Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: webrtc/modules/audio_coding/codecs/isac/audio_decoder_isac_t_impl.h

Issue 2020353003: AudioDecoderIsacT: Require caller to always specify sample rate (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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()
22 : AudioDecoderIsacT(rtc::Optional<int>(), nullptr) {}
23
24 template <typename T>
25 AudioDecoderIsacT<T>::AudioDecoderIsacT(
26 const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo)
27 : AudioDecoderIsacT(rtc::Optional<int>(), bwinfo) {}
28
29 template <typename T>
30 AudioDecoderIsacT<T>::AudioDecoderIsacT(int sample_rate_hz) 21 AudioDecoderIsacT<T>::AudioDecoderIsacT(int sample_rate_hz)
31 : AudioDecoderIsacT(rtc::Optional<int>(sample_rate_hz), nullptr) {} 22 : AudioDecoderIsacT(sample_rate_hz, nullptr) {}
32 23
33 template <typename T> 24 template <typename T>
34 AudioDecoderIsacT<T>::AudioDecoderIsacT( 25 AudioDecoderIsacT<T>::AudioDecoderIsacT(
35 int sample_rate_hz, 26 int sample_rate_hz,
36 const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo) 27 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) { 28 : sample_rate_hz_(sample_rate_hz), bwinfo_(bwinfo) {
44 RTC_CHECK(!sample_rate_hz || *sample_rate_hz == 16000 || 29 RTC_CHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000)
45 *sample_rate_hz == 32000) 30 << "Unsupported sample rate " << sample_rate_hz;
46 << "Unsupported sample rate " << *sample_rate_hz;
47 RTC_CHECK_EQ(0, T::Create(&isac_state_)); 31 RTC_CHECK_EQ(0, T::Create(&isac_state_));
48 T::DecoderInit(isac_state_); 32 T::DecoderInit(isac_state_);
49 if (bwinfo_) { 33 if (bwinfo_) {
50 IsacBandwidthInfo bi; 34 IsacBandwidthInfo bi;
51 T::GetBandwidthInfo(isac_state_, &bi); 35 T::GetBandwidthInfo(isac_state_, &bi);
52 bwinfo_->Set(bi); 36 bwinfo_->Set(bi);
53 } 37 }
54 if (sample_rate_hz_) { 38 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, sample_rate_hz_));
55 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, *sample_rate_hz_));
56 }
57 } 39 }
58 40
59 template <typename T> 41 template <typename T>
60 AudioDecoderIsacT<T>::~AudioDecoderIsacT() { 42 AudioDecoderIsacT<T>::~AudioDecoderIsacT() {
61 RTC_CHECK_EQ(0, T::Free(isac_state_)); 43 RTC_CHECK_EQ(0, T::Free(isac_state_));
62 } 44 }
63 45
64 template <typename T> 46 template <typename T>
65 int AudioDecoderIsacT<T>::DecodeInternal(const uint8_t* encoded, 47 int AudioDecoderIsacT<T>::DecodeInternal(const uint8_t* encoded,
66 size_t encoded_len, 48 size_t encoded_len,
67 int sample_rate_hz, 49 int sample_rate_hz,
68 int16_t* decoded, 50 int16_t* decoded,
69 SpeechType* speech_type) { 51 SpeechType* speech_type) {
70 if (sample_rate_hz_) { 52 RTC_CHECK_EQ(sample_rate_hz_, sample_rate_hz);
71 RTC_CHECK_EQ(*sample_rate_hz_, sample_rate_hz);
72 } else {
73 RTC_CHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000)
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_));
77 }
78 int16_t temp_type = 1; // Default is speech. 53 int16_t temp_type = 1; // Default is speech.
79 int ret = 54 int ret =
80 T::DecodeInternal(isac_state_, encoded, encoded_len, decoded, &temp_type); 55 T::DecodeInternal(isac_state_, encoded, encoded_len, decoded, &temp_type);
81 *speech_type = ConvertSpeechType(temp_type); 56 *speech_type = ConvertSpeechType(temp_type);
82 return ret; 57 return ret;
83 } 58 }
84 59
85 template <typename T> 60 template <typename T>
86 bool AudioDecoderIsacT<T>::HasDecodePlc() const { 61 bool AudioDecoderIsacT<T>::HasDecodePlc() const {
87 return false; 62 return false;
(...skipping 26 matching lines...) Expand all
114 return ret; 89 return ret;
115 } 90 }
116 91
117 template <typename T> 92 template <typename T>
118 int AudioDecoderIsacT<T>::ErrorCode() { 93 int AudioDecoderIsacT<T>::ErrorCode() {
119 return T::GetErrorCode(isac_state_); 94 return T::GetErrorCode(isac_state_);
120 } 95 }
121 96
122 template <typename T> 97 template <typename T>
123 int AudioDecoderIsacT<T>::SampleRateHz() const { 98 int AudioDecoderIsacT<T>::SampleRateHz() const {
124 RTC_CHECK(sample_rate_hz_) << "Sample rate not set yet!"; 99 return sample_rate_hz_;
125 return *sample_rate_hz_;
126 } 100 }
127 101
128 template <typename T> 102 template <typename T>
129 size_t AudioDecoderIsacT<T>::Channels() const { 103 size_t AudioDecoderIsacT<T>::Channels() const {
130 return 1; 104 return 1;
131 } 105 }
132 106
133 } // namespace webrtc 107 } // namespace webrtc
134 108
135 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_DECODER_ISAC_T_IMPL_H_ 109 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_DECODER_ISAC_T_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698