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

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

Issue 2368223002: Add VideoSendStream::Stats::prefered_media_bitrate_bps (Closed)
Patch Set: Addressed nits Created 4 years, 2 months 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') | webrtc/video_send_stream.h » ('j') | 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
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 CpuOveruseOptions options; 182 CpuOveruseOptions options;
183 if (full_overuse_time) { 183 if (full_overuse_time) {
184 options.low_encode_usage_threshold_percent = 150; 184 options.low_encode_usage_threshold_percent = 150;
185 options.high_encode_usage_threshold_percent = 200; 185 options.high_encode_usage_threshold_percent = 200;
186 } 186 }
187 return options; 187 return options;
188 } 188 }
189 189
190 } // namespace 190 } // namespace
191 191
192 class ViEEncoder::ConfigureEncoderTask : public rtc::QueuedTask {
193 public:
194 ConfigureEncoderTask(ViEEncoder* vie_encoder,
195 VideoEncoderConfig config,
196 size_t max_data_payload_length)
197 : vie_encoder_(vie_encoder),
198 config_(std::move(config)),
199 max_data_payload_length_(max_data_payload_length) {}
200
201 private:
202 bool Run() override {
203 vie_encoder_->ConfigureEncoderOnTaskQueue(std::move(config_),
204 max_data_payload_length_);
205 return true;
206 }
207
208 ViEEncoder* const vie_encoder_;
209 VideoEncoderConfig config_;
210 size_t max_data_payload_length_;
211 };
212
192 class ViEEncoder::EncodeTask : public rtc::QueuedTask { 213 class ViEEncoder::EncodeTask : public rtc::QueuedTask {
193 public: 214 public:
194 EncodeTask(const VideoFrame& frame, 215 EncodeTask(const VideoFrame& frame,
195 ViEEncoder* vie_encoder, 216 ViEEncoder* vie_encoder,
196 int64_t time_when_posted_in_ms, 217 int64_t time_when_posted_in_ms,
197 bool log_stats) 218 bool log_stats)
198 : vie_encoder_(vie_encoder), 219 : vie_encoder_(vie_encoder),
199 time_when_posted_ms_(time_when_posted_in_ms), 220 time_when_posted_ms_(time_when_posted_in_ms),
200 log_stats_(log_stats) { 221 log_stats_(log_stats) {
201 frame_.ShallowCopy(frame); 222 frame_.ShallowCopy(frame);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 296
276 ViEEncoder::ViEEncoder(uint32_t number_of_cores, 297 ViEEncoder::ViEEncoder(uint32_t number_of_cores,
277 SendStatisticsProxy* stats_proxy, 298 SendStatisticsProxy* stats_proxy,
278 const VideoSendStream::Config::EncoderSettings& settings, 299 const VideoSendStream::Config::EncoderSettings& settings,
279 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, 300 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback,
280 LoadObserver* overuse_callback, 301 LoadObserver* overuse_callback,
281 EncodedFrameObserver* encoder_timing) 302 EncodedFrameObserver* encoder_timing)
282 : shutdown_event_(true /* manual_reset */, false), 303 : shutdown_event_(true /* manual_reset */, false),
283 number_of_cores_(number_of_cores), 304 number_of_cores_(number_of_cores),
284 source_proxy_(new VideoSourceProxy(this)), 305 source_proxy_(new VideoSourceProxy(this)),
306 sink_(nullptr),
285 settings_(settings), 307 settings_(settings),
308 codec_type_(PayloadNameToCodecType(settings.payload_name)),
286 vp_(VideoProcessing::Create()), 309 vp_(VideoProcessing::Create()),
287 video_sender_(Clock::GetRealTimeClock(), this, this), 310 video_sender_(Clock::GetRealTimeClock(), this, this),
288 overuse_detector_(Clock::GetRealTimeClock(), 311 overuse_detector_(Clock::GetRealTimeClock(),
289 GetCpuOveruseOptions(settings.full_overuse_time), 312 GetCpuOveruseOptions(settings.full_overuse_time),
290 this, 313 this,
291 encoder_timing, 314 encoder_timing,
292 stats_proxy), 315 stats_proxy),
293 load_observer_(overuse_callback), 316 load_observer_(overuse_callback),
294 stats_proxy_(stats_proxy), 317 stats_proxy_(stats_proxy),
295 pre_encode_callback_(pre_encode_callback), 318 pre_encode_callback_(pre_encode_callback),
296 module_process_thread_(nullptr), 319 module_process_thread_(nullptr),
297 encoder_config_(), 320 encoder_config_(),
298 encoder_start_bitrate_bps_(0), 321 encoder_start_bitrate_bps_(0),
322 max_data_payload_length_(0),
299 last_observed_bitrate_bps_(0), 323 last_observed_bitrate_bps_(0),
300 encoder_paused_and_dropped_frame_(false), 324 encoder_paused_and_dropped_frame_(false),
301 has_received_sli_(false), 325 has_received_sli_(false),
302 picture_id_sli_(0), 326 picture_id_sli_(0),
303 has_received_rpsi_(false), 327 has_received_rpsi_(false),
304 picture_id_rpsi_(0), 328 picture_id_rpsi_(0),
305 clock_(Clock::GetRealTimeClock()), 329 clock_(Clock::GetRealTimeClock()),
306 last_captured_timestamp_(0), 330 last_captured_timestamp_(0),
307 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - 331 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() -
308 clock_->TimeInMilliseconds()), 332 clock_->TimeInMilliseconds()),
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 391
368 void ViEEncoder::SetStartBitrate(int start_bitrate_bps) { 392 void ViEEncoder::SetStartBitrate(int start_bitrate_bps) {
369 encoder_queue_.PostTask([this, start_bitrate_bps] { 393 encoder_queue_.PostTask([this, start_bitrate_bps] {
370 RTC_DCHECK_RUN_ON(&encoder_queue_); 394 RTC_DCHECK_RUN_ON(&encoder_queue_);
371 encoder_start_bitrate_bps_ = start_bitrate_bps; 395 encoder_start_bitrate_bps_ = start_bitrate_bps;
372 }); 396 });
373 } 397 }
374 398
375 void ViEEncoder::ConfigureEncoder(VideoEncoderConfig config, 399 void ViEEncoder::ConfigureEncoder(VideoEncoderConfig config,
376 size_t max_data_payload_length) { 400 size_t max_data_payload_length) {
377 VideoCodec video_codec = VideoEncoderConfigToVideoCodec( 401 encoder_queue_.PostTask(
378 config, settings_.payload_name, settings_.payload_type); 402 std::unique_ptr<rtc::QueuedTask>(new ConfigureEncoderTask(
379 LOG(LS_INFO) << "ConfigureEncoder: " << config.ToString(); 403 this, std::move(config), max_data_payload_length)));
380 std::vector<VideoStream> stream = std::move(config.streams);
381 int min_transmit_bitrate = config.min_transmit_bitrate_bps;
382 encoder_queue_.PostTask([this, video_codec, max_data_payload_length, stream,
383 min_transmit_bitrate] {
384 ConfigureEncoderInternal(video_codec, max_data_payload_length, stream,
385 min_transmit_bitrate);
386 });
387 return;
388 } 404 }
389 405
390 void ViEEncoder::ConfigureEncoderInternal(const VideoCodec& video_codec, 406 void ViEEncoder::ConfigureEncoderOnTaskQueue(VideoEncoderConfig config,
391 size_t max_data_payload_length, 407 size_t max_data_payload_length) {
392 std::vector<VideoStream> stream,
393 int min_transmit_bitrate) {
394 RTC_DCHECK_RUN_ON(&encoder_queue_); 408 RTC_DCHECK_RUN_ON(&encoder_queue_);
395 RTC_DCHECK_GE(encoder_start_bitrate_bps_, 0);
396 RTC_DCHECK(sink_); 409 RTC_DCHECK(sink_);
410 LOG(LS_INFO) << "ConfigureEncoderOnTaskQueue";
411
412 max_data_payload_length_ = max_data_payload_length;
413 encoder_config_ = std::move(config);
414
415 VideoCodec video_codec = VideoEncoderConfigToVideoCodec(
416 encoder_config_, settings_.payload_name, settings_.payload_type);
397 417
398 // Setting target width and height for VPM. 418 // Setting target width and height for VPM.
399 RTC_CHECK_EQ(VPM_OK, 419 RTC_CHECK_EQ(VPM_OK,
400 vp_->SetTargetResolution(video_codec.width, video_codec.height, 420 vp_->SetTargetResolution(video_codec.width, video_codec.height,
401 video_codec.maxFramerate)); 421 video_codec.maxFramerate));
402 422
403 encoder_config_ = video_codec; 423 video_codec.startBitrate =
404 encoder_config_.startBitrate = encoder_start_bitrate_bps_ / 1000; 424 std::max(encoder_start_bitrate_bps_ / 1000, video_codec.minBitrate);
405 encoder_config_.startBitrate = 425 video_codec.startBitrate =
406 std::max(encoder_config_.startBitrate, video_codec.minBitrate); 426 std::min(video_codec.startBitrate, video_codec.maxBitrate);
407 encoder_config_.startBitrate =
408 std::min(encoder_config_.startBitrate, video_codec.maxBitrate);
409 427
410 bool success = video_sender_.RegisterSendCodec( 428 bool success = video_sender_.RegisterSendCodec(
411 &encoder_config_, number_of_cores_, 429 &video_codec, number_of_cores_,
412 static_cast<uint32_t>(max_data_payload_length)) == VCM_OK; 430 static_cast<uint32_t>(max_data_payload_length)) == VCM_OK;
413 431
414 if (!success) { 432 if (!success) {
415 LOG(LS_ERROR) << "Failed to configure encoder."; 433 LOG(LS_ERROR) << "Failed to configure encoder.";
416 RTC_DCHECK(success); 434 RTC_DCHECK(success);
417 } 435 }
418 436
437 rate_allocator_.reset(new SimulcastRateAllocator(video_codec));
419 if (stats_proxy_) { 438 if (stats_proxy_) {
420 VideoEncoderConfig::ContentType content_type = 439 stats_proxy_->OnEncoderReconfigured(encoder_config_,
421 VideoEncoderConfig::ContentType::kRealtimeVideo; 440 rate_allocator_->GetPreferedBitrate());
422 switch (video_codec.mode) {
423 case kRealtimeVideo:
424 content_type = VideoEncoderConfig::ContentType::kRealtimeVideo;
425 break;
426 case kScreensharing:
427 content_type = VideoEncoderConfig::ContentType::kScreen;
428 break;
429 default:
430 RTC_NOTREACHED();
431 break;
432 }
433 stats_proxy_->SetContentType(content_type);
434 } 441 }
435 442
436 sink_->OnEncoderConfigurationChanged(stream, min_transmit_bitrate); 443 sink_->OnEncoderConfigurationChanged(
444 encoder_config_.streams, encoder_config_.min_transmit_bitrate_bps);
437 } 445 }
438 446
439 void ViEEncoder::OnFrame(const VideoFrame& video_frame) { 447 void ViEEncoder::OnFrame(const VideoFrame& video_frame) {
440 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); 448 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_);
441 stats_proxy_->OnIncomingFrame(video_frame.width(), video_frame.height()); 449 stats_proxy_->OnIncomingFrame(video_frame.width(), video_frame.height());
442 450
443 VideoFrame incoming_frame = video_frame; 451 VideoFrame incoming_frame = video_frame;
444 452
445 // Local time in webrtc time base. 453 // Local time in webrtc time base.
446 int64_t current_time = clock_->TimeInMilliseconds(); 454 int64_t current_time = clock_->TimeInMilliseconds();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 // Pass frame via preprocessor. 538 // Pass frame via preprocessor.
531 frame_to_send = vp_->PreprocessFrame(video_frame); 539 frame_to_send = vp_->PreprocessFrame(video_frame);
532 if (!frame_to_send) { 540 if (!frame_to_send) {
533 // Drop this frame, or there was an error processing it. 541 // Drop this frame, or there was an error processing it.
534 return; 542 return;
535 } 543 }
536 } 544 }
537 545
538 overuse_detector_.FrameCaptured(video_frame, time_when_posted_in_ms); 546 overuse_detector_.FrameCaptured(video_frame, time_when_posted_in_ms);
539 547
540 if (encoder_config_.codecType == webrtc::kVideoCodecVP8) { 548 if (codec_type_ == webrtc::kVideoCodecVP8) {
541 webrtc::CodecSpecificInfo codec_specific_info; 549 webrtc::CodecSpecificInfo codec_specific_info;
542 codec_specific_info.codecType = webrtc::kVideoCodecVP8; 550 codec_specific_info.codecType = webrtc::kVideoCodecVP8;
543 551
544 codec_specific_info.codecSpecific.VP8.hasReceivedRPSI = 552 codec_specific_info.codecSpecific.VP8.hasReceivedRPSI =
545 has_received_rpsi_; 553 has_received_rpsi_;
546 codec_specific_info.codecSpecific.VP8.hasReceivedSLI = 554 codec_specific_info.codecSpecific.VP8.hasReceivedSLI =
547 has_received_sli_; 555 has_received_sli_;
548 codec_specific_info.codecSpecific.VP8.pictureIdRPSI = 556 codec_specific_info.codecSpecific.VP8.pictureIdRPSI =
549 picture_id_rpsi_; 557 picture_id_rpsi_;
550 codec_specific_info.codecSpecific.VP8.pictureIdSLI = 558 codec_specific_info.codecSpecific.VP8.pictureIdSLI =
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 load_observer_->OnLoadUpdate(LoadObserver::kOveruse); 679 load_observer_->OnLoadUpdate(LoadObserver::kOveruse);
672 } 680 }
673 681
674 void ViEEncoder::NormalUsage() { 682 void ViEEncoder::NormalUsage() {
675 RTC_DCHECK_RUN_ON(&encoder_queue_); 683 RTC_DCHECK_RUN_ON(&encoder_queue_);
676 if (load_observer_) 684 if (load_observer_)
677 load_observer_->OnLoadUpdate(LoadObserver::kUnderuse); 685 load_observer_->OnLoadUpdate(LoadObserver::kUnderuse);
678 } 686 }
679 687
680 } // namespace webrtc 688 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/vie_encoder.h ('k') | webrtc/video_send_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698