| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ | 11 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ |
| 12 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ | 12 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ |
| 13 | 13 |
| 14 #include <memory> | 14 #include <memory> |
| 15 #include <string> | 15 #include <string> |
| 16 #include <vector> | 16 #include <vector> |
| 17 | 17 |
| 18 #include "webrtc/api/video/video_frame.h" | 18 #include "webrtc/api/video/video_frame.h" |
| 19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
| 20 #include "webrtc/modules/video_coding/codecs/test/packet_manipulator.h" | 20 #include "webrtc/modules/video_coding/codecs/test/packet_manipulator.h" |
| 21 #include "webrtc/modules/video_coding/codecs/test/stats.h" | 21 #include "webrtc/modules/video_coding/codecs/test/stats.h" |
| 22 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 22 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
| 23 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" | 23 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" |
| 24 #include "webrtc/modules/video_coding/utility/vp8_header_parser.h" | 24 #include "webrtc/modules/video_coding/utility/vp8_header_parser.h" |
| 25 #include "webrtc/modules/video_coding/utility/vp9_uncompressed_header_parser.h" | 25 #include "webrtc/modules/video_coding/utility/vp9_uncompressed_header_parser.h" |
| 26 #include "webrtc/rtc_base/buffer.h" | 26 #include "webrtc/rtc_base/buffer.h" |
| 27 #include "webrtc/rtc_base/checks.h" | 27 #include "webrtc/rtc_base/checks.h" |
| 28 #include "webrtc/rtc_base/constructormagic.h" | 28 #include "webrtc/rtc_base/constructormagic.h" |
| 29 #include "webrtc/rtc_base/sequenced_task_checker.h" |
| 30 #include "webrtc/rtc_base/task_queue.h" |
| 29 #include "webrtc/test/testsupport/frame_reader.h" | 31 #include "webrtc/test/testsupport/frame_reader.h" |
| 30 #include "webrtc/test/testsupport/frame_writer.h" | 32 #include "webrtc/test/testsupport/frame_writer.h" |
| 31 | 33 |
| 32 namespace webrtc { | 34 namespace webrtc { |
| 33 | 35 |
| 34 class VideoBitrateAllocator; | 36 class VideoBitrateAllocator; |
| 35 | 37 |
| 36 namespace test { | 38 namespace test { |
| 37 | 39 |
| 38 // Defines which frame types shall be excluded from packet loss and when. | 40 // Defines which frame types shall be excluded from packet loss and when. |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 int decoded_width = 0; | 191 int decoded_width = 0; |
| 190 int decoded_height = 0; | 192 int decoded_height = 0; |
| 191 size_t manipulated_length = 0; | 193 size_t manipulated_length = 0; |
| 192 }; | 194 }; |
| 193 | 195 |
| 194 class VideoProcessorEncodeCompleteCallback | 196 class VideoProcessorEncodeCompleteCallback |
| 195 : public webrtc::EncodedImageCallback { | 197 : public webrtc::EncodedImageCallback { |
| 196 public: | 198 public: |
| 197 explicit VideoProcessorEncodeCompleteCallback( | 199 explicit VideoProcessorEncodeCompleteCallback( |
| 198 VideoProcessor* video_processor) | 200 VideoProcessor* video_processor) |
| 199 : video_processor_(video_processor) {} | 201 : video_processor_(video_processor), |
| 202 task_queue_(rtc::TaskQueue::Current()) {} |
| 203 |
| 200 Result OnEncodedImage( | 204 Result OnEncodedImage( |
| 201 const webrtc::EncodedImage& encoded_image, | 205 const webrtc::EncodedImage& encoded_image, |
| 202 const webrtc::CodecSpecificInfo* codec_specific_info, | 206 const webrtc::CodecSpecificInfo* codec_specific_info, |
| 203 const webrtc::RTPFragmentationHeader* fragmentation) override { | 207 const webrtc::RTPFragmentationHeader* fragmentation) override { |
| 204 // Forward to parent class. | |
| 205 RTC_CHECK(codec_specific_info); | 208 RTC_CHECK(codec_specific_info); |
| 209 |
| 210 if (task_queue_ && !task_queue_->IsCurrent()) { |
| 211 task_queue_->PostTask(std::unique_ptr<rtc::QueuedTask>( |
| 212 new EncodeCallbackTask(video_processor_, encoded_image, |
| 213 codec_specific_info, fragmentation))); |
| 214 return Result(Result::OK, 0); |
| 215 } |
| 216 |
| 206 video_processor_->FrameEncoded(codec_specific_info->codecType, | 217 video_processor_->FrameEncoded(codec_specific_info->codecType, |
| 207 encoded_image, fragmentation); | 218 encoded_image, fragmentation); |
| 208 return Result(Result::OK, 0); | 219 return Result(Result::OK, 0); |
| 209 } | 220 } |
| 210 | 221 |
| 211 private: | 222 private: |
| 223 class EncodeCallbackTask : public rtc::QueuedTask { |
| 224 public: |
| 225 EncodeCallbackTask(VideoProcessor* video_processor, |
| 226 const webrtc::EncodedImage& encoded_image, |
| 227 const webrtc::CodecSpecificInfo* codec_specific_info, |
| 228 const webrtc::RTPFragmentationHeader* fragmentation) |
| 229 : video_processor_(video_processor), |
| 230 buffer_(encoded_image._buffer, encoded_image._length), |
| 231 encoded_image_(encoded_image), |
| 232 codec_specific_info_(*codec_specific_info) { |
| 233 encoded_image_._buffer = buffer_.data(); |
| 234 RTC_CHECK(fragmentation); |
| 235 fragmentation_.CopyFrom(*fragmentation); |
| 236 } |
| 237 |
| 238 bool Run() override { |
| 239 video_processor_->FrameEncoded(codec_specific_info_.codecType, |
| 240 encoded_image_, &fragmentation_); |
| 241 return true; |
| 242 } |
| 243 |
| 244 private: |
| 245 VideoProcessor* const video_processor_; |
| 246 rtc::Buffer buffer_; |
| 247 webrtc::EncodedImage encoded_image_; |
| 248 const webrtc::CodecSpecificInfo codec_specific_info_; |
| 249 webrtc::RTPFragmentationHeader fragmentation_; |
| 250 }; |
| 251 |
| 212 VideoProcessor* const video_processor_; | 252 VideoProcessor* const video_processor_; |
| 253 rtc::TaskQueue* const task_queue_; |
| 213 }; | 254 }; |
| 214 | 255 |
| 215 class VideoProcessorDecodeCompleteCallback | 256 class VideoProcessorDecodeCompleteCallback |
| 216 : public webrtc::DecodedImageCallback { | 257 : public webrtc::DecodedImageCallback { |
| 217 public: | 258 public: |
| 218 explicit VideoProcessorDecodeCompleteCallback( | 259 explicit VideoProcessorDecodeCompleteCallback( |
| 219 VideoProcessor* video_processor) | 260 VideoProcessor* video_processor) |
| 220 : video_processor_(video_processor) {} | 261 : video_processor_(video_processor), |
| 262 task_queue_(rtc::TaskQueue::Current()) {} |
| 263 |
| 221 int32_t Decoded(webrtc::VideoFrame& image) override { | 264 int32_t Decoded(webrtc::VideoFrame& image) override { |
| 222 // Forward to parent class. | 265 if (task_queue_ && !task_queue_->IsCurrent()) { |
| 266 task_queue_->PostTask( |
| 267 [this, image]() { video_processor_->FrameDecoded(image); }); |
| 268 return 0; |
| 269 } |
| 270 |
| 223 video_processor_->FrameDecoded(image); | 271 video_processor_->FrameDecoded(image); |
| 224 return 0; | 272 return 0; |
| 225 } | 273 } |
| 274 |
| 226 int32_t Decoded(webrtc::VideoFrame& image, | 275 int32_t Decoded(webrtc::VideoFrame& image, |
| 227 int64_t decode_time_ms) override { | 276 int64_t decode_time_ms) override { |
| 228 return Decoded(image); | 277 return Decoded(image); |
| 229 } | 278 } |
| 279 |
| 230 void Decoded(webrtc::VideoFrame& image, | 280 void Decoded(webrtc::VideoFrame& image, |
| 231 rtc::Optional<int32_t> decode_time_ms, | 281 rtc::Optional<int32_t> decode_time_ms, |
| 232 rtc::Optional<uint8_t> qp) override { | 282 rtc::Optional<uint8_t> qp) override { |
| 233 Decoded(image); | 283 Decoded(image); |
| 234 } | 284 } |
| 235 | 285 |
| 236 private: | 286 private: |
| 237 VideoProcessor* const video_processor_; | 287 VideoProcessor* const video_processor_; |
| 288 rtc::TaskQueue* const task_queue_; |
| 238 }; | 289 }; |
| 239 | 290 |
| 240 // Invoked by the callback adapter when a frame has completed encoding. | 291 // Invoked by the callback adapter when a frame has completed encoding. |
| 241 void FrameEncoded(webrtc::VideoCodecType codec, | 292 void FrameEncoded(webrtc::VideoCodecType codec, |
| 242 const webrtc::EncodedImage& encodedImage, | 293 const webrtc::EncodedImage& encodedImage, |
| 243 const webrtc::RTPFragmentationHeader* fragmentation); | 294 const webrtc::RTPFragmentationHeader* fragmentation); |
| 244 | 295 |
| 245 // Invoked by the callback adapter when a frame has completed decoding. | 296 // Invoked by the callback adapter when a frame has completed decoding. |
| 246 void FrameDecoded(const webrtc::VideoFrame& image); | 297 void FrameDecoded(const webrtc::VideoFrame& image); |
| 247 | 298 |
| 248 // Use the frame number as the basis for timestamp to identify frames. Let the | 299 // Use the frame number as the basis for timestamp to identify frames. Let the |
| 249 // first timestamp be non-zero, to not make the IvfFileWriter believe that we | 300 // first timestamp be non-zero, to not make the IvfFileWriter believe that we |
| 250 // want to use capture timestamps in the IVF files. | 301 // want to use capture timestamps in the IVF files. |
| 251 uint32_t FrameNumberToTimestamp(int frame_number) const; | 302 uint32_t FrameNumberToTimestamp(int frame_number) const; |
| 252 int TimestampToFrameNumber(uint32_t timestamp) const; | 303 int TimestampToFrameNumber(uint32_t timestamp) const; |
| 253 | 304 |
| 254 TestConfig config_; | 305 bool initialized_ GUARDED_BY(sequence_checker_); |
| 306 |
| 307 TestConfig config_ GUARDED_BY(sequence_checker_); |
| 255 | 308 |
| 256 webrtc::VideoEncoder* const encoder_; | 309 webrtc::VideoEncoder* const encoder_; |
| 257 webrtc::VideoDecoder* const decoder_; | 310 webrtc::VideoDecoder* const decoder_; |
| 258 const std::unique_ptr<VideoBitrateAllocator> bitrate_allocator_; | 311 const std::unique_ptr<VideoBitrateAllocator> bitrate_allocator_; |
| 259 | 312 |
| 260 // Adapters for the codec callbacks. | 313 // Adapters for the codec callbacks. |
| 261 VideoProcessorEncodeCompleteCallback encode_callback_; | 314 VideoProcessorEncodeCompleteCallback encode_callback_; |
| 262 VideoProcessorDecodeCompleteCallback decode_callback_; | 315 VideoProcessorDecodeCompleteCallback decode_callback_; |
| 263 | 316 |
| 264 // Fake network. | 317 // Fake network. |
| 265 PacketManipulator* const packet_manipulator_; | 318 PacketManipulator* const packet_manipulator_; |
| 266 | 319 |
| 267 // These (mandatory) file manipulators are used for, e.g., objective PSNR and | 320 // These (mandatory) file manipulators are used for, e.g., objective PSNR and |
| 268 // SSIM calculations at the end of a test run. | 321 // SSIM calculations at the end of a test run. |
| 269 FrameReader* const analysis_frame_reader_; | 322 FrameReader* const analysis_frame_reader_; |
| 270 FrameWriter* const analysis_frame_writer_; | 323 FrameWriter* const analysis_frame_writer_; |
| 271 | 324 |
| 272 // These (optional) file writers are used to persistently store the encoded | 325 // These (optional) file writers are used to persistently store the encoded |
| 273 // and decoded bitstreams. The purpose is to give the experimenter an option | 326 // and decoded bitstreams. The purpose is to give the experimenter an option |
| 274 // to subjectively evaluate the quality of the processing. Each frame writer | 327 // to subjectively evaluate the quality of the processing. Each frame writer |
| 275 // is enabled by being non-null. | 328 // is enabled by being non-null. |
| 276 IvfFileWriter* const encoded_frame_writer_; | 329 IvfFileWriter* const encoded_frame_writer_; |
| 277 FrameWriter* const decoded_frame_writer_; | 330 FrameWriter* const decoded_frame_writer_; |
| 278 | 331 |
| 279 bool initialized_; | |
| 280 | |
| 281 // Frame metadata for all frames that have been added through a call to | 332 // Frame metadata for all frames that have been added through a call to |
| 282 // ProcessFrames(). We need to store this metadata over the course of the | 333 // ProcessFrames(). We need to store this metadata over the course of the |
| 283 // test run, to support pipelining HW codecs. | 334 // test run, to support pipelining HW codecs. |
| 284 std::vector<FrameInfo> frame_infos_; | 335 std::vector<FrameInfo> frame_infos_ GUARDED_BY(sequence_checker_); |
| 285 int last_encoded_frame_num_; | 336 int last_encoded_frame_num_ GUARDED_BY(sequence_checker_); |
| 286 int last_decoded_frame_num_; | 337 int last_decoded_frame_num_ GUARDED_BY(sequence_checker_); |
| 287 | 338 |
| 288 // Keep track of if we have excluded the first key frame from packet loss. | 339 // Keep track of if we have excluded the first key frame from packet loss. |
| 289 bool first_key_frame_has_been_excluded_; | 340 bool first_key_frame_has_been_excluded_ GUARDED_BY(sequence_checker_); |
| 290 | 341 |
| 291 // Keep track of the last successfully decoded frame, since we write that | 342 // Keep track of the last successfully decoded frame, since we write that |
| 292 // frame to disk when decoding fails. | 343 // frame to disk when decoding fails. |
| 293 rtc::Buffer last_decoded_frame_buffer_; | 344 rtc::Buffer last_decoded_frame_buffer_ GUARDED_BY(sequence_checker_); |
| 294 | 345 |
| 295 // Statistics. | 346 // Statistics. |
| 296 Stats* stats_; | 347 Stats* stats_; |
| 297 int num_dropped_frames_; | 348 int num_dropped_frames_ GUARDED_BY(sequence_checker_); |
| 298 int num_spatial_resizes_; | 349 int num_spatial_resizes_ GUARDED_BY(sequence_checker_); |
| 350 |
| 351 rtc::SequencedTaskChecker sequence_checker_; |
| 299 | 352 |
| 300 RTC_DISALLOW_COPY_AND_ASSIGN(VideoProcessor); | 353 RTC_DISALLOW_COPY_AND_ASSIGN(VideoProcessor); |
| 301 }; | 354 }; |
| 302 | 355 |
| 303 } // namespace test | 356 } // namespace test |
| 304 } // namespace webrtc | 357 } // namespace webrtc |
| 305 | 358 |
| 306 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ | 359 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ |
| OLD | NEW |