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
diff --git a/webrtc/modules/audio_coding/main/acm2/acm_cng.h b/webrtc/modules/audio_coding/main/acm2/acm_cng.h
index a0c1c55..8b0a392 100644
--- a/webrtc/modules/audio_coding/main/acm2/acm_cng.h
+++ b/webrtc/modules/audio_coding/main/acm2/acm_cng.h
@@ -35,7 +35,8 @@
   int16_t InternalInitEncoder(WebRtcACMCodecParams *codec_params);
 
  protected:
-  void DestructEncoderSafe();
+  void DestructEncoderSafe() OVERRIDE
+      EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
 
   int16_t InternalCreateEncoder();
 
diff --git a/webrtc/modules/audio_coding/main/acm2/acm_g722.h b/webrtc/modules/audio_coding/main/acm2/acm_g722.h
index 6197a9d..6cdd79d 100644
--- a/webrtc/modules/audio_coding/main/acm2/acm_g722.h
+++ b/webrtc/modules/audio_coding/main/acm2/acm_g722.h
@@ -33,7 +33,9 @@
   // 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 @@
                           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/webrtc/modules/audio_coding/main/acm2/acm_generic_codec.h b/webrtc/modules/audio_coding/main/acm2/acm_generic_codec.h
index fa21ca0..d90e8fd 100644
--- a/webrtc/modules/audio_coding/main/acm2/acm_generic_codec.h
+++ b/webrtc/modules/audio_coding/main/acm2/acm_generic_codec.h
@@ -312,7 +312,10 @@
   //   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 @@
   //   -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 @@
   //   -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 @@
   //
   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 @@
   //   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 @@
   // 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 @@
   // 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 @@
   //
   // 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 @@
   //   -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 @@
   //   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 @@
   //   -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 @@
   //   -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 @@
   //   -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 @@
 
   // &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 @@
   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/webrtc/modules/audio_coding/main/acm2/acm_ilbc.h b/webrtc/modules/audio_coding/main/acm2/acm_ilbc.h
index fd6e853..714c900 100644
--- a/webrtc/modules/audio_coding/main/acm2/acm_ilbc.h
+++ b/webrtc/modules/audio_coding/main/acm2/acm_ilbc.h
@@ -29,14 +29,18 @@
   // 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/webrtc/modules/audio_coding/main/acm2/acm_isac.cc b/webrtc/modules/audio_coding/main/acm2/acm_isac.cc
index 9fbcdd4..2adae86 100644
--- a/webrtc/modules/audio_coding/main/acm2/acm_isac.cc
+++ b/webrtc/modules/audio_coding/main/acm2/acm_isac.cc
@@ -694,7 +694,10 @@
                  "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 @@
 
 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/webrtc/modules/audio_coding/main/acm2/acm_isac.h b/webrtc/modules/audio_coding/main/acm2/acm_isac.h
index 3249526..31263c7 100644
--- a/webrtc/modules/audio_coding/main/acm2/acm_isac.h
+++ b/webrtc/modules/audio_coding/main/acm2/acm_isac.h
@@ -34,19 +34,23 @@
   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 @@
                     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/webrtc/modules/audio_coding/main/acm2/acm_opus.h b/webrtc/modules/audio_coding/main/acm2/acm_opus.h
index 07ce072..b94adc4 100644
--- a/webrtc/modules/audio_coding/main/acm2/acm_opus.h
+++ b/webrtc/modules/audio_coding/main/acm2/acm_opus.h
@@ -28,7 +28,9 @@
 
   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 @@
 
   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/webrtc/modules/audio_coding/main/acm2/acm_pcm16b.h b/webrtc/modules/audio_coding/main/acm2/acm_pcm16b.h
index 23b8c12..de4330d 100644
--- a/webrtc/modules/audio_coding/main/acm2/acm_pcm16b.h
+++ b/webrtc/modules/audio_coding/main/acm2/acm_pcm16b.h
@@ -25,12 +25,15 @@
   // 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/webrtc/modules/audio_coding/main/acm2/acm_pcma.h b/webrtc/modules/audio_coding/main/acm2/acm_pcma.h
index 2da873c..a2d8874 100644
--- a/webrtc/modules/audio_coding/main/acm2/acm_pcma.h
+++ b/webrtc/modules/audio_coding/main/acm2/acm_pcma.h
@@ -25,7 +25,9 @@
   // 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/webrtc/modules/audio_coding/main/acm2/acm_pcmu.h b/webrtc/modules/audio_coding/main/acm2/acm_pcmu.h
index 18d8279..7aa83b7 100644
--- a/webrtc/modules/audio_coding/main/acm2/acm_pcmu.h
+++ b/webrtc/modules/audio_coding/main/acm2/acm_pcmu.h
@@ -25,12 +25,15 @@
   // 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();