Annotating the rest of AcmGenericCodec

A few locks had to be acquired to fully annotate the class, and a few
others had to be moved.
Removing an API method that was not used.

BUG=3401
R=kwiberg@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6526 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
henrik.lundin@webrtc.org
2014-06-24 05:51:34 +00:00
parent f6d37de466
commit b338ca6557
10 changed files with 93 additions and 50 deletions

View File

@@ -35,7 +35,8 @@ class ACMCNG: public ACMGenericCodec {
int16_t InternalInitEncoder(WebRtcACMCodecParams *codec_params); int16_t InternalInitEncoder(WebRtcACMCodecParams *codec_params);
protected: protected:
void DestructEncoderSafe(); void DestructEncoderSafe() OVERRIDE
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
int16_t InternalCreateEncoder(); int16_t InternalCreateEncoder();

View File

@@ -33,7 +33,9 @@ class ACMG722 : public ACMGenericCodec {
// For FEC. // For FEC.
ACMGenericCodec* CreateInstance(void); ACMGenericCodec* CreateInstance(void);
int16_t InternalEncode(uint8_t* bitstream, int16_t* bitstream_len_byte); int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) OVERRIDE
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
int16_t InternalInitEncoder(WebRtcACMCodecParams* codec_params); int16_t InternalInitEncoder(WebRtcACMCodecParams* codec_params);
@@ -44,7 +46,8 @@ class ACMG722 : public ACMGenericCodec {
const uint8_t audio_channel) const uint8_t audio_channel)
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_); EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
void DestructEncoderSafe(); void DestructEncoderSafe() OVERRIDE
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
int16_t InternalCreateEncoder(); int16_t InternalCreateEncoder();

View File

