Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: webrtc/video/vie_encoder.cc

Issue 2531383002: Wire up BitrateAllocation to be sent as RTCP TargetBitrate (Closed)
Patch Set: Simulcast fix Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« webrtc/video/end_to_end_tests.cc ('K') | « webrtc/video/vie_encoder.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/modules/video_coding/include/video_codec_initializer.h" 17 #include "webrtc/modules/video_coding/include/video_codec_initializer.h"
18 #include "webrtc/base/checks.h" 18 #include "webrtc/base/checks.h"
19 #include "webrtc/base/logging.h" 19 #include "webrtc/base/logging.h"
20 #include "webrtc/base/trace_event.h" 20 #include "webrtc/base/trace_event.h"
21 #include "webrtc/base/timeutils.h" 21 #include "webrtc/base/timeutils.h"
22 #include "webrtc/common_video/include/video_bitrate_allocator.h"
22 #include "webrtc/modules/pacing/paced_sender.h" 23 #include "webrtc/modules/pacing/paced_sender.h"
23 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" 24 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h"
24 #include "webrtc/modules/video_coding/include/video_coding.h" 25 #include "webrtc/modules/video_coding/include/video_coding.h"
25 #include "webrtc/modules/video_coding/include/video_coding_defines.h" 26 #include "webrtc/modules/video_coding/include/video_coding_defines.h"
26 #include "webrtc/video/overuse_frame_detector.h" 27 #include "webrtc/video/overuse_frame_detector.h"
27 #include "webrtc/video/send_statistics_proxy.h" 28 #include "webrtc/video/send_statistics_proxy.h"
28 #include "webrtc/video_frame.h" 29 #include "webrtc/video_frame.h"
29
30 namespace webrtc { 30 namespace webrtc {
31 31
32 namespace { 32 namespace {
33 // Time interval for logging frame counts. 33 // Time interval for logging frame counts.
34 const int64_t kFrameLogIntervalMs = 60000; 34 const int64_t kFrameLogIntervalMs = 60000;
35 35
36 // TODO(pbos): Lower these thresholds (to closer to 100%) when we handle 36 // TODO(pbos): Lower these thresholds (to closer to 100%) when we handle
37 // pipelining encoders better (multiple input frames before something comes 37 // pipelining encoders better (multiple input frames before something comes
38 // out). This should effectively turn off CPU adaptations for systems that 38 // out). This should effectively turn off CPU adaptations for systems that
39 // remotely cope with the load right now. 39 // remotely cope with the load right now.
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 VideoSendStream::DegradationPreference::kBalanced), 261 VideoSendStream::DegradationPreference::kBalanced),
262 cpu_restricted_counter_(0), 262 cpu_restricted_counter_(0),
263 last_frame_width_(0), 263 last_frame_width_(0),
264 last_frame_height_(0), 264 last_frame_height_(0),
265 last_captured_timestamp_(0), 265 last_captured_timestamp_(0),
266 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - 266 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() -
267 clock_->TimeInMilliseconds()), 267 clock_->TimeInMilliseconds()),
268 last_frame_log_ms_(clock_->TimeInMilliseconds()), 268 last_frame_log_ms_(clock_->TimeInMilliseconds()),
269 captured_frame_count_(0), 269 captured_frame_count_(0),
270 dropped_frame_count_(0), 270 dropped_frame_count_(0),
271 bitrate_observer_(nullptr),
271 encoder_queue_("EncoderQueue") { 272 encoder_queue_("EncoderQueue") {
272 encoder_queue_.PostTask([this] { 273 encoder_queue_.PostTask([this] {
273 RTC_DCHECK_RUN_ON(&encoder_queue_); 274 RTC_DCHECK_RUN_ON(&encoder_queue_);
274 overuse_detector_.StartCheckForOveruse(); 275 overuse_detector_.StartCheckForOveruse();
275 video_sender_.RegisterExternalEncoder( 276 video_sender_.RegisterExternalEncoder(
276 settings_.encoder, settings_.payload_type, settings_.internal_source); 277 settings_.encoder, settings_.payload_type, settings_.internal_source);
277 }); 278 });
278 } 279 }
279 280
280 ViEEncoder::~ViEEncoder() { 281 ViEEncoder::~ViEEncoder() {
281 RTC_DCHECK_RUN_ON(&thread_checker_); 282 RTC_DCHECK_RUN_ON(&thread_checker_);
282 RTC_DCHECK(shutdown_event_.Wait(0)) 283 RTC_DCHECK(shutdown_event_.Wait(0))
283 << "Must call ::Stop() before destruction."; 284 << "Must call ::Stop() before destruction.";
284 } 285 }
285 286
286 void ViEEncoder::Stop() { 287 void ViEEncoder::Stop() {
287 RTC_DCHECK_RUN_ON(&thread_checker_); 288 RTC_DCHECK_RUN_ON(&thread_checker_);
288 source_proxy_->SetSource(nullptr, VideoSendStream::DegradationPreference()); 289 source_proxy_->SetSource(nullptr, VideoSendStream::DegradationPreference());
289 encoder_queue_.PostTask([this] { 290 encoder_queue_.PostTask([this] {
290 RTC_DCHECK_RUN_ON(&encoder_queue_); 291 RTC_DCHECK_RUN_ON(&encoder_queue_);
291 overuse_detector_.StopCheckForOveruse(); 292 overuse_detector_.StopCheckForOveruse();
292 rate_allocator_.reset(); 293 rate_allocator_.reset();
294 bitrate_observer_ = nullptr;
293 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type, 295 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type,
294 false); 296 false);
295 shutdown_event_.Set(); 297 shutdown_event_.Set();
296 }); 298 });
297 299
298 shutdown_event_.Wait(rtc::Event::kForever); 300 shutdown_event_.Wait(rtc::Event::kForever);
299 } 301 }
300 302
301 void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) { 303 void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) {
302 RTC_DCHECK_RUN_ON(&thread_checker_); 304 RTC_DCHECK_RUN_ON(&thread_checker_);
303 RTC_DCHECK(!module_process_thread_); 305 RTC_DCHECK(!module_process_thread_);
304 module_process_thread_ = module_process_thread; 306 module_process_thread_ = module_process_thread;
305 module_process_thread_->RegisterModule(&video_sender_); 307 module_process_thread_->RegisterModule(&video_sender_);
306 module_process_thread_checker_.DetachFromThread(); 308 module_process_thread_checker_.DetachFromThread();
307 } 309 }
308 310
309 void ViEEncoder::DeRegisterProcessThread() { 311 void ViEEncoder::DeRegisterProcessThread() {
310 RTC_DCHECK_RUN_ON(&thread_checker_); 312 RTC_DCHECK_RUN_ON(&thread_checker_);
311 module_process_thread_->DeRegisterModule(&video_sender_); 313 module_process_thread_->DeRegisterModule(&video_sender_);
312 } 314 }
313 315
316 void ViEEncoder::SetBitrateObserver(
317 VideoBitrateAllocationObserver* bitrate_observer) {
318 RTC_DCHECK_RUN_ON(&thread_checker_);
319 encoder_queue_.PostTask([this, bitrate_observer] {
320 RTC_DCHECK_RUN_ON(&encoder_queue_);
321 RTC_DCHECK(!bitrate_observer_);
322 bitrate_observer_ = bitrate_observer;
323 });
324 }
325
314 void ViEEncoder::SetSource( 326 void ViEEncoder::SetSource(
315 rtc::VideoSourceInterface<VideoFrame>* source, 327 rtc::VideoSourceInterface<VideoFrame>* source,
316 const VideoSendStream::DegradationPreference& degradation_preference) { 328 const VideoSendStream::DegradationPreference& degradation_preference) {
317 RTC_DCHECK_RUN_ON(&thread_checker_); 329 RTC_DCHECK_RUN_ON(&thread_checker_);
318 source_proxy_->SetSource(source, degradation_preference); 330 source_proxy_->SetSource(source, degradation_preference);
319 encoder_queue_.PostTask([this, degradation_preference] { 331 encoder_queue_.PostTask([this, degradation_preference] {
320 RTC_DCHECK_RUN_ON(&encoder_queue_); 332 RTC_DCHECK_RUN_ON(&encoder_queue_);
321 degradation_preference_ = degradation_preference; 333 degradation_preference_ = degradation_preference;
322 // Set the stats for if we are currently CPU restricted. We are CPU 334 // Set the stats for if we are currently CPU restricted. We are CPU
323 // restricted depending on degradation preference and 335 // restricted depending on degradation preference and
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 codec.expect_encode_from_texture = last_frame_info_->is_texture; 412 codec.expect_encode_from_texture = last_frame_info_->is_texture;
401 413
402 bool success = video_sender_.RegisterSendCodec( 414 bool success = video_sender_.RegisterSendCodec(
403 &codec, number_of_cores_, 415 &codec, number_of_cores_,
404 static_cast<uint32_t>(max_data_payload_length_)) == VCM_OK; 416 static_cast<uint32_t>(max_data_payload_length_)) == VCM_OK;
405 if (!success) { 417 if (!success) {
406 LOG(LS_ERROR) << "Failed to configure encoder."; 418 LOG(LS_ERROR) << "Failed to configure encoder.";
407 RTC_DCHECK(success); 419 RTC_DCHECK(success);
408 } 420 }
409 421
410 video_sender_.UpdateChannelParemeters(rate_allocator_.get()); 422 video_sender_.UpdateChannelParemeters(rate_allocator_.get(),
423 bitrate_observer_);
411 if (stats_proxy_) { 424 if (stats_proxy_) {
412 int framerate = stats_proxy_->GetSendFrameRate(); 425 int framerate = stats_proxy_->GetSendFrameRate();
413 if (framerate == 0) 426 if (framerate == 0)
414 framerate = codec.maxFramerate; 427 framerate = codec.maxFramerate;
415 stats_proxy_->OnEncoderReconfigured( 428 stats_proxy_->OnEncoderReconfigured(
416 encoder_config_, rate_allocator_->GetPreferredBitrateBps(framerate)); 429 encoder_config_, rate_allocator_->GetPreferredBitrateBps(framerate));
417 } 430 }
418 431
419 pending_encoder_reconfiguration_ = false; 432 pending_encoder_reconfiguration_ = false;
420 433
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 return; 645 return;
633 } 646 }
634 RTC_DCHECK_RUN_ON(&encoder_queue_); 647 RTC_DCHECK_RUN_ON(&encoder_queue_);
635 RTC_DCHECK(sink_) << "sink_ must be set before the encoder is active."; 648 RTC_DCHECK(sink_) << "sink_ must be set before the encoder is active.";
636 649
637 LOG(LS_VERBOSE) << "OnBitrateUpdated, bitrate " << bitrate_bps 650 LOG(LS_VERBOSE) << "OnBitrateUpdated, bitrate " << bitrate_bps
638 << " packet loss " << static_cast<int>(fraction_lost) 651 << " packet loss " << static_cast<int>(fraction_lost)
639 << " rtt " << round_trip_time_ms; 652 << " rtt " << round_trip_time_ms;
640 653
641 video_sender_.SetChannelParameters(bitrate_bps, fraction_lost, 654 video_sender_.SetChannelParameters(bitrate_bps, fraction_lost,
642 round_trip_time_ms, rate_allocator_.get()); 655 round_trip_time_ms, rate_allocator_.get(),
656 bitrate_observer_);
643 657
644 encoder_start_bitrate_bps_ = 658 encoder_start_bitrate_bps_ =
645 bitrate_bps != 0 ? bitrate_bps : encoder_start_bitrate_bps_; 659 bitrate_bps != 0 ? bitrate_bps : encoder_start_bitrate_bps_;
646 bool video_is_suspended = bitrate_bps == 0; 660 bool video_is_suspended = bitrate_bps == 0;
647 bool video_suspension_changed = video_is_suspended != EncoderPaused(); 661 bool video_suspension_changed = video_is_suspended != EncoderPaused();
648 last_observed_bitrate_bps_ = bitrate_bps; 662 last_observed_bitrate_bps_ = bitrate_bps;
649 663
650 if (stats_proxy_ && video_suspension_changed) { 664 if (stats_proxy_ && video_suspension_changed) {
651 LOG(LS_INFO) << "Video suspend state changed to: " 665 LOG(LS_INFO) << "Video suspend state changed to: "
652 << (video_is_suspended ? "suspended" : "not suspended"); 666 << (video_is_suspended ? "suspended" : "not suspended");
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 current_pixel_count > *max_pixel_count_step_up_) { 706 current_pixel_count > *max_pixel_count_step_up_) {
693 max_pixel_count_ = rtc::Optional<int>(); 707 max_pixel_count_ = rtc::Optional<int>();
694 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count); 708 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count);
695 --cpu_restricted_counter_; 709 --cpu_restricted_counter_;
696 stats_proxy_->OnCpuRestrictedResolutionChanged(cpu_restricted_counter_ > 0); 710 stats_proxy_->OnCpuRestrictedResolutionChanged(cpu_restricted_counter_ > 0);
697 source_proxy_->RequestHigherResolutionThan(current_pixel_count); 711 source_proxy_->RequestHigherResolutionThan(current_pixel_count);
698 } 712 }
699 } 713 }
700 714
701 } // namespace webrtc 715 } // namespace webrtc
OLDNEW
« webrtc/video/end_to_end_tests.cc ('K') | « webrtc/video/vie_encoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698