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 18 matching lines...) Expand all Loading... |
29 #ifdef WEBRTC_CODEC_OPUS | 29 #ifdef WEBRTC_CODEC_OPUS |
30 #include "webrtc/modules/audio_coding/codecs/opus/include/audio_encoder_opus.h" | 30 #include "webrtc/modules/audio_coding/codecs/opus/include/audio_encoder_opus.h" |
31 #endif | 31 #endif |
32 #include "webrtc/modules/audio_coding/codecs/pcm16b/include/audio_encoder_pcm16b
.h" | 32 #include "webrtc/modules/audio_coding/codecs/pcm16b/include/audio_encoder_pcm16b
.h" |
33 #include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h" | 33 #include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h" |
34 #include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h" | 34 #include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h" |
35 | 35 |
36 namespace webrtc { | 36 namespace webrtc { |
37 namespace acm2 { | 37 namespace acm2 { |
38 | 38 |
39 rtc::Maybe<RentACodec::CodecId> RentACodec::CodecIdByParams( | 39 rtc::Optional<RentACodec::CodecId> RentACodec::CodecIdByParams( |
40 const char* payload_name, | 40 const char* payload_name, |
41 int sampling_freq_hz, | 41 int sampling_freq_hz, |
42 int channels) { | 42 int channels) { |
43 return CodecIdFromIndex( | 43 return CodecIdFromIndex( |
44 ACMCodecDB::CodecId(payload_name, sampling_freq_hz, channels)); | 44 ACMCodecDB::CodecId(payload_name, sampling_freq_hz, channels)); |
45 } | 45 } |
46 | 46 |
47 rtc::Maybe<CodecInst> RentACodec::CodecInstById(CodecId codec_id) { | 47 rtc::Optional<CodecInst> RentACodec::CodecInstById(CodecId codec_id) { |
48 rtc::Maybe<int> mi = CodecIndexFromId(codec_id); | 48 rtc::Optional<int> mi = CodecIndexFromId(codec_id); |
49 return mi ? rtc::Maybe<CodecInst>(Database()[*mi]) : rtc::Maybe<CodecInst>(); | 49 return mi ? rtc::Optional<CodecInst>(Database()[*mi]) |
| 50 : rtc::Optional<CodecInst>(); |
50 } | 51 } |
51 | 52 |
52 rtc::Maybe<RentACodec::CodecId> RentACodec::CodecIdByInst( | 53 rtc::Optional<RentACodec::CodecId> RentACodec::CodecIdByInst( |
53 const CodecInst& codec_inst) { | 54 const CodecInst& codec_inst) { |
54 return CodecIdFromIndex(ACMCodecDB::CodecNumber(codec_inst)); | 55 return CodecIdFromIndex(ACMCodecDB::CodecNumber(codec_inst)); |
55 } | 56 } |
56 | 57 |
57 rtc::Maybe<CodecInst> RentACodec::CodecInstByParams(const char* payload_name, | 58 rtc::Optional<CodecInst> RentACodec::CodecInstByParams(const char* payload_name, |
58 int sampling_freq_hz, | 59 int sampling_freq_hz, |
59 int channels) { | 60 int channels) { |
60 rtc::Maybe<CodecId> codec_id = | 61 rtc::Optional<CodecId> codec_id = |
61 CodecIdByParams(payload_name, sampling_freq_hz, channels); | 62 CodecIdByParams(payload_name, sampling_freq_hz, channels); |
62 if (!codec_id) | 63 if (!codec_id) |
63 return rtc::Maybe<CodecInst>(); | 64 return rtc::Optional<CodecInst>(); |
64 rtc::Maybe<CodecInst> ci = CodecInstById(*codec_id); | 65 rtc::Optional<CodecInst> ci = CodecInstById(*codec_id); |
65 RTC_DCHECK(ci); | 66 RTC_DCHECK(ci); |
66 | 67 |
67 // Keep the number of channels from the function call. For most codecs it | 68 // Keep the number of channels from the function call. For most codecs it |
68 // will be the same value as in default codec settings, but not for all. | 69 // will be the same value as in default codec settings, but not for all. |
69 ci->channels = channels; | 70 ci->channels = channels; |
70 | 71 |
71 return ci; | 72 return ci; |
72 } | 73 } |
73 | 74 |
74 bool RentACodec::IsCodecValid(const CodecInst& codec_inst) { | 75 bool RentACodec::IsCodecValid(const CodecInst& codec_inst) { |
75 return ACMCodecDB::CodecNumber(codec_inst) >= 0; | 76 return ACMCodecDB::CodecNumber(codec_inst) >= 0; |
76 } | 77 } |
77 | 78 |
78 rtc::Maybe<bool> RentACodec::IsSupportedNumChannels(CodecId codec_id, | 79 rtc::Optional<bool> RentACodec::IsSupportedNumChannels(CodecId codec_id, |
79 int num_channels) { | 80 int num_channels) { |
80 auto i = CodecIndexFromId(codec_id); | 81 auto i = CodecIndexFromId(codec_id); |
81 return i ? rtc::Maybe<bool>(ACMCodecDB::codec_settings_[*i].channel_support >= | 82 return i ? rtc::Optional<bool>( |
82 num_channels) | 83 ACMCodecDB::codec_settings_[*i].channel_support >= |
83 : rtc::Maybe<bool>(); | 84 num_channels) |
| 85 : rtc::Optional<bool>(); |
84 } | 86 } |
85 | 87 |
86 rtc::ArrayView<const CodecInst> RentACodec::Database() { | 88 rtc::ArrayView<const CodecInst> RentACodec::Database() { |
87 return rtc::ArrayView<const CodecInst>(ACMCodecDB::database_, | 89 return rtc::ArrayView<const CodecInst>(ACMCodecDB::database_, |
88 NumberOfCodecs()); | 90 NumberOfCodecs()); |
89 } | 91 } |
90 | 92 |
91 rtc::Maybe<NetEqDecoder> RentACodec::NetEqDecoderFromCodecId(CodecId codec_id, | 93 rtc::Optional<NetEqDecoder> RentACodec::NetEqDecoderFromCodecId( |
92 int num_channels) { | 94 CodecId codec_id, |
93 rtc::Maybe<int> i = CodecIndexFromId(codec_id); | 95 int num_channels) { |
| 96 rtc::Optional<int> i = CodecIndexFromId(codec_id); |
94 if (!i) | 97 if (!i) |
95 return rtc::Maybe<NetEqDecoder>(); | 98 return rtc::Optional<NetEqDecoder>(); |
96 const NetEqDecoder ned = ACMCodecDB::neteq_decoders_[*i]; | 99 const NetEqDecoder ned = ACMCodecDB::neteq_decoders_[*i]; |
97 return rtc::Maybe<NetEqDecoder>( | 100 return rtc::Optional<NetEqDecoder>( |
98 (ned == NetEqDecoder::kDecoderOpus && num_channels == 2) | 101 (ned == NetEqDecoder::kDecoderOpus && num_channels == 2) |
99 ? NetEqDecoder::kDecoderOpus_2ch | 102 ? NetEqDecoder::kDecoderOpus_2ch |
100 : ned); | 103 : ned); |
101 } | 104 } |
102 | 105 |
103 namespace { | 106 namespace { |
104 | 107 |
105 // Returns a new speech encoder, or null on error. | 108 // Returns a new speech encoder, or null on error. |
106 // TODO(kwiberg): Don't handle errors here (bug 5033) | 109 // TODO(kwiberg): Don't handle errors here (bug 5033) |
107 rtc::scoped_ptr<AudioEncoder> CreateEncoder( | 110 rtc::scoped_ptr<AudioEncoder> CreateEncoder( |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 } | 167 } |
165 | 168 |
166 AudioDecoder* RentACodec::RentIsacDecoder() { | 169 AudioDecoder* RentACodec::RentIsacDecoder() { |
167 if (!isac_decoder_) | 170 if (!isac_decoder_) |
168 isac_decoder_ = CreateIsacDecoder(&isac_bandwidth_info_); | 171 isac_decoder_ = CreateIsacDecoder(&isac_bandwidth_info_); |
169 return isac_decoder_.get(); | 172 return isac_decoder_.get(); |
170 } | 173 } |
171 | 174 |
172 } // namespace acm2 | 175 } // namespace acm2 |
173 } // namespace webrtc | 176 } // namespace webrtc |
OLD | NEW |