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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 scale_counter_(kScaleReasonSize, 0), | 286 scale_counter_(kScaleReasonSize, 0), |
287 degradation_preference_(DegradationPreference::kMaintainResolution), | 287 degradation_preference_(DegradationPreference::kMaintainResolution), |
288 last_captured_timestamp_(0), | 288 last_captured_timestamp_(0), |
289 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - | 289 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - |
290 clock_->TimeInMilliseconds()), | 290 clock_->TimeInMilliseconds()), |
291 last_frame_log_ms_(clock_->TimeInMilliseconds()), | 291 last_frame_log_ms_(clock_->TimeInMilliseconds()), |
292 captured_frame_count_(0), | 292 captured_frame_count_(0), |
293 dropped_frame_count_(0), | 293 dropped_frame_count_(0), |
294 bitrate_observer_(nullptr), | 294 bitrate_observer_(nullptr), |
295 encoder_queue_("EncoderQueue") { | 295 encoder_queue_("EncoderQueue") { |
| 296 RTC_DCHECK(stats_proxy); |
296 encoder_queue_.PostTask([this] { | 297 encoder_queue_.PostTask([this] { |
297 RTC_DCHECK_RUN_ON(&encoder_queue_); | 298 RTC_DCHECK_RUN_ON(&encoder_queue_); |
298 overuse_detector_.StartCheckForOveruse(); | 299 overuse_detector_.StartCheckForOveruse(); |
299 video_sender_.RegisterExternalEncoder( | 300 video_sender_.RegisterExternalEncoder( |
300 settings_.encoder, settings_.payload_type, settings_.internal_source); | 301 settings_.encoder, settings_.payload_type, settings_.internal_source); |
301 }); | 302 }); |
302 } | 303 } |
303 | 304 |
304 ViEEncoder::~ViEEncoder() { | 305 ViEEncoder::~ViEEncoder() { |
305 RTC_DCHECK_RUN_ON(&thread_checker_); | 306 RTC_DCHECK_RUN_ON(&thread_checker_); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 &codec, number_of_cores_, | 436 &codec, number_of_cores_, |
436 static_cast<uint32_t>(max_data_payload_length_)) == VCM_OK; | 437 static_cast<uint32_t>(max_data_payload_length_)) == VCM_OK; |
437 if (!success) { | 438 if (!success) { |
438 LOG(LS_ERROR) << "Failed to configure encoder."; | 439 LOG(LS_ERROR) << "Failed to configure encoder."; |
439 RTC_DCHECK(success); | 440 RTC_DCHECK(success); |
440 } | 441 } |
441 | 442 |
442 video_sender_.UpdateChannelParemeters(rate_allocator_.get(), | 443 video_sender_.UpdateChannelParemeters(rate_allocator_.get(), |
443 bitrate_observer_); | 444 bitrate_observer_); |
444 | 445 |
445 if (stats_proxy_) { | 446 int framerate = stats_proxy_->GetSendFrameRate(); |
446 int framerate = stats_proxy_->GetSendFrameRate(); | 447 if (framerate == 0) |
447 if (framerate == 0) | 448 framerate = codec.maxFramerate; |
448 framerate = codec.maxFramerate; | 449 stats_proxy_->OnEncoderReconfigured( |
449 stats_proxy_->OnEncoderReconfigured( | 450 encoder_config_, rate_allocator_->GetPreferredBitrateBps(framerate)); |
450 encoder_config_, rate_allocator_->GetPreferredBitrateBps(framerate)); | |
451 } | |
452 | 451 |
453 pending_encoder_reconfiguration_ = false; | 452 pending_encoder_reconfiguration_ = false; |
454 | 453 |
455 sink_->OnEncoderConfigurationChanged( | 454 sink_->OnEncoderConfigurationChanged( |
456 std::move(streams), encoder_config_.min_transmit_bitrate_bps); | 455 std::move(streams), encoder_config_.min_transmit_bitrate_bps); |
457 | 456 |
458 ConfigureQualityScaler(); | 457 ConfigureQualityScaler(); |
459 } | 458 } |
460 | 459 |
461 void ViEEncoder::ConfigureQualityScaler() { | 460 void ViEEncoder::ConfigureQualityScaler() { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 video_sender_.IntraFrameRequest(0); | 632 video_sender_.IntraFrameRequest(0); |
634 } | 633 } |
635 | 634 |
636 EncodedImageCallback::Result ViEEncoder::OnEncodedImage( | 635 EncodedImageCallback::Result ViEEncoder::OnEncodedImage( |
637 const EncodedImage& encoded_image, | 636 const EncodedImage& encoded_image, |
638 const CodecSpecificInfo* codec_specific_info, | 637 const CodecSpecificInfo* codec_specific_info, |
639 const RTPFragmentationHeader* fragmentation) { | 638 const RTPFragmentationHeader* fragmentation) { |
640 // Encoded is called on whatever thread the real encoder implementation run | 639 // Encoded is called on whatever thread the real encoder implementation run |
641 // on. In the case of hardware encoders, there might be several encoders | 640 // on. In the case of hardware encoders, there might be several encoders |
642 // running in parallel on different threads. | 641 // running in parallel on different threads. |
643 if (stats_proxy_) | 642 stats_proxy_->OnSendEncodedImage(encoded_image, codec_specific_info); |
644 stats_proxy_->OnSendEncodedImage(encoded_image, codec_specific_info); | |
645 | 643 |
646 EncodedImageCallback::Result result = | 644 EncodedImageCallback::Result result = |
647 sink_->OnEncodedImage(encoded_image, codec_specific_info, fragmentation); | 645 sink_->OnEncodedImage(encoded_image, codec_specific_info, fragmentation); |
648 | 646 |
649 int64_t time_sent_us = rtc::TimeMicros(); | 647 int64_t time_sent_us = rtc::TimeMicros(); |
650 uint32_t timestamp = encoded_image._timeStamp; | 648 uint32_t timestamp = encoded_image._timeStamp; |
651 const int qp = encoded_image.qp_; | 649 const int qp = encoded_image.qp_; |
652 encoder_queue_.PostTask([this, timestamp, time_sent_us, qp] { | 650 encoder_queue_.PostTask([this, timestamp, time_sent_us, qp] { |
653 RTC_DCHECK_RUN_ON(&encoder_queue_); | 651 RTC_DCHECK_RUN_ON(&encoder_queue_); |
654 overuse_detector_.FrameSent(timestamp, time_sent_us); | 652 overuse_detector_.FrameSent(timestamp, time_sent_us); |
655 if (quality_scaler_ && qp >= 0) | 653 if (quality_scaler_ && qp >= 0) |
656 quality_scaler_->ReportQP(qp); | 654 quality_scaler_->ReportQP(qp); |
657 }); | 655 }); |
658 | 656 |
659 return result; | 657 return result; |
660 } | 658 } |
661 | 659 |
662 void ViEEncoder::OnDroppedFrame() { | 660 void ViEEncoder::OnDroppedFrame() { |
663 encoder_queue_.PostTask([this] { | 661 encoder_queue_.PostTask([this] { |
664 RTC_DCHECK_RUN_ON(&encoder_queue_); | 662 RTC_DCHECK_RUN_ON(&encoder_queue_); |
665 if (quality_scaler_) | 663 if (quality_scaler_) |
666 quality_scaler_->ReportDroppedFrame(); | 664 quality_scaler_->ReportDroppedFrame(); |
667 }); | 665 }); |
668 } | 666 } |
669 | 667 |
670 void ViEEncoder::SendStatistics(uint32_t bit_rate, uint32_t frame_rate) { | 668 void ViEEncoder::SendStatistics(uint32_t bit_rate, uint32_t frame_rate) { |
671 RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread()); | 669 RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread()); |
672 if (stats_proxy_) | 670 stats_proxy_->OnEncoderStatsUpdate(frame_rate, bit_rate); |
673 stats_proxy_->OnEncoderStatsUpdate(frame_rate, bit_rate); | |
674 } | 671 } |
675 | 672 |
676 void ViEEncoder::OnReceivedSLI(uint8_t picture_id) { | 673 void ViEEncoder::OnReceivedSLI(uint8_t picture_id) { |
677 if (!encoder_queue_.IsCurrent()) { | 674 if (!encoder_queue_.IsCurrent()) { |
678 encoder_queue_.PostTask([this, picture_id] { OnReceivedSLI(picture_id); }); | 675 encoder_queue_.PostTask([this, picture_id] { OnReceivedSLI(picture_id); }); |
679 return; | 676 return; |
680 } | 677 } |
681 RTC_DCHECK_RUN_ON(&encoder_queue_); | 678 RTC_DCHECK_RUN_ON(&encoder_queue_); |
682 picture_id_sli_ = picture_id; | 679 picture_id_sli_ = picture_id; |
683 has_received_sli_ = true; | 680 has_received_sli_ = true; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 video_sender_.SetChannelParameters(bitrate_bps, fraction_lost, | 722 video_sender_.SetChannelParameters(bitrate_bps, fraction_lost, |
726 round_trip_time_ms, rate_allocator_.get(), | 723 round_trip_time_ms, rate_allocator_.get(), |
727 bitrate_observer_); | 724 bitrate_observer_); |
728 | 725 |
729 encoder_start_bitrate_bps_ = | 726 encoder_start_bitrate_bps_ = |
730 bitrate_bps != 0 ? bitrate_bps : encoder_start_bitrate_bps_; | 727 bitrate_bps != 0 ? bitrate_bps : encoder_start_bitrate_bps_; |
731 bool video_is_suspended = bitrate_bps == 0; | 728 bool video_is_suspended = bitrate_bps == 0; |
732 bool video_suspension_changed = video_is_suspended != EncoderPaused(); | 729 bool video_suspension_changed = video_is_suspended != EncoderPaused(); |
733 last_observed_bitrate_bps_ = bitrate_bps; | 730 last_observed_bitrate_bps_ = bitrate_bps; |
734 | 731 |
735 if (stats_proxy_ && video_suspension_changed) { | 732 if (video_suspension_changed) { |
736 LOG(LS_INFO) << "Video suspend state changed to: " | 733 LOG(LS_INFO) << "Video suspend state changed to: " |
737 << (video_is_suspended ? "suspended" : "not suspended"); | 734 << (video_is_suspended ? "suspended" : "not suspended"); |
738 stats_proxy_->OnSuspendChange(video_is_suspended); | 735 stats_proxy_->OnSuspendChange(video_is_suspended); |
739 } | 736 } |
740 } | 737 } |
741 | 738 |
742 void ViEEncoder::AdaptDown(AdaptReason reason) { | 739 void ViEEncoder::AdaptDown(AdaptReason reason) { |
743 RTC_DCHECK_RUN_ON(&encoder_queue_); | 740 RTC_DCHECK_RUN_ON(&encoder_queue_); |
744 if (degradation_preference_ != DegradationPreference::kBalanced || | 741 if (degradation_preference_ != DegradationPreference::kBalanced || |
745 !last_frame_info_) { | 742 !last_frame_info_) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 --scale_counter_[reason]; | 808 --scale_counter_[reason]; |
812 source_proxy_->RequestHigherResolutionThan(current_pixel_count); | 809 source_proxy_->RequestHigherResolutionThan(current_pixel_count); |
813 LOG(LS_INFO) << "Scaling up resolution."; | 810 LOG(LS_INFO) << "Scaling up resolution."; |
814 for (size_t i = 0; i < kScaleReasonSize; ++i) { | 811 for (size_t i = 0; i < kScaleReasonSize; ++i) { |
815 LOG(LS_INFO) << "Scaled " << scale_counter_[i] | 812 LOG(LS_INFO) << "Scaled " << scale_counter_[i] |
816 << " times for reason: " << (i ? "cpu" : "quality"); | 813 << " times for reason: " << (i ? "cpu" : "quality"); |
817 } | 814 } |
818 } | 815 } |
819 | 816 |
820 } // namespace webrtc | 817 } // namespace webrtc |
OLD | NEW |