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