Deleting all ACM1 files

ACM1 is deprecated and replaced by ACM2
(webrtc/modules/audio_coding/acm2/).

BUG=2996
R=turaj@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6115 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
henrik.lundin@webrtc.org 2014-05-13 08:08:56 +00:00
parent 46e636a3f5
commit 3a5825909d
55 changed files with 0 additions and 17424 deletions

View File

@ -1,67 +0,0 @@
# Copyright (c) 2011 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.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include $(LOCAL_PATH)/../../../../../android-webrtc.mk
LOCAL_ARM_MODE := arm
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_MODULE := libwebrtc_audio_coding
LOCAL_MODULE_TAGS := optional
LOCAL_CPP_EXTENSION := .cc
LOCAL_SRC_FILES := \
acm_cng.cc \
acm_codec_database.cc \
acm_dtmf_detection.cc \
acm_dtmf_playout.cc \
acm_g722.cc \
acm_generic_codec.cc \
acm_ilbc.cc \
acm_isac.cc \
acm_neteq.cc \
acm_pcm16b.cc \
acm_pcma.cc \
acm_pcmu.cc \
acm_red.cc \
acm_resampler.cc \
audio_coding_module.cc \
audio_coding_module_impl.cc
# Flags passed to both C and C++ files.
LOCAL_CFLAGS := \
$(MY_WEBRTC_COMMON_DEFS)
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/../interface \
$(LOCAL_PATH)/../../codecs/cng/include \
$(LOCAL_PATH)/../../codecs/g711/include \
$(LOCAL_PATH)/../../codecs/g722/include \
$(LOCAL_PATH)/../../codecs/ilbc/interface \
$(LOCAL_PATH)/../../codecs/iSAC/main/interface \
$(LOCAL_PATH)/../../codecs/iSAC/fix/interface \
$(LOCAL_PATH)/../../codecs/pcm16b/include \
$(LOCAL_PATH)/../../neteq/interface \
$(LOCAL_PATH)/../../../.. \
$(LOCAL_PATH)/../../../interface \
$(LOCAL_PATH)/../../../../common_audio/resampler/include \
$(LOCAL_PATH)/../../../../common_audio/signal_processing/include \
$(LOCAL_PATH)/../../../../common_audio/vad/include \
$(LOCAL_PATH)/../../../../system_wrappers/interface
LOCAL_SHARED_LIBRARIES := \
libcutils \
libdl \
libstlport
ifndef NDK_ROOT
include external/stlport/libstlport.mk
endif
include $(BUILD_STATIC_LIBRARY)

View File

@ -1,5 +0,0 @@
# These are for the common case of adding or renaming files. If you're doing
# structural changes, please get a review from a reviewer in this file.
per-file *.gyp=*
per-file *.gypi=*

View File

@ -1,430 +0,0 @@
/*
* 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/source/acm_amr.h"
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
#include "webrtc/system_wrappers/interface/rw_lock_wrapper.h"
#include "webrtc/system_wrappers/interface/trace.h"
#ifdef WEBRTC_CODEC_AMR
// NOTE! GSM AMR is not included in the open-source package. The following
// interface file is needed:
//
// /modules/audio_coding/codecs/amr/main/interface/amr_interface.h
//
// The API in the header file should match the one below.
//
// int16_t WebRtcAmr_CreateEnc(AMR_encinst_t_** enc_inst);
// int16_t WebRtcAmr_CreateDec(AMR_decinst_t_** dec_inst);
// int16_t WebRtcAmr_FreeEnc(AMR_encinst_t_* enc_inst);
// int16_t WebRtcAmr_FreeDec(AMR_decinst_t_* dec_inst);
// int16_t WebRtcAmr_Encode(AMR_encinst_t_* enc_inst,
// int16_t* input,
// int16_t len,
// int16_t*output,
// int16_t mode);
// int16_t WebRtcAmr_EncoderInit(AMR_encinst_t_* enc_inst,
// int16_t dtx_mode);
// int16_t WebRtcAmr_EncodeBitmode(AMR_encinst_t_* enc_inst,
// int format);
// int16_t WebRtcAmr_Decode(AMR_decinst_t_* dec_inst);
// int16_t WebRtcAmr_DecodePlc(AMR_decinst_t_* dec_inst);
// int16_t WebRtcAmr_DecoderInit(AMR_decinst_t_* dec_inst);
// int16_t WebRtcAmr_DecodeBitmode(AMR_decinst_t_* dec_inst,
// int format);
#include "amr_interface.h"
#endif
namespace webrtc {
namespace acm1 {
#ifndef WEBRTC_CODEC_AMR
ACMAMR::ACMAMR(int16_t /* codec_id */)
: encoder_inst_ptr_(NULL),
decoder_inst_ptr_(NULL),
encoding_mode_(-1), // Invalid value.
encoding_rate_(0), // Invalid value.
encoder_packing_format_(AMRBandwidthEfficient),
decoder_packing_format_(AMRBandwidthEfficient) {
return;
}
ACMAMR::~ACMAMR() {
return;
}
int16_t ACMAMR::InternalEncode(uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */) {
return -1;
}
int16_t ACMAMR::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return -1;
}
int16_t ACMAMR::EnableDTX() {
return -1;
}
int16_t ACMAMR::DisableDTX() {
return -1;
}
int16_t ACMAMR::InternalInitEncoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int16_t ACMAMR::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int32_t ACMAMR::CodecDef(WebRtcNetEQ_CodecDef& /* codec_def */,
const CodecInst& /* codec_inst */) {
return -1;
}
ACMGenericCodec* ACMAMR::CreateInstance(void) {
return NULL;
}
int16_t ACMAMR::InternalCreateEncoder() {
return -1;
}
void ACMAMR::DestructEncoderSafe() {
return;
}
int16_t ACMAMR::InternalCreateDecoder() {
return -1;
}
void ACMAMR::DestructDecoderSafe() {
return;
}
int16_t ACMAMR::SetBitRateSafe(const int32_t /* rate */) {
return -1;
}
void ACMAMR::InternalDestructEncoderInst(void* /* ptr_inst */) {
return;
}
int16_t ACMAMR::SetAMREncoderPackingFormat(
ACMAMRPackingFormat /* packing_format */) {
return -1;
}
ACMAMRPackingFormat ACMAMR::AMREncoderPackingFormat() const {
return AMRUndefined;
}
int16_t ACMAMR::SetAMRDecoderPackingFormat(
ACMAMRPackingFormat /* packing_format */) {
return -1;
}
ACMAMRPackingFormat ACMAMR::AMRDecoderPackingFormat() const {
return AMRUndefined;
}
#else //===================== Actual Implementation =======================
#define WEBRTC_AMR_MR475 0
#define WEBRTC_AMR_MR515 1
#define WEBRTC_AMR_MR59 2
#define WEBRTC_AMR_MR67 3
#define WEBRTC_AMR_MR74 4
#define WEBRTC_AMR_MR795 5
#define WEBRTC_AMR_MR102 6
#define WEBRTC_AMR_MR122 7
ACMAMR::ACMAMR(int16_t codec_id)
: encoder_inst_ptr_(NULL),
decoder_inst_ptr_(NULL),
encoding_mode_(-1), // invalid value
encoding_rate_(0) { // invalid value
codec_id_ = codec_id;
has_internal_dtx_ = true;
encoder_packing_format_ = AMRBandwidthEfficient;
decoder_packing_format_ = AMRBandwidthEfficient;
return;
}
ACMAMR::~ACMAMR() {
if (encoder_inst_ptr_ != NULL) {
WebRtcAmr_FreeEnc(encoder_inst_ptr_);
encoder_inst_ptr_ = NULL;
}
if (decoder_inst_ptr_ != NULL) {
WebRtcAmr_FreeDec(decoder_inst_ptr_);
decoder_inst_ptr_ = NULL;
}
return;
}
int16_t ACMAMR::InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) {
int16_t vad_decision = 1;
// sanity check, if the rate is set correctly. we might skip this
// sanity check. if rate is not set correctly, initialization flag
// should be false and should not be here.
if ((encoding_mode_ < WEBRTC_AMR_MR475) ||
(encoding_mode_ > WEBRTC_AMR_MR122)) {
*bitstream_len_byte = 0;
return -1;
}
*bitstream_len_byte = WebRtcAmr_Encode(encoder_inst_ptr_,
&in_audio_[in_audio_ix_read_],
frame_len_smpl_,
(int16_t*)bitstream,
encoding_mode_);
// Update VAD, if internal DTX is used
if (has_internal_dtx_ && dtx_enabled_) {
if (*bitstream_len_byte <= (7 * frame_len_smpl_ / 160)) {
vad_decision = 0;
}
for (int16_t n = 0; n < MAX_FRAME_SIZE_10MSEC; n++) {
vad_label_[n] = vad_decision;
}
}
// increment the read index
in_audio_ix_read_ += frame_len_smpl_;
return *bitstream_len_byte;
}
int16_t ACMAMR::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return 0;
}
int16_t ACMAMR::EnableDTX() {
if (dtx_enabled_) {
return 0;
} else if (encoder_exist_) { // check if encoder exist
// enable DTX
if (WebRtcAmr_EncoderInit(encoder_inst_ptr_, 1) < 0) {
return -1;
}
dtx_enabled_ = true;
return 0;
} else {
return -1;
}
}
int16_t ACMAMR::DisableDTX() {
if (!dtx_enabled_) {
return 0;
} else if (encoder_exist_) { // check if encoder exist
// disable DTX
if (WebRtcAmr_EncoderInit(encoder_inst_ptr_, 0) < 0) {
return -1;
}
dtx_enabled_ = false;
return 0;
} else {
// encoder doesn't exists, therefore disabling is harmless
return 0;
}
}
int16_t ACMAMR::InternalInitEncoder(WebRtcACMCodecParams* codec_params) {
int16_t status = SetBitRateSafe((codec_params->codec_inst).rate);
status += (WebRtcAmr_EncoderInit(
encoder_inst_ptr_, ((codec_params->enable_dtx) ? 1 : 0)) < 0) ? -1 : 0;
status += (WebRtcAmr_EncodeBitmode(
encoder_inst_ptr_, encoder_packing_format_) < 0) ? -1 : 0;
return (status < 0) ? -1 : 0;
}
int16_t ACMAMR::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
int16_t status =
((WebRtcAmr_DecoderInit(decoder_inst_ptr_) < 0) ? -1 : 0);
status += WebRtcAmr_DecodeBitmode(decoder_inst_ptr_, decoder_packing_format_);
return (status < 0) ? -1 : 0;
}
int32_t ACMAMR::CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) {
if (!decoder_initialized_) {
// Todo:
// log error
return -1;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_AMR_FUNCTION."
// Then call NetEQ to add the codec to it's
// database.
SET_CODEC_PAR((codec_def), kDecoderAMR, codec_inst.pltype, decoder_inst_ptr_,
8000);
SET_AMR_FUNCTIONS((codec_def));
return 0;
}
ACMGenericCodec* ACMAMR::CreateInstance(void) {
return NULL;
}
int16_t ACMAMR::InternalCreateEncoder() {
return WebRtcAmr_CreateEnc(&encoder_inst_ptr_);
}
void ACMAMR::DestructEncoderSafe() {
if (encoder_inst_ptr_ != NULL) {
WebRtcAmr_FreeEnc(encoder_inst_ptr_);
encoder_inst_ptr_ = NULL;
}
// there is no encoder set the following
encoder_exist_ = false;
encoder_initialized_ = false;
encoding_mode_ = -1; // invalid value
encoding_rate_ = 0; // invalid value
}
int16_t ACMAMR::InternalCreateDecoder() {
return WebRtcAmr_CreateDec(&decoder_inst_ptr_);
}
void ACMAMR::DestructDecoderSafe() {
if (decoder_inst_ptr_ != NULL) {
WebRtcAmr_FreeDec(decoder_inst_ptr_);
decoder_inst_ptr_ = NULL;
}
// there is no encoder instance set the followings
decoder_exist_ = false;
decoder_initialized_ = false;
}
int16_t ACMAMR::SetBitRateSafe(const int32_t rate) {
switch (rate) {
case 4750: {
encoding_mode_ = WEBRTC_AMR_MR475;
encoding_rate_ = 4750;
break;
}
case 5150: {
encoding_mode_ = WEBRTC_AMR_MR515;
encoding_rate_ = 5150;
break;
}
case 5900: {
encoding_mode_ = WEBRTC_AMR_MR59;
encoding_rate_ = 5900;
break;
}
case 6700: {
encoding_mode_ = WEBRTC_AMR_MR67;
encoding_rate_ = 6700;
break;
}
case 7400: {
encoding_mode_ = WEBRTC_AMR_MR74;
encoding_rate_ = 7400;
break;
}
case 7950: {
encoding_mode_ = WEBRTC_AMR_MR795;
encoding_rate_ = 7950;
break;
}
case 10200: {
encoding_mode_ = WEBRTC_AMR_MR102;
encoding_rate_ = 10200;
break;
}
case 12200: {
encoding_mode_ = WEBRTC_AMR_MR122;
encoding_rate_ = 12200;
break;
}
default: {
return -1;
}
}
return 0;
}
void ACMAMR::InternalDestructEncoderInst(void* ptr_inst) {
// Free the memory where ptr_inst is pointing to
if (ptr_inst != NULL) {
WebRtcAmr_FreeEnc(reinterpret_cast<AMR_encinst_t_*>(ptr_inst));
}
return;
}
int16_t ACMAMR::SetAMREncoderPackingFormat(
ACMAMRPackingFormat packing_format) {
if ((packing_format != AMRBandwidthEfficient) &&
(packing_format != AMROctetAlligned) &&
(packing_format != AMRFileStorage)) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Invalid AMR Encoder packing-format.");
return -1;
} else {
if (WebRtcAmr_EncodeBitmode(encoder_inst_ptr_, packing_format) < 0) {
return -1;
} else {
encoder_packing_format_ = packing_format;
return 0;
}
}
}
ACMAMRPackingFormat ACMAMR::AMREncoderPackingFormat() const {
return encoder_packing_format_;
}
int16_t ACMAMR::SetAMRDecoderPackingFormat(
ACMAMRPackingFormat packing_format) {
if ((packing_format != AMRBandwidthEfficient) &&
(packing_format != AMROctetAlligned) &&
(packing_format != AMRFileStorage)) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Invalid AMR decoder packing-format.");
return -1;
} else {
if (WebRtcAmr_DecodeBitmode(decoder_inst_ptr_, packing_format) < 0) {
return -1;
} else {
decoder_packing_format_ = packing_format;
return 0;
}
}
}
ACMAMRPackingFormat ACMAMR::AMRDecoderPackingFormat() const {
return decoder_packing_format_;
}
#endif
} // namespace acm1
} // namespace webrtc

View File

@ -1,87 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_AMR_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_AMR_H_
#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
// forward declaration
struct AMR_encinst_t_;
struct AMR_decinst_t_;
namespace webrtc {
namespace acm1 {
class ACMAMR : public ACMGenericCodec {
public:
explicit ACMAMR(int16_t codec_id);
virtual ~ACMAMR();
// for FEC
virtual ACMGenericCodec* CreateInstance(void) OVERRIDE;
virtual int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) OVERRIDE;
virtual int16_t InternalInitEncoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
virtual int16_t InternalInitDecoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
int16_t SetAMREncoderPackingFormat(const ACMAMRPackingFormat packing_format);
ACMAMRPackingFormat AMREncoderPackingFormat() const;
int16_t SetAMRDecoderPackingFormat(const ACMAMRPackingFormat packing_format);
ACMAMRPackingFormat AMRDecoderPackingFormat() const;
protected:
virtual int16_t DecodeSafe(uint8_t* bitstream,
int16_t bitstream_len_byte,
int16_t* audio,
int16_t* audio_samples,
int8_t* speech_type) OVERRIDE;
virtual int32_t CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) OVERRIDE;
virtual void DestructEncoderSafe() OVERRIDE;
virtual void DestructDecoderSafe() OVERRIDE;
virtual int16_t InternalCreateEncoder() OVERRIDE;
virtual int16_t InternalCreateDecoder() OVERRIDE;
virtual void InternalDestructEncoderInst(void* ptr_inst) OVERRIDE;
virtual int16_t SetBitRateSafe(const int32_t rate) OVERRIDE;
virtual int16_t EnableDTX() OVERRIDE;
virtual int16_t DisableDTX() OVERRIDE;
AMR_encinst_t_* encoder_inst_ptr_;
AMR_decinst_t_* decoder_inst_ptr_;
int16_t encoding_mode_;
int16_t encoding_rate_;
ACMAMRPackingFormat encoder_packing_format_;
ACMAMRPackingFormat decoder_packing_format_;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_AMR_H_

View File

@ -1,436 +0,0 @@
/*
* 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/source/acm_amrwb.h"
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
#include "webrtc/system_wrappers/interface/rw_lock_wrapper.h"
#include "webrtc/system_wrappers/interface/trace.h"
#ifdef WEBRTC_CODEC_AMRWB
// NOTE! GSM AMR-wb is not included in the open-source package. The
// following interface file is needed:
//
// /modules/audio_coding/codecs/amrwb/main/interface/amrwb_interface.h
//
// The API in the header file should match the one below.
//
// int16_t WebRtcAmrWb_CreateEnc(AMRWB_encinst_t_** enc_inst);
// int16_t WebRtcAmrWb_CreateDec(AMRWB_decinst_t_** dec_inst);
// int16_t WebRtcAmrWb_FreeEnc(AMRWB_encinst_t_* enc_inst);
// int16_t WebRtcAmrWb_FreeDec(AMRWB_decinst_t_* dec_inst);
// int16_t WebRtcAmrWb_Encode(AMRWB_encinst_t_* enc_inst, int16_t* input,
// int16_t len, int16_t* output, int16_t mode);
// int16_t WebRtcAmrWb_EncoderInit(AMRWB_encinst_t_* enc_inst,
// int16_t dtx_mode);
// int16_t WebRtcAmrWb_EncodeBitmode(AMRWB_encinst_t_* enc_inst,
// int format);
// int16_t WebRtcAmrWb_Decode(AMRWB_decinst_t_* dec_inst);
// int16_t WebRtcAmrWb_DecodePlc(AMRWB_decinst_t_* dec_inst);
// int16_t WebRtcAmrWb_DecoderInit(AMRWB_decinst_t_* dec_inst);
// int16_t WebRtcAmrWb_DecodeBitmode(AMRWB_decinst_t_* dec_inst,
// int format);
#include "amrwb_interface.h"
#endif
namespace webrtc {
namespace acm1 {
#ifndef WEBRTC_CODEC_AMRWB
ACMAMRwb::ACMAMRwb(int16_t /* codec_id */)
: encoder_inst_ptr_(NULL),
decoder_inst_ptr_(NULL),
encoding_mode_(-1), // invalid value
encoding_rate_(0), // invalid value
encoder_packing_format_(AMRBandwidthEfficient),
decoder_packing_format_(AMRBandwidthEfficient) {
}
ACMAMRwb::~ACMAMRwb() {
}
int16_t ACMAMRwb::InternalEncode(
uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */) {
return -1;
}
int16_t ACMAMRwb::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return -1;
}
int16_t ACMAMRwb::EnableDTX() {
return -1;
}
int16_t ACMAMRwb::DisableDTX() {
return -1;
}
int16_t ACMAMRwb::InternalInitEncoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int16_t ACMAMRwb::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int32_t ACMAMRwb::CodecDef(WebRtcNetEQ_CodecDef& /* codec_def */,
const CodecInst& /* codec_inst */) {
return -1;
}
ACMGenericCodec*
ACMAMRwb::CreateInstance(void) {
return NULL;
}
int16_t ACMAMRwb::InternalCreateEncoder() {
return -1;
}
void ACMAMRwb::DestructEncoderSafe() {
return;
}
int16_t ACMAMRwb::InternalCreateDecoder() {
return -1;
}
void ACMAMRwb::DestructDecoderSafe() {
return;
}
int16_t ACMAMRwb::SetBitRateSafe(const int32_t /* rate */) {
return -1;
}
void ACMAMRwb::InternalDestructEncoderInst(void* /* ptr_inst */) {
return;
}
int16_t ACMAMRwb::SetAMRwbEncoderPackingFormat(
ACMAMRPackingFormat /* packing_format */) {
return -1;
}
ACMAMRPackingFormat ACMAMRwb::AMRwbEncoderPackingFormat() const {
return AMRUndefined;
}
int16_t ACMAMRwb::SetAMRwbDecoderPackingFormat(
ACMAMRPackingFormat /* packing_format */) {
return -1;
}
ACMAMRPackingFormat ACMAMRwb::AMRwbDecoderPackingFormat() const {
return AMRUndefined;
}
#else //===================== Actual Implementation =======================
#define AMRWB_MODE_7k 0
#define AMRWB_MODE_9k 1
#define AMRWB_MODE_12k 2
#define AMRWB_MODE_14k 3
#define AMRWB_MODE_16k 4
#define AMRWB_MODE_18k 5
#define AMRWB_MODE_20k 6
#define AMRWB_MODE_23k 7
#define AMRWB_MODE_24k 8
ACMAMRwb::ACMAMRwb(int16_t codec_id)
: encoder_inst_ptr_(NULL),
decoder_inst_ptr_(NULL),
encoding_mode_(-1), // invalid value
encoding_rate_(0) { // invalid value
codec_id_ = codec_id;
has_internal_dtx_ = true;
encoder_packing_format_ = AMRBandwidthEfficient;
decoder_packing_format_ = AMRBandwidthEfficient;
return;
}
ACMAMRwb::~ACMAMRwb() {
if (encoder_inst_ptr_ != NULL) {
WebRtcAmrWb_FreeEnc(encoder_inst_ptr_);
encoder_inst_ptr_ = NULL;
}
if (decoder_inst_ptr_ != NULL) {
WebRtcAmrWb_FreeDec(decoder_inst_ptr_);
decoder_inst_ptr_ = NULL;
}
return;
}
int16_t ACMAMRwb::InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) {
int16_t vad_decision = 1;
// sanity check, if the rate is set correctly. we might skip this
// sanity check. if rate is not set correctly, initialization flag
// should be false and should not be here.
if ((encoding_mode_ < AMRWB_MODE_7k) || (encoding_mode_ > AMRWB_MODE_24k)) {
*bitstream_len_byte = 0;
return -1;
}
*bitstream_len_byte = WebRtcAmrWb_Encode(encoder_inst_ptr_,
&in_audio_[in_audio_ix_read_],
frame_len_smpl_,
(int16_t*)bitstream,
encoding_mode_);
// Update VAD, if internal DTX is used
if (has_internal_dtx_ && dtx_enabled_) {
if (*bitstream_len_byte <= (7 * frame_len_smpl_ / 160)) {
vad_decision = 0;
}
for (int16_t n = 0; n < MAX_FRAME_SIZE_10MSEC; n++) {
vad_label_[n] = vad_decision;
}
}
// 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 ACMAMRwb::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return 0;
}
int16_t ACMAMRwb::EnableDTX() {
if (dtx_enabled_) {
return 0;
} else if (encoder_exist_) { // check if encoder exist
// enable DTX
if (WebRtcAmrWb_EncoderInit(encoder_inst_ptr_, 1) < 0) {
return -1;
}
dtx_enabled_ = true;
return 0;
} else {
return -1;
}
}
int16_t ACMAMRwb::DisableDTX() {
if (!dtx_enabled_) {
return 0;
} else if (encoder_exist_) { // check if encoder exist
// disable DTX
if (WebRtcAmrWb_EncoderInit(encoder_inst_ptr_, 0) < 0) {
return -1;
}
dtx_enabled_ = false;
return 0;
} else {
// encoder doesn't exists, therefore disabling is harmless
return 0;
}
}
int16_t ACMAMRwb::InternalInitEncoder(
WebRtcACMCodecParams* codec_params) {
// sanity check
if (encoder_inst_ptr_ == NULL) {
return -1;
}
int16_t status = SetBitRateSafe((codec_params->codec_inst).rate);
status += (WebRtcAmrWb_EncoderInit(
encoder_inst_ptr_, ((codec_params->enable_dtx) ? 1 : 0)) < 0) ? -1 : 0;
status += (WebRtcAmrWb_EncodeBitmode(
encoder_inst_ptr_, encoder_packing_format_) < 0) ? -1 : 0;
return (status < 0) ? -1 : 0;
}
int16_t ACMAMRwb::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
int16_t status = WebRtcAmrWb_DecodeBitmode(decoder_inst_ptr_,
decoder_packing_format_);
status += ((WebRtcAmrWb_DecoderInit(decoder_inst_ptr_) < 0) ? -1 : 0);
return (status < 0) ? -1 : 0;
}
int32_t ACMAMRwb::CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) {
if (!decoder_initialized_) {
return -1;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_AMRWB_FUNCTION."
// Then call NetEQ to add the codec to it's
// database.
SET_CODEC_PAR((codec_def), kDecoderAMRWB, codec_inst.pltype,
decoder_inst_ptr_, 16000);
SET_AMRWB_FUNCTIONS((codec_def));
return 0;
}
ACMGenericCodec* ACMAMRwb::CreateInstance(void) {
return NULL;
}
int16_t ACMAMRwb::InternalCreateEncoder() {
return WebRtcAmrWb_CreateEnc(&encoder_inst_ptr_);
}
void ACMAMRwb::DestructEncoderSafe() {
if (encoder_inst_ptr_ != NULL) {
WebRtcAmrWb_FreeEnc(encoder_inst_ptr_);
encoder_inst_ptr_ = NULL;
}
// there is no encoder set the following
encoder_exist_ = false;
encoder_initialized_ = false;
encoding_mode_ = -1; // invalid value
encoding_rate_ = 0;
}
int16_t ACMAMRwb::InternalCreateDecoder() {
return WebRtcAmrWb_CreateDec(&decoder_inst_ptr_);
}
void ACMAMRwb::DestructDecoderSafe() {
if (decoder_inst_ptr_ != NULL) {
WebRtcAmrWb_FreeDec(decoder_inst_ptr_);
decoder_inst_ptr_ = NULL;
}
// there is no encoder instance set the followings
decoder_exist_ = false;
decoder_initialized_ = false;
}
int16_t ACMAMRwb::SetBitRateSafe(const int32_t rate) {
switch (rate) {
case 7000: {
encoding_mode_ = AMRWB_MODE_7k;
encoding_rate_ = 7000;
break;
}
case 9000: {
encoding_mode_ = AMRWB_MODE_9k;
encoding_rate_ = 9000;
break;
}
case 12000: {
encoding_mode_ = AMRWB_MODE_12k;
encoding_rate_ = 12000;
break;
}
case 14000: {
encoding_mode_ = AMRWB_MODE_14k;
encoding_rate_ = 14000;
break;
}
case 16000: {
encoding_mode_ = AMRWB_MODE_16k;
encoding_rate_ = 16000;
break;
}
case 18000: {
encoding_mode_ = AMRWB_MODE_18k;
encoding_rate_ = 18000;
break;
}
case 20000: {
encoding_mode_ = AMRWB_MODE_20k;
encoding_rate_ = 20000;
break;
}
case 23000: {
encoding_mode_ = AMRWB_MODE_23k;
encoding_rate_ = 23000;
break;
}
case 24000: {
encoding_mode_ = AMRWB_MODE_24k;
encoding_rate_ = 24000;
break;
}
default: {
return -1;
}
}
return 0;
}
void ACMAMRwb::InternalDestructEncoderInst(void* ptr_inst) {
if (ptr_inst != NULL) {
WebRtcAmrWb_FreeEnc(static_cast<AMRWB_encinst_t_*>(ptr_inst));
}
return;
}
int16_t ACMAMRwb::SetAMRwbEncoderPackingFormat(
ACMAMRPackingFormat packing_format) {
if ((packing_format != AMRBandwidthEfficient) &&
(packing_format != AMROctetAlligned) &&
(packing_format != AMRFileStorage)) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Invalid AMRwb encoder packing-format.");
return -1;
} else {
if (WebRtcAmrWb_EncodeBitmode(encoder_inst_ptr_, packing_format) < 0) {
return -1;
} else {
encoder_packing_format_ = packing_format;
return 0;
}
}
}
ACMAMRPackingFormat ACMAMRwb::AMRwbEncoderPackingFormat() const {
return encoder_packing_format_;
}
int16_t ACMAMRwb::SetAMRwbDecoderPackingFormat(
ACMAMRPackingFormat packing_format) {
if ((packing_format != AMRBandwidthEfficient) &&
(packing_format != AMROctetAlligned) &&
(packing_format != AMRFileStorage)) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Invalid AMRwb decoder packing-format.");
return -1;
} else {
if (WebRtcAmrWb_DecodeBitmode(decoder_inst_ptr_, packing_format) < 0) {
return -1;
} else {
decoder_packing_format_ = packing_format;
return 0;
}
}
}
ACMAMRPackingFormat ACMAMRwb::AMRwbDecoderPackingFormat() const {
return decoder_packing_format_;
}
#endif
} // namespace acm1
} // namespace webrtc

View File

@ -1,90 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_AMRWB_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_AMRWB_H_
#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
// forward declaration
struct AMRWB_encinst_t_;
struct AMRWB_decinst_t_;
namespace webrtc {
namespace acm1 {
class ACMAMRwb : public ACMGenericCodec {
public:
explicit ACMAMRwb(int16_t codec_id);
virtual ~ACMAMRwb();
// for FEC
virtual ACMGenericCodec* CreateInstance(void) OVERRIDE;
virtual int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) OVERRIDE;
virtual int16_t InternalInitEncoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
virtual int16_t InternalInitDecoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
virtual int16_t SetAMRwbEncoderPackingFormat(
const ACMAMRPackingFormat packing_format);
virtual ACMAMRPackingFormat AMRwbEncoderPackingFormat() const;
virtual int16_t SetAMRwbDecoderPackingFormat(
const ACMAMRPackingFormat packing_format);
virtual ACMAMRPackingFormat AMRwbDecoderPackingFormat() const;
protected:
virtual int16_t DecodeSafe(uint8_t* bitstream,
int16_t bitstream_len_byte,
int16_t* audio,
int16_t* audio_samples,
int8_t* speech_type) OVERRIDE;
virtual int32_t CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) OVERRIDE;
virtual void DestructEncoderSafe() OVERRIDE;
virtual void DestructDecoderSafe() OVERRIDE;
virtual int16_t InternalCreateEncoder() OVERRIDE;
virtual int16_t InternalCreateDecoder() OVERRIDE;
virtual void InternalDestructEncoderInst(void* ptr_inst) OVERRIDE;
virtual int16_t SetBitRateSafe(const int32_t rate) OVERRIDE;
virtual int16_t EnableDTX() OVERRIDE;
virtual int16_t DisableDTX() OVERRIDE;
AMRWB_encinst_t_* encoder_inst_ptr_;
AMRWB_decinst_t_* decoder_inst_ptr_;
int16_t encoding_mode_;
int16_t encoding_rate_;
ACMAMRPackingFormat encoder_packing_format_;
ACMAMRPackingFormat decoder_packing_format_;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_AMRWB_H_

View File

@ -1,339 +0,0 @@
/*
* 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/source/acm_celt.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
#include "webrtc/system_wrappers/interface/trace.h"
#ifdef WEBRTC_CODEC_CELT
// NOTE! Celt is not included in the open-source package. Modify this file or
// your codec API to match the function call and name of used Celt API file.
#include "celt_interface.h"
#endif
namespace webrtc {
namespace acm1 {
#ifndef WEBRTC_CODEC_CELT
ACMCELT::ACMCELT(int16_t /* codec_id */)
: enc_inst_ptr_(NULL),
dec_inst_ptr_(NULL),
sampling_freq_(0),
bitrate_(0),
channels_(1),
dec_channels_(1) {
return;
}
ACMCELT::~ACMCELT() {
return;
}
int16_t ACMCELT::InternalEncode(uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */) {
return -1;
}
int16_t ACMCELT::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return -1;
}
int16_t ACMCELT::InternalInitEncoder(WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int16_t ACMCELT::InternalInitDecoder(WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int32_t ACMCELT::CodecDef(WebRtcNetEQ_CodecDef& /* codec_def */,
const CodecInst& /* codec_inst */) {
return -1;
}
ACMGenericCodec* ACMCELT::CreateInstance(void) {
return NULL;
}
int16_t ACMCELT::InternalCreateEncoder() {
return -1;
}
void ACMCELT::DestructEncoderSafe() {
return;
}
int16_t ACMCELT::InternalCreateDecoder() {
return -1;
}
void ACMCELT::DestructDecoderSafe() {
return;
}
void ACMCELT::InternalDestructEncoderInst(void* /* ptr_inst */) {
return;
}
bool ACMCELT::IsTrueStereoCodec() {
return true;
}
int16_t ACMCELT::SetBitRateSafe(const int32_t /*rate*/) {
return -1;
}
void ACMCELT::SplitStereoPacket(uint8_t* /*payload*/,
int32_t* /*payload_length*/) {}
#else //===================== Actual Implementation =======================
ACMCELT::ACMCELT(int16_t codec_id)
: enc_inst_ptr_(NULL),
dec_inst_ptr_(NULL),
sampling_freq_(32000), // Default sampling frequency.
bitrate_(64000), // Default rate.
channels_(1), // Default send mono.
dec_channels_(1) { // Default receive mono.
// TODO(tlegrand): remove later when ACMGenericCodec has a new constructor.
codec_id_ = codec_id;
return;
}
ACMCELT::~ACMCELT() {
if (enc_inst_ptr_ != NULL) {
WebRtcCelt_FreeEnc(enc_inst_ptr_);
enc_inst_ptr_ = NULL;
}
if (dec_inst_ptr_ != NULL) {
WebRtcCelt_FreeDec(dec_inst_ptr_);
dec_inst_ptr_ = NULL;
}
return;
}
int16_t ACMCELT::InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) {
*bitstream_len_byte = 0;
// Call Encoder.
*bitstream_len_byte = WebRtcCelt_Encode(enc_inst_ptr_,
&in_audio_[in_audio_ix_read_],
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_ * channels_;
if (*bitstream_len_byte < 0) {
// Error reported from the encoder.
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalEncode: Encode error for Celt");
*bitstream_len_byte = 0;
return -1;
}
return *bitstream_len_byte;
}
int16_t ACMCELT::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return 0;
}
int16_t ACMCELT::InternalInitEncoder(WebRtcACMCodecParams* codec_params) {
// Set bitrate and check that it is within the valid range.
int16_t status = SetBitRateSafe((codec_params->codec_inst).rate);
if (status < 0) {
return -1;
}
// If number of channels changed we need to re-create memory.
if (codec_params->codec_inst.channels != channels_) {
WebRtcCelt_FreeEnc(enc_inst_ptr_);
enc_inst_ptr_ = NULL;
// Store new number of channels.
channels_ = codec_params->codec_inst.channels;
if (WebRtcCelt_CreateEnc(&enc_inst_ptr_, channels_) < 0) {
return -1;
}
}
// Initiate encoder.
if (WebRtcCelt_EncoderInit(enc_inst_ptr_, channels_, bitrate_) >= 0) {
return 0;
} else {
return -1;
}
}
int16_t ACMCELT::InternalInitDecoder(WebRtcACMCodecParams* codec_params) {
// If number of channels changed we need to re-create memory.
if (codec_params->codec_inst.channels != dec_channels_) {
WebRtcCelt_FreeDec(dec_inst_ptr_);
dec_inst_ptr_ = NULL;
// Store new number of channels.
dec_channels_ = codec_params->codec_inst.channels;
if (WebRtcCelt_CreateDec(&dec_inst_ptr_, dec_channels_) < 0) {
return -1;
}
}
// Initiate decoder, both master and slave parts.
if (WebRtcCelt_DecoderInit(dec_inst_ptr_) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalInitDecoder: init decoder failed for Celt.");
return -1;
}
if (WebRtcCelt_DecoderInitSlave(dec_inst_ptr_) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalInitDecoder: init decoder failed for Celt.");
return -1;
}
return 0;
}
int32_t ACMCELT::CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) {
if (!decoder_initialized_) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"CodecDef: Decoder uninitialized for Celt");
return -1;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" and "SET_CELT_FUNCTIONS" or "SET_CELTSLAVE_FUNCTIONS".
// Then call NetEQ to add the codec to it's
// database.
if (codec_inst.channels == 1) {
SET_CODEC_PAR(codec_def, kDecoderCELT_32, codec_inst.pltype, dec_inst_ptr_,
32000);
} else {
SET_CODEC_PAR(codec_def, kDecoderCELT_32_2ch, codec_inst.pltype,
dec_inst_ptr_, 32000);
}
// If this is the master of NetEQ, regular decoder will be added, otherwise
// the slave decoder will be used.
if (is_master_) {
SET_CELT_FUNCTIONS(codec_def);
} else {
SET_CELTSLAVE_FUNCTIONS(codec_def);
}
return 0;
}
ACMGenericCodec* ACMCELT::CreateInstance(void) {
return NULL;
}
int16_t ACMCELT::InternalCreateEncoder() {
if (WebRtcCelt_CreateEnc(&enc_inst_ptr_, num_channels_) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalCreateEncoder: create encoder failed for Celt");
return -1;
}
channels_ = num_channels_;
return 0;
}
void ACMCELT::DestructEncoderSafe() {
encoder_exist_ = false;
encoder_initialized_ = false;
if (enc_inst_ptr_ != NULL) {
WebRtcCelt_FreeEnc(enc_inst_ptr_);
enc_inst_ptr_ = NULL;
}
}
int16_t ACMCELT::InternalCreateDecoder() {
if (WebRtcCelt_CreateDec(&dec_inst_ptr_, dec_channels_) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalCreateDecoder: create decoder failed for Celt");
return -1;
}
return 0;
}
void ACMCELT::DestructDecoderSafe() {
decoder_exist_ = false;
decoder_initialized_ = false;
if (dec_inst_ptr_ != NULL) {
WebRtcCelt_FreeDec(dec_inst_ptr_);
dec_inst_ptr_ = NULL;
}
}
void ACMCELT::InternalDestructEncoderInst(void* ptr_inst) {
if (ptr_inst != NULL) {
WebRtcCelt_FreeEnc(static_cast<CELT_encinst_t*>(ptr_inst));
}
return;
}
bool ACMCELT::IsTrueStereoCodec() {
return true;
}
int16_t ACMCELT::SetBitRateSafe(const int32_t rate) {
// Check that rate is in the valid range.
if ((rate >= 48000) && (rate <= 128000)) {
// Store new rate.
bitrate_ = rate;
// Initiate encoder with new rate.
if (WebRtcCelt_EncoderInit(enc_inst_ptr_, channels_, bitrate_) >= 0) {
return 0;
} else {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"SetBitRateSafe: Failed to initiate Celt with rate %d",
rate);
return -1;
}
} else {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"SetBitRateSafe: Invalid rate Celt, %d", rate);
return -1;
}
}
// Copy the stereo packet so that NetEq will insert into both master and slave.
void ACMCELT::SplitStereoPacket(uint8_t* payload, int32_t* payload_length) {
// Check for valid inputs.
assert(payload != NULL);
assert(*payload_length > 0);
// Duplicate the payload.
memcpy(&payload[*payload_length], &payload[0],
sizeof(uint8_t) * (*payload_length));
// Double the size of the packet.
*payload_length *= 2;
}
#endif
} // namespace acm1
} // namespace webrtc

