blob: cbfb35bf33963eab0bb02f7038fa3455c80bb6a9 [file] [log] [blame]
sprang@webrtc.org8b881922013-12-10 10:05:17 +00001/*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "test/configurable_frame_size_encoder.h"
sprang@webrtc.org8b881922013-12-10 10:05:17 +000012
13#include <string.h>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "common_video/include/video_frame.h"
16#include "modules/video_coding/include/video_codec_interface.h"
17#include "rtc_base/checks.h"
18#include "test/gtest.h"
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +000019
sprang@webrtc.org8b881922013-12-10 10:05:17 +000020namespace webrtc {
21namespace test {
22
23ConfigurableFrameSizeEncoder::ConfigurableFrameSizeEncoder(
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000024 size_t max_frame_size)
sprang@webrtc.org8b881922013-12-10 10:05:17 +000025 : callback_(NULL),
26 max_frame_size_(max_frame_size),
27 current_frame_size_(max_frame_size),
28 buffer_(new uint8_t[max_frame_size]) {
29 memset(buffer_.get(), 0, max_frame_size);
30}
31
32ConfigurableFrameSizeEncoder::~ConfigurableFrameSizeEncoder() {}
33
34int32_t ConfigurableFrameSizeEncoder::InitEncode(
35 const VideoCodec* codec_settings,
36 int32_t number_of_cores,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000037 size_t max_payload_size) {
sprang@webrtc.org8b881922013-12-10 10:05:17 +000038 return WEBRTC_VIDEO_CODEC_OK;
39}
40
41int32_t ConfigurableFrameSizeEncoder::Encode(
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070042 const VideoFrame& inputImage,
sprang@webrtc.org8b881922013-12-10 10:05:17 +000043 const CodecSpecificInfo* codecSpecificInfo,
pbos22993e12015-10-19 02:39:06 -070044 const std::vector<FrameType>* frame_types) {
sprang@webrtc.org8b881922013-12-10 10:05:17 +000045 EncodedImage encodedImage(
46 buffer_.get(), current_frame_size_, max_frame_size_);
47 encodedImage._completeFrame = true;
48 encodedImage._encodedHeight = inputImage.height();
49 encodedImage._encodedWidth = inputImage.width();
Peter Boström49e196a2015-10-23 15:58:18 +020050 encodedImage._frameType = kVideoFrameKey;
sprang@webrtc.org8b881922013-12-10 10:05:17 +000051 encodedImage._timeStamp = inputImage.timestamp();
52 encodedImage.capture_time_ms_ = inputImage.render_time_ms();
53 RTPFragmentationHeader* fragmentation = NULL;
sprang@webrtc.org346094c2014-02-18 08:40:33 +000054 CodecSpecificInfo specific;
55 memset(&specific, 0, sizeof(specific));
sergeyu2cb155a2016-11-04 11:39:29 -070056 callback_->OnEncodedImage(encodedImage, &specific, fragmentation);
sprang@webrtc.org8b881922013-12-10 10:05:17 +000057
58 return WEBRTC_VIDEO_CODEC_OK;
59}
60
61int32_t ConfigurableFrameSizeEncoder::RegisterEncodeCompleteCallback(
62 EncodedImageCallback* callback) {
63 callback_ = callback;
64 return WEBRTC_VIDEO_CODEC_OK;
65}
66
67int32_t ConfigurableFrameSizeEncoder::Release() {
68 return WEBRTC_VIDEO_CODEC_OK;
69}
70
71int32_t ConfigurableFrameSizeEncoder::SetChannelParameters(uint32_t packet_loss,
pkasting@chromium.org16825b12015-01-12 21:51:21 +000072 int64_t rtt) {
sprang@webrtc.org8b881922013-12-10 10:05:17 +000073 return WEBRTC_VIDEO_CODEC_OK;
74}
75
Erik Språng08127a92016-11-16 16:41:30 +010076int32_t ConfigurableFrameSizeEncoder::SetRateAllocation(
77 const BitrateAllocation& allocation,
78 uint32_t framerate) {
sprang@webrtc.org8b881922013-12-10 10:05:17 +000079 return WEBRTC_VIDEO_CODEC_OK;
80}
81
82int32_t ConfigurableFrameSizeEncoder::SetPeriodicKeyFrames(bool enable) {
83 return WEBRTC_VIDEO_CODEC_OK;
84}
85
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000086int32_t ConfigurableFrameSizeEncoder::SetFrameSize(size_t size) {
Erik Språng08127a92016-11-16 16:41:30 +010087 RTC_DCHECK_LE(size, max_frame_size_);
sprang@webrtc.org8b881922013-12-10 10:05:17 +000088 current_frame_size_ = size;
89 return WEBRTC_VIDEO_CODEC_OK;
90}
91
92} // namespace test
93} // namespace webrtc