 Chromium Code Reviews
 Chromium Code Reviews Issue 1788583004:
  Enable setting the maximum bitrate limit in RtpSender.  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master
    
  
    Issue 1788583004:
  Enable setting the maximum bitrate limit in RtpSender.  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master| OLD | NEW | 
|---|---|
| 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 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 786 | 786 | 
| 787 if (changed_params.rtp_header_extensions) { | 787 if (changed_params.rtp_header_extensions) { | 
| 788 send_rtp_extensions_ = *changed_params.rtp_header_extensions; | 788 send_rtp_extensions_ = *changed_params.rtp_header_extensions; | 
| 789 } | 789 } | 
| 790 | 790 | 
| 791 if (changed_params.max_bandwidth_bps) { | 791 if (changed_params.max_bandwidth_bps) { | 
| 792 // TODO(pbos): Figure out whether b=AS means max bitrate for this | 792 // TODO(pbos): Figure out whether b=AS means max bitrate for this | 
| 793 // WebRtcVideoChannel2 (in which case we're good), or per sender (SSRC), in | 793 // WebRtcVideoChannel2 (in which case we're good), or per sender (SSRC), in | 
| 794 // which case this should not set a Call::BitrateConfig but rather | 794 // which case this should not set a Call::BitrateConfig but rather | 
| 795 // reconfigure all senders. | 795 // reconfigure all senders. | 
| 796 int max_bitrate_bps = *changed_params.max_bandwidth_bps; | 796 int max_global_bitrate = *changed_params.max_bandwidth_bps; | 
| 797 bitrate_config_.start_bitrate_bps = -1; | 797 bitrate_config_.start_bitrate_bps = -1; | 
| 798 bitrate_config_.max_bitrate_bps = max_bitrate_bps; | 798 bitrate_config_.max_bitrate_bps = max_global_bitrate; | 
| 799 if (max_bitrate_bps > 0 && | 799 if (max_global_bitrate > 0 && | 
| 800 bitrate_config_.min_bitrate_bps > max_bitrate_bps) { | 800 bitrate_config_.min_bitrate_bps > max_global_bitrate) { | 
| 801 bitrate_config_.min_bitrate_bps = max_bitrate_bps; | 801 bitrate_config_.min_bitrate_bps = max_global_bitrate; | 
| 
pthatcher1
2016/03/16 00:48:42
I think you can leave the code as it was with the
 
skvlad
2016/03/16 02:29:22
Done.
 | |
| 802 // TODO(skvlad): Remove the global limits once we transition to | |
| 803 // unified plan SDP. | |
| 
pthatcher1
2016/03/16 00:48:42
I think you can remove this comment and replace it
 
skvlad
2016/03/16 02:29:22
Done.
 | |
| 804 | |
| 805 // TODO(skvlad): Ensure that the encoder does not get reconfigured when | |
| 806 // one of the two maximums change, but the effective maximum for the | |
| 807 // stream does not. | |
| 
pthatcher1
2016/03/16 00:48:42
That's probably an optimization that isn't worth d
 
skvlad
2016/03/16 02:29:22
This optimization was in fact working in the previ
 | |
| 802 } | 808 } | 
| 803 bitrate_config_changed = true; | 809 bitrate_config_changed = true; | 
| 804 } | 810 } | 
| 805 | 811 | 
| 806 if (bitrate_config_changed) { | 812 if (bitrate_config_changed) { | 
| 807 call_->SetBitrateConfig(bitrate_config_); | 813 call_->SetBitrateConfig(bitrate_config_); | 
| 808 } | 814 } | 
| 809 | 815 | 
| 810 if (changed_params.options) | 816 if (changed_params.options) | 
| 811 send_params_.options.SetAll(*changed_params.options); | 817 send_params_.options.SetAll(*changed_params.options); | 
| (...skipping 12 matching lines...) Expand all Loading... | |
| 824 RTC_DCHECK(kv.second != nullptr); | 830 RTC_DCHECK(kv.second != nullptr); | 
| 825 kv.second->SetFeedbackParameters(HasNack(send_codec_->codec), | 831 kv.second->SetFeedbackParameters(HasNack(send_codec_->codec), | 
| 826 HasRemb(send_codec_->codec), | 832 HasRemb(send_codec_->codec), | 
| 827 HasTransportCc(send_codec_->codec)); | 833 HasTransportCc(send_codec_->codec)); | 
| 828 } | 834 } | 
| 829 } | 835 } | 
| 830 } | 836 } | 
| 831 send_params_ = params; | 837 send_params_ = params; | 
| 832 return true; | 838 return true; | 
| 833 } | 839 } | 
| 840 webrtc::RtpParameters WebRtcVideoChannel2::GetRtpParameters( | |
| 841 uint32_t ssrc) const { | |
| 842 rtc::CritScope stream_lock(&stream_crit_); | |
| 843 auto it = send_streams_.find(ssrc); | |
| 844 if (it == send_streams_.end()) { | |
| 845 LOG(LS_WARNING) << "Attempting to get RTP parameters for stream with ssrc " | |
| 846 << ssrc << " which doesn't exist."; | |
| 847 return webrtc::RtpParameters(); | |
| 848 } | |
| 849 | |
| 850 return it->second->rtp_parameters(); | |
| 851 } | |
| 852 | |
| 853 bool WebRtcVideoChannel2::SetRtpParameters( | |
| 854 uint32_t ssrc, | |
| 855 const webrtc::RtpParameters& parameters) { | |
| 856 rtc::CritScope stream_lock(&stream_crit_); | |
| 857 auto it = send_streams_.find(ssrc); | |
| 858 if (it == send_streams_.end()) { | |
| 859 LOG(LS_ERROR) << "Attempting to set RTP parameters for stream with ssrc " | |
| 860 << ssrc << " which doesn't exist."; | |
| 861 return false; | |
| 862 } | |
| 863 | |
| 864 return it->second->SetRtpParameters(parameters); | |
| 865 } | |
| 834 | 866 | 
| 835 bool WebRtcVideoChannel2::GetChangedRecvParameters( | 867 bool WebRtcVideoChannel2::GetChangedRecvParameters( | 
| 836 const VideoRecvParameters& params, | 868 const VideoRecvParameters& params, | 
| 837 ChangedRecvParameters* changed_params) const { | 869 ChangedRecvParameters* changed_params) const { | 
| 838 if (!ValidateCodecFormats(params.codecs) || | 870 if (!ValidateCodecFormats(params.codecs) || | 
| 839 !ValidateRtpExtensions(params.extensions)) { | 871 !ValidateRtpExtensions(params.extensions)) { | 
| 840 return false; | 872 return false; | 
| 841 } | 873 } | 
| 842 | 874 | 
| 843 // Handle receive codecs. | 875 // Handle receive codecs. | 
| (...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1486 number_of_cpu_adapt_changes_(0), | 1518 number_of_cpu_adapt_changes_(0), | 
| 1487 capturer_(nullptr), | 1519 capturer_(nullptr), | 
| 1488 external_encoder_factory_(external_encoder_factory), | 1520 external_encoder_factory_(external_encoder_factory), | 
| 1489 stream_(nullptr), | 1521 stream_(nullptr), | 
| 1490 parameters_(config, send_params.options, max_bitrate_bps, codec_settings), | 1522 parameters_(config, send_params.options, max_bitrate_bps, codec_settings), | 
| 1491 pending_encoder_reconfiguration_(false), | 1523 pending_encoder_reconfiguration_(false), | 
| 1492 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false), | 1524 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false), | 
| 1493 sending_(false), | 1525 sending_(false), | 
| 1494 muted_(false), | 1526 muted_(false), | 
| 1495 first_frame_timestamp_ms_(0), | 1527 first_frame_timestamp_ms_(0), | 
| 1496 last_frame_timestamp_ms_(0) { | 1528 last_frame_timestamp_ms_(0), | 
| 1529 rtp_parameters_(CreateRtpParametersWithOneEncoding()), | |
| 1530 global_max_bitrate_(max_bitrate_bps) { | |
| 1497 parameters_.config.rtp.max_packet_size = kVideoMtu; | 1531 parameters_.config.rtp.max_packet_size = kVideoMtu; | 
| 1498 parameters_.conference_mode = send_params.conference_mode; | 1532 parameters_.conference_mode = send_params.conference_mode; | 
| 1499 | 1533 | 
| 1500 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); | 1534 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); | 
| 1501 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, | 1535 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, | 
| 1502 ¶meters_.config.rtp.rtx.ssrcs); | 1536 ¶meters_.config.rtp.rtx.ssrcs); | 
| 1503 parameters_.config.rtp.c_name = sp.cname; | 1537 parameters_.config.rtp.c_name = sp.cname; | 
| 1504 parameters_.config.rtp.extensions = rtp_extensions; | 1538 parameters_.config.rtp.extensions = rtp_extensions; | 
| 1505 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size | 1539 parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size | 
| 1506 ? webrtc::RtcpMode::kReducedSize | 1540 ? webrtc::RtcpMode::kReducedSize | 
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1768 bool recreate_stream = false; | 1802 bool recreate_stream = false; | 
| 1769 if (params.rtcp_mode) { | 1803 if (params.rtcp_mode) { | 
| 1770 parameters_.config.rtp.rtcp_mode = *params.rtcp_mode; | 1804 parameters_.config.rtp.rtcp_mode = *params.rtcp_mode; | 
| 1771 recreate_stream = true; | 1805 recreate_stream = true; | 
| 1772 } | 1806 } | 
| 1773 if (params.rtp_header_extensions) { | 1807 if (params.rtp_header_extensions) { | 
| 1774 parameters_.config.rtp.extensions = *params.rtp_header_extensions; | 1808 parameters_.config.rtp.extensions = *params.rtp_header_extensions; | 
| 1775 recreate_stream = true; | 1809 recreate_stream = true; | 
| 1776 } | 1810 } | 
| 1777 if (params.max_bandwidth_bps) { | 1811 if (params.max_bandwidth_bps) { | 
| 1778 // Max bitrate has changed, reconfigure encoder settings on the next frame | 1812 global_max_bitrate_ = *params.max_bandwidth_bps; | 
| 1779 // or stream recreation. | 1813 ApplyBitrateLimit(MinPositive( | 
| 1780 parameters_.max_bitrate_bps = *params.max_bandwidth_bps; | 1814 rtp_parameters_.encodings[0].max_bitrate_bps, global_max_bitrate_)); | 
| 
pthatcher1
2016/03/16 00:48:42
I think we can just leave this code as it was with
 
