sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #include "test/configurable_frame_size_encoder.h" |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 | [diff] [blame] | 12 | |
| 13 | #include <string.h> |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 14 | |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 15 | #include <cstdint> |
| 16 | #include <type_traits> |
| 17 | #include <utility> |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 | [diff] [blame] | 18 | |
Niels Möller | 4dc66c5 | 2018-10-05 12:17:58 | [diff] [blame] | 19 | #include "api/video/encoded_image.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 20 | #include "modules/video_coding/include/video_codec_interface.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 21 | #include "modules/video_coding/include/video_error_codes.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 22 | #include "rtc_base/checks.h" |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 | [diff] [blame] | 23 | |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 | [diff] [blame] | 24 | namespace webrtc { |
| 25 | namespace test { |
| 26 | |
| 27 | ConfigurableFrameSizeEncoder::ConfigurableFrameSizeEncoder( |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 | [diff] [blame] | 28 | size_t max_frame_size) |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 | [diff] [blame] | 29 | : callback_(NULL), |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 | [diff] [blame] | 30 | current_frame_size_(max_frame_size), |
Niels Möller | 12f465c | 2020-09-23 10:45:17 | [diff] [blame] | 31 | codec_type_(kVideoCodecGeneric) {} |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 | [diff] [blame] | 32 | |
| 33 | ConfigurableFrameSizeEncoder::~ConfigurableFrameSizeEncoder() {} |
| 34 | |
Elad Alon | 8f01c4e | 2019-06-28 13:19:43 | [diff] [blame] | 35 | void ConfigurableFrameSizeEncoder::SetFecControllerOverride( |
| 36 | FecControllerOverride* fec_controller_override) { |
| 37 | // Ignored. |
| 38 | } |
| 39 | |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 | [diff] [blame] | 40 | int32_t ConfigurableFrameSizeEncoder::InitEncode( |
| 41 | const VideoCodec* codec_settings, |
Elad Alon | 370f93a | 2019-06-11 12:57:57 | [diff] [blame] | 42 | const Settings& settings) { |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 | [diff] [blame] | 43 | return WEBRTC_VIDEO_CODEC_OK; |
| 44 | } |
| 45 | |
| 46 | int32_t ConfigurableFrameSizeEncoder::Encode( |
Miguel Casas-Sanchez | 4765070 | 2015-05-30 00:21:40 | [diff] [blame] | 47 | const VideoFrame& inputImage, |
Niels Möller | 87e2d78 | 2019-03-07 09:18:23 | [diff] [blame] | 48 | const std::vector<VideoFrameType>* frame_types) { |
Niels Möller | 12f465c | 2020-09-23 10:45:17 | [diff] [blame] | 49 | EncodedImage encodedImage; |
| 50 | auto buffer = EncodedImageBuffer::Create(current_frame_size_); |
| 51 | memset(buffer->data(), 0, current_frame_size_); |
| 52 | encodedImage.SetEncodedData(buffer); |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 | [diff] [blame] | 53 | encodedImage._encodedHeight = inputImage.height(); |
| 54 | encodedImage._encodedWidth = inputImage.width(); |
Niels Möller | 8f7ce22 | 2019-03-21 14:43:58 | [diff] [blame] | 55 | encodedImage._frameType = VideoFrameType::kVideoFrameKey; |
Per K | 0fa9088 | 2024-03-13 08:52:41 | [diff] [blame] | 56 | encodedImage.SetRtpTimestamp(inputImage.rtp_timestamp()); |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 | [diff] [blame] | 57 | encodedImage.capture_time_ms_ = inputImage.render_time_ms(); |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 | [diff] [blame] | 58 | CodecSpecificInfo specific{}; |
| 59 | specific.codecType = codec_type_; |
Danil Chapovalov | 2549f17 | 2020-08-12 15:30:36 | [diff] [blame] | 60 | callback_->OnEncodedImage(encodedImage, &specific); |
Niels Möller | 759f959 | 2018-10-09 12:57:01 | [diff] [blame] | 61 | if (post_encode_callback_) { |
| 62 | (*post_encode_callback_)(); |
| 63 | } |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 | [diff] [blame] | 64 | return WEBRTC_VIDEO_CODEC_OK; |
| 65 | } |
| 66 | |
| 67 | int32_t ConfigurableFrameSizeEncoder::RegisterEncodeCompleteCallback( |
| 68 | EncodedImageCallback* callback) { |
| 69 | callback_ = callback; |
| 70 | return WEBRTC_VIDEO_CODEC_OK; |
| 71 | } |
| 72 | |
| 73 | int32_t ConfigurableFrameSizeEncoder::Release() { |
| 74 | return WEBRTC_VIDEO_CODEC_OK; |
| 75 | } |
| 76 | |
Erik Språng | 16cb8f5 | 2019-04-12 11:59:09 | [diff] [blame] | 77 | void ConfigurableFrameSizeEncoder::SetRates( |
| 78 | const RateControlParameters& parameters) {} |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 | [diff] [blame] | 79 | |
Wan-Teh Chang | bd86684 | 2023-02-14 23:26:40 | [diff] [blame] | 80 | VideoEncoder::EncoderInfo ConfigurableFrameSizeEncoder::GetEncoderInfo() const { |
| 81 | return EncoderInfo(); |
| 82 | } |
| 83 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 | [diff] [blame] | 84 | int32_t ConfigurableFrameSizeEncoder::SetFrameSize(size_t size) { |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 | [diff] [blame] | 85 | current_frame_size_ = size; |
| 86 | return WEBRTC_VIDEO_CODEC_OK; |
| 87 | } |
| 88 | |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 | [diff] [blame] | 89 | void ConfigurableFrameSizeEncoder::SetCodecType(VideoCodecType codec_type) { |
| 90 | codec_type_ = codec_type; |
| 91 | } |
| 92 | |
Niels Möller | 759f959 | 2018-10-09 12:57:01 | [diff] [blame] | 93 | void ConfigurableFrameSizeEncoder::RegisterPostEncodeCallback( |
| 94 | std::function<void(void)> post_encode_callback) { |
| 95 | post_encode_callback_ = std::move(post_encode_callback); |
| 96 | } |
| 97 | |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 | [diff] [blame] | 98 | } // namespace test |
| 99 | } // namespace webrtc |