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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "common_video/include/video_frame.h" |
| 16 | #include "modules/video_coding/include/video_codec_interface.h" |
| 17 | #include "rtc_base/checks.h" |
| 18 | #include "test/gtest.h" |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 19 | |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 20 | namespace webrtc { |
| 21 | namespace test { |
| 22 | |
| 23 | ConfigurableFrameSizeEncoder::ConfigurableFrameSizeEncoder( |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 24 | size_t max_frame_size) |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 25 | : callback_(NULL), |
| 26 | max_frame_size_(max_frame_size), |
| 27 | current_frame_size_(max_frame_size), |
| 28 | buffer_(new uint8_t[max_frame_size]) { |
| 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) { |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 45 | EncodedImage encodedImage( |
| 46 | buffer_.get(), current_frame_size_, max_frame_size_); |
| 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; |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 51 | encodedImage._timeStamp = inputImage.timestamp(); |
| 52 | encodedImage.capture_time_ms_ = inputImage.render_time_ms(); |
| 53 | RTPFragmentationHeader* fragmentation = NULL; |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 54 | CodecSpecificInfo specific; |
| 55 | memset(&specific, 0, sizeof(specific)); |
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( |
| 77 | const BitrateAllocation& allocation, |
| 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 | |
| 82 | int32_t ConfigurableFrameSizeEncoder::SetPeriodicKeyFrames(bool enable) { |
| 83 | return WEBRTC_VIDEO_CODEC_OK; |
| 84 | } |
| 85 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 86 | int32_t ConfigurableFrameSizeEncoder::SetFrameSize(size_t size) { |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 87 | RTC_DCHECK_LE(size, max_frame_size_); |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 88 | current_frame_size_ = size; |
| 89 | return WEBRTC_VIDEO_CODEC_OK; |
| 90 | } |
| 91 | |
| 92 | } // namespace test |
| 93 | } // namespace webrtc |