OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ |
12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ | 12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ |
13 | 13 |
14 #include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_encoder_i
sac.h" | 14 #include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_encoder_i
sac.h" |
15 | 15 |
16 #include <algorithm> | |
17 | |
18 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
19 #include "webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h" | |
20 | 17 |
21 namespace webrtc { | 18 namespace webrtc { |
22 | 19 |
23 template <typename T> | 20 template <typename T> |
24 typename AudioEncoderIsacT<T>::Config CreateIsacConfig( | 21 typename AudioEncoderIsacT<T>::Config CreateIsacConfig( |
25 const CodecInst& codec_inst, | 22 const CodecInst& codec_inst, |
26 LockedIsacBandwidthInfo* bwinfo) { | 23 LockedIsacBandwidthInfo* bwinfo) { |
27 typename AudioEncoderIsacT<T>::Config config; | 24 typename AudioEncoderIsacT<T>::Config config; |
28 config.bwinfo = bwinfo; | 25 config.bwinfo = bwinfo; |
29 config.payload_type = codec_inst.pltype; | 26 config.payload_type = codec_inst.pltype; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 183 |
187 // Set the decoder sample rate even though we just use the encoder. This | 184 // Set the decoder sample rate even though we just use the encoder. This |
188 // doesn't appear to be necessary to produce a valid encoding, but without it | 185 // doesn't appear to be necessary to produce a valid encoding, but without it |
189 // we get an encoding that isn't bit-for-bit identical with what a combined | 186 // we get an encoding that isn't bit-for-bit identical with what a combined |
190 // encoder+decoder object produces. | 187 // encoder+decoder object produces. |
191 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, decoder_sample_rate_hz)); | 188 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, decoder_sample_rate_hz)); |
192 | 189 |
193 config_ = config; | 190 config_ = config; |
194 } | 191 } |
195 | 192 |
196 template <typename T> | |
197 AudioDecoderIsacT<T>::AudioDecoderIsacT() | |
198 : AudioDecoderIsacT(nullptr) {} | |
199 | |
200 template <typename T> | |
201 AudioDecoderIsacT<T>::AudioDecoderIsacT(LockedIsacBandwidthInfo* bwinfo) | |
202 : bwinfo_(bwinfo), decoder_sample_rate_hz_(-1) { | |
203 RTC_CHECK_EQ(0, T::Create(&isac_state_)); | |
204 T::DecoderInit(isac_state_); | |
205 if (bwinfo_) { | |
206 IsacBandwidthInfo bi; | |
207 T::GetBandwidthInfo(isac_state_, &bi); | |
208 bwinfo_->Set(bi); | |
209 } | |
210 } | |
211 | |
212 template <typename T> | |
213 AudioDecoderIsacT<T>::~AudioDecoderIsacT() { | |
214 RTC_CHECK_EQ(0, T::Free(isac_state_)); | |
215 } | |
216 | |
217 template <typename T> | |
218 int AudioDecoderIsacT<T>::DecodeInternal(const uint8_t* encoded, | |
219 size_t encoded_len, | |
220 int sample_rate_hz, | |
221 int16_t* decoded, | |
222 SpeechType* speech_type) { | |
223 // We want to crate the illusion that iSAC supports 48000 Hz decoding, while | |
224 // in fact it outputs 32000 Hz. This is the iSAC fullband mode. | |
225 if (sample_rate_hz == 48000) | |
226 sample_rate_hz = 32000; | |
227 RTC_CHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000) | |
228 << "Unsupported sample rate " << sample_rate_hz; | |
229 if (sample_rate_hz != decoder_sample_rate_hz_) { | |
230 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, sample_rate_hz)); | |
231 decoder_sample_rate_hz_ = sample_rate_hz; | |
232 } | |
233 int16_t temp_type = 1; // Default is speech. | |
234 int ret = | |
235 T::DecodeInternal(isac_state_, encoded, encoded_len, decoded, &temp_type); | |
236 *speech_type = ConvertSpeechType(temp_type); | |
237 return ret; | |
238 } | |
239 | |
240 template <typename T> | |
241 bool AudioDecoderIsacT<T>::HasDecodePlc() const { | |
242 return false; | |
243 } | |
244 | |
245 template <typename T> | |
246 size_t AudioDecoderIsacT<T>::DecodePlc(size_t num_frames, int16_t* decoded) { | |
247 return T::DecodePlc(isac_state_, decoded, num_frames); | |
248 } | |
249 | |
250 template <typename T> | |
251 void AudioDecoderIsacT<T>::Reset() { | |
252 T::DecoderInit(isac_state_); | |
253 } | |
254 | |
255 template <typename T> | |
256 int AudioDecoderIsacT<T>::IncomingPacket(const uint8_t* payload, | |
257 size_t payload_len, | |
258 uint16_t rtp_sequence_number, | |
259 uint32_t rtp_timestamp, | |
260 uint32_t arrival_timestamp) { | |
261 int ret = T::UpdateBwEstimate( | |
262 isac_state_, payload, payload_len, | |
263 rtp_sequence_number, rtp_timestamp, arrival_timestamp); | |
264 if (bwinfo_) { | |
265 IsacBandwidthInfo bwinfo; | |
266 T::GetBandwidthInfo(isac_state_, &bwinfo); | |
267 bwinfo_->Set(bwinfo); | |
268 } | |
269 return ret; | |
270 } | |
271 | |
272 template <typename T> | |
273 int AudioDecoderIsacT<T>::ErrorCode() { | |
274 return T::GetErrorCode(isac_state_); | |
275 } | |
276 | |
277 template <typename T> | |
278 size_t AudioDecoderIsacT<T>::Channels() const { | |
279 return 1; | |
280 } | |
281 | |
282 } // namespace webrtc | 193 } // namespace webrtc |
283 | 194 |
284 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ | 195 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ |
OLD | NEW |