OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 12 matching lines...) Expand all Loading... | |
23 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 23 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
24 #include "webrtc/modules/pacing/paced_sender.h" | 24 #include "webrtc/modules/pacing/paced_sender.h" |
25 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 25 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
26 #include "webrtc/voice_engine/channel_proxy.h" | 26 #include "webrtc/voice_engine/channel_proxy.h" |
27 #include "webrtc/voice_engine/include/voe_base.h" | 27 #include "webrtc/voice_engine/include/voe_base.h" |
28 #include "webrtc/voice_engine/include/voe_volume_control.h" | 28 #include "webrtc/voice_engine/include/voe_volume_control.h" |
29 #include "webrtc/voice_engine/voice_engine_impl.h" | 29 #include "webrtc/voice_engine/voice_engine_impl.h" |
30 | 30 |
31 namespace webrtc { | 31 namespace webrtc { |
32 | 32 |
33 namespace { | |
34 | |
35 constexpr char kOpusCodecName[] = "opus"; | |
36 | |
37 bool IsCodec(const webrtc::CodecInst& codec, const char* ref_name) { | |
38 return (STR_CASE_CMP(codec.plname, ref_name) == 0); | |
39 } | |
40 } // namespace | |
41 | |
42 namespace internal { | 33 namespace internal { |
43 AudioSendStream::AudioSendStream( | 34 AudioSendStream::AudioSendStream( |
44 const webrtc::AudioSendStream::Config& config, | 35 const webrtc::AudioSendStream::Config& config, |
45 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, | 36 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, |
46 rtc::TaskQueue* worker_queue, | 37 rtc::TaskQueue* worker_queue, |
47 PacketRouter* packet_router, | 38 PacketRouter* packet_router, |
48 CongestionController* congestion_controller, | 39 CongestionController* congestion_controller, |
49 BitrateAllocator* bitrate_allocator, | 40 BitrateAllocator* bitrate_allocator, |
50 RtcEventLog* event_log, | 41 RtcEventLog* event_log, |
51 RtcpRttStats* rtcp_rtt_stats) | 42 RtcpRttStats* rtcp_rtt_stats) |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 channel_proxy_->SetVADStatus(false); | 269 channel_proxy_->SetVADStatus(false); |
279 channel_proxy_->SetCodecFECStatus(false); | 270 channel_proxy_->SetCodecFECStatus(false); |
280 | 271 |
281 // We disable audio network adaptor here. This will on one hand make sure that | 272 // We disable audio network adaptor here. This will on one hand make sure that |
282 // audio network adaptor is disabled by default, and on the other allow audio | 273 // audio network adaptor is disabled by default, and on the other allow audio |
283 // network adaptor to be reconfigured, since SetReceiverFrameLengthRange can | 274 // network adaptor to be reconfigured, since SetReceiverFrameLengthRange can |
284 // be only called when audio network adaptor is disabled. | 275 // be only called when audio network adaptor is disabled. |
285 channel_proxy_->DisableAudioNetworkAdaptor(); | 276 channel_proxy_->DisableAudioNetworkAdaptor(); |
286 | 277 |
287 const auto& send_codec_spec = config_.send_codec_spec; | 278 const auto& send_codec_spec = config_.send_codec_spec; |
288 | 279 channel_proxy_->SetSendFormat(send_codec_spec.payload_type, |
the sun
2017/02/22 14:35:01
I'd like to get to a point when AudioSendStream do
ossu
2017/02/22 15:03:35
I've not be able to satisfactorily solve the bitra
| |
289 // We set the codec first, since the below extra configuration is only applied | 280 send_codec_spec.format.format, |
290 // to the "current" codec. | 281 config_.encoder_factory.get()); |
291 | 282 // TODO(ossu): Formalize bandwidth parameters and send along to encoder |
292 // If codec is already configured, we do not it again. | 283 // constructor. |
293 // TODO(minyue): check if this check is really needed, or can we move it into | 284 if (send_codec_spec.target_bitrate_bps) { |
294 // |codec->SetSendCodec|. | 285 channel_proxy_->SetBitrate(*send_codec_spec.target_bitrate_bps, 0); |
295 webrtc::CodecInst current_codec = {0}; | |
296 if (!channel_proxy_->GetSendCodec(¤t_codec) || | |
297 (send_codec_spec.codec_inst != current_codec)) { | |
298 if (!channel_proxy_->SetSendCodec(send_codec_spec.codec_inst)) { | |
299 LOG(LS_WARNING) << "SetSendCodec() failed."; | |
300 return false; | |
301 } | |
302 } | 286 } |
303 | 287 if (config_.audio_network_adaptor_config) { |
304 // Codec internal FEC. Treat any failure as fatal internal error. | 288 // Audio network adaptor is only allowed for Opus currently. |
305 if (send_codec_spec.enable_codec_fec) { | 289 channel_proxy_->EnableAudioNetworkAdaptor( |
306 if (!channel_proxy_->SetCodecFECStatus(true)) { | 290 *config_.audio_network_adaptor_config); |
307 LOG(LS_WARNING) << "SetCodecFECStatus() failed."; | 291 LOG(LS_INFO) << "Audio network adaptor enabled on SSRC " |
308 return false; | 292 << config_.rtp.ssrc; |
309 } | |
310 } | |
311 | |
312 // DTX and maxplaybackrate are only set if current codec is Opus. | |
313 if (IsCodec(send_codec_spec.codec_inst, kOpusCodecName)) { | |
314 if (!channel_proxy_->SetOpusDtx(send_codec_spec.enable_opus_dtx)) { | |
315 LOG(LS_WARNING) << "SetOpusDtx() failed."; | |
316 return false; | |
317 } | |
318 | |
319 // If opus_max_playback_rate <= 0, the default maximum playback rate | |
320 // (48 kHz) will be used. | |
321 if (send_codec_spec.opus_max_playback_rate > 0) { | |
322 if (!channel_proxy_->SetOpusMaxPlaybackRate( | |
323 send_codec_spec.opus_max_playback_rate)) { | |
324 LOG(LS_WARNING) << "SetOpusMaxPlaybackRate() failed."; | |
325 return false; | |
326 } | |
327 } | |
328 | |
329 if (config_.audio_network_adaptor_config) { | |
330 // Audio network adaptor is only allowed for Opus currently. | |
331 // |SetReceiverFrameLengthRange| needs to be called before | |
332 // |EnableAudioNetworkAdaptor|. | |
333 channel_proxy_->SetReceiverFrameLengthRange(send_codec_spec.min_ptime_ms, | |
334 send_codec_spec.max_ptime_ms); | |
335 channel_proxy_->EnableAudioNetworkAdaptor( | |
336 *config_.audio_network_adaptor_config); | |
337 LOG(LS_INFO) << "Audio network adaptor enabled on SSRC " | |
338 << config_.rtp.ssrc; | |
339 } | |
340 } | 293 } |
341 | 294 |
342 // Set the CN payloadtype and the VAD status. | 295 // Set the CN payloadtype and the VAD status. |
343 if (send_codec_spec.cng_payload_type != -1) { | 296 if (send_codec_spec.cng_payload_type != -1) { |
344 // The CN payload type for 8000 Hz clockrate is fixed at 13. | 297 // The CN payload type for 8000 Hz clockrate is fixed at 13. |
345 if (send_codec_spec.cng_plfreq != 8000) { | 298 if (send_codec_spec.cng_plfreq != 8000) { |
346 webrtc::PayloadFrequencies cn_freq; | 299 webrtc::PayloadFrequencies cn_freq; |
347 switch (send_codec_spec.cng_plfreq) { | 300 switch (send_codec_spec.cng_plfreq) { |
348 case 16000: | 301 case 16000: |
349 cn_freq = webrtc::kFreq16000Hz; | 302 cn_freq = webrtc::kFreq16000Hz; |
(...skipping 14 matching lines...) Expand all Loading... | |
364 // Not returning false because the SetSendCNPayloadType will fail if | 317 // Not returning false because the SetSendCNPayloadType will fail if |
365 // the channel is already sending. | 318 // the channel is already sending. |
366 // This can happen if the remote description is applied twice, for | 319 // This can happen if the remote description is applied twice, for |
367 // example in the case of ROAP on top of JSEP, where both side will | 320 // example in the case of ROAP on top of JSEP, where both side will |
368 // send the offer. | 321 // send the offer. |
369 } | 322 } |
370 } | 323 } |
371 | 324 |
372 // Only turn on VAD if we have a CN payload type that matches the | 325 // Only turn on VAD if we have a CN payload type that matches the |
373 // clockrate for the codec we are going to use. | 326 // clockrate for the codec we are going to use. |
374 if (send_codec_spec.cng_plfreq == send_codec_spec.codec_inst.plfreq && | 327 if (send_codec_spec.cng_plfreq == |
375 send_codec_spec.codec_inst.channels == 1) { | 328 send_codec_spec.format.format.clockrate_hz && |
329 send_codec_spec.format.info.num_channels == 1) { | |
376 // TODO(minyue): If CN frequency == 48000 Hz is allowed, consider the | 330 // TODO(minyue): If CN frequency == 48000 Hz is allowed, consider the |
377 // interaction between VAD and Opus FEC. | 331 // interaction between VAD and Opus FEC. |
378 if (!channel_proxy_->SetVADStatus(true)) { | 332 if (!channel_proxy_->SetVADStatus(true)) { |
379 LOG(LS_WARNING) << "SetVADStatus() failed."; | 333 LOG(LS_WARNING) << "SetVADStatus() failed."; |
380 return false; | 334 return false; |
381 } | 335 } |
382 } | 336 } |
383 } | 337 } |
384 return true; | 338 return true; |
385 } | 339 } |
386 | 340 |
387 } // namespace internal | 341 } // namespace internal |
388 } // namespace webrtc | 342 } // namespace webrtc |
OLD | NEW |