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 "modules/video_coding/codecs/test/videoprocessor.h" | 11 #include "modules/video_coding/codecs/test/videoprocessor.h" |
12 | 12 |
13 #include <string.h> | 13 #include <string.h> |
14 | 14 |
15 #include <algorithm> | |
15 #include <limits> | 16 #include <limits> |
16 #include <memory> | 17 #include <memory> |
17 #include <utility> | 18 #include <utility> |
18 #include <vector> | 19 #include <vector> |
19 | 20 |
20 #include "api/video/i420_buffer.h" | 21 #include "api/video/i420_buffer.h" |
21 #include "common_types.h" // NOLINT(build/include) | 22 #include "common_types.h" // NOLINT(build/include) |
23 #include "common_video/h264/h264_common.h" | |
22 #include "modules/video_coding/codecs/vp8/simulcast_rate_allocator.h" | 24 #include "modules/video_coding/codecs/vp8/simulcast_rate_allocator.h" |
23 #include "modules/video_coding/include/video_codec_initializer.h" | 25 #include "modules/video_coding/include/video_codec_initializer.h" |
24 #include "modules/video_coding/utility/default_video_bitrate_allocator.h" | 26 #include "modules/video_coding/utility/default_video_bitrate_allocator.h" |
25 #include "rtc_base/checks.h" | 27 #include "rtc_base/checks.h" |
26 #include "rtc_base/logging.h" | 28 #include "rtc_base/logging.h" |
27 #include "rtc_base/timeutils.h" | 29 #include "rtc_base/timeutils.h" |
28 #include "system_wrappers/include/cpu_info.h" | 30 #include "system_wrappers/include/cpu_info.h" |
29 #include "test/gtest.h" | 31 #include "test/gtest.h" |
30 | 32 |
31 namespace webrtc { | 33 namespace webrtc { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 if (config.codec_settings.codecType == kVideoCodecVP8) { | 103 if (config.codec_settings.codecType == kVideoCodecVP8) { |
102 ASSERT_TRUE(vp8::GetQp(encoded_frame._buffer, encoded_frame._length, &qp)); | 104 ASSERT_TRUE(vp8::GetQp(encoded_frame._buffer, encoded_frame._length, &qp)); |
103 } else if (config.codec_settings.codecType == kVideoCodecVP9) { | 105 } else if (config.codec_settings.codecType == kVideoCodecVP9) { |
104 ASSERT_TRUE(vp9::GetQp(encoded_frame._buffer, encoded_frame._length, &qp)); | 106 ASSERT_TRUE(vp9::GetQp(encoded_frame._buffer, encoded_frame._length, &qp)); |
105 } else { | 107 } else { |
106 return; | 108 return; |
107 } | 109 } |
108 EXPECT_EQ(encoded_frame.qp_, qp) << "Encoder QP != parsed bitstream QP."; | 110 EXPECT_EQ(encoded_frame.qp_, qp) << "Encoder QP != parsed bitstream QP."; |
109 } | 111 } |
110 | 112 |
113 rtc::Optional<size_t> GetMaxNaluLength(const EncodedImage& encoded_frame, | |
114 const TestConfig& config) { | |
115 if (config.codec_settings.codecType != kVideoCodecH264) | |
116 return rtc::Optional<size_t>(); | |
117 | |
118 std::vector<webrtc::H264::NaluIndex> nalu_indices = | |
119 webrtc::H264::FindNaluIndices(encoded_frame._buffer, | |
120 encoded_frame._length); | |
hbos
2017/09/27 15:56:42
Should we return empty optional if nalu_indices is
ssilkin
2017/09/28 09:53:09
Added RTC_CHECK for empty nalu_indices. It is expe
hbos
2017/09/28 12:08:34
Is it safe to assume the encoded image is "correct
hbos
2017/09/28 12:10:45
Or is this only on frames we've encoded?
brandtr
2017/09/28 13:39:26
This is just test code, so I think it's OK to be l
| |
121 | |
122 size_t max_length = 0; | |
123 for (const webrtc::H264::NaluIndex& index : nalu_indices) | |
124 max_length = std::max(max_length, index.payload_size); | |
125 | |
126 return rtc::Optional<size_t>(max_length); | |
127 } | |
128 | |
111 int GetElapsedTimeMicroseconds(int64_t start_ns, int64_t stop_ns) { | 129 int GetElapsedTimeMicroseconds(int64_t start_ns, int64_t stop_ns) { |
112 int64_t diff_us = (stop_ns - start_ns) / rtc::kNumNanosecsPerMicrosec; | 130 int64_t diff_us = (stop_ns - start_ns) / rtc::kNumNanosecsPerMicrosec; |
113 RTC_DCHECK_GE(diff_us, std::numeric_limits<int>::min()); | 131 RTC_DCHECK_GE(diff_us, std::numeric_limits<int>::min()); |
114 RTC_DCHECK_LE(diff_us, std::numeric_limits<int>::max()); | 132 RTC_DCHECK_LE(diff_us, std::numeric_limits<int>::max()); |
115 return static_cast<int>(diff_us); | 133 return static_cast<int>(diff_us); |
116 } | 134 } |
117 | 135 |
118 } // namespace | 136 } // namespace |
119 | 137 |
120 const char* ExcludeFrameTypesToStr(ExcludeFrameTypes e) { | 138 const char* ExcludeFrameTypesToStr(ExcludeFrameTypes e) { |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 frame_stat->encoding_successful = true; | 362 frame_stat->encoding_successful = true; |
345 frame_stat->encoded_frame_size_bytes = encoded_image._length; | 363 frame_stat->encoded_frame_size_bytes = encoded_image._length; |
346 frame_stat->frame_type = encoded_image._frameType; | 364 frame_stat->frame_type = encoded_image._frameType; |
347 frame_stat->qp = encoded_image.qp_; | 365 frame_stat->qp = encoded_image.qp_; |
348 frame_stat->bitrate_kbps = static_cast<int>( | 366 frame_stat->bitrate_kbps = static_cast<int>( |
349 encoded_image._length * config_.codec_settings.maxFramerate * 8 / 1000); | 367 encoded_image._length * config_.codec_settings.maxFramerate * 8 / 1000); |
350 frame_stat->total_packets = | 368 frame_stat->total_packets = |
351 encoded_image._length / config_.networking_config.packet_size_in_bytes + | 369 encoded_image._length / config_.networking_config.packet_size_in_bytes + |
352 1; | 370 1; |
353 | 371 |
372 frame_stat->max_nalu_length = GetMaxNaluLength(encoded_image, config_); | |
373 | |
354 // Simulate packet loss. | 374 // Simulate packet loss. |
355 bool exclude_this_frame = false; | 375 bool exclude_this_frame = false; |
356 if (encoded_image._frameType == kVideoFrameKey) { | 376 if (encoded_image._frameType == kVideoFrameKey) { |
357 // Only keyframes can be excluded. | 377 // Only keyframes can be excluded. |
358 switch (config_.exclude_frame_types) { | 378 switch (config_.exclude_frame_types) { |
359 case kExcludeOnlyFirstKeyFrame: | 379 case kExcludeOnlyFirstKeyFrame: |
360 if (!first_key_frame_has_been_excluded_) { | 380 if (!first_key_frame_has_been_excluded_) { |
361 first_key_frame_has_been_excluded_ = true; | 381 first_key_frame_has_been_excluded_ = true; |
362 exclude_this_frame = true; | 382 exclude_this_frame = true; |
363 } | 383 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
477 if (decoded_frame_writer_) { | 497 if (decoded_frame_writer_) { |
478 RTC_DCHECK_EQ(extracted_length, decoded_frame_writer_->FrameLength()); | 498 RTC_DCHECK_EQ(extracted_length, decoded_frame_writer_->FrameLength()); |
479 RTC_CHECK(decoded_frame_writer_->WriteFrame(extracted_buffer.data())); | 499 RTC_CHECK(decoded_frame_writer_->WriteFrame(extracted_buffer.data())); |
480 } | 500 } |
481 | 501 |
482 last_decoded_frame_buffer_ = std::move(extracted_buffer); | 502 last_decoded_frame_buffer_ = std::move(extracted_buffer); |
483 } | 503 } |
484 | 504 |
485 } // namespace test | 505 } // namespace test |
486 } // namespace webrtc | 506 } // namespace webrtc |
OLD | NEW |