Remove the state_ member from AudioDecoder

The subclasses that need a state pointer should declare them---with
the right type, not void*, to get rid of all those casts.

Two small but not quite trivial cleanups are included because they
blocked the state_ removal:

  - AudioDecoderG722Stereo now inherits directly from AudioDecoder
    instead of being a subclass of AudioDecoderG722.

  - AudioDecoder now has a CngDecoderInstance member function, which
    is implemented only by AudioDecoderCng. This replaces the previous
    practice of calling AudioDecoder::state() and casting the result
    to a CNG_dec_inst*. It still isn't pretty, but now the blemish is
    plainly visible in the AudioDecoder class declaration.

R=henrik.lundin@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7644 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
kwiberg@webrtc.org
2014-11-06 07:54:31 +00:00
parent 32022c6fb1
commit 8b2058e733
7 changed files with 86 additions and 68 deletions

View File

@ -19,6 +19,22 @@
#include "webrtc/engine_configurations.h"
#endif
#include "webrtc/base/constructormagic.h"
#include "webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h"
#ifdef WEBRTC_CODEC_G722
#include "webrtc/modules/audio_coding/codecs/g722/include/g722_interface.h"
#endif
#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
#include "webrtc/modules/audio_coding/neteq/interface/audio_decoder.h"
#include "webrtc/typedefs.h"
@ -109,6 +125,7 @@ class AudioDecoderIlbc : public AudioDecoder {
virtual int Init();
private:
iLBC_decinst_t* dec_state_;
DISALLOW_COPY_AND_ASSIGN(AudioDecoderIlbc);
};
#endif
@ -133,6 +150,7 @@ class AudioDecoderIsac : public AudioDecoder {
virtual int ErrorCode();
private:
ISACStruct* isac_state_;
DISALLOW_COPY_AND_ASSIGN(AudioDecoderIsac);
};
#endif
@ -153,6 +171,7 @@ class AudioDecoderIsacFix : public AudioDecoder {
virtual int ErrorCode();
private:
ISACFIX_MainStruct* isac_state_;
DISALLOW_COPY_AND_ASSIGN(AudioDecoderIsacFix);
};
#endif
@ -169,10 +188,11 @@ class AudioDecoderG722 : public AudioDecoder {
virtual int PacketDuration(const uint8_t* encoded, size_t encoded_len);
private:
G722DecInst* dec_state_;
DISALLOW_COPY_AND_ASSIGN(AudioDecoderG722);
};
class AudioDecoderG722Stereo : public AudioDecoderG722 {
class AudioDecoderG722Stereo : public AudioDecoder {
public:
AudioDecoderG722Stereo();
virtual ~AudioDecoderG722Stereo();
@ -189,8 +209,8 @@ class AudioDecoderG722Stereo : public AudioDecoderG722 {
void SplitStereoPacket(const uint8_t* encoded, size_t encoded_len,
uint8_t* encoded_deinterleaved);
void* const state_left_;
void* state_right_;
G722DecInst* dec_state_left_;
G722DecInst* dec_state_right_;
DISALLOW_COPY_AND_ASSIGN(AudioDecoderG722Stereo);
};
@ -229,6 +249,7 @@ class AudioDecoderOpus : public AudioDecoder {
virtual bool PacketHasFec(const uint8_t* encoded, size_t encoded_len) const;
private:
OpusDecInst* dec_state_;
DISALLOW_COPY_AND_ASSIGN(AudioDecoderOpus);
};
#endif
@ -252,7 +273,10 @@ class AudioDecoderCng : public AudioDecoder {
uint32_t rtp_timestamp,
uint32_t arrival_timestamp) { return -1; }
virtual CNG_dec_inst* CngDecoderInstance() OVERRIDE { return dec_state_; }
private:
CNG_dec_inst* dec_state_;
DISALLOW_COPY_AND_ASSIGN(AudioDecoderCng);
};