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

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

Issue 2531383002: Wire up BitrateAllocation to be sent as RTCP TargetBitrate (Closed)
Patch Set: Undo crit removal 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
« no previous file with comments | « 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 picture_id_rpsi_(0), 258 picture_id_rpsi_(0),
259 clock_(Clock::GetRealTimeClock()), 259 clock_(Clock::GetRealTimeClock()),
260 last_frame_width_(0), 260 last_frame_width_(0),
261 last_frame_height_(0), 261 last_frame_height_(0),
262 last_captured_timestamp_(0), 262 last_captured_timestamp_(0),
263 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - 263 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() -
264 clock_->TimeInMilliseconds()), 264 clock_->TimeInMilliseconds()),
265 last_frame_log_ms_(clock_->TimeInMilliseconds()), 265 last_frame_log_ms_(clock_->TimeInMilliseconds()),
266 captured_frame_count_(0), 266 captured_frame_count_(0),
267 dropped_frame_count_(0), 267 dropped_frame_count_(0),
268 bitrate_observer_(nullptr),
268 encoder_queue_("EncoderQueue") { 269 encoder_queue_("EncoderQueue") {
269 encoder_queue_.PostTask([this] { 270 encoder_queue_.PostTask([this] {
270 RTC_DCHECK_RUN_ON(&encoder_queue_); 271 RTC_DCHECK_RUN_ON(&encoder_queue_);
271 overuse_detector_.StartCheckForOveruse(); 272 overuse_detector_.StartCheckForOveruse();
272 video_sender_.RegisterExternalEncoder( 273 video_sender_.RegisterExternalEncoder(
273 settings_.encoder, settings_.payload_type, settings_.internal_source); 274 settings_.encoder, settings_.payload_type, settings_.internal_source);
274 }); 275 });
275 } 276 }
276 277
277 ViEEncoder::~ViEEncoder() { 278 ViEEncoder::~ViEEncoder() {
278 RTC_DCHECK_RUN_ON(&thread_checker_); 279 RTC_DCHECK_RUN_ON(&thread_checker_);
279 RTC_DCHECK(shutdown_event_.Wait(0)) 280 RTC_DCHECK(shutdown_event_.Wait(0))
280 << "Must call ::Stop() before destruction."; 281 << "Must call ::Stop() before destruction.";
281 } 282 }
282 283
283 void ViEEncoder::Stop() { 284 void ViEEncoder::Stop() {
284 RTC_DCHECK_RUN_ON(&thread_checker_); 285 RTC_DCHECK_RUN_ON(&thread_checker_);
285 source_proxy_->SetSource(nullptr, VideoSendStream::DegradationPreference()); 286 source_proxy_->SetSource(nullptr, VideoSendStream::DegradationPreference());
286 encoder_queue_.PostTask([this] { 287 encoder_queue_.PostTask([this] {
287 RTC_DCHECK_RUN_ON(&encoder_queue_); 288 RTC_DCHECK_RUN_ON(&encoder_queue_);
288 overuse_detector_.StopCheckForOveruse(); 289 overuse_detector_.StopCheckForOveruse();
289 rate_allocator_.reset(); 290 rate_allocator_.reset();
291 bitrate_observer_ = nullptr;
290 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type, 292 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type,
291 false); 293 false);
292 quality_scaler_ = nullptr; 294 quality_scaler_ = nullptr;
293 shutdown_event_.Set(); 295 shutdown_event_.Set();
294 }); 296 });
295 297
296 shutdown_event_.Wait(rtc::Event::kForever); 298 shutdown_event_.Wait(rtc::Event::kForever);
297 } 299 }
298 300
299 void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) { 301 void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) {
300 RTC_DCHECK_RUN_ON(&thread_checker_); 302 RTC_DCHECK_RUN_ON(&thread_checker_);
301 RTC_DCHECK(!module_process_thread_); 303 RTC_DCHECK(!module_process_thread_);
302 module_process_thread_ = module_process_thread; 304 module_process_thread_ = module_process_thread;
303 module_process_thread_->RegisterModule(&video_sender_); 305 module_process_thread_->RegisterModule(&video_sender_);
304 module_process_thread_checker_.DetachFromThread(); 306 module_process_thread_checker_.DetachFromThread();
305 } 307 }
306 308
307 void ViEEncoder::DeRegisterProcessThread() { 309 void ViEEncoder::DeRegisterProcessThread() {
308 RTC_DCHECK_RUN_ON(&thread_checker_); 310 RTC_DCHECK_RUN_ON(&thread_checker_);
309 module_process_thread_->DeRegisterModule(&video_sender_); 311 module_process_thread_->DeRegisterModule(&video_sender_);
310 } 312 }
311 313
314 void ViEEncoder::SetBitrateObserver(
315 VideoBitrateAllocationObserver* bitrate_observer) {
316 RTC_DCHECK_RUN_ON(&thread_checker_);
317 encoder_queue_.PostTask([this, bitrate_observer] {
318 RTC_DCHECK_RUN_ON(&encoder_queue_);
319 RTC_DCHECK(!bitrate_observer_);
320 bitrate_observer_ = bitrate_observer;
321 });
322 }
323
312 void ViEEncoder::SetSource( 324 void ViEEncoder::SetSource(
313 rtc::VideoSourceInterface<VideoFrame>* source, 325 rtc::VideoSourceInterface<VideoFrame>* source,
314 const VideoSendStream::DegradationPreference& degradation_preference) { 326 const VideoSendStream::DegradationPreference& degradation_preference) {
315 RTC_DCHECK_RUN_ON(&thread_checker_); 327 RTC_DCHECK_RUN_ON(&thread_checker_);
316 source_proxy_->SetSource(source, degradation_preference); 328 source_proxy_->SetSource(source, degradation_preference);
317 encoder_queue_.PostTask([this, degradation_preference] { 329 encoder_queue_.PostTask([this, degradation_preference] {
318 RTC_DCHECK_RUN_ON(&encoder_queue_); 330 RTC_DCHECK_RUN_ON(&encoder_queue_);
319 scaling_enabled_ = 331 scaling_enabled_ =
320 (degradation_preference != 332 (degradation_preference !=
321 VideoSendStream::DegradationPreference::kMaintainResolution); 333 VideoSendStream::DegradationPreference::kMaintainResolution);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 codec.expect_encode_from_texture = last_frame_info_->is_texture; 405 codec.expect_encode_from_texture = last_frame_info_->is_texture;
394 406
395 bool success = video_sender_.RegisterSendCodec( 407 bool success = video_sender_.RegisterSendCodec(
396 &codec, number_of_cores_, 408 &codec, number_of_cores_,
397 static_cast<uint32_t>(max_data_payload_length_)) == VCM_OK; 409 static_cast<uint32_t>(max_data_payload_length_)) == VCM_OK;
398 if (!success) { 410 if (!success) {
399 LOG(LS_ERROR) << "Failed to configure encoder."; 411 LOG(LS_ERROR) << "Failed to configure encoder.";
400 RTC_DCHECK(success); 412 RTC_DCHECK(success);
401 } 413 }
402 414
403 video_sender_.UpdateChannelParemeters(rate_allocator_.get()); 415 video_sender_.UpdateChannelParemeters(rate_allocator_.get(),
416 bitrate_observer_);
417
404 if (stats_proxy_) { 418 if (stats_proxy_) {
405 int framerate = stats_proxy_->GetSendFrameRate(); 419 int framerate = stats_proxy_->GetSendFrameRate();
406 if (framerate == 0) 420 if (framerate == 0)
407 framerate = codec.maxFramerate; 421 framerate = codec.maxFramerate;
408 stats_proxy_->OnEncoderReconfigured( 422 stats_proxy_->OnEncoderReconfigured(
409 encoder_config_, rate_allocator_->GetPreferredBitrateBps(framerate)); 423 encoder_config_, rate_allocator_->GetPreferredBitrateBps(framerate));
410 } 424 }
411 425
412 pending_encoder_reconfiguration_ = false; 426 pending_encoder_reconfiguration_ = false;
413 427
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 return; 662 return;
649 } 663 }
650 RTC_DCHECK_RUN_ON(&encoder_queue_); 664 RTC_DCHECK_RUN_ON(&encoder_queue_);
651 RTC_DCHECK(sink_) << "sink_ must be set before the encoder is active."; 665 RTC_DCHECK(sink_) << "sink_ must be set before the encoder is active.";
652 666
653 LOG(LS_VERBOSE) << "OnBitrateUpdated, bitrate " << bitrate_bps 667 LOG(LS_VERBOSE) << "OnBitrateUpdated, bitrate " << bitrate_bps
654 << " packet loss " << static_cast<int>(fraction_lost) 668 << " packet loss " << static_cast<int>(fraction_lost)
655 << " rtt " << round_trip_time_ms; 669 << " rtt " << round_trip_time_ms;
656 670
657 video_sender_.SetChannelParameters(bitrate_bps, fraction_lost, 671 video_sender_.SetChannelParameters(bitrate_bps, fraction_lost,
658 round_trip_time_ms, rate_allocator_.get()); 672 round_trip_time_ms, rate_allocator_.get(),
673 bitrate_observer_);
659 674
660 encoder_start_bitrate_bps_ = 675 encoder_start_bitrate_bps_ =
661 bitrate_bps != 0 ? bitrate_bps : encoder_start_bitrate_bps_; 676 bitrate_bps != 0 ? bitrate_bps : encoder_start_bitrate_bps_;
662 bool video_is_suspended = bitrate_bps == 0; 677 bool video_is_suspended = bitrate_bps == 0;
663 bool video_suspension_changed = video_is_suspended != EncoderPaused(); 678 bool video_suspension_changed = video_is_suspended != EncoderPaused();
664 last_observed_bitrate_bps_ = bitrate_bps; 679 last_observed_bitrate_bps_ = bitrate_bps;
665 680
666 if (stats_proxy_ && video_suspension_changed) { 681 if (stats_proxy_ && video_suspension_changed) {
667 LOG(LS_INFO) << "Video suspend state changed to: " 682 LOG(LS_INFO) << "Video suspend state changed to: "
668 << (video_is_suspended ? "suspended" : "not suspended"); 683 << (video_is_suspended ? "suspended" : "not suspended");
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 --scale_counter_[reason]; 743 --scale_counter_[reason];
729 source_proxy_->RequestHigherResolutionThan(current_pixel_count); 744 source_proxy_->RequestHigherResolutionThan(current_pixel_count);
730 LOG(LS_INFO) << "Scaling up resolution."; 745 LOG(LS_INFO) << "Scaling up resolution.";
731 for (size_t i = 0; i < kScaleReasonSize; ++i) { 746 for (size_t i = 0; i < kScaleReasonSize; ++i) {
732 LOG(LS_INFO) << "Scaled " << scale_counter_[i] 747 LOG(LS_INFO) << "Scaled " << scale_counter_[i]
733 << " times for reason: " << (i ? "quality" : "cpu"); 748 << " times for reason: " << (i ? "quality" : "cpu");
734 } 749 }
735 } 750 }
736 751
737 } // namespace webrtc 752 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/vie_encoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698