blob: dd259456fd375a769fbd65363e1c3dc331e74a5c [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>
Jonas Olssona4d87372019-07-05 19:08:33 +020014
Yves Gerey3e707812018-11-28 16:47:49 +010015#include <cstdint>
16#include <type_traits>
17#include <utility>
sprang@webrtc.org8b881922013-12-10 10:05:17 +000018
Niels Möller4dc66c52018-10-05 14:17:58 +020019#include "api/video/encoded_image.h"
Yves Gerey3e707812018-11-28 16:47:49 +010020#include "modules/include/module_common_types.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "modules/video_coding/include/video_codec_interface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010022#include "modules/video_coding/include/video_error_codes.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "rtc_base/checks.h"
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +000024
sprang@webrtc.org8b881922013-12-10 10:05:17 +000025namespace webrtc {
26namespace test {
27
28ConfigurableFrameSizeEncoder::ConfigurableFrameSizeEncoder(
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000029 size_t max_frame_size)
sprang@webrtc.org8b881922013-12-10 10:05:17 +000030 : callback_(NULL),
31 max_frame_size_(max_frame_size),
32 current_frame_size_(max_frame_size),
Philip Eliassond52a1a62018-09-07 13:03:55 +000033 buffer_(new uint8_t[max_frame_size]),
34 codec_type_(kVideoCodecGeneric) {
sprang@webrtc.org8b881922013-12-10 10:05:17 +000035 memset(buffer_.get(), 0, max_frame_size);
36}
37
38ConfigurableFrameSizeEncoder::~ConfigurableFrameSizeEncoder() {}
39
Elad Alon8f01c4e2019-06-28 15:19:43 +020040void ConfigurableFrameSizeEncoder::SetFecControllerOverride(
41 FecControllerOverride* fec_controller_override) {
42 // Ignored.
43}
44
sprang@webrtc.org8b881922013-12-10 10:05:17 +000045int32_t ConfigurableFrameSizeEncoder::InitEncode(
46 const VideoCodec* codec_settings,
Elad Alon370f93a2019-06-11 14:57:57 +020047 const Settings& settings) {
sprang@webrtc.org8b881922013-12-10 10:05:17 +000048 return WEBRTC_VIDEO_CODEC_OK;
49}
50
51int32_t ConfigurableFrameSizeEncoder::Encode(
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070052 const VideoFrame& inputImage,
Niels Möller87e2d782019-03-07 10:18:23 +010053 const std::vector<VideoFrameType>* frame_types) {
Yves Gerey665174f2018-06-19 15:03:05 +020054 EncodedImage encodedImage(buffer_.get(), current_frame_size_,
55 max_frame_size_);
sprang@webrtc.org8b881922013-12-10 10:05:17 +000056 encodedImage._completeFrame = true;
57 encodedImage._encodedHeight = inputImage.height();
58 encodedImage._encodedWidth = inputImage.width();
Niels Möller8f7ce222019-03-21 15:43:58 +010059 encodedImage._frameType = VideoFrameType::kVideoFrameKey;
Niels Möller23775882018-08-16 10:24:12 +020060 encodedImage.SetTimestamp(inputImage.timestamp());
sprang@webrtc.org8b881922013-12-10 10:05:17 +000061 encodedImage.capture_time_ms_ = inputImage.render_time_ms();
62 RTPFragmentationHeader* fragmentation = NULL;
Philip Eliassond52a1a62018-09-07 13:03:55 +000063 CodecSpecificInfo specific{};
64 specific.codecType = codec_type_;
sergeyu2cb155a2016-11-04 11:39:29 -070065 callback_->OnEncodedImage(encodedImage, &specific, fragmentation);
Niels Möller759f9592018-10-09 14:57:01 +020066 if (post_encode_callback_) {
67 (*post_encode_callback_)();
68 }
sprang@webrtc.org8b881922013-12-10 10:05:17 +000069 return WEBRTC_VIDEO_CODEC_OK;
70}
71
72int32_t ConfigurableFrameSizeEncoder::RegisterEncodeCompleteCallback(
73 EncodedImageCallback* callback) {
74 callback_ = callback;
75 return WEBRTC_VIDEO_CODEC_OK;
76}
77
78int32_t ConfigurableFrameSizeEncoder::Release() {
79 return WEBRTC_VIDEO_CODEC_OK;
80}
81
Erik Språng16cb8f52019-04-12 13:59:09 +020082void ConfigurableFrameSizeEncoder::SetRates(
83 const RateControlParameters& parameters) {}
sprang@webrtc.org8b881922013-12-10 10:05:17 +000084
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000085int32_t ConfigurableFrameSizeEncoder::SetFrameSize(size_t size) {
Erik Språng08127a92016-11-16 16:41:30 +010086 RTC_DCHECK_LE(size, max_frame_size_);
sprang@webrtc.org8b881922013-12-10 10:05:17 +000087 current_frame_size_ = size;
88 return WEBRTC_VIDEO_CODEC_OK;
89}
90
Philip Eliassond52a1a62018-09-07 13:03:55 +000091void ConfigurableFrameSizeEncoder::SetCodecType(VideoCodecType codec_type) {
92 codec_type_ = codec_type;
93}
94
Niels Möller759f9592018-10-09 14:57:01 +020095void ConfigurableFrameSizeEncoder::RegisterPostEncodeCallback(
96 std::function<void(void)> post_encode_callback) {
97 post_encode_callback_ = std::move(post_encode_callback);
98}
99
sprang@webrtc.org8b881922013-12-10 10:05:17 +0000100} // namespace test
101} // namespace webrtc