| 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 #include "webrtc/modules/video_coding/codecs/test/videoprocessor.h" | 11 #include "webrtc/modules/video_coding/codecs/test/videoprocessor.h" |
| 12 | 12 |
| 13 #include <string.h> | 13 #include <string.h> |
| 14 | 14 |
| 15 #include <limits> | 15 #include <limits> |
| 16 #include <memory> | 16 #include <memory> |
| 17 #include <utility> | 17 #include <utility> |
| 18 #include <vector> | 18 #include <vector> |
| 19 | 19 |
| 20 #include "webrtc/api/video/i420_buffer.h" | 20 #include "webrtc/api/video/i420_buffer.h" |
| 21 #include "webrtc/common_types.h" | 21 #include "webrtc/common_types.h" |
| 22 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_rate_allocator.h" | 22 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_rate_allocator.h" |
| 23 #include "webrtc/modules/video_coding/include/video_codec_initializer.h" | 23 #include "webrtc/modules/video_coding/include/video_codec_initializer.h" |
| 24 #include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h" | 24 #include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h" |
| 25 #include "webrtc/rtc_base/checks.h" | 25 #include "webrtc/rtc_base/checks.h" |
| 26 #include "webrtc/rtc_base/logging.h" | 26 #include "webrtc/rtc_base/logging.h" |
| 27 #include "webrtc/rtc_base/timeutils.h" | 27 #include "webrtc/rtc_base/timeutils.h" |
| 28 #include "webrtc/system_wrappers/include/cpu_info.h" | 28 #include "webrtc/system_wrappers/include/cpu_info.h" |
| 29 #include "webrtc/test/gtest.h" |
| 29 | 30 |
| 30 namespace webrtc { | 31 namespace webrtc { |
| 31 namespace test { | 32 namespace test { |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 const int kRtpClockRateHz = 90000; | 36 const int kRtpClockRateHz = 90000; |
| 36 | 37 |
| 37 std::unique_ptr<VideoBitrateAllocator> CreateBitrateAllocator( | 38 std::unique_ptr<VideoBitrateAllocator> CreateBitrateAllocator( |
| 38 TestConfig* config) { | 39 TestConfig* config) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 codec_settings.VP9().numberOfSpatialLayers); | 85 codec_settings.VP9().numberOfSpatialLayers); |
| 85 printf(" Flexible mode : %d\n", codec_settings.VP9().flexibleMode); | 86 printf(" Flexible mode : %d\n", codec_settings.VP9().flexibleMode); |
| 86 } else if (codec_settings.codecType == kVideoCodecH264) { | 87 } else if (codec_settings.codecType == kVideoCodecH264) { |
| 87 printf(" Frame dropping : %d\n", codec_settings.H264().frameDroppingOn); | 88 printf(" Frame dropping : %d\n", codec_settings.H264().frameDroppingOn); |
| 88 printf(" Key frame interval: %d\n", | 89 printf(" Key frame interval: %d\n", |
| 89 codec_settings.H264().keyFrameInterval); | 90 codec_settings.H264().keyFrameInterval); |
| 90 printf(" Profile : %d\n", codec_settings.H264().profile); | 91 printf(" Profile : %d\n", codec_settings.H264().profile); |
| 91 } | 92 } |
| 92 } | 93 } |
| 93 | 94 |
| 95 void VerifyQpParser(const EncodedImage& encoded_frame, |
| 96 const TestConfig& config) { |
| 97 if (config.hw_codec) |
| 98 return; |
| 99 |
| 100 int qp; |
| 101 if (config.codec_settings.codecType == kVideoCodecVP8) { |
| 102 ASSERT_TRUE(vp8::GetQp(encoded_frame._buffer, encoded_frame._length, &qp)); |
| 103 } else if (config.codec_settings.codecType == kVideoCodecVP9) { |
| 104 ASSERT_TRUE(vp9::GetQp(encoded_frame._buffer, encoded_frame._length, &qp)); |
| 105 } else { |
| 106 return; |
| 107 } |
| 108 EXPECT_EQ(encoded_frame.qp_, qp) << "Encoder QP != parsed bitstream QP."; |
| 109 } |
| 110 |
| 94 int GetElapsedTimeMicroseconds(int64_t start_ns, int64_t stop_ns) { | 111 int GetElapsedTimeMicroseconds(int64_t start_ns, int64_t stop_ns) { |
| 95 int64_t diff_us = (stop_ns - start_ns) / rtc::kNumNanosecsPerMicrosec; | 112 int64_t diff_us = (stop_ns - start_ns) / rtc::kNumNanosecsPerMicrosec; |
| 96 RTC_DCHECK_GE(diff_us, std::numeric_limits<int>::min()); | 113 RTC_DCHECK_GE(diff_us, std::numeric_limits<int>::min()); |
| 97 RTC_DCHECK_LE(diff_us, std::numeric_limits<int>::max()); | 114 RTC_DCHECK_LE(diff_us, std::numeric_limits<int>::max()); |
| 98 return static_cast<int>(diff_us); | 115 return static_cast<int>(diff_us); |
| 99 } | 116 } |
| 100 | 117 |
| 101 } // namespace | 118 } // namespace |
| 102 | 119 |
| 103 const char* ExcludeFrameTypesToStr(ExcludeFrameTypes e) { | 120 const char* ExcludeFrameTypesToStr(ExcludeFrameTypes e) { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 config_.codec_settings.maxFramerate = framerate_fps; | 273 config_.codec_settings.maxFramerate = framerate_fps; |
| 257 int set_rates_result = encoder_->SetRateAllocation( | 274 int set_rates_result = encoder_->SetRateAllocation( |
| 258 bitrate_allocator_->GetAllocation(bitrate_kbps * 1000, framerate_fps), | 275 bitrate_allocator_->GetAllocation(bitrate_kbps * 1000, framerate_fps), |
| 259 framerate_fps); | 276 framerate_fps); |
| 260 RTC_DCHECK_GE(set_rates_result, 0) | 277 RTC_DCHECK_GE(set_rates_result, 0) |
| 261 << "Failed to update encoder with new rate " << bitrate_kbps << "."; | 278 << "Failed to update encoder with new rate " << bitrate_kbps << "."; |
| 262 num_dropped_frames_ = 0; | 279 num_dropped_frames_ = 0; |
| 263 num_spatial_resizes_ = 0; | 280 num_spatial_resizes_ = 0; |
| 264 } | 281 } |
| 265 | 282 |
| 266 int VideoProcessor::GetQpFromEncoder(int frame_number) const { | |
| 267 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_); | |
| 268 RTC_CHECK_LT(frame_number, frame_infos_.size()); | |
| 269 return frame_infos_[frame_number].qp_encoder; | |
| 270 } | |
| 271 | |
| 272 int VideoProcessor::GetQpFromBitstream(int frame_number) const { | |
| 273 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_); | |
| 274 RTC_CHECK_LT(frame_number, frame_infos_.size()); | |
| 275 return frame_infos_[frame_number].qp_bitstream; | |
| 276 } | |
| 277 | |
| 278 int VideoProcessor::NumberDroppedFrames() { | 283 int VideoProcessor::NumberDroppedFrames() { |
| 279 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_); | 284 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_); |
| 280 return num_dropped_frames_; | 285 return num_dropped_frames_; |
| 281 } | 286 } |
| 282 | 287 |
| 283 int VideoProcessor::NumberSpatialResizes() { | 288 int VideoProcessor::NumberSpatialResizes() { |
| 284 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_); | 289 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_); |
| 285 return num_spatial_resizes_; | 290 return num_spatial_resizes_; |
| 286 } | 291 } |
| 287 | 292 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 } | 330 } |
| 326 | 331 |
| 327 last_frame_missing = | 332 last_frame_missing = |
| 328 (frame_infos_[last_encoded_frame_num_].manipulated_length == 0); | 333 (frame_infos_[last_encoded_frame_num_].manipulated_length == 0); |
| 329 } | 334 } |
| 330 // Ensure strict monotonicity. | 335 // Ensure strict monotonicity. |
| 331 RTC_CHECK_GT(frame_number, last_encoded_frame_num_); | 336 RTC_CHECK_GT(frame_number, last_encoded_frame_num_); |
| 332 last_encoded_frame_num_ = frame_number; | 337 last_encoded_frame_num_ = frame_number; |
| 333 | 338 |
| 334 // Frame is not dropped, so update frame information and statistics. | 339 // Frame is not dropped, so update frame information and statistics. |
| 340 VerifyQpParser(encoded_image, config_); |
| 335 RTC_CHECK_LT(frame_number, frame_infos_.size()); | 341 RTC_CHECK_LT(frame_number, frame_infos_.size()); |
| 336 FrameInfo* frame_info = &frame_infos_[frame_number]; | 342 FrameInfo* frame_info = &frame_infos_[frame_number]; |
| 337 frame_info->qp_encoder = encoded_image.qp_; | |
| 338 if (codec == kVideoCodecVP8) { | |
| 339 vp8::GetQp(encoded_image._buffer, encoded_image._length, | |
| 340 &frame_info->qp_bitstream); | |
| 341 } else if (codec == kVideoCodecVP9) { | |
| 342 vp9::GetQp(encoded_image._buffer, encoded_image._length, | |
| 343 &frame_info->qp_bitstream); | |
| 344 } | |
| 345 FrameStatistic* frame_stat = &stats_->stats_[frame_number]; | 343 FrameStatistic* frame_stat = &stats_->stats_[frame_number]; |
| 346 frame_stat->encode_time_in_us = | 344 frame_stat->encode_time_in_us = |
| 347 GetElapsedTimeMicroseconds(frame_info->encode_start_ns, encode_stop_ns); | 345 GetElapsedTimeMicroseconds(frame_info->encode_start_ns, encode_stop_ns); |
| 348 frame_stat->encoding_successful = true; | 346 frame_stat->encoding_successful = true; |
| 349 frame_stat->encoded_frame_length_in_bytes = encoded_image._length; | 347 frame_stat->encoded_frame_length_in_bytes = encoded_image._length; |
| 350 frame_stat->frame_number = frame_number; | 348 frame_stat->frame_number = frame_number; |
| 351 frame_stat->frame_type = encoded_image._frameType; | 349 frame_stat->frame_type = encoded_image._frameType; |
| 352 frame_stat->qp = encoded_image.qp_; | 350 frame_stat->qp = encoded_image.qp_; |
| 353 frame_stat->bit_rate_in_kbps = static_cast<int>( | 351 frame_stat->bit_rate_in_kbps = static_cast<int>( |
| 354 encoded_image._length * config_.codec_settings.maxFramerate * 8 / 1000); | 352 encoded_image._length * config_.codec_settings.maxFramerate * 8 / 1000); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 | 496 |
| 499 RTC_DCHECK_GT(timestamp, 0); | 497 RTC_DCHECK_GT(timestamp, 0); |
| 500 const int ticks_per_frame = | 498 const int ticks_per_frame = |
| 501 kRtpClockRateHz / config_.codec_settings.maxFramerate; | 499 kRtpClockRateHz / config_.codec_settings.maxFramerate; |
| 502 RTC_DCHECK_EQ(timestamp % ticks_per_frame, 0); | 500 RTC_DCHECK_EQ(timestamp % ticks_per_frame, 0); |
| 503 return (timestamp / ticks_per_frame) - 1; | 501 return (timestamp / ticks_per_frame) - 1; |
| 504 } | 502 } |
| 505 | 503 |
| 506 } // namespace test | 504 } // namespace test |
| 507 } // namespace webrtc | 505 } // namespace webrtc |
| OLD | NEW |