blob: bc94011b4853ce9acc884bc5c0625e71ff4e87d2 [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,
sprang@webrtc.org8b881922013-12-10 10:05:17 +000048 const CodecSpecificInfo* codecSpecificInfo,
pbos22993e12015-10-19 02:39:06 -070049 const std::vector<FrameType>* frame_types) {
Yves Gerey665174f2018-06-19 15:03:05 +020050 EncodedImage encodedImage(buffer_.get(), current_frame_size_,
51 max_frame_size_);
sprang@webrtc.org8b881922013-12-10 10:05:17 +000052 encodedImage._completeFrame = true;
53 encodedImage._encodedHeight = inputImage.height();
54 encodedImage._encodedWidth = inputImage.width();
Peter Boström49e196a2015-10-23 15:58:18 +020055 encodedImage._frameType = kVideoFrameKey;
Niels Möller23775882018-08-16 10:24:12 +020056 encodedImage.SetTimestamp(inputImage.timestamp());
sprang@webrtc.org8b881922013-12-10 10:05:17 +000057 encodedImage.capture_time_ms_ = inputImage.render_time_ms();
58 RTPFragmentationHeader* fragmentation = NULL;
Philip Eliassond52a1a62018-09-07 13:03:55 +000059 CodecSpecificInfo specific{};
60 specific.codecType = codec_type_;
sergeyu2cb155a2016-11-04 11:39:29 -070061 callback_->OnEncodedImage(encodedImage, &specific, fragmentation);
Niels Möller759f9592018-10-09 14:57:01 +020062 if (post_encode_callback_) {
63 (*post_encode_callback_)();
64 }
sprang@webrtc.org8b881922013-12-10 10:05:17 +000065 return WEBRTC_VIDEO_CODEC_OK;
66}
67
68int32_t ConfigurableFrameSizeEncoder::RegisterEncodeCompleteCallback(
69 EncodedImageCallback* callback) {
70 callback_ = callback;
71 return WEBRTC_VIDEO_CODEC_OK;
72}
73
74int32_t ConfigurableFrameSizeEncoder::Release() {
75 return WEBRTC_VIDEO_CODEC_OK;
76}
77
Erik Språng08127a92016-11-16 16:41:30 +010078int32_t ConfigurableFrameSizeEncoder::SetRateAllocation(
Erik Språng566124a2018-04-23 12:32:22 +020079 const VideoBitrateAllocation& allocation,
Erik Språng08127a92016-11-16 16:41:30 +010080 uint32_t framerate) {
sprang@webrtc.org8b881922013-12-10 10:05:17 +000081 return WEBRTC_VIDEO_CODEC_OK;
82}
83
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000084int32_t ConfigurableFrameSizeEncoder::SetFrameSize(size_t size) {
Erik Språng08127a92016-11-16 16:41:30 +010085 RTC_DCHECK_LE(size, max_frame_size_);
sprang@webrtc.org8b881922013-12-10 10:05:17 +000086 current_frame_size_ = size;
87 return WEBRTC_VIDEO_CODEC_OK;
88}
89
Philip Eliassond52a1a62018-09-07 13:03:55 +000090void ConfigurableFrameSizeEncoder::SetCodecType(VideoCodecType codec_type) {
91 codec_type_ = codec_type;
92}
93
Niels Möller759f9592018-10-09 14:57:01 +020094void ConfigurableFrameSizeEncoder::RegisterPostEncodeCallback(
95 std::function<void(void)> post_encode_callback) {
96 post_encode_callback_ = std::move(post_encode_callback);
97}
98
sprang@webrtc.org8b881922013-12-10 10:05:17 +000099} // namespace test
100} // namespace webrtc