View File

@ -1,79 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_CELT_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_CELT_H_
#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
// forward declaration
struct CELT_encinst_t_;
struct CELT_decinst_t_;
namespace webrtc {
namespace acm1 {
class ACMCELT : public ACMGenericCodec {
public:
explicit ACMCELT(int16_t codec_id);
virtual ~ACMCELT();
virtual ACMGenericCodec* CreateInstance(void) OVERRIDE;
virtual int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) OVERRIDE;
virtual int16_t InternalInitEncoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
virtual int16_t InternalInitDecoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
protected:
virtual int16_t DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) OVERRIDE;
virtual int32_t CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) OVERRIDE;
virtual void DestructEncoderSafe() OVERRIDE;
virtual void DestructDecoderSafe() OVERRIDE;
virtual int16_t InternalCreateEncoder() OVERRIDE;
virtual int16_t InternalCreateDecoder() OVERRIDE;
virtual void InternalDestructEncoderInst(void* ptr_inst) OVERRIDE;
virtual bool IsTrueStereoCodec() OVERRIDE;
virtual int16_t SetBitRateSafe(const int32_t rate) OVERRIDE;
virtual void SplitStereoPacket(uint8_t* payload,
int32_t* payload_length) OVERRIDE;
CELT_encinst_t_* enc_inst_ptr_;
CELT_decinst_t_* dec_inst_ptr_;
uint16_t sampling_freq_;
int32_t bitrate_;
uint16_t channels_;
uint16_t dec_channels_;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_CELT_H_

View File

@ -1,150 +0,0 @@
/*
* 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/source/acm_cng.h"
#include "webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h"
#include "webrtc/modules/audio_coding/main/source/acm_codec_database.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
#include "webrtc/system_wrappers/interface/trace.h"
namespace webrtc {
namespace acm1 {
ACMCNG::ACMCNG(int16_t codec_id) {
encoder_inst_ptr_ = NULL;
decoder_inst_ptr_ = NULL;
codec_id_ = codec_id;
samp_freq_hz_ = ACMCodecDB::CodecFreq(codec_id_);
return;
}
ACMCNG::~ACMCNG() {
if (encoder_inst_ptr_ != NULL) {
WebRtcCng_FreeEnc(encoder_inst_ptr_);
encoder_inst_ptr_ = NULL;
}
if (decoder_inst_ptr_ != NULL) {
WebRtcCng_FreeDec(decoder_inst_ptr_);
decoder_inst_ptr_ = NULL;
}
return;
}
// CNG is not like a regular encoder, this function
// should not be called normally
// instead the following function is called from inside
// ACMGenericCodec::ProcessFrameVADDTX
int16_t ACMCNG::InternalEncode(uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */) {
return -1;
}
int16_t ACMCNG::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return 0;
}
// CNG is not like a regular encoder,
// this function should not be called normally
// instead the following function is called from inside
// ACMGenericCodec::ProcessFrameVADDTX
int16_t ACMCNG::InternalInitEncoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int16_t ACMCNG::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
return WebRtcCng_InitDec(decoder_inst_ptr_);
}
int32_t ACMCNG::CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) {
if (!decoder_initialized_) {
// TODO(tlegrand): log error
return -1;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_CNG_FUNCTION."
// Then return the structure back to NetEQ to add the codec to it's
// database.
if (samp_freq_hz_ == 8000 || samp_freq_hz_ == 16000 ||
samp_freq_hz_ == 32000 || samp_freq_hz_ == 48000) {
SET_CODEC_PAR((codec_def), kDecoderCNG, codec_inst.pltype,
decoder_inst_ptr_, samp_freq_hz_);
SET_CNG_FUNCTIONS((codec_def));
return 0;
} else {
return -1;
}
}
ACMGenericCodec* ACMCNG::CreateInstance(void) {
return NULL;
}
int16_t ACMCNG::InternalCreateEncoder() {
if (WebRtcCng_CreateEnc(&encoder_inst_ptr_) < 0) {
encoder_inst_ptr_ = NULL;
return -1;
} else {
return 0;
}
}
void ACMCNG::DestructEncoderSafe() {
if (encoder_inst_ptr_ != NULL) {
WebRtcCng_FreeEnc(encoder_inst_ptr_);
encoder_inst_ptr_ = NULL;
}
encoder_exist_ = false;
encoder_initialized_ = false;
}
int16_t ACMCNG::InternalCreateDecoder() {
if (WebRtcCng_CreateDec(&decoder_inst_ptr_) < 0) {
decoder_inst_ptr_ = NULL;
return -1;
} else {
return 0;
}
}
void ACMCNG::DestructDecoderSafe() {
if (decoder_inst_ptr_ != NULL) {
WebRtcCng_FreeDec(decoder_inst_ptr_);
decoder_inst_ptr_ = NULL;
}
decoder_exist_ = false;
decoder_initialized_ = false;
}
void ACMCNG::InternalDestructEncoderInst(void* ptr_inst) {
if (ptr_inst != NULL) {
WebRtcCng_FreeEnc(static_cast<CNG_enc_inst*>(ptr_inst));
}
return;
}
int16_t ACMCNG::EnableDTX() { return -1; }
int16_t ACMCNG::DisableDTX() { return -1; }
} // namespace acm1
} // namespace webrtc

View File

@ -1,73 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_CNG_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_CNG_H_
#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
// forward declaration
struct WebRtcCngEncInst;
struct WebRtcCngDecInst;
namespace webrtc {
namespace acm1 {
class ACMCNG: public ACMGenericCodec {
public:
explicit ACMCNG(int16_t codec_id);
virtual ~ACMCNG();
// for FEC
virtual ACMGenericCodec* CreateInstance(void) OVERRIDE;
virtual int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) OVERRIDE;
virtual int16_t InternalInitEncoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
virtual int16_t InternalInitDecoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
protected:
virtual int16_t DecodeSafe(uint8_t* bitstream,
int16_t bitstream_len_byte,
int16_t* audio,
int16_t* audio_samples,
int8_t* speech_type) OVERRIDE;
virtual int32_t CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) OVERRIDE;
virtual void DestructEncoderSafe() OVERRIDE;
virtual void DestructDecoderSafe() OVERRIDE;
virtual int16_t InternalCreateEncoder() OVERRIDE;
virtual int16_t InternalCreateDecoder() OVERRIDE;
virtual void InternalDestructEncoderInst(void* ptr_inst) OVERRIDE;
virtual int16_t EnableDTX() OVERRIDE;
virtual int16_t DisableDTX() OVERRIDE;
WebRtcCngEncInst* encoder_inst_ptr_;
WebRtcCngDecInst* decoder_inst_ptr_;
uint16_t samp_freq_hz_;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_CNG_H_

View File

@ -1,956 +0,0 @@
/*
* 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.
*/
/*
* This file generates databases with information about all supported audio
* codecs.
*/
// TODO(tlegrand): Change constant input pointers in all functions to constant
// references, where appropriate.
#include "webrtc/modules/audio_coding/main/source/acm_codec_database.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/system_wrappers/interface/trace.h"
// Includes needed to create the codecs.
// G.711, PCM mu-law and A-law.
#include "webrtc/modules/audio_coding/codecs/g711/include/g711_interface.h"
#include "webrtc/modules/audio_coding/main/source/acm_pcma.h"
#include "webrtc/modules/audio_coding/main/source/acm_pcmu.h"
// CNG.
#include "webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h"
#include "webrtc/modules/audio_coding/main/source/acm_cng.h"
// NetEQ.
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
#ifdef WEBRTC_CODEC_ISAC
#include "webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h"
#endif
#ifdef WEBRTC_CODEC_ISACFX
#include "webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h"
#endif
#if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX))
#include "webrtc/modules/audio_coding/main/source/acm_isac.h"
#include "webrtc/modules/audio_coding/main/source/acm_isac_macros.h"
#endif
#ifdef WEBRTC_CODEC_PCM16
#include "webrtc/modules/audio_coding/codecs/pcm16b/include/pcm16b.h"
#include "webrtc/modules/audio_coding/main/source/acm_pcm16b.h"
#endif
#ifdef WEBRTC_CODEC_ILBC
#include "webrtc/modules/audio_coding/codecs/ilbc/interface/ilbc.h"
#include "webrtc/modules/audio_coding/main/source/acm_ilbc.h"
#endif
#ifdef WEBRTC_CODEC_AMR
#include "webrtc/modules/audio_coding/codecs/amr/include/amr_interface.h"
#include "webrtc/modules/audio_coding/main/source/acm_amr.h"
#endif
#ifdef WEBRTC_CODEC_AMRWB
#include "webrtc/modules/audio_coding/codecs/amrwb/include/amrwb_interface.h"
#include "webrtc/modules/audio_coding/main/source/acm_amrwb.h"
#endif
#ifdef WEBRTC_CODEC_CELT
#include "webrtc/modules/audio_coding/codecs/celt/include/celt_interface.h"
#include "webrtc/modules/audio_coding/main/source/acm_celt.h"
#endif
#ifdef WEBRTC_CODEC_G722
#include "webrtc/modules/audio_coding/codecs/g722/include/g722_interface.h"
#include "webrtc/modules/audio_coding/main/source/acm_g722.h"
#endif
#ifdef WEBRTC_CODEC_G722_1
#include "webrtc/modules/audio_coding/codecs/g7221/include/g7221_interface.h"
#include "webrtc/modules/audio_coding/main/source/acm_g7221.h"
#endif
#ifdef WEBRTC_CODEC_G722_1C
#include "webrtc/modules/audio_coding/codecs/g7221c/include/g7221c_interface.h"
#include "webrtc/modules/audio_coding/main/source/acm_g7221c.h"
#endif
#ifdef WEBRTC_CODEC_G729
#include "webrtc/modules/audio_coding/codecs/g729/include/g729_interface.h"
#include "webrtc/modules/audio_coding/main/source/acm_g729.h"
#endif
#ifdef WEBRTC_CODEC_G729_1
#include "webrtc/modules/audio_coding/codecs/g7291/include/g7291_interface.h"
#include "webrtc/modules/audio_coding/main/source/acm_g7291.h"
#endif
#ifdef WEBRTC_CODEC_GSMFR
#include "webrtc/modules/audio_coding/codecs/gsmfr/include/gsmfr_interface.h"
#include "webrtc/modules/audio_coding/main/source/acm_gsmfr.h"
#endif
#ifdef WEBRTC_CODEC_OPUS
#include "webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h"
#include "webrtc/modules/audio_coding/main/source/acm_opus.h"
#endif
#ifdef WEBRTC_CODEC_SPEEX
#include "webrtc/modules/audio_coding/codecs/speex/include/speex_interface.h"
#include "webrtc/modules/audio_coding/main/source/acm_speex.h"
#endif
#ifdef WEBRTC_CODEC_AVT
#include "webrtc/modules/audio_coding/main/source/acm_dtmf_playout.h"
#endif
#ifdef WEBRTC_CODEC_RED
#include "webrtc/modules/audio_coding/main/source/acm_red.h"
#endif
namespace webrtc {
namespace acm1 {
// Not yet used payload-types.
// 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68,
// 67, 66, 65
const CodecInst ACMCodecDB::database_[] = {
#if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX))
{103, "ISAC", 16000, kIsacPacSize480, 1, kIsacWbDefaultRate},
# if (defined(WEBRTC_CODEC_ISAC))
{104, "ISAC", 32000, kIsacPacSize960, 1, kIsacSwbDefaultRate},
{105, "ISAC", 48000, kIsacPacSize1440, 1, kIsacSwbDefaultRate},
# endif
#endif
#ifdef WEBRTC_CODEC_PCM16
// Mono
{107, "L16", 8000, 80, 1, 128000},
{108, "L16", 16000, 160, 1, 256000},
{109, "L16", 32000, 320, 1, 512000},
// Stereo
{111, "L16", 8000, 80, 2, 128000},
{112, "L16", 16000, 160, 2, 256000},
{113, "L16", 32000, 320, 2, 512000},
#endif
// G.711, PCM mu-law and A-law.
// Mono
{0, "PCMU", 8000, 160, 1, 64000},
{8, "PCMA", 8000, 160, 1, 64000},
// Stereo
{110, "PCMU", 8000, 160, 2, 64000},
{118, "PCMA", 8000, 160, 2, 64000},
#ifdef WEBRTC_CODEC_ILBC
{102, "ILBC", 8000, 240, 1, 13300},
#endif
#ifdef WEBRTC_CODEC_AMR
{114, "AMR", 8000, 160, 1, 12200},
#endif
#ifdef WEBRTC_CODEC_AMRWB
{115, "AMR-WB", 16000, 320, 1, 20000},
#endif
#ifdef WEBRTC_CODEC_CELT
// Mono
{116, "CELT", 32000, 640, 1, 64000},
// Stereo
{117, "CELT", 32000, 640, 2, 64000},
#endif
#ifdef WEBRTC_CODEC_G722
// Mono
{9, "G722", 16000, 320, 1, 64000},
// Stereo
{119, "G722", 16000, 320, 2, 64000},
#endif
#ifdef WEBRTC_CODEC_G722_1
{92, "G7221", 16000, 320, 1, 32000},
{91, "G7221", 16000, 320, 1, 24000},
{90, "G7221", 16000, 320, 1, 16000},
#endif
#ifdef WEBRTC_CODEC_G722_1C
{89, "G7221", 32000, 640, 1, 48000},
{88, "G7221", 32000, 640, 1, 32000},
{87, "G7221", 32000, 640, 1, 24000},
#endif
#ifdef WEBRTC_CODEC_G729
{18, "G729", 8000, 240, 1, 8000},
#endif
#ifdef WEBRTC_CODEC_G729_1
{86, "G7291", 16000, 320, 1, 32000},
#endif
#ifdef WEBRTC_CODEC_GSMFR
{3, "GSM", 8000, 160, 1, 13200},
#endif
#ifdef WEBRTC_CODEC_OPUS
// Opus internally supports 48, 24, 16, 12, 8 kHz.
// Mono and stereo.
{120, "opus", 48000, 960, 2, 64000},
#endif
#ifdef WEBRTC_CODEC_SPEEX
{85, "speex", 8000, 160, 1, 11000},
{84, "speex", 16000, 320, 1, 22000},
#endif
// Comfort noise for four different sampling frequencies.
{13, "CN", 8000, 240, 1, 0},
{98, "CN", 16000, 480, 1, 0},
{99, "CN", 32000, 960, 1, 0},
#ifdef ENABLE_48000_HZ
{100, "CN", 48000, 1440, 1, 0},
#endif
#ifdef WEBRTC_CODEC_AVT
{106, "telephone-event", 8000, 240, 1, 0},
#endif
#ifdef WEBRTC_CODEC_RED
{127, "red", 8000, 0, 1, 0},
#endif
// To prevent compile errors due to trailing commas.
{-1, "Null", -1, -1, -1, -1}
};
// Create database with all codec settings at compile time.
// Each entry needs the following parameters in the given order:
// Number of allowed packet sizes, a vector with the allowed packet sizes,
// Basic block samples, max number of channels that are supported.
const ACMCodecDB::CodecSettings ACMCodecDB::codec_settings_[] = {
#if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX))
{2, {kIsacPacSize480, kIsacPacSize960}, 0, 1},
# if (defined(WEBRTC_CODEC_ISAC))
{1, {kIsacPacSize960}, 0, 1},
{1, {kIsacPacSize1440}, 0, 1},
# endif
#endif
#ifdef WEBRTC_CODEC_PCM16
// Mono
{4, {80, 160, 240, 320}, 0, 2},
{4, {160, 320, 480, 640}, 0, 2},
{2, {320, 640}, 0, 2},
// Stereo
{4, {80, 160, 240, 320}, 0, 2},
{4, {160, 320, 480, 640}, 0, 2},
{2, {320, 640}, 0, 2},
#endif
// G.711, PCM mu-law and A-law.
// Mono
{6, {80, 160, 240, 320, 400, 480}, 0, 2},
{6, {80, 160, 240, 320, 400, 480}, 0, 2},
// Stereo
{6, {80, 160, 240, 320, 400, 480}, 0, 2},
{6, {80, 160, 240, 320, 400, 480}, 0, 2},
#ifdef WEBRTC_CODEC_ILBC
{4, {160, 240, 320, 480}, 0, 1},
#endif
#ifdef WEBRTC_CODEC_AMR
{3, {160, 320, 480}, 0, 1},
#endif
#ifdef WEBRTC_CODEC_AMRWB
{3, {320, 640, 960}, 0, 1},
#endif
#ifdef WEBRTC_CODEC_CELT
// Mono
{1, {640}, 0, 2},
// Stereo
{1, {640}, 0, 2},
#endif
#ifdef WEBRTC_CODEC_G722
// Mono
{6, {160, 320, 480, 640, 800, 960}, 0, 2},
// Stereo
{6, {160, 320, 480, 640, 800, 960}, 0, 2},
#endif
#ifdef WEBRTC_CODEC_G722_1
{1, {320}, 320, 1},
{1, {320}, 320, 1},
{1, {320}, 320, 1},
#endif
#ifdef WEBRTC_CODEC_G722_1C
{1, {640}, 640, 1},
{1, {640}, 640, 1},
{1, {640}, 640, 1},
#endif
#ifdef WEBRTC_CODEC_G729
{6, {80, 160, 240, 320, 400, 480}, 0, 1},
#endif
#ifdef WEBRTC_CODEC_G729_1
{3, {320, 640, 960}, 0, 1},
#endif
#ifdef WEBRTC_CODEC_GSMFR
{3, {160, 320, 480}, 160, 1},
#endif
#ifdef WEBRTC_CODEC_OPUS
// Opus supports frames shorter than 10ms,
// but it doesn't help us to use them.
// Mono and stereo.
{4, {480, 960, 1920, 2880}, 0, 2},
#endif
#ifdef WEBRTC_CODEC_SPEEX
{3, {160, 320, 480}, 0, 1},
{3, {320, 640, 960}, 0, 1},
#endif
// Comfort noise for three different sampling frequencies.
{1, {240}, 240, 1},
{1, {480}, 480, 1},
{1, {960}, 960, 1},
#ifdef ENABLE_48000_HZ
{1, {1440}, 1440, 1},
#endif
#ifdef WEBRTC_CODEC_AVT
{1, {240}, 240, 1},
#endif
#ifdef WEBRTC_CODEC_RED
{1, {0}, 0, 1},
#endif
// To prevent compile errors due to trailing commas.
{-1, {-1}, -1, -1}
};
// Create a database of all NetEQ decoders at compile time.
const WebRtcNetEQDecoder ACMCodecDB::neteq_decoders_[] = {
#if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX))
kDecoderISAC,
# if (defined(WEBRTC_CODEC_ISAC))
kDecoderISACswb,
kDecoderISACfb,
# endif
#endif
#ifdef WEBRTC_CODEC_PCM16
// Mono
kDecoderPCM16B,
kDecoderPCM16Bwb,
kDecoderPCM16Bswb32kHz,
// Stereo
kDecoderPCM16B_2ch,
kDecoderPCM16Bwb_2ch,
kDecoderPCM16Bswb32kHz_2ch,
#endif
// G.711, PCM mu-las and A-law.
// Mono
kDecoderPCMu,
kDecoderPCMa,
// Stereo
kDecoderPCMu_2ch,
kDecoderPCMa_2ch,
#ifdef WEBRTC_CODEC_ILBC
kDecoderILBC,
#endif
#ifdef WEBRTC_CODEC_AMR
kDecoderAMR,
#endif
#ifdef WEBRTC_CODEC_AMRWB
kDecoderAMRWB,
#endif
#ifdef WEBRTC_CODEC_CELT
// Mono
kDecoderCELT_32,
// Stereo
kDecoderCELT_32_2ch,
#endif
#ifdef WEBRTC_CODEC_G722
// Mono
kDecoderG722,
// Stereo
kDecoderG722_2ch,
#endif
#ifdef WEBRTC_CODEC_G722_1
kDecoderG722_1_32,
kDecoderG722_1_24,
kDecoderG722_1_16,
#endif
#ifdef WEBRTC_CODEC_G722_1C
kDecoderG722_1C_48,
kDecoderG722_1C_32,
kDecoderG722_1C_24,
#endif
#ifdef WEBRTC_CODEC_G729
kDecoderG729,
#endif
#ifdef WEBRTC_CODEC_G729_1
kDecoderG729_1,
#endif
#ifdef WEBRTC_CODEC_GSMFR
kDecoderGSMFR,
#endif
#ifdef WEBRTC_CODEC_OPUS
// Mono and stereo.
kDecoderOpus,
#endif
#ifdef WEBRTC_CODEC_SPEEX
kDecoderSPEEX_8,
kDecoderSPEEX_16,
#endif
// Comfort noise for three different sampling frequencies.
kDecoderCNG,
kDecoderCNG,
kDecoderCNG,
#ifdef ENABLE_48000_HZ
kDecoderCNG,
#endif
#ifdef WEBRTC_CODEC_AVT
kDecoderAVT,
#endif
#ifdef WEBRTC_CODEC_RED
kDecoderRED,
#endif
kDecoderReservedEnd
};
// Get codec information from database.
// TODO(tlegrand): replace memcpy with a pointer to the data base memory.
int ACMCodecDB::Codec(int codec_id, CodecInst* codec_inst) {
// Error check to see that codec_id is not out of bounds.
if ((codec_id < 0) || (codec_id >= kNumCodecs)) {
return -1;
}
// Copy database information for the codec to the output.
memcpy(codec_inst, &database_[codec_id], sizeof(CodecInst));
return 0;
}
// Enumerator for error codes when asking for codec database id.
enum {
kInvalidCodec = -10,
kInvalidPayloadtype = -30,
kInvalidPacketSize = -40,
kInvalidRate = -50
};
// Gets the codec id number from the database. If there is some mismatch in
// the codec settings, the function will return an error code.
// NOTE! The first mismatch found will generate the return value.
int ACMCodecDB::CodecNumber(const CodecInst* codec_inst, int* mirror_id) {
// Look for a matching codec in the database.
int codec_id = CodecId(codec_inst);
// Checks if we found a matching codec.
if (codec_id == -1) {
return kInvalidCodec;
}
// Checks the validity of payload type
if (!ValidPayloadType(codec_inst->pltype)) {
return kInvalidPayloadtype;
}
// Comfort Noise is special case, packet-size & rate is not checked.
if (STR_CASE_CMP(database_[codec_id].plname, "CN") == 0) {
*mirror_id = codec_id;
return codec_id;
}
// RED is special case, packet-size & rate is not checked.
if (STR_CASE_CMP(database_[codec_id].plname, "red") == 0) {
*mirror_id = codec_id;
return codec_id;
}
// Checks the validity of packet size.
if (codec_settings_[codec_id].num_packet_sizes > 0) {
bool packet_size_ok = false;
int i;
int packet_size_samples;
for (i = 0; i < codec_settings_[codec_id].num_packet_sizes; i++) {
packet_size_samples =
codec_settings_[codec_id].packet_sizes_samples[i];
if (codec_inst->pacsize == packet_size_samples) {
packet_size_ok = true;
break;
}
}
if (!packet_size_ok) {
return kInvalidPacketSize;
}
}
if (codec_inst->pacsize < 1) {
return kInvalidPacketSize;
}
// Check the validity of rate. Codecs with multiple rates have their own
// function for this.
*mirror_id = codec_id;
if (STR_CASE_CMP("isac", codec_inst->plname) == 0) {
if (IsISACRateValid(codec_inst->rate)) {
// Set mirrorID to iSAC WB which is only created once to be used both for
// iSAC WB and SWB, because they need to share struct.
*mirror_id = kISAC;
return codec_id;
} else {
return kInvalidRate;
}
} else if (STR_CASE_CMP("ilbc", codec_inst->plname) == 0) {
return IsILBCRateValid(codec_inst->rate, codec_inst->pacsize)
? codec_id : kInvalidRate;
} else if (STR_CASE_CMP("amr", codec_inst->plname) == 0) {
return IsAMRRateValid(codec_inst->rate)
? codec_id : kInvalidRate;
} else if (STR_CASE_CMP("amr-wb", codec_inst->plname) == 0) {
return IsAMRwbRateValid(codec_inst->rate)
? codec_id : kInvalidRate;
} else if (STR_CASE_CMP("g7291", codec_inst->plname) == 0) {
return IsG7291RateValid(codec_inst->rate)
? codec_id : kInvalidRate;
} else if (STR_CASE_CMP("opus", codec_inst->plname) == 0) {
return IsOpusRateValid(codec_inst->rate)
? codec_id : kInvalidRate;
} else if (STR_CASE_CMP("speex", codec_inst->plname) == 0) {
return IsSpeexRateValid(codec_inst->rate)
? codec_id : kInvalidRate;
} else if (STR_CASE_CMP("celt", codec_inst->plname) == 0) {
return IsCeltRateValid(codec_inst->rate)
? codec_id : kInvalidRate;
}
return IsRateValid(codec_id, codec_inst->rate) ?
codec_id : kInvalidRate;
}
// Looks for a matching payload name, frequency, and channels in the
// codec list. Need to check all three since some codecs have several codec
// entries with different frequencies and/or channels.
// Does not check other codec settings, such as payload type and packet size.
// Returns the id of the codec, or -1 if no match is found.
int ACMCodecDB::CodecId(const CodecInst* codec_inst) {
return (CodecId(codec_inst->plname, codec_inst->plfreq,
codec_inst->channels));
}
int ACMCodecDB::CodecId(const char* payload_name, int frequency, int channels) {
for (int id = 0; id < kNumCodecs; id++) {
bool name_match = false;
bool frequency_match = false;
bool channels_match = false;
// Payload name, sampling frequency and number of channels need to match.
// NOTE! If |frequency| is -1, the frequency is not applicable, and is
// always treated as true, like for RED.
name_match = (STR_CASE_CMP(database_[id].plname, payload_name) == 0);
frequency_match = (frequency == database_[id].plfreq) || (frequency == -1);
// The number of channels must match for all codecs but Opus.
if (STR_CASE_CMP(payload_name, "opus") != 0) {
channels_match = (channels == database_[id].channels);
} else {
// For opus we just check that number of channels is valid.
channels_match = (channels == 1 || channels == 2);
}
if (name_match && frequency_match && channels_match) {
// We have found a matching codec in the list.
return id;
}
}
// We didn't find a matching codec.
return -1;
}
// Gets codec id number, and mirror id, from database for the receiver.
int ACMCodecDB::ReceiverCodecNumber(const CodecInst* codec_inst,
int* mirror_id) {
// Look for a matching codec in the database.
int codec_id = CodecId(codec_inst);
// Set |mirror_id| to |codec_id|, except for iSAC. In case of iSAC we always
// set |mirror_id| to iSAC WB (kISAC) which is only created once to be used
// both for iSAC WB and SWB, because they need to share struct.
if (STR_CASE_CMP(codec_inst->plname, "ISAC") != 0) {
*mirror_id = codec_id;
} else {
*mirror_id = kISAC;
}
return codec_id;
}
// Returns the codec sampling frequency for codec with id = "codec_id" in
// database.
int ACMCodecDB::CodecFreq(int codec_id) {
// Error check to see that codec_id is not out of bounds.
if (codec_id < 0 || codec_id >= kNumCodecs) {
return -1;
}
return database_[codec_id].plfreq;
}
// Returns the codec's basic coding block size in samples.
int ACMCodecDB::BasicCodingBlock(int codec_id) {
// Error check to see that codec_id is not out of bounds.
if (codec_id < 0 || codec_id >= kNumCodecs) {
return -1;
}
return codec_settings_[codec_id].basic_block_samples;
}
// Returns the NetEQ decoder database.
const WebRtcNetEQDecoder* ACMCodecDB::NetEQDecoders() {
return neteq_decoders_;
}
// Gets mirror id. The Id is used for codecs sharing struct for settings that
// need different payload types.
int ACMCodecDB::MirrorID(int codec_id) {
if (STR_CASE_CMP(database_[codec_id].plname, "isac") == 0) {
return kISAC;
} else {
return codec_id;
}
}
// Creates memory/instance for storing codec state.
ACMGenericCodec* ACMCodecDB::CreateCodecInstance(const CodecInst* codec_inst) {
// All we have support for right now.
if (!STR_CASE_CMP(codec_inst->plname, "ISAC")) {
#if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX))
return new ACMISAC(kISAC);
#endif
} else if (!STR_CASE_CMP(codec_inst->plname, "PCMU")) {
if (codec_inst->channels == 1) {
return new ACMPCMU(kPCMU);
} else {
return new ACMPCMU(kPCMU_2ch);
}
} else if (!STR_CASE_CMP(codec_inst->plname, "PCMA")) {
if (codec_inst->channels == 1) {
return new ACMPCMA(kPCMA);
} else {
return new ACMPCMA(kPCMA_2ch);
}
} else if (!STR_CASE_CMP(codec_inst->plname, "ILBC")) {
#ifdef WEBRTC_CODEC_ILBC
return new ACMILBC(kILBC);
#endif
} else if (!STR_CASE_CMP(codec_inst->plname, "AMR")) {
#ifdef WEBRTC_CODEC_AMR
return new ACMAMR(kGSMAMR);
#endif
} else if (!STR_CASE_CMP(codec_inst->plname, "AMR-WB")) {
#ifdef WEBRTC_CODEC_AMRWB
return new ACMAMRwb(kGSMAMRWB);
#endif
} else if (!STR_CASE_CMP(codec_inst->plname, "CELT")) {
#ifdef WEBRTC_CODEC_CELT
if (codec_inst->channels == 1) {
return new ACMCELT(kCELT32);
} else {
return new ACMCELT(kCELT32_2ch);
}
#endif
} else if (!STR_CASE_CMP(codec_inst->plname, "G722")) {
#ifdef WEBRTC_CODEC_G722
if (codec_inst->channels == 1) {
return new ACMG722(kG722);
} else {
return new ACMG722(kG722_2ch);
}
#endif
} else if (!STR_CASE_CMP(codec_inst->plname, "G7221")) {
switch (codec_inst->plfreq) {
case 16000: {
#ifdef WEBRTC_CODEC_G722_1
int codec_id;
switch (codec_inst->rate) {
case 16000 : {
codec_id = kG722_1_16;
break;
}
case 24000 : {
codec_id = kG722_1_24;
break;
}
case 32000 : {
codec_id = kG722_1_32;
break;
}
default: {
return NULL;
}
}
return new ACMG722_1(codec_id);
#endif
}
case 32000: {
#ifdef WEBRTC_CODEC_G722_1C
int codec_id;
switch (codec_inst->rate) {
case 24000 : {
codec_id = kG722_1C_24;
break;
}
case 32000 : {
codec_id = kG722_1C_32;
break;
}
case 48000 : {
codec_id = kG722_1C_48;
break;
}
default: {
return NULL;
}
}
return new ACMG722_1C(codec_id);
#endif
}
}
} else if (!STR_CASE_CMP(codec_inst->plname, "CN")) {
// For CN we need to check sampling frequency to know what codec to create.
int codec_id;
switch (codec_inst->plfreq) {
case 8000: {
codec_id = kCNNB;
break;
}
case 16000: {
codec_id = kCNWB;
break;
}
case 32000: {
codec_id = kCNSWB;
break;
}
#ifdef ENABLE_48000_HZ
case 48000: {
codec_id = kCNFB;
break;
}
#endif
default: {
return NULL;
}
}
return new ACMCNG(codec_id);
} else if (!STR_CASE_CMP(codec_inst->plname, "G729")) {
#ifdef WEBRTC_CODEC_G729
return new ACMG729(kG729);
#endif
} else if (!STR_CASE_CMP(codec_inst->plname, "G7291")) {
#ifdef WEBRTC_CODEC_G729_1
return new ACMG729_1(kG729_1);
#endif
} else if (!STR_CASE_CMP(codec_inst->plname, "opus")) {
#ifdef WEBRTC_CODEC_OPUS
return new ACMOpus(kOpus);
#endif
} else if (!STR_CASE_CMP(codec_inst->plname, "speex")) {
#ifdef WEBRTC_CODEC_SPEEX
int codec_id;
switch (codec_inst->plfreq) {
case 8000: {
codec_id = kSPEEX8;
break;
}
case 16000: {
codec_id = kSPEEX16;
break;
}
default: {
return NULL;
}
}
return new ACMSPEEX(codec_id);
#endif
} else if (!STR_CASE_CMP(codec_inst->plname, "CN")) {
// For CN we need to check sampling frequency to know what codec to create.
int codec_id;
switch (codec_inst->plfreq) {
case 8000: {
codec_id = kCNNB;
break;
}
case 16000: {
codec_id = kCNWB;
break;
}
case 32000: {
codec_id = kCNSWB;
break;
}
#ifdef ENABLE_48000_HZ
case 48000: {
codec_id = kCNFB;
break;
}
#endif
default: {
return NULL;
}
}
return new ACMCNG(codec_id);
} else if (!STR_CASE_CMP(codec_inst->plname, "L16")) {
#ifdef WEBRTC_CODEC_PCM16
// For L16 we need to check sampling frequency to know what codec to create.
int codec_id;
if (codec_inst->channels == 1) {
switch (codec_inst->plfreq) {
case 8000: {
codec_id = kPCM16B;
break;
}
case 16000: {
codec_id = kPCM16Bwb;
break;
}
case 32000: {
codec_id = kPCM16Bswb32kHz;
break;
}
default: {
return NULL;
}
}
} else {
switch (codec_inst->plfreq) {
case 8000: {
codec_id = kPCM16B_2ch;
break;
}
case 16000: {
codec_id = kPCM16Bwb_2ch;
break;
}
case 32000: {
codec_id = kPCM16Bswb32kHz_2ch;
break;
}
default: {
return NULL;
}
}
}
return new ACMPCM16B(codec_id);
#endif
} else if (!STR_CASE_CMP(codec_inst->plname, "telephone-event")) {
#ifdef WEBRTC_CODEC_AVT
return new ACMDTMFPlayout(kAVT);
#endif
} else if (!STR_CASE_CMP(codec_inst->plname, "red")) {
#ifdef WEBRTC_CODEC_RED
return new ACMRED(kRED);
#endif
}
return NULL;
}
// Checks if the bitrate is valid for the codec.
bool ACMCodecDB::IsRateValid(int codec_id, int rate) {
if (database_[codec_id].rate == rate) {
return true;
} else {
return false;
}
}
// Checks if the bitrate is valid for iSAC.
bool ACMCodecDB::IsISACRateValid(int rate) {
if ((rate == -1) || ((rate <= 56000) && (rate >= 10000))) {
return true;
} else {
return false;
}
}
// Checks if the bitrate is valid for iLBC.
bool ACMCodecDB::IsILBCRateValid(int rate, int frame_size_samples) {
if (((frame_size_samples == 240) || (frame_size_samples == 480)) &&
(rate == 13300)) {
return true;
} else if (((frame_size_samples == 160) || (frame_size_samples == 320)) &&
(rate == 15200)) {
return true;
} else {
return false;
}
}
// Check if the bitrate is valid for the GSM-AMR.
bool ACMCodecDB::IsAMRRateValid(int rate) {
switch (rate) {
case 4750:
case 5150:
case 5900:
case 6700:
case 7400:
case 7950:
case 10200:
case 12200: {
return true;
}
default: {
return false;
}
}
}
// Check if the bitrate is valid for GSM-AMR-WB.
bool ACMCodecDB::IsAMRwbRateValid(int rate) {
switch (rate) {
case 7000:
case 9000:
case 12000:
case 14000:
case 16000:
case 18000:
case 20000:
case 23000:
case 24000: {
return true;
}
default: {
return false;
}
}
}
// Check if the bitrate is valid for G.729.1.
bool ACMCodecDB::IsG7291RateValid(int rate) {
switch (rate) {
case 8000:
case 12000:
case 14000:
case 16000:
case 18000:
case 20000:
case 22000:
case 24000:
case 26000:
case 28000:
case 30000:
case 32000: {
return true;
}
default: {
return false;
}
}
}
// Checks if the bitrate is valid for Speex.
bool ACMCodecDB::IsSpeexRateValid(int rate) {
if (rate > 2000) {
return true;
} else {
return false;
}
}
// Checks if the bitrate is valid for Opus.
bool ACMCodecDB::IsOpusRateValid(int rate) {
if ((rate < 6000) || (rate > 510000)) {
return false;
}
return true;
}
// Checks if the bitrate is valid for Celt.
bool ACMCodecDB::IsCeltRateValid(int rate) {
if ((rate >= 48000) && (rate <= 128000)) {
return true;
} else {
return false;
}
}
// Checks if the payload type is in the valid range.
bool ACMCodecDB::ValidPayloadType(int payload_type) {
if ((payload_type < 0) || (payload_type > 127)) {
return false;
}
return true;
}
} // namespace acm1
} // namespace webrtc

View File

@ -1,336 +0,0 @@
/*
* 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.
*/
/*
* This file generates databases with information about all supported audio
* codecs.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_CODEC_DATABASE_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_CODEC_DATABASE_H_
#include "webrtc/common_types.h"
#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
namespace webrtc {
namespace acm1 {
// TODO(tlegrand): replace class ACMCodecDB with a namespace.
class ACMCodecDB {
public:
// Enum with array indexes for the supported codecs. NOTE! The order MUST
// be the same as when creating the database in acm_codec_database.cc.
enum {
kNone = -1
#if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX))
, kISAC
# if (defined(WEBRTC_CODEC_ISAC))
, kISACSWB
, kISACFB
# endif
#endif
#ifdef WEBRTC_CODEC_PCM16
// Mono
, kPCM16B
, kPCM16Bwb
, kPCM16Bswb32kHz
// Stereo
, kPCM16B_2ch
, kPCM16Bwb_2ch
, kPCM16Bswb32kHz_2ch
#endif
// Mono
, kPCMU
, kPCMA
// Stereo
, kPCMU_2ch
, kPCMA_2ch
#ifdef WEBRTC_CODEC_ILBC
, kILBC
#endif
#ifdef WEBRTC_CODEC_AMR
, kGSMAMR
#endif
#ifdef WEBRTC_CODEC_AMRWB
, kGSMAMRWB
#endif
#ifdef WEBRTC_CODEC_CELT
// Mono
, kCELT32
// Stereo
, kCELT32_2ch
#endif
#ifdef WEBRTC_CODEC_G722
// Mono
, kG722
// Stereo
, kG722_2ch
#endif
#ifdef WEBRTC_CODEC_G722_1
, kG722_1_32
, kG722_1_24
, kG722_1_16
#endif
#ifdef WEBRTC_CODEC_G722_1C
, kG722_1C_48
, kG722_1C_32
, kG722_1C_24
#endif
#ifdef WEBRTC_CODEC_G729
, kG729
#endif
#ifdef WEBRTC_CODEC_G729_1
, kG729_1
#endif
#ifdef WEBRTC_CODEC_GSMFR
, kGSMFR
#endif
#ifdef WEBRTC_CODEC_OPUS
// Mono and stereo
, kOpus
#endif
#ifdef WEBRTC_CODEC_SPEEX
, kSPEEX8
, kSPEEX16
#endif
, kCNNB
, kCNWB
, kCNSWB
#ifdef ENABLE_48000_HZ
, kCNFB
#endif
#ifdef WEBRTC_CODEC_AVT
, kAVT
#endif
#ifdef WEBRTC_CODEC_RED
, kRED
#endif
, kNumCodecs
};
// Set unsupported codecs to -1
#ifndef WEBRTC_CODEC_ISAC
enum {kISACSWB = -1};
enum {kISACFB = -1};
# ifndef WEBRTC_CODEC_ISACFX
enum {kISAC = -1};
# endif
#endif
#ifndef WEBRTC_CODEC_PCM16
// Mono
enum {kPCM16B = -1};
enum {kPCM16Bwb = -1};
enum {kPCM16Bswb32kHz = -1};
// Stereo
enum {kPCM16B_2ch = -1};
enum {kPCM16Bwb_2ch = -1};
enum {kPCM16Bswb32kHz_2ch = -1};
#endif
// 48 kHz not supported, always set to -1.
enum {kPCM16Bswb48kHz = -1};
#ifndef WEBRTC_CODEC_ILBC
enum {kILBC = -1};
#endif
#ifndef WEBRTC_CODEC_AMR
enum {kGSMAMR = -1};
#endif
#ifndef WEBRTC_CODEC_AMRWB
enum {kGSMAMRWB = -1};
#endif
#ifndef WEBRTC_CODEC_CELT
// Mono
enum {kCELT32 = -1};
// Stereo
enum {kCELT32_2ch = -1};
#endif
#ifndef WEBRTC_CODEC_G722
// Mono
enum {kG722 = -1};
// Stereo
enum {kG722_2ch = -1};
#endif
#ifndef WEBRTC_CODEC_G722_1
enum {kG722_1_32 = -1};
enum {kG722_1_24 = -1};
enum {kG722_1_16 = -1};
#endif
#ifndef WEBRTC_CODEC_G722_1C
enum {kG722_1C_48 = -1};
enum {kG722_1C_32 = -1};
enum {kG722_1C_24 = -1};
#endif
#ifndef WEBRTC_CODEC_G729
enum {kG729 = -1};
#endif
#ifndef WEBRTC_CODEC_G729_1
enum {kG729_1 = -1};
#endif
#ifndef WEBRTC_CODEC_GSMFR
enum {kGSMFR = -1};
#endif
#ifndef WEBRTC_CODEC_SPEEX
enum {kSPEEX8 = -1};
enum {kSPEEX16 = -1};
#endif
#ifndef WEBRTC_CODEC_OPUS
// Mono and stereo
enum {kOpus = -1};
#endif
#ifndef WEBRTC_CODEC_AVT
enum {kAVT = -1};
#endif
#ifndef WEBRTC_CODEC_RED
enum {kRED = -1};
#endif
// kMaxNumCodecs - Maximum number of codecs that can be activated in one
// build.
// kMaxNumPacketSize - Maximum number of allowed packet sizes for one codec.
// These might need to be increased if adding a new codec to the database
static const int kMaxNumCodecs = 50;
static const int kMaxNumPacketSize = 6;
// Codec specific settings
//
// num_packet_sizes - number of allowed packet sizes.
// packet_sizes_samples - list of the allowed packet sizes.
// basic_block_samples - assigned a value different from 0 if the codec
// requires to be fed with a specific number of samples
// that can be different from packet size.
// channel_support - number of channels supported to encode;
// 1 = mono, 2 = stereo, etc.
struct CodecSettings {
int num_packet_sizes;
int packet_sizes_samples[kMaxNumPacketSize];
int basic_block_samples;
int channel_support;
};
// Gets codec information from database at the position in database given by
// [codec_id].
// Input:
// [codec_id] - number that specifies at what position in the database to
// get the information.
// Output:
// [codec_inst] - filled with information about the codec.
// Return:
// 0 if successful, otherwise -1.
static int Codec(int codec_id, CodecInst* codec_inst);
// Returns codec id and mirror id from database, given the information
// received in the input [codec_inst]. Mirror id is a number that tells
// where to find the codec's memory (instance). The number is either the
// same as codec id (most common), or a number pointing at a different
// entry in the database, if the codec has several entries with different
// payload types. This is used for codecs that must share one struct even if
// the payload type differs.
// One example is the codec iSAC which has the same struct for both 16 and
// 32 khz, but they have different entries in the database. Let's say the
// function is called with iSAC 32kHz. The function will return 1 as that is
// the entry in the data base, and [mirror_id] = 0, as that is the entry for
// iSAC 16 kHz, which holds the shared memory.
// Input:
// [codec_inst] - Information about the codec for which we require the
// database id.
// Output:
// [mirror_id] - mirror id, which most often is the same as the return
// value, see above.
// Return:
// codec id if successful, otherwise < 0.
static int CodecNumber(const CodecInst* codec_inst, int* mirror_id);
static int CodecId(const CodecInst* codec_inst);
static int CodecId(const char* payload_name, int frequency, int channels);
static int ReceiverCodecNumber(const CodecInst* codec_inst, int* mirror_id);
// Returns the codec sampling frequency for codec with id = "codec_id" in
// database.
// TODO(tlegrand): Check if function is needed, or if we can change
// to access database directly.
// Input:
// [codec_id] - number that specifies at what position in the database to
// get the information.
// Return:
// codec sampling frequency if successful, otherwise -1.
static int CodecFreq(int codec_id);
// Return the codec's basic coding block size in samples.
// TODO(tlegrand): Check if function is needed, or if we can change
// to access database directly.
// Input:
// [codec_id] - number that specifies at what position in the database to
// get the information.
// Return:
// codec basic block size if successful, otherwise -1.
static int BasicCodingBlock(int codec_id);
// Returns the NetEQ decoder database.
static const WebRtcNetEQDecoder* NetEQDecoders();
// Returns mirror id, which is a number that tells where to find the codec's
// memory (instance). It is either the same as codec id (most common), or a
// number pointing at a different entry in the database, if the codec have
// several entries with different payload types. This is used for codecs that
// must share struct even if the payload type differs.
// TODO(tlegrand): Check if function is needed, or if we can change
// to access database directly.
// Input:
// [codec_id] - number that specifies codec's position in the database.
// Return:
// Mirror id on success, otherwise -1.
static int MirrorID(int codec_id);
// Create memory/instance for storing codec state.
// Input:
// [codec_inst] - information about codec. Only name of codec, "plname", is
// used in this function.
static ACMGenericCodec* CreateCodecInstance(const CodecInst* codec_inst);
// Checks if the bitrate is valid for the codec.
// Input:
// [codec_id] - number that specifies codec's position in the database.
// [rate] - bitrate to check.
// [frame_size_samples] - (used for iLBC) specifies which frame size to go
// with the rate.
static bool IsRateValid(int codec_id, int rate);
static bool IsISACRateValid(int rate);
static bool IsILBCRateValid(int rate, int frame_size_samples);
static bool IsAMRRateValid(int rate);
static bool IsAMRwbRateValid(int rate);
static bool IsG7291RateValid(int rate);
static bool IsSpeexRateValid(int rate);
static bool IsOpusRateValid(int rate);
static bool IsCeltRateValid(int rate);
// Check if the payload type is valid, meaning that it is in the valid range
// of 0 to 127.
// Input:
// [payload_type] - payload type.
static bool ValidPayloadType(int payload_type);
// Databases with information about the supported codecs
// database_ - stored information about all codecs: payload type, name,
// sampling frequency, packet size in samples, default channel
// support, and default rate.
// codec_settings_ - stored codec settings: number of allowed packet sizes,
// a vector with the allowed packet sizes, basic block
// samples, and max number of channels that are supported.
// neteq_decoders_ - list of supported decoders in NetEQ.
static const CodecInst database_[kMaxNumCodecs];
static const CodecSettings codec_settings_[kMaxNumCodecs];
static const WebRtcNetEQDecoder neteq_decoders_[kMaxNumCodecs];
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_CODEC_DATABASE_H_

View File

@ -1,42 +0,0 @@
/*
* 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/source/acm_dtmf_detection.h"
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
namespace webrtc {
namespace acm1 {
ACMDTMFDetection::ACMDTMFDetection() {}
ACMDTMFDetection::~ACMDTMFDetection() {}
int16_t ACMDTMFDetection::Enable(ACMCountries /* cpt */) {
return -1;
}
int16_t ACMDTMFDetection::Disable() {
return -1;
}
int16_t ACMDTMFDetection::Detect(
const int16_t* /* in_audio_buff */,
const uint16_t /* in_buff_len_word16 */,
const int32_t /* in_freq_hz */,
bool& /* tone_detected */,
int16_t& /* tone */) {
return -1;
}
} // namespace acm1
} // namespace webrtc

