kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 1 | /* |
marpan@webrtc.org | f4c2de9 | 2012-06-05 21:07:28 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 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 | */ |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ |
| 12 | #define MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 13 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 14 | #include <stddef.h> |
| 15 | #include <stdint.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 16 | |
brandtr | b57f426 | 2017-08-30 06:29:51 -0700 | [diff] [blame] | 17 | #include <map> |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 18 | #include <memory> |
Rasmus Brandt | 001c782 | 2019-03-22 13:41:48 +0100 | [diff] [blame] | 19 | #include <utility> |
brandtr | 17b958c | 2017-03-07 01:41:43 -0800 | [diff] [blame] | 20 | #include <vector> |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 21 | |
Danil Chapovalov | 471783f | 2019-03-11 14:26:02 +0100 | [diff] [blame] | 22 | #include "absl/memory/memory.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 23 | #include "absl/types/optional.h" |
Danil Chapovalov | 471783f | 2019-03-11 14:26:02 +0100 | [diff] [blame] | 24 | #include "api/task_queue/queued_task.h" |
Danil Chapovalov | ad89528 | 2019-03-11 10:28:05 +0000 | [diff] [blame] | 25 | #include "api/task_queue/task_queue_base.h" |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 26 | #include "api/test/videocodec_test_fixture.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 27 | #include "api/video/encoded_image.h" |
| 28 | #include "api/video/video_bitrate_allocation.h" |
Jiawei Ou | 4206a0a | 2018-07-20 15:49:43 -0700 | [diff] [blame] | 29 | #include "api/video/video_bitrate_allocator.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 30 | #include "api/video/video_frame.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 31 | #include "api/video_codecs/video_decoder.h" |
| 32 | #include "api/video_codecs/video_encoder.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 33 | #include "modules/include/module_common_types.h" |
Rasmus Brandt | 7d72d0f | 2019-03-26 16:56:14 +0100 | [diff] [blame] | 34 | #include "modules/video_coding/codecs/test/videocodec_test_stats_impl.h" |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 35 | #include "modules/video_coding/include/video_codec_interface.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 36 | #include "modules/video_coding/utility/ivf_file_writer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 37 | #include "rtc_base/buffer.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 38 | #include "rtc_base/checks.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 39 | #include "rtc_base/constructor_magic.h" |
Sebastian Jansson | b55015e | 2019-04-09 13:44:04 +0200 | [diff] [blame] | 40 | #include "rtc_base/synchronization/sequence_checker.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 41 | #include "rtc_base/thread_annotations.h" |
| 42 | #include "rtc_base/thread_checker.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 43 | #include "test/testsupport/frame_reader.h" |
| 44 | #include "test/testsupport/frame_writer.h" |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 45 | |
| 46 | namespace webrtc { |
| 47 | namespace test { |
| 48 | |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 49 | // Handles encoding/decoding of video using the VideoEncoder/VideoDecoder |
| 50 | // interfaces. This is done in a sequential manner in order to be able to |
| 51 | // measure times properly. |
| 52 | // The class processes a frame at the time for the configured input file. |
| 53 | // It maintains state of where in the source input file the processing is at. |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 54 | class VideoProcessor { |
| 55 | public: |
Sergey Silkin | 10d9d59 | 2018-02-01 13:25:17 +0100 | [diff] [blame] | 56 | using VideoDecoderList = std::vector<std::unique_ptr<VideoDecoder>>; |
Rasmus Brandt | 001c782 | 2019-03-22 13:41:48 +0100 | [diff] [blame] | 57 | using LayerKey = std::pair<int /* spatial_idx */, int /* temporal_idx */>; |
| 58 | using IvfFileWriterMap = std::map<LayerKey, std::unique_ptr<IvfFileWriter>>; |
| 59 | // TODO(brandtr): Consider changing FrameWriterList to be a FrameWriterMap, |
| 60 | // to be able to save different TLs separately. |
Sergey Silkin | 10d9d59 | 2018-02-01 13:25:17 +0100 | [diff] [blame] | 61 | using FrameWriterList = std::vector<std::unique_ptr<FrameWriter>>; |
| 62 | |
brandtr | c409552 | 2017-08-07 08:12:33 -0700 | [diff] [blame] | 63 | VideoProcessor(webrtc::VideoEncoder* encoder, |
Sergey Silkin | 10d9d59 | 2018-02-01 13:25:17 +0100 | [diff] [blame] | 64 | VideoDecoderList* decoders, |
| 65 | FrameReader* input_frame_reader, |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 66 | const VideoCodecTestFixture::Config& config, |
Rasmus Brandt | 7d72d0f | 2019-03-26 16:56:14 +0100 | [diff] [blame] | 67 | VideoCodecTestStatsImpl* stats, |
Rasmus Brandt | 001c782 | 2019-03-22 13:41:48 +0100 | [diff] [blame] | 68 | IvfFileWriterMap* encoded_frame_writers, |
Sergey Silkin | 10d9d59 | 2018-02-01 13:25:17 +0100 | [diff] [blame] | 69 | FrameWriterList* decoded_frame_writers); |
brandtr | c409552 | 2017-08-07 08:12:33 -0700 | [diff] [blame] | 70 | ~VideoProcessor(); |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 71 | |
Sergey Silkin | 10d9d59 | 2018-02-01 13:25:17 +0100 | [diff] [blame] | 72 | // Reads a frame and sends it to the encoder. When the encode callback |
| 73 | // is received, the encoded frame is buffered. After encoding is finished |
| 74 | // buffered frame is sent to decoder. Quality evaluation is done in |
| 75 | // the decode callback. |
brandtr | 8935d97 | 2017-09-06 01:53:22 -0700 | [diff] [blame] | 76 | void ProcessFrame(); |
marpan@webrtc.org | f4c2de9 | 2012-06-05 21:07:28 +0000 | [diff] [blame] | 77 | |
brandtr | bdd555c | 2017-08-21 01:34:04 -0700 | [diff] [blame] | 78 | // Updates the encoder with target rates. Must be called at least once. |
Sergey Silkin | 44cec0b | 2019-07-11 14:20:38 +0200 | [diff] [blame] | 79 | void SetRates(size_t bitrate_kbps, double framerate_fps); |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 80 | |
| 81 | private: |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 82 | class VideoProcessorEncodeCompleteCallback |
pbos@webrtc.org | 7f7162a | 2013-07-30 15:18:31 +0000 | [diff] [blame] | 83 | : public webrtc::EncodedImageCallback { |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 84 | public: |
brandtr | c409552 | 2017-08-07 08:12:33 -0700 | [diff] [blame] | 85 | explicit VideoProcessorEncodeCompleteCallback( |
| 86 | VideoProcessor* video_processor) |
brandtr | c8c5905 | 2017-08-21 06:44:16 -0700 | [diff] [blame] | 87 | : video_processor_(video_processor), |
Danil Chapovalov | ad89528 | 2019-03-11 10:28:05 +0000 | [diff] [blame] | 88 | task_queue_(TaskQueueBase::Current()) { |
Rasmus Brandt | 5f7a891 | 2018-02-28 17:17:15 +0100 | [diff] [blame] | 89 | RTC_DCHECK(video_processor_); |
Rasmus Brandt | 4b381af | 2018-02-07 13:56:16 +0100 | [diff] [blame] | 90 | RTC_DCHECK(task_queue_); |
| 91 | } |
brandtr | c8c5905 | 2017-08-21 06:44:16 -0700 | [diff] [blame] | 92 | |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 93 | Result OnEncodedImage( |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 94 | const webrtc::EncodedImage& encoded_image, |
| 95 | const webrtc::CodecSpecificInfo* codec_specific_info, |
brandtr | 8bc9385 | 2017-02-15 05:19:51 -0800 | [diff] [blame] | 96 | const webrtc::RTPFragmentationHeader* fragmentation) override { |
brandtr | 8bc9385 | 2017-02-15 05:19:51 -0800 | [diff] [blame] | 97 | RTC_CHECK(codec_specific_info); |
brandtr | c8c5905 | 2017-08-21 06:44:16 -0700 | [diff] [blame] | 98 | |
Rasmus Brandt | 4b381af | 2018-02-07 13:56:16 +0100 | [diff] [blame] | 99 | // Post the callback to the right task queue, if needed. |
| 100 | if (!task_queue_->IsCurrent()) { |
Danil Chapovalov | 471783f | 2019-03-11 14:26:02 +0100 | [diff] [blame] | 101 | task_queue_->PostTask(absl::make_unique<EncodeCallbackTask>( |
| 102 | video_processor_, encoded_image, codec_specific_info)); |
brandtr | c8c5905 | 2017-08-21 06:44:16 -0700 | [diff] [blame] | 103 | return Result(Result::OK, 0); |
| 104 | } |
| 105 | |
Sergey Silkin | 10d9d59 | 2018-02-01 13:25:17 +0100 | [diff] [blame] | 106 | video_processor_->FrameEncoded(encoded_image, *codec_specific_info); |
brandtr | 8bc9385 | 2017-02-15 05:19:51 -0800 | [diff] [blame] | 107 | return Result(Result::OK, 0); |
| 108 | } |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 109 | |
| 110 | private: |
Danil Chapovalov | 471783f | 2019-03-11 14:26:02 +0100 | [diff] [blame] | 111 | class EncodeCallbackTask : public QueuedTask { |
brandtr | c8c5905 | 2017-08-21 06:44:16 -0700 | [diff] [blame] | 112 | public: |
| 113 | EncodeCallbackTask(VideoProcessor* video_processor, |
| 114 | const webrtc::EncodedImage& encoded_image, |
brandtr | 4553562 | 2017-08-22 03:33:11 -0700 | [diff] [blame] | 115 | const webrtc::CodecSpecificInfo* codec_specific_info) |
brandtr | c8c5905 | 2017-08-21 06:44:16 -0700 | [diff] [blame] | 116 | : video_processor_(video_processor), |
brandtr | c8c5905 | 2017-08-21 06:44:16 -0700 | [diff] [blame] | 117 | encoded_image_(encoded_image), |
| 118 | codec_specific_info_(*codec_specific_info) { |
Niels Möller | 663844d | 2019-02-14 16:15:54 +0100 | [diff] [blame] | 119 | encoded_image_.Retain(); |
brandtr | c8c5905 | 2017-08-21 06:44:16 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | bool Run() override { |
Sergey Silkin | 10d9d59 | 2018-02-01 13:25:17 +0100 | [diff] [blame] | 123 | video_processor_->FrameEncoded(encoded_image_, codec_specific_info_); |
brandtr | c8c5905 | 2017-08-21 06:44:16 -0700 | [diff] [blame] | 124 | return true; |
| 125 | } |
| 126 | |
| 127 | private: |
| 128 | VideoProcessor* const video_processor_; |
brandtr | c8c5905 | 2017-08-21 06:44:16 -0700 | [diff] [blame] | 129 | webrtc::EncodedImage encoded_image_; |
| 130 | const webrtc::CodecSpecificInfo codec_specific_info_; |
brandtr | c8c5905 | 2017-08-21 06:44:16 -0700 | [diff] [blame] | 131 | }; |
| 132 | |
brandtr | c409552 | 2017-08-07 08:12:33 -0700 | [diff] [blame] | 133 | VideoProcessor* const video_processor_; |
Danil Chapovalov | ad89528 | 2019-03-11 10:28:05 +0000 | [diff] [blame] | 134 | TaskQueueBase* const task_queue_; |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 137 | class VideoProcessorDecodeCompleteCallback |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 138 | : public webrtc::DecodedImageCallback { |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 139 | public: |
brandtr | c409552 | 2017-08-07 08:12:33 -0700 | [diff] [blame] | 140 | explicit VideoProcessorDecodeCompleteCallback( |
Sergey Silkin | 645e2e0 | 2018-04-06 09:42:13 +0200 | [diff] [blame] | 141 | VideoProcessor* video_processor, |
| 142 | size_t simulcast_svc_idx) |
brandtr | c8c5905 | 2017-08-21 06:44:16 -0700 | [diff] [blame] | 143 | : video_processor_(video_processor), |
Sergey Silkin | 645e2e0 | 2018-04-06 09:42:13 +0200 | [diff] [blame] | 144 | simulcast_svc_idx_(simulcast_svc_idx), |
Danil Chapovalov | ad89528 | 2019-03-11 10:28:05 +0000 | [diff] [blame] | 145 | task_queue_(TaskQueueBase::Current()) { |
Rasmus Brandt | 5f7a891 | 2018-02-28 17:17:15 +0100 | [diff] [blame] | 146 | RTC_DCHECK(video_processor_); |
Rasmus Brandt | 4b381af | 2018-02-07 13:56:16 +0100 | [diff] [blame] | 147 | RTC_DCHECK(task_queue_); |
| 148 | } |
brandtr | c8c5905 | 2017-08-21 06:44:16 -0700 | [diff] [blame] | 149 | |
Sami Kalliomäki | 451b29c | 2018-07-04 14:33:51 +0200 | [diff] [blame] | 150 | int32_t Decoded(webrtc::VideoFrame& image) override; |
brandtr | c8c5905 | 2017-08-21 06:44:16 -0700 | [diff] [blame] | 151 | |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 152 | int32_t Decoded(webrtc::VideoFrame& image, |
| 153 | int64_t decode_time_ms) override { |
brandtr | 6bb8e0e | 2017-02-20 04:35:52 -0800 | [diff] [blame] | 154 | return Decoded(image); |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 155 | } |
brandtr | c8c5905 | 2017-08-21 06:44:16 -0700 | [diff] [blame] | 156 | |
brandtr | 6bb8e0e | 2017-02-20 04:35:52 -0800 | [diff] [blame] | 157 | void Decoded(webrtc::VideoFrame& image, |
Danil Chapovalov | 0040b66 | 2018-06-18 10:48:16 +0200 | [diff] [blame] | 158 | absl::optional<int32_t> decode_time_ms, |
| 159 | absl::optional<uint8_t> qp) override { |
brandtr | bea36fd | 2017-08-07 03:36:54 -0700 | [diff] [blame] | 160 | Decoded(image); |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 161 | } |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 162 | |
| 163 | private: |
brandtr | c409552 | 2017-08-07 08:12:33 -0700 | [diff] [blame] | 164 | VideoProcessor* const video_processor_; |
Sergey Silkin | 645e2e0 | 2018-04-06 09:42:13 +0200 | [diff] [blame] | 165 | const size_t simulcast_svc_idx_; |
Danil Chapovalov | ad89528 | 2019-03-11 10:28:05 +0000 | [diff] [blame] | 166 | TaskQueueBase* const task_queue_; |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 167 | }; |
brandtr | 8bc9385 | 2017-02-15 05:19:51 -0800 | [diff] [blame] | 168 | |
brandtr | bdd555c | 2017-08-21 01:34:04 -0700 | [diff] [blame] | 169 | // Invoked by the callback adapter when a frame has completed encoding. |
Sergey Silkin | 10d9d59 | 2018-02-01 13:25:17 +0100 | [diff] [blame] | 170 | void FrameEncoded(const webrtc::EncodedImage& encoded_image, |
| 171 | const webrtc::CodecSpecificInfo& codec_specific); |
brandtr | 8bc9385 | 2017-02-15 05:19:51 -0800 | [diff] [blame] | 172 | |
brandtr | bdd555c | 2017-08-21 01:34:04 -0700 | [diff] [blame] | 173 | // Invoked by the callback adapter when a frame has completed decoding. |
Sergey Silkin | 645e2e0 | 2018-04-06 09:42:13 +0200 | [diff] [blame] | 174 | void FrameDecoded(const webrtc::VideoFrame& image, size_t simulcast_svc_idx); |
| 175 | |
| 176 | void DecodeFrame(const EncodedImage& encoded_image, size_t simulcast_svc_idx); |
brandtr | 8bc9385 | 2017-02-15 05:19:51 -0800 | [diff] [blame] | 177 | |
Rasmus Brandt | 0f1c0bd | 2018-03-12 10:01:16 +0100 | [diff] [blame] | 178 | // In order to supply the SVC decoders with super frames containing all |
| 179 | // lower layer frames, we merge and store the layer frames in this method. |
Sergey Silkin | 645e2e0 | 2018-04-06 09:42:13 +0200 | [diff] [blame] | 180 | const webrtc::EncodedImage* BuildAndStoreSuperframe( |
Rasmus Brandt | 0f1c0bd | 2018-03-12 10:01:16 +0100 | [diff] [blame] | 181 | const EncodedImage& encoded_image, |
| 182 | const VideoCodecType codec, |
| 183 | size_t frame_number, |
Sergey Silkin | 645e2e0 | 2018-04-06 09:42:13 +0200 | [diff] [blame] | 184 | size_t simulcast_svc_idx, |
| 185 | bool inter_layer_predicted) RTC_RUN_ON(sequence_checker_); |
Sergey Silkin | 10d9d59 | 2018-02-01 13:25:17 +0100 | [diff] [blame] | 186 | |
Rasmus Brandt | d062a3c | 2018-03-08 16:45:54 +0100 | [diff] [blame] | 187 | // Test input/output. |
Kári Tristan Helgason | 169005d | 2018-05-22 13:34:14 +0200 | [diff] [blame] | 188 | VideoCodecTestFixture::Config config_ RTC_GUARDED_BY(sequence_checker_); |
Sergey Silkin | 10d9d59 | 2018-02-01 13:25:17 +0100 | [diff] [blame] | 189 | const size_t num_simulcast_or_spatial_layers_; |
Rasmus Brandt | 7d72d0f | 2019-03-26 16:56:14 +0100 | [diff] [blame] | 190 | VideoCodecTestStatsImpl* const stats_; |
Sergey Silkin | 10d9d59 | 2018-02-01 13:25:17 +0100 | [diff] [blame] | 191 | |
Rasmus Brandt | d062a3c | 2018-03-08 16:45:54 +0100 | [diff] [blame] | 192 | // Codecs. |
brandtr | 8bc9385 | 2017-02-15 05:19:51 -0800 | [diff] [blame] | 193 | webrtc::VideoEncoder* const encoder_; |
Sergey Silkin | 10d9d59 | 2018-02-01 13:25:17 +0100 | [diff] [blame] | 194 | VideoDecoderList* const decoders_; |
brandtr | aebc61e | 2017-02-28 07:13:47 -0800 | [diff] [blame] | 195 | const std::unique_ptr<VideoBitrateAllocator> bitrate_allocator_; |
Erik Språng | 566124a | 2018-04-23 12:32:22 +0200 | [diff] [blame] | 196 | VideoBitrateAllocation bitrate_allocation_ RTC_GUARDED_BY(sequence_checker_); |
Sergey Silkin | 44cec0b | 2019-07-11 14:20:38 +0200 | [diff] [blame] | 197 | double framerate_fps_ RTC_GUARDED_BY(sequence_checker_); |
brandtr | aebc61e | 2017-02-28 07:13:47 -0800 | [diff] [blame] | 198 | |
| 199 | // Adapters for the codec callbacks. |
brandtr | bdd555c | 2017-08-21 01:34:04 -0700 | [diff] [blame] | 200 | VideoProcessorEncodeCompleteCallback encode_callback_; |
Sergey Silkin | 645e2e0 | 2018-04-06 09:42:13 +0200 | [diff] [blame] | 201 | // Assign separate callback object to each decoder. This allows us to identify |
| 202 | // decoded layer in frame decode callback. |
| 203 | // simulcast_svc_idx -> decode callback. |
| 204 | std::vector<std::unique_ptr<VideoProcessorDecodeCompleteCallback>> |
| 205 | decode_callback_; |
brandtr | aebc61e | 2017-02-28 07:13:47 -0800 | [diff] [blame] | 206 | |
Rasmus Brandt | d062a3c | 2018-03-08 16:45:54 +0100 | [diff] [blame] | 207 | // Each call to ProcessFrame() will read one frame from |input_frame_reader_|. |
| 208 | FrameReader* const input_frame_reader_; |
| 209 | |
| 210 | // Input frames are used as reference for frame quality evaluations. |
Sergey Silkin | 64eaa99 | 2017-11-17 14:47:32 +0100 | [diff] [blame] | 211 | // Async codecs might queue frames. To handle that we keep input frame |
| 212 | // and release it after corresponding coded frame is decoded and quality |
| 213 | // measurement is done. |
Rasmus Brandt | d062a3c | 2018-03-08 16:45:54 +0100 | [diff] [blame] | 214 | // frame_number -> frame. |
| 215 | std::map<size_t, VideoFrame> input_frames_ RTC_GUARDED_BY(sequence_checker_); |
Sergey Silkin | 10d9d59 | 2018-02-01 13:25:17 +0100 | [diff] [blame] | 216 | |
| 217 | // Encoder delivers coded frame layer-by-layer. We store coded frames and |
| 218 | // then, after all layers are encoded, decode them. Such separation of |
| 219 | // frame processing on superframe level simplifies encoding/decoding time |
| 220 | // measurement. |
Rasmus Brandt | 0f1c0bd | 2018-03-12 10:01:16 +0100 | [diff] [blame] | 221 | // simulcast_svc_idx -> merged SVC encoded frame. |
| 222 | std::vector<EncodedImage> merged_encoded_frames_ |
Sergey Silkin | 10d9d59 | 2018-02-01 13:25:17 +0100 | [diff] [blame] | 223 | RTC_GUARDED_BY(sequence_checker_); |
| 224 | |
Rasmus Brandt | d062a3c | 2018-03-08 16:45:54 +0100 | [diff] [blame] | 225 | // These (optional) file writers are used to persistently store the encoded |
| 226 | // and decoded bitstreams. Each frame writer is enabled by being non-null. |
Rasmus Brandt | 001c782 | 2019-03-22 13:41:48 +0100 | [diff] [blame] | 227 | IvfFileWriterMap* const encoded_frame_writers_; |
Rasmus Brandt | d062a3c | 2018-03-08 16:45:54 +0100 | [diff] [blame] | 228 | FrameWriterList* const decoded_frame_writers_; |
brandtr | 8bc9385 | 2017-02-15 05:19:51 -0800 | [diff] [blame] | 229 | |
Rasmus Brandt | 0f1c0bd | 2018-03-12 10:01:16 +0100 | [diff] [blame] | 230 | // Metadata for inputed/encoded/decoded frames. Used for frame identification, |
| 231 | // frame drop detection, etc. We assume that encoded/decoded frames are |
| 232 | // ordered within each simulcast/spatial layer, but we do not make any |
| 233 | // assumptions of frame ordering between layers. |
Rasmus Brandt | d062a3c | 2018-03-08 16:45:54 +0100 | [diff] [blame] | 234 | size_t last_inputed_frame_num_ RTC_GUARDED_BY(sequence_checker_); |
| 235 | size_t last_inputed_timestamp_ RTC_GUARDED_BY(sequence_checker_); |
Rasmus Brandt | 0f1c0bd | 2018-03-12 10:01:16 +0100 | [diff] [blame] | 236 | // simulcast_svc_idx -> encode status. |
| 237 | std::vector<bool> first_encoded_frame_ RTC_GUARDED_BY(sequence_checker_); |
| 238 | // simulcast_svc_idx -> frame_number. |
| 239 | std::vector<size_t> last_encoded_frame_num_ RTC_GUARDED_BY(sequence_checker_); |
| 240 | // simulcast_svc_idx -> decode status. |
| 241 | std::vector<bool> first_decoded_frame_ RTC_GUARDED_BY(sequence_checker_); |
| 242 | // simulcast_svc_idx -> frame_number. |
| 243 | std::vector<size_t> last_decoded_frame_num_ RTC_GUARDED_BY(sequence_checker_); |
Sergey Silkin | 5613879 | 2018-05-02 10:50:55 +0200 | [diff] [blame] | 244 | // simulcast_svc_idx -> buffer. |
| 245 | std::vector<rtc::Buffer> decoded_frame_buffer_ |
| 246 | RTC_GUARDED_BY(sequence_checker_); |
Rasmus Brandt | d062a3c | 2018-03-08 16:45:54 +0100 | [diff] [blame] | 247 | |
Sergey Silkin | c89eed9 | 2018-04-01 23:57:51 +0200 | [diff] [blame] | 248 | // Time spent in frame encode callback. It is accumulated for layers and |
| 249 | // reset when frame encode starts. When next layer is encoded post-encode time |
| 250 | // is substracted from measured encode time. Thus we get pure encode time. |
| 251 | int64_t post_encode_time_ns_ RTC_GUARDED_BY(sequence_checker_); |
| 252 | |
Rasmus Brandt | d062a3c | 2018-03-08 16:45:54 +0100 | [diff] [blame] | 253 | // This class must be operated on a TaskQueue. |
Sebastian Jansson | b55015e | 2019-04-09 13:44:04 +0200 | [diff] [blame] | 254 | SequenceChecker sequence_checker_; |
brandtr | bdd555c | 2017-08-21 01:34:04 -0700 | [diff] [blame] | 255 | |
| 256 | RTC_DISALLOW_COPY_AND_ASSIGN(VideoProcessor); |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 257 | }; |
| 258 | |
| 259 | } // namespace test |
| 260 | } // namespace webrtc |
| 261 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 262 | #endif // MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ |