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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 output_filename(""), | 107 output_filename(""), |
108 output_dir("out"), | 108 output_dir("out"), |
109 networking_config(), | 109 networking_config(), |
110 exclude_frame_types(kExcludeOnlyFirstKeyFrame), | 110 exclude_frame_types(kExcludeOnlyFirstKeyFrame), |
111 frame_length_in_bytes(0), | 111 frame_length_in_bytes(0), |
112 use_single_core(false), | 112 use_single_core(false), |
113 keyframe_interval(0), | 113 keyframe_interval(0), |
114 codec_settings(nullptr), | 114 codec_settings(nullptr), |
115 verbose(true) {} | 115 verbose(true) {} |
116 | 116 |
117 TestConfig::~TestConfig() {} | 117 TestConfig::~TestConfig() = default; |
118 | 118 |
119 VideoProcessorImpl::VideoProcessorImpl(webrtc::VideoEncoder* encoder, | 119 VideoProcessorImpl::VideoProcessorImpl(webrtc::VideoEncoder* encoder, |
120 webrtc::VideoDecoder* decoder, | 120 webrtc::VideoDecoder* decoder, |
121 FrameReader* analysis_frame_reader, | 121 FrameReader* analysis_frame_reader, |
122 FrameWriter* analysis_frame_writer, | 122 FrameWriter* analysis_frame_writer, |
123 PacketManipulator* packet_manipulator, | 123 PacketManipulator* packet_manipulator, |
124 const TestConfig& config, | 124 const TestConfig& config, |
125 Stats* stats, | 125 Stats* stats, |
126 FrameWriter* source_frame_writer, | 126 FrameWriter* source_frame_writer, |
127 IvfFileWriter* encoded_frame_writer, | 127 IvfFileWriter* encoded_frame_writer, |
(...skipping 21 matching lines...) Expand all Loading... | |
149 num_spatial_resizes_(0), | 149 num_spatial_resizes_(0), |
150 bit_rate_factor_(0.0) { | 150 bit_rate_factor_(0.0) { |
151 RTC_DCHECK(encoder); | 151 RTC_DCHECK(encoder); |
152 RTC_DCHECK(decoder); | 152 RTC_DCHECK(decoder); |
153 RTC_DCHECK(packet_manipulator); | 153 RTC_DCHECK(packet_manipulator); |
154 RTC_DCHECK(analysis_frame_reader); | 154 RTC_DCHECK(analysis_frame_reader); |
155 RTC_DCHECK(analysis_frame_writer); | 155 RTC_DCHECK(analysis_frame_writer); |
156 RTC_DCHECK(stats); | 156 RTC_DCHECK(stats); |
157 | 157 |
158 frame_infos_.reserve(num_frames_); | 158 frame_infos_.reserve(num_frames_); |
159 | |
160 task_checker_.Detach(); | |
159 } | 161 } |
160 | 162 |
163 VideoProcessorImpl::~VideoProcessorImpl() = default; | |
sprang_webrtc
2017/03/20 19:36:17
nit: Could you declare ~VideoProcessor and ~Video
brandtr
2017/03/21 09:40:54
Done.
| |
164 | |
161 bool VideoProcessorImpl::Init() { | 165 bool VideoProcessorImpl::Init() { |
166 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | |
162 RTC_DCHECK(!initialized_) | 167 RTC_DCHECK(!initialized_) |
163 << "This VideoProcessor has already been initialized."; | 168 << "This VideoProcessor has already been initialized."; |
164 | 169 |
165 // Calculate a factor used for bit rate calculations. | 170 // Calculate a factor used for bit rate calculations. |
166 bit_rate_factor_ = config_.codec_settings->maxFramerate * 0.001 * 8; // bits | 171 bit_rate_factor_ = config_.codec_settings->maxFramerate * 0.001 * 8; // bits |
167 | 172 |
168 // Setup required callbacks for the encoder/decoder. | 173 // Setup required callbacks for the encoder/decoder. |
169 RTC_CHECK_EQ(encoder_->RegisterEncodeCompleteCallback(encode_callback_.get()), | 174 RTC_CHECK_EQ(encoder_->RegisterEncodeCompleteCallback(encode_callback_.get()), |
170 WEBRTC_VIDEO_CODEC_OK) | 175 WEBRTC_VIDEO_CODEC_OK) |
171 << "Failed to register encode complete callback"; | 176 << "Failed to register encode complete callback"; |
(...skipping 24 matching lines...) Expand all Loading... | |
196 printf(" Decoder implementation name: %s\n", | 201 printf(" Decoder implementation name: %s\n", |
197 decoder_->ImplementationName()); | 202 decoder_->ImplementationName()); |
198 PrintCodecSettings(config_.codec_settings); | 203 PrintCodecSettings(config_.codec_settings); |
199 } | 204 } |
200 | 205 |
201 initialized_ = true; | 206 initialized_ = true; |
202 | 207 |
203 return true; | 208 return true; |
204 } | 209 } |
205 | 210 |
206 VideoProcessorImpl::~VideoProcessorImpl() { | 211 void VideoProcessorImpl::DeregisterCallbacks() { |
212 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | |
207 encoder_->RegisterEncodeCompleteCallback(nullptr); | 213 encoder_->RegisterEncodeCompleteCallback(nullptr); |
208 decoder_->RegisterDecodeCompleteCallback(nullptr); | 214 decoder_->RegisterDecodeCompleteCallback(nullptr); |
209 } | 215 } |
210 | 216 |
211 void VideoProcessorImpl::SetRates(int bit_rate, int frame_rate) { | 217 void VideoProcessorImpl::SetRates(int bit_rate, int frame_rate) { |
218 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | |
212 int set_rates_result = encoder_->SetRateAllocation( | 219 int set_rates_result = encoder_->SetRateAllocation( |
213 bitrate_allocator_->GetAllocation(bit_rate * 1000, frame_rate), | 220 bitrate_allocator_->GetAllocation(bit_rate * 1000, frame_rate), |
214 frame_rate); | 221 frame_rate); |
215 RTC_DCHECK_GE(set_rates_result, 0) | 222 RTC_DCHECK_GE(set_rates_result, 0) |
216 << "Failed to update encoder with new rate " << bit_rate; | 223 << "Failed to update encoder with new rate " << bit_rate; |
217 num_dropped_frames_ = 0; | 224 num_dropped_frames_ = 0; |
218 num_spatial_resizes_ = 0; | 225 num_spatial_resizes_ = 0; |
219 } | 226 } |
220 | 227 |
221 size_t VideoProcessorImpl::EncodedFrameSize(int frame_number) { | 228 size_t VideoProcessorImpl::EncodedFrameSize(int frame_number) { |
229 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | |
222 RTC_DCHECK_LT(frame_number, frame_infos_.size()); | 230 RTC_DCHECK_LT(frame_number, frame_infos_.size()); |
223 return frame_infos_[frame_number].encoded_frame_size; | 231 return frame_infos_[frame_number].encoded_frame_size; |
224 } | 232 } |
225 | 233 |
226 FrameType VideoProcessorImpl::EncodedFrameType(int frame_number) { | 234 FrameType VideoProcessorImpl::EncodedFrameType(int frame_number) { |
235 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | |
227 RTC_DCHECK_LT(frame_number, frame_infos_.size()); | 236 RTC_DCHECK_LT(frame_number, frame_infos_.size()); |
228 return frame_infos_[frame_number].encoded_frame_type; | 237 return frame_infos_[frame_number].encoded_frame_type; |
229 } | 238 } |
230 | 239 |
231 int VideoProcessorImpl::NumberDroppedFrames() { | 240 int VideoProcessorImpl::NumberDroppedFrames() { |
241 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | |
232 return num_dropped_frames_; | 242 return num_dropped_frames_; |
233 } | 243 } |
234 | 244 |
235 int VideoProcessorImpl::NumberSpatialResizes() { | 245 int VideoProcessorImpl::NumberSpatialResizes() { |
246 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | |
236 return num_spatial_resizes_; | 247 return num_spatial_resizes_; |
237 } | 248 } |
238 | 249 |
239 bool VideoProcessorImpl::ProcessFrame(int frame_number) { | 250 bool VideoProcessorImpl::ProcessFrame(int frame_number) { |
251 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | |
240 RTC_DCHECK_GE(frame_number, 0); | 252 RTC_DCHECK_GE(frame_number, 0); |
241 RTC_DCHECK_LE(frame_number, frame_infos_.size()) | 253 RTC_DCHECK_LE(frame_number, frame_infos_.size()) |
242 << "Must process frames without gaps."; | 254 << "Must process frames without gaps."; |
243 RTC_DCHECK(initialized_) << "Attempting to use uninitialized VideoProcessor"; | 255 RTC_DCHECK(initialized_) << "Attempting to use uninitialized VideoProcessor"; |
244 | 256 |
245 rtc::scoped_refptr<VideoFrameBuffer> buffer( | 257 rtc::scoped_refptr<VideoFrameBuffer> buffer( |
246 analysis_frame_reader_->ReadFrame()); | 258 analysis_frame_reader_->ReadFrame()); |
247 | 259 |
248 if (!buffer) { | 260 if (!buffer) { |
249 // Last frame has been reached. | 261 // Last frame has been reached. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 } | 304 } |
293 | 305 |
294 void VideoProcessorImpl::FrameEncoded( | 306 void VideoProcessorImpl::FrameEncoded( |
295 webrtc::VideoCodecType codec, | 307 webrtc::VideoCodecType codec, |
296 const EncodedImage& encoded_image, | 308 const EncodedImage& encoded_image, |
297 const webrtc::RTPFragmentationHeader* fragmentation) { | 309 const webrtc::RTPFragmentationHeader* fragmentation) { |
298 // For the highest measurement accuracy of the encode time, the start/stop | 310 // For the highest measurement accuracy of the encode time, the start/stop |
299 // time recordings should wrap the Encode call as tightly as possible. | 311 // time recordings should wrap the Encode call as tightly as possible. |
300 int64_t encode_stop_ns = rtc::TimeNanos(); | 312 int64_t encode_stop_ns = rtc::TimeNanos(); |
301 | 313 |
314 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | |
315 | |
302 if (encoded_frame_writer_) { | 316 if (encoded_frame_writer_) { |
303 RTC_CHECK(encoded_frame_writer_->WriteFrame(encoded_image, codec)); | 317 RTC_CHECK(encoded_frame_writer_->WriteFrame(encoded_image, codec)); |
304 } | 318 } |
305 | 319 |
306 // Timestamp is proportional to frame number, so this gives us number of | 320 // Timestamp is proportional to frame number, so this gives us number of |
307 // dropped frames. | 321 // dropped frames. |
308 int frame_number = TimestampToFrameNumber(encoded_image._timeStamp); | 322 int frame_number = TimestampToFrameNumber(encoded_image._timeStamp); |
309 bool last_frame_missing = false; | 323 bool last_frame_missing = false; |
310 if (frame_number > 0) { | 324 if (frame_number > 0) { |
311 RTC_DCHECK_GE(last_encoded_frame_num_, 0); | 325 RTC_DCHECK_GE(last_encoded_frame_num_, 0); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 decoded_frame_writer_->WriteFrame(last_decoded_frame_buffer_.data())); | 430 decoded_frame_writer_->WriteFrame(last_decoded_frame_buffer_.data())); |
417 } | 431 } |
418 } | 432 } |
419 } | 433 } |
420 | 434 |
421 void VideoProcessorImpl::FrameDecoded(const VideoFrame& image) { | 435 void VideoProcessorImpl::FrameDecoded(const VideoFrame& image) { |
422 // For the highest measurement accuracy of the decode time, the start/stop | 436 // For the highest measurement accuracy of the decode time, the start/stop |
423 // time recordings should wrap the Decode call as tightly as possible. | 437 // time recordings should wrap the Decode call as tightly as possible. |
424 int64_t decode_stop_ns = rtc::TimeNanos(); | 438 int64_t decode_stop_ns = rtc::TimeNanos(); |
425 | 439 |
440 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | |
441 | |
426 // Update frame information and statistics. | 442 // Update frame information and statistics. |
427 int frame_number = TimestampToFrameNumber(image.timestamp()); | 443 int frame_number = TimestampToFrameNumber(image.timestamp()); |
428 RTC_DCHECK_LT(frame_number, frame_infos_.size()); | 444 RTC_DCHECK_LT(frame_number, frame_infos_.size()); |
429 FrameInfo* frame_info = &frame_infos_[frame_number]; | 445 FrameInfo* frame_info = &frame_infos_[frame_number]; |
430 frame_info->decoded_width = image.width(); | 446 frame_info->decoded_width = image.width(); |
431 frame_info->decoded_height = image.height(); | 447 frame_info->decoded_height = image.height(); |
432 FrameStatistic* frame_stat = &stats_->stats_[frame_number]; | 448 FrameStatistic* frame_stat = &stats_->stats_[frame_number]; |
433 frame_stat->decode_time_in_us = | 449 frame_stat->decode_time_in_us = |
434 GetElapsedTimeMicroseconds(frame_info->decode_start_ns, decode_stop_ns); | 450 GetElapsedTimeMicroseconds(frame_info->decode_start_ns, decode_stop_ns); |
435 frame_stat->decoding_successful = true; | 451 frame_stat->decoding_successful = true; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 if (decoded_frame_writer_) { | 507 if (decoded_frame_writer_) { |
492 RTC_DCHECK_EQ(extracted_length, decoded_frame_writer_->FrameLength()); | 508 RTC_DCHECK_EQ(extracted_length, decoded_frame_writer_->FrameLength()); |
493 RTC_CHECK(decoded_frame_writer_->WriteFrame(extracted_buffer.data())); | 509 RTC_CHECK(decoded_frame_writer_->WriteFrame(extracted_buffer.data())); |
494 } | 510 } |
495 | 511 |
496 last_decoded_frame_buffer_ = std::move(extracted_buffer); | 512 last_decoded_frame_buffer_ = std::move(extracted_buffer); |
497 } | 513 } |
498 | 514 |
499 } // namespace test | 515 } // namespace test |
500 } // namespace webrtc | 516 } // namespace webrtc |
OLD | NEW |