Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: webrtc/modules/audio_coding/acm2/acm_receiver.cc

Issue 2351183002: AcmReceiver: Eliminate AcmReceiver::decoders_ (Closed)
Patch Set: case-insensitive string comparison Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 sizeof(int16_t) * audio_frame->samples_per_channel_ * 172 sizeof(int16_t) * audio_frame->samples_per_channel_ *
173 audio_frame->num_channels_); 173 audio_frame->num_channels_);
174 174
175 call_stats_.DecodedByNetEq(audio_frame->speech_type_); 175 call_stats_.DecodedByNetEq(audio_frame->speech_type_);
176 return 0; 176 return 0;
177 } 177 }
178 178
179 int32_t AcmReceiver::AddCodec(int acm_codec_id, 179 int32_t AcmReceiver::AddCodec(int acm_codec_id,
180 uint8_t payload_type, 180 uint8_t payload_type,
181 size_t channels, 181 size_t channels,
182 int sample_rate_hz, 182 int /*sample_rate_hz*/,
183 AudioDecoder* audio_decoder, 183 AudioDecoder* audio_decoder,
184 const std::string& name) { 184 const std::string& name) {
185 // TODO(kwiberg): This function has been ignoring the |sample_rate_hz|
186 // argument for a long time. Arguably, it should simply be removed.
187
185 const auto neteq_decoder = [acm_codec_id, channels]() -> NetEqDecoder { 188 const auto neteq_decoder = [acm_codec_id, channels]() -> NetEqDecoder {
186 if (acm_codec_id == -1) 189 if (acm_codec_id == -1)
187 return NetEqDecoder::kDecoderArbitrary; // External decoder. 190 return NetEqDecoder::kDecoderArbitrary; // External decoder.
188 const rtc::Optional<RentACodec::CodecId> cid = 191 const rtc::Optional<RentACodec::CodecId> cid =
189 RentACodec::CodecIdFromIndex(acm_codec_id); 192 RentACodec::CodecIdFromIndex(acm_codec_id);
190 RTC_DCHECK(cid) << "Invalid codec index: " << acm_codec_id; 193 RTC_DCHECK(cid) << "Invalid codec index: " << acm_codec_id;
191 const rtc::Optional<NetEqDecoder> ned = 194 const rtc::Optional<NetEqDecoder> ned =
192 RentACodec::NetEqDecoderFromCodecId(*cid, channels); 195 RentACodec::NetEqDecoderFromCodecId(*cid, channels);
193 RTC_DCHECK(ned) << "Invalid codec ID: " << static_cast<int>(*cid); 196 RTC_DCHECK(ned) << "Invalid codec ID: " << static_cast<int>(*cid);
194 return *ned; 197 return *ned;
195 }(); 198 }();
199 const rtc::Optional<SdpAudioFormat> new_format =
200 RentACodec::NetEqDecoderToSdpAudioFormat(neteq_decoder);
196 201
197 rtc::CritScope lock(&crit_sect_); 202 rtc::CritScope lock(&crit_sect_);
198 203
199 // The corresponding NetEq decoder ID. 204 const SdpAudioFormat* const old_format =
200 // If this codec has been registered before. 205 neteq_->GetDecoderFormat(payload_type);
201 auto it = decoders_.find(payload_type); 206 if (old_format && new_format && *old_format == *new_format) {
202 if (it != decoders_.end()) { 207 // Re-registering the same codec. Do nothing and return.
203 const Decoder& decoder = it->second; 208 return 0;
204 if (acm_codec_id != -1 && decoder.acm_codec_id == acm_codec_id && 209 }
205 decoder.channels == channels &&
206 decoder.sample_rate_hz == sample_rate_hz) {
207 // Re-registering the same codec. Do nothing and return.
208 return 0;
209 }
210 210
211 // Changing codec. First unregister the old codec, then register the new 211 if (neteq_->RemovePayloadType(payload_type) != NetEq::kOK &&
212 // one. 212 neteq_->LastError() != NetEq::kDecoderNotFound) {
213 if (neteq_->RemovePayloadType(payload_type) != NetEq::kOK) { 213 LOG(LERROR) << "Cannot remove payload " << static_cast<int>(payload_type);
214 LOG(LERROR) << "Cannot remove payload " << static_cast<int>(payload_type); 214 return -1;
215 return -1;
216 }
217
218 decoders_.erase(it);
219 } 215 }
220 216
221 int ret_val; 217 int ret_val;
222 if (!audio_decoder) { 218 if (!audio_decoder) {
223 ret_val = neteq_->RegisterPayloadType(neteq_decoder, name, payload_type); 219 ret_val = neteq_->RegisterPayloadType(neteq_decoder, name, payload_type);
224 } else { 220 } else {
225 ret_val = neteq_->RegisterExternalDecoder( 221 ret_val = neteq_->RegisterExternalDecoder(
226 audio_decoder, neteq_decoder, name, payload_type); 222 audio_decoder, neteq_decoder, name, payload_type);
227 } 223 }
228 if (ret_val != NetEq::kOK) { 224 if (ret_val != NetEq::kOK) {
229 LOG(LERROR) << "AcmReceiver::AddCodec " << acm_codec_id 225 LOG(LERROR) << "AcmReceiver::AddCodec " << acm_codec_id
230 << static_cast<int>(payload_type) 226 << static_cast<int>(payload_type)
231 << " channels: " << channels; 227 << " channels: " << channels;
232 return -1; 228 return -1;
233 } 229 }
234
235 Decoder decoder;
236 decoder.acm_codec_id = acm_codec_id;
237 decoder.payload_type = payload_type;
238 decoder.channels = channels;
239 decoder.sample_rate_hz = sample_rate_hz;
240 decoders_[payload_type] = decoder;
241 return 0; 230 return 0;
242 } 231 }
243 232
244 void AcmReceiver::FlushBuffers() { 233 void AcmReceiver::FlushBuffers() {
245 neteq_->FlushBuffers(); 234 neteq_->FlushBuffers();
246 } 235 }
247 236
248 void AcmReceiver::RemoveAllCodecs() { 237 void AcmReceiver::RemoveAllCodecs() {
249 rtc::CritScope lock(&crit_sect_); 238 rtc::CritScope lock(&crit_sect_);
250 neteq_->RemoveAllPayloadTypes(); 239 neteq_->RemoveAllPayloadTypes();
251 decoders_.clear();
252 last_audio_decoder_ = rtc::Optional<CodecInst>(); 240 last_audio_decoder_ = rtc::Optional<CodecInst>();
253 last_packet_sample_rate_hz_ = rtc::Optional<int>(); 241 last_packet_sample_rate_hz_ = rtc::Optional<int>();
254 } 242 }
255 243
256 int AcmReceiver::RemoveCodec(uint8_t payload_type) { 244 int AcmReceiver::RemoveCodec(uint8_t payload_type) {
257 rtc::CritScope lock(&crit_sect_); 245 rtc::CritScope lock(&crit_sect_);
258 auto it = decoders_.find(payload_type); 246 if (neteq_->RemovePayloadType(payload_type) != NetEq::kOK &&
259 if (it == decoders_.end()) { // Such a payload-type is not registered. 247 neteq_->LastError() != NetEq::kDecoderNotFound) {
260 return 0;
261 }
262 if (neteq_->RemovePayloadType(payload_type) != NetEq::kOK) {
263 LOG(LERROR) << "AcmReceiver::RemoveCodec" << static_cast<int>(payload_type); 248 LOG(LERROR) << "AcmReceiver::RemoveCodec" << static_cast<int>(payload_type);
264 return -1; 249 return -1;
265 } 250 }
266 if (last_audio_decoder_ && payload_type == last_audio_decoder_->pltype) { 251 if (last_audio_decoder_ && payload_type == last_audio_decoder_->pltype) {
267 last_audio_decoder_ = rtc::Optional<CodecInst>(); 252 last_audio_decoder_ = rtc::Optional<CodecInst>();
268 last_packet_sample_rate_hz_ = rtc::Optional<int>(); 253 last_packet_sample_rate_hz_ = rtc::Optional<int>();
269 } 254 }
270 decoders_.erase(it);
271 return 0; 255 return 0;
272 } 256 }
273 257
274 rtc::Optional<uint32_t> AcmReceiver::GetPlayoutTimestamp() { 258 rtc::Optional<uint32_t> AcmReceiver::GetPlayoutTimestamp() {
275 return neteq_->GetPlayoutTimestamp(); 259 return neteq_->GetPlayoutTimestamp();
276 } 260 }
277 261
278 int AcmReceiver::FilteredCurrentDelayMs() const { 262 int AcmReceiver::FilteredCurrentDelayMs() const {
279 return neteq_->FilteredCurrentDelayMs(); 263 return neteq_->FilteredCurrentDelayMs();
280 } 264 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 354
371 void AcmReceiver::GetDecodingCallStatistics( 355 void AcmReceiver::GetDecodingCallStatistics(
372 AudioDecodingCallStats* stats) const { 356 AudioDecodingCallStats* stats) const {
373 rtc::CritScope lock(&crit_sect_); 357 rtc::CritScope lock(&crit_sect_);
374 *stats = call_stats_.GetDecodingStatistics(); 358 *stats = call_stats_.GetDecodingStatistics();
375 } 359 }
376 360
377 } // namespace acm2 361 } // namespace acm2
378 362
379 } // namespace webrtc 363 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/acm2/acm_receiver.h ('k') | webrtc/modules/audio_coding/codecs/audio_format.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698