Files
platform-external-webrtc/webrtc/modules/audio_coding/main/acm2/acm_gsmfr.cc
henrik.lundin@webrtc.org 3154a1cf9d Reland r8210 "Add a new parameter to ACMGenericCodec constructor""
This effectively reverts r8211.

The problem with r8210 was that the change in constructor signature was not done for other codec selections that then default one. That is, some code that was hidden under #ifdef did not get updated. This is now fixed.

BUG=4228
COAUTHOR=kwiberg@webrtc.org
TBR=minyue@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/37879004

Cr-Commit-Position: refs/heads/master@{#8215}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8215 4adac7df-926f-26a2-2b94-8c16560cd09d
2015-01-30 12:30:22 +00:00

155 lines
4.3 KiB
C++

/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/modules/audio_coding/main/acm2/acm_gsmfr.h"
#ifdef WEBRTC_CODEC_GSMFR
// NOTE! GSM-FR is not included in the open-source package. Modify this file
// or your codec API to match the function calls and names of used GSM-FR API
// file.
#include "webrtc/modules/audio_coding/main/codecs/gsmfr/interface/gsmfr_interface.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/system_wrappers/interface/trace.h"
#endif
namespace webrtc {
namespace acm2 {
#ifndef WEBRTC_CODEC_GSMFR
ACMGSMFR::ACMGSMFR(int16_t /* codec_id */, bool enable_red)
: ACMGenericCodec(enable_red), encoder_inst_ptr_(NULL) {
}
ACMGSMFR::~ACMGSMFR() { return; }
int16_t ACMGSMFR::InternalEncode(uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */) {
return -1;
}
int16_t ACMGSMFR::EnableDTX() { return -1; }
int16_t ACMGSMFR::DisableDTX() { return -1; }
int16_t ACMGSMFR::InternalInitEncoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
ACMGenericCodec* ACMGSMFR::CreateInstance(void) { return NULL; }
int16_t ACMGSMFR::InternalCreateEncoder() { return -1; }
void ACMGSMFR::DestructEncoderSafe() { return; }
#else //===================== Actual Implementation =======================
ACMGSMFR::ACMGSMFR(int16_t codec_id, bool enable_red)
: ACMGenericCodec(enable_red),
codec_id_(codec_id),
has_internal_dtx_(true),
encoder_inst_ptr_(NULL) {
}
ACMGSMFR::~ACMGSMFR() {
if (encoder_inst_ptr_ != NULL) {
WebRtcGSMFR_FreeEnc(encoder_inst_ptr_);
encoder_inst_ptr_ = NULL;
}
return;
}
int16_t ACMGSMFR::InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) {
*bitstream_len_byte = WebRtcGSMFR_Encode(
encoder_inst_ptr_, &in_audio_[in_audio_ix_read_], frame_len_smpl_,
reinterpret_cast<int16_t*>(bitstream));
// increment the read index this tell the caller that how far
// we have gone forward in reading the audio buffer
in_audio_ix_read_ += frame_len_smpl_;
return *bitstream_len_byte;
}
int16_t ACMGSMFR::EnableDTX() {
if (dtx_enabled_) {
return 0;
} else if (encoder_exist_) {
if (WebRtcGSMFR_EncoderInit(encoder_inst_ptr_, 1) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"EnableDTX: cannot init encoder for GSMFR");
return -1;
}
dtx_enabled_ = true;
return 0;
} else {
return -1;
}
}
int16_t ACMGSMFR::DisableDTX() {
if (!dtx_enabled_) {
return 0;
} else if (encoder_exist_) {
if (WebRtcGSMFR_EncoderInit(encoder_inst_ptr_, 0) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"DisableDTX: cannot init encoder for GSMFR");
return -1;
}
dtx_enabled_ = false;
return 0;
} else {
// encoder doesn't exists, therefore disabling is harmless
return 0;
}
}
int16_t ACMGSMFR::InternalInitEncoder(WebRtcACMCodecParams* codec_params) {
if (WebRtcGSMFR_EncoderInit(encoder_inst_ptr_,
((codec_params->enable_dtx) ? 1 : 0)) < 0) {
WEBRTC_TRACE(webrtc::kTraceError,
webrtc::kTraceAudioCoding,
unique_id_,
"InternalInitEncoder: cannot init encoder for GSMFR");
}
return 0;
}
ACMGenericCodec* ACMGSMFR::CreateInstance(void) { return NULL; }
int16_t ACMGSMFR::InternalCreateEncoder() {
if (WebRtcGSMFR_CreateEnc(&encoder_inst_ptr_) < 0) {
WEBRTC_TRACE(webrtc::kTraceError,
webrtc::kTraceAudioCoding,
unique_id_,
"InternalCreateEncoder: cannot create instance for GSMFR "
"encoder");
return -1;
}
return 0;
}
void ACMGSMFR::DestructEncoderSafe() {
if (encoder_inst_ptr_ != NULL) {
WebRtcGSMFR_FreeEnc(encoder_inst_ptr_);
encoder_inst_ptr_ = NULL;
}
encoder_exist_ = false;
encoder_initialized_ = false;
}
#endif
} // namespace acm2
} // namespace webrtc