AudioEncoder subclass for iSACfix

This patch refactors AudioEncoderDecoderIsac so that it can share
almost all code with the very similar AudioEncoderDecoderIsacFix.

BUG=3926
R=henrik.lundin@webrtc.org, kjellander@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/29259004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7912 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
kwiberg@webrtc.org
2014-12-16 12:49:37 +00:00
parent 0198933b3d
commit 88bdec8c3a
12 changed files with 586 additions and 369 deletions

View File

@ -23,7 +23,7 @@
#include "webrtc/modules/audio_coding/codecs/ilbc/interface/ilbc.h"
#endif
#ifdef WEBRTC_CODEC_ISACFX
#include "webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h"
#include "webrtc/modules/audio_coding/codecs/isac/fix/interface/audio_encoder_isacfix.h"
#endif
#ifdef WEBRTC_CODEC_ISAC
#include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_encoder_isac.h"
@ -127,48 +127,6 @@ int AudioDecoderIlbc::Init() {
}
#endif
// iSAC fix
#ifdef WEBRTC_CODEC_ISACFX
AudioDecoderIsacFix::AudioDecoderIsacFix() {
WebRtcIsacfix_Create(&isac_state_);
}
AudioDecoderIsacFix::~AudioDecoderIsacFix() {
WebRtcIsacfix_Free(isac_state_);
}
int AudioDecoderIsacFix::Decode(const uint8_t* encoded, size_t encoded_len,
int16_t* decoded, SpeechType* speech_type) {
int16_t temp_type = 1; // Default is speech.
int16_t ret = WebRtcIsacfix_Decode(isac_state_,
encoded,
static_cast<int16_t>(encoded_len), decoded,
&temp_type);
*speech_type = ConvertSpeechType(temp_type);
return ret;
}
int AudioDecoderIsacFix::Init() {
return WebRtcIsacfix_DecoderInit(isac_state_);
}
int AudioDecoderIsacFix::IncomingPacket(const uint8_t* payload,
size_t payload_len,
uint16_t rtp_sequence_number,
uint32_t rtp_timestamp,
uint32_t arrival_timestamp) {
return WebRtcIsacfix_UpdateBwEstimate(
isac_state_,
payload,
static_cast<int32_t>(payload_len),
rtp_sequence_number, rtp_timestamp, arrival_timestamp);
}
int AudioDecoderIsacFix::ErrorCode() {
return WebRtcIsacfix_GetErrorCode(isac_state_);
}
#endif
// G.722
#ifdef WEBRTC_CODEC_G722
AudioDecoderG722::AudioDecoderG722() {
@ -485,8 +443,10 @@ AudioDecoder* CreateAudioDecoder(NetEqDecoder codec_type) {
return new AudioDecoderIlbc;
#endif
#if defined(WEBRTC_CODEC_ISACFX)
case kDecoderISAC:
return new AudioDecoderIsacFix;
case kDecoderISAC: {
AudioEncoderDecoderIsacFix::Config config;
return new AudioEncoderDecoderIsacFix(config);
}
#elif defined(WEBRTC_CODEC_ISAC)
case kDecoderISAC: {
AudioEncoderDecoderIsac::Config config;

View File

@ -27,12 +27,6 @@
#ifdef WEBRTC_CODEC_ILBC
#include "webrtc/modules/audio_coding/codecs/ilbc/interface/ilbc.h"
#endif
#ifdef WEBRTC_CODEC_ISACFX
#include "webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h"
#endif
#ifdef WEBRTC_CODEC_ISAC
#include "webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h"
#endif
#ifdef WEBRTC_CODEC_OPUS
#include "webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h"
#endif
@ -130,27 +124,6 @@ class AudioDecoderIlbc : public AudioDecoder {
};
#endif
#ifdef WEBRTC_CODEC_ISACFX
class AudioDecoderIsacFix : public AudioDecoder {
public:
AudioDecoderIsacFix();
virtual ~AudioDecoderIsacFix();
virtual int Decode(const uint8_t* encoded, size_t encoded_len,
int16_t* decoded, SpeechType* speech_type);
virtual int Init();
virtual int IncomingPacket(const uint8_t* payload,
size_t payload_len,
uint16_t rtp_sequence_number,
uint32_t rtp_timestamp,
uint32_t arrival_timestamp);
virtual int ErrorCode();
private:
ISACFIX_MainStruct* isac_state_;
DISALLOW_COPY_AND_ASSIGN(AudioDecoderIsacFix);
};
#endif
#ifdef WEBRTC_CODEC_G722
class AudioDecoderG722 : public AudioDecoder {
public:

View File

@ -20,7 +20,7 @@
#include "webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h"
#include "webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h"
#include "webrtc/modules/audio_coding/codecs/ilbc/interface/audio_encoder_ilbc.h"
#include "webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h"
#include "webrtc/modules/audio_coding/codecs/isac/fix/interface/audio_encoder_isacfix.h"
#include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_encoder_isac.h"
#include "webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h"
#include "webrtc/modules/audio_coding/codecs/pcm16b/include/audio_encoder_pcm16b.h"
@ -388,38 +388,20 @@ class AudioDecoderIsacFixTest : public AudioDecoderTest {
protected:
AudioDecoderIsacFixTest() : AudioDecoderTest() {
codec_input_rate_hz_ = 16000;
input_size_ = 160;
frame_size_ = 480;
data_length_ = 10 * frame_size_;
decoder_ = new AudioDecoderIsacFix;
assert(decoder_);
WebRtcIsacfix_Create(&encoder_);
}
AudioEncoderDecoderIsacFix::Config config;
config.payload_type = payload_type_;
config.sample_rate_hz = codec_input_rate_hz_;
config.frame_size_ms =
1000 * static_cast<int>(frame_size_) / codec_input_rate_hz_;
~AudioDecoderIsacFixTest() {
WebRtcIsacfix_Free(encoder_);
// We need to create separate AudioEncoderDecoderIsacFix objects for
// encoding and decoding, because the test class destructor destroys them
// both.
audio_encoder_.reset(new AudioEncoderDecoderIsacFix(config));
decoder_ = new AudioEncoderDecoderIsacFix(config);
}
virtual void InitEncoder() {
ASSERT_EQ(0, WebRtcIsacfix_EncoderInit(encoder_, 1)); // Fixed mode.
ASSERT_EQ(0,
WebRtcIsacfix_Control(encoder_, 32000, 30)); // 32 kbps, 30 ms.
}
virtual int EncodeFrame(const int16_t* input, size_t input_len_samples,
uint8_t* output) {
// Insert 3 * 10 ms. Expect non-zero output on third call.
EXPECT_EQ(0, WebRtcIsacfix_Encode(encoder_, input, output));
input += input_size_;
EXPECT_EQ(0, WebRtcIsacfix_Encode(encoder_, input, output));
input += input_size_;
int enc_len_bytes = WebRtcIsacfix_Encode(encoder_, input, output);
EXPECT_GT(enc_len_bytes, 0);
return enc_len_bytes;
}
ISACFIX_MainStruct* encoder_;
int input_size_;
};
class AudioDecoderG722Test : public AudioDecoderTest {