blob: ba529cba51d3c82fc69f36261713c94fa6743952 [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>
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <cstdint>
15#include <type_traits>
16#include <utility>
sprang@webrtc.org8b881922013-12-10 10:05:17 +000017
Niels Möller4dc66c52018-10-05 14:17:58 +020018#include "api/video/encoded_image.h"
Yves Gerey3e707812018-11-28 16:47:49 +010019#include "modules/include/module_common_types.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "modules/video_coding/include/video_codec_interface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010021#include "modules/video_coding/include/video_error_codes.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "rtc_base/checks.h"
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +000023
sprang@webrtc.org8b881922013-12-10 10:05:17 +000024namespace webrtc {
25namespace test {
26
27ConfigurableFrameSizeEncoder::ConfigurableFrameSizeEncoder(
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000028 size_t max_frame_size)
sprang@webrtc.org8b881922013-12-10 10:05:17 +000029 : callback_(NULL),
30 max_frame_size_(max_frame_size),
31 current_frame_size_(max_frame_size),
Philip Eliassond52a1a62018-09-07 13:03:55 +000032 buffer_(new uint8_t[max_frame_size]),
33 codec_type_(kVideoCodecGeneric) {
sprang@webrtc.org8b881922013-12-10 10:05:17 +000034 memset(buffer_.get(), 0, max_frame_size);
35}
36
37ConfigurableFrameSizeEncoder::~ConfigurableFrameSizeEncoder() {}
38
39int32_t ConfigurableFrameSizeEncoder::InitEncode(
40 const VideoCodec* codec_settings,
41 int32_t number_of_cores,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000042 size_t max_payload_size) {
sprang@webrtc.org8b881922013-12-10 10:05:17 +000043 return WEBRTC_VIDEO_CODEC_OK;
44}
45
46int32_t ConfigurableFrameSizeEncoder::Encode(
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070047 const VideoFrame& inputImage,
Niels Möller87e2d782019-03-07 10:18:23 +010048 const std::vector<VideoFrameType>* frame_types) {
Yves Gerey665174f2018-06-19 15:03:05 +020049 EncodedImage encodedImage(buffer_.get(), current_frame_size_,
50 max_frame_size_);
sprang@webrtc.org8b881922013-12-10 10:05:17 +000051 encodedImage._completeFrame = true;
52 encodedImage._encodedHeight = inputImage.height();
53 encodedImage._encodedWidth = inputImage.width();
Niels Möller8f7ce222019-03-21 15:43:58 +010054 encodedImage._frameType = VideoFrameType::kVideoFrameKey;
Niels Möller23775882018-08-16 10:24:12 +020055 encodedImage.SetTimestamp(inputImage.timestamp());
sprang@webrtc.org8b881922013-12-10 10:05:17 +000056 encodedImage.capture_time_ms_ = inputImage.render_time_ms();
57 RTPFragmentationHeader* fragmentation = NULL;
Philip Eliassond52a1a62018-09-07 13:03:55 +000058 CodecSpecificInfo specific{};
59 specific.codecType = codec_type_;
sergeyu2cb155a2016-11-04 11:39:29 -070060 callback_->OnEncodedImage(encodedImage, &specific, fragmentation);
Niels Möller759f9592018-10-09 14:57:01 +020061 if (post_encode_callback_) {
62 (*post_encode_callback_)();
63 }
sprang@webrtc.org8b881922013-12-10 10:05:17 +000064 return WEBRTC_VIDEO_CODEC_OK;
65}
66
67int32_t ConfigurableFrameSizeEncoder::RegisterEncodeCompleteCallback(
68 EncodedImageCallback* callback) {
69 callback_ = callback;
70 return WEBRTC_VIDEO_CODEC_OK;
71}
72
73int32_t ConfigurableFrameSizeEncoder::Release() {
74 return WEBRTC_VIDEO_CODEC_OK;
75}
76
Erik Språng16cb8f52019-04-12 13:59:09 +020077void ConfigurableFrameSizeEncoder::SetRates(
78 const RateControlParameters& parameters) {}
sprang@webrtc.org8b881922013-12-10 10:05:17 +000079
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000080int32_t ConfigurableFrameSizeEncoder::SetFrameSize(size_t size) {
Erik Språng08127a92016-11-16 16:41:30 +010081 RTC_DCHECK_LE(size, max_frame_size_);
sprang@webrtc.org8b881922013-12-10 10:05:17 +000082 current_frame_size_ = size;
83 return WEBRTC_VIDEO_CODEC_OK;
84}
85
Philip Eliassond52a1a62018-09-07 13:03:55 +000086void ConfigurableFrameSizeEncoder::SetCodecType(VideoCodecType codec_type) {
87 codec_type_ = codec_type;
88}
89
Niels Möller759f9592018-10-09 14:57:01 +020090void ConfigurableFrameSizeEncoder::RegisterPostEncodeCallback(
91 std::function<void(void)> post_encode_callback) {
92 post_encode_callback_ = std::move(post_encode_callback);
93}
94
sprang@webrtc.org8b881922013-12-10 10:05:17 +000095} // namespace test
96} // namespace webrtc