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 "webrtc/video/vie_encoder.h" | 11 #include "webrtc/video/vie_encoder.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <limits> | 14 #include <limits> |
15 #include <utility> | 15 #include <utility> |
16 | 16 |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
18 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" |
19 #include "webrtc/base/trace_event.h" | 19 #include "webrtc/base/trace_event.h" |
20 #include "webrtc/base/timeutils.h" | 20 #include "webrtc/base/timeutils.h" |
21 #include "webrtc/modules/pacing/paced_sender.h" | 21 #include "webrtc/modules/pacing/paced_sender.h" |
22 #include "webrtc/modules/video_coding/include/video_bitrate_allocator_factory.h" | |
22 #include "webrtc/modules/video_coding/include/video_coding.h" | 23 #include "webrtc/modules/video_coding/include/video_coding.h" |
23 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | 24 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
24 #include "webrtc/video/overuse_frame_detector.h" | 25 #include "webrtc/video/overuse_frame_detector.h" |
25 #include "webrtc/video/send_statistics_proxy.h" | 26 #include "webrtc/video/send_statistics_proxy.h" |
26 #include "webrtc/video_frame.h" | 27 #include "webrtc/video_frame.h" |
27 | 28 |
28 namespace webrtc { | 29 namespace webrtc { |
29 | 30 |
30 namespace { | 31 namespace { |
31 // Time interval for logging frame counts. | 32 // Time interval for logging frame counts. |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 RTC_DCHECK_RUN_ON(&thread_checker_); | 345 RTC_DCHECK_RUN_ON(&thread_checker_); |
345 RTC_DCHECK(shutdown_event_.Wait(0)) | 346 RTC_DCHECK(shutdown_event_.Wait(0)) |
346 << "Must call ::Stop() before destruction."; | 347 << "Must call ::Stop() before destruction."; |
347 } | 348 } |
348 | 349 |
349 void ViEEncoder::Stop() { | 350 void ViEEncoder::Stop() { |
350 RTC_DCHECK_RUN_ON(&thread_checker_); | 351 RTC_DCHECK_RUN_ON(&thread_checker_); |
351 source_proxy_->SetSource(nullptr); | 352 source_proxy_->SetSource(nullptr); |
352 encoder_queue_.PostTask([this] { | 353 encoder_queue_.PostTask([this] { |
353 RTC_DCHECK_RUN_ON(&encoder_queue_); | 354 RTC_DCHECK_RUN_ON(&encoder_queue_); |
355 rate_allocator_.reset(); | |
354 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type, | 356 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type, |
355 false); | 357 false); |
356 overuse_detector_.StopCheckForOveruse(); | 358 overuse_detector_.StopCheckForOveruse(); |
357 shutdown_event_.Set(); | 359 shutdown_event_.Set(); |
358 }); | 360 }); |
359 | 361 |
360 shutdown_event_.Wait(rtc::Event::kForever); | 362 shutdown_event_.Wait(rtc::Event::kForever); |
361 } | 363 } |
362 | 364 |
363 void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) { | 365 void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
431 last_frame_info_->width, last_frame_info_->height, encoder_config_); | 433 last_frame_info_->width, last_frame_info_->height, encoder_config_); |
432 | 434 |
433 VideoCodec codec = VideoEncoderConfigToVideoCodec( | 435 VideoCodec codec = VideoEncoderConfigToVideoCodec( |
434 encoder_config_, streams, settings_.payload_name, settings_.payload_type); | 436 encoder_config_, streams, settings_.payload_name, settings_.payload_type); |
435 | 437 |
436 codec.startBitrate = | 438 codec.startBitrate = |
437 std::max(encoder_start_bitrate_bps_ / 1000, codec.minBitrate); | 439 std::max(encoder_start_bitrate_bps_ / 1000, codec.minBitrate); |
438 codec.startBitrate = std::min(codec.startBitrate, codec.maxBitrate); | 440 codec.startBitrate = std::min(codec.startBitrate, codec.maxBitrate); |
439 codec.expect_encode_from_texture = last_frame_info_->is_texture; | 441 codec.expect_encode_from_texture = last_frame_info_->is_texture; |
440 | 442 |
443 rate_allocator_ = VideoBitrateAllocatorFactory::GetBitrateAllocator(&codec); | |
perkj_webrtc
2016/10/25 11:02:27
This looks much better I think.
But one more ques
sprang_webrtc
2016/10/25 11:43:03
Hm, I'm not sure. It'll become a little messy beca
| |
444 | |
441 bool success = video_sender_.RegisterSendCodec( | 445 bool success = video_sender_.RegisterSendCodec( |
442 &codec, number_of_cores_, | 446 &codec, number_of_cores_, |
443 static_cast<uint32_t>(max_data_payload_length_)) == VCM_OK; | 447 static_cast<uint32_t>(max_data_payload_length_)) == VCM_OK; |
444 if (!success) { | 448 if (!success) { |
445 LOG(LS_ERROR) << "Failed to configure encoder."; | 449 LOG(LS_ERROR) << "Failed to configure encoder."; |
446 RTC_DCHECK(success); | 450 RTC_DCHECK(success); |
447 } | 451 } |
448 | 452 |
449 rate_allocator_.reset(new SimulcastRateAllocator(codec)); | |
450 if (stats_proxy_) { | 453 if (stats_proxy_) { |
451 stats_proxy_->OnEncoderReconfigured(encoder_config_, | 454 int frame_rate = stats_proxy_->GetSendFrameRate(); |
452 rate_allocator_->GetPreferedBitrate()); | 455 if (frame_rate == 0) |
456 frame_rate = codec.maxFramerate; | |
457 stats_proxy_->OnEncoderReconfigured( | |
458 encoder_config_, rate_allocator_->GetPreferedBitrate(frame_rate)); | |
453 } | 459 } |
454 | 460 |
455 pending_encoder_reconfiguration_ = false; | 461 pending_encoder_reconfiguration_ = false; |
456 if (stats_proxy_) { | 462 |
457 stats_proxy_->OnEncoderReconfigured(encoder_config_, | |
458 rate_allocator_->GetPreferedBitrate()); | |
459 } | |
460 sink_->OnEncoderConfigurationChanged( | 463 sink_->OnEncoderConfigurationChanged( |
461 std::move(streams), encoder_config_.min_transmit_bitrate_bps); | 464 std::move(streams), encoder_config_.min_transmit_bitrate_bps); |
462 } | 465 } |
463 | 466 |
464 void ViEEncoder::OnFrame(const VideoFrame& video_frame) { | 467 void ViEEncoder::OnFrame(const VideoFrame& video_frame) { |
465 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); | 468 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); |
466 stats_proxy_->OnIncomingFrame(video_frame.width(), video_frame.height()); | 469 stats_proxy_->OnIncomingFrame(video_frame.width(), video_frame.height()); |
467 | 470 |
468 VideoFrame incoming_frame = video_frame; | 471 VideoFrame incoming_frame = video_frame; |
469 | 472 |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
672 return; | 675 return; |
673 } | 676 } |
674 RTC_DCHECK_RUN_ON(&encoder_queue_); | 677 RTC_DCHECK_RUN_ON(&encoder_queue_); |
675 RTC_DCHECK(sink_) << "sink_ must be set before the encoder is active."; | 678 RTC_DCHECK(sink_) << "sink_ must be set before the encoder is active."; |
676 | 679 |
677 LOG(LS_VERBOSE) << "OnBitrateUpdated, bitrate " << bitrate_bps | 680 LOG(LS_VERBOSE) << "OnBitrateUpdated, bitrate " << bitrate_bps |
678 << " packet loss " << static_cast<int>(fraction_lost) | 681 << " packet loss " << static_cast<int>(fraction_lost) |
679 << " rtt " << round_trip_time_ms; | 682 << " rtt " << round_trip_time_ms; |
680 | 683 |
681 video_sender_.SetChannelParameters(bitrate_bps, fraction_lost, | 684 video_sender_.SetChannelParameters(bitrate_bps, fraction_lost, |
682 round_trip_time_ms); | 685 round_trip_time_ms, rate_allocator_.get()); |
683 | 686 |
684 encoder_start_bitrate_bps_ = | 687 encoder_start_bitrate_bps_ = |
685 bitrate_bps != 0 ? bitrate_bps : encoder_start_bitrate_bps_; | 688 bitrate_bps != 0 ? bitrate_bps : encoder_start_bitrate_bps_; |
686 bool video_is_suspended = bitrate_bps == 0; | 689 bool video_is_suspended = bitrate_bps == 0; |
687 bool video_suspension_changed = | 690 bool video_suspension_changed = |
688 video_is_suspended != (last_observed_bitrate_bps_ == 0); | 691 video_is_suspended != (last_observed_bitrate_bps_ == 0); |
689 last_observed_bitrate_bps_ = bitrate_bps; | 692 last_observed_bitrate_bps_ = bitrate_bps; |
690 | 693 |
691 if (stats_proxy_ && video_suspension_changed) { | 694 if (stats_proxy_ && video_suspension_changed) { |
692 LOG(LS_INFO) << "Video suspend state changed to: " | 695 LOG(LS_INFO) << "Video suspend state changed to: " |
(...skipping 11 matching lines...) Expand all Loading... | |
704 load_observer_->OnLoadUpdate(LoadObserver::kOveruse); | 707 load_observer_->OnLoadUpdate(LoadObserver::kOveruse); |
705 } | 708 } |
706 | 709 |
707 void ViEEncoder::NormalUsage() { | 710 void ViEEncoder::NormalUsage() { |
708 RTC_DCHECK_RUN_ON(&encoder_queue_); | 711 RTC_DCHECK_RUN_ON(&encoder_queue_); |
709 if (load_observer_) | 712 if (load_observer_) |
710 load_observer_->OnLoadUpdate(LoadObserver::kUnderuse); | 713 load_observer_->OnLoadUpdate(LoadObserver::kUnderuse); |
711 } | 714 } |
712 | 715 |
713 } // namespace webrtc | 716 } // namespace webrtc |
OLD | NEW |