Home | History | Annotate | Download | only in acm2
      1 /*
      2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_ACM2_ACM_ISAC_H_
     12 #define WEBRTC_MODULES_AUDIO_CODING_MAIN_ACM2_ACM_ISAC_H_
     13 
     14 #include "webrtc/base/thread_annotations.h"
     15 #include "webrtc/modules/audio_coding/main/acm2/acm_generic_codec.h"
     16 #include "webrtc/modules/audio_coding/neteq/interface/audio_decoder.h"
     17 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
     18 
     19 namespace webrtc {
     20 
     21 class CriticalSectionWrapper;
     22 
     23 namespace acm2 {
     24 
     25 struct ACMISACInst;
     26 
     27 enum IsacCodingMode {
     28   ADAPTIVE,
     29   CHANNEL_INDEPENDENT
     30 };
     31 
     32 class ACMISAC : public ACMGenericCodec, AudioDecoder {
     33  public:
     34   explicit ACMISAC(int16_t codec_id);
     35   ~ACMISAC();
     36 
     37   int16_t InternalInitDecoder(WebRtcACMCodecParams* codec_params)
     38       EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
     39 
     40   // Methods below are inherited from ACMGenericCodec.
     41   ACMGenericCodec* CreateInstance(void) OVERRIDE;
     42 
     43   int16_t InternalEncode(uint8_t* bitstream,
     44                          int16_t* bitstream_len_byte) OVERRIDE
     45       EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
     46 
     47   int16_t InternalInitEncoder(WebRtcACMCodecParams* codec_params) OVERRIDE
     48       EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
     49 
     50   int16_t UpdateDecoderSampFreq(int16_t codec_id) OVERRIDE;
     51 
     52   int16_t UpdateEncoderSampFreq(uint16_t samp_freq_hz) OVERRIDE
     53       EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
     54 
     55   int16_t EncoderSampFreq(uint16_t* samp_freq_hz) OVERRIDE;
     56 
     57   int32_t ConfigISACBandwidthEstimator(const uint8_t init_frame_size_msec,
     58                                        const uint16_t init_rate_bit_per_sec,
     59                                        const bool enforce_frame_size) OVERRIDE;
     60 
     61   int32_t SetISACMaxPayloadSize(const uint16_t max_payload_len_bytes) OVERRIDE;
     62 
     63   int32_t SetISACMaxRate(const uint32_t max_rate_bit_per_sec) OVERRIDE;
     64 
     65   int16_t REDPayloadISAC(const int32_t isac_rate,
     66                          const int16_t isac_bw_estimate,
     67                          uint8_t* payload,
     68                          int16_t* payload_len_bytes) OVERRIDE;
     69 
     70   // Methods below are inherited from AudioDecoder.
     71   virtual int Decode(const uint8_t* encoded,
     72                      size_t encoded_len,
     73                      int16_t* decoded,
     74                      SpeechType* speech_type) OVERRIDE;
     75 
     76   virtual bool HasDecodePlc() const OVERRIDE { return true; }
     77 
     78   virtual int DecodePlc(int num_frames, int16_t* decoded) OVERRIDE;
     79 
     80   virtual int Init() OVERRIDE { return 0; }
     81 
     82   virtual int IncomingPacket(const uint8_t* payload,
     83                              size_t payload_len,
     84                              uint16_t rtp_sequence_number,
     85                              uint32_t rtp_timestamp,
     86                              uint32_t arrival_timestamp) OVERRIDE;
     87 
     88   virtual int DecodeRedundant(const uint8_t* encoded,
     89                               size_t encoded_len,
     90                               int16_t* decoded,
     91                               SpeechType* speech_type) OVERRIDE;
     92 
     93   virtual int ErrorCode() OVERRIDE;
     94 
     95  protected:
     96   int16_t Transcode(uint8_t* bitstream,
     97                     int16_t* bitstream_len_byte,
     98                     int16_t q_bwe,
     99                     int32_t rate,
    100                     bool is_red);
    101 
    102   void UpdateFrameLen() EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
    103 
    104   // Methods below are inherited from ACMGenericCodec.
    105   void DestructEncoderSafe() OVERRIDE
    106       EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
    107 
    108   int16_t SetBitRateSafe(const int32_t bit_rate) OVERRIDE
    109       EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
    110 
    111   int32_t GetEstimatedBandwidthSafe() OVERRIDE;
    112 
    113   int32_t SetEstimatedBandwidthSafe(int32_t estimated_bandwidth) OVERRIDE;
    114 
    115   int32_t GetRedPayloadSafe(uint8_t* red_payload,
    116                             int16_t* payload_bytes) OVERRIDE;
    117 
    118   int16_t InternalCreateEncoder() OVERRIDE;
    119 
    120   void CurrentRate(int32_t* rate_bit_per_sec) OVERRIDE;
    121 
    122   virtual AudioDecoder* Decoder(int codec_id) OVERRIDE;
    123 
    124   // |codec_inst_crit_sect_| protects |codec_inst_ptr_|.
    125   const scoped_ptr<CriticalSectionWrapper> codec_inst_crit_sect_;
    126   ACMISACInst* codec_inst_ptr_ GUARDED_BY(codec_inst_crit_sect_);
    127   bool is_enc_initialized_;
    128   IsacCodingMode isac_coding_mode_;
    129   bool enforce_frame_size_;
    130   int32_t isac_current_bn_;
    131   uint16_t samples_in_10ms_audio_;
    132   bool decoder_initialized_;
    133 };
    134 
    135 }  // namespace acm2
    136 
    137 }  // namespace webrtc
    138 
    139 #endif  // WEBRTC_MODULES_AUDIO_CODING_MAIN_ACM2_ACM_ISAC_H_
    140