@@ -312,7 +312,10 @@ class ACMGenericCodec {
// true if the codec has an internal DTX, e.g. G729, // true if the codec has an internal DTX, e.g. G729,
// false otherwise. // false otherwise.
// //
bool HasInternalDTX() const { return has_internal_dtx_; } bool HasInternalDTX() const {
ReadLockScoped rl(codec_wrapper_lock_);
return has_internal_dtx_;
}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// int32_t GetEstimatedBandwidth() // int32_t GetEstimatedBandwidth()
@@ -436,7 +439,8 @@ class ACMGenericCodec {
// -1 if failed, or if this is meaningless for the given codec. // -1 if failed, or if this is meaningless for the given codec.
// 0 if succeeded. // 0 if succeeded.
// //
virtual int16_t UpdateEncoderSampFreq(uint16_t samp_freq_hz); virtual int16_t UpdateEncoderSampFreq(uint16_t samp_freq_hz)
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// EncoderSampFreq() // EncoderSampFreq()
@@ -450,7 +454,8 @@ class ACMGenericCodec {
// -1 if failed to output sampling rate. // -1 if failed to output sampling rate.
// 0 if the sample rate is returned successfully. // 0 if the sample rate is returned successfully.
// //
virtual int16_t EncoderSampFreq(uint16_t* samp_freq_hz); virtual int16_t EncoderSampFreq(uint16_t* samp_freq_hz)
SHARED_LOCKS_REQUIRED(codec_wrapper_lock_);
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// int32_t ConfigISACBandwidthEstimator() // int32_t ConfigISACBandwidthEstimator()
@@ -515,8 +520,6 @@ class ACMGenericCodec {
// //
virtual int32_t SetISACMaxRate(const uint32_t max_rate_bps); virtual int32_t SetISACMaxRate(const uint32_t max_rate_bps);
int32_t FrameSize() { return frame_len_smpl_; }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// REDPayloadISAC() // REDPayloadISAC()
// This is an iSAC-specific function. The function is called to get RED // This is an iSAC-specific function. The function is called to get RED
@@ -569,7 +572,10 @@ class ACMGenericCodec {
// true if the codec has an internal FEC, e.g. Opus. // true if the codec has an internal FEC, e.g. Opus.
// false otherwise. // false otherwise.
// //
bool HasInternalFEC() const { return has_internal_fec_; } bool HasInternalFEC() const {
ReadLockScoped rl(codec_wrapper_lock_);
return has_internal_fec_;
}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// int SetFEC(); // int SetFEC();
@@ -624,7 +630,8 @@ class ACMGenericCodec {
// See EncoderParam() for the description of function, input(s)/output(s) // See EncoderParam() for the description of function, input(s)/output(s)
// and return value. // and return value.
// //
int16_t EncoderParamsSafe(WebRtcACMCodecParams* enc_params); int16_t EncoderParamsSafe(WebRtcACMCodecParams* enc_params)
SHARED_LOCKS_REQUIRED(codec_wrapper_lock_);
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// See ResetEncoder() for the description of function, input(s)/output(s) // See ResetEncoder() for the description of function, input(s)/output(s)
@@ -651,7 +658,8 @@ class ACMGenericCodec {
// See DestructEncoder() for the description of function, // See DestructEncoder() for the description of function,
// input(s)/output(s) and return value. // input(s)/output(s) and return value.
// //
virtual void DestructEncoderSafe() = 0; virtual void DestructEncoderSafe()
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_) = 0;
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// See SetBitRate() for the description of function, input(s)/output(s) // See SetBitRate() for the description of function, input(s)/output(s)
@@ -659,7 +667,8 @@ class ACMGenericCodec {
// //
// Any codec that can change the bit-rate has to implement this. // Any codec that can change the bit-rate has to implement this.
// //
virtual int16_t SetBitRateSafe(const int32_t bitrate_bps); virtual int16_t SetBitRateSafe(const int32_t bitrate_bps)
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// See GetEstimatedBandwidth() for the description of function, // See GetEstimatedBandwidth() for the description of function,
@@ -707,7 +716,7 @@ class ACMGenericCodec {
// -1 if failed, // -1 if failed,
// 0 if succeeded. // 0 if succeeded.
// //
int16_t CreateEncoder(); int16_t CreateEncoder() EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// int16_t EnableVAD(); // int16_t EnableVAD();
@@ -773,7 +782,8 @@ class ACMGenericCodec {
// otherwise the length of the bit-stream is returned. // otherwise the length of the bit-stream is returned.
// //
virtual int16_t InternalEncode(uint8_t* bitstream, virtual int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) = 0; int16_t* bitstream_len_byte)
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_) = 0;
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// int16_t InternalInitEncoder() // int16_t InternalInitEncoder()
@@ -794,7 +804,8 @@ class ACMGenericCodec {
// -1 if failed, // -1 if failed,
// 0 if succeeded. // 0 if succeeded.
// //
virtual int16_t InternalInitEncoder(WebRtcACMCodecParams* codec_params) = 0; virtual int16_t InternalInitEncoder(WebRtcACMCodecParams* codec_params)
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_) = 0;
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// void IncreaseNoMissedSamples() // void IncreaseNoMissedSamples()
@@ -805,7 +816,8 @@ class ACMGenericCodec {
// -num_samples : the number of overwritten samples is incremented // -num_samples : the number of overwritten samples is incremented
// by this value. // by this value.
// //
void IncreaseNoMissedSamples(const int16_t num_samples); void IncreaseNoMissedSamples(const int16_t num_samples)
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// int16_t InternalCreateEncoder() // int16_t InternalCreateEncoder()
@@ -849,7 +861,8 @@ class ACMGenericCodec {
// -1 if failed, // -1 if failed,
// 0 if succeeded. // 0 if succeeded.
// //
virtual int16_t InternalResetEncoder(); virtual int16_t InternalResetEncoder()
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// int16_t ProcessFrameVADDTX() // int16_t ProcessFrameVADDTX()
@@ -900,41 +913,42 @@ class ACMGenericCodec {
// &in_audio_[in_audio_ix_write_] always point to where new audio can be // &in_audio_[in_audio_ix_write_] always point to where new audio can be
// written to // written to
int16_t in_audio_ix_write_; int16_t in_audio_ix_write_ GUARDED_BY(codec_wrapper_lock_);
// &in_audio_[in_audio_ix_read_] points to where audio has to be read from // &in_audio_[in_audio_ix_read_] points to where audio has to be read from
int16_t in_audio_ix_read_; int16_t in_audio_ix_read_ GUARDED_BY(codec_wrapper_lock_);
int16_t in_timestamp_ix_write_; int16_t in_timestamp_ix_write_ GUARDED_BY(codec_wrapper_lock_);
// Where the audio is stored before encoding, // Where the audio is stored before encoding,
// To save memory the following buffer can be allocated // To save memory the following buffer can be allocated
// dynamically for 80 ms depending on the sampling frequency // dynamically for 80 ms depending on the sampling frequency
// of the codec. // of the codec.
int16_t* in_audio_; int16_t* in_audio_ GUARDED_BY(codec_wrapper_lock_);
uint32_t* in_timestamp_; uint32_t* in_timestamp_ GUARDED_BY(codec_wrapper_lock_);
int16_t frame_len_smpl_; int16_t frame_len_smpl_ GUARDED_BY(codec_wrapper_lock_);
uint16_t num_channels_; uint16_t num_channels_ GUARDED_BY(codec_wrapper_lock_);
// This will point to a static database of the supported codecs // This will point to a static database of the supported codecs
int16_t codec_id_; int16_t codec_id_ GUARDED_BY(codec_wrapper_lock_);
// This will account for the number of samples were not encoded // This will account for the number of samples were not encoded
// the case is rare, either samples are missed due to overwrite // the case is rare, either samples are missed due to overwrite
// at input buffer or due to encoding error // at input buffer or due to encoding error
uint32_t num_missed_samples_; uint32_t num_missed_samples_ GUARDED_BY(codec_wrapper_lock_);
// True if the encoder instance created // True if the encoder instance created
bool encoder_exist_; bool encoder_exist_ GUARDED_BY(codec_wrapper_lock_);
// True if the encoder instance initialized // True if the encoder instance initialized
bool encoder_initialized_; bool encoder_initialized_ GUARDED_BY(codec_wrapper_lock_);
const bool registered_in_neteq_; // TODO(henrik.lundin) Remove? const bool registered_in_neteq_
GUARDED_BY(codec_wrapper_lock_); // TODO(henrik.lundin) Remove?
// VAD/DTX // VAD/DTX
bool has_internal_dtx_; bool has_internal_dtx_ GUARDED_BY(codec_wrapper_lock_);
WebRtcVadInst* ptr_vad_inst_ GUARDED_BY(codec_wrapper_lock_); WebRtcVadInst* ptr_vad_inst_ GUARDED_BY(codec_wrapper_lock_);
bool vad_enabled_ GUARDED_BY(codec_wrapper_lock_); bool vad_enabled_ GUARDED_BY(codec_wrapper_lock_);
ACMVADMode vad_mode_ GUARDED_BY(codec_wrapper_lock_); ACMVADMode vad_mode_ GUARDED_BY(codec_wrapper_lock_);
@@ -947,9 +961,9 @@ class ACMGenericCodec {
int16_t prev_frame_cng_ GUARDED_BY(codec_wrapper_lock_); int16_t prev_frame_cng_ GUARDED_BY(codec_wrapper_lock_);
// FEC. // FEC.
bool has_internal_fec_; bool has_internal_fec_ GUARDED_BY(codec_wrapper_lock_);
WebRtcACMCodecParams encoder_params_; WebRtcACMCodecParams encoder_params_ GUARDED_BY(codec_wrapper_lock_);
// Used as a global lock for all available decoders // Used as a global lock for all available decoders
// so that no decoder is used when NetEQ decodes. // so that no decoder is used when NetEQ decodes.

View File

@@ -29,14 +29,18 @@ class ACMILBC : public ACMGenericCodec {
// for FEC // for FEC
ACMGenericCodec* CreateInstance(void); ACMGenericCodec* CreateInstance(void);
int16_t InternalEncode(uint8_t* bitstream, int16_t* bitstream_len_byte); int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) OVERRIDE
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
int16_t InternalInitEncoder(WebRtcACMCodecParams* codec_params); int16_t InternalInitEncoder(WebRtcACMCodecParams* codec_params);
protected: protected:
int16_t SetBitRateSafe(const int32_t rate); int16_t SetBitRateSafe(const int32_t rate) OVERRIDE
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
void DestructEncoderSafe(); void DestructEncoderSafe() OVERRIDE
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
int16_t InternalCreateEncoder(); int16_t InternalCreateEncoder();

View File

@@ -694,7 +694,10 @@ int32_t ACMISAC::ConfigISACBandwidthEstimator(
"Couldn't config iSAC BWE."); "Couldn't config iSAC BWE.");
return -1; return -1;
} }
{
WriteLockScoped wl(codec_wrapper_lock_);
UpdateFrameLen(); UpdateFrameLen();
}
CriticalSectionScoped lock(codec_inst_crit_sect_.get()); CriticalSectionScoped lock(codec_inst_crit_sect_.get());
ACM_ISAC_GETSENDBITRATE(codec_inst_ptr_->inst, &isac_current_bn_); ACM_ISAC_GETSENDBITRATE(codec_inst_ptr_->inst, &isac_current_bn_);
return 0; return 0;
@@ -792,6 +795,7 @@ int ACMISAC::ErrorCode() {
AudioDecoder* ACMISAC::Decoder(int codec_id) { AudioDecoder* ACMISAC::Decoder(int codec_id) {
// Create iSAC instance if it does not exist. // Create iSAC instance if it does not exist.
WriteLockScoped wl(codec_wrapper_lock_);
if (!encoder_exist_) { if (!encoder_exist_) {
CriticalSectionScoped lock(codec_inst_crit_sect_.get()); CriticalSectionScoped lock(codec_inst_crit_sect_.get());
assert(codec_inst_ptr_->inst == NULL); assert(codec_inst_ptr_->inst == NULL);

View File

@@ -34,19 +34,23 @@ class ACMISAC : public ACMGenericCodec, AudioDecoder {
explicit ACMISAC(int16_t codec_id); explicit ACMISAC(int16_t codec_id);
~ACMISAC(); ~ACMISAC();
int16_t InternalInitDecoder(WebRtcACMCodecParams* codec_params); int16_t InternalInitDecoder(WebRtcACMCodecParams* codec_params)
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
// Methods below are inherited from ACMGenericCodec. // Methods below are inherited from ACMGenericCodec.
ACMGenericCodec* CreateInstance(void) OVERRIDE; ACMGenericCodec* CreateInstance(void) OVERRIDE;
int16_t InternalEncode(uint8_t* bitstream, int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) OVERRIDE; int16_t* bitstream_len_byte) OVERRIDE
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
int16_t InternalInitEncoder(WebRtcACMCodecParams* codec_params) OVERRIDE; int16_t InternalInitEncoder(WebRtcACMCodecParams* codec_params) OVERRIDE
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
int16_t UpdateDecoderSampFreq(int16_t codec_id) OVERRIDE; int16_t UpdateDecoderSampFreq(int16_t codec_id) OVERRIDE;
int16_t UpdateEncoderSampFreq(uint16_t samp_freq_hz) 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; int16_t EncoderSampFreq(uint16_t* samp_freq_hz) OVERRIDE;
@@ -95,12 +99,14 @@ class ACMISAC : public ACMGenericCodec, AudioDecoder {
int32_t rate, int32_t rate,
bool is_red); bool is_red);
void UpdateFrameLen(); void UpdateFrameLen() EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
// Methods below are inherited from ACMGenericCodec. // Methods below are inherited from ACMGenericCodec.
void DestructEncoderSafe() OVERRIDE; void DestructEncoderSafe() OVERRIDE
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
int16_t SetBitRateSafe(const int32_t bit_rate) OVERRIDE; int16_t SetBitRateSafe(const int32_t bit_rate) OVERRIDE
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
int32_t GetEstimatedBandwidthSafe() OVERRIDE; int32_t GetEstimatedBandwidthSafe() OVERRIDE;

View File

@@ -28,7 +28,9 @@ class ACMOpus : public ACMGenericCodec {
ACMGenericCodec* CreateInstance(void); ACMGenericCodec* CreateInstance(void);
int16_t InternalEncode(uint8_t* bitstream, int16_t* bitstream_len_byte); int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) OVERRIDE
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
int16_t InternalInitEncoder(WebRtcACMCodecParams *codec_params); int16_t InternalInitEncoder(WebRtcACMCodecParams *codec_params);
@@ -43,7 +45,8 @@ class ACMOpus : public ACMGenericCodec {
void InternalDestructEncoderInst(void* ptr_inst); void InternalDestructEncoderInst(void* ptr_inst);
int16_t SetBitRateSafe(const int32_t rate); int16_t SetBitRateSafe(const int32_t rate) OVERRIDE
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
WebRtcOpusEncInst* encoder_inst_ptr_; WebRtcOpusEncInst* encoder_inst_ptr_;
uint16_t sample_freq_; uint16_t sample_freq_;

View File

@@ -25,12 +25,15 @@ class ACMPCM16B : public ACMGenericCodec {
// For FEC. // For FEC.
ACMGenericCodec* CreateInstance(void); ACMGenericCodec* CreateInstance(void);
int16_t InternalEncode(uint8_t* bitstream, int16_t* bitstream_len_byte); int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) OVERRIDE
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
int16_t InternalInitEncoder(WebRtcACMCodecParams* codec_params); int16_t InternalInitEncoder(WebRtcACMCodecParams* codec_params);
protected: protected:
void DestructEncoderSafe(); void DestructEncoderSafe() OVERRIDE
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
int16_t InternalCreateEncoder(); int16_t InternalCreateEncoder();

View File

@@ -25,7 +25,9 @@ class ACMPCMA : public ACMGenericCodec {
// For FEC. // For FEC.
ACMGenericCodec* CreateInstance(void); ACMGenericCodec* CreateInstance(void);
int16_t InternalEncode(uint8_t* bitstream, int16_t* bitstream_len_byte); int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) OVERRIDE
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
int16_t InternalInitEncoder(WebRtcACMCodecParams* codec_params); int16_t InternalInitEncoder(WebRtcACMCodecParams* codec_params);

View File

@@ -25,12 +25,15 @@ class ACMPCMU : public ACMGenericCodec {
// For FEC. // For FEC.
ACMGenericCodec* CreateInstance(void); ACMGenericCodec* CreateInstance(void);
int16_t InternalEncode(uint8_t* bitstream, int16_t* bitstream_len_byte); int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) OVERRIDE
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
int16_t InternalInitEncoder(WebRtcACMCodecParams* codec_params); int16_t InternalInitEncoder(WebRtcACMCodecParams* codec_params);
protected: protected:
void DestructEncoderSafe(); void DestructEncoderSafe() OVERRIDE
EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
int16_t InternalCreateEncoder(); int16_t InternalCreateEncoder();