blob: 77326077ba79152c53f64a7c2d589fc6cb07795d [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,
Elad Alon370f93a2019-06-11 14:57:57 +020041 const Settings& settings) {
sprang@webrtc.org8b881922013-12-10 10:05:17 +000042 return WEBRTC_VIDEO_CODEC_OK;
43}
44
45int32_t ConfigurableFrameSizeEncoder::Encode(
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070046 const VideoFrame& inputImage,
Niels Möller87e2d782019-03-07 10:18:23 +010047 const std::vector<VideoFrameType>* frame_types) {
Yves Gerey665174f2018-06-19 15:03:05 +020048 EncodedImage encodedImage(buffer_.get(), current_frame_size_,
49 max_frame_size_);
sprang@webrtc.org8b881922013-12-10 10:05:17 +000050 encodedImage._completeFrame = true;
51 encodedImage._encodedHeight = inputImage.height();
52 encodedImage._encodedWidth = inputImage.width();
Niels Möller8f7ce222019-03-21 15:43:58 +010053 encodedImage._frameType = VideoFrameType::kVideoFrameKey;
Niels Möller23775882018-08-16 10:24:12 +020054 encodedImage.SetTimestamp(inputImage.timestamp());
sprang@webrtc.org8b881922013-12-10 10:05:17 +000055 encodedImage.capture_time_ms_ = inputImage.render_time_ms();
56 RTPFragmentationHeader* fragmentation = NULL;
Philip Eliassond52a1a62018-09-07 13:03:55 +000057 CodecSpecificInfo specific{};
58 specific.codecType = codec_type_;
sergeyu2cb155a2016-11-04 11:39:29 -070059 callback_->OnEncodedImage(encodedImage, &specific, fragmentation);
Niels Möller759f9592018-10-09 14:57:01 +020060 if (post_encode_callback_) {
61 (*post_encode_callback_)();
62 }
sprang@webrtc.org8b881922013-12-10 10:05:17 +000063 return WEBRTC_VIDEO_CODEC_OK;
64}
65
66int32_t ConfigurableFrameSizeEncoder::RegisterEncodeCompleteCallback(
67 EncodedImageCallback* callback) {
68 callback_ = callback;
69 return WEBRTC_VIDEO_CODEC_OK;
70}
71
72int32_t ConfigurableFrameSizeEncoder::Release() {
73 return WEBRTC_VIDEO_CODEC_OK;
74}
75
Erik Språng16cb8f52019-04-12 13:59:09 +020076void ConfigurableFrameSizeEncoder::SetRates(
77 const RateControlParameters& parameters) {}
sprang@webrtc.org8b881922013-12-10 10:05:17 +000078
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000079int32_t ConfigurableFrameSizeEncoder::SetFrameSize(size_t size) {
Erik Språng08127a92016-11-16 16:41:30 +010080 RTC_DCHECK_LE(size, max_frame_size_);
sprang@webrtc.org8b881922013-12-10 10:05:17 +000081 current_frame_size_ = size;
82 return WEBRTC_VIDEO_CODEC_OK;
83}
84
Philip Eliassond52a1a62018-09-07 13:03:55 +000085void ConfigurableFrameSizeEncoder::SetCodecType(VideoCodecType codec_type) {
86 codec_type_ = codec_type;
87}
88
Niels Möller759f9592018-10-09 14:57:01 +020089void ConfigurableFrameSizeEncoder::RegisterPostEncodeCallback(
90 std::function<void(void)> post_encode_callback) {
91 post_encode_callback_ = std::move(post_encode_callback);
92}
93
sprang@webrtc.org8b881922013-12-10 10:05:17 +000094} // namespace test
95} // namespace webrtc