Index: webrtc/media/engine/webrtcvoiceengine.cc |
diff --git a/webrtc/media/engine/webrtcvoiceengine.cc b/webrtc/media/engine/webrtcvoiceengine.cc |
index 954008cfa1c69ed7a9f3864928cf8eb95842f76f..c1aca1708360518d0da2e00627e9ae29a9b55863 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; |
the sun
2016/10/25 09:25:46
= 0
always initializing is a good habit
minyue-webrtc
2016/10/27 14:33:10
Done.
|
+ 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); |
} |
@@ -898,7 +908,6 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { |
LOG_RTCERR1(SetPlayoutSampleRate, *options.playout_sample_rate); |
} |
} |
- |
return true; |
} |
@@ -1150,6 +1159,7 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream |
const webrtc::AudioSendStream::Config::SendCodecSpec& send_codec_spec, |
const std::vector<webrtc::RtpExtension>& extensions, |
int max_send_bitrate_bps, |
+ const rtc::Optional<std::string>& audio_network_adaptor_config, |
webrtc::Call* call, |
webrtc::Transport* send_transport) |
: voe_audio_transport_(voe_audio_transport), |
@@ -1165,6 +1175,7 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream |
config_.rtp.c_name = c_name; |
config_.voe_channel_id = ch; |
config_.rtp.extensions = extensions; |
+ config_.audio_network_adaptor_config = audio_network_adaptor_config; |
RecreateAudioSendStream(send_codec_spec); |
} |
@@ -1196,6 +1207,16 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream |
RecreateAudioSendStream(); |
} |
+ void RecreateAudioSendStream( |
+ const rtc::Optional<std::string>& audio_network_adaptor_config) { |
+ RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
+ if (config_.audio_network_adaptor_config == audio_network_adaptor_config) { |
+ return; |
+ } |
+ config_.audio_network_adaptor_config = audio_network_adaptor_config; |
+ RecreateAudioSendStream(); |
+ } |
+ |
bool SetMaxSendBitrate(int bps) { |
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
auto send_rate = |
@@ -1717,6 +1738,25 @@ bool WebRtcVoiceMediaChannel::SetOptions(const AudioOptions& options) { |
"Failed to apply engine options during channel SetOptions."; |
return false; |
} |
+ |
+ if (options_.audio_network_adaptor) { |
+ // Only override current setting when |options_.audio_network_adaptor| has |
+ // a value. |
+ if (!*options_.audio_network_adaptor) { |
the sun
2016/10/25 09:25:46
Simplify the logic to use a single loop.
|
+ // Turn off audio network adaptor. |
+ for (auto& it : send_streams_) { |
+ it.second->RecreateAudioSendStream(rtc::Optional<std::string>()); |
+ } |
+ } else if (options_.audio_network_adaptor_config) { |
+ // Turn on audio network adaptor only when |
+ // |options_.audio_network_adaptor_config| is defined. |
+ for (auto& it : send_streams_) { |
+ it.second->RecreateAudioSendStream( |
+ options_.audio_network_adaptor_config); |
+ } |
+ } |
+ } |
+ |
LOG(LS_INFO) << "Set voice channel options. Current options: " |
<< options_.ToString(); |
return true; |
@@ -1830,7 +1870,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. |
@@ -2006,9 +2048,17 @@ bool WebRtcVoiceMediaChannel::AddSendStream(const StreamParams& sp) { |
webrtc::AudioTransport* audio_transport = |
engine()->voe()->base()->audio_transport(); |
+ rtc::Optional<std::string> audio_network_adaptor_config; |
+ if (options_.audio_network_adaptor && *options_.audio_network_adaptor && |
the sun
2016/10/25 09:25:46
So this is exactly the same logic as in SetOptions
minyue-webrtc
2016/10/27 14:33:10
Not really exactly the same, here we interpret "op
|
+ options_.audio_network_adaptor_config) { |
+ // Turn on audio network adaptor only when |options_.audio_network_adaptor| |
+ // equals true and |options_.audio_network_adaptor_config| has a value. |
+ audio_network_adaptor_config = options_.audio_network_adaptor_config; |
+ } |
WebRtcAudioSendStream* stream = new WebRtcAudioSendStream( |
channel, audio_transport, ssrc, sp.cname, send_codec_spec_, |
- send_rtp_extensions_, max_send_bitrate_bps_, call_, this); |
+ send_rtp_extensions_, max_send_bitrate_bps_, audio_network_adaptor_config, |
+ call_, this); |
send_streams_.insert(std::make_pair(ssrc, stream)); |
// At this point the stream's local SSRC has been updated. If it is the first |