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/modules/audio_coding/main/acm2/acm_generic_codec.h" 15 #include "webrtc/modules/audio_coding/neteq/interface/audio_decoder.h" 16 #include "webrtc/system_wrappers/interface/scoped_ptr.h" 17 #include "webrtc/system_wrappers/interface/thread_annotations.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 39 // Methods below are inherited from ACMGenericCodec. 40 ACMGenericCodec* CreateInstance(void) OVERRIDE; 41 42 int16_t InternalEncode(uint8_t* bitstream, 43 int16_t* bitstream_len_byte) OVERRIDE; 44 45 int16_t InternalInitEncoder(WebRtcACMCodecParams* codec_params) OVERRIDE; 46 47 int16_t UpdateDecoderSampFreq(int16_t codec_id) OVERRIDE; 48 49 int16_t UpdateEncoderSampFreq(uint16_t samp_freq_hz) OVERRIDE; 50 51 int16_t EncoderSampFreq(uint16_t* samp_freq_hz) OVERRIDE; 52 53 int32_t ConfigISACBandwidthEstimator(const uint8_t init_frame_size_msec, 54 const uint16_t init_rate_bit_per_sec, 55 const bool enforce_frame_size) OVERRIDE; 56 57 int32_t SetISACMaxPayloadSize(const uint16_t max_payload_len_bytes) OVERRIDE; 58 59 int32_t SetISACMaxRate(const uint32_t max_rate_bit_per_sec) OVERRIDE; 60 61 int16_t REDPayloadISAC(const int32_t isac_rate, 62 const int16_t isac_bw_estimate, 63 uint8_t* payload, 64 int16_t* payload_len_bytes) OVERRIDE; 65 66 // Methods below are inherited from AudioDecoder. 67 virtual int Decode(const uint8_t* encoded, 68 size_t encoded_len, 69 int16_t* decoded, 70 SpeechType* speech_type) OVERRIDE; 71 HasDecodePlc()72 virtual bool HasDecodePlc() const OVERRIDE { return true; } 73 74 virtual int DecodePlc(int num_frames, int16_t* decoded) OVERRIDE; 75 Init()76 virtual int Init() OVERRIDE { return 0; } 77 78 virtual int IncomingPacket(const uint8_t* payload, 79 size_t payload_len, 80 uint16_t rtp_sequence_number, 81 uint32_t rtp_timestamp, 82 uint32_t arrival_timestamp) OVERRIDE; 83 84 virtual int DecodeRedundant(const uint8_t* encoded, 85 size_t encoded_len, 86 int16_t* decoded, 87 SpeechType* speech_type) OVERRIDE; 88 89 virtual int ErrorCode() OVERRIDE; 90 91 protected: 92 int16_t Transcode(uint8_t* bitstream, 93 int16_t* bitstream_len_byte, 94 int16_t q_bwe, 95 int32_t rate, 96 bool is_red); 97 98 void UpdateFrameLen(); 99 100 // Methods below are inherited from ACMGenericCodec. 101 void DestructEncoderSafe() OVERRIDE; 102 103 int16_t SetBitRateSafe(const int32_t bit_rate) OVERRIDE; 104 105 int32_t GetEstimatedBandwidthSafe() OVERRIDE; 106 107 int32_t SetEstimatedBandwidthSafe(int32_t estimated_bandwidth) OVERRIDE; 108 109 int32_t GetRedPayloadSafe(uint8_t* red_payload, 110 int16_t* payload_bytes) OVERRIDE; 111 112 int16_t InternalCreateEncoder() OVERRIDE; 113 114 void InternalDestructEncoderInst(void* ptr_inst) OVERRIDE; 115 116 void CurrentRate(int32_t* rate_bit_per_sec) OVERRIDE; 117 118 virtual AudioDecoder* Decoder(int codec_id) OVERRIDE; 119 120 // |codec_inst_crit_sect_| protects |codec_inst_ptr_|. 121 const scoped_ptr<CriticalSectionWrapper> codec_inst_crit_sect_; 122 ACMISACInst* codec_inst_ptr_ GUARDED_BY(codec_inst_crit_sect_); 123 bool is_enc_initialized_; 124 IsacCodingMode isac_coding_mode_; 125 bool enforce_frame_size_; 126 int32_t isac_current_bn_; 127 uint16_t samples_in_10ms_audio_; 128 bool decoder_initialized_; 129 }; 130 131 } // namespace acm2 132 133 } // namespace webrtc 134 135 #endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_ACM2_ACM_ISAC_H_ 136