Chromium Code Reviews| Index: webrtc/media/engine/webrtcvoiceengine.cc |
| diff --git a/webrtc/media/engine/webrtcvoiceengine.cc b/webrtc/media/engine/webrtcvoiceengine.cc |
| index 2cd19e7435e884ceefe2c801cd8070b12977948c..236d25bc497ace9098119b5afa42c568b6668b19 100644 |
| --- a/webrtc/media/engine/webrtcvoiceengine.cc |
| +++ b/webrtc/media/engine/webrtcvoiceengine.cc |
| @@ -1138,13 +1138,16 @@ int WebRtcVoiceEngine::CreateVoEChannel() { |
| class WebRtcVoiceMediaChannel::WebRtcAudioSendStream |
| : public AudioRenderer::Sink { |
| public: |
| - WebRtcAudioSendStream(int ch, webrtc::AudioTransport* voe_audio_transport, |
| - uint32_t ssrc, const std::string& c_name, |
| + WebRtcAudioSendStream(int ch, |
| + webrtc::AudioTransport* voe_audio_transport, |
| + uint32_t ssrc, |
| + const std::string& c_name, |
| const std::vector<webrtc::RtpExtension>& extensions, |
| webrtc::Call* call) |
| : voe_audio_transport_(voe_audio_transport), |
| call_(call), |
| - config_(nullptr) { |
| + config_(nullptr), |
| + rtp_parameters_(webrtc::RTCRtpParameters::CreateDefault()) { |
| RTC_DCHECK_GE(ch, 0); |
| // TODO(solenberg): Once we're not using FakeWebRtcVoiceEngine anymore: |
| // RTC_DCHECK(voe_audio_transport); |
| @@ -1247,6 +1250,12 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream |
| return config_.voe_channel_id; |
| } |
| + webrtc::RTCRtpParameters rtp_parameters() const { return rtp_parameters_; } |
| + |
| + void set_rtp_parameters(const webrtc::RTCRtpParameters& parameters) { |
| + rtp_parameters_ = parameters; |
| + } |
| + |
| private: |
| rtc::ThreadChecker worker_thread_checker_; |
| rtc::ThreadChecker audio_capture_thread_checker_; |
| @@ -1261,6 +1270,7 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream |
| // PeerConnection will make sure invalidating the pointer before the object |
| // goes away. |
| AudioRenderer* renderer_ = nullptr; |
| + webrtc::RTCRtpParameters rtp_parameters_; |
| RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcAudioSendStream); |
| }; |
| @@ -1429,6 +1439,40 @@ bool WebRtcVoiceMediaChannel::SetRecvParameters( |
| return true; |
| } |
| +webrtc::RTCRtpParameters WebRtcVoiceMediaChannel::GetRtpParameters( |
|
pthatcher1
2016/03/12 01:21:04
Can you split this into a CL for video and a secon
|
| + uint32_t ssrc) { |
| + auto it = send_streams_.find(ssrc); |
| + if (it == send_streams_.end()) { |
| + LOG(LS_WARNING) << "Attempting to get RTP parameters for stream with ssrc " |
| + << ssrc << " which doesn't exist."; |
| + return webrtc::RTCRtpParameters(); |
| + } |
| + return it->second->rtp_parameters(); |
| +} |
| + |
| +bool WebRtcVoiceMediaChannel::SetRtpParameters( |
| + uint32_t ssrc, |
| + const webrtc::RTCRtpParameters& parameters) { |
| + auto it = send_streams_.find(ssrc); |
| + if (it == send_streams_.end()) { |
| + LOG(LS_WARNING) << "Trying to set RTP parameters for stream with ssrc " |
| + << ssrc << " which doesn't exist."; |
| + return false; |
| + } |
| + |
| + if (parameters.encodings.size() != 1) { |
| + LOG(LS_WARNING) |
| + << "Attempting to set RTP parameters without exactly 1 encoding"; |
| + return false; |
| + } |
| + if (ApplyBitrateLimits(it->second->channel(), send_bitrate_bps_, |
| + parameters.encodings[0].max_bitrate_bps)) { |
| + it->second->set_rtp_parameters(parameters); |
| + return true; |
| + } |
|
pthatcher1
2016/03/12 01:21:04
It feels like we should move the ApplyBitrateLimit
|
| + return false; |
| +} |
| + |
| bool WebRtcVoiceMediaChannel::SetOptions(const AudioOptions& options) { |
| RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| LOG(LS_INFO) << "Setting voice channel options: " |
| @@ -2356,15 +2400,39 @@ bool WebRtcVoiceMediaChannel::SetMaxSendBandwidth(int bps) { |
| bool WebRtcVoiceMediaChannel::SetSendBitrateInternal(int bps) { |
| LOG(LS_INFO) << "WebRtcVoiceMediaChannel::SetSendBitrateInternal."; |
| + for (const auto& ch : send_streams_) { |
| + if (!ApplyBitrateLimits( |
| + ch.second->channel(), bps, |
| + ch.second->rtp_parameters().encodings[0].max_bitrate_bps)) { |
| + LOG(LS_INFO) << "Failed to limit max bitrate of a stream"; |
| + return false; |
| + } |
| + } |
| + |
| + if (send_streams_.size() == 0) { |
| + LOG(LS_ERROR) << "send_streams_ empty!"; |
| + } |
| + |
| send_bitrate_setting_ = true; |
| send_bitrate_bps_ = bps; |
| + return true; |
| +} |
| +bool WebRtcVoiceMediaChannel::ApplyBitrateLimits(int channel, |
| + int global_limit, |
| + int local_limit) { |
|
pthatcher1
2016/03/12 01:21:04
Why not just pass in one value and do the min() be
|
| if (!send_codec_) { |
| LOG(LS_INFO) << "The send codec has not been set up yet. " |
| << "The send bitrate setting will be applied later."; |
| return true; |
| } |
| + int bps = MinPositive(global_limit, local_limit); |
| + |
| + LOG(LS_INFO) << "Applying bandwidth limit to channel " << channel |
| + << ": global_limit=" << global_limit |
| + << " local_limit=" << local_limit << " result=" << bps; |
| + |
| // Bitrate is auto by default. |
| // TODO(bemasc): Fix this so that if SetMaxSendBandwidth(50) is followed by |
| // SetMaxSendBandwith(0), the second call removes the previous limit. |
| @@ -2377,12 +2445,10 @@ bool WebRtcVoiceMediaChannel::SetSendBitrateInternal(int bps) { |
| if (is_multi_rate) { |
| // If codec is multi-rate then just set the bitrate. |
| codec.rate = bps; |
| - for (const auto& ch : send_streams_) { |
| - if (!SetSendCodec(ch.second->channel(), codec)) { |
| - LOG(LS_INFO) << "Failed to set codec " << codec.plname |
| - << " to bitrate " << bps << " bps."; |
| - return false; |
| - } |
| + if (!SetSendCodec(channel, codec)) { |
| + LOG(LS_INFO) << "Failed to set codec " << codec.plname << " to bitrate " |
| + << bps << " bps."; |
| + return false; |
| } |
| return true; |
| } else { |