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

Unified Diff: webrtc/media/engine/webrtcvoiceengine.cc

Issue 2397573006: Using AudioOption to enable audio network adaptor. (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/media/engine/webrtcvoiceengine.cc
diff --git a/webrtc/media/engine/webrtcvoiceengine.cc b/webrtc/media/engine/webrtcvoiceengine.cc
index 358c142a1b01bea7ba3a977f55279a78cc45221f..d4d9f323ede41a5e62139cafcb4ce231b9fdc2c6 100644
--- a/webrtc/media/engine/webrtcvoiceengine.cc
+++ b/webrtc/media/engine/webrtcvoiceengine.cc
@@ -186,6 +186,18 @@ bool IsCodecFeatureEnabled(const AudioCodec& codec, const char* feature) {
return codec.GetParam(feature, &value) && value == 1;
}
+// Returns integer parameter params[feature] if it is defined. Returns
+// |default_value| otherwise.
+int GetCodecFeatureInt(const AudioCodec& codec,
+ const char* feature,
+ int default_value) {
+ int value;
+ if (codec.GetParam(feature, &value)) {
+ return value;
+ }
+ return default_value;
+}
+
// Use params[kCodecParamMaxAverageBitrate] if it is defined, use codec.bitrate
// otherwise. If the value (either from params or codec.bitrate) <=0, use the
// default configuration. If the value is beyond feasible bit rate of Opus,
@@ -221,29 +233,27 @@ int GetOpusBitrate(const AudioCodec& codec, int max_playback_rate) {
return bitrate;
}
-// Returns kOpusDefaultPlaybackRate if params[kCodecParamMaxPlaybackRate] is not
-// defined. Returns the value of params[kCodecParamMaxPlaybackRate] otherwise.
-int GetOpusMaxPlaybackRate(const AudioCodec& codec) {
- int value;
- if (codec.GetParam(kCodecParamMaxPlaybackRate, &value)) {
- return value;
- }
- return kOpusDefaultMaxPlaybackRate;
-}
-
-void GetOpusConfig(const AudioCodec& codec, webrtc::CodecInst* voe_codec,
- bool* enable_codec_fec, int* max_playback_rate,
- bool* enable_codec_dtx) {
+void GetOpusConfig(const AudioCodec& codec,
+ webrtc::CodecInst* voe_codec,
+ bool* enable_codec_fec,
+ int* max_playback_rate,
+ bool* enable_codec_dtx,
+ int* min_ptime_ms,
+ int* max_ptime_ms) {
*enable_codec_fec = IsCodecFeatureEnabled(codec, kCodecParamUseInbandFec);
*enable_codec_dtx = IsCodecFeatureEnabled(codec, kCodecParamUseDtx);
- *max_playback_rate = GetOpusMaxPlaybackRate(codec);
+ *max_playback_rate = GetCodecFeatureInt(codec, kCodecParamMaxPlaybackRate,
+ kOpusDefaultMaxPlaybackRate);
+ *max_ptime_ms =
+ GetCodecFeatureInt(codec, kCodecParamMaxPTime, kOpusDefaultMaxPTime);
+ *min_ptime_ms =
+ GetCodecFeatureInt(codec, kCodecParamMinPTime, kOpusDefaultMinPTime);
// If OPUS, change what we send according to the "stereo" codec
// parameter, and not the "channels" parameter. We set
// voe_codec.channels to 2 if "stereo=1" and 1 otherwise. If
// the bitrate is not specified, i.e. is <= zero, we set it to the
// appropriate default value for mono or stereo Opus.
-
voe_codec->channels = IsCodecFeatureEnabled(codec, kCodecParamStereo) ? 2 : 1;
voe_codec->rate = GetOpusBitrate(codec, *max_playback_rate);
}
@@ -828,6 +838,12 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) {
}
}
+ if (options.audio_network_adaptor_config) {
+ channel_config_.acm_config.audio_network_adaptor_enabled = true;
+ channel_config_.acm_config.audio_network_adaptor_config =
+ *options.audio_network_adaptor_config;
+ }
+
webrtc::Config config;
if (options.delay_agnostic_aec)
@@ -1304,6 +1320,26 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream
UpdateSendState();
}
+ bool EnableAudioNetworkAdaptor(const std::string& config_string) {
+ RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
+ RTC_DCHECK(stream_);
+ return stream_->EnableAudioNetworkAdaptor(config_string);
+ }
+
+ void DisableAudioNetworkAdaptor() {
+ RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
+ RTC_DCHECK(stream_);
+ stream_->DisableAudioNetworkAdaptor();
+ }
+
+ void SetReceiverFrameLengthRange(int min_frame_length_ms,
michaelt 2016/10/19 13:32:55 Will you add a interface for ana_dump as well ?
+ int max_frame_length_ms) {
+ RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
+ RTC_DCHECK(stream_);
+ stream_->SetReceiverFrameLengthRange(min_frame_length_ms,
+ max_frame_length_ms);
+ }
+
private:
void UpdateSendState() {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
@@ -1786,7 +1822,9 @@ bool WebRtcVoiceMediaChannel::SetSendCodecs(
GetOpusConfig(*codec, &send_codec_spec.codec_inst,
&send_codec_spec.enable_codec_fec,
&send_codec_spec.opus_max_playback_rate,
- &send_codec_spec.enable_opus_dtx);
+ &send_codec_spec.enable_opus_dtx,
+ &send_codec_spec.min_ptime_ms,
+ &send_codec_spec.max_ptime_ms);
}
// Set packet size if the AudioCodec param kCodecParamPTime is set.
@@ -1839,7 +1877,7 @@ bool WebRtcVoiceMediaChannel::SetSendCodecs(
send_codec_spec_ = std::move(send_codec_spec);
for (const auto& kv : send_streams_) {
kv.second->RecreateAudioSendStream(send_codec_spec_);
- if (!SetSendCodecs(kv.second->channel(), kv.second->rtp_parameters())) {
+ if (!SetSendCodecs(kv.first, kv.second->rtp_parameters())) {
return false;
}
}
@@ -1865,8 +1903,10 @@ bool WebRtcVoiceMediaChannel::SetSendCodecs(
// Apply current codec settings to a single voe::Channel used for sending.
bool WebRtcVoiceMediaChannel::SetSendCodecs(
- int channel,
+ uint32_t ssrc,
const webrtc::RtpParameters& rtp_parameters) {
+ int channel = GetSendChannelId(ssrc);
+
// Disable VAD and FEC unless we know the other side wants them.
engine()->voe()->codec()->SetVADStatus(channel, false);
engine()->voe()->codec()->SetFECStatus(channel, false);
@@ -1966,6 +2006,26 @@ bool WebRtcVoiceMediaChannel::SetSendCodecs(
}
}
}
+
+ auto it = send_streams_.find(ssrc);
+ RTC_CHECK(it != send_streams_.end());
+ const auto acm_config = engine()->channel_config_.acm_config;
+ if (acm_config.audio_network_adaptor_enabled) {
+ if (IsCodec(send_codec_spec_.codec_inst, kOpusCodecName)) {
+ // Audio network adaptor is only allowed for Opus currently.
+ if (it->second->EnableAudioNetworkAdaptor(
michaelt 2016/10/19 13:32:55 You will have to change the order of Enable and se
+ acm_config.audio_network_adaptor_config)) {
the sun 2016/10/06 08:03:46 If this information is already propagated to the C
+ LOG(LS_ERROR) << "Audio network adaptor cannot be enabled on SSRC "
+ << ssrc;
+ return false;
+ }
+ LOG(LS_INFO) << "Audio network adaptor enabled on SSRC " << ssrc;
+ it->second->SetReceiverFrameLengthRange(send_codec_spec_.min_ptime_ms,
+ send_codec_spec_.max_ptime_ms);
+ }
+ } else {
+ it->second->DisableAudioNetworkAdaptor();
+ }
return true;
}
@@ -2103,7 +2163,7 @@ bool WebRtcVoiceMediaChannel::AddSendStream(const StreamParams& sp) {
// Set the current codecs to be used for the new channel. We need to do this
// after adding the channel to send_channels_, because of how max bitrate is
// currently being configured by SetSendCodec().
- if (HasSendCodec() && !SetSendCodecs(channel, stream->rtp_parameters())) {
+ if (HasSendCodec() && !SetSendCodecs(ssrc, stream->rtp_parameters())) {
RemoveSendStream(ssrc);
return false;
}

Powered by Google App Engine
This is Rietveld 408576698