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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 if (IsOpus(send_codec)) { | 166 if (IsOpus(send_codec)) { |
167 // VAD/DTX not supported. | 167 // VAD/DTX not supported. |
168 codec_stack_params_.use_cng = false; | 168 codec_stack_params_.use_cng = false; |
169 } | 169 } |
170 AudioEncoder* enc = rent_a_codec_.RentEncoder(send_codec); | 170 AudioEncoder* enc = rent_a_codec_.RentEncoder(send_codec); |
171 if (!enc) | 171 if (!enc) |
172 return -1; | 172 return -1; |
173 rent_a_codec_.RentEncoderStack(enc, &codec_stack_params_); | 173 rent_a_codec_.RentEncoderStack(enc, &codec_stack_params_); |
174 RTC_DCHECK(CurrentEncoder()); | 174 RTC_DCHECK(CurrentEncoder()); |
175 | 175 |
176 codec_stack_params_.use_codec_fec = | |
177 codec_stack_params_.use_codec_fec && | |
178 enc->SetFec(codec_stack_params_.use_codec_fec); | |
179 | |
180 send_codec_inst_ = send_codec; | 176 send_codec_inst_ = send_codec; |
181 return 0; | 177 return 0; |
182 } | 178 } |
183 | 179 |
184 // This is an existing codec; re-create it if any parameters have changed. | 180 // This is an existing codec; re-create it if any parameters have changed. |
185 if (send_codec_inst_.plfreq != send_codec.plfreq || | 181 if (send_codec_inst_.plfreq != send_codec.plfreq || |
186 send_codec_inst_.pacsize != send_codec.pacsize || | 182 send_codec_inst_.pacsize != send_codec.pacsize || |
187 send_codec_inst_.channels != send_codec.channels) { | 183 send_codec_inst_.channels != send_codec.channels) { |
188 AudioEncoder* enc = rent_a_codec_.RentEncoder(send_codec); | 184 AudioEncoder* enc = rent_a_codec_.RentEncoder(send_codec); |
189 if (!enc) | 185 if (!enc) |
190 return -1; | 186 return -1; |
191 rent_a_codec_.RentEncoderStack(enc, &codec_stack_params_); | 187 rent_a_codec_.RentEncoderStack(enc, &codec_stack_params_); |
192 RTC_DCHECK(CurrentEncoder()); | 188 RTC_DCHECK(CurrentEncoder()); |
193 } | 189 } |
194 send_codec_inst_.plfreq = send_codec.plfreq; | 190 send_codec_inst_.plfreq = send_codec.plfreq; |
195 send_codec_inst_.pacsize = send_codec.pacsize; | 191 send_codec_inst_.pacsize = send_codec.pacsize; |
196 send_codec_inst_.channels = send_codec.channels; | 192 send_codec_inst_.channels = send_codec.channels; |
197 send_codec_inst_.pltype = send_codec.pltype; | 193 send_codec_inst_.pltype = send_codec.pltype; |
198 | 194 |
199 // Check if a change in Rate is required. | 195 // Check if a change in Rate is required. |
200 if (send_codec.rate != send_codec_inst_.rate) { | 196 if (send_codec.rate != send_codec_inst_.rate) { |
201 CurrentEncoder()->SetTargetBitrate(send_codec.rate); | 197 CurrentEncoder()->SetTargetBitrate(send_codec.rate); |
202 send_codec_inst_.rate = send_codec.rate; | 198 send_codec_inst_.rate = send_codec.rate; |
203 } | 199 } |
204 | 200 |
205 codec_stack_params_.use_codec_fec = | |
206 codec_stack_params_.use_codec_fec && | |
207 CurrentEncoder()->SetFec(codec_stack_params_.use_codec_fec); | |
208 | |
209 return 0; | 201 return 0; |
210 } | 202 } |
211 | 203 |
212 void CodecManager::RegisterEncoder(AudioEncoder* external_speech_encoder) { | 204 void CodecManager::RegisterEncoder(AudioEncoder* external_speech_encoder) { |
213 // Make up a CodecInst. | 205 // Make up a CodecInst. |
214 send_codec_inst_.channels = external_speech_encoder->NumChannels(); | 206 send_codec_inst_.channels = external_speech_encoder->NumChannels(); |
215 send_codec_inst_.plfreq = external_speech_encoder->SampleRateHz(); | 207 send_codec_inst_.plfreq = external_speech_encoder->SampleRateHz(); |
216 send_codec_inst_.pacsize = rtc::CheckedDivExact( | 208 send_codec_inst_.pacsize = rtc::CheckedDivExact( |
217 static_cast<int>(external_speech_encoder->Max10MsFramesInAPacket() * | 209 static_cast<int>(external_speech_encoder->Max10MsFramesInAPacket() * |
218 send_codec_inst_.plfreq), | 210 send_codec_inst_.plfreq), |
219 100); | 211 100); |
220 send_codec_inst_.pltype = -1; // Not valid. | 212 send_codec_inst_.pltype = -1; // Not valid. |
221 send_codec_inst_.rate = -1; // Not valid. | 213 send_codec_inst_.rate = -1; // Not valid. |
222 static const char kName[] = "external"; | 214 static const char kName[] = "external"; |
223 memcpy(send_codec_inst_.plname, kName, sizeof(kName)); | 215 memcpy(send_codec_inst_.plname, kName, sizeof(kName)); |
224 | 216 |
225 if (codec_stack_params_.use_codec_fec) { | |
226 // Switch FEC on. On failure, remember that FEC is off. | |
227 if (!external_speech_encoder->SetFec(true)) | |
228 codec_stack_params_.use_codec_fec = false; | |
229 } else { | |
230 // Switch FEC off. This shouldn't fail. | |
231 const bool success = external_speech_encoder->SetFec(false); | |
232 RTC_DCHECK(success); | |
233 } | |
234 | |
235 rent_a_codec_.RentEncoderStack(external_speech_encoder, &codec_stack_params_); | 217 rent_a_codec_.RentEncoderStack(external_speech_encoder, &codec_stack_params_); |
236 } | 218 } |
237 | 219 |
238 rtc::Optional<CodecInst> CodecManager::GetCodecInst() const { | 220 rtc::Optional<CodecInst> CodecManager::GetCodecInst() const { |
239 int dummy_id = 0; | 221 int dummy_id = 0; |
240 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, dummy_id, | 222 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, dummy_id, |
241 "SendCodec()"); | 223 "SendCodec()"); |
242 | 224 |
243 if (!CurrentEncoder()) { | 225 if (!CurrentEncoder()) { |
244 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, dummy_id, | 226 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, dummy_id, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 CurrentEncoder()->SetFec(enable_codec_fec) && enable_codec_fec; | 304 CurrentEncoder()->SetFec(enable_codec_fec) && enable_codec_fec; |
323 return codec_stack_params_.use_codec_fec == enable_codec_fec ? 0 : -1; | 305 return codec_stack_params_.use_codec_fec == enable_codec_fec ? 0 : -1; |
324 } | 306 } |
325 | 307 |
326 AudioDecoder* CodecManager::GetAudioDecoder(const CodecInst& codec) { | 308 AudioDecoder* CodecManager::GetAudioDecoder(const CodecInst& codec) { |
327 return IsIsac(codec) ? rent_a_codec_.RentIsacDecoder() : nullptr; | 309 return IsIsac(codec) ? rent_a_codec_.RentIsacDecoder() : nullptr; |
328 } | 310 } |
329 | 311 |
330 } // namespace acm2 | 312 } // namespace acm2 |
331 } // namespace webrtc | 313 } // namespace webrtc |
OLD | NEW |