| 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 // Recreate the encoder if anything except the send bitrate has changed. | 158 // Recreate the encoder if anything except the send bitrate has changed. |
| 159 if (!CurrentEncoder() || send_codec_inst_.pltype != send_codec.pltype || | 159 if (!CurrentEncoder() || send_codec_inst_.pltype != send_codec.pltype || |
| 160 STR_CASE_CMP(send_codec_inst_.plname, send_codec.plname) != 0 || | 160 STR_CASE_CMP(send_codec_inst_.plname, send_codec.plname) != 0 || |
| 161 send_codec_inst_.plfreq != send_codec.plfreq || | 161 send_codec_inst_.plfreq != send_codec.plfreq || |
| 162 send_codec_inst_.pacsize != send_codec.pacsize || | 162 send_codec_inst_.pacsize != send_codec.pacsize || |
| 163 send_codec_inst_.channels != send_codec.channels) { | 163 send_codec_inst_.channels != send_codec.channels) { |
| 164 RTC_DCHECK(CodecSupported(send_codec)); | 164 RTC_DCHECK(CodecSupported(send_codec)); |
| 165 AudioEncoder* enc = rent_a_codec_.RentEncoder(send_codec); | 165 AudioEncoder* enc = rent_a_codec_.RentEncoder(send_codec); |
| 166 if (!enc) | 166 if (!enc) |
| 167 return -1; | 167 return -1; |
| 168 rent_a_codec_.RentEncoderStack(enc, &codec_stack_params_); | 168 codec_stack_params_.speech_encoder = enc; |
| 169 rent_a_codec_.RentEncoderStack(&codec_stack_params_); |
| 169 RTC_DCHECK(CurrentEncoder()); | 170 RTC_DCHECK(CurrentEncoder()); |
| 170 } | 171 } |
| 171 | 172 |
| 172 send_codec_inst_ = send_codec; | 173 send_codec_inst_ = send_codec; |
| 173 CurrentEncoder()->SetTargetBitrate(send_codec_inst_.rate); | 174 CurrentEncoder()->SetTargetBitrate(send_codec_inst_.rate); |
| 174 return 0; | 175 return 0; |
| 175 } | 176 } |
| 176 | 177 |
| 177 void CodecManager::RegisterEncoder(AudioEncoder* external_speech_encoder) { | 178 void CodecManager::RegisterEncoder(AudioEncoder* external_speech_encoder) { |
| 178 // Make up a CodecInst. | 179 // Make up a CodecInst. |
| 179 send_codec_inst_.channels = external_speech_encoder->NumChannels(); | 180 send_codec_inst_.channels = external_speech_encoder->NumChannels(); |
| 180 send_codec_inst_.plfreq = external_speech_encoder->SampleRateHz(); | 181 send_codec_inst_.plfreq = external_speech_encoder->SampleRateHz(); |
| 181 send_codec_inst_.pacsize = rtc::CheckedDivExact( | 182 send_codec_inst_.pacsize = rtc::CheckedDivExact( |
| 182 static_cast<int>(external_speech_encoder->Max10MsFramesInAPacket() * | 183 static_cast<int>(external_speech_encoder->Max10MsFramesInAPacket() * |
| 183 send_codec_inst_.plfreq), | 184 send_codec_inst_.plfreq), |
| 184 100); | 185 100); |
| 185 send_codec_inst_.pltype = -1; // Not valid. | 186 send_codec_inst_.pltype = -1; // Not valid. |
| 186 send_codec_inst_.rate = -1; // Not valid. | 187 send_codec_inst_.rate = -1; // Not valid. |
| 187 static const char kName[] = "external"; | 188 static const char kName[] = "external"; |
| 188 memcpy(send_codec_inst_.plname, kName, sizeof(kName)); | 189 memcpy(send_codec_inst_.plname, kName, sizeof(kName)); |
| 189 | 190 |
| 190 rent_a_codec_.RentEncoderStack(external_speech_encoder, &codec_stack_params_); | 191 codec_stack_params_.speech_encoder = external_speech_encoder; |
| 192 rent_a_codec_.RentEncoderStack(&codec_stack_params_); |
| 191 } | 193 } |
| 192 | 194 |
| 193 rtc::Optional<CodecInst> CodecManager::GetCodecInst() const { | 195 rtc::Optional<CodecInst> CodecManager::GetCodecInst() const { |
| 194 int dummy_id = 0; | 196 int dummy_id = 0; |
| 195 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, dummy_id, | 197 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, dummy_id, |
| 196 "SendCodec()"); | 198 "SendCodec()"); |
| 197 | 199 |
| 198 if (!CurrentEncoder()) { | 200 if (!CurrentEncoder()) { |
| 199 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, dummy_id, | 201 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, dummy_id, |
| 200 "SendCodec Failed, no codec is registered"); | 202 "SendCodec Failed, no codec is registered"); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 212 if (enable && | 214 if (enable && |
| 213 codec_stack_params_.red_payload_types.count(send_codec_inst_.plfreq) < | 215 codec_stack_params_.red_payload_types.count(send_codec_inst_.plfreq) < |
| 214 1) { | 216 1) { |
| 215 WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, 0, | 217 WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, 0, |
| 216 "Cannot enable RED at %i Hz.", send_codec_inst_.plfreq); | 218 "Cannot enable RED at %i Hz.", send_codec_inst_.plfreq); |
| 217 return false; | 219 return false; |
| 218 } | 220 } |
| 219 if (codec_stack_params_.use_red != enable) { | 221 if (codec_stack_params_.use_red != enable) { |
| 220 codec_stack_params_.use_red = enable; | 222 codec_stack_params_.use_red = enable; |
| 221 if (CurrentEncoder()) | 223 if (CurrentEncoder()) |
| 222 rent_a_codec_.RentEncoderStack(rent_a_codec_.GetEncoder(), | 224 rent_a_codec_.RentEncoderStack(&codec_stack_params_); |
| 223 &codec_stack_params_); | |
| 224 } | 225 } |
| 225 return true; | 226 return true; |
| 226 } | 227 } |
| 227 | 228 |
| 228 int CodecManager::SetVAD(bool enable, ACMVADMode mode) { | 229 int CodecManager::SetVAD(bool enable, ACMVADMode mode) { |
| 229 // Sanity check of the mode. | 230 // Sanity check of the mode. |
| 230 RTC_DCHECK(mode == VADNormal || mode == VADLowBitrate || mode == VADAggr || | 231 RTC_DCHECK(mode == VADNormal || mode == VADLowBitrate || mode == VADAggr || |
| 231 mode == VADVeryAggr); | 232 mode == VADVeryAggr); |
| 232 | 233 |
| 233 // Check that the send codec is mono. We don't support VAD/DTX for stereo | 234 // Check that the send codec is mono. We don't support VAD/DTX for stereo |
| 234 // sending. | 235 // sending. |
| 235 auto* enc = rent_a_codec_.GetEncoder(); | 236 const bool stereo_send = |
| 236 const bool stereo_send = enc ? (enc->NumChannels() != 1) : false; | 237 codec_stack_params_.speech_encoder |
| 238 ? (codec_stack_params_.speech_encoder->NumChannels() != 1) |
| 239 : false; |
| 237 if (enable && stereo_send) { | 240 if (enable && stereo_send) { |
| 238 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, 0, | 241 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, 0, |
| 239 "VAD/DTX not supported for stereo sending"); | 242 "VAD/DTX not supported for stereo sending"); |
| 240 codec_stack_params_.use_cng = false; | 243 codec_stack_params_.use_cng = false; |
| 241 return -1; | 244 return -1; |
| 242 } | 245 } |
| 243 | 246 |
| 244 // If a send codec is registered, set VAD/DTX for the codec. | 247 // If a send codec is registered, set VAD/DTX for the codec. |
| 245 if (IsOpus(send_codec_inst_)) { | 248 if (IsOpus(send_codec_inst_)) { |
| 246 // VAD/DTX not supported. | 249 // VAD/DTX not supported. |
| 247 codec_stack_params_.use_cng = false; | 250 codec_stack_params_.use_cng = false; |
| 248 return 0; | 251 return 0; |
| 249 } | 252 } |
| 250 | 253 |
| 251 if (codec_stack_params_.use_cng != enable || | 254 if (codec_stack_params_.use_cng != enable || |
| 252 codec_stack_params_.vad_mode != mode) { | 255 codec_stack_params_.vad_mode != mode) { |
| 253 codec_stack_params_.use_cng = enable; | 256 codec_stack_params_.use_cng = enable; |
| 254 codec_stack_params_.vad_mode = mode; | 257 codec_stack_params_.vad_mode = mode; |
| 255 if (enc) | 258 if (codec_stack_params_.speech_encoder) |
| 256 rent_a_codec_.RentEncoderStack(enc, &codec_stack_params_); | 259 rent_a_codec_.RentEncoderStack(&codec_stack_params_); |
| 257 } | 260 } |
| 258 return 0; | 261 return 0; |
| 259 } | 262 } |
| 260 | 263 |
| 261 void CodecManager::VAD(bool* dtx_enabled, | 264 void CodecManager::VAD(bool* dtx_enabled, |
| 262 bool* vad_enabled, | 265 bool* vad_enabled, |
| 263 ACMVADMode* mode) const { | 266 ACMVADMode* mode) const { |
| 264 *dtx_enabled = *vad_enabled = codec_stack_params_.use_cng; | 267 *dtx_enabled = *vad_enabled = codec_stack_params_.use_cng; |
| 265 *mode = codec_stack_params_.vad_mode; | 268 *mode = codec_stack_params_.vad_mode; |
| 266 } | 269 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 277 CurrentEncoder()->SetFec(enable_codec_fec) && enable_codec_fec; | 280 CurrentEncoder()->SetFec(enable_codec_fec) && enable_codec_fec; |
| 278 return codec_stack_params_.use_codec_fec == enable_codec_fec ? 0 : -1; | 281 return codec_stack_params_.use_codec_fec == enable_codec_fec ? 0 : -1; |
| 279 } | 282 } |
| 280 | 283 |
| 281 AudioDecoder* CodecManager::GetAudioDecoder(const CodecInst& codec) { | 284 AudioDecoder* CodecManager::GetAudioDecoder(const CodecInst& codec) { |
| 282 return IsIsac(codec) ? rent_a_codec_.RentIsacDecoder() : nullptr; | 285 return IsIsac(codec) ? rent_a_codec_.RentIsacDecoder() : nullptr; |
| 283 } | 286 } |
| 284 | 287 |
| 285 } // namespace acm2 | 288 } // namespace acm2 |
| 286 } // namespace webrtc | 289 } // namespace webrtc |
| OLD | NEW |