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 #include "webrtc/modules/audio_coding/main/acm2/acm_cng.h"
     12 
     13 #include "webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h"
     14 #include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h"
     15 #include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
     16 #include "webrtc/system_wrappers/interface/trace.h"
     17 
     18 namespace webrtc {
     19 
     20 namespace acm2 {
     21 
     22 ACMCNG::ACMCNG(int16_t codec_id) {
     23   encoder_inst_ptr_ = NULL;
     24   codec_id_ = codec_id;
     25   samp_freq_hz_ = ACMCodecDB::CodecFreq(codec_id_);
     26   return;
     27 }
     28 
     29 ACMCNG::~ACMCNG() {
     30   if (encoder_inst_ptr_ != NULL) {
     31     WebRtcCng_FreeEnc(encoder_inst_ptr_);
     32     encoder_inst_ptr_ = NULL;
     33   }
     34   return;
     35 }
     36 
     37 // CNG is not like a regular encoder, this function
     38 // should not be called normally
     39 // instead the following function is called from inside
     40 // ACMGenericCodec::ProcessFrameVADDTX
     41 int16_t ACMCNG::InternalEncode(uint8_t* /* bitstream */,
     42                                int16_t* /* bitstream_len_byte */) {
     43   return -1;
     44 }
     45 
     46 // CNG is not like a regular encoder,
     47 // this function should not be called normally
     48 // instead the following function is called from inside
     49 // ACMGenericCodec::ProcessFrameVADDTX
     50 int16_t ACMCNG::InternalInitEncoder(WebRtcACMCodecParams* /* codec_params */) {
     51   return -1;
     52 }
     53 
     54 ACMGenericCodec* ACMCNG::CreateInstance(void) { return NULL; }
     55 
     56 int16_t ACMCNG::InternalCreateEncoder() {
     57   if (WebRtcCng_CreateEnc(&encoder_inst_ptr_) < 0) {
     58     encoder_inst_ptr_ = NULL;
     59     return -1;
     60   } else {
     61     return 0;
     62   }
     63 }
     64 
     65 void ACMCNG::DestructEncoderSafe() {
     66   if (encoder_inst_ptr_ != NULL) {
     67     WebRtcCng_FreeEnc(encoder_inst_ptr_);
     68     encoder_inst_ptr_ = NULL;
     69   }
     70   encoder_exist_ = false;
     71   encoder_initialized_ = false;
     72 }
     73 
     74 }  // namespace acm2
     75 
     76 }  // namespace webrtc
     77