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 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_DECODER_ISAC_T_IMPL_H_ | 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_ | 12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_DECODER_ISAC_T_IMPL_H_ |
13 | 13 |
14 #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_decoder_isa
c.h" | 14 #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_decoder_isa
c.h" |
15 | 15 |
16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
17 | 17 |
18 namespace webrtc { | 18 namespace webrtc { |
19 | 19 |
20 template <typename T> | 20 template <typename T> |
21 AudioDecoderIsacT<T>::AudioDecoderIsacT() | 21 AudioDecoderIsacT<T>::AudioDecoderIsacT() |
22 : AudioDecoderIsacT(nullptr) {} | 22 : AudioDecoderIsacT(rtc::Optional<int>(), nullptr) {} |
23 | 23 |
24 template <typename T> | 24 template <typename T> |
25 AudioDecoderIsacT<T>::AudioDecoderIsacT( | 25 AudioDecoderIsacT<T>::AudioDecoderIsacT( |
26 const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo) | 26 const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo) |
27 : bwinfo_(bwinfo), decoder_sample_rate_hz_(-1) { | 27 : AudioDecoderIsacT(rtc::Optional<int>(), bwinfo) {} |
| 28 |
| 29 template <typename T> |
| 30 AudioDecoderIsacT<T>::AudioDecoderIsacT(int sample_rate_hz) |
| 31 : AudioDecoderIsacT(rtc::Optional<int>(sample_rate_hz), nullptr) {} |
| 32 |
| 33 template <typename T> |
| 34 AudioDecoderIsacT<T>::AudioDecoderIsacT( |
| 35 int sample_rate_hz, |
| 36 const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo) |
| 37 : AudioDecoderIsacT(rtc::Optional<int>(sample_rate_hz), bwinfo) {} |
| 38 |
| 39 template <typename T> |
| 40 AudioDecoderIsacT<T>::AudioDecoderIsacT( |
| 41 rtc::Optional<int> sample_rate_hz, |
| 42 const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo) |
| 43 : sample_rate_hz_(sample_rate_hz), bwinfo_(bwinfo) { |
| 44 RTC_CHECK(!sample_rate_hz || *sample_rate_hz == 16000 || |
| 45 *sample_rate_hz == 32000) |
| 46 << "Unsupported sample rate " << *sample_rate_hz; |
28 RTC_CHECK_EQ(0, T::Create(&isac_state_)); | 47 RTC_CHECK_EQ(0, T::Create(&isac_state_)); |
29 T::DecoderInit(isac_state_); | 48 T::DecoderInit(isac_state_); |
30 if (bwinfo_) { | 49 if (bwinfo_) { |
31 IsacBandwidthInfo bi; | 50 IsacBandwidthInfo bi; |
32 T::GetBandwidthInfo(isac_state_, &bi); | 51 T::GetBandwidthInfo(isac_state_, &bi); |
33 bwinfo_->Set(bi); | 52 bwinfo_->Set(bi); |
34 } | 53 } |
| 54 if (sample_rate_hz_) { |
| 55 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, *sample_rate_hz_)); |
| 56 } |
35 } | 57 } |
36 | 58 |
37 template <typename T> | 59 template <typename T> |
38 AudioDecoderIsacT<T>::~AudioDecoderIsacT() { | 60 AudioDecoderIsacT<T>::~AudioDecoderIsacT() { |
39 RTC_CHECK_EQ(0, T::Free(isac_state_)); | 61 RTC_CHECK_EQ(0, T::Free(isac_state_)); |
40 } | 62 } |
41 | 63 |
42 template <typename T> | 64 template <typename T> |
43 int AudioDecoderIsacT<T>::DecodeInternal(const uint8_t* encoded, | 65 int AudioDecoderIsacT<T>::DecodeInternal(const uint8_t* encoded, |
44 size_t encoded_len, | 66 size_t encoded_len, |
45 int sample_rate_hz, | 67 int sample_rate_hz, |
46 int16_t* decoded, | 68 int16_t* decoded, |
47 SpeechType* speech_type) { | 69 SpeechType* speech_type) { |
48 RTC_CHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000) | 70 if (sample_rate_hz_) { |
49 << "Unsupported sample rate " << sample_rate_hz; | 71 RTC_CHECK_EQ(*sample_rate_hz_, sample_rate_hz); |
50 if (sample_rate_hz != decoder_sample_rate_hz_) { | 72 } else { |
51 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, sample_rate_hz)); | 73 RTC_CHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000) |
52 decoder_sample_rate_hz_ = sample_rate_hz; | 74 << "Unsupported sample rate " << sample_rate_hz; |
| 75 sample_rate_hz_ = rtc::Optional<int>(sample_rate_hz); |
| 76 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, *sample_rate_hz_)); |
53 } | 77 } |
54 int16_t temp_type = 1; // Default is speech. | 78 int16_t temp_type = 1; // Default is speech. |
55 int ret = | 79 int ret = |
56 T::DecodeInternal(isac_state_, encoded, encoded_len, decoded, &temp_type); | 80 T::DecodeInternal(isac_state_, encoded, encoded_len, decoded, &temp_type); |
57 *speech_type = ConvertSpeechType(temp_type); | 81 *speech_type = ConvertSpeechType(temp_type); |
58 return ret; | 82 return ret; |
59 } | 83 } |
60 | 84 |
61 template <typename T> | 85 template <typename T> |
62 bool AudioDecoderIsacT<T>::HasDecodePlc() const { | 86 bool AudioDecoderIsacT<T>::HasDecodePlc() const { |
(...skipping 26 matching lines...) Expand all Loading... |
89 } | 113 } |
90 return ret; | 114 return ret; |
91 } | 115 } |
92 | 116 |
93 template <typename T> | 117 template <typename T> |
94 int AudioDecoderIsacT<T>::ErrorCode() { | 118 int AudioDecoderIsacT<T>::ErrorCode() { |
95 return T::GetErrorCode(isac_state_); | 119 return T::GetErrorCode(isac_state_); |
96 } | 120 } |
97 | 121 |
98 template <typename T> | 122 template <typename T> |
| 123 int AudioDecoderIsacT<T>::SampleRateHz() const { |
| 124 RTC_CHECK(sample_rate_hz_) << "Sample rate not set yet!"; |
| 125 return *sample_rate_hz_; |
| 126 } |
| 127 |
| 128 template <typename T> |
99 size_t AudioDecoderIsacT<T>::Channels() const { | 129 size_t AudioDecoderIsacT<T>::Channels() const { |
100 return 1; | 130 return 1; |
101 } | 131 } |
102 | 132 |
103 } // namespace webrtc | 133 } // namespace webrtc |
104 | 134 |
105 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_DECODER_ISAC_T_IMPL_H_ | 135 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_DECODER_ISAC_T_IMPL_H_ |
OLD | NEW |