View File

@ -1,42 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_DTMF_DETECTION_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_DTMF_DETECTION_H_
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
#include "webrtc/modules/audio_coding/main/source/acm_resampler.h"
#include "webrtc/typedefs.h"
namespace webrtc {
namespace acm1 {
class ACMDTMFDetection {
public:
ACMDTMFDetection();
~ACMDTMFDetection();
int16_t Enable(ACMCountries cpt = ACMDisableCountryDetection);
int16_t Disable();
int16_t Detect(const int16_t* in_audio_buff,
const uint16_t in_buff_len_word16,
const int32_t in_freq_hz,
bool& tone_detected,
int16_t& tone);
private:
ACMResampler resampler_;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_DTMF_DETECTION_H_

View File

@ -1,171 +0,0 @@
/*
* 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/source/acm_dtmf_playout.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
#include "webrtc/system_wrappers/interface/trace.h"
namespace webrtc {
namespace acm1 {
#ifndef WEBRTC_CODEC_AVT
ACMDTMFPlayout::ACMDTMFPlayout(
int16_t /* codec_id */) {
return;
}
ACMDTMFPlayout::~ACMDTMFPlayout() {
return;
}
int16_t ACMDTMFPlayout::InternalEncode(
uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */) {
return -1;
}
int16_t ACMDTMFPlayout::DecodeSafe(
uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return -1;
}
int16_t ACMDTMFPlayout::InternalInitEncoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int16_t ACMDTMFPlayout::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int32_t ACMDTMFPlayout::CodecDef(WebRtcNetEQ_CodecDef& /* codec_def */,
const CodecInst& /* codec_inst */) {
return -1;
}
ACMGenericCodec* ACMDTMFPlayout::CreateInstance(void) {
return NULL;
}
int16_t ACMDTMFPlayout::InternalCreateEncoder() {
return -1;
}
int16_t ACMDTMFPlayout::InternalCreateDecoder() {
return -1;
}
void ACMDTMFPlayout::InternalDestructEncoderInst(void* /* ptr_inst */) {
return;
}
void ACMDTMFPlayout::DestructEncoderSafe() {
return;
}
void ACMDTMFPlayout::DestructDecoderSafe() {
return;
}
#else //===================== Actual Implementation =======================
ACMDTMFPlayout::ACMDTMFPlayout(int16_t codec_id) {
codec_id_ = codec_id;
}
ACMDTMFPlayout::~ACMDTMFPlayout() {
return;
}
int16_t ACMDTMFPlayout::InternalEncode(
uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */) {
return 0;
}
int16_t ACMDTMFPlayout::DecodeSafe(
uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return 0;
}
int16_t ACMDTMFPlayout::InternalInitEncoder(
WebRtcACMCodecParams* /* codec_params */) {
// This codec does not need initialization,
// DTMFPlayout has no instance
return 0;
}
int16_t ACMDTMFPlayout::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
// This codec does not need initialization,
// DTMFPlayout has no instance
return 0;
}
int32_t ACMDTMFPlayout::CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) {
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_AVT_FUNCTION."
// Then call NetEQ to add the codec to it's
// database.
SET_CODEC_PAR((codec_def), kDecoderAVT, codec_inst.pltype, NULL, 8000);
SET_AVT_FUNCTIONS((codec_def));
return 0;
}
ACMGenericCodec* ACMDTMFPlayout::CreateInstance(void) {
return NULL;
}
int16_t ACMDTMFPlayout::InternalCreateEncoder() {
// DTMFPlayout has no instance
return 0;
}
int16_t ACMDTMFPlayout::InternalCreateDecoder() {
// DTMFPlayout has no instance
return 0;
}
void ACMDTMFPlayout::InternalDestructEncoderInst(void* /* ptr_inst */) {
// DTMFPlayout has no instance
return;
}
void ACMDTMFPlayout::DestructEncoderSafe() {
// DTMFPlayout has no instance
return;
}
void ACMDTMFPlayout::DestructDecoderSafe() {
// DTMFPlayout has no instance
return;
}
#endif
} // namespace acm1
} // namespace webrtc

View File

@ -1,62 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_DTMF_PLAYOUT_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_DTMF_PLAYOUT_H_
#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
namespace webrtc {
namespace acm1 {
class ACMDTMFPlayout: public ACMGenericCodec {
public:
explicit ACMDTMFPlayout(int16_t codec_id);
virtual ~ACMDTMFPlayout();
// for FEC
virtual ACMGenericCodec* CreateInstance(void) OVERRIDE;
virtual int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) OVERRIDE;
virtual int16_t InternalInitEncoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
virtual int16_t InternalInitDecoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
protected:
virtual int16_t DecodeSafe(uint8_t* bitstream,
int16_t bitstream_len_byte,
int16_t* audio,
int16_t* audio_samples,
int8_t* speech_type) OVERRIDE;
virtual int32_t CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) OVERRIDE;
virtual void DestructEncoderSafe() OVERRIDE;
virtual void DestructDecoderSafe() OVERRIDE;
virtual int16_t InternalCreateEncoder() OVERRIDE;
virtual int16_t InternalCreateDecoder() OVERRIDE;
virtual void InternalDestructEncoderInst(void* ptr_inst) OVERRIDE;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_DTMF_PLAYOUT_H_

View File

@ -1,358 +0,0 @@
/*
* 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/source/acm_g722.h"
#include "webrtc/modules/audio_coding/codecs/g722/include/g722_interface.h"
#include "webrtc/modules/audio_coding/main/source/acm_codec_database.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
#include "webrtc/system_wrappers/interface/trace.h"
namespace webrtc {
namespace acm1 {
#ifndef WEBRTC_CODEC_G722
ACMG722::ACMG722(int16_t /* codec_id */)
: ptr_enc_str_(NULL),
ptr_dec_str_(NULL),
encoder_inst_ptr_(NULL),
encoder_inst_ptr_right_(NULL),
decoder_inst_ptr_(NULL) {}
ACMG722::~ACMG722() {}
int32_t ACMG722::Add10MsDataSafe(
const uint32_t /* timestamp */,
const int16_t* /* data */,
const uint16_t /* length_smpl */,
const uint8_t /* audio_channel */) {
return -1;
}
int16_t ACMG722::InternalEncode(
uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */) {
return -1;
}
int16_t ACMG722::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return -1;
}
int16_t ACMG722::InternalInitEncoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int16_t ACMG722::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int32_t ACMG722::CodecDef(WebRtcNetEQ_CodecDef& /* codec_def */,
const CodecInst& /* codec_inst */) {
return -1;
}
ACMGenericCodec* ACMG722::CreateInstance(void) {
return NULL;
}
int16_t ACMG722::InternalCreateEncoder() {
return -1;
}
void ACMG722::DestructEncoderSafe() {
return;
}
int16_t ACMG722::InternalCreateDecoder() {
return -1;
}
void ACMG722::DestructDecoderSafe() {
return;
}
void ACMG722::InternalDestructEncoderInst(void* /* ptr_inst */) {
return;
}
void ACMG722::SplitStereoPacket(uint8_t* /*payload*/,
int32_t* /*payload_length*/) {}
#else //===================== Actual Implementation =======================
// Encoder and decoder memory
struct ACMG722EncStr {
G722EncInst* inst; // instance for left channel in case of stereo
G722EncInst* inst_right; // instance for right channel in case of stereo
};
struct ACMG722DecStr {
G722DecInst* inst; // instance for left channel in case of stereo
G722DecInst* inst_right; // instance for right channel in case of stereo
};
ACMG722::ACMG722(int16_t codec_id)
: encoder_inst_ptr_(NULL),
encoder_inst_ptr_right_(NULL),
decoder_inst_ptr_(NULL) {
// Encoder
ptr_enc_str_ = new ACMG722EncStr;
if (ptr_enc_str_ != NULL) {
ptr_enc_str_->inst = NULL;
ptr_enc_str_->inst_right = NULL;
}
// Decoder
ptr_dec_str_ = new ACMG722DecStr;
if (ptr_dec_str_ != NULL) {
ptr_dec_str_->inst = NULL;
ptr_dec_str_->inst_right = NULL; // Not used
}
codec_id_ = codec_id;
return;
}
ACMG722::~ACMG722() {
// Encoder
if (ptr_enc_str_ != NULL) {
if (ptr_enc_str_->inst != NULL) {
WebRtcG722_FreeEncoder(ptr_enc_str_->inst);
ptr_enc_str_->inst = NULL;
}
if (ptr_enc_str_->inst_right != NULL) {
WebRtcG722_FreeEncoder(ptr_enc_str_->inst_right);
ptr_enc_str_->inst_right = NULL;
}
delete ptr_enc_str_;
ptr_enc_str_ = NULL;
}
// Decoder
if (ptr_dec_str_ != NULL) {
if (ptr_dec_str_->inst != NULL) {
WebRtcG722_FreeDecoder(ptr_dec_str_->inst);
ptr_dec_str_->inst = NULL;
}
if (ptr_dec_str_->inst_right != NULL) {
WebRtcG722_FreeDecoder(ptr_dec_str_->inst_right);
ptr_dec_str_->inst_right = NULL;
}
delete ptr_dec_str_;
ptr_dec_str_ = NULL;
}
return;
}
int32_t ACMG722::Add10MsDataSafe(const uint32_t timestamp,
const int16_t* data,
const uint16_t length_smpl,
const uint8_t audio_channel) {
return ACMGenericCodec::Add10MsDataSafe((timestamp >> 1), data, length_smpl,
audio_channel);
}
int16_t ACMG722::InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) {
// If stereo, split input signal in left and right channel before encoding
if (num_channels_ == 2) {
int16_t left_channel[960];
int16_t right_channel[960];
uint8_t out_left[480];
uint8_t out_right[480];
int16_t len_in_bytes;
for (int i = 0, j = 0; i < frame_len_smpl_ * 2; i += 2, j++) {
left_channel[j] = in_audio_[in_audio_ix_read_ + i];
right_channel[j] = in_audio_[in_audio_ix_read_ + i + 1];
}
len_in_bytes = WebRtcG722_Encode(encoder_inst_ptr_, left_channel,
frame_len_smpl_,
(int16_t*)out_left);
len_in_bytes += WebRtcG722_Encode(encoder_inst_ptr_right_, right_channel,
frame_len_smpl_,
(int16_t*)out_right);
*bitstream_len_byte = len_in_bytes;
// Interleave the 4 bits per sample from left and right channel
for (int i = 0, j = 0; i < len_in_bytes; i += 2, j++) {
bitstream[i] = (out_left[j] & 0xF0) + (out_right[j] >> 4);
bitstream[i + 1] = ((out_left[j] & 0x0F) << 4) + (out_right[j] & 0x0F);
}
} else {
*bitstream_len_byte = WebRtcG722_Encode(encoder_inst_ptr_,
&in_audio_[in_audio_ix_read_],
frame_len_smpl_,
(int16_t*)bitstream);
}
// increment the read index this tell the caller how far
// we have gone forward in reading the audio buffer
in_audio_ix_read_ += frame_len_smpl_ * num_channels_;
return *bitstream_len_byte;
}
int16_t ACMG722::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return 0;
}
int16_t ACMG722::InternalInitEncoder(WebRtcACMCodecParams* codec_params) {
if (codec_params->codec_inst.channels == 2) {
// Create codec struct for right channel
if (ptr_enc_str_->inst_right == NULL) {
WebRtcG722_CreateEncoder(&ptr_enc_str_->inst_right);
if (ptr_enc_str_->inst_right == NULL) {
return -1;
}
}
encoder_inst_ptr_right_ = ptr_enc_str_->inst_right;
if (WebRtcG722_EncoderInit(encoder_inst_ptr_right_) < 0) {
return -1;
}
}
return WebRtcG722_EncoderInit(encoder_inst_ptr_);
}
int16_t ACMG722::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
return WebRtcG722_DecoderInit(decoder_inst_ptr_);
}
int32_t ACMG722::CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) {
if (!decoder_initialized_) {
// TODO(turajs): log error
return -1;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_G722_FUNCTION."
// Then call NetEQ to add the codec to it's
// database.
if (codec_inst.channels == 1) {
SET_CODEC_PAR(codec_def, kDecoderG722, codec_inst.pltype, decoder_inst_ptr_,
16000);
} else {
SET_CODEC_PAR(codec_def, kDecoderG722_2ch, codec_inst.pltype,
decoder_inst_ptr_, 16000);
}
SET_G722_FUNCTIONS(codec_def);
return 0;
}
ACMGenericCodec* ACMG722::CreateInstance(void) {
return NULL;
}
int16_t ACMG722::InternalCreateEncoder() {
if (ptr_enc_str_ == NULL) {
// this structure must be created at the costructor
// if it is still NULL then there is a probelm and
// we dont continue
return -1;
}
WebRtcG722_CreateEncoder(&ptr_enc_str_->inst);
if (ptr_enc_str_->inst == NULL) {
return -1;
}
encoder_inst_ptr_ = ptr_enc_str_->inst;
return 0;
}
void ACMG722::DestructEncoderSafe() {
if (ptr_enc_str_ != NULL) {
if (ptr_enc_str_->inst != NULL) {
WebRtcG722_FreeEncoder(ptr_enc_str_->inst);
ptr_enc_str_->inst = NULL;
}
}
encoder_exist_ = false;
encoder_initialized_ = false;
}
int16_t ACMG722::InternalCreateDecoder() {
if (ptr_dec_str_ == NULL) {
// this structure must be created at the costructor
// if it is still NULL then there is a probelm and
// we dont continue
return -1;
}
WebRtcG722_CreateDecoder(&ptr_dec_str_->inst);
if (ptr_dec_str_->inst == NULL) {
return -1;
}
decoder_inst_ptr_ = ptr_dec_str_->inst;
return 0;
}
void ACMG722::DestructDecoderSafe() {
decoder_exist_ = false;
decoder_initialized_ = false;
if (ptr_dec_str_ != NULL) {
if (ptr_dec_str_->inst != NULL) {
WebRtcG722_FreeDecoder(ptr_dec_str_->inst);
ptr_dec_str_->inst = NULL;
}
}
}
void ACMG722::InternalDestructEncoderInst(void* ptr_inst) {
if (ptr_inst != NULL) {
WebRtcG722_FreeEncoder(static_cast<G722EncInst*>(ptr_inst));
}
return;
}
// Split the stereo packet and place left and right channel after each other
// in the payload vector.
void ACMG722::SplitStereoPacket(uint8_t* payload, int32_t* payload_length) {
uint8_t right_byte;
// Check for valid inputs.
assert(payload != NULL);
assert(*payload_length > 0);
// Regroup the 4 bits/sample so to |l1 l2| |r1 r2| |l3 l4| |r3 r4| ...,
// where "lx" is 4 bits representing left sample number x, and "rx" right
// sample. Two samples fits in one byte, represented with |...|.
for (int i = 0; i < *payload_length; i += 2) {
right_byte = ((payload[i] & 0x0F) << 4) + (payload[i + 1] & 0x0F);
payload[i] = (payload[i] & 0xF0) + (payload[i + 1] >> 4);
payload[i + 1] = right_byte;
}
// Move one byte representing right channel each loop, and place it at the
// end of the bytestream vector. After looping the data is reordered to:
// |l1 l2| |l3 l4| ... |l(N-1) lN| |r1 r2| |r3 r4| ... |r(N-1) r(N)|,
// where N is the total number of samples.
for (int i = 0; i < *payload_length / 2; i++) {
right_byte = payload[i + 1];
memmove(&payload[i + 1], &payload[i + 2], *payload_length - i - 2);
payload[*payload_length - 1] = right_byte;
}
}
#endif
} // namespace acm1
} // namespace webrtc

View File

