Don't forget to support G722 stereo decoding

https://codereview.webrtc.org/2940833002 added support for G722
decoding with the AudioDecoderFactoryTemplate API, but forgot to
support stereo.

BUG=webrtc:7839

Review-Url: https://codereview.webrtc.org/2945423003
Cr-Commit-Position: refs/heads/master@{#18761}
This commit is contained in:
kwiberg
2017-06-26 04:19:43 -07:00
committed by Commit Bot
parent 2f45b6b15f
commit 1b97e26364
7 changed files with 47 additions and 27 deletions

View File

@ -135,7 +135,7 @@ NamedDecoderConstructor decoder_constructors[] = {
return true;
} else if (format.num_channels == 2) {
if (out) {
out->reset(new AudioDecoderG722Stereo);
out->reset(new AudioDecoderG722StereoImpl);
}
return true;
}

View File

@ -69,23 +69,23 @@ size_t AudioDecoderG722Impl::Channels() const {
return 1;
}
AudioDecoderG722Stereo::AudioDecoderG722Stereo() {
AudioDecoderG722StereoImpl::AudioDecoderG722StereoImpl() {
WebRtcG722_CreateDecoder(&dec_state_left_);
WebRtcG722_CreateDecoder(&dec_state_right_);
WebRtcG722_DecoderInit(dec_state_left_);
WebRtcG722_DecoderInit(dec_state_right_);
}
AudioDecoderG722Stereo::~AudioDecoderG722Stereo() {
AudioDecoderG722StereoImpl::~AudioDecoderG722StereoImpl() {
WebRtcG722_FreeDecoder(dec_state_left_);
WebRtcG722_FreeDecoder(dec_state_right_);
}
int AudioDecoderG722Stereo::DecodeInternal(const uint8_t* encoded,
size_t encoded_len,
int sample_rate_hz,
int16_t* decoded,
SpeechType* speech_type) {
int AudioDecoderG722StereoImpl::DecodeInternal(const uint8_t* encoded,
size_t encoded_len,
int sample_rate_hz,
int16_t* decoded,
SpeechType* speech_type) {
RTC_DCHECK_EQ(SampleRateHz(), sample_rate_hz);
int16_t temp_type = 1; // Default is speech.
// De-interleave the bit-stream into two separate payloads.
@ -112,20 +112,20 @@ int AudioDecoderG722Stereo::DecodeInternal(const uint8_t* encoded,
return static_cast<int>(ret);
}
int AudioDecoderG722Stereo::SampleRateHz() const {
int AudioDecoderG722StereoImpl::SampleRateHz() const {
return 16000;
}
size_t AudioDecoderG722Stereo::Channels() const {
size_t AudioDecoderG722StereoImpl::Channels() const {
return 2;
}
void AudioDecoderG722Stereo::Reset() {
void AudioDecoderG722StereoImpl::Reset() {
WebRtcG722_DecoderInit(dec_state_left_);
WebRtcG722_DecoderInit(dec_state_right_);
}
std::vector<AudioDecoder::ParseResult> AudioDecoderG722Stereo::ParsePayload(
std::vector<AudioDecoder::ParseResult> AudioDecoderG722StereoImpl::ParsePayload(
rtc::Buffer&& payload,
uint32_t timestamp) {
return LegacyEncodedAudioFrame::SplitBySamples(this, std::move(payload),
@ -134,9 +134,10 @@ std::vector<AudioDecoder::ParseResult> AudioDecoderG722Stereo::ParsePayload(
// Split the stereo packet and place left and right channel after each other
// in the output array.
void AudioDecoderG722Stereo::SplitStereoPacket(const uint8_t* encoded,
size_t encoded_len,
uint8_t* encoded_deinterleaved) {
void AudioDecoderG722StereoImpl::SplitStereoPacket(
const uint8_t* encoded,
size_t encoded_len,
uint8_t* encoded_deinterleaved) {
// Regroup the 4 bits/sample so |l1 l2| |r1 r2| |l3 l4| |r3 r4| ...,
// where "lx" is 4 bits representing left sample number x, and "rx" right
// sample. Two samples fit in one byte, represented with |...|.

View File

@ -42,10 +42,10 @@ class AudioDecoderG722Impl final : public AudioDecoder {
RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoderG722Impl);
};
class AudioDecoderG722Stereo final : public AudioDecoder {
class AudioDecoderG722StereoImpl final : public AudioDecoder {
public:
AudioDecoderG722Stereo();
~AudioDecoderG722Stereo() override;
AudioDecoderG722StereoImpl();
~AudioDecoderG722StereoImpl() override;
void Reset() override;
std::vector<ParseResult> ParsePayload(rtc::Buffer&& payload,
uint32_t timestamp) override;
@ -71,7 +71,7 @@ class AudioDecoderG722Stereo final : public AudioDecoder {
G722DecInst* dec_state_left_;
G722DecInst* dec_state_right_;
RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoderG722Stereo);
RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoderG722StereoImpl);
};
} // namespace webrtc