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 |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "webrtc/modules/video_coding/include/video_codec_initializer.h" | 24 #include "webrtc/modules/video_coding/include/video_codec_initializer.h" |
25 #include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h" | 25 #include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h" |
26 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" | 26 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" |
27 #include "webrtc/system_wrappers/include/cpu_info.h" | 27 #include "webrtc/system_wrappers/include/cpu_info.h" |
28 | 28 |
29 namespace webrtc { | 29 namespace webrtc { |
30 namespace test { | 30 namespace test { |
31 | 31 |
32 namespace { | 32 namespace { |
33 const int k90khzTimestampFrameDiff = 3000; // Assuming 30 fps. | 33 const int k90khzTimestampFrameDiff = 3000; // Assuming 30 fps. |
| 34 |
| 35 std::unique_ptr<VideoBitrateAllocator> CreateBitrateAllocator( |
| 36 const TestConfig& config) { |
| 37 std::unique_ptr<TemporalLayersFactory> tl_factory; |
| 38 if (config.codec_settings->codecType == VideoCodecType::kVideoCodecVP8) { |
| 39 tl_factory.reset(new TemporalLayersFactory()); |
| 40 config.codec_settings->VP8()->tl_factory = tl_factory.get(); |
| 41 } |
| 42 return std::unique_ptr<VideoBitrateAllocator>( |
| 43 VideoCodecInitializer::CreateBitrateAllocator(*config.codec_settings, |
| 44 std::move(tl_factory))); |
| 45 } |
| 46 |
34 } // namespace | 47 } // namespace |
35 | 48 |
36 const char* ExcludeFrameTypesToStr(ExcludeFrameTypes e) { | 49 const char* ExcludeFrameTypesToStr(ExcludeFrameTypes e) { |
37 switch (e) { | 50 switch (e) { |
38 case kExcludeOnlyFirstKeyFrame: | 51 case kExcludeOnlyFirstKeyFrame: |
39 return "ExcludeOnlyFirstKeyFrame"; | 52 return "ExcludeOnlyFirstKeyFrame"; |
40 case kExcludeAllKeyFrames: | 53 case kExcludeAllKeyFrames: |
41 return "ExcludeAllKeyFrames"; | 54 return "ExcludeAllKeyFrames"; |
42 default: | 55 default: |
43 RTC_NOTREACHED(); | 56 RTC_NOTREACHED(); |
(...skipping 23 matching lines...) Expand all Loading... |
67 FrameReader* analysis_frame_reader, | 80 FrameReader* analysis_frame_reader, |
68 FrameWriter* analysis_frame_writer, | 81 FrameWriter* analysis_frame_writer, |
69 PacketManipulator* packet_manipulator, | 82 PacketManipulator* packet_manipulator, |
70 const TestConfig& config, | 83 const TestConfig& config, |
71 Stats* stats, | 84 Stats* stats, |
72 FrameWriter* source_frame_writer, | 85 FrameWriter* source_frame_writer, |
73 IvfFileWriter* encoded_frame_writer, | 86 IvfFileWriter* encoded_frame_writer, |
74 FrameWriter* decoded_frame_writer) | 87 FrameWriter* decoded_frame_writer) |
75 : encoder_(encoder), | 88 : encoder_(encoder), |
76 decoder_(decoder), | 89 decoder_(decoder), |
| 90 bitrate_allocator_(CreateBitrateAllocator(config)), |
| 91 encode_callback_(new VideoProcessorEncodeCompleteCallback(this)), |
| 92 decode_callback_(new VideoProcessorDecodeCompleteCallback(this)), |
| 93 packet_manipulator_(packet_manipulator), |
| 94 config_(config), |
77 analysis_frame_reader_(analysis_frame_reader), | 95 analysis_frame_reader_(analysis_frame_reader), |
78 analysis_frame_writer_(analysis_frame_writer), | 96 analysis_frame_writer_(analysis_frame_writer), |
79 packet_manipulator_(packet_manipulator), | |
80 config_(config), | |
81 stats_(stats), | |
82 source_frame_writer_(source_frame_writer), | 97 source_frame_writer_(source_frame_writer), |
83 encoded_frame_writer_(encoded_frame_writer), | 98 encoded_frame_writer_(encoded_frame_writer), |
84 decoded_frame_writer_(decoded_frame_writer), | 99 decoded_frame_writer_(decoded_frame_writer), |
85 first_key_frame_has_been_excluded_(false), | 100 first_key_frame_has_been_excluded_(false), |
86 last_frame_missing_(false), | 101 last_frame_missing_(false), |
87 initialized_(false), | 102 initialized_(false), |
88 encoded_frame_size_(0), | 103 encoded_frame_size_(0), |
89 encoded_frame_type_(kVideoFrameKey), | 104 encoded_frame_type_(kVideoFrameKey), |
90 prev_time_stamp_(0), | 105 prev_time_stamp_(0), |
| 106 last_encoder_frame_width_(0), |
| 107 last_encoder_frame_height_(0), |
| 108 stats_(stats), |
91 num_dropped_frames_(0), | 109 num_dropped_frames_(0), |
92 num_spatial_resizes_(0), | 110 num_spatial_resizes_(0), |
93 last_encoder_frame_width_(0), | |
94 last_encoder_frame_height_(0), | |
95 bit_rate_factor_(0.0), | 111 bit_rate_factor_(0.0), |
96 encode_start_ns_(0), | 112 encode_start_ns_(0), |
97 decode_start_ns_(0) { | 113 decode_start_ns_(0) { |
98 std::unique_ptr<TemporalLayersFactory> tl_factory; | |
99 if (config_.codec_settings->codecType == VideoCodecType::kVideoCodecVP8) { | |
100 tl_factory.reset(new TemporalLayersFactory()); | |
101 config.codec_settings->VP8()->tl_factory = tl_factory.get(); | |
102 } | |
103 bitrate_allocator_ = VideoCodecInitializer::CreateBitrateAllocator( | |
104 *config.codec_settings, std::move(tl_factory)); | |
105 RTC_DCHECK(encoder); | 114 RTC_DCHECK(encoder); |
106 RTC_DCHECK(decoder); | 115 RTC_DCHECK(decoder); |
| 116 RTC_DCHECK(packet_manipulator); |
107 RTC_DCHECK(analysis_frame_reader); | 117 RTC_DCHECK(analysis_frame_reader); |
108 RTC_DCHECK(analysis_frame_writer); | 118 RTC_DCHECK(analysis_frame_writer); |
109 RTC_DCHECK(packet_manipulator); | |
110 RTC_DCHECK(stats); | 119 RTC_DCHECK(stats); |
111 } | 120 } |
112 | 121 |
113 bool VideoProcessorImpl::Init() { | 122 bool VideoProcessorImpl::Init() { |
114 // Calculate a factor used for bit rate calculations. | 123 // Calculate a factor used for bit rate calculations. |
115 bit_rate_factor_ = config_.codec_settings->maxFramerate * 0.001 * 8; // bits | 124 bit_rate_factor_ = config_.codec_settings->maxFramerate * 0.001 * 8; // bits |
116 | 125 |
117 // Initialize data structures used by the encoder/decoder APIs. | 126 // Initialize data structures used by the encoder/decoder APIs. |
118 size_t frame_length_in_bytes = analysis_frame_reader_->FrameLength(); | 127 size_t frame_length_in_bytes = analysis_frame_reader_->FrameLength(); |
119 last_successful_frame_buffer_.reset(new uint8_t[frame_length_in_bytes]); | 128 last_successful_frame_buffer_.reset(new uint8_t[frame_length_in_bytes]); |
120 | 129 |
121 // Set fixed properties common for all frames. | 130 // Set fixed properties common for all frames. |
122 // To keep track of spatial resize actions by encoder. | 131 // To keep track of spatial resize actions by encoder. |
123 last_encoder_frame_width_ = config_.codec_settings->width; | 132 last_encoder_frame_width_ = config_.codec_settings->width; |
124 last_encoder_frame_height_ = config_.codec_settings->height; | 133 last_encoder_frame_height_ = config_.codec_settings->height; |
125 | 134 |
126 // Setup required callbacks for the encoder/decoder. | 135 // Setup required callbacks for the encoder/decoder. |
127 encode_callback_.reset(new VideoProcessorEncodeCompleteCallback(this)); | |
128 decode_callback_.reset(new VideoProcessorDecodeCompleteCallback(this)); | |
129 RTC_CHECK_EQ(encoder_->RegisterEncodeCompleteCallback(encode_callback_.get()), | 136 RTC_CHECK_EQ(encoder_->RegisterEncodeCompleteCallback(encode_callback_.get()), |
130 WEBRTC_VIDEO_CODEC_OK) | 137 WEBRTC_VIDEO_CODEC_OK) |
131 << "Failed to register encode complete callback"; | 138 << "Failed to register encode complete callback"; |
132 RTC_CHECK_EQ(decoder_->RegisterDecodeCompleteCallback(decode_callback_.get()), | 139 RTC_CHECK_EQ(decoder_->RegisterDecodeCompleteCallback(decode_callback_.get()), |
133 WEBRTC_VIDEO_CODEC_OK) | 140 WEBRTC_VIDEO_CODEC_OK) |
134 << "Failed to register decode complete callback"; | 141 << "Failed to register decode complete callback"; |
135 | 142 |
136 // Init the encoder and decoder. | 143 // Initialize the encoder and decoder. |
137 uint32_t num_cores = | 144 uint32_t num_cores = |
138 config_.use_single_core ? 1 : CpuInfo::DetectNumberOfCores(); | 145 config_.use_single_core ? 1 : CpuInfo::DetectNumberOfCores(); |
139 RTC_CHECK_EQ( | 146 RTC_CHECK_EQ( |
140 encoder_->InitEncode(config_.codec_settings, num_cores, | 147 encoder_->InitEncode(config_.codec_settings, num_cores, |
141 config_.networking_config.max_payload_size_in_bytes), | 148 config_.networking_config.max_payload_size_in_bytes), |
142 WEBRTC_VIDEO_CODEC_OK) | 149 WEBRTC_VIDEO_CODEC_OK) |
143 << "Failed to initialize VideoEncoder"; | 150 << "Failed to initialize VideoEncoder"; |
144 | 151 |
145 RTC_CHECK_EQ(decoder_->InitDecode(config_.codec_settings, num_cores), | 152 RTC_CHECK_EQ(decoder_->InitDecode(config_.codec_settings, num_cores), |
146 WEBRTC_VIDEO_CODEC_OK) | 153 WEBRTC_VIDEO_CODEC_OK) |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 stat.frame_number = frame_number; | 322 stat.frame_number = frame_number; |
316 stat.frame_type = encoded_image._frameType; | 323 stat.frame_type = encoded_image._frameType; |
317 stat.qp = encoded_image.qp_; | 324 stat.qp = encoded_image.qp_; |
318 stat.bit_rate_in_kbps = encoded_image._length * bit_rate_factor_; | 325 stat.bit_rate_in_kbps = encoded_image._length * bit_rate_factor_; |
319 stat.total_packets = | 326 stat.total_packets = |
320 encoded_image._length / config_.networking_config.packet_size_in_bytes + | 327 encoded_image._length / config_.networking_config.packet_size_in_bytes + |
321 1; | 328 1; |
322 | 329 |
323 // Simulate packet loss. | 330 // Simulate packet loss. |
324 bool exclude_this_frame = false; | 331 bool exclude_this_frame = false; |
325 // Only keyframes can be excluded. | |
326 if (encoded_image._frameType == kVideoFrameKey) { | 332 if (encoded_image._frameType == kVideoFrameKey) { |
| 333 // Only keyframes can be excluded. |
327 switch (config_.exclude_frame_types) { | 334 switch (config_.exclude_frame_types) { |
328 case kExcludeOnlyFirstKeyFrame: | 335 case kExcludeOnlyFirstKeyFrame: |
329 if (!first_key_frame_has_been_excluded_) { | 336 if (!first_key_frame_has_been_excluded_) { |
330 first_key_frame_has_been_excluded_ = true; | 337 first_key_frame_has_been_excluded_ = true; |
331 exclude_this_frame = true; | 338 exclude_this_frame = true; |
332 } | 339 } |
333 break; | 340 break; |
334 case kExcludeAllKeyFrames: | 341 case kExcludeAllKeyFrames: |
335 exclude_this_frame = true; | 342 exclude_this_frame = true; |
336 break; | 343 break; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 int VideoProcessorImpl::GetElapsedTimeMicroseconds(int64_t start, | 466 int VideoProcessorImpl::GetElapsedTimeMicroseconds(int64_t start, |
460 int64_t stop) { | 467 int64_t stop) { |
461 int64_t encode_time = (stop - start) / rtc::kNumNanosecsPerMicrosec; | 468 int64_t encode_time = (stop - start) / rtc::kNumNanosecsPerMicrosec; |
462 RTC_DCHECK_GE(encode_time, std::numeric_limits<int>::min()); | 469 RTC_DCHECK_GE(encode_time, std::numeric_limits<int>::min()); |
463 RTC_DCHECK_LE(encode_time, std::numeric_limits<int>::max()); | 470 RTC_DCHECK_LE(encode_time, std::numeric_limits<int>::max()); |
464 return static_cast<int>(encode_time); | 471 return static_cast<int>(encode_time); |
465 } | 472 } |
466 | 473 |
467 } // namespace test | 474 } // namespace test |
468 } // namespace webrtc | 475 } // namespace webrtc |
OLD | NEW |