| 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 17 matching lines...) Expand all Loading... |
| 28 #include "webrtc/system_wrappers/include/cpu_info.h" | 28 #include "webrtc/system_wrappers/include/cpu_info.h" |
| 29 | 29 |
| 30 namespace webrtc { | 30 namespace webrtc { |
| 31 namespace test { | 31 namespace test { |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 const int kRtpClockRateHz = 90000; | 35 const int kRtpClockRateHz = 90000; |
| 36 | 36 |
| 37 std::unique_ptr<VideoBitrateAllocator> CreateBitrateAllocator( | 37 std::unique_ptr<VideoBitrateAllocator> CreateBitrateAllocator( |
| 38 const TestConfig& config) { | 38 TestConfig* config) { |
| 39 std::unique_ptr<TemporalLayersFactory> tl_factory; | 39 std::unique_ptr<TemporalLayersFactory> tl_factory; |
| 40 if (config.codec_settings->codecType == VideoCodecType::kVideoCodecVP8) { | 40 if (config->codec_settings.codecType == VideoCodecType::kVideoCodecVP8) { |
| 41 tl_factory.reset(new TemporalLayersFactory()); | 41 tl_factory.reset(new TemporalLayersFactory()); |
| 42 config.codec_settings->VP8()->tl_factory = tl_factory.get(); | 42 config->codec_settings.VP8()->tl_factory = tl_factory.get(); |
| 43 } | 43 } |
| 44 return std::unique_ptr<VideoBitrateAllocator>( | 44 return std::unique_ptr<VideoBitrateAllocator>( |
| 45 VideoCodecInitializer::CreateBitrateAllocator(*config.codec_settings, | 45 VideoCodecInitializer::CreateBitrateAllocator(config->codec_settings, |
| 46 std::move(tl_factory))); | 46 std::move(tl_factory))); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void PrintCodecSettings(const VideoCodec* codec_settings) { | 49 void PrintCodecSettings(const VideoCodec& codec_settings) { |
| 50 RTC_DCHECK(codec_settings); | |
| 51 printf(" Codec settings:\n"); | 50 printf(" Codec settings:\n"); |
| 52 printf(" Codec type : %s\n", | 51 printf(" Codec type : %s\n", |
| 53 CodecTypeToPayloadName(codec_settings->codecType).value_or("Unknown")); | 52 CodecTypeToPayloadName(codec_settings.codecType).value_or("Unknown")); |
| 54 printf(" Start bitrate : %d kbps\n", codec_settings->startBitrate); | 53 printf(" Start bitrate : %d kbps\n", codec_settings.startBitrate); |
| 55 printf(" Max bitrate : %d kbps\n", codec_settings->maxBitrate); | 54 printf(" Max bitrate : %d kbps\n", codec_settings.maxBitrate); |
| 56 printf(" Min bitrate : %d kbps\n", codec_settings->minBitrate); | 55 printf(" Min bitrate : %d kbps\n", codec_settings.minBitrate); |
| 57 printf(" Width : %d\n", codec_settings->width); | 56 printf(" Width : %d\n", codec_settings.width); |
| 58 printf(" Height : %d\n", codec_settings->height); | 57 printf(" Height : %d\n", codec_settings.height); |
| 59 printf(" Max frame rate : %d\n", codec_settings->maxFramerate); | 58 printf(" Max frame rate : %d\n", codec_settings.maxFramerate); |
| 60 printf(" QPmax : %d\n", codec_settings->qpMax); | 59 printf(" QPmax : %d\n", codec_settings.qpMax); |
| 61 if (codec_settings->codecType == kVideoCodecVP8) { | 60 if (codec_settings.codecType == kVideoCodecVP8) { |
| 62 printf(" Complexity : %d\n", codec_settings->VP8().complexity); | 61 printf(" Complexity : %d\n", codec_settings.VP8().complexity); |
| 63 printf(" Denoising : %d\n", codec_settings->VP8().denoisingOn); | 62 printf(" Denoising : %d\n", codec_settings.VP8().denoisingOn); |
| 64 printf(" Error concealment : %d\n", | 63 printf(" Error concealment : %d\n", |
| 65 codec_settings->VP8().errorConcealmentOn); | 64 codec_settings.VP8().errorConcealmentOn); |
| 66 printf(" Frame dropping : %d\n", codec_settings->VP8().frameDroppingOn); | 65 printf(" Frame dropping : %d\n", codec_settings.VP8().frameDroppingOn); |
| 67 printf(" Resilience : %d\n", codec_settings->VP8().resilience); | 66 printf(" Resilience : %d\n", codec_settings.VP8().resilience); |
| 67 printf(" Key frame interval: %d\n", codec_settings.VP8().keyFrameInterval); |
| 68 } else if (codec_settings.codecType == kVideoCodecVP9) { |
| 69 printf(" Complexity : %d\n", codec_settings.VP9().complexity); |
| 70 printf(" Denoising : %d\n", codec_settings.VP9().denoisingOn); |
| 71 printf(" Frame dropping : %d\n", codec_settings.VP9().frameDroppingOn); |
| 72 printf(" Resilience : %d\n", codec_settings.VP9().resilienceOn); |
| 73 printf(" Key frame interval: %d\n", codec_settings.VP9().keyFrameInterval); |
| 74 printf(" Adaptive QP mode : %d\n", codec_settings.VP9().adaptiveQpMode); |
| 75 } else if (codec_settings.codecType == kVideoCodecH264) { |
| 76 printf(" Frame dropping : %d\n", codec_settings.H264().frameDroppingOn); |
| 68 printf(" Key frame interval: %d\n", | 77 printf(" Key frame interval: %d\n", |
| 69 codec_settings->VP8().keyFrameInterval); | 78 codec_settings.H264().keyFrameInterval); |
| 70 } else if (codec_settings->codecType == kVideoCodecVP9) { | 79 printf(" Profile : %d\n", codec_settings.H264().profile); |
| 71 printf(" Complexity : %d\n", codec_settings->VP9().complexity); | |
| 72 printf(" Denoising : %d\n", codec_settings->VP9().denoisingOn); | |
| 73 printf(" Frame dropping : %d\n", codec_settings->VP9().frameDroppingOn); | |
| 74 printf(" Resilience : %d\n", codec_settings->VP9().resilienceOn); | |
| 75 printf(" Key frame interval: %d\n", | |
| 76 codec_settings->VP9().keyFrameInterval); | |
| 77 printf(" Adaptive QP mode : %d\n", codec_settings->VP9().adaptiveQpMode); | |
| 78 } else if (codec_settings->codecType == kVideoCodecH264) { | |
| 79 printf(" Frame dropping : %d\n", | |
| 80 codec_settings->H264().frameDroppingOn); | |
| 81 printf(" Key frame interval: %d\n", | |
| 82 codec_settings->H264().keyFrameInterval); | |
| 83 printf(" Profile : %d\n", codec_settings->H264().profile); | |
| 84 } | 80 } |
| 85 } | 81 } |
| 86 | 82 |
| 87 int GetElapsedTimeMicroseconds(int64_t start_ns, int64_t stop_ns) { | 83 int GetElapsedTimeMicroseconds(int64_t start_ns, int64_t stop_ns) { |
| 88 int64_t diff_us = (stop_ns - start_ns) / rtc::kNumNanosecsPerMicrosec; | 84 int64_t diff_us = (stop_ns - start_ns) / rtc::kNumNanosecsPerMicrosec; |
| 89 RTC_DCHECK_GE(diff_us, std::numeric_limits<int>::min()); | 85 RTC_DCHECK_GE(diff_us, std::numeric_limits<int>::min()); |
| 90 RTC_DCHECK_LE(diff_us, std::numeric_limits<int>::max()); | 86 RTC_DCHECK_LE(diff_us, std::numeric_limits<int>::max()); |
| 91 return static_cast<int>(diff_us); | 87 return static_cast<int>(diff_us); |
| 92 } | 88 } |
| 93 | 89 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 107 | 103 |
| 108 VideoProcessor::VideoProcessor(webrtc::VideoEncoder* encoder, | 104 VideoProcessor::VideoProcessor(webrtc::VideoEncoder* encoder, |
| 109 webrtc::VideoDecoder* decoder, | 105 webrtc::VideoDecoder* decoder, |
| 110 FrameReader* analysis_frame_reader, | 106 FrameReader* analysis_frame_reader, |
| 111 FrameWriter* analysis_frame_writer, | 107 FrameWriter* analysis_frame_writer, |
| 112 PacketManipulator* packet_manipulator, | 108 PacketManipulator* packet_manipulator, |
| 113 const TestConfig& config, | 109 const TestConfig& config, |
| 114 Stats* stats, | 110 Stats* stats, |
| 115 IvfFileWriter* encoded_frame_writer, | 111 IvfFileWriter* encoded_frame_writer, |
| 116 FrameWriter* decoded_frame_writer) | 112 FrameWriter* decoded_frame_writer) |
| 117 : encoder_(encoder), | 113 : config_(config), |
| 114 encoder_(encoder), |
| 118 decoder_(decoder), | 115 decoder_(decoder), |
| 119 bitrate_allocator_(CreateBitrateAllocator(config)), | 116 bitrate_allocator_(CreateBitrateAllocator(&config_)), |
| 120 encode_callback_(new VideoProcessorEncodeCompleteCallback(this)), | 117 encode_callback_(new VideoProcessorEncodeCompleteCallback(this)), |
| 121 decode_callback_(new VideoProcessorDecodeCompleteCallback(this)), | 118 decode_callback_(new VideoProcessorDecodeCompleteCallback(this)), |
| 122 packet_manipulator_(packet_manipulator), | 119 packet_manipulator_(packet_manipulator), |
| 123 config_(config), | |
| 124 analysis_frame_reader_(analysis_frame_reader), | 120 analysis_frame_reader_(analysis_frame_reader), |
| 125 analysis_frame_writer_(analysis_frame_writer), | 121 analysis_frame_writer_(analysis_frame_writer), |
| 126 encoded_frame_writer_(encoded_frame_writer), | 122 encoded_frame_writer_(encoded_frame_writer), |
| 127 decoded_frame_writer_(decoded_frame_writer), | 123 decoded_frame_writer_(decoded_frame_writer), |
| 128 initialized_(false), | 124 initialized_(false), |
| 129 last_encoded_frame_num_(-1), | 125 last_encoded_frame_num_(-1), |
| 130 last_decoded_frame_num_(-1), | 126 last_decoded_frame_num_(-1), |
| 131 first_key_frame_has_been_excluded_(false), | 127 first_key_frame_has_been_excluded_(false), |
| 132 last_decoded_frame_buffer_(0, analysis_frame_reader->FrameLength()), | 128 last_decoded_frame_buffer_(0, analysis_frame_reader->FrameLength()), |
| 133 stats_(stats), | 129 stats_(stats), |
| 134 num_dropped_frames_(0), | 130 num_dropped_frames_(0), |
| 135 num_spatial_resizes_(0) { | 131 num_spatial_resizes_(0) { |
| 136 RTC_DCHECK(encoder); | 132 RTC_DCHECK(encoder); |
| 137 RTC_DCHECK(decoder); | 133 RTC_DCHECK(decoder); |
| 138 RTC_DCHECK(packet_manipulator); | 134 RTC_DCHECK(packet_manipulator); |
| 139 RTC_DCHECK(analysis_frame_reader); | 135 RTC_DCHECK(analysis_frame_reader); |
| 140 RTC_DCHECK(analysis_frame_writer); | 136 RTC_DCHECK(analysis_frame_writer); |
| 141 RTC_DCHECK(stats); | 137 RTC_DCHECK(stats); |
| 142 frame_infos_.reserve(analysis_frame_reader->NumberOfFrames()); | 138 frame_infos_.reserve(analysis_frame_reader->NumberOfFrames()); |
| 143 } | 139 } |
| 144 | 140 |
| 145 VideoProcessor::~VideoProcessor() { | 141 VideoProcessor::~VideoProcessor() { |
| 146 encoder_->RegisterEncodeCompleteCallback(nullptr); | 142 encoder_->RegisterEncodeCompleteCallback(nullptr); |
| 147 decoder_->RegisterDecodeCompleteCallback(nullptr); | 143 decoder_->RegisterDecodeCompleteCallback(nullptr); |
| 148 } | 144 } |
| 149 | 145 |
| 150 void VideoProcessor::Init() { | 146 void VideoProcessor::Init() { |
| 151 RTC_DCHECK(!initialized_) << "VideoProcessor already initialized."; | 147 RTC_DCHECK(!initialized_) << "VideoProcessor already initialized."; |
| 152 RTC_DCHECK(config_.codec_settings) << "No codec settings supplied."; | |
| 153 initialized_ = true; | 148 initialized_ = true; |
| 154 | 149 |
| 155 // Setup required callbacks for the encoder and decoder. | 150 // Setup required callbacks for the encoder and decoder. |
| 156 RTC_CHECK_EQ(encoder_->RegisterEncodeCompleteCallback(encode_callback_.get()), | 151 RTC_CHECK_EQ(encoder_->RegisterEncodeCompleteCallback(encode_callback_.get()), |
| 157 WEBRTC_VIDEO_CODEC_OK) | 152 WEBRTC_VIDEO_CODEC_OK) |
| 158 << "Failed to register encode complete callback"; | 153 << "Failed to register encode complete callback"; |
| 159 RTC_CHECK_EQ(decoder_->RegisterDecodeCompleteCallback(decode_callback_.get()), | 154 RTC_CHECK_EQ(decoder_->RegisterDecodeCompleteCallback(decode_callback_.get()), |
| 160 WEBRTC_VIDEO_CODEC_OK) | 155 WEBRTC_VIDEO_CODEC_OK) |
| 161 << "Failed to register decode complete callback"; | 156 << "Failed to register decode complete callback"; |
| 162 | 157 |
| 163 // Initialize the encoder and decoder. | 158 // Initialize the encoder and decoder. |
| 164 uint32_t num_cores = | 159 uint32_t num_cores = |
| 165 config_.use_single_core ? 1 : CpuInfo::DetectNumberOfCores(); | 160 config_.use_single_core ? 1 : CpuInfo::DetectNumberOfCores(); |
| 166 RTC_CHECK_EQ( | 161 RTC_CHECK_EQ( |
| 167 encoder_->InitEncode(config_.codec_settings, num_cores, | 162 encoder_->InitEncode(&config_.codec_settings, num_cores, |
| 168 config_.networking_config.max_payload_size_in_bytes), | 163 config_.networking_config.max_payload_size_in_bytes), |
| 169 WEBRTC_VIDEO_CODEC_OK) | 164 WEBRTC_VIDEO_CODEC_OK) |
| 170 << "Failed to initialize VideoEncoder"; | 165 << "Failed to initialize VideoEncoder"; |
| 171 | 166 |
| 172 RTC_CHECK_EQ(decoder_->InitDecode(config_.codec_settings, num_cores), | 167 RTC_CHECK_EQ(decoder_->InitDecode(&config_.codec_settings, num_cores), |
| 173 WEBRTC_VIDEO_CODEC_OK) | 168 WEBRTC_VIDEO_CODEC_OK) |
| 174 << "Failed to initialize VideoDecoder"; | 169 << "Failed to initialize VideoDecoder"; |
| 175 | 170 |
| 176 if (config_.verbose) { | 171 if (config_.verbose) { |
| 177 printf("Video Processor:\n"); | 172 printf("Video Processor:\n"); |
| 178 printf(" Filename : %s\n", config_.filename.c_str()); | 173 printf(" Filename : %s\n", config_.filename.c_str()); |
| 179 printf(" Total # of frames: %d\n", | 174 printf(" Total # of frames: %d\n", |
| 180 analysis_frame_reader_->NumberOfFrames()); | 175 analysis_frame_reader_->NumberOfFrames()); |
| 181 printf(" # CPU cores used : %d\n", num_cores); | 176 printf(" # CPU cores used : %d\n", num_cores); |
| 182 const char* encoder_name = encoder_->ImplementationName(); | 177 const char* encoder_name = encoder_->ImplementationName(); |
| 183 printf(" Encoder implementation name: %s\n", encoder_name); | 178 printf(" Encoder implementation name: %s\n", encoder_name); |
| 184 const char* decoder_name = decoder_->ImplementationName(); | 179 const char* decoder_name = decoder_->ImplementationName(); |
| 185 printf(" Decoder implementation name: %s\n", decoder_name); | 180 printf(" Decoder implementation name: %s\n", decoder_name); |
| 186 if (strcmp(encoder_name, decoder_name) == 0) { | 181 if (strcmp(encoder_name, decoder_name) == 0) { |
| 187 printf(" Codec implementation name : %s_%s\n", | 182 printf(" Codec implementation name : %s_%s\n", |
| 188 CodecTypeToPayloadName(config_.codec_settings->codecType) | 183 CodecTypeToPayloadName(config_.codec_settings.codecType) |
| 189 .value_or("Unknown"), | 184 .value_or("Unknown"), |
| 190 encoder_->ImplementationName()); | 185 encoder_->ImplementationName()); |
| 191 } | 186 } |
| 192 PrintCodecSettings(config_.codec_settings); | 187 PrintCodecSettings(config_.codec_settings); |
| 193 printf("\n"); | 188 printf("\n"); |
| 194 } | 189 } |
| 195 } | 190 } |
| 196 | 191 |
| 197 bool VideoProcessor::ProcessFrame(int frame_number) { | 192 bool VideoProcessor::ProcessFrame(int frame_number) { |
| 198 RTC_DCHECK_GE(frame_number, 0); | 193 RTC_DCHECK_GE(frame_number, 0); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 if (frame_stat->encode_return_code != WEBRTC_VIDEO_CODEC_OK) { | 230 if (frame_stat->encode_return_code != WEBRTC_VIDEO_CODEC_OK) { |
| 236 LOG(LS_WARNING) << "Failed to encode frame " << frame_number | 231 LOG(LS_WARNING) << "Failed to encode frame " << frame_number |
| 237 << ", return code: " << frame_stat->encode_return_code | 232 << ", return code: " << frame_stat->encode_return_code |
| 238 << "."; | 233 << "."; |
| 239 } | 234 } |
| 240 | 235 |
| 241 return true; | 236 return true; |
| 242 } | 237 } |
| 243 | 238 |
| 244 void VideoProcessor::SetRates(int bit_rate, int frame_rate) { | 239 void VideoProcessor::SetRates(int bit_rate, int frame_rate) { |
| 245 config_.codec_settings->maxFramerate = frame_rate; | 240 config_.codec_settings.maxFramerate = frame_rate; |
| 246 int set_rates_result = encoder_->SetRateAllocation( | 241 int set_rates_result = encoder_->SetRateAllocation( |
| 247 bitrate_allocator_->GetAllocation(bit_rate * 1000, frame_rate), | 242 bitrate_allocator_->GetAllocation(bit_rate * 1000, frame_rate), |
| 248 frame_rate); | 243 frame_rate); |
| 249 RTC_DCHECK_GE(set_rates_result, 0) | 244 RTC_DCHECK_GE(set_rates_result, 0) |
| 250 << "Failed to update encoder with new rate " << bit_rate; | 245 << "Failed to update encoder with new rate " << bit_rate; |
| 251 num_dropped_frames_ = 0; | 246 num_dropped_frames_ = 0; |
| 252 num_spatial_resizes_ = 0; | 247 num_spatial_resizes_ = 0; |
| 253 } | 248 } |
| 254 | 249 |
| 255 size_t VideoProcessor::EncodedFrameSize(int frame_number) { | 250 size_t VideoProcessor::EncodedFrameSize(int frame_number) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 } | 336 } |
| 342 FrameStatistic* frame_stat = &stats_->stats_[frame_number]; | 337 FrameStatistic* frame_stat = &stats_->stats_[frame_number]; |
| 343 frame_stat->encode_time_in_us = | 338 frame_stat->encode_time_in_us = |
| 344 GetElapsedTimeMicroseconds(frame_info->encode_start_ns, encode_stop_ns); | 339 GetElapsedTimeMicroseconds(frame_info->encode_start_ns, encode_stop_ns); |
| 345 frame_stat->encoding_successful = true; | 340 frame_stat->encoding_successful = true; |
| 346 frame_stat->encoded_frame_length_in_bytes = encoded_image._length; | 341 frame_stat->encoded_frame_length_in_bytes = encoded_image._length; |
| 347 frame_stat->frame_number = frame_number; | 342 frame_stat->frame_number = frame_number; |
| 348 frame_stat->frame_type = encoded_image._frameType; | 343 frame_stat->frame_type = encoded_image._frameType; |
| 349 frame_stat->qp = encoded_image.qp_; | 344 frame_stat->qp = encoded_image.qp_; |
| 350 frame_stat->bit_rate_in_kbps = static_cast<int>( | 345 frame_stat->bit_rate_in_kbps = static_cast<int>( |
| 351 encoded_image._length * config_.codec_settings->maxFramerate * 8 / 1000); | 346 encoded_image._length * config_.codec_settings.maxFramerate * 8 / 1000); |
| 352 frame_stat->total_packets = | 347 frame_stat->total_packets = |
| 353 encoded_image._length / config_.networking_config.packet_size_in_bytes + | 348 encoded_image._length / config_.networking_config.packet_size_in_bytes + |
| 354 1; | 349 1; |
| 355 | 350 |
| 356 // Simulate packet loss. | 351 // Simulate packet loss. |
| 357 bool exclude_this_frame = false; | 352 bool exclude_this_frame = false; |
| 358 if (encoded_image._frameType == kVideoFrameKey) { | 353 if (encoded_image._frameType == kVideoFrameKey) { |
| 359 // Only keyframes can be excluded. | 354 // Only keyframes can be excluded. |
| 360 switch (config_.exclude_frame_types) { | 355 switch (config_.exclude_frame_types) { |
| 361 case kExcludeOnlyFirstKeyFrame: | 356 case kExcludeOnlyFirstKeyFrame: |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 } | 441 } |
| 447 // Ensure strict monotonicity. | 442 // Ensure strict monotonicity. |
| 448 RTC_CHECK_GT(frame_number, last_decoded_frame_num_); | 443 RTC_CHECK_GT(frame_number, last_decoded_frame_num_); |
| 449 last_decoded_frame_num_ = frame_number; | 444 last_decoded_frame_num_ = frame_number; |
| 450 | 445 |
| 451 // Check if codec size is different from the original size, and if so, | 446 // Check if codec size is different from the original size, and if so, |
| 452 // scale back to original size. This is needed for the PSNR and SSIM | 447 // scale back to original size. This is needed for the PSNR and SSIM |
| 453 // calculations. | 448 // calculations. |
| 454 size_t extracted_length; | 449 size_t extracted_length; |
| 455 rtc::Buffer extracted_buffer; | 450 rtc::Buffer extracted_buffer; |
| 456 if (image.width() != config_.codec_settings->width || | 451 if (image.width() != config_.codec_settings.width || |
| 457 image.height() != config_.codec_settings->height) { | 452 image.height() != config_.codec_settings.height) { |
| 458 rtc::scoped_refptr<I420Buffer> scaled_buffer(I420Buffer::Create( | 453 rtc::scoped_refptr<I420Buffer> scaled_buffer(I420Buffer::Create( |
| 459 config_.codec_settings->width, config_.codec_settings->height)); | 454 config_.codec_settings.width, config_.codec_settings.height)); |
| 460 // Should be the same aspect ratio, no cropping needed. | 455 // Should be the same aspect ratio, no cropping needed. |
| 461 scaled_buffer->ScaleFrom(*image.video_frame_buffer()->ToI420()); | 456 scaled_buffer->ScaleFrom(*image.video_frame_buffer()->ToI420()); |
| 462 | 457 |
| 463 size_t length = CalcBufferSize(VideoType::kI420, scaled_buffer->width(), | 458 size_t length = CalcBufferSize(VideoType::kI420, scaled_buffer->width(), |
| 464 scaled_buffer->height()); | 459 scaled_buffer->height()); |
| 465 extracted_buffer.SetSize(length); | 460 extracted_buffer.SetSize(length); |
| 466 extracted_length = | 461 extracted_length = |
| 467 ExtractBuffer(scaled_buffer, length, extracted_buffer.data()); | 462 ExtractBuffer(scaled_buffer, length, extracted_buffer.data()); |
| 468 } else { | 463 } else { |
| 469 // No resize. | 464 // No resize. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 480 RTC_DCHECK_EQ(extracted_length, decoded_frame_writer_->FrameLength()); | 475 RTC_DCHECK_EQ(extracted_length, decoded_frame_writer_->FrameLength()); |
| 481 RTC_CHECK(decoded_frame_writer_->WriteFrame(extracted_buffer.data())); | 476 RTC_CHECK(decoded_frame_writer_->WriteFrame(extracted_buffer.data())); |
| 482 } | 477 } |
| 483 | 478 |
| 484 last_decoded_frame_buffer_ = std::move(extracted_buffer); | 479 last_decoded_frame_buffer_ = std::move(extracted_buffer); |
| 485 } | 480 } |
| 486 | 481 |
| 487 uint32_t VideoProcessor::FrameNumberToTimestamp(int frame_number) { | 482 uint32_t VideoProcessor::FrameNumberToTimestamp(int frame_number) { |
| 488 RTC_DCHECK_GE(frame_number, 0); | 483 RTC_DCHECK_GE(frame_number, 0); |
| 489 const int ticks_per_frame = | 484 const int ticks_per_frame = |
| 490 kRtpClockRateHz / config_.codec_settings->maxFramerate; | 485 kRtpClockRateHz / config_.codec_settings.maxFramerate; |
| 491 return (frame_number + 1) * ticks_per_frame; | 486 return (frame_number + 1) * ticks_per_frame; |
| 492 } | 487 } |
| 493 | 488 |
| 494 int VideoProcessor::TimestampToFrameNumber(uint32_t timestamp) { | 489 int VideoProcessor::TimestampToFrameNumber(uint32_t timestamp) { |
| 495 RTC_DCHECK_GT(timestamp, 0); | 490 RTC_DCHECK_GT(timestamp, 0); |
| 496 const int ticks_per_frame = | 491 const int ticks_per_frame = |
| 497 kRtpClockRateHz / config_.codec_settings->maxFramerate; | 492 kRtpClockRateHz / config_.codec_settings.maxFramerate; |
| 498 RTC_DCHECK_EQ(timestamp % ticks_per_frame, 0); | 493 RTC_DCHECK_EQ(timestamp % ticks_per_frame, 0); |
| 499 return (timestamp / ticks_per_frame) - 1; | 494 return (timestamp / ticks_per_frame) - 1; |
| 500 } | 495 } |
| 501 | 496 |
| 502 } // namespace test | 497 } // namespace test |
| 503 } // namespace webrtc | 498 } // namespace webrtc |
| OLD | NEW |