1 /* 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_DECODER_ISAC_T_IMPL_H_ 12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_DECODER_ISAC_T_IMPL_H_ 13 14 #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_decoder_isac.h" 15 16 #include "webrtc/base/checks.h" 17 18 namespace webrtc { 19 20 template <typename T> 21 AudioDecoderIsacT<T>::AudioDecoderIsacT() 22 : AudioDecoderIsacT(nullptr) {} 23 24 template <typename T> 25 AudioDecoderIsacT<T>::AudioDecoderIsacT(LockedIsacBandwidthInfo* bwinfo) 26 : bwinfo_(bwinfo), decoder_sample_rate_hz_(-1) { 27 RTC_CHECK_EQ(0, T::Create(&isac_state_)); 28 T::DecoderInit(isac_state_); 29 if (bwinfo_) { 30 IsacBandwidthInfo bi; 31 T::GetBandwidthInfo(isac_state_, &bi); 32 bwinfo_->Set(bi); 33 } 34 } 35 36 template <typename T> 37 AudioDecoderIsacT<T>::~AudioDecoderIsacT() { 38 RTC_CHECK_EQ(0, T::Free(isac_state_)); 39 } 40 41 template <typename T> 42 int AudioDecoderIsacT<T>::DecodeInternal(const uint8_t* encoded, 43 size_t encoded_len, 44 int sample_rate_hz, 45 int16_t* decoded, 46 SpeechType* speech_type) { 47 RTC_CHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000) 48 << "Unsupported sample rate " << sample_rate_hz; 49 if (sample_rate_hz != decoder_sample_rate_hz_) { 50 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, sample_rate_hz)); 51 decoder_sample_rate_hz_ = sample_rate_hz; 52 } 53 int16_t temp_type = 1; // Default is speech. 54 int ret = 55 T::DecodeInternal(isac_state_, encoded, encoded_len, decoded, &temp_type); 56 *speech_type = ConvertSpeechType(temp_type); 57 return ret; 58 } 59 60 template <typename T> 61 bool AudioDecoderIsacT<T>::HasDecodePlc() const { 62 return false; 63 } 64 65 template <typename T> 66 size_t AudioDecoderIsacT<T>::DecodePlc(size_t num_frames, int16_t* decoded) { 67 return T::DecodePlc(isac_state_, decoded, num_frames); 68 } 69 70 template <typename T> 71 void AudioDecoderIsacT<T>::Reset() { 72 T::DecoderInit(isac_state_); 73 } 74 75 template <typename T> 76 int AudioDecoderIsacT<T>::IncomingPacket(const uint8_t* payload, 77 size_t payload_len, 78 uint16_t rtp_sequence_number, 79 uint32_t rtp_timestamp, 80 uint32_t arrival_timestamp) { 81 int ret = T::UpdateBwEstimate(isac_state_, payload, payload_len, 82 rtp_sequence_number, rtp_timestamp, 83 arrival_timestamp); 84 if (bwinfo_) { 85 IsacBandwidthInfo bwinfo; 86 T::GetBandwidthInfo(isac_state_, &bwinfo); 87 bwinfo_->Set(bwinfo); 88 } 89 return ret; 90 } 91 92 template <typename T> 93 int AudioDecoderIsacT<T>::ErrorCode() { 94 return T::GetErrorCode(isac_state_); 95 } 96 97 template <typename T> 98 size_t AudioDecoderIsacT<T>::Channels() const { 99 return 1; 100 } 101 102 } // namespace webrtc 103 104 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_DECODER_ISAC_T_IMPL_H_ 105