@ -1,84 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G722_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G722_H_
#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
typedef struct WebRtcG722EncInst G722EncInst;
typedef struct WebRtcG722DecInst G722DecInst;
namespace webrtc {
namespace acm1 {
// forward declaration
struct ACMG722EncStr;
struct ACMG722DecStr;
class ACMG722 : public ACMGenericCodec {
public:
explicit ACMG722(int16_t codec_id);
virtual ~ACMG722();
// for FEC
virtual ACMGenericCodec* CreateInstance(void) OVERRIDE;
virtual int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) OVERRIDE;
virtual int16_t InternalInitEncoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
virtual int16_t InternalInitDecoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
protected:
virtual int16_t DecodeSafe(uint8_t* bitstream,
int16_t bitstream_len_byte,
int16_t* audio,
int16_t* audio_samples,
int8_t* speech_type) OVERRIDE;
virtual int32_t CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) OVERRIDE;
virtual int32_t Add10MsDataSafe(const uint32_t timestamp,
const int16_t* data,
const uint16_t length_smpl,
const uint8_t audio_channel) OVERRIDE;
virtual void DestructEncoderSafe() OVERRIDE;
virtual void DestructDecoderSafe() OVERRIDE;
virtual int16_t InternalCreateEncoder() OVERRIDE;
virtual int16_t InternalCreateDecoder() OVERRIDE;
virtual void InternalDestructEncoderInst(void* ptr_inst) OVERRIDE;
virtual void SplitStereoPacket(uint8_t* payload,
int32_t* payload_length) OVERRIDE;
ACMG722EncStr* ptr_enc_str_;
ACMG722DecStr* ptr_dec_str_;
G722EncInst* encoder_inst_ptr_;
G722EncInst* encoder_inst_ptr_right_; // Prepared for stereo
G722DecInst* decoder_inst_ptr_;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G722_H_

View File

@ -1,500 +0,0 @@
/*
* 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/source/acm_g7221.h"
#include "webrtc/modules/audio_coding/main/source/acm_codec_database.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
#include "webrtc/system_wrappers/interface/trace.h"
#ifdef WEBRTC_CODEC_G722_1
// NOTE! G.722.1 is not included in the open-source package. The following
// interface file is needed:
//
// /modules/audio_coding/codecs/g7221/main/interface/g7221_interface.h
//
// The API in the header file should match the one below.
//
// int16_t WebRtcG7221_CreateEnc16(G722_1_16_encinst_t_** enc_inst);
// int16_t WebRtcG7221_CreateEnc24(G722_1_24_encinst_t_** enc_inst);
// int16_t WebRtcG7221_CreateEnc32(G722_1_32_encinst_t_** enc_inst);
// int16_t WebRtcG7221_CreateDec16(G722_1_16_decinst_t_** dec_inst);
// int16_t WebRtcG7221_CreateDec24(G722_1_24_decinst_t_** dec_inst);
// int16_t WebRtcG7221_CreateDec32(G722_1_32_decinst_t_** dec_inst);
//
// int16_t WebRtcG7221_FreeEnc16(G722_1_16_encinst_t_** enc_inst);
// int16_t WebRtcG7221_FreeEnc24(G722_1_24_encinst_t_** enc_inst);
// int16_t WebRtcG7221_FreeEnc32(G722_1_32_encinst_t_** enc_inst);
// int16_t WebRtcG7221_FreeDec16(G722_1_16_decinst_t_** dec_inst);
// int16_t WebRtcG7221_FreeDec24(G722_1_24_decinst_t_** dec_inst);
// int16_t WebRtcG7221_FreeDec32(G722_1_32_decinst_t_** dec_inst);
//
// int16_t WebRtcG7221_EncoderInit16(G722_1_16_encinst_t_* enc_inst);
// int16_t WebRtcG7221_EncoderInit24(G722_1_24_encinst_t_* enc_inst);
// int16_t WebRtcG7221_EncoderInit32(G722_1_32_encinst_t_* enc_inst);
// int16_t WebRtcG7221_DecoderInit16(G722_1_16_decinst_t_* dec_inst);
// int16_t WebRtcG7221_DecoderInit24(G722_1_24_decinst_t_* dec_inst);
// int16_t WebRtcG7221_DecoderInit32(G722_1_32_decinst_t_* dec_inst);
//
// int16_t WebRtcG7221_Encode16(G722_1_16_encinst_t_* enc_inst,
// int16_t* input,
// int16_t len,
// int16_t* output);
// int16_t WebRtcG7221_Encode24(G722_1_24_encinst_t_* enc_inst,
// int16_t* input,
// int16_t len,
// int16_t* output);
// int16_t WebRtcG7221_Encode32(G722_1_32_encinst_t_* enc_inst,
// int16_t* input,
// int16_t len,
// int16_t* output);
//
// int16_t WebRtcG7221_Decode16(G722_1_16_decinst_t_* dec_inst,
// int16_t* bitstream,
// int16_t len,
// int16_t* output);
// int16_t WebRtcG7221_Decode24(G722_1_24_decinst_t_* dec_inst,
// int16_t* bitstream,
// int16_t len,
// int16_t* output);
// int16_t WebRtcG7221_Decode32(G722_1_32_decinst_t_* dec_inst,
// int16_t* bitstream,
// int16_t len,
// int16_t* output);
//
// int16_t WebRtcG7221_DecodePlc16(G722_1_16_decinst_t_* dec_inst,
// int16_t* output,
// int16_t nr_lost_frames);
// int16_t WebRtcG7221_DecodePlc24(G722_1_24_decinst_t_* dec_inst,
// int16_t* output,
// int16_t nr_lost_frames);
// int16_t WebRtcG7221_DecodePlc32(G722_1_32_decinst_t_* dec_inst,
// int16_t* output,
// int16_t nr_lost_frames);
#include "g7221_interface.h"
#endif
namespace webrtc {
namespace acm1 {
#ifndef WEBRTC_CODEC_G722_1
ACMG722_1::ACMG722_1(int16_t /* codec_id */)
: operational_rate_(-1),
encoder_inst_ptr_(NULL),
encoder_inst_ptr_right_(NULL),
decoder_inst_ptr_(NULL),
encoder_inst16_ptr_(NULL),
encoder_inst16_ptr_right_(NULL),
encoder_inst24_ptr_(NULL),
encoder_inst24_ptr_right_(NULL),
encoder_inst32_ptr_(NULL),
encoder_inst32_ptr_right_(NULL),
decoder_inst16_ptr_(NULL),
decoder_inst24_ptr_(NULL),
decoder_inst32_ptr_(NULL) {
return;
}
ACMG722_1::~ACMG722_1() {
return;
}
int16_t ACMG722_1::InternalEncode(
uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */) {
return -1;
}
int16_t ACMG722_1::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return -1;
}
int16_t ACMG722_1::InternalInitEncoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int16_t ACMG722_1::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int32_t ACMG722_1::CodecDef(WebRtcNetEQ_CodecDef& /* codec_def */,
const CodecInst& /* codec_inst */) {
return -1;
}
ACMGenericCodec* ACMG722_1::CreateInstance(void) {
return NULL;
}
int16_t ACMG722_1::InternalCreateEncoder() {
return -1;
}
void ACMG722_1::DestructEncoderSafe() {
return;
}
int16_t ACMG722_1::InternalCreateDecoder() {
return -1;
}
void ACMG722_1::DestructDecoderSafe() {
return;
}
void ACMG722_1::InternalDestructEncoderInst(void* /* ptr_inst */) {
return;
}
#else //===================== Actual Implementation =======================
ACMG722_1::ACMG722_1(int16_t codec_id)
: encoder_inst_ptr_(NULL),
encoder_inst_ptr_right_(NULL),
decoder_inst_ptr_(NULL),
encoder_inst16_ptr_(NULL),
encoder_inst16_ptr_right_(NULL),
encoder_inst24_ptr_(NULL),
encoder_inst24_ptr_right_(NULL),
encoder_inst32_ptr_(NULL),
encoder_inst32_ptr_right_(NULL),
decoder_inst16_ptr_(NULL),
decoder_inst24_ptr_(NULL),
decoder_inst32_ptr_(NULL) {
codec_id_ = codec_id;
if (codec_id_ == ACMCodecDB::kG722_1_16) {
operational_rate_ = 16000;
} else if (codec_id_ == ACMCodecDB::kG722_1_24) {
operational_rate_ = 24000;
} else if (codec_id_ == ACMCodecDB::kG722_1_32) {
operational_rate_ = 32000;
} else {
operational_rate_ = -1;
}
return;
}
ACMG722_1::~ACMG722_1() {
if (encoder_inst_ptr_ != NULL) {
delete encoder_inst_ptr_;
encoder_inst_ptr_ = NULL;
}
if (encoder_inst_ptr_right_ != NULL) {
delete encoder_inst_ptr_right_;
encoder_inst_ptr_right_ = NULL;
}
if (decoder_inst_ptr_ != NULL) {
delete decoder_inst_ptr_;
decoder_inst_ptr_ = NULL;
}
switch (operational_rate_) {
case 16000: {
encoder_inst16_ptr_ = NULL;
encoder_inst16_ptr_right_ = NULL;
decoder_inst16_ptr_ = NULL;
break;
}
case 24000: {
encoder_inst24_ptr_ = NULL;
encoder_inst24_ptr_right_ = NULL;
decoder_inst24_ptr_ = NULL;
break;
}
case 32000: {
encoder_inst32_ptr_ = NULL;
encoder_inst32_ptr_right_ = NULL;
decoder_inst32_ptr_ = NULL;
break;
}
default: {
break;
}
}
return;
}
int16_t ACMG722_1::InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) {
int16_t left_channel[320];
int16_t right_channel[320];
int16_t len_in_bytes;
int16_t out_bits[160];
// If stereo, split input signal in left and right channel before encoding
if (num_channels_ == 2) {
for (int i = 0, j = 0; i < frame_len_smpl_ * 2; i += 2, j++) {
left_channel[j] = in_audio_[in_audio_ix_read_ + i];
right_channel[j] = in_audio_[in_audio_ix_read_ + i + 1];
}
} else {
memcpy(left_channel, &in_audio_[in_audio_ix_read_], 320);
}
switch (operational_rate_) {
case 16000: {
len_in_bytes = WebRtcG7221_Encode16(encoder_inst16_ptr_, left_channel,
320, &out_bits[0]);
if (num_channels_ == 2) {
len_in_bytes += WebRtcG7221_Encode16(encoder_inst16_ptr_right_,
right_channel, 320,
&out_bits[len_in_bytes / 2]);
}
break;
}
case 24000: {
len_in_bytes = WebRtcG7221_Encode24(encoder_inst24_ptr_, left_channel,
320, &out_bits[0]);
if (num_channels_ == 2) {
len_in_bytes += WebRtcG7221_Encode24(encoder_inst24_ptr_right_,
right_channel, 320,
&out_bits[len_in_bytes / 2]);
}
break;
}
case 32000: {
len_in_bytes = WebRtcG7221_Encode32(encoder_inst32_ptr_, left_channel,
320, &out_bits[0]);
if (num_channels_ == 2) {
len_in_bytes += WebRtcG7221_Encode32(encoder_inst32_ptr_right_,
right_channel, 320,
&out_bits[len_in_bytes / 2]);
}
break;
}
default: {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalInitEncode: Wrong rate for G722_1.");
return -1;
}
}
memcpy(bitstream, out_bits, len_in_bytes);
*bitstream_len_byte = len_in_bytes;
// increment the read index this tell the caller that how far
// we have gone forward in reading the audio buffer
in_audio_ix_read_ += 320 * num_channels_;
return *bitstream_len_byte;
}
int16_t ACMG722_1::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return 0;
}
int16_t ACMG722_1::InternalInitEncoder(
WebRtcACMCodecParams* codec_params) {
int16_t ret;
switch (operational_rate_) {
case 16000: {
ret = WebRtcG7221_EncoderInit16(encoder_inst16_ptr_right_);
if (ret < 0) {
return ret;
}
return WebRtcG7221_EncoderInit16(encoder_inst16_ptr_);
}
case 24000: {
ret = WebRtcG7221_EncoderInit24(encoder_inst24_ptr_right_);
if (ret < 0) {
return ret;
}
return WebRtcG7221_EncoderInit24(encoder_inst24_ptr_);
}
case 32000: {
ret = WebRtcG7221_EncoderInit32(encoder_inst32_ptr_right_);
if (ret < 0) {
return ret;
}
return WebRtcG7221_EncoderInit32(encoder_inst32_ptr_);
}
default: {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding,
unique_id_, "InternalInitEncoder: Wrong rate for G722_1.");
return -1;
}
}
}
int16_t ACMG722_1::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
switch (operational_rate_) {
case 16000: {
return WebRtcG7221_DecoderInit16(decoder_inst16_ptr_);
}
case 24000: {
return WebRtcG7221_DecoderInit24(decoder_inst24_ptr_);
}
case 32000: {
return WebRtcG7221_DecoderInit32(decoder_inst32_ptr_);
}
default: {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalInitDecoder: Wrong rate for G722_1.");
return -1;
}
}
}
int32_t ACMG722_1::CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) {
if (!decoder_initialized_) {
// Todo:
// log error
return -1;
}
// NetEq has an array of pointers to WebRtcNetEQ_CodecDef.
// Get an entry of that array (neteq wrapper will allocate memory)
// by calling "netEq->CodecDef", where "NETEQ_CODEC_G722_1_XX" would
// be the index of the entry.
// Fill up the given structure by calling
// "SET_CODEC_PAR" & "SET_G722_1_XX_FUNCTION."
// Then return the structure back to NetEQ to add the codec to it's
// database.
switch (operational_rate_) {
case 16000: {
SET_CODEC_PAR((codec_def), kDecoderG722_1_16, codec_inst.pltype,
decoder_inst16_ptr_, 16000);
SET_G722_1_16_FUNCTIONS((codec_def));
break;
}
case 24000: {
SET_CODEC_PAR((codec_def), kDecoderG722_1_24, codec_inst.pltype,
decoder_inst24_ptr_, 16000);
SET_G722_1_24_FUNCTIONS((codec_def));
break;
}
case 32000: {
SET_CODEC_PAR((codec_def), kDecoderG722_1_32, codec_inst.pltype,
decoder_inst32_ptr_, 16000);
SET_G722_1_32_FUNCTIONS((codec_def));
break;
}
default: {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"CodecDef: Wrong rate for G722_1.");
return -1;
}
}
return 0;
}
ACMGenericCodec* ACMG722_1::CreateInstance(void) {
return NULL;
}
int16_t ACMG722_1::InternalCreateEncoder() {
if ((encoder_inst_ptr_ == NULL) || (encoder_inst_ptr_right_ == NULL)) {
return -1;
}
switch (operational_rate_) {
case 16000: {
WebRtcG7221_CreateEnc16(&encoder_inst16_ptr_);
WebRtcG7221_CreateEnc16(&encoder_inst16_ptr_right_);
break;
}
case 24000: {
WebRtcG7221_CreateEnc24(&encoder_inst24_ptr_);
WebRtcG7221_CreateEnc24(&encoder_inst24_ptr_right_);
break;
}
case 32000: {
WebRtcG7221_CreateEnc32(&encoder_inst32_ptr_);
WebRtcG7221_CreateEnc32(&encoder_inst32_ptr_right_);
break;
}
default: {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalCreateEncoder: Wrong rate for G722_1.");
return -1;
}
}
return 0;
}
void ACMG722_1::DestructEncoderSafe() {
encoder_exist_ = false;
encoder_initialized_ = false;
if (encoder_inst_ptr_ != NULL) {
delete encoder_inst_ptr_;
encoder_inst_ptr_ = NULL;
}
if (encoder_inst_ptr_right_ != NULL) {
delete encoder_inst_ptr_right_;
encoder_inst_ptr_right_ = NULL;
}
encoder_inst16_ptr_ = NULL;
encoder_inst24_ptr_ = NULL;
encoder_inst32_ptr_ = NULL;
}
int16_t ACMG722_1::InternalCreateDecoder() {
if (decoder_inst_ptr_ == NULL) {
return -1;
}
switch (operational_rate_) {
case 16000: {
WebRtcG7221_CreateDec16(&decoder_inst16_ptr_);
break;
}
case 24000: {
WebRtcG7221_CreateDec24(&decoder_inst24_ptr_);
break;
}
case 32000: {
WebRtcG7221_CreateDec32(&decoder_inst32_ptr_);
break;
}
default: {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalCreateDecoder: Wrong rate for G722_1.");
return -1;
}
}
return 0;
}
void ACMG722_1::DestructDecoderSafe() {
decoder_exist_ = false;
decoder_initialized_ = false;
if (decoder_inst_ptr_ != NULL) {
delete decoder_inst_ptr_;
decoder_inst_ptr_ = NULL;
}
decoder_inst16_ptr_ = NULL;
decoder_inst24_ptr_ = NULL;
decoder_inst32_ptr_ = NULL;
}
void ACMG722_1::InternalDestructEncoderInst(void* ptr_inst) {
if (ptr_inst != NULL) {
delete ptr_inst;
}
return;
}
#endif
} // namespace acm1
} // namespace webrtc

View File

@ -1,86 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G7221_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G7221_H_
#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
// forward declaration
struct G722_1_16_encinst_t_;
struct G722_1_16_decinst_t_;
struct G722_1_24_encinst_t_;
struct G722_1_24_decinst_t_;
struct G722_1_32_encinst_t_;
struct G722_1_32_decinst_t_;
struct G722_1_Inst_t_;
namespace webrtc {
namespace acm1 {
class ACMG722_1: public ACMGenericCodec {
public:
explicit ACMG722_1(int16_t codec_id);
~ACMG722_1();
// for FEC
ACMGenericCodec* CreateInstance(void);
int16_t InternalEncode(uint8_t* bitstream, int16_t* bitstream_len_byte);
int16_t InternalInitEncoder(WebRtcACMCodecParams *codec_params);
int16_t InternalInitDecoder(WebRtcACMCodecParams *codec_params);
protected:
int16_t DecodeSafe(uint8_t* bitstream,
int16_t bitstream_len_byte,
int16_t* audio, int16_t* audio_samples,
int8_t* speech_type);
int32_t CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst);
void DestructEncoderSafe();
void DestructDecoderSafe();
int16_t InternalCreateEncoder();
int16_t InternalCreateDecoder();
void InternalDestructEncoderInst(void* ptr_inst);
int32_t operational_rate_;
G722_1_Inst_t_* encoder_inst_ptr_;
G722_1_Inst_t_* encoder_inst_ptr_right_; // Used in stereo mode
G722_1_Inst_t_* decoder_inst_ptr_;
// Only one set of these pointer is valid at any instance
G722_1_16_encinst_t_* encoder_inst16_ptr_;
G722_1_16_encinst_t_* encoder_inst16_ptr_right_;
G722_1_24_encinst_t_* encoder_inst24_ptr_;
G722_1_24_encinst_t_* encoder_inst24_ptr_right_;
G722_1_32_encinst_t_* encoder_inst32_ptr_;
G722_1_32_encinst_t_* encoder_inst32_ptr_right_;
// Only one of these pointer is valid at any instance
G722_1_16_decinst_t_* decoder_inst16_ptr_;
G722_1_24_decinst_t_* decoder_inst24_ptr_;
G722_1_32_decinst_t_* decoder_inst32_ptr_;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G7221_H_

View File

@ -1,510 +0,0 @@
/*
* 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/source/acm_g7221c.h"
#include "webrtc/modules/audio_coding/main/source/acm_codec_database.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
#include "webrtc/system_wrappers/interface/trace.h"
#ifdef WEBRTC_CODEC_G722_1C
// NOTE! G.722.1C is not included in the open-source package. The following
// interface file is needed:
//
// /modules/audio_coding/codecs/g7221c/main/interface/g7221c_interface.h
//
// The API in the header file should match the one below.
//
// int16_t WebRtcG7221C_CreateEnc24(G722_1C_24_encinst_t_** enc_inst);
// int16_t WebRtcG7221C_CreateEnc32(G722_1C_32_encinst_t_** enc_inst);
// int16_t WebRtcG7221C_CreateEnc48(G722_1C_48_encinst_t_** enc_inst);
// int16_t WebRtcG7221C_CreateDec24(G722_1C_24_decinst_t_** dec_inst);
// int16_t WebRtcG7221C_CreateDec32(G722_1C_32_decinst_t_** dec_inst);
// int16_t WebRtcG7221C_CreateDec48(G722_1C_48_decinst_t_** dec_inst);
//
// int16_t WebRtcG7221C_FreeEnc24(G722_1C_24_encinst_t_** enc_inst);
// int16_t WebRtcG7221C_FreeEnc32(G722_1C_32_encinst_t_** enc_inst);
// int16_t WebRtcG7221C_FreeEnc48(G722_1C_48_encinst_t_** enc_inst);
// int16_t WebRtcG7221C_FreeDec24(G722_1C_24_decinst_t_** dec_inst);
// int16_t WebRtcG7221C_FreeDec32(G722_1C_32_decinst_t_** dec_inst);
// int16_t WebRtcG7221C_FreeDec48(G722_1C_48_decinst_t_** dec_inst);
//
// int16_t WebRtcG7221C_EncoderInit24(G722_1C_24_encinst_t_* enc_inst);
// int16_t WebRtcG7221C_EncoderInit32(G722_1C_32_encinst_t_* enc_inst);
// int16_t WebRtcG7221C_EncoderInit48(G722_1C_48_encinst_t_* enc_inst);
// int16_t WebRtcG7221C_DecoderInit24(G722_1C_24_decinst_t_* dec_inst);
// int16_t WebRtcG7221C_DecoderInit32(G722_1C_32_decinst_t_* dec_inst);
// int16_t WebRtcG7221C_DecoderInit48(G722_1C_48_decinst_t_* dec_inst);
//
// int16_t WebRtcG7221C_Encode24(G722_1C_24_encinst_t_* enc_inst,
// int16_t* input,
// int16_t len,
// int16_t* output);
// int16_t WebRtcG7221C_Encode32(G722_1C_32_encinst_t_* enc_inst,
// int16_t* input,
// int16_t len,
// int16_t* output);
// int16_t WebRtcG7221C_Encode48(G722_1C_48_encinst_t_* enc_inst,
// int16_t* input,
// int16_t len,
// int16_t* output);
//
// int16_t WebRtcG7221C_Decode24(G722_1C_24_decinst_t_* dec_inst,
// int16_t* bitstream,
// int16_t len,
// int16_t* output);
// int16_t WebRtcG7221C_Decode32(G722_1C_32_decinst_t_* dec_inst,
// int16_t* bitstream,
// int16_t len,
// int16_t* output);
// int16_t WebRtcG7221C_Decode48(G722_1C_48_decinst_t_* dec_inst,
// int16_t* bitstream,
// int16_t len,
// int16_t* output);
//
// int16_t WebRtcG7221C_DecodePlc24(G722_1C_24_decinst_t_* dec_inst,
// int16_t* output,
// int16_t nr_lost_frames);
// int16_t WebRtcG7221C_DecodePlc32(G722_1C_32_decinst_t_* dec_inst,
// int16_t* output,
// int16_t nr_lost_frames);
// int16_t WebRtcG7221C_DecodePlc48(G722_1C_48_decinst_t_* dec_inst,
// int16_t* output,
// int16_t nr_lost_frames);
#include "g7221c_interface.h"
#endif
namespace webrtc {
namespace acm1 {
#ifndef WEBRTC_CODEC_G722_1C
ACMG722_1C::ACMG722_1C(int16_t /* codec_id */)
: operational_rate_(-1),
encoder_inst_ptr_(NULL),
encoder_inst_ptr_right_(NULL),
decoder_inst_ptr_(NULL),
encoder_inst24_ptr_(NULL),
encoder_inst24_ptr_right_(NULL),
encoder_inst32_ptr_(NULL),
encoder_inst32_ptr_right_(NULL),
encoder_inst48_ptr_(NULL),
encoder_inst48_ptr_right_(NULL),
decoder_inst24_ptr_(NULL),
decoder_inst32_ptr_(NULL),
decoder_inst48_ptr_(NULL) {
return;
}
ACMG722_1C::~ACMG722_1C() {
return;
}
int16_t ACMG722_1C::InternalEncode(
uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */) {
return -1;
}
int16_t ACMG722_1C::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return -1;
}
int16_t ACMG722_1C::InternalInitEncoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int16_t ACMG722_1C::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int32_t ACMG722_1C::CodecDef(WebRtcNetEQ_CodecDef& /* codec_def */,
const CodecInst& /* codec_inst */) {
return -1;
}
ACMGenericCodec* ACMG722_1C::CreateInstance(void) {
return NULL;
}
int16_t ACMG722_1C::InternalCreateEncoder() {
return -1;
}
void ACMG722_1C::DestructEncoderSafe() {
return;
}
int16_t ACMG722_1C::InternalCreateDecoder() {
return -1;
}
void ACMG722_1C::DestructDecoderSafe() {
return;
}
void ACMG722_1C::InternalDestructEncoderInst(void* /* ptr_inst */) {
return;
}
#else //===================== Actual Implementation =======================
ACMG722_1C::ACMG722_1C(int16_t codec_id)
: encoder_inst_ptr_(NULL),
encoder_inst_ptr_right_(NULL),
decoder_inst_ptr_(NULL),
encoder_inst24_ptr_(NULL),
encoder_inst24_ptr_right_(NULL),
encoder_inst32_ptr_(NULL),
encoder_inst32_ptr_right_(NULL),
encoder_inst48_ptr_(NULL),
encoder_inst48_ptr_right_(NULL),
decoder_inst24_ptr_(NULL),
decoder_inst32_ptr_(NULL),
decoder_inst48_ptr_(NULL) {
codec_id_ = codec_id;
if (codec_id_ == ACMCodecDB::kG722_1C_24) {
operational_rate_ = 24000;
} else if (codec_id_ == ACMCodecDB::kG722_1C_32) {
operational_rate_ = 32000;
} else if (codec_id_ == ACMCodecDB::kG722_1C_48) {
operational_rate_ = 48000;
} else {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Wrong codec id for G722_1c.");
operational_rate_ = -1;
}
return;
}
ACMG722_1C::~ACMG722_1C() {
if (encoder_inst_ptr_ != NULL) {
delete encoder_inst_ptr_;
encoder_inst_ptr_ = NULL;
}
if (encoder_inst_ptr_right_ != NULL) {
delete encoder_inst_ptr_right_;
encoder_inst_ptr_right_ = NULL;
}
if (decoder_inst_ptr_ != NULL) {
delete decoder_inst_ptr_;
decoder_inst_ptr_ = NULL;
}
switch (operational_rate_) {
case 24000: {
encoder_inst24_ptr_ = NULL;
encoder_inst24_ptr_right_ = NULL;
decoder_inst24_ptr_ = NULL;
break;
}
case 32000: {
encoder_inst32_ptr_ = NULL;
encoder_inst32_ptr_right_ = NULL;
decoder_inst32_ptr_ = NULL;
break;
}
case 48000: {
encoder_inst48_ptr_ = NULL;
encoder_inst48_ptr_right_ = NULL;
decoder_inst48_ptr_ = NULL;
break;
}
default: {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Wrong rate for G722_1c.");
break;
}
}
return;
}
int16_t ACMG722_1C::InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) {
int16_t left_channel[640];
int16_t right_channel[640];
int16_t len_in_bytes;
int16_t out_bits[240];
// If stereo, split input signal in left and right channel before encoding
if (num_channels_ == 2) {
for (int i = 0, j = 0; i < frame_len_smpl_ * 2; i += 2, j++) {
left_channel[j] = in_audio_[in_audio_ix_read_ + i];
right_channel[j] = in_audio_[in_audio_ix_read_ + i + 1];
}
} else {
memcpy(left_channel, &in_audio_[in_audio_ix_read_], 640);
}
switch (operational_rate_) {
case 24000: {
len_in_bytes = WebRtcG7221C_Encode24(encoder_inst24_ptr_, left_channel,
640, &out_bits[0]);
if (num_channels_ == 2) {
len_in_bytes += WebRtcG7221C_Encode24(encoder_inst24_ptr_right_,
right_channel, 640,
&out_bits[len_in_bytes / 2]);
}
break;
}
case 32000: {
len_in_bytes = WebRtcG7221C_Encode32(encoder_inst32_ptr_, left_channel,
640, &out_bits[0]);
if (num_channels_ == 2) {
len_in_bytes += WebRtcG7221C_Encode32(encoder_inst32_ptr_right_,
right_channel, 640,
&out_bits[len_in_bytes / 2]);
}
break;
}
case 48000: {
len_in_bytes = WebRtcG7221C_Encode48(encoder_inst48_ptr_, left_channel,
640, &out_bits[0]);
if (num_channels_ == 2) {
len_in_bytes += WebRtcG7221C_Encode48(encoder_inst48_ptr_right_,
right_channel, 640,
&out_bits[len_in_bytes / 2]);
}
break;
}
default: {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalEncode: Wrong rate for G722_1c.");
return -1;
}
}
memcpy(bitstream, out_bits, len_in_bytes);
*bitstream_len_byte = len_in_bytes;
// increment the read index this tell the caller that how far
// we have gone forward in reading the audio buffer
in_audio_ix_read_ += 640 * num_channels_;
return *bitstream_len_byte;
}
int16_t ACMG722_1C::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return 0;
}
int16_t ACMG722_1C::InternalInitEncoder(
WebRtcACMCodecParams* codec_params) {
int16_t ret;
switch (operational_rate_) {
case 24000: {
ret = WebRtcG7221C_EncoderInit24(encoder_inst24_ptr_right_);
if (ret < 0) {
return ret;
}
return WebRtcG7221C_EncoderInit24(encoder_inst24_ptr_);
}
case 32000: {
ret = WebRtcG7221C_EncoderInit32(encoder_inst32_ptr_right_);
if (ret < 0) {
return ret;
}
return WebRtcG7221C_EncoderInit32(encoder_inst32_ptr_);
}
case 48000: {
ret = WebRtcG7221C_EncoderInit48(encoder_inst48_ptr_right_);
if (ret < 0) {
return ret;
}
return WebRtcG7221C_EncoderInit48(encoder_inst48_ptr_);
}
default: {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalInitEncode: Wrong rate for G722_1c.");
return -1;
}
}
}
int16_t ACMG722_1C::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
switch (operational_rate_) {
case 24000: {
return WebRtcG7221C_DecoderInit24(decoder_inst24_ptr_);
}
case 32000: {
return WebRtcG7221C_DecoderInit32(decoder_inst32_ptr_);
}
case 48000: {
return WebRtcG7221C_DecoderInit48(decoder_inst48_ptr_);
}
default: {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalInitDecoder: Wrong rate for G722_1c.");
return -1;
}
}
}
int32_t ACMG722_1C::CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) {
if (!decoder_initialized_) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"CodeDef: decoder not initialized for G722_1c");
return -1;
}
// NetEq has an array of pointers to WebRtcNetEQ_CodecDef.
// get an entry of that array (neteq wrapper will allocate memory)
// by calling "netEq->CodecDef", where "NETEQ_CODEC_G722_1_XX" would
// be the index of the entry.
// Fill up the given structure by calling
// "SET_CODEC_PAR" & "SET_G722_1_XX_FUNCTION."
// Then return the structure back to NetEQ to add the codec to it's
// database.
switch (operational_rate_) {
case 24000: {
SET_CODEC_PAR((codec_def), kDecoderG722_1C_24, codec_inst.pltype,
decoder_inst24_ptr_, 32000);
SET_G722_1C_24_FUNCTIONS((codec_def));
break;
}
case 32000: {
SET_CODEC_PAR((codec_def), kDecoderG722_1C_32, codec_inst.pltype,
decoder_inst32_ptr_, 32000);
SET_G722_1C_32_FUNCTIONS((codec_def));
break;
}
case 48000: {
SET_CODEC_PAR((codec_def), kDecoderG722_1C_32, codec_inst.pltype,
decoder_inst48_ptr_, 32000);
SET_G722_1C_48_FUNCTIONS((codec_def));
break;
}
default: {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"CodeDef: Wrong rate for G722_1c.");
return -1;
}
}
return 0;
}
ACMGenericCodec*
ACMG722_1C::CreateInstance(void) {
return NULL;
}
int16_t ACMG722_1C::InternalCreateEncoder() {
if ((encoder_inst_ptr_ == NULL) || (encoder_inst_ptr_right_ == NULL)) {
return -1;
}
switch (operational_rate_) {
case 24000: {
WebRtcG7221C_CreateEnc24(&encoder_inst24_ptr_);
WebRtcG7221C_CreateEnc24(&encoder_inst24_ptr_right_);
break;
}
case 32000: {
WebRtcG7221C_CreateEnc32(&encoder_inst32_ptr_);
WebRtcG7221C_CreateEnc32(&encoder_inst32_ptr_right_);
break;
}
case 48000: {
WebRtcG7221C_CreateEnc48(&encoder_inst48_ptr_);
WebRtcG7221C_CreateEnc48(&encoder_inst48_ptr_right_);
break;
}
default: {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalCreateEncoder: Wrong rate for G722_1c.");
return -1;
}
}
return 0;
}
void ACMG722_1C::DestructEncoderSafe() {
encoder_exist_ = false;
encoder_initialized_ = false;
if (encoder_inst_ptr_ != NULL) {
delete encoder_inst_ptr_;
encoder_inst_ptr_ = NULL;
}
if (encoder_inst_ptr_right_ != NULL) {
delete encoder_inst_ptr_right_;
encoder_inst_ptr_right_ = NULL;
}
encoder_inst24_ptr_ = NULL;
encoder_inst32_ptr_ = NULL;
encoder_inst48_ptr_ = NULL;
}
int16_t ACMG722_1C::InternalCreateDecoder() {
if (decoder_inst_ptr_ == NULL) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalCreateEncoder: cannot create decoder");
return -1;
}
switch (operational_rate_) {
case 24000: {
WebRtcG7221C_CreateDec24(&decoder_inst24_ptr_);
break;
}
case 32000: {
WebRtcG7221C_CreateDec32(&decoder_inst32_ptr_);
break;
}
case 48000: {
WebRtcG7221C_CreateDec48(&decoder_inst48_ptr_);
break;
}
default: {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalCreateEncoder: Wrong rate for G722_1c.");
return -1;
}
}
return 0;
}
void ACMG722_1C::DestructDecoderSafe() {
decoder_exist_ = false;
decoder_initialized_ = false;
if (decoder_inst_ptr_ != NULL) {
delete decoder_inst_ptr_;
decoder_inst_ptr_ = NULL;
}
decoder_inst24_ptr_ = NULL;
decoder_inst32_ptr_ = NULL;
decoder_inst48_ptr_ = NULL;
}
void ACMG722_1C::InternalDestructEncoderInst(void* ptr_inst) {
if (ptr_inst != NULL) {
delete ptr_inst;
}
return;
}
#endif
} // namespace acm1
} // namespace webrtc

View File

@ -1,94 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G7221C_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G7221C_H_
#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
// forward declaration
struct G722_1C_24_encinst_t_;
struct G722_1C_24_decinst_t_;
struct G722_1C_32_encinst_t_;
struct G722_1C_32_decinst_t_;
struct G722_1C_48_encinst_t_;
struct G722_1C_48_decinst_t_;
struct G722_1_Inst_t_;
namespace webrtc {
namespace acm1 {
class ACMG722_1C : public ACMGenericCodec {
public:
explicit ACMG722_1C(int16_t codec_id);
~ACMG722_1C();
// for FEC
ACMGenericCodec* CreateInstance(void);
int16_t InternalEncode(
uint8_t* bitstream,
int16_t* bitstream_len_byte);
int16_t InternalInitEncoder(
WebRtcACMCodecParams *codec_params);
int16_t InternalInitDecoder(
WebRtcACMCodecParams *codec_params);
protected:
int16_t DecodeSafe(
uint8_t* bitstream,
int16_t bitstream_len_byte,
int16_t* audio,
int16_t* audio_samples,
int8_t* speech_type);
int32_t CodecDef(
WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst);
void DestructEncoderSafe();
void DestructDecoderSafe();
int16_t InternalCreateEncoder();
int16_t InternalCreateDecoder();
void InternalDestructEncoderInst(
void* ptr_inst);
int32_t operational_rate_;
G722_1_Inst_t_* encoder_inst_ptr_;
G722_1_Inst_t_* encoder_inst_ptr_right_; // Used in stereo mode
G722_1_Inst_t_* decoder_inst_ptr_;
// Only one set of these pointer is valid at any instance
G722_1C_24_encinst_t_* encoder_inst24_ptr_;
G722_1C_24_encinst_t_* encoder_inst24_ptr_right_;
G722_1C_32_encinst_t_* encoder_inst32_ptr_;
G722_1C_32_encinst_t_* encoder_inst32_ptr_right_;
G722_1C_48_encinst_t_* encoder_inst48_ptr_;
G722_1C_48_encinst_t_* encoder_inst48_ptr_right_;
// Only one of these pointer is valid at any instance
G722_1C_24_decinst_t_* decoder_inst24_ptr_;
G722_1C_32_decinst_t_* decoder_inst32_ptr_;
G722_1C_48_decinst_t_* decoder_inst48_ptr_;
};
} // namespace acm1
} // namespace webrtc;
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G7221C_H_

View File

