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:
@ -23,8 +23,10 @@ namespace webrtc {
|
||||
rtc::Optional<AudioDecoderG722::Config> AudioDecoderG722::SdpToConfig(
|
||||
const SdpAudioFormat& format) {
|
||||
return STR_CASE_CMP(format.name.c_str(), "g722") == 0 &&
|
||||
format.clockrate_hz == 8000
|
||||
? rtc::Optional<Config>(Config())
|
||||
format.clockrate_hz == 8000 &&
|
||||
(format.num_channels == 1 || format.num_channels == 2)
|
||||
? rtc::Optional<Config>(
|
||||
Config{rtc::dchecked_cast<int>(format.num_channels)})
|
||||
: rtc::Optional<Config>();
|
||||
}
|
||||
|
||||
@ -35,7 +37,14 @@ void AudioDecoderG722::AppendSupportedDecoders(
|
||||
|
||||
std::unique_ptr<AudioDecoder> AudioDecoderG722::MakeAudioDecoder(
|
||||
Config config) {
|
||||
switch (config.num_channels) {
|
||||
case 1:
|
||||
return rtc::MakeUnique<AudioDecoderG722Impl>();
|
||||
case 2:
|
||||
return rtc::MakeUnique<AudioDecoderG722StereoImpl>();
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -25,7 +25,10 @@ namespace webrtc {
|
||||
//
|
||||
// NOTE: This struct is still under development and may change without notice.
|
||||
struct AudioDecoderG722 {
|
||||
struct Config {}; // Empty---no config values needed!
|
||||
struct Config {
|
||||
bool IsOk() const { return num_channels == 1 || num_channels == 2; }
|
||||
int num_channels;
|
||||
};
|
||||
static rtc::Optional<Config> SdpToConfig(const SdpAudioFormat& audio_format);
|
||||
static void AppendSupportedDecoders(std::vector<AudioCodecSpec>* specs);
|
||||
static std::unique_ptr<AudioDecoder> MakeAudioDecoder(Config config);
|
||||
|
||||
@ -119,9 +119,16 @@ TEST(AudioDecoderFactoryTemplateTest, G722) {
|
||||
EXPECT_FALSE(factory->IsSupportedDecoder({"foo", 8000, 1}));
|
||||
EXPECT_TRUE(factory->IsSupportedDecoder({"g722", 8000, 1}));
|
||||
EXPECT_EQ(nullptr, factory->MakeAudioDecoder({"bar", 16000, 1}));
|
||||
auto dec = factory->MakeAudioDecoder({"g722", 8000, 1});
|
||||
ASSERT_NE(nullptr, dec);
|
||||
EXPECT_EQ(16000, dec->SampleRateHz());
|
||||
auto dec1 = factory->MakeAudioDecoder({"g722", 8000, 1});
|
||||
ASSERT_NE(nullptr, dec1);
|
||||
EXPECT_EQ(16000, dec1->SampleRateHz());
|
||||
EXPECT_EQ(1u, dec1->Channels());
|
||||
auto dec2 = factory->MakeAudioDecoder({"g722", 8000, 2});
|
||||
ASSERT_NE(nullptr, dec2);
|
||||
EXPECT_EQ(16000, dec2->SampleRateHz());
|
||||
EXPECT_EQ(2u, dec2->Channels());
|
||||
auto dec3 = factory->MakeAudioDecoder({"g722", 8000, 3});
|
||||
ASSERT_EQ(nullptr, dec3);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -69,19 +69,19 @@ 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,
|
||||
int AudioDecoderG722StereoImpl::DecodeInternal(const uint8_t* encoded,
|
||||
size_t encoded_len,
|
||||
int sample_rate_hz,
|
||||
int16_t* decoded,
|
||||
@ -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,7 +134,8 @@ 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,
|
||||
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| ...,
|
||||
|
||||
@ -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
|
||||
|
||||
@ -418,7 +418,7 @@ class AudioDecoderG722StereoTest : public AudioDecoderTest {
|
||||
codec_input_rate_hz_ = 16000;
|
||||
frame_size_ = 160;
|
||||
data_length_ = 10 * frame_size_;
|
||||
decoder_ = new AudioDecoderG722Stereo;
|
||||
decoder_ = new AudioDecoderG722StereoImpl;
|
||||
assert(decoder_);
|
||||
AudioEncoderG722Config config;
|
||||
config.frame_size_ms = 10;
|
||||
|
||||
Reference in New Issue
Block a user