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 #include "webrtc/modules/audio_coding/main/acm2/acm_pcm16b.h" 12 13 #ifdef WEBRTC_CODEC_PCM16 14 #include "webrtc/modules/audio_coding/codecs/pcm16b/include/pcm16b.h" 15 #include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h" 16 #include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h" 17 #include "webrtc/system_wrappers/interface/trace.h" 18 #endif 19 20 namespace webrtc { 21 22 namespace acm2 { 23 24 #ifndef WEBRTC_CODEC_PCM16 25 26 ACMPCM16B::ACMPCM16B(int16_t /* codec_id */) { return; } 27 28 ACMPCM16B::~ACMPCM16B() { return; } 29 30 int16_t ACMPCM16B::InternalEncode(uint8_t* /* bitstream */, 31 int16_t* /* bitstream_len_byte */) { 32 return -1; 33 } 34 35 int16_t ACMPCM16B::InternalInitEncoder( 36 WebRtcACMCodecParams* /* codec_params */) { 37 return -1; 38 } 39 40 ACMGenericCodec* ACMPCM16B::CreateInstance(void) { return NULL; } 41 42 int16_t ACMPCM16B::InternalCreateEncoder() { return -1; } 43 44 void ACMPCM16B::InternalDestructEncoderInst(void* /* ptr_inst */) { return; } 45 46 void ACMPCM16B::DestructEncoderSafe() { return; } 47 48 #else //===================== Actual Implementation ======================= 49 ACMPCM16B::ACMPCM16B(int16_t codec_id) { 50 codec_id_ = codec_id; 51 sampling_freq_hz_ = ACMCodecDB::CodecFreq(codec_id_); 52 } 53 54 ACMPCM16B::~ACMPCM16B() { return; } 55 56 int16_t ACMPCM16B::InternalEncode(uint8_t* bitstream, 57 int16_t* bitstream_len_byte) { 58 *bitstream_len_byte = WebRtcPcm16b_Encode(&in_audio_[in_audio_ix_read_], 59 frame_len_smpl_ * num_channels_, 60 bitstream); 61 // Increment the read index to tell the caller that how far 62 // we have gone forward in reading the audio buffer. 63 in_audio_ix_read_ += frame_len_smpl_ * num_channels_; 64 return *bitstream_len_byte; 65 } 66 67 int16_t ACMPCM16B::InternalInitEncoder( 68 WebRtcACMCodecParams* /* codec_params */) { 69 // This codec does not need initialization, PCM has no instance. 70 return 0; 71 } 72 73 ACMGenericCodec* ACMPCM16B::CreateInstance(void) { return NULL; } 74 75 int16_t ACMPCM16B::InternalCreateEncoder() { 76 // PCM has no instance. 77 return 0; 78 } 79 80 void ACMPCM16B::InternalDestructEncoderInst(void* /* ptr_inst */) { 81 // PCM has no instance. 82 return; 83 } 84 85 void ACMPCM16B::DestructEncoderSafe() { 86 // PCM has no instance. 87 encoder_exist_ = false; 88 encoder_initialized_ = false; 89 return; 90 } 91 92 #endif 93 94 } // namespace acm2 95 96 } // namespace webrtc 97