@ -1,366 +0,0 @@
/*
* 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/source/acm_g729.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
#include "webrtc/system_wrappers/interface/trace.h"
#ifdef WEBRTC_CODEC_G729
// NOTE! G.729 is not included in the open-source package. Modify this file
// or your codec API to match the function calls and names of used G.729 API
// file.
#include "g729_interface.h"
#endif
namespace webrtc {
namespace acm1 {
#ifndef WEBRTC_CODEC_G729
ACMG729::ACMG729(int16_t /* codec_id */)
: encoder_inst_ptr_(NULL),
decoder_inst_ptr_(NULL) {
return;
}
ACMG729::~ACMG729() {
return;
}
int16_t ACMG729::InternalEncode(
uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */) {
return -1;
}
int16_t ACMG729::EnableDTX() {
return -1;
}
int16_t ACMG729::DisableDTX() {
return -1;
}
int32_t ACMG729::ReplaceInternalDTXSafe(
const bool /*replace_internal_dtx */) {
return -1;
}
int32_t ACMG729::IsInternalDTXReplacedSafe(
bool* /* internal_dtx_replaced */) {
return -1;
}
int16_t ACMG729::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return -1;
}
int16_t ACMG729::InternalInitEncoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int16_t ACMG729::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int32_t ACMG729::CodecDef(WebRtcNetEQ_CodecDef& /* codec_def */,
const CodecInst& /* codec_inst */) {
return -1;
}
ACMGenericCodec* ACMG729::CreateInstance(void) {
return NULL;
}
int16_t ACMG729::InternalCreateEncoder() {
return -1;
}
void ACMG729::DestructEncoderSafe() {
return;
}
int16_t ACMG729::InternalCreateDecoder() {
return -1;
}
void ACMG729::DestructDecoderSafe() {
return;
}
void ACMG729::InternalDestructEncoderInst(void* /* ptr_inst */) {
return;
}
#else //===================== Actual Implementation =======================
ACMG729::ACMG729(int16_t codec_id)
: encoder_inst_ptr_(NULL),
decoder_inst_ptr_(NULL) {
codec_id_ = codec_id;
has_internal_dtx_ = true;
return;
}
ACMG729::~ACMG729() {
if (encoder_inst_ptr_ != NULL) {
// Delete encoder memory
WebRtcG729_FreeEnc(encoder_inst_ptr_);
encoder_inst_ptr_ = NULL;
}
if (decoder_inst_ptr_ != NULL) {
// Delete decoder memory
WebRtcG729_FreeDec(decoder_inst_ptr_);
decoder_inst_ptr_ = NULL;
}
return;
}
int16_t ACMG729::InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) {
// Initialize before entering the loop
int16_t num_encoded_samples = 0;
int16_t tmp_len_byte = 0;
int16_t vad_decision = 0;
*bitstream_len_byte = 0;
while (num_encoded_samples < frame_len_smpl_) {
// Call G.729 encoder with pointer to encoder memory, input
// audio, number of samples and bitsream
tmp_len_byte = WebRtcG729_Encode(
encoder_inst_ptr_, &in_audio_[in_audio_ix_read_], 80,
(int16_t*)(&(bitstream[*bitstream_len_byte])));
// increment the read index this tell the caller that how far
// we have gone forward in reading the audio buffer
in_audio_ix_read_ += 80;
// sanity check
if (tmp_len_byte < 0) {
// error has happened
*bitstream_len_byte = 0;
return -1;
}
// increment number of written bytes
*bitstream_len_byte += tmp_len_byte;
switch (tmp_len_byte) {
case 0: {
if (0 == num_encoded_samples) {
// this is the first 10 ms in this packet and there is
// no data generated, perhaps DTX is enabled and the
// codec is not generating any bit-stream for this 10 ms.
// we do not continue encoding this frame.
return 0;
}
break;
}
case 2: {
// check if G.729 internal DTX is enabled
if (has_internal_dtx_ && dtx_enabled_) {
vad_decision = 0;
for (int16_t n = 0; n < MAX_FRAME_SIZE_10MSEC; n++) {
vad_label_[n] = vad_decision;
}
}
// we got a SID and have to send out this packet no matter
// how much audio we have encoded
return *bitstream_len_byte;
}
case 10: {
vad_decision = 1;
// this is a valid length just continue encoding
break;
}
default: {
return -1;
}
}
// update number of encoded samples
num_encoded_samples += 80;
}
// update VAD decision vector
if (has_internal_dtx_ && !vad_decision && dtx_enabled_) {
for (int16_t n = 0; n < MAX_FRAME_SIZE_10MSEC; n++) {
vad_label_[n] = vad_decision;
}
}
// done encoding, return number of encoded bytes
return *bitstream_len_byte;
}
int16_t ACMG729::EnableDTX() {
if (dtx_enabled_) {
// DTX already enabled, do nothing
return 0;
} else if (encoder_exist_) {
// Re-init the G.729 encoder to turn on DTX
if (WebRtcG729_EncoderInit(encoder_inst_ptr_, 1) < 0) {
return -1;
}
dtx_enabled_ = true;
return 0;
} else {
return -1;
}
}
int16_t ACMG729::DisableDTX() {
if (!dtx_enabled_) {
// DTX already dissabled, do nothing
return 0;
} else if (encoder_exist_) {
// Re-init the G.729 decoder to turn off DTX
if (WebRtcG729_EncoderInit(encoder_inst_ptr_, 0) < 0) {
return -1;
}
dtx_enabled_ = false;
return 0;
} else {
// encoder doesn't exists, therefore disabling is harmless
return 0;
}
}
int32_t ACMG729::ReplaceInternalDTXSafe(const bool replace_internal_dtx) {
// This function is used to disable the G.729 built in DTX and use an
// external instead.
if (replace_internal_dtx == has_internal_dtx_) {
// Make sure we keep the DTX/VAD setting if possible
bool old_enable_dtx = dtx_enabled_;
bool old_enable_vad = vad_enabled_;
ACMVADMode old_mode = vad_mode_;
if (replace_internal_dtx) {
// Disable internal DTX before enabling external DTX
DisableDTX();
} else {
// Disable external DTX before enabling internal
ACMGenericCodec::DisableDTX();
}
has_internal_dtx_ = !replace_internal_dtx;
int16_t status = SetVADSafe(old_enable_dtx, old_enable_vad, old_mode);
// Check if VAD status has changed from inactive to active, or if error was
// reported
if (status == 1) {
vad_enabled_ = true;
return status;
} else if (status < 0) {
has_internal_dtx_ = replace_internal_dtx;
return -1;
}
}
return 0;
}
int32_t ACMG729::IsInternalDTXReplacedSafe(bool* internal_dtx_replaced) {
// Get status of wether DTX is replaced or not
*internal_dtx_replaced = !has_internal_dtx_;
return 0;
}
int16_t ACMG729::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
// This function is not used. G.729 decoder is called from inside NetEQ
return 0;
}
int16_t ACMG729::InternalInitEncoder(WebRtcACMCodecParams* codec_params) {
// Init G.729 encoder
return WebRtcG729_EncoderInit(encoder_inst_ptr_,
((codec_params->enable_dtx) ? 1 : 0));
}
int16_t ACMG729::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
// Init G.729 decoder
return WebRtcG729_DecoderInit(decoder_inst_ptr_);
}
int32_t ACMG729::CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) {
if (!decoder_initialized_) {
// Todo:
// log error
return -1;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_G729_FUNCTION."
// Then call NetEQ to add the codec to it's
// database.
SET_CODEC_PAR((codec_def), kDecoderG729, codec_inst.pltype, decoder_inst_ptr_,
8000);
SET_G729_FUNCTIONS((codec_def));
return 0;
}
ACMGenericCodec* ACMG729::CreateInstance(void) {
// Function not used
return NULL;
}
int16_t ACMG729::InternalCreateEncoder() {
// Create encoder memory
return WebRtcG729_CreateEnc(&encoder_inst_ptr_);
}
void ACMG729::DestructEncoderSafe() {
// Free encoder memory
encoder_exist_ = false;
encoder_initialized_ = false;
if (encoder_inst_ptr_ != NULL) {
WebRtcG729_FreeEnc(encoder_inst_ptr_);
encoder_inst_ptr_ = NULL;
}
}
int16_t ACMG729::InternalCreateDecoder() {
// Create decoder memory
return WebRtcG729_CreateDec(&decoder_inst_ptr_);
}
void ACMG729::DestructDecoderSafe() {
// Free decoder memory
decoder_exist_ = false;
decoder_initialized_ = false;
if (decoder_inst_ptr_ != NULL) {
WebRtcG729_FreeDec(decoder_inst_ptr_);
decoder_inst_ptr_ = NULL;
}
}
void ACMG729::InternalDestructEncoderInst(void* ptr_inst) {
if (ptr_inst != NULL) {
WebRtcG729_FreeEnc((G729_encinst_t_*) ptr_inst);
}
return;
}
#endif
} // namespace acm1
} // namespace webrtc

View File

@ -1,76 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G729_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G729_H_
#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
// forward declaration
struct G729_encinst_t_;
struct G729_decinst_t_;
namespace webrtc {
namespace acm1 {
class ACMG729 : public ACMGenericCodec {
public:
explicit ACMG729(int16_t codec_id);
~ACMG729();
// for FEC
ACMGenericCodec* CreateInstance(void);
int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte);
int16_t InternalInitEncoder(WebRtcACMCodecParams *codec_params);
int16_t InternalInitDecoder(WebRtcACMCodecParams *codec_params);
protected:
int16_t DecodeSafe(uint8_t* bitstream,
int16_t bitstream_len_byte,
int16_t* audio,
int16_t* audio_samples,
int8_t* speech_type);
int32_t CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst);
void DestructEncoderSafe();
void DestructDecoderSafe();
int16_t InternalCreateEncoder();
int16_t InternalCreateDecoder();
void InternalDestructEncoderInst(void* ptr_inst);
int16_t EnableDTX();
int16_t DisableDTX();
int32_t ReplaceInternalDTXSafe(const bool replace_internal_dtx);
int32_t IsInternalDTXReplacedSafe(bool* internal_dtx_replaced);
G729_encinst_t_* encoder_inst_ptr_;
G729_decinst_t_* decoder_inst_ptr_;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G729_H_

View File

@ -1,349 +0,0 @@
/*
* 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/source/acm_g7291.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
#include "webrtc/system_wrappers/interface/trace.h"
#ifdef WEBRTC_CODEC_G729_1
// NOTE! G.729.1 is not included in the open-source package. Modify this file
// or your codec API to match the function calls and names of used G.729.1 API
// file.
#include "g7291_interface.h"
#endif
namespace webrtc {
namespace acm1 {
#ifndef WEBRTC_CODEC_G729_1
ACMG729_1::ACMG729_1(int16_t /* codec_id */)
: encoder_inst_ptr_(NULL),
decoder_inst_ptr_(NULL),
my_rate_(32000),
flag_8khz_(0),
flag_g729_mode_(0) {
return;
}
ACMG729_1::~ACMG729_1() {
return;
}
int16_t ACMG729_1::InternalEncode(
uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */) {
return -1;
}
int16_t ACMG729_1::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return -1;
}
int16_t ACMG729_1::InternalInitEncoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int16_t ACMG729_1::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int32_t ACMG729_1::CodecDef(WebRtcNetEQ_CodecDef& /* codec_def */,
const CodecInst& /* codec_inst */) {
return -1;
}
ACMGenericCodec* ACMG729_1::CreateInstance(void) {
return NULL;
}
int16_t ACMG729_1::InternalCreateEncoder() {
return -1;
}
void ACMG729_1::DestructEncoderSafe() {
return;
}
int16_t ACMG729_1::InternalCreateDecoder() {
return -1;
}
void ACMG729_1::DestructDecoderSafe() {
return;
}
void ACMG729_1::InternalDestructEncoderInst(void* /* ptr_inst */) {
return;
}
int16_t ACMG729_1::SetBitRateSafe(const int32_t /*rate*/) {
return -1;
}
#else //===================== Actual Implementation =======================
struct G729_1_inst_t_;
ACMG729_1::ACMG729_1(int16_t codec_id)
: encoder_inst_ptr_(NULL),
decoder_inst_ptr_(NULL),
my_rate_(32000), // Default rate.
flag_8khz_(0),
flag_g729_mode_(0) {
// TODO(tlegrand): We should add codec_id as a input variable to the
// constructor of ACMGenericCodec.
codec_id_ = codec_id;
return;
}
ACMG729_1::~ACMG729_1() {
if (encoder_inst_ptr_ != NULL) {
WebRtcG7291_Free(encoder_inst_ptr_);
encoder_inst_ptr_ = NULL;
}
if (decoder_inst_ptr_ != NULL) {
WebRtcG7291_Free(decoder_inst_ptr_);
decoder_inst_ptr_ = NULL;
}
return;
}
int16_t ACMG729_1::InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) {
// Initialize before entering the loop
int16_t num_encoded_samples = 0;
*bitstream_len_byte = 0;
int16_t byte_length_frame = 0;
// Derive number of 20ms frames per encoded packet.
// [1,2,3] <=> [20,40,60]ms <=> [320,640,960] samples
int16_t num_20ms_frames = (frame_len_smpl_ / 320);
// Byte length for the frame. +1 is for rate information.
byte_length_frame = my_rate_ / (8 * 50) * num_20ms_frames + (1 -
flag_g729_mode_);
// The following might be revised if we have G729.1 Annex C (support for DTX);
do {
*bitstream_len_byte = WebRtcG7291_Encode(encoder_inst_ptr_,
&in_audio_[in_audio_ix_read_],
(int16_t*) bitstream,
my_rate_, num_20ms_frames);
// increment the read index this tell the caller that how far
// we have gone forward in reading the audio buffer
in_audio_ix_read_ += 160;
// sanity check
if (*bitstream_len_byte < 0) {
// error has happened
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalEncode: Encode error for G729_1");
*bitstream_len_byte = 0;
return -1;
}
num_encoded_samples += 160;
} while (*bitstream_len_byte == 0);
// This criteria will change if we have Annex C.
if (*bitstream_len_byte != byte_length_frame) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalEncode: Encode error for G729_1");
*bitstream_len_byte = 0;
return -1;
}
if (num_encoded_samples != frame_len_smpl_) {
*bitstream_len_byte = 0;
return -1;
}
return *bitstream_len_byte;
}
int16_t ACMG729_1::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return 0;
}
int16_t ACMG729_1::InternalInitEncoder(
WebRtcACMCodecParams* codec_params) {
//set the bit rate and initialize
my_rate_ = codec_params->codec_inst.rate;
return SetBitRateSafe((uint32_t) my_rate_);
}
int16_t ACMG729_1::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
if (WebRtcG7291_DecoderInit(decoder_inst_ptr_) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalInitDecoder: init decoder failed for G729_1");
return -1;
}
return 0;
}
int32_t ACMG729_1::CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) {
if (!decoder_initialized_) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"CodeDef: Decoder uninitialized for G729_1");
return -1;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_G729_FUNCTION."
// Then call NetEQ to add the codec to it's
// database.
SET_CODEC_PAR((codec_def), kDecoderG729_1, codec_inst.pltype,
decoder_inst_ptr_, 16000);
SET_G729_1_FUNCTIONS((codec_def));
return 0;
}
ACMGenericCodec* ACMG729_1::CreateInstance(void) {
return NULL;
}
int16_t ACMG729_1::InternalCreateEncoder() {
if (WebRtcG7291_Create(&encoder_inst_ptr_) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalCreateEncoder: create encoder failed for G729_1");
return -1;
}
return 0;
}
void ACMG729_1::DestructEncoderSafe() {
encoder_exist_ = false;
encoder_initialized_ = false;
if (encoder_inst_ptr_ != NULL) {
WebRtcG7291_Free(encoder_inst_ptr_);
encoder_inst_ptr_ = NULL;
}
}
int16_t ACMG729_1::InternalCreateDecoder() {
if (WebRtcG7291_Create(&decoder_inst_ptr_) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalCreateDecoder: create decoder failed for G729_1");
return -1;
}
return 0;
}
void ACMG729_1::DestructDecoderSafe() {
decoder_exist_ = false;
decoder_initialized_ = false;
if (decoder_inst_ptr_ != NULL) {
WebRtcG7291_Free(decoder_inst_ptr_);
decoder_inst_ptr_ = NULL;
}
}
void ACMG729_1::InternalDestructEncoderInst(void* ptr_inst) {
if (ptr_inst != NULL) {
// WebRtcG7291_Free((G729_1_inst_t*)ptrInst);
}
return;
}
int16_t ACMG729_1::SetBitRateSafe(const int32_t rate) {
// allowed rates: { 8000, 12000, 14000, 16000, 18000, 20000,
// 22000, 24000, 26000, 28000, 30000, 32000};
// TODO(tlegrand): This check exists in one other place two. Should be
// possible to reuse code.
switch (rate) {
case 8000: {
my_rate_ = 8000;
break;
}
case 12000: {
my_rate_ = 12000;
break;
}
case 14000: {
my_rate_ = 14000;
break;
}
case 16000: {
my_rate_ = 16000;
break;
}
case 18000: {
my_rate_ = 18000;
break;
}
case 20000: {
my_rate_ = 20000;
break;
}
case 22000: {
my_rate_ = 22000;
break;
}
case 24000: {
my_rate_ = 24000;
break;
}
case 26000: {
my_rate_ = 26000;
break;
}
case 28000: {
my_rate_ = 28000;
break;
}
case 30000: {
my_rate_ = 30000;
break;
}
case 32000: {
my_rate_ = 32000;
break;
}
default: {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"SetBitRateSafe: Invalid rate G729_1");
return -1;
}
}
// Re-init with new rate
if (WebRtcG7291_EncoderInit(encoder_inst_ptr_, my_rate_, flag_8khz_,
flag_g729_mode_) >= 0) {
encoder_params_.codec_inst.rate = my_rate_;
return 0;
} else {
return -1;
}
}
#endif
} // namespace acm1
} // namespace webrtc

View File

@ -1,72 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G7291_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G7291_H_
#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
// forward declaration
struct G729_1_inst_t_;
struct G729_1_inst_t_;
namespace webrtc {
namespace acm1 {
class ACMG729_1 : public ACMGenericCodec {
public:
explicit ACMG729_1(int16_t codec_id);
~ACMG729_1();
// for FEC
ACMGenericCodec* CreateInstance(void);
int16_t InternalEncode(uint8_t* bitstream, int16_t* bitstream_len_byte);
int16_t InternalInitEncoder(WebRtcACMCodecParams *codec_params);
int16_t InternalInitDecoder(WebRtcACMCodecParams *codec_params);
protected:
int16_t DecodeSafe(uint8_t* bitstream,
int16_t bitstream_len_byte,
int16_t* audio,
int16_t* audio_samples,
int8_t* speech_type);
int32_t CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst);
void DestructEncoderSafe();
void DestructDecoderSafe();
int16_t InternalCreateEncoder();
int16_t InternalCreateDecoder();
void InternalDestructEncoderInst(void* ptr_inst);
int16_t SetBitRateSafe(const int32_t rate);
G729_1_inst_t_* encoder_inst_ptr_;
G729_1_inst_t_* decoder_inst_ptr_;
uint16_t my_rate_;
int16_t flag_8khz_;
int16_t flag_g729_mode_;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G7291_H_

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,267 +0,0 @@
/*
* 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/source/acm_gsmfr.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
#include "webrtc/system_wrappers/interface/trace.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 "gsmfr_interface.h"
#endif
namespace webrtc {
namespace acm1 {
#ifndef WEBRTC_CODEC_GSMFR
ACMGSMFR::ACMGSMFR(int16_t /* codec_id */)
: encoder_inst_ptr_(NULL),
decoder_inst_ptr_(NULL) {
return;
}
ACMGSMFR::~ACMGSMFR() {
return;
}
int16_t ACMGSMFR::InternalEncode(
uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */) {
return -1;
}
int16_t ACMGSMFR::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return -1;
}
int16_t ACMGSMFR::EnableDTX() {
return -1;
}
int16_t ACMGSMFR::DisableDTX() {
return -1;
}
int16_t ACMGSMFR::InternalInitEncoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int16_t ACMGSMFR::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int32_t ACMGSMFR::CodecDef(WebRtcNetEQ_CodecDef& /* codec_def */,
const CodecInst& /* codec_inst */) {
return -1;
}
ACMGenericCodec* ACMGSMFR::CreateInstance(void) {
return NULL;
}
int16_t ACMGSMFR::InternalCreateEncoder() {
return -1;
}
void ACMGSMFR::DestructEncoderSafe() {
return;
}
int16_t ACMGSMFR::InternalCreateDecoder() {
return -1;
}
void ACMGSMFR::DestructDecoderSafe() {
return;
}
void ACMGSMFR::InternalDestructEncoderInst(void* /* ptr_inst */) {
return;
}
#else //===================== Actual Implementation =======================
ACMGSMFR::ACMGSMFR(int16_t codec_id)
: encoder_inst_ptr_(NULL),
decoder_inst_ptr_(NULL) {
codec_id_ = codec_id;
has_internal_dtx_ = true;
return;
}
ACMGSMFR::~ACMGSMFR() {
if (encoder_inst_ptr_ != NULL) {
WebRtcGSMFR_FreeEnc(encoder_inst_ptr_);
encoder_inst_ptr_ = NULL;
}
if (decoder_inst_ptr_ != NULL) {
WebRtcGSMFR_FreeDec(decoder_inst_ptr_);
decoder_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_,
(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::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return 0;
}
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;
}
int16_t ACMGSMFR::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
if (WebRtcGSMFR_DecoderInit(decoder_inst_ptr_) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalInitDecoder: cannot init decoder for GSMFR");
return -1;
}
return 0;
}
int32_t ACMGSMFR::CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) {
if (!decoder_initialized_) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"CodecDef: decoder is not initialized for GSMFR");
return -1;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_GSMFR_FUNCTION."
// Then call NetEQ to add the codec to it's
// database.
SET_CODEC_PAR((codec_def), kDecoderGSMFR, codec_inst.pltype,
decoder_inst_ptr_, 8000);
SET_GSMFR_FUNCTIONS((codec_def));
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;
}
int16_t ACMGSMFR::InternalCreateDecoder() {
if (WebRtcGSMFR_CreateDec(&decoder_inst_ptr_) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalCreateDecoder: cannot create instance for GSMFR "
"decoder");
return -1;
}
return 0;
}
void ACMGSMFR::DestructDecoderSafe() {
if (decoder_inst_ptr_ != NULL) {
WebRtcGSMFR_FreeDec(decoder_inst_ptr_);
decoder_inst_ptr_ = NULL;
}
decoder_exist_ = false;
decoder_initialized_ = false;
}
void ACMGSMFR::InternalDestructEncoderInst(void* ptr_inst) {
if (ptr_inst != NULL) {
WebRtcGSMFR_FreeEnc((GSMFR_encinst_t_*) ptr_inst);
}
return;
}
#endif
} // namespace acm1
} // namespace webrtc

View File

@ -1,71 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_GSMFR_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_GSMFR_H_
#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
// forward declaration
struct GSMFR_encinst_t_;
struct GSMFR_decinst_t_;
namespace webrtc {
namespace acm1 {
class ACMGSMFR : public ACMGenericCodec {
public:
explicit ACMGSMFR(int16_t codec_id);
~ACMGSMFR();
// for FEC
ACMGenericCodec* CreateInstance(void);
int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte);
int16_t InternalInitEncoder(WebRtcACMCodecParams *codec_params);
int16_t InternalInitDecoder(WebRtcACMCodecParams *codec_params);
protected:
int16_t DecodeSafe(uint8_t* bitstream,
int16_t bitstream_len_byte,
int16_t* audio,
int16_t* audio_samples,
int8_t* speech_type);
int32_t CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst);
void DestructEncoderSafe();
void DestructDecoderSafe();
int16_t InternalCreateEncoder();
int16_t InternalCreateDecoder();
void InternalDestructEncoderInst(void* ptr_inst);
int16_t EnableDTX();
int16_t DisableDTX();
GSMFR_encinst_t_* encoder_inst_ptr_;
GSMFR_decinst_t_* decoder_inst_ptr_;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_GSMFR_H_

View File

@ -1,259 +0,0 @@
/*
* 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/source/acm_ilbc.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
#include "webrtc/system_wrappers/interface/trace.h"
#ifdef WEBRTC_CODEC_ILBC
#include "webrtc/modules/audio_coding/codecs/ilbc/interface/ilbc.h"
#endif
namespace webrtc {
namespace acm1 {
#ifndef WEBRTC_CODEC_ILBC
ACMILBC::ACMILBC(int16_t /* codec_id */)
: encoder_inst_ptr_(NULL),
decoder_inst_ptr_(NULL) {
return;
}
ACMILBC::~ACMILBC() {
return;
}
int16_t ACMILBC::InternalEncode(
uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */) {
return -1;
}
int16_t ACMILBC::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return -1;
}
int16_t ACMILBC::InternalInitEncoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int16_t ACMILBC::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int32_t ACMILBC::CodecDef(WebRtcNetEQ_CodecDef& /* codec_def */,
const CodecInst& /* codec_inst */) {
return -1;
}
ACMGenericCodec* ACMILBC::CreateInstance(void) {
return NULL;
}
int16_t ACMILBC::InternalCreateEncoder() {
return -1;
}
void ACMILBC::DestructEncoderSafe() {
return;
}
int16_t ACMILBC::InternalCreateDecoder() {
return -1;
}
void ACMILBC::DestructDecoderSafe() {
return;
}
void ACMILBC::InternalDestructEncoderInst(void* /* ptr_inst */) {
return;
}
int16_t ACMILBC::SetBitRateSafe(const int32_t /* rate */) {
return -1;
}
#else //===================== Actual Implementation =======================
ACMILBC::ACMILBC(int16_t codec_id)
: encoder_inst_ptr_(NULL),
decoder_inst_ptr_(NULL) {
codec_id_ = codec_id;
return;
}
ACMILBC::~ACMILBC() {
if (encoder_inst_ptr_ != NULL) {
WebRtcIlbcfix_EncoderFree(encoder_inst_ptr_);
encoder_inst_ptr_ = NULL;
}
if (decoder_inst_ptr_ != NULL) {
WebRtcIlbcfix_DecoderFree(decoder_inst_ptr_);
decoder_inst_ptr_ = NULL;
}
return;
}
int16_t ACMILBC::InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) {
*bitstream_len_byte = WebRtcIlbcfix_Encode(encoder_inst_ptr_,
&in_audio_[in_audio_ix_read_],
frame_len_smpl_,
(int16_t*)bitstream);
if (*bitstream_len_byte < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalEncode: error in encode for ILBC");
return -1;
}
// 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 ACMILBC::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return 0;
}
int16_t ACMILBC::InternalInitEncoder(WebRtcACMCodecParams* codec_params) {
// initialize with a correct processing block length
if ((160 == (codec_params->codec_inst).pacsize) ||
(320 == (codec_params->codec_inst).pacsize)) {
// processing block of 20ms
return WebRtcIlbcfix_EncoderInit(encoder_inst_ptr_, 20);
} else if ((240 == (codec_params->codec_inst).pacsize) ||
(480 == (codec_params->codec_inst).pacsize)) {
// processing block of 30ms
return WebRtcIlbcfix_EncoderInit(encoder_inst_ptr_, 30);
} else {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalInitEncoder: invalid processing block");
return -1;
}
}
int16_t ACMILBC::InternalInitDecoder(WebRtcACMCodecParams* codec_params) {
// initialize with a correct processing block length
if ((160 == (codec_params->codec_inst).pacsize) ||
(320 == (codec_params->codec_inst).pacsize)) {
// processing block of 20ms
return WebRtcIlbcfix_DecoderInit(decoder_inst_ptr_, 20);
} else if ((240 == (codec_params->codec_inst).pacsize) ||
(480 == (codec_params->codec_inst).pacsize)) {
// processing block of 30ms
return WebRtcIlbcfix_DecoderInit(decoder_inst_ptr_, 30);
} else {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalInitDecoder: invalid processing block");
return -1;
}
}
int32_t ACMILBC::CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) {
if (!decoder_initialized_) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"CodeDef: decoder not initialized for ILBC");
return -1;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_ILBC_FUNCTION."
// Then return the structure back to NetEQ to add the codec to it's
// database.
SET_CODEC_PAR((codec_def), kDecoderILBC, codec_inst.pltype, decoder_inst_ptr_,
8000);
SET_ILBC_FUNCTIONS((codec_def));
return 0;
}
ACMGenericCodec* ACMILBC::CreateInstance(void) {
return NULL;
}
int16_t ACMILBC::InternalCreateEncoder() {
if (WebRtcIlbcfix_EncoderCreate(&encoder_inst_ptr_) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalCreateEncoder: cannot create instance for ILBC "
"encoder");
return -1;
}
return 0;
}
void ACMILBC::DestructEncoderSafe() {
encoder_initialized_ = false;
encoder_exist_ = false;
if (encoder_inst_ptr_ != NULL) {
WebRtcIlbcfix_EncoderFree(encoder_inst_ptr_);
encoder_inst_ptr_ = NULL;
}
}
int16_t ACMILBC::InternalCreateDecoder() {
if (WebRtcIlbcfix_DecoderCreate(&decoder_inst_ptr_) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalCreateDecoder: cannot create instance for ILBC "
"decoder");
return -1;
}
return 0;
}
void ACMILBC::DestructDecoderSafe() {
decoder_initialized_ = false;
decoder_exist_ = false;
if (decoder_inst_ptr_ != NULL) {
WebRtcIlbcfix_DecoderFree(decoder_inst_ptr_);
decoder_inst_ptr_ = NULL;
}
}
void ACMILBC::InternalDestructEncoderInst(void* ptr_inst) {
if (ptr_inst != NULL) {
WebRtcIlbcfix_EncoderFree((iLBC_encinst_t_*) ptr_inst);
}
return;
}
int16_t ACMILBC::SetBitRateSafe(const int32_t rate) {
// Check that rate is valid. No need to store the value
if (rate == 13300) {
WebRtcIlbcfix_EncoderInit(encoder_inst_ptr_, 30);
} else if (rate == 15200) {
WebRtcIlbcfix_EncoderInit(encoder_inst_ptr_, 20);
} else {
return -1;
}
encoder_params_.codec_inst.rate = rate;
return 0;
}
#endif
} // namespace acm1
} // namespace webrtc

View File

