From 47b4b9d94cafb22e19bc8a6e6ca83b0568dcb973 Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Tue, 24 Jun 2014 05:51:34 +0000 Subject: 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/webrtc@6526 4adac7df-926f-26a2-2b94-8c16560cd09d --- modules/audio_coding/main/acm2/acm_cng.h | 3 +- modules/audio_coding/main/acm2/acm_g722.h | 7 ++- modules/audio_coding/main/acm2/acm_generic_codec.h | 72 +++++++++++++--------- modules/audio_coding/main/acm2/acm_ilbc.h | 10 ++- modules/audio_coding/main/acm2/acm_isac.cc | 6 +- modules/audio_coding/main/acm2/acm_isac.h | 20 +++--- modules/audio_coding/main/acm2/acm_opus.h | 7 ++- modules/audio_coding/main/acm2/acm_pcm16b.h | 7 ++- modules/audio_coding/main/acm2/acm_pcma.h | 4 +- modules/audio_coding/main/acm2/acm_pcmu.h | 7 ++- 10 files changed, 93 insertions(+), 50 deletions(-) (limited to 'modules') diff --git a/modules/audio_coding/main/acm2/acm_cng.h b/modules/audio_coding/main/acm2/acm_cng.h index a0c1c554..8b0a3928 100644 --- a/modules/audio_coding/main/acm2/acm_cng.h +++ b/modules/audio_coding/main/acm2/acm_cng.h @@ -35,7 +35,8 @@ class ACMCNG: public ACMGenericCodec { int16_t InternalInitEncoder(WebRtcACMCodecParams *codec_params); protected: - void DestructEncoderSafe(); + void DestructEncoderSafe() OVERRIDE + EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_); int16_t InternalCreateEncoder(); diff --git a/modules/audio_coding/main/acm2/acm_g722.h b/modules/audio_coding/main/acm2/acm_g722.h index 6197a9d9..6cdd79d4 100644 --- a/modules/audio_coding/main/acm2/acm_g722.h +++ b/modules/audio_coding/main/acm2/acm_g722.h @@ -33,7 +33,9 @@ class ACMG722 : public ACMGenericCodec { // For FEC. 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); @@ -44,7 +46,8 @@ class ACMG722 : public ACMGenericCodec { const uint8_t audio_channel) EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_); - void DestructEncoderSafe(); + void DestructEncoderSafe() OVERRIDE + EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_); int16_t InternalCreateEncoder(); diff --git a/modules/audio_coding/main/acm2/acm_generic_codec.h b/modules/audio_coding/main/acm2/acm_generic_codec.h index fa21ca01..d90e8fdd 100644 --- a/modules/audio_coding/main/acm2/acm_generic_codec.h +++ b/modules/audio_coding/main/acm2/acm_generic_codec.h @@ -312,7 +312,10 @@ class ACMGenericCodec { // true if the codec has an internal DTX, e.g. G729, // false otherwise. // - bool HasInternalDTX() const { return has_internal_dtx_; } + bool HasInternalDTX() const { + ReadLockScoped rl(codec_wrapper_lock_); + return has_internal_dtx_; + } /////////////////////////////////////////////////////////////////////////// // int32_t GetEstimatedBandwidth() @@ -436,7 +439,8 @@ 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); + virtual int16_t UpdateEncoderSampFreq(uint16_t samp_freq_hz) + EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_); /////////////////////////////////////////////////////////////////////////// // EncoderSampFreq() @@ -450,7 +454,8 @@ 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); + virtual int16_t EncoderSampFreq(uint16_t* samp_freq_hz) + SHARED_LOCKS_REQUIRED(codec_wrapper_lock_); /////////////////////////////////////////////////////////////////////////// // int32_t ConfigISACBandwidthEstimator() @@ -515,8 +520,6 @@ class ACMGenericCodec { // virtual int32_t SetISACMaxRate(const uint32_t max_rate_bps); - int32_t FrameSize() { return frame_len_smpl_; } - /////////////////////////////////////////////////////////////////////////// // REDPayloadISAC() // 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. // false otherwise. // - bool HasInternalFEC() const { return has_internal_fec_; } + bool HasInternalFEC() const { + ReadLockScoped rl(codec_wrapper_lock_); + return has_internal_fec_; + } /////////////////////////////////////////////////////////////////////////// // int SetFEC(); @@ -624,7 +630,8 @@ class ACMGenericCodec { // See EncoderParam() for the description of function, input(s)/output(s) // 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) @@ -651,7 +658,8 @@ class ACMGenericCodec { // See DestructEncoder() for the description of function, // 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) @@ -659,7 +667,8 @@ class ACMGenericCodec { // // 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, @@ -707,7 +716,7 @@ class ACMGenericCodec { // -1 if failed, // 0 if succeeded. // - int16_t CreateEncoder(); + int16_t CreateEncoder() EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_); /////////////////////////////////////////////////////////////////////////// // int16_t EnableVAD(); @@ -773,7 +782,8 @@ class ACMGenericCodec { // otherwise the length of the bit-stream is returned. // 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() @@ -794,7 +804,8 @@ class ACMGenericCodec { // -1 if failed, // 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() @@ -805,7 +816,8 @@ class ACMGenericCodec { // -num_samples : the number of overwritten samples is incremented // 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() @@ -849,7 +861,8 @@ class ACMGenericCodec { // -1 if failed, // 0 if succeeded. // - virtual int16_t InternalResetEncoder(); + virtual int16_t InternalResetEncoder() + EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_); /////////////////////////////////////////////////////////////////////////// // int16_t ProcessFrameVADDTX() @@ -900,41 +913,42 @@ class ACMGenericCodec { // &in_audio_[in_audio_ix_write_] always point to where new audio can be // 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 - 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, // To save memory the following buffer can be allocated // dynamically for 80 ms depending on the sampling frequency // of the codec. - int16_t* in_audio_; - uint32_t* in_timestamp_; + int16_t* in_audio_ GUARDED_BY(codec_wrapper_lock_); + uint32_t* in_timestamp_ GUARDED_BY(codec_wrapper_lock_); - int16_t frame_len_smpl_; - uint16_t num_channels_; + int16_t frame_len_smpl_ GUARDED_BY(codec_wrapper_lock_); + uint16_t num_channels_ GUARDED_BY(codec_wrapper_lock_); // 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 // the case is rare, either samples are missed due to overwrite // 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 - bool encoder_exist_; + bool encoder_exist_ GUARDED_BY(codec_wrapper_lock_); // 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 - bool has_internal_dtx_; + bool has_internal_dtx_ GUARDED_BY(codec_wrapper_lock_); WebRtcVadInst* ptr_vad_inst_ GUARDED_BY(codec_wrapper_lock_); bool vad_enabled_ 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_); // 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 // so that no decoder is used when NetEQ decodes. diff --git a/modules/audio_coding/main/acm2/acm_ilbc.h b/modules/audio_coding/main/acm2/acm_ilbc.h index fd6e8537..714c9004 100644 --- a/modules/audio_coding/main/acm2/acm_ilbc.h +++ b/modules/audio_coding/main/acm2/acm_ilbc.h @@ -29,14 +29,18 @@ class ACMILBC : public ACMGenericCodec { // for FEC 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); 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(); diff --git a/modules/audio_coding/main/acm2/acm_isac.cc b/modules/audio_coding/main/acm2/acm_isac.cc index 9fbcdd4c..2adae861 100644 --- a/modules/audio_coding/main/acm2/acm_isac.cc +++ b/modules/audio_coding/main/acm2/acm_isac.cc @@ -694,7 +694,10 @@ int32_t ACMISAC::ConfigISACBandwidthEstimator( "Couldn't config iSAC BWE."); return -1; } - UpdateFrameLen(); + { + WriteLockScoped wl(codec_wrapper_lock_); + UpdateFrameLen(); + } CriticalSectionScoped lock(codec_inst_crit_sect_.get()); ACM_ISAC_GETSENDBITRATE(codec_inst_ptr_->inst, &isac_current_bn_); return 0; @@ -792,6 +795,7 @@ int ACMISAC::ErrorCode() { AudioDecoder* ACMISAC::Decoder(int codec_id) { // Create iSAC instance if it does not exist. + WriteLockScoped wl(codec_wrapper_lock_); if (!encoder_exist_) { CriticalSectionScoped lock(codec_inst_crit_sect_.get()); assert(codec_inst_ptr_->inst == NULL); diff --git a/modules/audio_coding/main/acm2/acm_isac.h b/modules/audio_coding/main/acm2/acm_isac.h index 3249526f..31263c70 100644 --- a/modules/audio_coding/main/acm2/acm_isac.h +++ b/modules/audio_coding/main/acm2/acm_isac.h @@ -34,19 +34,23 @@ class ACMISAC : public ACMGenericCodec, AudioDecoder { explicit ACMISAC(int16_t codec_id); ~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. ACMGenericCodec* CreateInstance(void) OVERRIDE; 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 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; @@ -95,12 +99,14 @@ class ACMISAC : public ACMGenericCodec, AudioDecoder { int32_t rate, bool is_red); - void UpdateFrameLen(); + void UpdateFrameLen() EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_); // 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; diff --git a/modules/audio_coding/main/acm2/acm_opus.h b/modules/audio_coding/main/acm2/acm_opus.h index 07ce0721..b94adc47 100644 --- a/modules/audio_coding/main/acm2/acm_opus.h +++ b/modules/audio_coding/main/acm2/acm_opus.h @@ -28,7 +28,9 @@ class ACMOpus : public ACMGenericCodec { 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); @@ -43,7 +45,8 @@ class ACMOpus : public ACMGenericCodec { 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_; uint16_t sample_freq_; diff --git a/modules/audio_coding/main/acm2/acm_pcm16b.h b/modules/audio_coding/main/acm2/acm_pcm16b.h index 23b8c121..de4330d5 100644 --- a/modules/audio_coding/main/acm2/acm_pcm16b.h +++ b/modules/audio_coding/main/acm2/acm_pcm16b.h @@ -25,12 +25,15 @@ class ACMPCM16B : public ACMGenericCodec { // For FEC. 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); protected: - void DestructEncoderSafe(); + void DestructEncoderSafe() OVERRIDE + EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_); int16_t InternalCreateEncoder(); diff --git a/modules/audio_coding/main/acm2/acm_pcma.h b/modules/audio_coding/main/acm2/acm_pcma.h index 2da873cb..a2d8874a 100644 --- a/modules/audio_coding/main/acm2/acm_pcma.h +++ b/modules/audio_coding/main/acm2/acm_pcma.h @@ -25,7 +25,9 @@ class ACMPCMA : public ACMGenericCodec { // For FEC. 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); diff --git a/modules/audio_coding/main/acm2/acm_pcmu.h b/modules/audio_coding/main/acm2/acm_pcmu.h index 18d8279d..7aa83b75 100644 --- a/modules/audio_coding/main/acm2/acm_pcmu.h +++ b/modules/audio_coding/main/acm2/acm_pcmu.h @@ -25,12 +25,15 @@ class ACMPCMU : public ACMGenericCodec { // For FEC. 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); protected: - void DestructEncoderSafe(); + void DestructEncoderSafe() OVERRIDE + EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_); int16_t InternalCreateEncoder(); -- cgit v1.2.3