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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 return 0; | 142 return 0; |
143 case RentACodec::RegistrationResult::kBadFreq: | 143 case RentACodec::RegistrationResult::kBadFreq: |
144 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, | 144 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, |
145 "RegisterSendCodec() failed, invalid frequency for CNG" | 145 "RegisterSendCodec() failed, invalid frequency for CNG" |
146 " registration"); | 146 " registration"); |
147 return -1; | 147 return -1; |
148 case RentACodec::RegistrationResult::kSkip: | 148 case RentACodec::RegistrationResult::kSkip: |
149 break; | 149 break; |
150 } | 150 } |
151 | 151 |
152 // Check if the codec is already registered as send codec. | 152 encoder_is_opus_ = IsOpus(send_codec); |
153 bool new_codec = true; | 153 if (encoder_is_opus_) { |
154 if (CurrentEncoder()) { | 154 // VAD/DTX not supported. |
155 auto new_codec_id = RentACodec::CodecIdByInst(send_codec_inst_); | 155 codec_stack_params_.use_cng = false; |
156 RTC_DCHECK(new_codec_id); | |
157 auto old_codec_id = RentACodec::CodecIdFromIndex(codec_id); | |
158 new_codec = !old_codec_id || *new_codec_id != *old_codec_id; | |
159 } | 156 } |
160 | 157 |
161 encoder_is_opus_ = IsOpus(send_codec); | 158 // Recreate the encoder if anything except the send bitrate has changed. |
162 | 159 if (!CurrentEncoder() || send_codec_inst_.pltype != send_codec.pltype || |
163 if (new_codec) { | 160 STR_CASE_CMP(send_codec_inst_.plname, send_codec.plname) != 0 || |
164 // This is a new codec. Register it and return. | 161 send_codec_inst_.plfreq != send_codec.plfreq || |
165 RTC_DCHECK(CodecSupported(send_codec)); | |
166 if (IsOpus(send_codec)) { | |
167 // VAD/DTX not supported. | |
168 codec_stack_params_.use_cng = false; | |
169 } | |
170 AudioEncoder* enc = rent_a_codec_.RentEncoder(send_codec); | |
171 if (!enc) | |
172 return -1; | |
173 rent_a_codec_.RentEncoderStack(enc, &codec_stack_params_); | |
174 RTC_DCHECK(CurrentEncoder()); | |
175 | |
176 send_codec_inst_ = send_codec; | |
177 return 0; | |
178 } | |
179 | |
180 // This is an existing codec; re-create it if any parameters have changed. | |
181 if (send_codec_inst_.plfreq != send_codec.plfreq || | |
182 send_codec_inst_.pacsize != send_codec.pacsize || | 162 send_codec_inst_.pacsize != send_codec.pacsize || |
183 send_codec_inst_.channels != send_codec.channels) { | 163 send_codec_inst_.channels != send_codec.channels) { |
164 RTC_DCHECK(CodecSupported(send_codec)); | |
184 AudioEncoder* enc = rent_a_codec_.RentEncoder(send_codec); | 165 AudioEncoder* enc = rent_a_codec_.RentEncoder(send_codec); |
185 if (!enc) | 166 if (!enc) |
186 return -1; | 167 return -1; |
187 rent_a_codec_.RentEncoderStack(enc, &codec_stack_params_); | 168 rent_a_codec_.RentEncoderStack(enc, &codec_stack_params_); |
188 RTC_DCHECK(CurrentEncoder()); | 169 RTC_DCHECK(CurrentEncoder()); |
189 } | 170 } |
190 send_codec_inst_.plfreq = send_codec.plfreq; | |
191 send_codec_inst_.pacsize = send_codec.pacsize; | |
192 send_codec_inst_.channels = send_codec.channels; | |
193 send_codec_inst_.pltype = send_codec.pltype; | |
194 | 171 |
195 // Check if a change in Rate is required. | 172 send_codec_inst_ = send_codec; |
hlundin-webrtc
2015/12/01 12:11:45
I'd like a DCHECK at this point to verify that all
kwiberg-webrtc
2015/12/01 12:37:27
But they're not---we pass through here whether or
hlundin-webrtc
2015/12/01 13:07:04
Oh, well, then I guess not...
| |
196 if (send_codec.rate != send_codec_inst_.rate) { | 173 CurrentEncoder()->SetTargetBitrate(send_codec_inst_.rate); |
197 CurrentEncoder()->SetTargetBitrate(send_codec.rate); | |
198 send_codec_inst_.rate = send_codec.rate; | |
199 } | |
200 | |
201 return 0; | 174 return 0; |
202 } | 175 } |
203 | 176 |
204 void CodecManager::RegisterEncoder(AudioEncoder* external_speech_encoder) { | 177 void CodecManager::RegisterEncoder(AudioEncoder* external_speech_encoder) { |
205 // Make up a CodecInst. | 178 // Make up a CodecInst. |
206 send_codec_inst_.channels = external_speech_encoder->NumChannels(); | 179 send_codec_inst_.channels = external_speech_encoder->NumChannels(); |
207 send_codec_inst_.plfreq = external_speech_encoder->SampleRateHz(); | 180 send_codec_inst_.plfreq = external_speech_encoder->SampleRateHz(); |
208 send_codec_inst_.pacsize = rtc::CheckedDivExact( | 181 send_codec_inst_.pacsize = rtc::CheckedDivExact( |
209 static_cast<int>(external_speech_encoder->Max10MsFramesInAPacket() * | 182 static_cast<int>(external_speech_encoder->Max10MsFramesInAPacket() * |
210 send_codec_inst_.plfreq), | 183 send_codec_inst_.plfreq), |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 CurrentEncoder()->SetFec(enable_codec_fec) && enable_codec_fec; | 277 CurrentEncoder()->SetFec(enable_codec_fec) && enable_codec_fec; |
305 return codec_stack_params_.use_codec_fec == enable_codec_fec ? 0 : -1; | 278 return codec_stack_params_.use_codec_fec == enable_codec_fec ? 0 : -1; |
306 } | 279 } |
307 | 280 |
308 AudioDecoder* CodecManager::GetAudioDecoder(const CodecInst& codec) { | 281 AudioDecoder* CodecManager::GetAudioDecoder(const CodecInst& codec) { |
309 return IsIsac(codec) ? rent_a_codec_.RentIsacDecoder() : nullptr; | 282 return IsIsac(codec) ? rent_a_codec_.RentIsacDecoder() : nullptr; |
310 } | 283 } |
311 | 284 |
312 } // namespace acm2 | 285 } // namespace acm2 |
313 } // namespace webrtc | 286 } // namespace webrtc |
OLD | NEW |