diff --git a/src/modules/audio_coding/main/interface/audio_coding_module.h b/src/modules/audio_coding/main/interface/audio_coding_module.h index 7164e2999..b4b9cc96b 100644 --- a/src/modules/audio_coding/main/interface/audio_coding_module.h +++ b/src/modules/audio_coding/main/interface/audio_coding_module.h @@ -8,1069 +8,981 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef AUDIO_CODING_MODULE_H -#define AUDIO_CODING_MODULE_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_INTERFACE_AUDIO_CODING_MODULE_H +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_INTERFACE_AUDIO_CODING_MODULE_H -#include "module.h" #include "audio_coding_module_typedefs.h" +#include "module.h" #include "module_common_types.h" - -namespace webrtc -{ +namespace webrtc { // forward declarations struct CodecInst; - #define WEBRTC_10MS_PCM_AUDIO 960 // 16 bits super wideband 48 Khz - // Callback class used for sending data ready to be packetized -class AudioPacketizationCallback -{ -public: - virtual ~AudioPacketizationCallback() {} - - virtual WebRtc_Word32 SendData( - FrameType frameType, - WebRtc_UWord8 payloadType, - WebRtc_UWord32 timeStamp, - const WebRtc_UWord8* payloadData, - WebRtc_UWord16 payloadSize, - const RTPFragmentationHeader* fragmentation) = 0; +class AudioPacketizationCallback { + public: + virtual ~AudioPacketizationCallback() {} + + virtual WebRtc_Word32 SendData( + FrameType frameType, WebRtc_UWord8 payloadType, WebRtc_UWord32 timeStamp, + const WebRtc_UWord8* payloadData, WebRtc_UWord16 payloadSize, + const RTPFragmentationHeader* fragmentation) = 0; }; // Callback class used for inband Dtmf detection -class AudioCodingFeedback -{ -public: - virtual ~AudioCodingFeedback() {} +class AudioCodingFeedback { + public: + virtual ~AudioCodingFeedback() {} - virtual WebRtc_Word32 IncomingDtmf( - const WebRtc_UWord8 digitDtmf, - const bool end) = 0; + virtual WebRtc_Word32 IncomingDtmf(const WebRtc_UWord8 digitDtmf, + const bool end) = 0; }; // Callback class used for reporting VAD decision -class ACMVADCallback -{ -public: - virtual ~ACMVADCallback() {} - virtual WebRtc_Word32 InFrameType( - WebRtc_Word16 frameType) = 0; +class ACMVADCallback { + public: + virtual ~ACMVADCallback() {} + + virtual WebRtc_Word32 InFrameType(WebRtc_Word16 frameType) = 0; }; // Callback class used for reporting receiver statistics -class ACMVQMonCallback -{ -public: - virtual ~ACMVQMonCallback() {} +class ACMVQMonCallback { + public: + virtual ~ACMVQMonCallback() {} - virtual WebRtc_Word32 NetEqStatistics( - const WebRtc_Word32 id, // current ACM id - const WebRtc_UWord16 MIUsValid, // valid voice duration in ms - const WebRtc_UWord16 MIUsReplaced, // concealed voice duration in ms - const WebRtc_UWord8 eventFlags, // concealed voice flags - const WebRtc_UWord16 delayMS) = 0; // average delay in ms + virtual WebRtc_Word32 NetEqStatistics( + const WebRtc_Word32 id, // current ACM id + const WebRtc_UWord16 MIUsValid, // valid voice duration in ms + const WebRtc_UWord16 MIUsReplaced, // concealed voice duration in ms + const WebRtc_UWord8 eventFlags, // concealed voice flags + const WebRtc_UWord16 delayMS) = 0; // average delay in ms }; -class AudioCodingModule: public Module -{ -protected: - AudioCodingModule(){} - virtual ~AudioCodingModule(){} - -public: - /////////////////////////////////////////////////////////////////////////// - // Creation and destruction of a ACM - // - static AudioCodingModule* Create( - const WebRtc_Word32 id); - - static void Destroy( - AudioCodingModule* module); - - /////////////////////////////////////////////////////////////////////////// - // Utility functions - // - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 GetVersion() - // Returns version of the module and its components. - // - // Outputs: - // -version : a buffer that the version string is stored. - // -remainBuffBytes : remaining size of the buffer "version" in - // bytes, excluding terminating-null. - // -position : the first character of the ACM version will - // written to version[position] and so on. - // - // Return value: - // -1 if failed to write the whole version string, - // 0 if succeeded. - // - static WebRtc_Word32 GetVersion( - WebRtc_Word8* version, - WebRtc_UWord32& remainBuffBytes, - WebRtc_UWord32& position); - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_UWord8 NumberOfCodecs() - // Returns number of supported codecs. - // - // Return value: - // number of supported codecs. - /// - static WebRtc_UWord8 NumberOfCodecs(); - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 Codec() - // Get supported codec with list number. - // - // Input: - // -listId : list number. - // - // Output: - // -codec : a structure where the parameters of the codec, - // given by list number is written to. - // - // Return value: - // -1 if the list number (listId) is invalid. - // 0 if succeeded. - // - static WebRtc_Word32 Codec( - const WebRtc_UWord8 listId, - CodecInst& codec); - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 Codec() - // Get supported codec with the given codec name and sampling frequency. - // If the sampling frequency is -1 then the search will be only based on - // codec name. - // - // Input: - // -payloadName : name of the codec. - // -samplingFreqHz : samling frequency of the codec. - // - // Output: - // -codec : a structure where the parameters of the codec, - // given by name is written to. - // - // Return value: - // -1 if the list number (listId) is invalid. - // 0 if succeeded. - // - static WebRtc_Word32 Codec( - const WebRtc_Word8* payloadName, - CodecInst& codec, - const WebRtc_Word32 samplingFreqHz = -1); - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 Codec() - // - // Returns the list number of the given codec name and sampling frequency. - // If the sampling frequency is -1 then the search will be only based on - // codec name. - // - // Input: - // -payloadName : name of the codec. - // -samplingFreqHz : samling frequency of the codec. - // - // Return value: - // if the codec is found, the index of the codec in the list, - // -1 if the codec is not found. - // - static WebRtc_Word32 Codec( - const WebRtc_Word8* payloadName, - const WebRtc_Word32 samplingFreqHz = -1); - - - /////////////////////////////////////////////////////////////////////////// - // bool IsCodecValid() - // Checks the validity of the parameters of the given codec. - // - // Input: - // -codec : the structur which keeps the parameters of the - // codec. - // - // Reurn value: - // true if the parameters are valid, - // false if any parameter is not valid. - // - static bool IsCodecValid(const CodecInst& codec); - - /////////////////////////////////////////////////////////////////////////// - // Sender - // - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 InitializeSender() - // Any encoder-related state of ACM will be initialized to the - // same state when ACM is created. This will not interrupt or - // effect decoding functionality of ACM. ACM will lose all the - // encoding-related settings by calling this function. - // For instance, a send codec has to be registered again. - // - // Return value: - // -1 if failed to initialize, - // 0 if succeeded. - // - virtual WebRtc_Word32 InitializeSender() = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 ResetEncoder() - // This API resets the states of encoder. All the encoder settings, such as - // send-codec or VAD/DTX, will be preserved. - // - // Return value: - // -1 if failed to initialize, - // 0 if succeeded. - // - virtual WebRtc_Word32 ResetEncoder() = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 RegisterSendCodec() - // Registers a codec, specified by "sendCodec," as sending codec. - // This API can be called multiple of times to register Codec. The last codec - // registered overwrites the previous ones. - // The API can also be used to change payload type for CNG and RED, which are - // registered by default to default payload types. - // Note that registering CNG and RED won't overwrite speech codecs. - // This API can be called to set/change the send payload-type, frame-size - // or encoding rate (if applicable for the codec). - // - // Input: - // -sendCodec : Parameters of the codec to be registered, c.f. - // common_types.h for the definition of - // CodecInst. - // - // Return value: - // -1 if failed to initialize, - // 0 if succeeded. - // - virtual WebRtc_Word32 RegisterSendCodec( - const CodecInst& sendCodec) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 SendCodec() - // Get parameters for the codec currently registered as send codec. - // - // Output: - // -currentSendCodec : parameters of the send codec. - // - // Return value: - // -1 if failed to get send codec, - // 0 if succeeded. - // - virtual WebRtc_Word32 SendCodec( - CodecInst& currentSendCodec) const = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 SendFrequency() - // Get the sampling frequency of the current encoder in Hertz. - // - // Return value: - // positive; sampling frequency [Hz] of the current encoder. - // -1 if an error has happened. - // - virtual WebRtc_Word32 SendFrequency() const = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 Bitrate() - // Get encoding bit-rate in bits per second. - // - // Return value: - // positive; encoding rate in bits/sec, - // -1 if an error is happened. - // - virtual WebRtc_Word32 SendBitrate() const = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 SetReceivedEstimatedBandwidth() - // Set available bandwidth [bits/sec] of the up-link channel. - // This information is used for traffic shaping, and is currently only - // supported if iSAC is the send codec. - // - // Input: - // -bw : bandwidth in bits/sec estimated for - // up-link. - // Return value - // -1 if error occurred in setting the bandwidth, - // 0 bandwidth is set successfully. - // - virtual WebRtc_Word32 SetReceivedEstimatedBandwidth( - const WebRtc_Word32 bw) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 RegisterTransportCallback() - // Register a transport callback which will be called to deliver - // the encoded buffers whenever Process() is called and a - // bit-stream is ready. - // - // Input: - // -transport : pointer to the callback class - // transport->SendData() is called whenever - // Process() is called and bit-stream is ready - // to deliver. - // - // Return value: - // -1 if the transport callback could not be registered - // 0 if registration is successful. - // - virtual WebRtc_Word32 RegisterTransportCallback( - AudioPacketizationCallback* transport) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 Add10MsData() - // Add 10MS of raw (PCM) audio data to the encoder. If the sampling - // frequency of the audio does not match the sampling frequency of the - // current encoder ACM will resample the audio. - // - // Input: - // -audioFrame : the input audio frame, containing raw audio - // sampling frequency etc., - // c.f. module_common_types.h for definition of - // AudioFrame. - // - // Return value: - // 0 successfully added the frame. - // -1 some error occurred and data is not added. - // < -1 to add the frame to the buffer n samples had to be - // overwritten, -n is the return value in this case. - // - virtual WebRtc_Word32 Add10MsData( - const AudioFrame& audioFrame) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // (FEC) Forward Error Correction - // - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 SetFECStatus(const bool enable) - // configure FEC status i.e. on/off. - // - // RFC 2198 describes a solution which has a single payload type which - // signifies a packet with redundancy. That packet then becomes a container, - // encapsulating multiple payloads into a single RTP packet. - // Such a scheme is flexible, since any amount of redundancy may be - // encapsulated within a single packet. There is, however, a small overhead - // since each encapsulated payload must be preceded by a header indicating - // the type of data enclosed. - // - // This means that FEC is actually a RED scheme. - // - // Input: - // -enableFEC : if true FEC is enabled, otherwise FEC is - // disabled. - // - // Return value: - // -1 if failed to set FEC status, - // 0 if succeeded. - // - virtual WebRtc_Word32 SetFECStatus( - const bool enableFEC) = 0; - - /////////////////////////////////////////////////////////////////////////// - // bool FECStatus() - // Get FEC status - // - // Return value - // true if FEC is enabled, - // false if FEC is disabled. - // - virtual bool FECStatus() const = 0; - - - /////////////////////////////////////////////////////////////////////////// - // (VAD) Voice Activity Detection - // - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 SetVAD() - // If DTX is enabled & the codec does not have internal DTX/VAD - // WebRtc VAD will be automatically enabled and 'enableVAD' is ignored. - // - // If DTX is disabled but VAD is enabled no DTX packets are send, - // regardless of whether the codec has internal DTX/VAD or not. In this - // case, WebRtc VAD is running to label frames as active/in-active. - // - // Inputs: - // -enableDTX : if true DTX is enabled, - // otherwise DTX is disabled. - // -enableVAD : if true VAD is enabled, - // otherwise VAD is disabled. - // -vadMode : determines the aggressiveness of VAD. A more - // aggressive mode results in more frames labeled - // as in-active, c.f. definition of - // ACMVADMode in audio_coding_module_typedefs.h - // for valid values. - // - // Return value: - // -1 if failed to set up VAD/DTX, - // 0 if succeeded. - // - virtual WebRtc_Word32 SetVAD( - const bool enableDTX = true, - const bool enableVAD = false, - const ACMVADMode vadMode = VADNormal) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 VAD() - // Get VAD status. - // - // Outputs: - // -dtxEnabled : is set to true if DTX is enabled, otherwise - // is set to false. - // -vadEnabled : is set to true if VAD is enabled, otherwise - // is set to false. - // -vadMode : is set to the current aggressiveness of VAD. - // - // Return value: - // -1 if fails to retrieve the setting of DTX/VAD, - // 0 if succeeeded. - // - virtual WebRtc_Word32 VAD( - bool& dtxEnabled, - bool& vadEnabled, - ACMVADMode& vadMode) const = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 ReplaceInternalDTXWithWebRtc() - // Used to replace codec internal DTX scheme with WebRtc. This is only - // supported for G729, where this call replaces AnnexB with WebRtc DTX. - // - // Input: - // -useWebRtcDTX : if false (default) the codec built-in DTX/VAD - // scheme is used, otherwise the internal DTX is - // replaced with WebRtc DTX/VAD. - // - // Return value: - // -1 if failed to replace codec internal DTX with WebRtc, - // 0 if succeeded. - // - virtual WebRtc_Word32 ReplaceInternalDTXWithWebRtc( - const bool useWebRtcDTX = false) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 IsInternalDTXReplacedWithWebRtc() - // Get status if the codec internal DTX (when such exists) is replaced with - // WebRtc DTX. This is only supported for G729. - // - // Output: - // -usesWebRtcDTX : is set to true if the codec internal DTX is - // replaced with WebRtc DTX/VAD, otherwise it is set - // to false. - // - // Return value: - // -1 if failed to determine if codec internal DTX is replaced with WebRtc, - // 0 if succeeded. - // - virtual WebRtc_Word32 IsInternalDTXReplacedWithWebRtc( - bool& usesWebRtcDTX) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 RegisterVADCallback() - // Call this method to register a callback function which is called - // any time that ACM encounters an empty frame. That is a frame which is - // recognized inactive. Depending on the codec WebRtc VAD or internal codec - // VAD is employed to identify a frame as active/inactive. - // - // Input: - // -vadCallback : pointer to a callback function. - // - // Return value: - // -1 if failed to register the callback function. - // 0 if the callback function is registered successfully. - // - virtual WebRtc_Word32 RegisterVADCallback( - ACMVADCallback* vadCallback) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // Receiver - // - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 InitializeReceiver() - // Any decoder-related state of ACM will be initialized to the - // same state when ACM is created. This will not interrupt or - // effect encoding functionality of ACM. ACM would lose all the - // decoding-related settings by calling this function. - // For instance, all registered codecs are deleted and have to be - // registered again. - // - // Return value: - // -1 if failed to initialize, - // 0 if succeeded. - // - virtual WebRtc_Word32 InitializeReceiver() = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 ResetDecoder() - // This API resets the states of decoders. ACM will not lose any - // decoder-related settings, such as registered codecs. - // - // Return value: - // -1 if failed to initialize, - // 0 if succeeded. - // - virtual WebRtc_Word32 ResetDecoder() = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 ReceiveFrequency() - // Get sampling frequency of the last received payload. - // - // Return value: - // non-negative the sampling frequency in Hertz. - // -1 if an error has occurred. - // - virtual WebRtc_Word32 ReceiveFrequency() const = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 PlayoutFrequency() - // Get sampling frequency of audio played out. - // - // Return value: - // the sampling frequency in Hertz. - // - virtual WebRtc_Word32 PlayoutFrequency() const = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 RegisterReceiveCodec() - // Register possible decoders, can be called multiple times for - // codecs, CNG-NB, CNG-WB, CNG-SWB, AVT and RED. - // - // Input: - // -receiveCodec : parameters of the codec to be registered, c.f. - // common_types.h for the definition of - // CodecInst. - // - // Return value: - // -1 if failed to register the codec - // 0 if the codec registered successfully. - // - virtual WebRtc_Word32 RegisterReceiveCodec( - const CodecInst& receiveCodec) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 UnregisterReceiveCodec() - // Unregister the codec currently registered with a specific payload type - // from the list of possible receive codecs. - // - // Input: - // -payloadType : The number representing the payload type to - // unregister. - // - // Output: - // -1 if the unregistration fails. - // 0 if the given codec is successfully unregistered. - // - virtual WebRtc_Word32 UnregisterReceiveCodec( - const WebRtc_Word16 receiveCodec) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 ReceiveCodec() - // Get the codec associated with last received payload. - // - // Output: - // -currRcvCodec : parameters of the codec associated with the last - // received payload, c.f. common_types.h for - // the definition of CodecInst. - // - // Return value: - // -1 if failed to retrieve the codec, - // 0 if the codec is successfully retrieved. - // - virtual WebRtc_Word32 ReceiveCodec( - CodecInst& currRcvCodec) const = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 IncomingPacket() - // Call this function to insert a parsed RTP packet into ACM. - // - // Inputs: - // -incomingPayload : received payload. - // -payloadLengthByte : the length of payload in bytes. - // -rtpInfo : the relevant information retrieved from RTP - // header. - // - // Return value: - // -1 if failed to push in the payload - // 0 if payload is successfully pushed in. - // - virtual WebRtc_Word32 IncomingPacket( - const WebRtc_Word8* incomingPayload, - const WebRtc_Word32 payloadLengthByte, - const WebRtcRTPHeader& rtpInfo) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 IncomingPayload() - // Call this API to push incoming payloads when there is no rtp-info. - // The rtp-info will be created in ACM. One usage for this API is when - // pre-encoded files are pushed in ACM - // - // Inputs: - // -incomingPayload : received payload. - // -payloadLenghtByte : the length, in bytes, of the received payload. - // -payloadType : the payload-type. This specifies which codec has - // to be used to decode the payload. - // -timestamp : send timestamp of the payload. ACM starts with - // a random value and increment it by the - // packet-size, which is given when the codec in - // question is registered by RegisterReceiveCodec(). - // Therefore, it is essential to have the timestamp - // if the frame-size differ from the registered - // value or if the incoming payload contains DTX - // packets. - // - // Return value: - // -1 if failed to push in the payload - // 0 if payload is successfully pushed in. - // - virtual WebRtc_Word32 IncomingPayload( - const WebRtc_Word8* incomingPayload, - const WebRtc_Word32 payloadLengthByte, - const WebRtc_UWord8 payloadType, - const WebRtc_UWord32 timestamp = 0) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 SetMinimumPlayoutDelay() - // Set Minimum playout delay, used for lip-sync. - // - // Input: - // -timeMs : minimum delay in milliseconds. - // - // Return value: - // -1 if failed to set the delay, - // 0 if the minimum delay is set. - // - virtual WebRtc_Word32 SetMinimumPlayoutDelay( - const WebRtc_Word32 timeMs) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 Delay() - // Get the current playout delay. - // - // Output: - // - delayInMs : delay in millisecond - // - // Return value: - // -1 if failed to get the delay, - // 0 if succeeded to get the delay. - // - virtual WebRtc_Word32 Delay(WebRtc_UWord16& delayMs) const = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 RegisterIncomingMessagesCallback() - // Used by the module to deliver messages to the codec module/application - // when a Dtmf tone is detected, as well as when it stopped. - // - // Inputs: - // -inMsgCallback : pointer to callback function which will be called - // if Dtmf is detected. - // -cpt : enables CPT (Call Progress Tone) detection for the - // specified country. c.f. definition of ACMCountries - // in audio_coding_module_typedefs.h for valid - // entries. The default value disables CPT - // detection. - // - // Return value: - // -1 if the message callback could not be registered - // 0 if registration is successful. - // - virtual WebRtc_Word32 RegisterIncomingMessagesCallback( - AudioCodingFeedback* inMsgCallback, - const ACMCountries cpt = ACMDisableCountryDetection) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 SetDtmfPlayoutStatus() - // Configure Dtmf playout, i.e. whether out-of-band - // Dtmf tones are played or not. - // - // Input: - // -enable : if true to enable playout out-of-band Dtmf tones, - // false to disable. - // - // Return value: - // -1 if the method fails, e.g. Dtmf playout is not supported. - // 0 if the status is set successfully. - // - virtual WebRtc_Word32 SetDtmfPlayoutStatus(const bool enable) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // bool DtmfPlayoutStatus() - // Get Dtmf playout status. - // - // Return value: - // true if out-of-band Dtmf tones are played, - // false if playout of Dtmf tones is disabled. - // - virtual bool DtmfPlayoutStatus() const = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 SetBackgroundNoiseMode() - // Sets the mode of the background noise playout in an event of long - // packetloss burst. For the valid modes see the declaration of - // ACMBackgroundNoiseMode in audio_coding_module_typedefs.h. - // - // Input: - // -mode : the mode for the background noise playout. - // - // Return value: - // -1 if failed to set the mode. - // 0 if succeeded in setting the mode. - // - virtual WebRtc_Word32 SetBackgroundNoiseMode( - const ACMBackgroundNoiseMode mode) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 BackgroundNoiseMode() - // Call this method to get the mode of the background noise playout. - // Playout of background noise is a result of a long packetloss burst. - // See ACMBackgroundNoiseMode in audio_coding_module_typedefs.h for - // possible modes. - // - // Output: - // -mode : a reference to ACMBackgroundNoiseMode enumerator. - // - // Return value: - // 0 if the output is a valid mode. - // -1 if ACM failed to output a valid mode. - // - virtual WebRtc_Word32 BackgroundNoiseMode( - ACMBackgroundNoiseMode& mode) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 PlayoutTimestamp() - // The send timestamp of an RTP packet is associated with the decoded - // audio of the packet in question. This function returns the timestamp of - // the latest audio obtained by calling PlayoutData10ms(). - // - // Input: - // -timestamp : a reference to a WebRtc_UWord32 to receive the - // timestamp. - // Return value: - // 0 if the output is a correct timestamp. - // -1 if failed to output the correct timestamp. - // - // - virtual WebRtc_Word32 PlayoutTimestamp( - WebRtc_UWord32& timestamp) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 DecoderEstimatedBandwidth() - // Get the estimate of the Bandwidth, in bits/second, based on the incoming - // stream. This API is useful in one-way communication scenarios, where - // the bandwidth information is sent in an out-of-band fashion. - // Currently only supported if iSAC is registered as a reciever. - // - // Return value: - // >0 bandwidth in bits/second. - // -1 if failed to get a bandwidth estimate. - // - virtual WebRtc_Word32 DecoderEstimatedBandwidth() const = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 SetPlayoutMode() - // Call this API to set the playout mode. Playout mode could be optimized - // for i) voice, ii) FAX or iii) streaming. In Voice mode, NetEQ is - // optimized to deliver highest audio quality while maintaining a minimum - // delay. In FAX mode, NetEQ is optimized to have few delay changes as - // possible and maintain a constant delay, perhaps large relative to voice - // mode, to avoid PLC. In streaming mode, we tolerate a little more delay - // to acheive better jitter robustness. - // - // Input: - // -mode : playout mode. Possible inputs are: - // "voice", - // "fax" and - // "streaming". - // - // Return value: - // -1 if failed to set the mode, - // 0 if succeeding. - // - virtual WebRtc_Word32 SetPlayoutMode( - const AudioPlayoutMode mode) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // AudioPlayoutMode PlayoutMode() - // Get playout mode, i.e. whether it is speech, FAX or streaming. See - // audio_coding_module_typedefs.h for definition of AudioPlayoutMode. - // - // Return value: - // voice: is for voice output, - // fax: a mode that is optimized for receiving FAX signals. - // In this mode NetEq tries to maintain a constant high - // delay to avoid PLC if possible. - // streaming: a mode that is suitable for streaminq. In this mode we - // accept longer delay to improve jitter robustness. - // - virtual AudioPlayoutMode PlayoutMode() const = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 PlayoutData10Ms( - // Get 10 milliseconds of raw audio data for playout, at the given sampling - // frequency. ACM will perform a resampling if required. - // - // Input: - // -desiredFreqHz : the desired sampling frequency, in Hertz, of the - // output audio. If set to -1, the function returns the - // audio at the current sampling frequency. - // - // Output: - // -audioFrame : output audio frame which contains raw audio data - // and other relevant parameters, c.f. - // module_common_types.h for the definition of - // AudioFrame. - // - // Return value: - // -1 if the function fails, - // 0 if the function succeeds. - // - virtual WebRtc_Word32 PlayoutData10Ms( - const WebRtc_Word32 desiredFreqHz, - AudioFrame &audioFrame) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // (CNG) Comfort Noise Generation - // Generate comfort noise when receiving DTX packets - // - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word16 SetReceiveVADStatus() - // configure VAD status i.e. on/off on the incoming stream - // Running VAD on decoded audio is desired in some applications, e.g. - // conferencing. - // - // Input: - // -enable : true to enable VAD on incoming stream, and false - // to disable. - // - // Return value: - // -1 if failed to enable/disable VAD, - // 0 if succeded to enable/disable VAD. - // - virtual WebRtc_Word16 SetReceiveVADStatus( - const bool enable) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // bool ReceiveVADStatus() - // Call this API to get whether VAD is enabled on incoming stream or not. - // Running VAD on decoded audio is desired in some applications, e.g. - // conferencing. - // - // Return value: - // true if VAD is enabled on the incoming stream, - // false if VAD is disabled on the incoming stream. - // - virtual bool ReceiveVADStatus() const = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word16 SetReceiveVADMode() - // Configure VAD aggressiveness on the incoming stream. - // - // Input: - // -mode : aggressiveness of the VAD on incoming stream. - // See audio_coding_module_typedefs.h for the - // definition of ACMVADMode, and possible - // values for aggressiveness. - // - // Return value: - // -1 if fails to set the mode, - // 0 if the mode is set successfully. - // - virtual WebRtc_Word16 SetReceiveVADMode( - const ACMVADMode mode) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // ACMVADMode ReceiveVADMode() - // Get VAD aggressiveness on the incoming stream. - // - // Return value: - // aggressiveness of VAD, running on the incoming stream. A more - // aggressive mode means more audio frames will be labeled as in-active. - // See audio_coding_module_typedefs.h for the definition of - // ACMVADMode. - // - virtual ACMVADMode ReceiveVADMode() const = 0; - - /////////////////////////////////////////////////////////////////////////// - // Codec specific - // - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 SetISACMaxRate() - // Set the maximum instantaneous rate of iSAC. For a payload of B bits - // with a frame-size of T sec the instantaneous rate is B/T bist per - // second. Therefore, (B/T < maxRateBitPerSec) and - // (B < maxPayloadLenBytes * 8) are always satisfied for iSAC payloads, - // c.f SetISACMaxPayloadSize(). - // - // Input: - // -maxRateBitPerSec : maximum instantaneous bit-rate given in bits/sec. - // - // Return value: - // -1 if failed to set the maximum rate. - // 0 if the maximum rate is set successfully. - // - virtual WebRtc_Word32 SetISACMaxRate( - const WebRtc_UWord32 maxRateBitPerSec) = 0; - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 SetISACMaxPayloadSize() - // Set the maximum payload size of iSAC packets. No iSAC payload, - // regardless of its frame-size, may exceed the given limit. For - // an iSAC payload of size B bits and frame-size T sec we have; - // (B < maxPayloadLenBytes * 8) and (B/T < maxRateBitPerSec), c.f. - // SetISACMaxRate(). - // - // Input: - // -maxPayloadLenBytes : maximum payload size in bytes. - // - // Return value: - // -1 if failed to set the maximm payload-size. - // 0 if the given linit is seet successfully. - // - virtual WebRtc_Word32 SetISACMaxPayloadSize( - const WebRtc_UWord16 maxPayloadLenBytes) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 ConfigISACBandwidthEstimator() - // Call this function to configure the bandwidth estimator of ISAC. - // During the adaptation of bit-rate, iSAC atomatically adjusts the - // frame-size (either 30 or 60 ms) to save on RTP header. The initial - // frame-size can be specified by the first argument. The configuration also - // regards the initial estimate of bandwidths. The estimator starts from - // this point and converges to the actual bottleneck. This is given by the - // second parameter. Furthermore, it is also possible to control the - // adaptation of frame-size. This is specified by the last parameter. - // - // Input: - // -initFrameSizeMsec : initial frame-size in milisecods. For iSAC-wb - // 30 ms and 60 ms (default) are acceptable values, - // and for iSAC-swb 30 ms is the only acceptable - // value. Zero indiates default value. - // -initRateBitPerSec : initial estimate of the bandwidth. Values - // between 10000 and 58000 are acceptable. - // -enforceFrameSize : if true, the frame-size will not be adapted. - // - // Return value: - // -1 if failed to configure the bandwidth estimator, - // 0 if the configuration was successfully applied. - // - virtual WebRtc_Word32 ConfigISACBandwidthEstimator( - const WebRtc_UWord8 initFrameSizeMsec, - const WebRtc_UWord16 initRateBitPerSec, - const bool enforceFrameSize = false) = 0; - - - /////////////////////////////////////////////////////////////////////////// - // statistics - // - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 NetworkStatistics() - // Get network statistics. - // - // Input: - // -networkStatistics : a structure that contains network statistics. - // - // Return value: - // -1 if failed to set the network statistics, - // 0 if statistics are set successfully. - // - virtual WebRtc_Word32 NetworkStatistics( - ACMNetworkStatistics& networkStatistics) const = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 JitterStatistics() - // Get the jitter statistics. - // - // Input: - // -jitterStatistics : the given jitter statistics. - // - // Return value: - // -1 if failed to set the jitter statistics, - // 0 if jitter statistics are set successfully. - // - virtual WebRtc_Word32 JitterStatistics( - ACMJitterStatistics& jitterStatistics) const = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 PreferredBufferSize() - // Get the optimal buffer size calculated for the current network - // conditions. - // - // Output: - // -prefBuffSize : the optimal size of the jitter buffer in - // milliseconds. - // - // Return value: - // -1 if the preferred buffer size could not be computed, - // 0 if a valid buffer is computed successfully. - // - virtual WebRtc_Word32 PreferredBufferSize( - WebRtc_UWord16& prefBufSize) const = 0; - - - /////////////////////////////////////////////////////////////////////////// - // WebRtc_Word32 ResetJitterStatistics() - // Reset jitter statistics. - // - // Return value: - // -1 if failed to reset the statistics, - // 0 if succeeded. - // - virtual WebRtc_Word32 ResetJitterStatistics() const = 0; +class AudioCodingModule: public Module { + protected: + AudioCodingModule() {} + virtual ~AudioCodingModule() {} + + public: + /////////////////////////////////////////////////////////////////////////// + // Creation and destruction of a ACM + // + static AudioCodingModule* Create(const WebRtc_Word32 id); + + static void Destroy(AudioCodingModule* module); + + /////////////////////////////////////////////////////////////////////////// + // Utility functions + // + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 GetVersion() + // Returns version of the module and its components. + // + // Outputs: + // -version : a buffer that the version string is stored. + // -remainBuffBytes : remaining size of the buffer "version" in + // bytes, excluding terminating-null. + // -position : the first character of the ACM version will + // written to version[position] and so on. + // + // Return value: + // -1 if failed to write the whole version string, + // 0 if succeeded. + // + static WebRtc_Word32 GetVersion(WebRtc_Word8* version, + WebRtc_UWord32& remainBuffBytes, + WebRtc_UWord32& position); + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_UWord8 NumberOfCodecs() + // Returns number of supported codecs. + // + // Return value: + // number of supported codecs. + /// + static WebRtc_UWord8 NumberOfCodecs(); + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 Codec() + // Get supported codec with list number. + // + // Input: + // -listId : list number. + // + // Output: + // -codec : a structure where the parameters of the codec, + // given by list number is written to. + // + // Return value: + // -1 if the list number (listId) is invalid. + // 0 if succeeded. + // + static WebRtc_Word32 Codec(const WebRtc_UWord8 listId, CodecInst& codec); + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 Codec() + // Get supported codec with the given codec name and sampling frequency. + // If the sampling frequency is -1 then the search will be only based on + // codec name. + // + // Input: + // -payloadName : name of the codec. + // -samplingFreqHz : samling frequency of the codec. + // + // Output: + // -codec : a structure where the parameters of the codec, + // given by name is written to. + // + // Return value: + // -1 if the list number (listId) is invalid. + // 0 if succeeded. + // + static WebRtc_Word32 Codec(const WebRtc_Word8* payloadName, CodecInst& codec, + const WebRtc_Word32 samplingFreqHz = -1); + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 Codec() + // + // Returns the list number of the given codec name and sampling frequency. + // If the sampling frequency is -1 then the search will be only based on + // codec name. + // + // Input: + // -payloadName : name of the codec. + // -samplingFreqHz : samling frequency of the codec. + // + // Return value: + // if the codec is found, the index of the codec in the list, + // -1 if the codec is not found. + // + static WebRtc_Word32 Codec(const WebRtc_Word8* payloadName, + const WebRtc_Word32 samplingFreqHz = -1); + + /////////////////////////////////////////////////////////////////////////// + // bool IsCodecValid() + // Checks the validity of the parameters of the given codec. + // + // Input: + // -codec : the structur which keeps the parameters of the + // codec. + // + // Reurn value: + // true if the parameters are valid, + // false if any parameter is not valid. + // + static bool IsCodecValid(const CodecInst& codec); + + /////////////////////////////////////////////////////////////////////////// + // Sender + // + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 InitializeSender() + // Any encoder-related state of ACM will be initialized to the + // same state when ACM is created. This will not interrupt or + // effect decoding functionality of ACM. ACM will lose all the + // encoding-related settings by calling this function. + // For instance, a send codec has to be registered again. + // + // Return value: + // -1 if failed to initialize, + // 0 if succeeded. + // + virtual WebRtc_Word32 InitializeSender() = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 ResetEncoder() + // This API resets the states of encoder. All the encoder settings, such as + // send-codec or VAD/DTX, will be preserved. + // + // Return value: + // -1 if failed to initialize, + // 0 if succeeded. + // + virtual WebRtc_Word32 ResetEncoder() = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 RegisterSendCodec() + // Registers a codec, specified by "sendCodec," as sending codec. + // This API can be called multiple of times to register Codec. The last codec + // registered overwrites the previous ones. + // The API can also be used to change payload type for CNG and RED, which are + // registered by default to default payload types. + // Note that registering CNG and RED won't overwrite speech codecs. + // This API can be called to set/change the send payload-type, frame-size + // or encoding rate (if applicable for the codec). + // + // Input: + // -sendCodec : Parameters of the codec to be registered, c.f. + // common_types.h for the definition of + // CodecInst. + // + // Return value: + // -1 if failed to initialize, + // 0 if succeeded. + // + virtual WebRtc_Word32 RegisterSendCodec(const CodecInst& sendCodec) = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 SendCodec() + // Get parameters for the codec currently registered as send codec. + // + // Output: + // -currentSendCodec : parameters of the send codec. + // + // Return value: + // -1 if failed to get send codec, + // 0 if succeeded. + // + virtual WebRtc_Word32 SendCodec(CodecInst& currentSendCodec) const = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 SendFrequency() + // Get the sampling frequency of the current encoder in Hertz. + // + // Return value: + // positive; sampling frequency [Hz] of the current encoder. + // -1 if an error has happened. + // + virtual WebRtc_Word32 SendFrequency() const = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 Bitrate() + // Get encoding bit-rate in bits per second. + // + // Return value: + // positive; encoding rate in bits/sec, + // -1 if an error is happened. + // + virtual WebRtc_Word32 SendBitrate() const = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 SetReceivedEstimatedBandwidth() + // Set available bandwidth [bits/sec] of the up-link channel. + // This information is used for traffic shaping, and is currently only + // supported if iSAC is the send codec. + // + // Input: + // -bw : bandwidth in bits/sec estimated for + // up-link. + // Return value + // -1 if error occurred in setting the bandwidth, + // 0 bandwidth is set successfully. + // + virtual WebRtc_Word32 SetReceivedEstimatedBandwidth( + const WebRtc_Word32 bw) = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 RegisterTransportCallback() + // Register a transport callback which will be called to deliver + // the encoded buffers whenever Process() is called and a + // bit-stream is ready. + // + // Input: + // -transport : pointer to the callback class + // transport->SendData() is called whenever + // Process() is called and bit-stream is ready + // to deliver. + // + // Return value: + // -1 if the transport callback could not be registered + // 0 if registration is successful. + // + virtual WebRtc_Word32 RegisterTransportCallback( + AudioPacketizationCallback* transport) = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 Add10MsData() + // Add 10MS of raw (PCM) audio data to the encoder. If the sampling + // frequency of the audio does not match the sampling frequency of the + // current encoder ACM will resample the audio. + // + // Input: + // -audioFrame : the input audio frame, containing raw audio + // sampling frequency etc., + // c.f. module_common_types.h for definition of + // AudioFrame. + // + // Return value: + // 0 successfully added the frame. + // -1 some error occurred and data is not added. + // < -1 to add the frame to the buffer n samples had to be + // overwritten, -n is the return value in this case. + // + virtual WebRtc_Word32 Add10MsData(const AudioFrame& audioFrame) = 0; + + /////////////////////////////////////////////////////////////////////////// + // (FEC) Forward Error Correction + // + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 SetFECStatus(const bool enable) + // configure FEC status i.e. on/off. + // + // RFC 2198 describes a solution which has a single payload type which + // signifies a packet with redundancy. That packet then becomes a container, + // encapsulating multiple payloads into a single RTP packet. + // Such a scheme is flexible, since any amount of redundancy may be + // encapsulated within a single packet. There is, however, a small overhead + // since each encapsulated payload must be preceded by a header indicating + // the type of data enclosed. + // + // This means that FEC is actually a RED scheme. + // + // Input: + // -enableFEC : if true FEC is enabled, otherwise FEC is + // disabled. + // + // Return value: + // -1 if failed to set FEC status, + // 0 if succeeded. + // + virtual WebRtc_Word32 SetFECStatus(const bool enableFEC) = 0; + + /////////////////////////////////////////////////////////////////////////// + // bool FECStatus() + // Get FEC status + // + // Return value + // true if FEC is enabled, + // false if FEC is disabled. + // + virtual bool FECStatus() const = 0; + + /////////////////////////////////////////////////////////////////////////// + // (VAD) Voice Activity Detection + // + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 SetVAD() + // If DTX is enabled & the codec does not have internal DTX/VAD + // WebRtc VAD will be automatically enabled and 'enableVAD' is ignored. + // + // If DTX is disabled but VAD is enabled no DTX packets are send, + // regardless of whether the codec has internal DTX/VAD or not. In this + // case, WebRtc VAD is running to label frames as active/in-active. + // + // Inputs: + // -enableDTX : if true DTX is enabled, + // otherwise DTX is disabled. + // -enableVAD : if true VAD is enabled, + // otherwise VAD is disabled. + // -vadMode : determines the aggressiveness of VAD. A more + // aggressive mode results in more frames labeled + // as in-active, c.f. definition of + // ACMVADMode in audio_coding_module_typedefs.h + // for valid values. + // + // Return value: + // -1 if failed to set up VAD/DTX, + // 0 if succeeded. + // + virtual WebRtc_Word32 SetVAD(const bool enableDTX = true, + const bool enableVAD = false, + const ACMVADMode vadMode = VADNormal) = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 VAD() + // Get VAD status. + // + // Outputs: + // -dtxEnabled : is set to true if DTX is enabled, otherwise + // is set to false. + // -vadEnabled : is set to true if VAD is enabled, otherwise + // is set to false. + // -vadMode : is set to the current aggressiveness of VAD. + // + // Return value: + // -1 if fails to retrieve the setting of DTX/VAD, + // 0 if succeeeded. + // + virtual WebRtc_Word32 VAD(bool& dtxEnabled, bool& vadEnabled, + ACMVADMode& vadMode) const = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 ReplaceInternalDTXWithWebRtc() + // Used to replace codec internal DTX scheme with WebRtc. This is only + // supported for G729, where this call replaces AnnexB with WebRtc DTX. + // + // Input: + // -useWebRtcDTX : if false (default) the codec built-in DTX/VAD + // scheme is used, otherwise the internal DTX is + // replaced with WebRtc DTX/VAD. + // + // Return value: + // -1 if failed to replace codec internal DTX with WebRtc, + // 0 if succeeded. + // + virtual WebRtc_Word32 ReplaceInternalDTXWithWebRtc( + const bool useWebRtcDTX = false) = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 IsInternalDTXReplacedWithWebRtc() + // Get status if the codec internal DTX (when such exists) is replaced with + // WebRtc DTX. This is only supported for G729. + // + // Output: + // -usesWebRtcDTX : is set to true if the codec internal DTX is + // replaced with WebRtc DTX/VAD, otherwise it is set + // to false. + // + // Return value: + // -1 if failed to determine if codec internal DTX is replaced with WebRtc, + // 0 if succeeded. + // + virtual WebRtc_Word32 IsInternalDTXReplacedWithWebRtc( + bool& usesWebRtcDTX) = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 RegisterVADCallback() + // Call this method to register a callback function which is called + // any time that ACM encounters an empty frame. That is a frame which is + // recognized inactive. Depending on the codec WebRtc VAD or internal codec + // VAD is employed to identify a frame as active/inactive. + // + // Input: + // -vadCallback : pointer to a callback function. + // + // Return value: + // -1 if failed to register the callback function. + // 0 if the callback function is registered successfully. + // + virtual WebRtc_Word32 RegisterVADCallback(ACMVADCallback* vadCallback) = 0; + + /////////////////////////////////////////////////////////////////////////// + // Receiver + // + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 InitializeReceiver() + // Any decoder-related state of ACM will be initialized to the + // same state when ACM is created. This will not interrupt or + // effect encoding functionality of ACM. ACM would lose all the + // decoding-related settings by calling this function. + // For instance, all registered codecs are deleted and have to be + // registered again. + // + // Return value: + // -1 if failed to initialize, + // 0 if succeeded. + // + virtual WebRtc_Word32 InitializeReceiver() = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 ResetDecoder() + // This API resets the states of decoders. ACM will not lose any + // decoder-related settings, such as registered codecs. + // + // Return value: + // -1 if failed to initialize, + // 0 if succeeded. + // + virtual WebRtc_Word32 ResetDecoder() = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 ReceiveFrequency() + // Get sampling frequency of the last received payload. + // + // Return value: + // non-negative the sampling frequency in Hertz. + // -1 if an error has occurred. + // + virtual WebRtc_Word32 ReceiveFrequency() const = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 PlayoutFrequency() + // Get sampling frequency of audio played out. + // + // Return value: + // the sampling frequency in Hertz. + // + virtual WebRtc_Word32 PlayoutFrequency() const = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 RegisterReceiveCodec() + // Register possible decoders, can be called multiple times for + // codecs, CNG-NB, CNG-WB, CNG-SWB, AVT and RED. + // + // Input: + // -receiveCodec : parameters of the codec to be registered, c.f. + // common_types.h for the definition of + // CodecInst. + // + // Return value: + // -1 if failed to register the codec + // 0 if the codec registered successfully. + // + virtual WebRtc_Word32 RegisterReceiveCodec(const CodecInst& receiveCodec) = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 UnregisterReceiveCodec() + // Unregister the codec currently registered with a specific payload type + // from the list of possible receive codecs. + // + // Input: + // -payloadType : The number representing the payload type to + // unregister. + // + // Output: + // -1 if the unregistration fails. + // 0 if the given codec is successfully unregistered. + // + virtual WebRtc_Word32 UnregisterReceiveCodec( + const WebRtc_Word16 receiveCodec) = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 ReceiveCodec() + // Get the codec associated with last received payload. + // + // Output: + // -currRcvCodec : parameters of the codec associated with the last + // received payload, c.f. common_types.h for + // the definition of CodecInst. + // + // Return value: + // -1 if failed to retrieve the codec, + // 0 if the codec is successfully retrieved. + // + virtual WebRtc_Word32 ReceiveCodec(CodecInst& currRcvCodec) const = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 IncomingPacket() + // Call this function to insert a parsed RTP packet into ACM. + // + // Inputs: + // -incomingPayload : received payload. + // -payloadLengthByte : the length of payload in bytes. + // -rtpInfo : the relevant information retrieved from RTP + // header. + // + // Return value: + // -1 if failed to push in the payload + // 0 if payload is successfully pushed in. + // + virtual WebRtc_Word32 IncomingPacket(const WebRtc_Word8* incomingPayload, + const WebRtc_Word32 payloadLengthByte, + const WebRtcRTPHeader& rtpInfo) = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 IncomingPayload() + // Call this API to push incoming payloads when there is no rtp-info. + // The rtp-info will be created in ACM. One usage for this API is when + // pre-encoded files are pushed in ACM + // + // Inputs: + // -incomingPayload : received payload. + // -payloadLenghtByte : the length, in bytes, of the received payload. + // -payloadType : the payload-type. This specifies which codec has + // to be used to decode the payload. + // -timestamp : send timestamp of the payload. ACM starts with + // a random value and increment it by the + // packet-size, which is given when the codec in + // question is registered by RegisterReceiveCodec(). + // Therefore, it is essential to have the timestamp + // if the frame-size differ from the registered + // value or if the incoming payload contains DTX + // packets. + // + // Return value: + // -1 if failed to push in the payload + // 0 if payload is successfully pushed in. + // + virtual WebRtc_Word32 IncomingPayload(const WebRtc_Word8* incomingPayload, + const WebRtc_Word32 payloadLengthByte, + const WebRtc_UWord8 payloadType, + const WebRtc_UWord32 timestamp = 0) = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 SetMinimumPlayoutDelay() + // Set Minimum playout delay, used for lip-sync. + // + // Input: + // -timeMs : minimum delay in milliseconds. + // + // Return value: + // -1 if failed to set the delay, + // 0 if the minimum delay is set. + // + virtual WebRtc_Word32 SetMinimumPlayoutDelay(const WebRtc_Word32 timeMs) = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 Delay() + // Get the current playout delay. + // + // Output: + // - delayInMs : delay in millisecond + // + // Return value: + // -1 if failed to get the delay, + // 0 if succeeded to get the delay. + // + virtual WebRtc_Word32 Delay(WebRtc_UWord16& delayMs) const = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 RegisterIncomingMessagesCallback() + // Used by the module to deliver messages to the codec module/application + // when a Dtmf tone is detected, as well as when it stopped. + // + // Inputs: + // -inMsgCallback : pointer to callback function which will be called + // if Dtmf is detected. + // -cpt : enables CPT (Call Progress Tone) detection for the + // specified country. c.f. definition of ACMCountries + // in audio_coding_module_typedefs.h for valid + // entries. The default value disables CPT + // detection. + // + // Return value: + // -1 if the message callback could not be registered + // 0 if registration is successful. + // + virtual WebRtc_Word32 + RegisterIncomingMessagesCallback( + AudioCodingFeedback* inMsgCallback, + const ACMCountries cpt = ACMDisableCountryDetection) = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 SetDtmfPlayoutStatus() + // Configure Dtmf playout, i.e. whether out-of-band + // Dtmf tones are played or not. + // + // Input: + // -enable : if true to enable playout out-of-band Dtmf tones, + // false to disable. + // + // Return value: + // -1 if the method fails, e.g. Dtmf playout is not supported. + // 0 if the status is set successfully. + // + virtual WebRtc_Word32 SetDtmfPlayoutStatus(const bool enable) = 0; + + /////////////////////////////////////////////////////////////////////////// + // bool DtmfPlayoutStatus() + // Get Dtmf playout status. + // + // Return value: + // true if out-of-band Dtmf tones are played, + // false if playout of Dtmf tones is disabled. + // + virtual bool DtmfPlayoutStatus() const = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 SetBackgroundNoiseMode() + // Sets the mode of the background noise playout in an event of long + // packetloss burst. For the valid modes see the declaration of + // ACMBackgroundNoiseMode in audio_coding_module_typedefs.h. + // + // Input: + // -mode : the mode for the background noise playout. + // + // Return value: + // -1 if failed to set the mode. + // 0 if succeeded in setting the mode. + // + virtual WebRtc_Word32 SetBackgroundNoiseMode( + const ACMBackgroundNoiseMode mode) = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 BackgroundNoiseMode() + // Call this method to get the mode of the background noise playout. + // Playout of background noise is a result of a long packetloss burst. + // See ACMBackgroundNoiseMode in audio_coding_module_typedefs.h for + // possible modes. + // + // Output: + // -mode : a reference to ACMBackgroundNoiseMode enumerator. + // + // Return value: + // 0 if the output is a valid mode. + // -1 if ACM failed to output a valid mode. + // + virtual WebRtc_Word32 BackgroundNoiseMode(ACMBackgroundNoiseMode& mode) = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 PlayoutTimestamp() + // The send timestamp of an RTP packet is associated with the decoded + // audio of the packet in question. This function returns the timestamp of + // the latest audio obtained by calling PlayoutData10ms(). + // + // Input: + // -timestamp : a reference to a WebRtc_UWord32 to receive the + // timestamp. + // Return value: + // 0 if the output is a correct timestamp. + // -1 if failed to output the correct timestamp. + // + // + virtual WebRtc_Word32 PlayoutTimestamp(WebRtc_UWord32& timestamp) = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 DecoderEstimatedBandwidth() + // Get the estimate of the Bandwidth, in bits/second, based on the incoming + // stream. This API is useful in one-way communication scenarios, where + // the bandwidth information is sent in an out-of-band fashion. + // Currently only supported if iSAC is registered as a reciever. + // + // Return value: + // >0 bandwidth in bits/second. + // -1 if failed to get a bandwidth estimate. + // + virtual WebRtc_Word32 DecoderEstimatedBandwidth() const = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 SetPlayoutMode() + // Call this API to set the playout mode. Playout mode could be optimized + // for i) voice, ii) FAX or iii) streaming. In Voice mode, NetEQ is + // optimized to deliver highest audio quality while maintaining a minimum + // delay. In FAX mode, NetEQ is optimized to have few delay changes as + // possible and maintain a constant delay, perhaps large relative to voice + // mode, to avoid PLC. In streaming mode, we tolerate a little more delay + // to acheive better jitter robustness. + // + // Input: + // -mode : playout mode. Possible inputs are: + // "voice", + // "fax" and + // "streaming". + // + // Return value: + // -1 if failed to set the mode, + // 0 if succeeding. + // + virtual WebRtc_Word32 SetPlayoutMode(const AudioPlayoutMode mode) = 0; + + /////////////////////////////////////////////////////////////////////////// + // AudioPlayoutMode PlayoutMode() + // Get playout mode, i.e. whether it is speech, FAX or streaming. See + // audio_coding_module_typedefs.h for definition of AudioPlayoutMode. + // + // Return value: + // voice: is for voice output, + // fax: a mode that is optimized for receiving FAX signals. + // In this mode NetEq tries to maintain a constant high + // delay to avoid PLC if possible. + // streaming: a mode that is suitable for streaminq. In this mode we + // accept longer delay to improve jitter robustness. + // + virtual AudioPlayoutMode PlayoutMode() const = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 PlayoutData10Ms( + // Get 10 milliseconds of raw audio data for playout, at the given sampling + // frequency. ACM will perform a resampling if required. + // + // Input: + // -desiredFreqHz : the desired sampling frequency, in Hertz, of the + // output audio. If set to -1, the function returns the + // audio at the current sampling frequency. + // + // Output: + // -audioFrame : output audio frame which contains raw audio data + // and other relevant parameters, c.f. + // module_common_types.h for the definition of + // AudioFrame. + // + // Return value: + // -1 if the function fails, + // 0 if the function succeeds. + // + virtual WebRtc_Word32 + PlayoutData10Ms(const WebRtc_Word32 desiredFreqHz, + AudioFrame &audioFrame) = 0; + + /////////////////////////////////////////////////////////////////////////// + // (CNG) Comfort Noise Generation + // Generate comfort noise when receiving DTX packets + // + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word16 SetReceiveVADStatus() + // configure VAD status i.e. on/off on the incoming stream + // Running VAD on decoded audio is desired in some applications, e.g. + // conferencing. + // + // Input: + // -enable : true to enable VAD on incoming stream, and false + // to disable. + // + // Return value: + // -1 if failed to enable/disable VAD, + // 0 if succeded to enable/disable VAD. + // + virtual WebRtc_Word16 SetReceiveVADStatus(const bool enable) = 0; + + /////////////////////////////////////////////////////////////////////////// + // bool ReceiveVADStatus() + // Call this API to get whether VAD is enabled on incoming stream or not. + // Running VAD on decoded audio is desired in some applications, e.g. + // conferencing. + // + // Return value: + // true if VAD is enabled on the incoming stream, + // false if VAD is disabled on the incoming stream. + // + virtual bool ReceiveVADStatus() const = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word16 SetReceiveVADMode() + // Configure VAD aggressiveness on the incoming stream. + // + // Input: + // -mode : aggressiveness of the VAD on incoming stream. + // See audio_coding_module_typedefs.h for the + // definition of ACMVADMode, and possible + // values for aggressiveness. + // + // Return value: + // -1 if fails to set the mode, + // 0 if the mode is set successfully. + // + virtual WebRtc_Word16 SetReceiveVADMode(const ACMVADMode mode) = 0; + + /////////////////////////////////////////////////////////////////////////// + // ACMVADMode ReceiveVADMode() + // Get VAD aggressiveness on the incoming stream. + // + // Return value: + // aggressiveness of VAD, running on the incoming stream. A more + // aggressive mode means more audio frames will be labeled as in-active. + // See audio_coding_module_typedefs.h for the definition of + // ACMVADMode. + // + virtual ACMVADMode ReceiveVADMode() const = 0; + + /////////////////////////////////////////////////////////////////////////// + // Codec specific + // + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 SetISACMaxRate() + // Set the maximum instantaneous rate of iSAC. For a payload of B bits + // with a frame-size of T sec the instantaneous rate is B/T bist per + // second. Therefore, (B/T < maxRateBitPerSec) and + // (B < maxPayloadLenBytes * 8) are always satisfied for iSAC payloads, + // c.f SetISACMaxPayloadSize(). + // + // Input: + // -maxRateBitPerSec : maximum instantaneous bit-rate given in bits/sec. + // + // Return value: + // -1 if failed to set the maximum rate. + // 0 if the maximum rate is set successfully. + // + virtual WebRtc_Word32 SetISACMaxRate( + const WebRtc_UWord32 maxRateBitPerSec) = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 SetISACMaxPayloadSize() + // Set the maximum payload size of iSAC packets. No iSAC payload, + // regardless of its frame-size, may exceed the given limit. For + // an iSAC payload of size B bits and frame-size T sec we have; + // (B < maxPayloadLenBytes * 8) and (B/T < maxRateBitPerSec), c.f. + // SetISACMaxRate(). + // + // Input: + // -maxPayloadLenBytes : maximum payload size in bytes. + // + // Return value: + // -1 if failed to set the maximm payload-size. + // 0 if the given linit is seet successfully. + // + virtual WebRtc_Word32 SetISACMaxPayloadSize( + const WebRtc_UWord16 maxPayloadLenBytes) = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 ConfigISACBandwidthEstimator() + // Call this function to configure the bandwidth estimator of ISAC. + // During the adaptation of bit-rate, iSAC atomatically adjusts the + // frame-size (either 30 or 60 ms) to save on RTP header. The initial + // frame-size can be specified by the first argument. The configuration also + // regards the initial estimate of bandwidths. The estimator starts from + // this point and converges to the actual bottleneck. This is given by the + // second parameter. Furthermore, it is also possible to control the + // adaptation of frame-size. This is specified by the last parameter. + // + // Input: + // -initFrameSizeMsec : initial frame-size in milisecods. For iSAC-wb + // 30 ms and 60 ms (default) are acceptable values, + // and for iSAC-swb 30 ms is the only acceptable + // value. Zero indiates default value. + // -initRateBitPerSec : initial estimate of the bandwidth. Values + // between 10000 and 58000 are acceptable. + // -enforceFrameSize : if true, the frame-size will not be adapted. + // + // Return value: + // -1 if failed to configure the bandwidth estimator, + // 0 if the configuration was successfully applied. + // + virtual WebRtc_Word32 ConfigISACBandwidthEstimator( + const WebRtc_UWord8 initFrameSizeMsec, + const WebRtc_UWord16 initRateBitPerSec, + const bool enforceFrameSize = false) = 0; + + /////////////////////////////////////////////////////////////////////////// + // statistics + // + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 NetworkStatistics() + // Get network statistics. + // + // Input: + // -networkStatistics : a structure that contains network statistics. + // + // Return value: + // -1 if failed to set the network statistics, + // 0 if statistics are set successfully. + // + virtual WebRtc_Word32 NetworkStatistics( + ACMNetworkStatistics& networkStatistics) const = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 JitterStatistics() + // Get the jitter statistics. + // + // Input: + // -jitterStatistics : the given jitter statistics. + // + // Return value: + // -1 if failed to set the jitter statistics, + // 0 if jitter statistics are set successfully. + // + virtual WebRtc_Word32 JitterStatistics( + ACMJitterStatistics& jitterStatistics) const = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 PreferredBufferSize() + // Get the optimal buffer size calculated for the current network + // conditions. + // + // Output: + // -prefBuffSize : the optimal size of the jitter buffer in + // milliseconds. + // + // Return value: + // -1 if the preferred buffer size could not be computed, + // 0 if a valid buffer is computed successfully. + // + virtual WebRtc_Word32 PreferredBufferSize( + WebRtc_UWord16& prefBufSize) const = 0; + + /////////////////////////////////////////////////////////////////////////// + // WebRtc_Word32 ResetJitterStatistics() + // Reset jitter statistics. + // + // Return value: + // -1 if failed to reset the statistics, + // 0 if succeeded. + // + virtual WebRtc_Word32 ResetJitterStatistics() const = 0; }; -} // namespace webrtc - -#endif +} // namespace webrtc +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_INTERFACE_AUDIO_CODING_MODULE_H diff --git a/src/modules/audio_coding/main/interface/audio_coding_module_typedefs.h b/src/modules/audio_coding/main/interface/audio_coding_module_typedefs.h index 28b7a4e30..d66fdc9e4 100644 --- a/src/modules/audio_coding/main/interface/audio_coding_module_typedefs.h +++ b/src/modules/audio_coding/main/interface/audio_coding_module_typedefs.h @@ -8,13 +8,12 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef AUDIO_CODING_MODULE_TYPEDEFS_H -#define AUDIO_CODING_MODULE_TYPEDEFS_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_INTERFACE_AUDIO_CODING_MODULE_TYPEDEFS_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_INTERFACE_AUDIO_CODING_MODULE_TYPEDEFS_H_ #include "typedefs.h" -namespace webrtc -{ +namespace webrtc { /////////////////////////////////////////////////////////////////////////// // enum AudioPlayoutMode @@ -36,41 +35,37 @@ namespace webrtc // this mode can be used to improve the jitter robustness at // the cost of increased delay. // -enum AudioPlayoutMode -{ - voice = 0, - fax = 1, - streaming = 2 +enum AudioPlayoutMode { + voice = 0, + fax = 1, + streaming = 2 }; - /////////////////////////////////////////////////////////////////////////// // enum ACMSpeechType // An enumerator for possible labels of a decoded frame. // -// -normal : a normal speech frame. If VAD is enabled on the -// incoming stream this label indicate that the -// frame is active. -// -PLC : a PLC frame. The corresponding packet was lost -// and this frame generated by PLC techniques. -// -CNG : the frame is comfort noise. This happens if VAD -// is enabled at the sender and we have received -// SID. -// -PLCCNG : PLC will fade to comfort noise if the duration -// of PLC is long. This labels such a case. -// -VADPassive : the VAD at the receiver recognizes this frame as -// passive. +// -normal : a normal speech frame. If VAD is enabled on the +// incoming stream this label indicate that the +// frame is active. +// -PLC : a PLC frame. The corresponding packet was lost +// and this frame generated by PLC techniques. +// -CNG : the frame is comfort noise. This happens if VAD +// is enabled at the sender and we have received +// SID. +// -PLCCNG : PLC will fade to comfort noise if the duration +// of PLC is long. This labels such a case. +// -VADPassive : the VAD at the receiver recognizes this frame as +// passive. // -enum ACMSpeechType -{ - normal = 0, - PLC = 1, - CNG = 2, - PLCCNG = 3, - VADPassive = 4 +enum ACMSpeechType { + normal = 0, + PLC = 1, + CNG = 2, + PLCCNG = 3, + VADPassive = 4 }; - /////////////////////////////////////////////////////////////////////////// // enum ACMVADMode // An enumerator for aggressiveness of VAD @@ -80,52 +75,50 @@ enum ACMSpeechType // -VADAggr : an aggressive mode. // -VADVeryAggr : the most agressive mode. // -enum ACMVADMode -{ - VADNormal = 0, - VADLowBitrate = 1, - VADAggr = 2, - VADVeryAggr = 3 +enum ACMVADMode { + VADNormal = 0, + VADLowBitrate = 1, + VADAggr = 2, + VADVeryAggr = 3 }; - /////////////////////////////////////////////////////////////////////////// // enum ACMCountries // An enumerator for countries, used when enabling CPT for a specific country. // -enum ACMCountries -{ - ACMDisableCountryDetection = -1, // disable CPT detection - ACMUSA = 0, - ACMJapan, - ACMCanada, - ACMFrance, - ACMGermany, - ACMAustria, - ACMBelgium, - ACMUK, - ACMCzech, - ACMDenmark, - ACMFinland, - ACMGreece, - ACMHungary, - ACMIceland , - ACMIreland, - ACMItaly, - ACMLuxembourg, - ACMMexico, - ACMNorway, - ACMPoland, - ACMPortugal, - ACMSpain, - ACMSweden, - ACMTurkey, - ACMChina, - ACMHongkong, - ACMTaiwan, - ACMKorea, - ACMSingapore, - ACMNonStandard1 // non-standard countries +enum ACMCountries { + ACMDisableCountryDetection = -1, // disable CPT detection + ACMUSA = 0, + ACMJapan, + ACMCanada, + ACMFrance, + ACMGermany, + ACMAustria, + ACMBelgium, + ACMUK, + ACMCzech, + ACMDenmark, + ACMFinland, + ACMGreece, + ACMHungary, + ACMIceland, + ACMIreland, + ACMItaly, + ACMLuxembourg, + ACMMexico, + ACMNorway, + ACMPoland, + ACMPortugal, + ACMSpain, + ACMSweden, + ACMTurkey, + ACMChina, + ACMHongkong, + ACMTaiwan, + ACMKorea, + ACMSingapore, + ACMNonStandard1 +// non-standard countries }; /////////////////////////////////////////////////////////////////////////// @@ -138,12 +131,11 @@ enum ACMCountries // -AMROctetAlligned : Octet-alligned mode. // -AMRFileStorage : file-storage mode. // -enum ACMAMRPackingFormat -{ - AMRUndefined = -1, - AMRBandwidthEfficient = 0, - AMROctetAlligned = 1, - AMRFileStorage = 2 +enum ACMAMRPackingFormat { + AMRUndefined = -1, + AMRBandwidthEfficient = 0, + AMROctetAlligned = 1, + AMRFileStorage = 2 }; @@ -155,20 +147,20 @@ enum ACMAMRPackingFormat // -preferredBufferSize : preferred (optimal) buffer size in ms // -currentPacketLossRate : loss rate (network + late) (in Q14) // -currentDiscardRate : late loss rate (in Q14) -// -currentExpandRate : fraction (of original stream) of synthesized speech -// inserted through expansion (in Q14) +// -currentExpandRate : fraction (of original stream) of synthesized +// speech inserted through expansion (in Q14) // -currentPreemptiveRate : fraction of synthesized speech inserted through // pre-emptive expansion (in Q14) -// -currentAccelerateRate : fraction of data removed through acceleration (in Q14) -typedef struct -{ - WebRtc_UWord16 currentBufferSize; - WebRtc_UWord16 preferredBufferSize; - WebRtc_UWord16 currentPacketLossRate; - WebRtc_UWord16 currentDiscardRate; - WebRtc_UWord16 currentExpandRate; - WebRtc_UWord16 currentPreemptiveRate; - WebRtc_UWord16 currentAccelerateRate; +// -currentAccelerateRate : fraction of data removed through acceleration +// (in Q14) +typedef struct { + WebRtc_UWord16 currentBufferSize; + WebRtc_UWord16 preferredBufferSize; + WebRtc_UWord16 currentPacketLossRate; + WebRtc_UWord16 currentDiscardRate; + WebRtc_UWord16 currentExpandRate; + WebRtc_UWord16 currentPreemptiveRate; + WebRtc_UWord16 currentAccelerateRate; } ACMNetworkStatistics; /////////////////////////////////////////////////////////////////////////// @@ -178,50 +170,59 @@ typedef struct // -jbMinSize : smallest Jitter Buffer size during call in ms // -jbMaxSize : largest Jitter Buffer size during call in ms // -jbAvgSize : the average JB size, measured over time - ms -// -jbChangeCount : number of times the Jitter Buffer changed (using Accelerate or Pre-emptive Expand) +// -jbChangeCount : number of times the Jitter Buffer changed (using +// Accelerate or Pre-emptive Expand) // -lateLossMs : amount (in ms) of audio data received late // -accelerateMs : milliseconds removed to reduce jitter buffer size // -flushedMs : milliseconds discarded through buffer flushing // -generatedSilentMs : milliseconds of generated silence -// -interpolatedVoiceMs : milliseconds of synthetic audio data (non-background noise) -// -interpolatedSilentMs : milliseconds of synthetic audio data (background noise level) -// -numExpandTiny : count of tiny expansions in output audio less than 250 ms*/ -// -numExpandSmall : count of small expansions in output audio 250 to 500 ms*/ -// -numExpandMedium : count of medium expansions in output audio 500 to 2000 ms*/ -// -numExpandLong : count of long expansions in output audio longer than 2000 +// -interpolatedVoiceMs : milliseconds of synthetic audio data +// (non-background noise) +// -interpolatedSilentMs : milliseconds of synthetic audio data (background +// noise level) +// -numExpandTiny : count of tiny expansions in output audio less +// than 250 ms +// -numExpandSmall : count of small expansions in output audio 250 to +// 500 ms +// -numExpandMedium : count of medium expansions in output audio 500 to +// 2000 ms +// -numExpandLong : count of long expansions in output audio longer +// than 2000 // -longestExpandDurationMs : duration of longest audio drop-out -// -countIAT500ms : count of times we got small network outage (inter-arrival time in [500, 1000) ms) -// -countIAT1000ms : count of times we got medium network outage (inter-arrival time in [1000, 2000) ms) -// -countIAT2000ms : count of times we got large network outage (inter-arrival time >= 2000 ms) +// -countIAT500ms : count of times we got small network outage +// (inter-arrival time in [500, 1000) ms) +// -countIAT1000ms : count of times we got medium network outage +// (inter-arrival time in [1000, 2000) ms) +// -countIAT2000ms : count of times we got large network outage +// (inter-arrival time >= 2000 ms) // -longestIATms : longest packet inter-arrival time in ms // -minPacketDelayMs : min time incoming Packet "waited" to be played // -maxPacketDelayMs : max time incoming Packet "waited" to be played // -avgPacketDelayMs : avg time incoming Packet "waited" to be played // -typedef struct -{ - WebRtc_UWord32 jbMinSize; - WebRtc_UWord32 jbMaxSize; - WebRtc_UWord32 jbAvgSize; - WebRtc_UWord32 jbChangeCount; - WebRtc_UWord32 lateLossMs; - WebRtc_UWord32 accelerateMs; - WebRtc_UWord32 flushedMs; - WebRtc_UWord32 generatedSilentMs; - WebRtc_UWord32 interpolatedVoiceMs; - WebRtc_UWord32 interpolatedSilentMs; - WebRtc_UWord32 numExpandTiny; - WebRtc_UWord32 numExpandSmall; - WebRtc_UWord32 numExpandMedium; - WebRtc_UWord32 numExpandLong; - WebRtc_UWord32 longestExpandDurationMs; - WebRtc_UWord32 countIAT500ms; - WebRtc_UWord32 countIAT1000ms; - WebRtc_UWord32 countIAT2000ms; - WebRtc_UWord32 longestIATms; - WebRtc_UWord32 minPacketDelayMs; - WebRtc_UWord32 maxPacketDelayMs; - WebRtc_UWord32 avgPacketDelayMs; +typedef struct { + WebRtc_UWord32 jbMinSize; + WebRtc_UWord32 jbMaxSize; + WebRtc_UWord32 jbAvgSize; + WebRtc_UWord32 jbChangeCount; + WebRtc_UWord32 lateLossMs; + WebRtc_UWord32 accelerateMs; + WebRtc_UWord32 flushedMs; + WebRtc_UWord32 generatedSilentMs; + WebRtc_UWord32 interpolatedVoiceMs; + WebRtc_UWord32 interpolatedSilentMs; + WebRtc_UWord32 numExpandTiny; + WebRtc_UWord32 numExpandSmall; + WebRtc_UWord32 numExpandMedium; + WebRtc_UWord32 numExpandLong; + WebRtc_UWord32 longestExpandDurationMs; + WebRtc_UWord32 countIAT500ms; + WebRtc_UWord32 countIAT1000ms; + WebRtc_UWord32 countIAT2000ms; + WebRtc_UWord32 longestIATms; + WebRtc_UWord32 minPacketDelayMs; + WebRtc_UWord32 maxPacketDelayMs; + WebRtc_UWord32 avgPacketDelayMs; } ACMJitterStatistics; /////////////////////////////////////////////////////////////////////////// @@ -232,14 +233,12 @@ typedef struct // -Fade : noise fades to zero after some time // -Off : background noise is always zero // -enum ACMBackgroundNoiseMode -{ - On, - Fade, - Off +enum ACMBackgroundNoiseMode { + On, + Fade, + Off }; +} // namespace webrtc -} // namespace webrtc - -#endif +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_INTERFACE_AUDIO_CODING_MODULE_TYPEDEFS_H_ diff --git a/src/modules/audio_coding/main/source/acm_amr.cc b/src/modules/audio_coding/main/source/acm_amr.cc index 4e074cefe..ac84a93a1 100644 --- a/src/modules/audio_coding/main/source/acm_amr.cc +++ b/src/modules/audio_coding/main/source/acm_amr.cc @@ -18,192 +18,131 @@ #include "webrtc_neteq_help_macros.h" #ifdef WEBRTC_CODEC_AMR - // NOTE! GSM AMR is not included in the open-source package. The following - // interface file is needed: - // - // /modules/audio_coding/codecs/amr/main/interface/amr_interface.h - // - // The API in the header file should match the one below. - // - // int16_t WebRtcAmr_CreateEnc(AMR_encinst_t_** encInst); - // int16_t WebRtcAmr_CreateDec(AMR_decinst_t_** decInst); - // int16_t WebRtcAmr_FreeEnc(AMR_encinst_t_* encInst); - // int16_t WebRtcAmr_FreeDec(AMR_decinst_t_* decInst); - // int16_t WebRtcAmr_Encode(AMR_encinst_t_* encInst, - // int16_t* input, - // int16_t len, - // int16_t*output, - // int16_t mode); - // int16_t WebRtcAmr_EncoderInit(AMR_encinst_t_* encInst, - // int16_t dtxMode); - // int16_t WebRtcAmr_EncodeBitmode(AMR_encinst_t_* encInst, - // int format); - // int16_t WebRtcAmr_Decode(AMR_decinst_t_* decInst); - // int16_t WebRtcAmr_DecodePlc(AMR_decinst_t_* decInst); - // int16_t WebRtcAmr_DecoderInit(AMR_decinst_t_* decInst); - // int16_t WebRtcAmr_DecodeBitmode(AMR_decinst_t_* decInst, - // int format); - // void WebRtcAmr_Version(char *versionStr, short len); - #include "amr_interface.h" +// NOTE! GSM AMR is not included in the open-source package. The following +// interface file is needed: +// +// /modules/audio_coding/codecs/amr/main/interface/amr_interface.h +// +// The API in the header file should match the one below. +// +// int16_t WebRtcAmr_CreateEnc(AMR_encinst_t_** encInst); +// int16_t WebRtcAmr_CreateDec(AMR_decinst_t_** decInst); +// int16_t WebRtcAmr_FreeEnc(AMR_encinst_t_* encInst); +// int16_t WebRtcAmr_FreeDec(AMR_decinst_t_* decInst); +// int16_t WebRtcAmr_Encode(AMR_encinst_t_* encInst, +// int16_t* input, +// int16_t len, +// int16_t*output, +// int16_t mode); +// int16_t WebRtcAmr_EncoderInit(AMR_encinst_t_* encInst, +// int16_t dtxMode); +// int16_t WebRtcAmr_EncodeBitmode(AMR_encinst_t_* encInst, +// int format); +// int16_t WebRtcAmr_Decode(AMR_decinst_t_* decInst); +// int16_t WebRtcAmr_DecodePlc(AMR_decinst_t_* decInst); +// int16_t WebRtcAmr_DecoderInit(AMR_decinst_t_* decInst); +// int16_t WebRtcAmr_DecodeBitmode(AMR_decinst_t_* decInst, +// int format); +// void WebRtcAmr_Version(char *versionStr, short len); +#include "amr_interface.h" #endif namespace webrtc { #ifndef WEBRTC_CODEC_AMR -ACMAMR::ACMAMR(WebRtc_Word16 /* codecID */) -{ - return; +ACMAMR::ACMAMR(WebRtc_Word16 /* codecID */) { + return; } - -ACMAMR::~ACMAMR() -{ - return; +ACMAMR::~ACMAMR() { + return; } - -WebRtc_Word16 -ACMAMR::InternalEncode( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16* /* bitStreamLenByte */) -{ - return -1; +WebRtc_Word16 ACMAMR::InternalEncode(WebRtc_UWord8* /* bitStream */, + WebRtc_Word16* /* bitStreamLenByte */) { + return -1; } - -WebRtc_Word16 -ACMAMR::DecodeSafe( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, - WebRtc_Word16* /* audio */, - WebRtc_Word16* /* audioSamples */, - WebRtc_Word8* /* speechType */) -{ - return -1; +WebRtc_Word16 ACMAMR::DecodeSafe(WebRtc_UWord8* /* bitStream */, + WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16* /* audio */, + WebRtc_Word16* /* audioSamples */, + WebRtc_Word8* /* speechType */) { + return -1; } - -WebRtc_Word16 -ACMAMR::EnableDTX() -{ - return -1; +WebRtc_Word16 ACMAMR::EnableDTX() { + return -1; } - -WebRtc_Word16 -ACMAMR::DisableDTX() -{ - return -1; +WebRtc_Word16 ACMAMR::DisableDTX() { + return -1; } - -WebRtc_Word16 -ACMAMR::InternalInitEncoder( - WebRtcACMCodecParams* /* codecParams */) -{ - return -1; +WebRtc_Word16 ACMAMR::InternalInitEncoder( + WebRtcACMCodecParams* /* codecParams */) { + return -1; } - -WebRtc_Word16 -ACMAMR::InternalInitDecoder( - WebRtcACMCodecParams* /* codecParams */) -{ - return -1; +WebRtc_Word16 ACMAMR::InternalInitDecoder( + WebRtcACMCodecParams* /* codecParams */) { + return -1; } -WebRtc_Word32 -ACMAMR::CodecDef( - WebRtcNetEQ_CodecDef& /* codecDef */, - const CodecInst& /* codecInst */) -{ - return -1; +WebRtc_Word32 ACMAMR::CodecDef(WebRtcNetEQ_CodecDef& /* codecDef */, + const CodecInst& /* codecInst */) { + return -1; } -ACMGenericCodec* -ACMAMR::CreateInstance(void) -{ - return NULL; +ACMGenericCodec* ACMAMR::CreateInstance(void) { + return NULL; } - -WebRtc_Word16 -ACMAMR::InternalCreateEncoder() -{ - return -1; +WebRtc_Word16 ACMAMR::InternalCreateEncoder() { + return -1; } - -void -ACMAMR::DestructEncoderSafe() -{ - return; +void ACMAMR::DestructEncoderSafe() { + return; } - -WebRtc_Word16 -ACMAMR::InternalCreateDecoder() -{ - return -1; +WebRtc_Word16 ACMAMR::InternalCreateDecoder() { + return -1; } - -void -ACMAMR::DestructDecoderSafe() -{ - return; +void ACMAMR::DestructDecoderSafe() { + return; } - -WebRtc_Word16 -ACMAMR::SetBitRateSafe( - const WebRtc_Word32 /* rate */) -{ - return -1; +WebRtc_Word16 ACMAMR::SetBitRateSafe(const WebRtc_Word32 /* rate */) { + return -1; } - -void -ACMAMR::InternalDestructEncoderInst( - void* /* ptrInst */) -{ - return; +void ACMAMR::InternalDestructEncoderInst(void* /* ptrInst */) { + return; } - -WebRtc_Word16 -ACMAMR::SetAMREncoderPackingFormat( - ACMAMRPackingFormat /* packingFormat */) -{ - return -1; +WebRtc_Word16 ACMAMR::SetAMREncoderPackingFormat( + ACMAMRPackingFormat /* packingFormat */) { + return -1; } - -ACMAMRPackingFormat -ACMAMR::AMREncoderPackingFormat() const -{ - return AMRUndefined; +ACMAMRPackingFormat ACMAMR::AMREncoderPackingFormat() const { + return AMRUndefined; } -WebRtc_Word16 -ACMAMR::SetAMRDecoderPackingFormat( - ACMAMRPackingFormat /* packingFormat */) -{ - return -1; +WebRtc_Word16 ACMAMR::SetAMRDecoderPackingFormat( + ACMAMRPackingFormat /* packingFormat */) { + return -1; } -ACMAMRPackingFormat -ACMAMR::AMRDecoderPackingFormat() const -{ - return AMRUndefined; +ACMAMRPackingFormat ACMAMR::AMRDecoderPackingFormat() const { + return AMRUndefined; } -WebRtc_Word16 -ACMAMR::UnregisterFromNetEqSafe( - ACMNetEQ* /* netEq */, - WebRtc_Word16 /* payloadType */) -{ - return -1; +WebRtc_Word16 ACMAMR::UnregisterFromNetEqSafe(ACMNetEQ* /* netEq */, + WebRtc_Word16 /* payloadType */) { + return -1; } @@ -218,377 +157,282 @@ ACMAMR::UnregisterFromNetEqSafe( #define WEBRTC_AMR_MR102 6 #define WEBRTC_AMR_MR122 7 -ACMAMR::ACMAMR(WebRtc_Word16 codecID): -_encoderInstPtr(NULL), -_decoderInstPtr(NULL), -_encodingMode(-1), // invalid value -_encodingRate(0) // invalid value -{ - _codecID = codecID; - _hasInternalDTX = true; - _encoderPackingFormat = AMRBandwidthEfficient; - _decoderPackingFormat = AMRBandwidthEfficient; - return; +ACMAMR::ACMAMR(WebRtc_Word16 codecID) + : _encoderInstPtr(NULL), + _decoderInstPtr(NULL), + _encodingMode(-1), // invalid value + _encodingRate(0) { // invalid value + _codecID = codecID; + _hasInternalDTX = true; + _encoderPackingFormat = AMRBandwidthEfficient; + _decoderPackingFormat = AMRBandwidthEfficient; + return; } - -ACMAMR::~ACMAMR() -{ - if(_encoderInstPtr != NULL) - { - WebRtcAmr_FreeEnc(_encoderInstPtr); - _encoderInstPtr = NULL; - } - if(_decoderInstPtr != NULL) - { - WebRtcAmr_FreeDec(_decoderInstPtr); - _decoderInstPtr = NULL; - } - return; +ACMAMR::~ACMAMR() { + if (_encoderInstPtr != NULL) { + WebRtcAmr_FreeEnc(_encoderInstPtr); + _encoderInstPtr = NULL; + } + if (_decoderInstPtr != NULL) { + WebRtcAmr_FreeDec(_decoderInstPtr); + _decoderInstPtr = NULL; + } + return; } +WebRtc_Word16 ACMAMR::InternalEncode(WebRtc_UWord8* bitStream, + WebRtc_Word16* bitStreamLenByte) { + WebRtc_Word16 vadDecision = 1; + // sanity check, if the rate is set correctly. we might skip this + // sanity check. if rate is not set correctly, initialization flag + // should be false and should not be here. + if ((_encodingMode < WEBRTC_AMR_MR475) || + (_encodingMode > WEBRTC_AMR_MR122)) { + *bitStreamLenByte = 0; + return -1; + } + *bitStreamLenByte = WebRtcAmr_Encode(_encoderInstPtr, + &_inAudio[_inAudioIxRead], + _frameLenSmpl, + (WebRtc_Word16*) bitStream, + _encodingMode); -WebRtc_Word16 -ACMAMR::InternalEncode( - WebRtc_UWord8* bitStream, - WebRtc_Word16* bitStreamLenByte) -{ - WebRtc_Word16 vadDecision = 1; - // sanity check, if the rate is set correctly. we might skip this - // sanity check. if rate is not set correctly, initialization flag - // should be false and should not be here. - if((_encodingMode < WEBRTC_AMR_MR475) || (_encodingMode > WEBRTC_AMR_MR122)) - { - *bitStreamLenByte = 0; - return -1; + // Update VAD, if internal DTX is used + if (_hasInternalDTX && _dtxEnabled) { + if (*bitStreamLenByte <= (7 * _frameLenSmpl / 160)) { + vadDecision = 0; } - *bitStreamLenByte = WebRtcAmr_Encode(_encoderInstPtr, - &_inAudio[_inAudioIxRead], _frameLenSmpl, (WebRtc_Word16*)bitStream, - _encodingMode); - - // Update VAD, if internal DTX is used - if(_hasInternalDTX && _dtxEnabled) - { - if(*bitStreamLenByte <= (7*_frameLenSmpl/160)) - { - vadDecision = 0; - } - for(WebRtc_Word16 n = 0; n < MAX_FRAME_SIZE_10MSEC; n++) - { - _vadLabel[n] = vadDecision; - } + for (WebRtc_Word16 n = 0; n < MAX_FRAME_SIZE_10MSEC; n++) { + _vadLabel[n] = vadDecision; } - // increment the read index - _inAudioIxRead += _frameLenSmpl; - return *bitStreamLenByte; + } + // increment the read index + _inAudioIxRead += _frameLenSmpl; + return *bitStreamLenByte; } +WebRtc_Word16 ACMAMR::DecodeSafe(WebRtc_UWord8* /* bitStream */, + WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16* /* audio */, + WebRtc_Word16* /* audioSamples */, + WebRtc_Word8* /* speechType */) { + return 0; +} -WebRtc_Word16 -ACMAMR::DecodeSafe( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, - WebRtc_Word16* /* audio */, - WebRtc_Word16* /* audioSamples */, - WebRtc_Word8* /* speechType */) -{ +WebRtc_Word16 ACMAMR::EnableDTX() { + if (_dtxEnabled) { return 0; -} - - -WebRtc_Word16 -ACMAMR::EnableDTX() -{ - if(_dtxEnabled) - { - return 0; + } else if (_encoderExist) { // check if encoder exist + // enable DTX + if (WebRtcAmr_EncoderInit(_encoderInstPtr, 1) < 0) { + return -1; } - else if(_encoderExist) // check if encoder exist - { - // enable DTX - if(WebRtcAmr_EncoderInit(_encoderInstPtr, 1) < 0) - { - return -1; - } - _dtxEnabled = true; - return 0; - } - else - { - return -1; - } -} - - -WebRtc_Word16 -ACMAMR::DisableDTX() -{ - if(!_dtxEnabled) - { - return 0; - } - else if(_encoderExist) // check if encoder exist - { - // disable DTX - if(WebRtcAmr_EncoderInit(_encoderInstPtr, 0) < 0) - { - return -1; - } - _dtxEnabled = false; - return 0; - } - else - { - // encoder doesn't exists, therefore disabling is harmless - return 0; - } -} - - -WebRtc_Word16 -ACMAMR::InternalInitEncoder( - WebRtcACMCodecParams* codecParams) -{ - WebRtc_Word16 status = SetBitRateSafe((codecParams->codecInstant).rate); - status += (WebRtcAmr_EncoderInit(_encoderInstPtr, - ((codecParams->enableDTX)? 1:0)) < 0)? -1:0; - status += (WebRtcAmr_EncodeBitmode(_encoderInstPtr, - _encoderPackingFormat ) < 0)? -1:0; - return (status < 0)? -1:0; -} - - -WebRtc_Word16 -ACMAMR::InternalInitDecoder( - WebRtcACMCodecParams* /* codecParams */) -{ - WebRtc_Word16 status = ( - (WebRtcAmr_DecoderInit(_decoderInstPtr) < 0)? -1:0); - status += - WebRtcAmr_DecodeBitmode(_decoderInstPtr, _decoderPackingFormat); - return (status < 0)? -1:0; -} - - -WebRtc_Word32 -ACMAMR::CodecDef( - WebRtcNetEQ_CodecDef& codecDef, - const CodecInst& codecInst) -{ - if (!_decoderInitialized) - { - // Todo: - // log error - return -1; - } - // Fill up the structure by calling - // "SET_CODEC_PAR" & "SET_AMR_FUNCTION." - // Then call NetEQ to add the codec to it's - // database. - SET_CODEC_PAR((codecDef), kDecoderAMR, codecInst.pltype, - _decoderInstPtr, 8000); - SET_AMR_FUNCTIONS((codecDef)); + _dtxEnabled = true; return 0; + } else { + return -1; + } } - -ACMGenericCodec* -ACMAMR::CreateInstance(void) -{ - return NULL; -} - - -WebRtc_Word16 -ACMAMR::InternalCreateEncoder() -{ - return WebRtcAmr_CreateEnc(&_encoderInstPtr); -} - - -void -ACMAMR::DestructEncoderSafe() -{ - if(_encoderInstPtr != NULL) - { - WebRtcAmr_FreeEnc(_encoderInstPtr); - _encoderInstPtr = NULL; - } - // there is no encoder set the following - _encoderExist = false; - _encoderInitialized = false; - _encodingMode = -1; // invalid value - _encodingRate = 0; // invalid value -} - - -WebRtc_Word16 -ACMAMR::InternalCreateDecoder() -{ - return WebRtcAmr_CreateDec(&_decoderInstPtr); -} - - -void -ACMAMR::DestructDecoderSafe() -{ - if(_decoderInstPtr != NULL) - { - WebRtcAmr_FreeDec(_decoderInstPtr); - _decoderInstPtr = NULL; - } - // there is no encoder instance set the followings - _decoderExist = false; - _decoderInitialized = false; -} - - -WebRtc_Word16 -ACMAMR::SetBitRateSafe(const WebRtc_Word32 rate) -{ - switch(rate) - { - case 4750: - _encodingMode = WEBRTC_AMR_MR475; - _encodingRate = 4750; - break; - case 5150: - _encodingMode = WEBRTC_AMR_MR515; - _encodingRate = 5150; - break; - case 5900: - _encodingMode = WEBRTC_AMR_MR59; - _encodingRate = 5900; - break; - case 6700: - _encodingMode = WEBRTC_AMR_MR67; - _encodingRate = 6700; - break; - case 7400: - _encodingMode = WEBRTC_AMR_MR74; - _encodingRate = 7400; - break; - case 7950: - _encodingMode = WEBRTC_AMR_MR795; - _encodingRate = 7950; - break; - case 10200: - _encodingMode = WEBRTC_AMR_MR102; - _encodingRate = 10200; - break; - case 12200: - _encodingMode = WEBRTC_AMR_MR122; - _encodingRate = 12200; - break; - default: - return -1; - break; - } +WebRtc_Word16 ACMAMR::DisableDTX() { + if (!_dtxEnabled) { return 0; + } else if (_encoderExist) { // check if encoder exist + // disable DTX + if (WebRtcAmr_EncoderInit(_encoderInstPtr, 0) < 0) { + return -1; + } + _dtxEnabled = false; + return 0; + } else { + // encoder doesn't exists, therefore disabling is harmless + return 0; + } } - -void -ACMAMR::InternalDestructEncoderInst( - void* ptrInst) -{ - // Free the memory where ptrInst is pointing to - if(ptrInst != NULL) - { - WebRtcAmr_FreeEnc((AMR_encinst_t_*)ptrInst); - } - return; +WebRtc_Word16 ACMAMR::InternalInitEncoder(WebRtcACMCodecParams* codecParams) { + WebRtc_Word16 status = SetBitRateSafe((codecParams->codecInstant).rate); + status += (WebRtcAmr_EncoderInit( + _encoderInstPtr, ((codecParams->enableDTX) ? 1 : 0)) < 0) ? -1 : 0; + status += (WebRtcAmr_EncodeBitmode( + _encoderInstPtr, _encoderPackingFormat) < 0) ? -1 : 0; + return (status < 0) ? -1 : 0; } - -WebRtc_Word16 -ACMAMR::SetAMREncoderPackingFormat( - ACMAMRPackingFormat packingFormat) -{ - if((packingFormat != AMRBandwidthEfficient) && - (packingFormat != AMROctetAlligned) && - (packingFormat != AMRFileStorage)) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "Invalid AMR Encoder packing-format."); - return -1; - } - else - { - if(WebRtcAmr_EncodeBitmode(_encoderInstPtr, - packingFormat) < 0) - { - return -1; - } - else - { - _encoderPackingFormat = packingFormat; - return 0; - } - - } +WebRtc_Word16 ACMAMR::InternalInitDecoder( + WebRtcACMCodecParams* /* codecParams */) { + WebRtc_Word16 status = + ((WebRtcAmr_DecoderInit(_decoderInstPtr) < 0) ? -1 : 0); + status += WebRtcAmr_DecodeBitmode(_decoderInstPtr, _decoderPackingFormat); + return (status < 0) ? -1 : 0; } - -ACMAMRPackingFormat -ACMAMR::AMREncoderPackingFormat() const -{ - return _encoderPackingFormat; +WebRtc_Word32 ACMAMR::CodecDef(WebRtcNetEQ_CodecDef& codecDef, + const CodecInst& codecInst) { + if (!_decoderInitialized) { + // Todo: + // log error + return -1; + } + // Fill up the structure by calling + // "SET_CODEC_PAR" & "SET_AMR_FUNCTION." + // Then call NetEQ to add the codec to it's + // database. + SET_CODEC_PAR((codecDef), kDecoderAMR, codecInst.pltype, _decoderInstPtr, + 8000); + SET_AMR_FUNCTIONS((codecDef)); + return 0; } -WebRtc_Word16 -ACMAMR::SetAMRDecoderPackingFormat( - ACMAMRPackingFormat packingFormat) -{ - if((packingFormat != AMRBandwidthEfficient) && - (packingFormat != AMROctetAlligned) && - (packingFormat != AMRFileStorage)) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "Invalid AMR decoder packing-format."); - return -1; - } - else - { - if(WebRtcAmr_DecodeBitmode(_decoderInstPtr, - packingFormat) < 0) - { - return -1; - } - else - { - _decoderPackingFormat = packingFormat; - return 0; - } - - } +ACMGenericCodec* ACMAMR::CreateInstance(void) { + return NULL; } -ACMAMRPackingFormat -ACMAMR::AMRDecoderPackingFormat() const -{ - return _decoderPackingFormat; +WebRtc_Word16 ACMAMR::InternalCreateEncoder() { + return WebRtcAmr_CreateEnc(&_encoderInstPtr); } -WebRtc_Word16 -ACMAMR::UnregisterFromNetEqSafe( - ACMNetEQ* netEq, - WebRtc_Word16 payloadType) -{ - if(payloadType != _decoderParams.codecInstant.pltype) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "Cannot unregister codec %s given payload-type %d does not match \ -the stored payload type", - _decoderParams.codecInstant.plname, - payloadType, - _decoderParams.codecInstant.pltype); - return -1; +void ACMAMR::DestructEncoderSafe() { + if (_encoderInstPtr != NULL) { + WebRtcAmr_FreeEnc(_encoderInstPtr); + _encoderInstPtr = NULL; + } + // there is no encoder set the following + _encoderExist = false; + _encoderInitialized = false; + _encodingMode = -1; // invalid value + _encodingRate = 0; // invalid value +} + +WebRtc_Word16 ACMAMR::InternalCreateDecoder() { + return WebRtcAmr_CreateDec(&_decoderInstPtr); +} + +void ACMAMR::DestructDecoderSafe() { + if (_decoderInstPtr != NULL) { + WebRtcAmr_FreeDec(_decoderInstPtr); + _decoderInstPtr = NULL; + } + // there is no encoder instance set the followings + _decoderExist = false; + _decoderInitialized = false; +} + +WebRtc_Word16 ACMAMR::SetBitRateSafe(const WebRtc_Word32 rate) { + switch (rate) { + case 4750: { + _encodingMode = WEBRTC_AMR_MR475; + _encodingRate = 4750; + break; } - return netEq->RemoveCodec(kDecoderAMR); + case 5150: { + _encodingMode = WEBRTC_AMR_MR515; + _encodingRate = 5150; + break; + } + case 5900: { + _encodingMode = WEBRTC_AMR_MR59; + _encodingRate = 5900; + break; + } + case 6700: { + _encodingMode = WEBRTC_AMR_MR67; + _encodingRate = 6700; + break; + } + case 7400: { + _encodingMode = WEBRTC_AMR_MR74; + _encodingRate = 7400; + break; + } + case 7950: { + _encodingMode = WEBRTC_AMR_MR795; + _encodingRate = 7950; + break; + } + case 10200: { + _encodingMode = WEBRTC_AMR_MR102; + _encodingRate = 10200; + break; + } + case 12200: { + _encodingMode = WEBRTC_AMR_MR122; + _encodingRate = 12200; + break; + } + default: { + return -1; + } + } + return 0; +} + +void ACMAMR::InternalDestructEncoderInst(void* ptrInst) { + // Free the memory where ptrInst is pointing to + if (ptrInst != NULL) { + WebRtcAmr_FreeEnc(reinterpret_cast(ptrInst)); + } + return; +} + +WebRtc_Word16 ACMAMR::SetAMREncoderPackingFormat( + ACMAMRPackingFormat packingFormat) { + if ((packingFormat != AMRBandwidthEfficient) && + (packingFormat != AMROctetAlligned) && + (packingFormat != AMRFileStorage)) { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "Invalid AMR Encoder packing-format."); + return -1; + } else { + if (WebRtcAmr_EncodeBitmode(_encoderInstPtr, packingFormat) < 0) { + return -1; + } else { + _encoderPackingFormat = packingFormat; + return 0; + } + } +} + +ACMAMRPackingFormat ACMAMR::AMREncoderPackingFormat() const { + return _encoderPackingFormat; +} + +WebRtc_Word16 ACMAMR::SetAMRDecoderPackingFormat( + ACMAMRPackingFormat packingFormat) { + if ((packingFormat != AMRBandwidthEfficient) && + (packingFormat != AMROctetAlligned) && + (packingFormat != AMRFileStorage)) { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "Invalid AMR decoder packing-format."); + return -1; + } else { + if (WebRtcAmr_DecodeBitmode(_decoderInstPtr, packingFormat) < 0) { + return -1; + } else { + _decoderPackingFormat = packingFormat; + return 0; + } + } +} + +ACMAMRPackingFormat ACMAMR::AMRDecoderPackingFormat() const { + return _decoderPackingFormat; +} + +WebRtc_Word16 ACMAMR::UnregisterFromNetEqSafe(ACMNetEQ* netEq, + WebRtc_Word16 payloadType) { + if (payloadType != _decoderParams.codecInstant.pltype) { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "Cannot unregister codec %s given payload-type %d does not " + "match the stored payload type", + _decoderParams.codecInstant.plname, payloadType, + _decoderParams.codecInstant.pltype); + return -1; + } + return netEq->RemoveCodec(kDecoderAMR); } #endif } - diff --git a/src/modules/audio_coding/main/source/acm_amr.h b/src/modules/audio_coding/main/source/acm_amr.h index 3cb4c3f46..cc342e72d 100644 --- a/src/modules/audio_coding/main/source/acm_amr.h +++ b/src/modules/audio_coding/main/source/acm_amr.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_AMR_H -#define ACM_AMR_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_AMR_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_AMR_H_ #include "acm_generic_codec.h" @@ -21,76 +21,66 @@ namespace webrtc { enum ACMAMRPackingFormat; -class ACMAMR : public ACMGenericCodec -{ -public: - ACMAMR(WebRtc_Word16 codecID); - ~ACMAMR(); - // for FEC - ACMGenericCodec* CreateInstance(void); +class ACMAMR: public ACMGenericCodec { + public: + ACMAMR(WebRtc_Word16 codecID); + ~ACMAMR(); + // for FEC + ACMGenericCodec* CreateInstance(void); - WebRtc_Word16 InternalEncode( - WebRtc_UWord8* bitstream, - WebRtc_Word16* bitStreamLenByte); - - WebRtc_Word16 InternalInitEncoder( - WebRtcACMCodecParams *codecParams); - - WebRtc_Word16 InternalInitDecoder( - WebRtcACMCodecParams *codecParams); - - WebRtc_Word16 SetAMREncoderPackingFormat( - const ACMAMRPackingFormat packingFormat); + WebRtc_Word16 InternalEncode(WebRtc_UWord8* bitstream, + WebRtc_Word16* bitStreamLenByte); - ACMAMRPackingFormat AMREncoderPackingFormat() const; + WebRtc_Word16 InternalInitEncoder(WebRtcACMCodecParams *codecParams); - WebRtc_Word16 SetAMRDecoderPackingFormat( - const ACMAMRPackingFormat packingFormat); + WebRtc_Word16 InternalInitDecoder(WebRtcACMCodecParams *codecParams); - ACMAMRPackingFormat AMRDecoderPackingFormat() const; + WebRtc_Word16 SetAMREncoderPackingFormat( + const ACMAMRPackingFormat packingFormat); -protected: - WebRtc_Word16 DecodeSafe( - WebRtc_UWord8* bitStream, - WebRtc_Word16 bitStreamLenByte, - WebRtc_Word16* audio, - WebRtc_Word16* audioSamples, - WebRtc_Word8* speechType); + ACMAMRPackingFormat AMREncoderPackingFormat() const; - WebRtc_Word32 CodecDef( - WebRtcNetEQ_CodecDef& codecDef, - const CodecInst& codecInst); + WebRtc_Word16 SetAMRDecoderPackingFormat( + const ACMAMRPackingFormat packingFormat); - void DestructEncoderSafe(); + ACMAMRPackingFormat AMRDecoderPackingFormat() const; - void DestructDecoderSafe(); + protected: + WebRtc_Word16 DecodeSafe(WebRtc_UWord8* bitStream, + WebRtc_Word16 bitStreamLenByte, + WebRtc_Word16* audio, WebRtc_Word16* audioSamples, + WebRtc_Word8* speechType); - WebRtc_Word16 InternalCreateEncoder(); - - WebRtc_Word16 InternalCreateDecoder(); - - void InternalDestructEncoderInst( - void* ptrInst); + WebRtc_Word32 CodecDef(WebRtcNetEQ_CodecDef& codecDef, + const CodecInst& codecInst); - WebRtc_Word16 SetBitRateSafe( - const WebRtc_Word32 rate); - - WebRtc_Word16 EnableDTX(); - - WebRtc_Word16 DisableDTX(); - - WebRtc_Word16 UnregisterFromNetEqSafe( - ACMNetEQ* netEq, - WebRtc_Word16 payloadType); + void DestructEncoderSafe(); - AMR_encinst_t_* _encoderInstPtr; - AMR_decinst_t_* _decoderInstPtr; - WebRtc_Word16 _encodingMode; - WebRtc_Word16 _encodingRate; - ACMAMRPackingFormat _encoderPackingFormat; - ACMAMRPackingFormat _decoderPackingFormat; + void DestructDecoderSafe(); + + WebRtc_Word16 InternalCreateEncoder(); + + WebRtc_Word16 InternalCreateDecoder(); + + void InternalDestructEncoderInst(void* ptrInst); + + WebRtc_Word16 SetBitRateSafe(const WebRtc_Word32 rate); + + WebRtc_Word16 EnableDTX(); + + WebRtc_Word16 DisableDTX(); + + WebRtc_Word16 UnregisterFromNetEqSafe(ACMNetEQ* netEq, + WebRtc_Word16 payloadType); + + AMR_encinst_t_* _encoderInstPtr; + AMR_decinst_t_* _decoderInstPtr; + WebRtc_Word16 _encodingMode; + WebRtc_Word16 _encodingRate; + ACMAMRPackingFormat _encoderPackingFormat; + ACMAMRPackingFormat _decoderPackingFormat; }; } // namespace webrtc -#endif // ACM_AMR_H +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_AMR_H_ diff --git a/src/modules/audio_coding/main/source/acm_amrwb.cc b/src/modules/audio_coding/main/source/acm_amrwb.cc index 501689654..9e62dded5 100644 --- a/src/modules/audio_coding/main/source/acm_amrwb.cc +++ b/src/modules/audio_coding/main/source/acm_amrwb.cc @@ -18,176 +18,130 @@ #include "webrtc_neteq_help_macros.h" #ifdef WEBRTC_CODEC_AMRWB - // NOTE! GSM AMR-wb is not included in the open-source package. The - // following interface file is needed: - // - // /modules/audio_coding/codecs/amrwb/main/interface/amrwb_interface.h - // - // The API in the header file should match the one below. - // - // int16_t WebRtcAmrWb_CreateEnc(AMRWB_encinst_t_** encInst); - // int16_t WebRtcAmrWb_CreateDec(AMRWB_decinst_t_** decInst); - // int16_t WebRtcAmrWb_FreeEnc(AMRWB_encinst_t_* encInst); - // int16_t WebRtcAmrWb_FreeDec(AMRWB_decinst_t_* decInst); - // int16_t WebRtcAmrWb_Encode(AMRWB_encinst_t_* encInst, int16_t* input, - // int16_t len, int16_t*output, int16_t mode); - // int16_t WebRtcAmrWb_EncoderInit(AMRWB_encinst_t_* encInst, - // int16_t dtxMode); - // int16_t WebRtcAmrWb_EncodeBitmode(AMRWB_encinst_t_* encInst, - // int format); - // int16_t WebRtcAmrWb_Decode(AMRWB_decinst_t_* decInst); - // int16_t WebRtcAmrWb_DecodePlc(AMRWB_decinst_t_* decInst); - // int16_t WebRtcAmrWb_DecoderInit(AMRWB_decinst_t_* decInst); - // int16_t WebRtcAmrWb_DecodeBitmode(AMRWB_decinst_t_* decInst, - // int format); - // void WebRtcAmrWb_Version(char *versionStr, short len); - #include "amrwb_interface.h" +// NOTE! GSM AMR-wb is not included in the open-source package. The +// following interface file is needed: +// +// /modules/audio_coding/codecs/amrwb/main/interface/amrwb_interface.h +// +// The API in the header file should match the one below. +// +// int16_t WebRtcAmrWb_CreateEnc(AMRWB_encinst_t_** encInst); +// int16_t WebRtcAmrWb_CreateDec(AMRWB_decinst_t_** decInst); +// int16_t WebRtcAmrWb_FreeEnc(AMRWB_encinst_t_* encInst); +// int16_t WebRtcAmrWb_FreeDec(AMRWB_decinst_t_* decInst); +// int16_t WebRtcAmrWb_Encode(AMRWB_encinst_t_* encInst, int16_t* input, +// int16_t len, int16_t* output, int16_t mode); +// int16_t WebRtcAmrWb_EncoderInit(AMRWB_encinst_t_* encInst, +// int16_t dtxMode); +// int16_t WebRtcAmrWb_EncodeBitmode(AMRWB_encinst_t_* encInst, +// int format); +// int16_t WebRtcAmrWb_Decode(AMRWB_decinst_t_* decInst); +// int16_t WebRtcAmrWb_DecodePlc(AMRWB_decinst_t_* decInst); +// int16_t WebRtcAmrWb_DecoderInit(AMRWB_decinst_t_* decInst); +// int16_t WebRtcAmrWb_DecodeBitmode(AMRWB_decinst_t_* decInst, +// int format); +// void WebRtcAmrWb_Version(char *versionStr, short len); +#include "amrwb_interface.h" #endif namespace webrtc { #ifndef WEBRTC_CODEC_AMRWB -ACMAMRwb::ACMAMRwb(WebRtc_Word16 /* codecID*/) -{ - return; +ACMAMRwb::ACMAMRwb(WebRtc_Word16 /* codecID*/) { + return; } -ACMAMRwb::~ACMAMRwb() -{ - return; +ACMAMRwb::~ACMAMRwb() { + return; } -WebRtc_Word16 -ACMAMRwb::InternalEncode( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16* /* bitStreamLenByte */) -{ - return -1; +WebRtc_Word16 ACMAMRwb::InternalEncode(WebRtc_UWord8* /* bitStream */, + WebRtc_Word16* /* bitStreamLenByte */) { + return -1; } -WebRtc_Word16 -ACMAMRwb::DecodeSafe( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, - WebRtc_Word16* /* audio */, - WebRtc_Word16* /* audioSamples */, - WebRtc_Word8* /* speechType */) -{ - return -1; +WebRtc_Word16 ACMAMRwb::DecodeSafe(WebRtc_UWord8* /* bitStream */, + WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16* /* audio */, + WebRtc_Word16* /* audioSamples */, + WebRtc_Word8* /* speechType */) { + return -1; } -WebRtc_Word16 -ACMAMRwb::EnableDTX() -{ - return -1; +WebRtc_Word16 ACMAMRwb::EnableDTX() { + return -1; } -WebRtc_Word16 -ACMAMRwb::DisableDTX() -{ - return -1; +WebRtc_Word16 ACMAMRwb::DisableDTX() { + return -1; } -WebRtc_Word16 -ACMAMRwb::InternalInitEncoder( - WebRtcACMCodecParams* /* codecParams */) -{ - return -1; +WebRtc_Word16 ACMAMRwb::InternalInitEncoder( + WebRtcACMCodecParams* /* codecParams */) { + return -1; } -WebRtc_Word16 -ACMAMRwb::InternalInitDecoder( - WebRtcACMCodecParams* /* codecParams */) -{ - return -1; +WebRtc_Word16 ACMAMRwb::InternalInitDecoder( + WebRtcACMCodecParams* /* codecParams */) { + return -1; } -WebRtc_Word32 -ACMAMRwb::CodecDef( - WebRtcNetEQ_CodecDef& /* codecDef */, - const CodecInst& /* codecInst */) -{ - return -1; +WebRtc_Word32 ACMAMRwb::CodecDef(WebRtcNetEQ_CodecDef& /* codecDef */, + const CodecInst& /* codecInst */) { + return -1; } ACMGenericCodec* -ACMAMRwb::CreateInstance(void) -{ - return NULL; +ACMAMRwb::CreateInstance(void) { + return NULL; } - - -WebRtc_Word16 -ACMAMRwb::InternalCreateEncoder() -{ - return -1; +WebRtc_Word16 ACMAMRwb::InternalCreateEncoder() { + return -1; } -void -ACMAMRwb::DestructEncoderSafe() -{ - return; +void ACMAMRwb::DestructEncoderSafe() { + return; } - -WebRtc_Word16 -ACMAMRwb::InternalCreateDecoder() -{ - return -1; +WebRtc_Word16 ACMAMRwb::InternalCreateDecoder() { + return -1; } -void -ACMAMRwb::DestructDecoderSafe() -{ - return; +void ACMAMRwb::DestructDecoderSafe() { + return; } -WebRtc_Word16 -ACMAMRwb::SetBitRateSafe( - const WebRtc_Word32 /* rate */) -{ - return -1; +WebRtc_Word16 ACMAMRwb::SetBitRateSafe(const WebRtc_Word32 /* rate */) { + return -1; } -void -ACMAMRwb::InternalDestructEncoderInst( - void* /* ptrInst */) -{ - return; +void ACMAMRwb::InternalDestructEncoderInst(void* /* ptrInst */) { + return; } -WebRtc_Word16 -ACMAMRwb::SetAMRwbEncoderPackingFormat( - ACMAMRPackingFormat /* packingFormat */) -{ - return -1; +WebRtc_Word16 ACMAMRwb::SetAMRwbEncoderPackingFormat( + ACMAMRPackingFormat /* packingFormat */) { + return -1; } -ACMAMRPackingFormat -ACMAMRwb::AMRwbEncoderPackingFormat() const -{ - return AMRUndefined; +ACMAMRPackingFormat ACMAMRwb::AMRwbEncoderPackingFormat() const { + return AMRUndefined; } WebRtc_Word16 ACMAMRwb::SetAMRwbDecoderPackingFormat( - ACMAMRPackingFormat /* packingFormat */) -{ - return -1; + ACMAMRPackingFormat /* packingFormat */) { + return -1; } -ACMAMRPackingFormat -ACMAMRwb::AMRwbDecoderPackingFormat() const -{ - return AMRUndefined; +ACMAMRPackingFormat ACMAMRwb::AMRwbDecoderPackingFormat() const { + return AMRUndefined; } -WebRtc_Word16 -ACMAMRwb::UnregisterFromNetEqSafe( - ACMNetEQ* /* netEq */, - WebRtc_Word16 /* payloadType */) -{ - return -1; +WebRtc_Word16 ACMAMRwb::UnregisterFromNetEqSafe( + ACMNetEQ* /* netEq */, + WebRtc_Word16 /* payloadType */) { + return -1; } #else //===================== Actual Implementation ======================= @@ -202,387 +156,288 @@ ACMAMRwb::UnregisterFromNetEqSafe( #define AMRWB_MODE_23k 7 #define AMRWB_MODE_24k 8 -ACMAMRwb::ACMAMRwb(WebRtc_Word16 codecID): -_encoderInstPtr(NULL), -_decoderInstPtr(NULL), -_encodingMode(-1), // invalid value -_encodingRate(0) // invalid value -{ - _codecID = codecID; - _hasInternalDTX = true; - _encoderPackingFormat = AMRBandwidthEfficient; - _decoderPackingFormat = AMRBandwidthEfficient; - return; +ACMAMRwb::ACMAMRwb(WebRtc_Word16 codecID) + : _encoderInstPtr(NULL), + _decoderInstPtr(NULL), + _encodingMode(-1), // invalid value + _encodingRate(0) { // invalid value + _codecID = codecID; + _hasInternalDTX = true; + _encoderPackingFormat = AMRBandwidthEfficient; + _decoderPackingFormat = AMRBandwidthEfficient; + return; } -ACMAMRwb::~ACMAMRwb() -{ - if(_encoderInstPtr != NULL) - { - WebRtcAmrWb_FreeEnc(_encoderInstPtr); - _encoderInstPtr = NULL; - } - if(_decoderInstPtr != NULL) - { - WebRtcAmrWb_FreeDec(_decoderInstPtr); - _decoderInstPtr = NULL; - } - return; +ACMAMRwb::~ACMAMRwb() { + if (_encoderInstPtr != NULL) { + WebRtcAmrWb_FreeEnc(_encoderInstPtr); + _encoderInstPtr = NULL; + } + if (_decoderInstPtr != NULL) { + WebRtcAmrWb_FreeDec(_decoderInstPtr); + _decoderInstPtr = NULL; + } + return; } -WebRtc_Word16 -ACMAMRwb::InternalEncode( - WebRtc_UWord8* bitStream, - WebRtc_Word16* bitStreamLenByte) -{ - WebRtc_Word16 vadDecision = 1; - // sanity check, if the rate is set correctly. we might skip this - // sanity check. if rate is not set correctly, initialization flag - // should be false and should not be here. - if((_encodingMode < AMRWB_MODE_7k) || (_encodingMode > AMRWB_MODE_24k)) - { - *bitStreamLenByte = 0; - return -1; +WebRtc_Word16 ACMAMRwb::InternalEncode(WebRtc_UWord8* bitStream, + WebRtc_Word16* bitStreamLenByte) { + WebRtc_Word16 vadDecision = 1; + // sanity check, if the rate is set correctly. we might skip this + // sanity check. if rate is not set correctly, initialization flag + // should be false and should not be here. + if ((_encodingMode < AMRWB_MODE_7k) || (_encodingMode > AMRWB_MODE_24k)) { + *bitStreamLenByte = 0; + return -1; + } + *bitStreamLenByte = WebRtcAmrWb_Encode(_encoderInstPtr, + &_inAudio[_inAudioIxRead], + _frameLenSmpl, + (WebRtc_Word16*) bitStream, + _encodingMode); + + // Update VAD, if internal DTX is used + if (_hasInternalDTX && _dtxEnabled) { + if (*bitStreamLenByte <= (7 * _frameLenSmpl / 160)) { + vadDecision = 0; } - *bitStreamLenByte = - WebRtcAmrWb_Encode(_encoderInstPtr, &_inAudio[_inAudioIxRead], - _frameLenSmpl, (WebRtc_Word16*)bitStream, _encodingMode); - - // Update VAD, if internal DTX is used - if(_hasInternalDTX && _dtxEnabled) - { - if (*bitStreamLenByte <= (7*_frameLenSmpl/160)) - { - vadDecision = 0; - } - for(WebRtc_Word16 n = 0; n < MAX_FRAME_SIZE_10MSEC; n++) - { - _vadLabel[n] = vadDecision; - } + for (WebRtc_Word16 n = 0; n < MAX_FRAME_SIZE_10MSEC; n++) { + _vadLabel[n] = vadDecision; } - // increment the read index this tell the caller that how far - // we have gone forward in reading the audio buffer - _inAudioIxRead += _frameLenSmpl; - return *bitStreamLenByte; + } + // increment the read index this tell the caller that how far + // we have gone forward in reading the audio buffer + _inAudioIxRead += _frameLenSmpl; + return *bitStreamLenByte; } -WebRtc_Word16 -ACMAMRwb::DecodeSafe( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, - WebRtc_Word16* /* audio */, - WebRtc_Word16* /* audioSamples */, - WebRtc_Word8* /* speechType */) -{ +WebRtc_Word16 ACMAMRwb::DecodeSafe(WebRtc_UWord8* /* bitStream */, + WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16* /* audio */, + WebRtc_Word16* /* audioSamples */, + WebRtc_Word8* /* speechType */) { + return 0; +} + +WebRtc_Word16 ACMAMRwb::EnableDTX() { + if (_dtxEnabled) { return 0; -} - -WebRtc_Word16 -ACMAMRwb::EnableDTX() -{ - if(_dtxEnabled) - { - return 0; + } else if (_encoderExist) { // check if encoder exist + // enable DTX + if (WebRtcAmrWb_EncoderInit(_encoderInstPtr, 1) < 0) { + return -1; } - else if(_encoderExist) // check if encoder exist - { - // enable DTX - if(WebRtcAmrWb_EncoderInit(_encoderInstPtr, 1) < 0) - { - return -1; - } - _dtxEnabled = true; - return 0; - } - else - { - return -1; - } -} - -WebRtc_Word16 -ACMAMRwb::DisableDTX() -{ - if(!_dtxEnabled) - { - return 0; - } - else if(_encoderExist) // check if encoder exist - { - // disable DTX - if(WebRtcAmrWb_EncoderInit(_encoderInstPtr, 0) < 0) - { - return -1; - } - _dtxEnabled = false; - return 0; - } - else - { - // encoder doesn't exists, therefore disabling is harmless - return 0; - } -} - -WebRtc_Word16 -ACMAMRwb::InternalInitEncoder( - WebRtcACMCodecParams* codecParams) -{ - // sanity check - if (_encoderInstPtr == NULL) - { - return -1; - } - - WebRtc_Word16 status = SetBitRateSafe((codecParams->codecInstant).rate); - status += (WebRtcAmrWb_EncoderInit( - _encoderInstPtr, ((codecParams->enableDTX)? 1:0)) < 0)? -1:0; - status += (WebRtcAmrWb_EncodeBitmode( - _encoderInstPtr, _encoderPackingFormat ) < 0)? -1:0; - return (status < 0)? -1:0; -} - -WebRtc_Word16 -ACMAMRwb::InternalInitDecoder( - WebRtcACMCodecParams* /* codecParams */) -{ - WebRtc_Word16 status = WebRtcAmrWb_DecodeBitmode( - _decoderInstPtr, _decoderPackingFormat); - status += ((WebRtcAmrWb_DecoderInit(_decoderInstPtr) < 0)? -1:0); - return (status < 0)? -1:0; -} - -WebRtc_Word32 -ACMAMRwb::CodecDef( - WebRtcNetEQ_CodecDef& codecDef, - const CodecInst& codecInst) -{ - if (!_decoderInitialized) - { - // Todo: - // log error - return -1; - } - - // Fill up the structure by calling - // "SET_CODEC_PAR" & "SET_AMRWB_FUNCTION." - // Then call NetEQ to add the codec to it's - // database. - SET_CODEC_PAR((codecDef), kDecoderAMRWB, codecInst.pltype, - _decoderInstPtr, 16000); - SET_AMRWB_FUNCTIONS((codecDef)); + _dtxEnabled = true; return 0; + } else { + return -1; + } } -ACMGenericCodec* -ACMAMRwb::CreateInstance(void) -{ - return NULL; -} - -WebRtc_Word16 -ACMAMRwb::InternalCreateEncoder() -{ - return WebRtcAmrWb_CreateEnc(&_encoderInstPtr); -} - -void -ACMAMRwb::DestructEncoderSafe() -{ - if(_encoderInstPtr != NULL) - { - WebRtcAmrWb_FreeEnc(_encoderInstPtr); - _encoderInstPtr = NULL; - } - // there is no encoder set the following - _encoderExist = false; - _encoderInitialized = false; - _encodingMode = -1; // invalid value - _encodingRate = 0; -} - - -WebRtc_Word16 -ACMAMRwb::InternalCreateDecoder() -{ - return WebRtcAmrWb_CreateDec(&_decoderInstPtr); -} - -void -ACMAMRwb::DestructDecoderSafe() -{ - if(_decoderInstPtr != NULL) - { - WebRtcAmrWb_FreeDec(_decoderInstPtr); - _decoderInstPtr = NULL; - } - // there is no encoder instance set the followings - _decoderExist = false; - _decoderInitialized = false; -} - -WebRtc_Word16 -ACMAMRwb::SetBitRateSafe( - const WebRtc_Word32 rate) -{ - switch(rate) - { - case 7000: - { - _encodingMode = AMRWB_MODE_7k; - _encodingRate = 7000; - break; - } - case 9000: - { - _encodingMode = AMRWB_MODE_9k; - _encodingRate = 9000; - break; - } - case 12000: - { - _encodingMode = AMRWB_MODE_12k; - _encodingRate = 12000; - break; - } - case 14000: - { - _encodingMode = AMRWB_MODE_14k; - _encodingRate = 14000; - break; - } - case 16000: - { - _encodingMode = AMRWB_MODE_16k; - _encodingRate = 16000; - break; - } - case 18000: - { - _encodingMode = AMRWB_MODE_18k; - _encodingRate = 18000; - break; - } - case 20000: - { - _encodingMode = AMRWB_MODE_20k; - _encodingRate = 20000; - break; - } - case 23000: - { - _encodingMode = AMRWB_MODE_23k; - _encodingRate = 23000; - break; - } - case 24000: - { - _encodingMode = AMRWB_MODE_24k; - _encodingRate = 24000; - break; - } - default: - { - return -1; - break; - } - } +WebRtc_Word16 ACMAMRwb::DisableDTX() { + if (!_dtxEnabled) { return 0; + } else if (_encoderExist) { // check if encoder exist + // disable DTX + if (WebRtcAmrWb_EncoderInit(_encoderInstPtr, 0) < 0) { + return -1; + } + _dtxEnabled = false; + return 0; + } else { + // encoder doesn't exists, therefore disabling is harmless + return 0; + } } -void -ACMAMRwb::InternalDestructEncoderInst( - void* ptrInst) -{ - if(ptrInst != NULL) - { - WebRtcAmrWb_FreeEnc((AMRWB_encinst_t_*)ptrInst); - } - return; +WebRtc_Word16 ACMAMRwb::InternalInitEncoder(WebRtcACMCodecParams* codecParams) { + // sanity check + if (_encoderInstPtr == NULL) { + return -1; + } + + WebRtc_Word16 status = SetBitRateSafe((codecParams->codecInstant).rate); + status += (WebRtcAmrWb_EncoderInit( + _encoderInstPtr, ((codecParams->enableDTX) ? 1 : 0)) < 0) ? -1 : 0; + status += (WebRtcAmrWb_EncodeBitmode( + _encoderInstPtr, _encoderPackingFormat) < 0) ? -1 : 0; + return (status < 0) ? -1 : 0; } -WebRtc_Word16 -ACMAMRwb::SetAMRwbEncoderPackingFormat( - ACMAMRPackingFormat packingFormat) -{ - if((packingFormat != AMRBandwidthEfficient) && - (packingFormat != AMROctetAlligned) && - (packingFormat != AMRFileStorage)) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "Invalid AMRwb encoder packing-format."); - return -1; - } - else - { - - if(WebRtcAmrWb_EncodeBitmode(_encoderInstPtr, - packingFormat) < 0) - { - return -1; - } - else - { - _encoderPackingFormat = packingFormat; - return 0; - } - } +WebRtc_Word16 ACMAMRwb::InternalInitDecoder( + WebRtcACMCodecParams* /* codecParams */) { + WebRtc_Word16 status = WebRtcAmrWb_DecodeBitmode(_decoderInstPtr, + _decoderPackingFormat); + status += ((WebRtcAmrWb_DecoderInit(_decoderInstPtr) < 0) ? -1 : 0); + return (status < 0) ? -1 : 0; } -ACMAMRPackingFormat -ACMAMRwb::AMRwbEncoderPackingFormat() const -{ - return _encoderPackingFormat; +WebRtc_Word32 ACMAMRwb::CodecDef(WebRtcNetEQ_CodecDef& codecDef, + const CodecInst& codecInst) { + if (!_decoderInitialized) { + return -1; + } + + // Fill up the structure by calling + // "SET_CODEC_PAR" & "SET_AMRWB_FUNCTION." + // Then call NetEQ to add the codec to it's + // database. + SET_CODEC_PAR((codecDef), kDecoderAMRWB, codecInst.pltype, _decoderInstPtr, + 16000); + SET_AMRWB_FUNCTIONS((codecDef)); + return 0; +} + +ACMGenericCodec* ACMAMRwb::CreateInstance(void) { + return NULL; +} + +WebRtc_Word16 ACMAMRwb::InternalCreateEncoder() { + return WebRtcAmrWb_CreateEnc(&_encoderInstPtr); +} + +void ACMAMRwb::DestructEncoderSafe() { + if (_encoderInstPtr != NULL) { + WebRtcAmrWb_FreeEnc(_encoderInstPtr); + _encoderInstPtr = NULL; + } + // there is no encoder set the following + _encoderExist = false; + _encoderInitialized = false; + _encodingMode = -1; // invalid value + _encodingRate = 0; +} + +WebRtc_Word16 ACMAMRwb::InternalCreateDecoder() { + return WebRtcAmrWb_CreateDec(&_decoderInstPtr); +} + +void ACMAMRwb::DestructDecoderSafe() { + if (_decoderInstPtr != NULL) { + WebRtcAmrWb_FreeDec(_decoderInstPtr); + _decoderInstPtr = NULL; + } + // there is no encoder instance set the followings + _decoderExist = false; + _decoderInitialized = false; +} + +WebRtc_Word16 ACMAMRwb::SetBitRateSafe(const WebRtc_Word32 rate) { + switch (rate) { + case 7000: { + _encodingMode = AMRWB_MODE_7k; + _encodingRate = 7000; + break; + } + case 9000: { + _encodingMode = AMRWB_MODE_9k; + _encodingRate = 9000; + break; + } + case 12000: { + _encodingMode = AMRWB_MODE_12k; + _encodingRate = 12000; + break; + } + case 14000: { + _encodingMode = AMRWB_MODE_14k; + _encodingRate = 14000; + break; + } + case 16000: { + _encodingMode = AMRWB_MODE_16k; + _encodingRate = 16000; + break; + } + case 18000: { + _encodingMode = AMRWB_MODE_18k; + _encodingRate = 18000; + break; + } + case 20000: { + _encodingMode = AMRWB_MODE_20k; + _encodingRate = 20000; + break; + } + case 23000: { + _encodingMode = AMRWB_MODE_23k; + _encodingRate = 23000; + break; + } + case 24000: { + _encodingMode = AMRWB_MODE_24k; + _encodingRate = 24000; + break; + } + default: { + return -1; + } + } + return 0; +} + +void ACMAMRwb::InternalDestructEncoderInst(void* ptrInst) { + if (ptrInst != NULL) { + WebRtcAmrWb_FreeEnc(static_cast(ptrInst)); + } + return; +} + +WebRtc_Word16 ACMAMRwb::SetAMRwbEncoderPackingFormat( + ACMAMRPackingFormat packingFormat) { + if ((packingFormat != AMRBandwidthEfficient) && + (packingFormat != AMROctetAlligned) && + (packingFormat != AMRFileStorage)) { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "Invalid AMRwb encoder packing-format."); + return -1; + } else { + if (WebRtcAmrWb_EncodeBitmode(_encoderInstPtr, packingFormat) < 0) { + return -1; + } else { + _encoderPackingFormat = packingFormat; + return 0; + } + } +} + +ACMAMRPackingFormat ACMAMRwb::AMRwbEncoderPackingFormat() const { + return _encoderPackingFormat; } WebRtc_Word16 ACMAMRwb::SetAMRwbDecoderPackingFormat( - ACMAMRPackingFormat packingFormat) -{ - if((packingFormat != AMRBandwidthEfficient) && - (packingFormat != AMROctetAlligned) && - (packingFormat != AMRFileStorage)) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "Invalid AMRwb decoder packing-format."); - return -1; - } - else - { - if(WebRtcAmrWb_DecodeBitmode(_decoderInstPtr, - packingFormat) < 0) - { - return -1; - } - else - { - _decoderPackingFormat = packingFormat; - return 0; - } + ACMAMRPackingFormat packingFormat) { + if ((packingFormat != AMRBandwidthEfficient) && + (packingFormat != AMROctetAlligned) && + (packingFormat != AMRFileStorage)) { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "Invalid AMRwb decoder packing-format."); + return -1; + } else { + if (WebRtcAmrWb_DecodeBitmode(_decoderInstPtr, packingFormat) < 0) { + return -1; + } else { + _decoderPackingFormat = packingFormat; + return 0; } + } } -ACMAMRPackingFormat -ACMAMRwb::AMRwbDecoderPackingFormat() const -{ - return _decoderPackingFormat; +ACMAMRPackingFormat ACMAMRwb::AMRwbDecoderPackingFormat() const { + return _decoderPackingFormat; } -WebRtc_Word16 -ACMAMRwb::UnregisterFromNetEqSafe( - ACMNetEQ* netEq, - WebRtc_Word16 payloadType) -{ - if(payloadType != _decoderParams.codecInstant.pltype) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "Cannot unregister codec %s given payload-type %d does not match \ -the stored payload type", - _decoderParams.codecInstant.plname, - payloadType, - _decoderParams.codecInstant.pltype); - return -1; - } - return netEq->RemoveCodec(kDecoderAMRWB); +WebRtc_Word16 ACMAMRwb::UnregisterFromNetEqSafe(ACMNetEQ* netEq, + WebRtc_Word16 payloadType) { + if (payloadType != _decoderParams.codecInstant.pltype) { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "Cannot unregister codec %s given payload-type %d does not" + "match the stored payload type", + _decoderParams.codecInstant.plname, payloadType, + _decoderParams.codecInstant.pltype); + return -1; + } + return netEq->RemoveCodec(kDecoderAMRWB); } #endif diff --git a/src/modules/audio_coding/main/source/acm_amrwb.h b/src/modules/audio_coding/main/source/acm_amrwb.h index ba3a4b495..775f07f1f 100644 --- a/src/modules/audio_coding/main/source/acm_amrwb.h +++ b/src/modules/audio_coding/main/source/acm_amrwb.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_AMRWB_H -#define ACM_AMRWB_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_AMRWB_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_AMRWB_H_ #include "acm_generic_codec.h" @@ -21,77 +21,67 @@ namespace webrtc { enum ACMAMRPackingFormat; -class ACMAMRwb : public ACMGenericCodec -{ -public: - ACMAMRwb(WebRtc_Word16 codecID); - ~ACMAMRwb(); - // for FEC - ACMGenericCodec* CreateInstance(void); +class ACMAMRwb: public ACMGenericCodec { + public: + ACMAMRwb(WebRtc_Word16 codecID); + ~ACMAMRwb(); + // for FEC + ACMGenericCodec* CreateInstance(void); - WebRtc_Word16 InternalEncode( - WebRtc_UWord8* bitstream, - WebRtc_Word16* bitStreamLenByte); + WebRtc_Word16 InternalEncode(WebRtc_UWord8* bitstream, + WebRtc_Word16* bitStreamLenByte); - WebRtc_Word16 InternalInitEncoder( - WebRtcACMCodecParams *codecParams); + WebRtc_Word16 InternalInitEncoder(WebRtcACMCodecParams* codecParams); - WebRtc_Word16 InternalInitDecoder( - WebRtcACMCodecParams *codecParams); + WebRtc_Word16 InternalInitDecoder(WebRtcACMCodecParams* codecParams); - WebRtc_Word16 SetAMRwbEncoderPackingFormat( - const ACMAMRPackingFormat packingFormat); + WebRtc_Word16 SetAMRwbEncoderPackingFormat( + const ACMAMRPackingFormat packingFormat); - ACMAMRPackingFormat AMRwbEncoderPackingFormat() const; + ACMAMRPackingFormat AMRwbEncoderPackingFormat() const; - WebRtc_Word16 SetAMRwbDecoderPackingFormat( - const ACMAMRPackingFormat packingFormat); + WebRtc_Word16 SetAMRwbDecoderPackingFormat( + const ACMAMRPackingFormat packingFormat); - ACMAMRPackingFormat AMRwbDecoderPackingFormat() const; + ACMAMRPackingFormat AMRwbDecoderPackingFormat() const; -protected: - WebRtc_Word16 DecodeSafe( - WebRtc_UWord8* bitStream, - WebRtc_Word16 bitStreamLenByte, - WebRtc_Word16* audio, - WebRtc_Word16* audioSamples, - WebRtc_Word8* speechType); + protected: + WebRtc_Word16 DecodeSafe(WebRtc_UWord8* bitStream, + WebRtc_Word16 bitStreamLenByte, + WebRtc_Word16* audio, WebRtc_Word16* audioSamples, + WebRtc_Word8* speechType); - WebRtc_Word32 CodecDef( - WebRtcNetEQ_CodecDef& codecDef, - const CodecInst& codecInst); + WebRtc_Word32 CodecDef(WebRtcNetEQ_CodecDef& codecDef, + const CodecInst& codecInst); - void DestructEncoderSafe(); + void DestructEncoderSafe(); - void DestructDecoderSafe(); + void DestructDecoderSafe(); - WebRtc_Word16 InternalCreateEncoder(); - - WebRtc_Word16 InternalCreateDecoder(); - - void InternalDestructEncoderInst( - void* ptrInst); + WebRtc_Word16 InternalCreateEncoder(); - WebRtc_Word16 SetBitRateSafe( - const WebRtc_Word32 rate); - - WebRtc_Word16 EnableDTX(); - - WebRtc_Word16 DisableDTX(); + WebRtc_Word16 InternalCreateDecoder(); - WebRtc_Word16 UnregisterFromNetEqSafe( - ACMNetEQ* netEq, - WebRtc_Word16 payloadType); + void InternalDestructEncoderInst(void* ptrInst); - AMRWB_encinst_t_* _encoderInstPtr; - AMRWB_decinst_t_* _decoderInstPtr; + WebRtc_Word16 SetBitRateSafe(const WebRtc_Word32 rate); - WebRtc_Word16 _encodingMode; - WebRtc_Word16 _encodingRate; - ACMAMRPackingFormat _encoderPackingFormat; - ACMAMRPackingFormat _decoderPackingFormat; + WebRtc_Word16 EnableDTX(); + + WebRtc_Word16 DisableDTX(); + + WebRtc_Word16 UnregisterFromNetEqSafe(ACMNetEQ* netEq, + WebRtc_Word16 payloadType); + + AMRWB_encinst_t_* _encoderInstPtr; + AMRWB_decinst_t_* _decoderInstPtr; + + WebRtc_Word16 _encodingMode; + WebRtc_Word16 _encodingRate; + ACMAMRPackingFormat _encoderPackingFormat; + ACMAMRPackingFormat _decoderPackingFormat; }; } // namespace webrtc -#endif // ACM_AMRWB_H +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_AMRWB_H_ diff --git a/src/modules/audio_coding/main/source/acm_cng.cc b/src/modules/audio_coding/main/source/acm_cng.cc index 606fb8a23..1bda752e3 100644 --- a/src/modules/audio_coding/main/source/acm_cng.cc +++ b/src/modules/audio_coding/main/source/acm_cng.cc @@ -17,197 +17,141 @@ #include "webrtc_neteq.h" #include "webrtc_neteq_help_macros.h" -namespace webrtc -{ +namespace webrtc { -ACMCNG::ACMCNG(WebRtc_Word16 codecID) -{ +ACMCNG::ACMCNG(WebRtc_Word16 codecID) { + _encoderInstPtr = NULL; + _decoderInstPtr = NULL; + _codecID = codecID; + _sampFreqHz = ACMCodecDB::CodecFreq(_codecID); + return; +} + +ACMCNG::~ACMCNG() { + if (_encoderInstPtr != NULL) { + WebRtcCng_FreeEnc(_encoderInstPtr); _encoderInstPtr = NULL; + } + if (_decoderInstPtr != NULL) { + WebRtcCng_FreeDec(_decoderInstPtr); _decoderInstPtr = NULL; - _codecID = codecID; - _sampFreqHz = ACMCodecDB::CodecFreq(_codecID); - return; + } + return; } - -ACMCNG::~ACMCNG() -{ - if(_encoderInstPtr != NULL) - { - WebRtcCng_FreeEnc(_encoderInstPtr); - _encoderInstPtr = NULL; - } - if(_decoderInstPtr != NULL) - { - WebRtcCng_FreeDec(_decoderInstPtr); - _decoderInstPtr = NULL; - } - return; -} - - // CNG is not like a regular encoder, this function // should not be called normally // instead the following function is called from inside // ACMGenericCodec::ProcessFrameVADDTX -WebRtc_Word16 -ACMCNG::InternalEncode( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16* /* bitStreamLenByte */) -{ - return -1; +WebRtc_Word16 ACMCNG::InternalEncode(WebRtc_UWord8* /* bitStream */, + WebRtc_Word16* /* bitStreamLenByte */) { + return -1; } -WebRtc_Word16 -ACMCNG::DecodeSafe( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, - WebRtc_Word16* /* audio */, - WebRtc_Word16* /* audioSamples */, - WebRtc_Word8* /* speechType */) -{ - return 0; +WebRtc_Word16 ACMCNG::DecodeSafe(WebRtc_UWord8* /* bitStream */, + WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16* /* audio */, + WebRtc_Word16* /* audioSamples */, + WebRtc_Word8* /* speechType */) { + return 0; } - // CNG is not like a regular encoder, // this function should not be called normally // instead the following function is called from inside // ACMGenericCodec::ProcessFrameVADDTX -WebRtc_Word16 -ACMCNG::InternalInitEncoder( - WebRtcACMCodecParams* /* codecParams */) -{ +WebRtc_Word16 ACMCNG::InternalInitEncoder( + WebRtcACMCodecParams* /* codecParams */) { + return -1; +} + +WebRtc_Word16 ACMCNG::InternalInitDecoder( + WebRtcACMCodecParams* /* codecParams */) { + return WebRtcCng_InitDec(_decoderInstPtr); +} + +WebRtc_Word32 ACMCNG::CodecDef(WebRtcNetEQ_CodecDef& codecDef, + const CodecInst& codecInst) { + if (!_decoderInitialized) { + // TODO (tlegrand): log error return -1; + } + // Fill up the structure by calling + // "SET_CODEC_PAR" & "SET_CNG_FUNCTION." + // Then return the structure back to NetEQ to add the codec to it's + // database. + + if (_sampFreqHz == 8000 || _sampFreqHz == 16000 || _sampFreqHz == 32000) { + SET_CODEC_PAR((codecDef), kDecoderCNG, codecInst.pltype, + _decoderInstPtr, _sampFreqHz); + SET_CNG_FUNCTIONS((codecDef)); + return 0; + } else { + return -1; + } } - -WebRtc_Word16 -ACMCNG::InternalInitDecoder( - WebRtcACMCodecParams* /* codecParams */) -{ - return WebRtcCng_InitDec(_decoderInstPtr); +ACMGenericCodec* ACMCNG::CreateInstance(void) { + return NULL; } - -WebRtc_Word32 -ACMCNG::CodecDef( - WebRtcNetEQ_CodecDef& codecDef, - const CodecInst& codecInst) -{ - if (!_decoderInitialized) - { - // TODO (tlegrand): log error - return -1; - } - // Fill up the structure by calling - // "SET_CODEC_PAR" & "SET_CNG_FUNCTION." - // Then return the structure back to NetEQ to add the codec to it's - // database. - - if (_sampFreqHz == 8000 || _sampFreqHz == 16000 || _sampFreqHz == 32000) - { - SET_CODEC_PAR((codecDef), kDecoderCNG, codecInst.pltype, - _decoderInstPtr, _sampFreqHz); - SET_CNG_FUNCTIONS((codecDef)); - return 0; - } - else - { - return -1; - } +WebRtc_Word16 ACMCNG::InternalCreateEncoder() { + if (WebRtcCng_CreateEnc(&_encoderInstPtr) < 0) { + _encoderInstPtr = NULL; + return -1; + } else { + return 0; + } } - -ACMGenericCodec* ACMCNG::CreateInstance(void) -{ - return NULL; +void ACMCNG::DestructEncoderSafe() { + if (_encoderInstPtr != NULL) { + WebRtcCng_FreeEnc(_encoderInstPtr); + _encoderInstPtr = NULL; + } + _encoderExist = false; + _encoderInitialized = false; } - -WebRtc_Word16 -ACMCNG::InternalCreateEncoder() -{ - if(WebRtcCng_CreateEnc(&_encoderInstPtr) < 0) - { - _encoderInstPtr = NULL; - return -1; - } - else - { - return 0; - } +WebRtc_Word16 ACMCNG::InternalCreateDecoder() { + if (WebRtcCng_CreateDec(&_decoderInstPtr) < 0) { + _decoderInstPtr = NULL; + return -1; + } else { + return 0; + } } - -void -ACMCNG::DestructEncoderSafe() -{ - if(_encoderInstPtr != NULL) - { - WebRtcCng_FreeEnc(_encoderInstPtr); - _encoderInstPtr = NULL; - } - _encoderExist = false; - _encoderInitialized = false; +void ACMCNG::DestructDecoderSafe() { + if (_decoderInstPtr != NULL) { + WebRtcCng_FreeDec(_decoderInstPtr); + _decoderInstPtr = NULL; + } + _decoderExist = false; + _decoderInitialized = false; } - -WebRtc_Word16 -ACMCNG::InternalCreateDecoder() -{ - if(WebRtcCng_CreateDec(&_decoderInstPtr) < 0) - { - _decoderInstPtr = NULL; - return -1; - } - else - { - return 0; - } +void ACMCNG::InternalDestructEncoderInst(void* ptrInst) { + if (ptrInst != NULL) { + WebRtcCng_FreeEnc(static_cast(ptrInst)); + } + return; } - -void -ACMCNG::DestructDecoderSafe() -{ - if(_decoderInstPtr != NULL) - { - WebRtcCng_FreeDec(_decoderInstPtr); - _decoderInstPtr = NULL; - } - _decoderExist = false; - _decoderInitialized = false; -} - - -void -ACMCNG::InternalDestructEncoderInst( - void* ptrInst) -{ - if(ptrInst != NULL) - { - WebRtcCng_FreeEnc((CNG_enc_inst*)ptrInst); - } - return; -} - -WebRtc_Word16 -ACMCNG::UnregisterFromNetEqSafe( - ACMNetEQ* netEq, - WebRtc_Word16 payloadType) -{ - if(payloadType != _decoderParams.codecInstant.pltype) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "Cannot unregister codec %s given payload-type %d does not match \ -the stored payload type", - _decoderParams.codecInstant.plname, - payloadType, - _decoderParams.codecInstant.pltype); - return -1; - } - return netEq->RemoveCodec(kDecoderCNG); +WebRtc_Word16 ACMCNG::UnregisterFromNetEqSafe(ACMNetEQ* netEq, + WebRtc_Word16 payloadType) { + if (payloadType != _decoderParams.codecInstant.pltype) { + WEBRTC_TRACE( + webrtc::kTraceError, + webrtc::kTraceAudioCoding, + _uniqueID, + "Cannot unregister codec %s given payload-type %d does not " + "match the stored payload type", + _decoderParams.codecInstant.plname, payloadType, + _decoderParams.codecInstant.pltype); + return -1; + } + return netEq->RemoveCodec(kDecoderCNG); } } // namespace webrtc diff --git a/src/modules/audio_coding/main/source/acm_cng.h b/src/modules/audio_coding/main/source/acm_cng.h index 2ceb59f6c..1781b2be9 100644 --- a/src/modules/audio_coding/main/source/acm_cng.h +++ b/src/modules/audio_coding/main/source/acm_cng.h @@ -8,80 +8,66 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_CNG_H -#define ACM_CNG_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_CNG_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_CNG_H_ #include "acm_generic_codec.h" - // forward declaration struct WebRtcCngEncInst; struct WebRtcCngDecInst; -namespace webrtc -{ +namespace webrtc { -class ACMCNG : public ACMGenericCodec -{ -public: - ACMCNG(WebRtc_Word16 codecID); - ~ACMCNG(); - // for FEC - ACMGenericCodec* CreateInstance(void); +class ACMCNG: public ACMGenericCodec { + public: + ACMCNG(WebRtc_Word16 codecID); + ~ACMCNG(); + // for FEC + ACMGenericCodec* CreateInstance(void); - WebRtc_Word16 InternalEncode( - WebRtc_UWord8* bitstream, - WebRtc_Word16* bitStreamLenByte); + WebRtc_Word16 InternalEncode(WebRtc_UWord8* bitstream, + WebRtc_Word16* bitStreamLenByte); - WebRtc_Word16 InternalInitEncoder( - WebRtcACMCodecParams *codecParams); + WebRtc_Word16 InternalInitEncoder(WebRtcACMCodecParams *codecParams); - WebRtc_Word16 InternalInitDecoder( - WebRtcACMCodecParams *codecParams); + WebRtc_Word16 InternalInitDecoder(WebRtcACMCodecParams *codecParams); protected: - WebRtc_Word16 DecodeSafe( - WebRtc_UWord8* bitStream, - WebRtc_Word16 bitStreamLenByte, - WebRtc_Word16* audio, - WebRtc_Word16* audioSamples, - WebRtc_Word8* speechType); + WebRtc_Word16 DecodeSafe(WebRtc_UWord8* bitStream, + WebRtc_Word16 bitStreamLenByte, + WebRtc_Word16* audio, WebRtc_Word16* audioSamples, + WebRtc_Word8* speechType); - WebRtc_Word32 CodecDef( - WebRtcNetEQ_CodecDef& codecDef, - const CodecInst& codecInst); + WebRtc_Word32 CodecDef(WebRtcNetEQ_CodecDef& codecDef, + const CodecInst& codecInst); - void DestructEncoderSafe(); + void DestructEncoderSafe(); - void DestructDecoderSafe(); + void DestructDecoderSafe(); - WebRtc_Word16 InternalCreateEncoder(); + WebRtc_Word16 InternalCreateEncoder(); - WebRtc_Word16 InternalCreateDecoder(); + WebRtc_Word16 InternalCreateDecoder(); - void InternalDestructEncoderInst( - void* ptrInst); + void InternalDestructEncoderInst(void* ptrInst); - WebRtc_Word16 EnableDTX() - { - return -1; - } + WebRtc_Word16 EnableDTX() { + return -1; + } - WebRtc_Word16 DisableDTX() - { - return -1; - } + WebRtc_Word16 DisableDTX() { + return -1; + } - WebRtc_Word16 UnregisterFromNetEqSafe( - ACMNetEQ* netEq, - WebRtc_Word16 payloadType); + WebRtc_Word16 UnregisterFromNetEqSafe(ACMNetEQ* netEq, + WebRtc_Word16 payloadType); - WebRtcCngEncInst* _encoderInstPtr; - WebRtcCngDecInst* _decoderInstPtr; - WebRtc_Word16 _sampFreqHz; + WebRtcCngEncInst* _encoderInstPtr; + WebRtcCngDecInst* _decoderInstPtr; + WebRtc_Word16 _sampFreqHz; }; } // namespace webrtc -#endif // ACM_CNG_H - +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_CNG_H_ diff --git a/src/modules/audio_coding/main/source/acm_common_defs.h b/src/modules/audio_coding/main/source/acm_common_defs.h index 7258fc7c0..fd8dbd6ef 100644 --- a/src/modules/audio_coding/main/source/acm_common_defs.h +++ b/src/modules/audio_coding/main/source/acm_common_defs.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_ACM_COMMON_DEFS_H -#define WEBRTC_ACM_COMMON_DEFS_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_COMMON_DEFS_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_COMMON_DEFS_H_ #include @@ -18,23 +18,21 @@ #include "engine_configurations.h" #include "typedefs.h" - // Checks for enabled codecs, we prevent enabling codecs which are not // compatible. #if ((defined WEBRTC_CODEC_ISAC) && (defined WEBRTC_CODEC_ISACFX)) - # error iSAC and iSACFX codecs cannot be enabled at the same time +#error iSAC and iSACFX codecs cannot be enabled at the same time #endif #ifdef WIN32 - // OS-dependent case-insensitive string comparison - #define STR_CASE_CMP(x,y) ::_stricmp(x,y) +// OS-dependent case-insensitive string comparison +#define STR_CASE_CMP(x,y) ::_stricmp(x,y) #else - // OS-dependent case-insensitive string comparison - #define STR_CASE_CMP(x,y) ::strcasecmp(x,y) +// OS-dependent case-insensitive string comparison +#define STR_CASE_CMP(x,y) ::strcasecmp(x,y) #endif -namespace webrtc -{ +namespace webrtc { // 60 ms is the maximum block size we support. An extra 20 ms is considered // for safety if process() method is not called when it should be, i.e. we @@ -46,16 +44,16 @@ namespace webrtc // audio if the sampling frequency is 8000 Hz (80 samples per block). // Therefore, The size of the buffer where we keep timestamps // is defined as follows -#define TIMESTAMP_BUFFER_SIZE_W32 AUDIO_BUFFER_SIZE_W16/80 +#define TIMESTAMP_BUFFER_SIZE_W32 (AUDIO_BUFFER_SIZE_W16/80) // The maximum size of a payload, that is 60 ms of PCM-16 @ 32 kHz stereo -#define MAX_PAYLOAD_SIZE_BYTE 7680 +#define MAX_PAYLOAD_SIZE_BYTE 7680 // General codec specific defines -#define ISACWB_DEFAULT_RATE 32000 -#define ISACSWB_DEFAULT_RATE 56000 -#define ISACWB_PAC_SIZE 480 -#define ISACSWB_PAC_SIZE 960 +const int kIsacWbDefaultRate = 32000; +const int kIsacSwbDefaultRate = 56000; +const int kIsacPacSize480 = 480; +const int kIsacPacSize960 = 960; // An encoded bit-stream is labeled by one of the following enumerators. // @@ -66,14 +64,13 @@ namespace webrtc // kPassiveDTXWB : Passive audio frame coded by wide-band CN. // kPassiveDTXSWB : Passive audio frame coded by super-wide-band CN. // -enum WebRtcACMEncodingType -{ - kNoEncoding, - kActiveNormalEncoded, - kPassiveNormalEncoded, - kPassiveDTXNB, - kPassiveDTXWB, - kPassiveDTXSWB +enum WebRtcACMEncodingType { + kNoEncoding, + kActiveNormalEncoded, + kPassiveNormalEncoded, + kPassiveDTXNB, + kPassiveDTXWB, + kPassiveDTXSWB }; // A structure which contains codec parameters. For instance, used when @@ -85,12 +82,11 @@ enum WebRtcACMEncodingType // enableVAD : set true to enable VAD. // vadMode : VAD mode, c.f. audio_coding_module_typedefs.h // for possible values. -struct WebRtcACMCodecParams -{ - CodecInst codecInstant; - bool enableDTX; - bool enableVAD; - ACMVADMode vadMode; +struct WebRtcACMCodecParams { + CodecInst codecInstant; + bool enableDTX; + bool enableVAD; + ACMVADMode vadMode; }; // A structure that encapsulates audio buffer and related parameters @@ -104,17 +100,16 @@ struct WebRtcACMCodecParams // lastTimestamp : same as ACMGenericCodec::_lastTimestamp // lastInTimestamp : same as AudioCodingModuleImpl::_lastInTimestamp // -struct WebRtcACMAudioBuff -{ - WebRtc_Word16 inAudio[AUDIO_BUFFER_SIZE_W16]; - WebRtc_Word16 inAudioIxRead; - WebRtc_Word16 inAudioIxWrite; - WebRtc_UWord32 inTimestamp[TIMESTAMP_BUFFER_SIZE_W32]; - WebRtc_Word16 inTimestampIxWrite; - WebRtc_UWord32 lastTimestamp; - WebRtc_UWord32 lastInTimestamp; +struct WebRtcACMAudioBuff { + WebRtc_Word16 inAudio[AUDIO_BUFFER_SIZE_W16]; + WebRtc_Word16 inAudioIxRead; + WebRtc_Word16 inAudioIxWrite; + WebRtc_UWord32 inTimestamp[TIMESTAMP_BUFFER_SIZE_W32]; + WebRtc_Word16 inTimestampIxWrite; + WebRtc_UWord32 lastTimestamp; + WebRtc_UWord32 lastInTimestamp; }; } // namespace webrtc -#endif +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_COMMON_DEFS_H_ diff --git a/src/modules/audio_coding/main/source/acm_dtmf_detection.cc b/src/modules/audio_coding/main/source/acm_dtmf_detection.cc index cab9ea57e..1238e181f 100644 --- a/src/modules/audio_coding/main/source/acm_dtmf_detection.cc +++ b/src/modules/audio_coding/main/source/acm_dtmf_detection.cc @@ -8,57 +8,37 @@ * be found in the AUTHORS file in the root of the source tree. */ - #include "acm_dtmf_detection.h" #include "audio_coding_module_typedefs.h" -namespace webrtc -{ +namespace webrtc { -ACMDTMFDetection::ACMDTMFDetection() -{ +ACMDTMFDetection::ACMDTMFDetection() {} + +ACMDTMFDetection::~ACMDTMFDetection() {} + +WebRtc_Word16 ACMDTMFDetection::Enable(ACMCountries /* cpt */) { + return -1; } - -ACMDTMFDetection::~ACMDTMFDetection() -{ +WebRtc_Word16 ACMDTMFDetection::Disable() { + return -1; } - -WebRtc_Word16 -ACMDTMFDetection::Enable( - ACMCountries /* cpt */) -{ - return -1; -} - - -WebRtc_Word16 -ACMDTMFDetection::Disable() -{ - return -1; -} - - -WebRtc_Word16 -ACMDTMFDetection::Detect( - const WebRtc_Word16* /* inAudioBuff */, +WebRtc_Word16 ACMDTMFDetection::Detect( + const WebRtc_Word16* /* inAudioBuff */, const WebRtc_UWord16 /* inBuffLenWord16 */, - const WebRtc_Word32 /* inFreqHz */, - bool& /* toneDetected */, - WebRtc_Word16& /* tone */) -{ - return -1; + const WebRtc_Word32 /* inFreqHz */, + bool& /* toneDetected */, + WebRtc_Word16& /* tone */) { + return -1; } - -WebRtc_Word16 -ACMDTMFDetection::GetVersion( - WebRtc_Word8* /* version */, +WebRtc_Word16 ACMDTMFDetection::GetVersion( + WebRtc_Word8* /* version */, WebRtc_UWord32& /* remainingBufferInBytes */, - WebRtc_UWord32& /* position */) -{ - return -1; + WebRtc_UWord32& /* position */) { + return -1; } } // namespace webrtc diff --git a/src/modules/audio_coding/main/source/acm_dtmf_detection.h b/src/modules/audio_coding/main/source/acm_dtmf_detection.h index 0142fc904..16aba8445 100644 --- a/src/modules/audio_coding/main/source/acm_dtmf_detection.h +++ b/src/modules/audio_coding/main/source/acm_dtmf_detection.h @@ -8,40 +8,36 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_DTMF_DETECTION_H -#define ACM_DTMF_DETECTION_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_DTMF_DETECTION_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_DTMF_DETECTION_H_ #include "acm_resampler.h" #include "audio_coding_module_typedefs.h" #include "typedefs.h" -namespace webrtc -{ +namespace webrtc { -class ACMDTMFDetection -{ -public: - ACMDTMFDetection(); - ~ACMDTMFDetection(); - WebRtc_Word16 Enable(ACMCountries cpt = ACMDisableCountryDetection); - WebRtc_Word16 Disable(); - WebRtc_Word16 Detect( - const WebRtc_Word16* inAudioBuff, - const WebRtc_UWord16 inBuffLenWord16, - const WebRtc_Word32 inFreqHz, - bool& toneDetected, - WebRtc_Word16& tone); - - static WebRtc_Word16 GetVersion( - WebRtc_Word8* version, - WebRtc_UWord32& remainingBufferInBytes, - WebRtc_UWord32& position); +class ACMDTMFDetection { + public: + ACMDTMFDetection(); + ~ACMDTMFDetection(); + WebRtc_Word16 Enable(ACMCountries cpt = ACMDisableCountryDetection); + WebRtc_Word16 Disable(); + WebRtc_Word16 Detect(const WebRtc_Word16* inAudioBuff, + const WebRtc_UWord16 inBuffLenWord16, + const WebRtc_Word32 inFreqHz, + bool& toneDetected, + WebRtc_Word16& tone); -private: - ACMResampler _resampler; - bool _init; + static WebRtc_Word16 GetVersion(WebRtc_Word8* version, + WebRtc_UWord32& remainingBufferInBytes, + WebRtc_UWord32& position); + + private: + ACMResampler _resampler; + bool _init; }; } // namespace webrtc -#endif // ACM_DTMF_DETECTION_H +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_DTMF_DETECTION_H_ diff --git a/src/modules/audio_coding/main/source/acm_dtmf_playout.cc b/src/modules/audio_coding/main/source/acm_dtmf_playout.cc index 8286cb540..e748f8a51 100644 --- a/src/modules/audio_coding/main/source/acm_dtmf_playout.cc +++ b/src/modules/audio_coding/main/source/acm_dtmf_playout.cc @@ -8,260 +8,177 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "acm_common_defs.h" #include "acm_dtmf_playout.h" +#include "acm_common_defs.h" #include "acm_neteq.h" #include "trace.h" #include "webrtc_neteq.h" #include "webrtc_neteq_help_macros.h" -namespace webrtc -{ +namespace webrtc { #ifndef WEBRTC_CODEC_AVT ACMDTMFPlayout::ACMDTMFPlayout( - WebRtc_Word16 /* codecID */) -{ - return; + WebRtc_Word16 /* codecID */) { + return; } - -ACMDTMFPlayout::~ACMDTMFPlayout() -{ - return; +ACMDTMFPlayout::~ACMDTMFPlayout() { + return; } - -WebRtc_Word16 -ACMDTMFPlayout::InternalEncode( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16* /* bitStreamLenByte */) -{ - return -1; +WebRtc_Word16 ACMDTMFPlayout::InternalEncode( + WebRtc_UWord8* /* bitStream */, + WebRtc_Word16* /* bitStreamLenByte */) { + return -1; } - -WebRtc_Word16 -ACMDTMFPlayout::DecodeSafe( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, - WebRtc_Word16* /* audio */, - WebRtc_Word16* /* audioSamples */, - WebRtc_Word8* /* speechType */) -{ - return -1; +WebRtc_Word16 ACMDTMFPlayout::DecodeSafe(WebRtc_UWord8* /* bitStream */, + WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16* /* audio */, + WebRtc_Word16* /* audioSamples */, + WebRtc_Word8* /* speechType */) { + return -1; } - -WebRtc_Word16 -ACMDTMFPlayout::InternalInitEncoder( - WebRtcACMCodecParams* /* codecParams */) -{ - return -1; +WebRtc_Word16 ACMDTMFPlayout::InternalInitEncoder( + WebRtcACMCodecParams* /* codecParams */) { + return -1; } - -WebRtc_Word16 -ACMDTMFPlayout::InternalInitDecoder( - WebRtcACMCodecParams* /* codecParams */) -{ - return -1; +WebRtc_Word16 ACMDTMFPlayout::InternalInitDecoder( + WebRtcACMCodecParams* /* codecParams */) { + return -1; } - -WebRtc_Word32 -ACMDTMFPlayout::CodecDef( - WebRtcNetEQ_CodecDef& /* codecDef */, - const CodecInst& /* codecInst */) -{ - return -1; +WebRtc_Word32 ACMDTMFPlayout::CodecDef(WebRtcNetEQ_CodecDef& /* codecDef */, + const CodecInst& /* codecInst */) { + return -1; } - -ACMGenericCodec* -ACMDTMFPlayout::CreateInstance(void) -{ - return NULL; +ACMGenericCodec* ACMDTMFPlayout::CreateInstance(void) { + return NULL; } - -WebRtc_Word16 -ACMDTMFPlayout::InternalCreateEncoder() -{ - return -1; +WebRtc_Word16 ACMDTMFPlayout::InternalCreateEncoder() { + return -1; } - -WebRtc_Word16 -ACMDTMFPlayout::InternalCreateDecoder() -{ - return -1; +WebRtc_Word16 ACMDTMFPlayout::InternalCreateDecoder() { + return -1; } - -void -ACMDTMFPlayout::InternalDestructEncoderInst( - void* /* ptrInst */) -{ - return; +void ACMDTMFPlayout::InternalDestructEncoderInst(void* /* ptrInst */) { + return; } -void -ACMDTMFPlayout::DestructEncoderSafe() -{ - return; +void ACMDTMFPlayout::DestructEncoderSafe() { + return; } -void -ACMDTMFPlayout::DestructDecoderSafe() -{ - return; +void ACMDTMFPlayout::DestructDecoderSafe() { + return; } - -WebRtc_Word16 -ACMDTMFPlayout::UnregisterFromNetEqSafe( - ACMNetEQ* /* netEq */, - WebRtc_Word16 /* payloadType */) -{ - return -1; +WebRtc_Word16 ACMDTMFPlayout::UnregisterFromNetEqSafe( + ACMNetEQ* /* netEq */, + WebRtc_Word16 /* payloadType */) { + return -1; } #else //===================== Actual Implementation ======================= -ACMDTMFPlayout::ACMDTMFPlayout( - WebRtc_Word16 codecID) -{ - _codecID = codecID; +ACMDTMFPlayout::ACMDTMFPlayout(WebRtc_Word16 codecID) { + _codecID = codecID; } - -ACMDTMFPlayout::~ACMDTMFPlayout() -{ - return; +ACMDTMFPlayout::~ACMDTMFPlayout() { + return; } - -WebRtc_Word16 -ACMDTMFPlayout::InternalEncode( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16* /* bitStreamLenByte */) -{ - return 0; +WebRtc_Word16 ACMDTMFPlayout::InternalEncode( + WebRtc_UWord8* /* bitStream */, + WebRtc_Word16* /* bitStreamLenByte */) { + return 0; } - -WebRtc_Word16 -ACMDTMFPlayout::DecodeSafe( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, - WebRtc_Word16* /* audio */, - WebRtc_Word16* /* audioSamples */, - WebRtc_Word8* /* speechType */) -{ - return 0; +WebRtc_Word16 ACMDTMFPlayout::DecodeSafe(WebRtc_UWord8* /* bitStream */, + WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16* /* audio */, + WebRtc_Word16* /* audioSamples */, + WebRtc_Word8* /* speechType */) { + return 0; } - -WebRtc_Word16 -ACMDTMFPlayout::InternalInitEncoder( - WebRtcACMCodecParams* /* codecParams */) -{ - // This codec does not need initialization, - // DTMFPlayout has no instance - return 0; +WebRtc_Word16 ACMDTMFPlayout::InternalInitEncoder( + WebRtcACMCodecParams* /* codecParams */) { + // This codec does not need initialization, + // DTMFPlayout has no instance + return 0; } - -WebRtc_Word16 -ACMDTMFPlayout::InternalInitDecoder( - WebRtcACMCodecParams* /* codecParams */) -{ - // This codec does not need initialization, - // DTMFPlayout has no instance - return 0; +WebRtc_Word16 ACMDTMFPlayout::InternalInitDecoder( + WebRtcACMCodecParams* /* codecParams */) { + // This codec does not need initialization, + // DTMFPlayout has no instance + return 0; } - -WebRtc_Word32 -ACMDTMFPlayout::CodecDef( - WebRtcNetEQ_CodecDef& codecDef, - const CodecInst& codecInst) -{ - // Fill up the structure by calling - // "SET_CODEC_PAR" & "SET_AVT_FUNCTION." - // Then call NetEQ to add the codec to it's - // database. - SET_CODEC_PAR((codecDef), kDecoderAVT, codecInst.pltype, NULL, 8000); - SET_AVT_FUNCTIONS((codecDef)); - return 0; +WebRtc_Word32 ACMDTMFPlayout::CodecDef(WebRtcNetEQ_CodecDef& codecDef, + const CodecInst& codecInst) { + // Fill up the structure by calling + // "SET_CODEC_PAR" & "SET_AVT_FUNCTION." + // Then call NetEQ to add the codec to it's + // database. + SET_CODEC_PAR((codecDef), kDecoderAVT, codecInst.pltype, NULL, 8000); + SET_AVT_FUNCTIONS((codecDef)); + return 0; } - -ACMGenericCodec* -ACMDTMFPlayout::CreateInstance(void) -{ - return NULL; +ACMGenericCodec* ACMDTMFPlayout::CreateInstance(void) { + return NULL; } - -WebRtc_Word16 -ACMDTMFPlayout::InternalCreateEncoder() -{ - // DTMFPlayout has no instance - return 0; +WebRtc_Word16 ACMDTMFPlayout::InternalCreateEncoder() { + // DTMFPlayout has no instance + return 0; } - -WebRtc_Word16 -ACMDTMFPlayout::InternalCreateDecoder() -{ - // DTMFPlayout has no instance - return 0; +WebRtc_Word16 ACMDTMFPlayout::InternalCreateDecoder() { + // DTMFPlayout has no instance + return 0; } - -void -ACMDTMFPlayout::InternalDestructEncoderInst( - void* /* ptrInst */) -{ - // DTMFPlayout has no instance - return; +void ACMDTMFPlayout::InternalDestructEncoderInst(void* /* ptrInst */) { + // DTMFPlayout has no instance + return; } - -void -ACMDTMFPlayout::DestructEncoderSafe() -{ - // DTMFPlayout has no instance - return; +void ACMDTMFPlayout::DestructEncoderSafe() { + // DTMFPlayout has no instance + return; } -void -ACMDTMFPlayout::DestructDecoderSafe() -{ - // DTMFPlayout has no instance - return; +void ACMDTMFPlayout::DestructDecoderSafe() { + // DTMFPlayout has no instance + return; } - -WebRtc_Word16 -ACMDTMFPlayout::UnregisterFromNetEqSafe( +WebRtc_Word16 ACMDTMFPlayout::UnregisterFromNetEqSafe( ACMNetEQ* netEq, - WebRtc_Word16 payloadType) -{ - if(payloadType != _decoderParams.codecInstant.pltype) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "Cannot unregister codec %s given payload-type %d does not match \ -the stored payload type", - _decoderParams.codecInstant.plname, - payloadType, - _decoderParams.codecInstant.pltype); - return -1; - } - return netEq->RemoveCodec(kDecoderAVT); + WebRtc_Word16 payloadType) { + if (payloadType != _decoderParams.codecInstant.pltype) { + WEBRTC_TRACE(webrtc::kTraceError, + webrtc::kTraceAudioCoding, + _uniqueID, + "Cannot unregister codec %s given payload-type %d does not " + "match the stored payload type", + _decoderParams.codecInstant.plname, payloadType, + _decoderParams.codecInstant.pltype); + return -1; + } + return netEq->RemoveCodec(kDecoderAVT); } #endif diff --git a/src/modules/audio_coding/main/source/acm_dtmf_playout.h b/src/modules/audio_coding/main/source/acm_dtmf_playout.h index 9f38baa33..a75d6918c 100644 --- a/src/modules/audio_coding/main/source/acm_dtmf_playout.h +++ b/src/modules/audio_coding/main/source/acm_dtmf_playout.h @@ -8,61 +8,50 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_DTMF_PLAYOUT_H -#define ACM_DTMF_PLAYOUT_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_DTMF_PLAYOUT_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_DTMF_PLAYOUT_H_ #include "acm_generic_codec.h" -namespace webrtc -{ +namespace webrtc { -class ACMDTMFPlayout : public ACMGenericCodec -{ -public: - ACMDTMFPlayout(WebRtc_Word16 codecID); - ~ACMDTMFPlayout(); - // for FEC - ACMGenericCodec* CreateInstance(void); +class ACMDTMFPlayout: public ACMGenericCodec { + public: + ACMDTMFPlayout(WebRtc_Word16 codecID); + ~ACMDTMFPlayout(); + // for FEC + ACMGenericCodec* CreateInstance(void); - WebRtc_Word16 InternalEncode( - WebRtc_UWord8* bitstream, - WebRtc_Word16* bitStreamLenByte); + WebRtc_Word16 InternalEncode(WebRtc_UWord8* bitstream, + WebRtc_Word16* bitStreamLenByte); - WebRtc_Word16 InternalInitEncoder( - WebRtcACMCodecParams *codecParams); + WebRtc_Word16 InternalInitEncoder(WebRtcACMCodecParams *codecParams); - WebRtc_Word16 InternalInitDecoder( - WebRtcACMCodecParams *codecParams); + WebRtc_Word16 InternalInitDecoder(WebRtcACMCodecParams *codecParams); -protected: - WebRtc_Word16 DecodeSafe( - WebRtc_UWord8* bitStream, - WebRtc_Word16 bitStreamLenByte, - WebRtc_Word16* audio, - WebRtc_Word16* audioSamples, - WebRtc_Word8* speechType); + protected: + WebRtc_Word16 DecodeSafe(WebRtc_UWord8* bitStream, + WebRtc_Word16 bitStreamLenByte, + WebRtc_Word16* audio, WebRtc_Word16* audioSamples, + WebRtc_Word8* speechType); - WebRtc_Word32 CodecDef( - WebRtcNetEQ_CodecDef& codecDef, - const CodecInst& codecInst); + WebRtc_Word32 CodecDef(WebRtcNetEQ_CodecDef& codecDef, + const CodecInst& codecInst); - void DestructEncoderSafe(); - - void DestructDecoderSafe(); - - WebRtc_Word16 InternalCreateEncoder(); - - WebRtc_Word16 InternalCreateDecoder(); - - WebRtc_Word16 UnregisterFromNetEqSafe( - ACMNetEQ* netEq, - WebRtc_Word16 payloadType); + void DestructEncoderSafe(); - void InternalDestructEncoderInst( - void* ptrInst); + void DestructDecoderSafe(); + + WebRtc_Word16 InternalCreateEncoder(); + + WebRtc_Word16 InternalCreateDecoder(); + + WebRtc_Word16 UnregisterFromNetEqSafe(ACMNetEQ* netEq, + WebRtc_Word16 payloadType); + + void InternalDestructEncoderInst(void* ptrInst); }; } // namespace webrtc -#endif // ACM_DTMF_PLAYOUT_H - +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_DTMF_PLAYOUT_H_ diff --git a/src/modules/audio_coding/main/source/acm_g722.cc b/src/modules/audio_coding/main/source/acm_g722.cc index 8f00231c6..46de35452 100644 --- a/src/modules/audio_coding/main/source/acm_g722.cc +++ b/src/modules/audio_coding/main/source/acm_g722.cc @@ -21,427 +21,307 @@ namespace webrtc { #ifndef WEBRTC_CODEC_G722 -ACMG722::ACMG722( - WebRtc_Word16 /* codecID */) -{ - return; +ACMG722::ACMG722(WebRtc_Word16 /* codecID */) { + return; } - -ACMG722::~ACMG722() -{ - return; +ACMG722::~ACMG722() { + return; } - -WebRtc_Word32 -ACMG722::Add10MsDataSafe( - const WebRtc_UWord32 /* timestamp */, - const WebRtc_Word16* /* data */, - const WebRtc_UWord16 /* lengthSmpl */, - const WebRtc_UWord8 /* audioChannel */) -{ - return -1; +WebRtc_Word32 ACMG722::Add10MsDataSafe(const WebRtc_UWord32 /* timestamp */, + const WebRtc_Word16* /* data */, + const WebRtc_UWord16 /* lengthSmpl */, + const WebRtc_UWord8 /* audioChannel */) { + return -1; } - -WebRtc_Word16 -ACMG722::InternalEncode( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16* /* bitStreamLenByte */) -{ - return -1; +WebRtc_Word16 ACMG722::InternalEncode(WebRtc_UWord8* /* bitStream */, + WebRtc_Word16* /* bitStreamLenByte */) { + return -1; } - -WebRtc_Word16 -ACMG722::DecodeSafe( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, - WebRtc_Word16* /* audio */, - WebRtc_Word16* /* audioSamples */, - WebRtc_Word8* /* speechType */) -{ - return -1; +WebRtc_Word16 ACMG722::DecodeSafe(WebRtc_UWord8* /* bitStream */, + WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16* /* audio */, + WebRtc_Word16* /* audioSamples */, + WebRtc_Word8* /* speechType */) { + return -1; } - -WebRtc_Word16 -ACMG722::InternalInitEncoder( - WebRtcACMCodecParams* /* codecParams */) -{ - return -1; +WebRtc_Word16 ACMG722::InternalInitEncoder( + WebRtcACMCodecParams* /* codecParams */) { + return -1; } - -WebRtc_Word16 -ACMG722::InternalInitDecoder( - WebRtcACMCodecParams* /* codecParams */) -{ - return -1; +WebRtc_Word16 ACMG722::InternalInitDecoder( + WebRtcACMCodecParams* /* codecParams */) { + return -1; } - -WebRtc_Word32 -ACMG722::CodecDef( - WebRtcNetEQ_CodecDef& /* codecDef */, - const CodecInst& /* codecInst */) -{ - return -1; +WebRtc_Word32 ACMG722::CodecDef(WebRtcNetEQ_CodecDef& /* codecDef */, + const CodecInst& /* codecInst */) { + return -1; } - -ACMGenericCodec* -ACMG722::CreateInstance(void) -{ - return NULL; +ACMGenericCodec* ACMG722::CreateInstance(void) { + return NULL; } - -WebRtc_Word16 -ACMG722::InternalCreateEncoder() -{ - return -1; +WebRtc_Word16 ACMG722::InternalCreateEncoder() { + return -1; } - -void -ACMG722::DestructEncoderSafe() -{ - return; +void ACMG722::DestructEncoderSafe() { + return; } - -WebRtc_Word16 -ACMG722::InternalCreateDecoder() -{ - return -1; +WebRtc_Word16 ACMG722::InternalCreateDecoder() { + return -1; } - -void -ACMG722::DestructDecoderSafe() -{ - return; +void ACMG722::DestructDecoderSafe() { + return; } - -void -ACMG722::InternalDestructEncoderInst( - void* /* ptrInst */) -{ - return; +void ACMG722::InternalDestructEncoderInst(void* /* ptrInst */) { + return; } - -WebRtc_Word16 -ACMG722::UnregisterFromNetEqSafe( - ACMNetEQ* /* netEq */, - WebRtc_Word16 /* payloadType */) -{ - return -1; +WebRtc_Word16 ACMG722::UnregisterFromNetEqSafe( + ACMNetEQ* /* netEq */, + WebRtc_Word16 /* payloadType */) { + return -1; } - #else //===================== Actual Implementation ======================= - // Encoder and decoder memory struct ACMG722EncStr { - G722EncInst* inst; // instance for left channel in case of stereo - G722EncInst* instRight; // instance for right channel in case of stereo + G722EncInst* inst; // instance for left channel in case of stereo + G722EncInst* instRight; // instance for right channel in case of stereo }; struct ACMG722DecStr { - G722DecInst* inst; // instance for left channel in case of stereo - G722DecInst* instRight; // instance for right channel in case of stereo + G722DecInst* inst; // instance for left channel in case of stereo + G722DecInst* instRight; // instance for right channel in case of stereo }; -ACMG722::ACMG722( - WebRtc_Word16 codecID) -{ - // Encoder - _ptrEncStr = new ACMG722EncStr; - if(_ptrEncStr != NULL) - { - _ptrEncStr->inst = NULL; - _ptrEncStr->instRight = NULL; +ACMG722::ACMG722(WebRtc_Word16 codecID) { + // Encoder + _ptrEncStr = new ACMG722EncStr; + if (_ptrEncStr != NULL) { + _ptrEncStr->inst = NULL; + _ptrEncStr->instRight = NULL; + } + // Decoder + _ptrDecStr = new ACMG722DecStr; + if (_ptrDecStr != NULL) { + _ptrDecStr->inst = NULL; + _ptrDecStr->instRight = NULL; // Not used + } + _codecID = codecID; + return; +} + +ACMG722::~ACMG722() { + // Encoder + if (_ptrEncStr != NULL) { + if (_ptrEncStr->inst != NULL) { + WebRtcG722_FreeEncoder(_ptrEncStr->inst); + _ptrEncStr->inst = NULL; } - // Decoder - _ptrDecStr = new ACMG722DecStr; - if(_ptrDecStr != NULL) - { - _ptrDecStr->inst = NULL; - _ptrDecStr->instRight = NULL; // Not used + if (_ptrEncStr->instRight != NULL) { + WebRtcG722_FreeEncoder(_ptrEncStr->instRight); + _ptrEncStr->instRight = NULL; } - _codecID = codecID; - return; -} - - -ACMG722::~ACMG722() -{ - if(_ptrEncStr != NULL) - { - if(_ptrEncStr->inst != NULL) - { - WebRtcG722_FreeEncoder(_ptrEncStr->inst); - _ptrEncStr->inst = NULL; - } - - if(_ptrEncStr->instRight != NULL) - { - WebRtcG722_FreeEncoder(_ptrEncStr->instRight); - _ptrEncStr->instRight = NULL; - } - - delete _ptrEncStr; - _ptrEncStr = NULL; + delete _ptrEncStr; + _ptrEncStr = NULL; + } + // Decoder + if (_ptrDecStr != NULL) { + if (_ptrDecStr->inst != NULL) { + WebRtcG722_FreeDecoder(_ptrDecStr->inst); + _ptrDecStr->inst = NULL; } - if(_ptrDecStr != NULL) - { - if(_ptrDecStr->inst != NULL) - { - WebRtcG722_FreeDecoder(_ptrDecStr->inst); - _ptrDecStr->inst = NULL; - } - if(_ptrDecStr->instRight != NULL) - { - WebRtcG722_FreeDecoder(_ptrDecStr->instRight); - _ptrDecStr->instRight = NULL; - } - - delete _ptrDecStr; - _ptrDecStr = NULL; + if (_ptrDecStr->instRight != NULL) { + WebRtcG722_FreeDecoder(_ptrDecStr->instRight); + _ptrDecStr->instRight = NULL; } - return; + delete _ptrDecStr; + _ptrDecStr = NULL; + } + return; } - -WebRtc_Word32 -ACMG722::Add10MsDataSafe( - const WebRtc_UWord32 timestamp, - const WebRtc_Word16* data, - const WebRtc_UWord16 lengthSmpl, - const WebRtc_UWord8 audioChannel) -{ - return ACMGenericCodec::Add10MsDataSafe((timestamp>>1), data, lengthSmpl, - audioChannel); +WebRtc_Word32 ACMG722::Add10MsDataSafe(const WebRtc_UWord32 timestamp, + const WebRtc_Word16* data, + const WebRtc_UWord16 lengthSmpl, + const WebRtc_UWord8 audioChannel) { + return ACMGenericCodec::Add10MsDataSafe((timestamp >> 1), data, lengthSmpl, + audioChannel); } -WebRtc_Word16 -ACMG722::InternalEncode( - WebRtc_UWord8* bitStream, - WebRtc_Word16* bitStreamLenByte) -{ - // If stereo, split input signal in left and right channel before encoding - if(_noChannels == 2) { - WebRtc_Word16 leftChannel[960]; - WebRtc_Word16 rightChannel[960]; - WebRtc_UWord8 outLeft[480]; - WebRtc_UWord8 outRight[480]; - WebRtc_Word16 lenInBytes; - for (int i=0, j=0; i<_frameLenSmpl*2; i+=2, j++) { - leftChannel[j] = _inAudio[_inAudioIxRead+i]; - rightChannel[j] = _inAudio[_inAudioIxRead+i+1]; - } - lenInBytes = WebRtcG722_Encode(_encoderInstPtr, - leftChannel, _frameLenSmpl, (WebRtc_Word16*)outLeft); - lenInBytes += WebRtcG722_Encode(_encoderInstPtrRight, - rightChannel, _frameLenSmpl, (WebRtc_Word16*)outRight); - *bitStreamLenByte = lenInBytes; - - // Interleave the 4 bits per sample from left and right channel - for (int i=0, j=0; i> 4); - bitStream[i+1] = ((outRight[j] & 0x0F) << 4) + (outLeft[j] & 0x0F); - } - } else { - *bitStreamLenByte = WebRtcG722_Encode(_encoderInstPtr, - &_inAudio[_inAudioIxRead], _frameLenSmpl, (WebRtc_Word16*)bitStream); +WebRtc_Word16 ACMG722::InternalEncode(WebRtc_UWord8* bitStream, + WebRtc_Word16* bitStreamLenByte) { + // If stereo, split input signal in left and right channel before encoding + if (_noChannels == 2) { + WebRtc_Word16 leftChannel[960]; + WebRtc_Word16 rightChannel[960]; + WebRtc_UWord8 outLeft[480]; + WebRtc_UWord8 outRight[480]; + WebRtc_Word16 lenInBytes; + for (int i = 0, j = 0; i < _frameLenSmpl * 2; i += 2, j++) { + leftChannel[j] = _inAudio[_inAudioIxRead + i]; + rightChannel[j] = _inAudio[_inAudioIxRead + i + 1]; } + lenInBytes = WebRtcG722_Encode(_encoderInstPtr, leftChannel, _frameLenSmpl, + (WebRtc_Word16*) outLeft); + lenInBytes += WebRtcG722_Encode(_encoderInstPtrRight, rightChannel, + _frameLenSmpl, (WebRtc_Word16*) outRight); + *bitStreamLenByte = lenInBytes; - // increment the read index this tell the caller how far - // we have gone forward in reading the audio buffer - _inAudioIxRead += _frameLenSmpl*_noChannels; - return *bitStreamLenByte; -} - - -WebRtc_Word16 -ACMG722::DecodeSafe( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, - WebRtc_Word16* /* audio */, - WebRtc_Word16* /* audioSamples */, - WebRtc_Word8* /* speechType */) -{ - return 0; -} - - -WebRtc_Word16 -ACMG722::InternalInitEncoder( - WebRtcACMCodecParams* codecParams) -{ - if(codecParams->codecInstant.channels == 2) - { - // Create codec struct for right channel - if (_ptrEncStr->instRight == NULL) - { - WebRtcG722_CreateEncoder(&_ptrEncStr->instRight); - if(_ptrEncStr->instRight == NULL) - { - return -1; - } - } - _encoderInstPtrRight = (G722EncInst*)_ptrEncStr->instRight; - if (WebRtcG722_EncoderInit(_encoderInstPtrRight) < 0) - { - return -1; - } + // Interleave the 4 bits per sample from left and right channel + for (int i = 0, j = 0; i < lenInBytes; i += 2, j++) { + bitStream[i] = (outRight[j] & 0xF0) + (outLeft[j] >> 4); + bitStream[i + 1] = ((outRight[j] & 0x0F) << 4) + (outLeft[j] & 0x0F); } + } else { + *bitStreamLenByte = WebRtcG722_Encode(_encoderInstPtr, + &_inAudio[_inAudioIxRead], + _frameLenSmpl, + (WebRtc_Word16*) bitStream); + } - return WebRtcG722_EncoderInit(_encoderInstPtr); + // increment the read index this tell the caller how far + // we have gone forward in reading the audio buffer + _inAudioIxRead += _frameLenSmpl * _noChannels; + return *bitStreamLenByte; } - -WebRtc_Word16 -ACMG722::InternalInitDecoder( - WebRtcACMCodecParams* /* codecParams */) -{ - return WebRtcG722_DecoderInit(_decoderInstPtr); +WebRtc_Word16 ACMG722::DecodeSafe(WebRtc_UWord8* /* bitStream */, + WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16* /* audio */, + WebRtc_Word16* /* audioSamples */, + WebRtc_Word8* /* speechType */) { + return 0; } - -WebRtc_Word32 -ACMG722::CodecDef( - WebRtcNetEQ_CodecDef& codecDef, - const CodecInst& codecInst) -{ - if (!_decoderInitialized) - { - // TODO: log error +WebRtc_Word16 ACMG722::InternalInitEncoder(WebRtcACMCodecParams* codecParams) { + if (codecParams->codecInstant.channels == 2) { + // Create codec struct for right channel + if (_ptrEncStr->instRight == NULL) { + WebRtcG722_CreateEncoder(&_ptrEncStr->instRight); + if (_ptrEncStr->instRight == NULL) { return -1; + } } - // Fill up the structure by calling - // "SET_CODEC_PAR" & "SET_G722_FUNCTION." - // Then call NetEQ to add the codec to it's - // database. - SET_CODEC_PAR((codecDef), kDecoderG722, codecInst.pltype, - _decoderInstPtr, 16000); - SET_G722_FUNCTIONS((codecDef)); - return 0; + _encoderInstPtrRight = _ptrEncStr->instRight; + if (WebRtcG722_EncoderInit(_encoderInstPtrRight) < 0) { + return -1; + } + } + + return WebRtcG722_EncoderInit(_encoderInstPtr); } - -ACMGenericCodec* -ACMG722::CreateInstance(void) -{ - return NULL; +WebRtc_Word16 ACMG722::InternalInitDecoder( + WebRtcACMCodecParams* /* codecParams */) { + return WebRtcG722_DecoderInit(_decoderInstPtr); } - -WebRtc_Word16 -ACMG722::InternalCreateEncoder() -{ - if(_ptrEncStr == NULL) - { - // this structure must be created at the costructor - // if it is still NULL then there is a probelm and - // we dont continue - return -1; - } - WebRtcG722_CreateEncoder(&_ptrEncStr->inst); - if(_ptrEncStr->inst == NULL) - { - return -1; - } - _encoderInstPtr = (G722EncInst*)_ptrEncStr->inst; - return 0; +WebRtc_Word32 ACMG722::CodecDef(WebRtcNetEQ_CodecDef& codecDef, + const CodecInst& codecInst) { + if (!_decoderInitialized) { + // TODO: log error + return -1; + } + // Fill up the structure by calling + // "SET_CODEC_PAR" & "SET_G722_FUNCTION." + // Then call NetEQ to add the codec to it's + // database. + SET_CODEC_PAR((codecDef), kDecoderG722, codecInst.pltype, _decoderInstPtr, + 16000); + SET_G722_FUNCTIONS((codecDef)); + return 0; } - -void -ACMG722::DestructEncoderSafe() -{ - if(_ptrEncStr != NULL) - { - if(_ptrEncStr->inst != NULL) - { - WebRtcG722_FreeEncoder(_ptrEncStr->inst); - _ptrEncStr->inst = NULL; - } - } - _encoderExist = false; - _encoderInitialized = false; - +ACMGenericCodec* ACMG722::CreateInstance(void) { + return NULL; } -WebRtc_Word16 -ACMG722::InternalCreateDecoder() -{ - if(_ptrDecStr == NULL) - { - // this structure must be created at the costructor - // if it is still NULL then there is a probelm and - // we dont continue - return -1; - } - - WebRtcG722_CreateDecoder(&_ptrDecStr->inst); - if(_ptrDecStr->inst == NULL) - { - return -1; - } - _decoderInstPtr = (G722DecInst*)_ptrDecStr->inst; - return 0; +WebRtc_Word16 ACMG722::InternalCreateEncoder() { + if (_ptrEncStr == NULL) { + // this structure must be created at the costructor + // if it is still NULL then there is a probelm and + // we dont continue + return -1; + } + WebRtcG722_CreateEncoder(&_ptrEncStr->inst); + if (_ptrEncStr->inst == NULL) { + return -1; + } + _encoderInstPtr = _ptrEncStr->inst; + return 0; } -void -ACMG722::DestructDecoderSafe() -{ - _decoderExist = false; - _decoderInitialized = false; - if(_ptrDecStr != NULL) - { - if(_ptrDecStr->inst != NULL) - { - WebRtcG722_FreeDecoder(_ptrDecStr->inst); - _ptrDecStr->inst = NULL; - } +void ACMG722::DestructEncoderSafe() { + if (_ptrEncStr != NULL) { + if (_ptrEncStr->inst != NULL) { + WebRtcG722_FreeEncoder(_ptrEncStr->inst); + _ptrEncStr->inst = NULL; } + } + _encoderExist = false; + _encoderInitialized = false; } +WebRtc_Word16 ACMG722::InternalCreateDecoder() { + if (_ptrDecStr == NULL) { + // this structure must be created at the costructor + // if it is still NULL then there is a probelm and + // we dont continue + return -1; + } -void -ACMG722::InternalDestructEncoderInst( - void* ptrInst) -{ - if(ptrInst != NULL) - { - WebRtcG722_FreeEncoder((G722EncInst*)ptrInst); - } - return; + WebRtcG722_CreateDecoder(&_ptrDecStr->inst); + if (_ptrDecStr->inst == NULL) { + return -1; + } + _decoderInstPtr = _ptrDecStr->inst; + return 0; } - -WebRtc_Word16 -ACMG722::UnregisterFromNetEqSafe( - ACMNetEQ* netEq, - WebRtc_Word16 payloadType) -{ - if(payloadType != _decoderParams.codecInstant.pltype) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "Cannot unregister codec %s given payload-type %d does not match \ -the stored payload type", - _decoderParams.codecInstant.plname, - payloadType, - _decoderParams.codecInstant.pltype); - return -1; +void ACMG722::DestructDecoderSafe() { + _decoderExist = false; + _decoderInitialized = false; + if (_ptrDecStr != NULL) { + if (_ptrDecStr->inst != NULL) { + WebRtcG722_FreeDecoder(_ptrDecStr->inst); + _ptrDecStr->inst = NULL; } - return netEq->RemoveCodec(kDecoderG722); + } +} + +void ACMG722::InternalDestructEncoderInst(void* ptrInst) { + if (ptrInst != NULL) { + WebRtcG722_FreeEncoder(static_cast(ptrInst)); + } + return; +} + +WebRtc_Word16 ACMG722::UnregisterFromNetEqSafe(ACMNetEQ* netEq, + WebRtc_Word16 payloadType) { + if (payloadType != _decoderParams.codecInstant.pltype) { + WEBRTC_TRACE(webrtc::kTraceError, + webrtc::kTraceAudioCoding, + _uniqueID, + "Cannot unregister codec %s given payload-type %d does not " + "match the stored payload type", + _decoderParams.codecInstant.plname, payloadType, + _decoderParams.codecInstant.pltype); + return -1; + } + return netEq->RemoveCodec(kDecoderG722); } #endif diff --git a/src/modules/audio_coding/main/source/acm_g722.h b/src/modules/audio_coding/main/source/acm_g722.h index 9194acb2d..776d18870 100644 --- a/src/modules/audio_coding/main/source/acm_g722.h +++ b/src/modules/audio_coding/main/source/acm_g722.h @@ -8,13 +8,13 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_G722_H -#define ACM_G722_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G722_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G722_H_ #include "acm_generic_codec.h" -typedef struct WebRtcG722EncInst G722EncInst; -typedef struct WebRtcG722DecInst G722DecInst; +typedef struct WebRtcG722EncInst G722EncInst; +typedef struct WebRtcG722DecInst G722DecInst; namespace webrtc { @@ -22,65 +22,55 @@ namespace webrtc { struct ACMG722EncStr; struct ACMG722DecStr; -class ACMG722 : public ACMGenericCodec -{ -public: - ACMG722(WebRtc_Word16 codecID); - ~ACMG722(); - // for FEC - ACMGenericCodec* CreateInstance(void); +class ACMG722: public ACMGenericCodec { + public: + ACMG722(WebRtc_Word16 codecID); + ~ACMG722(); + // for FEC + ACMGenericCodec* CreateInstance(void); - WebRtc_Word16 InternalEncode( - WebRtc_UWord8* bitstream, - WebRtc_Word16* bitStreamLenByte); + WebRtc_Word16 InternalEncode(WebRtc_UWord8* bitstream, + WebRtc_Word16* bitStreamLenByte); - WebRtc_Word16 InternalInitEncoder( - WebRtcACMCodecParams *codecParams); + WebRtc_Word16 InternalInitEncoder(WebRtcACMCodecParams *codecParams); - WebRtc_Word16 InternalInitDecoder( - WebRtcACMCodecParams *codecParams); + WebRtc_Word16 InternalInitDecoder(WebRtcACMCodecParams *codecParams); -protected: - WebRtc_Word16 DecodeSafe( - WebRtc_UWord8* bitStream, - WebRtc_Word16 bitStreamLenByte, - WebRtc_Word16* audio, - WebRtc_Word16* audioSamples, - WebRtc_Word8* speechType); + protected: + WebRtc_Word16 DecodeSafe(WebRtc_UWord8* bitStream, + WebRtc_Word16 bitStreamLenByte, + WebRtc_Word16* audio, WebRtc_Word16* audioSamples, + WebRtc_Word8* speechType); - WebRtc_Word32 CodecDef( - WebRtcNetEQ_CodecDef& codecDef, - const CodecInst& codecInst); + WebRtc_Word32 CodecDef(WebRtcNetEQ_CodecDef& codecDef, + const CodecInst& codecInst); - WebRtc_Word32 Add10MsDataSafe( - const WebRtc_UWord32 timestamp, - const WebRtc_Word16* data, - const WebRtc_UWord16 lengthSmpl, - const WebRtc_UWord8 audioChannel); + WebRtc_Word32 Add10MsDataSafe(const WebRtc_UWord32 timestamp, + const WebRtc_Word16* data, + const WebRtc_UWord16 lengthSmpl, + const WebRtc_UWord8 audioChannel); - void DestructEncoderSafe(); - - void DestructDecoderSafe(); + void DestructEncoderSafe(); - WebRtc_Word16 InternalCreateEncoder(); - - WebRtc_Word16 InternalCreateDecoder(); - - void InternalDestructEncoderInst( - void* ptrInst); + void DestructDecoderSafe(); - WebRtc_Word16 UnregisterFromNetEqSafe( - ACMNetEQ* netEq, - WebRtc_Word16 payloadType); + WebRtc_Word16 InternalCreateEncoder(); - ACMG722EncStr* _ptrEncStr; - ACMG722DecStr* _ptrDecStr; + WebRtc_Word16 InternalCreateDecoder(); - G722EncInst* _encoderInstPtr; - G722EncInst* _encoderInstPtrRight; // Prepared for stereo - G722DecInst* _decoderInstPtr; + void InternalDestructEncoderInst(void* ptrInst); + + WebRtc_Word16 UnregisterFromNetEqSafe(ACMNetEQ* netEq, + WebRtc_Word16 payloadType); + + ACMG722EncStr* _ptrEncStr; + ACMG722DecStr* _ptrDecStr; + + G722EncInst* _encoderInstPtr; + G722EncInst* _encoderInstPtrRight; // Prepared for stereo + G722DecInst* _decoderInstPtr; }; } // namespace webrtc -#endif // ACM_G722_H +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G722_H_ diff --git a/src/modules/audio_coding/main/source/acm_g7221.cc b/src/modules/audio_coding/main/source/acm_g7221.cc index 91a2e8a7c..570736400 100644 --- a/src/modules/audio_coding/main/source/acm_g7221.cc +++ b/src/modules/audio_coding/main/source/acm_g7221.cc @@ -17,657 +17,497 @@ #include "webrtc_neteq_help_macros.h" #ifdef WEBRTC_CODEC_G722_1 - // NOTE! G.722.1 is not included in the open-source package. The following - // interface file is needed: - // - // /modules/audio_coding/codecs/g7221/main/interface/g7221_interface.h - // - // The API in the header file should match the one below. - // - // int16_t WebRtcG7221_CreateEnc16(G722_1_16_encinst_t_** encInst); - // int16_t WebRtcG7221_CreateEnc24(G722_1_24_encinst_t_** encInst); - // int16_t WebRtcG7221_CreateEnc32(G722_1_32_encinst_t_** encInst); - // int16_t WebRtcG7221_CreateDec16(G722_1_16_decinst_t_** decInst); - // int16_t WebRtcG7221_CreateDec24(G722_1_24_decinst_t_** decInst); - // int16_t WebRtcG7221_CreateDec32(G722_1_32_decinst_t_** decInst); - // - // int16_t WebRtcG7221_FreeEnc16(G722_1_16_encinst_t_** encInst); - // int16_t WebRtcG7221_FreeEnc24(G722_1_24_encinst_t_** encInst); - // int16_t WebRtcG7221_FreeEnc32(G722_1_32_encinst_t_** encInst); - // int16_t WebRtcG7221_FreeDec16(G722_1_16_decinst_t_** decInst); - // int16_t WebRtcG7221_FreeDec24(G722_1_24_decinst_t_** decInst); - // int16_t WebRtcG7221_FreeDec32(G722_1_32_decinst_t_** decInst); - // - // int16_t WebRtcG7221_EncoderInit16(G722_1_16_encinst_t_* encInst); - // int16_t WebRtcG7221_EncoderInit24(G722_1_24_encinst_t_* encInst); - // int16_t WebRtcG7221_EncoderInit32(G722_1_32_encinst_t_* encInst); - // int16_t WebRtcG7221_DecoderInit16(G722_1_16_decinst_t_* decInst); - // int16_t WebRtcG7221_DecoderInit24(G722_1_24_decinst_t_* decInst); - // int16_t WebRtcG7221_DecoderInit32(G722_1_32_decinst_t_* decInst); - // - // int16_t WebRtcG7221_Encode16(G722_1_16_encinst_t_* encInst, - // int16_t* input, - // int16_t len, - // int16_t* output); - // int16_t WebRtcG7221_Encode24(G722_1_24_encinst_t_* encInst, - // int16_t* input, - // int16_t len, - // int16_t* output); - // int16_t WebRtcG7221_Encode32(G722_1_32_encinst_t_* encInst, - // int16_t* input, - // int16_t len, - // int16_t* output); - // - // int16_t WebRtcG7221_Decode16(G722_1_16_decinst_t_* decInst, - // int16_t* bitstream, - // int16_t len, - // int16_t* output); - // int16_t WebRtcG7221_Decode24(G722_1_24_decinst_t_* decInst, - // int16_t* bitstream, - // int16_t len, - // int16_t* output); - // int16_t WebRtcG7221_Decode32(G722_1_32_decinst_t_* decInst, - // int16_t* bitstream, - // int16_t len, - // int16_t* output); - // - // int16_t WebRtcG7221_DecodePlc16(G722_1_16_decinst_t_* decInst, - // int16_t* output, - // int16_t nrLostFrames); - // int16_t WebRtcG7221_DecodePlc24(G722_1_24_decinst_t_* decInst, - // int16_t* output, - // int16_t nrLostFrames); - // int16_t WebRtcG7221_DecodePlc32(G722_1_32_decinst_t_* decInst, - // int16_t* output, - // int16_t nrLostFrames); - // void WebRtcG7221_Version(char *versionStr, short len); - #include "g7221_interface.h" +// NOTE! G.722.1 is not included in the open-source package. The following +// interface file is needed: +// +// /modules/audio_coding/codecs/g7221/main/interface/g7221_interface.h +// +// The API in the header file should match the one below. +// +// int16_t WebRtcG7221_CreateEnc16(G722_1_16_encinst_t_** encInst); +// int16_t WebRtcG7221_CreateEnc24(G722_1_24_encinst_t_** encInst); +// int16_t WebRtcG7221_CreateEnc32(G722_1_32_encinst_t_** encInst); +// int16_t WebRtcG7221_CreateDec16(G722_1_16_decinst_t_** decInst); +// int16_t WebRtcG7221_CreateDec24(G722_1_24_decinst_t_** decInst); +// int16_t WebRtcG7221_CreateDec32(G722_1_32_decinst_t_** decInst); +// +// int16_t WebRtcG7221_FreeEnc16(G722_1_16_encinst_t_** encInst); +// int16_t WebRtcG7221_FreeEnc24(G722_1_24_encinst_t_** encInst); +// int16_t WebRtcG7221_FreeEnc32(G722_1_32_encinst_t_** encInst); +// int16_t WebRtcG7221_FreeDec16(G722_1_16_decinst_t_** decInst); +// int16_t WebRtcG7221_FreeDec24(G722_1_24_decinst_t_** decInst); +// int16_t WebRtcG7221_FreeDec32(G722_1_32_decinst_t_** decInst); +// +// int16_t WebRtcG7221_EncoderInit16(G722_1_16_encinst_t_* encInst); +// int16_t WebRtcG7221_EncoderInit24(G722_1_24_encinst_t_* encInst); +// int16_t WebRtcG7221_EncoderInit32(G722_1_32_encinst_t_* encInst); +// int16_t WebRtcG7221_DecoderInit16(G722_1_16_decinst_t_* decInst); +// int16_t WebRtcG7221_DecoderInit24(G722_1_24_decinst_t_* decInst); +// int16_t WebRtcG7221_DecoderInit32(G722_1_32_decinst_t_* decInst); +// +// int16_t WebRtcG7221_Encode16(G722_1_16_encinst_t_* encInst, +// int16_t* input, +// int16_t len, +// int16_t* output); +// int16_t WebRtcG7221_Encode24(G722_1_24_encinst_t_* encInst, +// int16_t* input, +// int16_t len, +// int16_t* output); +// int16_t WebRtcG7221_Encode32(G722_1_32_encinst_t_* encInst, +// int16_t* input, +// int16_t len, +// int16_t* output); +// +// int16_t WebRtcG7221_Decode16(G722_1_16_decinst_t_* decInst, +// int16_t* bitstream, +// int16_t len, +// int16_t* output); +// int16_t WebRtcG7221_Decode24(G722_1_24_decinst_t_* decInst, +// int16_t* bitstream, +// int16_t len, +// int16_t* output); +// int16_t WebRtcG7221_Decode32(G722_1_32_decinst_t_* decInst, +// int16_t* bitstream, +// int16_t len, +// int16_t* output); +// +// int16_t WebRtcG7221_DecodePlc16(G722_1_16_decinst_t_* decInst, +// int16_t* output, +// int16_t nrLostFrames); +// int16_t WebRtcG7221_DecodePlc24(G722_1_24_decinst_t_* decInst, +// int16_t* output, +// int16_t nrLostFrames); +// int16_t WebRtcG7221_DecodePlc32(G722_1_32_decinst_t_* decInst, +// int16_t* output, +// int16_t nrLostFrames); +// void WebRtcG7221_Version(char *versionStr, short len); +#include "g7221_interface.h" #endif namespace webrtc { #ifndef WEBRTC_CODEC_G722_1 -ACMG722_1::ACMG722_1( - WebRtc_Word16 /* codecID */) -{ - return; +ACMG722_1::ACMG722_1(WebRtc_Word16 /* codecID */) { + return; } -ACMG722_1::~ACMG722_1() -{ - return; +ACMG722_1::~ACMG722_1() { + return; } - -WebRtc_Word16 -ACMG722_1::InternalEncode( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16* /* bitStreamLenByte */) -{ - return -1; +WebRtc_Word16 ACMG722_1::InternalEncode(WebRtc_UWord8* /* bitStream */, + WebRtc_Word16* /* bitStreamLenByte */) { + return -1; } - -WebRtc_Word16 -ACMG722_1::DecodeSafe( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, - WebRtc_Word16* /* audio */, - WebRtc_Word16* /* audioSamples */, - WebRtc_Word8* /* speechType */) -{ - return -1; +WebRtc_Word16 ACMG722_1::DecodeSafe(WebRtc_UWord8* /* bitStream */, + WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16* /* audio */, + WebRtc_Word16* /* audioSamples */, + WebRtc_Word8* /* speechType */) { + return -1; } - -WebRtc_Word16 -ACMG722_1::InternalInitEncoder( - WebRtcACMCodecParams* /* codecParams */) -{ - return -1; +WebRtc_Word16 ACMG722_1::InternalInitEncoder( + WebRtcACMCodecParams* /* codecParams */) { + return -1; } - -WebRtc_Word16 -ACMG722_1::InternalInitDecoder( - WebRtcACMCodecParams* /* codecParams */) -{ - return -1; +WebRtc_Word16 ACMG722_1::InternalInitDecoder( + WebRtcACMCodecParams* /* codecParams */) { + return -1; } - -WebRtc_Word32 -ACMG722_1::CodecDef( - WebRtcNetEQ_CodecDef& /* codecDef */, - const CodecInst& /* codecInst */) -{ - return -1; +WebRtc_Word32 ACMG722_1::CodecDef(WebRtcNetEQ_CodecDef& /* codecDef */, + const CodecInst& /* codecInst */) { + return -1; } -ACMGenericCodec* -ACMG722_1::CreateInstance(void) -{ - return NULL; +ACMGenericCodec* ACMG722_1::CreateInstance(void) { + return NULL; } - -WebRtc_Word16 -ACMG722_1::InternalCreateEncoder() -{ - return -1; +WebRtc_Word16 ACMG722_1::InternalCreateEncoder() { + return -1; } - -void -ACMG722_1::DestructEncoderSafe() -{ - return; +void ACMG722_1::DestructEncoderSafe() { + return; } - -WebRtc_Word16 -ACMG722_1::InternalCreateDecoder() -{ - return -1; +WebRtc_Word16 ACMG722_1::InternalCreateDecoder() { + return -1; } - -void -ACMG722_1::DestructDecoderSafe() -{ - return; +void ACMG722_1::DestructDecoderSafe() { + return; } - -void -ACMG722_1::InternalDestructEncoderInst( - void* /* ptrInst */) -{ - return; +void ACMG722_1::InternalDestructEncoderInst(void* /* ptrInst */) { + return; } - -WebRtc_Word16 -ACMG722_1::UnregisterFromNetEqSafe( - ACMNetEQ* /* netEq */, - WebRtc_Word16 /* payloadType */) -{ - return -1; +WebRtc_Word16 ACMG722_1::UnregisterFromNetEqSafe( + ACMNetEQ* /* netEq */, WebRtc_Word16 /* payloadType */) { + return -1; } - #else //===================== Actual Implementation ======================= - ACMG722_1::ACMG722_1( WebRtc_Word16 codecID): -_encoderInstPtr(NULL), -_encoderInstPtrRight(NULL), -_decoderInstPtr(NULL), -_encoderInst16Ptr(NULL), -_encoderInst16PtrR(NULL), -_encoderInst24Ptr(NULL), -_encoderInst24PtrR(NULL), -_encoderInst32Ptr(NULL), -_encoderInst32PtrR(NULL), -_decoderInst16Ptr(NULL), -_decoderInst24Ptr(NULL), -_decoderInst32Ptr(NULL) -{ - _codecID = codecID; - if(_codecID == ACMCodecDB::kG722_1_16) - { - _operationalRate = 16000; - } - else if(_codecID == ACMCodecDB::kG722_1_24) - { - _operationalRate = 24000; - } - else if(_codecID == ACMCodecDB::kG722_1_32) - { - _operationalRate = 32000; - } - else - { - _operationalRate = -1; - } - return; + _encoderInstPtr(NULL), + _encoderInstPtrRight(NULL), + _decoderInstPtr(NULL), + _encoderInst16Ptr(NULL), + _encoderInst16PtrR(NULL), + _encoderInst24Ptr(NULL), + _encoderInst24PtrR(NULL), + _encoderInst32Ptr(NULL), + _encoderInst32PtrR(NULL), + _decoderInst16Ptr(NULL), + _decoderInst24Ptr(NULL), + _decoderInst32Ptr(NULL) { + _codecID = codecID; + if (_codecID == ACMCodecDB::kG722_1_16) { + _operationalRate = 16000; + } else if (_codecID == ACMCodecDB::kG722_1_24) { + _operationalRate = 24000; + } else if (_codecID == ACMCodecDB::kG722_1_32) { + _operationalRate = 32000; + } else { + _operationalRate = -1; + } + return; } -ACMG722_1::~ACMG722_1() -{ - if(_encoderInstPtr != NULL) - { - delete _encoderInstPtr; - _encoderInstPtr = NULL; - } - if(_encoderInstPtrRight != NULL) - {Inst - delete _encoderInstPtrRight; - _encoderInstPtrRight = NULL; - } - if(_decoderInstPtr != NULL) - { - delete _decoderInstPtr; - _decoderInstPtr = NULL; - } +ACMG722_1::~ACMG722_1() { + if (_encoderInstPtr != NULL) { + delete _encoderInstPtr; + _encoderInstPtr = NULL; + } + if (_encoderInstPtrRight != NULL) { + delete _encoderInstPtrRight; + _encoderInstPtrRight = NULL; + } + if (_decoderInstPtr != NULL) { + delete _decoderInstPtr; + _decoderInstPtr = NULL; + } - switch(_operationalRate) - { - case 16000: - { - _encoderInst16Ptr = NULL; - _encoderInst16PtrR = NULL; - _decoderInst16Ptr = NULL; - break; - } - case 24000: - { - _encoderInst24Ptr = NULL; - _encoderInst24PtrR = NULL; - _decoderInst24Ptr = NULL; - break; - } - case 32000: - { - _encoderInst32Ptr = NULL; - _encoderInst32PtrR = NULL; - _decoderInst32Ptr = NULL; - break; - } - default: - { - break; - } + switch (_operationalRate) { + case 16000: { + _encoderInst16Ptr = NULL; + _encoderInst16PtrR = NULL; + _decoderInst16Ptr = NULL; + break; } - return; + case 24000: { + _encoderInst24Ptr = NULL; + _encoderInst24PtrR = NULL; + _decoderInst24Ptr = NULL; + break; + } + case 32000: { + _encoderInst32Ptr = NULL; + _encoderInst32PtrR = NULL; + _decoderInst32Ptr = NULL; + break; + } + default: { + break; + } + } + return; } +WebRtc_Word16 ACMG722_1::InternalEncode(WebRtc_UWord8* bitStream, + WebRtc_Word16* bitStreamLenByte) { + WebRtc_Word16 leftChannel[320]; + WebRtc_Word16 rightChannel[320]; + WebRtc_Word16 lenInBytes; + WebRtc_Word16 outB[160]; -WebRtc_Word16 -ACMG722_1::InternalEncode( - WebRtc_UWord8* bitStream, - WebRtc_Word16* bitStreamLenByte) -{ - WebRtc_Word16 leftChannel[320]; - WebRtc_Word16 rightChannel[320]; - WebRtc_Word16 lenInBytes; - WebRtc_Word16 outB[160]; - - // If stereo, split input signal in left and right channel before encoding - if(_noChannels == 2) - { - for (int i=0, j=0; i<_frameLenSmpl*2; i+=2, j++) { - leftChannel[j] = _inAudio[_inAudioIxRead+i]; - rightChannel[j] = _inAudio[_inAudioIxRead+i+1]; - } - } else { - memcpy(leftChannel, &_inAudio[_inAudioIxRead], 320); + // If stereo, split input signal in left and right channel before encoding + if (_noChannels == 2) { + for (int i = 0, j = 0; i < _frameLenSmpl * 2; i += 2, j++) { + leftChannel[j] = _inAudio[_inAudioIxRead + i]; + rightChannel[j] = _inAudio[_inAudioIxRead + i + 1]; } + } else { + memcpy(leftChannel, &_inAudio[_inAudioIxRead], 320); + } - switch(_operationalRate) - { - case 16000: - {Inst - lenInBytes = WebRtcG7221_Encode16(_encoderInst16Ptr, - leftChannel, 320, &outB[0]); - if (_noChannels == 2) - { - lenInBytes += WebRtcG7221_Encode16(_encoderInst16PtrR, - rightChannel, 320, &outB[lenInBytes/2]); - } - break; - } - case 24000: - { - lenInBytes = WebRtcG7221_Encode24(_encoderInst24Ptr, - leftChannel, 320, &outB[0]); - if (_noChannels == 2) - { - lenInBytes += WebRtcG7221_Encode24(_encoderInst24PtrR, - rightChannel, 320, &outB[lenInBytes/2]); - } - break; - } - case 32000: - { - lenInBytes = WebRtcG7221_Encode32(_encoderInst32Ptr, - leftChannel, 320, &outB[0]); - if (_noChannels == 2) - { - lenInBytes += WebRtcG7221_Encode32(_encoderInst32PtrR, - rightChannel, 320, &outB[lenInBytes/2]); - } - break; - } - default: - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalInitEncode: Wrong rate for G722_1."); - return -1; - break; - } + switch (_operationalRate) { + case 16000: { + Inst lenInBytes = WebRtcG7221_Encode16(_encoderInst16Ptr, leftChannel, + 320, &outB[0]); + if (_noChannels == 2) { + lenInBytes += WebRtcG7221_Encode16(_encoderInst16PtrR, rightChannel, + 320, &outB[lenInBytes / 2]); + } + break; } - memcpy(bitStream, outB, lenInBytes); - *bitStreamLenByte = lenInBytes; - - // increment the read index this tell the caller that how far - // we have gone forward in reading the audio buffer - _inAudioIxRead += 320*_noChannels; - return *bitStreamLenByte; + case 24000: { + lenInBytes = WebRtcG7221_Encode24(_encoderInst24Ptr, leftChannel, 320, + &outB[0]); + if (_noChannels == 2) { + lenInBytes += WebRtcG7221_Encode24(_encoderInst24PtrR, rightChannel, + 320, &outB[lenInBytes / 2]); + } + break; + } + case 32000: { + lenInBytes = WebRtcG7221_Encode32(_encoderInst32Ptr, leftChannel, 320, + &outB[0]); + if (_noChannels == 2) { + lenInBytes += WebRtcG7221_Encode32(_encoderInst32PtrR, rightChannel, + 320, &outB[lenInBytes / 2]); + } + break; + } + default: { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalInitEncode: Wrong rate for G722_1."); + return -1; + } + } + memcpy(bitStream, outB, lenInBytes); + *bitStreamLenByte = lenInBytes; + + // increment the read index this tell the caller that how far + // we have gone forward in reading the audio buffer + _inAudioIxRead += 320 * _noChannels; + return *bitStreamLenByte; } - -WebRtc_Word16 -ACMG722_1::DecodeSafe( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, - WebRtc_Word16* /* audio */, - WebRtc_Word16* /* audioSamples */, - WebRtc_Word8* /* speechType */) -{ - return 0; +WebRtc_Word16 ACMG722_1::DecodeSafe(WebRtc_UWord8* /* bitStream */, + WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16* /* audio */, + WebRtc_Word16* /* audioSamples */, + WebRtc_Word8* /* speechType */) { + return 0; } +WebRtc_Word16 ACMG722_1::InternalInitEncoder( + WebRtcACMCodecParams* codecParams) { + WebRtc_Word16 ret; -WebRtc_Word16 -ACMG722_1::InternalInitEncoder( - WebRtcACMCodecParams* codecParams) -{ - WebRtc_Word16 ret; - - switch(_operationalRate) - { - case 16000: - { - ret = WebRtcG7221_EncoderInit16(_encoderInst16PtrR); - if (ret < 0) { - return ret; - } - return WebRtcG7221_EncoderInit16(_encoderInst16Ptr); - break; - } - case 24000: - { - ret = WebRtcG7221_EncoderInit24(_encoderInst24PtrR); - if (ret < 0) { - return ret; - } - return WebRtcG7221_EncoderInit24(_encoderInst24Ptr); - break; - } - case 32000: - { - ret = WebRtcG7221_EncoderInit32(_encoderInst32PtrR); - if (ret < 0) { - return ret; - } - return WebRtcG7221_EncoderInit32(_encoderInst32Ptr); - break; - } - default: - { - WEBRTC_TRACE(webrtc::kTraceError,Inst webrtc::kTraceAudioCoding, _uniqueID, - "InternalInitEncoder: Wrong rate for G722_1."); - return -1; - break; - } + switch (_operationalRate) { + case 16000: { + ret = WebRtcG7221_EncoderInit16(_encoderInst16PtrR); + if (ret < 0) { + return ret; + } + return WebRtcG7221_EncoderInit16(_encoderInst16Ptr); } + case 24000: { + ret = WebRtcG7221_EncoderInit24(_encoderInst24PtrR); + if (ret < 0) { + return ret; + } + return WebRtcG7221_EncoderInit24(_encoderInst24Ptr); + } + case 32000: { + ret = WebRtcG7221_EncoderInit32(_encoderInst32PtrR); + if (ret < 0) { + return ret; + } + return WebRtcG7221_EncoderInit32(_encoderInst32Ptr); + } + default: { + WEBRTC_TRACE(webrtc::kTraceError,Inst webrtc::kTraceAudioCoding, + _uniqueID, "InternalInitEncoder: Wrong rate for G722_1."); + return -1; + } + } } - -WebRtc_Word16 -ACMG722_1::InternalInitDecoder( - WebRtcACMCodecParams* /* codecParams */) -{ - switch(_operationalRate) - { - case 16000: - { - return WebRtcG7221_DecoderInit16(_decoderInst16Ptr); - break; - } - case 24000: - { - return WebRtcG7221_DecoderInit24(_decoderInst24Ptr); - break; - } - case 32000: - { - return WebRtcG7221_DecoderInit32(_decoderInst32Ptr); - break; - } - default: - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalInitDecoder: Wrong rate for G722_1."); - return -1; - break; - } +WebRtc_Word16 ACMG722_1::InternalInitDecoder( + WebRtcACMCodecParams* /* codecParams */) { + switch (_operationalRate) { + case 16000: { + return WebRtcG7221_DecoderInit16(_decoderInst16Ptr); } + case 24000: { + return WebRtcG7221_DecoderInit24(_decoderInst24Ptr); + } + case 32000: { + return WebRtcG7221_DecoderInit32(_decoderInst32Ptr); + } + default: { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalInitDecoder: Wrong rate for G722_1."); + return -1; + } + } } - -WebRtc_Word32 -ACMG722_1::CodecDef( - WebRtcNetEQ_CodecDef& codecDef, - const CodecInst& codecInst) -{ - if (!_decoderInitialized) - { - // Todo: - // log error - return -1; +WebRtc_Word32 ACMG722_1::CodecDef(WebRtcNetEQ_CodecDef& codecDef, + const CodecInst& codecInst) { + if (!_decoderInitialized) { + // Todo: + // log error + return -1; + } + // NetEq has an array of pointers to WebRtcNetEQ_CodecDef. + // Get an entry of that array (neteq wrapper will allocate memory) + // by calling "netEq->CodecDef", where "NETEQ_CODEC_G722_1_XX" would + // be the index of the entry. + // Fill up the given structure by calling + // "SET_CODEC_PAR" & "SET_G722_1_XX_FUNCTION." + // Then return the structure back to NetEQ to add the codec to it's + // database. + switch (_operationalRate) { + case 16000: { + SET_CODEC_PAR((codecDef), kDecoderG722_1_16, codecInst.pltype, + _decoderInst16Ptr, 16000); + SET_G722_1_16_FUNCTIONS((codecDef)); + break; } - // NetEq has an array of pointers to WebRtcNetEQ_CodecDef. - // get an entry of that array (neteq wrapper will allocate memory) - // by calling "netEq->CodecDef", where "NETEQ_CODEC_G722_1_XX" would - // be the index of the entry. - // Fill up the given structure by calling - // "SET_CODEC_PAR" & "SET_G722_1_XX_FUNCTION." - // Then return the structure back to NetEQ to add the codec to it's - // database. - switch(_operationalRate) - { - case 16000: - { - SET_CODEC_PAR((codecDef), kDecoderG722_1_16, codecInst.pltype, - _decoderInst16Ptr, 16000); - SET_G722_1_16_FUNCTIONS((codecDef)); - break; - } - case 24000: - { - SET_CODEC_PAR((codecDef), kDecoderG722_1_24, codecInst.pltype, - _decoderInst24Ptr, 16000); - SET_G722_1_24_FUNCTIONS((codecDef)); - break; - } - case 32000: - { - SET_CODEC_PAR((codecDef), kDecoderG722_1_32, codecInst.pltype, - _decoderInst32Ptr, 16000); - SET_G722_1_32_FUNCTIONS((codecDef)); - break; - } - default: - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "CodecDef: Wrong rate for G722_1."); - return -1; - break; - } + case 24000: { + SET_CODEC_PAR((codecDef), kDecoderG722_1_24, codecInst.pltype, + _decoderInst24Ptr, 16000); + SET_G722_1_24_FUNCTIONS((codecDef)); + break; } - return 0; + case 32000: { + SET_CODEC_PAR((codecDef), kDecoderG722_1_32, codecInst.pltype, + _decoderInst32Ptr, 16000); + SET_G722_1_32_FUNCTIONS((codecDef)); + break; + } + default: { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "CodecDef: Wrong rate for G722_1."); + return -1; + } + } + return 0; } -ACMGenericCodec* -ACMG722_1::CreateInstance(void) -{ - return NULL; +ACMGenericCodec* ACMG722_1::CreateInstance(void) { + return NULL; } - -WebRtc_Word16 -ACMG722_1::InternalCreateEncoder() -{ - if((_encoderInstPtr == NULL) || (_encoderInstPtrRight == NULL)) - { - return -1; +WebRtc_Word16 ACMG722_1::InternalCreateEncoder() { + if ((_encoderInstPtr == NULL) || (_encoderInstPtrRight == NULL)) { + return -1; + } + switch (_operationalRate) { + case 16000: { + WebRtcG7221_CreateEnc16(&_encoderInst16Ptr); + WebRtcG7221_CreateEnc16(&_encoderInst16PtrR); + break; } - switch(_operationalRate) - { - case 16000: - { - WebRtcG7221_CreateEnc16(&_encoderInst16Ptr); - WebRtcG7221_CreateEnc16(&_encoderInst16PtrR); - break; - } - case 24000: - { - WebRtcG7221_CreateEnc24(&_encoderInst24Ptr); - WebRtcG7221_CreateEnc24(&_encoderInst24PtrR); - break; - } - case 32000: - { - WebRtcG7221_CreateEnc32(&_encoderInst32Ptr); - WebRtcG7221_CreateEnc32(&_encoderInst32PtrR); - break; - } - default: - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalCreateEncoder: Wrong rate for G722_1."); - return -1; - break; - } + case 24000: { + WebRtcG7221_CreateEnc24(&_encoderInst24Ptr); + WebRtcG7221_CreateEnc24(&_encoderInst24PtrR); + break; } - return 0; + case 32000: { + WebRtcG7221_CreateEnc32(&_encoderInst32Ptr); + WebRtcG7221_CreateEnc32(&_encoderInst32PtrR); + break; + } + default: { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalCreateEncoder: Wrong rate for G722_1."); + return -1; + } + } + return 0; } - -void -ACMG722_1::DestructEncoderSafe() -{ - _encoderExist = false; - _encoderInitialized = false; - if(_encoderInstPtr != NULL) - { - delete _encoderInstPtr; - _encoderInstPtr = NULL; - } - if(_encoderInstPtrRight != NULL) - { - delete _encoderInstPtrRight; - _encoderInstPtrRight = NULL; - } - _encoderInst16Ptr = NULL; - _encoderInst24Ptr = NULL; - _encoderInst32Ptr = NULL; +void ACMG722_1::DestructEncoderSafe() { + _encoderExist = false; + _encoderInitialized = false; + if (_encoderInstPtr != NULL) { + delete _encoderInstPtr; + _encoderInstPtr = NULL; + } + if (_encoderInstPtrRight != NULL) { + delete _encoderInstPtrRight; + _encoderInstPtrRight = NULL; + } + _encoderInst16Ptr = NULL; + _encoderInst24Ptr = NULL; + _encoderInst32Ptr = NULL; } - -WebRtc_Word16 -ACMG722_1::InternalCreateDecoder() -{ - if(_decoderInstPtr == NULL) - { - return -1; +WebRtc_Word16 ACMG722_1::InternalCreateDecoder() { + if (_decoderInstPtr == NULL) { + return -1; + } + switch (_operationalRate) { + case 16000: { + WebRtcG7221_CreateDec16(&_decoderInst16Ptr); + break; } - switch(_operationalRate) - { - case 16000: - { - WebRtcG7221_CreateDec16(&_decoderInst16Ptr); - break; - } - case 24000: - { - WebRtcG7221_CreateDec24(&_decoderInst24Ptr); - break; - } - case 32000: - { - WebRtcG7221_CreateDec32(&_decoderInst32Ptr); - break; - } - default: - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalCreateDecoder: Wrong rate for G722_1."); - return -1; - break; - } + case 24000: { + WebRtcG7221_CreateDec24(&_decoderInst24Ptr); + break; } - return 0; + case 32000: { + WebRtcG7221_CreateDec32(&_decoderInst32Ptr); + break; + } + default: { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalCreateDecoder: Wrong rate for G722_1."); + return -1; + } + } + return 0; } - -void -ACMG722_1::DestructDecoderSafe() -{ - _decoderExist = false; - _decoderInitialized = false; - if(_decoderInstPtr != NULL) - { - delete _decoderInstPtr; - _decoderInstPtr = NULL; - } - _decoderInst16Ptr = NULL; - _decoderInst24Ptr = NULL; - _decoderInst32Ptr = NULL; +void ACMG722_1::DestructDecoderSafe() { + _decoderExist = false; + _decoderInitialized = false; + if (_decoderInstPtr != NULL) { + delete _decoderInstPtr; + _decoderInstPtr = NULL; + } + _decoderInst16Ptr = NULL; + _decoderInst24Ptr = NULL; + _decoderInst32Ptr = NULL; } - -void -ACMG722_1::InternalDestructEncoderInst( - void* ptrInst) -{ - if(ptrInst != NULL) - { - delete ptrInst; - } - return; +void ACMG722_1::InternalDestructEncoderInst(void* ptrInst) { + if (ptrInst != NULL) { + delete ptrInst; + } + return; } - -WebRtc_Word16 -ACMG722_1::UnregisterFromNetEqSafe( - ACMNetEQ* netEq, - WebRtc_Word16 payloadType) -{ - if(payloadType != _decoderParams.codecInstant.pltype) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "Cannot unregister codec %s given payload-type %d does not match \ -the stored payload type", - _decoderParams.codecInstant.plname, - payloadType, - _decoderParams.codecInstant.pltype); - return -1; +WebRtc_Word16 ACMG722_1::UnregisterFromNetEqSafe(ACMNetEQ* netEq, + WebRtc_Word16 payloadType) { + if (payloadType != _decoderParams.codecInstant.pltype) { + WEBRTC_TRACE(webrtc::kTraceError, + webrtc::kTraceAudioCoding, + _uniqueID, + "Cannot unregister codec %s given payload-type %d does not " + "match the stored payload type", + _decoderParams.codecInstant.plname, payloadType, + _decoderParams.codecInstant.pltype); + return -1; + } + switch (_operationalRate) { + case 16000: { + return netEq->RemoveCodec(kDecoderG722_1_16); } - switch(_operationalRate) - { - case 16000: - { - return netEq->RemoveCodec(kDecoderG722_1_16); - } - case 24000: - { - return netEq->RemoveCodec(kDecoderG722_1_24); - } - case 32000: - { - return netEq->RemoveCodec(kDecoderG722_1_32); - } - default: - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "UnregisterFromNetEqSafe: Wrong rate for G722_1."); - return -1; - } + case 24000: { + return netEq->RemoveCodec(kDecoderG722_1_24); } + case 32000: { + return netEq->RemoveCodec(kDecoderG722_1_32); + } + default: { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "UnregisterFromNetEqSafe: Wrong rate for G722_1."); + return -1; + } + } } #endif diff --git a/src/modules/audio_coding/main/source/acm_g7221.h b/src/modules/audio_coding/main/source/acm_g7221.h index c3c52c83d..3130afde9 100644 --- a/src/modules/audio_coding/main/source/acm_g7221.h +++ b/src/modules/audio_coding/main/source/acm_g7221.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_G722_1_H -#define ACM_G722_1_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G722_1_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G722_1_H_ #include "acm_generic_codec.h" @@ -24,71 +24,62 @@ struct G722_1_Inst_t_; namespace webrtc { -class ACMG722_1 : public ACMGenericCodec -{ -public: - ACMG722_1(WebRtc_Word16 codecID); - ~ACMG722_1(); - // for FEC - ACMGenericCodec* CreateInstance(void); +class ACMG722_1: public ACMGenericCodec { + public: + ACMG722_1(WebRtc_Word16 codecID); + ~ACMG722_1(); + // for FEC + ACMGenericCodec* CreateInstance(void); - WebRtc_Word16 InternalEncode( - WebRtc_UWord8* bitstream, - WebRtc_Word16* bitStreamLenByte); + WebRtc_Word16 InternalEncode(WebRtc_UWord8* bitstream, + WebRtc_Word16* bitStreamLenByte); - WebRtc_Word16 InternalInitEncoder( - WebRtcACMCodecParams *codecParams); + WebRtc_Word16 InternalInitEncoder(WebRtcACMCodecParams *codecParams); - WebRtc_Word16 InternalInitDecoder( - WebRtcACMCodecParams *codecParams); + WebRtc_Word16 InternalInitDecoder(WebRtcACMCodecParams *codecParams); -protected: - WebRtc_Word16 DecodeSafe( - WebRtc_UWord8* bitStream, - WebRtc_Word16 bitStreamLenByte, - WebRtc_Word16* audio, - WebRtc_Word16* audioSamples, - WebRtc_Word8* speechType); + protected: + WebRtc_Word16 DecodeSafe(WebRtc_UWord8* bitStream, + WebRtc_Word16 bitStreamLenByte, + WebRtc_Word16* audio, WebRtc_Word16* audioSamples, + WebRtc_Word8* speechType); - WebRtc_Word32 CodecDef( - WebRtcNetEQ_CodecDef& codecDef, - const CodecInst& codecInst); + WebRtc_Word32 CodecDef(WebRtcNetEQ_CodecDef& codecDef, + const CodecInst& codecInst); - void DestructEncoderSafe(); - - void DestructDecoderSafe(); + void DestructEncoderSafe(); - WebRtc_Word16 InternalCreateEncoder(); - - WebRtc_Word16 InternalCreateDecoder(); - - void InternalDestructEncoderInst( - void* ptrInst); + void DestructDecoderSafe(); - WebRtc_Word16 UnregisterFromNetEqSafe( - ACMNetEQ* netEq, - WebRtc_Word16 payloadType); + WebRtc_Word16 InternalCreateEncoder(); - WebRtc_Word32 _operationalRate; + WebRtc_Word16 InternalCreateDecoder(); - G722_1_Inst_t_* _encoderInstPtr; - G722_1_Inst_t_* _encoderInstPtrRight; //Used in stereo mode - G722_1_Inst_t_* _decoderInstPtr; + void InternalDestructEncoderInst(void* ptrInst); - // Only one set of these pointer is valid at any instance - G722_1_16_encinst_t_* _encoderInst16Ptr; - G722_1_16_encinst_t_* _encoderInst16PtrR; - G722_1_24_encinst_t_* _encoderInst24Ptr; - G722_1_24_encinst_t_* _encoderInst24PtrR; - G722_1_32_encinst_t_* _encoderInst32Ptr; - G722_1_32_encinst_t_* _encoderInst32PtrR; + WebRtc_Word16 UnregisterFromNetEqSafe(ACMNetEQ* netEq, + WebRtc_Word16 payloadType); - // Only one of these pointer is valid at any instance - G722_1_16_decinst_t_* _decoderInst16Ptr; - G722_1_24_decinst_t_* _decoderInst24Ptr; - G722_1_32_decinst_t_* _decoderInst32Ptr; + WebRtc_Word32 _operationalRate; + + G722_1_Inst_t_* _encoderInstPtr; + G722_1_Inst_t_* _encoderInstPtrRight; //Used in stereo mode + G722_1_Inst_t_* _decoderInstPtr; + + // Only one set of these pointer is valid at any instance + G722_1_16_encinst_t_* _encoderInst16Ptr; + G722_1_16_encinst_t_* _encoderInst16PtrR; + G722_1_24_encinst_t_* _encoderInst24Ptr; + G722_1_24_encinst_t_* _encoderInst24PtrR; + G722_1_32_encinst_t_* _encoderInst32Ptr; + G722_1_32_encinst_t_* _encoderInst32PtrR; + + // Only one of these pointer is valid at any instance + G722_1_16_decinst_t_* _decoderInst16Ptr; + G722_1_24_decinst_t_* _decoderInst24Ptr; + G722_1_32_decinst_t_* _decoderInst32Ptr; }; } // namespace webrtc -#endif // ACM_G722_1_H +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G722_1_H_ diff --git a/src/modules/audio_coding/main/source/acm_g7221c.cc b/src/modules/audio_coding/main/source/acm_g7221c.cc index 4b1ead4c0..300ce190d 100644 --- a/src/modules/audio_coding/main/source/acm_g7221c.cc +++ b/src/modules/audio_coding/main/source/acm_g7221c.cc @@ -17,71 +17,71 @@ #include "trace.h" #ifdef WEBRTC_CODEC_G722_1C - // NOTE! G.722.1C is not included in the open-source package. The following - // interface file is needed: - // - // /modules/audio_coding/codecs/g7221c/main/interface/g7221c_interface.h - // - // The API in the header file should match the one below. - // - // int16_t WebRtcG7221C_CreateEnc24(G722_1C_24_encinst_t_** encInst); - // int16_t WebRtcG7221C_CreateEnc32(G722_1C_32_encinst_t_** encInst); - // int16_t WebRtcG7221C_CreateEnc48(G722_1C_48_encinst_t_** encInst); - // int16_t WebRtcG7221C_CreateDec24(G722_1C_24_decinst_t_** decInst); - // int16_t WebRtcG7221C_CreateDec32(G722_1C_32_decinst_t_** decInst); - // int16_t WebRtcG7221C_CreateDec48(G722_1C_48_decinst_t_** decInst); - // - // int16_t WebRtcG7221C_FreeEnc24(G722_1C_24_encinst_t_** encInst); - // int16_t WebRtcG7221C_FreeEnc32(G722_1C_32_encinst_t_** encInst); - // int16_t WebRtcG7221C_FreeEnc48(G722_1C_48_encinst_t_** encInst); - // int16_t WebRtcG7221C_FreeDec24(G722_1C_24_decinst_t_** decInst); - // int16_t WebRtcG7221C_FreeDec32(G722_1C_32_decinst_t_** decInst); - // int16_t WebRtcG7221C_FreeDec48(G722_1C_48_decinst_t_** decInst); - // - // int16_t WebRtcG7221C_EncoderInit24(G722_1C_24_encinst_t_* encInst); - // int16_t WebRtcG7221C_EncoderInit32(G722_1C_32_encinst_t_* encInst); - // int16_t WebRtcG7221C_EncoderInit48(G722_1C_48_encinst_t_* encInst); - // int16_t WebRtcG7221C_DecoderInit24(G722_1C_24_decinst_t_* decInst); - // int16_t WebRtcG7221C_DecoderInit32(G722_1C_32_decinst_t_* decInst); - // int16_t WebRtcG7221C_DecoderInit48(G722_1C_48_decinst_t_* decInst); - // - // int16_t WebRtcG7221C_Encode24(G722_1C_24_encinst_t_* encInst, - // int16_t* input, - // int16_t len, - // int16_t* output); - // int16_t WebRtcG7221C_Encode32(G722_1C_32_encinst_t_* encInst, - // int16_t* input, - // int16_t len, - // int16_t* output); - // int16_t WebRtcG7221C_Encode48(G722_1C_48_encinst_t_* encInst, - // int16_t* input, - // int16_t len, - // int16_t* output); - // - // int16_t WebRtcG7221C_Decode24(G722_1C_24_decinst_t_* decInst, - // int16_t* bitstream, - // int16_t len, - // int16_t* output); - // int16_t WebRtcG7221C_Decode32(G722_1C_32_decinst_t_* decInst, - // int16_t* bitstream, - // int16_t len, - // int16_t* output); - // int16_t WebRtcG7221C_Decode48(G722_1C_48_decinst_t_* decInst, - // int16_t* bitstream, - // int16_t len, - // int16_t* output); - // - // int16_t WebRtcG7221C_DecodePlc24(G722_1C_24_decinst_t_* decInst, - // int16_t* output, - // int16_t nrLostFrames); - // int16_t WebRtcG7221C_DecodePlc32(G722_1C_32_decinst_t_* decInst, - // int16_t* output, - // int16_t nrLostFrames); - // int16_t WebRtcG7221C_DecodePlc48(G722_1C_48_decinst_t_* decInst, - // int16_t* output, - // int16_t nrLostFrames); - // void WebRtcG7221C_Version(char *versionStr, short len); - #include "g7221c_interface.h" +// NOTE! G.722.1C is not included in the open-source package. The following +// interface file is needed: +// +// /modules/audio_coding/codecs/g7221c/main/interface/g7221c_interface.h +// +// The API in the header file should match the one below. +// +// int16_t WebRtcG7221C_CreateEnc24(G722_1C_24_encinst_t_** encInst); +// int16_t WebRtcG7221C_CreateEnc32(G722_1C_32_encinst_t_** encInst); +// int16_t WebRtcG7221C_CreateEnc48(G722_1C_48_encinst_t_** encInst); +// int16_t WebRtcG7221C_CreateDec24(G722_1C_24_decinst_t_** decInst); +// int16_t WebRtcG7221C_CreateDec32(G722_1C_32_decinst_t_** decInst); +// int16_t WebRtcG7221C_CreateDec48(G722_1C_48_decinst_t_** decInst); +// +// int16_t WebRtcG7221C_FreeEnc24(G722_1C_24_encinst_t_** encInst); +// int16_t WebRtcG7221C_FreeEnc32(G722_1C_32_encinst_t_** encInst); +// int16_t WebRtcG7221C_FreeEnc48(G722_1C_48_encinst_t_** encInst); +// int16_t WebRtcG7221C_FreeDec24(G722_1C_24_decinst_t_** decInst); +// int16_t WebRtcG7221C_FreeDec32(G722_1C_32_decinst_t_** decInst); +// int16_t WebRtcG7221C_FreeDec48(G722_1C_48_decinst_t_** decInst); +// +// int16_t WebRtcG7221C_EncoderInit24(G722_1C_24_encinst_t_* encInst); +// int16_t WebRtcG7221C_EncoderInit32(G722_1C_32_encinst_t_* encInst); +// int16_t WebRtcG7221C_EncoderInit48(G722_1C_48_encinst_t_* encInst); +// int16_t WebRtcG7221C_DecoderInit24(G722_1C_24_decinst_t_* decInst); +// int16_t WebRtcG7221C_DecoderInit32(G722_1C_32_decinst_t_* decInst); +// int16_t WebRtcG7221C_DecoderInit48(G722_1C_48_decinst_t_* decInst); +// +// int16_t WebRtcG7221C_Encode24(G722_1C_24_encinst_t_* encInst, +// int16_t* input, +// int16_t len, +// int16_t* output); +// int16_t WebRtcG7221C_Encode32(G722_1C_32_encinst_t_* encInst, +// int16_t* input, +// int16_t len, +// int16_t* output); +// int16_t WebRtcG7221C_Encode48(G722_1C_48_encinst_t_* encInst, +// int16_t* input, +// int16_t len, +// int16_t* output); +// +// int16_t WebRtcG7221C_Decode24(G722_1C_24_decinst_t_* decInst, +// int16_t* bitstream, +// int16_t len, +// int16_t* output); +// int16_t WebRtcG7221C_Decode32(G722_1C_32_decinst_t_* decInst, +// int16_t* bitstream, +// int16_t len, +// int16_t* output); +// int16_t WebRtcG7221C_Decode48(G722_1C_48_decinst_t_* decInst, +// int16_t* bitstream, +// int16_t len, +// int16_t* output); +// +// int16_t WebRtcG7221C_DecodePlc24(G722_1C_24_decinst_t_* decInst, +// int16_t* output, +// int16_t nrLostFrames); +// int16_t WebRtcG7221C_DecodePlc32(G722_1C_32_decinst_t_* decInst, +// int16_t* output, +// int16_t nrLostFrames); +// int16_t WebRtcG7221C_DecodePlc48(G722_1C_48_decinst_t_* decInst, +// int16_t* output, +// int16_t nrLostFrames); +// void WebRtcG7221C_Version(char *versionStr, short len); +#include "g7221c_interface.h" #endif namespace webrtc { @@ -89,595 +89,430 @@ namespace webrtc { #ifndef WEBRTC_CODEC_G722_1C ACMG722_1C::ACMG722_1C( - WebRtc_Word16 /* codecID */) -{ - return; + WebRtc_Word16 /* codecID */) { + return; } -ACMG722_1C::~ACMG722_1C() -{ - return; +ACMG722_1C::~ACMG722_1C() { + return; } - -WebRtc_Word16 -ACMG722_1C::InternalEncode( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16* /* bitStreamLenByte */) -{ - return -1; +WebRtc_Word16 ACMG722_1C::InternalEncode( + WebRtc_UWord8* /* bitStream */, + WebRtc_Word16* /* bitStreamLenByte */) { + return -1; } - -WebRtc_Word16 -ACMG722_1C::DecodeSafe( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, - WebRtc_Word16* /* audio */, - WebRtc_Word16* /* audioSamples */, - WebRtc_Word8* /* speechType */) -{ - return -1; +WebRtc_Word16 ACMG722_1C::DecodeSafe(WebRtc_UWord8* /* bitStream */, + WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16* /* audio */, + WebRtc_Word16* /* audioSamples */, + WebRtc_Word8* /* speechType */) { + return -1; } - -WebRtc_Word16 -ACMG722_1C::InternalInitEncoder( - WebRtcACMCodecParams* /* codecParams */) -{ - return -1; +WebRtc_Word16 ACMG722_1C::InternalInitEncoder( + WebRtcACMCodecParams* /* codecParams */) { + return -1; } - -WebRtc_Word16 -ACMG722_1C::InternalInitDecoder( - WebRtcACMCodecParams* /* codecParams */) -{ - return -1; +WebRtc_Word16 ACMG722_1C::InternalInitDecoder( + WebRtcACMCodecParams* /* codecParams */) { + return -1; } - -WebRtc_Word32 -ACMG722_1C::CodecDef( - WebRtcNetEQ_CodecDef& /* codecDef */, - const CodecInst& /* codecInst */) -{ - return -1; +WebRtc_Word32 ACMG722_1C::CodecDef(WebRtcNetEQ_CodecDef& /* codecDef */, + const CodecInst& /* codecInst */) { + return -1; } -ACMGenericCodec* -ACMG722_1C::CreateInstance(void) -{ - return NULL; +ACMGenericCodec* ACMG722_1C::CreateInstance(void) { + return NULL; } - -WebRtc_Word16 -ACMG722_1C::InternalCreateEncoder() -{ - return -1; +WebRtc_Word16 ACMG722_1C::InternalCreateEncoder() { + return -1; } - -void -ACMG722_1C::DestructEncoderSafe() -{ - return; +void ACMG722_1C::DestructEncoderSafe() { + return; } - -WebRtc_Word16 -ACMG722_1C::InternalCreateDecoder() -{ - return -1; +WebRtc_Word16 ACMG722_1C::InternalCreateDecoder() { + return -1; } - -void -ACMG722_1C::DestructDecoderSafe() -{ - return; +void ACMG722_1C::DestructDecoderSafe() { + return; } - -void -ACMG722_1C::InternalDestructEncoderInst( - void* /* ptrInst */) -{ - return; +void ACMG722_1C::InternalDestructEncoderInst(void* /* ptrInst */) { + return; } - -WebRtc_Word16 -ACMG722_1C::UnregisterFromNetEqSafe( - ACMNetEQ* /* netEq */, - WebRtc_Word16 /* payloadType */) -{ - return -1; +WebRtc_Word16 ACMG722_1C::UnregisterFromNetEqSafe( + ACMNetEQ* /* netEq */, + WebRtc_Word16 /* payloadType */) { + return -1; } - #else //===================== Actual Implementation ======================= - -ACMG722_1C::ACMG722_1C( - WebRtc_Word16 codecID): -_encoderInstPtr(NULL), -_encoderInstPtrRight(NULL), -_decoderInstPtr(NULL), -_encoderInst24Ptr(NULL), -_encoderInst24PtrR(NULL), -_encoderInst32Ptr(NULL), -_encoderInst32PtrR(NULL), -_encoderInst48Ptr(NULL), -_encoderInst48PtrR(NULL), -_decoderInst24Ptr(NULL), -_decoderInst32Ptr(NULL), -_decoderInst48Ptr(NULL) -{ - _codecID = codecID; - if(_codecID == ACMCodecDB::kG722_1C_24) - { - _operationalRate = 24000; - } - else if(_codecID == ACMCodecDB::kG722_1C_32) - { - _operationalRate = 32000; - } - else if(_codecID == ACMCodecDB::kG722_1C_48) - { - _operationalRate = 48000; - } - else - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "Wrong codec id for G722_1c."); - - _operationalRate = -1; - } - return; +ACMG722_1C::ACMG722_1C(WebRtc_Word16 codecID) : + _encoderInstPtr(NULL), _encoderInstPtrRight(NULL), _decoderInstPtr(NULL), + _encoderInst24Ptr(NULL), _encoderInst24PtrR(NULL), _encoderInst32Ptr(NULL), + _encoderInst32PtrR(NULL), _encoderInst48Ptr(NULL), _encoderInst48PtrR(NULL), + _decoderInst24Ptr(NULL), _decoderInst32Ptr(NULL), _decoderInst48Ptr(NULL) { + _codecID = codecID; + if (_codecID == ACMCodecDB::kG722_1C_24) { + _operationalRate = 24000; + } else if (_codecID == ACMCodecDB::kG722_1C_32) { + _operationalRate = 32000; + } else if (_codecID == ACMCodecDB::kG722_1C_48) { + _operationalRate = 48000; + } else { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "Wrong codec id for G722_1c."); + _operationalRate = -1; + } + return; } -ACMG722_1C::~ACMG722_1C() -{ - if(_encoderInstPtr != NULL) - { - delete _encoderInstPtr; - _encoderInstPtr = NULL; - } - if(_encoderInstPtrRight != NULL) - { - delete _encoderInstPtrRight; - _encoderInstPtrRight = NULL; - } - if(_decoderInstPtr != NULL) - { - delete _decoderInstPtr; - _decoderInstPtr = NULL; - } +ACMG722_1C::~ACMG722_1C() { + if (_encoderInstPtr != NULL) { + delete _encoderInstPtr; + _encoderInstPtr = NULL; + } + if (_encoderInstPtrRight != NULL) { + delete _encoderInstPtrRight; + _encoderInstPtrRight = NULL; + } + if (_decoderInstPtr != NULL) { + delete _decoderInstPtr; + _decoderInstPtr = NULL; + } - switch(_operationalRate) - { - case 24000: - { - _encoderInst24Ptr = NULL; - _encoderInst24PtrR = NULL; - _decoderInst24Ptr = NULL; - break; - } - case 32000: - { - _encoderInst32Ptr = NULL; - _encoderInst32PtrR = NULL; - _decoderInst32Ptr = NULL; - break; - } - case 48000: - { - _encoderInst48Ptr = NULL; - _encoderInst48PtrR = NULL; - _decoderInst48Ptr = NULL; - break; - } - default: - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "Wrong rate for G722_1c."); - break; - } + switch (_operationalRate) { + case 24000: { + _encoderInst24Ptr = NULL; + _encoderInst24PtrR = NULL; + _decoderInst24Ptr = NULL; + break; } - return; + case 32000: { + _encoderInst32Ptr = NULL; + _encoderInst32PtrR = NULL; + _decoderInst32Ptr = NULL; + break; + } + case 48000: { + _encoderInst48Ptr = NULL; + _encoderInst48PtrR = NULL; + _decoderInst48Ptr = NULL; + break; + } + default: { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "Wrong rate for G722_1c."); + break; + } + } + return; } +WebRtc_Word16 ACMG722_1C::InternalEncode(WebRtc_UWord8* bitStream, + WebRtc_Word16* bitStreamLenByte) { + WebRtc_Word16 leftChannel[640]; + WebRtc_Word16 rightChannel[640]; + WebRtc_Word16 lenInBytes; + WebRtc_Word16 outB[240]; -WebRtc_Word16 -ACMG722_1C::InternalEncode( - WebRtc_UWord8* bitStream, - WebRtc_Word16* bitStreamLenByte) -{ - WebRtc_Word16 leftChannel[640]; - WebRtc_Word16 rightChannel[640]; - WebRtc_Word16 lenInBytes; - WebRtc_Word16 outB[240]; - - // If stereo, split input signal in left and right channel before encoding - if(_noChannels == 2) - { - for (int i=0, j=0; i<_frameLenSmpl*2; i+=2, j++) { - leftChannel[j] = _inAudio[_inAudioIxRead+i]; - rightChannel[j] = _inAudio[_inAudioIxRead+i+1]; - } - } else { - memcpy(leftChannel, &_inAudio[_inAudioIxRead], 640); + // If stereo, split input signal in left and right channel before encoding + if (_noChannels == 2) { + for (int i = 0, j = 0; i < _frameLenSmpl * 2; i += 2, j++) { + leftChannel[j] = _inAudio[_inAudioIxRead + i]; + rightChannel[j] = _inAudio[_inAudioIxRead + i + 1]; } + } else { + memcpy(leftChannel, &_inAudio[_inAudioIxRead], 640); + } - switch(_operationalRate) - { - case 24000: - { - lenInBytes = WebRtcG7221C_Encode24(_encoderInst24Ptr, - leftChannel, 640, &outB[0]); - if (_noChannels == 2) - { - lenInBytes += WebRtcG7221C_Encode24(_encoderInst24PtrR, - rightChannel, 640, &outB[lenInBytes/2]); - } - break; - } - case 32000: - { - lenInBytes = WebRtcG7221C_Encode32(_encoderInst32Ptr, - leftChannel, 640, &outB[0]); - if (_noChannels == 2) - { - lenInBytes += WebRtcG7221C_Encode32(_encoderInst32PtrR, - rightChannel, 640, &outB[lenInBytes/2]); - } - break; - } - case 48000: - { - lenInBytes = WebRtcG7221C_Encode48(_encoderInst48Ptr, - leftChannel, 640, &outB[0]); - if (_noChannels == 2) - { - lenInBytes += WebRtcG7221C_Encode48(_encoderInst48PtrR, - rightChannel, 640, &outB[lenInBytes/2]); - } - break; - } - default: - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalEncode: Wrong rate for G722_1c."); - return -1; - break; - } + switch (_operationalRate) { + case 24000: { + lenInBytes = WebRtcG7221C_Encode24(_encoderInst24Ptr, leftChannel, 640, + &outB[0]); + if (_noChannels == 2) { + lenInBytes += WebRtcG7221C_Encode24(_encoderInst24PtrR, rightChannel, + 640, &outB[lenInBytes / 2]); + } + break; } - - memcpy(bitStream, outB, lenInBytes); - *bitStreamLenByte = lenInBytes; - - // increment the read index this tell the caller that how far - // we have gone forward in reading the audio buffer - _inAudioIxRead += 640*_noChannels; + case 32000: { + lenInBytes = WebRtcG7221C_Encode32(_encoderInst32Ptr, leftChannel, 640, + &outB[0]); + if (_noChannels == 2) { + lenInBytes += WebRtcG7221C_Encode32(_encoderInst32PtrR, rightChannel, + 640, &outB[lenInBytes / 2]); + } + break; + } + case 48000: { + lenInBytes = WebRtcG7221C_Encode48(_encoderInst48Ptr, leftChannel, 640, + &outB[0]); + if (_noChannels == 2) { + lenInBytes += WebRtcG7221C_Encode48(_encoderInst48PtrR, rightChannel, + 640, &outB[lenInBytes / 2]); + } + break; + } + default: { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalEncode: Wrong rate for G722_1c."); + return -1; + } + } - return *bitStreamLenByte; + memcpy(bitStream, outB, lenInBytes); + *bitStreamLenByte = lenInBytes; + + // increment the read index this tell the caller that how far + // we have gone forward in reading the audio buffer + _inAudioIxRead += 640 * _noChannels; + + return *bitStreamLenByte; } - -WebRtc_Word16 -ACMG722_1C::DecodeSafe( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, - WebRtc_Word16* /* audio */, - WebRtc_Word16* /* audioSamples */, - WebRtc_Word8* /* speechType */) -{ - return 0; +WebRtc_Word16 ACMG722_1C::DecodeSafe(WebRtc_UWord8* /* bitStream */, + WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16* /* audio */, + WebRtc_Word16* /* audioSamples */, + WebRtc_Word8* /* speechType */) { + return 0; } -WebRtc_Word16 -ACMG722_1C::InternalInitEncoder( - WebRtcACMCodecParams* codecParams) -{ - WebRtc_Word16 ret; - - switch(_operationalRate) - { - case 24000: - { - ret = WebRtcG7221C_EncoderInit24(_encoderInst24PtrR); - if (ret < 0) { - return ret; - } - return WebRtcG7221C_EncoderInit24(_encoderInst24Ptr); - break; - } - case 32000: - { - ret = WebRtcG7221C_EncoderInit32(_encoderInst32PtrR); - if (ret < 0) { - return ret; - } - return WebRtcG7221C_EncoderInit32(_encoderInst32Ptr); - break; - } - case 48000: - { - ret = WebRtcG7221C_EncoderInit48(_encoderInst48PtrR); - if (ret < 0) { - return ret; - } - return WebRtcG7221C_EncoderInit48(_encoderInst48Ptr); - break; - } - default: - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalInitEncode: Wrong rate for G722_1c."); - return -1; - break; - } +WebRtc_Word16 ACMG722_1C::InternalInitEncoder( + WebRtcACMCodecParams* codecParams) { + WebRtc_Word16 ret; + + switch (_operationalRate) { + case 24000: { + ret = WebRtcG7221C_EncoderInit24(_encoderInst24PtrR); + if (ret < 0) { + return ret; + } + return WebRtcG7221C_EncoderInit24(_encoderInst24Ptr); } + case 32000: { + ret = WebRtcG7221C_EncoderInit32(_encoderInst32PtrR); + if (ret < 0) { + return ret; + } + return WebRtcG7221C_EncoderInit32(_encoderInst32Ptr); + } + case 48000: { + ret = WebRtcG7221C_EncoderInit48(_encoderInst48PtrR); + if (ret < 0) { + return ret; + } + return WebRtcG7221C_EncoderInit48(_encoderInst48Ptr); + } + default: { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalInitEncode: Wrong rate for G722_1c."); + return -1; + } + } } - -WebRtc_Word16 -ACMG722_1C::InternalInitDecoder( - WebRtcACMCodecParams* /* codecParams */) -{ - switch(_operationalRate) - { - case 24000: - { - return WebRtcG7221C_DecoderInit24(_decoderInst24Ptr); - break; - } - case 32000: - { - return WebRtcG7221C_DecoderInit32(_decoderInst32Ptr); - break; - } - case 48000: - { - return WebRtcG7221C_DecoderInit48(_decoderInst48Ptr); - break; - } - default: - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalInitDecoder: Wrong rate for G722_1c."); - return -1; - break; - } +WebRtc_Word16 ACMG722_1C::InternalInitDecoder( + WebRtcACMCodecParams* /* codecParams */) { + switch (_operationalRate) { + case 24000: { + return WebRtcG7221C_DecoderInit24(_decoderInst24Ptr); } + case 32000: { + return WebRtcG7221C_DecoderInit32(_decoderInst32Ptr); + } + case 48000: { + return WebRtcG7221C_DecoderInit48(_decoderInst48Ptr); + } + default: { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalInitDecoder: Wrong rate for G722_1c."); + return -1; + } + } } +WebRtc_Word32 ACMG722_1C::CodecDef(WebRtcNetEQ_CodecDef& codecDef, + const CodecInst& codecInst) { -WebRtc_Word32 -ACMG722_1C::CodecDef( - WebRtcNetEQ_CodecDef& codecDef, - const CodecInst& codecInst) -{ - - if (!_decoderInitialized) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "CodeDef: decoder not initialized for G722_1c"); - return -1; + if (!_decoderInitialized) { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "CodeDef: decoder not initialized for G722_1c"); + return -1; + } + // NetEq has an array of pointers to WebRtcNetEQ_CodecDef. + // get an entry of that array (neteq wrapper will allocate memory) + // by calling "netEq->CodecDef", where "NETEQ_CODEC_G722_1_XX" would + // be the index of the entry. + // Fill up the given structure by calling + // "SET_CODEC_PAR" & "SET_G722_1_XX_FUNCTION." + // Then return the structure back to NetEQ to add the codec to it's + // database. + switch (_operationalRate) { + case 24000: { + SET_CODEC_PAR((codecDef), kDecoderG722_1C_24, codecInst.pltype, + _decoderInst24Ptr, 32000); + SET_G722_1C_24_FUNCTIONS((codecDef)); + break; } - // NetEq has an array of pointers to WebRtcNetEQ_CodecDef. - // get an entry of that array (neteq wrapper will allocate memory) - // by calling "netEq->CodecDef", where "NETEQ_CODEC_G722_1_XX" would - // be the index of the entry. - // Fill up the given structure by calling - // "SET_CODEC_PAR" & "SET_G722_1_XX_FUNCTION." - // Then return the structure back to NetEQ to add the codec to it's - // database. - switch(_operationalRate) - { - case 24000: - { - SET_CODEC_PAR((codecDef), kDecoderG722_1C_24, codecInst.pltype, - _decoderInst24Ptr, 32000); - SET_G722_1C_24_FUNCTIONS((codecDef)); - break; - } - case 32000: - { - SET_CODEC_PAR((codecDef), kDecoderG722_1C_32, codecInst.pltype, - _decoderInst32Ptr, 32000); - SET_G722_1C_32_FUNCTIONS((codecDef)); - break; - } - case 48000: - { - SET_CODEC_PAR((codecDef), kDecoderG722_1C_32, codecInst.pltype, - _decoderInst48Ptr, 32000); - SET_G722_1C_48_FUNCTIONS((codecDef)); - break; - } - default: - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "CodeDef: Wrong rate for G722_1c."); - return -1; - break; - } + case 32000: { + SET_CODEC_PAR((codecDef), kDecoderG722_1C_32, codecInst.pltype, + _decoderInst32Ptr, 32000); + SET_G722_1C_32_FUNCTIONS((codecDef)); + break; } - return 0; + case 48000: { + SET_CODEC_PAR((codecDef), kDecoderG722_1C_32, codecInst.pltype, + _decoderInst48Ptr, 32000); + SET_G722_1C_48_FUNCTIONS((codecDef)); + break; + } + default: { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "CodeDef: Wrong rate for G722_1c."); + return -1; + } + } + return 0; } -ACMGenericCodec* -ACMG722_1C::CreateInstance(void) -{ - return NULL; +ACMGenericCodec* +ACMG722_1C::CreateInstance(void) { + return NULL; } - -WebRtc_Word16 -ACMG722_1C::InternalCreateEncoder() -{ - if((_encoderInstPtr == NULL) || (_encoderInstPtrRight == NULL)) - { - return -1; +WebRtc_Word16 ACMG722_1C::InternalCreateEncoder() { + if ((_encoderInstPtr == NULL) || (_encoderInstPtrRight == NULL)) { + return -1; + } + switch (_operationalRate) { + case 24000: { + WebRtcG7221C_CreateEnc24(&_encoderInst24Ptr); + WebRtcG7221C_CreateEnc24(&_encoderInst24PtrR); + break; } - switch(_operationalRate) - { - case 24000: - { - WebRtcG7221C_CreateEnc24(&_encoderInst24Ptr); - WebRtcG7221C_CreateEnc24(&_encoderInst24PtrR); - break; - } - case 32000: - { - WebRtcG7221C_CreateEnc32(&_encoderInst32Ptr); - WebRtcG7221C_CreateEnc32(&_encoderInst32PtrR); - break; - } - case 48000: - { - WebRtcG7221C_CreateEnc48(&_encoderInst48Ptr); - WebRtcG7221C_CreateEnc48(&_encoderInst48PtrR); - break; - } - default: - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalCreateEncoder: Wrong rate for G722_1c."); - return -1; - break; - } + case 32000: { + WebRtcG7221C_CreateEnc32(&_encoderInst32Ptr); + WebRtcG7221C_CreateEnc32(&_encoderInst32PtrR); + break; } - return 0; + case 48000: { + WebRtcG7221C_CreateEnc48(&_encoderInst48Ptr); + WebRtcG7221C_CreateEnc48(&_encoderInst48PtrR); + break; + } + default: { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalCreateEncoder: Wrong rate for G722_1c."); + return -1; + } + } + return 0; } - -void -ACMG722_1C::DestructEncoderSafe() -{ - _encoderExist = false; - _encoderInitialized = false; - if(_encoderInstPtr != NULL) - { - delete _encoderInstPtr; - _encoderInstPtr = NULL; - } - if(_encoderInstPtrRight != NULL) - { - delete _encoderInstPtrRight; - _encoderInstPtrRight = NULL; - } - _encoderInst24Ptr = NULL; - _encoderInst32Ptr = NULL; - _encoderInst48Ptr = NULL; +void ACMG722_1C::DestructEncoderSafe() { + _encoderExist = false; + _encoderInitialized = false; + if (_encoderInstPtr != NULL) { + delete _encoderInstPtr; + _encoderInstPtr = NULL; + } + if (_encoderInstPtrRight != NULL) { + delete _encoderInstPtrRight; + _encoderInstPtrRight = NULL; + } + _encoderInst24Ptr = NULL; + _encoderInst32Ptr = NULL; + _encoderInst48Ptr = NULL; } - -WebRtc_Word16 -ACMG722_1C::InternalCreateDecoder() -{ - if(_decoderInstPtr == NULL) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalCreateEncoder: cannot create decoder"); - return -1; +WebRtc_Word16 ACMG722_1C::InternalCreateDecoder() { + if (_decoderInstPtr == NULL) { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalCreateEncoder: cannot create decoder"); + return -1; + } + switch (_operationalRate) { + case 24000: { + WebRtcG7221C_CreateDec24(&_decoderInst24Ptr); + break; } - switch(_operationalRate) - { - case 24000: - { - WebRtcG7221C_CreateDec24(&_decoderInst24Ptr); - break; - } - case 32000: - { - WebRtcG7221C_CreateDec32(&_decoderInst32Ptr); - break; - } - case 48000: - { - WebRtcG7221C_CreateDec48(&_decoderInst48Ptr); - break; - } - default: - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalCreateEncoder: Wrong rate for G722_1c."); - return -1; - break; - } + case 32000: { + WebRtcG7221C_CreateDec32(&_decoderInst32Ptr); + break; } - return 0; + case 48000: { + WebRtcG7221C_CreateDec48(&_decoderInst48Ptr); + break; + } + default: { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalCreateEncoder: Wrong rate for G722_1c."); + return -1; + } + } + return 0; } - -void -ACMG722_1C::DestructDecoderSafe() -{ - _decoderExist = false; - _decoderInitialized = false; - if(_decoderInstPtr != NULL) - { - delete _decoderInstPtr; - _decoderInstPtr = NULL; - } - _decoderInst24Ptr = NULL; - _decoderInst32Ptr = NULL; - _decoderInst48Ptr = NULL; +void ACMG722_1C::DestructDecoderSafe() { + _decoderExist = false; + _decoderInitialized = false; + if (_decoderInstPtr != NULL) { + delete _decoderInstPtr; + _decoderInstPtr = NULL; + } + _decoderInst24Ptr = NULL; + _decoderInst32Ptr = NULL; + _decoderInst48Ptr = NULL; } - -void -ACMG722_1C::InternalDestructEncoderInst( - void* ptrInst) -{ - if(ptrInst != NULL) - { - delete ptrInst; - } - return; +void ACMG722_1C::InternalDestructEncoderInst(void* ptrInst) { + if (ptrInst != NULL) { + delete ptrInst; + } + return; } - -WebRtc_Word16 -ACMG722_1C::UnregisterFromNetEqSafe( - ACMNetEQ* netEq, - WebRtc_Word16 payloadType) -{ - if(payloadType != _decoderParams.codecInstant.pltype) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "Cannot unregister codec %s given payload-type %d does not match \ -the stored payload type", - _decoderParams.codecInstant.plname, - payloadType, - _decoderParams.codecInstant.pltype); - return -1; +WebRtc_Word16 ACMG722_1C::UnregisterFromNetEqSafe(ACMNetEQ* netEq, + WebRtc_Word16 payloadType) { + if (payloadType != _decoderParams.codecInstant.pltype) { + WEBRTC_TRACE(webrtc::kTraceError, + webrtc::kTraceAudioCoding, + _uniqueID, + "Cannot unregister codec %s given payload-type %d does not" + "match the stored payload type", + _decoderParams.codecInstant.plname, payloadType, + _decoderParams.codecInstant.pltype); + return -1; + } + switch (_operationalRate) { + case 24000: { + return netEq->RemoveCodec(kDecoderG722_1C_24); } - switch(_operationalRate) - { - case 24000: - { - return netEq->RemoveCodec(kDecoderG722_1C_24); - } - case 32000: - { - return netEq->RemoveCodec(kDecoderG722_1C_32); - } - case 48000: - { - return netEq->RemoveCodec(kDecoderG722_1C_48); - } - default: - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "Could not remove codec from NetEQ for G722_1c. \ -Sampling frequency doesn't match"); - return -1; - } + case 32000: { + return netEq->RemoveCodec(kDecoderG722_1C_32); } + case 48000: { + return netEq->RemoveCodec(kDecoderG722_1C_48); + } + default: { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "Could not remove codec from NetEQ for G722_1c." + "Sampling frequency doesn't match"); + return -1; + } + } } #endif diff --git a/src/modules/audio_coding/main/source/acm_g7221c.h b/src/modules/audio_coding/main/source/acm_g7221c.h index a57113a95..5129e4c5a 100644 --- a/src/modules/audio_coding/main/source/acm_g7221c.h +++ b/src/modules/audio_coding/main/source/acm_g7221c.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_G722_1C_H -#define ACM_G722_1C_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G722_1C_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G722_1C_H_ #include "acm_generic_codec.h" @@ -33,7 +33,7 @@ public: ACMGenericCodec* CreateInstance(void); WebRtc_Word16 InternalEncode( - WebRtc_UWord8* bitstream, + WebRtc_UWord8* bitstream, WebRtc_Word16* bitStreamLenByte); WebRtc_Word16 InternalInitEncoder( @@ -45,23 +45,23 @@ public: protected: WebRtc_Word16 DecodeSafe( WebRtc_UWord8* bitStream, - WebRtc_Word16 bitStreamLenByte, - WebRtc_Word16* audio, - WebRtc_Word16* audioSamples, + WebRtc_Word16 bitStreamLenByte, + WebRtc_Word16* audio, + WebRtc_Word16* audioSamples, WebRtc_Word8* speechType); WebRtc_Word32 CodecDef( - WebRtcNetEQ_CodecDef& codecDef, + WebRtcNetEQ_CodecDef& codecDef, const CodecInst& codecInst); void DestructEncoderSafe(); - + void DestructDecoderSafe(); WebRtc_Word16 InternalCreateEncoder(); - + WebRtc_Word16 InternalCreateDecoder(); - + void InternalDestructEncoderInst( void* ptrInst); @@ -91,4 +91,4 @@ protected: } // namespace webrtc; -#endif // ACM_G722_1C_H +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G722_1C_H_ diff --git a/src/modules/audio_coding/main/source/acm_g729.h b/src/modules/audio_coding/main/source/acm_g729.h index 800e65c50..50b648aaa 100644 --- a/src/modules/audio_coding/main/source/acm_g729.h +++ b/src/modules/audio_coding/main/source/acm_g729.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_G729_H -#define ACM_G729_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G729_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G729_H_ #include "acm_generic_codec.h" @@ -40,28 +40,28 @@ public: protected: WebRtc_Word16 DecodeSafe( WebRtc_UWord8* bitStream, - WebRtc_Word16 bitStreamLenByte, - WebRtc_Word16* audio, - WebRtc_Word16* audioSamples, + WebRtc_Word16 bitStreamLenByte, + WebRtc_Word16* audio, + WebRtc_Word16* audioSamples, WebRtc_Word8* speechType); WebRtc_Word32 CodecDef( - WebRtcNetEQ_CodecDef& codecDef, + WebRtcNetEQ_CodecDef& codecDef, const CodecInst& codecInst); void DestructEncoderSafe(); - + void DestructDecoderSafe(); WebRtc_Word16 InternalCreateEncoder(); - + WebRtc_Word16 InternalCreateDecoder(); - + void InternalDestructEncoderInst( void* ptrInst); WebRtc_Word16 EnableDTX(); - + WebRtc_Word16 DisableDTX(); WebRtc_Word32 ReplaceInternalDTXSafe( @@ -81,5 +81,4 @@ protected: } // namespace webrtc -#endif //ACM_G729_H - +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G729_H_ diff --git a/src/modules/audio_coding/main/source/acm_g7291.cc b/src/modules/audio_coding/main/source/acm_g7291.cc index 682ba08d5..faa506a84 100644 --- a/src/modules/audio_coding/main/source/acm_g7291.cc +++ b/src/modules/audio_coding/main/source/acm_g7291.cc @@ -55,20 +55,20 @@ ACMG729_1::~ACMG729_1() } -WebRtc_Word16 +WebRtc_Word16 ACMG729_1::InternalEncode( - WebRtc_UWord8* /* bitStream */, + WebRtc_UWord8* /* bitStream */, WebRtc_Word16* /* bitStreamLenByte */) { return -1; } -WebRtc_Word16 +WebRtc_Word16 ACMG729_1::DecodeSafe( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, - WebRtc_Word16* /* audio */, + WebRtc_UWord8* /* bitStream */, + WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16* /* audio */, WebRtc_Word16* /* audioSamples */, WebRtc_Word8* /* speechType */) { @@ -76,7 +76,7 @@ ACMG729_1::DecodeSafe( } -WebRtc_Word16 +WebRtc_Word16 ACMG729_1::InternalInitEncoder( WebRtcACMCodecParams* /* codecParams */) { @@ -84,7 +84,7 @@ ACMG729_1::InternalInitEncoder( } -WebRtc_Word16 +WebRtc_Word16 ACMG729_1::InternalInitDecoder( WebRtcACMCodecParams* /* codecParams */) { @@ -92,51 +92,51 @@ ACMG729_1::InternalInitDecoder( } -WebRtc_Word32 +WebRtc_Word32 ACMG729_1::CodecDef( - WebRtcNetEQ_CodecDef& /* codecDef */, + WebRtcNetEQ_CodecDef& /* codecDef */, const CodecInst& /* codecInst */) { return -1; } -ACMGenericCodec* +ACMGenericCodec* ACMG729_1::CreateInstance(void) { return NULL; } -WebRtc_Word16 +WebRtc_Word16 ACMG729_1::InternalCreateEncoder() { return -1; } -void +void ACMG729_1::DestructEncoderSafe() { return; } -WebRtc_Word16 +WebRtc_Word16 ACMG729_1::InternalCreateDecoder() { return -1; } -void +void ACMG729_1::DestructDecoderSafe() { return; } -void +void ACMG729_1::InternalDestructEncoderInst( void* /* ptrInst */) { @@ -144,7 +144,7 @@ ACMG729_1::InternalDestructEncoderInst( } -WebRtc_Word16 +WebRtc_Word16 ACMG729_1::UnregisterFromNetEqSafe( ACMNetEQ* /* netEq */, WebRtc_Word16 /* payloadType */) @@ -152,11 +152,11 @@ ACMG729_1::UnregisterFromNetEqSafe( return -1; } -WebRtc_Word16 +WebRtc_Word16 ACMG729_1::SetBitRateSafe( const WebRtc_Word32 /*rate*/ ) { - return -1; + return -1; } #else //===================== Actual Implementation ======================= @@ -173,10 +173,10 @@ _decoderInstPtr(NULL) // which is DTX. _hasInternalDTX = false; - // Default rate + // Default rate _myRate = 32000; - _flag8kHz = 0; + _flag8kHz = 0; _flagG729mode = 0; return; } @@ -197,9 +197,9 @@ ACMG729_1::~ACMG729_1() } -WebRtc_Word16 +WebRtc_Word16 ACMG729_1::InternalEncode( - WebRtc_UWord8* bitStream, + WebRtc_UWord8* bitStream, WebRtc_Word16* bitStreamLenByte) { @@ -207,10 +207,10 @@ ACMG729_1::InternalEncode( WebRtc_Word16 noEncodedSamples = 0; *bitStreamLenByte = 0; - WebRtc_Word16 byteLengthFrame = 0; + WebRtc_Word16 byteLengthFrame = 0; // Derive number of 20ms frames per encoded packet. - // [1,2,3] <=> [20,40,60]ms <=> [320,640,960] samples + // [1,2,3] <=> [20,40,60]ms <=> [320,640,960] samples WebRtc_Word16 n20msFrames = (_frameLenSmpl / 320); // Byte length for the frame. +1 is for rate information. byteLengthFrame = _myRate/(8*50) * n20msFrames + (1 - _flagG729mode); @@ -219,30 +219,30 @@ ACMG729_1::InternalEncode( do { *bitStreamLenByte = WebRtcG7291_Encode(_encoderInstPtr, &_inAudio[_inAudioIxRead], - (WebRtc_Word16*)bitStream, _myRate, n20msFrames); + (WebRtc_Word16*)bitStream, _myRate, n20msFrames); - // increment the read index this tell the caller that how far - // we have gone forward in reading the audio buffer - _inAudioIxRead += 160; + // increment the read index this tell the caller that how far + // we have gone forward in reading the audio buffer + _inAudioIxRead += 160; - // sanity check + // sanity check if(*bitStreamLenByte < 0) { - // error has happened - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalEncode: Encode error for G729_1"); + // error has happened + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalEncode: Encode error for G729_1"); *bitStreamLenByte = 0; return -1; - } + } - noEncodedSamples += 160; + noEncodedSamples += 160; } while(*bitStreamLenByte == 0); // This criteria will change if we have Annex C. if(*bitStreamLenByte != byteLengthFrame) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "InternalEncode: Encode error for G729_1"); *bitStreamLenByte = 0; return -1; @@ -259,11 +259,11 @@ ACMG729_1::InternalEncode( } -WebRtc_Word16 +WebRtc_Word16 ACMG729_1::DecodeSafe( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, - WebRtc_Word16* /* audio */, + WebRtc_UWord8* /* bitStream */, + WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16* /* audio */, WebRtc_Word16* /* audioSamples */, WebRtc_Word8* /* speechType */) { @@ -271,43 +271,43 @@ ACMG729_1::DecodeSafe( } -WebRtc_Word16 +WebRtc_Word16 ACMG729_1::InternalInitEncoder( WebRtcACMCodecParams* codecParams) -{ - //set the bit rate and initialize - _myRate = codecParams->codecInstant.rate; +{ + //set the bit rate and initialize + _myRate = codecParams->codecInstant.rate; return SetBitRateSafe( (WebRtc_UWord32)_myRate); } -WebRtc_Word16 +WebRtc_Word16 ACMG729_1::InternalInitDecoder( WebRtcACMCodecParams* /* codecParams */) { if (WebRtcG7291_DecoderInit(_decoderInstPtr) < 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalInitDecoder: init decoder failed for G729_1"); - return -1; - } - return 0; + { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalInitDecoder: init decoder failed for G729_1"); + return -1; + } + return 0; } -WebRtc_Word32 +WebRtc_Word32 ACMG729_1::CodecDef( WebRtcNetEQ_CodecDef& codecDef, const CodecInst& codecInst) { if (!_decoderInitialized) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "CodeDef: Decoder uninitialized for G729_1"); - return -1; + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "CodeDef: Decoder uninitialized for G729_1"); + return -1; } - // Fill up the structure by calling + // Fill up the structure by calling // "SET_CODEC_PAR" & "SET_G729_FUNCTION." // Then call NetEQ to add the codec to it's // database. @@ -318,27 +318,27 @@ ACMG729_1::CodecDef( } -ACMGenericCodec* +ACMGenericCodec* ACMG729_1::CreateInstance(void) { return NULL; } -WebRtc_Word16 +WebRtc_Word16 ACMG729_1::InternalCreateEncoder() { if (WebRtcG7291_Create(&_encoderInstPtr) < 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalCreateEncoder: create encoder failed for G729_1"); - return -1; - } - return 0; + { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalCreateEncoder: create encoder failed for G729_1"); + return -1; + } + return 0; } -void +void ACMG729_1::DestructEncoderSafe() { _encoderExist = false; @@ -351,20 +351,20 @@ ACMG729_1::DestructEncoderSafe() } -WebRtc_Word16 +WebRtc_Word16 ACMG729_1::InternalCreateDecoder() -{ +{ if (WebRtcG7291_Create(&_decoderInstPtr) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalCreateDecoder: create decoder failed for G729_1"); - return -1; + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalCreateDecoder: create decoder failed for G729_1"); + return -1; } return 0; } -void +void ACMG729_1::DestructDecoderSafe() { _decoderExist = false; @@ -377,10 +377,10 @@ ACMG729_1::DestructDecoderSafe() } -void +void ACMG729_1::InternalDestructEncoderInst( void* ptrInst) -{ +{ if(ptrInst != NULL) { //WebRtcG7291_Free((G729_1_inst_t*)ptrInst); @@ -389,25 +389,25 @@ ACMG729_1::InternalDestructEncoderInst( } -WebRtc_Word16 +WebRtc_Word16 ACMG729_1::UnregisterFromNetEqSafe( ACMNetEQ* netEq, WebRtc_Word16 payloadType) { if(payloadType != _decoderParams.codecInstant.pltype) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "Cannot unregister codec: given payload-type does not match \ -the stored payload type", - _decoderParams.codecInstant.plname, - payloadType, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "Cannot unregister codec: given payload-type does not match \ +the stored payload type", + _decoderParams.codecInstant.plname, + payloadType, _decoderParams.codecInstant.pltype); return -1; } return netEq->RemoveCodec(kDecoderG729_1); } -WebRtc_Word16 +WebRtc_Word16 ACMG729_1::SetBitRateSafe( const WebRtc_Word32 rate) { @@ -422,77 +422,76 @@ ACMG729_1::SetBitRateSafe( _myRate = 8000; break; } - case 12000: + case 12000: { _myRate = 12000; break; } - case 14000: + case 14000: { _myRate = 14000; break; } - case 16000: + case 16000: { _myRate = 16000; break; } - case 18000: + case 18000: { _myRate = 18000; break; } - case 20000: + case 20000: { _myRate = 20000; break; } - case 22000: + case 22000: { _myRate = 22000; break; } - case 24000: + case 24000: { _myRate = 24000; break; - } - case 26000: + } + case 26000: { _myRate = 26000; break; } - case 28000: + case 28000: { _myRate = 28000; break; } - case 30000: + case 30000: { _myRate = 30000; break; } - case 32000: + case 32000: { _myRate = 32000; break; } default: { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "SetBitRateSafe: Invalid rate G729_1"); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "SetBitRateSafe: Invalid rate G729_1"); return -1; - break; } } - + // Re-init with new rate if (WebRtcG7291_EncoderInit(_encoderInstPtr, _myRate, _flag8kHz, _flagG729mode) >= 0) { _encoderParams.codecInstant.rate = _myRate; return 0; - } - else + } + else { return -1; } diff --git a/src/modules/audio_coding/main/source/acm_g7291.h b/src/modules/audio_coding/main/source/acm_g7291.h index a0c41423f..cb27dc978 100644 --- a/src/modules/audio_coding/main/source/acm_g7291.h +++ b/src/modules/audio_coding/main/source/acm_g7291.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_G729_1_H -#define ACM_G729_1_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G729_1_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G729_1_H_ #include "acm_generic_codec.h" @@ -28,7 +28,7 @@ public: ACMGenericCodec* CreateInstance(void); WebRtc_Word16 InternalEncode( - WebRtc_UWord8* bitstream, + WebRtc_UWord8* bitstream, WebRtc_Word16* bitStreamLenByte); WebRtc_Word16 InternalInitEncoder( @@ -39,24 +39,24 @@ public: protected: WebRtc_Word16 DecodeSafe( - WebRtc_UWord8* bitStream, - WebRtc_Word16 bitStreamLenByte, - WebRtc_Word16* audio, - WebRtc_Word16* audioSamples, + WebRtc_UWord8* bitStream, + WebRtc_Word16 bitStreamLenByte, + WebRtc_Word16* audio, + WebRtc_Word16* audioSamples, WebRtc_Word8* speechType); WebRtc_Word32 CodecDef( - WebRtcNetEQ_CodecDef& codecDef, + WebRtcNetEQ_CodecDef& codecDef, const CodecInst& codecInst); void DestructEncoderSafe(); - + void DestructDecoderSafe(); WebRtc_Word16 InternalCreateEncoder(); - + WebRtc_Word16 InternalCreateDecoder(); - + void InternalDestructEncoderInst( void* ptrInst); @@ -65,22 +65,21 @@ protected: //WebRtc_Word16 DisableDTX(); WebRtc_Word16 UnregisterFromNetEqSafe( - ACMNetEQ* netEq, + ACMNetEQ* netEq, WebRtc_Word16 payloadType); - WebRtc_Word16 SetBitRateSafe( - const WebRtc_Word32 rate); + WebRtc_Word16 SetBitRateSafe( + const WebRtc_Word32 rate); G729_1_inst_t_* _encoderInstPtr; G729_1_inst_t_* _decoderInstPtr; WebRtc_UWord16 _myRate; - WebRtc_Word16 _flag8kHz; + WebRtc_Word16 _flag8kHz; WebRtc_Word16 _flagG729mode; }; } // namespace webrtc -#endif // ACM_G729_1_H - +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G729_1_H_ diff --git a/src/modules/audio_coding/main/source/acm_generic_codec.cc b/src/modules/audio_coding/main/source/acm_generic_codec.cc index 7920421b0..c9864ff63 100644 --- a/src/modules/audio_coding/main/source/acm_generic_codec.cc +++ b/src/modules/audio_coding/main/source/acm_generic_codec.cc @@ -34,43 +34,42 @@ enum // We set some of the variables to invalid values as a check point // if a proper initialization has happened. Another approach is // to initialize to a default codec that we are sure is always included. -ACMGenericCodec::ACMGenericCodec(): -_inAudioIxWrite(0), -_inAudioIxRead(0), -_inTimestampIxWrite(0), -_inAudio(NULL), -_inTimestamp(NULL), -_frameLenSmpl(-1), // invalid value -_noChannels(1), -_codecID(-1), // invalid value -_noMissedSamples(0), -_encoderExist(false), -_decoderExist(false), -_encoderInitialized(false), -_decoderInitialized(false), -_registeredInNetEq(false), -_hasInternalDTX(false), -_ptrVADInst(NULL), -_vadEnabled(false), -_vadMode(VADNormal), -_dtxEnabled(false), -_ptrDTXInst(NULL), -_numLPCParams(kNewCNGNumPLCParams), -_sentCNPrevious(false), -_isMaster(true), -_netEqDecodeLock(NULL), -_codecWrapperLock(*RWLockWrapper::CreateRWLock()), -_lastEncodedTimestamp(0), -_lastTimestamp(0), -_isAudioBuffFresh(true), -_uniqueID(0) -{ - _lastTimestamp = 0xD87F3F9F; - //NullifyCodecInstance(); +ACMGenericCodec::ACMGenericCodec() + : _inAudioIxWrite(0), + _inAudioIxRead(0), + _inTimestampIxWrite(0), + _inAudio(NULL), + _inTimestamp(NULL), + _frameLenSmpl(-1), // invalid value + _noChannels(1), + _codecID(-1), // invalid value + _noMissedSamples(0), + _encoderExist(false), + _decoderExist(false), + _encoderInitialized(false), + _decoderInitialized(false), + _registeredInNetEq(false), + _hasInternalDTX(false), + _ptrVADInst(NULL), + _vadEnabled(false), + _vadMode(VADNormal), + _dtxEnabled(false), + _ptrDTXInst(NULL), + _numLPCParams(kNewCNGNumPLCParams), + _sentCNPrevious(false), + _isMaster(true), + _netEqDecodeLock(NULL), + _codecWrapperLock(*RWLockWrapper::CreateRWLock()), + _lastEncodedTimestamp(0), + _lastTimestamp(0), + _isAudioBuffFresh(true), + _uniqueID(0) { + _lastTimestamp = 0xD87F3F9F; + //NullifyCodecInstance(); } ACMGenericCodec::~ACMGenericCodec() { - // Check all the members which are pointers and + // Check all the members which are pointers and // if they are not NULL delete/free them. if(_ptrVADInst != NULL) @@ -78,13 +77,13 @@ ACMGenericCodec::~ACMGenericCodec() WebRtcVad_Free(_ptrVADInst); _ptrVADInst = NULL; } - + if (_inAudio != NULL) { delete [] _inAudio; _inAudio = NULL; } - + if (_inTimestamp != NULL) { delete [] _inTimestamp; @@ -116,10 +115,10 @@ ACMGenericCodec::Add10MsDataSafe( const WebRtc_UWord16 lengthSmpl, const WebRtc_UWord8 audioChannel) { - // The codec expects to get data in correct sampling rate. + // The codec expects to get data in correct sampling rate. // get the sampling frequency of the codec WebRtc_UWord16 plFreqHz; - + if(EncoderSampFreq(plFreqHz) < 0) { // _codecID is not correct, perhaps the codec is not initialized yet. @@ -129,7 +128,7 @@ ACMGenericCodec::Add10MsDataSafe( // Sanity check, if the length of the input corresponds to 10 ms. if((plFreqHz / 100) != lengthSmpl) { - // This is not 10 ms of audio, given the sampling frequency of the + // This is not 10 ms of audio, given the sampling frequency of the // codec return -1; } @@ -140,13 +139,13 @@ ACMGenericCodec::Add10MsDataSafe( { _inAudioIxWrite -= lengthSmpl; _inTimestampIxWrite--; - WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, _uniqueID, "Adding 10ms with previous timestamp, \ overwriting the previous 10ms"); } else { - WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, _uniqueID, "Adding 10ms with previous timestamp, this will sound bad"); } } @@ -160,10 +159,10 @@ overwriting the previous 10ms"); AUDIO_BUFFER_SIZE_W16; // Move the data (overwite the old data) - memmove(_inAudio, _inAudio + missedSamples, + memmove(_inAudio, _inAudio + missedSamples, (AUDIO_BUFFER_SIZE_W16 - lengthSmpl*audioChannel)*sizeof(WebRtc_Word16)); // Copy the new data - memcpy(_inAudio + (AUDIO_BUFFER_SIZE_W16 - lengthSmpl*audioChannel), data, + memcpy(_inAudio + (AUDIO_BUFFER_SIZE_W16 - lengthSmpl*audioChannel), data, lengthSmpl*audioChannel * sizeof(WebRtc_Word16)); // Get the number of 10 ms blocks which are overwritten @@ -171,7 +170,7 @@ overwriting the previous 10ms"); (WebRtc_Word16)((missedSamples/audioChannel * 100) / plFreqHz); // Move the timestamps - memmove(_inTimestamp, _inTimestamp + missed10MsecBlocks, + memmove(_inTimestamp, _inTimestamp + missed10MsecBlocks, (_inTimestampIxWrite - missed10MsecBlocks) * sizeof(WebRtc_UWord32)); _inTimestampIxWrite -= missed10MsecBlocks; _inTimestamp[_inTimestampIxWrite] = timestamp; @@ -204,7 +203,7 @@ ACMGenericCodec::Encode( { WriteLockScoped lockCodec(_codecWrapperLock); ReadLockScoped lockNetEq(*_netEqDecodeLock); - return EncodeSafe(bitStream, bitStreamLenByte, + return EncodeSafe(bitStream, bitStreamLenByte, timeStamp, encodingType); } @@ -228,19 +227,19 @@ ACMGenericCodec::EncodeSafe( return 0; } - // Not all codecs accept the whole frame to be pushed into + // Not all codecs accept the whole frame to be pushed into // encoder at once. const WebRtc_Word16 myBasicCodingBlockSmpl = ACMCodecDB::BasicCodingBlock(_codecID); - if((myBasicCodingBlockSmpl < 0) || - (!_encoderInitialized) || + if((myBasicCodingBlockSmpl < 0) || + (!_encoderInitialized) || (!_encoderExist)) { // This should not happen *timeStamp = 0; *bitStreamLenByte = 0; *encodingType = kNoEncoding; - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "EncodeSafe: error, basic coding sample block is negative"); return -1; } @@ -253,10 +252,10 @@ ACMGenericCodec::EncodeSafe( // If VAD is disabled all labels are set to ONE (active) WebRtc_Word16 status = 0; WebRtc_Word16 dtxProcessedSamples = 0; - - status = ProcessFrameVADDTX(bitStream, bitStreamLenByte, + + status = ProcessFrameVADDTX(bitStream, bitStreamLenByte, &dtxProcessedSamples); - + if(status < 0) { *timeStamp = 0; @@ -268,11 +267,11 @@ ACMGenericCodec::EncodeSafe( if(dtxProcessedSamples > 0) { // Dtx have processed some samples may or may not a bit-stream - // is generated we should not do any encoding (normally there + // is generated we should not do any encoding (normally there // will be not enough data) - // Setting the following makes that the move of audio data - // and timestamps happen correctly + // Setting the following makes that the move of audio data + // and timestamps happen correctly _inAudioIxRead = dtxProcessedSamples; // This will let the owner of ACMGenericCodec to know that the // generated bit-stream is DTX to use correct payload type @@ -286,17 +285,17 @@ ACMGenericCodec::EncodeSafe( *encodingType = kPassiveDTXSWB; } else { status = -1; - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "EncodeSafe: Wrong sampling frequency for DTX."); } - + // Transport empty frame if we have an empty bitstream if ((*bitStreamLenByte == 0) && (_sentCNPrevious || ((_inAudioIxWrite - _inAudioIxRead) <= 0)) ) { // Makes sure we transmit an empty frame - *bitStreamLenByte = 1; + *bitStreamLenByte = 1; *encodingType = kNoEncoding; } _sentCNPrevious = true; @@ -310,16 +309,16 @@ ACMGenericCodec::EncodeSafe( // if any registered. if(myBasicCodingBlockSmpl == 0) { - // This codec can handle all allowed frame sizes as basic + // This codec can handle all allowed frame sizes as basic // coding block status = InternalEncode(bitStream, bitStreamLenByte); if(status < 0) { - // TODO: - // Maybe reseting the encoder to be fresh for the next + // TODO: + // Maybe reseting the encoder to be fresh for the next // frame - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "EncodeSafe: error in internalEncode"); *bitStreamLenByte = 0; *encodingType = kNoEncoding; @@ -327,9 +326,9 @@ ACMGenericCodec::EncodeSafe( } else { - // A basic-coding-block for this codec is defined so we loop + // A basic-coding-block for this codec is defined so we loop // over the audio with the steps of the basic-coding-block. - // It is not necessary that in each itteration + // It is not necessary that in each itteration WebRtc_Word16 tmpBitStreamLenByte; // Reset the variables which will be increamented in the loop @@ -337,35 +336,35 @@ ACMGenericCodec::EncodeSafe( bool done = false; while(!done) { - status = InternalEncode(&bitStream[*bitStreamLenByte], + status = InternalEncode(&bitStream[*bitStreamLenByte], &tmpBitStreamLenByte); *bitStreamLenByte += tmpBitStreamLenByte; - // Guard Against errors and too large payloads - if((status < 0) || + // Guard Against errors and too large payloads + if((status < 0) || (*bitStreamLenByte > MAX_PAYLOAD_SIZE_BYTE)) { // Error has happened if we are in the middle of a full // frame we have to exit. Before exiting, whatever bits - // are in the buffer are probably corruptred. Anyways + // are in the buffer are probably corruptred. Anyways // we ignore them. *bitStreamLenByte = 0; *encodingType = kNoEncoding; - // We might have come here because of the second + // We might have come here because of the second // condition. - status = -1; + status = -1; WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "EncodeSafe: error in InternalEncode"); // break from the loop break; } - + done = _inAudioIxRead >= _frameLenSmpl; } } if(status >= 0) { - *encodingType = (_vadLabel[0] == 1)? + *encodingType = (_vadLabel[0] == 1)? kActiveNormalEncoded:kPassiveNormalEncoded; // Transport empty frame if we have an empty bitsteram if ((*bitStreamLenByte == 0) && ((_inAudioIxWrite - _inAudioIxRead) <= 0)) @@ -377,17 +376,17 @@ ACMGenericCodec::EncodeSafe( } } } - + // Move the timestampe buffer according to the number of 10 ms blocks // which are read. WebRtc_UWord16 sampFreqHz; EncoderSampFreq(sampFreqHz); - + WebRtc_Word16 num10MsecBlocks = (WebRtc_Word16)((_inAudioIxRead/_noChannels * 100) / sampFreqHz); if(_inTimestampIxWrite > num10MsecBlocks) { - memmove(_inTimestamp, _inTimestamp + num10MsecBlocks, + memmove(_inTimestamp, _inTimestamp + num10MsecBlocks, (_inTimestampIxWrite - num10MsecBlocks) * sizeof(WebRtc_Word32)); } _inTimestampIxWrite -= num10MsecBlocks; @@ -396,7 +395,7 @@ ACMGenericCodec::EncodeSafe( // of the buffer and accordingly adjust the read and write indices. if(_inAudioIxRead < _inAudioIxWrite) { - memmove(_inAudio, &_inAudio[_inAudioIxRead], + memmove(_inAudio, &_inAudio[_inAudioIxRead], (_inAudioIxWrite - _inAudioIxRead)*sizeof(WebRtc_Word16)); } @@ -416,18 +415,18 @@ ACMGenericCodec::Decode( WebRtc_Word8* speechType) { WriteLockScoped wl(_codecWrapperLock); - return DecodeSafe(bitStream, bitStreamLenByte, audio, + return DecodeSafe(bitStream, bitStreamLenByte, audio, audioSamples, speechType); } -bool +bool ACMGenericCodec::EncoderInitialized() { ReadLockScoped rl(_codecWrapperLock); return _encoderInitialized; } -bool +bool ACMGenericCodec::DecoderInitialized() { ReadLockScoped rl(_codecWrapperLock); @@ -446,7 +445,7 @@ ACMGenericCodec::RegisterInNetEq( if(CodecDef(codecDef, codecInst) < 0) { // Failed to register - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "RegisterInNetEq: error, failed to register"); _registeredInNetEq = false; return -1; @@ -455,12 +454,12 @@ ACMGenericCodec::RegisterInNetEq( { if(netEq->AddCodec(&codecDef, _isMaster) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "RegisterInNetEq: error, failed to add codec"); _registeredInNetEq = false; return -1; } - // Registered + // Registered _registeredInNetEq = true; return 0; } @@ -494,13 +493,13 @@ ACMGenericCodec::EncoderParamsSafe( encParams->codecInstant.pltype = -1; encParams->codecInstant.pacsize = 0; encParams->codecInstant.rate = 0; - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "EncoderParamsSafe: error, encoder not initialized"); return -1; } } -bool +bool ACMGenericCodec::DecoderParams( WebRtcACMCodecParams* decParams, const WebRtc_UWord8 payloadType) @@ -514,7 +513,7 @@ ACMGenericCodec::DecoderParamsSafe( WebRtcACMCodecParams* decParams, const WebRtc_UWord8 payloadType) { - // Decoder parameters are valid only if decoder is initialized + // Decoder parameters are valid only if decoder is initialized if(_decoderInitialized) { if(payloadType == _decoderParams.codecInstant.pltype) @@ -564,24 +563,24 @@ ACMGenericCodec::ResetEncoderSafe() // Reset the encoder if(InternalResetEncoder() < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "ResetEncoderSafe: error in reset encoder"); return -1; } - + // Disable DTX & VAD this deletes the states // we like to have fresh start DisableDTX(); DisableVAD(); - // Set DTX/VAD + // Set DTX/VAD return SetVADSafe(enableDTX, enableVAD, mode); } WebRtc_Word16 ACMGenericCodec::InternalResetEncoder() { - // For most of the codecs it is sufficient to + // For most of the codecs it is sufficient to // call their internal initialization. // There are some exceptions. // ---- @@ -613,7 +612,7 @@ ACMGenericCodec::InitEncoderSafe( if(codecNumber < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "InitEncoderSafe: error, codec number negative"); return -1; } @@ -621,14 +620,14 @@ ACMGenericCodec::InitEncoderSafe( if((_codecID >= 0) && (_codecID != codecNumber) && (_codecID != mirrorID)) { // The current codec is not the same as the one given by codecParams - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "InitEncoderSafe: current codec is not the same as the one given by codecParams"); return -1; } if(!CanChangeEncodingParam(codecParams->codecInstant)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "InitEncoderSafe: cannot change encoding parameters"); return -1; } @@ -645,7 +644,7 @@ ACMGenericCodec::InitEncoderSafe( status = CreateEncoder(); if(status < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "InitEncoderSafe: cannot create encoder"); return -1; } @@ -657,8 +656,8 @@ ACMGenericCodec::InitEncoderSafe( _frameLenSmpl = (codecParams->codecInstant).pacsize; status = InternalInitEncoder(codecParams); if(status < 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "InitEncoderSafe: error in init encoder"); _encoderInitialized = false; return -1; @@ -671,7 +670,7 @@ ACMGenericCodec::InitEncoderSafe( { _inAudio = new WebRtc_Word16[AUDIO_BUFFER_SIZE_W16]; if(_inAudio == NULL) - { + { return -1; } memset(_inAudio, 0, AUDIO_BUFFER_SIZE_W16 * sizeof(WebRtc_Word16)); @@ -688,17 +687,17 @@ ACMGenericCodec::InitEncoderSafe( } _isAudioBuffFresh = true; } - status = SetVADSafe(codecParams->enableDTX, codecParams->enableVAD, + status = SetVADSafe(codecParams->enableDTX, codecParams->enableVAD, codecParams->vadMode); - + _noChannels = codecParams->codecInstant.channels; return status; } -bool +bool ACMGenericCodec::CanChangeEncodingParam( - CodecInst& /*codecInst*/) + CodecInst& /*codecInst*/) { return true; } @@ -725,17 +724,17 @@ ACMGenericCodec::InitDecoderSafe( if(codecNumber < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "InitDecoderSafe: error, invalid codec number"); return -1; } // Check if the parameters are for this codec if((_codecID >= 0) && (_codecID != codecNumber) && (_codecID != mirrorID)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "InitDecoderSafe: current codec is not the same as the one given " "by codecParams"); - // The current codec is not the same as the one given by codecParams + // The current codec is not the same as the one given by codecParams return -1; } @@ -753,7 +752,7 @@ ACMGenericCodec::InitDecoderSafe( status = CreateDecoder(); if(status < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "InitDecoderSafe: cannot create decoder"); return -1; } @@ -765,8 +764,8 @@ ACMGenericCodec::InitDecoderSafe( status = InternalInitDecoder(codecParams); if(status < 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "InitDecoderSafe: cannot init decoder"); _decoderInitialized = false; return -1; @@ -796,22 +795,22 @@ ACMGenericCodec::ResetDecoderSafe(WebRtc_Word16 payloadType) { return 0; } - // Initialization of the decoder should work for all - // the codec. If there is a codec that has to keep + // Initialization of the decoder should work for all + // the codec. If there is a codec that has to keep // some states then we need to define a virtual and // overwrite in that codec DecoderParamsSafe(&decoderParams, (WebRtc_UWord8) payloadType); return InternalInitDecoder(&decoderParams); } -void +void ACMGenericCodec::ResetNoMissedSamples() { WriteLockScoped cs(_codecWrapperLock); _noMissedSamples = 0; } -void +void ACMGenericCodec::IncreaseNoMissedSamples( const WebRtc_Word16 noSamples) { @@ -825,11 +824,11 @@ ACMGenericCodec::NoMissedSamples() const ReadLockScoped cs(_codecWrapperLock); return _noMissedSamples; } -void +void ACMGenericCodec::DestructEncoder() { WriteLockScoped wl(_codecWrapperLock); - + // Disable VAD and delete the instance if(_ptrVADInst != NULL) { @@ -851,7 +850,7 @@ ACMGenericCodec::DestructEncoder() DestructEncoderSafe(); } -void +void ACMGenericCodec::DestructDecoder() { WriteLockScoped wl(_codecWrapperLock); @@ -877,13 +876,13 @@ ACMGenericCodec::SetBitRateSafe( CodecInst codecParams; if(ACMCodecDB::Codec(_codecID, &codecParams) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "SetBitRateSafe: error in ACMCodecDB::Codec"); return -1; } if(codecParams.rate != bitRateBPS) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "SetBitRateSafe: rate value is not acceptable"); return -1; } @@ -946,14 +945,14 @@ ACMGenericCodec::CreateEncoder() WebRtc_Word16 status = 0; if(!_encoderExist) { - status = InternalCreateEncoder(); + status = InternalCreateEncoder(); // We just created the codec and obviously it is not initialized _encoderInitialized = false; } if(status < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "CreateEncoder: error in internal create encoder"); _encoderExist = false; } @@ -970,14 +969,14 @@ ACMGenericCodec::CreateDecoder() WebRtc_Word16 status = 0; if(!_decoderExist) { - status = InternalCreateDecoder(); + status = InternalCreateDecoder(); // Decoder just created and obviously it is not initialized _decoderInitialized = false; } if(status < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "CreateDecoder: error in internal create decoder"); _decoderExist = false; } @@ -1005,11 +1004,11 @@ ACMGenericCodec::AudioBuffer( WebRtcACMAudioBuff& audioBuff) { ReadLockScoped cs(_codecWrapperLock); - memcpy(audioBuff.inAudio, _inAudio, + memcpy(audioBuff.inAudio, _inAudio, AUDIO_BUFFER_SIZE_W16 * sizeof(WebRtc_Word16)); audioBuff.inAudioIxRead = _inAudioIxRead; audioBuff.inAudioIxWrite = _inAudioIxWrite; - memcpy(audioBuff.inTimestamp, _inTimestamp, + memcpy(audioBuff.inTimestamp, _inTimestamp, TIMESTAMP_BUFFER_SIZE_W32*sizeof(WebRtc_UWord32)); audioBuff.inTimestampIxWrite = _inTimestampIxWrite; audioBuff.lastTimestamp = _lastTimestamp; @@ -1022,11 +1021,11 @@ ACMGenericCodec::SetAudioBuffer( WebRtcACMAudioBuff& audioBuff) { WriteLockScoped cs(_codecWrapperLock); - memcpy(_inAudio, audioBuff.inAudio, + memcpy(_inAudio, audioBuff.inAudio, AUDIO_BUFFER_SIZE_W16 * sizeof(WebRtc_Word16)); _inAudioIxRead = audioBuff.inAudioIxRead; _inAudioIxWrite = audioBuff.inAudioIxWrite; - memcpy(_inTimestamp, audioBuff.inTimestamp, + memcpy(_inTimestamp, audioBuff.inTimestamp, TIMESTAMP_BUFFER_SIZE_W32*sizeof(WebRtc_UWord32)); _inTimestampIxWrite = audioBuff.inTimestampIxWrite; _lastTimestamp = audioBuff.lastTimestamp; @@ -1075,7 +1074,7 @@ ACMGenericCodec::SetVADSafe( { if (ACMGenericCodec::EnableDTX() < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "SetVADSafe: error in enable DTX"); return -1; } @@ -1084,7 +1083,7 @@ ACMGenericCodec::SetVADSafe( { if(EnableDTX() < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "SetVADSafe: error in enable DTX"); return -1; } @@ -1096,7 +1095,7 @@ ACMGenericCodec::SetVADSafe( // however, we let the user to turn it on if they need call-backs // on silence. Store VAD mode for future even if VAD is off. _vadMode = mode; - return (enableVAD)? EnableVAD(mode):DisableVAD(); + return (enableVAD)? EnableVAD(mode):DisableVAD(); } else { @@ -1109,11 +1108,11 @@ ACMGenericCodec::SetVADSafe( { DisableDTX(); } - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "SetVADSafe: error in enable VAD"); return -1; } - + // Return '1', to let the caller know VAD was turned on, even if the // function was called with VAD='false' if (enableVAD == false) { @@ -1134,7 +1133,7 @@ ACMGenericCodec::SetVADSafe( { DisableDTX(); } - return (enableVAD)? EnableVAD(mode):DisableVAD(); + return (enableVAD)? EnableVAD(mode):DisableVAD(); } } @@ -1195,7 +1194,7 @@ ACMGenericCodec::EnableVAD( { if((mode < VADNormal) || (mode > VADVeryAggr)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "EnableVAD: error in VAD mode range"); return -1; } @@ -1205,7 +1204,7 @@ ACMGenericCodec::EnableVAD( if(WebRtcVad_Create(&_ptrVADInst) < 0) { _ptrVADInst = NULL; - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "EnableVAD: error in create VAD"); return -1; } @@ -1213,7 +1212,7 @@ ACMGenericCodec::EnableVAD( { WebRtcVad_Free(_ptrVADInst); _ptrVADInst = NULL; - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "EnableVAD: error in init VAD"); return -1; } @@ -1233,7 +1232,7 @@ ACMGenericCodec::EnableVAD( WebRtcVad_Free(_ptrVADInst); _ptrVADInst = NULL; } - WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, _uniqueID, "EnableVAD: failed to set the VAD mode"); return -1; } @@ -1314,14 +1313,14 @@ ACMGenericCodec::ProcessFrameVADDTX( // Calculate number of VAD-blocks to process, and number of samples in each block. int noSamplesToProcess[2]; - if (frameLenMsec == 40) + if (frameLenMsec == 40) { // 20 ms in each VAD block noSamplesToProcess[0] = noSamplesToProcess[1] = 2*samplesIn10Msec; - } + } else { - // For 10-30 ms framesizes, second VAD block will be size zero ms, + // For 10-30 ms framesizes, second VAD block will be size zero ms, // for 50 and 60 ms first VAD block will be 30 ms. noSamplesToProcess[0] = (frameLenMsec > 30)? 3*samplesIn10Msec : _frameLenSmpl; noSamplesToProcess[1] = _frameLenSmpl-noSamplesToProcess[0]; @@ -1340,20 +1339,20 @@ ACMGenericCodec::ProcessFrameVADDTX( // Mono, copy data from _inAudio to continue work on memcpy(audio, _inAudio, sizeof(WebRtc_Word16)*noSamplesToProcess[i]); } - + // Call VAD status = WebRtcVad_Process(_ptrVADInst, (WebRtc_Word16)freqHz, audio, noSamplesToProcess[i]); _vadLabel[i] = status; - + if(status < 0) { // This will force that the data be removed from the buffer *samplesProcessed += noSamplesToProcess[i]; return -1; } - + // If VAD decision non-active, update DTX. NOTE! We only do this if the first part of // a frame gets the VAD decision "inactive". Otherwise DTX might say it is time to // transmit SID frame, but we will encode the whole frame, because the first part is @@ -1418,8 +1417,8 @@ ACMGenericCodec::UnregisterFromNetEq( } if(UnregisterFromNetEqSafe(netEq, payloadType) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "UnregisterFromNetEq: error, cannot unregister from NetEq"); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "UnregisterFromNetEq: error, cannot unregister from NetEq"); _registeredInNetEq = true; return -1; } @@ -1430,7 +1429,7 @@ ACMGenericCodec::UnregisterFromNetEq( } } -void +void ACMGenericCodec::SetUniqueID( const WebRtc_UWord32 id) { @@ -1441,7 +1440,7 @@ bool ACMGenericCodec::IsAudioBufferFresh() const { ReadLockScoped rl(_codecWrapperLock); - return _isAudioBuffFresh; + return _isAudioBuffFresh; } // This function is replaced by codec specific functions for some codecs @@ -1452,8 +1451,8 @@ ACMGenericCodec::EncoderSampFreq(WebRtc_UWord16& sampFreqHz) f = ACMCodecDB::CodecFreq(_codecID); if(f < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "EncoderSampFreq: codec frequency is negative"); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "EncoderSampFreq: codec frequency is negative"); return -1; } else @@ -1470,7 +1469,7 @@ ACMGenericCodec::ConfigISACBandwidthEstimator( const WebRtc_UWord16 /* initRateBitPerSec */, const bool /* enforceFrameSize */) { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, _uniqueID, "The send-codec is not iSAC, failed to config iSAC bandwidth estimator."); return -1; } @@ -1479,16 +1478,16 @@ WebRtc_Word32 ACMGenericCodec::SetISACMaxRate( const WebRtc_UWord32 /* maxRateBitPerSec */) { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, _uniqueID, "The send-codec is not iSAC, failed to set iSAC max rate."); return -1; } - + WebRtc_Word32 ACMGenericCodec::SetISACMaxPayloadSize( const WebRtc_UWord16 /* maxPayloadLenBytes */) { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, _uniqueID, "The send-codec is not iSAC, failed to set iSAC max payload-size."); return -1; } @@ -1514,7 +1513,7 @@ WebRtc_Word16 ACMGenericCodec::UpdateEncoderSampFreq( WebRtc_UWord16 /* encoderSampFreqHz */) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "It is asked for a change in smapling frequency while the \ current send-codec supports only one sampling rate."); return -1; @@ -1538,7 +1537,7 @@ ACMGenericCodec::REDPayloadISAC( WebRtc_UWord8* /* payload */, WebRtc_Word16* /* payloadLenBytes */) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Error: REDPayloadISAC is an iSAC specific function"); return -1; } diff --git a/src/modules/audio_coding/main/source/acm_generic_codec.h b/src/modules/audio_coding/main/source/acm_generic_codec.h index 23e16a6a2..7f50669ea 100644 --- a/src/modules/audio_coding/main/source/acm_generic_codec.h +++ b/src/modules/audio_coding/main/source/acm_generic_codec.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_GENERIC_CODEC_H -#define ACM_GENERIC_CODEC_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_GENERIC_CODEC_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_GENERIC_CODEC_H_ #include "acm_common_defs.h" #include "audio_coding_module_typedefs.h" @@ -322,7 +322,7 @@ public: // 0 if the rate is adjusted successfully // WebRtc_Word16 SetBitRate(const WebRtc_Word32 bitRateBPS); - + /////////////////////////////////////////////////////////////////////////// // DestructEncoderInst() @@ -411,7 +411,7 @@ public: const bool enableDTX = true, const bool enableVAD = false, const ACMVADMode mode = VADNormal); - + /////////////////////////////////////////////////////////////////////////// // WebRtc_Word32 ReplaceInternalDTX() @@ -451,9 +451,9 @@ public: // -netEqDecodeLock : pointer to the lock associated with NetEQ of ACM. // void SetNetEqDecodeLock( - RWLockWrapper* netEqDecodeLock) - { - _netEqDecodeLock = netEqDecodeLock; + RWLockWrapper* netEqDecodeLock) + { + _netEqDecodeLock = netEqDecodeLock; } @@ -465,7 +465,7 @@ public: // true if the codec has an internal DTX, e.g. G729, // false otherwise. // - bool HasInternalDTX() const + bool HasInternalDTX() const { return _hasInternalDTX; } @@ -481,7 +481,7 @@ public: // >0 estimated bandwidth in bits/sec. // WebRtc_Word32 GetEstimatedBandwidth(); - + /////////////////////////////////////////////////////////////////////////// // WebRtc_Word32 SetEstimatedBandwidth() @@ -514,7 +514,7 @@ public: WebRtc_UWord8* redPayload, WebRtc_Word16* payloadBytes); - + /////////////////////////////////////////////////////////////////////////// // WebRtc_Word16 ResetEncoder() // By calling this function you would re-initialize the encoder with the @@ -540,7 +540,7 @@ public: WebRtc_Word16 ResetDecoder( WebRtc_Word16 payloadType); - + /////////////////////////////////////////////////////////////////////////// // void DestructEncoder() // This function is called to delete the encoder instance, if possible, to @@ -581,7 +581,7 @@ public: // WebRtc_UWord32 LastEncodedTimestamp() const; - + /////////////////////////////////////////////////////////////////////////// // WebRtc_Word32 UnregisterFromNetEq() // To remove the codec from NetEQ. If the codec (or the decoder instance) @@ -654,7 +654,7 @@ public: return 0; } - + /////////////////////////////////////////////////////////////////////////// // UpdateEncoderSampFreq() // Call this function to update the encoder sampling frequency. This @@ -757,7 +757,7 @@ public: // virtual WebRtc_Word32 SetISACMaxRate( const WebRtc_UWord32 maxRateBitPerSec); - + /////////////////////////////////////////////////////////////////////////// // SaveDecoderParamS() @@ -779,7 +779,7 @@ public: void SetIsMaster(bool isMaster); - + /////////////////////////////////////////////////////////////////////////// // REDPayloadISAC() @@ -810,7 +810,7 @@ public: const WebRtc_Word16 isacBwEstimate, WebRtc_UWord8* payload, WebRtc_Word16* payloadLenBytes); - + protected: /////////////////////////////////////////////////////////////////////////// // All the functions with FunctionNameSafe(...) contain the actual @@ -840,7 +840,7 @@ protected: WebRtc_Word16* audio, WebRtc_Word16* audioSamples, WebRtc_Word8* speechType) = 0; - + /////////////////////////////////////////////////////////////////////////// // See Add10MsSafe() for the description of function, input(s)/output(s) // and return value. @@ -850,22 +850,22 @@ protected: const WebRtc_Word16* data, const WebRtc_UWord16 length, const WebRtc_UWord8 audioChannel); - + /////////////////////////////////////////////////////////////////////////// // See RegisterInNetEq() for the description of function, // input(s)/output(s) and return value. // virtual WebRtc_Word32 CodecDef( - WebRtcNetEQ_CodecDef& codecDef, + WebRtcNetEQ_CodecDef& codecDef, const CodecInst& codecInst) = 0; - + /////////////////////////////////////////////////////////////////////////// // See EncoderParam() for the description of function, input(s)/output(s) // and return value. // WebRtc_Word16 EncoderParamsSafe( WebRtcACMCodecParams *encParams); - + /////////////////////////////////////////////////////////////////////////// // See DecoderParam for the description of function, input(s)/output(s) // and return value. @@ -883,13 +883,13 @@ protected: virtual bool DecoderParamsSafe( WebRtcACMCodecParams *decParams, const WebRtc_UWord8 payloadType); - + /////////////////////////////////////////////////////////////////////////// // See ResetEncoder() for the description of function, input(s)/output(s) // and return value. // WebRtc_Word16 ResetEncoderSafe(); - + /////////////////////////////////////////////////////////////////////////// // See InitEncoder() for the description of function, input(s)/output(s) // and return value. @@ -905,14 +905,14 @@ protected: WebRtc_Word16 InitDecoderSafe( WebRtcACMCodecParams *codecParams, bool forceInitialization); - + /////////////////////////////////////////////////////////////////////////// // See ResetDecoder() for the description of function, input(s)/output(s) // and return value. // WebRtc_Word16 ResetDecoderSafe( WebRtc_Word16 payloadType); - + /////////////////////////////////////////////////////////////////////////// // See DestructEncoder() for the description of function, // input(s)/output(s) and return value. @@ -924,7 +924,7 @@ protected: // input(s)/output(s) and return value. // virtual void DestructDecoderSafe() = 0; - + /////////////////////////////////////////////////////////////////////////// // See SetBitRate() for the description of function, input(s)/output(s) // and return value. @@ -933,19 +933,19 @@ protected: // virtual WebRtc_Word16 SetBitRateSafe( const WebRtc_Word32 bitRateBPS); - + /////////////////////////////////////////////////////////////////////////// // See GetEstimatedBandwidth() for the description of function, input(s)/output(s) // and return value. // virtual WebRtc_Word32 GetEstimatedBandwidthSafe(); - + /////////////////////////////////////////////////////////////////////////// // See SetEstimatedBandwidth() for the description of function, input(s)/output(s) // and return value. // virtual WebRtc_Word32 SetEstimatedBandwidthSafe(WebRtc_Word32 estimatedBandwidth); - + /////////////////////////////////////////////////////////////////////////// // See GetRedPayload() for the description of function, input(s)/output(s) // and return value. @@ -1145,7 +1145,7 @@ protected: // virtual WebRtc_Word16 InternalCreateEncoder() = 0; - + /////////////////////////////////////////////////////////////////////////// // WebRtc_Word16 InternalCreateDecoder() // This is a codec-specific method called in CreateDecoderSafe() it is @@ -1175,7 +1175,7 @@ protected: // 0 if succeeded. // virtual void InternalDestructEncoderInst( - void* ptrInst) = 0; + void* ptrInst) = 0; /////////////////////////////////////////////////////////////////////////// @@ -1230,7 +1230,7 @@ protected: WebRtc_Word16* bitStreamLenByte, WebRtc_Word16* samplesProcessed); - + /////////////////////////////////////////////////////////////////////////// // CanChangeEncodingParam() // Check if the codec parameters can be changed. In conferencing normally @@ -1242,7 +1242,7 @@ protected: // virtual bool CanChangeEncodingParam(CodecInst& codecInst); - + /////////////////////////////////////////////////////////////////////////// // CurrentRate() // Call to get the current encoding rate of the encoder. This function @@ -1256,24 +1256,23 @@ protected: virtual void CurrentRate( WebRtc_Word32& /* rateBitPerSec */) { - return; } virtual void SaveDecoderParamSafe( const WebRtcACMCodecParams* codecParams); - - // &_inAudio[_inAudioIxWrite] always point to where new audio can be - // written to + + // &_inAudio[_inAudioIxWrite] always point to where new audio can be + // written to WebRtc_Word16 _inAudioIxWrite; // &_inAudio[_inAudioIxRead] points to where audio has to be read from WebRtc_Word16 _inAudioIxRead; - + WebRtc_Word16 _inTimestampIxWrite; - // Where the audio is stored before encoding, + // Where the audio is stored before encoding, // To save memory the following buffer can be allocated // dynamically for 80ms depending on the sampling frequency // of the codec. @@ -1285,12 +1284,12 @@ protected: // This will point to a static database of the supported codecs WebRtc_Word16 _codecID; - + // This will account for the No of samples were not encoded // the case is rare, either samples are missed due to overwite // at input buffer or due to encoding error WebRtc_UWord32 _noMissedSamples; - + // True if the encoder instance created bool _encoderExist; bool _decoderExist; @@ -1330,4 +1329,4 @@ protected: } // namespace webrt -#endif // ACM_GENERIC_CODEC_H +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_GENERIC_CODEC_H_ diff --git a/src/modules/audio_coding/main/source/acm_gsmfr.cc b/src/modules/audio_coding/main/source/acm_gsmfr.cc index 3a4e4a616..a17716670 100644 --- a/src/modules/audio_coding/main/source/acm_gsmfr.cc +++ b/src/modules/audio_coding/main/source/acm_gsmfr.cc @@ -55,42 +55,42 @@ ACMGSMFR::~ACMGSMFR() } -WebRtc_Word16 +WebRtc_Word16 ACMGSMFR::InternalEncode( - WebRtc_UWord8* /* bitStream */, + WebRtc_UWord8* /* bitStream */, WebRtc_Word16* /* bitStreamLenByte */) { return -1; } -WebRtc_Word16 +WebRtc_Word16 ACMGSMFR::DecodeSafe( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, - WebRtc_Word16* /* audio */, - WebRtc_Word16* /* audioSamples */, + WebRtc_UWord8* /* bitStream */, + WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16* /* audio */, + WebRtc_Word16* /* audioSamples */, WebRtc_Word8* /* speechType */) { return -1; } -WebRtc_Word16 +WebRtc_Word16 ACMGSMFR::EnableDTX() { return -1; } -WebRtc_Word16 +WebRtc_Word16 ACMGSMFR::DisableDTX() { return -1; } -WebRtc_Word16 +WebRtc_Word16 ACMGSMFR::InternalInitEncoder( WebRtcACMCodecParams* /* codecParams */) { @@ -98,7 +98,7 @@ ACMGSMFR::InternalInitEncoder( } -WebRtc_Word16 +WebRtc_Word16 ACMGSMFR::InternalInitDecoder( WebRtcACMCodecParams* /* codecParams */) { @@ -106,51 +106,51 @@ ACMGSMFR::InternalInitDecoder( } -WebRtc_Word32 +WebRtc_Word32 ACMGSMFR::CodecDef( - WebRtcNetEQ_CodecDef& /* codecDef */, + WebRtcNetEQ_CodecDef& /* codecDef */, const CodecInst& /* codecInst */) { return -1; } -ACMGenericCodec* +ACMGenericCodec* ACMGSMFR::CreateInstance(void) { return NULL; } -WebRtc_Word16 +WebRtc_Word16 ACMGSMFR::InternalCreateEncoder() { return -1; } -void +void ACMGSMFR::DestructEncoderSafe() { return; } -WebRtc_Word16 +WebRtc_Word16 ACMGSMFR::InternalCreateDecoder() { return -1; } -void +void ACMGSMFR::DestructDecoderSafe() { return; } -void +void ACMGSMFR::InternalDestructEncoderInst( void* /* ptrInst */) { @@ -158,7 +158,7 @@ ACMGSMFR::InternalDestructEncoderInst( } -WebRtc_Word16 +WebRtc_Word16 ACMGSMFR::UnregisterFromNetEqSafe( ACMNetEQ* /* netEq */, WebRtc_Word16 /* payloadType */) @@ -196,33 +196,33 @@ ACMGSMFR::~ACMGSMFR() } -WebRtc_Word16 +WebRtc_Word16 ACMGSMFR::InternalEncode( - WebRtc_UWord8* bitStream, + WebRtc_UWord8* bitStream, WebRtc_Word16* bitStreamLenByte) { *bitStreamLenByte = WebRtcGSMFR_Encode(_encoderInstPtr, &_inAudio[_inAudioIxRead], _frameLenSmpl, (WebRtc_Word16*)bitStream); - // increment the read index this tell the caller that how far + // increment the read index this tell the caller that how far // we have gone forward in reading the audio buffer _inAudioIxRead += _frameLenSmpl; return *bitStreamLenByte; } -WebRtc_Word16 +WebRtc_Word16 ACMGSMFR::DecodeSafe( - WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, - WebRtc_Word16* /* audio */, - WebRtc_Word16* /* audioSamples */, + WebRtc_UWord8* /* bitStream */, + WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16* /* audio */, + WebRtc_Word16* /* audioSamples */, WebRtc_Word8* /* speechType */) { return 0; } -WebRtc_Word16 +WebRtc_Word16 ACMGSMFR::EnableDTX() { if(_dtxEnabled) @@ -233,8 +233,8 @@ ACMGSMFR::EnableDTX() { if(WebRtcGSMFR_EncoderInit(_encoderInstPtr, 1) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "EnableDTX: cannot init encoder for GSMFR"); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "EnableDTX: cannot init encoder for GSMFR"); return -1; } _dtxEnabled = true; @@ -247,7 +247,7 @@ ACMGSMFR::EnableDTX() } -WebRtc_Word16 +WebRtc_Word16 ACMGSMFR::DisableDTX() { if(!_dtxEnabled) @@ -258,8 +258,8 @@ ACMGSMFR::DisableDTX() { if(WebRtcGSMFR_EncoderInit(_encoderInstPtr, 0) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "DisableDTX: cannot init encoder for GSMFR"); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "DisableDTX: cannot init encoder for GSMFR"); return -1; } _dtxEnabled = false; @@ -273,45 +273,45 @@ ACMGSMFR::DisableDTX() } -WebRtc_Word16 +WebRtc_Word16 ACMGSMFR::InternalInitEncoder( WebRtcACMCodecParams* codecParams) { if (WebRtcGSMFR_EncoderInit(_encoderInstPtr, ((codecParams->enableDTX)? 1:0)) < 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalInitEncoder: cannot init encoder for GSMFR"); - } - return 0; + { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalInitEncoder: cannot init encoder for GSMFR"); + } + return 0; } -WebRtc_Word16 +WebRtc_Word16 ACMGSMFR::InternalInitDecoder( WebRtcACMCodecParams* /* codecParams */) { if (WebRtcGSMFR_DecoderInit(_decoderInstPtr) < 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalInitDecoder: cannot init decoder for GSMFR"); - return -1; - } - return 0; + { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalInitDecoder: cannot init decoder for GSMFR"); + return -1; + } + return 0; } -WebRtc_Word32 +WebRtc_Word32 ACMGSMFR::CodecDef( WebRtcNetEQ_CodecDef& codecDef, const CodecInst& codecInst) { if (!_decoderInitialized) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "CodecDef: decoder is not initialized for GSMFR"); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "CodecDef: decoder is not initialized for GSMFR"); return -1; } - // Fill up the structure by calling + // Fill up the structure by calling // "SET_CODEC_PAR" & "SET_GSMFR_FUNCTION." // Then call NetEQ to add the codec to it's // database. @@ -322,27 +322,27 @@ ACMGSMFR::CodecDef( } -ACMGenericCodec* +ACMGenericCodec* ACMGSMFR::CreateInstance(void) { return NULL; } -WebRtc_Word16 +WebRtc_Word16 ACMGSMFR::InternalCreateEncoder() { if (WebRtcGSMFR_CreateEnc(&_encoderInstPtr) < 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalCreateEncoder: cannot create instance for GSMFR encoder"); - return -1; - } - return 0; + { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalCreateEncoder: cannot create instance for GSMFR encoder"); + return -1; + } + return 0; } -void +void ACMGSMFR::DestructEncoderSafe() { if(_encoderInstPtr != NULL) @@ -355,20 +355,20 @@ ACMGSMFR::DestructEncoderSafe() } -WebRtc_Word16 +WebRtc_Word16 ACMGSMFR::InternalCreateDecoder() { if (WebRtcGSMFR_CreateDec(&_decoderInstPtr) < 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalCreateDecoder: cannot create instance for GSMFR decoder"); - return -1; - } - return 0; + { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalCreateDecoder: cannot create instance for GSMFR decoder"); + return -1; + } + return 0; } -void +void ACMGSMFR::DestructDecoderSafe() { if(_decoderInstPtr != NULL) @@ -381,7 +381,7 @@ ACMGSMFR::DestructDecoderSafe() } -void +void ACMGSMFR::InternalDestructEncoderInst( void* ptrInst) { @@ -393,18 +393,18 @@ ACMGSMFR::InternalDestructEncoderInst( } -WebRtc_Word16 +WebRtc_Word16 ACMGSMFR::UnregisterFromNetEqSafe( ACMNetEQ* netEq, WebRtc_Word16 payloadType) { if(payloadType != _decoderParams.codecInstant.pltype) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "Cannot unregister codec: payload-type does not match \ -the stored payload type", - _decoderParams.codecInstant.plname, - payloadType, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "Cannot unregister codec: payload-type does not match \ +the stored payload type", + _decoderParams.codecInstant.plname, + payloadType, _decoderParams.codecInstant.pltype); return -1; } diff --git a/src/modules/audio_coding/main/source/acm_gsmfr.h b/src/modules/audio_coding/main/source/acm_gsmfr.h index 87eeb5af3..43e05fc08 100644 --- a/src/modules/audio_coding/main/source/acm_gsmfr.h +++ b/src/modules/audio_coding/main/source/acm_gsmfr.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_GSMFR_H -#define ACM_GSMFR_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_GSMFR_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_GSMFR_H_ #include "acm_generic_codec.h" @@ -28,7 +28,7 @@ public: ACMGenericCodec* CreateInstance(void); WebRtc_Word16 InternalEncode( - WebRtc_UWord8* bitstream, + WebRtc_UWord8* bitstream, WebRtc_Word16* bitStreamLenByte); WebRtc_Word16 InternalInitEncoder( @@ -39,29 +39,29 @@ public: protected: WebRtc_Word16 DecodeSafe( - WebRtc_UWord8* bitStream, - WebRtc_Word16 bitStreamLenByte, - WebRtc_Word16* audio, + WebRtc_UWord8* bitStream, + WebRtc_Word16 bitStreamLenByte, + WebRtc_Word16* audio, WebRtc_Word16* audioSamples, WebRtc_Word8* speechType); WebRtc_Word32 CodecDef( - WebRtcNetEQ_CodecDef& codecDef, + WebRtcNetEQ_CodecDef& codecDef, const CodecInst& codecInst); void DestructEncoderSafe(); - + void DestructDecoderSafe(); WebRtc_Word16 InternalCreateEncoder(); - + WebRtc_Word16 InternalCreateDecoder(); - + void InternalDestructEncoderInst( void* ptrInst); WebRtc_Word16 EnableDTX(); - + WebRtc_Word16 DisableDTX(); WebRtc_Word16 UnregisterFromNetEqSafe( @@ -74,5 +74,4 @@ protected: } // namespace webrtc -#endif // ACM_GSMFR_H - +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_GSMFR_H_ diff --git a/src/modules/audio_coding/main/source/acm_ilbc.cc b/src/modules/audio_coding/main/source/acm_ilbc.cc index 28e69e792..46de1ad03 100644 --- a/src/modules/audio_coding/main/source/acm_ilbc.cc +++ b/src/modules/audio_coding/main/source/acm_ilbc.cc @@ -76,7 +76,7 @@ ACMILBC::InternalInitDecoder( WebRtc_Word32 ACMILBC::CodecDef( - WebRtcNetEQ_CodecDef& /* codecDef */, + WebRtcNetEQ_CodecDef& /* codecDef */, const CodecInst& /* codecInst */) { return -1; @@ -97,7 +97,7 @@ ACMILBC::InternalCreateEncoder() } -void +void ACMILBC::DestructEncoderSafe() { return; @@ -111,14 +111,14 @@ ACMILBC::InternalCreateDecoder() } -void +void ACMILBC::DestructDecoderSafe() { return; } -void +void ACMILBC::InternalDestructEncoderInst( void* /* ptrInst */) { @@ -175,15 +175,15 @@ ACMILBC::InternalEncode( WebRtc_UWord8* bitStream, WebRtc_Word16* bitStreamLenByte) { - *bitStreamLenByte = WebRtcIlbcfix_Encode(_encoderInstPtr, + *bitStreamLenByte = WebRtcIlbcfix_Encode(_encoderInstPtr, &_inAudio[_inAudioIxRead], _frameLenSmpl, (WebRtc_Word16*)bitStream); if (*bitStreamLenByte < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalEncode: error in encode for ILBC"); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalEncode: error in encode for ILBC"); return -1; } - // increment the read index this tell the caller that how far + // increment the read index this tell the caller that how far // we have gone forward in reading the audio buffer _inAudioIxRead += _frameLenSmpl; return *bitStreamLenByte; @@ -207,7 +207,7 @@ ACMILBC::InternalInitEncoder( WebRtcACMCodecParams* codecParams) { // initialize with a correct processing block length - if((160 == (codecParams->codecInstant).pacsize) || + if((160 == (codecParams->codecInstant).pacsize) || (320 == (codecParams->codecInstant).pacsize)) { // processing block of 20ms @@ -221,8 +221,8 @@ ACMILBC::InternalInitEncoder( } else { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalInitEncoder: invalid processing block"); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalInitEncoder: invalid processing block"); return -1; } } @@ -233,13 +233,13 @@ ACMILBC::InternalInitDecoder( WebRtcACMCodecParams* codecParams) { // initialize with a correct processing block length - if((160 == (codecParams->codecInstant).pacsize) || + if((160 == (codecParams->codecInstant).pacsize) || (320 == (codecParams->codecInstant).pacsize)) { // processing block of 20ms return WebRtcIlbcfix_DecoderInit(_decoderInstPtr, 20); } - else if((240 == (codecParams->codecInstant).pacsize) || + else if((240 == (codecParams->codecInstant).pacsize) || (480 == (codecParams->codecInstant).pacsize)) { // processing block of 30ms @@ -247,8 +247,8 @@ ACMILBC::InternalInitDecoder( } else { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalInitDecoder: invalid processing block"); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalInitDecoder: invalid processing block"); return -1; } } @@ -261,15 +261,15 @@ ACMILBC::CodecDef( { if (!_decoderInitialized) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "CodeDef: decoder not initialized for ILBC"); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "CodeDef: decoder not initialized for ILBC"); return -1; } - // Fill up the structure by calling + // Fill up the structure by calling // "SET_CODEC_PAR" & "SET_ILBC_FUNCTION." // Then return the structure back to NetEQ to add the codec to it's // database. - SET_CODEC_PAR((codecDef), kDecoderILBC, codecInst.pltype, + SET_CODEC_PAR((codecDef), kDecoderILBC, codecInst.pltype, _decoderInstPtr, 8000); SET_ILBC_FUNCTIONS((codecDef)); return 0; @@ -288,15 +288,15 @@ ACMILBC::InternalCreateEncoder() { if (WebRtcIlbcfix_EncoderCreate(&_encoderInstPtr) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalCreateEncoder: cannot create instance for ILBC encoder"); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalCreateEncoder: cannot create instance for ILBC encoder"); return -1; } return 0; } -void +void ACMILBC::DestructEncoderSafe() { _encoderInitialized = false; @@ -314,15 +314,15 @@ ACMILBC::InternalCreateDecoder() { if (WebRtcIlbcfix_DecoderCreate(&_decoderInstPtr) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalCreateDecoder: cannot create instance for ILBC decoder"); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalCreateDecoder: cannot create instance for ILBC decoder"); return -1; } return 0; } -void +void ACMILBC::DestructDecoderSafe() { _decoderInitialized = false; @@ -335,7 +335,7 @@ ACMILBC::DestructDecoderSafe() } -void +void ACMILBC::InternalDestructEncoderInst( void* ptrInst) { @@ -350,10 +350,10 @@ WebRtc_Word16 ACMILBC::SetBitRateSafe(const WebRtc_Word32 rate) { // Check that rate is valid. No need to store the value - if (rate == 13300) + if (rate == 13300) { WebRtcIlbcfix_EncoderInit(_encoderInstPtr, 30); - } + } else if (rate == 15200) { WebRtcIlbcfix_EncoderInit(_encoderInstPtr, 20); @@ -374,11 +374,11 @@ ACMILBC::UnregisterFromNetEqSafe( { if(payloadType != _decoderParams.codecInstant.pltype) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Cannot unregister codec: given payload-type does not match \ -the stored payload type", - _decoderParams.codecInstant.plname, - payloadType, +the stored payload type", + _decoderParams.codecInstant.plname, + payloadType, _decoderParams.codecInstant.pltype); return -1; } diff --git a/src/modules/audio_coding/main/source/acm_ilbc.h b/src/modules/audio_coding/main/source/acm_ilbc.h index c35c2cec7..2d3e42022 100644 --- a/src/modules/audio_coding/main/source/acm_ilbc.h +++ b/src/modules/audio_coding/main/source/acm_ilbc.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_ILBC_H -#define ACM_ILBC_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_ILBC_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_ILBC_H_ #include "acm_generic_codec.h" @@ -47,21 +47,21 @@ protected: WebRtc_Word8* speechType); WebRtc_Word32 CodecDef( - WebRtcNetEQ_CodecDef& codecDef, + WebRtcNetEQ_CodecDef& codecDef, const CodecInst& codecInst); - + WebRtc_Word16 SetBitRateSafe( const WebRtc_Word32 rate); void DestructEncoderSafe(); - + void DestructDecoderSafe(); WebRtc_Word16 InternalCreateEncoder(); - + WebRtc_Word16 InternalCreateDecoder(); - + void InternalDestructEncoderInst( void* ptrInst); @@ -75,5 +75,4 @@ protected: } // namespace webrtc -#endif //ACM_ILBC_H - +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_ILBC_H_ diff --git a/src/modules/audio_coding/main/source/acm_isac.cc b/src/modules/audio_coding/main/source/acm_isac.cc index e24279213..42a7469fc 100644 --- a/src/modules/audio_coding/main/source/acm_isac.cc +++ b/src/modules/audio_coding/main/source/acm_isac.cc @@ -43,10 +43,10 @@ struct ACMISACInst #define ISAC_MAX_RATE 56000 -// How the scaling is computed. iSAC computes a gain based on the +// How the scaling is computed. iSAC computes a gain based on the // bottleneck. It follows the following expression for that -// -// G(BN_kbps) = pow(10, (a + b * BN_kbps + c * BN_kbps * BN_kbps) / 20.0) +// +// G(BN_kbps) = pow(10, (a + b * BN_kbps + c * BN_kbps * BN_kbps) / 20.0) // / 3.4641; // // Where for 30 ms framelength we have, @@ -59,11 +59,11 @@ struct ACMISACInst #define ISAC_NUM_SUPPORTED_RATES 9 const WebRtc_UWord16 isacSuportedRates[ISAC_NUM_SUPPORTED_RATES] = { - 32000, 30000, 26000, 23000, 21000, + 32000, 30000, 26000, 23000, 21000, 19000, 17000, 15000, 12000}; const float isacScale[ISAC_NUM_SUPPORTED_RATES] = { - 1.0f, 0.8954f, 0.7178f, 0.6081f, 0.5445f, + 1.0f, 0.8954f, 0.7178f, 0.6081f, 0.5445f, 0.4875f, 0.4365f, 0.3908f, 0.3311f}; // Tables for bandwidth estimates @@ -78,10 +78,10 @@ const WebRtc_Word32 isacRatesWB[NR_ISAC_BANDWIDTHS] = const WebRtc_Word32 isacRatesSWB[NR_ISAC_BANDWIDTHS] = { - 10000, 11000, 12400, 13800, 15300, 17000, - 18900, 21000, 23200, 25400, 27600, 29800, - 32000, 34100, 36300, 38500, 40700, 42900, - 45100, 47300, 49500, 51700, 53900, 56000, + 10000, 11000, 12400, 13800, 15300, 17000, + 18900, 21000, 23200, 25400, 27600, 29800, + 32000, 34100, 36300, 38500, 40700, 42900, + 45100, 47300, 49500, 51700, 53900, 56000, }; #if (!defined(WEBRTC_CODEC_ISAC) && !defined(WEBRTC_CODEC_ISACFX)) @@ -150,7 +150,7 @@ ACMISAC::InternalCreateDecoder() } -void +void ACMISAC::DestructDecoderSafe() { return; @@ -164,7 +164,7 @@ ACMISAC::InternalCreateEncoder() } -void +void ACMISAC::DestructEncoderSafe() { return; @@ -173,14 +173,14 @@ ACMISAC::DestructEncoderSafe() WebRtc_Word32 ACMISAC::CodecDef( - WebRtcNetEQ_CodecDef& /* codecDef */, + WebRtcNetEQ_CodecDef& /* codecDef */, const CodecInst& /* codecInst */) { return -1; } -void +void ACMISAC::InternalDestructEncoderInst( void* /* ptrInst */) { @@ -286,7 +286,7 @@ ACMISAC::SetISACMaxPayloadSize( { return -1; } - + WebRtc_Word32 ACMISAC::SetISACMaxRate( const WebRtc_UWord32 /* maxRateBitPerSec */) @@ -295,20 +295,20 @@ ACMISAC::SetISACMaxRate( } -void +void ACMISAC::UpdateFrameLen() { return; } -void +void ACMISAC::CurrentRate( WebRtc_Word32& /*rateBitPerSec */) { return; } -bool +bool ACMISAC::DecoderParamsSafe( WebRtcACMCodecParams* /* decParams */, const WebRtc_UWord8 /* payloadType */) @@ -316,7 +316,7 @@ ACMISAC::DecoderParamsSafe( return false; } -void +void ACMISAC::SaveDecoderParamSafe( const WebRtcACMCodecParams* /* codecParams */) { @@ -346,17 +346,17 @@ enum IsacSamplingRate kIsacSuperWideband = 32 }; -static float +static float ACMISACFixTranscodingScale( WebRtc_UWord16 rate) { // find the scale for transcoding, the scale is rounded - // downward + // downward float scale = -1; for(WebRtc_Word16 n=0; n < ISAC_NUM_SUPPORTED_RATES; n++) { if(rate >= isacSuportedRates[n]) - { + { scale = isacScale[n]; break; } @@ -364,7 +364,7 @@ ACMISACFixTranscodingScale( return scale; } -static void +static void ACMISACFixGetSendBitrate( ACM_ISAC_STRUCT* inst, WebRtc_Word32* bottleNeck) @@ -506,9 +506,9 @@ ACMISAC::InternalEncode( // it should be treated like codecs with 'basic coding block' // non-zero, and the following 'while-loop' should not be necessary. // However, due to a mistake in the codec the frame-size might change - // at the first 10ms pushed in to iSAC if the bit-rate is low, this is - // sort of a bug in iSAC. to address this we treat iSAC as the - // following. + // at the first 10ms pushed in to iSAC if the bit-rate is low, this is + // sort of a bug in iSAC. to address this we treat iSAC as the + // following. if (_codecInstPtr == NULL) { @@ -527,7 +527,7 @@ pushed in but no bit-stream is generated."); } *bitStreamLenByte = ACM_ISAC_ENCODE(_codecInstPtr->inst, &_inAudio[_inAudioIxRead], (WebRtc_Word16*)bitstream); - // increment the read index this tell the caller that how far + // increment the read index this tell the caller that how far // we have gone forward in reading the audio buffer _inAudioIxRead += _samplesIn10MsAudio; } @@ -571,9 +571,9 @@ ACMISAC::InternalInitEncoder( { _isacCodingMode = ADAPTIVE; } - + // sanity check that rate is in acceptable range - else if((codecParams->codecInstant.rate >= ISAC_MIN_RATE) && + else if((codecParams->codecInstant.rate >= ISAC_MIN_RATE) && (codecParams->codecInstant.rate <= ISAC_MAX_RATE)) { _isacCodingMode = CHANNEL_INDEPENDENT; @@ -584,7 +584,7 @@ ACMISAC::InternalInitEncoder( return -1; } - // we need to set the encoder sampling frequency. + // we need to set the encoder sampling frequency. if(UpdateEncoderSampFreq((WebRtc_UWord16)codecParams->codecInstant.plfreq) < 0) { return -1; @@ -599,8 +599,8 @@ ACMISAC::InternalInitEncoder( if(_isacCodingMode == CHANNEL_INDEPENDENT) { if(ACM_ISAC_CONTROL(_codecInstPtr->inst, - codecParams->codecInstant.rate, - codecParams->codecInstant.pacsize / + codecParams->codecInstant.rate, + codecParams->codecInstant.pacsize / (codecParams->codecInstant.plfreq / 1000)) < 0) { return -1; @@ -608,7 +608,7 @@ ACMISAC::InternalInitEncoder( } else { - // We need this for adaptive case and has to be called + // We need this for adaptive case and has to be called // after initialization ACM_ISAC_GETSENDBITRATE( _codecInstPtr->inst, &_isacCurrentBN); @@ -637,15 +637,15 @@ ACMISAC::InternalInitDecoder( } // in a one-way communication we may never register send-codec. - // However we like that the BWE to work properly so it has to - // be initialized. The BWE is initialized when iSAC encoder is initialized. + // However we like that the BWE to work properly so it has to + // be initialized. The BWE is initialized when iSAC encoder is initialized. // Therefore, we need this. if(!_encoderInitialized) { // Since we don't require a valid rate or a valid packet size when initializing // the decoder, we set valid values before initializing encoder - codecParams->codecInstant.rate = ISACWB_DEFAULT_RATE; - codecParams->codecInstant.pacsize = ISACSWB_PAC_SIZE; + codecParams->codecInstant.rate = kIsacWbDefaultRate; + codecParams->codecInstant.pacsize = kIsacPacSize960; if(InternalInitEncoder(codecParams) < 0) { return -1; @@ -670,7 +670,7 @@ ACMISAC::InternalCreateDecoder() _encoderInitialized = false; if(status < 0) { - _encoderExist = false; + _encoderExist = false; } else { @@ -680,7 +680,7 @@ ACMISAC::InternalCreateDecoder() } -void +void ACMISAC::DestructDecoderSafe() { // codec with shared instance cannot delete. @@ -712,7 +712,7 @@ ACMISAC::InternalCreateEncoder() } -void +void ACMISAC::DestructEncoderSafe() { // codec with shared instance cannot delete. @@ -737,7 +737,7 @@ ACMISAC::CodecDef( // log error return -1; } - // Fill up the structure by calling + // Fill up the structure by calling // "SET_CODEC_PAR" & "SET_ISAC_FUNCTION." // Then call NetEQ to add the codec to it's // database. @@ -766,7 +766,7 @@ ACMISAC::CodecDef( } -void +void ACMISAC::InternalDestructEncoderInst( void* ptrInst) { @@ -821,7 +821,7 @@ ACMISAC::SetBitRateSafe( bool reinit = false; // change the BN of iSAC if(bitRate == -1) - { + { // ADAPTIVE MODE // Check if it was already in adaptive mode if(_isacCodingMode != ADAPTIVE) @@ -833,13 +833,13 @@ ACMISAC::SetBitRateSafe( } } // Sanity check if the rate valid - else if((bitRate >= ISAC_MIN_RATE) && + else if((bitRate >= ISAC_MIN_RATE) && (bitRate <= ISAC_MAX_RATE)) { //check if it was in channel-independent mode before if(_isacCodingMode != CHANNEL_INDEPENDENT) { - // was not in channel independent, set the mode to + // was not in channel independent, set the mode to // channel-independent and flag for re-initialization _isacCodingMode = CHANNEL_INDEPENDENT; reinit = true; @@ -867,13 +867,13 @@ ACMISAC::SetBitRateSafe( { status = ACM_ISAC_CONTROL(_codecInstPtr->inst, _isacCurrentBN, - (encoderSampFreq == 32000)? 30:(_frameLenSmpl / 16)); + (encoderSampFreq == 32000)? 30:(_frameLenSmpl / 16)); if(status < 0) { status = -1; } } - + // Update encoder parameters _encoderParams.codecInstant.rate = bitRate; @@ -889,9 +889,9 @@ ACMISAC::GetEstimatedBandwidthSafe() WebRtc_Word16 delayIndex; IsacSamplingRate sampRate; - // Get bandwidth information + // Get bandwidth information ACM_ISAC_GETSENDBWE(_codecInstPtr->inst, &bandwidthIndex, &delayIndex); - + // Validy check of index if ((bandwidthIndex < 0) || (bandwidthIndex > NR_ISAC_BANDWIDTHS)) { @@ -921,11 +921,11 @@ ACMISAC::SetEstimatedBandwidthSafe( sampRate = ACM_ISAC_GETENCSAMPRATE(_codecInstPtr->inst); if(sampRate == kIsacWideband) - { + { // Search through the WB rate table to find the index - + bandwidthIndex = NR_ISAC_BANDWIDTHS/2 - 1; - for (int i=0; i<(NR_ISAC_BANDWIDTHS/2); i++) + for (int i=0; i<(NR_ISAC_BANDWIDTHS/2); i++) { if (estimatedBandwidth == isacRatesWB[i]) { @@ -936,7 +936,7 @@ ACMISAC::SetEstimatedBandwidthSafe( bandwidthIndex = i + NR_ISAC_BANDWIDTHS/2; break; } else if (estimatedBandwidth < isacRatesWB[i]) - { + { bandwidthIndex = i; break; } @@ -946,7 +946,7 @@ ACMISAC::SetEstimatedBandwidthSafe( { // Search through the SWB rate table to find the index bandwidthIndex = NR_ISAC_BANDWIDTHS - 1; - for (int i=0; iinst, (WebRtc_Word16*)redPayload); if (bytes < 0) { @@ -996,15 +996,15 @@ ACMISAC::UnregisterFromNetEqSafe( } else if(payloadType == _decoderParams32kHz.codecInstant.pltype) { - return netEq->RemoveCodec(kDecoderISACswb); + return netEq->RemoveCodec(kDecoderISACswb); } else { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Cannot unregister codec %s given payload-type %d does not match \ -the stored payload type %d or %d", - _decoderParams.codecInstant.plname, - payloadType, +the stored payload type %d or %d", + _decoderParams.codecInstant.plname, + payloadType, _decoderParams.codecInstant.pltype, _decoderParams32kHz.codecInstant.pltype); @@ -1066,7 +1066,7 @@ ACMISAC::UpdateEncoderSampFreq( } _samplesIn10MsAudio = 160; } - else + else { if(WebRtcIsac_SetEncSampRate(_codecInstPtr->inst, kIsacSuperWideband) < 0) @@ -1084,7 +1084,7 @@ ACMISAC::UpdateEncoderSampFreq( #else WebRtc_UWord16 /* codecId */) { -#endif +#endif return 0; } @@ -1116,8 +1116,8 @@ ACMISAC::ConfigISACBandwidthEstimator( WebRtc_UWord16 sampFreqHz; EncoderSampFreq(sampFreqHz); // @TODO: at 32kHz we hardcode calling with 30ms and enforce - // the frame-size otherwise we might get error. Revise if - // control-bwe is changed. + // the frame-size otherwise we might get error. Revise if + // control-bwe is changed. if(sampFreqHz == 32000) { status = ACM_ISAC_CONTROL_BWE(_codecInstPtr->inst, @@ -1146,7 +1146,7 @@ ACMISAC::SetISACMaxPayloadSize( { return ACM_ISAC_SETMAXPAYLOADSIZE(_codecInstPtr->inst, maxPayloadLenBytes); } - + WebRtc_Word32 ACMISAC::SetISACMaxRate( const WebRtc_UWord32 maxRateBitPerSec) @@ -1155,14 +1155,14 @@ ACMISAC::SetISACMaxRate( } -void +void ACMISAC::UpdateFrameLen() { _frameLenSmpl = ACM_ISAC_GETNEWFRAMELEN(_codecInstPtr->inst); _encoderParams.codecInstant.pacsize = _frameLenSmpl; } -void +void ACMISAC::CurrentRate(WebRtc_Word32& rateBitPerSec) { if(_isacCodingMode == ADAPTIVE) @@ -1172,7 +1172,7 @@ ACMISAC::CurrentRate(WebRtc_Word32& rateBitPerSec) } -bool +bool ACMISAC::DecoderParamsSafe( WebRtcACMCodecParams* decParams, const WebRtc_UWord8 payloadType) @@ -1186,7 +1186,7 @@ ACMISAC::DecoderParamsSafe( } if(payloadType == _decoderParams32kHz.codecInstant.pltype) { - memcpy(decParams, &_decoderParams32kHz, + memcpy(decParams, &_decoderParams32kHz, sizeof(WebRtcACMCodecParams)); return true; } @@ -1194,10 +1194,10 @@ ACMISAC::DecoderParamsSafe( return false; } -void +void ACMISAC::SaveDecoderParamSafe( const WebRtcACMCodecParams* codecParams) -{ +{ // set decoder sampling frequency. if(codecParams->codecInstant.plfreq == 32000) { diff --git a/src/modules/audio_coding/main/source/acm_isac.h b/src/modules/audio_coding/main/source/acm_isac.h index 681c1a4f6..6013c61ad 100644 --- a/src/modules/audio_coding/main/source/acm_isac.h +++ b/src/modules/audio_coding/main/source/acm_isac.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_ISAC_H -#define ACM_ISAC_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_ISAC_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_ISAC_H_ #include "acm_generic_codec.h" @@ -32,7 +32,7 @@ public: WebRtc_Word16 InternalEncode( WebRtc_UWord8* bitstream, WebRtc_Word16* bitStreamLenByte); - + WebRtc_Word16 InternalInitEncoder( WebRtcACMCodecParams *codecParams); @@ -52,7 +52,7 @@ public: WebRtc_Word16* /* bitStreamLenByte */, WebRtc_UWord32* /* timestamp */, WebRtcACMEncodingType* /* encodingType */) - { + { return -1; } @@ -91,13 +91,13 @@ protected: WebRtc_Word8* speechType); WebRtc_Word32 CodecDef( - WebRtcNetEQ_CodecDef& codecDef, + WebRtcNetEQ_CodecDef& codecDef, const CodecInst& codecInst); void DestructEncoderSafe(); - + void DestructDecoderSafe(); - + WebRtc_Word16 SetBitRateSafe( const WebRtc_Word32 bitRate); @@ -110,9 +110,9 @@ protected: WebRtc_Word16* payloadBytes); WebRtc_Word16 InternalCreateEncoder(); - + WebRtc_Word16 InternalCreateDecoder(); - + void InternalDestructEncoderInst( void* ptrInst); @@ -130,7 +130,7 @@ protected: void CurrentRate(WebRtc_Word32& rateBitPerSec); void UpdateFrameLen(); - + bool DecoderParamsSafe( WebRtcACMCodecParams *decParams, const WebRtc_UWord8 payloadType); @@ -150,4 +150,4 @@ protected: } //namespace -#endif // ACM_ISAC_H +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_ISAC_H_ diff --git a/src/modules/audio_coding/main/source/acm_isac_macros.h b/src/modules/audio_coding/main/source/acm_isac_macros.h index 030164c8b..9e5f55f2e 100644 --- a/src/modules/audio_coding/main/source/acm_isac_macros.h +++ b/src/modules/audio_coding/main/source/acm_isac_macros.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_ISAC_MACROS_H -#define ACM_ISAC_MACROS_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_ISAC_MACROS_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_ISAC_MACROS_H_ #include "engine_configurations.h" @@ -72,5 +72,5 @@ namespace webrtc } //namespace -#endif // ACM_ISAC_MACROS_H +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_ISAC_MACROS_H_ diff --git a/src/modules/audio_coding/main/source/acm_neteq.cc b/src/modules/audio_coding/main/source/acm_neteq.cc index 8294171f4..d3a69d9c4 100644 --- a/src/modules/audio_coding/main/source/acm_neteq.cc +++ b/src/modules/audio_coding/main/source/acm_neteq.cc @@ -122,7 +122,7 @@ ACMNetEQ::Init() // Has to enable VAD if(EnableVADByIdxSafe(idx) < 0) { - // Failed to enable VAD. + // Failed to enable VAD. // Delete VAD instance, if it is created if(_ptrVADInst[idx] != NULL) { @@ -164,7 +164,7 @@ ACMNetEQ::InitByIdxSafe( _instMem[idx] = malloc(memorySizeBytes); if (_instMem[idx] == NULL) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "InitByIdxSafe: NetEq Initialization error: could not allocate memory for NetEq"); _isInitialized[idx] = false; return -1; @@ -176,8 +176,8 @@ ACMNetEQ::InitByIdxSafe( _instMem[idx] = NULL; } LogError("Assign", idx); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, - "InitByIdxSafe: NetEq Initialization error: could not Assign"); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + "InitByIdxSafe: NetEq Initialization error: could not Assign"); _isInitialized[idx] = false; return -1; } @@ -188,8 +188,8 @@ ACMNetEQ::InitByIdxSafe( _instMem[idx] = NULL; } LogError("Init", idx); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, - "InitByIdxSafe: NetEq Initialization error: could not initialize NetEq"); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + "InitByIdxSafe: NetEq Initialization error: could not initialize NetEq"); _isInitialized[idx] = false; return -1; } @@ -206,28 +206,28 @@ ACMNetEQ::EnableVADByIdxSafe( if(WebRtcVad_Create(&_ptrVADInst[idx]) < 0) { _ptrVADInst[idx] = NULL; - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, - "EnableVADByIdxSafe: NetEq Initialization error: could not create VAD"); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + "EnableVADByIdxSafe: NetEq Initialization error: could not create VAD"); return -1; } } - + if(WebRtcNetEQ_SetVADInstance(_inst[idx], _ptrVADInst[idx], (WebRtcNetEQ_VADInitFunction) WebRtcVad_Init, (WebRtcNetEQ_VADSetmodeFunction) WebRtcVad_set_mode, (WebRtcNetEQ_VADFunction) WebRtcVad_Process) < 0) { LogError("setVADinstance", idx); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, - "EnableVADByIdxSafe: NetEq Initialization error: could not set VAD instance"); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + "EnableVADByIdxSafe: NetEq Initialization error: could not set VAD instance"); return -1; } if(WebRtcNetEQ_SetVADMode(_inst[idx], _vadMode) < 0) { LogError("setVADmode", idx); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, - "EnableVADByIdxSafe: NetEq Initialization error: could not set VAD mode"); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + "EnableVADByIdxSafe: NetEq Initialization error: could not set VAD mode"); return -1; } return 0; @@ -238,18 +238,18 @@ ACMNetEQ::EnableVADByIdxSafe( WebRtc_Word32 ACMNetEQ::AllocatePacketBuffer( - WebRtcNetEQDecoder* usedCodecs, + WebRtcNetEQDecoder* usedCodecs, WebRtc_Word16 noOfCodecs) { // Due to WebRtcNetEQ_GetRecommendedBufferSize // the following has to be int otherwise we will have compiler error - // if not casted + // if not casted CriticalSectionScoped lock(*_netEqCritSect); for(WebRtc_Word16 idx = 0; idx < _numSlaves + 1; idx++) { if(AllocatePacketBufferByIdxSafe(usedCodecs, noOfCodecs, idx) < 0) - { + { return -1; } } @@ -258,7 +258,7 @@ ACMNetEQ::AllocatePacketBuffer( WebRtc_Word16 ACMNetEQ::AllocatePacketBufferByIdxSafe( - WebRtcNetEQDecoder* usedCodecs, + WebRtcNetEQDecoder* usedCodecs, WebRtc_Word16 noOfCodecs, const WebRtc_Word16 idx) { @@ -267,11 +267,11 @@ ACMNetEQ::AllocatePacketBufferByIdxSafe( if(!_isInitialized[idx]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "AllocatePacketBufferByIdxSafe: NetEq is not initialized."); return -1; } - if (WebRtcNetEQ_GetRecommendedBufferSize(_inst[idx], usedCodecs, noOfCodecs, + if (WebRtcNetEQ_GetRecommendedBufferSize(_inst[idx], usedCodecs, noOfCodecs, kTCPLargeJitter , &maxNoPackets, &bufferSizeInBytes) != 0) { @@ -286,8 +286,8 @@ ACMNetEQ::AllocatePacketBufferByIdxSafe( _netEqPacketBuffer[idx] = (WebRtc_Word16 *)malloc(bufferSizeInBytes); if (_netEqPacketBuffer[idx] == NULL) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "AllocatePacketBufferByIdxSafe: NetEq Initialization error: could not allocate " "memory for NetEq Packet Buffer"); return -1; @@ -319,7 +319,7 @@ ACMNetEQ::SetExtraDelay( { if(!_isInitialized[idx]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "SetExtraDelay: NetEq is not initialized."); return -1; } @@ -329,7 +329,7 @@ ACMNetEQ::SetExtraDelay( return -1; } } - return 0; + return 0; } @@ -344,7 +344,7 @@ ACMNetEQ::SetAVTPlayout( { if(!_isInitialized[idx]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "SetAVTPlayout: NetEq is not initialized."); return -1; } @@ -373,7 +373,7 @@ ACMNetEQ::CurrentSampFreqHz() const CriticalSectionScoped lock(*_netEqCritSect); if(!_isInitialized[0]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "CurrentSampFreqHz: NetEq is not initialized."); return -1; } @@ -392,7 +392,7 @@ ACMNetEQ::SetPlayoutMode( { if(!_isInitialized[idx]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "SetPlayoutMode: NetEq is not initialized."); return -1; } @@ -410,10 +410,9 @@ ACMNetEQ::SetPlayoutMode( playoutMode = kPlayoutStreaming; break; default: - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, - "SetPlayoutMode: NetEq Error playout mode not recognized"); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + "SetPlayoutMode: NetEq Error playout mode not recognized"); return -1; - break; } if(WebRtcNetEQ_SetPlayoutMode(_inst[idx], playoutMode) < 0) { @@ -443,7 +442,7 @@ ACMNetEQ::NetworkStatistics( CriticalSectionScoped lock(*_netEqCritSect); if(!_isInitialized[0]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "NetworkStatistics: NetEq is not initialized."); return -1; } @@ -474,7 +473,7 @@ ACMNetEQ::JitterStatistics( CriticalSectionScoped lock(*_netEqCritSect); if(!_isInitialized[0]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "JitterStatistics: NetEq is not initialized."); return -1; } @@ -555,7 +554,7 @@ ACMNetEQ::RecIn( netEqRTPInfo.markerBit = rtpInfo.header.markerBit; CriticalSectionScoped lock(*_netEqCritSect); - // Down-cast the time to (32-6)-bit since we only care about + // Down-cast the time to (32-6)-bit since we only care about // the least significant bits. (32-6) bits cover 2^(32-6) = 67108864 ms. // we masked 6 most significant bits of 32-bit so we don't loose resolution // when do the following multiplication. @@ -565,23 +564,23 @@ ACMNetEQ::RecIn( (_currentSampFreqKHz * nowInMs); int status; - + if(rtpInfo.type.Audio.channel == 1) { if(!_isInitialized[0]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "RecIn: NetEq is not initialized."); return -1; } // PUSH into Master - status = WebRtcNetEQ_RecInRTPStruct(_inst[0], &netEqRTPInfo, + status = WebRtcNetEQ_RecInRTPStruct(_inst[0], &netEqRTPInfo, (WebRtc_UWord8 *)incomingPayload, (WebRtc_Word16)payloadLength, recvTimestamp); if(status < 0) { LogError("RecInRTPStruct", 0); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "RecIn: NetEq, error in pushing in Master"); return -1; } @@ -590,27 +589,27 @@ ACMNetEQ::RecIn( { if(!_isInitialized[1]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "RecIn: NetEq is not initialized."); return -1; } // PUSH into Slave - status = WebRtcNetEQ_RecInRTPStruct(_inst[1], &netEqRTPInfo, + status = WebRtcNetEQ_RecInRTPStruct(_inst[1], &netEqRTPInfo, (WebRtc_UWord8 *)incomingPayload, (WebRtc_Word16)payloadLength, recvTimestamp); if(status < 0) { LogError("RecInRTPStruct", 1); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "RecIn: NetEq, error in pushing in Slave"); return -1; } } else { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "RecIn: NetEq, error invalid numbe of channels %d \ -(1, for Master stream, and 2, for slave stream, are valid values)", +(1, for Master stream, and 2, for slave stream, are valid values)", rtpInfo.type.Audio.channel); return -1; } @@ -635,13 +634,13 @@ ACMNetEQ::RecOut( { if(!_isInitialized[0]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "RecOut: NetEq is not initialized."); return -1; } { WriteLockScoped lockCodec(*_decodeLock); - if(WebRtcNetEQ_RecOut(_inst[0], &(audioFrame._payloadData[0]), + if(WebRtcNetEQ_RecOut(_inst[0], &(audioFrame._payloadData[0]), &payloadLenSample) != 0) { LogError("RecOut", 0); @@ -665,7 +664,7 @@ ACMNetEQ::RecOut( { if(!_isInitialized[0] || !_isInitialized[1]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "RecOut: NetEq is not initialized."); return -1; } @@ -673,11 +672,11 @@ ACMNetEQ::RecOut( WebRtc_Word16 payloadSlave[480]; { WriteLockScoped lockCodec(*_decodeLock); - if(WebRtcNetEQ_RecOutMasterSlave(_inst[0], payloadMaster, + if(WebRtcNetEQ_RecOutMasterSlave(_inst[0], payloadMaster, &payloadLenSample, _masterSlaveInfo, 1) != 0) { LogError("RecOutMasterSlave", 0); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "RecOut: NetEq, error in pulling out for master"); // Check for errors that can be recovered from: @@ -689,11 +688,11 @@ ACMNetEQ::RecOut( return -1; } } - if(WebRtcNetEQ_RecOutMasterSlave(_inst[1], payloadSlave, + if(WebRtcNetEQ_RecOutMasterSlave(_inst[1], payloadSlave, &payloadLenSampleSlave, _masterSlaveInfo, 0) != 0) { LogError("RecOutMasterSlave", 1); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "RecOut: NetEq, error in pulling out for slave"); // Check for errors that can be recovered from: @@ -708,15 +707,15 @@ ACMNetEQ::RecOut( } if(payloadLenSample != payloadLenSampleSlave) { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, _id, "RecOut: mismatch between the lenght of the decoded \ -audio by Master (%d samples) and Slave (%d samples).", +audio by Master (%d samples) and Slave (%d samples).", payloadLenSample, payloadLenSampleSlave); if(payloadLenSample > payloadLenSampleSlave) { - memset(&payloadSlave[payloadLenSampleSlave], 0, + memset(&payloadSlave[payloadLenSampleSlave], 0, (payloadLenSample - payloadLenSampleSlave) * sizeof(WebRtc_Word16)); - } + } } for(WebRtc_Word16 n = 0; n < payloadLenSample; n++) @@ -728,12 +727,12 @@ audio by Master (%d samples) and Slave (%d samples).", WebRtcNetEQ_GetSpeechOutputType(_inst[0], &typeMaster); WebRtcNetEQ_GetSpeechOutputType(_inst[1], &typeSlave); - if((typeMaster == kOutputNormal) || + if((typeMaster == kOutputNormal) || (typeSlave == kOutputNormal)) { type = kOutputNormal; } - else + else { type = typeMaster; } @@ -741,7 +740,7 @@ audio by Master (%d samples) and Slave (%d samples).", audioFrame._payloadDataLengthInSamples = static_cast(payloadLenSample); // NetEq always returns 10 ms of audio. - _currentSampFreqKHz = static_cast(audioFrame._payloadDataLengthInSamples) / 10.0f; + _currentSampFreqKHz = static_cast(audioFrame._payloadDataLengthInSamples) / 10.0f; audioFrame._frequencyInHz = audioFrame._payloadDataLengthInSamples * 100; if(_vadStatus) { @@ -796,7 +795,7 @@ audio by Master (%d samples) and Slave (%d samples).", { // type is kOutputVADPassive which // we don't expect to get if _vadStatus is false - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, _id, "RecOut: NetEq returned kVadPassive while _vadStatus is false."); audioFrame._vadActivity = AudioFrame::kVadUnknown; audioFrame._speechType = AudioFrame::kNormalSpeech; @@ -816,7 +815,7 @@ ACMNetEQ::AddCodec( { if (codecDef == NULL) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "ACMNetEQ::AddCodec: error, codecDef is NULL"); return -1; } @@ -834,14 +833,14 @@ ACMNetEQ::AddCodec( if(!_isInitialized[idx]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "ACMNetEQ::AddCodec: NetEq is not initialized."); return -1; } if(WebRtcNetEQ_CodecDbAdd(_inst[idx], codecDef) < 0) { LogError("CodecDB_Add", idx); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "ACMNetEQ::AddCodec: NetEq, error in adding codec"); return -1; } @@ -863,50 +862,50 @@ ACMNetEQ::RTPPack( WebRtc_Word32 idx = 0; WEBRTC_SPL_SET_BYTE(rtpPacket, (WebRtc_Word8)0x80, idx); idx++; - + WEBRTC_SPL_SET_BYTE(rtpPacket, rtpInfo.header.payloadType, idx); idx++; - + WEBRTC_SPL_SET_BYTE(rtpPacket, WEBRTC_SPL_GET_BYTE( &(rtpInfo.header.sequenceNumber), 1), idx); idx++; - + WEBRTC_SPL_SET_BYTE(rtpPacket, WEBRTC_SPL_GET_BYTE( &(rtpInfo.header.sequenceNumber), 0), idx); idx++; - + WEBRTC_SPL_SET_BYTE(rtpPacket, WEBRTC_SPL_GET_BYTE( &(rtpInfo.header.timestamp), 3), idx); idx++; - + WEBRTC_SPL_SET_BYTE(rtpPacket, WEBRTC_SPL_GET_BYTE( &(rtpInfo.header.timestamp), 2), idx); idx++; - + WEBRTC_SPL_SET_BYTE(rtpPacket, WEBRTC_SPL_GET_BYTE( &(rtpInfo.header.timestamp), 1), idx); idx++; - + WEBRTC_SPL_SET_BYTE(rtpPacket, WEBRTC_SPL_GET_BYTE( &(rtpInfo.header.timestamp), 0), idx); idx++; - + WEBRTC_SPL_SET_BYTE(rtpPacket, WEBRTC_SPL_GET_BYTE( &(rtpInfo.header.ssrc), 3), idx); idx++; - + WEBRTC_SPL_SET_BYTE(rtpPacket, WEBRTC_SPL_GET_BYTE( &(rtpInfo.header.ssrc), 2), idx); idx++; - + WEBRTC_SPL_SET_BYTE(rtpPacket, WEBRTC_SPL_GET_BYTE( &(rtpInfo.header.ssrc), 1), idx); idx++; - + WEBRTC_SPL_SET_BYTE(rtpPacket, WEBRTC_SPL_GET_BYTE( &(rtpInfo.header.ssrc), 0), idx); idx++; - + for (WebRtc_Word16 i=0; i < payloadLengthW8; i++) { WEBRTC_SPL_SET_BYTE(rtpPacket, payload[i], idx); @@ -921,7 +920,7 @@ ACMNetEQ::RTPPack( } -bool +bool ACMNetEQ::VADStatus() const { CriticalSectionScoped lock(*_netEqCritSect); @@ -938,16 +937,16 @@ ACMNetEQ::SetVADStatus( { if(!_isInitialized[idx]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "SetVADStatus: NetEq is not initialized."); return -1; } if(_vadStatus && !status) { - // We have been using VAD but we want to stop using it calling the + // We have been using VAD but we want to stop using it calling the // following function with NULL as VAD instance switches off the // post-decode VAD - if(WebRtcNetEQ_SetVADInstance(_inst[idx], NULL, + if(WebRtcNetEQ_SetVADInstance(_inst[idx], NULL, (WebRtcNetEQ_VADInitFunction) WebRtcVad_Init, (WebRtcNetEQ_VADSetmodeFunction) WebRtcVad_set_mode, (WebRtcNetEQ_VADFunction) WebRtcVad_Process) < 0) @@ -972,7 +971,7 @@ ACMNetEQ::SetVADStatus( { return -1; } - + // Set previous VAD status to PASSIVE _previousAudioActivity = AudioFrame::kVadPassive; } @@ -997,7 +996,7 @@ ACMNetEQ::SetVADMode( CriticalSectionScoped lock(*_netEqCritSect); if((mode < VADNormal) || (mode > VADVeryAggr)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "SetVADMode: NetEq error: could not set VAD mode, mode is not supported"); return -1; } @@ -1007,7 +1006,7 @@ ACMNetEQ::SetVADMode( { if(!_isInitialized[idx]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "SetVADMode: NetEq is not initialized."); return -1; } @@ -1031,7 +1030,7 @@ ACMNetEQ::FlushBuffers() { if(!_isInitialized[idx]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "FlushBuffers: NetEq is not initialized."); return -1; } @@ -1081,22 +1080,22 @@ ACMNetEQ::RemoveCodec( WebRtcNetEQDecoder codecIdx, bool isStereo) { - // sanity check + // sanity check if((codecIdx <= kDecoderReservedStart) || (codecIdx >= kDecoderReservedEnd)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "RemoveCodec: NetEq error: could not Remove Codec, codec index out of range"); return -1; } CriticalSectionScoped lock(*_netEqCritSect); if(!_isInitialized[0]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "RemoveCodec: NetEq is not initialized."); return -1; } - + if(WebRtcNetEQ_CodecDbRemove(_inst[0], codecIdx) < 0) { LogError("CodecDB_Remove", 0); @@ -1122,7 +1121,7 @@ ACMNetEQ::Delay( CriticalSectionScoped lock(*_netEqCritSect); if(!_isInitialized[0]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Delay: NetEq is not initialized."); return -1; } @@ -1147,7 +1146,7 @@ ACMNetEQ::SetBackgroundNoiseMode( { if(!_isInitialized[idx]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "SetBackgroundNoiseMode: NetEq is not initialized."); return -1; } @@ -1168,7 +1167,7 @@ ACMNetEQ::BackgroundNoiseMode( CriticalSectionScoped lock(*_netEqCritSect); if(!_isInitialized[0]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "BackgroundNoiseMode: NetEq is not initialized."); return -1; } @@ -1193,7 +1192,7 @@ ACMNetEQ::SetUniqueId( } -void +void ACMNetEQ::LogError( const WebRtc_Word8* neteqFuncName, const WebRtc_Word16 idx) const @@ -1205,8 +1204,8 @@ ACMNetEQ::LogError( strncpy(myFuncName, neteqFuncName, 49); errorName[NETEQ_ERR_MSG_LEN_BYTE - 1] = '\0'; myFuncName[49] = '\0'; - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, - "NetEq-%d Error in function %s, error-code: %d, error-string: %s", + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + "NetEq-%d Error in function %s, error-code: %d, error-string: %s", idx, myFuncName, neteqErrorCode, @@ -1242,19 +1241,19 @@ ACMNetEQ::AddSlave( // initialize the receiver, this also sets up VAD. if(InitByIdxSafe(slaveIdx) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "AddSlave: AddSlave Failed, Could not Initialize"); return -1; } - + // Allocate buffer. if(AllocatePacketBufferByIdxSafe(usedCodecs, noOfCodecs, slaveIdx) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "AddSlave: AddSlave Failed, Could not Allocate Packet Buffer"); return -1; } - + if(_masterSlaveInfo != NULL) { free(_masterSlaveInfo); @@ -1262,15 +1261,15 @@ ACMNetEQ::AddSlave( } int msInfoSize = WebRtcNetEQ_GetMasterSlaveInfoSize(); _masterSlaveInfo = malloc(msInfoSize); - + if(_masterSlaveInfo == NULL) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "AddSlave: AddSlave Failed, Could not Allocate memory for Master-Slave Info"); return -1; } - // We accept this as initialized NetEQ, the rest is to synchronize + // We accept this as initialized NetEQ, the rest is to synchronize // Slave with Master. _numSlaves = 1; _isInitialized[slaveIdx] = true; @@ -1280,14 +1279,14 @@ ACMNetEQ::AddSlave( if(WebRtcNetEQ_GetCurrentDelay(_inst[0], ¤tDelayMs) < 0) { LogError("GetCurrentDelay", 0); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "AddSlave: AddSlave Failed, Could not Get Current Delay from Master."); return -1; } if(WebRtcNetEQ_SetExtraDelay(_inst[slaveIdx], currentDelayMs) < 0) { LogError("SetExtraDelay", slaveIdx); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "AddSlave: AddSlave Failed, Could not set delay"); return -1; } @@ -1296,7 +1295,7 @@ ACMNetEQ::AddSlave( if(WebRtcNetEQ_SetAVTPlayout(_inst[slaveIdx], (_avtPlayout) ? 1 : 0) < 0) { LogError("SetAVTPlayout", slaveIdx); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "AddSlave: AddSlave Failed, Could not set AVT playout."); return -1; } @@ -1306,7 +1305,7 @@ ACMNetEQ::AddSlave( if(WebRtcNetEQ_GetBGNMode(_inst[0], ¤tMode) < 0) { LogError("GetBGNMode", 0); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "AAddSlave: AddSlave Failed, Could not Get BGN form Master."); return -1; } @@ -1314,7 +1313,7 @@ ACMNetEQ::AddSlave( if(WebRtcNetEQ_SetBGNMode(_inst[slaveIdx], (WebRtcNetEQBGNMode)currentMode) < 0) { LogError("SetBGNMode", slaveIdx); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "AddSlave: AddSlave Failed, Could not set BGN mode."); return -1; } @@ -1332,15 +1331,14 @@ ACMNetEQ::AddSlave( playoutMode = kPlayoutStreaming; break; default: - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, - "AddSlave: NetEq Error, playout mode not recognized"); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + "AddSlave: NetEq Error, playout mode not recognized"); return -1; - break; } if(WebRtcNetEQ_SetPlayoutMode(_inst[slaveIdx], playoutMode) < 0) { LogError("SetPlayoutMode", 1); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "AddSlave: AddSlave Failed, Could not Set Playout Mode."); return -1; } @@ -1365,4 +1363,3 @@ ACMNetEQ::NumSlaves() } } // namespace webrtc - diff --git a/src/modules/audio_coding/main/source/acm_neteq.h b/src/modules/audio_coding/main/source/acm_neteq.h index 0b983f8c9..da19b8d60 100644 --- a/src/modules/audio_coding/main/source/acm_neteq.h +++ b/src/modules/audio_coding/main/source/acm_neteq.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_NETEQ_H -#define ACM_NETEQ_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_NETEQ_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_NETEQ_H_ #include "audio_coding_module.h" #include "audio_coding_module_typedefs.h" @@ -69,7 +69,7 @@ public: // if out of memory. // WebRtc_Word32 Init(); - + // // RecIn() // Gives the payload to NetEQ. @@ -132,7 +132,7 @@ public: // <0 if NetEQ returned an error. // WebRtc_Word32 AllocatePacketBuffer( - WebRtcNetEQDecoder* usedCodecs, + WebRtcNetEQDecoder* usedCodecs, WebRtc_Word16 noOfCodecs); // @@ -298,9 +298,9 @@ public: // // Return value : Pointer to the decode lock. // - RWLockWrapper* DecodeLock() const - { - return _decodeLock; + RWLockWrapper* DecodeLock() const + { + return _decodeLock; } // @@ -372,13 +372,13 @@ public: void SetReceivedStereo( bool receivedStereo); - + WebRtc_UWord8 NumSlaves(); enum JB {masterJB = 0, slaveJB = 1}; WebRtc_Word16 AddSlave( - WebRtcNetEQDecoder* usedCodecs, + WebRtcNetEQDecoder* usedCodecs, WebRtc_Word16 noOfCodecs); private: @@ -426,7 +426,7 @@ private: bool _avtPlayout; AudioPlayoutMode _playoutMode; CriticalSectionWrapper* _netEqCritSect; - + WebRtcVadInst* _ptrVADInst[MAX_NUM_SLAVE_NETEQ + 1]; bool _vadStatus; @@ -443,4 +443,4 @@ private: } //namespace webrtc -#endif //ACM_NETEQ_H +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_NETEQ_H_ diff --git a/src/modules/audio_coding/main/source/acm_opus.cc b/src/modules/audio_coding/main/source/acm_opus.cc index 069175b96..8c3cbce72 100644 --- a/src/modules/audio_coding/main/source/acm_opus.cc +++ b/src/modules/audio_coding/main/source/acm_opus.cc @@ -39,7 +39,7 @@ ACMOPUS::~ACMOPUS() } -WebRtc_Word16 +WebRtc_Word16 ACMOPUS::InternalEncode( WebRtc_UWord8* /* bitStream */, WebRtc_Word16* /* bitStreamLenByte */) @@ -48,11 +48,11 @@ ACMOPUS::InternalEncode( } -WebRtc_Word16 +WebRtc_Word16 ACMOPUS::DecodeSafe( WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, - WebRtc_Word16* /* audio */, + WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16* /* audio */, WebRtc_Word16* /* audioSamples */, WebRtc_Word8* /* speechType */) { @@ -60,7 +60,7 @@ ACMOPUS::DecodeSafe( } -WebRtc_Word16 +WebRtc_Word16 ACMOPUS::InternalInitEncoder( WebRtcACMCodecParams* /* codecParams */) { @@ -68,7 +68,7 @@ ACMOPUS::InternalInitEncoder( } -WebRtc_Word16 +WebRtc_Word16 ACMOPUS::InternalInitDecoder( WebRtcACMCodecParams* /* codecParams */) { @@ -76,9 +76,9 @@ ACMOPUS::InternalInitDecoder( } -WebRtc_Word32 +WebRtc_Word32 ACMOPUS::CodecDef( - WebRtcNetEQ_CodecDef& /* codecDef */, + WebRtcNetEQ_CodecDef& /* codecDef */, const CodecInst& /* codecInst */) { return -1; @@ -92,35 +92,35 @@ ACMOPUS::CreateInstance(void) } -WebRtc_Word16 +WebRtc_Word16 ACMOPUS::InternalCreateEncoder() { return -1; } -void +void ACMOPUS::DestructEncoderSafe() { return; } -WebRtc_Word16 +WebRtc_Word16 ACMOPUS::InternalCreateDecoder() { return -1; } -void +void ACMOPUS::DestructDecoderSafe() { return; } -void +void ACMOPUS::InternalDestructEncoderInst( void* /* ptrInst */) { @@ -128,7 +128,7 @@ ACMOPUS::InternalDestructEncoderInst( } -WebRtc_Word16 +WebRtc_Word16 ACMOPUS::UnregisterFromNetEqSafe( ACMNetEQ* /* netEq */, WebRtc_Word16 /* payloadType */) @@ -136,7 +136,7 @@ ACMOPUS::UnregisterFromNetEqSafe( return -1; } -WebRtc_Word16 +WebRtc_Word16 ACMOPUS::SetBitRateSafe( const WebRtc_Word32 /*rate*/ ) { @@ -172,14 +172,14 @@ _opusMode(1), // default mode is the hybrid mode _flagVBR(0) // default VBR off { _codecID = codecID; - + // Current implementation doesn't have DTX. That might change. _hasInternalDTX = false; // Default sampling frequency _mySampFreq = 48000; - - // default rate + + // default rate _myRate = 50000; return; @@ -201,7 +201,7 @@ ACMOPUS::~ACMOPUS() } -WebRtc_Word16 +WebRtc_Word16 ACMOPUS::InternalEncode( WebRtc_UWord8* bitStream, WebRtc_Word16* bitStreamLenByte) @@ -212,14 +212,14 @@ ACMOPUS::InternalEncode( WebRtc_Word16 byteLengthFrame = 0; - // Derive what byte-length is requested + // Derive what byte-length is requested byteLengthFrame = _myRate*_frameLenSmpl/(8*_mySampFreq); // Call Encoder *bitStreamLenByte = WebRtcOpus_Encode(_encoderInstPtr, &_inAudio[_inAudioIxRead], (WebRtc_Word16*)bitStream, _frameLenSmpl, byteLengthFrame); - // increment the read index this tell the caller that how far + // increment the read index this tell the caller that how far // we have gone forward in reading the audio buffer _inAudioIxRead += _frameLenSmpl; @@ -227,8 +227,8 @@ ACMOPUS::InternalEncode( if(*bitStreamLenByte < 0) { // error has happened - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, - "InternalEncode: Encode error for Opus"); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + "InternalEncode: Encode error for Opus"); *bitStreamLenByte = 0; return -1; } @@ -238,11 +238,11 @@ ACMOPUS::InternalEncode( -WebRtc_Word16 +WebRtc_Word16 ACMOPUS::DecodeSafe( WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, - WebRtc_Word16* /* audio */, + WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16* /* audio */, WebRtc_Word16* /* audioSamples */, WebRtc_Word8* /* speechType */) { @@ -250,7 +250,7 @@ ACMOPUS::DecodeSafe( } -WebRtc_Word16 +WebRtc_Word16 ACMOPUS::InternalInitEncoder( WebRtcACMCodecParams* codecParams) { @@ -260,7 +260,7 @@ ACMOPUS::InternalInitEncoder( } -WebRtc_Word16 +WebRtc_Word16 ACMOPUS::InternalInitDecoder( WebRtcACMCodecParams* /* codecParams */) { @@ -274,7 +274,7 @@ ACMOPUS::InternalInitDecoder( } -WebRtc_Word32 +WebRtc_Word32 ACMOPUS::CodecDef( WebRtcNetEQ_CodecDef& codecDef, const CodecInst& codecInst) @@ -286,7 +286,7 @@ ACMOPUS::CodecDef( return -1; } - // Fill up the structure by calling + // Fill up the structure by calling // "SET_CODEC_PAR" & "SET_G729_FUNCTION." // Then call NetEQ to add the codec to it's // database. @@ -304,7 +304,7 @@ ACMOPUS::CreateInstance(void) } -WebRtc_Word16 +WebRtc_Word16 ACMOPUS::InternalCreateEncoder() { if (WebRtcOpus_CreateEnc(&_encoderInstPtr, _mySampFreq) < 0) @@ -317,7 +317,7 @@ ACMOPUS::InternalCreateEncoder() } -void +void ACMOPUS::DestructEncoderSafe() { _encoderExist = false; @@ -330,12 +330,12 @@ ACMOPUS::DestructEncoderSafe() } -WebRtc_Word16 +WebRtc_Word16 ACMOPUS::InternalCreateDecoder() -{ +{ if (WebRtcOpus_CreateDec(&_decoderInstPtr, _mySampFreq) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "InternalCreateDecoder: create decoder failed for Opus"); return -1; } @@ -343,7 +343,7 @@ ACMOPUS::InternalCreateDecoder() } -void +void ACMOPUS::DestructDecoderSafe() { _decoderExist = false; @@ -356,10 +356,10 @@ ACMOPUS::DestructDecoderSafe() } -void +void ACMOPUS::InternalDestructEncoderInst( void* ptrInst) -{ +{ if(ptrInst != NULL) { WebRtcOpus_FreeEnc((OPUS_inst_t*)ptrInst); @@ -368,25 +368,25 @@ ACMOPUS::InternalDestructEncoderInst( } -WebRtc_Word16 +WebRtc_Word16 ACMOPUS::UnregisterFromNetEqSafe( ACMNetEQ* netEq, WebRtc_Word16 payloadType) { if(payloadType != _decoderParams.codecInstant.pltype) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Cannot unregister codec: given payload-type does not match \ -the stored payload type", - _decoderParams.codecInstant.plname, - payloadType, +the stored payload type", + _decoderParams.codecInstant.plname, + payloadType, _decoderParams.codecInstant.pltype); return -1; } return netEq->RemoveCodec(kDecoderOpus); } -WebRtc_Word16 +WebRtc_Word16 ACMOPUS::SetBitRateSafe( const WebRtc_Word32 rate) { @@ -459,17 +459,16 @@ ACMOPUS::SetBitRateSafe( WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "SetBitRateSafe: Invalid rate Opus"); return -1; - break; } } - + // Re-init with new rate if (WebRtcOpus_EncoderInit(_encoderInstPtr, _mySampFreq, _opusMode, _flagVBR) >= 0) { _encoderParams.codecInstant.rate = _myRate; return 0; - } - else + } + else { return -1; } diff --git a/src/modules/audio_coding/main/source/acm_opus.h b/src/modules/audio_coding/main/source/acm_opus.h index 47a8a1392..278c36919 100644 --- a/src/modules/audio_coding/main/source/acm_opus.h +++ b/src/modules/audio_coding/main/source/acm_opus.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_OPUS_H -#define ACM_OPUS_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_OPUS_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_OPUS_H_ #include "acm_generic_codec.h" @@ -41,23 +41,23 @@ public: protected: WebRtc_Word16 DecodeSafe( WebRtc_UWord8* bitStream, - WebRtc_Word16 bitStreamLenByte, - WebRtc_Word16* audio, - WebRtc_Word16* audioSamples, + WebRtc_Word16 bitStreamLenByte, + WebRtc_Word16* audio, + WebRtc_Word16* audioSamples, WebRtc_Word8* speechType); WebRtc_Word32 CodecDef( - WebRtcNetEQ_CodecDef& codecDef, + WebRtcNetEQ_CodecDef& codecDef, const CodecInst& codecInst); void DestructEncoderSafe(); - + void DestructDecoderSafe(); WebRtc_Word16 InternalCreateEncoder(); - + WebRtc_Word16 InternalCreateDecoder(); - + void InternalDestructEncoderInst( void* ptrInst); @@ -80,5 +80,4 @@ protected: } // namespace webrtc -#endif // ACM_OPUS_H - +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_OPUS_H_ diff --git a/src/modules/audio_coding/main/source/acm_pcm16b.cc b/src/modules/audio_coding/main/source/acm_pcm16b.cc index 1887f5bef..5c93e9058 100644 --- a/src/modules/audio_coding/main/source/acm_pcm16b.cc +++ b/src/modules/audio_coding/main/source/acm_pcm16b.cc @@ -38,7 +38,7 @@ ACMPCM16B::~ACMPCM16B() } -WebRtc_Word16 +WebRtc_Word16 ACMPCM16B::InternalEncode( WebRtc_UWord8* /* bitStream */, WebRtc_Word16* /* bitStreamLenByte */) @@ -47,10 +47,10 @@ ACMPCM16B::InternalEncode( } -WebRtc_Word16 +WebRtc_Word16 ACMPCM16B::DecodeSafe( WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16 /* bitStreamLenByte */, WebRtc_Word16* /* audio */, WebRtc_Word16* /* audioSamples */, WebRtc_Word8* /* speechType */) @@ -59,15 +59,15 @@ ACMPCM16B::DecodeSafe( } -WebRtc_Word16 +WebRtc_Word16 ACMPCM16B::InternalInitEncoder( WebRtcACMCodecParams* /* codecParams */) { - return -1; + return -1; } -WebRtc_Word16 +WebRtc_Word16 ACMPCM16B::InternalInitDecoder( WebRtcACMCodecParams* /* codecParams */) { @@ -75,9 +75,9 @@ ACMPCM16B::InternalInitDecoder( } -WebRtc_Word32 +WebRtc_Word32 ACMPCM16B::CodecDef( - WebRtcNetEQ_CodecDef& /* codecDef */, + WebRtcNetEQ_CodecDef& /* codecDef */, const CodecInst& /* codecInst */) { return -1; @@ -91,21 +91,21 @@ ACMPCM16B::CreateInstance(void) } -WebRtc_Word16 +WebRtc_Word16 ACMPCM16B::InternalCreateEncoder() { return -1; } -WebRtc_Word16 +WebRtc_Word16 ACMPCM16B::InternalCreateDecoder() { return -1; } -void +void ACMPCM16B::InternalDestructEncoderInst( void* /* ptrInst */) { @@ -113,20 +113,20 @@ ACMPCM16B::InternalDestructEncoderInst( } -void +void ACMPCM16B::DestructEncoderSafe() { return; } -void +void ACMPCM16B::DestructDecoderSafe() { return; } -WebRtc_Word16 +WebRtc_Word16 ACMPCM16B::UnregisterFromNetEqSafe( ACMNetEQ* /* netEq */, WebRtc_Word16 /* payloadType */) @@ -153,7 +153,7 @@ ACMPCM16B::~ACMPCM16B() } -WebRtc_Word16 +WebRtc_Word16 ACMPCM16B::InternalEncode( WebRtc_UWord8* bitStream, WebRtc_Word16* bitStreamLenByte) @@ -168,10 +168,10 @@ ACMPCM16B::InternalEncode( } -WebRtc_Word16 +WebRtc_Word16 ACMPCM16B::DecodeSafe( WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16 /* bitStreamLenByte */, WebRtc_Word16* /* audio */, WebRtc_Word16* /* audioSamples */, WebRtc_Word8* /* speechType */) @@ -180,17 +180,17 @@ ACMPCM16B::DecodeSafe( } -WebRtc_Word16 +WebRtc_Word16 ACMPCM16B::InternalInitEncoder( WebRtcACMCodecParams* /* codecParams */) { // This codec does not need initialization, // PCM has no instance - return 0; + return 0; } -WebRtc_Word16 +WebRtc_Word16 ACMPCM16B::InternalInitDecoder( WebRtcACMCodecParams* /* codecParams */) { @@ -200,12 +200,12 @@ ACMPCM16B::InternalInitDecoder( } -WebRtc_Word32 +WebRtc_Word32 ACMPCM16B::CodecDef( WebRtcNetEQ_CodecDef& codecDef, const CodecInst& codecInst) { - // Fill up the structure by calling + // Fill up the structure by calling // "SET_CODEC_PAR" & "SET_PCMU_FUNCTION." // Then call NetEQ to add the codec to it's // database. @@ -248,7 +248,7 @@ ACMPCM16B::CreateInstance(void) } -WebRtc_Word16 +WebRtc_Word16 ACMPCM16B::InternalCreateEncoder() { // PCM has no instance @@ -256,7 +256,7 @@ ACMPCM16B::InternalCreateEncoder() } -WebRtc_Word16 +WebRtc_Word16 ACMPCM16B::InternalCreateDecoder() { // PCM has no instance @@ -264,7 +264,7 @@ ACMPCM16B::InternalCreateDecoder() } -void +void ACMPCM16B::InternalDestructEncoderInst( void* /* ptrInst */) { @@ -273,7 +273,7 @@ ACMPCM16B::InternalDestructEncoderInst( } -void +void ACMPCM16B::DestructEncoderSafe() { // PCM has no instance @@ -282,7 +282,7 @@ ACMPCM16B::DestructEncoderSafe() return; } -void +void ACMPCM16B::DestructDecoderSafe() { // PCM has no instance @@ -292,18 +292,18 @@ ACMPCM16B::DestructDecoderSafe() } -WebRtc_Word16 +WebRtc_Word16 ACMPCM16B::UnregisterFromNetEqSafe( ACMNetEQ* netEq, WebRtc_Word16 payloadType) { if(payloadType != _decoderParams.codecInstant.pltype) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Cannot unregister codec %s given payload-type %d does not match \ -the stored payload type", - _decoderParams.codecInstant.plname, - payloadType, +the stored payload type", + _decoderParams.codecInstant.plname, + payloadType, _decoderParams.codecInstant.pltype); return -1; } @@ -313,17 +313,14 @@ the stored payload type", case 8000: { return netEq->RemoveCodec(kDecoderPCM16B); - break; } case 16000: { return netEq->RemoveCodec(kDecoderPCM16Bwb); - break; } case 32000: { return netEq->RemoveCodec(kDecoderPCM16Bswb32kHz); - break; } default: { diff --git a/src/modules/audio_coding/main/source/acm_pcm16b.h b/src/modules/audio_coding/main/source/acm_pcm16b.h index 7f4b6916f..a81d8fed1 100644 --- a/src/modules/audio_coding/main/source/acm_pcm16b.h +++ b/src/modules/audio_coding/main/source/acm_pcm16b.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_PCM16B_H -#define ACM_PCM16B_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_PCM16B_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_PCM16B_H_ #include "acm_generic_codec.h" @@ -37,23 +37,23 @@ public: protected: WebRtc_Word16 DecodeSafe( WebRtc_UWord8* bitStream, - WebRtc_Word16 bitStreamLenByte, - WebRtc_Word16* audio, - WebRtc_Word16* audioSamples, + WebRtc_Word16 bitStreamLenByte, + WebRtc_Word16* audio, + WebRtc_Word16* audioSamples, WebRtc_Word8* speechType); WebRtc_Word32 CodecDef( - WebRtcNetEQ_CodecDef& codecDef, + WebRtcNetEQ_CodecDef& codecDef, const CodecInst& codecInst); void DestructEncoderSafe(); - + void DestructDecoderSafe(); - + WebRtc_Word16 InternalCreateEncoder(); - + WebRtc_Word16 InternalCreateDecoder(); - + WebRtc_Word16 UnregisterFromNetEqSafe( ACMNetEQ* netEq, WebRtc_Word16 payloadType); @@ -66,5 +66,4 @@ protected: } // namespace webrtc -#endif //ACM_PCM16B_H - +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_PCM16B_H_ diff --git a/src/modules/audio_coding/main/source/acm_pcma.h b/src/modules/audio_coding/main/source/acm_pcma.h index 874f471b2..db25798bd 100644 --- a/src/modules/audio_coding/main/source/acm_pcma.h +++ b/src/modules/audio_coding/main/source/acm_pcma.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_PCMA_H -#define ACM_PCMA_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_PCMA_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_PCMA_H_ #include "acm_generic_codec.h" @@ -37,13 +37,13 @@ public: protected: WebRtc_Word16 DecodeSafe( WebRtc_UWord8* bitStream, - WebRtc_Word16 bitStreamLenByte, - WebRtc_Word16* audio, - WebRtc_Word16* audioSamples, + WebRtc_Word16 bitStreamLenByte, + WebRtc_Word16* audio, + WebRtc_Word16* audioSamples, WebRtc_Word8* speechType); WebRtc_Word32 CodecDef( - WebRtcNetEQ_CodecDef& codecDef, + WebRtcNetEQ_CodecDef& codecDef, const CodecInst& codecInst); void DestructEncoderSafe(); @@ -51,9 +51,9 @@ protected: void DestructDecoderSafe(); WebRtc_Word16 InternalCreateEncoder(); - + WebRtc_Word16 InternalCreateDecoder(); - + WebRtc_Word16 UnregisterFromNetEqSafe( ACMNetEQ* netEq, WebRtc_Word16 payloadType); @@ -64,5 +64,4 @@ protected: } // namespace webrtc -#endif //ACM_PCMA_H - +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_PCMA_H_ diff --git a/src/modules/audio_coding/main/source/acm_pcmu.cc b/src/modules/audio_coding/main/source/acm_pcmu.cc index 945eaa022..320ba5b47 100644 --- a/src/modules/audio_coding/main/source/acm_pcmu.cc +++ b/src/modules/audio_coding/main/source/acm_pcmu.cc @@ -33,24 +33,24 @@ ACMPCMU::~ACMPCMU() } -WebRtc_Word16 +WebRtc_Word16 ACMPCMU::InternalEncode( WebRtc_UWord8* bitStream, WebRtc_Word16* bitStreamLenByte) { *bitStreamLenByte = WebRtcG711_EncodeU(NULL, &_inAudio[_inAudioIxRead], _frameLenSmpl*_noChannels, (WebRtc_Word16*)bitStream); - // increment the read index this tell the caller that how far + // increment the read index this tell the caller that how far // we have gone forward in reading the audio buffer _inAudioIxRead += _frameLenSmpl*_noChannels; return *bitStreamLenByte; } -WebRtc_Word16 +WebRtc_Word16 ACMPCMU::DecodeSafe( WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16 /* bitStreamLenByte */, WebRtc_Word16* /* audio */, WebRtc_Word16* /* audioSamples */, WebRtc_Word8* /* speechType */) @@ -59,17 +59,17 @@ ACMPCMU::DecodeSafe( } -WebRtc_Word16 +WebRtc_Word16 ACMPCMU::InternalInitEncoder( WebRtcACMCodecParams* /* codecParams */) { // This codec does not need initialization, // PCM has no instance - return 0; + return 0; } -WebRtc_Word16 +WebRtc_Word16 ACMPCMU::InternalInitDecoder( WebRtcACMCodecParams* /* codecParams */) { @@ -79,12 +79,12 @@ ACMPCMU::InternalInitDecoder( } -WebRtc_Word32 +WebRtc_Word32 ACMPCMU::CodecDef( WebRtcNetEQ_CodecDef& codecDef, const CodecInst& codecInst) { - // Fill up the structure by calling + // Fill up the structure by calling // "SET_CODEC_PAR" & "SET_PCMU_FUNCTION." // Then call NetEQ to add the codec to it's // database. @@ -101,7 +101,7 @@ ACMPCMU::CreateInstance(void) } -WebRtc_Word16 +WebRtc_Word16 ACMPCMU::InternalCreateEncoder() { // PCM has no instance @@ -109,7 +109,7 @@ ACMPCMU::InternalCreateEncoder() } -WebRtc_Word16 +WebRtc_Word16 ACMPCMU::InternalCreateDecoder() { // PCM has no instance @@ -117,7 +117,7 @@ ACMPCMU::InternalCreateDecoder() } -void +void ACMPCMU::InternalDestructEncoderInst( void* /* ptrInst */) { @@ -126,7 +126,7 @@ ACMPCMU::InternalDestructEncoderInst( } -void +void ACMPCMU::DestructEncoderSafe() { // PCM has no instance @@ -144,7 +144,7 @@ void ACMPCMU::DestructDecoderSafe() } -WebRtc_Word16 +WebRtc_Word16 ACMPCMU::UnregisterFromNetEqSafe( ACMNetEQ* netEq, WebRtc_Word16 payloadType) @@ -152,15 +152,15 @@ ACMPCMU::UnregisterFromNetEqSafe( if(payloadType != _decoderParams.codecInstant.pltype) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Cannot unregister codec %s given payload-type %d does not match \ -the stored payload type", - _decoderParams.codecInstant.plname, - payloadType, +the stored payload type", + _decoderParams.codecInstant.plname, + payloadType, _decoderParams.codecInstant.pltype); return -1; } - + return netEq->RemoveCodec(kDecoderPCMu); } diff --git a/src/modules/audio_coding/main/source/acm_pcmu.h b/src/modules/audio_coding/main/source/acm_pcmu.h index a4fbbadaa..2fc4223f7 100644 --- a/src/modules/audio_coding/main/source/acm_pcmu.h +++ b/src/modules/audio_coding/main/source/acm_pcmu.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_PCMU_H -#define ACM_PCMU_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_PCMU_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_PCMU_H_ #include "acm_generic_codec.h" @@ -37,23 +37,23 @@ public: protected: WebRtc_Word16 DecodeSafe( WebRtc_UWord8* bitStream, - WebRtc_Word16 bitStreamLenByte, - WebRtc_Word16* audio, - WebRtc_Word16* audioSamples, + WebRtc_Word16 bitStreamLenByte, + WebRtc_Word16* audio, + WebRtc_Word16* audioSamples, WebRtc_Word8* speechType); WebRtc_Word32 CodecDef( - WebRtcNetEQ_CodecDef& codecDef, + WebRtcNetEQ_CodecDef& codecDef, const CodecInst& codecInst); void DestructEncoderSafe(); - + void DestructDecoderSafe(); - + WebRtc_Word16 InternalCreateEncoder(); - + WebRtc_Word16 InternalCreateDecoder(); - + WebRtc_Word16 UnregisterFromNetEqSafe( ACMNetEQ* netEq, WebRtc_Word16 payloadType); @@ -64,5 +64,4 @@ protected: } // namespace webrtc -#endif //ACM_PCMU_H - +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_PCMU_H_ diff --git a/src/modules/audio_coding/main/source/acm_red.cc b/src/modules/audio_coding/main/source/acm_red.cc index edc8c7649..88dbc247d 100644 --- a/src/modules/audio_coding/main/source/acm_red.cc +++ b/src/modules/audio_coding/main/source/acm_red.cc @@ -30,7 +30,7 @@ ACMRED::~ACMRED() } -WebRtc_Word16 +WebRtc_Word16 ACMRED::InternalEncode( WebRtc_UWord8* /* bitStream */, WebRtc_Word16* /* bitStreamLenByte */) @@ -41,10 +41,10 @@ ACMRED::InternalEncode( } -WebRtc_Word16 +WebRtc_Word16 ACMRED::DecodeSafe( WebRtc_UWord8* /* bitStream */, - WebRtc_Word16 /* bitStreamLenByte */, + WebRtc_Word16 /* bitStreamLenByte */, WebRtc_Word16* /* audio */, WebRtc_Word16* /* audioSamples */, WebRtc_Word8* /* speechType */) @@ -53,17 +53,17 @@ ACMRED::DecodeSafe( } -WebRtc_Word16 +WebRtc_Word16 ACMRED::InternalInitEncoder( WebRtcACMCodecParams* /* codecParams */) { // This codec does not need initialization, // RED has no instance - return 0; + return 0; } -WebRtc_Word16 +WebRtc_Word16 ACMRED::InternalInitDecoder( WebRtcACMCodecParams* /* codecParams */) { @@ -73,7 +73,7 @@ ACMRED::InternalInitDecoder( } -WebRtc_Word32 +WebRtc_Word32 ACMRED::CodecDef( WebRtcNetEQ_CodecDef& codecDef, const CodecInst& codecInst) @@ -85,7 +85,7 @@ ACMRED::CodecDef( return -1; } - // Fill up the structure by calling + // Fill up the structure by calling // "SET_CODEC_PAR" & "SET_PCMU_FUNCTION." // Then call NetEQ to add the codec to it's // database. @@ -102,7 +102,7 @@ ACMRED::CreateInstance(void) } -WebRtc_Word16 +WebRtc_Word16 ACMRED::InternalCreateEncoder() { // RED has no instance @@ -110,7 +110,7 @@ ACMRED::InternalCreateEncoder() } -WebRtc_Word16 +WebRtc_Word16 ACMRED::InternalCreateDecoder() { // RED has no instance @@ -118,7 +118,7 @@ ACMRED::InternalCreateDecoder() } -void +void ACMRED::InternalDestructEncoderInst( void* /* ptrInst */) { @@ -127,7 +127,7 @@ ACMRED::InternalDestructEncoderInst( } -void +void ACMRED::DestructEncoderSafe() { // RED has no instance @@ -141,18 +141,18 @@ void ACMRED::DestructDecoderSafe() } -WebRtc_Word16 +WebRtc_Word16 ACMRED::UnregisterFromNetEqSafe( ACMNetEQ* netEq, WebRtc_Word16 payloadType) { if(payloadType != _decoderParams.codecInstant.pltype) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Cannot unregister codec %s given payload-type %d does not match \ -the stored payload type", - _decoderParams.codecInstant.plname, - payloadType, +the stored payload type", + _decoderParams.codecInstant.plname, + payloadType, _decoderParams.codecInstant.pltype); return -1; } diff --git a/src/modules/audio_coding/main/source/acm_red.h b/src/modules/audio_coding/main/source/acm_red.h index 5900ec684..d22cb8cde 100644 --- a/src/modules/audio_coding/main/source/acm_red.h +++ b/src/modules/audio_coding/main/source/acm_red.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_RED_H -#define ACM_RED_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_RED_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_RED_H_ #include "acm_generic_codec.h" @@ -37,23 +37,23 @@ public: protected: WebRtc_Word16 DecodeSafe( WebRtc_UWord8* bitStream, - WebRtc_Word16 bitStreamLenByte, - WebRtc_Word16* audio, - WebRtc_Word16* audioSamples, + WebRtc_Word16 bitStreamLenByte, + WebRtc_Word16* audio, + WebRtc_Word16* audioSamples, WebRtc_Word8* speechType); WebRtc_Word32 CodecDef( - WebRtcNetEQ_CodecDef& codecDef, + WebRtcNetEQ_CodecDef& codecDef, const CodecInst& codecInst); void DestructEncoderSafe(); - + void DestructDecoderSafe(); - + WebRtc_Word16 InternalCreateEncoder(); - + WebRtc_Word16 InternalCreateDecoder(); - + WebRtc_Word16 UnregisterFromNetEqSafe( ACMNetEQ* netEq, WebRtc_Word16 payloadType); @@ -64,5 +64,4 @@ protected: } // namespace webrtc -#endif //ACM_RED_H - +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_RED_H_ diff --git a/src/modules/audio_coding/main/source/acm_resampler.cc b/src/modules/audio_coding/main/source/acm_resampler.cc index 7389c1424..16db4c51f 100644 --- a/src/modules/audio_coding/main/source/acm_resampler.cc +++ b/src/modules/audio_coding/main/source/acm_resampler.cc @@ -32,15 +32,15 @@ ACMResampler::~ACMResampler() } -WebRtc_Word16 +WebRtc_Word16 ACMResampler::Resample10Msec( - const WebRtc_Word16* inAudio, - WebRtc_Word32 inFreqHz, - WebRtc_Word16* outAudio, + const WebRtc_Word16* inAudio, + WebRtc_Word32 inFreqHz, + WebRtc_Word16* outAudio, WebRtc_Word32 outFreqHz, WebRtc_UWord8 numAudioChannels) { - + CriticalSectionScoped cs(_resamplerCritSect); if(inFreqHz == outFreqHz) @@ -55,20 +55,20 @@ ACMResampler::Resample10Msec( WebRtc_Word32 ret; ResamplerType type; - type = (numAudioChannels == 1)? kResamplerSynchronous:kResamplerSynchronousStereo; - - ret = _resampler.ResetIfNeeded(inFreqHz,outFreqHz,type); + type = (numAudioChannels == 1)? kResamplerSynchronous:kResamplerSynchronousStereo; + + ret = _resampler.ResetIfNeeded(inFreqHz,outFreqHz,type); if (ret < 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, - "Error in reset of resampler"); + { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + "Error in reset of resampler"); return -1; } - + ret = _resampler.Push(inAudio, lengthIn, outAudio, maxLen, outLen); if (ret < 0 ) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Error in resampler: resampler.Push"); return -1; } @@ -79,11 +79,11 @@ ACMResampler::Resample10Msec( } -void +void ACMResampler::SetUniqueId( WebRtc_Word32 id) { - CriticalSectionScoped lock(_resamplerCritSect); + CriticalSectionScoped lock(_resamplerCritSect); _id = id; } diff --git a/src/modules/audio_coding/main/source/acm_resampler.h b/src/modules/audio_coding/main/source/acm_resampler.h index f4d5c538b..56ca5222d 100644 --- a/src/modules/audio_coding/main/source/acm_resampler.h +++ b/src/modules/audio_coding/main/source/acm_resampler.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_RESAMPLER_H -#define ACM_RESAMPLER_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_RESAMPLER_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_RESAMPLER_H_ #include "resampler.h" #include "typedefs.h" @@ -23,14 +23,14 @@ class ACMResampler public: ACMResampler(); ~ACMResampler(); - + WebRtc_Word16 Resample10Msec( const WebRtc_Word16* inAudio, const WebRtc_Word32 inFreqHz, WebRtc_Word16* outAudio, const WebRtc_Word32 outFreqHz, WebRtc_UWord8 numAudioChannels); - + void SetUniqueId( WebRtc_Word32 id); @@ -44,4 +44,4 @@ private: } // namespace webrtc -#endif //ACM_RESAMPLER_H +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_RESAMPLER_H_ diff --git a/src/modules/audio_coding/main/source/acm_speex.cc b/src/modules/audio_coding/main/source/acm_speex.cc index 0d58ab074..60ba94e7b 100644 --- a/src/modules/audio_coding/main/source/acm_speex.cc +++ b/src/modules/audio_coding/main/source/acm_speex.cc @@ -127,7 +127,7 @@ ACMSPEEX::InternalCreateEncoder() return -1; } -void +void ACMSPEEX::DestructEncoderSafe() { return; @@ -140,7 +140,7 @@ ACMSPEEX::InternalCreateDecoder() return -1; } -void +void ACMSPEEX::DestructDecoderSafe() { return; @@ -153,7 +153,7 @@ ACMSPEEX::SetBitRateSafe( return -1; } -void +void ACMSPEEX::InternalDestructEncoderInst( void* /* ptrInst */) { @@ -196,7 +196,7 @@ _encoderInstPtr(NULL), _decoderInstPtr(NULL) { _codecID = codecID; - + // Set sampling frequency, frame size and rate Speex if(_codecID == ACMCodecDB::kSPEEX8) { @@ -212,7 +212,7 @@ _decoderInstPtr(NULL) } else { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Wrong codec id for Speex."); _samplingFrequency = -1; @@ -257,14 +257,14 @@ ACMSPEEX::InternalEncode( status = WebRtcSpeex_Encode(_encoderInstPtr, &_inAudio[_inAudioIxRead], _encodingRate); - // increment the read index this tell the caller that how far + // increment the read index this tell the caller that how far // we have gone forward in reading the audio buffer _inAudioIxRead += _samplesIn20MsAudio; numEncodedSamples += _samplesIn20MsAudio; - if(status < 0) + if(status < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Error in Speex encoder"); return status; } @@ -315,7 +315,7 @@ ACMSPEEX::EnableDTX() // enable DTX if(WebRtcSpeex_EncoderInit(_encoderInstPtr, (_vbrEnabled ? 1:0), _complMode, 1) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Cannot enable DTX for Speex"); return -1; } @@ -342,7 +342,7 @@ ACMSPEEX::DisableDTX() // disable DTX if(WebRtcSpeex_EncoderInit(_encoderInstPtr, (_vbrEnabled ? 1:0), _complMode, 0) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Cannot disable DTX for Speex"); return -1; } @@ -365,7 +365,7 @@ ACMSPEEX::InternalInitEncoder( // sanity check if (_encoderInstPtr == NULL) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Cannot initialize Speex encoder, instance does not exist"); return -1; } @@ -376,7 +376,7 @@ ACMSPEEX::InternalInitEncoder( if (status >= 0) { return 0; } else { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Error in initialization of Speex encoder"); return -1; } @@ -387,20 +387,20 @@ ACMSPEEX::InternalInitDecoder( WebRtcACMCodecParams* /* codecParams */) { WebRtc_Word16 status; - + // sanity check if (_decoderInstPtr == NULL) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Cannot initialize Speex decoder, instance does not exist"); return -1; } status = ((WebRtcSpeex_DecoderInit(_decoderInstPtr) < 0)? -1:0); - + if (status >= 0) { return 0; } else { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Error in initialization of Speex decoder"); return -1; } @@ -413,12 +413,12 @@ ACMSPEEX::CodecDef( { if (!_decoderInitialized) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Error, Speex decoder is not initialized"); return -1; } - // Fill up the structure by calling + // Fill up the structure by calling // "SET_CODEC_PAR" & "SET_SPEEX_FUNCTION." // Then call NetEQ to add the codec to it's // database. @@ -439,14 +439,13 @@ ACMSPEEX::CodecDef( } default: { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Unsupported sampling frequency for Speex"); - + return -1; - break; } } - + SET_SPEEX_FUNCTIONS((codecDef)); return 0; } @@ -463,7 +462,7 @@ ACMSPEEX::InternalCreateEncoder() return WebRtcSpeex_CreateEnc(&_encoderInstPtr, _samplingFrequency); } -void +void ACMSPEEX::DestructEncoderSafe() { if(_encoderInstPtr != NULL) @@ -484,7 +483,7 @@ ACMSPEEX::InternalCreateDecoder() return WebRtcSpeex_CreateDec(&_decoderInstPtr, _samplingFrequency, 1); } -void +void ACMSPEEX::DestructDecoderSafe() { if(_decoderInstPtr != NULL) @@ -508,17 +507,17 @@ ACMSPEEX::SetBitRateSafe( _encodingRate = rate; _encoderParams.codecInstant.rate = rate; } else { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Unsupported encoding rate for Speex"); - + return -1; } - + return 0; } -void +void ACMSPEEX::InternalDestructEncoderInst( void* ptrInst) { @@ -537,11 +536,11 @@ ACMSPEEX::UnregisterFromNetEqSafe( { if(payloadType != _decoderParams.codecInstant.pltype) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Cannot unregister codec %s given payload-type %d does not match \ -the stored payload type", - _decoderParams.codecInstant.plname, - payloadType, +the stored payload type", + _decoderParams.codecInstant.plname, + payloadType, _decoderParams.codecInstant.pltype); return -1; } @@ -559,7 +558,7 @@ the stored payload type", } default: { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Could not unregister Speex from NetEQ. Sampling frequency doesn't match"); return -1; } @@ -583,9 +582,9 @@ ACMSPEEX::EnableVBR() // enable Variable Bit Rate (VBR) if(WebRtcSpeex_EncoderInit(_encoderInstPtr, 1, _complMode, (_dtxEnabled? 1:0)) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Cannot enable VBR mode for Speex"); - + return -1; } _vbrEnabled = true; @@ -612,7 +611,7 @@ ACMSPEEX::DisableVBR() // disable DTX if(WebRtcSpeex_EncoderInit(_encoderInstPtr, 0, _complMode, (_dtxEnabled? 1:0)) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Cannot disable DTX for Speex"); return -1; @@ -643,7 +642,7 @@ ACMSPEEX::SetComplMode( // Set new mode if(WebRtcSpeex_EncoderInit(_encoderInstPtr, 0, mode, (_dtxEnabled? 1:0)) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID, "Error in complexity mode for Speex"); return -1; } @@ -662,4 +661,3 @@ ACMSPEEX::SetComplMode( #endif } // namespace webrtc - diff --git a/src/modules/audio_coding/main/source/acm_speex.h b/src/modules/audio_coding/main/source/acm_speex.h index f1bed387f..7988e45b6 100644 --- a/src/modules/audio_coding/main/source/acm_speex.h +++ b/src/modules/audio_coding/main/source/acm_speex.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef ACM_SPEEX_H -#define ACM_SPEEX_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_SPEEX_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_SPEEX_H_ #include "acm_generic_codec.h" @@ -54,28 +54,28 @@ protected: void DestructDecoderSafe(); WebRtc_Word16 InternalCreateEncoder(); - + WebRtc_Word16 InternalCreateDecoder(); - + void InternalDestructEncoderInst( void* ptrInst); WebRtc_Word16 SetBitRateSafe( const WebRtc_Word32 rate); - + WebRtc_Word16 EnableDTX(); - + WebRtc_Word16 DisableDTX(); -#ifdef UNUSEDSPEEX +#ifdef UNUSEDSPEEX WebRtc_Word16 EnableVBR(); WebRtc_Word16 DisableVBR(); - + WebRtc_Word16 SetComplMode( WebRtc_Word16 mode); #endif - + WebRtc_Word16 UnregisterFromNetEqSafe( ACMNetEQ* netEq, WebRtc_Word16 payloadType); @@ -91,4 +91,4 @@ protected: } // namespace webrtc -#endif // ACM_SPEEX_H +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_SPEEX_H_ diff --git a/src/modules/audio_coding/main/source/audio_coding_module.cc b/src/modules/audio_coding/main/source/audio_coding_module.cc index 45e7761e9..9434d18c4 100644 --- a/src/modules/audio_coding/main/source/audio_coding_module.cc +++ b/src/modules/audio_coding/main/source/audio_coding_module.cc @@ -18,7 +18,7 @@ namespace webrtc { // Create module -AudioCodingModule* +AudioCodingModule* AudioCodingModule::Create( const WebRtc_Word32 id) { @@ -26,7 +26,7 @@ AudioCodingModule::Create( } // Destroy module -void +void AudioCodingModule::Destroy( AudioCodingModule* module) { @@ -34,10 +34,10 @@ AudioCodingModule::Destroy( } // Returns version of the module and its components. -WebRtc_Word32 +WebRtc_Word32 AudioCodingModule::GetVersion( WebRtc_Word8* version, - WebRtc_UWord32& remainingBufferInBytes, + WebRtc_UWord32& remainingBufferInBytes, WebRtc_UWord32& position) { WebRtc_Word32 len = position; @@ -45,7 +45,7 @@ AudioCodingModule::GetVersion( position = static_cast(strlen(version)); remainingBufferInBytes -= (position - len); - + // Get NetEQ version. if(ACMNetEQ::GetVersion(version, remainingBufferInBytes, position) < 0) @@ -72,32 +72,32 @@ AudioCodingModule::GetVersion( // Get number of supported codecs WebRtc_UWord8 AudioCodingModule::NumberOfCodecs() { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, -1, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, -1, "NumberOfCodecs()"); return static_cast(ACMCodecDB::kNumCodecs); } -// Get supported codec param with id -WebRtc_Word32 +// Get supported codec param with id +WebRtc_Word32 AudioCodingModule::Codec( const WebRtc_UWord8 listId, CodecInst& codec) { WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, -1, "Codec(const WebRtc_UWord8 listId, CodecInst& codec)"); - + // Get the codec settings for the codec with the given list ID return ACMCodecDB::Codec(listId, &codec); } -// Get supported codec Param with name -WebRtc_Word32 +// Get supported codec Param with name +WebRtc_Word32 AudioCodingModule::Codec( const WebRtc_Word8* payloadName, CodecInst& codec, const WebRtc_Word32 samplingFreqHz) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, -1, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, -1, "Codec(const WebRtc_Word8* payloadName, CodecInst& codec)"); // Search through codec list for a matching name @@ -108,7 +108,7 @@ AudioCodingModule::Codec( if(!STR_CASE_CMP(codec.plname, payloadName)) { - // If samplingFreqHz is set (!= -1), check if frequency matches + // If samplingFreqHz is set (!= -1), check if frequency matches if((samplingFreqHz == codec.plfreq) || (samplingFreqHz == -1)) { // We found a match, return OK @@ -118,7 +118,7 @@ AudioCodingModule::Codec( } // if we are here we couldn't find anything - // set the params to unacceptable values + // set the params to unacceptable values codec.plname[0] = '\0'; codec.pltype = -1; codec.pacsize = 0; @@ -133,7 +133,7 @@ AudioCodingModule::Codec( const WebRtc_Word8* payloadName, const WebRtc_Word32 samplingFreqHz) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, -1, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, -1, "Codec(const WebRtc_Word8* payloadName)"); CodecInst codec; @@ -145,10 +145,10 @@ AudioCodingModule::Codec( if(!STR_CASE_CMP(codec.plname, payloadName)) { - // If samplingFreqHz is set (!= -1), check if frequency matches + // If samplingFreqHz is set (!= -1), check if frequency matches if((samplingFreqHz == codec.plfreq) || (samplingFreqHz == -1)) { - // We found a match, return codec list number (index) + // We found a match, return codec list number (index) return codecCntr; } } @@ -159,17 +159,17 @@ AudioCodingModule::Codec( } // Checks the validity of the parameters of the given codec -bool +bool AudioCodingModule::IsCodecValid( const CodecInst& codec) { int mirrorID; char errMsg[500]; - + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, -1, "IsCodecValid(const CodecInst& codec)"); int codecNumber = ACMCodecDB::CodecNumber(&codec, &mirrorID, errMsg, 500); - + if(codecNumber < 0) { WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, -1, errMsg); diff --git a/src/modules/audio_coding/main/source/audio_coding_module_impl.cc b/src/modules/audio_coding/main/source/audio_coding_module_impl.cc index b861e92b1..a2ae11249 100644 --- a/src/modules/audio_coding/main/source/audio_coding_module_impl.cc +++ b/src/modules/audio_coding/main/source/audio_coding_module_impl.cc @@ -32,9 +32,9 @@ #include #define LOGWITHTIME(logString) \ sprintf(message, logString, _id); \ - _trace.TimedLogg(message); + _trace.TimedLogg(message); #else - #define LOGWITHTIME(logString) + #define LOGWITHTIME(logString) #endif namespace webrtc @@ -123,7 +123,7 @@ AudioCodingModuleImpl::AudioCodingModuleImpl( if(InitializeReceiverSafe() < 0 ) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Cannot initialize reciever"); } #ifdef TIMED_LOGGING @@ -133,28 +133,28 @@ AudioCodingModuleImpl::AudioCodingModuleImpl( #ifdef ACM_QA_TEST char fileName[500]; sprintf(fileName, "ACM_QA_incomingPL_%03d_%d%d%d%d%d%d.dat", - _id, - rand() % 10, - rand() % 10, - rand() % 10, - rand() % 10, - rand() % 10, + _id, + rand() % 10, + rand() % 10, + rand() % 10, + rand() % 10, + rand() % 10, rand() % 10); _incomingPL = fopen(fileName, "wb"); sprintf(fileName, "ACM_QA_outgoingPL_%03d_%d%d%d%d%d%d.dat", - _id, - rand() % 10, - rand() % 10, - rand() % 10, - rand() % 10, - rand() % 10, + _id, + rand() % 10, + rand() % 10, + rand() % 10, + rand() % 10, + rand() % 10, rand() % 10); _outgoingPL = fopen(fileName, "wb"); #endif - WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceAudioCoding, id, "Created"); + WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceAudioCoding, id, "Created"); } AudioCodingModuleImpl::~AudioCodingModuleImpl() @@ -211,14 +211,14 @@ AudioCodingModuleImpl::~AudioCodingModuleImpl() _fragmentation = NULL; } } - - + + #ifdef ACM_QA_TEST if(_incomingPL != NULL) { fclose(_incomingPL); } - + if(_outgoingPL != NULL) { fclose(_outgoingPL); @@ -230,15 +230,15 @@ AudioCodingModuleImpl::~AudioCodingModuleImpl() delete _acmCritSect; _acmCritSect = NULL; - WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceAudioCoding, _id, "Destroyed"); + WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceAudioCoding, _id, "Destroyed"); } -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::ChangeUniqueId( const WebRtc_Word32 id) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, - "ChangeUniqueId(new id:%d)", id); + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + "ChangeUniqueId(new id:%d)", id); { CriticalSectionScoped lock(*_acmCritSect); _id = id; @@ -247,7 +247,7 @@ AudioCodingModuleImpl::ChangeUniqueId( { fclose(_incomingPL); } - + if(_outgoingPL != NULL) { fclose(_outgoingPL); @@ -255,23 +255,23 @@ AudioCodingModuleImpl::ChangeUniqueId( char fileName[500]; sprintf(fileName, "ACM_QA_incomingPL_%03d_%d%d%d%d%d%d.dat", - _id, - rand() % 10, - rand() % 10, - rand() % 10, - rand() % 10, - rand() % 10, + _id, + rand() % 10, + rand() % 10, + rand() % 10, + rand() % 10, + rand() % 10, rand() % 10); _incomingPL = fopen(fileName, "wb"); sprintf(fileName, "ACM_QA_outgoingPL_%03d_%d%d%d%d%d%d.dat", - _id, - rand() % 10, - rand() % 10, - rand() % 10, - rand() % 10, - rand() % 10, + _id, + rand() % 10, + rand() % 10, + rand() % 10, + rand() % 10, + rand() % 10, rand() % 10); _outgoingPL = fopen(fileName, "wb"); #endif @@ -284,40 +284,40 @@ AudioCodingModuleImpl::ChangeUniqueId( } } } - + _netEq.SetUniqueId(_id); return 0; } -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::Version( WebRtc_Word8* version, - WebRtc_UWord32& remainingBufferInBytes, + WebRtc_UWord32& remainingBufferInBytes, WebRtc_UWord32& position) const { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, - "Version()"); + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + "Version()"); if(version == NULL) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Input buffer is NULL"); return -1; } return GetVersion(version, remainingBufferInBytes, position); } -// returns the number of milliseconds until the module want a +// returns the number of milliseconds until the module want a // worker thread to call Process -WebRtc_Word32 -AudioCodingModuleImpl::TimeUntilNextProcess() +WebRtc_Word32 +AudioCodingModuleImpl::TimeUntilNextProcess() { CriticalSectionScoped lock(*_acmCritSect); if(!HaveValidEncoder("TimeUntilNextProcess")) - { + { return -1; } - return _codecs[_currentSendCodecIdx]->SamplesLeftToEncode() / + return _codecs[_currentSendCodecIdx]->SamplesLeftToEncode() / (_sendCodecInst.plfreq / 1000); } @@ -401,7 +401,7 @@ AudioCodingModuleImpl::Process() default: { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Process(): Wrong Encoding-Type"); return -1; } @@ -410,7 +410,7 @@ AudioCodingModuleImpl::Process() _previousPayloadType = currentPayloadType; // Redundancy encode is done here, - // the two bitstreams packetized into + // the two bitstreams packetized into // one RTP packet and the fragmentation points // are set. // Only apply RED on speech data. @@ -555,12 +555,12 @@ AudioCodingModuleImpl::Process() // Sender // -// Initialize send codec -WebRtc_Word32 +// Initialize send codec +WebRtc_Word32 AudioCodingModuleImpl::InitializeSender() { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, - "InitializeSender()"); + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + "InitializeSender()"); CriticalSectionScoped lock(*_acmCritSect); @@ -598,11 +598,11 @@ AudioCodingModuleImpl::InitializeSender() return 0; } -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::ResetEncoder() { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, - "ResetEncoder()"); + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + "ResetEncoder()"); CriticalSectionScoped lock(*_acmCritSect); if(!HaveValidEncoder("ResetEncoder")) @@ -612,13 +612,13 @@ AudioCodingModuleImpl::ResetEncoder() return _codecs[_currentSendCodecIdx]->ResetEncoder(); } -void +void AudioCodingModuleImpl::UnregisterSendCodec() { CriticalSectionScoped lock(*_acmCritSect); _sendCodecRegistered = false; _currentSendCodecIdx = -1; // invalid value - + return; } @@ -626,8 +626,8 @@ ACMGenericCodec* AudioCodingModuleImpl::CreateCodec( const CodecInst& codec) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, - "CreateCodec()"); + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + "CreateCodec()"); ACMGenericCodec* myCodec = NULL; @@ -637,7 +637,7 @@ AudioCodingModuleImpl::CreateCodec( // Error, could not create the codec // logging error - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "ACMCodecDB::CreateCodecInstance() failed in \ CreateCodec()"); return myCodec; @@ -649,11 +649,11 @@ CreateCodec()"); } // can be called multiple times for Codec, CNG, RED -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::RegisterSendCodec( const CodecInst& sendCodec) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "Registering Send Codec"); if((sendCodec.channels != 1) && (sendCodec.channels != 2)) @@ -686,7 +686,7 @@ mono codecs are supported, i.e. channels=1.", sendCodec.channels); // telephone-event cannot be a send codec if(!STR_CASE_CMP(sendCodec.plname, "telephone-event")) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "telephone-event cannot be registered as send codec"); return -1; } @@ -698,8 +698,8 @@ mono codecs are supported, i.e. channels=1.", sendCodec.channels); // Check if the payload-type is valid if(!ACMCodecDB::ValidPayloadType(sendCodec.pltype)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, - "Invalid payload-type %d for %s.", + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + "Invalid payload-type %d for %s.", sendCodec.pltype, sendCodec.plname); return -1; } @@ -708,12 +708,12 @@ mono codecs are supported, i.e. channels=1.", sendCodec.channels); return 0; } - // CNG can be registered with other payload type. If not registered the + // CNG can be registered with other payload type. If not registered the // default payload types will be used: CNNB=13 (fixed), CNWB=97, CNSWB=98 - if(!STR_CASE_CMP(sendCodec.plname, "CN")) + if(!STR_CASE_CMP(sendCodec.plname, "CN")) { // CNG is registered - + switch(sendCodec.plfreq) { case 8000: @@ -733,20 +733,20 @@ mono codecs are supported, i.e. channels=1.", sendCodec.channels); } default : { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "RegisterSendCodec() failed, invalid frequency for CNG registeration"); return -1; } } - + return 0; } // Check if the payload-type is valid if(!ACMCodecDB::ValidPayloadType(sendCodec.pltype)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, - "Invalid payload-type %d for %s.", + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + "Invalid payload-type %d for %s.", sendCodec.pltype, sendCodec.plname); return -1; } @@ -754,8 +754,8 @@ mono codecs are supported, i.e. channels=1.", sendCodec.channels); // Check if codec supports the number of channels if(ACMCodecDB::codec_settings_[codecID].channel_support < sendCodec.channels) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, - "%d number of channels not supportedn for %s.", + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + "%d number of channels not supportedn for %s.", sendCodec.channels, sendCodec.plname); return -1; } @@ -790,7 +790,7 @@ mono codecs are supported, i.e. channels=1.", sendCodec.channels); _codecs[mirrorId] = CreateCodec(sendCodec); if(_codecs[mirrorId] == NULL) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Cannot Create the codec"); return -1; } @@ -807,44 +807,44 @@ mono codecs are supported, i.e. channels=1.", sendCodec.channels); WebRtc_Word16 status; WebRtcACMCodecParams codecParams; - memcpy(&(codecParams.codecInstant), &sendCodec, + memcpy(&(codecParams.codecInstant), &sendCodec, sizeof(CodecInst)); codecParams.enableVAD = _vadEnabled; codecParams.enableDTX = _dtxEnabled; codecParams.vadMode = _vadMode; // force initialization - status = tmpCodecPtr->InitEncoder(&codecParams, true); - + status = tmpCodecPtr->InitEncoder(&codecParams, true); + // Check if VAD was turned on, or if error is reported if (status == 1) { _vadEnabled = true; } else if (status < 0) { - // could not initialize the encoder + // could not initialize the encoder // Check if already have a registered codec // Depending on that differet messages are logged if(!_sendCodecRegistered) { _currentSendCodecIdx = -1; // invalid value - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Cannot Initialize the encoder No Encoder is registered"); } else { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Cannot Initialize the encoder, continue encoding \ with the previously registered codec"); } return -1; - } + } - // Everything is fine so we can replace the previous codec + // Everything is fine so we can replace the previous codec // with this one if(_sendCodecRegistered) { // If we change codec we start fresh with FEC. - // This is not strictly required by the standard. + // This is not strictly required by the standard. _isFirstRED = true; if(tmpCodecPtr->SetVAD(_dtxEnabled, _vadEnabled, _vadMode) < 0){ @@ -882,11 +882,11 @@ with the previously registered codec"); // successfully. if(!ACMCodecDB::ValidPayloadType(sendCodec.pltype)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Out of range payload type"); return -1; } - + } // If there is a codec that ONE instance of codec supports multiple @@ -911,16 +911,16 @@ with the previously registered codec"); { WebRtcACMCodecParams codecParams; - memcpy(&(codecParams.codecInstant), &sendCodec, + memcpy(&(codecParams.codecInstant), &sendCodec, sizeof(CodecInst)); codecParams.enableVAD = _vadEnabled; codecParams.enableDTX = _dtxEnabled; codecParams.vadMode = _vadMode; - + // force initialization if(_codecs[_currentSendCodecIdx]->InitEncoder(&codecParams, true) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Could not change the codec packet-size."); return -1; } @@ -938,7 +938,7 @@ with the previously registered codec"); { if(_codecs[codecID]->SetBitRate(sendCodec.rate) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Could not change the codec rate."); return -1; } @@ -951,92 +951,92 @@ with the previously registered codec"); } // get current send codec -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::SendCodec( CodecInst& currentSendCodec) const { - WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, _id, "SendCodec()"); CriticalSectionScoped lock(*_acmCritSect); - + if(!_sendCodecRegistered) { - WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, _id, "SendCodec Failed, no codec is registered"); - + return -1; } WebRtcACMCodecParams encoderParam; _codecs[_currentSendCodecIdx]->EncoderParams(&encoderParam); encoderParam.codecInstant.pltype = _sendCodecInst.pltype; - memcpy(¤tSendCodec, &(encoderParam.codecInstant), + memcpy(¤tSendCodec, &(encoderParam.codecInstant), sizeof(CodecInst)); - + return 0; } // get current send freq -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::SendFrequency() const { - WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, _id, "SendFrequency()"); CriticalSectionScoped lock(*_acmCritSect); - + if(!_sendCodecRegistered) { - WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, _id, "SendFrequency Failed, no codec is registered"); - + return -1; } - + return _sendCodecInst.plfreq; } // Get encode bitrate // Adaptive rate codecs return their current encode target rate, while other codecs // return there longterm avarage or their fixed rate. -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::SendBitrate() const { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "SendBitrate()"); CriticalSectionScoped lock(*_acmCritSect); - + if(!_sendCodecRegistered) { - WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, _id, "SendBitrate Failed, no codec is registered"); - + return -1; } - + WebRtcACMCodecParams encoderParam; _codecs[_currentSendCodecIdx]->EncoderParams(&encoderParam); - + return encoderParam.codecInstant.rate; } // set available bandwidth, inform the encoder about the estimated bandwidth // received from the remote party -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::SetReceivedEstimatedBandwidth( const WebRtc_Word32 bw ) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "SetReceivedEstimatedBandwidth()"); return _codecs[_currentSendCodecIdx]->SetEstimatedBandwidth(bw); } // register a transport callback wich will be called to deliver // the encoded buffers -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::RegisterTransportCallback( AudioPacketizationCallback* transport) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "RegisterTransportCallback()"); CriticalSectionScoped lock(*_callbackCritSect); _packetizationCallback = transport; @@ -1045,13 +1045,13 @@ AudioCodingModuleImpl::RegisterTransportCallback( // Used by the module to deliver messages to the codec module/appliation // AVT(DTMF) -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::RegisterIncomingMessagesCallback( #ifndef WEBRTC_DTMF_DETECTION AudioCodingFeedback* /* incomingMessagesCallback */, const ACMCountries /* cpt */) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "RegisterIncomingMessagesCallback()"); return -1; #else @@ -1100,10 +1100,10 @@ AudioCodingModuleImpl::RegisterIncomingMessagesCallback( delete _dtmfDetector; _dtmfDetector = NULL; } - } + } } } - // check if we failed in setting up the DTMF-detector class + // check if we failed in setting up the DTMF-detector class if((status < 0)) { // we failed, we cannot have the callback @@ -1116,8 +1116,8 @@ AudioCodingModuleImpl::RegisterIncomingMessagesCallback( } -// Add 10MS of raw (PCM) audio data to the encoder -WebRtc_Word32 +// Add 10MS of raw (PCM) audio data to the encoder +WebRtc_Word32 AudioCodingModuleImpl::Add10MsData( const AudioFrame& audioFrame) { @@ -1131,28 +1131,28 @@ AudioCodingModuleImpl::Add10MsData( if(audioFrame._payloadDataLengthInSamples == 0) { assert(false); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Cannot Add 10 ms audio, payload length is zero"); return -1; } // Allow for 8, 16, 32 and 48kHz input audio - if((audioFrame._frequencyInHz != 8000) && - (audioFrame._frequencyInHz != 16000) && - (audioFrame._frequencyInHz != 32000) && + if((audioFrame._frequencyInHz != 8000) && + (audioFrame._frequencyInHz != 16000) && + (audioFrame._frequencyInHz != 32000) && (audioFrame._frequencyInHz != 48000)) { assert(false); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Cannot Add 10 ms audio, input frequency not valid"); return -1; } - + // If the length and frequency matches. We currently just support raw PCM - if((audioFrame._frequencyInHz/ 100) != + if((audioFrame._frequencyInHz/ 100) != audioFrame._payloadDataLengthInSamples) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Cannot Add 10 ms audio, input frequency and length doesn't \ match"); return -1; @@ -1160,8 +1160,8 @@ match"); // Calculate the timestamp that should be pushed to codec. // This might be different from the timestamp of the frame - // due to re-sampling - bool resamplingRequired = + // due to re-sampling + bool resamplingRequired = ((WebRtc_Word32)audioFrame._frequencyInHz != _sendCodecInst.plfreq); WebRtc_UWord32 currentTimestamp; @@ -1185,27 +1185,27 @@ match"); { diffInputTimestamp = audioFrame._timeStamp - _lastInTimestamp; } - currentTimestamp = _lastTimestamp + (WebRtc_UWord32)(diffInputTimestamp * + currentTimestamp = _lastTimestamp + (WebRtc_UWord32)(diffInputTimestamp * ((double)_sendCodecInst.plfreq / (double)audioFrame._frequencyInHz)); newLengthSmpl = _inputResampler.Resample10Msec( - audioFrame._payloadData, audioFrame._frequencyInHz, + audioFrame._payloadData, audioFrame._frequencyInHz, resampledAudio, sendPlFreq, _sendCodecInst.channels); if(newLengthSmpl < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Cannot add 10 ms audio, resmapling failed"); return -1; } - status = _codecs[_currentSendCodecIdx]->Add10MsData(currentTimestamp, + status = _codecs[_currentSendCodecIdx]->Add10MsData(currentTimestamp, resampledAudio, newLengthSmpl, audioFrame._audioChannel); } else { currentTimestamp = audioFrame._timeStamp; - status = _codecs[_currentSendCodecIdx]->Add10MsData(currentTimestamp, + status = _codecs[_currentSendCodecIdx]->Add10MsData(currentTimestamp, audioFrame._payloadData, audioFrame._payloadDataLengthInSamples, audioFrame._audioChannel); } @@ -1218,22 +1218,22 @@ match"); // (FEC) Forward Error Correction // -bool +bool AudioCodingModuleImpl::FECStatus() const { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "FECStatus()"); CriticalSectionScoped lock(*_acmCritSect); return _fecEnabled; } // configure FEC status i.e on/off -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::SetFECStatus( #ifdef WEBRTC_CODEC_RED const bool enableFEC) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "SetFECStatus()"); CriticalSectionScoped lock(*_acmCritSect); @@ -1241,13 +1241,13 @@ AudioCodingModuleImpl::SetFECStatus( { // Reset the RED buffer memset(_redBuffer, 0, MAX_PAYLOAD_SIZE_BYTE); - + // Reset fragmentation buffers _fragmentation->fragmentationVectorSize = 2; _fragmentation->fragmentationOffset[0] = 0; _fragmentation->fragmentationOffset[1] = MAX_PAYLOAD_SIZE_BYTE; - memset(_fragmentation->fragmentationLength, 0, sizeof(WebRtc_UWord32) * 2); - memset(_fragmentation->fragmentationTimeDiff, 0, sizeof(WebRtc_UWord16) * 2); + memset(_fragmentation->fragmentationLength, 0, sizeof(WebRtc_UWord32) * 2); + memset(_fragmentation->fragmentationTimeDiff, 0, sizeof(WebRtc_UWord16) * 2); memset(_fragmentation->fragmentationPlType, 0, sizeof(WebRtc_UWord8) * 2); // set _fecEnabled @@ -1270,13 +1270,13 @@ AudioCodingModuleImpl::SetFECStatus( // (VAD) Voice Activity Detection // -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::SetVAD( const bool enableDTX, const bool enableVAD, const ACMVADMode vadMode) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "SetVAD()"); CriticalSectionScoped lock(*_acmCritSect); @@ -1286,12 +1286,12 @@ AudioCodingModuleImpl::SetVAD( (vadMode != VADAggr) && (vadMode != VADVeryAggr)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Invalid VAD Mode %d, no change is made to VAD/DTX status", (int)vadMode); return -1; } - + // If a send codec is registered, set VAD/DTX for the codec if(HaveValidEncoder("SetVAD")) { WebRtc_Word16 status = @@ -1305,7 +1305,7 @@ AudioCodingModuleImpl::SetVAD( return 0; } else if (status < 0) { // SetVAD failed - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "SetVAD failed"); _vadEnabled = false; @@ -1314,24 +1314,24 @@ AudioCodingModuleImpl::SetVAD( return -1; } } - + _vadEnabled = enableVAD; _dtxEnabled = enableDTX; _vadMode = vadMode; - + return 0; } -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::VAD( bool& dtxEnabled, bool& vadEnabled, ACMVADMode& vadMode) const { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "VAD()"); CriticalSectionScoped lock(*_acmCritSect); - + dtxEnabled = _dtxEnabled; vadEnabled = _vadEnabled; vadMode = _vadMode; @@ -1343,7 +1343,7 @@ AudioCodingModuleImpl::VAD( // Receiver // -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::InitializeReceiver() { CriticalSectionScoped lock(*_acmCritSect); @@ -1351,13 +1351,13 @@ AudioCodingModuleImpl::InitializeReceiver() } // Initialize receiver, resets codec database etc -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::InitializeReceiverSafe() { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "InitializeReceiver()"); - // If the receiver is already initialized then we + // If the receiver is already initialized then we // also like to destruct decoders if any exist. After a call // to this function, we should have a clean start-up. if(_receiverInitialized) @@ -1366,15 +1366,15 @@ AudioCodingModuleImpl::InitializeReceiverSafe() { if(UnregisterReceiveCodecSafe(codecCntr) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, - "InitializeReceiver() failed, Could not unregister codec"); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + "InitializeReceiver() failed, Could not unregister codec"); return -1; } } } if (_netEq.Init() != 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "InitializeReceiver() failed, Could not initialize NetEQ"); return -1; } @@ -1382,7 +1382,7 @@ AudioCodingModuleImpl::InitializeReceiverSafe() if (_netEq.AllocatePacketBuffer(ACMCodecDB::NetEQDecoders(), ACMCodecDB::kNumCodecs) != 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "NetEQ cannot allocatePacket Buffer"); return -1; } @@ -1400,7 +1400,7 @@ AudioCodingModuleImpl::InitializeReceiverSafe() if(RegisterRecCodecMSSafe(ACMCodecDB::database_[i], i, i, ACMNetEQ::masterJB) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Cannot register master codec."); return -1; } @@ -1414,20 +1414,20 @@ AudioCodingModuleImpl::InitializeReceiverSafe() } // Reset the decoder state -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::ResetDecoder() { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "ResetDecoder()"); CriticalSectionScoped lock(*_acmCritSect); - + for(int codecCntr = 0; codecCntr < ACMCodecDB::kMaxNumCodecs; codecCntr++) { if((_codecs[codecCntr] != NULL) && (_registeredPlTypes[codecCntr] != -1)) { if(_codecs[codecCntr]->ResetDecoder(_registeredPlTypes[codecCntr]) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "ResetDecoder failed:"); return -1; } @@ -1437,16 +1437,16 @@ AudioCodingModuleImpl::ResetDecoder() } // get current receive freq -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::ReceiveFrequency() const { - WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, _id, "ReceiveFrequency()"); WebRtcACMCodecParams codecParams; - + CriticalSectionScoped lock(*_acmCritSect); if(DecoderParamByPlType(_lastRecvAudioCodecPlType, codecParams) < 0) - { + { return _netEq.CurrentSampFreqHz(); } else @@ -1456,32 +1456,32 @@ AudioCodingModuleImpl::ReceiveFrequency() const } // get current playout freq -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::PlayoutFrequency() const { - WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, _id, "PlayoutFrequency()"); - + CriticalSectionScoped lock(*_acmCritSect); return _netEq.CurrentSampFreqHz(); } -// register possible reveive codecs, can be called multiple times, +// register possible reveive codecs, can be called multiple times, // for codecs, CNG (NB, WB and SWB), DTMF, RED -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::RegisterReceiveCodec( const CodecInst& receiveCodec) { CriticalSectionScoped lock(*_acmCritSect); - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "RegisterReceiveCodec()"); if(receiveCodec.channels > 2) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "More than 2 audio channel is not supported."); return -1; } @@ -1491,15 +1491,15 @@ AudioCodingModuleImpl::RegisterReceiveCodec( if(codecId < 0 || codecId >= ACMCodecDB::kNumCodecs) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Wrong codec params to be registered as receive codec"); return -1; } // Check if the payload-type is valid. if(!ACMCodecDB::ValidPayloadType(receiveCodec.pltype)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, - "Invalid payload-type %d for %s.", + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + "Invalid payload-type %d for %s.", receiveCodec.pltype, receiveCodec.plname); return -1; } @@ -1508,7 +1508,7 @@ AudioCodingModuleImpl::RegisterReceiveCodec( { if(InitializeReceiverSafe() < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Cannot initialize reciver, so failed registering a codec."); return -1; } @@ -1519,7 +1519,7 @@ AudioCodingModuleImpl::RegisterReceiveCodec( { if(UnregisterReceiveCodecSafe(codecId) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Cannot register master codec."); return -1; } @@ -1528,11 +1528,11 @@ AudioCodingModuleImpl::RegisterReceiveCodec( if(RegisterRecCodecMSSafe(receiveCodec, codecId, mirrorId, ACMNetEQ::masterJB) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Cannot register master codec."); return -1; } - + // If receive stereo, make sure we have two instances of NetEQ, one for each channel if(receiveCodec.channels == 2) @@ -1542,21 +1542,21 @@ AudioCodingModuleImpl::RegisterReceiveCodec( if(_netEq.AddSlave(ACMCodecDB::NetEQDecoders(), ACMCodecDB::kNumCodecs) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Cannot Add Slave jitter buffer to NetEQ."); return -1; } } - if(RegisterRecCodecMSSafe(receiveCodec, codecId, mirrorId, + if(RegisterRecCodecMSSafe(receiveCodec, codecId, mirrorId, ACMNetEQ::slaveJB) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Cannot register slave codec."); return -1; } - if((_stereoReceive[codecId] == false) && + if((_stereoReceive[codecId] == false) && (_lastRecvAudioCodecPlType == receiveCodec.pltype)) { _lastRecvAudioCodecPlType = -1; @@ -1579,14 +1579,14 @@ AudioCodingModuleImpl::RegisterReceiveCodec( -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::RegisterRecCodecMSSafe( const CodecInst& receiveCodec, WebRtc_Word16 codecId, WebRtc_Word16 mirrorId, ACMNetEQ::JB jitterBuffer) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "RegisterReceiveCodecMSSafe()"); ACMGenericCodec** codecArray; @@ -1600,7 +1600,7 @@ AudioCodingModuleImpl::RegisterRecCodecMSSafe( } else { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "RegisterReceiveCodecMSSafe failed, jitterBuffer is neither master or slave "); return -1; } @@ -1610,7 +1610,7 @@ AudioCodingModuleImpl::RegisterRecCodecMSSafe( codecArray[mirrorId] = CreateCodec(receiveCodec); if(codecArray[mirrorId] == NULL) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Cannot create codec to register as receive codec"); return -1; } @@ -1627,7 +1627,7 @@ AudioCodingModuleImpl::RegisterRecCodecMSSafe( WebRtc_Word16 status = 0; bool registerInNetEq = true; WebRtcACMCodecParams codecParams; - memcpy(&(codecParams.codecInstant), &receiveCodec, + memcpy(&(codecParams.codecInstant), &receiveCodec, sizeof(CodecInst)); codecParams.enableVAD = false; codecParams.enableDTX = false; @@ -1635,14 +1635,14 @@ AudioCodingModuleImpl::RegisterRecCodecMSSafe( if (!codecArray[codecId]->DecoderInitialized()) { // force initialization - status = codecArray[codecId]->InitDecoder(&codecParams, true); + status = codecArray[codecId]->InitDecoder(&codecParams, true); if(status < 0) { // could not initialize the decoder we don't want to // continue if we could not initialize properly. - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "could not initialize the receive codec, codec not registered"); - + return -1; } } @@ -1658,12 +1658,12 @@ AudioCodingModuleImpl::RegisterRecCodecMSSafe( if(codecArray[codecId]->RegisterInNetEq(&_netEq, receiveCodec) != 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Receive codec could not be registered in NetEQ"); - + return -1; } - // Guaranty that the same payload-type that is + // Guaranty that the same payload-type that is // registered in NetEQ is stored in the codec. codecArray[codecId]->SaveDecoderParam(&codecParams); } @@ -1674,22 +1674,22 @@ AudioCodingModuleImpl::RegisterRecCodecMSSafe( // Get current received codec -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::ReceiveCodec( CodecInst& currentReceiveCodec) const { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "ReceiveCodec()"); WebRtcACMCodecParams decoderParam; CriticalSectionScoped lock(*_acmCritSect); - + for(int decCntr = 0; decCntr < ACMCodecDB::kMaxNumCodecs; decCntr++) { if(_codecs[decCntr] != NULL) { if(_codecs[decCntr]->DecoderInitialized()) { - if(_codecs[decCntr]->DecoderParams(&decoderParam, + if(_codecs[decCntr]->DecoderParams(&decoderParam, _lastRecvAudioCodecPlType)) { memcpy(¤tReceiveCodec, &decoderParam.codecInstant, @@ -1699,7 +1699,7 @@ AudioCodingModuleImpl::ReceiveCodec( } } } - + // if we are here then we haven't found any codec // set codec pltype to -1 to indicate that the structure // is invalid and return -1. @@ -1708,7 +1708,7 @@ AudioCodingModuleImpl::ReceiveCodec( } // Incoming packet from network parsed and ready for decode -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::IncomingPacket( const WebRtc_Word8* incomingPayload, const WebRtc_Word32 payloadLength, @@ -1718,12 +1718,12 @@ AudioCodingModuleImpl::IncomingPacket( if (payloadLength < 0) { // Log error - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "IncomingPacket() Error, payload-length cannot be negative"); return -1; } { - // store the payload Type. this will be used to retrieve "received codec" + // store the payload Type. this will be used to retrieve "received codec" // and "received frequency." CriticalSectionScoped lock(*_acmCritSect); #ifdef ACM_QA_TEST @@ -1763,8 +1763,8 @@ AudioCodingModuleImpl::IncomingPacket( // SWB payloads. If payload is changed there might be a need to reset // sampling rate of decoder. depending what we have received "now". // TODO (tlegrand): Change or remove the following comment - // I cannot use the function that BV has written, i.e. - // "DecoderParamByPlType()" as for iSAC there is one instance and + // I cannot use the function that BV has written, i.e. + // "DecoderParamByPlType()" as for iSAC there is one instance and // multiple payloads. for(int i = 0; i < ACMCodecDB::kMaxNumCodecs; i++) { @@ -1772,9 +1772,9 @@ AudioCodingModuleImpl::IncomingPacket( { if(_codecs[i] == NULL) { - // we found a payload type but the corresponding + // we found a payload type but the corresponding // codec is NULL this should not happen - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "IncomingPacket() Error, payload type found but corresponding " "codec is NULL"); return -1; @@ -1793,15 +1793,15 @@ AudioCodingModuleImpl::IncomingPacket( } // Minimum playout delay (Used for lip-sync) -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::SetMinimumPlayoutDelay( const WebRtc_Word32 timeMs) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "SetMinimumPlayoutDelay()"); if((timeMs < 0) || (timeMs > 1000)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Delay must be in the range of 0-1000 milliseconds."); return -1; } @@ -1809,21 +1809,21 @@ AudioCodingModuleImpl::SetMinimumPlayoutDelay( } // current play out delay -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::Delay( WebRtc_UWord16& delayMs) const { // NetEQ will get an API for this later. - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "Delay()"); return _netEq.Delay(delayMs); } // Get Dtmf playout status -bool +bool AudioCodingModuleImpl::DtmfPlayoutStatus() const { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "DtmfPlayoutStatus()"); #ifndef WEBRTC_CODEC_AVT return false; @@ -1834,18 +1834,18 @@ AudioCodingModuleImpl::DtmfPlayoutStatus() const // configure Dtmf playout status i.e on/off // playout the incoming outband Dtmf tone -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::SetDtmfPlayoutStatus( #ifndef WEBRTC_CODEC_AVT const bool /* enable */) { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, _id, "SetDtmfPlayoutStatus() failed: AVT is not supported."); return -1; #else const bool enable) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "SetDtmfPlayoutStatus()"); return _netEq.SetAVTPlayout(enable); #endif @@ -1853,11 +1853,11 @@ AudioCodingModuleImpl::SetDtmfPlayoutStatus( // Estimate the Bandwidth based on the incoming stream // This is also done in the RTP module -// need this for one way audio where the RTCP send the BW estimate -WebRtc_Word32 -AudioCodingModuleImpl::DecoderEstimatedBandwidth() const +// need this for one way audio where the RTCP send the BW estimate +WebRtc_Word32 +AudioCodingModuleImpl::DecoderEstimatedBandwidth() const { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "DecoderEstimatedBandwidth()"); CodecInst codecInst; @@ -1885,7 +1885,7 @@ AudioCodingModuleImpl::DecoderEstimatedBandwidth() const if(codecID < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "DecoderEstimatedBandwidth failed"); return -1; } @@ -1899,11 +1899,11 @@ AudioCodingModuleImpl::DecoderEstimatedBandwidth() const } // Set playout mode for: voice, fax, or streaming -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::SetPlayoutMode( const AudioPlayoutMode mode) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "SetPlayoutMode()"); if((mode != voice) && (mode != fax) && @@ -1920,7 +1920,7 @@ AudioCodingModuleImpl::SetPlayoutMode( AudioPlayoutMode AudioCodingModuleImpl::PlayoutMode() const { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "PlayoutMode()"); return _netEq.PlayoutMode(); } @@ -1928,7 +1928,7 @@ AudioCodingModuleImpl::PlayoutMode() const // Get 10 milliseconds of raw audio data to play out // automatic resample to the requested frequency -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::PlayoutData10Ms( const WebRtc_Word32 desiredFreqHz, AudioFrame& audioFrame) @@ -1939,7 +1939,7 @@ AudioCodingModuleImpl::PlayoutData10Ms( // recOut always returns 10 ms if (_netEq.RecOut(audioFrameTmp) != 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "PlayoutData failed, RecOut Failed"); return -1; } @@ -1947,25 +1947,25 @@ AudioCodingModuleImpl::PlayoutData10Ms( audioFrame._audioChannel = audioFrameTmp._audioChannel; audioFrame._vadActivity = audioFrameTmp._vadActivity; audioFrame._speechType = audioFrameTmp._speechType; - + stereoMode = (audioFrameTmp._audioChannel > 1); //For stereo playout: // Master and Slave samples are interleaved starting with Master - + const WebRtc_UWord16 recvFreq = static_cast(audioFrameTmp._frequencyInHz); bool toneDetected = false; WebRtc_Word16 lastDetectedTone; WebRtc_Word16 tone; // limit the scope of ACM Critical section - // perhaps we don't need to have output resampler in - // critical section, it is supposed to be called in this + // perhaps we don't need to have output resampler in + // critical section, it is supposed to be called in this // function and no where else. However, it won't degrade complexity { CriticalSectionScoped lock(*_acmCritSect); if ((recvFreq != desiredFreqHz) && (desiredFreqHz != -1)) - { + { // resample payloadData WebRtc_Word16 tmpLen = _outputResampler.Resample10Msec( audioFrameTmp._payloadData, recvFreq, audioFrame._payloadData, desiredFreqHz, @@ -1973,23 +1973,23 @@ AudioCodingModuleImpl::PlayoutData10Ms( if(tmpLen < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "PlayoutData failed, resampler failed"); return -1; - } - + } + //Set the payload data length from the resampler audioFrame._payloadDataLengthInSamples = (WebRtc_UWord16)tmpLen; // set the ssampling frequency audioFrame._frequencyInHz = desiredFreqHz; } else - { - memcpy(audioFrame._payloadData, audioFrameTmp._payloadData, + { + memcpy(audioFrame._payloadData, audioFrameTmp._payloadData, audioFrameTmp._payloadDataLengthInSamples * audioFrame._audioChannel * sizeof(WebRtc_Word16)); // set the payload length - audioFrame._payloadDataLengthInSamples = audioFrameTmp._payloadDataLengthInSamples; + audioFrame._payloadDataLengthInSamples = audioFrameTmp._payloadDataLengthInSamples; // set the sampling frequency audioFrame._frequencyInHz = recvFreq; } @@ -2001,23 +2001,23 @@ AudioCodingModuleImpl::PlayoutData10Ms( if(audioFrame._frequencyInHz == 8000) { // use audioFrame._payloadData then Dtmf detector doesn't - // need resampling + // need resampling if(!stereoMode) { - _dtmfDetector->Detect(audioFrame._payloadData, - audioFrame._payloadDataLengthInSamples, + _dtmfDetector->Detect(audioFrame._payloadData, + audioFrame._payloadDataLengthInSamples, audioFrame._frequencyInHz, toneDetected, tone); } else { // we are in 8 kHz so the master channel needs only 80 samples - WebRtc_Word16 masterChannel[80]; + WebRtc_Word16 masterChannel[80]; for(int n = 0; n < 80; n++) { masterChannel[n] = audioFrame._payloadData[n<<1]; } _dtmfDetector->Detect(masterChannel, - audioFrame._payloadDataLengthInSamples, + audioFrame._payloadDataLengthInSamples, audioFrame._frequencyInHz, toneDetected, tone); } } @@ -2026,8 +2026,8 @@ AudioCodingModuleImpl::PlayoutData10Ms( // Do the detection on the audio that we got from NetEQ (audioFrameTmp). if(!stereoMode) { - _dtmfDetector->Detect(audioFrameTmp._payloadData, - audioFrameTmp._payloadDataLengthInSamples, recvFreq, + _dtmfDetector->Detect(audioFrameTmp._payloadData, + audioFrameTmp._payloadDataLengthInSamples, recvFreq, toneDetected, tone); } else @@ -2038,7 +2038,7 @@ AudioCodingModuleImpl::PlayoutData10Ms( masterChannel[n] = audioFrameTmp._payloadData[n<<1]; } _dtmfDetector->Detect(masterChannel, - audioFrameTmp._payloadDataLengthInSamples, recvFreq, + audioFrameTmp._payloadDataLengthInSamples, recvFreq, toneDetected, tone); } } @@ -2056,7 +2056,7 @@ AudioCodingModuleImpl::PlayoutData10Ms( } if(toneDetected) - { + { // we will deal with callback here, so enter callback critical // section CriticalSectionScoped lock(*_callbackCritSect); @@ -2071,7 +2071,7 @@ AudioCodingModuleImpl::PlayoutData10Ms( else if((tone == kACMToneEnd) && (lastDetectedTone != kACMToneEnd)) { - // The tone is "END" and the previously detected tone is + // The tone is "END" and the previously detected tone is // not "END," so call fir an end. _dtmfCallback->IncomingDtmf((WebRtc_UWord8)lastDetectedTone, true); @@ -2098,7 +2098,7 @@ AudioCodingModuleImpl::PlayoutData10Ms( bool AudioCodingModuleImpl::ReceiveVADStatus() const { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "ReceiveVADStatus()"); return _netEq.VADStatus(); } @@ -2109,7 +2109,7 @@ WebRtc_Word16 AudioCodingModuleImpl::SetReceiveVADStatus( const bool enable) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "SetReceiveVADStatus()"); return _netEq.SetVADStatus(enable); } @@ -2118,7 +2118,7 @@ AudioCodingModuleImpl::SetReceiveVADStatus( ACMVADMode AudioCodingModuleImpl::ReceiveVADMode() const { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "ReceiveVADMode()"); return _netEq.VADMode(); } @@ -2128,7 +2128,7 @@ WebRtc_Word16 AudioCodingModuleImpl::SetReceiveVADMode( const ACMVADMode mode) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "SetReceiveVADMode()"); return _netEq.SetVADMode(mode); } @@ -2137,62 +2137,62 @@ AudioCodingModuleImpl::SetReceiveVADMode( // statistics // -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::NetworkStatistics( ACMNetworkStatistics& statistics) const { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "NetworkStatistics()"); WebRtc_Word32 status; status = _netEq.NetworkStatistics(&statistics); return status; } -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::JitterStatistics( ACMJitterStatistics& jitterStatistics) const { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "JitterStatistics()"); return _netEq.JitterStatistics(&jitterStatistics); } -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::PreferredBufferSize( WebRtc_UWord16& prefbufsize) const { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "PreferedBufferSize()"); return _netEq.PreferredBufferSize(&prefbufsize); } -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::ResetJitterStatistics() const { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "ResetJitterStatistics()"); return _netEq.ResetJitterStatistics(); } -void +void AudioCodingModuleImpl::DestructEncoderInst( void* ptrInst) { - WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, _id, "DestructEncoderInst()"); if(!HaveValidEncoder("DestructEncoderInst")) { return; } - + _codecs[_currentSendCodecIdx]->DestructEncoderInst(ptrInst); } -WebRtc_Word16 +WebRtc_Word16 AudioCodingModuleImpl::AudioBuffer( WebRtcACMAudioBuff& audioBuff) { - WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, _id, "AudioBuffer()"); if(!HaveValidEncoder("AudioBuffer")) { @@ -2203,11 +2203,11 @@ AudioCodingModuleImpl::AudioBuffer( return _codecs[_currentSendCodecIdx]->AudioBuffer(audioBuff); } -WebRtc_Word16 +WebRtc_Word16 AudioCodingModuleImpl::SetAudioBuffer( WebRtcACMAudioBuff& audioBuff) { - WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, _id, "SetAudioBuffer()"); if(!HaveValidEncoder("SetAudioBuffer")) { @@ -2218,10 +2218,10 @@ AudioCodingModuleImpl::SetAudioBuffer( } -WebRtc_UWord32 +WebRtc_UWord32 AudioCodingModuleImpl::EarliestTimestamp() const { - WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, _id, "EarliestTimestamp()"); if(!HaveValidEncoder("EarliestTimestamp")) { @@ -2231,18 +2231,18 @@ AudioCodingModuleImpl::EarliestTimestamp() const return _codecs[_currentSendCodecIdx]->EarliestTimestamp(); } -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::RegisterVADCallback( ACMVADCallback* vadCallback) { - WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, _id, "RegisterVADCallback()"); CriticalSectionScoped lock(*_callbackCritSect); _vadCallback = vadCallback; return 0; } -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::IncomingPayload( const WebRtc_Word8* incomingPayload, const WebRtc_Word32 payloadLength, @@ -2252,7 +2252,7 @@ AudioCodingModuleImpl::IncomingPayload( if (payloadLength < 0) { // Log error in trace file. - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "IncomingPacket() Error, payload-length cannot be negative"); return -1; } @@ -2265,7 +2265,7 @@ AudioCodingModuleImpl::IncomingPayload( _dummyRTPHeader = new WebRtcRTPHeader; if (_dummyRTPHeader == NULL) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "IncomingPacket() Error, out of memory"); return -1; } @@ -2275,7 +2275,7 @@ AudioCodingModuleImpl::IncomingPayload( _dummyRTPHeader->header.markerBit = false; // start with random numbers _dummyRTPHeader->header.sequenceNumber = rand(); - _dummyRTPHeader->header.timestamp = (((WebRtc_UWord32)rand()) << 16) + + _dummyRTPHeader->header.timestamp = (((WebRtc_UWord32)rand()) << 16) + (WebRtc_UWord32)rand(); _dummyRTPHeader->type.Audio.channel = 1; @@ -2293,7 +2293,7 @@ AudioCodingModuleImpl::IncomingPayload( if(payloadType != _dummyRTPHeader->header.payloadType) { - // payload type has changed since the last time we might need to + // payload type has changed since the last time we might need to // update the frame-size WebRtcACMCodecParams codecParams; if(DecoderParamByPlType(payloadType, codecParams) < 0) @@ -2327,7 +2327,7 @@ AudioCodingModuleImpl::IncomingPayload( return 0; } -WebRtc_Word16 +WebRtc_Word16 AudioCodingModuleImpl::DecoderParamByPlType( const WebRtc_UWord8 payloadType, WebRtcACMCodecParams& codecParams) const @@ -2339,7 +2339,7 @@ AudioCodingModuleImpl::DecoderParamByPlType( { if(_codecs[codecCntr]->DecoderInitialized()) { - if(_codecs[codecCntr]->DecoderParams(&codecParams, + if(_codecs[codecCntr]->DecoderParams(&codecParams, payloadType)) { return 0; @@ -2347,7 +2347,7 @@ AudioCodingModuleImpl::DecoderParamByPlType( } } } - // if we are here it means that we could not find a + // if we are here it means that we could not find a // codec with that payload type. reset the values to // not acceptable values and return -1; codecParams.codecInstant.plname[0] = '\0'; @@ -2359,7 +2359,7 @@ AudioCodingModuleImpl::DecoderParamByPlType( -WebRtc_Word16 +WebRtc_Word16 AudioCodingModuleImpl::DecoderListIDByPlName( const WebRtc_Word8* payloadName, const WebRtc_UWord16 sampFreqHz) const @@ -2374,34 +2374,34 @@ AudioCodingModuleImpl::DecoderListIDByPlName( { assert(_registeredPlTypes[codecCntr] >= 0); assert(_registeredPlTypes[codecCntr] <= 255); - _codecs[codecCntr]->DecoderParams(&codecParams, + _codecs[codecCntr]->DecoderParams(&codecParams, (WebRtc_UWord8)_registeredPlTypes[codecCntr]); if(!STR_CASE_CMP(codecParams.codecInstant.plname, payloadName)) { // Check if the given sampling frequency matches. - // A zero sampling frequency means we matching the names - // is sufficient and we don't need to check for the + // A zero sampling frequency means we matching the names + // is sufficient and we don't need to check for the // frequencies. - // Currently it is only iSAC which has one name but two + // Currently it is only iSAC which has one name but two // sampling frequencies. if((sampFreqHz == 0) || (codecParams.codecInstant.plfreq == sampFreqHz)) - { + { return codecCntr; } } } } } - // if we are here it means that we could not find a + // if we are here it means that we could not find a // codec with that payload type. return -1; return -1; } -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::LastEncodedTimestamp(WebRtc_UWord32& timestamp) const { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "LastEncodedTimestamp()"); CriticalSectionScoped lock(*_acmCritSect); if(!HaveValidEncoder("LastEncodedTimestamp")) @@ -2415,13 +2415,13 @@ AudioCodingModuleImpl::LastEncodedTimestamp(WebRtc_UWord32& timestamp) const WebRtc_Word32 AudioCodingModuleImpl::ReplaceInternalDTXWithWebRtc(bool useWebRtcDTX) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "ReplaceInternalDTXWithWebRtc()"); CriticalSectionScoped lock(*_acmCritSect); if(!HaveValidEncoder("ReplaceInternalDTXWithWebRtc")) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Cannot replace codec internal DTX when no send codec is registered."); return -1; } @@ -2444,7 +2444,7 @@ AudioCodingModuleImpl::ReplaceInternalDTXWithWebRtc(bool useWebRtcDTX) WebRtc_Word32 AudioCodingModuleImpl::IsInternalDTXReplacedWithWebRtc(bool& usesWebRtcDTX) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "IsInternalDTXReplacedWithWebRtc()"); CriticalSectionScoped lock(*_acmCritSect); @@ -2460,11 +2460,11 @@ AudioCodingModuleImpl::IsInternalDTXReplacedWithWebRtc(bool& usesWebRtcDTX) } -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::SetISACMaxRate( const WebRtc_UWord32 maxRateBitPerSec) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "SetISACMaxRate()"); CriticalSectionScoped lock(*_acmCritSect); @@ -2477,11 +2477,11 @@ AudioCodingModuleImpl::SetISACMaxRate( } -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::SetISACMaxPayloadSize( const WebRtc_UWord16 maxPayloadLenBytes) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "SetISACPayloadSize()"); CriticalSectionScoped lock(*_acmCritSect); @@ -2493,13 +2493,13 @@ AudioCodingModuleImpl::SetISACMaxPayloadSize( return _codecs[_currentSendCodecIdx]->SetISACMaxPayloadSize(maxPayloadLenBytes); } -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::ConfigISACBandwidthEstimator( const WebRtc_UWord8 initFrameSizeMsec, const WebRtc_UWord16 initRateBitPerSec, const bool enforceFrameSize) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "ConfigISACBandwidthEstimator()"); CriticalSectionScoped lock(*_acmCritSect); @@ -2512,27 +2512,27 @@ AudioCodingModuleImpl::ConfigISACBandwidthEstimator( initFrameSizeMsec, initRateBitPerSec, enforceFrameSize); } -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::SetBackgroundNoiseMode( const ACMBackgroundNoiseMode mode) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "SetBackgroundNoiseMode()"); if((mode < On) || (mode > Off)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "The specified background noise is out of range.\n"); return -1; } return _netEq.SetBackgroundNoiseMode(mode); } -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::BackgroundNoiseMode( ACMBackgroundNoiseMode& mode) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "BackgroundNoiseMode()"); return _netEq.BackgroundNoiseMode(mode); } @@ -2541,7 +2541,7 @@ WebRtc_Word32 AudioCodingModuleImpl::PlayoutTimestamp( WebRtc_UWord32& timestamp) { - WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, _id, "PlayoutTimestamp()"); return _netEq.PlayoutTimestamp(timestamp); } @@ -2554,43 +2554,43 @@ bool AudioCodingModuleImpl::HaveValidEncoder( const WebRtc_Word8* callerName) const { - if((!_sendCodecRegistered) || + if((!_sendCodecRegistered) || (_currentSendCodecIdx < 0) || (_currentSendCodecIdx >= ACMCodecDB::kNumCodecs)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "%s failed: No send codec is registered.", callerName); return false; } if((_currentSendCodecIdx < 0) || (_currentSendCodecIdx >= ACMCodecDB::kNumCodecs)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, - "%s failed: Send codec index out of range.", callerName); + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + "%s failed: Send codec index out of range.", callerName); return false; } if(_codecs[_currentSendCodecIdx] == NULL) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "%s failed: Send codec is NULL pointer.", callerName); return false; } return true; } -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::UnregisterReceiveCodec( const WebRtc_Word16 payloadType) { - WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id, "UnregisterReceiveCodec()"); CriticalSectionScoped lock(*_acmCritSect); WebRtc_Word16 codecID; - + // Search through the list of registered payload types for (codecID = 0; codecID < ACMCodecDB::kMaxNumCodecs; codecID++) { - if (_registeredPlTypes[codecID] == payloadType) + if (_registeredPlTypes[codecID] == payloadType) { // we have found the codecID registered with the payload type break; @@ -2607,7 +2607,7 @@ AudioCodingModuleImpl::UnregisterReceiveCodec( return UnregisterReceiveCodecSafe(codecID); } -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::UnregisterReceiveCodecSafe( const WebRtc_Word16 codecID) { @@ -2623,18 +2623,18 @@ AudioCodingModuleImpl::UnregisterReceiveCodecSafe( { CodecInst codecInst; ACMCodecDB::Codec(codecID, &codecInst); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id, "Unregistering %s-%d from NetEQ failed.", codecInst.plname, codecInst.plfreq); return -1; } - - // CN is a special case for NetEQ, all three sampling frequencies are + + // CN is a special case for NetEQ, all three sampling frequencies are // deletad if one is deleted if(STR_CASE_CMP(ACMCodecDB::database_[codecID].plname, "CN") == 0) { - // Search codecs nearby in the database to unregister all CN. - for (int i=-2; i<3; i++) + // Search codecs nearby in the database to unregister all CN. + for (int i=-2; i<3; i++) { if (STR_CASE_CMP(ACMCodecDB::database_[codecID+i].plname, "CN") == 0) { @@ -2672,12 +2672,12 @@ AudioCodingModuleImpl::UnregisterReceiveCodecSafe( } -WebRtc_Word32 +WebRtc_Word32 AudioCodingModuleImpl::REDPayloadISAC( - const WebRtc_Word32 isacRate, + const WebRtc_Word32 isacRate, const WebRtc_Word16 isacBwEstimate, WebRtc_UWord8* payload, - WebRtc_Word16* payloadLenByte) + WebRtc_Word16* payloadLenByte) { if(!HaveValidEncoder("EncodeData")) diff --git a/src/modules/audio_coding/main/source/audio_coding_module_impl.h b/src/modules/audio_coding/main/source/audio_coding_module_impl.h index c3f2c3928..eb5176cd5 100644 --- a/src/modules/audio_coding/main/source/audio_coding_module_impl.h +++ b/src/modules/audio_coding/main/source/audio_coding_module_impl.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef AUDIO_CODING_MODULE_IMPL_H -#define AUDIO_CODING_MODULE_IMPL_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_AUDIO_CODING_MODULE_IMPL_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_AUDIO_CODING_MODULE_IMPL_H_ #include "acm_codec_database.h" #include "acm_neteq.h" @@ -59,9 +59,9 @@ public: WebRtc_Word32 TimeUntilNextProcess(); // Process any pending tasks such as timeouts - WebRtc_Word32 Process(); + WebRtc_Word32 Process(); - // used in conference to go to and from active encoding, hence + // used in conference to go to and from active encoding, hence // in and out of mix WebRtc_Word32 SetMode( const bool passive); @@ -94,7 +94,7 @@ public: // return there longterm avarage or their fixed rate. 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 virtual WebRtc_Word32 SetReceivedEstimatedBandwidth( const WebRtc_Word32 bw); @@ -123,7 +123,7 @@ public: ACMBackgroundNoiseMode& mode); ///////////////////////////////////////// - // (FEC) Forward Error Correction + // (FEC) Forward Error Correction // // configure FEC status i.e on/off @@ -193,7 +193,7 @@ public: CodecInst& currentReceiveCodec) const; // incoming packet from network parsed and ready for decode - WebRtc_Word32 IncomingPacket( + WebRtc_Word32 IncomingPacket( const WebRtc_Word8* incomingPayload, const WebRtc_Word32 payloadLength, const WebRtcRTPHeader& rtpInfo); @@ -222,7 +222,7 @@ public: // Estimate the Bandwidth based on the incoming stream // This is also done in the RTP module - // need this for one way audio where the RTCP send the BW estimate + // need this for one way audio where the RTCP send the BW estimate WebRtc_Word32 DecoderEstimatedBandwidth() const; // Set playout mode voice, fax @@ -261,21 +261,21 @@ public: void DestructEncoderInst(void* ptrInst); WebRtc_Word16 AudioBuffer(WebRtcACMAudioBuff& audioBuff); - + // GET RED payload for iSAC. The method id called // when 'this' ACM is default ACM. WebRtc_Word32 REDPayloadISAC( - const WebRtc_Word32 isacRate, + const WebRtc_Word32 isacRate, const WebRtc_Word16 isacBwEstimate, WebRtc_UWord8* payload, WebRtc_Word16* payloadLenByte); - + WebRtc_Word16 SetAudioBuffer(WebRtcACMAudioBuff& audioBuff); WebRtc_UWord32 EarliestTimestamp() const; WebRtc_Word32 LastEncodedTimestamp(WebRtc_UWord32& timestamp) const; - + WebRtc_Word32 ReplaceInternalDTXWithWebRtc( const bool useWebRtcDTX); @@ -361,15 +361,15 @@ private: WebRtc_UWord32 _lastFECTimestamp; WebRtc_UWord8 _redPayloadType; // if no RED is registered as receive codec this - // will have an invalid value. + // will have an invalid value. WebRtc_UWord8 _receiveREDPayloadType; - + // This is to keep track of CN instances where we can send DTMFs WebRtc_UWord8 _previousPayloadType; // This keeps track of payload types associated with _codecs[]. - // We define it as signed variable and initialize with -1 to indicate - // unused elements. + // We define it as signed variable and initialize with -1 to indicate + // unused elements. WebRtc_Word16 _registeredPlTypes[ACMCodecDB::kMaxNumCodecs]; // Used when payloads are pushed into ACM without any RTP info @@ -380,7 +380,7 @@ private: bool _receiverInitialized; ACMDTMFDetection* _dtmfDetector; - + AudioCodingFeedback* _dtmfCallback; WebRtc_Word16 _lastDetectedTone; CriticalSectionWrapper* _callbackCritSect; @@ -397,4 +397,4 @@ private: } // namespace webrtc -#endif +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_AUDIO_CODING_MODULE_IMPL_H_