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 <limits> | 15 #include <limits> |
16 #include <memory> | 16 #include <memory> |
17 #include <utility> | 17 #include <utility> |
18 #include <vector> | 18 #include <vector> |
19 #include <algorithm> | |
brandtr
2017/09/26 09:19:13
Also sort the include order here.
ssilkin
2017/09/26 11:07:04
Done.
| |
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) |
22 #include "modules/video_coding/codecs/vp8/simulcast_rate_allocator.h" | 23 #include "modules/video_coding/codecs/vp8/simulcast_rate_allocator.h" |
23 #include "modules/video_coding/include/video_codec_initializer.h" | 24 #include "modules/video_coding/include/video_codec_initializer.h" |
24 #include "modules/video_coding/utility/default_video_bitrate_allocator.h" | 25 #include "modules/video_coding/utility/default_video_bitrate_allocator.h" |
25 #include "rtc_base/checks.h" | 26 #include "rtc_base/checks.h" |
26 #include "rtc_base/logging.h" | 27 #include "rtc_base/logging.h" |
27 #include "rtc_base/timeutils.h" | 28 #include "rtc_base/timeutils.h" |
28 #include "system_wrappers/include/cpu_info.h" | 29 #include "system_wrappers/include/cpu_info.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 if (config.codec_settings.codecType == kVideoCodecVP8) { | 102 if (config.codec_settings.codecType == kVideoCodecVP8) { |
102 ASSERT_TRUE(vp8::GetQp(encoded_frame._buffer, encoded_frame._length, &qp)); | 103 ASSERT_TRUE(vp8::GetQp(encoded_frame._buffer, encoded_frame._length, &qp)); |
103 } else if (config.codec_settings.codecType == kVideoCodecVP9) { | 104 } else if (config.codec_settings.codecType == kVideoCodecVP9) { |
104 ASSERT_TRUE(vp9::GetQp(encoded_frame._buffer, encoded_frame._length, &qp)); | 105 ASSERT_TRUE(vp9::GetQp(encoded_frame._buffer, encoded_frame._length, &qp)); |
105 } else { | 106 } else { |
106 return; | 107 return; |
107 } | 108 } |
108 EXPECT_EQ(encoded_frame.qp_, qp) << "Encoder QP != parsed bitstream QP."; | 109 EXPECT_EQ(encoded_frame.qp_, qp) << "Encoder QP != parsed bitstream QP."; |
109 } | 110 } |
110 | 111 |
112 rtc::Optional<size_t> GetMaxNaluLength(const EncodedImage& encoded_frame, | |
113 const TestConfig& config) { | |
brandtr
2017/09/26 09:19:13
To fix the indentation, you can run 'git cl format
ssilkin
2017/09/26 11:07:04
Great. I didn't know about that command.
| |
114 if (config.codec_settings.codecType != kVideoCodecH264) | |
115 return rtc::Optional<size_t>(); | |
116 | |
117 std::vector<webrtc::H264::NaluIndex> nalu_indices = | |
118 webrtc::H264::FindNaluIndices(encoded_frame._buffer, | |
119 encoded_frame._length); | |
120 | |
121 size_t maxLength = 0; | |
brandtr
2017/09/26 09:19:13
We typically use snake_case for naming local varia
ssilkin
2017/09/26 11:07:04
Done.
| |
122 for (const webrtc::H264::NaluIndex& index : nalu_indices) | |
123 maxLength = std::max(maxLength, index.payload_size); | |
124 | |
125 return rtc::Optional<size_t>(maxLength); | |
126 } | |
127 | |
111 int GetElapsedTimeMicroseconds(int64_t start_ns, int64_t stop_ns) { | 128 int GetElapsedTimeMicroseconds(int64_t start_ns, int64_t stop_ns) { |
112 int64_t diff_us = (stop_ns - start_ns) / rtc::kNumNanosecsPerMicrosec; | 129 int64_t diff_us = (stop_ns - start_ns) / rtc::kNumNanosecsPerMicrosec; |
113 RTC_DCHECK_GE(diff_us, std::numeric_limits<int>::min()); | 130 RTC_DCHECK_GE(diff_us, std::numeric_limits<int>::min()); |
114 RTC_DCHECK_LE(diff_us, std::numeric_limits<int>::max()); | 131 RTC_DCHECK_LE(diff_us, std::numeric_limits<int>::max()); |
115 return static_cast<int>(diff_us); | 132 return static_cast<int>(diff_us); |
116 } | 133 } |
117 | 134 |
118 } // namespace | 135 } // namespace |
119 | 136 |
120 const char* ExcludeFrameTypesToStr(ExcludeFrameTypes e) { | 137 const char* ExcludeFrameTypesToStr(ExcludeFrameTypes e) { |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 frame_stat->encoding_successful = true; | 361 frame_stat->encoding_successful = true; |
345 frame_stat->encoded_frame_size_bytes = encoded_image._length; | 362 frame_stat->encoded_frame_size_bytes = encoded_image._length; |
346 frame_stat->frame_type = encoded_image._frameType; | 363 frame_stat->frame_type = encoded_image._frameType; |
347 frame_stat->qp = encoded_image.qp_; | 364 frame_stat->qp = encoded_image.qp_; |
348 frame_stat->bitrate_kbps = static_cast<int>( | 365 frame_stat->bitrate_kbps = static_cast<int>( |
349 encoded_image._length * config_.codec_settings.maxFramerate * 8 / 1000); | 366 encoded_image._length * config_.codec_settings.maxFramerate * 8 / 1000); |
350 frame_stat->total_packets = | 367 frame_stat->total_packets = |
351 encoded_image._length / config_.networking_config.packet_size_in_bytes + | 368 encoded_image._length / config_.networking_config.packet_size_in_bytes + |
352 1; | 369 1; |
353 | 370 |
371 frame_stat->max_nalu_length = GetMaxNaluLength(encoded_image, config_); | |
372 | |
354 // Simulate packet loss. | 373 // Simulate packet loss. |
355 bool exclude_this_frame = false; | 374 bool exclude_this_frame = false; |
356 if (encoded_image._frameType == kVideoFrameKey) { | 375 if (encoded_image._frameType == kVideoFrameKey) { |
357 // Only keyframes can be excluded. | 376 // Only keyframes can be excluded. |
358 switch (config_.exclude_frame_types) { | 377 switch (config_.exclude_frame_types) { |
359 case kExcludeOnlyFirstKeyFrame: | 378 case kExcludeOnlyFirstKeyFrame: |
360 if (!first_key_frame_has_been_excluded_) { | 379 if (!first_key_frame_has_been_excluded_) { |
361 first_key_frame_has_been_excluded_ = true; | 380 first_key_frame_has_been_excluded_ = true; |
362 exclude_this_frame = true; | 381 exclude_this_frame = true; |
363 } | 382 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
477 if (decoded_frame_writer_) { | 496 if (decoded_frame_writer_) { |
478 RTC_DCHECK_EQ(extracted_length, decoded_frame_writer_->FrameLength()); | 497 RTC_DCHECK_EQ(extracted_length, decoded_frame_writer_->FrameLength()); |
479 RTC_CHECK(decoded_frame_writer_->WriteFrame(extracted_buffer.data())); | 498 RTC_CHECK(decoded_frame_writer_->WriteFrame(extracted_buffer.data())); |
480 } | 499 } |
481 | 500 |
482 last_decoded_frame_buffer_ = std::move(extracted_buffer); | 501 last_decoded_frame_buffer_ = std::move(extracted_buffer); |
483 } | 502 } |
484 | 503 |
485 } // namespace test | 504 } // namespace test |
486 } // namespace webrtc | 505 } // namespace webrtc |
OLD | NEW |