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,113 +24,83 @@ 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( AudioCodingModuleImpl(const WebRtc_Word32 id);
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 // Returns the number of milliseconds until the module want a worker thread
virtual WebRtc_Word32 ChangeUniqueId( // to call Process.
const WebRtc_Word32 id);
// returns the number of milliseconds until the module want
// a worker thread to call Process
WebRtc_Word32 TimeUntilNextProcess(); WebRtc_Word32 TimeUntilNextProcess();
// Process any pending tasks such as timeouts // Process any pending tasks such as timeouts.
WebRtc_Word32 Process(); WebRtc_Word32 Process();
// used in conference to go to and from active encoding, hence
// in and out of mix
WebRtc_Word32 SetMode(
const bool passive);
///////////////////////////////////////// /////////////////////////////////////////
// Sender // Sender
// //
// initialize send codec // Initialize send codec.
WebRtc_Word32 InitializeSender(); WebRtc_Word32 InitializeSender();
// reset send codec // Reset send codec.
WebRtc_Word32 ResetEncoder(); WebRtc_Word32 ResetEncoder();
// can be called multiple times for Codec, CNG, RED // Can be called multiple times for Codec, CNG, RED.
WebRtc_Word32 RegisterSendCodec( WebRtc_Word32 RegisterSendCodec(const CodecInst& send_codec);
const CodecInst& sendCodec);
// get current send codec // Get current send codec.
WebRtc_Word32 SendCodec( WebRtc_Word32 SendCodec(CodecInst& current_codec) const;
CodecInst& currentSendCodec) const;
// get current send freq // Get current send frequency.
WebRtc_Word32 SendFrequency() const; WebRtc_Word32 SendFrequency() const;
// Get encode bitrate // Get encode bitrate.
// Adaptive rate codecs return their current encode target rate, while other codecs // Adaptive rate codecs return their current encode target rate, while other
// return there longterm avarage or their fixed rate. // codecs return there longterm avarage or their fixed rate.
WebRtc_Word32 SendBitrate() const; WebRtc_Word32 SendBitrate() const;
// set available bandwidth, inform the encoder about the // Set available bandwidth, inform the encoder about the
// estimated bandwidth received from the remote party // estimated bandwidth received from the remote party.
virtual WebRtc_Word32 SetReceivedEstimatedBandwidth( virtual WebRtc_Word32 SetReceivedEstimatedBandwidth(const WebRtc_Word32 bw);
const WebRtc_Word32 bw);
// register a transport callback which will be // Register a transport callback which will be
// called to deliver the encoded buffers // called to deliver the encoded buffers.
WebRtc_Word32 RegisterTransportCallback( WebRtc_Word32 RegisterTransportCallback(
AudioPacketizationCallback* transport); AudioPacketizationCallback* transport);
// Used by the module to deliver messages to the codec module/application // Used by the module to deliver messages to the codec module/application
// AVT(DTMF) // AVT(DTMF).
WebRtc_Word32 RegisterIncomingMessagesCallback( WebRtc_Word32 RegisterIncomingMessagesCallback(
AudioCodingFeedback* incomingMessagesCallback, AudioCodingFeedback* incoming_message, const ACMCountries cpt);
const ACMCountries cpt);
// Add 10MS of raw (PCM) audio data to the encoder // Add 10MS of raw (PCM) audio data to the encoder.
WebRtc_Word32 Add10MsData( WebRtc_Word32 Add10MsData(const AudioFrame& audio_frame);
const AudioFrame& audioFrame);
// set background noise mode for NetEQ, on, off or fade // Set background noise mode for NetEQ, on, off or fade.
WebRtc_Word32 SetBackgroundNoiseMode( WebRtc_Word32 SetBackgroundNoiseMode(const ACMBackgroundNoiseMode mode);
const ACMBackgroundNoiseMode mode);
// get current background noise mode // Get current background noise mode.
WebRtc_Word32 BackgroundNoiseMode( WebRtc_Word32 BackgroundNoiseMode(ACMBackgroundNoiseMode& mode);
ACMBackgroundNoiseMode& mode);
///////////////////////////////////////// /////////////////////////////////////////
// (FEC) Forward Error Correction // (FEC) Forward Error Correction
// //
// configure FEC status i.e on/off // Configure FEC status i.e on/off.
WebRtc_Word32 SetFECStatus( WebRtc_Word32 SetFECStatus(const bool enable_fec);
const bool enable);
// Get FEC status // Get FEC status.
bool FECStatus() const; bool FECStatus() const;
///////////////////////////////////////// /////////////////////////////////////////
@@ -139,171 +109,144 @@ public:
// (CNG) Comfort Noise Generation // (CNG) Comfort Noise Generation
// //
WebRtc_Word32 SetVAD( WebRtc_Word32 SetVAD(const bool enable_dtx = true,
const bool enableDTX = true, const bool enable_vad = false,
const bool enableVAD = false, const ACMVADMode mode = VADNormal);
const ACMVADMode vadMode = VADNormal);
WebRtc_Word32 VAD( WebRtc_Word32 VAD(bool& dtx_enabled, bool& vad_enabled,
bool& dtxEnabled, ACMVADMode& mode) const;
bool& vadEnabled,
ACMVADMode& vadMode) const;
WebRtc_Word32 RegisterVADCallback( WebRtc_Word32 RegisterVADCallback(ACMVADCallback* vadCallback);
ACMVADCallback* vadCallback);
// Get VAD aggressiveness on the incoming stream // Get VAD aggressiveness on the incoming stream.
ACMVADMode ReceiveVADMode() const; ACMVADMode ReceiveVADMode() const;
// Configure VAD aggressiveness on the incoming stream // Configure VAD aggressiveness on the incoming stream.
WebRtc_Word16 SetReceiveVADMode( WebRtc_Word16 SetReceiveVADMode(const ACMVADMode mode);
const ACMVADMode mode);
///////////////////////////////////////// /////////////////////////////////////////
// Receiver // Receiver
// //
// initialize receiver, resets codec database etc // Initialize receiver, resets codec database etc.
WebRtc_Word32 InitializeReceiver(); WebRtc_Word32 InitializeReceiver();
// reset the decoder state // Reset the decoder state.
WebRtc_Word32 ResetDecoder(); WebRtc_Word32 ResetDecoder();
// get current receive freq // Get current receive frequency.
WebRtc_Word32 ReceiveFrequency() const; WebRtc_Word32 ReceiveFrequency() const;
// get current playout freq // Get current playout frequency.
WebRtc_Word32 PlayoutFrequency() const; WebRtc_Word32 PlayoutFrequency() const;
// register possible reveive codecs, can be called multiple times, // Register possible reveive codecs, can be called multiple times,
// for codecs, CNG, DTMF, RED // for codecs, CNG, DTMF, RED.
WebRtc_Word32 RegisterReceiveCodec( WebRtc_Word32 RegisterReceiveCodec(const CodecInst& receive_codec);
const CodecInst& receiveCodec);
// get current received codec // Get current received codec.
WebRtc_Word32 ReceiveCodec( WebRtc_Word32 ReceiveCodec(CodecInst& current_codec) const;
CodecInst& currentReceiveCodec) const;
// incoming packet from network parsed and ready for decode // Incoming packet from network parsed and ready for decode.
WebRtc_Word32 IncomingPacket( WebRtc_Word32 IncomingPacket(const WebRtc_UWord8* incoming_payload,
const WebRtc_UWord8* incomingPayload, const WebRtc_Word32 payload_length,
const WebRtc_Word32 payloadLength, const WebRtcRTPHeader& rtp_info);
const WebRtcRTPHeader& rtpInfo);
// Incoming payloads, without rtp-info, the rtp-info will be created in ACM. // Incoming payloads, without rtp-info, the rtp-info will be created in ACM.
// One usage for this API is when pre-encoded files are pushed in ACM. // One usage for this API is when pre-encoded files are pushed in ACM.
WebRtc_Word32 IncomingPayload( WebRtc_Word32 IncomingPayload(const WebRtc_UWord8* incoming_payload,
const WebRtc_UWord8* incomingPayload, const WebRtc_Word32 payload_length,
const WebRtc_Word32 payloadLength, const WebRtc_UWord8 payload_type,
const WebRtc_UWord8 payloadType,
const WebRtc_UWord32 timestamp = 0); const WebRtc_UWord32 timestamp = 0);
// Minimum playout dealy (Used for lip-sync) // Minimum playout dealy (used for lip-sync).
WebRtc_Word32 SetMinimumPlayoutDelay( WebRtc_Word32 SetMinimumPlayoutDelay(const WebRtc_Word32 time_ms);
const WebRtc_Word32 timeMs);
// configure Dtmf playout status i.e on/off playout the incoming outband Dtmf tone // Configure Dtmf playout status i.e on/off playout the incoming outband Dtmf
WebRtc_Word32 SetDtmfPlayoutStatus( // tone.
const bool enable); WebRtc_Word32 SetDtmfPlayoutStatus(const bool enable);
// Get Dtmf playout status // Get Dtmf playout status.
bool DtmfPlayoutStatus() const; bool DtmfPlayoutStatus() const;
// Estimate the Bandwidth based on the incoming stream // Estimate the Bandwidth based on the incoming stream, needed
// This is also done in the RTP module // for one way audio where the RTCP send the BW estimate.
// need this for one way audio where the RTCP send the BW estimate // This is also done in the RTP module .
WebRtc_Word32 DecoderEstimatedBandwidth() const; WebRtc_Word32 DecoderEstimatedBandwidth() const;
// Set playout mode voice, fax // Set playout mode voice, fax.
WebRtc_Word32 SetPlayoutMode( WebRtc_Word32 SetPlayoutMode(const AudioPlayoutMode mode);
const AudioPlayoutMode mode);
// Get playout mode voice, fax // Get playout mode voice, fax.
AudioPlayoutMode PlayoutMode() const; AudioPlayoutMode PlayoutMode() const;
// Get playout timestamp // Get playout timestamp.
WebRtc_Word32 PlayoutTimestamp( WebRtc_Word32 PlayoutTimestamp(WebRtc_UWord32& timestamp);
WebRtc_UWord32& timestamp);
// Get 10 milliseconds of raw audio data to play out
// automatic resample to the requested frequency if > 0
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* payloadLenByte); WebRtc_Word16* length_bytes);
WebRtc_Word16 SetAudioBuffer(WebRtcACMAudioBuff& audioBuff); WebRtc_Word16 SetAudioBuffer(WebRtcACMAudioBuff& buffer);
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( WebRtc_Word32 ReplaceInternalDTXWithWebRtc(const bool use_webrtc_dtx);
const bool useWebRtcDTX);
WebRtc_Word32 IsInternalDTXReplacedWithWebRtc( WebRtc_Word32 IsInternalDTXReplacedWithWebRtc(bool& uses_webrtc_dtx);
bool& usesWebRtcDTX);
WebRtc_Word32 SetISACMaxRate( WebRtc_Word32 SetISACMaxRate(const WebRtc_UWord32 max_bit_per_sec);
const WebRtc_UWord32 rateBitPerSec);
WebRtc_Word32 SetISACMaxPayloadSize( WebRtc_Word32 SetISACMaxPayloadSize(const WebRtc_UWord16 max_size_bytes);
const WebRtc_UWord16 payloadLenBytes);
WebRtc_Word32 ConfigISACBandwidthEstimator( WebRtc_Word32 ConfigISACBandwidthEstimator(
const WebRtc_UWord8 initFrameSizeMsec, const WebRtc_UWord8 frame_size_ms,
const WebRtc_UWord16 initRateBitPerSec, const WebRtc_UWord16 rate_bit_per_sec,
const bool enforceFrameSize = false); const bool enforce_frame_size = false);
WebRtc_Word32 UnregisterReceiveCodec( WebRtc_Word32 UnregisterReceiveCodec(const WebRtc_Word16 payload_type);
const WebRtc_Word16 payloadType);
protected: protected:
void UnregisterSendCodec(); void UnregisterSendCodec();
WebRtc_Word32 UnregisterReceiveCodecSafe( WebRtc_Word32 UnregisterReceiveCodecSafe(const WebRtc_Word16 id);
const WebRtc_Word16 codecID);
ACMGenericCodec* CreateCodec( ACMGenericCodec* CreateCodec(const CodecInst& codec);
const CodecInst& codec);
WebRtc_Word16 DecoderParamByPlType( WebRtc_Word16 DecoderParamByPlType(const WebRtc_UWord8 payload_type,
const WebRtc_UWord8 payloadType, WebRtcACMCodecParams& codec_params) const;
WebRtcACMCodecParams& codecParams) const;
WebRtc_Word16 DecoderListIDByPlName( WebRtc_Word16 DecoderListIDByPlName(
const char* payloadName, const char* name, const WebRtc_UWord16 frequency = 0) const;
const WebRtc_UWord16 sampFreqHz = 0) const;
WebRtc_Word32 InitializeReceiverSafe(); WebRtc_Word32 InitializeReceiverSafe();
bool HaveValidEncoder(const char* callerName) const; bool HaveValidEncoder(const char* caller_name) const;
WebRtc_Word32 RegisterRecCodecMSSafe( WebRtc_Word32 RegisterRecCodecMSSafe(const CodecInst& receive_codec,
const CodecInst& receiveCodec, WebRtc_Word16 codec_id,
WebRtc_Word16 codecId, WebRtc_Word16 mirror_id,
WebRtc_Word16 mirrorId, ACMNetEQ::JB jitter_buffer);
ACMNetEQ::JB jitterBuffer);
private: private:
// Change required states after starting to receive the codec corresponding // Change required states after starting to receive the codec corresponding
@@ -358,17 +301,17 @@ private:
ACMVADCallback* _vadCallback; ACMVADCallback* _vadCallback;
WebRtc_UWord8 _lastRecvAudioCodecPlType; WebRtc_UWord8 _lastRecvAudioCodecPlType;
// RED/FEC // RED/FEC.
bool _isFirstRED; bool _isFirstRED;
bool _fecEnabled; bool _fecEnabled;
WebRtc_UWord8* _redBuffer; WebRtc_UWord8* _redBuffer;
RTPFragmentationHeader* _fragmentation; RTPFragmentationHeader* _fragmentation;
WebRtc_UWord32 _lastFECTimestamp; WebRtc_UWord32 _lastFECTimestamp;
// if no RED is registered as receive codec this // If no RED is registered as receive codec this
// will have an invalid value. // will have an invalid value.
WebRtc_UWord8 _receiveREDPayloadType; WebRtc_UWord8 _receiveREDPayloadType;
// This is to keep track of CN instances where we can send DTMFs // This is to keep track of CN instances where we can send DTMFs.
WebRtc_UWord8 _previousPayloadType; WebRtc_UWord8 _previousPayloadType;
// This keeps track of payload types associated with _codecs[]. // This keeps track of payload types associated with _codecs[].
@@ -388,9 +331,6 @@ private:
AudioCodingFeedback* _dtmfCallback; AudioCodingFeedback* _dtmfCallback;
WebRtc_Word16 _lastDetectedTone; WebRtc_Word16 _lastDetectedTone;
CriticalSectionWrapper* _callbackCritSect; CriticalSectionWrapper* _callbackCritSect;
#ifdef TIMED_LOGGING
TimedTrace _trace;
#endif
AudioFrame _audioFrame; AudioFrame _audioFrame;