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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 // draft-spittka-payload-rtp-opus-03 | 76 // draft-spittka-payload-rtp-opus-03 |
77 | 77 |
78 // Recommended bitrates: | 78 // Recommended bitrates: |
79 // 8-12 kb/s for NB speech, | 79 // 8-12 kb/s for NB speech, |
80 // 16-20 kb/s for WB speech, | 80 // 16-20 kb/s for WB speech, |
81 // 28-40 kb/s for FB speech, | 81 // 28-40 kb/s for FB speech, |
82 // 48-64 kb/s for FB mono music, and | 82 // 48-64 kb/s for FB mono music, and |
83 // 64-128 kb/s for FB stereo music. | 83 // 64-128 kb/s for FB stereo music. |
84 // The current implementation applies the following values to mono signals, | 84 // The current implementation applies the following values to mono signals, |
85 // and multiplies them by 2 for stereo. | 85 // and multiplies them by 2 for stereo. |
86 const int kOpusBitrateNb = 12000; | 86 const int kOpusBitrateNbBps = 12000; |
87 const int kOpusBitrateWb = 20000; | 87 const int kOpusBitrateWbBps = 20000; |
88 const int kOpusBitrateFb = 32000; | 88 const int kOpusBitrateFbBps = 32000; |
89 | 89 |
90 // Opus bitrate should be in the range between 6000 and 510000. | 90 // Opus bitrate should be in the range between 6000 and 510000. |
91 const int kOpusMinBitrate = 6000; | 91 const int kOpusMinBitrateBps = 6000; |
92 const int kOpusMaxBitrate = 510000; | 92 const int kOpusMaxBitrateBps = 510000; |
93 | 93 |
94 // iSAC bitrate should be <= 56000. | 94 // iSAC bitrate should be <= 56000. |
95 const int kIsacMaxBitrate = 56000; | 95 const int kIsacMaxBitrateBps = 56000; |
96 | 96 |
97 // Default audio dscp value. | 97 // Default audio dscp value. |
98 // See http://tools.ietf.org/html/rfc2474 for details. | 98 // See http://tools.ietf.org/html/rfc2474 for details. |
99 // See also http://tools.ietf.org/html/draft-jennings-rtcweb-qos-00 | 99 // See also http://tools.ietf.org/html/draft-jennings-rtcweb-qos-00 |
100 const rtc::DiffServCodePoint kAudioDscpValue = rtc::DSCP_EF; | 100 const rtc::DiffServCodePoint kAudioDscpValue = rtc::DSCP_EF; |
101 | 101 |
102 // Constants from voice_engine_defines.h. | 102 // Constants from voice_engine_defines.h. |
103 const int kMinTelephoneEventCode = 0; // RFC4733 (Section 2.3.1) | 103 const int kMinTelephoneEventCode = 0; // RFC4733 (Section 2.3.1) |
104 const int kMaxTelephoneEventCode = 255; | 104 const int kMaxTelephoneEventCode = 255; |
105 const int kMinTelephoneEventDuration = 100; | 105 const int kMinTelephoneEventDuration = 100; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 // clamp it. Returns the Opus bit rate for operation. | 215 // clamp it. Returns the Opus bit rate for operation. |
216 int GetOpusBitrate(const AudioCodec& codec, int max_playback_rate) { | 216 int GetOpusBitrate(const AudioCodec& codec, int max_playback_rate) { |
217 int bitrate = 0; | 217 int bitrate = 0; |
218 bool use_param = true; | 218 bool use_param = true; |
219 if (!codec.GetParam(kCodecParamMaxAverageBitrate, &bitrate)) { | 219 if (!codec.GetParam(kCodecParamMaxAverageBitrate, &bitrate)) { |
220 bitrate = codec.bitrate; | 220 bitrate = codec.bitrate; |
221 use_param = false; | 221 use_param = false; |
222 } | 222 } |
223 if (bitrate <= 0) { | 223 if (bitrate <= 0) { |
224 if (max_playback_rate <= 8000) { | 224 if (max_playback_rate <= 8000) { |
225 bitrate = kOpusBitrateNb; | 225 bitrate = kOpusBitrateNbBps; |
226 } else if (max_playback_rate <= 16000) { | 226 } else if (max_playback_rate <= 16000) { |
227 bitrate = kOpusBitrateWb; | 227 bitrate = kOpusBitrateWbBps; |
228 } else { | 228 } else { |
229 bitrate = kOpusBitrateFb; | 229 bitrate = kOpusBitrateFbBps; |
230 } | 230 } |
231 | 231 |
232 if (IsCodecFeatureEnabled(codec, kCodecParamStereo)) { | 232 if (IsCodecFeatureEnabled(codec, kCodecParamStereo)) { |
233 bitrate *= 2; | 233 bitrate *= 2; |
234 } | 234 } |
235 } else if (bitrate < kOpusMinBitrate || bitrate > kOpusMaxBitrate) { | 235 } else if (bitrate < kOpusMinBitrateBps || bitrate > kOpusMaxBitrateBps) { |
236 bitrate = (bitrate < kOpusMinBitrate) ? kOpusMinBitrate : kOpusMaxBitrate; | 236 bitrate = (bitrate < kOpusMinBitrateBps) ? kOpusMinBitrateBps |
| 237 : kOpusMaxBitrateBps; |
237 std::string rate_source = | 238 std::string rate_source = |
238 use_param ? "Codec parameter \"maxaveragebitrate\"" : | 239 use_param ? "Codec parameter \"maxaveragebitrate\"" : |
239 "Supplied Opus bitrate"; | 240 "Supplied Opus bitrate"; |
240 LOG(LS_WARNING) << rate_source | 241 LOG(LS_WARNING) << rate_source |
241 << " is invalid and is replaced by: " | 242 << " is invalid and is replaced by: " |
242 << bitrate; | 243 << bitrate; |
243 } | 244 } |
244 return bitrate; | 245 return bitrate; |
245 } | 246 } |
246 | 247 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 if (IsCodec(*voe_codec, kG722CodecName)) { | 472 if (IsCodec(*voe_codec, kG722CodecName)) { |
472 // If the ASSERT triggers, the codec definition in WebRTC VoiceEngine | 473 // If the ASSERT triggers, the codec definition in WebRTC VoiceEngine |
473 // has changed, and this special case is no longer needed. | 474 // has changed, and this special case is no longer needed. |
474 RTC_DCHECK(voe_codec->plfreq != new_plfreq); | 475 RTC_DCHECK(voe_codec->plfreq != new_plfreq); |
475 voe_codec->plfreq = new_plfreq; | 476 voe_codec->plfreq = new_plfreq; |
476 } | 477 } |
477 } | 478 } |
478 }; | 479 }; |
479 | 480 |
480 const WebRtcVoiceCodecs::CodecPref WebRtcVoiceCodecs::kCodecPrefs[11] = { | 481 const WebRtcVoiceCodecs::CodecPref WebRtcVoiceCodecs::kCodecPrefs[11] = { |
481 {kOpusCodecName, 48000, 2, 111, true, {10, 20, 40, 60}, kOpusMaxBitrate}, | 482 {kOpusCodecName, 48000, 2, 111, true, {10, 20, 40, 60}, kOpusMaxBitrateBps}, |
482 {kIsacCodecName, 16000, 1, 103, true, {30, 60}, kIsacMaxBitrate}, | 483 {kIsacCodecName, 16000, 1, 103, true, {30, 60}, kIsacMaxBitrateBps}, |
483 {kIsacCodecName, 32000, 1, 104, true, {30}, kIsacMaxBitrate}, | 484 {kIsacCodecName, 32000, 1, 104, true, {30}, kIsacMaxBitrateBps}, |
484 // G722 should be advertised as 8000 Hz because of the RFC "bug". | 485 // G722 should be advertised as 8000 Hz because of the RFC "bug". |
485 {kG722CodecName, 8000, 1, 9, false, {10, 20, 30, 40, 50, 60}}, | 486 {kG722CodecName, 8000, 1, 9, false, {10, 20, 30, 40, 50, 60}}, |
486 {kIlbcCodecName, 8000, 1, 102, false, {20, 30, 40, 60}}, | 487 {kIlbcCodecName, 8000, 1, 102, false, {20, 30, 40, 60}}, |
487 {kPcmuCodecName, 8000, 1, 0, false, {10, 20, 30, 40, 50, 60}}, | 488 {kPcmuCodecName, 8000, 1, 0, false, {10, 20, 30, 40, 50, 60}}, |
488 {kPcmaCodecName, 8000, 1, 8, false, {10, 20, 30, 40, 50, 60}}, | 489 {kPcmaCodecName, 8000, 1, 8, false, {10, 20, 30, 40, 50, 60}}, |
489 {kCnCodecName, 32000, 1, 106, false, {}}, | 490 {kCnCodecName, 32000, 1, 106, false, {}}, |
490 {kCnCodecName, 16000, 1, 105, false, {}}, | 491 {kCnCodecName, 16000, 1, 105, false, {}}, |
491 {kCnCodecName, 8000, 1, 13, false, {}}, | 492 {kCnCodecName, 8000, 1, 13, false, {}}, |
492 {kDtmfCodecName, 8000, 1, 126, false, {}} | 493 {kDtmfCodecName, 8000, 1, 126, false, {}}}; |
493 }; | |
494 | 494 |
495 rtc::Optional<int> ComputeSendBitrate(int max_send_bitrate_bps, | 495 rtc::Optional<int> ComputeSendBitrate(int max_send_bitrate_bps, |
496 int rtp_max_bitrate_bps, | 496 int rtp_max_bitrate_bps, |
497 const webrtc::CodecInst& codec_inst) { | 497 const webrtc::CodecInst& codec_inst) { |
498 const int bps = MinPositive(max_send_bitrate_bps, rtp_max_bitrate_bps); | 498 const int bps = MinPositive(max_send_bitrate_bps, rtp_max_bitrate_bps); |
499 const int codec_rate = codec_inst.rate; | 499 const int codec_rate = codec_inst.rate; |
500 | 500 |
501 if (bps <= 0) { | 501 if (bps <= 0) { |
502 return rtc::Optional<int>(codec_rate); | 502 return rtc::Optional<int>(codec_rate); |
503 } | 503 } |
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1385 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1385 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
1386 if (stream_) { | 1386 if (stream_) { |
1387 call_->DestroyAudioSendStream(stream_); | 1387 call_->DestroyAudioSendStream(stream_); |
1388 stream_ = nullptr; | 1388 stream_ = nullptr; |
1389 } | 1389 } |
1390 RTC_DCHECK(!stream_); | 1390 RTC_DCHECK(!stream_); |
1391 if (webrtc::field_trial::FindFullName("WebRTC-AdaptAudioBitrate") == | 1391 if (webrtc::field_trial::FindFullName("WebRTC-AdaptAudioBitrate") == |
1392 "Enabled") { | 1392 "Enabled") { |
1393 // TODO(mflodman): Keep testing this and set proper values. | 1393 // TODO(mflodman): Keep testing this and set proper values. |
1394 // Note: This is an early experiment currently only supported by Opus. | 1394 // Note: This is an early experiment currently only supported by Opus. |
1395 config_.min_bitrate_kbps = kOpusMinBitrate; | 1395 config_.min_bitrate_bps = kOpusMinBitrateBps; |
1396 config_.max_bitrate_kbps = kOpusBitrateFb; | 1396 config_.max_bitrate_bps = kOpusBitrateFbBps; |
1397 } | 1397 } |
1398 stream_ = call_->CreateAudioSendStream(config_); | 1398 stream_ = call_->CreateAudioSendStream(config_); |
1399 RTC_CHECK(stream_); | 1399 RTC_CHECK(stream_); |
1400 UpdateSendState(); | 1400 UpdateSendState(); |
1401 } | 1401 } |
1402 | 1402 |
1403 rtc::ThreadChecker worker_thread_checker_; | 1403 rtc::ThreadChecker worker_thread_checker_; |
1404 rtc::RaceChecker audio_capture_race_checker_; | 1404 rtc::RaceChecker audio_capture_race_checker_; |
1405 webrtc::AudioTransport* const voe_audio_transport_ = nullptr; | 1405 webrtc::AudioTransport* const voe_audio_transport_ = nullptr; |
1406 webrtc::Call* call_ = nullptr; | 1406 webrtc::Call* call_ = nullptr; |
(...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2572 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 2572 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
2573 const auto it = send_streams_.find(ssrc); | 2573 const auto it = send_streams_.find(ssrc); |
2574 if (it != send_streams_.end()) { | 2574 if (it != send_streams_.end()) { |
2575 return it->second->channel(); | 2575 return it->second->channel(); |
2576 } | 2576 } |
2577 return -1; | 2577 return -1; |
2578 } | 2578 } |
2579 } // namespace cricket | 2579 } // namespace cricket |
2580 | 2580 |
2581 #endif // HAVE_WEBRTC_VOICE | 2581 #endif // HAVE_WEBRTC_VOICE |
OLD | NEW |