Opus implementation of the AudioDecoderFactoryTemplate API
BUG=webrtc:7837 Review-Url: https://codereview.webrtc.org/2942733003 Cr-Commit-Position: refs/heads/master@{#18646}
This commit is contained in:
@ -162,7 +162,7 @@ NamedDecoderConstructor decoder_constructors[] = {
|
||||
if (format.clockrate_hz == 48000 && format.num_channels == 2 &&
|
||||
num_channels) {
|
||||
if (out) {
|
||||
out->reset(new AudioDecoderOpus(*num_channels));
|
||||
out->reset(new AudioDecoderOpusImpl(*num_channels));
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@ -19,7 +19,7 @@ namespace webrtc {
|
||||
namespace {
|
||||
class OpusFrame : public AudioDecoder::EncodedAudioFrame {
|
||||
public:
|
||||
OpusFrame(AudioDecoderOpus* decoder,
|
||||
OpusFrame(AudioDecoderOpusImpl* decoder,
|
||||
rtc::Buffer&& payload,
|
||||
bool is_primary_payload)
|
||||
: decoder_(decoder),
|
||||
@ -57,25 +57,25 @@ class OpusFrame : public AudioDecoder::EncodedAudioFrame {
|
||||
}
|
||||
|
||||
private:
|
||||
AudioDecoderOpus* const decoder_;
|
||||
AudioDecoderOpusImpl* const decoder_;
|
||||
const rtc::Buffer payload_;
|
||||
const bool is_primary_payload_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
AudioDecoderOpus::AudioDecoderOpus(size_t num_channels)
|
||||
AudioDecoderOpusImpl::AudioDecoderOpusImpl(size_t num_channels)
|
||||
: channels_(num_channels) {
|
||||
RTC_DCHECK(num_channels == 1 || num_channels == 2);
|
||||
WebRtcOpus_DecoderCreate(&dec_state_, channels_);
|
||||
WebRtcOpus_DecoderInit(dec_state_);
|
||||
}
|
||||
|
||||
AudioDecoderOpus::~AudioDecoderOpus() {
|
||||
AudioDecoderOpusImpl::~AudioDecoderOpusImpl() {
|
||||
WebRtcOpus_DecoderFree(dec_state_);
|
||||
}
|
||||
|
||||
std::vector<AudioDecoder::ParseResult> AudioDecoderOpus::ParsePayload(
|
||||
std::vector<AudioDecoder::ParseResult> AudioDecoderOpusImpl::ParsePayload(
|
||||
rtc::Buffer&& payload,
|
||||
uint32_t timestamp) {
|
||||
std::vector<ParseResult> results;
|
||||
@ -95,11 +95,11 @@ std::vector<AudioDecoder::ParseResult> AudioDecoderOpus::ParsePayload(
|
||||
return results;
|
||||
}
|
||||
|
||||
int AudioDecoderOpus::DecodeInternal(const uint8_t* encoded,
|
||||
size_t encoded_len,
|
||||
int sample_rate_hz,
|
||||
int16_t* decoded,
|
||||
SpeechType* speech_type) {
|
||||
int AudioDecoderOpusImpl::DecodeInternal(const uint8_t* encoded,
|
||||
size_t encoded_len,
|
||||
int sample_rate_hz,
|
||||
int16_t* decoded,
|
||||
SpeechType* speech_type) {
|
||||
RTC_DCHECK_EQ(sample_rate_hz, 48000);
|
||||
int16_t temp_type = 1; // Default is speech.
|
||||
int ret =
|
||||
@ -110,11 +110,11 @@ int AudioDecoderOpus::DecodeInternal(const uint8_t* encoded,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int AudioDecoderOpus::DecodeRedundantInternal(const uint8_t* encoded,
|
||||
size_t encoded_len,
|
||||
int sample_rate_hz,
|
||||
int16_t* decoded,
|
||||
SpeechType* speech_type) {
|
||||
int AudioDecoderOpusImpl::DecodeRedundantInternal(const uint8_t* encoded,
|
||||
size_t encoded_len,
|
||||
int sample_rate_hz,
|
||||
int16_t* decoded,
|
||||
SpeechType* speech_type) {
|
||||
if (!PacketHasFec(encoded, encoded_len)) {
|
||||
// This packet is a RED packet.
|
||||
return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded,
|
||||
@ -131,17 +131,17 @@ int AudioDecoderOpus::DecodeRedundantInternal(const uint8_t* encoded,
|
||||
return ret;
|
||||
}
|
||||
|
||||
void AudioDecoderOpus::Reset() {
|
||||
void AudioDecoderOpusImpl::Reset() {
|
||||
WebRtcOpus_DecoderInit(dec_state_);
|
||||
}
|
||||
|
||||
int AudioDecoderOpus::PacketDuration(const uint8_t* encoded,
|
||||
size_t encoded_len) const {
|
||||
int AudioDecoderOpusImpl::PacketDuration(const uint8_t* encoded,
|
||||
size_t encoded_len) const {
|
||||
return WebRtcOpus_DurationEst(dec_state_, encoded, encoded_len);
|
||||
}
|
||||
|
||||
int AudioDecoderOpus::PacketDurationRedundant(const uint8_t* encoded,
|
||||
size_t encoded_len) const {
|
||||
int AudioDecoderOpusImpl::PacketDurationRedundant(const uint8_t* encoded,
|
||||
size_t encoded_len) const {
|
||||
if (!PacketHasFec(encoded, encoded_len)) {
|
||||
// This packet is a RED packet.
|
||||
return PacketDuration(encoded, encoded_len);
|
||||
@ -150,18 +150,18 @@ int AudioDecoderOpus::PacketDurationRedundant(const uint8_t* encoded,
|
||||
return WebRtcOpus_FecDurationEst(encoded, encoded_len);
|
||||
}
|
||||
|
||||
bool AudioDecoderOpus::PacketHasFec(const uint8_t* encoded,
|
||||
size_t encoded_len) const {
|
||||
bool AudioDecoderOpusImpl::PacketHasFec(const uint8_t* encoded,
|
||||
size_t encoded_len) const {
|
||||
int fec;
|
||||
fec = WebRtcOpus_PacketHasFec(encoded, encoded_len);
|
||||
return (fec == 1);
|
||||
}
|
||||
|
||||
int AudioDecoderOpus::SampleRateHz() const {
|
||||
int AudioDecoderOpusImpl::SampleRateHz() const {
|
||||
return 48000;
|
||||
}
|
||||
|
||||
size_t AudioDecoderOpus::Channels() const {
|
||||
size_t AudioDecoderOpusImpl::Channels() const {
|
||||
return channels_;
|
||||
}
|
||||
|
||||
|
||||
@ -17,10 +17,10 @@
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class AudioDecoderOpus final : public AudioDecoder {
|
||||
class AudioDecoderOpusImpl final : public AudioDecoder {
|
||||
public:
|
||||
explicit AudioDecoderOpus(size_t num_channels);
|
||||
~AudioDecoderOpus() override;
|
||||
explicit AudioDecoderOpusImpl(size_t num_channels);
|
||||
~AudioDecoderOpusImpl() override;
|
||||
|
||||
std::vector<ParseResult> ParsePayload(rtc::Buffer&& payload,
|
||||
uint32_t timestamp) override;
|
||||
@ -47,7 +47,7 @@ class AudioDecoderOpus final : public AudioDecoder {
|
||||
private:
|
||||
OpusDecInst* dec_state_;
|
||||
const size_t channels_;
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoderOpus);
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoderOpusImpl);
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
Reference in New Issue
Block a user