1 /*
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
11 #include "test/configurable_frame_size_encoder.h"
12
13 #include <string.h>
14
15 #include <cstdint>
16 #include <type_traits>
17 #include <utility>
18
19 #include "api/video/encoded_image.h"
20 #include "modules/include/module_common_types.h"
21 #include "modules/video_coding/include/video_codec_interface.h"
22 #include "modules/video_coding/include/video_error_codes.h"
23 #include "rtc_base/checks.h"
24
25 namespace webrtc {
26 namespace test {
27
ConfigurableFrameSizeEncoder(size_t max_frame_size)28 ConfigurableFrameSizeEncoder::ConfigurableFrameSizeEncoder(
29 size_t max_frame_size)
30 : callback_(NULL),
31 max_frame_size_(max_frame_size),
32 current_frame_size_(max_frame_size),
33 buffer_(new uint8_t[max_frame_size]),
34 codec_type_(kVideoCodecGeneric) {
35 memset(buffer_.get(), 0, max_frame_size);
36 }
37
~ConfigurableFrameSizeEncoder()38 ConfigurableFrameSizeEncoder::~ConfigurableFrameSizeEncoder() {}
39
SetFecControllerOverride(FecControllerOverride * fec_controller_override)40 void ConfigurableFrameSizeEncoder::SetFecControllerOverride(
41 FecControllerOverride* fec_controller_override) {
42 // Ignored.
43 }
44
InitEncode(const VideoCodec * codec_settings,const Settings & settings)45 int32_t ConfigurableFrameSizeEncoder::InitEncode(
46 const VideoCodec* codec_settings,
47 const Settings& settings) {
48 return WEBRTC_VIDEO_CODEC_OK;
49 }
50
Encode(const VideoFrame & inputImage,const std::vector<VideoFrameType> * frame_types)51 int32_t ConfigurableFrameSizeEncoder::Encode(
52 const VideoFrame& inputImage,
53 const std::vector<VideoFrameType>* frame_types) {
54 EncodedImage encodedImage(buffer_.get(), current_frame_size_,
55 max_frame_size_);
56 encodedImage._completeFrame = true;
57 encodedImage._encodedHeight = inputImage.height();
58 encodedImage._encodedWidth = inputImage.width();
59 encodedImage._frameType = VideoFrameType::kVideoFrameKey;
60 encodedImage.SetTimestamp(inputImage.timestamp());
61 encodedImage.capture_time_ms_ = inputImage.render_time_ms();
62 RTPFragmentationHeader* fragmentation = NULL;
63 CodecSpecificInfo specific{};
64 specific.codecType = codec_type_;
65 callback_->OnEncodedImage(encodedImage, &specific, fragmentation);
66 if (post_encode_callback_) {
67 (*post_encode_callback_)();
68 }
69 return WEBRTC_VIDEO_CODEC_OK;
70 }
71
RegisterEncodeCompleteCallback(EncodedImageCallback * callback)72 int32_t ConfigurableFrameSizeEncoder::RegisterEncodeCompleteCallback(
73 EncodedImageCallback* callback) {
74 callback_ = callback;
75 return WEBRTC_VIDEO_CODEC_OK;
76 }
77
Release()78 int32_t ConfigurableFrameSizeEncoder::Release() {
79 return WEBRTC_VIDEO_CODEC_OK;
80 }
81
SetRates(const RateControlParameters & parameters)82 void ConfigurableFrameSizeEncoder::SetRates(
83 const RateControlParameters& parameters) {}
84
SetFrameSize(size_t size)85 int32_t ConfigurableFrameSizeEncoder::SetFrameSize(size_t size) {
86 RTC_DCHECK_LE(size, max_frame_size_);
87 current_frame_size_ = size;
88 return WEBRTC_VIDEO_CODEC_OK;
89 }
90
SetCodecType(VideoCodecType codec_type)91 void ConfigurableFrameSizeEncoder::SetCodecType(VideoCodecType codec_type) {
92 codec_type_ = codec_type;
93 }
94
RegisterPostEncodeCallback(std::function<void (void)> post_encode_callback)95 void ConfigurableFrameSizeEncoder::RegisterPostEncodeCallback(
96 std::function<void(void)> post_encode_callback) {
97 post_encode_callback_ = std::move(post_encode_callback);
98 }
99
100 } // namespace test
101 } // namespace webrtc
102