@ -1,71 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_ILBC_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_ILBC_H_
#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
// forward declaration
struct iLBC_encinst_t_;
struct iLBC_decinst_t_;
namespace webrtc {
namespace acm1 {
class ACMILBC : public ACMGenericCodec {
public:
explicit ACMILBC(int16_t codec_id);
virtual ~ACMILBC();
// for FEC
virtual ACMGenericCodec* CreateInstance(void) OVERRIDE;
virtual int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) OVERRIDE;
virtual int16_t InternalInitEncoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
virtual int16_t InternalInitDecoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
protected:
virtual int16_t DecodeSafe(uint8_t* bitstream,
int16_t bitstream_len_byte,
int16_t* audio,
int16_t* audio_samples,
int8_t* speech_type) OVERRIDE;
virtual int32_t CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) OVERRIDE;
virtual int16_t SetBitRateSafe(const int32_t rate) OVERRIDE;
virtual void DestructEncoderSafe() OVERRIDE;
virtual void DestructDecoderSafe() OVERRIDE;
virtual int16_t InternalCreateEncoder() OVERRIDE;
virtual int16_t InternalCreateDecoder() OVERRIDE;
virtual void InternalDestructEncoderInst(void* ptr_inst) OVERRIDE;
iLBC_encinst_t_* encoder_inst_ptr_;
iLBC_decinst_t_* decoder_inst_ptr_;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_ILBC_H_

View File

@ -1,903 +0,0 @@
/*
* 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/source/acm_isac.h"
#include "webrtc/modules/audio_coding/main/source/acm_codec_database.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
#include "webrtc/system_wrappers/interface/trace.h"
#ifdef WEBRTC_CODEC_ISAC
#include "webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h"
#include "webrtc/modules/audio_coding/main/source/acm_isac_macros.h"
#endif
#ifdef WEBRTC_CODEC_ISACFX
#include "webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h"
#include "webrtc/modules/audio_coding/main/source/acm_isac_macros.h"
#endif
namespace webrtc {
namespace acm1 {
// we need this otherwise we cannot use forward declaration
// in the header file
#if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX))
struct ACMISACInst {
ACM_ISAC_STRUCT *inst;
};
#endif
#define ISAC_MIN_RATE 10000
#define ISAC_MAX_RATE 56000
// Tables for bandwidth estimates
#define NR_ISAC_BANDWIDTHS 24
static const int32_t kIsacRatesWb[NR_ISAC_BANDWIDTHS] = {
10000, 11100, 12300, 13700, 15200, 16900,
18800, 20900, 23300, 25900, 28700, 31900,
10100, 11200, 12400, 13800, 15300, 17000,
18900, 21000, 23400, 26000, 28800, 32000
};
static const int32_t kIsacRatesSwb[NR_ISAC_BANDWIDTHS] = {
10000, 11000, 12400, 13800, 15300, 17000,
18900, 21000, 23200, 25400, 27600, 29800,
32000, 34100, 36300, 38500, 40700, 42900,
45100, 47300, 49500, 51700, 53900, 56000,
};
#if (!defined(WEBRTC_CODEC_ISAC) && !defined(WEBRTC_CODEC_ISACFX))
ACMISAC::ACMISAC(int16_t /* codec_id */)
: codec_inst_ptr_(NULL),
is_enc_initialized_(false),
isac_coding_mode_(CHANNEL_INDEPENDENT),
enforce_frame_size_(false),
isac_currentBN_(32000),
samples_in10MsAudio_(160) { // Initiates to 16 kHz mode.
// Initiate decoder parameters for the 32 kHz mode.
memset(&decoder_params32kHz_, 0, sizeof(WebRtcACMCodecParams));
decoder_params32kHz_.codec_inst.pltype = -1;
return;
}
ACMISAC::~ACMISAC() {
return;
}
ACMGenericCodec* ACMISAC::CreateInstance(void) {
return NULL;
}
int16_t ACMISAC::InternalEncode(
uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */) {
return -1;
}
int16_t ACMISAC::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return 0;
}
int16_t ACMISAC::InternalInitEncoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int16_t ACMISAC::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int16_t ACMISAC::InternalCreateDecoder() {
return -1;
}
void ACMISAC::DestructDecoderSafe() {
return;
}
int16_t ACMISAC::InternalCreateEncoder() {
return -1;
}
void ACMISAC::DestructEncoderSafe() {
return;
}
int32_t ACMISAC::CodecDef(WebRtcNetEQ_CodecDef& /* codec_def */,
const CodecInst& /* codec_inst */) {
return -1;
}
void ACMISAC::InternalDestructEncoderInst(void* /* ptr_inst */) {
return;
}
int16_t ACMISAC::DeliverCachedIsacData(
uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */,
uint32_t* /* timestamp */,
WebRtcACMEncodingType* /* encoding_type */,
const uint16_t /* isac_rate */,
const uint8_t /* isac_bw_estimate */) {
return -1;
}
int16_t ACMISAC::Transcode(uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */,
int16_t /* q_bwe */,
int32_t /* scale */,
bool /* is_red */) {
return -1;
}
int16_t ACMISAC::SetBitRateSafe(int32_t /* bit_rate */) {
return -1;
}
int32_t ACMISAC::GetEstimatedBandwidthSafe() {
return -1;
}
int32_t ACMISAC::SetEstimatedBandwidthSafe(
int32_t /* estimated_bandwidth */) {
return -1;
}
int32_t ACMISAC::GetRedPayloadSafe(uint8_t* /* red_payload */,
int16_t* /* payload_bytes */) {
return -1;
}
int16_t ACMISAC::UpdateDecoderSampFreq(int16_t /* codec_id */) {
return -1;
}
int16_t ACMISAC::UpdateEncoderSampFreq(
uint16_t /* encoder_samp_freq_hz */) {
return -1;
}
int16_t ACMISAC::EncoderSampFreq(uint16_t& /* samp_freq_hz */) {
return -1;
}
int32_t ACMISAC::ConfigISACBandwidthEstimator(
const uint8_t /* init_frame_size_msec */,
const uint16_t /* init_rate_bit_per_sec */,
const bool /* enforce_frame_size */) {
return -1;
}
int32_t ACMISAC::SetISACMaxPayloadSize(
const uint16_t /* max_payload_len_bytes */) {
return -1;
}
int32_t ACMISAC::SetISACMaxRate(
const uint32_t /* max_rate_bit_per_sec */) {
return -1;
}
void ACMISAC::UpdateFrameLen() {
return;
}
void ACMISAC::CurrentRate(int32_t& /*rate_bit_per_sec */) {
return;
}
bool
ACMISAC::DecoderParamsSafe(
WebRtcACMCodecParams* /* dec_params */,
const uint8_t /* payload_type */) {
return false;
}
void
ACMISAC::SaveDecoderParamSafe(
const WebRtcACMCodecParams* /* codec_params */) {
return;
}
int16_t ACMISAC::REDPayloadISAC(
const int32_t /* isac_rate */,
const int16_t /* isac_bw_estimate */,
uint8_t* /* payload */,
int16_t* /* payload_len_bytes */) {
return -1;
}
#else //===================== Actual Implementation =======================
#ifdef WEBRTC_CODEC_ISACFX
// How the scaling is computed. iSAC computes a gain based on the
// bottleneck. It follows the following expression for that
//
// G(BN_kbps) = pow(10, (a + b * BN_kbps + c * BN_kbps * BN_kbps) / 20.0)
// / 3.4641;
//
// Where for 30 ms framelength we have,
//
// a = -23; b = 0.48; c = 0;
//
// As the default encoder is operating at 32kbps we have the scale as
//
// S(BN_kbps) = G(BN_kbps) / G(32);
#define ISAC_NUM_SUPPORTED_RATES 9
static const uint16_t kIsacSuportedRates[ISAC_NUM_SUPPORTED_RATES] = {
32000, 30000, 26000, 23000, 21000,
19000, 17000, 15000, 12000
};
static const float kIsacScale[ISAC_NUM_SUPPORTED_RATES] = {
1.0f, 0.8954f, 0.7178f, 0.6081f, 0.5445f,
0.4875f, 0.4365f, 0.3908f, 0.3311f
};
enum IsacSamplingRate {
kIsacWideband = 16,
kIsacSuperWideband = 32
};
static float ACMISACFixTranscodingScale(uint16_t rate) {
// find the scale for transcoding, the scale is rounded
// downward
float scale = -1;
for (int16_t n = 0; n < ISAC_NUM_SUPPORTED_RATES; n++) {
if (rate >= kIsacSuportedRates[n]) {
scale = kIsacScale[n];
break;
}
}
return scale;
}
static void ACMISACFixGetSendBitrate(ACM_ISAC_STRUCT* inst,
int32_t* bottleneck) {
*bottleneck = WebRtcIsacfix_GetUplinkBw(inst);
}
static int16_t ACMISACFixGetNewBitstream(ACM_ISAC_STRUCT* inst,
int16_t bwe_index,
int16_t /* jitter_index */,
int32_t rate,
int16_t* bitstream,
bool is_red) {
if (is_red) {
// RED not supported with iSACFIX
return -1;
}
float scale = ACMISACFixTranscodingScale((uint16_t) rate);
return WebRtcIsacfix_GetNewBitStream(inst, bwe_index, scale, bitstream);
}
static int16_t ACMISACFixGetSendBWE(ACM_ISAC_STRUCT* inst,
int16_t* rate_index,
int16_t* /* dummy */) {
int16_t local_rate_index;
int16_t status = WebRtcIsacfix_GetDownLinkBwIndex(inst,
&local_rate_index);
if (status < 0) {
return -1;
} else {
*rate_index = local_rate_index;
return 0;
}
}
static int16_t ACMISACFixControlBWE(ACM_ISAC_STRUCT* inst,
int32_t rate_bps,
int16_t frame_size_ms,
int16_t enforce_frame_size) {
return WebRtcIsacfix_ControlBwe(inst, (int16_t) rate_bps, frame_size_ms,
enforce_frame_size);
}
static int16_t ACMISACFixControl(ACM_ISAC_STRUCT* inst,
int32_t rate_bps,
int16_t frame_size_ms) {
return WebRtcIsacfix_Control(inst, (int16_t) rate_bps, frame_size_ms);
}
// The following two function should have the same signature as their counter
// part in iSAC floating-point, i.e. WebRtcIsac_EncSampRate &
// WebRtcIsac_DecSampRate.
static uint16_t ACMISACFixGetEncSampRate(ACM_ISAC_STRUCT* /* inst */) {
return 16000;
}
static uint16_t ACMISACFixGetDecSampRate(ACM_ISAC_STRUCT* /* inst */) {
return 16000;
}
#endif
ACMISAC::ACMISAC(int16_t codec_id)
: is_enc_initialized_(false),
isac_coding_mode_(CHANNEL_INDEPENDENT),
enforce_frame_size_(false),
isac_current_bn_(32000),
samples_in_10ms_audio_(160) { // Initiates to 16 kHz mode.
codec_id_ = codec_id;
// Create codec instance.
codec_inst_ptr_ = new ACMISACInst;
if (codec_inst_ptr_ == NULL) {
return;
}
codec_inst_ptr_->inst = NULL;
// Initiate decoder parameters for the 32 kHz mode.
memset(&decoder_params_32khz_, 0, sizeof(WebRtcACMCodecParams));
decoder_params_32khz_.codec_inst.pltype = -1;
// TODO(tlegrand): Check if the following is really needed, now that
// ACMGenericCodec has been updated to initialize this value.
// Initialize values that can be used uninitialized otherwise
decoder_params_.codec_inst.pltype = -1;
}
ACMISAC::~ACMISAC() {
if (codec_inst_ptr_ != NULL) {
if (codec_inst_ptr_->inst != NULL) {
ACM_ISAC_FREE(codec_inst_ptr_->inst);
codec_inst_ptr_->inst = NULL;
}
delete codec_inst_ptr_;
codec_inst_ptr_ = NULL;
}
return;
}
ACMGenericCodec* ACMISAC::CreateInstance(void) {
return NULL;
}
int16_t ACMISAC::InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) {
// ISAC takes 10ms audio everytime we call encoder, therefor,
// it should be treated like codecs with 'basic coding block'
// non-zero, and the following 'while-loop' should not be necessary.
// However, due to a mistake in the codec the frame-size might change
// at the first 10ms pushed in to iSAC if the bit-rate is low, this is
// sort of a bug in iSAC. to address this we treat iSAC as the
// following.
if (codec_inst_ptr_ == NULL) {
return -1;
}
*bitstream_len_byte = 0;
while ((*bitstream_len_byte == 0) && (in_audio_ix_read_ < frame_len_smpl_)) {
if (in_audio_ix_read_ > in_audio_ix_write_) {
// something is wrong.
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"The actual fram-size of iSAC appears to be larger that "
"expected. All audio pushed in but no bit-stream is "
"generated.");
return -1;
}
*bitstream_len_byte = ACM_ISAC_ENCODE(codec_inst_ptr_->inst,
&in_audio_[in_audio_ix_read_],
(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_ += samples_in_10ms_audio_;
}
if (*bitstream_len_byte == 0) {
WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, unique_id_,
"ISAC Has encoded the whole frame but no bit-stream is "
"generated.");
}
// a packet is generated iSAC, is set in adaptive mode may change
// the frame length and we like to update the bottleneck value as
// well, although updating bottleneck is not crucial
if ((*bitstream_len_byte > 0) && (isac_coding_mode_ == ADAPTIVE)) {
ACM_ISAC_GETSENDBITRATE(codec_inst_ptr_->inst, &isac_current_bn_);
}
UpdateFrameLen();
return *bitstream_len_byte;
}
int16_t ACMISAC::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_sample */,
int8_t* /* speech_type */) {
return 0;
}
int16_t ACMISAC::InternalInitEncoder(WebRtcACMCodecParams* codec_params) {
// if rate is set to -1 then iSAC has to be in adaptive mode
if (codec_params->codec_inst.rate == -1) {
isac_coding_mode_ = ADAPTIVE;
} else if ((codec_params->codec_inst.rate >= ISAC_MIN_RATE) &&
(codec_params->codec_inst.rate <= ISAC_MAX_RATE)) {
// sanity check that rate is in acceptable range
isac_coding_mode_ = CHANNEL_INDEPENDENT;
isac_current_bn_ = codec_params->codec_inst.rate;
} else {
return -1;
}
// we need to set the encoder sampling frequency.
if (UpdateEncoderSampFreq((uint16_t) codec_params->codec_inst.plfreq)
< 0) {
return -1;
}
if (ACM_ISAC_ENCODERINIT(codec_inst_ptr_->inst, isac_coding_mode_) < 0) {
return -1;
}
// apply the frame-size and rate if operating in
// channel-independent mode
if (isac_coding_mode_ == CHANNEL_INDEPENDENT) {
if (ACM_ISAC_CONTROL(codec_inst_ptr_->inst,
codec_params->codec_inst.rate,
codec_params->codec_inst.pacsize /
(codec_params->codec_inst.plfreq / 1000)) < 0) {
return -1;
}
} else {
// We need this for adaptive case and has to be called
// after initialization
ACM_ISAC_GETSENDBITRATE(codec_inst_ptr_->inst, &isac_current_bn_);
}
frame_len_smpl_ = ACM_ISAC_GETNEWFRAMELEN(codec_inst_ptr_->inst);
return 0;
}
int16_t ACMISAC::InternalInitDecoder(WebRtcACMCodecParams* codec_params) {
if (codec_inst_ptr_ == NULL) {
return -1;
}
// set decoder sampling frequency.
if (codec_params->codec_inst.plfreq == 32000 ||
codec_params->codec_inst.plfreq == 48000) {
UpdateDecoderSampFreq(ACMCodecDB::kISACSWB);
} else {
UpdateDecoderSampFreq(ACMCodecDB::kISAC);
}
// in a one-way communication we may never register send-codec.
// However we like that the BWE to work properly so it has to
// be initialized. The BWE is initialized when iSAC encoder is initialized.
// Therefore, we need this.
if (!encoder_initialized_) {
// Since we don't require a valid rate or a valid packet size when
// initializing the decoder, we set valid values before initializing encoder
codec_params->codec_inst.rate = kIsacWbDefaultRate;
codec_params->codec_inst.pacsize = kIsacPacSize960;
if (InternalInitEncoder(codec_params) < 0) {
return -1;
}
encoder_initialized_ = true;
}
return ACM_ISAC_DECODERINIT(codec_inst_ptr_->inst);
}
int16_t ACMISAC::InternalCreateDecoder() {
if (codec_inst_ptr_ == NULL) {
return -1;
}
int16_t status = ACM_ISAC_CREATE(&(codec_inst_ptr_->inst));
// specific to codecs with one instance for encoding and decoding
encoder_initialized_ = false;
if (status < 0) {
encoder_exist_ = false;
} else {
encoder_exist_ = true;
}
return status;
}
void ACMISAC::DestructDecoderSafe() {
// codec with shared instance cannot delete.
decoder_initialized_ = false;
return;
}
int16_t ACMISAC::InternalCreateEncoder() {
if (codec_inst_ptr_ == NULL) {
return -1;
}
int16_t status = ACM_ISAC_CREATE(&(codec_inst_ptr_->inst));
// specific to codecs with one instance for encoding and decoding
decoder_initialized_ = false;
if (status < 0) {
decoder_exist_ = false;
} else {
decoder_exist_ = true;
}
return status;
}
void ACMISAC::DestructEncoderSafe() {
// codec with shared instance cannot delete.
encoder_initialized_ = false;
return;
}
int32_t ACMISAC::CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) {
// Sanity checks
if (codec_inst_ptr_ == NULL) {
return -1;
}
if (!decoder_initialized_ || !decoder_exist_) {
return -1;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_ISAC_FUNCTION."
// Then call NetEQ to add the codec to it's
// database.
if (codec_inst.plfreq == 16000) {
SET_CODEC_PAR((codec_def), kDecoderISAC, codec_inst.pltype,
codec_inst_ptr_->inst, 16000);
#ifdef WEBRTC_CODEC_ISAC
SET_ISAC_FUNCTIONS((codec_def));
#else
SET_ISACfix_FUNCTIONS((codec_def));
#endif
} else {
#ifdef WEBRTC_CODEC_ISAC
// Decoder is either @ 16 kHz or 32 kHz. Even if encoder is set @ 48 kHz
// decoding is @ 32 kHz.
if (codec_inst.plfreq == 32000) {
SET_CODEC_PAR((codec_def), kDecoderISACswb, codec_inst.pltype,
codec_inst_ptr_->inst, 32000);
SET_ISACSWB_FUNCTIONS((codec_def));
} else {
SET_CODEC_PAR((codec_def), kDecoderISACfb, codec_inst.pltype,
codec_inst_ptr_->inst, 32000);
SET_ISACFB_FUNCTIONS((codec_def));
}
#else
return -1;
#endif
}
return 0;
}
void ACMISAC::InternalDestructEncoderInst(void* ptr_inst) {
if (ptr_inst != NULL) {
ACM_ISAC_FREE((ACM_ISAC_STRUCT *) ptr_inst);
}
return;
}
int16_t ACMISAC::Transcode(uint8_t* bitstream,
int16_t* bitstream_len_byte,
int16_t q_bwe,
int32_t rate,
bool is_red) {
int16_t jitter_info = 0;
// transcode from a higher rate to lower rate sanity check
if (codec_inst_ptr_ == NULL) {
return -1;
}
*bitstream_len_byte = ACM_ISAC_GETNEWBITSTREAM(codec_inst_ptr_->inst, q_bwe,
jitter_info, rate,
(int16_t*)bitstream,
(is_red) ? 1 : 0);
if (*bitstream_len_byte < 0) {
// error happened
*bitstream_len_byte = 0;
return -1;
} else {
return *bitstream_len_byte;
}
}
int16_t ACMISAC::SetBitRateSafe(int32_t bit_rate) {
if (codec_inst_ptr_ == NULL) {
return -1;
}
uint16_t encoder_samp_freq;
EncoderSampFreq(encoder_samp_freq);
bool reinit = false;
// change the BN of iSAC
if (bit_rate == -1) {
// ADAPTIVE MODE
// Check if it was already in adaptive mode
if (isac_coding_mode_ != ADAPTIVE) {
// was not in adaptive, then set the mode to adaptive
// and flag for re-initialization
isac_coding_mode_ = ADAPTIVE;
reinit = true;
}
} else if ((bit_rate >= ISAC_MIN_RATE) && (bit_rate <= ISAC_MAX_RATE)) {
// Sanity check if the rate valid
// check if it was in channel-independent mode before
if (isac_coding_mode_ != CHANNEL_INDEPENDENT) {
// was not in channel independent, set the mode to
// channel-independent and flag for re-initialization
isac_coding_mode_ = CHANNEL_INDEPENDENT;
reinit = true;
}
// store the bottleneck
isac_current_bn_ = (uint16_t) bit_rate;
} else {
// invlaid rate
return -1;
}
int16_t status = 0;
if (reinit) {
// initialize and check if it is successful
if (ACM_ISAC_ENCODERINIT(codec_inst_ptr_->inst, isac_coding_mode_) < 0) {
// failed initialization
return -1;
}
}
if (isac_coding_mode_ == CHANNEL_INDEPENDENT) {
status = ACM_ISAC_CONTROL(
codec_inst_ptr_->inst, isac_current_bn_,
(encoder_samp_freq == 32000 || encoder_samp_freq == 48000) ? 30 :
(frame_len_smpl_ / 16));
if (status < 0) {
status = -1;
}
}
// Update encoder parameters
encoder_params_.codec_inst.rate = bit_rate;
UpdateFrameLen();
return status;
}
int32_t ACMISAC::GetEstimatedBandwidthSafe() {
int16_t bandwidth_index = 0;
int16_t delay_index = 0;
int samp_rate;
// Get bandwidth information
ACM_ISAC_GETSENDBWE(codec_inst_ptr_->inst, &bandwidth_index, &delay_index);
// Validy check of index
if ((bandwidth_index < 0) || (bandwidth_index >= NR_ISAC_BANDWIDTHS)) {
return -1;
}
// Check sample frequency
samp_rate = ACM_ISAC_GETDECSAMPRATE(codec_inst_ptr_->inst);
if (samp_rate == 16000) {
return kIsacRatesWb[bandwidth_index];
} else {
return kIsacRatesSwb[bandwidth_index];
}
}
int32_t ACMISAC::SetEstimatedBandwidthSafe(
int32_t estimated_bandwidth) {
int samp_rate;
int16_t bandwidth_index;
// Check sample frequency and choose appropriate table
samp_rate = ACM_ISAC_GETENCSAMPRATE(codec_inst_ptr_->inst);
if (samp_rate == 16000) {
// Search through the WB rate table to find the index
bandwidth_index = NR_ISAC_BANDWIDTHS / 2 - 1;
for (int i = 0; i < (NR_ISAC_BANDWIDTHS / 2); i++) {
if (estimated_bandwidth == kIsacRatesWb[i]) {
bandwidth_index = i;
break;
} else if (estimated_bandwidth
== kIsacRatesWb[i + NR_ISAC_BANDWIDTHS / 2]) {
bandwidth_index = i + NR_ISAC_BANDWIDTHS / 2;
break;
} else if (estimated_bandwidth < kIsacRatesWb[i]) {
bandwidth_index = i;
break;
}
}
} else {
// Search through the SWB rate table to find the index
bandwidth_index = NR_ISAC_BANDWIDTHS - 1;
for (int i = 0; i < NR_ISAC_BANDWIDTHS; i++) {
if (estimated_bandwidth <= kIsacRatesSwb[i]) {
bandwidth_index = i;
break;
}
}
}
// Set iSAC Bandwidth Estimate
ACM_ISAC_SETBWE(codec_inst_ptr_->inst, bandwidth_index);
return 0;
}
int32_t ACMISAC::GetRedPayloadSafe(
#if (!defined(WEBRTC_CODEC_ISAC))
uint8_t* /* red_payload */, int16_t* /* payload_bytes */) {
return -1;
#else
uint8_t* red_payload, int16_t* payload_bytes) {
int16_t bytes = WebRtcIsac_GetRedPayload(codec_inst_ptr_->inst,
(int16_t*)red_payload);
if (bytes < 0) {
return -1;
}
*payload_bytes = bytes;
return 0;
#endif
}
int16_t ACMISAC::UpdateDecoderSampFreq(
#ifdef WEBRTC_CODEC_ISAC
int16_t codec_id) {
// The decoder supports only wideband and super-wideband.
if (ACMCodecDB::kISAC == codec_id) {
return WebRtcIsac_SetDecSampRate(codec_inst_ptr_->inst, 16000);
} else if (ACMCodecDB::kISACSWB == codec_id ||
ACMCodecDB::kISACFB == codec_id) {
return WebRtcIsac_SetDecSampRate(codec_inst_ptr_->inst, 32000);
} else {
return -1;
}
#else
int16_t /* codec_id */) {
return 0;
#endif
}
int16_t ACMISAC::UpdateEncoderSampFreq(
#ifdef WEBRTC_CODEC_ISAC
uint16_t encoder_samp_freq_hz) {
uint16_t current_samp_rate_hz;
EncoderSampFreq(current_samp_rate_hz);
if (current_samp_rate_hz != encoder_samp_freq_hz) {
if ((encoder_samp_freq_hz != 16000) &&
(encoder_samp_freq_hz != 32000) &&
(encoder_samp_freq_hz != 48000)) {
return -1;
} else {
in_audio_ix_read_ = 0;
in_audio_ix_write_ = 0;
in_timestamp_ix_write_ = 0;
if (WebRtcIsac_SetEncSampRate(codec_inst_ptr_->inst,
encoder_samp_freq_hz) < 0) {
return -1;
}
samples_in_10ms_audio_ = encoder_samp_freq_hz / 100;
frame_len_smpl_ = ACM_ISAC_GETNEWFRAMELEN(codec_inst_ptr_->inst);
encoder_params_.codec_inst.pacsize = frame_len_smpl_;
encoder_params_.codec_inst.plfreq = encoder_samp_freq_hz;
return 0;
}
}
#else
uint16_t /* codec_id */) {
#endif
return 0;
}
int16_t ACMISAC::EncoderSampFreq(uint16_t& samp_freq_hz) {
samp_freq_hz = ACM_ISAC_GETENCSAMPRATE(codec_inst_ptr_->inst);
return 0;
}
int32_t ACMISAC::ConfigISACBandwidthEstimator(
const uint8_t init_frame_size_msec,
const uint16_t init_rate_bit_per_sec,
const bool enforce_frame_size) {
int16_t status;
{
uint16_t samp_freq_hz;
EncoderSampFreq(samp_freq_hz);
// TODO(turajs): at 32kHz we hardcode calling with 30ms and enforce
// the frame-size otherwise we might get error. Revise if
// control-bwe is changed.
if (samp_freq_hz == 32000 || samp_freq_hz == 48000) {
status = ACM_ISAC_CONTROL_BWE(codec_inst_ptr_->inst,
init_rate_bit_per_sec, 30, 1);
} else {
status = ACM_ISAC_CONTROL_BWE(codec_inst_ptr_->inst,
init_rate_bit_per_sec,
init_frame_size_msec,
enforce_frame_size ? 1 : 0);
}
}
if (status < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Couldn't config iSAC BWE.");
return -1;
}
UpdateFrameLen();
ACM_ISAC_GETSENDBITRATE(codec_inst_ptr_->inst, &isac_current_bn_);
return 0;
}
int32_t ACMISAC::SetISACMaxPayloadSize(
const uint16_t max_payload_len_bytes) {
return ACM_ISAC_SETMAXPAYLOADSIZE(codec_inst_ptr_->inst,
max_payload_len_bytes);
}
int32_t ACMISAC::SetISACMaxRate(
const uint32_t max_rate_bit_per_sec) {
return ACM_ISAC_SETMAXRATE(codec_inst_ptr_->inst, max_rate_bit_per_sec);
}
void ACMISAC::UpdateFrameLen() {
frame_len_smpl_ = ACM_ISAC_GETNEWFRAMELEN(codec_inst_ptr_->inst);
encoder_params_.codec_inst.pacsize = frame_len_smpl_;
}
void ACMISAC::CurrentRate(int32_t& rate_bit_per_sec) {
if (isac_coding_mode_ == ADAPTIVE) {
ACM_ISAC_GETSENDBITRATE(codec_inst_ptr_->inst, &rate_bit_per_sec);
}
}
bool ACMISAC::DecoderParamsSafe(WebRtcACMCodecParams* dec_params,
const uint8_t payload_type) {
if (decoder_initialized_) {
if (payload_type == decoder_params_.codec_inst.pltype) {
memcpy(dec_params, &decoder_params_, sizeof(WebRtcACMCodecParams));
return true;
}
if (payload_type == decoder_params_32khz_.codec_inst.pltype) {
memcpy(dec_params, &decoder_params_32khz_, sizeof(WebRtcACMCodecParams));
return true;
}
}
return false;
}
void ACMISAC::SaveDecoderParamSafe(const WebRtcACMCodecParams* codec_params) {
// set decoder sampling frequency.
if (codec_params->codec_inst.plfreq == 32000 ||
codec_params->codec_inst.plfreq == 48000) {
memcpy(&decoder_params_32khz_, codec_params, sizeof(WebRtcACMCodecParams));
} else {
memcpy(&decoder_params_, codec_params, sizeof(WebRtcACMCodecParams));
}
}
int16_t ACMISAC::REDPayloadISAC(const int32_t isac_rate,
const int16_t isac_bw_estimate,
uint8_t* payload,
int16_t* payload_len_bytes) {
int16_t status;
ReadLockScoped rl(codec_wrapper_lock_);
status = Transcode(payload, payload_len_bytes, isac_bw_estimate, isac_rate,
true);
return status;
}
#endif
} // namespace acm1
} // namespace webrtc

View File

