Chromium Code Reviews| 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 21 matching lines...) Expand all Loading... | |
| 32 int dummy_id = 0; | 32 int dummy_id = 0; |
| 33 if ((send_codec.channels != 1) && (send_codec.channels != 2)) { | 33 if ((send_codec.channels != 1) && (send_codec.channels != 2)) { |
| 34 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, | 34 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, |
| 35 "Wrong number of channels (%d, only mono and stereo are " | 35 "Wrong number of channels (%d, only mono and stereo are " |
| 36 "supported) for %s encoder", | 36 "supported) for %s encoder", |
| 37 send_codec.channels, | 37 send_codec.channels, |
| 38 is_primary_encoder ? "primary" : "secondary"); | 38 is_primary_encoder ? "primary" : "secondary"); |
| 39 return -1; | 39 return -1; |
| 40 } | 40 } |
| 41 | 41 |
| 42 int codec_id = ACMCodecDB::CodecNumber(send_codec); | 42 auto maybe_codec_id = RentACodec::CodecIdByInst(send_codec); |
| 43 if (codec_id < 0) { | 43 if (!maybe_codec_id) { |
| 44 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, | 44 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, |
| 45 "Invalid codec setting for the send codec."); | 45 "Invalid codec setting for the send codec."); |
| 46 return -1; | 46 return -1; |
| 47 } | 47 } |
| 48 | 48 |
| 49 // Telephone-event cannot be a send codec. | 49 // Telephone-event cannot be a send codec. |
| 50 if (!STR_CASE_CMP(send_codec.plname, "telephone-event")) { | 50 if (!STR_CASE_CMP(send_codec.plname, "telephone-event")) { |
| 51 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, | 51 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, |
| 52 "telephone-event cannot be a send codec"); | 52 "telephone-event cannot be a send codec"); |
| 53 return -1; | 53 return -1; |
| 54 } | 54 } |
| 55 | 55 |
| 56 const rtc::Maybe<bool> supported_num_channels = [codec_id, &send_codec] { | 56 if (!RentACodec::IsSupportedNumChannels(*maybe_codec_id, send_codec.channels) |
|
hlundin-webrtc
2015/11/05 11:57:49
So much nicer... :)
kwiberg-webrtc
2015/11/05 12:27:52
Acknowledged.
| |
| 57 auto cid = RentACodec::CodecIdFromIndex(codec_id); | 57 .value_or(false)) { |
| 58 return cid ? RentACodec::IsSupportedNumChannels(*cid, send_codec.channels) | |
| 59 : rtc::Maybe<bool>(); | |
| 60 }(); | |
| 61 if (!supported_num_channels) | |
| 62 return -1; | |
| 63 if (!*supported_num_channels) { | |
| 64 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, | 58 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, |
| 65 "%d number of channels not supportedn for %s.", | 59 "%d number of channels not supportedn for %s.", |
| 66 send_codec.channels, send_codec.plname); | 60 send_codec.channels, send_codec.plname); |
| 67 return -1; | 61 return -1; |
| 68 } | 62 } |
| 69 | 63 |
| 70 if (!is_primary_encoder) { | 64 if (!is_primary_encoder) { |
| 71 // If registering the secondary encoder, then RED and CN are not valid | 65 // If registering the secondary encoder, then RED and CN are not valid |
| 72 // choices as encoder. | 66 // choices as encoder. |
| 73 if (IsCodecRED(send_codec)) { | 67 if (IsCodecRED(send_codec)) { |
| 74 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, | 68 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, |
| 75 "RED cannot be secondary codec"); | 69 "RED cannot be secondary codec"); |
| 76 return -1; | 70 return -1; |
| 77 } | 71 } |
| 78 | 72 |
| 79 if (IsCodecCN(send_codec)) { | 73 if (IsCodecCN(send_codec)) { |
| 80 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, | 74 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, |
| 81 "DTX cannot be secondary codec"); | 75 "DTX cannot be secondary codec"); |
| 82 return -1; | 76 return -1; |
| 83 } | 77 } |
| 84 } | 78 } |
| 85 return codec_id; | 79 return RentACodec::CodecIndexFromId(*maybe_codec_id).value_or(-1); |
| 86 } | 80 } |
| 87 | 81 |
| 88 bool IsIsac(const CodecInst& codec) { | 82 bool IsIsac(const CodecInst& codec) { |
| 89 return | 83 return |
| 90 #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) | 84 #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) |
| 91 !STR_CASE_CMP(codec.plname, "isac") || | 85 !STR_CASE_CMP(codec.plname, "isac") || |
| 92 #endif | 86 #endif |
| 93 false; | 87 false; |
| 94 } | 88 } |
| 95 | 89 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 "VAD/DTX is turned off, not supported when sending stereo."); | 238 "VAD/DTX is turned off, not supported when sending stereo."); |
| 245 } | 239 } |
| 246 dtx_enabled_ = false; | 240 dtx_enabled_ = false; |
| 247 } else { | 241 } else { |
| 248 stereo_send_ = false; | 242 stereo_send_ = false; |
| 249 } | 243 } |
| 250 | 244 |
| 251 // Check if the codec is already registered as send codec. | 245 // Check if the codec is already registered as send codec. |
| 252 bool new_codec = true; | 246 bool new_codec = true; |
| 253 if (codec_owner_.Encoder()) { | 247 if (codec_owner_.Encoder()) { |
| 254 int new_codec_id = ACMCodecDB::CodecNumber(send_codec_inst_); | 248 auto new_codec_id = RentACodec::CodecIdByInst(send_codec_inst_); |
| 255 RTC_DCHECK_GE(new_codec_id, 0); | 249 RTC_DCHECK(new_codec_id); |
| 256 new_codec = new_codec_id != codec_id; | 250 auto old_codec_id = RentACodec::CodecIdFromIndex(codec_id); |
| 251 new_codec = !old_codec_id || *new_codec_id != *old_codec_id; | |
| 257 } | 252 } |
| 258 | 253 |
| 259 if (RedPayloadType(send_codec.plfreq) == -1) { | 254 if (RedPayloadType(send_codec.plfreq) == -1) { |
| 260 red_enabled_ = false; | 255 red_enabled_ = false; |
| 261 } | 256 } |
| 262 | 257 |
| 263 encoder_is_opus_ = IsOpus(send_codec); | 258 encoder_is_opus_ = IsOpus(send_codec); |
| 264 | 259 |
| 265 if (new_codec) { | 260 if (new_codec) { |
| 266 // This is a new codec. Register it and return. | 261 // This is a new codec. Register it and return. |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 case 48000: | 446 case 48000: |
| 452 return -1; | 447 return -1; |
| 453 default: | 448 default: |
| 454 FATAL() << sample_rate_hz << " Hz is not supported"; | 449 FATAL() << sample_rate_hz << " Hz is not supported"; |
| 455 return -1; | 450 return -1; |
| 456 } | 451 } |
| 457 } | 452 } |
| 458 | 453 |
| 459 } // namespace acm2 | 454 } // namespace acm2 |
| 460 } // namespace webrtc | 455 } // namespace webrtc |
| OLD | NEW |