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

@ -14,6 +14,7 @@
#include <stdlib.h> // NULL
#include "webrtc/base/constructormagic.h"
#include "webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h"
#include "webrtc/typedefs.h"
namespace webrtc {
@ -63,7 +64,7 @@ class AudioDecoder {
// Used by PacketDuration below. Save the value -1 for errors.
enum { kNotImplemented = -2 };
AudioDecoder() : channels_(1), state_(NULL) {}
AudioDecoder() : channels_(1) {}
virtual ~AudioDecoder() {}
// Decodes |encode_len| bytes from |encoded| and writes the result in
@ -114,8 +115,9 @@ class AudioDecoder {
// Returns true if the packet has FEC and false otherwise.
virtual bool PacketHasFec(const uint8_t* encoded, size_t encoded_len) const;
// Returns the underlying decoder state.
void* state() { return state_; }
// If this is a CNG decoder, return the underlying CNG_dec_inst*. If this
// isn't a CNG decoder, don't call this method.
virtual CNG_dec_inst* CngDecoderInstance();
// Returns true if |codec_type| is supported.
static bool CodecSupported(NetEqDecoder codec_type);
@ -134,7 +136,6 @@ class AudioDecoder {
static SpeechType ConvertSpeechType(int16_t type);
size_t channels_;
void* state_;
private:
DISALLOW_COPY_AND_ASSIGN(AudioDecoder);