AudioDecoderIsacT: Require caller to always specify sample rate
This gets rid of the complex & icky state where the sample rate is not yet determined. BUG=webrtc:5801 Review-Url: https://codereview.webrtc.org/2020353003 Cr-Commit-Position: refs/heads/master@{#13011}
This commit is contained in:
@ -26,9 +26,6 @@ namespace webrtc {
|
||||
template <typename T>
|
||||
class AudioDecoderIsacT final : public AudioDecoder {
|
||||
public:
|
||||
AudioDecoderIsacT();
|
||||
explicit AudioDecoderIsacT(
|
||||
const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo);
|
||||
explicit AudioDecoderIsacT(int sample_rate_hz);
|
||||
AudioDecoderIsacT(int sample_rate_hz,
|
||||
const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo);
|
||||
@ -52,11 +49,8 @@ class AudioDecoderIsacT final : public AudioDecoder {
|
||||
SpeechType* speech_type) override;
|
||||
|
||||
private:
|
||||
AudioDecoderIsacT(rtc::Optional<int> sample_rate_hz,
|
||||
const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo);
|
||||
|
||||
typename T::instance_type* isac_state_;
|
||||
rtc::Optional<int> sample_rate_hz_;
|
||||
int sample_rate_hz_;
|
||||
rtc::scoped_refptr<LockedIsacBandwidthInfo> bwinfo_;
|
||||
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoderIsacT);
|
||||
|
||||
@ -17,33 +17,17 @@
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
template <typename T>
|
||||
AudioDecoderIsacT<T>::AudioDecoderIsacT()
|
||||
: AudioDecoderIsacT(rtc::Optional<int>(), nullptr) {}
|
||||
|
||||
template <typename T>
|
||||
AudioDecoderIsacT<T>::AudioDecoderIsacT(
|
||||
const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo)
|
||||
: AudioDecoderIsacT(rtc::Optional<int>(), bwinfo) {}
|
||||
|
||||
template <typename T>
|
||||
AudioDecoderIsacT<T>::AudioDecoderIsacT(int sample_rate_hz)
|
||||
: AudioDecoderIsacT(rtc::Optional<int>(sample_rate_hz), nullptr) {}
|
||||
: AudioDecoderIsacT(sample_rate_hz, nullptr) {}
|
||||
|
||||
template <typename T>
|
||||
AudioDecoderIsacT<T>::AudioDecoderIsacT(
|
||||
int sample_rate_hz,
|
||||
const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo)
|
||||
: AudioDecoderIsacT(rtc::Optional<int>(sample_rate_hz), bwinfo) {}
|
||||
|
||||
template <typename T>
|
||||
AudioDecoderIsacT<T>::AudioDecoderIsacT(
|
||||
rtc::Optional<int> sample_rate_hz,
|
||||
const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo)
|
||||
: sample_rate_hz_(sample_rate_hz), bwinfo_(bwinfo) {
|
||||
RTC_CHECK(!sample_rate_hz || *sample_rate_hz == 16000 ||
|
||||
*sample_rate_hz == 32000)
|
||||
<< "Unsupported sample rate " << *sample_rate_hz;
|
||||
RTC_CHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000)
|
||||
<< "Unsupported sample rate " << sample_rate_hz;
|
||||
RTC_CHECK_EQ(0, T::Create(&isac_state_));
|
||||
T::DecoderInit(isac_state_);
|
||||
if (bwinfo_) {
|
||||
@ -51,9 +35,7 @@ AudioDecoderIsacT<T>::AudioDecoderIsacT(
|
||||
T::GetBandwidthInfo(isac_state_, &bi);
|
||||
bwinfo_->Set(bi);
|
||||
}
|
||||
if (sample_rate_hz_) {
|
||||
RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, *sample_rate_hz_));
|
||||
}
|
||||
RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, sample_rate_hz_));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -67,14 +49,7 @@ int AudioDecoderIsacT<T>::DecodeInternal(const uint8_t* encoded,
|
||||
int sample_rate_hz,
|
||||
int16_t* decoded,
|
||||
SpeechType* speech_type) {
|
||||
if (sample_rate_hz_) {
|
||||
RTC_CHECK_EQ(*sample_rate_hz_, sample_rate_hz);
|
||||
} else {
|
||||
RTC_CHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000)
|
||||
<< "Unsupported sample rate " << sample_rate_hz;
|
||||
sample_rate_hz_ = rtc::Optional<int>(sample_rate_hz);
|
||||
RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, *sample_rate_hz_));
|
||||
}
|
||||
RTC_CHECK_EQ(sample_rate_hz_, sample_rate_hz);
|
||||
int16_t temp_type = 1; // Default is speech.
|
||||
int ret =
|
||||
T::DecodeInternal(isac_state_, encoded, encoded_len, decoded, &temp_type);
|
||||
@ -121,8 +96,7 @@ int AudioDecoderIsacT<T>::ErrorCode() {
|
||||
|
||||
template <typename T>
|
||||
int AudioDecoderIsacT<T>::SampleRateHz() const {
|
||||
RTC_CHECK(sample_rate_hz_) << "Sample rate not set yet!";
|
||||
return *sample_rate_hz_;
|
||||
return sample_rate_hz_;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
||||
Reference in New Issue
Block a user