@ -1,138 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_ISAC_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_ISAC_H_
#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
namespace webrtc {
namespace acm1 {
struct ACMISACInst;
enum IsacCodingMode {
ADAPTIVE,
CHANNEL_INDEPENDENT
};
class ACMISAC : public ACMGenericCodec {
public:
explicit ACMISAC(int16_t codec_id);
virtual ~ACMISAC();
// for FEC
virtual ACMGenericCodec* CreateInstance(void) OVERRIDE;
virtual int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) OVERRIDE;
virtual int16_t InternalInitEncoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
virtual int16_t InternalInitDecoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
int16_t DeliverCachedIsacData(uint8_t* bitstream,
int16_t* bitstream_len_byte,
uint32_t* timestamp,
WebRtcACMEncodingType* encoding_type,
const uint16_t isac_rate,
const uint8_t isac_bwestimate);
int16_t DeliverCachedData(uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */,
uint32_t* /* timestamp */,
WebRtcACMEncodingType* /* encoding_type */) {
return -1;
}
virtual int16_t UpdateDecoderSampFreq(int16_t codec_id) OVERRIDE;
virtual int16_t UpdateEncoderSampFreq(uint16_t samp_freq_hz) OVERRIDE;
virtual int16_t EncoderSampFreq(uint16_t& samp_freq_hz) OVERRIDE;
virtual int32_t ConfigISACBandwidthEstimator(
const uint8_t init_frame_size_msec,
const uint16_t init_rate_bit_per_sec,
const bool enforce_frame_size) OVERRIDE;
virtual int32_t SetISACMaxPayloadSize(
const uint16_t max_payload_len_bytes) OVERRIDE;
virtual int32_t SetISACMaxRate(const uint32_t max_rate_bit_per_sec) OVERRIDE;
virtual int16_t REDPayloadISAC(const int32_t isac_rate,
const int16_t isac_bw_estimate,
uint8_t* payload,
int16_t* payload_len_bytes) OVERRIDE;
protected:
virtual int16_t DecodeSafe(uint8_t* bitstream,
int16_t bitstream_len_byte,
int16_t* audio,
int16_t* audio_samples,
int8_t* speech_type) OVERRIDE;
virtual int32_t CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) OVERRIDE;
virtual void DestructEncoderSafe() OVERRIDE;
virtual void DestructDecoderSafe() OVERRIDE;
virtual int16_t SetBitRateSafe(const int32_t bit_rate) OVERRIDE;
virtual int32_t GetEstimatedBandwidthSafe() OVERRIDE;
virtual int32_t SetEstimatedBandwidthSafe(
int32_t estimated_bandwidth) OVERRIDE;
virtual int32_t GetRedPayloadSafe(uint8_t* red_payload,
int16_t* payload_bytes) OVERRIDE;
virtual int16_t InternalCreateEncoder() OVERRIDE;
virtual int16_t InternalCreateDecoder() OVERRIDE;
virtual void InternalDestructEncoderInst(void* ptr_inst) OVERRIDE;
int16_t Transcode(uint8_t* bitstream,
int16_t* bitstream_len_byte,
int16_t q_bwe,
int32_t rate,
bool is_red);
virtual void CurrentRate(int32_t& rate_bit_per_sec) OVERRIDE;
void UpdateFrameLen();
virtual bool DecoderParamsSafe(WebRtcACMCodecParams* dec_params,
const uint8_t payload_type) OVERRIDE;
virtual void SaveDecoderParamSafe(
const WebRtcACMCodecParams* codec_params) OVERRIDE;
ACMISACInst* codec_inst_ptr_;
bool is_enc_initialized_;
IsacCodingMode isac_coding_mode_;
bool enforce_frame_size_;
int32_t isac_current_bn_;
uint16_t samples_in_10ms_audio_;
WebRtcACMCodecParams decoder_params_32khz_;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_ISAC_H_

View File

@ -1,77 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_ISAC_MACROS_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_ISAC_MACROS_H_
#include "webrtc/engine_configurations.h"
namespace webrtc {
namespace acm1 {
#ifdef WEBRTC_CODEC_ISAC
#define ACM_ISAC_CREATE WebRtcIsac_Create
#define ACM_ISAC_FREE WebRtcIsac_Free
#define ACM_ISAC_ENCODERINIT WebRtcIsac_EncoderInit
#define ACM_ISAC_ENCODE WebRtcIsac_Encode
#define ACM_ISAC_DECODERINIT WebRtcIsac_DecoderInit
#define ACM_ISAC_DECODE_BWE WebRtcIsac_UpdateBwEstimate
#define ACM_ISAC_DECODE_B WebRtcIsac_Decode
#define ACM_ISAC_DECODEPLC WebRtcIsac_DecodePlc
#define ACM_ISAC_CONTROL WebRtcIsac_Control
#define ACM_ISAC_CONTROL_BWE WebRtcIsac_ControlBwe
#define ACM_ISAC_GETFRAMELEN WebRtcIsac_ReadFrameLen
#define ACM_ISAC_GETERRORCODE WebRtcIsac_GetErrorCode
#define ACM_ISAC_GETSENDBITRATE WebRtcIsac_GetUplinkBw
#define ACM_ISAC_SETMAXPAYLOADSIZE WebRtcIsac_SetMaxPayloadSize
#define ACM_ISAC_SETMAXRATE WebRtcIsac_SetMaxRate
#define ACM_ISAC_GETNEWBITSTREAM WebRtcIsac_GetNewBitStream
#define ACM_ISAC_GETSENDBWE WebRtcIsac_GetDownLinkBwIndex
#define ACM_ISAC_SETBWE WebRtcIsac_UpdateUplinkBw
#define ACM_ISAC_GETBWE WebRtcIsac_ReadBwIndex
#define ACM_ISAC_GETNEWFRAMELEN WebRtcIsac_GetNewFrameLen
#define ACM_ISAC_STRUCT ISACStruct
#define ACM_ISAC_GETENCSAMPRATE WebRtcIsac_EncSampRate
#define ACM_ISAC_GETDECSAMPRATE WebRtcIsac_DecSampRate
#endif
#ifdef WEBRTC_CODEC_ISACFX
#define ACM_ISAC_CREATE WebRtcIsacfix_Create
#define ACM_ISAC_FREE WebRtcIsacfix_Free
#define ACM_ISAC_ENCODERINIT WebRtcIsacfix_EncoderInit
#define ACM_ISAC_ENCODE WebRtcIsacfix_Encode
#define ACM_ISAC_DECODERINIT WebRtcIsacfix_DecoderInit
#define ACM_ISAC_DECODE_BWE WebRtcIsacfix_UpdateBwEstimate
#define ACM_ISAC_DECODE_B WebRtcIsacfix_Decode
#define ACM_ISAC_DECODEPLC WebRtcIsacfix_DecodePlc
#define ACM_ISAC_CONTROL ACMISACFixControl // local Impl
#define ACM_ISAC_CONTROL_BWE ACMISACFixControlBWE // local Impl
#define ACM_ISAC_GETFRAMELEN WebRtcIsacfix_ReadFrameLen
#define ACM_ISAC_GETERRORCODE WebRtcIsacfix_GetErrorCode
#define ACM_ISAC_GETSENDBITRATE ACMISACFixGetSendBitrate // local Impl
#define ACM_ISAC_SETMAXPAYLOADSIZE WebRtcIsacfix_SetMaxPayloadSize
#define ACM_ISAC_SETMAXRATE WebRtcIsacfix_SetMaxRate
#define ACM_ISAC_GETNEWBITSTREAM ACMISACFixGetNewBitstream // local Impl
#define ACM_ISAC_GETSENDBWE ACMISACFixGetSendBWE // local Impl
#define ACM_ISAC_SETBWE WebRtcIsacfix_UpdateUplinkBw
#define ACM_ISAC_GETBWE WebRtcIsacfix_ReadBwIndex
#define ACM_ISAC_GETNEWFRAMELEN WebRtcIsacfix_GetNewFrameLen
#define ACM_ISAC_STRUCT ISACFIX_MainStruct
#define ACM_ISAC_GETENCSAMPRATE ACMISACFixGetEncSampRate // local Impl
#define ACM_ISAC_GETDECSAMPRATE ACMISACFixGetDecSampRate // local Impl
#endif
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_ISAC_MACROS_H_

File diff suppressed because it is too large Load Diff

View File

@ -1,399 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_NETEQ_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_NETEQ_H_
#include "webrtc/common_audio/vad/include/webrtc_vad.h"
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
#include "webrtc/modules/interface/module_common_types.h"
#include "webrtc/typedefs.h"
namespace webrtc {
class CriticalSectionWrapper;
class RWLockWrapper;
struct CodecInst;
namespace acm1 {
#define MAX_NUM_SLAVE_NETEQ 1
class ACMNetEQ {
public:
enum JitterBuffer {
kMasterJb = 0,
kSlaveJb = 1
};
// Constructor of the class
ACMNetEQ();
// Destructor of the class.
~ACMNetEQ();
//
// Init()
// Allocates memory for NetEQ and VAD and initializes them.
//
// Return value : 0 if ok.
// -1 if NetEQ or VAD returned an error or
// if out of memory.
//
int32_t Init();
//
// RecIn()
// Gives the payload to NetEQ.
//
// Input:
// - incoming_payload : Incoming audio payload.
// - length_payload : Length of incoming audio payload.
// - rtp_info : RTP header for the incoming payload containing
// information about payload type, sequence number,
// timestamp, SSRC and marker bit.
// - receive_timestamp : received timestamp.
//
// Return value : 0 if ok.
// <0 if NetEQ returned an error.
//
int32_t RecIn(const uint8_t* incoming_payload,
const int32_t length_payload,
const WebRtcRTPHeader& rtp_info,
uint32_t receive_timestamp);
//
// RecIn()
// Insert a sync payload to NetEq. Should only be called if |av_sync_| is
// enabled;
//
// Input:
// - rtp_info : RTP header for the incoming payload containing
// information about payload type, sequence number,
// timestamp, SSRC and marker bit.
// - receive_timestamp : received timestamp.
//
// Return value : 0 if ok.
// <0 if NetEQ returned an error.
//
int RecIn(const WebRtcRTPHeader& rtp_info, uint32_t receive_timestamp);
//
// RecOut()
// Asks NetEQ for 10 ms of decoded audio.
//
// Input:
// -audio_frame : an audio frame were output data and
// associated parameters are written to.
//
// Return value : 0 if ok.
// -1 if NetEQ returned an error.
//
int32_t RecOut(AudioFrame& audio_frame);
//
// AddCodec()
// Adds a new codec to the NetEQ codec database.
//
// Input:
// - codec_def : The codec to be added.
// - to_master : true if the codec has to be added to Master
// NetEq, otherwise will be added to the Slave
// NetEQ.
//
// Return value : 0 if ok.
// <0 if NetEQ returned an error.
//
int32_t AddCodec(WebRtcNetEQ_CodecDef *codec_def,
bool to_master = true);
//
// AllocatePacketBuffer()
// Allocates the NetEQ packet buffer.
//
// Input:
// - used_codecs : An array of the codecs to be used by NetEQ.
// - num_codecs : Number of codecs in used_codecs.
//
// Return value : 0 if ok.
// <0 if NetEQ returned an error.
//
int32_t AllocatePacketBuffer(const WebRtcNetEQDecoder* used_codecs,
int16_t num_codecs);
//
// SetAVTPlayout()
// Enable/disable playout of AVT payloads.
//
// Input:
// - enable : Enable if true, disable if false.
//
// Return value : 0 if ok.
// <0 if NetEQ returned an error.
//
int32_t SetAVTPlayout(const bool enable);
//
// AVTPlayout()
// Get the current AVT playout state.
//
// Return value : True if AVT playout is enabled.
// False if AVT playout is disabled.
//
bool avt_playout() const;
//
// CurrentSampFreqHz()
// Get the current sampling frequency in Hz.
//
// Return value : Sampling frequency in Hz.
//
int32_t CurrentSampFreqHz() const;
//
// SetPlayoutMode()
// Sets the playout mode to voice or fax.
//
// Input:
// - mode : The playout mode to be used, voice,
// fax, or streaming.
//
// Return value : 0 if ok.
// <0 if NetEQ returned an error.
//
int32_t SetPlayoutMode(const AudioPlayoutMode mode);
//
// PlayoutMode()
// Get the current playout mode.
//
// Return value : The current playout mode.
//
AudioPlayoutMode playout_mode() const;
//
// NetworkStatistics()
// Get the current network statistics from NetEQ.
//
// Output:
// - statistics : The current network statistics.
//
// Return value : 0 if ok.
// <0 if NetEQ returned an error.
//
int32_t NetworkStatistics(ACMNetworkStatistics* statistics) const;
//
// VADMode()
// Get the current VAD Mode.
//
// Return value : The current VAD mode.
//
ACMVADMode vad_mode() const;
//
// SetVADMode()
// Set the VAD mode.
//
// Input:
// - mode : The new VAD mode.
//
// Return value : 0 if ok.
// -1 if an error occurred.
//
int16_t SetVADMode(const ACMVADMode mode);
//
// DecodeLock()
// Get the decode lock used to protect decoder instances while decoding.
//
// Return value : Pointer to the decode lock.
//
RWLockWrapper* DecodeLock() const {
return decode_lock_;
}
//
// FlushBuffers()
// Flushes the NetEQ packet and speech buffers.
//
// Return value : 0 if ok.
// -1 if NetEQ returned an error.
//
int32_t FlushBuffers();
//
// RemoveCodec()
// Removes a codec from the NetEQ codec database.
//
// Input:
// - codec_idx : Codec to be removed.
//
// Return value : 0 if ok.
// -1 if an error occurred.
//
int16_t RemoveCodec(WebRtcNetEQDecoder codec_idx,
bool is_stereo = false);
//
// SetBackgroundNoiseMode()
// Set the mode of the background noise.
//
// Input:
// - mode : an enumerator specifying the mode of the
// background noise.
//
// Return value : 0 if succeeded,
// -1 if failed to set the mode.
//
int16_t SetBackgroundNoiseMode(const ACMBackgroundNoiseMode mode);
//
// BackgroundNoiseMode()
// return the mode of the background noise.
//
// Return value : The mode of background noise.
//
int16_t BackgroundNoiseMode(ACMBackgroundNoiseMode& mode);
void set_id(int32_t id);
int32_t PlayoutTimestamp(uint32_t& timestamp);
void set_received_stereo(bool received_stereo);
uint8_t num_slaves();
// Delete all slaves.
void RemoveSlaves();
int16_t AddSlave(const WebRtcNetEQDecoder* used_codecs,
int16_t num_codecs);
void BufferSpec(int& num_packets, int& size_bytes, int& overhead_bytes) {
num_packets = min_of_max_num_packets_;
size_bytes = min_of_buffer_size_bytes_;
overhead_bytes = per_packet_overhead_bytes_;
}
//
// Set AV-sync mode.
//
void EnableAVSync(bool enable);
//
// Get sequence number and timestamp of the last decoded RTP.
//
bool DecodedRtpInfo(int* sequence_number, uint32_t* timestamp) const;
//
// Set a minimum delay in NetEq. Unless channel condition dictates a longer
// delay, the given delay is maintained by NetEq.
//
int SetMinimumDelay(int minimum_delay_ms);
//
// Set a maximum delay in NetEq.
//
int SetMaximumDelay(int maximum_delay_ms);
//
// The shortest latency, in milliseconds, required by jitter buffer. This
// is computed based on inter-arrival times and playout mode of NetEq. The
// actual delay is the maximum of least-required-delay and the minimum-delay
// specified by SetMinumumPlayoutDelay() API.
//
int LeastRequiredDelayMs() const ;
private:
//
// RTPPack()
// Creates a Word16 RTP packet out of the payload data in Word16 and
// a WebRtcRTPHeader.
//
// Input:
// - payload : Payload to be packetized.
// - payload_length_bytes : Length of the payload in bytes.
// - rtp_info : RTP header structure.
//
// Output:
// - rtp_packet : The RTP packet.
//
static void RTPPack(int16_t* rtp_packet, const int8_t* payload,
const int32_t payload_length_bytes,
const WebRtcRTPHeader& rtp_info);
void LogError(const char* neteq_func_name, const int16_t idx) const;
int16_t InitByIdxSafe(const int16_t idx);
//
// EnableVAD()
// Enable VAD.
//
// Return value : 0 if ok.
// -1 if an error occurred.
//
int16_t EnableVAD();
int16_t EnableVADByIdxSafe(const int16_t idx);
int16_t AllocatePacketBufferByIdxSafe(
const WebRtcNetEQDecoder* used_codecs,
int16_t num_codecs,
const int16_t idx);
// Delete the NetEQ corresponding to |index|.
void RemoveNetEQSafe(int index);
void RemoveSlavesSafe();
void* inst_[MAX_NUM_SLAVE_NETEQ + 1];
void* inst_mem_[MAX_NUM_SLAVE_NETEQ + 1];
int16_t* neteq_packet_buffer_[MAX_NUM_SLAVE_NETEQ + 1];
int32_t id_;
float current_samp_freq_khz_;
bool avt_playout_;
AudioPlayoutMode playout_mode_;
CriticalSectionWrapper* neteq_crit_sect_;
WebRtcVadInst* ptr_vadinst_[MAX_NUM_SLAVE_NETEQ + 1];
bool vad_status_;
ACMVADMode vad_mode_;
RWLockWrapper* decode_lock_;
bool is_initialized_[MAX_NUM_SLAVE_NETEQ + 1];
uint8_t num_slaves_;
bool received_stereo_;
void* master_slave_info_;
AudioFrame::VADActivity previous_audio_activity_;
CriticalSectionWrapper* callback_crit_sect_;
// Minimum of "max number of packets," among all NetEq instances.
int min_of_max_num_packets_;
// Minimum of buffer-size among all NetEq instances.
int min_of_buffer_size_bytes_;
int per_packet_overhead_bytes_;
// Keep track of AV-sync. Just used to set the slave when a slave is added.
bool av_sync_;
int minimum_delay_ms_;
int maximum_delay_ms_;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_NETEQ_H_

View File

@ -1,153 +0,0 @@
/*
* 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.
*/
// This file contains unit tests for ACM's NetEQ wrapper (class ACMNetEQ).
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
#include <stdlib.h>
#include "gtest/gtest.h"
#include "webrtc/modules/audio_coding/codecs/pcm16b/include/pcm16b.h"
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
#include "webrtc/modules/audio_coding/main/source/acm_codec_database.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
#include "webrtc/modules/interface/module_common_types.h"
#include "webrtc/typedefs.h"
namespace webrtc {
namespace acm1 {
class AcmNetEqTest : public ::testing::Test {
protected:
static const size_t kMaxPayloadLen = 5760; // 60 ms, 48 kHz, 16 bit samples.
static const int kPcm16WbPayloadType = 94;
AcmNetEqTest() {}
virtual void SetUp();
virtual void TearDown() {}
void InsertZeroPacket(uint16_t sequence_number,
uint32_t timestamp,
uint8_t payload_type,
uint32_t ssrc,
bool marker_bit,
size_t len_payload_bytes);
void PullData(int expected_num_samples);
ACMNetEQ neteq_;
};
void AcmNetEqTest::SetUp() {
ASSERT_EQ(0, neteq_.Init());
ASSERT_EQ(0, neteq_.AllocatePacketBuffer(ACMCodecDB::NetEQDecoders(),
ACMCodecDB::kNumCodecs));
WebRtcNetEQ_CodecDef codec_def;
SET_CODEC_PAR(codec_def, kDecoderPCM16Bwb, kPcm16WbPayloadType, NULL, 16000);
SET_PCM16B_WB_FUNCTIONS(codec_def);
ASSERT_EQ(0, neteq_.AddCodec(&codec_def, true));
}
void AcmNetEqTest::InsertZeroPacket(uint16_t sequence_number,
uint32_t timestamp,
uint8_t payload_type,
uint32_t ssrc,
bool marker_bit,
size_t len_payload_bytes) {
ASSERT_TRUE(len_payload_bytes <= kMaxPayloadLen);
uint16_t payload[kMaxPayloadLen] = {0};
WebRtcRTPHeader rtp_header;
rtp_header.header.sequenceNumber = sequence_number;
rtp_header.header.timestamp = timestamp;
rtp_header.header.ssrc = ssrc;
rtp_header.header.payloadType = payload_type;
rtp_header.header.markerBit = marker_bit;
rtp_header.type.Audio.channel = 1;
// Receive timestamp can be set to send timestamp in this test.
ASSERT_EQ(0, neteq_.RecIn(reinterpret_cast<uint8_t*>(payload),
len_payload_bytes, rtp_header, timestamp));
}
void AcmNetEqTest::PullData(int expected_num_samples) {
AudioFrame out_frame;
ASSERT_EQ(0, neteq_.RecOut(out_frame));
ASSERT_EQ(expected_num_samples, out_frame.samples_per_channel_);
}
TEST_F(AcmNetEqTest, NetworkStatistics) {
// Use fax mode to avoid time-scaling. This is to simplify the testing of
// packet waiting times in the packet buffer.
neteq_.SetPlayoutMode(fax);
// Insert 31 dummy packets at once. Each packet contains 10 ms 16 kHz audio.
int num_frames = 30;
const int kSamples = 10 * 16;
const int kPayloadBytes = kSamples * 2;
int i, j;
for (i = 0; i < num_frames; ++i) {
InsertZeroPacket(i, i * kSamples, kPcm16WbPayloadType, 0x1234, false,
kPayloadBytes);
}
// Pull out data once.
PullData(kSamples);
// Insert one more packet (to produce different mean and median).
i = num_frames;
InsertZeroPacket(i, i * kSamples, kPcm16WbPayloadType, 0x1234, false,
kPayloadBytes);
// Pull out all data.
for (j = 1; j < num_frames + 1; ++j) {
PullData(kSamples);
}
ACMNetworkStatistics stats;
ASSERT_EQ(0, neteq_.NetworkStatistics(&stats));
EXPECT_EQ(0, stats.currentBufferSize);
EXPECT_EQ(0, stats.preferredBufferSize);
EXPECT_FALSE(stats.jitterPeaksFound);
EXPECT_EQ(0, stats.currentPacketLossRate);
EXPECT_EQ(0, stats.currentDiscardRate);
EXPECT_EQ(0, stats.currentExpandRate);
EXPECT_EQ(0, stats.currentPreemptiveRate);
EXPECT_EQ(0, stats.currentAccelerateRate);
EXPECT_EQ(-916, stats.clockDriftPPM); // Initial value is slightly off.
EXPECT_EQ(300, stats.maxWaitingTimeMs);
EXPECT_EQ(10, stats.minWaitingTimeMs);
EXPECT_EQ(159, stats.meanWaitingTimeMs);
EXPECT_EQ(160, stats.medianWaitingTimeMs);
}
TEST_F(AcmNetEqTest, TestZeroLengthWaitingTimesVector) {
// Insert one packet.
const int kSamples = 10 * 16;
const int kPayloadBytes = kSamples * 2;
int i = 0;
InsertZeroPacket(i, i * kSamples, kPcm16WbPayloadType, 0x1234, false,
kPayloadBytes);
// Do not pull out any data.
ACMNetworkStatistics stats;
ASSERT_EQ(0, neteq_.NetworkStatistics(&stats));
EXPECT_EQ(0, stats.currentBufferSize);
EXPECT_EQ(0, stats.preferredBufferSize);
EXPECT_FALSE(stats.jitterPeaksFound);
EXPECT_EQ(0, stats.currentPacketLossRate);
EXPECT_EQ(0, stats.currentDiscardRate);
EXPECT_EQ(0, stats.currentExpandRate);
EXPECT_EQ(0, stats.currentPreemptiveRate);
EXPECT_EQ(0, stats.currentAccelerateRate);
EXPECT_EQ(-916, stats.clockDriftPPM); // Initial value is slightly off.
EXPECT_EQ(-1, stats.minWaitingTimeMs);
EXPECT_EQ(-1, stats.maxWaitingTimeMs);
EXPECT_EQ(-1, stats.meanWaitingTimeMs);
EXPECT_EQ(-1, stats.medianWaitingTimeMs);
}
} // namespace acm1
} // namespace webrtc

View File

@ -1,319 +0,0 @@
/*
* 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/source/acm_opus.h"
#include "webrtc/modules/audio_coding/main/source/acm_codec_database.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
#include "webrtc/system_wrappers/interface/trace.h"
#ifdef WEBRTC_CODEC_OPUS
#include "webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h"
#endif
namespace webrtc {
namespace acm1 {
#ifndef WEBRTC_CODEC_OPUS
ACMOpus::ACMOpus(int16_t /* codec_id */)
: encoder_inst_ptr_(NULL),
decoder_inst_ptr_(NULL),
sample_freq_(0),
bitrate_(0),
channels_(1) {
return;
}
ACMOpus::~ACMOpus() {
return;
}
int16_t ACMOpus::InternalEncode(uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */) {
return -1;
}
int16_t ACMOpus::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return -1;
}
int16_t ACMOpus::InternalInitEncoder(WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int16_t ACMOpus::InternalInitDecoder(WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int32_t ACMOpus::CodecDef(WebRtcNetEQ_CodecDef& /* codec_def */,
const CodecInst& /* codec_inst */) {
return -1;
}
ACMGenericCodec* ACMOpus::CreateInstance(void) {
return NULL;
}
int16_t ACMOpus::InternalCreateEncoder() {
return -1;
}
void ACMOpus::DestructEncoderSafe() {
return;
}
int16_t ACMOpus::InternalCreateDecoder() {
return -1;
}
void ACMOpus::DestructDecoderSafe() {
return;
}
void ACMOpus::InternalDestructEncoderInst(void* /* ptr_inst */) {
return;
}
int16_t ACMOpus::SetBitRateSafe(const int32_t /*rate*/) {
return -1;
}
bool ACMOpus::IsTrueStereoCodec() {
return true;
}
void ACMOpus::SplitStereoPacket(uint8_t* /*payload*/,
int32_t* /*payload_length*/) {}
#else //===================== Actual Implementation =======================
ACMOpus::ACMOpus(int16_t codec_id)
: encoder_inst_ptr_(NULL),
decoder_inst_ptr_(NULL),
sample_freq_(32000), // Default sampling frequency.
bitrate_(20000), // Default bit-rate.
channels_(1) { // Default mono
codec_id_ = codec_id;
// Opus has internal DTX, but we don't use it for now.
has_internal_dtx_ = false;
if (codec_id_ != ACMCodecDB::kOpus) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Wrong codec id for Opus.");
sample_freq_ = -1;
bitrate_ = -1;
}
return;
}
ACMOpus::~ACMOpus() {
if (encoder_inst_ptr_ != NULL) {
WebRtcOpus_EncoderFree(encoder_inst_ptr_);
encoder_inst_ptr_ = NULL;
}
if (decoder_inst_ptr_ != NULL) {
WebRtcOpus_DecoderFree(decoder_inst_ptr_);
decoder_inst_ptr_ = NULL;
}
return;
}
int16_t ACMOpus::InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) {
// Call Encoder.
*bitstream_len_byte = WebRtcOpus_Encode(encoder_inst_ptr_,
&in_audio_[in_audio_ix_read_],
frame_len_smpl_,
MAX_PAYLOAD_SIZE_BYTE, bitstream);
// Check for error reported from encoder.
if (*bitstream_len_byte < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InternalEncode: Encode error for Opus");
*bitstream_len_byte = 0;
return -1;
}
// Increment the read index. This tells the caller how far
// we have gone forward in reading the audio buffer.
in_audio_ix_read_ += frame_len_smpl_ * channels_;
return *bitstream_len_byte;
}
int16_t ACMOpus::DecodeSafe(uint8_t* bitstream, int16_t bitstream_len_byte,
int16_t* audio, int16_t* audio_samples,
int8_t* speech_type) {
return 0;
}
int16_t ACMOpus::InternalInitEncoder(WebRtcACMCodecParams* codec_params) {
int16_t ret;
if (encoder_inst_ptr_ != NULL) {
WebRtcOpus_EncoderFree(encoder_inst_ptr_);
encoder_inst_ptr_ = NULL;
}
ret = WebRtcOpus_EncoderCreate(&encoder_inst_ptr_,
codec_params->codec_inst.channels);
// Store number of channels.
channels_ = codec_params->codec_inst.channels;
if (ret < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Encoder creation failed for Opus");
return ret;
}
ret = WebRtcOpus_SetBitRate(encoder_inst_ptr_,
codec_params->codec_inst.rate);
if (ret < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Setting initial bitrate failed for Opus");
return ret;
}
// Store bitrate.
bitrate_ = codec_params->codec_inst.rate;
return 0;
}
int16_t ACMOpus::InternalInitDecoder(WebRtcACMCodecParams* codec_params) {
if (decoder_inst_ptr_ == NULL) {
if (WebRtcOpus_DecoderCreate(&decoder_inst_ptr_,
codec_params->codec_inst.channels) < 0) {
return -1;
}
}
// Number of channels in decoder should match the number in |codec_params|.
assert(codec_params->codec_inst.channels ==
WebRtcOpus_DecoderChannels(decoder_inst_ptr_));
if (WebRtcOpus_DecoderInit(decoder_inst_ptr_) < 0) {
return -1;
}
if (WebRtcOpus_DecoderInitSlave(decoder_inst_ptr_) < 0) {
return -1;
}
return 0;
}
int32_t ACMOpus::CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) {
if (!decoder_initialized_) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"CodeDef: Decoder uninitialized for Opus");
return -1;
}
// Fill up the structure by calling "SET_CODEC_PAR" & "SET_OPUS_FUNCTION."
// Then call NetEQ to add the codec to its database.
// TODO(tlegrand): Decoder is registered in NetEQ as a 32 kHz decoder, which
// is true until we have a full 48 kHz system, and remove the downsampling
// in the Opus decoder wrapper.
SET_CODEC_PAR(codec_def, kDecoderOpus, codec_inst.pltype,
decoder_inst_ptr_, 32000);
// If this is the master of NetEQ, regular decoder will be added, otherwise
// the slave decoder will be used.
if (is_master_) {
SET_OPUS_FUNCTIONS(codec_def);
} else {
SET_OPUSSLAVE_FUNCTIONS(codec_def);
}
return 0;
}
ACMGenericCodec* ACMOpus::CreateInstance(void) {
return NULL;
}
int16_t ACMOpus::InternalCreateEncoder() {
// Real encoder will be created in InternalInitEncoder.
return 0;
}
void ACMOpus::DestructEncoderSafe() {
if (encoder_inst_ptr_) {
WebRtcOpus_EncoderFree(encoder_inst_ptr_);
encoder_inst_ptr_ = NULL;
}
}
int16_t ACMOpus::InternalCreateDecoder() {
// Real decoder will be created in InternalInitDecoder
return 0;
}
void ACMOpus::DestructDecoderSafe() {
decoder_initialized_ = false;
if (decoder_inst_ptr_) {
WebRtcOpus_DecoderFree(decoder_inst_ptr_);
decoder_inst_ptr_ = NULL;
}
}
void ACMOpus::InternalDestructEncoderInst(void* ptr_inst) {
if (ptr_inst != NULL) {
WebRtcOpus_EncoderFree(reinterpret_cast<OpusEncInst*>(ptr_inst));
}
return;
}
int16_t ACMOpus::SetBitRateSafe(const int32_t rate) {
if (rate < 6000 || rate > 510000) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"SetBitRateSafe: Invalid rate Opus");
return -1;
}
bitrate_ = rate;
// Ask the encoder for the new rate.
if (WebRtcOpus_SetBitRate(encoder_inst_ptr_, bitrate_) >= 0) {
encoder_params_.codec_inst.rate = bitrate_;
return 0;
}
return -1;
}
bool ACMOpus::IsTrueStereoCodec() {
return true;
}
// Copy the stereo packet so that NetEq will insert into both master and slave.
void ACMOpus::SplitStereoPacket(uint8_t* payload, int32_t* payload_length) {
// Check for valid inputs.
assert(payload != NULL);
assert(*payload_length > 0);
// Duplicate the payload.
memcpy(&payload[*payload_length], &payload[0],
sizeof(uint8_t) * (*payload_length));
// Double the size of the packet.
*payload_length *= 2;
}
#endif // WEBRTC_CODEC_OPUS
} // namespace acm1
} // namespace webrtc

View File

@ -1,78 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_OPUS_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_OPUS_H_
#include "webrtc/common_audio/resampler/include/resampler.h"
#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
struct WebRtcOpusEncInst;
struct WebRtcOpusDecInst;
namespace webrtc {
namespace acm1 {
class ACMOpus : public ACMGenericCodec {
public:
explicit ACMOpus(int16_t codec_id);
virtual ~ACMOpus();
virtual ACMGenericCodec* CreateInstance(void) OVERRIDE;
virtual int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) OVERRIDE;
virtual int16_t InternalInitEncoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
virtual int16_t InternalInitDecoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
protected:
virtual int16_t DecodeSafe(uint8_t* bitstream,
int16_t bitstream_len_byte,
int16_t* audio,
int16_t* audio_samples,
int8_t* speech_type) OVERRIDE;
virtual int32_t CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) OVERRIDE;
virtual void DestructEncoderSafe() OVERRIDE;
virtual void DestructDecoderSafe() OVERRIDE;
virtual int16_t InternalCreateEncoder() OVERRIDE;
virtual int16_t InternalCreateDecoder() OVERRIDE;
virtual void InternalDestructEncoderInst(void* ptr_inst) OVERRIDE;
virtual int16_t SetBitRateSafe(const int32_t rate) OVERRIDE;
virtual bool IsTrueStereoCodec() OVERRIDE;
virtual void SplitStereoPacket(uint8_t* payload,
int32_t* payload_length) OVERRIDE;
WebRtcOpusEncInst* encoder_inst_ptr_;
WebRtcOpusDecInst* decoder_inst_ptr_;
uint16_t sample_freq_;
uint32_t bitrate_;
int channels_;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_OPUS_H_

View File

@ -1,251 +0,0 @@
/*
* 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/source/acm_pcm16b.h"
#include "webrtc/modules/audio_coding/main/source/acm_codec_database.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
#include "webrtc/system_wrappers/interface/trace.h"
#ifdef WEBRTC_CODEC_PCM16
#include "webrtc/modules/audio_coding/codecs/pcm16b/include/pcm16b.h"
#endif
namespace webrtc {
namespace acm1 {
#ifndef WEBRTC_CODEC_PCM16
ACMPCM16B::ACMPCM16B(int16_t /* codec_id */) {
return;
}
ACMPCM16B::~ACMPCM16B() {
return;
}
int16_t ACMPCM16B::InternalEncode(
uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */) {
return -1;
}
int16_t ACMPCM16B::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return -1;
}
int16_t ACMPCM16B::InternalInitEncoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int16_t ACMPCM16B::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int32_t ACMPCM16B::CodecDef(WebRtcNetEQ_CodecDef& /* codec_def */,
const CodecInst& /* codec_inst */) {
return -1;
}
ACMGenericCodec* ACMPCM16B::CreateInstance(void) {
return NULL;
}
int16_t ACMPCM16B::InternalCreateEncoder() {
return -1;
}
int16_t ACMPCM16B::InternalCreateDecoder() {
return -1;
}
void ACMPCM16B::InternalDestructEncoderInst(void* /* ptr_inst */) {
return;
}
void ACMPCM16B::DestructEncoderSafe() {
return;
}
void ACMPCM16B::DestructDecoderSafe() {
return;
}
void ACMPCM16B::SplitStereoPacket(uint8_t* /*payload*/,
int32_t* /*payload_length*/) {
}
#else //===================== Actual Implementation =======================
ACMPCM16B::ACMPCM16B(int16_t codec_id) {
codec_id_ = codec_id;
sampling_freq_hz_ = ACMCodecDB::CodecFreq(codec_id_);
}
ACMPCM16B::~ACMPCM16B() {
return;
}
int16_t ACMPCM16B::InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) {
*bitstream_len_byte = WebRtcPcm16b_Encode(&in_audio_[in_audio_ix_read_],
frame_len_smpl_ * num_channels_,
bitstream);
// Increment the read index to tell the caller that how far
// we have gone forward in reading the audio buffer.
in_audio_ix_read_ += frame_len_smpl_ * num_channels_;
return *bitstream_len_byte;
}
int16_t ACMPCM16B::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return 0;
}
int16_t ACMPCM16B::InternalInitEncoder(
WebRtcACMCodecParams* /* codec_params */) {
// This codec does not need initialization, PCM has no instance.
return 0;
}
int16_t ACMPCM16B::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
// This codec does not need initialization, PCM has no instance.
return 0;
}
int32_t ACMPCM16B::CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) {
// Fill up the structure by calling "SET_CODEC_PAR" & "SET_PCMU_FUNCTION".
// Then call NetEQ to add the codec to it's database.
if (codec_inst.channels == 1) {
switch (sampling_freq_hz_) {
case 8000: {
SET_CODEC_PAR(codec_def, kDecoderPCM16B, codec_inst.pltype, NULL, 8000);
SET_PCM16B_FUNCTIONS(codec_def);
break;
}
case 16000: {
SET_CODEC_PAR(codec_def, kDecoderPCM16Bwb, codec_inst.pltype, NULL,
16000);
SET_PCM16B_WB_FUNCTIONS(codec_def);
break;
}
case 32000: {
SET_CODEC_PAR(codec_def, kDecoderPCM16Bswb32kHz, codec_inst.pltype,
NULL, 32000);
SET_PCM16B_SWB32_FUNCTIONS(codec_def);
break;
}
default: {
return -1;
}
}
} else {
switch (sampling_freq_hz_) {
case 8000: {
SET_CODEC_PAR(codec_def, kDecoderPCM16B_2ch, codec_inst.pltype, NULL,
8000);
SET_PCM16B_FUNCTIONS(codec_def);
break;
}
case 16000: {
SET_CODEC_PAR(codec_def, kDecoderPCM16Bwb_2ch, codec_inst.pltype,
NULL, 16000);
SET_PCM16B_WB_FUNCTIONS(codec_def);
break;
}
case 32000: {
SET_CODEC_PAR(codec_def, kDecoderPCM16Bswb32kHz_2ch, codec_inst.pltype,
NULL, 32000);
SET_PCM16B_SWB32_FUNCTIONS(codec_def);
break;
}
default: {
return -1;
}
}
}
return 0;
}
ACMGenericCodec* ACMPCM16B::CreateInstance(void) {
return NULL;
}
int16_t ACMPCM16B::InternalCreateEncoder() {
// PCM has no instance.
return 0;
}
int16_t ACMPCM16B::InternalCreateDecoder() {
// PCM has no instance.
return 0;
}
void ACMPCM16B::InternalDestructEncoderInst(void* /* ptr_inst */) {
// PCM has no instance.
return;
}
void ACMPCM16B::DestructEncoderSafe() {
// PCM has no instance.
encoder_exist_ = false;
encoder_initialized_ = false;
return;
}
void ACMPCM16B::DestructDecoderSafe() {
// PCM has no instance.
decoder_exist_ = false;
decoder_initialized_ = false;
return;
}
// Split the stereo packet and place left and right channel after each other
// in the payload vector.
void ACMPCM16B::SplitStereoPacket(uint8_t* payload, int32_t* payload_length) {
uint8_t right_byte_msb;
uint8_t right_byte_lsb;
// Check for valid inputs.
assert(payload != NULL);
assert(*payload_length > 0);
// Move two bytes representing right channel each loop, and place it at the
// end of the bytestream vector. After looping the data is reordered to:
// l1 l2 l3 l4 ... l(N-1) lN r1 r2 r3 r4 ... r(N-1) r(N),
// where N is the total number of samples.
for (int i = 0; i < *payload_length / 2; i += 2) {
right_byte_msb = payload[i + 2];
right_byte_lsb = payload[i + 3];
memmove(&payload[i + 2], &payload[i + 4], *payload_length - i - 4);
payload[*payload_length - 2] = right_byte_msb;
payload[*payload_length - 1] = right_byte_lsb;
}
}
#endif
} // namespace acm1
} // namespace webrtc

View File

@ -1,67 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_PCM16B_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_PCM16B_H_
#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
namespace webrtc {
namespace acm1 {
class ACMPCM16B : public ACMGenericCodec {
public:
explicit ACMPCM16B(int16_t codec_id);
virtual ~ACMPCM16B();
// for FEC
virtual ACMGenericCodec* CreateInstance(void) OVERRIDE;
virtual int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) OVERRIDE;
virtual int16_t InternalInitEncoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
virtual int16_t InternalInitDecoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
protected:
virtual int16_t DecodeSafe(uint8_t* bitstream,
int16_t bitstream_len_byte,
int16_t* audio,
int16_t* audio_samples,
int8_t* speech_type) OVERRIDE;
virtual int32_t CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) OVERRIDE;
virtual void DestructEncoderSafe() OVERRIDE;
virtual void DestructDecoderSafe() OVERRIDE;
virtual int16_t InternalCreateEncoder() OVERRIDE;
virtual int16_t InternalCreateDecoder() OVERRIDE;
virtual void InternalDestructEncoderInst(void* ptr_inst) OVERRIDE;
virtual void SplitStereoPacket(uint8_t* payload,
int32_t* payload_length) OVERRIDE;
int32_t sampling_freq_hz_;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_PCM16B_H_

View File

@ -1,134 +0,0 @@
/*
* 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/source/acm_pcma.h"
#include "webrtc/modules/audio_coding/codecs/g711/include/g711_interface.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
#include "webrtc/system_wrappers/interface/trace.h"
// Codec interface
namespace webrtc {
namespace acm1 {
ACMPCMA::ACMPCMA(int16_t codec_id) {
codec_id_ = codec_id;
}
ACMPCMA::~ACMPCMA() {
return;
}
int16_t ACMPCMA::InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) {
*bitstream_len_byte = WebRtcG711_EncodeA(NULL, &in_audio_[in_audio_ix_read_],
frame_len_smpl_ * num_channels_,
(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_ * num_channels_;
return *bitstream_len_byte;
}
int16_t ACMPCMA::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return 0;
}
int16_t ACMPCMA::InternalInitEncoder(
WebRtcACMCodecParams* /* codec_params */) {
// This codec does not need initialization, PCM has no instance.
return 0;
}
int16_t ACMPCMA::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
// This codec does not need initialization, PCM has no instance.
return 0;
}
int32_t ACMPCMA::CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) {
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_PCMA_FUNCTION."
// Then call NetEQ to add the codec to it's database.
if (codec_inst.channels == 1) {
// Mono mode.
SET_CODEC_PAR(codec_def, kDecoderPCMa, codec_inst.pltype, NULL, 8000);
} else {
// Stereo mode.
SET_CODEC_PAR(codec_def, kDecoderPCMa_2ch, codec_inst.pltype, NULL, 8000);
}
SET_PCMA_FUNCTIONS(codec_def);
return 0;
}
ACMGenericCodec* ACMPCMA::CreateInstance(void) {
return NULL;
}
int16_t ACMPCMA::InternalCreateEncoder() {
// PCM has no instance.
return 0;
}
int16_t ACMPCMA::InternalCreateDecoder() {
// PCM has no instance.
return 0;
}
void ACMPCMA::InternalDestructEncoderInst(void* /* ptr_inst */) {
// PCM has no instance.
return;
}
void ACMPCMA::DestructEncoderSafe() {
// PCM has no instance.
return;
}
void ACMPCMA::DestructDecoderSafe() {
// PCM has no instance.
decoder_initialized_ = false;
decoder_exist_ = false;
return;
}
// Split the stereo packet and place left and right channel after each other
// in the payload vector.
void ACMPCMA::SplitStereoPacket(uint8_t* payload, int32_t* payload_length) {
uint8_t right_byte;
// Check for valid inputs.
assert(payload != NULL);
assert(*payload_length > 0);
// Move one bytes representing right channel each loop, and place it at the
// end of the bytestream vector. After looping the data is reordered to:
// l1 l2 l3 l4 ... l(N-1) lN r1 r2 r3 r4 ... r(N-1) r(N),
// where N is the total number of samples.
for (int i = 0; i < *payload_length / 2; i++) {
right_byte = payload[i + 1];
memmove(&payload[i + 1], &payload[i + 2], *payload_length - i - 2);
payload[*payload_length - 1] = right_byte;
}
}
} // namespace acm1
} // namespace webrtc

View File

@ -1,65 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_PCMA_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_PCMA_H_
#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
namespace webrtc {
namespace acm1 {
class ACMPCMA : public ACMGenericCodec {
public:
explicit ACMPCMA(int16_t codec_id);
virtual ~ACMPCMA();
// for FEC
virtual ACMGenericCodec* CreateInstance(void) OVERRIDE;
virtual int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) OVERRIDE;
virtual int16_t InternalInitEncoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
virtual int16_t InternalInitDecoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
protected:
virtual int16_t DecodeSafe(uint8_t* bitstream,
int16_t bitstream_len_byte,
int16_t* audio,
int16_t* audio_samples,
int8_t* speech_type) OVERRIDE;
virtual int32_t CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) OVERRIDE;
virtual void DestructEncoderSafe() OVERRIDE;
virtual void DestructDecoderSafe() OVERRIDE;
virtual int16_t InternalCreateEncoder() OVERRIDE;
virtual int16_t InternalCreateDecoder() OVERRIDE;
virtual void InternalDestructEncoderInst(void* ptr_inst) OVERRIDE;
virtual void SplitStereoPacket(uint8_t* payload,
int32_t* payload_length) OVERRIDE;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_PCMA_H_

View File

@ -1,136 +0,0 @@
/*
* 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/source/acm_pcmu.h"
#include "webrtc/modules/audio_coding/codecs/g711/include/g711_interface.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
#include "webrtc/system_wrappers/interface/trace.h"
// Codec interface
namespace webrtc {
namespace acm1 {
ACMPCMU::ACMPCMU(int16_t codec_id) {
codec_id_ = codec_id;
}
ACMPCMU::~ACMPCMU() {
return;
}
int16_t ACMPCMU::InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) {
*bitstream_len_byte = WebRtcG711_EncodeU(NULL, &in_audio_[in_audio_ix_read_],
frame_len_smpl_ * num_channels_,
(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_ * num_channels_;
return *bitstream_len_byte;
}
int16_t ACMPCMU::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return 0;
}
int16_t ACMPCMU::InternalInitEncoder(
WebRtcACMCodecParams* /* codec_params */) {
// This codec does not need initialization, PCM has no instance.
return 0;
}
int16_t ACMPCMU::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
// This codec does not need initialization, PCM has no instance.
return 0;
}
int32_t ACMPCMU::CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) {
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_PCMU_FUNCTION."
// Then call NetEQ to add the codec to it's database.
if (codec_inst.channels == 1) {
// Mono mode.
SET_CODEC_PAR(codec_def, kDecoderPCMu, codec_inst.pltype, NULL, 8000);
} else {
// Stereo mode.
SET_CODEC_PAR(codec_def, kDecoderPCMu_2ch, codec_inst.pltype, NULL, 8000);
}
SET_PCMU_FUNCTIONS(codec_def);
return 0;
}
ACMGenericCodec* ACMPCMU::CreateInstance(void) {
return NULL;
}
int16_t ACMPCMU::InternalCreateEncoder() {
// PCM has no instance.
return 0;
}
int16_t ACMPCMU::InternalCreateDecoder() {
// PCM has no instance.
return 0;
}
void ACMPCMU::InternalDestructEncoderInst(void* /* ptr_inst */) {
// PCM has no instance.
return;
}
void ACMPCMU::DestructEncoderSafe() {
// PCM has no instance.
encoder_exist_ = false;
encoder_initialized_ = false;
return;
}
void ACMPCMU::DestructDecoderSafe() {
// PCM has no instance.
decoder_initialized_ = false;
decoder_exist_ = false;
return;
}
// Split the stereo packet and place left and right channel after each other
// in the payload vector.
void ACMPCMU::SplitStereoPacket(uint8_t* payload, int32_t* payload_length) {
uint8_t right_byte;
// Check for valid inputs.
assert(payload != NULL);
assert(*payload_length > 0);
// Move one bytes representing right channel each loop, and place it at the
// end of the bytestream vector. After looping the data is reordered to:
// l1 l2 l3 l4 ... l(N-1) lN r1 r2 r3 r4 ... r(N-1) r(N),
// where N is the total number of samples.
for (int i = 0; i < *payload_length / 2; i++) {
right_byte = payload[i + 1];
memmove(&payload[i + 1], &payload[i + 2], *payload_length - i - 2);
payload[*payload_length - 1] = right_byte;
}
}
} // namespace acm1
} // namespace webrtc

View File

@ -1,65 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_PCMU_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_PCMU_H_
#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
namespace webrtc {
namespace acm1 {
class ACMPCMU : public ACMGenericCodec {
public:
explicit ACMPCMU(int16_t codec_id);
virtual ~ACMPCMU();
// for FEC
virtual ACMGenericCodec* CreateInstance(void) OVERRIDE;
virtual int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) OVERRIDE;
virtual int16_t InternalInitEncoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
virtual int16_t InternalInitDecoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
protected:
virtual int16_t DecodeSafe(uint8_t* bitstream,
int16_t bitstream_len_byte,
int16_t* audio,
int16_t* audio_samples,
int8_t* speech_type) OVERRIDE;
virtual int32_t CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) OVERRIDE;
virtual void DestructEncoderSafe() OVERRIDE;
virtual void DestructDecoderSafe() OVERRIDE;
virtual int16_t InternalCreateEncoder() OVERRIDE;
virtual int16_t InternalCreateDecoder() OVERRIDE;
virtual void InternalDestructEncoderInst(void* ptr_inst) OVERRIDE;
virtual void SplitStereoPacket(uint8_t* payload,
int32_t* payload_length) OVERRIDE;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_PCMU_H_

View File

@ -1,108 +0,0 @@
/*
* 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/source/acm_red.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
#include "webrtc/system_wrappers/interface/trace.h"
namespace webrtc {
namespace acm1 {
ACMRED::ACMRED(int16_t codec_id) {
codec_id_ = codec_id;
}
ACMRED::~ACMRED() {
return;
}
int16_t ACMRED::InternalEncode(uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */) {
// RED is never used as an encoder
// RED has no instance
return 0;
}
int16_t ACMRED::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return 0;
}
int16_t ACMRED::InternalInitEncoder(
WebRtcACMCodecParams* /* codec_params */) {
// This codec does not need initialization,
// RED has no instance
return 0;
}
int16_t ACMRED::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
// This codec does not need initialization,
// RED has no instance
return 0;
}
int32_t ACMRED::CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) {
if (!decoder_initialized_) {
// Todo:
// log error
return -1;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_PCMU_FUNCTION."
// Then call NetEQ to add the codec to it's
// database.
SET_CODEC_PAR((codec_def), kDecoderRED, codec_inst.pltype, NULL, 8000);
SET_RED_FUNCTIONS((codec_def));
return 0;
}
ACMGenericCodec* ACMRED::CreateInstance(void) {
return NULL;
}
int16_t ACMRED::InternalCreateEncoder() {
// RED has no instance
return 0;
}
int16_t ACMRED::InternalCreateDecoder() {
// RED has no instance
return 0;
}
void ACMRED::InternalDestructEncoderInst(void* /* ptr_inst */) {
// RED has no instance
return;
}
void ACMRED::DestructEncoderSafe() {
// RED has no instance
return;
}
void ACMRED::DestructDecoderSafe() {
// RED has no instance
return;
}
} // namespace acm1
} // namespace webrtc

