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:
@ -710,7 +710,7 @@ int AudioCodingModuleImpl::RegisterReceiveCodec(const CodecInst& codec) {
|
||||
rtc::CritScope lock(&acm_crit_sect_);
|
||||
auto* ef = encoder_factory_.get();
|
||||
return RegisterReceiveCodecUnlocked(
|
||||
codec, [ef] { return ef->rent_a_codec.RentIsacDecoder(); });
|
||||
codec, [&] { return ef->rent_a_codec.RentIsacDecoder(codec.plfreq); });
|
||||
}
|
||||
|
||||
int AudioCodingModuleImpl::RegisterReceiveCodec(
|
||||
|
||||
@ -279,11 +279,14 @@ std::unique_ptr<AudioEncoder> CreateCngEncoder(
|
||||
}
|
||||
|
||||
std::unique_ptr<AudioDecoder> CreateIsacDecoder(
|
||||
int sample_rate_hz,
|
||||
const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo) {
|
||||
#if defined(WEBRTC_CODEC_ISACFX)
|
||||
return std::unique_ptr<AudioDecoder>(new AudioDecoderIsacFix(bwinfo));
|
||||
return std::unique_ptr<AudioDecoder>(
|
||||
new AudioDecoderIsacFix(sample_rate_hz, bwinfo));
|
||||
#elif defined(WEBRTC_CODEC_ISAC)
|
||||
return std::unique_ptr<AudioDecoder>(new AudioDecoderIsac(bwinfo));
|
||||
return std::unique_ptr<AudioDecoder>(
|
||||
new AudioDecoderIsac(sample_rate_hz, bwinfo));
|
||||
#else
|
||||
FATAL() << "iSAC is not supported.";
|
||||
return std::unique_ptr<AudioDecoder>();
|
||||
@ -357,8 +360,8 @@ std::unique_ptr<AudioEncoder> RentACodec::RentEncoderStack(
|
||||
return encoder_stack;
|
||||
}
|
||||
|
||||
std::unique_ptr<AudioDecoder> RentACodec::RentIsacDecoder() {
|
||||
return CreateIsacDecoder(isac_bandwidth_info_);
|
||||
std::unique_ptr<AudioDecoder> RentACodec::RentIsacDecoder(int sample_rate_hz) {
|
||||
return CreateIsacDecoder(sample_rate_hz, isac_bandwidth_info_);
|
||||
}
|
||||
|
||||
} // namespace acm2
|
||||
|
||||
@ -220,7 +220,7 @@ class RentACodec {
|
||||
std::unique_ptr<AudioEncoder> RentEncoderStack(StackParameters* param);
|
||||
|
||||
// Creates and returns an iSAC decoder.
|
||||
std::unique_ptr<AudioDecoder> RentIsacDecoder();
|
||||
std::unique_ptr<AudioDecoder> RentIsacDecoder(int sample_rate_hz);
|
||||
|
||||
private:
|
||||
std::unique_ptr<AudioEncoder> speech_encoder_;
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -45,8 +45,9 @@ int32_t AudioCoder::SetEncodeCodec(const CodecInst& codec_inst) {
|
||||
}
|
||||
|
||||
int32_t AudioCoder::SetDecodeCodec(const CodecInst& codec_inst) {
|
||||
if (acm_->RegisterReceiveCodec(
|
||||
codec_inst, [&] { return rent_a_codec_.RentIsacDecoder(); }) == -1) {
|
||||
if (acm_->RegisterReceiveCodec(codec_inst, [&] {
|
||||
return rent_a_codec_.RentIsacDecoder(codec_inst.plfreq);
|
||||
}) == -1) {
|
||||
return -1;
|
||||
}
|
||||
memcpy(&receive_codec_, &codec_inst, sizeof(CodecInst));
|
||||
|
||||
@ -13,10 +13,10 @@
|
||||
|
||||
namespace webrtc {
|
||||
void FuzzOneInput(const uint8_t* data, size_t size) {
|
||||
AudioDecoderIsac dec(nullptr);
|
||||
const int sample_rate_hz = size % 2 == 0 ? 16000 : 32000; // 16 or 32 kHz.
|
||||
static const size_t kAllocatedOuputSizeSamples = 32000 / 10; // 100 ms.
|
||||
int16_t output[kAllocatedOuputSizeSamples];
|
||||
AudioDecoderIsac dec(sample_rate_hz);
|
||||
FuzzAudioDecoder(DecoderFunctionType::kNormalDecode, data, size, &dec,
|
||||
sample_rate_hz, sizeof(output), output);
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
|
||||
namespace webrtc {
|
||||
void FuzzOneInput(const uint8_t* data, size_t size) {
|
||||
AudioDecoderIsac dec(nullptr);
|
||||
AudioDecoderIsac dec(16000);
|
||||
FuzzAudioDecoderIncomingPacket(data, size, &dec);
|
||||
}
|
||||
} // namespace webrtc
|
||||
|
||||
@ -13,10 +13,10 @@
|
||||
|
||||
namespace webrtc {
|
||||
void FuzzOneInput(const uint8_t* data, size_t size) {
|
||||
AudioDecoderIsacFix dec(nullptr);
|
||||
static const int kSampleRateHz = 16000;
|
||||
static const size_t kAllocatedOuputSizeSamples = 16000 / 10; // 100 ms.
|
||||
int16_t output[kAllocatedOuputSizeSamples];
|
||||
AudioDecoderIsacFix dec(kSampleRateHz);
|
||||
FuzzAudioDecoder(DecoderFunctionType::kNormalDecode, data, size, &dec,
|
||||
kSampleRateHz, sizeof(output), output);
|
||||
}
|
||||
|
||||
@ -49,8 +49,8 @@ namespace {
|
||||
bool RegisterReceiveCodec(std::unique_ptr<AudioCodingModule>* acm,
|
||||
acm2::RentACodec* rac,
|
||||
const CodecInst& ci) {
|
||||
const int result =
|
||||
(*acm)->RegisterReceiveCodec(ci, [&] { return rac->RentIsacDecoder(); });
|
||||
const int result = (*acm)->RegisterReceiveCodec(
|
||||
ci, [&] { return rac->RentIsacDecoder(ci.plfreq); });
|
||||
return result == 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user