sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [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 06:47:31 +0200 | [diff] [blame] | 11 | #include "test/configurable_frame_size_encoder.h" |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 12 | |
| 13 | #include <string.h> |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 14 | #include <cstdint> |
| 15 | #include <type_traits> |
| 16 | #include <utility> |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 17 | |
Niels Möller | 4dc66c5 | 2018-10-05 14:17:58 +0200 | [diff] [blame] | 18 | #include "api/video/encoded_image.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 19 | #include "modules/include/module_common_types.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "modules/video_coding/include/video_codec_interface.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 21 | #include "modules/video_coding/include/video_error_codes.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "rtc_base/checks.h" |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 23 | |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 24 | namespace webrtc { |
| 25 | namespace test { |
| 26 | |
| 27 | ConfigurableFrameSizeEncoder::ConfigurableFrameSizeEncoder( |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 28 | size_t max_frame_size) |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 29 | : callback_(NULL), |
| 30 | max_frame_size_(max_frame_size), |
| 31 | current_frame_size_(max_frame_size), |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 32 | buffer_(new uint8_t[max_frame_size]), |
| 33 | codec_type_(kVideoCodecGeneric) { |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 34 | memset(buffer_.get(), 0, max_frame_size); |
| 35 | } |
| 36 | |
| 37 | ConfigurableFrameSizeEncoder::~ConfigurableFrameSizeEncoder() {} |
| 38 | |
| 39 | int32_t ConfigurableFrameSizeEncoder::InitEncode( |
| 40 | const VideoCodec* codec_settings, |
| 41 | int32_t number_of_cores, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 42 | size_t max_payload_size) { |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 43 | return WEBRTC_VIDEO_CODEC_OK; |
| 44 | } |
| 45 | |
| 46 | int32_t ConfigurableFrameSizeEncoder::Encode( |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 47 | const VideoFrame& inputImage, |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 48 | const CodecSpecificInfo* codecSpecificInfo, |
pbos | 22993e1 | 2015-10-19 02:39:06 -0700 | [diff] [blame] | 49 | const std::vector<FrameType>* frame_types) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 50 | EncodedImage encodedImage(buffer_.get(), current_frame_size_, |
| 51 | max_frame_size_); |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 52 | encodedImage._completeFrame = true; |
| 53 | encodedImage._encodedHeight = inputImage.height(); |
| 54 | encodedImage._encodedWidth = inputImage.width(); |
Peter Boström | 49e196a | 2015-10-23 15:58:18 +0200 | [diff] [blame] | 55 | encodedImage._frameType = kVideoFrameKey; |
Niels Möller | 2377588 | 2018-08-16 10:24:12 +0200 | [diff] [blame] | 56 | encodedImage.SetTimestamp(inputImage.timestamp()); |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 57 | encodedImage.capture_time_ms_ = inputImage.render_time_ms(); |
| 58 | RTPFragmentationHeader* fragmentation = NULL; |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 59 | CodecSpecificInfo specific{}; |
| 60 | specific.codecType = codec_type_; |
sergeyu | 2cb155a | 2016-11-04 11:39:29 -0700 | [diff] [blame] | 61 | callback_->OnEncodedImage(encodedImage, &specific, fragmentation); |
Niels Möller | 759f959 | 2018-10-09 14:57:01 +0200 | [diff] [blame] | 62 | if (post_encode_callback_) { |
| 63 | (*post_encode_callback_)(); |
| 64 | } |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 65 | return WEBRTC_VIDEO_CODEC_OK; |
| 66 | } |
| 67 | |
| 68 | int32_t ConfigurableFrameSizeEncoder::RegisterEncodeCompleteCallback( |
| 69 | EncodedImageCallback* callback) { |
| 70 | callback_ = callback; |
| 71 | return WEBRTC_VIDEO_CODEC_OK; |
| 72 | } |
| 73 | |
| 74 | int32_t ConfigurableFrameSizeEncoder::Release() { |
| 75 | return WEBRTC_VIDEO_CODEC_OK; |
| 76 | } |
| 77 | |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 78 | int32_t ConfigurableFrameSizeEncoder::SetRateAllocation( |
Erik Språng | 566124a | 2018-04-23 12:32:22 +0200 | [diff] [blame] | 79 | const VideoBitrateAllocation& allocation, |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 80 | uint32_t framerate) { |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 81 | return WEBRTC_VIDEO_CODEC_OK; |
| 82 | } |
| 83 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 84 | int32_t ConfigurableFrameSizeEncoder::SetFrameSize(size_t size) { |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 85 | RTC_DCHECK_LE(size, max_frame_size_); |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 86 | current_frame_size_ = size; |
| 87 | return WEBRTC_VIDEO_CODEC_OK; |
| 88 | } |
| 89 | |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 90 | void ConfigurableFrameSizeEncoder::SetCodecType(VideoCodecType codec_type) { |
| 91 | codec_type_ = codec_type; |
| 92 | } |
| 93 | |
Niels Möller | 759f959 | 2018-10-09 14:57:01 +0200 | [diff] [blame] | 94 | void ConfigurableFrameSizeEncoder::RegisterPostEncodeCallback( |
| 95 | std::function<void(void)> post_encode_callback) { |
| 96 | post_encode_callback_ = std::move(post_encode_callback); |
| 97 | } |
| 98 | |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 99 | } // namespace test |
| 100 | } // namespace webrtc |