Refactoring of audio_coding_module_impl

First patch set: pure formatting.

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@2125 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
tina.legrand@webrtc.org
2012-04-26 08:53:45 +00:00
parent a6ecd1ebb5
commit bc1b43b297
2 changed files with 2177 additions and 2654 deletions

View File

@@ -24,383 +24,323 @@ class ACMGenericCodec;
class CriticalSectionWrapper; class CriticalSectionWrapper;
class RWLockWrapper; class RWLockWrapper;
//#define TIMED_LOGGING
#ifdef TIMED_LOGGING
#include "../test/timedtrace.h"
#endif
#ifdef ACM_QA_TEST #ifdef ACM_QA_TEST
# include <stdio.h> # include <stdio.h>
#endif #endif
class AudioCodingModuleImpl : public AudioCodingModule class AudioCodingModuleImpl : public AudioCodingModule {
{ public:
public: // Constructor
// constructor AudioCodingModuleImpl(const WebRtc_Word32 id);
AudioCodingModuleImpl(
const WebRtc_Word32 id);
// destructor // Destructor
~AudioCodingModuleImpl(); ~AudioCodingModuleImpl();
// get version information for ACM and all components // Change the unique identifier of this object.
WebRtc_Word32 Version( virtual WebRtc_Word32 ChangeUniqueId(const WebRtc_Word32 id);
char* version,
WebRtc_UWord32& remainingBufferInBytes,
WebRtc_UWord32& position) const;
// change the unique identifier of this object
virtual WebRtc_Word32 ChangeUniqueId(
const WebRtc_Word32 id);
// returns the number of milliseconds until the module want
// a worker thread to call Process
WebRtc_Word32 TimeUntilNextProcess();
// Process any pending tasks such as timeouts
WebRtc_Word32 Process();
// used in conference to go to and from active encoding, hence // Returns the number of milliseconds until the module want a worker thread
// in and out of mix // to call Process.
WebRtc_Word32 SetMode( WebRtc_Word32 TimeUntilNextProcess();
const bool passive);
// Process any pending tasks such as timeouts.
WebRtc_Word32 Process();
/////////////////////////////////////////
// Sender
//
///////////////////////////////////////// // Initialize send codec.
// Sender WebRtc_Word32 InitializeSender();
//
// initialize send codec // Reset send codec.
WebRtc_Word32 InitializeSender(); WebRtc_Word32 ResetEncoder();
// reset send codec // Can be called multiple times for Codec, CNG, RED.
WebRtc_Word32 ResetEncoder(); WebRtc_Word32 RegisterSendCodec(const CodecInst& send_codec);
// can be called multiple times for Codec, CNG, RED // Get current send codec.
WebRtc_Word32 RegisterSendCodec( WebRtc_Word32 SendCodec(CodecInst& current_codec) const;
const CodecInst& sendCodec);
// get current send codec // Get current send frequency.
WebRtc_Word32 SendCodec( WebRtc_Word32 SendFrequency() const;
CodecInst& currentSendCodec) const;
// get current send freq // Get encode bitrate.
WebRtc_Word32 SendFrequency() const; // Adaptive rate codecs return their current encode target rate, while other
// codecs return there longterm avarage or their fixed rate.
WebRtc_Word32 SendBitrate() const;
// Get encode bitrate // Set available bandwidth, inform the encoder about the
// Adaptive rate codecs return their current encode target rate, while other codecs // estimated bandwidth received from the remote party.
// return there longterm avarage or their fixed rate. virtual WebRtc_Word32 SetReceivedEstimatedBandwidth(const WebRtc_Word32 bw);
WebRtc_Word32 SendBitrate() const;
// set available bandwidth, inform the encoder about the // Register a transport callback which will be
// estimated bandwidth received from the remote party // called to deliver the encoded buffers.
virtual WebRtc_Word32 SetReceivedEstimatedBandwidth( WebRtc_Word32 RegisterTransportCallback(
const WebRtc_Word32 bw); AudioPacketizationCallback* transport);
// register a transport callback which will be // Used by the module to deliver messages to the codec module/application
// called to deliver the encoded buffers // AVT(DTMF).
WebRtc_Word32 RegisterTransportCallback( WebRtc_Word32 RegisterIncomingMessagesCallback(
AudioPacketizationCallback* transport); AudioCodingFeedback* incoming_message, const ACMCountries cpt);
// Used by the module to deliver messages to the codec module/application // Add 10MS of raw (PCM) audio data to the encoder.
// AVT(DTMF) WebRtc_Word32 Add10MsData(const AudioFrame& audio_frame);
WebRtc_Word32 RegisterIncomingMessagesCallback(
AudioCodingFeedback* incomingMessagesCallback,
const ACMCountries cpt);
// Add 10MS of raw (PCM) audio data to the encoder // Set background noise mode for NetEQ, on, off or fade.
WebRtc_Word32 Add10MsData( WebRtc_Word32 SetBackgroundNoiseMode(const ACMBackgroundNoiseMode mode);
const AudioFrame& audioFrame);
// set background noise mode for NetEQ, on, off or fade
WebRtc_Word32 SetBackgroundNoiseMode(
const ACMBackgroundNoiseMode mode);
// get current background noise mode
WebRtc_Word32 BackgroundNoiseMode(
ACMBackgroundNoiseMode& mode);
///////////////////////////////////////// // Get current background noise mode.
// (FEC) Forward Error Correction WebRtc_Word32 BackgroundNoiseMode(ACMBackgroundNoiseMode& mode);
//
// configure FEC status i.e on/off /////////////////////////////////////////
WebRtc_Word32 SetFECStatus( // (FEC) Forward Error Correction
const bool enable); //
// Get FEC status
bool FECStatus() const;
///////////////////////////////////////// // Configure FEC status i.e on/off.
// (VAD) Voice Activity Detection WebRtc_Word32 SetFECStatus(const bool enable_fec);
// and
// (CNG) Comfort Noise Generation
//
WebRtc_Word32 SetVAD( // Get FEC status.
const bool enableDTX = true, bool FECStatus() const;
const bool enableVAD = false,
const ACMVADMode vadMode = VADNormal);
WebRtc_Word32 VAD( /////////////////////////////////////////
bool& dtxEnabled, // (VAD) Voice Activity Detection
bool& vadEnabled, // and
ACMVADMode& vadMode) const; // (CNG) Comfort Noise Generation
//
WebRtc_Word32 RegisterVADCallback( WebRtc_Word32 SetVAD(const bool enable_dtx = true,
ACMVADCallback* vadCallback); const bool enable_vad = false,
const ACMVADMode mode = VADNormal);
// Get VAD aggressiveness on the incoming stream WebRtc_Word32 VAD(bool& dtx_enabled, bool& vad_enabled,
ACMVADMode ReceiveVADMode() const; ACMVADMode& mode) const;
// Configure VAD aggressiveness on the incoming stream WebRtc_Word32 RegisterVADCallback(ACMVADCallback* vadCallback);
WebRtc_Word16 SetReceiveVADMode(
const ACMVADMode mode);
// Get VAD aggressiveness on the incoming stream.
ACMVADMode ReceiveVADMode() const;
///////////////////////////////////////// // Configure VAD aggressiveness on the incoming stream.
// Receiver WebRtc_Word16 SetReceiveVADMode(const ACMVADMode mode);
//
// initialize receiver, resets codec database etc /////////////////////////////////////////
WebRtc_Word32 InitializeReceiver(); // Receiver
//
// reset the decoder state // Initialize receiver, resets codec database etc.
WebRtc_Word32 ResetDecoder(); WebRtc_Word32 InitializeReceiver();
// get current receive freq // Reset the decoder state.
WebRtc_Word32 ReceiveFrequency() const; WebRtc_Word32 ResetDecoder();
// get current playout freq // Get current receive frequency.
WebRtc_Word32 PlayoutFrequency() const; WebRtc_Word32 ReceiveFrequency() const;
// register possible reveive codecs, can be called multiple times, // Get current playout frequency.
// for codecs, CNG, DTMF, RED WebRtc_Word32 PlayoutFrequency() const;
WebRtc_Word32 RegisterReceiveCodec(
const CodecInst& receiveCodec);
// get current received codec // Register possible reveive codecs, can be called multiple times,
WebRtc_Word32 ReceiveCodec( // for codecs, CNG, DTMF, RED.
CodecInst& currentReceiveCodec) const; WebRtc_Word32 RegisterReceiveCodec(const CodecInst& receive_codec);
// incoming packet from network parsed and ready for decode // Get current received codec.
WebRtc_Word32 IncomingPacket( WebRtc_Word32 ReceiveCodec(CodecInst& current_codec) const;
const WebRtc_UWord8* incomingPayload,
const WebRtc_Word32 payloadLength,
const WebRtcRTPHeader& rtpInfo);
// Incoming payloads, without rtp-info, the rtp-info will be created in ACM. // Incoming packet from network parsed and ready for decode.
// One usage for this API is when pre-encoded files are pushed in ACM. WebRtc_Word32 IncomingPacket(const WebRtc_UWord8* incoming_payload,
WebRtc_Word32 IncomingPayload( const WebRtc_Word32 payload_length,
const WebRtc_UWord8* incomingPayload, const WebRtcRTPHeader& rtp_info);
const WebRtc_Word32 payloadLength,
const WebRtc_UWord8 payloadType,
const WebRtc_UWord32 timestamp = 0);
// Minimum playout dealy (Used for lip-sync) // Incoming payloads, without rtp-info, the rtp-info will be created in ACM.
WebRtc_Word32 SetMinimumPlayoutDelay( // One usage for this API is when pre-encoded files are pushed in ACM.
const WebRtc_Word32 timeMs); WebRtc_Word32 IncomingPayload(const WebRtc_UWord8* incoming_payload,
const WebRtc_Word32 payload_length,
const WebRtc_UWord8 payload_type,
const WebRtc_UWord32 timestamp = 0);
// configure Dtmf playout status i.e on/off playout the incoming outband Dtmf tone // Minimum playout dealy (used for lip-sync).
WebRtc_Word32 SetDtmfPlayoutStatus( WebRtc_Word32 SetMinimumPlayoutDelay(const WebRtc_Word32 time_ms);
const bool enable);
// Get Dtmf playout status // Configure Dtmf playout status i.e on/off playout the incoming outband Dtmf
bool DtmfPlayoutStatus() const; // tone.
WebRtc_Word32 SetDtmfPlayoutStatus(const bool enable);
// Estimate the Bandwidth based on the incoming stream // Get Dtmf playout status.
// This is also done in the RTP module bool DtmfPlayoutStatus() const;
// need this for one way audio where the RTCP send the BW estimate
WebRtc_Word32 DecoderEstimatedBandwidth() const;
// Set playout mode voice, fax // Estimate the Bandwidth based on the incoming stream, needed
WebRtc_Word32 SetPlayoutMode( // for one way audio where the RTCP send the BW estimate.
const AudioPlayoutMode mode); // This is also done in the RTP module .
WebRtc_Word32 DecoderEstimatedBandwidth() const;
// Get playout mode voice, fax // Set playout mode voice, fax.
AudioPlayoutMode PlayoutMode() const; WebRtc_Word32 SetPlayoutMode(const AudioPlayoutMode mode);
// Get playout timestamp // Get playout mode voice, fax.
WebRtc_Word32 PlayoutTimestamp( AudioPlayoutMode PlayoutMode() const;
WebRtc_UWord32& timestamp);
// Get 10 milliseconds of raw audio data to play out // Get playout timestamp.
// automatic resample to the requested frequency if > 0 WebRtc_Word32 PlayoutTimestamp(WebRtc_UWord32& timestamp);
WebRtc_Word32 PlayoutData10Ms(
const WebRtc_Word32 desiredFreqHz,
AudioFrame &audioFrame);
// Get 10 milliseconds of raw audio data to play out, and
// automatic resample to the requested frequency if > 0.
WebRtc_Word32 PlayoutData10Ms(const WebRtc_Word32 desired_freq_hz,
AudioFrame &audio_frame);
///////////////////////////////////////// /////////////////////////////////////////
// Statistics // Statistics
// //
WebRtc_Word32 NetworkStatistics( WebRtc_Word32 NetworkStatistics(ACMNetworkStatistics& statistics) const;
ACMNetworkStatistics& statistics) const;
void DestructEncoderInst(void* ptrInst); void DestructEncoderInst(void* inst);
WebRtc_Word16 AudioBuffer(WebRtcACMAudioBuff& audioBuff); WebRtc_Word16 AudioBuffer(WebRtcACMAudioBuff& buffer);
// GET RED payload for iSAC. The method id called // GET RED payload for iSAC. The method id called when 'this' ACM is
// when 'this' ACM is default ACM. // the default ACM.
WebRtc_Word32 REDPayloadISAC( WebRtc_Word32 REDPayloadISAC(const WebRtc_Word32 isac_rate,
const WebRtc_Word32 isacRate, const WebRtc_Word16 isac_bw_estimate,
const WebRtc_Word16 isacBwEstimate, WebRtc_UWord8* payload,
WebRtc_UWord8* payload, WebRtc_Word16* length_bytes);
WebRtc_Word16* payloadLenByte);
WebRtc_Word16 SetAudioBuffer(WebRtcACMAudioBuff& buffer);
WebRtc_Word16 SetAudioBuffer(WebRtcACMAudioBuff& audioBuff);
WebRtc_UWord32 EarliestTimestamp() const;
WebRtc_UWord32 EarliestTimestamp() const;
WebRtc_Word32 LastEncodedTimestamp(WebRtc_UWord32& timestamp) const;
WebRtc_Word32 LastEncodedTimestamp(WebRtc_UWord32& timestamp) const;
WebRtc_Word32 ReplaceInternalDTXWithWebRtc(const bool use_webrtc_dtx);
WebRtc_Word32 ReplaceInternalDTXWithWebRtc(
const bool useWebRtcDTX); WebRtc_Word32 IsInternalDTXReplacedWithWebRtc(bool& uses_webrtc_dtx);
WebRtc_Word32 IsInternalDTXReplacedWithWebRtc( WebRtc_Word32 SetISACMaxRate(const WebRtc_UWord32 max_bit_per_sec);
bool& usesWebRtcDTX);
WebRtc_Word32 SetISACMaxPayloadSize(const WebRtc_UWord16 max_size_bytes);
WebRtc_Word32 SetISACMaxRate(
const WebRtc_UWord32 rateBitPerSec); WebRtc_Word32 ConfigISACBandwidthEstimator(
const WebRtc_UWord8 frame_size_ms,
WebRtc_Word32 SetISACMaxPayloadSize( const WebRtc_UWord16 rate_bit_per_sec,
const WebRtc_UWord16 payloadLenBytes); const bool enforce_frame_size = false);
WebRtc_Word32 ConfigISACBandwidthEstimator( WebRtc_Word32 UnregisterReceiveCodec(const WebRtc_Word16 payload_type);
const WebRtc_UWord8 initFrameSizeMsec,
const WebRtc_UWord16 initRateBitPerSec, protected:
const bool enforceFrameSize = false); void UnregisterSendCodec();
WebRtc_Word32 UnregisterReceiveCodec( WebRtc_Word32 UnregisterReceiveCodecSafe(const WebRtc_Word16 id);
const WebRtc_Word16 payloadType);
ACMGenericCodec* CreateCodec(const CodecInst& codec);
protected:
void UnregisterSendCodec(); WebRtc_Word16 DecoderParamByPlType(const WebRtc_UWord8 payload_type,
WebRtcACMCodecParams& codec_params) const;
WebRtc_Word32 UnregisterReceiveCodecSafe(
const WebRtc_Word16 codecID); WebRtc_Word16 DecoderListIDByPlName(
const char* name, const WebRtc_UWord16 frequency = 0) const;
ACMGenericCodec* CreateCodec(
const CodecInst& codec); WebRtc_Word32 InitializeReceiverSafe();
WebRtc_Word16 DecoderParamByPlType( bool HaveValidEncoder(const char* caller_name) const;
const WebRtc_UWord8 payloadType,
WebRtcACMCodecParams& codecParams) const; WebRtc_Word32 RegisterRecCodecMSSafe(const CodecInst& receive_codec,
WebRtc_Word16 codec_id,
WebRtc_Word16 DecoderListIDByPlName( WebRtc_Word16 mirror_id,
const char* payloadName, ACMNetEQ::JB jitter_buffer);
const WebRtc_UWord16 sampFreqHz = 0) const;
private:
WebRtc_Word32 InitializeReceiverSafe(); // Change required states after starting to receive the codec corresponding
// to |index|.
bool HaveValidEncoder(const char* callerName) const; int UpdateUponReceivingCodec(int index);
WebRtc_Word32 RegisterRecCodecMSSafe( // Remove all slaves and initialize a stereo slave with required codecs
const CodecInst& receiveCodec, // from the master.
WebRtc_Word16 codecId, int InitStereoSlave();
WebRtc_Word16 mirrorId,
ACMNetEQ::JB jitterBuffer); // Returns true if the codec's |index| is registered with the master and
// is a stereo codec, RED or CN.
private: bool IsCodecForSlave(int index);
// Change required states after starting to receive the codec corresponding
// to |index|. // Returns true if the |codec| is RED.
int UpdateUponReceivingCodec(int index); bool IsCodecRED(CodecInst codec);
// ...or if its |index| is RED.
// Remove all slaves and initialize a stereo slave with required codecs bool IsCodecRED(int index);
// from the master.
int InitStereoSlave(); // Returns true if the |codec| is CN.
bool IsCodecCN(int index);
// Returns true if the codec's |index| is registered with the master and // ...or if its |index| is CN.
// is a stereo codec, RED or CN. bool IsCodecCN(CodecInst codec);
bool IsCodecForSlave(int index);
AudioPacketizationCallback* _packetizationCallback;
// Returns true if the |codec| is RED. WebRtc_Word32 _id;
bool IsCodecRED(CodecInst codec); WebRtc_UWord32 _lastTimestamp;
// ...or if its |index| is RED. WebRtc_UWord32 _lastInTimestamp;
bool IsCodecRED(int index); CodecInst _sendCodecInst;
uint8_t _cng_nb_pltype;
// Returns true if the |codec| is CN. uint8_t _cng_wb_pltype;
bool IsCodecCN(int index); uint8_t _cng_swb_pltype;
// ...or if its |index| is CN. uint8_t _red_pltype;
bool IsCodecCN(CodecInst codec); bool _vadEnabled;
bool _dtxEnabled;
AudioPacketizationCallback* _packetizationCallback; ACMVADMode _vadMode;
WebRtc_Word32 _id; ACMGenericCodec* _codecs[ACMCodecDB::kMaxNumCodecs];
WebRtc_UWord32 _lastTimestamp; ACMGenericCodec* _slaveCodecs[ACMCodecDB::kMaxNumCodecs];
WebRtc_UWord32 _lastInTimestamp; WebRtc_Word16 _mirrorCodecIdx[ACMCodecDB::kMaxNumCodecs];
CodecInst _sendCodecInst; bool _stereoReceive[ACMCodecDB::kMaxNumCodecs];
uint8_t _cng_nb_pltype; bool _stereoReceiveRegistered;
uint8_t _cng_wb_pltype; bool _stereoSend;
uint8_t _cng_swb_pltype; int _prev_received_channel;
uint8_t _red_pltype; int _expected_channels;
bool _vadEnabled; WebRtc_Word32 _currentSendCodecIdx;
bool _dtxEnabled; int _current_receive_codec_idx;
ACMVADMode _vadMode; bool _sendCodecRegistered;
ACMGenericCodec* _codecs[ACMCodecDB::kMaxNumCodecs]; ACMResampler _inputResampler;
ACMGenericCodec* _slaveCodecs[ACMCodecDB::kMaxNumCodecs]; ACMResampler _outputResampler;
WebRtc_Word16 _mirrorCodecIdx[ACMCodecDB::kMaxNumCodecs]; ACMNetEQ _netEq;
bool _stereoReceive[ACMCodecDB::kMaxNumCodecs]; CriticalSectionWrapper* _acmCritSect;
bool _stereoReceiveRegistered; ACMVADCallback* _vadCallback;
bool _stereoSend; WebRtc_UWord8 _lastRecvAudioCodecPlType;
int _prev_received_channel;
int _expected_channels; // RED/FEC.
WebRtc_Word32 _currentSendCodecIdx; bool _isFirstRED;
int _current_receive_codec_idx; bool _fecEnabled;
bool _sendCodecRegistered; WebRtc_UWord8* _redBuffer;
ACMResampler _inputResampler; RTPFragmentationHeader* _fragmentation;
ACMResampler _outputResampler; WebRtc_UWord32 _lastFECTimestamp;
ACMNetEQ _netEq; // If no RED is registered as receive codec this
CriticalSectionWrapper* _acmCritSect; // will have an invalid value.
ACMVADCallback* _vadCallback; WebRtc_UWord8 _receiveREDPayloadType;
WebRtc_UWord8 _lastRecvAudioCodecPlType;
// This is to keep track of CN instances where we can send DTMFs.
// RED/FEC WebRtc_UWord8 _previousPayloadType;
bool _isFirstRED;
bool _fecEnabled; // This keeps track of payload types associated with _codecs[].
WebRtc_UWord8* _redBuffer; // We define it as signed variable and initialize with -1 to indicate
RTPFragmentationHeader* _fragmentation; // unused elements.
WebRtc_UWord32 _lastFECTimestamp; WebRtc_Word16 _registeredPlTypes[ACMCodecDB::kMaxNumCodecs];
// if no RED is registered as receive codec this
// will have an invalid value. // Used when payloads are pushed into ACM without any RTP info
WebRtc_UWord8 _receiveREDPayloadType; // One example is when pre-encoded bit-stream is pushed from
// a file.
// This is to keep track of CN instances where we can send DTMFs WebRtcRTPHeader* _dummyRTPHeader;
WebRtc_UWord8 _previousPayloadType; WebRtc_UWord16 _recvPlFrameSizeSmpls;
// This keeps track of payload types associated with _codecs[]. bool _receiverInitialized;
// We define it as signed variable and initialize with -1 to indicate ACMDTMFDetection* _dtmfDetector;
// unused elements.
WebRtc_Word16 _registeredPlTypes[ACMCodecDB::kMaxNumCodecs]; AudioCodingFeedback* _dtmfCallback;
WebRtc_Word16 _lastDetectedTone;
// Used when payloads are pushed into ACM without any RTP info CriticalSectionWrapper* _callbackCritSect;
// One example is when pre-encoded bit-stream is pushed from
// a file. AudioFrame _audioFrame;
WebRtcRTPHeader* _dummyRTPHeader;
WebRtc_UWord16 _recvPlFrameSizeSmpls;
bool _receiverInitialized;
ACMDTMFDetection* _dtmfDetector;
AudioCodingFeedback* _dtmfCallback;
WebRtc_Word16 _lastDetectedTone;
CriticalSectionWrapper* _callbackCritSect;
#ifdef TIMED_LOGGING
TimedTrace _trace;
#endif
AudioFrame _audioFrame;
#ifdef ACM_QA_TEST #ifdef ACM_QA_TEST
FILE* _outgoingPL; FILE* _outgoingPL;
FILE* _incomingPL; FILE* _incomingPL;
#endif #endif
}; };
} // namespace webrtc } // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_AUDIO_CODING_MODULE_IMPL_H_ #endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_AUDIO_CODING_MODULE_IMPL_H_