skvlad
2016/03/16 02:29:22
Done.
 | |
| 1781 pending_encoder_reconfiguration_ = true; | |
| 1782 } | 1815 } | 
| 1783 if (params.conference_mode) { | 1816 if (params.conference_mode) { | 
| 1784 parameters_.conference_mode = *params.conference_mode; | 1817 parameters_.conference_mode = *params.conference_mode; | 
| 1785 } | 1818 } | 
| 1786 if (params.options) | 1819 if (params.options) | 
| 1787 SetOptions(*params.options); | 1820 SetOptions(*params.options); | 
| 1788 | 1821 | 
| 1789 // Set codecs and options. | 1822 // Set codecs and options. | 
| 1790 if (params.codec) { | 1823 if (params.codec) { | 
| 1791 SetCodec(*params.codec); | 1824 SetCodec(*params.codec); | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1805 // that might cause a lock order inversion. | 1838 // that might cause a lock order inversion. | 
| 1806 if (params.rtp_header_extensions) { | 1839 if (params.rtp_header_extensions) { | 
| 1807 sink_wants_.rotation_applied = !ContainsHeaderExtension( | 1840 sink_wants_.rotation_applied = !ContainsHeaderExtension( | 
| 1808 *params.rtp_header_extensions, kRtpVideoRotationHeaderExtension); | 1841 *params.rtp_header_extensions, kRtpVideoRotationHeaderExtension); | 
| 1809 if (capturer_) { | 1842 if (capturer_) { | 
| 1810 capturer_->AddOrUpdateSink(this, sink_wants_); | 1843 capturer_->AddOrUpdateSink(this, sink_wants_); | 
| 1811 } | 1844 } | 
| 1812 } | 1845 } | 
| 1813 } | 1846 } | 
| 1814 | 1847 | 
| 1848 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetRtpParameters( | |
| 1849 const webrtc::RtpParameters& new_parameters) { | |
| 1850 if (!ValidateRtpParameters(new_parameters)) { | |
| 1851 return false; | |
| 1852 } | |
| 1853 | |
| 1854 rtc::CritScope cs(&lock_); | |
| 1855 int per_stream_bitrate_limit = new_parameters.encodings[0].max_bitrate_bps; | |
| 1856 int computed_limit = | |
| 1857 MinPositive(per_stream_bitrate_limit, global_max_bitrate_); | |
| 1858 ApplyBitrateLimit(computed_limit); | |
| 1859 rtp_parameters_ = new_parameters; | |
| 1860 return true; | |
| 
pthatcher1
2016/03/16 00:48:42
I think this whole method could be more simple:
 
skvlad
2016/03/16 02:29:22
Done.
 | |
| 1861 } | |
| 1862 | |
| 1863 bool WebRtcVideoChannel2::WebRtcVideoSendStream::ValidateRtpParameters( | |
| 1864 const webrtc::RtpParameters& rtp_parameters) { | |
| 1865 if (rtp_parameters.encodings.size() != 1) { | |
| 1866 LOG(LS_ERROR) | |
| 1867 << "Attempted to set RtpParameters without exactly one encoding"; | |
| 1868 return false; | |
| 1869 } | |
| 1870 return true; | |
| 1871 } | |
| 1872 | |
| 1873 void WebRtcVideoChannel2::WebRtcVideoSendStream::ApplyBitrateLimit( | |
| 1874 int max_bitrate_bps) { | |
| 1875 if (parameters_.max_bitrate_bps != max_bitrate_bps) { | |
| 1876 parameters_.max_bitrate_bps = max_bitrate_bps; | |
| 1877 pending_encoder_reconfiguration_ = true; | |
| 1878 } | |
| 1879 } | |
| 1880 | |
| 1815 webrtc::VideoEncoderConfig | 1881 webrtc::VideoEncoderConfig | 
| 1816 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( | 1882 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( | 
| 1817 const Dimensions& dimensions, | 1883 const Dimensions& dimensions, | 
| 1818 const VideoCodec& codec) const { | 1884 const VideoCodec& codec) const { | 
| 1819 webrtc::VideoEncoderConfig encoder_config; | 1885 webrtc::VideoEncoderConfig encoder_config; | 
| 1820 bool is_screencast = parameters_.options.is_screencast.value_or(false); | 1886 bool is_screencast = parameters_.options.is_screencast.value_or(false); | 
| 1821 if (is_screencast) { | 1887 if (is_screencast) { | 
| 1822 encoder_config.min_transmit_bitrate_bps = | 1888 encoder_config.min_transmit_bitrate_bps = | 
| 1823 1000 * parameters_.options.screencast_min_bitrate_kbps.value_or(0); | 1889 1000 * parameters_.options.screencast_min_bitrate_kbps.value_or(0); | 
| 1824 encoder_config.content_type = | 1890 encoder_config.content_type = | 
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1843 clamped_codec.width = width; | 1909 clamped_codec.width = width; | 
| 1844 clamped_codec.height = height; | 1910 clamped_codec.height = height; | 
| 1845 | 1911 | 
| 1846 // By default, the stream count for the codec configuration should match the | 1912 // By default, the stream count for the codec configuration should match the | 
| 1847 // number of negotiated ssrcs. But if the codec is blacklisted for simulcast | 1913 // number of negotiated ssrcs. But if the codec is blacklisted for simulcast | 
| 1848 // or a screencast, only configure a single stream. | 1914 // or a screencast, only configure a single stream. | 
| 1849 size_t stream_count = parameters_.config.rtp.ssrcs.size(); | 1915 size_t stream_count = parameters_.config.rtp.ssrcs.size(); | 
| 1850 if (IsCodecBlacklistedForSimulcast(codec.name) || is_screencast) { | 1916 if (IsCodecBlacklistedForSimulcast(codec.name) || is_screencast) { | 
| 1851 stream_count = 1; | 1917 stream_count = 1; | 
| 1852 } | 1918 } | 
| 1853 | 1919 | 
| 
pthatcher1
2016/03/16 00:48:42
I think we could simplify by just doing the follow
 
skvlad
2016/03/16 02:29:22
Done.
 | |
| 1854 encoder_config.streams = | 1920 encoder_config.streams = | 
| 1855 CreateVideoStreams(clamped_codec, parameters_.options, | 1921 CreateVideoStreams(clamped_codec, parameters_.options, | 
| 1856 parameters_.max_bitrate_bps, stream_count); | 1922 parameters_.max_bitrate_bps, stream_count); | 
| 1857 | 1923 | 
| 1858 // Conference mode screencast uses 2 temporal layers split at 100kbit. | 1924 // Conference mode screencast uses 2 temporal layers split at 100kbit. | 
| 1859 if (parameters_.conference_mode && is_screencast && | 1925 if (parameters_.conference_mode && is_screencast && | 
| 1860 encoder_config.streams.size() == 1) { | 1926 encoder_config.streams.size() == 1) { | 
| 1861 ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault(); | 1927 ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault(); | 
| 1862 | 1928 | 
| 1863 // For screenshare in conference mode, tl0 and tl1 bitrates are piggybacked | 1929 // For screenshare in conference mode, tl0 and tl1 bitrates are piggybacked | 
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2531 rtx_mapping[video_codecs[i].codec.id] != | 2597 rtx_mapping[video_codecs[i].codec.id] != | 
| 2532 fec_settings.red_payload_type) { | 2598 fec_settings.red_payload_type) { | 
| 2533 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2599 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 
| 2534 } | 2600 } | 
| 2535 } | 2601 } | 
| 2536 | 2602 | 
| 2537 return video_codecs; | 2603 return video_codecs; | 
| 2538 } | 2604 } | 
| 2539 | 2605 | 
| 2540 } // namespace cricket | 2606 } // namespace cricket | 
| OLD | NEW |