OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2004 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 auto it = std::unique(payload_types.begin(), payload_types.end()); | 179 auto it = std::unique(payload_types.begin(), payload_types.end()); |
180 return it == payload_types.end(); | 180 return it == payload_types.end(); |
181 } | 181 } |
182 | 182 |
183 // Return true if codec.params[feature] == "1", false otherwise. | 183 // Return true if codec.params[feature] == "1", false otherwise. |
184 bool IsCodecFeatureEnabled(const AudioCodec& codec, const char* feature) { | 184 bool IsCodecFeatureEnabled(const AudioCodec& codec, const char* feature) { |
185 int value; | 185 int value; |
186 return codec.GetParam(feature, &value) && value == 1; | 186 return codec.GetParam(feature, &value) && value == 1; |
187 } | 187 } |
188 | 188 |
| 189 // Returns integer parameter params[feature] if it is defined. Returns |
| 190 // |default_value| otherwise. |
| 191 int GetCodecFeatureInt(const AudioCodec& codec, |
| 192 const char* feature, |
| 193 int default_value) { |
| 194 int value; |
| 195 if (codec.GetParam(feature, &value)) { |
| 196 return value; |
| 197 } |
| 198 return default_value; |
| 199 } |
| 200 |
189 // Use params[kCodecParamMaxAverageBitrate] if it is defined, use codec.bitrate | 201 // Use params[kCodecParamMaxAverageBitrate] if it is defined, use codec.bitrate |
190 // otherwise. If the value (either from params or codec.bitrate) <=0, use the | 202 // otherwise. If the value (either from params or codec.bitrate) <=0, use the |
191 // default configuration. If the value is beyond feasible bit rate of Opus, | 203 // default configuration. If the value is beyond feasible bit rate of Opus, |
192 // clamp it. Returns the Opus bit rate for operation. | 204 // clamp it. Returns the Opus bit rate for operation. |
193 int GetOpusBitrate(const AudioCodec& codec, int max_playback_rate) { | 205 int GetOpusBitrate(const AudioCodec& codec, int max_playback_rate) { |
194 int bitrate = 0; | 206 int bitrate = 0; |
195 bool use_param = true; | 207 bool use_param = true; |
196 if (!codec.GetParam(kCodecParamMaxAverageBitrate, &bitrate)) { | 208 if (!codec.GetParam(kCodecParamMaxAverageBitrate, &bitrate)) { |
197 bitrate = codec.bitrate; | 209 bitrate = codec.bitrate; |
198 use_param = false; | 210 use_param = false; |
(...skipping 15 matching lines...) Expand all Loading... |
214 std::string rate_source = | 226 std::string rate_source = |
215 use_param ? "Codec parameter \"maxaveragebitrate\"" : | 227 use_param ? "Codec parameter \"maxaveragebitrate\"" : |
216 "Supplied Opus bitrate"; | 228 "Supplied Opus bitrate"; |
217 LOG(LS_WARNING) << rate_source | 229 LOG(LS_WARNING) << rate_source |
218 << " is invalid and is replaced by: " | 230 << " is invalid and is replaced by: " |
219 << bitrate; | 231 << bitrate; |
220 } | 232 } |
221 return bitrate; | 233 return bitrate; |
222 } | 234 } |
223 | 235 |
224 // Returns kOpusDefaultPlaybackRate if params[kCodecParamMaxPlaybackRate] is not | 236 void GetOpusConfig(const AudioCodec& codec, |
225 // defined. Returns the value of params[kCodecParamMaxPlaybackRate] otherwise. | 237 webrtc::CodecInst* voe_codec, |
226 int GetOpusMaxPlaybackRate(const AudioCodec& codec) { | 238 bool* enable_codec_fec, |
227 int value; | 239 int* max_playback_rate, |
228 if (codec.GetParam(kCodecParamMaxPlaybackRate, &value)) { | 240 bool* enable_codec_dtx, |
229 return value; | 241 int* min_ptime_ms, |
230 } | 242 int* max_ptime_ms) { |
231 return kOpusDefaultMaxPlaybackRate; | |
232 } | |
233 | |
234 void GetOpusConfig(const AudioCodec& codec, webrtc::CodecInst* voe_codec, | |
235 bool* enable_codec_fec, int* max_playback_rate, | |
236 bool* enable_codec_dtx) { | |
237 *enable_codec_fec = IsCodecFeatureEnabled(codec, kCodecParamUseInbandFec); | 243 *enable_codec_fec = IsCodecFeatureEnabled(codec, kCodecParamUseInbandFec); |
238 *enable_codec_dtx = IsCodecFeatureEnabled(codec, kCodecParamUseDtx); | 244 *enable_codec_dtx = IsCodecFeatureEnabled(codec, kCodecParamUseDtx); |
239 *max_playback_rate = GetOpusMaxPlaybackRate(codec); | 245 *max_playback_rate = GetCodecFeatureInt(codec, kCodecParamMaxPlaybackRate, |
| 246 kOpusDefaultMaxPlaybackRate); |
| 247 *max_ptime_ms = |
| 248 GetCodecFeatureInt(codec, kCodecParamMaxPTime, kOpusDefaultMaxPTime); |
| 249 *min_ptime_ms = |
| 250 GetCodecFeatureInt(codec, kCodecParamMinPTime, kOpusDefaultMinPTime); |
240 | 251 |
241 // If OPUS, change what we send according to the "stereo" codec | 252 // If OPUS, change what we send according to the "stereo" codec |
242 // parameter, and not the "channels" parameter. We set | 253 // parameter, and not the "channels" parameter. We set |
243 // voe_codec.channels to 2 if "stereo=1" and 1 otherwise. If | 254 // voe_codec.channels to 2 if "stereo=1" and 1 otherwise. If |
244 // the bitrate is not specified, i.e. is <= zero, we set it to the | 255 // the bitrate is not specified, i.e. is <= zero, we set it to the |
245 // appropriate default value for mono or stereo Opus. | 256 // appropriate default value for mono or stereo Opus. |
246 | |
247 voe_codec->channels = IsCodecFeatureEnabled(codec, kCodecParamStereo) ? 2 : 1; | 257 voe_codec->channels = IsCodecFeatureEnabled(codec, kCodecParamStereo) ? 2 : 1; |
248 voe_codec->rate = GetOpusBitrate(codec, *max_playback_rate); | 258 voe_codec->rate = GetOpusBitrate(codec, *max_playback_rate); |
249 } | 259 } |
250 | 260 |
251 webrtc::AudioState::Config MakeAudioStateConfig(VoEWrapper* voe_wrapper) { | 261 webrtc::AudioState::Config MakeAudioStateConfig(VoEWrapper* voe_wrapper) { |
252 webrtc::AudioState::Config config; | 262 webrtc::AudioState::Config config; |
253 config.voice_engine = voe_wrapper->engine(); | 263 config.voice_engine = voe_wrapper->engine(); |
254 return config; | 264 return config; |
255 } | 265 } |
256 | 266 |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 LOG_RTCERR1(SetRecordingSampleRate, *options.recording_sample_rate); | 901 LOG_RTCERR1(SetRecordingSampleRate, *options.recording_sample_rate); |
892 } | 902 } |
893 } | 903 } |
894 | 904 |
895 if (options.playout_sample_rate) { | 905 if (options.playout_sample_rate) { |
896 LOG(LS_INFO) << "Playout sample rate is " << *options.playout_sample_rate; | 906 LOG(LS_INFO) << "Playout sample rate is " << *options.playout_sample_rate; |
897 if (adm()->SetPlayoutSampleRate(*options.playout_sample_rate)) { | 907 if (adm()->SetPlayoutSampleRate(*options.playout_sample_rate)) { |
898 LOG_RTCERR1(SetPlayoutSampleRate, *options.playout_sample_rate); | 908 LOG_RTCERR1(SetPlayoutSampleRate, *options.playout_sample_rate); |
899 } | 909 } |
900 } | 910 } |
901 | |
902 return true; | 911 return true; |
903 } | 912 } |
904 | 913 |
905 void WebRtcVoiceEngine::SetDefaultDevices() { | 914 void WebRtcVoiceEngine::SetDefaultDevices() { |
906 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 915 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
907 #if !defined(WEBRTC_IOS) | 916 #if !defined(WEBRTC_IOS) |
908 int in_id = kDefaultAudioDeviceId; | 917 int in_id = kDefaultAudioDeviceId; |
909 int out_id = kDefaultAudioDeviceId; | 918 int out_id = kDefaultAudioDeviceId; |
910 LOG(LS_INFO) << "Setting microphone to (id=" << in_id | 919 LOG(LS_INFO) << "Setting microphone to (id=" << in_id |
911 << ") and speaker to (id=" << out_id << ")"; | 920 << ") and speaker to (id=" << out_id << ")"; |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 : public AudioSource::Sink { | 1152 : public AudioSource::Sink { |
1144 public: | 1153 public: |
1145 WebRtcAudioSendStream( | 1154 WebRtcAudioSendStream( |
1146 int ch, | 1155 int ch, |
1147 webrtc::AudioTransport* voe_audio_transport, | 1156 webrtc::AudioTransport* voe_audio_transport, |
1148 uint32_t ssrc, | 1157 uint32_t ssrc, |
1149 const std::string& c_name, | 1158 const std::string& c_name, |
1150 const webrtc::AudioSendStream::Config::SendCodecSpec& send_codec_spec, | 1159 const webrtc::AudioSendStream::Config::SendCodecSpec& send_codec_spec, |
1151 const std::vector<webrtc::RtpExtension>& extensions, | 1160 const std::vector<webrtc::RtpExtension>& extensions, |
1152 int max_send_bitrate_bps, | 1161 int max_send_bitrate_bps, |
| 1162 const rtc::Optional<std::string>& audio_network_adaptor_config, |
1153 webrtc::Call* call, | 1163 webrtc::Call* call, |
1154 webrtc::Transport* send_transport) | 1164 webrtc::Transport* send_transport) |
1155 : voe_audio_transport_(voe_audio_transport), | 1165 : voe_audio_transport_(voe_audio_transport), |
1156 call_(call), | 1166 call_(call), |
1157 config_(send_transport), | 1167 config_(send_transport), |
1158 max_send_bitrate_bps_(max_send_bitrate_bps), | 1168 max_send_bitrate_bps_(max_send_bitrate_bps), |
1159 rtp_parameters_(CreateRtpParametersWithOneEncoding()) { | 1169 rtp_parameters_(CreateRtpParametersWithOneEncoding()) { |
1160 RTC_DCHECK_GE(ch, 0); | 1170 RTC_DCHECK_GE(ch, 0); |
1161 // TODO(solenberg): Once we're not using FakeWebRtcVoiceEngine anymore: | 1171 // TODO(solenberg): Once we're not using FakeWebRtcVoiceEngine anymore: |
1162 // RTC_DCHECK(voe_audio_transport); | 1172 // RTC_DCHECK(voe_audio_transport); |
1163 RTC_DCHECK(call); | 1173 RTC_DCHECK(call); |
1164 config_.rtp.ssrc = ssrc; | 1174 config_.rtp.ssrc = ssrc; |
1165 config_.rtp.c_name = c_name; | 1175 config_.rtp.c_name = c_name; |
1166 config_.voe_channel_id = ch; | 1176 config_.voe_channel_id = ch; |
1167 config_.rtp.extensions = extensions; | 1177 config_.rtp.extensions = extensions; |
| 1178 if (audio_network_adaptor_config) { |
| 1179 config_.enable_audio_network_adaptor = true; |
| 1180 config_.audio_network_adaptor_config = *audio_network_adaptor_config; |
| 1181 } else { |
| 1182 config_.enable_audio_network_adaptor = false; |
| 1183 } |
1168 RecreateAudioSendStream(send_codec_spec); | 1184 RecreateAudioSendStream(send_codec_spec); |
1169 } | 1185 } |
1170 | 1186 |
1171 ~WebRtcAudioSendStream() override { | 1187 ~WebRtcAudioSendStream() override { |
1172 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1188 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
1173 ClearSource(); | 1189 ClearSource(); |
1174 call_->DestroyAudioSendStream(stream_); | 1190 call_->DestroyAudioSendStream(stream_); |
1175 } | 1191 } |
1176 | 1192 |
1177 void RecreateAudioSendStream( | 1193 void RecreateAudioSendStream( |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1823 | 1839 |
1824 send_codec_spec.transport_cc_enabled = HasTransportCc(*codec); | 1840 send_codec_spec.transport_cc_enabled = HasTransportCc(*codec); |
1825 send_codec_spec.nack_enabled = HasNack(*codec); | 1841 send_codec_spec.nack_enabled = HasNack(*codec); |
1826 | 1842 |
1827 // For Opus as the send codec, we are to determine inband FEC, maximum | 1843 // For Opus as the send codec, we are to determine inband FEC, maximum |
1828 // playback rate, and opus internal dtx. | 1844 // playback rate, and opus internal dtx. |
1829 if (IsCodec(*codec, kOpusCodecName)) { | 1845 if (IsCodec(*codec, kOpusCodecName)) { |
1830 GetOpusConfig(*codec, &send_codec_spec.codec_inst, | 1846 GetOpusConfig(*codec, &send_codec_spec.codec_inst, |
1831 &send_codec_spec.enable_codec_fec, | 1847 &send_codec_spec.enable_codec_fec, |
1832 &send_codec_spec.opus_max_playback_rate, | 1848 &send_codec_spec.opus_max_playback_rate, |
1833 &send_codec_spec.enable_opus_dtx); | 1849 &send_codec_spec.enable_opus_dtx, |
| 1850 &send_codec_spec.min_ptime_ms, |
| 1851 &send_codec_spec.max_ptime_ms); |
1834 } | 1852 } |
1835 | 1853 |
1836 // Set packet size if the AudioCodec param kCodecParamPTime is set. | 1854 // Set packet size if the AudioCodec param kCodecParamPTime is set. |
1837 int ptime_ms = 0; | 1855 int ptime_ms = 0; |
1838 if (codec->GetParam(kCodecParamPTime, &ptime_ms)) { | 1856 if (codec->GetParam(kCodecParamPTime, &ptime_ms)) { |
1839 if (!WebRtcVoiceCodecs::SetPTimeAsPacketSize( | 1857 if (!WebRtcVoiceCodecs::SetPTimeAsPacketSize( |
1840 &send_codec_spec.codec_inst, ptime_ms)) { | 1858 &send_codec_spec.codec_inst, ptime_ms)) { |
1841 LOG(LS_WARNING) << "Failed to set packet size for codec " | 1859 LOG(LS_WARNING) << "Failed to set packet size for codec " |
1842 << send_codec_spec.codec_inst.plname; | 1860 << send_codec_spec.codec_inst.plname; |
1843 return false; | 1861 return false; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2001 return false; | 2019 return false; |
2002 } | 2020 } |
2003 | 2021 |
2004 // Save the channel to send_streams_, so that RemoveSendStream() can still | 2022 // Save the channel to send_streams_, so that RemoveSendStream() can still |
2005 // delete the channel in case failure happens below. | 2023 // delete the channel in case failure happens below. |
2006 webrtc::AudioTransport* audio_transport = | 2024 webrtc::AudioTransport* audio_transport = |
2007 engine()->voe()->base()->audio_transport(); | 2025 engine()->voe()->base()->audio_transport(); |
2008 | 2026 |
2009 WebRtcAudioSendStream* stream = new WebRtcAudioSendStream( | 2027 WebRtcAudioSendStream* stream = new WebRtcAudioSendStream( |
2010 channel, audio_transport, ssrc, sp.cname, send_codec_spec_, | 2028 channel, audio_transport, ssrc, sp.cname, send_codec_spec_, |
2011 send_rtp_extensions_, max_send_bitrate_bps_, call_, this); | 2029 send_rtp_extensions_, max_send_bitrate_bps_, |
| 2030 options_.audio_network_adaptor_config, call_, this); |
2012 send_streams_.insert(std::make_pair(ssrc, stream)); | 2031 send_streams_.insert(std::make_pair(ssrc, stream)); |
2013 | 2032 |
2014 // At this point the stream's local SSRC has been updated. If it is the first | 2033 // At this point the stream's local SSRC has been updated. If it is the first |
2015 // send stream, make sure that all the receive streams are updated with the | 2034 // send stream, make sure that all the receive streams are updated with the |
2016 // same SSRC in order to send receiver reports. | 2035 // same SSRC in order to send receiver reports. |
2017 if (send_streams_.size() == 1) { | 2036 if (send_streams_.size() == 1) { |
2018 receiver_reports_ssrc_ = ssrc; | 2037 receiver_reports_ssrc_ = ssrc; |
2019 for (const auto& kv : recv_streams_) { | 2038 for (const auto& kv : recv_streams_) { |
2020 // TODO(solenberg): Allow applications to set the RTCP SSRC of receive | 2039 // TODO(solenberg): Allow applications to set the RTCP SSRC of receive |
2021 // streams instead, so we can avoid recreating the streams here. | 2040 // streams instead, so we can avoid recreating the streams here. |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2509 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 2528 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
2510 const auto it = send_streams_.find(ssrc); | 2529 const auto it = send_streams_.find(ssrc); |
2511 if (it != send_streams_.end()) { | 2530 if (it != send_streams_.end()) { |
2512 return it->second->channel(); | 2531 return it->second->channel(); |
2513 } | 2532 } |
2514 return -1; | 2533 return -1; |
2515 } | 2534 } |
2516 } // namespace cricket | 2535 } // namespace cricket |
2517 | 2536 |
2518 #endif // HAVE_WEBRTC_VOICE | 2537 #endif // HAVE_WEBRTC_VOICE |
OLD | NEW |