Chromium Code Reviews

Side by Side Diff: webrtc/media/engine/webrtcvideoengine2.cc

Issue 1813763005: Updated structures and functions for setting the max bitrate limit to take rtc::Optional<int> Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Code review feedback Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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 60 matching lines...)
71 } 71 }
72 if (codec.GetParam(kCodecParamStartBitrate, &bitrate_kbps) && 72 if (codec.GetParam(kCodecParamStartBitrate, &bitrate_kbps) &&
73 bitrate_kbps > 0) { 73 bitrate_kbps > 0) {
74 config.start_bitrate_bps = bitrate_kbps * 1000; 74 config.start_bitrate_bps = bitrate_kbps * 1000;
75 } else { 75 } else {
76 // Do not reconfigure start bitrate unless it's specified and positive. 76 // Do not reconfigure start bitrate unless it's specified and positive.
77 config.start_bitrate_bps = -1; 77 config.start_bitrate_bps = -1;
78 } 78 }
79 if (codec.GetParam(kCodecParamMaxBitrate, &bitrate_kbps) && 79 if (codec.GetParam(kCodecParamMaxBitrate, &bitrate_kbps) &&
80 bitrate_kbps > 0) { 80 bitrate_kbps > 0) {
81 config.max_bitrate_bps = bitrate_kbps * 1000; 81 config.max_bitrate_bps = rtc::Optional<int>(bitrate_kbps * 1000);
82 } else { 82 } else {
83 config.max_bitrate_bps = -1; 83 config.max_bitrate_bps = rtc::Optional<int>();
84 } 84 }
85 return config; 85 return config;
86 } 86 }
87 87
88 // An encoder factory that wraps Create requests for simulcastable codec types 88 // An encoder factory that wraps Create requests for simulcastable codec types
89 // with a webrtc::SimulcastEncoderAdapter. Non simulcastable codec type 89 // with a webrtc::SimulcastEncoderAdapter. Non simulcastable codec type
90 // requests are just passed through to the contained encoder factory. 90 // requests are just passed through to the contained encoder factory.
91 class WebRtcSimulcastEncoderFactory 91 class WebRtcSimulcastEncoderFactory
92 : public cricket::WebRtcVideoEncoderFactory { 92 : public cricket::WebRtcVideoEncoderFactory {
93 public: 93 public:
(...skipping 261 matching lines...)
355 codecs.push_back( 355 codecs.push_back(
356 VideoCodec::CreateRtxCodec(kDefaultRtxRedPlType, kDefaultRedPlType)); 356 VideoCodec::CreateRtxCodec(kDefaultRtxRedPlType, kDefaultRedPlType));
357 codecs.push_back(VideoCodec(kDefaultUlpfecType, kUlpfecCodecName)); 357 codecs.push_back(VideoCodec(kDefaultUlpfecType, kUlpfecCodecName));
358 return codecs; 358 return codecs;
359 } 359 }
360 360
361 std::vector<webrtc::VideoStream> 361 std::vector<webrtc::VideoStream>
362 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateSimulcastVideoStreams( 362 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateSimulcastVideoStreams(
363 const VideoCodec& codec, 363 const VideoCodec& codec,
364 const VideoOptions& options, 364 const VideoOptions& options,
365 int max_bitrate_bps, 365 rtc::Optional<int> max_bitrate_bps,
366 size_t num_streams) { 366 size_t num_streams) {
367 int max_qp = kDefaultQpMax; 367 int max_qp = kDefaultQpMax;
368 codec.GetParam(kCodecParamMaxQuantization, &max_qp); 368 codec.GetParam(kCodecParamMaxQuantization, &max_qp);
369 369
370 return GetSimulcastConfig( 370 return GetSimulcastConfig(
371 num_streams, codec.width, codec.height, max_bitrate_bps, max_qp, 371 num_streams, codec.width, codec.height, max_bitrate_bps, max_qp,
372 codec.framerate != 0 ? codec.framerate : kDefaultVideoMaxFramerate); 372 codec.framerate != 0 ? codec.framerate : kDefaultVideoMaxFramerate);
373 } 373 }
374 374
375 std::vector<webrtc::VideoStream> 375 std::vector<webrtc::VideoStream>
376 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoStreams( 376 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoStreams(
377 const VideoCodec& codec, 377 const VideoCodec& codec,
378 const VideoOptions& options, 378 const VideoOptions& options,
379 int max_bitrate_bps, 379 rtc::Optional<int> max_bitrate_bps,
380 size_t num_streams) { 380 size_t num_streams) {
381 int codec_max_bitrate_kbps; 381 int codec_max_bitrate_kbps;
382 if (codec.GetParam(kCodecParamMaxBitrate, &codec_max_bitrate_kbps)) { 382 if (codec.GetParam(kCodecParamMaxBitrate, &codec_max_bitrate_kbps)) {
383 max_bitrate_bps = codec_max_bitrate_kbps * 1000; 383 max_bitrate_bps = rtc::Optional<int>(codec_max_bitrate_kbps * 1000);
384 } 384 }
385 if (num_streams != 1) { 385 if (num_streams != 1) {
386 return CreateSimulcastVideoStreams(codec, options, max_bitrate_bps, 386 return CreateSimulcastVideoStreams(codec, options, max_bitrate_bps,
387 num_streams); 387 num_streams);
388 } 388 }
389 389
390 // For unset max bitrates set default bitrate for non-simulcast. 390 // For unset max bitrates set default bitrate for non-simulcast.
391 if (max_bitrate_bps <= 0) { 391 if (!max_bitrate_bps) {
392 max_bitrate_bps = 392 max_bitrate_bps = rtc::Optional<int>(
393 GetMaxDefaultVideoBitrateKbps(codec.width, codec.height) * 1000; 393 GetMaxDefaultVideoBitrateKbps(codec.width, codec.height) * 1000);
394 } 394 }
395 395
396 webrtc::VideoStream stream; 396 webrtc::VideoStream stream;
397 stream.width = codec.width; 397 stream.width = codec.width;
398 stream.height = codec.height; 398 stream.height = codec.height;
399 stream.max_framerate = 399 stream.max_framerate =
400 codec.framerate != 0 ? codec.framerate : kDefaultVideoMaxFramerate; 400 codec.framerate != 0 ? codec.framerate : kDefaultVideoMaxFramerate;
401 401
402 stream.min_bitrate_bps = kMinVideoBitrate * 1000; 402 stream.min_bitrate_bps = kMinVideoBitrate * 1000;
403 stream.target_bitrate_bps = stream.max_bitrate_bps = max_bitrate_bps; 403 stream.target_bitrate_bps = stream.max_bitrate_bps = *max_bitrate_bps;
404 404
405 int max_qp = kDefaultQpMax; 405 int max_qp = kDefaultQpMax;
406 codec.GetParam(kCodecParamMaxQuantization, &max_qp); 406 codec.GetParam(kCodecParamMaxQuantization, &max_qp);
407 stream.max_qp = max_qp; 407 stream.max_qp = max_qp;
408 std::vector<webrtc::VideoStream> streams; 408 std::vector<webrtc::VideoStream> streams;
409 streams.push_back(stream); 409 streams.push_back(stream);
410 return streams; 410 return streams;
411 } 411 }
412 412
413 void* WebRtcVideoChannel2::WebRtcVideoSendStream::ConfigureVideoEncoderSettings( 413 void* WebRtcVideoChannel2::WebRtcVideoSendStream::ConfigureVideoEncoderSettings(
(...skipping 305 matching lines...)
719 719
720 // Handle RTP header extensions. 720 // Handle RTP header extensions.
721 std::vector<webrtc::RtpExtension> filtered_extensions = FilterRtpExtensions( 721 std::vector<webrtc::RtpExtension> filtered_extensions = FilterRtpExtensions(
722 params.extensions, webrtc::RtpExtension::IsSupportedForVideo, true); 722 params.extensions, webrtc::RtpExtension::IsSupportedForVideo, true);
723 if (send_rtp_extensions_ != filtered_extensions) { 723 if (send_rtp_extensions_ != filtered_extensions) {
724 changed_params->rtp_header_extensions = 724 changed_params->rtp_header_extensions =
725 rtc::Optional<std::vector<webrtc::RtpExtension>>(filtered_extensions); 725 rtc::Optional<std::vector<webrtc::RtpExtension>>(filtered_extensions);
726 } 726 }
727 727
728 // Handle max bitrate. 728 // Handle max bitrate.
729 if (params.max_bandwidth_bps != bitrate_config_.max_bitrate_bps && 729 if (params.max_bitrate_bps != bitrate_config_.max_bitrate_bps) {
730 params.max_bandwidth_bps >= 0) { 730 changed_params->max_bandwidth_bps =
731 // 0 uncaps max bitrate (-1). 731 rtc::Optional<rtc::Optional<int>>(params.max_bitrate_bps);
732 changed_params->max_bandwidth_bps = rtc::Optional<int>(
733 params.max_bandwidth_bps == 0 ? -1 : params.max_bandwidth_bps);
734 } 732 }
735 733
736 // Handle conference mode. 734 // Handle conference mode.
737 if (params.conference_mode != send_params_.conference_mode) { 735 if (params.conference_mode != send_params_.conference_mode) {
738 changed_params->conference_mode = 736 changed_params->conference_mode =
739 rtc::Optional<bool>(params.conference_mode); 737 rtc::Optional<bool>(params.conference_mode);
740 } 738 }
741 739
742 // Handle RTCP mode. 740 // Handle RTCP mode.
743 if (params.rtcp.reduced_size != send_params_.rtcp.reduced_size) { 741 if (params.rtcp.reduced_size != send_params_.rtcp.reduced_size) {
(...skipping 32 matching lines...)
776 774
777 if (changed_params.rtp_header_extensions) { 775 if (changed_params.rtp_header_extensions) {
778 send_rtp_extensions_ = *changed_params.rtp_header_extensions; 776 send_rtp_extensions_ = *changed_params.rtp_header_extensions;
779 } 777 }
780 778
781 if (changed_params.max_bandwidth_bps) { 779 if (changed_params.max_bandwidth_bps) {
782 // TODO(pbos): Figure out whether b=AS means max bitrate for this 780 // TODO(pbos): Figure out whether b=AS means max bitrate for this
783 // WebRtcVideoChannel2 (in which case we're good), or per sender (SSRC), in 781 // WebRtcVideoChannel2 (in which case we're good), or per sender (SSRC), in
784 // which case this should not set a Call::BitrateConfig but rather 782 // which case this should not set a Call::BitrateConfig but rather
785 // reconfigure all senders. 783 // reconfigure all senders.
786 int max_bitrate_bps = *changed_params.max_bandwidth_bps;
787 bitrate_config_.start_bitrate_bps = -1; 784 bitrate_config_.start_bitrate_bps = -1;
788 bitrate_config_.max_bitrate_bps = max_bitrate_bps; 785 bitrate_config_.max_bitrate_bps = *changed_params.max_bandwidth_bps;
789 if (max_bitrate_bps > 0 && 786 if (bitrate_config_.max_bitrate_bps &&
790 bitrate_config_.min_bitrate_bps > max_bitrate_bps) { 787 (bitrate_config_.min_bitrate_bps > *bitrate_config_.max_bitrate_bps)) {
791 bitrate_config_.min_bitrate_bps = max_bitrate_bps; 788 bitrate_config_.min_bitrate_bps = *bitrate_config_.max_bitrate_bps;
792 } 789 }
793 bitrate_config_changed = true; 790 bitrate_config_changed = true;
794 } 791 }
795 792
796 if (bitrate_config_changed) { 793 if (bitrate_config_changed) {
797 call_->SetBitrateConfig(bitrate_config_); 794 call_->SetBitrateConfig(bitrate_config_);
798 } 795 }
799 796
800 { 797 {
801 rtc::CritScope stream_lock(&stream_crit_); 798 rtc::CritScope stream_lock(&stream_crit_);
(...skipping 648 matching lines...)
1450 send_streams_.begin(); 1447 send_streams_.begin();
1451 it != send_streams_.end(); ++it) { 1448 it != send_streams_.end(); ++it) {
1452 it->second->Stop(); 1449 it->second->Stop();
1453 } 1450 }
1454 } 1451 }
1455 1452
1456 WebRtcVideoChannel2::WebRtcVideoSendStream::VideoSendStreamParameters:: 1453 WebRtcVideoChannel2::WebRtcVideoSendStream::VideoSendStreamParameters::
1457 VideoSendStreamParameters( 1454 VideoSendStreamParameters(
1458 const webrtc::VideoSendStream::Config& config, 1455 const webrtc::VideoSendStream::Config& config,
1459 const VideoOptions& options, 1456 const VideoOptions& options,
1460 int max_bitrate_bps, 1457 rtc::Optional<int> max_bitrate_bps,
1461 const rtc::Optional<VideoCodecSettings>& codec_settings) 1458 const rtc::Optional<VideoCodecSettings>& codec_settings)
1462 : config(config), 1459 : config(config),
1463 options(options), 1460 options(options),
1464 max_bitrate_bps(max_bitrate_bps), 1461 max_bitrate_bps(max_bitrate_bps),
1465 codec_settings(codec_settings) {} 1462 codec_settings(codec_settings) {}
1466 1463
1467 WebRtcVideoChannel2::WebRtcVideoSendStream::AllocatedEncoder::AllocatedEncoder( 1464 WebRtcVideoChannel2::WebRtcVideoSendStream::AllocatedEncoder::AllocatedEncoder(
1468 webrtc::VideoEncoder* encoder, 1465 webrtc::VideoEncoder* encoder,
1469 webrtc::VideoCodecType type, 1466 webrtc::VideoCodecType type,
1470 bool external) 1467 bool external)
1471 : encoder(encoder), 1468 : encoder(encoder),
1472 external_encoder(nullptr), 1469 external_encoder(nullptr),
1473 type(type), 1470 type(type),
1474 external(external) { 1471 external(external) {
1475 if (external) { 1472 if (external) {
1476 external_encoder = encoder; 1473 external_encoder = encoder;
1477 this->encoder = 1474 this->encoder =
1478 new webrtc::VideoEncoderSoftwareFallbackWrapper(type, encoder); 1475 new webrtc::VideoEncoderSoftwareFallbackWrapper(type, encoder);
1479 } 1476 }
1480 } 1477 }
1481 1478
1482 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( 1479 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream(
1483 webrtc::Call* call, 1480 webrtc::Call* call,
1484 const StreamParams& sp, 1481 const StreamParams& sp,
1485 const webrtc::VideoSendStream::Config& config, 1482 const webrtc::VideoSendStream::Config& config,
1486 const VideoOptions& options, 1483 const VideoOptions& options,
1487 WebRtcVideoEncoderFactory* external_encoder_factory, 1484 WebRtcVideoEncoderFactory* external_encoder_factory,
1488 bool enable_cpu_overuse_detection, 1485 bool enable_cpu_overuse_detection,
1489 int max_bitrate_bps, 1486 rtc::Optional<int> max_bitrate_bps,
1490 const rtc::Optional<VideoCodecSettings>& codec_settings, 1487 const rtc::Optional<VideoCodecSettings>& codec_settings,
1491 const std::vector<webrtc::RtpExtension>& rtp_extensions, 1488 const std::vector<webrtc::RtpExtension>& rtp_extensions,
1492 // TODO(deadbeef): Don't duplicate information between send_params, 1489 // TODO(deadbeef): Don't duplicate information between send_params,
1493 // rtp_extensions, options, etc. 1490 // rtp_extensions, options, etc.
1494 const VideoSendParameters& send_params) 1491 const VideoSendParameters& send_params)
1495 : worker_thread_(rtc::Thread::Current()), 1492 : worker_thread_(rtc::Thread::Current()),
1496 ssrcs_(sp.ssrcs), 1493 ssrcs_(sp.ssrcs),
1497 ssrc_groups_(sp.ssrc_groups), 1494 ssrc_groups_(sp.ssrc_groups),
1498 call_(call), 1495 call_(call),
1499 cpu_restricted_counter_(0), 1496 cpu_restricted_counter_(0),
(...skipping 338 matching lines...)
1838 return true; 1835 return true;
1839 } 1836 }
1840 1837
1841 bool WebRtcVideoChannel2::WebRtcVideoSendStream::ValidateRtpParameters( 1838 bool WebRtcVideoChannel2::WebRtcVideoSendStream::ValidateRtpParameters(
1842 const webrtc::RtpParameters& rtp_parameters) { 1839 const webrtc::RtpParameters& rtp_parameters) {
1843 if (rtp_parameters.encodings.size() != 1) { 1840 if (rtp_parameters.encodings.size() != 1) {
1844 LOG(LS_ERROR) 1841 LOG(LS_ERROR)
1845 << "Attempted to set RtpParameters without exactly one encoding"; 1842 << "Attempted to set RtpParameters without exactly one encoding";
1846 return false; 1843 return false;
1847 } 1844 }
1845 if (rtp_parameters.encodings[0].max_bitrate_bps &&
1846 (*rtp_parameters.encodings[0].max_bitrate_bps <= 0)) {
1847 LOG(LS_ERROR) << "Attempted to set a negative bitrate limit";
1848 return false;
1849 }
1848 return true; 1850 return true;
1849 } 1851 }
1850 1852
1851 webrtc::VideoEncoderConfig 1853 webrtc::VideoEncoderConfig
1852 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( 1854 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig(
1853 const Dimensions& dimensions, 1855 const Dimensions& dimensions,
1854 const VideoCodec& codec) const { 1856 const VideoCodec& codec) const {
1855 webrtc::VideoEncoderConfig encoder_config; 1857 webrtc::VideoEncoderConfig encoder_config;
1856 bool is_screencast = parameters_.options.is_screencast.value_or(false); 1858 bool is_screencast = parameters_.options.is_screencast.value_or(false);
1857 if (is_screencast) { 1859 if (is_screencast) {
(...skipping 22 matching lines...)
1880 clamped_codec.height = height; 1882 clamped_codec.height = height;
1881 1883
1882 // By default, the stream count for the codec configuration should match the 1884 // By default, the stream count for the codec configuration should match the
1883 // number of negotiated ssrcs. But if the codec is blacklisted for simulcast 1885 // number of negotiated ssrcs. But if the codec is blacklisted for simulcast
1884 // or a screencast, only configure a single stream. 1886 // or a screencast, only configure a single stream.
1885 size_t stream_count = parameters_.config.rtp.ssrcs.size(); 1887 size_t stream_count = parameters_.config.rtp.ssrcs.size();
1886 if (IsCodecBlacklistedForSimulcast(codec.name) || is_screencast) { 1888 if (IsCodecBlacklistedForSimulcast(codec.name) || is_screencast) {
1887 stream_count = 1; 1889 stream_count = 1;
1888 } 1890 }
1889 1891
1890 int stream_max_bitrate = 1892 rtc::Optional<int> stream_max_bitrate =
1891 MinPositive(rtp_parameters_.encodings[0].max_bitrate_bps, 1893 OptionalMin(rtp_parameters_.encodings[0].max_bitrate_bps,
1892 parameters_.max_bitrate_bps); 1894 parameters_.max_bitrate_bps);
1893 encoder_config.streams = CreateVideoStreams( 1895 encoder_config.streams = CreateVideoStreams(
1894 clamped_codec, parameters_.options, stream_max_bitrate, stream_count); 1896 clamped_codec, parameters_.options, stream_max_bitrate, stream_count);
1895 1897
1896 // Conference mode screencast uses 2 temporal layers split at 100kbit. 1898 // Conference mode screencast uses 2 temporal layers split at 100kbit.
1897 if (parameters_.conference_mode && is_screencast && 1899 if (parameters_.conference_mode && is_screencast &&
1898 encoder_config.streams.size() == 1) { 1900 encoder_config.streams.size() == 1) {
1899 ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault(); 1901 ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault();
1900 1902
1901 // For screenshare in conference mode, tl0 and tl1 bitrates are piggybacked 1903 // For screenshare in conference mode, tl0 and tl1 bitrates are piggybacked
(...skipping 665 matching lines...)
2567 rtx_mapping[video_codecs[i].codec.id] != 2569 rtx_mapping[video_codecs[i].codec.id] !=
2568 fec_settings.red_payload_type) { 2570 fec_settings.red_payload_type) {
2569 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; 2571 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id];
2570 } 2572 }
2571 } 2573 }
2572 2574
2573 return video_codecs; 2575 return video_codecs;
2574 } 2576 }
2575 2577
2576 } // namespace cricket 2578 } // namespace cricket
OLDNEW

Powered by Google App Engine