Merge ACMGenericCodec and ACMGenericCodecWrapper

ACMGenericCodecWrapper was the only remaining subclass of
ACMGenericCodec, and was the only class that was ever instantiated.
This CL merges the two, essentially keeping the function implementations
from ACMGenericCodecWrapper except where the base class's code was
invoked.

As it turns out, a lot of functions were never used, but in some cases
they were refernced in AudioCodingModuleImpl. In these cases, the
referencing code is commented out and marked FATAL(). This will be
further cleaned up in follow-up CLs.

BUG=4228
COAUTHOR=kwiberg@webrtc.org
R=minyue@webrtc.org

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

Cr-Commit-Position: refs/heads/master@{#8463}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8463 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
henrik.lundin@webrtc.org
2015-02-23 16:33:05 +00:00
parent f3a306b5bc
commit 829a6f4ac2
5 changed files with 192 additions and 1756 deletions

View File

@ -415,38 +415,32 @@ ACMGenericCodec* ACMCodecDB::CreateCodecInstance(const CodecInst& codec_inst,
// All we have support for right now.
if (!STR_CASE_CMP(codec_inst.plname, "ISAC")) {
#if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX))
return new ACMGenericCodecWrapper(codec_inst, cng_pt_nb, cng_pt_wb,
cng_pt_swb, cng_pt_fb, enable_red,
red_payload_type);
return new ACMGenericCodec(codec_inst, cng_pt_nb, cng_pt_wb, cng_pt_swb,
cng_pt_fb, enable_red, red_payload_type);
#endif
} else if (!STR_CASE_CMP(codec_inst.plname, "PCMU") ||
!STR_CASE_CMP(codec_inst.plname, "PCMA")) {
return new ACMGenericCodecWrapper(codec_inst, cng_pt_nb, cng_pt_wb,
cng_pt_swb, cng_pt_fb, enable_red,
red_payload_type);
return new ACMGenericCodec(codec_inst, cng_pt_nb, cng_pt_wb, cng_pt_swb,
cng_pt_fb, enable_red, red_payload_type);
} else if (!STR_CASE_CMP(codec_inst.plname, "ILBC")) {
#ifdef WEBRTC_CODEC_ILBC
return new ACMGenericCodecWrapper(codec_inst, cng_pt_nb, cng_pt_wb,
cng_pt_swb, cng_pt_fb, enable_red,
red_payload_type);
return new ACMGenericCodec(codec_inst, cng_pt_nb, cng_pt_wb, cng_pt_swb,
cng_pt_fb, enable_red, red_payload_type);
#endif
} else if (!STR_CASE_CMP(codec_inst.plname, "G722")) {
#ifdef WEBRTC_CODEC_G722
return new ACMGenericCodecWrapper(codec_inst, cng_pt_nb, cng_pt_wb,
cng_pt_swb, cng_pt_fb, enable_red,
red_payload_type);
return new ACMGenericCodec(codec_inst, cng_pt_nb, cng_pt_wb, cng_pt_swb,
cng_pt_fb, enable_red, red_payload_type);
#endif
} else if (!STR_CASE_CMP(codec_inst.plname, "opus")) {
#ifdef WEBRTC_CODEC_OPUS
return new ACMGenericCodecWrapper(codec_inst, cng_pt_nb, cng_pt_wb,
cng_pt_swb, cng_pt_fb, enable_red,
red_payload_type);
return new ACMGenericCodec(codec_inst, cng_pt_nb, cng_pt_wb, cng_pt_swb,
cng_pt_fb, enable_red, red_payload_type);
#endif
} else if (!STR_CASE_CMP(codec_inst.plname, "L16")) {
#ifdef WEBRTC_CODEC_PCM16
return new ACMGenericCodecWrapper(codec_inst, cng_pt_nb, cng_pt_wb,
cng_pt_swb, cng_pt_fb, enable_red,
red_payload_type);
return new ACMGenericCodec(codec_inst, cng_pt_nb, cng_pt_wb, cng_pt_swb,
cng_pt_fb, enable_red, red_payload_type);
#endif
}
return NULL;

File diff suppressed because it is too large Load Diff

View File

@ -40,23 +40,56 @@ namespace acm2 {
// forward declaration
class AcmReceiver;
// Proxy for AudioDecoder
class AudioDecoderProxy final : public AudioDecoder {
public:
AudioDecoderProxy();
void SetDecoder(AudioDecoder* decoder);
bool IsSet() const;
int Decode(const uint8_t* encoded,
size_t encoded_len,
int16_t* decoded,
SpeechType* speech_type) override;
int DecodeRedundant(const uint8_t* encoded,
size_t encoded_len,
int16_t* decoded,
SpeechType* speech_type) override;
bool HasDecodePlc() const override;
int DecodePlc(int num_frames, int16_t* decoded) override;
int Init() override;
int IncomingPacket(const uint8_t* payload,
size_t payload_len,
uint16_t rtp_sequence_number,
uint32_t rtp_timestamp,
uint32_t arrival_timestamp) override;
int ErrorCode() override;
int PacketDuration(const uint8_t* encoded, size_t encoded_len) const override;
int PacketDurationRedundant(const uint8_t* encoded,
size_t encoded_len) const override;
bool PacketHasFec(const uint8_t* encoded, size_t encoded_len) const override;
CNG_dec_inst* CngDecoderInstance() override;
private:
scoped_ptr<CriticalSectionWrapper> decoder_lock_;
AudioDecoder* decoder_ GUARDED_BY(decoder_lock_);
};
class ACMGenericCodec {
public:
///////////////////////////////////////////////////////////////////////////
// Constructor of the class
//
explicit ACMGenericCodec(bool enable_red);
///////////////////////////////////////////////////////////////////////////
// Destructor of the class.
//
virtual ~ACMGenericCodec();
ACMGenericCodec(const CodecInst& codec_inst,
int cng_pt_nb,
int cng_pt_wb,
int cng_pt_swb,
int cng_pt_fb,
bool enable_red,
int red_payload_type);
~ACMGenericCodec();
///////////////////////////////////////////////////////////////////////////
// ACMGenericCodec* CreateInstance();
// The function will be used for FEC. It is not implemented yet.
//
virtual ACMGenericCodec* CreateInstance() = 0;
ACMGenericCodec* CreateInstance();
///////////////////////////////////////////////////////////////////////////
// int16_t Encode()
@ -111,11 +144,11 @@ class ACMGenericCodec {
// -1 if error is occurred, otherwise the length of the bit-stream in
// bytes.
//
virtual int16_t Encode(uint8_t* bitstream,
int16_t* bitstream_len_byte,
uint32_t* timestamp,
WebRtcACMEncodingType* encoding_type,
AudioEncoder::EncodedInfo* encoded_info);
int16_t Encode(uint8_t* bitstream,
int16_t* bitstream_len_byte,
uint32_t* timestamp,
WebRtcACMEncodingType* encoding_type,
AudioEncoder::EncodedInfo* encoded_info);
///////////////////////////////////////////////////////////////////////////
// bool EncoderInitialized();
@ -124,7 +157,7 @@ class ACMGenericCodec {
// True if the encoder is successfully initialized,
// false otherwise.
//
virtual bool EncoderInitialized();
bool EncoderInitialized();
///////////////////////////////////////////////////////////////////////////
// int16_t EncoderParams()
@ -140,7 +173,7 @@ class ACMGenericCodec {
// -1 if the encoder is not initialized,
// 0 otherwise.
//
virtual int16_t EncoderParams(WebRtcACMCodecParams* enc_params);
int16_t EncoderParams(WebRtcACMCodecParams* enc_params);
///////////////////////////////////////////////////////////////////////////
// int16_t InitEncoder(...)
@ -158,8 +191,8 @@ class ACMGenericCodec {
// -1 if failed to initialize.
//
//
virtual int16_t InitEncoder(WebRtcACMCodecParams* codec_params,
bool force_initialization);
int16_t InitEncoder(WebRtcACMCodecParams* codec_params,
bool force_initialization);
///////////////////////////////////////////////////////////////////////////
// int32_t Add10MsData(...)
@ -180,10 +213,10 @@ class ACMGenericCodec {
// -1 if failed
// 0 otherwise.
//
virtual int32_t Add10MsData(const uint32_t timestamp,
const int16_t* data,
const uint16_t length,
const uint8_t audio_channel);
int32_t Add10MsData(const uint32_t timestamp,
const int16_t* data,
const uint16_t length,
const uint8_t audio_channel);
///////////////////////////////////////////////////////////////////////////
// uint32_t NoMissedSamples()
@ -195,14 +228,14 @@ class ACMGenericCodec {
// Return Value:
// Number of samples which are overwritten.
//
virtual uint32_t NoMissedSamples() const;
uint32_t NoMissedSamples() const;
///////////////////////////////////////////////////////////////////////////
// void ResetNoMissedSamples()
// This function resets the number of overwritten samples to zero.
// (We might remove this function if we remove NoMissedSamples())
//
virtual void ResetNoMissedSamples();
void ResetNoMissedSamples();
///////////////////////////////////////////////////////////////////////////
// int16_t SetBitRate()
@ -216,7 +249,7 @@ class ACMGenericCodec {
// codec is not rate-adjustable.
// 0 if the rate is adjusted successfully
//
virtual int16_t SetBitRate(const int32_t bitrate_bps);
int16_t SetBitRate(const int32_t bitrate_bps);
///////////////////////////////////////////////////////////////////////////
// uint32_t EarliestTimestamp()
@ -226,7 +259,7 @@ class ACMGenericCodec {
// Return value:
// timestamp of the first 10 ms audio in the audio buffer.
//
virtual uint32_t EarliestTimestamp() const;
uint32_t EarliestTimestamp() const;
///////////////////////////////////////////////////////////////////////////
// int16_t SetVAD()
@ -255,40 +288,10 @@ class ACMGenericCodec {
// -1 if failed to set DTX & VAD as specified,
// 0 if succeeded.
//
virtual int16_t SetVAD(bool* enable_dtx, bool* enable_vad, ACMVADMode* mode);
int16_t SetVAD(bool* enable_dtx, bool* enable_vad, ACMVADMode* mode);
// Registers comfort noise at |sample_rate_hz| to use |payload_type|.
virtual void SetCngPt(int sample_rate_hz, int payload_type);
///////////////////////////////////////////////////////////////////////////
// int32_t ReplaceInternalDTX()
// This is called to replace the codec internal DTX with WebRtc DTX.
// This is only valid for G729 where the user has possibility to replace
// AnnexB with WebRtc DTX. For other codecs this function has no effect.
//
// Input:
// -replace_internal_dtx : if true the internal DTX is replaced with WebRtc.
//
// Return value
// -1 if failed to replace internal DTX,
// 0 if succeeded.
//
virtual int32_t ReplaceInternalDTX(const bool replace_internal_dtx);
///////////////////////////////////////////////////////////////////////////
// int32_t IsInternalDTXReplaced()
// This is called to check if the codec internal DTX is replaced by WebRtc
// DTX. This is only valid for G729 where the user has possibility to replace
// AnnexB with WebRtc DTX. For other codecs this function has no effect.
//
// Output:
// -internal_dtx_replaced: if true the internal DTX is replaced with WebRtc.
//
// Return value
// -1 if failed to check
// 0 if succeeded.
//
int32_t IsInternalDTXReplaced(bool* internal_dtx_replaced);
void SetCngPt(int sample_rate_hz, int payload_type);
///////////////////////////////////////////////////////////////////////////
// bool HasInternalDTX()
@ -303,31 +306,6 @@ class ACMGenericCodec {
return has_internal_dtx_;
}
///////////////////////////////////////////////////////////////////////////
// int32_t GetEstimatedBandwidth()
// Used to get decoder estimated bandwidth. Only iSAC will provide a value.
//
//
// Return value:
// -1 if fails to get decoder estimated bandwidth,
// >0 estimated bandwidth in bits/sec.
//
virtual int32_t GetEstimatedBandwidth();
///////////////////////////////////////////////////////////////////////////
// int32_t SetEstimatedBandwidth()
// Used to set estiamted bandwidth sent out of band from other side. Only
// iSAC will have use for the value.
//
// Input:
// -estimated_bandwidth: estimated bandwidth in bits/sec
//
// Return value:
// -1 if fails to set estimated bandwidth,
// 0 on success.
//
virtual int32_t SetEstimatedBandwidth(int32_t estimated_bandwidth);
///////////////////////////////////////////////////////////////////////////
// int32_t GetRedPayload()
// Used to get codec specific RED payload (if such is implemented).
@ -341,7 +319,7 @@ class ACMGenericCodec {
// -1 if fails to get codec specific RED,
// 0 if succeeded.
//
virtual int32_t GetRedPayload(uint8_t* red_payload, int16_t* payload_bytes);
int32_t GetRedPayload(uint8_t* red_payload, int16_t* payload_bytes);
///////////////////////////////////////////////////////////////////////////
// int16_t ResetEncoder()
@ -353,7 +331,7 @@ class ACMGenericCodec {
// -1 if failed,
// 0 if succeeded.
//
virtual int16_t ResetEncoder();
int16_t ResetEncoder();
///////////////////////////////////////////////////////////////////////////
// void DestructEncoder()
@ -362,16 +340,7 @@ class ACMGenericCodec {
// instance we cannot delete the encoder and instead we will initialize the
// encoder. We also delete VAD and DTX if they have been created.
//
virtual void DestructEncoder();
///////////////////////////////////////////////////////////////////////////
// int16_t SamplesLeftToEncode()
// Returns the number of samples required to be able to do encoding.
//
// Return value:
// Number of samples.
//
virtual int16_t SamplesLeftToEncode();
void DestructEncoder();
///////////////////////////////////////////////////////////////////////////
// SetUniqueID()
@ -380,7 +349,7 @@ class ACMGenericCodec {
// Input
// -id : A number to identify the codec.
//
virtual void SetUniqueID(const uint32_t id);
void SetUniqueID(const uint32_t id);
///////////////////////////////////////////////////////////////////////////
// UpdateDecoderSampFreq()
@ -407,7 +376,7 @@ class ACMGenericCodec {
// 0 if succeeded in updating the decoder.
// -1 if failed to update.
//
virtual int16_t UpdateDecoderSampFreq(int16_t /* codec_id */) { return 0; }
int16_t UpdateDecoderSampFreq(int16_t /* codec_id */);
///////////////////////////////////////////////////////////////////////////
// UpdateEncoderSampFreq()
@ -425,7 +394,7 @@ class ACMGenericCodec {
// -1 if failed, or if this is meaningless for the given codec.
// 0 if succeeded.
//
virtual int16_t UpdateEncoderSampFreq(uint16_t samp_freq_hz)
int16_t UpdateEncoderSampFreq(uint16_t samp_freq_hz)
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
///////////////////////////////////////////////////////////////////////////
@ -440,38 +409,9 @@ class ACMGenericCodec {
// -1 if failed to output sampling rate.
// 0 if the sample rate is returned successfully.
//
virtual int16_t EncoderSampFreq(uint16_t* samp_freq_hz)
int16_t EncoderSampFreq(uint16_t* samp_freq_hz)
SHARED_LOCKS_REQUIRED(codec_wrapper_lock_);
///////////////////////////////////////////////////////////////////////////
// int32_t ConfigISACBandwidthEstimator()
// Call this function to configure the bandwidth estimator of ISAC.
// During the adaptation of bit-rate, iSAC automatically 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:
// -init_frame_fize_ms : initial frame-size in milliseconds. For iSAC-wb
// 30 ms and 60 ms (default) are acceptable values,
// and for iSAC-swb 30 ms is the only acceptable
// value. Zero indicates default value.
// -init_rate_bps : initial estimate of the bandwidth. Values
// between 10000 and 58000 are acceptable.
// -enforce_frame_size : 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 int32_t ConfigISACBandwidthEstimator(
const uint8_t init_frame_size_msec,
const uint16_t init_rate_bps,
const bool enforce_frame_size);
///////////////////////////////////////////////////////////////////////////
// SetISACMaxPayloadSize()
// Set the maximum payload size of iSAC packets. No iSAC payload,
@ -487,7 +427,7 @@ class ACMGenericCodec {
// -1 if failed to set the maximum payload-size.
// 0 if the given length is set successfully.
//
virtual int32_t SetISACMaxPayloadSize(const uint16_t max_payload_len_bytes);
int32_t SetISACMaxPayloadSize(const uint16_t max_payload_len_bytes);
///////////////////////////////////////////////////////////////////////////
// SetISACMaxRate()
@ -504,35 +444,7 @@ class ACMGenericCodec {
// -1 if failed to set the maximum rate.
// 0 if the maximum rate is set successfully.
//
virtual int32_t SetISACMaxRate(const uint32_t max_rate_bps);
///////////////////////////////////////////////////////////////////////////
// REDPayloadISAC()
// This is an iSAC-specific function. The function is called to get RED
// payload from a default-encoder.
//
// Inputs:
// -isac_rate : the target rate of the main payload. A RED
// payload is generated according to the rate of
// main payload. Note that we are not specifying the
// rate of RED payload, but the main payload.
// -isac_bw_estimate : bandwidth information should be inserted in
// RED payload.
//
// Output:
// -payload : pointer to a buffer where the RED payload will
// written to.
// -payload_len_bytes : a place-holder to write the length of the RED
// payload in Bytes.
//
// Return value:
// -1 if an error occurs, otherwise the length of the payload (in Bytes)
// is returned.
//
virtual int16_t REDPayloadISAC(const int32_t isac_rate,
const int16_t isac_bw_estimate,
uint8_t* payload,
int16_t* payload_len_bytes);
int32_t SetISACMaxRate(const uint32_t max_rate_bps);
///////////////////////////////////////////////////////////////////////////
// int SetOpusApplication()
@ -546,7 +458,7 @@ class ACMGenericCodec {
// -1 if failed or on codecs other than Opus.
// 0 if succeeded.
//
virtual int SetOpusApplication(OpusApplicationMode /*application*/);
int SetOpusApplication(OpusApplicationMode /*application*/);
///////////////////////////////////////////////////////////////////////////
// int SetOpusMaxPlaybackRate()
@ -562,14 +474,14 @@ class ACMGenericCodec {
// -1 if failed or on codecs other than Opus
// 0 if succeeded.
//
virtual int SetOpusMaxPlaybackRate(int /* frequency_hz */);
int SetOpusMaxPlaybackRate(int /* frequency_hz */);
///////////////////////////////////////////////////////////////////////////
// HasFrameToEncode()
// Returns true if there is enough audio buffered for encoding, such that
// calling Encode() will return a payload.
//
virtual bool HasFrameToEncode() const;
bool HasFrameToEncode() const;
//
// Returns pointer to the AudioDecoder class of this codec. A codec which
@ -578,7 +490,7 @@ class ACMGenericCodec {
// decoder setting) should implement this method. This method is called if
// and only if the ACMCodecDB::codec_settings[codec_id].owns_decoder is true.
//
virtual AudioDecoder* Decoder(int /* codec_id */) { return NULL; }
AudioDecoder* Decoder(int /* codec_id */);
///////////////////////////////////////////////////////////////////////////
// bool HasInternalFEC()
@ -606,7 +518,7 @@ class ACMGenericCodec {
// -1 if failed,
// 0 if succeeded.
//
virtual int SetFEC(bool enable_fec);
int SetFEC(bool enable_fec);
///////////////////////////////////////////////////////////////////////////
// int SetPacketLossRate()
@ -621,302 +533,19 @@ class ACMGenericCodec {
// -1 if failed,
// 0 if succeeded or packet loss rate is ignored.
//
virtual int SetPacketLossRate(int /* loss_rate */) { return 0; }
int SetPacketLossRate(int /* loss_rate */);
// Sets if CopyRed should be enabled.
virtual void EnableCopyRed(bool enable, int red_payload_type);
void EnableCopyRed(bool enable, int red_payload_type);
// Returns true if the caller needs to produce RED data manually (that is, if
// RED has been enabled but the codec isn't able to produce the data itself).
virtual bool ExternalRedNeeded();
bool ExternalRedNeeded();
protected:
///////////////////////////////////////////////////////////////////////////
// All the functions with FunctionNameSafe(...) contain the actual
// implementation of FunctionName(...). FunctionName() acquires an
// appropriate lock and calls FunctionNameSafe() to do the actual work.
// Therefore, for the description of functionality, input/output arguments
// and return value we refer to FunctionName()
//
///////////////////////////////////////////////////////////////////////////
// See Add10MsSafe() for the description of function, input(s)/output(s)
// and return value.
//
virtual int32_t Add10MsDataSafe(const uint32_t timestamp,
const int16_t* data,
const uint16_t length,
const uint8_t audio_channel)
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
///////////////////////////////////////////////////////////////////////////
// See EncoderParam() for the description of function, input(s)/output(s)
// and return value.
//
int16_t EncoderParamsSafe(WebRtcACMCodecParams* enc_params)
SHARED_LOCKS_REQUIRED(codec_wrapper_lock_);
///////////////////////////////////////////////////////////////////////////
// See ResetEncoder() for the description of function, input(s)/output(s)
// and return value.
//
int16_t ResetEncoderSafe() EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
///////////////////////////////////////////////////////////////////////////
// See InitEncoder() for the description of function, input(s)/output(s)
// and return value.
//
virtual int16_t InitEncoderSafe(WebRtcACMCodecParams* codec_params,
bool force_initialization)
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
///////////////////////////////////////////////////////////////////////////
// See InitDecoder() for the description of function, input(s)/output(s)
// and return value.
//
int16_t InitDecoderSafe(WebRtcACMCodecParams* codec_params,
bool force_initialization);
///////////////////////////////////////////////////////////////////////////
// See DestructEncoder() for the description of function,
// input(s)/output(s) and return value.
//
virtual void DestructEncoderSafe()
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_) = 0;
///////////////////////////////////////////////////////////////////////////
// See SetBitRate() for the description of function, input(s)/output(s)
// and return value.
//
// Any codec that can change the bit-rate has to implement this.
//
virtual int16_t SetBitRateSafe(const int32_t bitrate_bps)
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
///////////////////////////////////////////////////////////////////////////
// See GetEstimatedBandwidth() for the description of function,
// input(s)/output(s) and return value.
//
virtual int32_t GetEstimatedBandwidthSafe();
///////////////////////////////////////////////////////////////////////////
// See SetEstimatedBandwidth() for the description of function,
// input(s)/output(s) and return value.
//
virtual int32_t SetEstimatedBandwidthSafe(int32_t estimated_bandwidth);
///////////////////////////////////////////////////////////////////////////
// See GetRedPayload() for the description of function, input(s)/output(s)
// and return value.
//
virtual int32_t GetRedPayloadSafe(uint8_t* red_payload,
int16_t* payload_bytes);
///////////////////////////////////////////////////////////////////////////
// See SetVAD() for the description of function, input(s)/output(s) and
// return value.
//
int16_t SetVADSafe(bool* enable_dtx, bool* enable_vad, ACMVADMode* mode)
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
///////////////////////////////////////////////////////////////////////////
// See ReplaceInternalDTX() for the description of function, input and
// return value.
//
virtual int32_t ReplaceInternalDTXSafe(const bool replace_internal_dtx);
///////////////////////////////////////////////////////////////////////////
// See IsInternalDTXReplaced() for the description of function, input and
// return value.
//
virtual int32_t IsInternalDTXReplacedSafe(bool* internal_dtx_replaced);
///////////////////////////////////////////////////////////////////////////
// int16_t CreateEncoder()
// Creates the encoder instance.
//
// Return value:
// -1 if failed,
// 0 if succeeded.
//
int16_t CreateEncoder() EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
///////////////////////////////////////////////////////////////////////////
// int16_t EnableVAD();
// Enables VAD with the given mode. The VAD instance will be created if
// it does not exists.
//
// Input:
// -mode : VAD mode c.f. audio_coding_module_typedefs.h for
// the options.
//
// Return value:
// -1 if failed,
// 0 if succeeded.
//
int16_t EnableVAD(ACMVADMode mode)
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
///////////////////////////////////////////////////////////////////////////
// int16_t DisableVAD()
// Disables VAD.
//
// Return value:
// -1 if failed,
// 0 if succeeded.
//
int16_t DisableVAD() EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
///////////////////////////////////////////////////////////////////////////
// int16_t EnableDTX()
// Enables DTX. This method should be overwritten for codecs which have
// internal DTX.
//
// Return value:
// -1 if failed,
// 0 if succeeded.
//
virtual int16_t EnableDTX() EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
///////////////////////////////////////////////////////////////////////////
// int16_t DisableDTX()
// Disables usage of DTX. This method should be overwritten for codecs which
// have internal DTX.
//
// Return value:
// -1 if failed,
// 0 if succeeded.
//
virtual int16_t DisableDTX() EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
///////////////////////////////////////////////////////////////////////////
// int16_t InternalEncode()
// This is a codec-specific function called in EncodeSafe() to actually
// encode a frame of audio.
//
// Outputs:
// -bitstream : pointer to a buffer where the bit-stream is
// written to.
// -bitstream_len_byte : the length of the bit-stream in bytes,
// a negative value indicates error.
//
// Return value:
// -1 if failed,
// otherwise the length of the bit-stream is returned.
//
virtual int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte)
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_) = 0;
///////////////////////////////////////////////////////////////////////////
// int16_t InternalInitEncoder()
// This is a codec-specific function called in InitEncoderSafe(), it has to
// do all codec-specific operation to initialize the encoder given the
// encoder parameters.
//
// Input:
// -codec_params : pointer to a structure that contains parameters to
// initialize encoder.
// Set codec_params->codec_inst.rate to -1 for
// iSAC to operate in adaptive mode.
// (to do: if frame-length is -1 frame-length will be
// automatically adjusted, otherwise, given
// frame-length is forced)
//
// Return value:
// -1 if failed,
// 0 if succeeded.
//
virtual int16_t InternalInitEncoder(WebRtcACMCodecParams* codec_params)
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_) = 0;
///////////////////////////////////////////////////////////////////////////
// void IncreaseNoMissedSamples()
// This method is called to increase the number of samples that are
// overwritten in the audio buffer.
//
// Input:
// -num_samples : the number of overwritten samples is incremented
// by this value.
//
void IncreaseNoMissedSamples(const int16_t num_samples)
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
///////////////////////////////////////////////////////////////////////////
// int16_t InternalCreateEncoder()
// This is a codec-specific method called in CreateEncoderSafe() it is
// supposed to perform all codec-specific operations to create encoder
// instance.
//
// Return value:
// -1 if failed,
// 0 if succeeded.
//
virtual int16_t InternalCreateEncoder() = 0;
///////////////////////////////////////////////////////////////////////////
// int16_t InternalResetEncoder()
// This method is called to reset the states of encoder. However, the
// current parameters, e.g. frame-length, should remain as they are. For
// most of the codecs a re-initialization of the encoder is what needs to
// be down. But for iSAC we like to keep the BWE history so we cannot
// re-initialize. As soon as such an API is implemented in iSAC this method
// has to be overwritten in ACMISAC class.
//
// Return value:
// -1 if failed,
// 0 if succeeded.
//
virtual int16_t InternalResetEncoder()
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
///////////////////////////////////////////////////////////////////////////
// int16_t ProcessFrameVADDTX()
// This function is called when a full frame of audio is available. It will
// break the audio frame into blocks such that each block could be processed
// by VAD & CN/DTX. If a frame is divided into two blocks then there are two
// cases. First, the first block is active, the second block will not be
// processed by CN/DTX but only by VAD and return to caller with
// '*samples_processed' set to zero. There, the audio frame will be encoded
// by the encoder. Second, the first block is inactive and is processed by
// CN/DTX, then we stop processing the next block and return to the caller
// which is EncodeSafe(), with "*samples_processed" equal to the number of
// samples in first block.
//
// Output:
// -bitstream : pointer to a buffer where DTX frame, if
// generated, will be written to.
// -bitstream_len_byte : contains the length of bit-stream in bytes, if
// generated. Zero if no bit-stream is generated.
// -samples_processed : contains no of samples that actually CN has
// processed. Those samples processed by CN will not
// be encoded by the encoder, obviously. If
// contains zero, it means that the frame has been
// identified as active by VAD. Note that
// "*samples_processed" might be non-zero but
// "*bitstream_len_byte" be zero.
//
// Return value:
// -1 if failed,
// 0 if succeeded.
//
int16_t ProcessFrameVADDTX(uint8_t* bitstream,
int16_t* bitstream_len_byte,
int16_t* samples_processed)
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
///////////////////////////////////////////////////////////////////////////
// CurrentRate()
// Call to get the current encoding rate of the encoder. This function
// should be overwritten for codecs which automatically change their
// target rate. One example is iSAC. The output of the function is the
// current target rate.
//
// Output:
// -rate_bps : the current target rate of the codec.
//
virtual void CurrentRate(int32_t* /* rate_bps */) {}
// This method is only for testing.
const AudioEncoder* GetAudioEncoder() const;
private:
// &in_audio_[in_audio_ix_write_] always point to where new audio can be
// written to
int16_t in_audio_ix_write_ GUARDED_BY(codec_wrapper_lock_);
@ -979,155 +608,7 @@ class ACMGenericCodec {
uint32_t last_timestamp_ GUARDED_BY(codec_wrapper_lock_);
uint32_t unique_id_;
};
// Proxy for AudioDecoder
class AudioDecoderProxy final : public AudioDecoder {
public:
AudioDecoderProxy();
void SetDecoder(AudioDecoder* decoder);
bool IsSet() const;
int Decode(const uint8_t* encoded,
size_t encoded_len,
int16_t* decoded,
SpeechType* speech_type) override;
int DecodeRedundant(const uint8_t* encoded,
size_t encoded_len,
int16_t* decoded,
SpeechType* speech_type) override;
bool HasDecodePlc() const override;
int DecodePlc(int num_frames, int16_t* decoded) override;
int Init() override;
int IncomingPacket(const uint8_t* payload,
size_t payload_len,
uint16_t rtp_sequence_number,
uint32_t rtp_timestamp,
uint32_t arrival_timestamp) override;
int ErrorCode() override;
int PacketDuration(const uint8_t* encoded, size_t encoded_len) const override;
int PacketDurationRedundant(const uint8_t* encoded,
size_t encoded_len) const override;
bool PacketHasFec(const uint8_t* encoded, size_t encoded_len) const override;
CNG_dec_inst* CngDecoderInstance() override;
private:
scoped_ptr<CriticalSectionWrapper> decoder_lock_;
AudioDecoder* decoder_ GUARDED_BY(decoder_lock_);
};
class ACMGenericCodecWrapper : public ACMGenericCodec {
public:
ACMGenericCodecWrapper(const CodecInst& codec_inst,
int cng_pt_nb,
int cng_pt_wb,
int cng_pt_swb,
int cng_pt_fb,
bool enable_red,
int red_payload_type);
virtual ~ACMGenericCodecWrapper() = default;
ACMGenericCodec* CreateInstance() override;
int16_t Encode(uint8_t* bitstream,
int16_t* bitstream_len_byte,
uint32_t* timestamp,
WebRtcACMEncodingType* encoding_type,
AudioEncoder::EncodedInfo* encoded_info) override;
bool EncoderInitialized() override;
int16_t EncoderParams(WebRtcACMCodecParams* enc_params) override;
int16_t InitEncoder(WebRtcACMCodecParams* codec_params,
bool force_initialization) override;
int32_t Add10MsData(const uint32_t timestamp,
const int16_t* data,
const uint16_t length,
const uint8_t audio_channel) override;
uint32_t NoMissedSamples() const override;
void ResetNoMissedSamples() override;
int16_t SetBitRate(const int32_t bitrate_bps) override;
uint32_t EarliestTimestamp() const override;
int16_t SetVAD(bool* enable_dtx, bool* enable_vad, ACMVADMode* mode) override;
void SetCngPt(int sample_rate_hz, int payload_type) override;
int32_t ReplaceInternalDTX(const bool replace_internal_dtx) override;
int32_t GetEstimatedBandwidth() override;
int32_t SetEstimatedBandwidth(int32_t estimated_bandwidth) override;
int32_t GetRedPayload(uint8_t* red_payload, int16_t* payload_bytes) override;
int16_t ResetEncoder() override;
void DestructEncoder() override;
int16_t SamplesLeftToEncode() override;
void SetUniqueID(const uint32_t id) override;
int16_t UpdateDecoderSampFreq(int16_t codec_id) override;
int16_t UpdateEncoderSampFreq(uint16_t samp_freq_hz) override
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
int16_t EncoderSampFreq(uint16_t* samp_freq_hz) override
SHARED_LOCKS_REQUIRED(codec_wrapper_lock_);
int32_t ConfigISACBandwidthEstimator(const uint8_t init_frame_size_msec,
const uint16_t init_rate_bps,
const bool enforce_frame_size) override;
int32_t SetISACMaxPayloadSize(const uint16_t max_payload_len_bytes) override;
int32_t SetISACMaxRate(const uint32_t max_rate_bps) override;
int16_t REDPayloadISAC(const int32_t isac_rate,
const int16_t isac_bw_estimate,
uint8_t* payload,
int16_t* payload_len_bytes) override;
int SetOpusMaxPlaybackRate(int /* frequency_hz */) override;
bool HasFrameToEncode() const override;
AudioDecoder* Decoder(int /* codec_id */) override;
int SetFEC(bool enable_fec) override;
int SetOpusApplication(OpusApplicationMode mode) override;
int SetPacketLossRate(int /* loss_rate */) override;
void EnableCopyRed(bool enable, int red_payload_type) override;
bool ExternalRedNeeded() override;
// This method is only for testing.
const AudioEncoder* GetAudioEncoder() const;
protected:
void DestructEncoderSafe() override
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) override
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
int16_t InternalInitEncoder(WebRtcACMCodecParams* codec_params) override
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
int16_t InternalCreateEncoder() override;
private:
void ResetAudioEncoder() EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
OpusApplicationMode GetOpusApplication(int num_channels) const

View File

@ -29,7 +29,7 @@ class AcmGenericCodecOpusTest : public ::testing::Test {
}
void CreateCodec() {
codec_wrapper_.reset(new ACMGenericCodecWrapper(
codec_wrapper_.reset(new ACMGenericCodec(
acm_codec_params_.codec_inst, kCngPt, kCngPt, kCngPt, kCngPt,
false /* enable RED */, kRedPt));
ASSERT_TRUE(codec_wrapper_);
@ -43,7 +43,7 @@ class AcmGenericCodecOpusTest : public ::testing::Test {
return ptr;
}
WebRtcACMCodecParams acm_codec_params_;
scoped_ptr<ACMGenericCodecWrapper> codec_wrapper_;
scoped_ptr<ACMGenericCodec> codec_wrapper_;
};
TEST_F(AcmGenericCodecOpusTest, DefaultApplicationModeMono) {

View File

@ -252,8 +252,9 @@ int64_t AudioCodingModuleImpl::TimeUntilNextProcess() {
if (!HaveValidEncoder("TimeUntilNextProcess")) {
return -1;
}
return codecs_[current_send_codec_idx_]->SamplesLeftToEncode() /
(send_codec_inst_.plfreq / 1000);
FATAL() << "Dead code?";
// return codecs_[current_send_codec_idx_]->SamplesLeftToEncode() /
// (send_codec_inst_.plfreq / 1000);
}
// Process any pending tasks such as timeouts.
@ -909,7 +910,8 @@ int AudioCodingModuleImpl::SendBitrate() const {
// received from the remote party.
int AudioCodingModuleImpl::SetReceivedEstimatedBandwidth(int bw) {
CriticalSectionScoped lock(acm_crit_sect_);
return codecs_[current_send_codec_idx_]->SetEstimatedBandwidth(bw);
FATAL() << "Dead code?";
// return codecs_[current_send_codec_idx_]->SetEstimatedBandwidth(bw);
}
// Register a transport callback which will be called to deliver
@ -1409,7 +1411,8 @@ int AudioCodingModuleImpl::DecoderEstimatedBandwidth() const {
if (last_audio_codec_id >= 0 &&
STR_CASE_CMP("ISAC", ACMCodecDB::database_[last_audio_codec_id].plname)) {
CriticalSectionScoped lock(acm_crit_sect_);
return codecs_[last_audio_codec_id]->GetEstimatedBandwidth();
FATAL() << "Dead code?";
// return codecs_[last_audio_codec_id]->GetEstimatedBandwidth();
}
return -1;
}
@ -1496,32 +1499,25 @@ int AudioCodingModuleImpl::ReplaceInternalDTXWithWebRtc(bool use_webrtc_dtx) {
return -1;
}
int res = codecs_[current_send_codec_idx_]->ReplaceInternalDTX(
use_webrtc_dtx);
FATAL() << "Dead code?";
// int res = codecs_[current_send_codec_idx_]->ReplaceInternalDTX(
// use_webrtc_dtx);
// Check if VAD is turned on, or if there is any error.
if (res == 1) {
vad_enabled_ = true;
} else if (res < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_,
"Failed to set ReplaceInternalDTXWithWebRtc(%d)",
use_webrtc_dtx);
return res;
}
// if (res == 1) {
// vad_enabled_ = true;
// } else if (res < 0) {
// WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_,
// "Failed to set ReplaceInternalDTXWithWebRtc(%d)",
// use_webrtc_dtx);
// return res;
// }
return 0;
}
int AudioCodingModuleImpl::IsInternalDTXReplacedWithWebRtc(
bool* uses_webrtc_dtx) {
CriticalSectionScoped lock(acm_crit_sect_);
if (!HaveValidEncoder("IsInternalDTXReplacedWithWebRtc")) {
return -1;
}
if (codecs_[current_send_codec_idx_]->IsInternalDTXReplaced(uses_webrtc_dtx)
< 0) {
return -1;
}
*uses_webrtc_dtx = true;
return 0;
}
@ -1556,8 +1552,9 @@ int AudioCodingModuleImpl::ConfigISACBandwidthEstimator(
return -1;
}
return codecs_[current_send_codec_idx_]->ConfigISACBandwidthEstimator(
frame_size_ms, rate_bit_per_sec, enforce_frame_size);
FATAL() << "Dead code?";
// return codecs_[current_send_codec_idx_]->ConfigISACBandwidthEstimator(
// frame_size_ms, rate_bit_per_sec, enforce_frame_size);
}
int AudioCodingModuleImpl::SetOpusApplication(OpusApplicationMode application) {
@ -1616,12 +1613,13 @@ int AudioCodingModuleImpl::REDPayloadISAC(int isac_rate,
if (!HaveValidEncoder("EncodeData")) {
return -1;
}
int status;
status = codecs_[current_send_codec_idx_]->REDPayloadISAC(isac_rate,
isac_bw_estimate,
payload,
length_bytes);
return status;
FATAL() << "Dead code?";
// int status;
// status = codecs_[current_send_codec_idx_]->REDPayloadISAC(isac_rate,
// isac_bw_estimate,
// payload,
// length_bytes);
// return status;
}
void AudioCodingModuleImpl::ResetFragmentation(int vector_size) {