| 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 |
| 11 #include "webrtc/modules/audio_coding/main/acm2/rent_a_codec.h" | 11 #include "webrtc/modules/audio_coding/main/acm2/rent_a_codec.h" |
| 12 | 12 |
| 13 #include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h" | 13 #include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h" |
| 14 #include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h" | 14 #include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h" |
| 15 | 15 |
| 16 namespace webrtc { | 16 namespace webrtc { |
| 17 namespace acm2 { | 17 namespace acm2 { |
| 18 | 18 |
| 19 rtc::Maybe<RentACodec::CodecId> RentACodec::CodecIdByParams( | 19 rtc::Optional<RentACodec::CodecId> RentACodec::CodecIdByParams( |
| 20 const char* payload_name, | 20 const char* payload_name, |
| 21 int sampling_freq_hz, | 21 int sampling_freq_hz, |
| 22 int channels) { | 22 int channels) { |
| 23 return CodecIdFromIndex( | 23 return CodecIdFromIndex( |
| 24 ACMCodecDB::CodecId(payload_name, sampling_freq_hz, channels)); | 24 ACMCodecDB::CodecId(payload_name, sampling_freq_hz, channels)); |
| 25 } | 25 } |
| 26 | 26 |
| 27 rtc::Maybe<CodecInst> RentACodec::CodecInstById(CodecId codec_id) { | 27 rtc::Optional<CodecInst> RentACodec::CodecInstById(CodecId codec_id) { |
| 28 rtc::Maybe<int> mi = CodecIndexFromId(codec_id); | 28 rtc::Optional<int> mi = CodecIndexFromId(codec_id); |
| 29 return mi ? rtc::Maybe<CodecInst>(Database()[*mi]) : rtc::Maybe<CodecInst>(); | 29 return mi ? rtc::Optional<CodecInst>(Database()[*mi]) |
| 30 : rtc::Optional<CodecInst>(); |
| 30 } | 31 } |
| 31 | 32 |
| 32 rtc::Maybe<RentACodec::CodecId> RentACodec::CodecIdByInst( | 33 rtc::Optional<RentACodec::CodecId> RentACodec::CodecIdByInst( |
| 33 const CodecInst& codec_inst) { | 34 const CodecInst& codec_inst) { |
| 34 return CodecIdFromIndex(ACMCodecDB::CodecNumber(codec_inst)); | 35 return CodecIdFromIndex(ACMCodecDB::CodecNumber(codec_inst)); |
| 35 } | 36 } |
| 36 | 37 |
| 37 rtc::Maybe<CodecInst> RentACodec::CodecInstByParams(const char* payload_name, | 38 rtc::Optional<CodecInst> RentACodec::CodecInstByParams(const char* payload_name, |
| 38 int sampling_freq_hz, | 39 int sampling_freq_hz, |
| 39 int channels) { | 40 int channels) { |
| 40 rtc::Maybe<CodecId> codec_id = | 41 rtc::Optional<CodecId> codec_id = |
| 41 CodecIdByParams(payload_name, sampling_freq_hz, channels); | 42 CodecIdByParams(payload_name, sampling_freq_hz, channels); |
| 42 if (!codec_id) | 43 if (!codec_id) |
| 43 return rtc::Maybe<CodecInst>(); | 44 return rtc::Optional<CodecInst>(); |
| 44 rtc::Maybe<CodecInst> ci = CodecInstById(*codec_id); | 45 rtc::Optional<CodecInst> ci = CodecInstById(*codec_id); |
| 45 RTC_DCHECK(ci); | 46 RTC_DCHECK(ci); |
| 46 | 47 |
| 47 // Keep the number of channels from the function call. For most codecs it | 48 // Keep the number of channels from the function call. For most codecs it |
| 48 // will be the same value as in default codec settings, but not for all. | 49 // will be the same value as in default codec settings, but not for all. |
| 49 ci->channels = channels; | 50 ci->channels = channels; |
| 50 | 51 |
| 51 return ci; | 52 return ci; |
| 52 } | 53 } |
| 53 | 54 |
| 54 bool RentACodec::IsCodecValid(const CodecInst& codec_inst) { | 55 bool RentACodec::IsCodecValid(const CodecInst& codec_inst) { |
| 55 return ACMCodecDB::CodecNumber(codec_inst) >= 0; | 56 return ACMCodecDB::CodecNumber(codec_inst) >= 0; |
| 56 } | 57 } |
| 57 | 58 |
| 58 rtc::Maybe<bool> RentACodec::IsSupportedNumChannels(CodecId codec_id, | 59 rtc::Optional<bool> RentACodec::IsSupportedNumChannels(CodecId codec_id, |
| 59 int num_channels) { | 60 int num_channels) { |
| 60 auto i = CodecIndexFromId(codec_id); | 61 auto i = CodecIndexFromId(codec_id); |
| 61 return i ? rtc::Maybe<bool>(ACMCodecDB::codec_settings_[*i].channel_support >= | 62 return i ? rtc::Optional<bool>( |
| 62 num_channels) | 63 ACMCodecDB::codec_settings_[*i].channel_support >= |
| 63 : rtc::Maybe<bool>(); | 64 num_channels) |
| 65 : rtc::Optional<bool>(); |
| 64 } | 66 } |
| 65 | 67 |
| 66 rtc::ArrayView<const CodecInst> RentACodec::Database() { | 68 rtc::ArrayView<const CodecInst> RentACodec::Database() { |
| 67 return rtc::ArrayView<const CodecInst>(ACMCodecDB::database_, | 69 return rtc::ArrayView<const CodecInst>(ACMCodecDB::database_, |
| 68 NumberOfCodecs()); | 70 NumberOfCodecs()); |
| 69 } | 71 } |
| 70 | 72 |
| 71 rtc::Maybe<NetEqDecoder> RentACodec::NetEqDecoderFromCodecId(CodecId codec_id, | 73 rtc::Optional<NetEqDecoder> RentACodec::NetEqDecoderFromCodecId( |
| 72 int num_channels) { | 74 CodecId codec_id, |
| 73 rtc::Maybe<int> i = CodecIndexFromId(codec_id); | 75 int num_channels) { |
| 76 rtc::Optional<int> i = CodecIndexFromId(codec_id); |
| 74 if (!i) | 77 if (!i) |
| 75 return rtc::Maybe<NetEqDecoder>(); | 78 return rtc::Optional<NetEqDecoder>(); |
| 76 const NetEqDecoder ned = ACMCodecDB::neteq_decoders_[*i]; | 79 const NetEqDecoder ned = ACMCodecDB::neteq_decoders_[*i]; |
| 77 return rtc::Maybe<NetEqDecoder>( | 80 return rtc::Optional<NetEqDecoder>( |
| 78 (ned == NetEqDecoder::kDecoderOpus && num_channels == 2) | 81 (ned == NetEqDecoder::kDecoderOpus && num_channels == 2) |
| 79 ? NetEqDecoder::kDecoderOpus_2ch | 82 ? NetEqDecoder::kDecoderOpus_2ch |
| 80 : ned); | 83 : ned); |
| 81 } | 84 } |
| 82 | 85 |
| 83 } // namespace acm2 | 86 } // namespace acm2 |
| 84 } // namespace webrtc | 87 } // namespace webrtc |
| OLD | NEW |