View File

@ -1,62 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_RED_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_RED_H_
#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
namespace webrtc {
namespace acm1 {
class ACMRED : public ACMGenericCodec {
public:
explicit ACMRED(int16_t codec_id);
virtual ~ACMRED();
// for FEC
virtual ACMGenericCodec* CreateInstance(void) OVERRIDE;
virtual int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) OVERRIDE;
virtual int16_t InternalInitEncoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
virtual int16_t InternalInitDecoder(
WebRtcACMCodecParams* codec_params) OVERRIDE;
protected:
virtual int16_t DecodeSafe(uint8_t* bitstream,
int16_t bitstream_len_byte,
int16_t* audio,
int16_t* audio_samples,
int8_t* speech_type) OVERRIDE;
virtual int32_t CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) OVERRIDE;
virtual void DestructEncoderSafe() OVERRIDE;
virtual void DestructDecoderSafe() OVERRIDE;
virtual int16_t InternalCreateEncoder() OVERRIDE;
virtual int16_t InternalCreateDecoder() OVERRIDE;
virtual void InternalDestructEncoderInst(void* ptr_inst) OVERRIDE;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_RED_H_

View File

@ -1,63 +0,0 @@
/*
* 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/source/acm_resampler.h"
#include <string.h>
#include "webrtc/common_audio/resampler/include/push_resampler.h"
#include "webrtc/system_wrappers/interface/logging.h"
namespace webrtc {
namespace acm1 {
ACMResampler::ACMResampler() {
}
ACMResampler::~ACMResampler() {
}
int16_t ACMResampler::Resample10Msec(const int16_t* in_audio,
int32_t in_freq_hz,
int16_t* out_audio,
int32_t out_freq_hz,
uint8_t num_audio_channels) {
if (in_freq_hz == out_freq_hz) {
size_t length = static_cast<size_t>(in_freq_hz * num_audio_channels / 100);
memcpy(out_audio, in_audio, length * sizeof(int16_t));
return static_cast<int16_t>(in_freq_hz / 100);
}
// |max_length| is the maximum number of samples for 10ms at 48kHz.
// TODO(turajs): is this actually the capacity of the |out_audio| buffer?
int max_length = 480 * num_audio_channels;
int in_length = in_freq_hz / 100 * num_audio_channels;
if (resampler_.InitializeIfNeeded(in_freq_hz, out_freq_hz,
num_audio_channels) != 0) {
LOG_FERR3(LS_ERROR, InitializeIfNeeded, in_freq_hz, out_freq_hz,
num_audio_channels);
return -1;
}
int out_length = resampler_.Resample(in_audio, in_length, out_audio,
max_length);
if (out_length == -1) {
LOG_FERR4(LS_ERROR, Resample, in_audio, in_length, out_audio, max_length);
return -1;
}
return out_length / num_audio_channels;
}
} // namespace acm1
} // namespace webrtc

View File

@ -1,38 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_RESAMPLER_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_RESAMPLER_H_
#include "webrtc/common_audio/resampler/include/push_resampler.h"
#include "webrtc/typedefs.h"
namespace webrtc {
namespace acm1 {
class ACMResampler {
public:
ACMResampler();
~ACMResampler();
int16_t Resample10Msec(const int16_t* in_audio,
const int32_t in_freq_hz,
int16_t* out_audio,
const int32_t out_freq_hz,
uint8_t num_audio_channels);
private:
PushResampler<int16_t> resampler_;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_RESAMPLER_H_

View File

@ -1,471 +0,0 @@
/*
* 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/source/acm_speex.h"
#include "webrtc/modules/audio_coding/main/source/acm_codec_database.h"
#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
#include "webrtc/system_wrappers/interface/trace.h"
#ifdef WEBRTC_CODEC_SPEEX
// NOTE! Speex is not included in the open-source package. Modify this file or
// your codec API to match the function calls and names of used Speex API file.
#include "speex_interface.h"
#endif
namespace webrtc {
namespace acm1 {
#ifndef WEBRTC_CODEC_SPEEX
ACMSPEEX::ACMSPEEX(int16_t /* codec_id */)
: encoder_inst_ptr_(NULL),
decoder_inst_ptr_(NULL),
compl_mode_(0),
vbr_enabled_(false),
encoding_rate_(-1),
sampling_frequency_(-1),
samples_in_20ms_audio_(-1) {
return;
}
ACMSPEEX::~ACMSPEEX() {
return;
}
int16_t ACMSPEEX::InternalEncode(
uint8_t* /* bitstream */,
int16_t* /* bitstream_len_byte */) {
return -1;
}
int16_t ACMSPEEX::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return -1;
}
int16_t ACMSPEEX::EnableDTX() {
return -1;
}
int16_t ACMSPEEX::DisableDTX() {
return -1;
}
int16_t ACMSPEEX::InternalInitEncoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int16_t ACMSPEEX::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
return -1;
}
int32_t ACMSPEEX::CodecDef(WebRtcNetEQ_CodecDef& /* codec_def */,
const CodecInst& /* codec_inst */) {
return -1;
}
ACMGenericCodec* ACMSPEEX::CreateInstance(void) {
return NULL;
}
int16_t ACMSPEEX::InternalCreateEncoder() {
return -1;
}
void ACMSPEEX::DestructEncoderSafe() {
return;
}
int16_t ACMSPEEX::InternalCreateDecoder() {
return -1;
}
void ACMSPEEX::DestructDecoderSafe() {
return;
}
int16_t ACMSPEEX::SetBitRateSafe(const int32_t /* rate */) {
return -1;
}
void ACMSPEEX::InternalDestructEncoderInst(void* /* ptr_inst */) {
return;
}
#ifdef UNUSEDSPEEX
int16_t ACMSPEEX::EnableVBR() {
return -1;
}
int16_t ACMSPEEX::DisableVBR() {
return -1;
}
int16_t ACMSPEEX::SetComplMode(int16_t mode) {
return -1;
}
#endif
#else //===================== Actual Implementation =======================
ACMSPEEX::ACMSPEEX(int16_t codec_id)
: encoder_inst_ptr_(NULL),
decoder_inst_ptr_(NULL) {
codec_id_ = codec_id;
// Set sampling frequency, frame size and rate Speex
if (codec_id_ == ACMCodecDB::kSPEEX8) {
sampling_frequency_ = 8000;
samples_in_20ms_audio_ = 160;
encoding_rate_ = 11000;
} else if (codec_id_ == ACMCodecDB::kSPEEX16) {
sampling_frequency_ = 16000;
samples_in_20ms_audio_ = 320;
encoding_rate_ = 22000;
} else {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Wrong codec id for Speex.");
sampling_frequency_ = -1;
samples_in_20ms_audio_ = -1;
encoding_rate_ = -1;
}
has_internal_dtx_ = true;
dtx_enabled_ = false;
vbr_enabled_ = false;
compl_mode_ = 3; // default complexity value
return;
}
ACMSPEEX::~ACMSPEEX() {
if (encoder_inst_ptr_ != NULL) {
WebRtcSpeex_FreeEnc(encoder_inst_ptr_);
encoder_inst_ptr_ = NULL;
}
if (decoder_inst_ptr_ != NULL) {
WebRtcSpeex_FreeDec(decoder_inst_ptr_);
decoder_inst_ptr_ = NULL;
}
return;
}
int16_t ACMSPEEX::InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte) {
int16_t status;
int16_t num_encoded_samples = 0;
int16_t n = 0;
while (num_encoded_samples < frame_len_smpl_) {
status = WebRtcSpeex_Encode(encoder_inst_ptr_,
&in_audio_[in_audio_ix_read_], encoding_rate_);
// increment the read index this tell the caller that how far
// we have gone forward in reading the audio buffer
in_audio_ix_read_ += samples_in_20ms_audio_;
num_encoded_samples += samples_in_20ms_audio_;
if (status < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Error in Speex encoder");
return status;
}
// Update VAD, if internal DTX is used
if (has_internal_dtx_ && dtx_enabled_) {
vad_label_[n++] = status;
vad_label_[n++] = status;
}
if (status == 0) {
// This frame is detected as inactive. We need send whatever
// encoded so far.
*bitstream_len_byte = WebRtcSpeex_GetBitstream(encoder_inst_ptr_,
(int16_t*)bitstream);
return *bitstream_len_byte;
}
}
*bitstream_len_byte = WebRtcSpeex_GetBitstream(encoder_inst_ptr_,
(int16_t*)bitstream);
return *bitstream_len_byte;
}
int16_t ACMSPEEX::DecodeSafe(uint8_t* /* bitstream */,
int16_t /* bitstream_len_byte */,
int16_t* /* audio */,
int16_t* /* audio_samples */,
int8_t* /* speech_type */) {
return 0;
}
int16_t ACMSPEEX::EnableDTX() {
if (dtx_enabled_) {
return 0;
} else if (encoder_exist_) { // check if encoder exist
// enable DTX
if (WebRtcSpeex_EncoderInit(encoder_inst_ptr_, (vbr_enabled_ ? 1 : 0),
compl_mode_, 1) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Cannot enable DTX for Speex");
return -1;
}
dtx_enabled_ = true;
return 0;
} else {
return -1;
}
return 0;
}
int16_t ACMSPEEX::DisableDTX() {
if (!dtx_enabled_) {
return 0;
} else if (encoder_exist_) { // check if encoder exist
// disable DTX
if (WebRtcSpeex_EncoderInit(encoder_inst_ptr_, (vbr_enabled_ ? 1 : 0),
compl_mode_, 0) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Cannot disable DTX for Speex");
return -1;
}
dtx_enabled_ = false;
return 0;
} else {
// encoder doesn't exists, therefore disabling is harmless
return 0;
}
return 0;
}
int16_t ACMSPEEX::InternalInitEncoder(
WebRtcACMCodecParams* codec_params) {
// sanity check
if (encoder_inst_ptr_ == NULL) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Cannot initialize Speex encoder, instance does not exist");
return -1;
}
int16_t status = SetBitRateSafe((codec_params->codecInstant).rate);
status +=
(WebRtcSpeex_EncoderInit(encoder_inst_ptr_, vbr_enabled_, compl_mode_,
((codec_params->enable_dtx) ? 1 : 0)) < 0) ?
-1 : 0;
if (status >= 0) {
return 0;
} else {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Error in initialization of Speex encoder");
return -1;
}
}
int16_t ACMSPEEX::InternalInitDecoder(
WebRtcACMCodecParams* /* codec_params */) {
int16_t status;
// sanity check
if (decoder_inst_ptr_ == NULL) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Cannot initialize Speex decoder, instance does not exist");
return -1;
}
status = ((WebRtcSpeex_DecoderInit(decoder_inst_ptr_) < 0) ? -1 : 0);
if (status >= 0) {
return 0;
} else {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Error in initialization of Speex decoder");
return -1;
}
}
int32_t ACMSPEEX::CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst) {
if (!decoder_initialized_) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Error, Speex decoder is not initialized");
return -1;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_SPEEX_FUNCTION."
// Then call NetEQ to add the codec to its
// database.
switch (sampling_frequency_) {
case 8000: {
SET_CODEC_PAR((codec_def), kDecoderSPEEX_8, codec_inst.pltype,
decoder_inst_ptr_, 8000);
break;
}
case 16000: {
SET_CODEC_PAR((codec_def), kDecoderSPEEX_16, codec_inst.pltype,
decoder_inst_ptr_, 16000);
break;
}
default: {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Unsupported sampling frequency for Speex");
return -1;
}
}
SET_SPEEX_FUNCTIONS((codec_def));
return 0;
}
ACMGenericCodec* ACMSPEEX::CreateInstance(void) {
return NULL;
}
int16_t ACMSPEEX::InternalCreateEncoder() {
return WebRtcSpeex_CreateEnc(&encoder_inst_ptr_, sampling_frequency_);
}
void ACMSPEEX::DestructEncoderSafe() {
if (encoder_inst_ptr_ != NULL) {
WebRtcSpeex_FreeEnc(encoder_inst_ptr_);
encoder_inst_ptr_ = NULL;
}
// there is no encoder set the following
encoder_exist_ = false;
encoder_initialized_ = false;
encoding_rate_ = 0;
}
int16_t ACMSPEEX::InternalCreateDecoder() {
return WebRtcSpeex_CreateDec(&decoder_inst_ptr_, sampling_frequency_, 1);
}
void ACMSPEEX::DestructDecoderSafe() {
if (decoder_inst_ptr_ != NULL) {
WebRtcSpeex_FreeDec(decoder_inst_ptr_);
decoder_inst_ptr_ = NULL;
}
// there is no encoder instance set the followings
decoder_exist_ = false;
decoder_initialized_ = false;
}
int16_t ACMSPEEX::SetBitRateSafe(const int32_t rate) {
// Check if changed rate
if (rate == encoding_rate_) {
return 0;
} else if (rate > 2000) {
encoding_rate_ = rate;
encoder_params_.codecInstant.rate = rate;
} else {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Unsupported encoding rate for Speex");
return -1;
}
return 0;
}
void ACMSPEEX::InternalDestructEncoderInst(void* ptr_inst) {
if (ptr_inst != NULL) {
WebRtcSpeex_FreeEnc((SPEEX_encinst_t_*) ptr_inst);
}
return;
}
#ifdef UNUSEDSPEEX
// This API is currently not in use. If requested to be able to enable/disable
// VBR an ACM API need to be added.
int16_t ACMSPEEX::EnableVBR() {
if (vbr_enabled_) {
return 0;
} else if (encoder_exist_) { // check if encoder exist
// enable Variable Bit Rate (VBR)
if (WebRtcSpeex_EncoderInit(encoder_inst_ptr_, 1, compl_mode_,
(dtx_enabled_ ? 1 : 0)) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Cannot enable VBR mode for Speex");
return -1;
}
vbr_enabled_ = true;
return 0;
} else {
return -1;
}
}
// This API is currently not in use. If requested to be able to enable/disable
// VBR an ACM API need to be added.
int16_t ACMSPEEX::DisableVBR() {
if (!vbr_enabled_) {
return 0;
} else if (encoder_exist_) { // check if encoder exist
// disable DTX
if (WebRtcSpeex_EncoderInit(encoder_inst_ptr_, 0, compl_mode_,
(dtx_enabled_ ? 1 : 0)) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Cannot disable DTX for Speex");
return -1;
}
vbr_enabled_ = false;
return 0;
} else {
// encoder doesn't exists, therefore disabling is harmless
return 0;
}
}
// This API is currently not in use. If requested to be able to set complexity
// an ACM API need to be added.
int16_t ACMSPEEX::SetComplMode(int16_t mode) {
// Check if new mode
if (mode == compl_mode_) {
return 0;
} else if (encoder_exist_) { // check if encoder exist
// Set new mode
if (WebRtcSpeex_EncoderInit(encoder_inst_ptr_, 0, mode,
(dtx_enabled_ ? 1 : 0)) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Error in complexity mode for Speex");
return -1;
}
compl_mode_ = mode;
return 0;
} else {
// encoder doesn't exists, therefore disabling is harmless
return 0;
}
}
#endif
#endif
} // namespace acm1
} // namespace webrtc

View File

@ -1,86 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_SPEEX_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_SPEEX_H_
#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
// forward declaration
struct SPEEX_encinst_t_;
struct SPEEX_decinst_t_;
namespace webrtc {
namespace acm1 {
class ACMSPEEX : public ACMGenericCodec {
public:
explicit ACMSPEEX(int16_t codec_id);
~ACMSPEEX();
// for FEC
ACMGenericCodec* CreateInstance(void);
int16_t InternalEncode(uint8_t* bitstream,
int16_t* bitstream_len_byte);
int16_t InternalInitEncoder(WebRtcACMCodecParams *codec_params);
int16_t InternalInitDecoder(WebRtcACMCodecParams *codec_params);
protected:
int16_t DecodeSafe(uint8_t* bitstream,
int16_t bitstream_len_byte,
int16_t* audio,
int16_t* audio_samples,
int8_t* speech_type);
int32_t CodecDef(WebRtcNetEQ_CodecDef& codec_def,
const CodecInst& codec_inst);
void DestructEncoderSafe();
void DestructDecoderSafe();
int16_t InternalCreateEncoder();
int16_t InternalCreateDecoder();
void InternalDestructEncoderInst(void* ptr_inst);
int16_t SetBitRateSafe(const int32_t rate);
int16_t EnableDTX();
int16_t DisableDTX();
#ifdef UNUSEDSPEEX
int16_t EnableVBR();
int16_t DisableVBR();
int16_t SetComplMode(int16_t mode);
#endif
SPEEX_encinst_t_* encoder_inst_ptr_;
SPEEX_decinst_t_* decoder_inst_ptr_;
int16_t compl_mode_;
bool vbr_enabled_;
int32_t encoding_rate_;
int16_t sampling_frequency_;
uint16_t samples_in_20ms_audio_;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_SPEEX_H_

View File

@ -1,153 +0,0 @@
# 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.
{
'variables': {
'audio_coding_dependencies': [
'CNG',
'G711',
'G722',
'iLBC',
'iSAC',
'iSACFix',
'PCM16B',
'NetEq',
'<(webrtc_root)/common_audio/common_audio.gyp:common_audio',
'<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:system_wrappers',
],
'audio_coding_defines': [],
'conditions': [
['include_opus==1', {
'audio_coding_dependencies': ['webrtc_opus',],
'audio_coding_defines': ['WEBRTC_CODEC_OPUS',],
}],
],
},
'targets': [
{
'target_name': 'audio_coding_module',
'type': 'static_library',
'defines': [
'<@(audio_coding_defines)',
],
'dependencies': [
'<@(audio_coding_dependencies)',
'acm2',
],
'include_dirs': [
'../interface',
'../../../interface',
'<(webrtc_root)',
],
'direct_dependent_settings': {
'include_dirs': [
'../interface',
'../../../interface',
'<(webrtc_root)',
],
},
'sources': [
'../interface/audio_coding_module.h',
'../interface/audio_coding_module_typedefs.h',
'acm_amr.cc',
'acm_amr.h',
'acm_amrwb.cc',
'acm_amrwb.h',
'acm_celt.cc',
'acm_celt.h',
'acm_cng.cc',
'acm_cng.h',
'acm_codec_database.cc',
'acm_codec_database.h',
'acm_dtmf_detection.cc',
'acm_dtmf_detection.h',
'acm_dtmf_playout.cc',
'acm_dtmf_playout.h',
'acm_g722.cc',
'acm_g722.h',
'acm_g7221.cc',
'acm_g7221.h',
'acm_g7221c.cc',
'acm_g7221c.h',
'acm_g729.cc',
'acm_g729.h',
'acm_g7291.cc',
'acm_g7291.h',
'acm_generic_codec.cc',
'acm_generic_codec.h',
'acm_gsmfr.cc',
'acm_gsmfr.h',
'acm_ilbc.cc',
'acm_ilbc.h',
'acm_isac.cc',
'acm_isac.h',
'acm_isac_macros.h',
'acm_neteq.cc',
'acm_neteq.h',
'acm_opus.cc',
'acm_opus.h',
'acm_speex.cc',
'acm_speex.h',
'acm_pcm16b.cc',
'acm_pcm16b.h',
'acm_pcma.cc',
'acm_pcma.h',
'acm_pcmu.cc',
'acm_pcmu.h',
'acm_red.cc',
'acm_red.h',
'acm_resampler.cc',
'acm_resampler.h',
'audio_coding_module_impl.cc',
'audio_coding_module_impl.h',
],
},
],
'conditions': [
['include_tests==1', {
'targets': [
{
'target_name': 'delay_test',
'type': 'executable',
'dependencies': [
'audio_coding_module',
'<(DEPTH)/testing/gtest.gyp:gtest',
'<(webrtc_root)/test/test.gyp:test_support',
'<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:system_wrappers',
'<(DEPTH)/third_party/gflags/gflags.gyp:gflags',
],
'sources': [
'../test/delay_test.cc',
'../test/Channel.cc',
'../test/PCMFile.cc',
'../test/utility.cc',
],
}, # delay_test
{
'target_name': 'insert_packet_with_timing',
'type': 'executable',
'dependencies': [
'audio_coding_module',
'<(DEPTH)/testing/gtest.gyp:gtest',
'<(webrtc_root)/test/test.gyp:test_support',
'<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:system_wrappers',
'<(DEPTH)/third_party/gflags/gflags.gyp:gflags',
],
'sources': [
'../test/insert_packet_with_timing.cc',
'../test/Channel.cc',
'../test/PCMFile.cc',
],
}, # delay_test
],
}],
],
'includes': [
'../acm2/audio_coding_module.gypi',
],
}

View File

@ -1,453 +0,0 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_AUDIO_CODING_MODULE_IMPL_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_AUDIO_CODING_MODULE_IMPL_H_
#include <vector>
#include "webrtc/common_types.h"
#include "webrtc/engine_configurations.h"
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
#include "webrtc/modules/audio_coding/main/source/acm_codec_database.h"
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
#include "webrtc/modules/audio_coding/main/source/acm_resampler.h"
#include "webrtc/modules/audio_coding/main/acm2/call_statistics.h"
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
namespace webrtc {
struct WebRtcACMAudioBuff;
struct WebRtcACMCodecParams;
class CriticalSectionWrapper;
class RWLockWrapper;
class Clock;
namespace acm2 {
class Nack;
}
namespace acm1 {
class ACMDTMFDetection;
class ACMGenericCodec;
class AudioCodingModuleImpl : public AudioCodingModule {
public:
AudioCodingModuleImpl(const int32_t id, Clock* clock);
~AudioCodingModuleImpl();
// Change the unique identifier of this object.
virtual int32_t ChangeUniqueId(const int32_t id);
// Returns the number of milliseconds until the module want a worker thread
// to call Process.
int32_t TimeUntilNextProcess();
// Process any pending tasks such as timeouts.
int32_t Process();
/////////////////////////////////////////
// Sender
//
// Initialize send codec.
int32_t InitializeSender();
// Reset send codec.
int32_t ResetEncoder();
// Can be called multiple times for Codec, CNG, RED.
int32_t RegisterSendCodec(const CodecInst& send_codec);
// Register Secondary codec for dual-streaming. Dual-streaming is activated
// right after the secondary codec is registered.
int RegisterSecondarySendCodec(const CodecInst& send_codec);
// Unregister the secondary codec. Dual-streaming is deactivated right after
// deregistering secondary codec.
void UnregisterSecondarySendCodec();
// Get the secondary codec.
int SecondarySendCodec(CodecInst* secondary_codec) const;
// Get current send codec.
int32_t SendCodec(CodecInst* current_codec) const;
// Get current send frequency.
int32_t SendFrequency() const;
// Get encode bit-rate.
// Adaptive rate codecs return their current encode target rate, while other
// codecs return there long-term average or their fixed rate.
int32_t SendBitrate() const;
// Set available bandwidth, inform the encoder about the
// estimated bandwidth received from the remote party.
virtual int32_t SetReceivedEstimatedBandwidth(const int32_t bw);
// Register a transport callback which will be
// called to deliver the encoded buffers.
int32_t RegisterTransportCallback(AudioPacketizationCallback* transport);
// Add 10 ms of raw (PCM) audio data to the encoder.
int32_t Add10MsData(const AudioFrame& audio_frame);
/////////////////////////////////////////
// (FEC) Forward Error Correction
//
// Configure FEC status i.e on/off.
int32_t SetFECStatus(const bool enable_fec);
// Get FEC status.
bool FECStatus() const;
/////////////////////////////////////////
// (VAD) Voice Activity Detection
// and
// (CNG) Comfort Noise Generation
//
int32_t SetVAD(bool enable_dtx = true,
bool enable_vad = false,
ACMVADMode mode = VADNormal);
int32_t VAD(bool* dtx_enabled, bool* vad_enabled, ACMVADMode* mode) const;
int32_t RegisterVADCallback(ACMVADCallback* vad_callback);
/////////////////////////////////////////
// Receiver
//
// Initialize receiver, resets codec database etc.
int32_t InitializeReceiver();
// Reset the decoder state.
int32_t ResetDecoder();
// Get current receive frequency.
int32_t ReceiveFrequency() const;
// Get current playout frequency.
int32_t PlayoutFrequency() const;
// Register possible receive codecs, can be called multiple times,
// for codecs, CNG, DTMF, RED.
int32_t RegisterReceiveCodec(const CodecInst& receive_codec);
// Get current received codec.
int32_t ReceiveCodec(CodecInst* current_codec) const;
// Incoming packet from network parsed and ready for decode.
int32_t IncomingPacket(const uint8_t* incoming_payload,
const int32_t payload_length,
const WebRtcRTPHeader& rtp_info);
// Incoming payloads, without rtp-info, the rtp-info will be created in ACM.
// One usage for this API is when pre-encoded files are pushed in ACM.
int32_t IncomingPayload(const uint8_t* incoming_payload,
const int32_t payload_length,
const uint8_t payload_type,
const uint32_t timestamp = 0);
// NetEq minimum playout delay (used for lip-sync). The actual target delay
// is the max of |time_ms| and the required delay dictated by the channel.
int SetMinimumPlayoutDelay(int time_ms);
// NetEq maximum playout delay. The actual target delay is the min of
// |time_ms| and the required delay dictated by the channel.
int SetMaximumPlayoutDelay(int time_ms);
// The shortest latency, in milliseconds, required by jitter buffer. This
// is computed based on inter-arrival times and playout mode of NetEq. The
// actual delay is the maximum of least-required-delay and the minimum-delay
// specified by SetMinumumPlayoutDelay() API.
//
int LeastRequiredDelayMs() const ;
// Configure Dtmf playout status i.e on/off playout the incoming outband Dtmf
// tone.
int32_t SetDtmfPlayoutStatus(const bool enable);
// Get Dtmf playout status.
bool DtmfPlayoutStatus() const;
// Estimate the Bandwidth based on the incoming stream, needed
// for one way audio where the RTCP send the BW estimate.
// This is also done in the RTP module .
int32_t DecoderEstimatedBandwidth() const;
// Set playout mode voice, fax.
int32_t SetPlayoutMode(const AudioPlayoutMode mode);
// Get playout mode voice, fax.
AudioPlayoutMode PlayoutMode() const;
// Get playout timestamp.
int32_t PlayoutTimestamp(uint32_t* timestamp);
// Get 10 milliseconds of raw audio data to play out, and
// automatic resample to the requested frequency if > 0.
int32_t PlayoutData10Ms(int32_t desired_freq_hz,
AudioFrame* audio_frame);
/////////////////////////////////////////
// Statistics
//
int32_t NetworkStatistics(ACMNetworkStatistics* statistics);
void DestructEncoderInst(void* inst);
int16_t AudioBuffer(WebRtcACMAudioBuff& buffer);
// GET RED payload for iSAC. The method id called when 'this' ACM is
// the default ACM.
int32_t REDPayloadISAC(const int32_t isac_rate,
const int16_t isac_bw_estimate,
uint8_t* payload,
int16_t* length_bytes);
int16_t SetAudioBuffer(WebRtcACMAudioBuff& buffer);
uint32_t EarliestTimestamp() const;
int32_t LastEncodedTimestamp(uint32_t& timestamp) const;
int32_t ReplaceInternalDTXWithWebRtc(const bool use_webrtc_dtx);
int32_t IsInternalDTXReplacedWithWebRtc(bool* uses_webrtc_dtx);
int SetISACMaxRate(int max_bit_per_sec);
int SetISACMaxPayloadSize(int max_size_bytes);
int32_t ConfigISACBandwidthEstimator(
int frame_size_ms,
int rate_bit_per_sec,
bool enforce_frame_size = false);
int UnregisterReceiveCodec(uint8_t payload_type);
std::vector<uint16_t> GetNackList(int round_trip_time_ms) const;
protected:
void UnregisterSendCodec();
int32_t UnregisterReceiveCodecSafe(const int16_t id);
ACMGenericCodec* CreateCodec(const CodecInst& codec);
int16_t DecoderParamByPlType(const uint8_t payload_type,
WebRtcACMCodecParams& codec_params) const;
int16_t DecoderListIDByPlName(
const char* name, const uint16_t frequency = 0) const;
int32_t InitializeReceiverSafe();
bool HaveValidEncoder(const char* caller_name) const;
int32_t RegisterRecCodecMSSafe(const CodecInst& receive_codec,
int16_t codec_id,
int16_t mirror_id,
ACMNetEQ::JitterBuffer jitter_buffer);
// Set VAD/DTX status. This function does not acquire a lock, and it is
// created to be called only from inside a critical section.
int SetVADSafe(bool enable_dtx, bool enable_vad, ACMVADMode mode);
// Process buffered audio when dual-streaming is not enabled (When RED is
// enabled still this function is used.)
int ProcessSingleStream();
// Process buffered audio when dual-streaming is enabled, i.e. secondary send
// codec is registered.
int ProcessDualStream();
// Preprocessing of input audio, including resampling and down-mixing if
// required, before pushing audio into encoder's buffer.
//
// in_frame: input audio-frame
// ptr_out: pointer to output audio_frame. If no preprocessing is required
// |ptr_out| will be pointing to |in_frame|, otherwise pointing to
// |preprocess_frame_|.
//
// Return value:
// -1: if encountering an error.
// 0: otherwise.
int PreprocessToAddData(const AudioFrame& in_frame,
const AudioFrame** ptr_out);
// Set initial playout delay.
// -delay_ms: delay in millisecond.
//
// Return value:
// -1: if cannot set the delay.
// 0: if delay set successfully.
int SetInitialPlayoutDelay(int delay_ms);
// Enable NACK and set the maximum size of the NACK list.
int EnableNack(size_t max_nack_list_size);
// Disable NACK.
void DisableNack();
void GetDecodingCallStatistics(AudioDecodingCallStats* call_stats) const;
private:
// Change required states after starting to receive the codec corresponding
// to |index|.
int UpdateUponReceivingCodec(int index);
// Remove all slaves and initialize a stereo slave with required codecs
// from the master.
int InitStereoSlave();
// Returns true if the codec's |index| is registered with the master and
// is a stereo codec, RED or CN.
bool IsCodecForSlave(int index) const;
int EncodeFragmentation(int fragmentation_index, int payload_type,
uint32_t current_timestamp,
ACMGenericCodec* encoder,
uint8_t* stream);
void ResetFragmentation(int vector_size);
bool GetSilence(int desired_sample_rate_hz, AudioFrame* frame);
// Push a synchronization packet into NetEq. Such packets result in a frame
// of zeros (not decoded by the corresponding decoder). The size of the frame
// is the same as last decoding. NetEq has a special payload for this.
// Call within the scope of ACM critical section.
int PushSyncPacketSafe();
// Update the parameters required in initial phase of buffering, when
// initial playout delay is requested. Call within the scope of ACM critical
// section.
void UpdateBufferingSafe(const WebRtcRTPHeader& rtp_info,
int payload_len_bytes);
//
// Return the timestamp of current time, computed according to sampling rate
// of the codec identified by |codec_id|.
//
uint32_t NowTimestamp(int codec_id);
AudioPacketizationCallback* packetization_callback_;
int32_t id_;
uint32_t last_timestamp_;
uint32_t last_in_timestamp_;
CodecInst send_codec_inst_;
uint8_t cng_nb_pltype_;
uint8_t cng_wb_pltype_;
uint8_t cng_swb_pltype_;
uint8_t cng_fb_pltype_;
uint8_t red_pltype_;
bool vad_enabled_;
bool dtx_enabled_;
ACMVADMode vad_mode_;
ACMGenericCodec* codecs_[ACMCodecDB::kMaxNumCodecs];
ACMGenericCodec* slave_codecs_[ACMCodecDB::kMaxNumCodecs];
int16_t mirror_codec_idx_[ACMCodecDB::kMaxNumCodecs];
bool stereo_receive_[ACMCodecDB::kMaxNumCodecs];
bool stereo_receive_registered_;
bool stereo_send_;
int prev_received_channel_;
int expected_channels_;
int32_t current_send_codec_idx_;
int current_receive_codec_idx_;
bool send_codec_registered_;
ACMResampler input_resampler_;
ACMResampler output_resampler_;
ACMNetEQ neteq_;
CriticalSectionWrapper* acm_crit_sect_;
ACMVADCallback* vad_callback_;
uint8_t last_recv_audio_codec_pltype_;
// RED/FEC.
bool is_first_red_;
bool fec_enabled_;
// TODO(turajs): |red_buffer_| is allocated in constructor, why having them
// as pointers and not an array. If concerned about the memory, then make a
// set-up function to allocate them only when they are going to be used, i.e.
// FEC or Dual-streaming is enabled.
uint8_t* red_buffer_;
// TODO(turajs): we actually don't need |fragmentation_| as a member variable.
// It is sufficient to keep the length & payload type of previous payload in
// member variables.
RTPFragmentationHeader fragmentation_;
uint32_t last_fec_timestamp_;
// If no RED is registered as receive codec this
// will have an invalid value.
uint8_t receive_red_pltype_;
// This is to keep track of CN instances where we can send DTMFs.
uint8_t previous_pltype_;
// This keeps track of payload types associated with codecs_[].
// We define it as signed variable and initialize with -1 to indicate
// unused elements.
int16_t registered_pltypes_[ACMCodecDB::kMaxNumCodecs];
// Used when payloads are pushed into ACM without any RTP info
// One example is when pre-encoded bit-stream is pushed from
// a file.
WebRtcRTPHeader* dummy_rtp_header_;
uint16_t recv_pl_frame_size_smpls_;
bool receiver_initialized_;
ACMDTMFDetection* dtmf_detector_;
AudioCodingFeedback* dtmf_callback_;
int16_t last_detected_tone_;
CriticalSectionWrapper* callback_crit_sect_;
AudioFrame audio_frame_;
AudioFrame preprocess_frame_;
CodecInst secondary_send_codec_inst_;
scoped_ptr<ACMGenericCodec> secondary_encoder_;
// Initial delay.
int initial_delay_ms_;
int num_packets_accumulated_;
int num_bytes_accumulated_;
int accumulated_audio_ms_;
int first_payload_received_;
uint32_t last_incoming_send_timestamp_;
bool track_neteq_buffer_;
uint32_t playout_ts_;
// AV-sync is enabled. In AV-sync mode, sync packet pushed during long packet
// losses.
bool av_sync_;
// Latest send timestamp difference of two consecutive packets.
uint32_t last_timestamp_diff_;
uint16_t last_sequence_number_;
uint32_t last_ssrc_;
bool last_packet_was_sync_;
int64_t last_receive_timestamp_;
Clock* clock_;
scoped_ptr<acm2::Nack> nack_;
bool nack_enabled_;
acm2::CallStatistics call_stats_;
};
} // namespace acm1
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_AUDIO_CODING_MODULE_IMPL_H_