From 3a5825909d24ec39112a8c882a8060ae745929a7 Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Tue, 13 May 2014 08:08:56 +0000 Subject: [PATCH] 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 --- .../audio_coding/main/source/Android.mk | 67 - .../modules/audio_coding/main/source/OWNERS | 5 - .../audio_coding/main/source/acm_amr.cc | 430 --- .../audio_coding/main/source/acm_amr.h | 87 - .../audio_coding/main/source/acm_amrwb.cc | 436 --- .../audio_coding/main/source/acm_amrwb.h | 90 - .../audio_coding/main/source/acm_celt.cc | 339 -- .../audio_coding/main/source/acm_celt.h | 79 - .../audio_coding/main/source/acm_cng.cc | 150 - .../audio_coding/main/source/acm_cng.h | 73 - .../main/source/acm_codec_database.cc | 956 ------ .../main/source/acm_codec_database.h | 336 -- .../main/source/acm_dtmf_detection.cc | 42 - .../main/source/acm_dtmf_detection.h | 42 - .../main/source/acm_dtmf_playout.cc | 171 - .../main/source/acm_dtmf_playout.h | 62 - .../audio_coding/main/source/acm_g722.cc | 358 -- .../audio_coding/main/source/acm_g722.h | 84 - .../audio_coding/main/source/acm_g7221.cc | 500 --- .../audio_coding/main/source/acm_g7221.h | 86 - .../audio_coding/main/source/acm_g7221c.cc | 510 --- .../audio_coding/main/source/acm_g7221c.h | 94 - .../audio_coding/main/source/acm_g729.cc | 366 -- .../audio_coding/main/source/acm_g729.h | 76 - .../audio_coding/main/source/acm_g7291.cc | 349 -- .../audio_coding/main/source/acm_g7291.h | 72 - .../main/source/acm_generic_codec.cc | 1263 ------- .../main/source/acm_generic_codec.h | 1224 ------- .../audio_coding/main/source/acm_gsmfr.cc | 267 -- .../audio_coding/main/source/acm_gsmfr.h | 71 - .../audio_coding/main/source/acm_ilbc.cc | 259 -- .../audio_coding/main/source/acm_ilbc.h | 71 - .../audio_coding/main/source/acm_isac.cc | 903 ----- .../audio_coding/main/source/acm_isac.h | 138 - .../main/source/acm_isac_macros.h | 77 - .../audio_coding/main/source/acm_neteq.cc | 1151 ------- .../audio_coding/main/source/acm_neteq.h | 399 --- .../main/source/acm_neteq_unittest.cc | 153 - .../audio_coding/main/source/acm_opus.cc | 319 -- .../audio_coding/main/source/acm_opus.h | 78 - .../audio_coding/main/source/acm_pcm16b.cc | 251 -- .../audio_coding/main/source/acm_pcm16b.h | 67 - .../audio_coding/main/source/acm_pcma.cc | 134 - .../audio_coding/main/source/acm_pcma.h | 65 - .../audio_coding/main/source/acm_pcmu.cc | 136 - .../audio_coding/main/source/acm_pcmu.h | 65 - .../audio_coding/main/source/acm_red.cc | 108 - .../audio_coding/main/source/acm_red.h | 62 - .../audio_coding/main/source/acm_resampler.cc | 63 - .../audio_coding/main/source/acm_resampler.h | 38 - .../audio_coding/main/source/acm_speex.cc | 471 --- .../audio_coding/main/source/acm_speex.h | 86 - .../main/source/audio_coding_module.gypi | 153 - .../main/source/audio_coding_module_impl.cc | 3039 ----------------- .../main/source/audio_coding_module_impl.h | 453 --- 55 files changed, 17424 deletions(-) delete mode 100644 webrtc/modules/audio_coding/main/source/Android.mk delete mode 100644 webrtc/modules/audio_coding/main/source/OWNERS delete mode 100644 webrtc/modules/audio_coding/main/source/acm_amr.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_amr.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_amrwb.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_amrwb.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_celt.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_celt.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_cng.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_cng.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_codec_database.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_codec_database.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_dtmf_detection.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_dtmf_detection.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_dtmf_playout.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_dtmf_playout.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_g722.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_g722.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_g7221.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_g7221.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_g7221c.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_g7221c.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_g729.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_g729.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_g7291.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_g7291.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_generic_codec.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_generic_codec.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_gsmfr.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_gsmfr.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_ilbc.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_ilbc.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_isac.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_isac.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_isac_macros.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_neteq.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_neteq.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_neteq_unittest.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_opus.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_opus.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_pcm16b.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_pcm16b.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_pcma.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_pcma.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_pcmu.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_pcmu.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_red.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_red.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_resampler.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_resampler.h delete mode 100644 webrtc/modules/audio_coding/main/source/acm_speex.cc delete mode 100644 webrtc/modules/audio_coding/main/source/acm_speex.h delete mode 100644 webrtc/modules/audio_coding/main/source/audio_coding_module.gypi delete mode 100644 webrtc/modules/audio_coding/main/source/audio_coding_module_impl.cc delete mode 100644 webrtc/modules/audio_coding/main/source/audio_coding_module_impl.h diff --git a/webrtc/modules/audio_coding/main/source/Android.mk b/webrtc/modules/audio_coding/main/source/Android.mk deleted file mode 100644 index 90214a9c4..000000000 --- a/webrtc/modules/audio_coding/main/source/Android.mk +++ /dev/null @@ -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) diff --git a/webrtc/modules/audio_coding/main/source/OWNERS b/webrtc/modules/audio_coding/main/source/OWNERS deleted file mode 100644 index 3ee6b4bf5..000000000 --- a/webrtc/modules/audio_coding/main/source/OWNERS +++ /dev/null @@ -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=* diff --git a/webrtc/modules/audio_coding/main/source/acm_amr.cc b/webrtc/modules/audio_coding/main/source/acm_amr.cc deleted file mode 100644 index d39860778..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_amr.cc +++ /dev/null @@ -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(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 - diff --git a/webrtc/modules/audio_coding/main/source/acm_amr.h b/webrtc/modules/audio_coding/main/source/acm_amr.h deleted file mode 100644 index 19c657246..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_amr.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/acm_amrwb.cc b/webrtc/modules/audio_coding/main/source/acm_amrwb.cc deleted file mode 100644 index 8b1b58d03..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_amrwb.cc +++ /dev/null @@ -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(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 diff --git a/webrtc/modules/audio_coding/main/source/acm_amrwb.h b/webrtc/modules/audio_coding/main/source/acm_amrwb.h deleted file mode 100644 index 25934187e..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_amrwb.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/acm_celt.cc b/webrtc/modules/audio_coding/main/source/acm_celt.cc deleted file mode 100644 index 3b838143d..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_celt.cc +++ /dev/null @@ -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(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 diff --git a/webrtc/modules/audio_coding/main/source/acm_celt.h b/webrtc/modules/audio_coding/main/source/acm_celt.h deleted file mode 100644 index 4a4610e0d..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_celt.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/acm_cng.cc b/webrtc/modules/audio_coding/main/source/acm_cng.cc deleted file mode 100644 index 6f3a5057e..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_cng.cc +++ /dev/null @@ -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(ptr_inst)); - } - return; -} - -int16_t ACMCNG::EnableDTX() { return -1; } -int16_t ACMCNG::DisableDTX() { return -1; } - -} // namespace acm1 - -} // namespace webrtc diff --git a/webrtc/modules/audio_coding/main/source/acm_cng.h b/webrtc/modules/audio_coding/main/source/acm_cng.h deleted file mode 100644 index 728312d55..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_cng.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/acm_codec_database.cc b/webrtc/modules/audio_coding/main/source/acm_codec_database.cc deleted file mode 100644 index 138effd6a..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_codec_database.cc +++ /dev/null @@ -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 diff --git a/webrtc/modules/audio_coding/main/source/acm_codec_database.h b/webrtc/modules/audio_coding/main/source/acm_codec_database.h deleted file mode 100644 index 7a7054dd1..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_codec_database.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/acm_dtmf_detection.cc b/webrtc/modules/audio_coding/main/source/acm_dtmf_detection.cc deleted file mode 100644 index edb629876..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_dtmf_detection.cc +++ /dev/null @@ -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 diff --git a/webrtc/modules/audio_coding/main/source/acm_dtmf_detection.h b/webrtc/modules/audio_coding/main/source/acm_dtmf_detection.h deleted file mode 100644 index 74553107a..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_dtmf_detection.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/acm_dtmf_playout.cc b/webrtc/modules/audio_coding/main/source/acm_dtmf_playout.cc deleted file mode 100644 index 32195e6fe..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_dtmf_playout.cc +++ /dev/null @@ -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 diff --git a/webrtc/modules/audio_coding/main/source/acm_dtmf_playout.h b/webrtc/modules/audio_coding/main/source/acm_dtmf_playout.h deleted file mode 100644 index 46175f59e..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_dtmf_playout.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/acm_g722.cc b/webrtc/modules/audio_coding/main/source/acm_g722.cc deleted file mode 100644 index 1c19109b6..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_g722.cc +++ /dev/null @@ -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(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 diff --git a/webrtc/modules/audio_coding/main/source/acm_g722.h b/webrtc/modules/audio_coding/main/source/acm_g722.h deleted file mode 100644 index cf7ebe1e2..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_g722.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/acm_g7221.cc b/webrtc/modules/audio_coding/main/source/acm_g7221.cc deleted file mode 100644 index ed172fd3e..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_g7221.cc +++ /dev/null @@ -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 diff --git a/webrtc/modules/audio_coding/main/source/acm_g7221.h b/webrtc/modules/audio_coding/main/source/acm_g7221.h deleted file mode 100644 index 8ea66742c..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_g7221.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/acm_g7221c.cc b/webrtc/modules/audio_coding/main/source/acm_g7221c.cc deleted file mode 100644 index 96caba0a0..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_g7221c.cc +++ /dev/null @@ -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 diff --git a/webrtc/modules/audio_coding/main/source/acm_g7221c.h b/webrtc/modules/audio_coding/main/source/acm_g7221c.h deleted file mode 100644 index d8875aa2f..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_g7221c.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/acm_g729.cc b/webrtc/modules/audio_coding/main/source/acm_g729.cc deleted file mode 100644 index 406bb61e4..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_g729.cc +++ /dev/null @@ -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 diff --git a/webrtc/modules/audio_coding/main/source/acm_g729.h b/webrtc/modules/audio_coding/main/source/acm_g729.h deleted file mode 100644 index 5cfff63b6..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_g729.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/acm_g7291.cc b/webrtc/modules/audio_coding/main/source/acm_g7291.cc deleted file mode 100644 index 0da6c99d2..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_g7291.cc +++ /dev/null @@ -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 diff --git a/webrtc/modules/audio_coding/main/source/acm_g7291.h b/webrtc/modules/audio_coding/main/source/acm_g7291.h deleted file mode 100644 index bac7faf83..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_g7291.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/acm_generic_codec.cc b/webrtc/modules/audio_coding/main/source/acm_generic_codec.cc deleted file mode 100644 index 4e53b873a..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_generic_codec.cc +++ /dev/null @@ -1,1263 +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_generic_codec.h" - -#include -#include - -#include "webrtc/common_audio/vad/include/webrtc_vad.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/system_wrappers/interface/trace.h" - -namespace webrtc { - -namespace acm1 { - -// Enum for CNG -enum { - kMaxPLCParamsCNG = WEBRTC_CNG_MAX_LPC_ORDER, - kNewCNGNumPLCParams = 8 -}; - -// Interval for sending new CNG parameters (SID frames) is 100 msec. -enum { - kCngSidIntervalMsec = 100 -}; - -// We set some of the variables to invalid values as a check point -// if a proper initialization has happened. Another approach is -// to initialize to a default codec that we are sure is always included. -ACMGenericCodec::ACMGenericCodec() - : in_audio_ix_write_(0), - in_audio_ix_read_(0), - in_timestamp_ix_write_(0), - in_audio_(NULL), - in_timestamp_(NULL), - frame_len_smpl_(-1), // invalid value - num_channels_(1), - codec_id_(-1), // invalid value - num_missed_samples_(0), - encoder_exist_(false), - decoder_exist_(false), - encoder_initialized_(false), - decoder_initialized_(false), - registered_in_neteq_(false), - has_internal_dtx_(false), - ptr_vad_inst_(NULL), - vad_enabled_(false), - vad_mode_(VADNormal), - dtx_enabled_(false), - ptr_dtx_inst_(NULL), - num_lpc_params_(kNewCNGNumPLCParams), - sent_cn_previous_(false), - is_master_(true), - prev_frame_cng_(0), - neteq_decode_lock_(NULL), - codec_wrapper_lock_(*RWLockWrapper::CreateRWLock()), - last_encoded_timestamp_(0), - last_timestamp_(0xD87F3F9F), - is_audio_buff_fresh_(true), - unique_id_(0) { - // Initialize VAD vector. - for (int i = 0; i < MAX_FRAME_SIZE_10MSEC; i++) { - vad_label_[i] = 0; - } - // Nullify memory for encoder and decoder, and set payload type to an - // invalid value. - memset(&encoder_params_, 0, sizeof(WebRtcACMCodecParams)); - encoder_params_.codec_inst.pltype = -1; - memset(&decoder_params_, 0, sizeof(WebRtcACMCodecParams)); - decoder_params_.codec_inst.pltype = -1; -} - -ACMGenericCodec::~ACMGenericCodec() { - // Check all the members which are pointers, and if they are not NULL - // delete/free them. - if (ptr_vad_inst_ != NULL) { - WebRtcVad_Free(ptr_vad_inst_); - ptr_vad_inst_ = NULL; - } - if (in_audio_ != NULL) { - delete[] in_audio_; - in_audio_ = NULL; - } - if (in_timestamp_ != NULL) { - delete[] in_timestamp_; - in_timestamp_ = NULL; - } - if (ptr_dtx_inst_ != NULL) { - WebRtcCng_FreeEnc(ptr_dtx_inst_); - ptr_dtx_inst_ = NULL; - } - delete &codec_wrapper_lock_; -} - -int32_t ACMGenericCodec::Add10MsData(const uint32_t timestamp, - const int16_t* data, - const uint16_t length_smpl, - const uint8_t audio_channel) { - WriteLockScoped wl(codec_wrapper_lock_); - return Add10MsDataSafe(timestamp, data, length_smpl, audio_channel); -} - -int32_t ACMGenericCodec::Add10MsDataSafe(const uint32_t timestamp, - const int16_t* data, - const uint16_t length_smpl, - const uint8_t audio_channel) { - // The codec expects to get data in correct sampling rate. Get the sampling - // frequency of the codec. - uint16_t plfreq_hz; - if (EncoderSampFreq(plfreq_hz) < 0) { - return -1; - } - - // Sanity check to make sure the length of the input corresponds to 10 ms. - if ((plfreq_hz / 100) != length_smpl) { - // This is not 10 ms of audio, given the sampling frequency of the codec. - return -1; - } - - if (last_timestamp_ == timestamp) { - // Same timestamp as the last time, overwrite. - if ((in_audio_ix_write_ >= length_smpl * audio_channel) && - (in_timestamp_ix_write_ > 0)) { - in_audio_ix_write_ -= length_smpl * audio_channel; - in_timestamp_ix_write_--; - WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, unique_id_, - "Adding 10ms with previous timestamp, overwriting the " - "previous 10ms"); - } else { - WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, unique_id_, - "Adding 10ms with previous timestamp, this will sound bad"); - } - } - - last_timestamp_ = timestamp; - - // If the data exceeds the buffer size, we throw away the oldest data and - // add the newly received 10 msec at the end. - if ((in_audio_ix_write_ + length_smpl * audio_channel) > - AUDIO_BUFFER_SIZE_W16) { - // Get the number of samples to be overwritten. - int16_t missed_samples = in_audio_ix_write_ + length_smpl * audio_channel - - AUDIO_BUFFER_SIZE_W16; - - // Move the data (overwrite the old data). - memmove(in_audio_, in_audio_ + missed_samples, - (AUDIO_BUFFER_SIZE_W16 - length_smpl * audio_channel) * - sizeof(int16_t)); - - // Copy the new data. - memcpy(in_audio_ + (AUDIO_BUFFER_SIZE_W16 - length_smpl * audio_channel), - data, length_smpl * audio_channel * sizeof(int16_t)); - - // Get the number of 10 ms blocks which are overwritten. - int16_t missed_10ms_blocks =static_cast( - (missed_samples / audio_channel * 100) / plfreq_hz); - - // Move the timestamps. - memmove(in_timestamp_, in_timestamp_ + missed_10ms_blocks, - (in_timestamp_ix_write_ - missed_10ms_blocks) * sizeof(uint32_t)); - in_timestamp_ix_write_ -= missed_10ms_blocks; - assert(in_timestamp_ix_write_ >= 0); - in_timestamp_[in_timestamp_ix_write_] = timestamp; - in_timestamp_ix_write_++; - - // Buffer is full. - in_audio_ix_write_ = AUDIO_BUFFER_SIZE_W16; - IncreaseNoMissedSamples(missed_samples); - is_audio_buff_fresh_ = false; - return -missed_samples; - } - - // Store the input data in our data buffer. - memcpy(in_audio_ + in_audio_ix_write_, data, - length_smpl * audio_channel * sizeof(int16_t)); - in_audio_ix_write_ += length_smpl * audio_channel; - - assert(in_timestamp_ix_write_ < TIMESTAMP_BUFFER_SIZE_W32); - assert(in_timestamp_ix_write_ >= 0); - - in_timestamp_[in_timestamp_ix_write_] = timestamp; - in_timestamp_ix_write_++; - is_audio_buff_fresh_ = false; - return 0; -} - -bool ACMGenericCodec::HasFrameToEncode() const { - ReadLockScoped lockCodec(codec_wrapper_lock_); - if (in_audio_ix_write_ < frame_len_smpl_ * num_channels_) - return false; - return true; -} - -int16_t ACMGenericCodec::Encode(uint8_t* bitstream, - int16_t* bitstream_len_byte, - uint32_t* timestamp, - WebRtcACMEncodingType* encoding_type) { - if (!HasFrameToEncode()) { - // There is not enough audio - *timestamp = 0; - *bitstream_len_byte = 0; - // Doesn't really matter what this parameter set to - *encoding_type = kNoEncoding; - return 0; - } - WriteLockScoped lockCodec(codec_wrapper_lock_); - ReadLockScoped lockNetEq(*neteq_decode_lock_); - - // Not all codecs accept the whole frame to be pushed into encoder at once. - // Some codecs needs to be feed with a specific number of samples different - // from the frame size. If this is the case, |myBasicCodingBlockSmpl| will - // report a number different from 0, and we will loop over calls to encoder - // further down, until we have encode a complete frame. - const int16_t my_basic_coding_block_smpl = - ACMCodecDB::BasicCodingBlock(codec_id_); - if (my_basic_coding_block_smpl < 0 || !encoder_initialized_ || - !encoder_exist_) { - // This should not happen, but in case it does, report no encoding done. - *timestamp = 0; - *bitstream_len_byte = 0; - *encoding_type = kNoEncoding; - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "EncodeSafe: error, basic coding sample block is negative"); - return -1; - } - // This makes the internal encoder read from the beginning of the buffer. - in_audio_ix_read_ = 0; - *timestamp = in_timestamp_[0]; - - // Process the audio through VAD. The function will set |_vad_labels|. - // If VAD is disabled all entries in |_vad_labels| are set to ONE (active). - int16_t status = 0; - int16_t dtx_processed_samples = 0; - status = ProcessFrameVADDTX(bitstream, bitstream_len_byte, - &dtx_processed_samples); - if (status < 0) { - *timestamp = 0; - *bitstream_len_byte = 0; - *encoding_type = kNoEncoding; - } else { - if (dtx_processed_samples > 0) { - // Dtx have processed some samples, and even if a bit-stream is generated - // we should not do any encoding (normally there won't be enough data). - - // Setting the following makes sure that the move of audio data and - // timestamps done correctly. - in_audio_ix_read_ = dtx_processed_samples; - // This will let the owner of ACMGenericCodec to know that the - // generated bit-stream is DTX to use correct payload type. - uint16_t samp_freq_hz; - EncoderSampFreq(samp_freq_hz); - if (samp_freq_hz == 8000) { - *encoding_type = kPassiveDTXNB; - } else if (samp_freq_hz == 16000) { - *encoding_type = kPassiveDTXWB; - } else if (samp_freq_hz == 32000) { - *encoding_type = kPassiveDTXSWB; - } else if (samp_freq_hz == 48000) { - *encoding_type = kPassiveDTXFB; - } else { - status = -1; - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "EncodeSafe: Wrong sampling frequency for DTX."); - } - - // Transport empty frame if we have an empty bitstream. - if ((*bitstream_len_byte == 0) && - (sent_cn_previous_ || - ((in_audio_ix_write_ - in_audio_ix_read_) <= 0))) { - // Makes sure we transmit an empty frame. - *bitstream_len_byte = 1; - *encoding_type = kNoEncoding; - } - sent_cn_previous_ = true; - } else { - // We should encode the audio frame. Either VAD and/or DTX is off, or the - // audio was considered "active". - - sent_cn_previous_ = false; - if (my_basic_coding_block_smpl == 0) { - // This codec can handle all allowed frame sizes as basic coding block. - status = InternalEncode(bitstream, bitstream_len_byte); - if (status < 0) { - // TODO(tlegrand): Maybe reseting the encoder to be fresh for the next - // frame. - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, - unique_id_, "EncodeSafe: error in internal_encode"); - *bitstream_len_byte = 0; - *encoding_type = kNoEncoding; - } - } else { - // A basic-coding-block for this codec is defined so we loop over the - // audio with the steps of the basic-coding-block. - int16_t tmp_bitstream_len_byte; - - // Reset the variables which will be incremented in the loop. - *bitstream_len_byte = 0; - do { - status = InternalEncode(&bitstream[*bitstream_len_byte], - &tmp_bitstream_len_byte); - *bitstream_len_byte += tmp_bitstream_len_byte; - - // Guard Against errors and too large payloads. - if ((status < 0) || (*bitstream_len_byte > MAX_PAYLOAD_SIZE_BYTE)) { - // Error has happened, and even if we are in the middle of a full - // frame we have to exit. Before exiting, whatever bits are in the - // buffer are probably corrupted, so we ignore them. - *bitstream_len_byte = 0; - *encoding_type = kNoEncoding; - // We might have come here because of the second condition. - status = -1; - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, - unique_id_, "EncodeSafe: error in InternalEncode"); - // break from the loop - break; - } - } while (in_audio_ix_read_ < frame_len_smpl_ * num_channels_); - } - if (status >= 0) { - *encoding_type = (vad_label_[0] == 1) ? kActiveNormalEncoded : - kPassiveNormalEncoded; - // Transport empty frame if we have an empty bitstream. - if ((*bitstream_len_byte == 0) && - ((in_audio_ix_write_ - in_audio_ix_read_) <= 0)) { - // Makes sure we transmit an empty frame. - *bitstream_len_byte = 1; - *encoding_type = kNoEncoding; - } - } - } - } - - // Move the timestamp buffer according to the number of 10 ms blocks - // which are read. - uint16_t samp_freq_hz; - EncoderSampFreq(samp_freq_hz); - int16_t num_10ms_blocks = static_cast( - (in_audio_ix_read_ / num_channels_ * 100) / samp_freq_hz); - if (in_timestamp_ix_write_ > num_10ms_blocks) { - memmove(in_timestamp_, in_timestamp_ + num_10ms_blocks, - (in_timestamp_ix_write_ - num_10ms_blocks) * sizeof(int32_t)); - } - in_timestamp_ix_write_ -= num_10ms_blocks; - assert(in_timestamp_ix_write_ >= 0); - // Remove encoded audio and move next audio to be encoded to the beginning - // of the buffer. Accordingly, adjust the read and write indices. - if (in_audio_ix_read_ < in_audio_ix_write_) { - memmove(in_audio_, &in_audio_[in_audio_ix_read_], - (in_audio_ix_write_ - in_audio_ix_read_) * sizeof(int16_t)); - } - in_audio_ix_write_ -= in_audio_ix_read_; - assert(in_timestamp_ix_write_ >= 0); - in_audio_ix_read_ = 0; - last_encoded_timestamp_ = *timestamp; - return (status < 0) ? (-1) : (*bitstream_len_byte); -} - -int16_t ACMGenericCodec::Decode(uint8_t* bitstream, - int16_t bitstream_len_byte, - int16_t* audio, - int16_t* audio_samples, - int8_t* speech_type) { - WriteLockScoped wl(codec_wrapper_lock_); - return DecodeSafe(bitstream, bitstream_len_byte, audio, audio_samples, - speech_type); -} - -bool ACMGenericCodec::EncoderInitialized() { - ReadLockScoped rl(codec_wrapper_lock_); - return encoder_initialized_; -} - -bool ACMGenericCodec::DecoderInitialized() { - ReadLockScoped rl(codec_wrapper_lock_); - return decoder_initialized_; -} - -int32_t ACMGenericCodec::RegisterInNetEq(ACMNetEQ* neteq, - const CodecInst& codec_inst) { - WebRtcNetEQ_CodecDef codec_def; - WriteLockScoped wl(codec_wrapper_lock_); - - if (CodecDef(codec_def, codec_inst) < 0) { - // Failed to register the decoder. - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "RegisterInNetEq: error, failed to register"); - registered_in_neteq_ = false; - return -1; - } else { - if (neteq->AddCodec(&codec_def, is_master_) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "RegisterInNetEq: error, failed to add codec"); - registered_in_neteq_ = false; - return -1; - } - // Succeeded registering the decoder. - registered_in_neteq_ = true; - return 0; - } -} - -int16_t ACMGenericCodec::EncoderParams(WebRtcACMCodecParams* enc_params) { - ReadLockScoped rl(codec_wrapper_lock_); - return EncoderParamsSafe(enc_params); -} - -int16_t ACMGenericCodec::EncoderParamsSafe(WebRtcACMCodecParams* enc_params) { - // Codec parameters are valid only if the encoder is initialized. - if (encoder_initialized_) { - int32_t current_rate; - memcpy(enc_params, &encoder_params_, sizeof(WebRtcACMCodecParams)); - current_rate = enc_params->codec_inst.rate; - CurrentRate(current_rate); - enc_params->codec_inst.rate = current_rate; - return 0; - } else { - enc_params->codec_inst.plname[0] = '\0'; - enc_params->codec_inst.pltype = -1; - enc_params->codec_inst.pacsize = 0; - enc_params->codec_inst.rate = 0; - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "EncoderParamsSafe: error, encoder not initialized"); - return -1; - } -} - -bool ACMGenericCodec::DecoderParams(WebRtcACMCodecParams* dec_params, - const uint8_t payload_type) { - ReadLockScoped rl(codec_wrapper_lock_); - return DecoderParamsSafe(dec_params, payload_type); -} - -bool ACMGenericCodec::DecoderParamsSafe(WebRtcACMCodecParams* dec_params, - const uint8_t payload_type) { - // Decoder parameters are valid only if decoder is initialized. - if (decoder_initialized_) { - if (payload_type == decoder_params_.codec_inst.pltype) { - memcpy(dec_params, &decoder_params_, sizeof(WebRtcACMCodecParams)); - return true; - } - } - - dec_params->codec_inst.plname[0] = '\0'; - dec_params->codec_inst.pltype = -1; - dec_params->codec_inst.pacsize = 0; - dec_params->codec_inst.rate = 0; - return false; -} - -int16_t ACMGenericCodec::ResetEncoder() { - WriteLockScoped lockCodec(codec_wrapper_lock_); - ReadLockScoped lockNetEq(*neteq_decode_lock_); - return ResetEncoderSafe(); -} - -int16_t ACMGenericCodec::ResetEncoderSafe() { - if (!encoder_exist_ || !encoder_initialized_) { - // We don't reset if encoder doesn't exists or isn't initialized yet. - return 0; - } - - in_audio_ix_write_ = 0; - in_audio_ix_read_ = 0; - in_timestamp_ix_write_ = 0; - num_missed_samples_ = 0; - is_audio_buff_fresh_ = true; - memset(in_audio_, 0, AUDIO_BUFFER_SIZE_W16 * sizeof(int16_t)); - memset(in_timestamp_, 0, TIMESTAMP_BUFFER_SIZE_W32 * sizeof(int32_t)); - - // Store DTX/VAD parameters. - bool enable_vad = vad_enabled_; - bool enable_dtx = dtx_enabled_; - ACMVADMode mode = vad_mode_; - - // Reset the encoder. - if (InternalResetEncoder() < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "ResetEncoderSafe: error in reset encoder"); - return -1; - } - - // Disable DTX & VAD to delete the states and have a fresh start. - DisableDTX(); - DisableVAD(); - - // Set DTX/VAD. - int status = SetVADSafe(&enable_dtx, &enable_vad, &mode); - dtx_enabled_ = enable_dtx; - vad_enabled_ = enable_vad; - vad_mode_ = mode; - return status; -} - -int16_t ACMGenericCodec::InternalResetEncoder() { - // Call the codecs internal encoder initialization/reset function. - return InternalInitEncoder(&encoder_params_); -} - -int16_t ACMGenericCodec::InitEncoder(WebRtcACMCodecParams* codec_params, - bool force_initialization) { - WriteLockScoped lockCodec(codec_wrapper_lock_); - ReadLockScoped lockNetEq(*neteq_decode_lock_); - return InitEncoderSafe(codec_params, force_initialization); -} - -int16_t ACMGenericCodec::InitEncoderSafe(WebRtcACMCodecParams* codec_params, - bool force_initialization) { - // Check if we got a valid set of parameters. - int mirrorID; - int codec_number = ACMCodecDB::CodecNumber(&(codec_params->codec_inst), - &mirrorID); - if (codec_number < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "InitEncoderSafe: error, codec number negative"); - return -1; - } - // Check if the parameters are for this codec. - if ((codec_id_ >= 0) && (codec_id_ != codec_number) && - (codec_id_ != mirrorID)) { - // The current codec is not the same as the one given by codec_params. - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "InitEncoderSafe: current codec is not the same as the one " - "given by codec_params"); - return -1; - } - - if (!CanChangeEncodingParam(codec_params->codec_inst)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "InitEncoderSafe: cannot change encoding parameters"); - return -1; - } - - if (encoder_initialized_ && !force_initialization) { - // The encoder is already initialized, and we don't want to force - // initialization. - return 0; - } - int16_t status; - if (!encoder_exist_) { - // New encoder, start with creating. - encoder_initialized_ = false; - status = CreateEncoder(); - if (status < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "InitEncoderSafe: cannot create encoder"); - return -1; - } else { - encoder_exist_ = true; - } - } - frame_len_smpl_ = (codec_params->codec_inst).pacsize; - num_channels_ = codec_params->codec_inst.channels; - status = InternalInitEncoder(codec_params); - if (status < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "InitEncoderSafe: error in init encoder"); - encoder_initialized_ = false; - return -1; - } else { - // Store encoder parameters. - memcpy(&encoder_params_, codec_params, sizeof(WebRtcACMCodecParams)); - encoder_initialized_ = true; - if (in_audio_ == NULL) { - in_audio_ = new int16_t[AUDIO_BUFFER_SIZE_W16]; - if (in_audio_ == NULL) { - return -1; - } - } - if (in_timestamp_ == NULL) { - in_timestamp_ = new uint32_t[TIMESTAMP_BUFFER_SIZE_W32]; - if (in_timestamp_ == NULL) { - return -1; - } - } - // Fresh start for audio buffer. - is_audio_buff_fresh_ = true; - memset(in_audio_, 0, AUDIO_BUFFER_SIZE_W16 * sizeof(int16_t)); - memset(in_timestamp_, 0, sizeof(uint32_t) * TIMESTAMP_BUFFER_SIZE_W32); - in_audio_ix_write_ = 0; - in_audio_ix_read_ = 0; - in_timestamp_ix_write_ = 0; - } - status = SetVADSafe(&codec_params->enable_dtx, &codec_params->enable_vad, - &codec_params->vad_mode); - return status; -} - -// TODO(tlegrand): Remove the function CanChangeEncodingParam. Returns true -// for all codecs. -bool ACMGenericCodec::CanChangeEncodingParam(CodecInst& /*codec_inst*/) { - return true; -} - -void ACMGenericCodec::CurrentRate(int32_t& /* rate_bps */) { - return; -} - -int16_t ACMGenericCodec::InitDecoder(WebRtcACMCodecParams* codec_params, - bool force_initialization) { - WriteLockScoped lockCodc(codec_wrapper_lock_); - WriteLockScoped lockNetEq(*neteq_decode_lock_); - return InitDecoderSafe(codec_params, force_initialization); -} - -int16_t ACMGenericCodec::InitDecoderSafe(WebRtcACMCodecParams* codec_params, - bool force_initialization) { - int mirror_id; - // Check if we got a valid set of parameters. - int codec_number = ACMCodecDB::ReceiverCodecNumber(&codec_params->codec_inst, - &mirror_id); - if (codec_number < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "InitDecoderSafe: error, invalid codec number"); - return -1; - } - // Check if the parameters are for this codec. - if ((codec_id_ >= 0) && (codec_id_ != codec_number) && - (codec_id_ != mirror_id)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "InitDecoderSafe: current codec is not the same as the one " - "given by codec_params"); - // The current codec is not the same as the one given by codec_params. - return -1; - } - - if (decoder_initialized_ && !force_initialization) { - // The decoder is already initialized, and we don't want to force - // initialization. - return 0; - } - - int16_t status; - if (!decoder_exist_) { - // New decoder, start with creating. - decoder_initialized_ = false; - status = CreateDecoder(); - if (status < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "InitDecoderSafe: cannot create decoder"); - return -1; - } else { - decoder_exist_ = true; - } - } - - status = InternalInitDecoder(codec_params); - if (status < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "InitDecoderSafe: cannot init decoder"); - decoder_initialized_ = false; - return -1; - } else { - // Store decoder parameters. - SaveDecoderParamSafe(codec_params); - decoder_initialized_ = true; - } - return 0; -} - -int16_t ACMGenericCodec::ResetDecoder(int16_t payload_type) { - WriteLockScoped lockCodec(codec_wrapper_lock_); - WriteLockScoped lockNetEq(*neteq_decode_lock_); - return ResetDecoderSafe(payload_type); -} - -int16_t ACMGenericCodec::ResetDecoderSafe(int16_t payload_type) { - WebRtcACMCodecParams decoder_params; - if (!decoder_exist_ || !decoder_initialized_) { - return 0; - } - // Initialization of the decoder should work for all the codec. For codecs - // that needs to keep some states an overloading implementation of - // |DecoderParamsSafe| exists. - DecoderParamsSafe(&decoder_params, static_cast(payload_type)); - return InternalInitDecoder(&decoder_params); -} - -void ACMGenericCodec::ResetNoMissedSamples() { - WriteLockScoped cs(codec_wrapper_lock_); - num_missed_samples_ = 0; -} - -void ACMGenericCodec::IncreaseNoMissedSamples(const int16_t num_samples) { - num_missed_samples_ += num_samples; -} - -// Get the number of missed samples, this can be public. -uint32_t ACMGenericCodec::NoMissedSamples() const { - ReadLockScoped cs(codec_wrapper_lock_); - return num_missed_samples_; -} - -void ACMGenericCodec::DestructEncoder() { - WriteLockScoped wl(codec_wrapper_lock_); - - // Disable VAD and delete the instance. - if (ptr_vad_inst_ != NULL) { - WebRtcVad_Free(ptr_vad_inst_); - ptr_vad_inst_ = NULL; - } - vad_enabled_ = false; - vad_mode_ = VADNormal; - - // Disable DTX and delete the instance. - dtx_enabled_ = false; - if (ptr_dtx_inst_ != NULL) { - WebRtcCng_FreeEnc(ptr_dtx_inst_); - ptr_dtx_inst_ = NULL; - } - num_lpc_params_ = kNewCNGNumPLCParams; - - DestructEncoderSafe(); -} - -void ACMGenericCodec::DestructDecoder() { - WriteLockScoped wl(codec_wrapper_lock_); - decoder_params_.codec_inst.pltype = -1; - DestructDecoderSafe(); -} - -int16_t ACMGenericCodec::SetBitRate(const int32_t bitrate_bps) { - WriteLockScoped wl(codec_wrapper_lock_); - return SetBitRateSafe(bitrate_bps); -} - -int16_t ACMGenericCodec::SetBitRateSafe(const int32_t bitrate_bps) { - // If the codec can change the bit-rate this function is overloaded. - // Otherwise the only acceptable value is the one that is in the database. - CodecInst codec_params; - if (ACMCodecDB::Codec(codec_id_, &codec_params) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "SetBitRateSafe: error in ACMCodecDB::Codec"); - return -1; - } - if (codec_params.rate != bitrate_bps) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "SetBitRateSafe: rate value is not acceptable"); - return -1; - } else { - return 0; - } -} - -// iSAC specific functions: -int32_t ACMGenericCodec::GetEstimatedBandwidth() { - WriteLockScoped wl(codec_wrapper_lock_); - return GetEstimatedBandwidthSafe(); -} - -int32_t ACMGenericCodec::GetEstimatedBandwidthSafe() { - // All codecs but iSAC will return -1. - return -1; -} - -int32_t ACMGenericCodec::SetEstimatedBandwidth(int32_t estimated_bandwidth) { - WriteLockScoped wl(codec_wrapper_lock_); - return SetEstimatedBandwidthSafe(estimated_bandwidth); -} - -int32_t ACMGenericCodec::SetEstimatedBandwidthSafe( - int32_t /*estimated_bandwidth*/) { - // All codecs but iSAC will return -1. - return -1; -} -// End of iSAC specific functions. - -int32_t ACMGenericCodec::GetRedPayload(uint8_t* red_payload, - int16_t* payload_bytes) { - WriteLockScoped wl(codec_wrapper_lock_); - return GetRedPayloadSafe(red_payload, payload_bytes); -} - -int32_t ACMGenericCodec::GetRedPayloadSafe(uint8_t* /* red_payload */, - int16_t* /* payload_bytes */) { - return -1; // Do nothing by default. -} - -int16_t ACMGenericCodec::CreateEncoder() { - int16_t status = 0; - if (!encoder_exist_) { - status = InternalCreateEncoder(); - // We just created the codec and obviously it is not initialized. - encoder_initialized_ = false; - } - if (status < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "CreateEncoder: error in internal create encoder"); - encoder_exist_ = false; - } else { - encoder_exist_ = true; - } - return status; -} - -int16_t ACMGenericCodec::CreateDecoder() { - int16_t status = 0; - if (!decoder_exist_) { - status = InternalCreateDecoder(); - // Decoder just created and obviously it is not initialized. - decoder_initialized_ = false; - } - if (status < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "CreateDecoder: error in internal create decoder"); - decoder_exist_ = false; - } else { - decoder_exist_ = true; - } - return status; -} - -void ACMGenericCodec::DestructEncoderInst(void* ptr_inst) { - if (ptr_inst != NULL) { - WriteLockScoped lockCodec(codec_wrapper_lock_); - ReadLockScoped lockNetEq(*neteq_decode_lock_); - InternalDestructEncoderInst(ptr_inst); - } -} - -// Get the current audio buffer including read and write states, and timestamps. -int16_t ACMGenericCodec::AudioBuffer(WebRtcACMAudioBuff& audio_buff) { - ReadLockScoped cs(codec_wrapper_lock_); - memcpy(audio_buff.in_audio, in_audio_, - AUDIO_BUFFER_SIZE_W16 * sizeof(int16_t)); - audio_buff.in_audio_ix_read = in_audio_ix_read_; - audio_buff.in_audio_ix_write = in_audio_ix_write_; - memcpy(audio_buff.in_timestamp, in_timestamp_, - TIMESTAMP_BUFFER_SIZE_W32 * sizeof(uint32_t)); - audio_buff.in_timestamp_ix_write = in_timestamp_ix_write_; - audio_buff.last_timestamp = last_timestamp_; - return 0; -} - -// Set the audio buffer. -int16_t ACMGenericCodec::SetAudioBuffer(WebRtcACMAudioBuff& audio_buff) { - WriteLockScoped cs(codec_wrapper_lock_); - memcpy(in_audio_, audio_buff.in_audio, - AUDIO_BUFFER_SIZE_W16 * sizeof(int16_t)); - in_audio_ix_read_ = audio_buff.in_audio_ix_read; - in_audio_ix_write_ = audio_buff.in_audio_ix_write; - memcpy(in_timestamp_, audio_buff.in_timestamp, - TIMESTAMP_BUFFER_SIZE_W32 * sizeof(uint32_t)); - in_timestamp_ix_write_ = audio_buff.in_timestamp_ix_write; - last_timestamp_ = audio_buff.last_timestamp; - is_audio_buff_fresh_ = false; - return 0; -} - -uint32_t ACMGenericCodec::LastEncodedTimestamp() const { - ReadLockScoped cs(codec_wrapper_lock_); - return last_encoded_timestamp_; -} - -uint32_t ACMGenericCodec::EarliestTimestamp() const { - ReadLockScoped cs(codec_wrapper_lock_); - return in_timestamp_[0]; -} - -int16_t ACMGenericCodec::SetVAD(bool* enable_dtx, bool* enable_vad, - ACMVADMode* mode) { - WriteLockScoped cs(codec_wrapper_lock_); - return SetVADSafe(enable_dtx, enable_vad, mode); -} - -int16_t ACMGenericCodec::SetVADSafe(bool* enable_dtx, bool* enable_vad, - ACMVADMode* mode) { - if (!STR_CASE_CMP(encoder_params_.codec_inst.plname, "OPUS") || - encoder_params_.codec_inst.channels == 2 ) { - // VAD/DTX is not supported for Opus (even if sending mono), or other - // stereo codecs. - DisableDTX(); - DisableVAD(); - *enable_dtx = false; - *enable_vad = false; - return 0; - } - - if (*enable_dtx) { - // Make G729 AnnexB a special case. - if (!STR_CASE_CMP(encoder_params_.codec_inst.plname, "G729") - && !has_internal_dtx_) { - if (ACMGenericCodec::EnableDTX() < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "SetVADSafe: error in enable DTX"); - *enable_dtx = false; - *enable_vad = vad_enabled_; - return -1; - } - } else { - if (EnableDTX() < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "SetVADSafe: error in enable DTX"); - *enable_dtx = false; - *enable_vad = vad_enabled_; - return -1; - } - } - - // If codec does not have internal DTX (normal case) enabling DTX requires - // an active VAD. '*enable_dtx == true' overwrites VAD status. - // If codec has internal DTX, practically we don't need WebRtc VAD, however, - // we let the user to turn it on if they need call-backs on silence. - if (!has_internal_dtx_) { - // DTX is enabled, and VAD will be activated. - *enable_vad = true; - } - } else { - // Make G729 AnnexB a special case. - if (!STR_CASE_CMP(encoder_params_.codec_inst.plname, "G729") - && !has_internal_dtx_) { - ACMGenericCodec::DisableDTX(); - *enable_dtx = false; - } else { - DisableDTX(); - *enable_dtx = false; - } - } - - int16_t status = (*enable_vad) ? EnableVAD(*mode) : DisableVAD(); - if (status < 0) { - // Failed to set VAD, disable DTX. - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "SetVADSafe: error in enable VAD"); - DisableDTX(); - *enable_dtx = false; - *enable_vad = false; - } - return status; -} - -int16_t ACMGenericCodec::EnableDTX() { - if (has_internal_dtx_) { - // We should not be here if we have internal DTX this function should be - // overloaded by the derived class in this case. - return -1; - } - if (!dtx_enabled_) { - if (WebRtcCng_CreateEnc(&ptr_dtx_inst_) < 0) { - ptr_dtx_inst_ = NULL; - return -1; - } - uint16_t freq_hz; - EncoderSampFreq(freq_hz); - if (WebRtcCng_InitEnc(ptr_dtx_inst_, freq_hz, kCngSidIntervalMsec, - num_lpc_params_) < 0) { - // Couldn't initialize, has to return -1, and free the memory. - WebRtcCng_FreeEnc(ptr_dtx_inst_); - ptr_dtx_inst_ = NULL; - return -1; - } - dtx_enabled_ = true; - } - return 0; -} - -int16_t ACMGenericCodec::DisableDTX() { - if (has_internal_dtx_) { - // We should not be here if we have internal DTX this function should be - // overloaded by the derived class in this case. - return -1; - } - if (ptr_dtx_inst_ != NULL) { - WebRtcCng_FreeEnc(ptr_dtx_inst_); - ptr_dtx_inst_ = NULL; - } - dtx_enabled_ = false; - return 0; -} - -int16_t ACMGenericCodec::EnableVAD(ACMVADMode mode) { - if ((mode < VADNormal) || (mode > VADVeryAggr)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "EnableVAD: error in VAD mode range"); - return -1; - } - - if (!vad_enabled_) { - if (WebRtcVad_Create(&ptr_vad_inst_) < 0) { - ptr_vad_inst_ = NULL; - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "EnableVAD: error in create VAD"); - return -1; - } - if (WebRtcVad_Init(ptr_vad_inst_) < 0) { - WebRtcVad_Free(ptr_vad_inst_); - ptr_vad_inst_ = NULL; - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "EnableVAD: error in init VAD"); - return -1; - } - } - - // Set the VAD mode to the given value. - if (WebRtcVad_set_mode(ptr_vad_inst_, mode) < 0) { - // We failed to set the mode and we have to return -1. If we already have a - // working VAD (vad_enabled_ == true) then we leave it to work. Otherwise, - // the following will be executed. - if (!vad_enabled_) { - // We just created the instance but cannot set the mode we have to free - // the memory. - WebRtcVad_Free(ptr_vad_inst_); - ptr_vad_inst_ = NULL; - } - WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, unique_id_, - "EnableVAD: failed to set the VAD mode"); - return -1; - } - vad_mode_ = mode; - vad_enabled_ = true; - return 0; -} - -int16_t ACMGenericCodec::DisableVAD() { - if (ptr_vad_inst_ != NULL) { - WebRtcVad_Free(ptr_vad_inst_); - ptr_vad_inst_ = NULL; - } - vad_enabled_ = false; - return 0; -} - -int32_t ACMGenericCodec::ReplaceInternalDTX(const bool replace_internal_dtx) { - WriteLockScoped cs(codec_wrapper_lock_); - return ReplaceInternalDTXSafe(replace_internal_dtx); -} - -int32_t ACMGenericCodec::ReplaceInternalDTXSafe( - const bool /* replace_internal_dtx */) { - return -1; -} - -int32_t ACMGenericCodec::IsInternalDTXReplaced(bool* internal_dtx_replaced) { - WriteLockScoped cs(codec_wrapper_lock_); - return IsInternalDTXReplacedSafe(internal_dtx_replaced); -} - -int32_t ACMGenericCodec::IsInternalDTXReplacedSafe( - bool* internal_dtx_replaced) { - *internal_dtx_replaced = false; - return 0; -} - -int16_t ACMGenericCodec::ProcessFrameVADDTX(uint8_t* bitstream, - int16_t* bitstream_len_byte, - int16_t* samples_processed) { - if (!vad_enabled_) { - // VAD not enabled, set all |vad_lable_[]| to 1 (speech detected). - for (int n = 0; n < MAX_FRAME_SIZE_10MSEC; n++) { - vad_label_[n] = 1; - } - *samples_processed = 0; - return 0; - } - - uint16_t freq_hz; - EncoderSampFreq(freq_hz); - - // Calculate number of samples in 10 ms blocks, and number ms in one frame. - int16_t samples_in_10ms = static_cast(freq_hz / 100); - int32_t frame_len_ms = static_cast(frame_len_smpl_) * 1000 / freq_hz; - int16_t status; - - // Vector for storing maximum 30 ms of mono audio at 48 kHz. - int16_t audio[1440]; - - // Calculate number of VAD-blocks to process, and number of samples in each - // block. - int num_samples_to_process[2]; - if (frame_len_ms == 40) { - // 20 ms in each VAD block. - num_samples_to_process[0] = num_samples_to_process[1] = 2 * samples_in_10ms; - } else { - // For 10-30 ms framesizes, second VAD block will be size zero ms, - // for 50 and 60 ms first VAD block will be 30 ms. - num_samples_to_process[0] = - (frame_len_ms > 30) ? 3 * samples_in_10ms : frame_len_smpl_; - num_samples_to_process[1] = frame_len_smpl_ - num_samples_to_process[0]; - } - - int offset = 0; - int loops = (num_samples_to_process[1] > 0) ? 2 : 1; - for (int i = 0; i < loops; i++) { - // TODO(turajs): Do we need to care about VAD together with stereo? - // If stereo, calculate mean of the two channels. - if (num_channels_ == 2) { - for (int j = 0; j < num_samples_to_process[i]; j++) { - audio[j] = (in_audio_[(offset + j) * 2] + - in_audio_[(offset + j) * 2 + 1]) / 2; - } - offset = num_samples_to_process[0]; - } else { - // Mono, copy data from in_audio_ to continue work on. - memcpy(audio, in_audio_, sizeof(int16_t) * num_samples_to_process[i]); - } - - // Call VAD. - status = static_cast(WebRtcVad_Process(ptr_vad_inst_, - static_cast(freq_hz), - audio, - num_samples_to_process[i])); - vad_label_[i] = status; - - if (status < 0) { - // This will force that the data be removed from the buffer. - *samples_processed += num_samples_to_process[i]; - return -1; - } - - // If VAD decision non-active, update DTX. NOTE! We only do this if the - // first part of a frame gets the VAD decision "inactive". Otherwise DTX - // might say it is time to transmit SID frame, but we will encode the whole - // frame, because the first part is active. - *samples_processed = 0; - if ((status == 0) && (i == 0) && dtx_enabled_ && !has_internal_dtx_) { - int16_t bitstream_len; - int num_10ms_frames = num_samples_to_process[i] / samples_in_10ms; - *bitstream_len_byte = 0; - for (int n = 0; n < num_10ms_frames; n++) { - // This block is (passive) && (vad enabled). If first CNG after - // speech, force SID by setting last parameter to "1". - status = WebRtcCng_Encode(ptr_dtx_inst_, &audio[n * samples_in_10ms], - samples_in_10ms, bitstream, &bitstream_len, - !prev_frame_cng_); - if (status < 0) { - return -1; - } - - // Update previous frame was CNG. - prev_frame_cng_ = 1; - - *samples_processed += samples_in_10ms * num_channels_; - - // |bitstream_len_byte| will only be > 0 once per 100 ms. - *bitstream_len_byte += bitstream_len; - } - - // Check if all samples got processed by the DTX. - if (*samples_processed != num_samples_to_process[i] * num_channels_) { - // Set to zero since something went wrong. Shouldn't happen. - *samples_processed = 0; - } - } else { - // Update previous frame was not CNG. - prev_frame_cng_ = 0; - } - - if (*samples_processed > 0) { - // The block contains inactive speech, and is processed by DTX. - // Discontinue running VAD. - break; - } - } - - return status; -} - -int16_t ACMGenericCodec::SamplesLeftToEncode() { - ReadLockScoped rl(codec_wrapper_lock_); - return (frame_len_smpl_ <= in_audio_ix_write_) ? 0 : - (frame_len_smpl_ - in_audio_ix_write_); -} - -void ACMGenericCodec::SetUniqueID(const uint32_t id) { - unique_id_ = id; -} - -bool ACMGenericCodec::IsAudioBufferFresh() const { - ReadLockScoped rl(codec_wrapper_lock_); - return is_audio_buff_fresh_; -} - -int16_t ACMGenericCodec::UpdateDecoderSampFreq(int16_t /* codec_id */) { - return 0; -} - -// This function is replaced by codec specific functions for some codecs. -int16_t ACMGenericCodec::EncoderSampFreq(uint16_t& samp_freq_hz) { - int32_t f; - f = ACMCodecDB::CodecFreq(codec_id_); - if (f < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "EncoderSampFreq: codec frequency is negative"); - return -1; - } else { - samp_freq_hz = static_cast(f); - return 0; - } -} - -int32_t ACMGenericCodec::ConfigISACBandwidthEstimator( - const uint8_t /* init_frame_size_msec */, - const uint16_t /* init_rate_bit_per_sec */, - const bool /* enforce_frame_size */) { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, unique_id_, - "The send-codec is not iSAC, failed to config iSAC bandwidth " - "estimator."); - return -1; -} - -int32_t ACMGenericCodec::SetISACMaxRate( - const uint32_t /* max_rate_bit_per_sec */) { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, unique_id_, - "The send-codec is not iSAC, failed to set iSAC max rate."); - return -1; -} - -int32_t ACMGenericCodec::SetISACMaxPayloadSize( - const uint16_t /* max_payload_len_bytes */) { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, unique_id_, - "The send-codec is not iSAC, failed to set iSAC max " - "payload-size."); - return -1; -} - -void ACMGenericCodec::SaveDecoderParam( - const WebRtcACMCodecParams* codec_params) { - WriteLockScoped wl(codec_wrapper_lock_); - SaveDecoderParamSafe(codec_params); -} - -void ACMGenericCodec::SaveDecoderParamSafe( - const WebRtcACMCodecParams* codec_params) { - memcpy(&decoder_params_, codec_params, sizeof(WebRtcACMCodecParams)); -} - -int16_t ACMGenericCodec::UpdateEncoderSampFreq( - uint16_t /* samp_freq_hz */) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "It is asked for a change in smapling frequency while the " - "current send-codec supports only one sampling rate."); - return -1; -} - -void ACMGenericCodec::SetIsMaster(bool is_master) { - WriteLockScoped wl(codec_wrapper_lock_); - is_master_ = is_master; -} - -int16_t ACMGenericCodec::REDPayloadISAC(const int32_t /* isac_rate */, - const int16_t /* isac_bw_estimate */, - uint8_t* /* payload */, - int16_t* /* payload_len_bytes */) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, - "Error: REDPayloadISAC is an iSAC specific function"); - return -1; -} - -bool ACMGenericCodec::IsTrueStereoCodec() { return false; } - -} // namespace acm1 - -} // namespace webrtc diff --git a/webrtc/modules/audio_coding/main/source/acm_generic_codec.h b/webrtc/modules/audio_coding/main/source/acm_generic_codec.h deleted file mode 100644 index c1f9cdc55..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_generic_codec.h +++ /dev/null @@ -1,1224 +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_GENERIC_CODEC_H_ -#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_GENERIC_CODEC_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/neteq/interface/webrtc_neteq.h" -#include "webrtc/system_wrappers/interface/rw_lock_wrapper.h" -#include "webrtc/system_wrappers/interface/trace.h" - -#define MAX_FRAME_SIZE_10MSEC 6 - -// forward declaration -struct WebRtcVadInst; -struct WebRtcCngEncInst; - -namespace webrtc { - -// forward declaration -struct CodecInst; -struct WebRtcACMCodecParams; - -namespace acm1 { - -class ACMNetEQ; - -class ACMGenericCodec { - public: - /////////////////////////////////////////////////////////////////////////// - // Constructor of the class - // - ACMGenericCodec(); - - /////////////////////////////////////////////////////////////////////////// - // Destructor of the class. - // - virtual ~ACMGenericCodec(); - - /////////////////////////////////////////////////////////////////////////// - // ACMGenericCodec* CreateInstance(); - // The function will be used for FEC. It is not implemented yet. - // - virtual ACMGenericCodec* CreateInstance() = 0; - - /////////////////////////////////////////////////////////////////////////// - // int16_t Encode() - // The function is called to perform an encoding of the audio stored in - // audio buffer. An encoding is performed only if enough audio, i.e. equal - // to the frame-size of the codec, exist. The audio frame will be processed - // by VAD and CN/DTX if required. There are few different cases. - // - // A) Neither VAD nor DTX is active; the frame is encoded by the encoder. - // - // B) VAD is enabled but not DTX; in this case the audio is processed by VAD - // and encoded by the encoder. The "*encoding_type" will be either - // "kActiveNormalEncode" or "kPassiveNormalEncode" if frame is active or - // passive, respectively. - // - // C) DTX is enabled; if the codec has internal VAD/DTX we just encode the - // frame by the encoder. Otherwise, the frame is passed through VAD and - // if identified as passive, then it will be processed by CN/DTX. If the - // frame is active it will be encoded by the encoder. - // - // This function acquires the appropriate locks and calls EncodeSafe() for - // the actual processing. - // - // Outputs: - // -bitstream : a buffer where bit-stream will be written to. - // -bitstream_len_byte : contains the length of the bit-stream in - // bytes. - // -timestamp : contains the RTP timestamp, this is the - // sampling time of the first sample encoded - // (measured in number of samples). - // -encoding_type : contains the type of encoding applied on the - // audio samples. The alternatives are - // (c.f. acm_common_types.h) - // -kNoEncoding: - // there was not enough data to encode. or - // some error has happened that we could - // not do encoding. - // -kActiveNormalEncoded: - // the audio frame is active and encoded by - // the given codec. - // -kPassiveNormalEncoded: - // the audio frame is passive but coded with - // the given codec (NO DTX). - // -kPassiveDTXWB: - // The audio frame is passive and used - // wide-band CN to encode. - // -kPassiveDTXNB: - // The audio frame is passive and used - // narrow-band CN to encode. - // - // Return value: - // -1 if error is occurred, otherwise the length of the bit-stream in - // bytes. - // - int16_t Encode(uint8_t* bitstream, - int16_t* bitstream_len_byte, - uint32_t* timestamp, - WebRtcACMEncodingType* encoding_type); - - /////////////////////////////////////////////////////////////////////////// - // int16_t Decode() - // This function is used to decode a given bit-stream, without engaging - // NetEQ. - // - // This function acquires the appropriate locks and calls DecodeSafe() for - // the actual processing. Please note that this is not functional yet. - // - // Inputs: - // -bitstream : a buffer where bit-stream will be read. - // -bitstream_len_byte : the length of the bit-stream in bytes. - // - // Outputs: - // -audio : pointer to a buffer where the audio will written. - // -audio_samples : number of audio samples out of decoding the given - // bit-stream. - // -speech_type : speech type (for future use). - // - // Return value: - // -1 if failed to decode, - // 0 if succeeded. - // - int16_t Decode(uint8_t* bitstream, - int16_t bitstream_len_byte, - int16_t* audio, - int16_t* audio_samples, - int8_t* speech_type); - - /////////////////////////////////////////////////////////////////////////// - // void SplitStereoPacket() - // This function is used to split stereo payloads in left and right channel. - // Codecs which has stereo support has there own implementation of the - // function. - // - // Input/Output: - // -payload : a vector with the received payload data. - // The function will reorder the data so that - // first half holds the left channel data, and the - // second half the right channel data. - // -payload_length : length of payload in bytes. Will be changed to - // twice the input in case of true stereo, where - // we simply copy the data and return it both for - // left channel and right channel decoding. - // - virtual void SplitStereoPacket(uint8_t* /* payload */, - int32_t* /* payload_length */) {} - - /////////////////////////////////////////////////////////////////////////// - // bool EncoderInitialized(); - // - // Return value: - // True if the encoder is successfully initialized, - // false otherwise. - // - bool EncoderInitialized(); - - /////////////////////////////////////////////////////////////////////////// - // bool DecoderInitialized(); - // - // Return value: - // True if the decoder is successfully initialized, - // false otherwise. - // - bool DecoderInitialized(); - - /////////////////////////////////////////////////////////////////////////// - // int16_t EncoderParams() - // It is called to get encoder parameters. It will call - // EncoderParamsSafe() in turn. - // - // Output: - // -enc_params : a buffer where the encoder parameters is - // written to. If the encoder is not - // initialized this buffer is filled with - // invalid values - // Return value: - // -1 if the encoder is not initialized, - // 0 otherwise. - // - int16_t EncoderParams(WebRtcACMCodecParams *enc_params); - - /////////////////////////////////////////////////////////////////////////// - // int16_t DecoderParams(...) - // It is called to get decoder parameters. It will call DecoderParamsSafe() - // in turn. - // - // Output: - // -dec_params : a buffer where the decoder parameters is - // written to. If the decoder is not initialized - // this buffer is filled with invalid values - // - // Return value: - // -1 if the decoder is not initialized, - // 0 otherwise. - // - // - bool DecoderParams(WebRtcACMCodecParams *dec_params, - const uint8_t payload_type); - - /////////////////////////////////////////////////////////////////////////// - // int16_t InitEncoder(...) - // This function is called to initialize the encoder with the given - // parameters. - // - // Input: - // -codec_params : parameters of encoder. - // -force_initialization: if false the initialization is invoked only if - // the encoder is not initialized. If true the - // encoder is forced to (re)initialize. - // - // Return value: - // 0 if could initialize successfully, - // -1 if failed to initialize. - // - // - int16_t InitEncoder(WebRtcACMCodecParams* codec_params, - bool force_initialization); - - /////////////////////////////////////////////////////////////////////////// - // int16_t InitDecoder() - // This function is called to initialize the decoder with the given - // parameters. (c.f. acm_common_defs.h & common_types.h for the - // definition of the structure) - // - // Input: - // -codec_params : parameters of decoder. - // -force_initialization: if false the initialization is invoked only - // if the decoder is not initialized. If true - // the encoder is forced to(re)initialize. - // - // Return value: - // 0 if could initialize successfully, - // -1 if failed to initialize. - // - // - int16_t InitDecoder(WebRtcACMCodecParams* codec_params, - bool force_initialization); - - /////////////////////////////////////////////////////////////////////////// - // int32_t RegisterInNetEq(...) - // This function is called to register the decoder in NetEq, with the given - // payload type. - // - // Inputs: - // -neteq : pointer to NetEq Instance - // -codec_inst : instance with of the codec settings of the codec - // - // Return values - // -1 if failed to register, - // 0 if successfully initialized. - // - int32_t RegisterInNetEq(ACMNetEQ* neteq, const CodecInst& codec_inst); - - /////////////////////////////////////////////////////////////////////////// - // int32_t Add10MsData(...) - // This function is called to add 10 ms of audio to the audio buffer of - // the codec. - // - // Inputs: - // -timestamp : the timestamp of the 10 ms audio. the timestamp - // is the sampling time of the - // first sample measured in number of samples. - // -data : a buffer that contains the audio. The codec - // expects to get the audio in correct sampling - // frequency - // -length : the length of the audio buffer - // -audio_channel : 0 for mono, 1 for stereo (not supported yet) - // - // Return values: - // -1 if failed - // 0 otherwise. - // - int32_t Add10MsData(const uint32_t timestamp, - const int16_t* data, - const uint16_t length, - const uint8_t audio_channel); - - /////////////////////////////////////////////////////////////////////////// - // uint32_t NoMissedSamples() - // This function returns the number of samples which are overwritten in - // the audio buffer. The audio samples are overwritten if the input audio - // buffer is full, but Add10MsData() is called. (We might remove this - // function if it is not used) - // - // Return Value: - // Number of samples which are overwritten. - // - uint32_t NoMissedSamples() const; - - /////////////////////////////////////////////////////////////////////////// - // void ResetNoMissedSamples() - // This function resets the number of overwritten samples to zero. - // (We might remove this function if we remove NoMissedSamples()) - // - void ResetNoMissedSamples(); - - /////////////////////////////////////////////////////////////////////////// - // int16_t SetBitRate() - // The function is called to set the encoding rate. - // - // Input: - // -bitrate_bps : encoding rate in bits per second - // - // Return value: - // -1 if failed to set the rate, due to invalid input or given - // codec is not rate-adjustable. - // 0 if the rate is adjusted successfully - // - int16_t SetBitRate(const int32_t bitrate_bps); - - /////////////////////////////////////////////////////////////////////////// - // DestructEncoderInst() - // This API is used in conferencing. It will free the memory that is pointed - // by |ptr_inst|. |ptr_inst| is a pointer to encoder instance, created and - // filled up by calling EncoderInst(...). - // - // Inputs: - // -ptr_inst : pointer to an encoder instance to be deleted. - // - // - void DestructEncoderInst(void* ptr_inst); - - /////////////////////////////////////////////////////////////////////////// - // int16_t AudioBuffer() - // This is used when synchronization of codecs is required. There are cases - // that the audio buffers of two codecs have to be synched. By calling this - // function on can get the audio buffer and other related parameters, such - // as timestamps... - // - // Output: - // -audio_buff : a pointer to WebRtcACMAudioBuff where the audio - // buffer of this codec will be written to. - // - // Return value: - // -1 if fails to copy the audio buffer, - // 0 if succeeded. - // - int16_t AudioBuffer(WebRtcACMAudioBuff& audio_buff); - - /////////////////////////////////////////////////////////////////////////// - // uint32_t EarliestTimestamp() - // Returns the timestamp of the first 10 ms in audio buffer. This is used - // to identify if a synchronization of two encoders is required. - // - // Return value: - // timestamp of the first 10 ms audio in the audio buffer. - // - uint32_t EarliestTimestamp() const; - - /////////////////////////////////////////////////////////////////////////// - // int16_t SetAudioBuffer() - // This function is called to set the audio buffer and the associated - // parameters to a given value. - // - // Return value: - // -1 if fails to copy the audio buffer, - // 0 if succeeded. - // - int16_t SetAudioBuffer(WebRtcACMAudioBuff& audio_buff); - - /////////////////////////////////////////////////////////////////////////// - // int16_t SetVAD() - // This is called to set VAD & DTX. If the codec has internal DTX, it will - // be used. If DTX is enabled and the codec does not have internal DTX, - // WebRtc-VAD will be used to decide if the frame is active. If DTX is - // disabled but VAD is enabled the audio is passed through VAD to label it - // as active or passive, but the frame is encoded normally. However the - // bit-stream is labeled properly so that ACM::Process() can use this - // information. In case of failure, the previous states of the VAD & DTX - // are kept. - // - // Input/Output: - // -enable_dtx : if true DTX will be enabled otherwise the DTX is - // disabled. If codec has internal DTX that will be - // used, otherwise WebRtc-CNG is used. In the latter - // case VAD is automatically activated. - // -enable_vad : if true WebRtc-VAD is enabled, otherwise VAD is - // disabled, except for the case that DTX is enabled - // but codec doesn't have internal DTX. In this case - // VAD is enabled regardless of the value of - // |enable_vad|. - // -mode : this specifies the aggressiveness of VAD. - // - // Return value - // -1 if failed to set DTX & VAD as specified, - // 0 if succeeded. - // - int16_t SetVAD(bool* enable_dtx, - bool* enable_vad, - ACMVADMode* mode); - - /////////////////////////////////////////////////////////////////////////// - // int32_t ReplaceInternalDTX() - // This is called to replace the codec internal DTX with WebRtc DTX. - // This is only valid for G729 where the user has possibility to replace - // AnnexB with WebRtc DTX. For other codecs this function has no effect. - // - // Input: - // -replace_internal_dtx : if true the internal DTX is replaced with WebRtc. - // - // Return value - // -1 if failed to replace internal DTX, - // 0 if succeeded. - // - int32_t ReplaceInternalDTX(const bool replace_internal_dtx); - - /////////////////////////////////////////////////////////////////////////// - // int32_t IsInternalDTXReplaced() - // This is called to check if the codec internal DTX is replaced by WebRtc - // DTX. This is only valid for G729 where the user has possibility to replace - // AnnexB with WebRtc DTX. For other codecs this function has no effect. - // - // Output: - // -internal_dtx_replaced: if true the internal DTX is replaced with WebRtc. - // - // Return value - // -1 if failed to check - // 0 if succeeded. - // - int32_t IsInternalDTXReplaced(bool* internal_dtx_replaced); - - /////////////////////////////////////////////////////////////////////////// - // void SetNetEqDecodeLock() - // Passes the NetEq lock to the codec. - // - // Input: - // -neteq_decode_lock : pointer to the lock associated with NetEQ of ACM. - // - void SetNetEqDecodeLock(RWLockWrapper* neteq_decode_lock) { - neteq_decode_lock_ = neteq_decode_lock; - } - - /////////////////////////////////////////////////////////////////////////// - // bool HasInternalDTX() - // Used to check if the codec has internal DTX. - // - // Return value: - // true if the codec has an internal DTX, e.g. G729, - // false otherwise. - // - bool HasInternalDTX() const { - return has_internal_dtx_; - } - - /////////////////////////////////////////////////////////////////////////// - // int32_t GetEstimatedBandwidth() - // Used to get decoder estimated bandwidth. Only iSAC will provide a value. - // - // - // Return value: - // -1 if fails to get decoder estimated bandwidth, - // >0 estimated bandwidth in bits/sec. - // - int32_t GetEstimatedBandwidth(); - - /////////////////////////////////////////////////////////////////////////// - // int32_t SetEstimatedBandwidth() - // Used to set estiamted bandwidth sent out of band from other side. Only - // iSAC will have use for the value. - // - // Input: - // -estimated_bandwidth: estimated bandwidth in bits/sec - // - // Return value: - // -1 if fails to set estimated bandwidth, - // 0 on success. - // - int32_t SetEstimatedBandwidth(int32_t estimated_bandwidth); - - /////////////////////////////////////////////////////////////////////////// - // int32_t GetRedPayload() - // Used to get codec specific RED payload (if such is implemented). - // Currently only done in iSAC. - // - // Outputs: - // -red_payload : a pointer to the data for RED payload. - // -payload_bytes : number of bytes in RED payload. - // - // Return value: - // -1 if fails to get codec specific RED, - // 0 if succeeded. - // - int32_t GetRedPayload(uint8_t* red_payload, - int16_t* payload_bytes); - - /////////////////////////////////////////////////////////////////////////// - // int16_t ResetEncoder() - // By calling this function you would re-initialize the encoder with the - // current parameters. All the settings, e.g. VAD/DTX, frame-size... should - // remain unchanged. (In case of iSAC we don't want to lose BWE history.) - // - // Return value - // -1 if failed, - // 0 if succeeded. - // - int16_t ResetEncoder(); - - /////////////////////////////////////////////////////////////////////////// - // int16_t ResetEncoder() - // By calling this function you would re-initialize the decoder with the - // current parameters. - // - // Return value - // -1 if failed, - // 0 if succeeded. - // - int16_t ResetDecoder(int16_t payload_type); - - /////////////////////////////////////////////////////////////////////////// - // void DestructEncoder() - // This function is called to delete the encoder instance, if possible, to - // have a fresh start. For codecs where encoder and decoder share the same - // instance we cannot delete the encoder and instead we will initialize the - // encoder. We also delete VAD and DTX if they have been created. - // - void DestructEncoder(); - - /////////////////////////////////////////////////////////////////////////// - // void DestructDecoder() - // This function is called to delete the decoder instance, if possible, to - // have a fresh start. For codecs where encoder and decoder share the same - // instance we cannot delete the encoder and instead we will initialize the - // decoder. Before deleting decoder instance it has to be removed from the - // NetEq list. - // - void DestructDecoder(); - - /////////////////////////////////////////////////////////////////////////// - // int16_t SamplesLeftToEncode() - // Returns the number of samples required to be able to do encoding. - // - // Return value: - // Number of samples. - // - int16_t SamplesLeftToEncode(); - - /////////////////////////////////////////////////////////////////////////// - // uint32_t LastEncodedTimestamp() - // Returns the timestamp of the last frame it encoded. - // - // Return value: - // Timestamp. - // - uint32_t LastEncodedTimestamp() const; - - /////////////////////////////////////////////////////////////////////////// - // SetUniqueID() - // Set a unique ID for the codec to be used for tracing and debugging - // - // Input - // -id : A number to identify the codec. - // - void SetUniqueID(const uint32_t id); - - /////////////////////////////////////////////////////////////////////////// - // IsAudioBufferFresh() - // Specifies if ever audio is injected to this codec. - // - // Return value - // -true; no audio is feed into this codec - // -false; audio has already been fed to the codec. - // - bool IsAudioBufferFresh() const; - - /////////////////////////////////////////////////////////////////////////// - // UpdateDecoderSampFreq() - // For most of the codecs this function does nothing. It must be - // implemented for those codecs that one codec instance serves as the - // decoder for different flavors of the codec. One example is iSAC. there, - // iSAC 16 kHz and iSAC 32 kHz are treated as two different codecs with - // different payload types, however, there is only one iSAC instance to - // decode. The reason for that is we would like to decode and encode with - // the same codec instance for bandwidth estimator to work. - // - // Each time that we receive a new payload type, we call this function to - // prepare the decoder associated with the new payload. Normally, decoders - // doesn't have to do anything. For iSAC the decoder has to change it's - // sampling rate. The input parameter specifies the current flavor of the - // codec in codec database. For instance, if we just got a SWB payload then - // the input parameter is ACMCodecDB::isacswb. - // - // Input: - // -codec_id : the ID of the codec associated with the - // payload type that we just received. - // - // Return value: - // 0 if succeeded in updating the decoder. - // -1 if failed to update. - // - virtual int16_t UpdateDecoderSampFreq(int16_t /* codec_id */); - - /////////////////////////////////////////////////////////////////////////// - // UpdateEncoderSampFreq() - // Call this function to update the encoder sampling frequency. This - // is for codecs where one payload-name supports several encoder sampling - // frequencies. Otherwise, to change the sampling frequency we need to - // register new codec. ACM will consider that as registration of a new - // codec, not a change in parameter. For iSAC, switching from WB to SWB - // is treated as a change in parameter. Therefore, we need this function. - // - // Input: - // -samp_freq_hz : encoder sampling frequency. - // - // Return value: - // -1 if failed, or if this is meaningless for the given codec. - // 0 if succeeded. - // - virtual int16_t UpdateEncoderSampFreq( - uint16_t samp_freq_hz); - - /////////////////////////////////////////////////////////////////////////// - // EncoderSampFreq() - // Get the sampling frequency that the encoder (WebRtc wrapper) expects. - // - // Output: - // -samp_freq_hz : sampling frequency, in Hertz, which the encoder - // should be fed with. - // - // Return value: - // -1 if failed to output sampling rate. - // 0 if the sample rate is returned successfully. - // - virtual int16_t EncoderSampFreq(uint16_t& samp_freq_hz); - - /////////////////////////////////////////////////////////////////////////// - // int32_t ConfigISACBandwidthEstimator() - // Call this function to configure the bandwidth estimator of ISAC. - // During the adaptation of bit-rate, iSAC automatically adjusts the - // frame-size (either 30 or 60 ms) to save on RTP header. The initial - // frame-size can be specified by the first argument. The configuration also - // regards the initial estimate of bandwidths. The estimator starts from - // this point and converges to the actual bottleneck. This is given by the - // second parameter. Furthermore, it is also possible to control the - // adaptation of frame-size. This is specified by the last parameter. - // - // Input: - // -init_frame_fize_ms : initial frame-size in milliseconds. For iSAC-wb - // 30 ms and 60 ms (default) are acceptable values, - // and for iSAC-swb 30 ms is the only acceptable - // value. Zero indicates default value. - // -init_rate_bps : initial estimate of the bandwidth. Values - // between 10000 and 58000 are acceptable. - // -enforce_frame_size : if true, the frame-size will not be adapted. - // - // Return value: - // -1 if failed to configure the bandwidth estimator, - // 0 if the configuration was successfully applied. - // - virtual int32_t ConfigISACBandwidthEstimator( - const uint8_t init_frame_size_msec, - const uint16_t init_rate_bps, - const bool enforce_frame_size); - - /////////////////////////////////////////////////////////////////////////// - // SetISACMaxPayloadSize() - // Set the maximum payload size of iSAC packets. No iSAC payload, - // regardless of its frame-size, may exceed the given limit. For - // an iSAC payload of size B bits and frame-size T sec we have; - // (B < max_payload_len_bytes * 8) and (B/T < max_rate_bit_per_sec), c.f. - // SetISACMaxRate(). - // - // Input: - // -max_payload_len_bytes : maximum payload size in bytes. - // - // Return value: - // -1 if failed to set the maximum payload-size. - // 0 if the given length is set successfully. - // - virtual int32_t SetISACMaxPayloadSize( - const uint16_t max_payload_len_bytes); - - /////////////////////////////////////////////////////////////////////////// - // SetISACMaxRate() - // Set the maximum instantaneous rate of iSAC. For a payload of B bits - // with a frame-size of T sec the instantaneous rate is B/T bits per - // second. Therefore, (B/T < max_rate_bit_per_sec) and - // (B < max_payload_len_bytes * 8) are always satisfied for iSAC payloads, - // c.f SetISACMaxPayloadSize(). - // - // Input: - // -max_rate_bps : maximum instantaneous bit-rate given in bits/sec. - // - // Return value: - // -1 if failed to set the maximum rate. - // 0 if the maximum rate is set successfully. - // - virtual int32_t SetISACMaxRate(const uint32_t max_rate_bps); - - /////////////////////////////////////////////////////////////////////////// - // SaveDecoderParamS() - // Save the parameters of decoder. - // - // Input: - // -codec_params : pointer to a structure where the parameters of - // decoder is stored in. - // - void SaveDecoderParam(const WebRtcACMCodecParams* codec_params); - - int32_t FrameSize() { - return frame_len_smpl_; - } - - void SetIsMaster(bool is_master); - - /////////////////////////////////////////////////////////////////////////// - // REDPayloadISAC() - // This is an iSAC-specific function. The function is called to get RED - // payload from a default-encoder. - // - // Inputs: - // -isac_rate : the target rate of the main payload. A RED - // payload is generated according to the rate of - // main payload. Note that we are not specifying the - // rate of RED payload, but the main payload. - // -isac_bw_estimate : bandwidth information should be inserted in - // RED payload. - // - // Output: - // -payload : pointer to a buffer where the RED payload will - // written to. - // -payload_len_bytes : a place-holder to write the length of the RED - // payload in Bytes. - // - // Return value: - // -1 if an error occurs, otherwise the length of the payload (in Bytes) - // is returned. - // - virtual int16_t REDPayloadISAC(const int32_t isac_rate, - const int16_t isac_bw_estimate, - uint8_t* payload, - int16_t* payload_len_bytes); - - /////////////////////////////////////////////////////////////////////////// - // IsTrueStereoCodec() - // Call to see if current encoder is a true stereo codec. This function - // should be overwritten for codecs which are true stereo codecs - // Return value: - // -true if stereo codec - // -false if not stereo codec. - // - virtual bool IsTrueStereoCodec(); - - /////////////////////////////////////////////////////////////////////////// - // HasFrameToEncode() - // Returns true if there is enough audio buffered for encoding, such that - // calling Encode() will return a payload. - // - bool HasFrameToEncode() const; - - protected: - /////////////////////////////////////////////////////////////////////////// - // All the functions with FunctionNameSafe(...) contain the actual - // implementation of FunctionName(...). FunctionName() acquires an - // appropriate lock and calls FunctionNameSafe() to do the actual work. - // Therefore, for the description of functionality, input/output arguments - // and return value we refer to FunctionName() - // - - /////////////////////////////////////////////////////////////////////////// - // See Decode() for the description of function, input(s)/output(s) and - // return value. - // - virtual int16_t DecodeSafe(uint8_t* bitstream, - int16_t bitstream_len_byte, - int16_t* audio, - int16_t* audio_samples, - int8_t* speech_type) = 0; - - /////////////////////////////////////////////////////////////////////////// - // See Add10MsSafe() for the description of function, input(s)/output(s) - // and return value. - // - virtual int32_t Add10MsDataSafe(const uint32_t timestamp, - const int16_t* data, - const uint16_t length, - const uint8_t audio_channel); - - /////////////////////////////////////////////////////////////////////////// - // See RegisterInNetEq() for the description of function, - // input(s)/output(s) and return value. - // - virtual int32_t CodecDef(WebRtcNetEQ_CodecDef& codec_def, - const CodecInst& codec_inst) = 0; - - /////////////////////////////////////////////////////////////////////////// - // See EncoderParam() for the description of function, input(s)/output(s) - // and return value. - // - int16_t EncoderParamsSafe(WebRtcACMCodecParams *enc_params); - - /////////////////////////////////////////////////////////////////////////// - // See DecoderParam for the description of function, input(s)/output(s) - // and return value. - // - // Note: - // Any Class where a single instance handle several flavors of the - // same codec, therefore, several payload types are associated with - // the same instance have to implement this function. - // - // Currently only iSAC is implementing it. A single iSAC instance is - // used for decoding both WB & SWB stream. At one moment both WB & SWB - // can be registered as receive codec. Hence two payloads are associated - // with a single codec instance. - // - virtual bool DecoderParamsSafe(WebRtcACMCodecParams *dec_params, - const uint8_t payload_type); - - /////////////////////////////////////////////////////////////////////////// - // See ResetEncoder() for the description of function, input(s)/output(s) - // and return value. - // - int16_t ResetEncoderSafe(); - - /////////////////////////////////////////////////////////////////////////// - // See InitEncoder() for the description of function, input(s)/output(s) - // and return value. - // - int16_t InitEncoderSafe(WebRtcACMCodecParams *codec_params, - bool force_initialization); - - /////////////////////////////////////////////////////////////////////////// - // See InitDecoder() for the description of function, input(s)/output(s) - // and return value. - // - int16_t InitDecoderSafe(WebRtcACMCodecParams *codec_params, - bool force_initialization); - - /////////////////////////////////////////////////////////////////////////// - // See ResetDecoder() for the description of function, input(s)/output(s) - // and return value. - // - int16_t ResetDecoderSafe(int16_t payload_type); - - /////////////////////////////////////////////////////////////////////////// - // See DestructEncoder() for the description of function, - // input(s)/output(s) and return value. - // - virtual void DestructEncoderSafe() = 0; - - /////////////////////////////////////////////////////////////////////////// - // See DestructDecoder() for the description of function, - // input(s)/output(s) and return value. - // - virtual void DestructDecoderSafe() = 0; - - /////////////////////////////////////////////////////////////////////////// - // See SetBitRate() for the description of function, input(s)/output(s) - // and return value. - // - // Any codec that can change the bit-rate has to implement this. - // - virtual int16_t SetBitRateSafe(const int32_t bitrate_bps); - - /////////////////////////////////////////////////////////////////////////// - // See GetEstimatedBandwidth() for the description of function, - // input(s)/output(s) and return value. - // - virtual int32_t GetEstimatedBandwidthSafe(); - - /////////////////////////////////////////////////////////////////////////// - // See SetEstimatedBandwidth() for the description of function, - // input(s)/output(s) and return value. - // - virtual int32_t SetEstimatedBandwidthSafe( - int32_t estimated_bandwidth); - - /////////////////////////////////////////////////////////////////////////// - // See GetRedPayload() for the description of function, input(s)/output(s) - // and return value. - // - virtual int32_t GetRedPayloadSafe(uint8_t* red_payload, - int16_t* payload_bytes); - - /////////////////////////////////////////////////////////////////////////// - // See SetVAD() for the description of function, input(s)/output(s) and - // return value. - // - int16_t SetVADSafe(bool* enable_dtx, - bool* enable_vad, - ACMVADMode* mode); - - /////////////////////////////////////////////////////////////////////////// - // See ReplaceInternalDTX() for the description of function, input and - // return value. - // - virtual int32_t ReplaceInternalDTXSafe(const bool replace_internal_dtx); - - /////////////////////////////////////////////////////////////////////////// - // See IsInternalDTXReplaced() for the description of function, input and - // return value. - // - virtual int32_t IsInternalDTXReplacedSafe(bool* internal_dtx_replaced); - - /////////////////////////////////////////////////////////////////////////// - // int16_t CreateEncoder() - // Creates the encoder instance. - // - // Return value: - // -1 if failed, - // 0 if succeeded. - // - int16_t CreateEncoder(); - - /////////////////////////////////////////////////////////////////////////// - // int16_t CreateDecoder() - // Creates the decoder instance. - // - // Return value: - // -1 if failed, - // 0 if succeeded. - // - int16_t CreateDecoder(); - - /////////////////////////////////////////////////////////////////////////// - // int16_t EnableVAD(); - // Enables VAD with the given mode. The VAD instance will be created if - // it does not exists. - // - // Input: - // -mode : VAD mode c.f. audio_coding_module_typedefs.h for - // the options. - // - // Return value: - // -1 if failed, - // 0 if succeeded. - // - int16_t EnableVAD(ACMVADMode mode); - - /////////////////////////////////////////////////////////////////////////// - // int16_t DisableVAD() - // Disables VAD. - // - // Return value: - // -1 if failed, - // 0 if succeeded. - // - int16_t DisableVAD(); - - /////////////////////////////////////////////////////////////////////////// - // int16_t EnableDTX() - // Enables DTX. This method should be overwritten for codecs which have - // internal DTX. - // - // Return value: - // -1 if failed, - // 0 if succeeded. - // - virtual int16_t EnableDTX(); - - /////////////////////////////////////////////////////////////////////////// - // int16_t DisableDTX() - // Disables usage of DTX. This method should be overwritten for codecs which - // have internal DTX. - // - // Return value: - // -1 if failed, - // 0 if succeeded. - // - virtual int16_t DisableDTX(); - - /////////////////////////////////////////////////////////////////////////// - // int16_t InternalEncode() - // This is a codec-specific function called in EncodeSafe() to actually - // encode a frame of audio. - // - // Outputs: - // -bitstream : pointer to a buffer where the bit-stream is - // written to. - // -bitstream_len_byte : the length of the bit-stream in bytes, - // a negative value indicates error. - // - // Return value: - // -1 if failed, - // otherwise the length of the bit-stream is returned. - // - virtual int16_t InternalEncode(uint8_t* bitstream, - int16_t* bitstream_len_byte) = 0; - - /////////////////////////////////////////////////////////////////////////// - // int16_t InternalInitEncoder() - // This is a codec-specific function called in InitEncoderSafe(), it has to - // do all codec-specific operation to initialize the encoder given the - // encoder parameters. - // - // Input: - // -codec_params : pointer to a structure that contains parameters to - // initialize encoder. - // Set codec_params->codec_inst.rate to -1 for - // iSAC to operate in adaptive mode. - // (to do: if frame-length is -1 frame-length will be - // automatically adjusted, otherwise, given - // frame-length is forced) - // - // Return value: - // -1 if failed, - // 0 if succeeded. - // - virtual int16_t InternalInitEncoder( - WebRtcACMCodecParams *codec_params) = 0; - - /////////////////////////////////////////////////////////////////////////// - // int16_t InternalInitDecoder() - // This is a codec-specific function called in InitDecoderSafe(), it has to - // do all codec-specific operation to initialize the decoder given the - // decoder parameters. - // - // Input: - // -codec_params : pointer to a structure that contains parameters to - // initialize encoder. - // - // Return value: - // -1 if failed, - // 0 if succeeded. - // - virtual int16_t InternalInitDecoder( - WebRtcACMCodecParams *codec_params) = 0; - - /////////////////////////////////////////////////////////////////////////// - // void IncreaseNoMissedSamples() - // This method is called to increase the number of samples that are - // overwritten in the audio buffer. - // - // Input: - // -num_samples : the number of overwritten samples is incremented - // by this value. - // - void IncreaseNoMissedSamples(const int16_t num_samples); - - /////////////////////////////////////////////////////////////////////////// - // int16_t InternalCreateEncoder() - // This is a codec-specific method called in CreateEncoderSafe() it is - // supposed to perform all codec-specific operations to create encoder - // instance. - // - // Return value: - // -1 if failed, - // 0 if succeeded. - // - virtual int16_t InternalCreateEncoder() = 0; - - /////////////////////////////////////////////////////////////////////////// - // int16_t InternalCreateDecoder() - // This is a codec-specific method called in CreateDecoderSafe() it is - // supposed to perform all codec-specific operations to create decoder - // instance. - // - // Return value: - // -1 if failed, - // 0 if succeeded. - // - virtual int16_t InternalCreateDecoder() = 0; - - /////////////////////////////////////////////////////////////////////////// - // void InternalDestructEncoderInst() - // This is a codec-specific method, used in conferencing, called from - // DestructEncoderInst(). The input argument is pointer to encoder instance - // (codec instance for codecs that encoder and decoder share the same - // instance). This method is called to free the memory that |ptr_inst| is - // pointing to. - // - // Input: - // -ptr_inst : pointer to encoder instance. - // - // Return value: - // -1 if failed, - // 0 if succeeded. - // - virtual void InternalDestructEncoderInst(void* ptr_inst) = 0; - - /////////////////////////////////////////////////////////////////////////// - // int16_t InternalResetEncoder() - // This method is called to reset the states of encoder. However, the - // current parameters, e.g. frame-length, should remain as they are. For - // most of the codecs a re-initialization of the encoder is what needs to - // be down. But for iSAC we like to keep the BWE history so we cannot - // re-initialize. As soon as such an API is implemented in iSAC this method - // has to be overwritten in ACMISAC class. - // - // Return value: - // -1 if failed, - // 0 if succeeded. - // - virtual int16_t InternalResetEncoder(); - - /////////////////////////////////////////////////////////////////////////// - // int16_t ProcessFrameVADDTX() - // This function is called when a full frame of audio is available. It will - // break the audio frame into blocks such that each block could be processed - // by VAD & CN/DTX. If a frame is divided into two blocks then there are two - // cases. First, the first block is active, the second block will not be - // processed by CN/DTX but only by VAD and return to caller with - // '*samples_processed' set to zero. There, the audio frame will be encoded - // by the encoder. Second, the first block is inactive and is processed by - // CN/DTX, then we stop processing the next block and return to the caller - // which is EncodeSafe(), with "*samples_processed" equal to the number of - // samples in first block. - // - // Output: - // -bitstream : pointer to a buffer where DTX frame, if - // generated, will be written to. - // -bitstream_len_byte : contains the length of bit-stream in bytes, if - // generated. Zero if no bit-stream is generated. - // -samples_processed : contains no of samples that actually CN has - // processed. Those samples processed by CN will not - // be encoded by the encoder, obviously. If - // contains zero, it means that the frame has been - // identified as active by VAD. Note that - // "*samples_processed" might be non-zero but - // "*bitstream_len_byte" be zero. - // - // Return value: - // -1 if failed, - // 0 if succeeded. - // - int16_t ProcessFrameVADDTX(uint8_t* bitstream, - int16_t* bitstream_len_byte, - int16_t* samples_processed); - - /////////////////////////////////////////////////////////////////////////// - // CanChangeEncodingParam() - // Check if the codec parameters can be changed. In conferencing normally - // codec parameters cannot be changed. The exception is bit-rate of isac. - // - // return value: - // -true if codec parameters are allowed to change. - // -false otherwise. - // - virtual bool CanChangeEncodingParam(CodecInst& codec_inst); - - /////////////////////////////////////////////////////////////////////////// - // CurrentRate() - // Call to get the current encoding rate of the encoder. This function - // should be overwritten for codecs which automatically change their - // target rate. One example is iSAC. The output of the function is the - // current target rate. - // - // Output: - // -rate_bps : the current target rate of the codec. - // - virtual void CurrentRate(int32_t& /* rate_bps */); - - virtual void SaveDecoderParamSafe(const WebRtcACMCodecParams* codec_params); - - // &in_audio_[in_audio_ix_write_] always point to where new audio can be - // written to - int16_t in_audio_ix_write_; - - // &in_audio_[in_audio_ix_read_] points to where audio has to be read from - int16_t in_audio_ix_read_; - - int16_t in_timestamp_ix_write_; - - // Where the audio is stored before encoding, - // To save memory the following buffer can be allocated - // dynamically for 80 ms depending on the sampling frequency - // of the codec. - int16_t* in_audio_; - uint32_t* in_timestamp_; - - int16_t frame_len_smpl_; - uint16_t num_channels_; - - // This will point to a static database of the supported codecs - int16_t codec_id_; - - // This will account for the number of samples were not encoded - // the case is rare, either samples are missed due to overwrite - // at input buffer or due to encoding error - uint32_t num_missed_samples_; - - // True if the encoder instance created - bool encoder_exist_; - bool decoder_exist_; - // True if the encoder instance initialized - bool encoder_initialized_; - bool decoder_initialized_; - - bool registered_in_neteq_; - - // VAD/DTX - bool has_internal_dtx_; - WebRtcVadInst* ptr_vad_inst_; - bool vad_enabled_; - ACMVADMode vad_mode_; - int16_t vad_label_[MAX_FRAME_SIZE_10MSEC]; - bool dtx_enabled_; - WebRtcCngEncInst* ptr_dtx_inst_; - uint8_t num_lpc_params_; - bool sent_cn_previous_; - bool is_master_; - int16_t prev_frame_cng_; - - WebRtcACMCodecParams encoder_params_; - WebRtcACMCodecParams decoder_params_; - - // Used as a global lock for all available decoders - // so that no decoder is used when NetEQ decodes. - RWLockWrapper* neteq_decode_lock_; - // Used to lock wrapper internal data - // such as buffers and state variables. - RWLockWrapper& codec_wrapper_lock_; - - uint32_t last_encoded_timestamp_; - uint32_t last_timestamp_; - bool is_audio_buff_fresh_; - uint32_t unique_id_; -}; - -} // namespace acm1 - -} // namespace webrtc - -#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_GENERIC_CODEC_H_ diff --git a/webrtc/modules/audio_coding/main/source/acm_gsmfr.cc b/webrtc/modules/audio_coding/main/source/acm_gsmfr.cc deleted file mode 100644 index 5ea0c56d9..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_gsmfr.cc +++ /dev/null @@ -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 diff --git a/webrtc/modules/audio_coding/main/source/acm_gsmfr.h b/webrtc/modules/audio_coding/main/source/acm_gsmfr.h deleted file mode 100644 index aa499734a..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_gsmfr.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/acm_ilbc.cc b/webrtc/modules/audio_coding/main/source/acm_ilbc.cc deleted file mode 100644 index 0f8049e80..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_ilbc.cc +++ /dev/null @@ -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 diff --git a/webrtc/modules/audio_coding/main/source/acm_ilbc.h b/webrtc/modules/audio_coding/main/source/acm_ilbc.h deleted file mode 100644 index bd2495fe3..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_ilbc.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/acm_isac.cc b/webrtc/modules/audio_coding/main/source/acm_isac.cc deleted file mode 100644 index 61fa32f6d..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_isac.cc +++ /dev/null @@ -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 diff --git a/webrtc/modules/audio_coding/main/source/acm_isac.h b/webrtc/modules/audio_coding/main/source/acm_isac.h deleted file mode 100644 index 20b6c5391..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_isac.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/acm_isac_macros.h b/webrtc/modules/audio_coding/main/source/acm_isac_macros.h deleted file mode 100644 index 01e1e44b3..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_isac_macros.h +++ /dev/null @@ -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_ - diff --git a/webrtc/modules/audio_coding/main/source/acm_neteq.cc b/webrtc/modules/audio_coding/main/source/acm_neteq.cc deleted file mode 100644 index 154cc54d0..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_neteq.cc +++ /dev/null @@ -1,1151 +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_neteq.h" - -#include // malloc - -#include // sort -#include - -#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" -#include "webrtc/common_types.h" -#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h" -#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_internal.h" -#include "webrtc/system_wrappers/interface/critical_section_wrapper.h" -#include "webrtc/system_wrappers/interface/rw_lock_wrapper.h" -#include "webrtc/system_wrappers/interface/trace.h" -#include "webrtc/system_wrappers/interface/trace_event.h" - -namespace webrtc { - -namespace acm1 { - -#define RTP_HEADER_SIZE 12 -#define NETEQ_INIT_FREQ 8000 -#define NETEQ_INIT_FREQ_KHZ (NETEQ_INIT_FREQ/1000) -#define NETEQ_ERR_MSG_LEN_BYTE (WEBRTC_NETEQ_MAX_ERROR_NAME + 1) - -ACMNetEQ::ACMNetEQ() - : id_(0), - current_samp_freq_khz_(NETEQ_INIT_FREQ_KHZ), - avt_playout_(false), - playout_mode_(voice), - neteq_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), - vad_status_(false), - vad_mode_(VADNormal), - decode_lock_(RWLockWrapper::CreateRWLock()), - num_slaves_(0), - received_stereo_(false), - master_slave_info_(NULL), - previous_audio_activity_(AudioFrame::kVadUnknown), - callback_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), - min_of_max_num_packets_(0), - min_of_buffer_size_bytes_(0), - per_packet_overhead_bytes_(0), - av_sync_(false), - minimum_delay_ms_(0), - maximum_delay_ms_(0) { - for (int n = 0; n < MAX_NUM_SLAVE_NETEQ + 1; n++) { - is_initialized_[n] = false; - ptr_vadinst_[n] = NULL; - inst_[n] = NULL; - inst_mem_[n] = NULL; - neteq_packet_buffer_[n] = NULL; - } -} - -ACMNetEQ::~ACMNetEQ() { - { - CriticalSectionScoped lock(neteq_crit_sect_); - RemoveNetEQSafe(0); // Master. - RemoveSlavesSafe(); - } - if (neteq_crit_sect_ != NULL) { - delete neteq_crit_sect_; - } - - if (decode_lock_ != NULL) { - delete decode_lock_; - } - - if (callback_crit_sect_ != NULL) { - delete callback_crit_sect_; - } -} - -int32_t ACMNetEQ::Init() { - CriticalSectionScoped lock(neteq_crit_sect_); - - for (int16_t idx = 0; idx < num_slaves_ + 1; idx++) { - if (InitByIdxSafe(idx) < 0) { - return -1; - } - // delete VAD instance and start fresh if required. - if (ptr_vadinst_[idx] != NULL) { - WebRtcVad_Free(ptr_vadinst_[idx]); - ptr_vadinst_[idx] = NULL; - } - if (vad_status_) { - // Has to enable VAD - if (EnableVADByIdxSafe(idx) < 0) { - // Failed to enable VAD. - // Delete VAD instance, if it is created - if (ptr_vadinst_[idx] != NULL) { - WebRtcVad_Free(ptr_vadinst_[idx]); - ptr_vadinst_[idx] = NULL; - } - // We are at initialization of NetEq, if failed to - // enable VAD, we delete the NetEq instance. - if (inst_mem_[idx] != NULL) { - free(inst_mem_[idx]); - inst_mem_[idx] = NULL; - inst_[idx] = NULL; - } - is_initialized_[idx] = false; - return -1; - } - } - is_initialized_[idx] = true; - } - if (EnableVAD() == -1) { - return -1; - } - return 0; -} - -int16_t ACMNetEQ::InitByIdxSafe(const int16_t idx) { - int memory_size_bytes; - if (WebRtcNetEQ_AssignSize(&memory_size_bytes) != 0) { - LogError("AssignSize", idx); - return -1; - } - - if (inst_mem_[idx] != NULL) { - free(inst_mem_[idx]); - inst_mem_[idx] = NULL; - inst_[idx] = NULL; - } - inst_mem_[idx] = malloc(memory_size_bytes); - if (inst_mem_[idx] == NULL) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "InitByIdxSafe: NetEq Initialization error: could not " - "allocate memory for NetEq"); - is_initialized_[idx] = false; - return -1; - } - if (WebRtcNetEQ_Assign(&inst_[idx], inst_mem_[idx]) != 0) { - if (inst_mem_[idx] != NULL) { - free(inst_mem_[idx]); - inst_mem_[idx] = NULL; - inst_[idx] = NULL; - } - LogError("Assign", idx); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "InitByIdxSafe: NetEq Initialization error: could not Assign"); - is_initialized_[idx] = false; - return -1; - } - if (WebRtcNetEQ_Init(inst_[idx], NETEQ_INIT_FREQ) != 0) { - if (inst_mem_[idx] != NULL) { - free(inst_mem_[idx]); - inst_mem_[idx] = NULL; - inst_[idx] = NULL; - } - LogError("Init", idx); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "InitByIdxSafe: NetEq Initialization error: could not " - "initialize NetEq"); - is_initialized_[idx] = false; - return -1; - } - is_initialized_[idx] = true; - return 0; -} - -int16_t ACMNetEQ::EnableVADByIdxSafe(const int16_t idx) { - if (ptr_vadinst_[idx] == NULL) { - if (WebRtcVad_Create(&ptr_vadinst_[idx]) < 0) { - ptr_vadinst_[idx] = NULL; - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "EnableVADByIdxSafe: NetEq Initialization error: could not " - "create VAD"); - return -1; - } - } - - if (WebRtcNetEQ_SetVADInstance( - inst_[idx], ptr_vadinst_[idx], - (WebRtcNetEQ_VADInitFunction) WebRtcVad_Init, - (WebRtcNetEQ_VADSetmodeFunction) WebRtcVad_set_mode, - (WebRtcNetEQ_VADFunction) WebRtcVad_Process) < 0) { - LogError("setVADinstance", idx); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "EnableVADByIdxSafe: NetEq Initialization error: could not " - "set VAD instance"); - return -1; - } - - if (WebRtcNetEQ_SetVADMode(inst_[idx], vad_mode_) < 0) { - LogError("setVADmode", idx); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "EnableVADByIdxSafe: NetEq Initialization error: could not " - "set VAD mode"); - return -1; - } - return 0; -} - -int32_t ACMNetEQ::AllocatePacketBuffer( - const WebRtcNetEQDecoder* used_codecs, - int16_t num_codecs) { - // Due to WebRtcNetEQ_GetRecommendedBufferSize - // the following has to be int otherwise we will have compiler error - // if not casted - - CriticalSectionScoped lock(neteq_crit_sect_); - for (int16_t idx = 0; idx < num_slaves_ + 1; idx++) { - if (AllocatePacketBufferByIdxSafe(used_codecs, num_codecs, idx) < 0) { - return -1; - } - } - return 0; -} - -int16_t ACMNetEQ::AllocatePacketBufferByIdxSafe( - const WebRtcNetEQDecoder* used_codecs, - int16_t num_codecs, - const int16_t idx) { - int max_num_packets; - int buffer_size_in_bytes; - int per_packet_overhead_bytes; - - if (!is_initialized_[idx]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "AllocatePacketBufferByIdxSafe: NetEq is not initialized."); - return -1; - } - if (WebRtcNetEQ_GetRecommendedBufferSize(inst_[idx], used_codecs, - num_codecs, - kTCPXLargeJitter, - &max_num_packets, - &buffer_size_in_bytes, - &per_packet_overhead_bytes) != 0) { - LogError("GetRecommendedBufferSize", idx); - return -1; - } - if (idx == 0) { - min_of_buffer_size_bytes_ = buffer_size_in_bytes; - min_of_max_num_packets_ = max_num_packets; - per_packet_overhead_bytes_ = per_packet_overhead_bytes; - } else { - min_of_buffer_size_bytes_ = std::min(min_of_buffer_size_bytes_, - buffer_size_in_bytes); - min_of_max_num_packets_ = std::min(min_of_max_num_packets_, - max_num_packets); - } - if (neteq_packet_buffer_[idx] != NULL) { - free(neteq_packet_buffer_[idx]); - neteq_packet_buffer_[idx] = NULL; - } - - neteq_packet_buffer_[idx] = (int16_t *) malloc(buffer_size_in_bytes); - if (neteq_packet_buffer_[idx] == NULL) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "AllocatePacketBufferByIdxSafe: NetEq Initialization error: " - "could not allocate memory for NetEq Packet Buffer"); - return -1; - } - if (WebRtcNetEQ_AssignBuffer(inst_[idx], max_num_packets, - neteq_packet_buffer_[idx], - buffer_size_in_bytes) != 0) { - if (neteq_packet_buffer_[idx] != NULL) { - free(neteq_packet_buffer_[idx]); - neteq_packet_buffer_[idx] = NULL; - } - LogError("AssignBuffer", idx); - return -1; - } - return 0; -} - -int32_t ACMNetEQ::SetAVTPlayout(const bool enable) { - CriticalSectionScoped lock(neteq_crit_sect_); - if (avt_playout_ != enable) { - for (int16_t idx = 0; idx < num_slaves_ + 1; idx++) { - if (!is_initialized_[idx]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "SetAVTPlayout: NetEq is not initialized."); - return -1; - } - if (WebRtcNetEQ_SetAVTPlayout(inst_[idx], (enable) ? 1 : 0) < 0) { - LogError("SetAVTPlayout", idx); - return -1; - } - } - } - avt_playout_ = enable; - return 0; -} - -bool ACMNetEQ::avt_playout() const { - CriticalSectionScoped lock(neteq_crit_sect_); - return avt_playout_; -} - -int32_t ACMNetEQ::CurrentSampFreqHz() const { - CriticalSectionScoped lock(neteq_crit_sect_); - if (!is_initialized_[0]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "CurrentSampFreqHz: NetEq is not initialized."); - return -1; - } - return (int32_t)(1000 * current_samp_freq_khz_); -} - -int32_t ACMNetEQ::SetPlayoutMode(const AudioPlayoutMode mode) { - CriticalSectionScoped lock(neteq_crit_sect_); - if (playout_mode_ == mode) - return 0; - - enum WebRtcNetEQPlayoutMode playout_mode = kPlayoutOff; - enum WebRtcNetEQBGNMode background_noise_mode = kBGNOn; - switch (mode) { - case voice: - playout_mode = kPlayoutOn; - background_noise_mode = kBGNOn; - break; - case fax: - playout_mode = kPlayoutFax; - WebRtcNetEQ_GetBGNMode(inst_[0], &background_noise_mode); // No change. - break; - case streaming: - playout_mode = kPlayoutStreaming; - background_noise_mode = kBGNOff; - break; - case off: - playout_mode = kPlayoutOff; - background_noise_mode = kBGNOff; - break; - } - - int err = 0; - for (int16_t idx = 0; idx < num_slaves_ + 1; idx++) { - if (!is_initialized_[idx]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "SetPlayoutMode: NetEq is not initialized."); - return -1; - } - - if (WebRtcNetEQ_SetPlayoutMode(inst_[idx], playout_mode) < 0) { - LogError("SetPlayoutMode", idx); - err = -1; - } - - if (WebRtcNetEQ_SetBGNMode(inst_[idx], kBGNOff) < 0) { - LogError("SetPlayoutMode::SetBGNMode", idx); - err = -1; - } - } - if (err == 0) - playout_mode_ = mode; - return err; -} - -AudioPlayoutMode ACMNetEQ::playout_mode() const { - CriticalSectionScoped lock(neteq_crit_sect_); - return playout_mode_; -} - -int32_t ACMNetEQ::NetworkStatistics( - ACMNetworkStatistics* statistics) const { - WebRtcNetEQ_NetworkStatistics stats; - CriticalSectionScoped lock(neteq_crit_sect_); - if (!is_initialized_[0]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "NetworkStatistics: NetEq is not initialized."); - return -1; - } - if (WebRtcNetEQ_GetNetworkStatistics(inst_[0], &stats) == 0) { - statistics->currentAccelerateRate = stats.currentAccelerateRate; - statistics->currentBufferSize = stats.currentBufferSize; - statistics->jitterPeaksFound = (stats.jitterPeaksFound > 0); - statistics->currentDiscardRate = stats.currentDiscardRate; - statistics->currentExpandRate = stats.currentExpandRate; - statistics->currentPacketLossRate = stats.currentPacketLossRate; - statistics->currentPreemptiveRate = stats.currentPreemptiveRate; - statistics->preferredBufferSize = stats.preferredBufferSize; - statistics->clockDriftPPM = stats.clockDriftPPM; - statistics->addedSamples = stats.addedSamples; - } else { - LogError("getNetworkStatistics", 0); - return -1; - } - const int kArrayLen = 100; - int waiting_times[kArrayLen]; - int waiting_times_len = WebRtcNetEQ_GetRawFrameWaitingTimes(inst_[0], - kArrayLen, - waiting_times); - if (waiting_times_len > 0) { - std::vector waiting_times_vec(waiting_times, - waiting_times + waiting_times_len); - std::sort(waiting_times_vec.begin(), waiting_times_vec.end()); - size_t size = waiting_times_vec.size(); - assert(size == static_cast(waiting_times_len)); - if (size % 2 == 0) { - statistics->medianWaitingTimeMs = (waiting_times_vec[size / 2 - 1] + - waiting_times_vec[size / 2]) / 2; - } else { - statistics->medianWaitingTimeMs = waiting_times_vec[size / 2]; - } - statistics->minWaitingTimeMs = waiting_times_vec.front(); - statistics->maxWaitingTimeMs = waiting_times_vec.back(); - double sum = 0; - for (size_t i = 0; i < size; ++i) { - sum += waiting_times_vec[i]; - } - statistics->meanWaitingTimeMs = static_cast(sum / size); - } else if (waiting_times_len == 0) { - statistics->meanWaitingTimeMs = -1; - statistics->medianWaitingTimeMs = -1; - statistics->minWaitingTimeMs = -1; - statistics->maxWaitingTimeMs = -1; - } else { - LogError("getRawFrameWaitingTimes", 0); - return -1; - } - return 0; -} - -// Should only be called in AV-sync mode. -int ACMNetEQ::RecIn(const WebRtcRTPHeader& rtp_info, - uint32_t receive_timestamp) { - assert(av_sync_); - - // Translate to NetEq structure. - WebRtcNetEQ_RTPInfo neteq_rtpinfo; - neteq_rtpinfo.payloadType = rtp_info.header.payloadType; - neteq_rtpinfo.sequenceNumber = rtp_info.header.sequenceNumber; - neteq_rtpinfo.timeStamp = rtp_info.header.timestamp; - neteq_rtpinfo.SSRC = rtp_info.header.ssrc; - neteq_rtpinfo.markerBit = rtp_info.header.markerBit; - - CriticalSectionScoped lock(neteq_crit_sect_); - - // Master should be initialized. - assert(is_initialized_[0]); - - // Push into Master. - int status = WebRtcNetEQ_RecInSyncRTP(inst_[0], &neteq_rtpinfo, - receive_timestamp); - if (status < 0) { - LogError("RecInSyncRTP", 0); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "RecIn (sync): NetEq, error in pushing in Master"); - return -1; - } - - // If the received stream is stereo, insert a sync payload into slave. - if (rtp_info.type.Audio.channel == 2) { - // Slave should be initialized. - assert(is_initialized_[1]); - - // PUSH into Slave - status = WebRtcNetEQ_RecInSyncRTP(inst_[1], &neteq_rtpinfo, - receive_timestamp); - if (status < 0) { - LogError("RecInRTPStruct", 1); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "RecIn (sync): NetEq, error in pushing in Slave"); - return -1; - } - } - return status; -} - -int32_t ACMNetEQ::RecIn(const uint8_t* incoming_payload, - const int32_t length_payload, - const WebRtcRTPHeader& rtp_info, - uint32_t receive_timestamp) { - int16_t payload_length = static_cast(length_payload); - - // Translate to NetEq structure. - WebRtcNetEQ_RTPInfo neteq_rtpinfo; - neteq_rtpinfo.payloadType = rtp_info.header.payloadType; - neteq_rtpinfo.sequenceNumber = rtp_info.header.sequenceNumber; - neteq_rtpinfo.timeStamp = rtp_info.header.timestamp; - neteq_rtpinfo.SSRC = rtp_info.header.ssrc; - neteq_rtpinfo.markerBit = rtp_info.header.markerBit; - - CriticalSectionScoped lock(neteq_crit_sect_); - - int status; - // In case of stereo payload, first half of the data should be pushed into - // master, and the second half into slave. - if (rtp_info.type.Audio.channel == 2) { - payload_length = payload_length / 2; - } - - // Check that master is initialized. - if (!is_initialized_[0]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "RecIn: NetEq is not initialized."); - return -1; - } - // Push into Master. - status = WebRtcNetEQ_RecInRTPStruct(inst_[0], &neteq_rtpinfo, - incoming_payload, payload_length, - receive_timestamp); - if (status < 0) { - LogError("RecInRTPStruct", 0); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "RecIn: NetEq, error in pushing in Master"); - return -1; - } - - // If the received stream is stereo, insert second half of paket into slave. - if (rtp_info.type.Audio.channel == 2) { - if (!is_initialized_[1]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "RecIn: NetEq is not initialized."); - return -1; - } - // Push into Slave. - status = WebRtcNetEQ_RecInRTPStruct(inst_[1], &neteq_rtpinfo, - &incoming_payload[payload_length], - payload_length, receive_timestamp); - if (status < 0) { - LogError("RecInRTPStruct", 1); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "RecIn: NetEq, error in pushing in Slave"); - return -1; - } - } - - return 0; -} - -int32_t ACMNetEQ::RecOut(AudioFrame& audio_frame) { - enum WebRtcNetEQOutputType type; - int16_t payload_len_sample; - enum WebRtcNetEQOutputType type_master; - enum WebRtcNetEQOutputType type_slave; - - int16_t payload_len_sample_slave; - - CriticalSectionScoped lockNetEq(neteq_crit_sect_); - - if (!received_stereo_) { - if (!is_initialized_[0]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "RecOut: NetEq is not initialized."); - return -1; - } - { - WriteLockScoped lockCodec(*decode_lock_); - if (WebRtcNetEQ_RecOut(inst_[0], &(audio_frame.data_[0]), - &payload_len_sample) != 0) { - LogError("RecOut", 0); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "RecOut: NetEq, error in pulling out for mono case"); - // Check for errors that can be recovered from: - // RECOUT_ERROR_SAMPLEUNDERRUN = 2003 - int error_code = WebRtcNetEQ_GetErrorCode(inst_[0]); - if (error_code != 2003) { - // Cannot recover; return an error - return -1; - } - } - } - WebRtcNetEQ_GetSpeechOutputType(inst_[0], &type); - audio_frame.num_channels_ = 1; - } else { - if (!is_initialized_[0] || !is_initialized_[1]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "RecOut: NetEq is not initialized."); - return -1; - } - int16_t payload_master[480]; - int16_t payload_slave[480]; - { - WriteLockScoped lockCodec(*decode_lock_); - if (WebRtcNetEQ_RecOutMasterSlave(inst_[0], payload_master, - &payload_len_sample, master_slave_info_, - 1) != 0) { - LogError("RecOutMasterSlave", 0); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "RecOut: NetEq, error in pulling out for master"); - - // Check for errors that can be recovered from: - // RECOUT_ERROR_SAMPLEUNDERRUN = 2003 - int error_code = WebRtcNetEQ_GetErrorCode(inst_[0]); - if (error_code != 2003) { - // Cannot recover; return an error - return -1; - } - } - if (WebRtcNetEQ_RecOutMasterSlave(inst_[1], payload_slave, - &payload_len_sample_slave, - master_slave_info_, 0) != 0) { - LogError("RecOutMasterSlave", 1); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "RecOut: NetEq, error in pulling out for slave"); - - // Check for errors that can be recovered from: - // RECOUT_ERROR_SAMPLEUNDERRUN = 2003 - int error_code = WebRtcNetEQ_GetErrorCode(inst_[1]); - if (error_code != 2003) { - // Cannot recover; return an error - return -1; - } - } - } - - if (payload_len_sample != payload_len_sample_slave) { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, id_, - "RecOut: mismatch between the lenght of the decoded audio " - "by Master (%d samples) and Slave (%d samples).", - payload_len_sample, payload_len_sample_slave); - if (payload_len_sample > payload_len_sample_slave) { - memset(&payload_slave[payload_len_sample_slave], 0, - (payload_len_sample - payload_len_sample_slave) * - sizeof(int16_t)); - } - } - - for (int16_t n = 0; n < payload_len_sample; n++) { - audio_frame.data_[n << 1] = payload_master[n]; - audio_frame.data_[(n << 1) + 1] = payload_slave[n]; - } - audio_frame.num_channels_ = 2; - - WebRtcNetEQ_GetSpeechOutputType(inst_[0], &type_master); - WebRtcNetEQ_GetSpeechOutputType(inst_[1], &type_slave); - if ((type_master == kOutputNormal) || (type_slave == kOutputNormal)) { - type = kOutputNormal; - } else { - type = type_master; - } - } - - audio_frame.samples_per_channel_ = - static_cast(payload_len_sample); - // NetEq always returns 10 ms of audio. - current_samp_freq_khz_ = - static_cast(audio_frame.samples_per_channel_) / 10.0f; - audio_frame.sample_rate_hz_ = audio_frame.samples_per_channel_ * 100; - if (vad_status_) { - if (type == kOutputVADPassive) { - audio_frame.vad_activity_ = AudioFrame::kVadPassive; - audio_frame.speech_type_ = AudioFrame::kNormalSpeech; - } else if (type == kOutputNormal) { - audio_frame.vad_activity_ = AudioFrame::kVadActive; - audio_frame.speech_type_ = AudioFrame::kNormalSpeech; - } else if (type == kOutputPLC) { - audio_frame.vad_activity_ = previous_audio_activity_; - audio_frame.speech_type_ = AudioFrame::kPLC; - } else if (type == kOutputCNG) { - audio_frame.vad_activity_ = AudioFrame::kVadPassive; - audio_frame.speech_type_ = AudioFrame::kCNG; - } else { - audio_frame.vad_activity_ = AudioFrame::kVadPassive; - audio_frame.speech_type_ = AudioFrame::kPLCCNG; - } - } else { - // Always return kVadUnknown when receive VAD is inactive - audio_frame.vad_activity_ = AudioFrame::kVadUnknown; - if (type == kOutputNormal) { - audio_frame.speech_type_ = AudioFrame::kNormalSpeech; - } else if (type == kOutputPLC) { - audio_frame.speech_type_ = AudioFrame::kPLC; - } else if (type == kOutputPLCtoCNG) { - audio_frame.speech_type_ = AudioFrame::kPLCCNG; - } else if (type == kOutputCNG) { - audio_frame.speech_type_ = AudioFrame::kCNG; - } else { - // type is kOutputVADPassive which - // we don't expect to get if vad_status_ is false - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, id_, - "RecOut: NetEq returned kVadPassive while vad_status_ is " - "false."); - audio_frame.vad_activity_ = AudioFrame::kVadUnknown; - audio_frame.speech_type_ = AudioFrame::kNormalSpeech; - } - } - previous_audio_activity_ = audio_frame.vad_activity_; - - WebRtcNetEQ_ProcessingActivity processing_stats; - WebRtcNetEQ_GetProcessingActivity(inst_[0], &processing_stats); - WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, id_, - "ACM::RecOut accelerate_bgn=%d accelerate_normal=%d" - " expand_bgn=%d expand_normal=%d" - " preemptive_bgn=%d preemptive_normal=%d" - " merge_bgn=%d merge_normal=%d", - processing_stats.accelerate_bgn_samples, - processing_stats.accelerate_normal_samples, - processing_stats.expand_bgn_sampels, - processing_stats.expand_normal_samples, - processing_stats.preemptive_expand_bgn_samples, - processing_stats.preemptive_expand_normal_samples, - processing_stats.merge_expand_bgn_samples, - processing_stats.merge_expand_normal_samples); - return 0; -} - -// When ACMGenericCodec has set the codec specific parameters in codec_def -// it calls AddCodec() to add the new codec to the NetEQ database. -int32_t ACMNetEQ::AddCodec(WebRtcNetEQ_CodecDef* codec_def, - bool to_master) { - if (codec_def == NULL) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "ACMNetEQ::AddCodec: error, codec_def is NULL"); - return -1; - } - CriticalSectionScoped lock(neteq_crit_sect_); - - int16_t idx; - if (to_master) { - idx = 0; - } else { - idx = 1; - } - - if (!is_initialized_[idx]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "ACMNetEQ::AddCodec: NetEq is not initialized."); - return -1; - } - if (WebRtcNetEQ_CodecDbAdd(inst_[idx], codec_def) < 0) { - LogError("CodecDB_Add", idx); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "ACMNetEQ::AddCodec: NetEq, error in adding codec"); - return -1; - } else { - return 0; - } -} - -// Creates a Word16 RTP packet out of a Word8 payload and an rtp info struct. -// Must be byte order safe. -void ACMNetEQ::RTPPack(int16_t* rtp_packet, const int8_t* payload, - const int32_t payload_length_bytes, - const WebRtcRTPHeader& rtp_info) { - int32_t idx = 0; - WEBRTC_SPL_SET_BYTE(rtp_packet, (int8_t) 0x80, idx); - idx++; - WEBRTC_SPL_SET_BYTE(rtp_packet, rtp_info.header.payloadType, idx); - idx++; - WEBRTC_SPL_SET_BYTE(rtp_packet, - WEBRTC_SPL_GET_BYTE(&(rtp_info.header.sequenceNumber), 1), - idx); - idx++; - WEBRTC_SPL_SET_BYTE(rtp_packet, - WEBRTC_SPL_GET_BYTE(&(rtp_info.header.sequenceNumber), 0), - idx); - idx++; - WEBRTC_SPL_SET_BYTE(rtp_packet, - WEBRTC_SPL_GET_BYTE(&(rtp_info.header.timestamp), 3), - idx); - idx++; - WEBRTC_SPL_SET_BYTE(rtp_packet, - WEBRTC_SPL_GET_BYTE(&(rtp_info.header.timestamp), 2), - idx); - idx++; - WEBRTC_SPL_SET_BYTE(rtp_packet, - WEBRTC_SPL_GET_BYTE(&(rtp_info.header.timestamp), 1), - idx); - idx++; - WEBRTC_SPL_SET_BYTE(rtp_packet, - WEBRTC_SPL_GET_BYTE(&(rtp_info.header.timestamp), 0), - idx); - idx++; - WEBRTC_SPL_SET_BYTE(rtp_packet, - WEBRTC_SPL_GET_BYTE(&(rtp_info.header.ssrc), 3), idx); - idx++; - WEBRTC_SPL_SET_BYTE(rtp_packet, WEBRTC_SPL_GET_BYTE(&(rtp_info.header.ssrc), - 2), idx); - idx++; - WEBRTC_SPL_SET_BYTE(rtp_packet, WEBRTC_SPL_GET_BYTE(&(rtp_info.header.ssrc), - 1), idx); - idx++; - WEBRTC_SPL_SET_BYTE(rtp_packet, WEBRTC_SPL_GET_BYTE(&(rtp_info.header.ssrc), - 0), idx); - idx++; - for (int16_t i = 0; i < payload_length_bytes; i++) { - WEBRTC_SPL_SET_BYTE(rtp_packet, payload[i], idx); - idx++; - } - if (payload_length_bytes & 1) { - // Our 16 bits buffer is one byte too large, set that - // last byte to zero. - WEBRTC_SPL_SET_BYTE(rtp_packet, 0x0, idx); - } -} - -int16_t ACMNetEQ::EnableVAD() { - CriticalSectionScoped lock(neteq_crit_sect_); - if (vad_status_) { - return 0; - } - for (int16_t idx = 0; idx < num_slaves_ + 1; idx++) { - if (!is_initialized_[idx]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "SetVADStatus: NetEq is not initialized."); - return -1; - } - // VAD was off and we have to turn it on - if (EnableVADByIdxSafe(idx) < 0) { - return -1; - } - - // Set previous VAD status to PASSIVE - previous_audio_activity_ = AudioFrame::kVadPassive; - } - vad_status_ = true; - return 0; -} - -ACMVADMode ACMNetEQ::vad_mode() const { - CriticalSectionScoped lock(neteq_crit_sect_); - return vad_mode_; -} - -int16_t ACMNetEQ::SetVADMode(const ACMVADMode mode) { - CriticalSectionScoped lock(neteq_crit_sect_); - if ((mode < VADNormal) || (mode > VADVeryAggr)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "SetVADMode: NetEq error: could not set VAD mode, mode is not " - "supported"); - return -1; - } else { - for (int16_t idx = 0; idx < num_slaves_ + 1; idx++) { - if (!is_initialized_[idx]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "SetVADMode: NetEq is not initialized."); - return -1; - } - if (WebRtcNetEQ_SetVADMode(inst_[idx], mode) < 0) { - LogError("SetVADmode", idx); - return -1; - } - } - vad_mode_ = mode; - return 0; - } -} - -int32_t ACMNetEQ::FlushBuffers() { - CriticalSectionScoped lock(neteq_crit_sect_); - for (int16_t idx = 0; idx < num_slaves_ + 1; idx++) { - if (!is_initialized_[idx]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "FlushBuffers: NetEq is not initialized."); - return -1; - } - if (WebRtcNetEQ_FlushBuffers(inst_[idx]) < 0) { - LogError("FlushBuffers", idx); - return -1; - } - } - return 0; -} - -int16_t ACMNetEQ::RemoveCodec(WebRtcNetEQDecoder codec_idx, - bool is_stereo) { - // sanity check - if ((codec_idx <= kDecoderReservedStart) || - (codec_idx >= kDecoderReservedEnd)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "RemoveCodec: NetEq error: could not Remove Codec, codec " - "index out of range"); - return -1; - } - CriticalSectionScoped lock(neteq_crit_sect_); - if (!is_initialized_[0]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "RemoveCodec: NetEq is not initialized."); - return -1; - } - - if (WebRtcNetEQ_CodecDbRemove(inst_[0], codec_idx) < 0) { - LogError("CodecDB_Remove", 0); - return -1; - } - - if (is_stereo) { - if (WebRtcNetEQ_CodecDbRemove(inst_[1], codec_idx) < 0) { - LogError("CodecDB_Remove", 1); - return -1; - } - } - - return 0; -} - -int16_t ACMNetEQ::SetBackgroundNoiseMode( - const ACMBackgroundNoiseMode mode) { - CriticalSectionScoped lock(neteq_crit_sect_); - for (int16_t idx = 0; idx < num_slaves_ + 1; idx++) { - if (!is_initialized_[idx]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "SetBackgroundNoiseMode: NetEq is not initialized."); - return -1; - } - if (WebRtcNetEQ_SetBGNMode(inst_[idx], (WebRtcNetEQBGNMode) mode) < 0) { - LogError("SetBGNMode", idx); - return -1; - } - } - return 0; -} - -int16_t ACMNetEQ::BackgroundNoiseMode(ACMBackgroundNoiseMode& mode) { - WebRtcNetEQBGNMode my_mode; - CriticalSectionScoped lock(neteq_crit_sect_); - if (!is_initialized_[0]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "BackgroundNoiseMode: NetEq is not initialized."); - return -1; - } - if (WebRtcNetEQ_GetBGNMode(inst_[0], &my_mode) < 0) { - LogError("WebRtcNetEQ_GetBGNMode", 0); - return -1; - } else { - mode = (ACMBackgroundNoiseMode) my_mode; - } - return 0; -} - -void ACMNetEQ::set_id(int32_t id) { - CriticalSectionScoped lock(neteq_crit_sect_); - id_ = id; -} - -void ACMNetEQ::LogError(const char* neteq_func_name, - const int16_t idx) const { - char error_name[NETEQ_ERR_MSG_LEN_BYTE]; - char my_func_name[50]; - int neteq_error_code = WebRtcNetEQ_GetErrorCode(inst_[idx]); - WebRtcNetEQ_GetErrorName(neteq_error_code, error_name, - NETEQ_ERR_MSG_LEN_BYTE - 1); - strncpy(my_func_name, neteq_func_name, 49); - error_name[NETEQ_ERR_MSG_LEN_BYTE - 1] = '\0'; - my_func_name[49] = '\0'; - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "NetEq-%d Error in function %s, error-code: %d, error-string: " - " %s", idx, my_func_name, neteq_error_code, error_name); -} - -int32_t ACMNetEQ::PlayoutTimestamp(uint32_t& timestamp) { - CriticalSectionScoped lock(neteq_crit_sect_); - if (WebRtcNetEQ_GetSpeechTimeStamp(inst_[0], ×tamp) < 0) { - LogError("GetSpeechTimeStamp", 0); - return -1; - } else { - return 0; - } -} - -void ACMNetEQ::RemoveSlaves() { - CriticalSectionScoped lock(neteq_crit_sect_); - RemoveSlavesSafe(); -} - -void ACMNetEQ::RemoveSlavesSafe() { - for (int i = 1; i < num_slaves_ + 1; i++) { - RemoveNetEQSafe(i); - } - - if (master_slave_info_ != NULL) { - free(master_slave_info_); - master_slave_info_ = NULL; - } - num_slaves_ = 0; -} - -void ACMNetEQ::RemoveNetEQSafe(int index) { - if (inst_mem_[index] != NULL) { - free(inst_mem_[index]); - inst_mem_[index] = NULL; - inst_[index] = NULL; - } - if (neteq_packet_buffer_[index] != NULL) { - free(neteq_packet_buffer_[index]); - neteq_packet_buffer_[index] = NULL; - } - if (ptr_vadinst_[index] != NULL) { - WebRtcVad_Free(ptr_vadinst_[index]); - ptr_vadinst_[index] = NULL; - } -} - -int16_t ACMNetEQ::AddSlave(const WebRtcNetEQDecoder* used_codecs, - int16_t num_codecs) { - CriticalSectionScoped lock(neteq_crit_sect_); - const int16_t slave_idx = 1; - if (num_slaves_ < 1) { - // initialize the receiver, this also sets up VAD. - if (InitByIdxSafe(slave_idx) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "AddSlave: AddSlave Failed, Could not Initialize"); - return -1; - } - - // Allocate buffer. - if (AllocatePacketBufferByIdxSafe(used_codecs, num_codecs, - slave_idx) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "AddSlave: AddSlave Failed, Could not Allocate Packet " - "Buffer"); - return -1; - } - - if (master_slave_info_ != NULL) { - free(master_slave_info_); - master_slave_info_ = NULL; - } - int ms_info_size = WebRtcNetEQ_GetMasterSlaveInfoSize(); - master_slave_info_ = malloc(ms_info_size); - - if (master_slave_info_ == NULL) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "AddSlave: AddSlave Failed, Could not Allocate memory for " - "Master-Slave Info"); - return -1; - } - - // We accept this as initialized NetEQ, the rest is to synchronize - // Slave with Master. - num_slaves_ = 1; - is_initialized_[slave_idx] = true; - - // Set AVT - if (WebRtcNetEQ_SetAVTPlayout(inst_[slave_idx], - (avt_playout_) ? 1 : 0) < 0) { - LogError("SetAVTPlayout", slave_idx); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "AddSlave: AddSlave Failed, Could not set AVT playout."); - return -1; - } - - // Set Background Noise - WebRtcNetEQBGNMode current_mode; - if (WebRtcNetEQ_GetBGNMode(inst_[0], ¤t_mode) < 0) { - LogError("GetBGNMode", 0); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "AAddSlave: AddSlave Failed, Could not Get BGN form " - "Master."); - return -1; - } - - if (WebRtcNetEQ_SetBGNMode(inst_[slave_idx], - (WebRtcNetEQBGNMode) current_mode) < 0) { - LogError("SetBGNMode", slave_idx); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "AddSlave: AddSlave Failed, Could not set BGN mode."); - return -1; - } - - enum WebRtcNetEQPlayoutMode playout_mode = kPlayoutOff; - switch (playout_mode_) { - case voice: - playout_mode = kPlayoutOn; - break; - case fax: - playout_mode = kPlayoutFax; - break; - case streaming: - playout_mode = kPlayoutStreaming; - break; - case off: - playout_mode = kPlayoutOff; - break; - } - if (WebRtcNetEQ_SetPlayoutMode(inst_[slave_idx], playout_mode) < 0) { - LogError("SetPlayoutMode", 1); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "AddSlave: AddSlave Failed, Could not Set Playout Mode."); - return -1; - } - - // Set AV-sync for the slave. - WebRtcNetEQ_EnableAVSync(inst_[slave_idx], av_sync_ ? 1 : 0); - - // Set minimum delay. - if (minimum_delay_ms_ > 0) - WebRtcNetEQ_SetMinimumDelay(inst_[slave_idx], minimum_delay_ms_); - - // Set maximum delay. - if (maximum_delay_ms_ > 0) - WebRtcNetEQ_SetMaximumDelay(inst_[slave_idx], maximum_delay_ms_); - } - - return 0; -} - -void ACMNetEQ::set_received_stereo(bool received_stereo) { - CriticalSectionScoped lock(neteq_crit_sect_); - received_stereo_ = received_stereo; -} - -uint8_t ACMNetEQ::num_slaves() { - CriticalSectionScoped lock(neteq_crit_sect_); - return num_slaves_; -} - -void ACMNetEQ::EnableAVSync(bool enable) { - CriticalSectionScoped lock(neteq_crit_sect_); - av_sync_ = enable; - for (int i = 0; i < num_slaves_ + 1; ++i) { - assert(is_initialized_[i]); - WebRtcNetEQ_EnableAVSync(inst_[i], enable ? 1 : 0); - } -} - -int ACMNetEQ::SetMinimumDelay(int minimum_delay_ms) { - CriticalSectionScoped lock(neteq_crit_sect_); - for (int i = 0; i < num_slaves_ + 1; ++i) { - assert(is_initialized_[i]); - if (WebRtcNetEQ_SetMinimumDelay(inst_[i], minimum_delay_ms) < 0) - return -1; - } - minimum_delay_ms_ = minimum_delay_ms; - return 0; -} - -int ACMNetEQ::SetMaximumDelay(int maximum_delay_ms) { - CriticalSectionScoped lock(neteq_crit_sect_); - for (int i = 0; i < num_slaves_ + 1; ++i) { - assert(is_initialized_[i]); - if (WebRtcNetEQ_SetMaximumDelay(inst_[i], maximum_delay_ms) < 0) - return -1; - } - maximum_delay_ms_ = maximum_delay_ms; - return 0; -} - -int ACMNetEQ::LeastRequiredDelayMs() const { - CriticalSectionScoped lock(neteq_crit_sect_); - assert(is_initialized_[0]); - - // Sufficient to query the master. - return WebRtcNetEQ_GetRequiredDelayMs(inst_[0]); -} - -bool ACMNetEQ::DecodedRtpInfo(int* sequence_number, uint32_t* timestamp) const { - CriticalSectionScoped lock(neteq_crit_sect_); - if (WebRtcNetEQ_DecodedRtpInfo(inst_[0], sequence_number, timestamp) < 0) - return false; - return true; -} - -} // namespace acm1 - -} // namespace webrtc diff --git a/webrtc/modules/audio_coding/main/source/acm_neteq.h b/webrtc/modules/audio_coding/main/source/acm_neteq.h deleted file mode 100644 index e52ddc795..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_neteq.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/acm_neteq_unittest.cc b/webrtc/modules/audio_coding/main/source/acm_neteq_unittest.cc deleted file mode 100644 index 8b973ba23..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_neteq_unittest.cc +++ /dev/null @@ -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 - -#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(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 diff --git a/webrtc/modules/audio_coding/main/source/acm_opus.cc b/webrtc/modules/audio_coding/main/source/acm_opus.cc deleted file mode 100644 index 413f3715f..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_opus.cc +++ /dev/null @@ -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(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 diff --git a/webrtc/modules/audio_coding/main/source/acm_opus.h b/webrtc/modules/audio_coding/main/source/acm_opus.h deleted file mode 100644 index 1e586ff41..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_opus.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/acm_pcm16b.cc b/webrtc/modules/audio_coding/main/source/acm_pcm16b.cc deleted file mode 100644 index 6fe12f757..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_pcm16b.cc +++ /dev/null @@ -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 diff --git a/webrtc/modules/audio_coding/main/source/acm_pcm16b.h b/webrtc/modules/audio_coding/main/source/acm_pcm16b.h deleted file mode 100644 index a97589b57..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_pcm16b.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/acm_pcma.cc b/webrtc/modules/audio_coding/main/source/acm_pcma.cc deleted file mode 100644 index 9e5514a9e..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_pcma.cc +++ /dev/null @@ -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 diff --git a/webrtc/modules/audio_coding/main/source/acm_pcma.h b/webrtc/modules/audio_coding/main/source/acm_pcma.h deleted file mode 100644 index cb506eaa6..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_pcma.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/acm_pcmu.cc b/webrtc/modules/audio_coding/main/source/acm_pcmu.cc deleted file mode 100644 index 6f4eb27aa..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_pcmu.cc +++ /dev/null @@ -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 diff --git a/webrtc/modules/audio_coding/main/source/acm_pcmu.h b/webrtc/modules/audio_coding/main/source/acm_pcmu.h deleted file mode 100644 index ea401d59c..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_pcmu.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/acm_red.cc b/webrtc/modules/audio_coding/main/source/acm_red.cc deleted file mode 100644 index 0d8134c17..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_red.cc +++ /dev/null @@ -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 diff --git a/webrtc/modules/audio_coding/main/source/acm_red.h b/webrtc/modules/audio_coding/main/source/acm_red.h deleted file mode 100644 index ede18b521..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_red.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/acm_resampler.cc b/webrtc/modules/audio_coding/main/source/acm_resampler.cc deleted file mode 100644 index 50ddab1d8..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_resampler.cc +++ /dev/null @@ -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 - -#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(in_freq_hz * num_audio_channels / 100); - memcpy(out_audio, in_audio, length * sizeof(int16_t)); - return static_cast(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 diff --git a/webrtc/modules/audio_coding/main/source/acm_resampler.h b/webrtc/modules/audio_coding/main/source/acm_resampler.h deleted file mode 100644 index ceeae05f2..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_resampler.h +++ /dev/null @@ -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 resampler_; -}; - -} // namespace acm1 -} // namespace webrtc - -#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_RESAMPLER_H_ diff --git a/webrtc/modules/audio_coding/main/source/acm_speex.cc b/webrtc/modules/audio_coding/main/source/acm_speex.cc deleted file mode 100644 index 1567929d8..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_speex.cc +++ /dev/null @@ -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 diff --git a/webrtc/modules/audio_coding/main/source/acm_speex.h b/webrtc/modules/audio_coding/main/source/acm_speex.h deleted file mode 100644 index 762aea8d9..000000000 --- a/webrtc/modules/audio_coding/main/source/acm_speex.h +++ /dev/null @@ -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_ diff --git a/webrtc/modules/audio_coding/main/source/audio_coding_module.gypi b/webrtc/modules/audio_coding/main/source/audio_coding_module.gypi deleted file mode 100644 index a0389b03e..000000000 --- a/webrtc/modules/audio_coding/main/source/audio_coding_module.gypi +++ /dev/null @@ -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', - ], -} diff --git a/webrtc/modules/audio_coding/main/source/audio_coding_module_impl.cc b/webrtc/modules/audio_coding/main/source/audio_coding_module_impl.cc deleted file mode 100644 index 5bdbd0119..000000000 --- a/webrtc/modules/audio_coding/main/source/audio_coding_module_impl.cc +++ /dev/null @@ -1,3039 +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/audio_coding_module_impl.h" - -#include -#include - -#include // For std::max. - -#include "webrtc/engine_configurations.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/acm2/call_statistics.h" -#include "webrtc/modules/audio_coding/main/source/acm_dtmf_detection.h" -#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h" -#include "webrtc/modules/audio_coding/main/source/acm_resampler.h" -#include "webrtc/modules/audio_coding/main/acm2/nack.h" -#include "webrtc/system_wrappers/interface/clock.h" -#include "webrtc/system_wrappers/interface/critical_section_wrapper.h" -#include "webrtc/system_wrappers/interface/logging.h" -#include "webrtc/system_wrappers/interface/rw_lock_wrapper.h" -#include "webrtc/system_wrappers/interface/tick_util.h" -#include "webrtc/system_wrappers/interface/trace.h" -#include "webrtc/system_wrappers/interface/trace_event.h" - -namespace webrtc { - -namespace acm1 { - -enum { - kACMToneEnd = 999 -}; - -// Maximum number of bytes in one packet (PCM16B, 20 ms packets, stereo). -enum { - kMaxPacketSize = 2560 -}; - -// Maximum number of payloads that can be packed in one RED payload. For -// regular FEC, we only pack two payloads. In case of dual-streaming, in worst -// case we might pack 3 payloads in one RED payload. -enum { - kNumFecFragmentationVectors = 2, - kMaxNumFragmentationVectors = 3 -}; - -static const uint32_t kMaskTimestamp = 0x03ffffff; -static const int kDefaultTimestampDiff = 960; // 20 ms @ 48 kHz. - -// If packet N is arrived all packets prior to N - |kNackThresholdPackets| which -// are not received are considered as lost, and appear in NACK list. -static const int kNackThresholdPackets = 2; - -namespace { - -bool IsCodecRED(const CodecInst* codec) { - return (STR_CASE_CMP(codec->plname, "RED") == 0); -} - -bool IsCodecRED(int index) { - return (IsCodecRED(&ACMCodecDB::database_[index])); -} - -bool IsCodecCN(const CodecInst* codec) { - return (STR_CASE_CMP(codec->plname, "CN") == 0); -} - -bool IsCodecCN(int index) { - return (IsCodecCN(&ACMCodecDB::database_[index])); -} - -// Stereo-to-mono can be used as in-place. -int DownMix(const AudioFrame& frame, int length_out_buff, int16_t* out_buff) { - if (length_out_buff < frame.samples_per_channel_) { - return -1; - } - for (int n = 0; n < frame.samples_per_channel_; ++n) - out_buff[n] = (frame.data_[2 * n] + frame.data_[2 * n + 1]) >> 1; - return 0; -} - -// Mono-to-stereo can be used as in-place. -int UpMix(const AudioFrame& frame, int length_out_buff, int16_t* out_buff) { - if (length_out_buff < frame.samples_per_channel_) { - return -1; - } - for (int n = frame.samples_per_channel_ - 1; n >= 0; --n) { - out_buff[2 * n + 1] = frame.data_[n]; - out_buff[2 * n] = frame.data_[n]; - } - return 0; -} - -// Return 1 if timestamp t1 is less than timestamp t2, while compensating for -// wrap-around. -int TimestampLessThan(uint32_t t1, uint32_t t2) { - uint32_t kHalfFullRange = static_cast(0xFFFFFFFF) / 2; - if (t1 == t2) { - return 0; - } else if (t1 < t2) { - if (t2 - t1 < kHalfFullRange) - return 1; - return 0; - } else { - if (t1 - t2 < kHalfFullRange) - return 0; - return 1; - } -} - -} // namespace - -AudioCodingModuleImpl::AudioCodingModuleImpl(const int32_t id, Clock* clock) - : packetization_callback_(NULL), - id_(id), - last_timestamp_(0xD87F3F9F), - last_in_timestamp_(0xD87F3F9F), - send_codec_inst_(), - cng_nb_pltype_(255), - cng_wb_pltype_(255), - cng_swb_pltype_(255), - cng_fb_pltype_(255), - red_pltype_(255), - vad_enabled_(false), - dtx_enabled_(false), - vad_mode_(VADNormal), - stereo_receive_registered_(false), - stereo_send_(false), - prev_received_channel_(0), - expected_channels_(1), - current_send_codec_idx_(-1), - current_receive_codec_idx_(-1), - send_codec_registered_(false), - acm_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), - vad_callback_(NULL), - last_recv_audio_codec_pltype_(255), - is_first_red_(true), - fec_enabled_(false), - last_fec_timestamp_(0), - receive_red_pltype_(255), - previous_pltype_(255), - dummy_rtp_header_(NULL), - recv_pl_frame_size_smpls_(0), - receiver_initialized_(false), - dtmf_detector_(NULL), - dtmf_callback_(NULL), - last_detected_tone_(kACMToneEnd), - callback_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), - secondary_send_codec_inst_(), - initial_delay_ms_(0), - num_packets_accumulated_(0), - num_bytes_accumulated_(0), - accumulated_audio_ms_(0), - first_payload_received_(false), - last_incoming_send_timestamp_(0), - track_neteq_buffer_(false), - playout_ts_(0), - av_sync_(false), - last_timestamp_diff_(kDefaultTimestampDiff), - last_sequence_number_(0), - last_ssrc_(0), - last_packet_was_sync_(false), - clock_(clock), - nack_(), - nack_enabled_(false) { - - // Nullify send codec memory, set payload type and set codec name to - // invalid values. - const char no_name[] = "noCodecRegistered"; - strncpy(send_codec_inst_.plname, no_name, RTP_PAYLOAD_NAME_SIZE - 1); - send_codec_inst_.pltype = -1; - - strncpy(secondary_send_codec_inst_.plname, no_name, - RTP_PAYLOAD_NAME_SIZE - 1); - secondary_send_codec_inst_.pltype = -1; - - for (int i = 0; i < ACMCodecDB::kMaxNumCodecs; i++) { - codecs_[i] = NULL; - registered_pltypes_[i] = -1; - stereo_receive_[i] = false; - slave_codecs_[i] = NULL; - mirror_codec_idx_[i] = -1; - } - - neteq_.set_id(id_); - - // Allocate memory for RED. - red_buffer_ = new uint8_t[MAX_PAYLOAD_SIZE_BYTE]; - - // TODO(turajs): This might not be exactly how this class is supposed to work. - // The external usage might be that |fragmentationVectorSize| has to match - // the allocated space for the member-arrays, while here, we allocate - // according to the maximum number of fragmentations and change - // |fragmentationVectorSize| on-the-fly based on actual number of - // fragmentations. However, due to copying to local variable before calling - // SendData, the RTP module receives a "valid" fragmentation, where allocated - // space matches |fragmentationVectorSize|, therefore, this should not cause - // any problem. A better approach is not using RTPFragmentationHeader as - // member variable, instead, use an ACM-specific structure to hold RED-related - // data. See module_common_type.h for the definition of - // RTPFragmentationHeader. - fragmentation_.VerifyAndAllocateFragmentationHeader( - kMaxNumFragmentationVectors); - - // Register the default payload type for RED and for CNG at sampling rates of - // 8, 16, 32 and 48 kHz. - for (int i = (ACMCodecDB::kNumCodecs - 1); i >= 0; i--) { - if (IsCodecRED(i)) { - red_pltype_ = static_cast(ACMCodecDB::database_[i].pltype); - } else if (IsCodecCN(i)) { - if (ACMCodecDB::database_[i].plfreq == 8000) { - cng_nb_pltype_ = static_cast(ACMCodecDB::database_[i].pltype); - } else if (ACMCodecDB::database_[i].plfreq == 16000) { - cng_wb_pltype_ = static_cast(ACMCodecDB::database_[i].pltype); - } else if (ACMCodecDB::database_[i].plfreq == 32000) { - cng_swb_pltype_ = static_cast(ACMCodecDB::database_[i].pltype); - } else if (ACMCodecDB::database_[i].plfreq == 48000) { - cng_fb_pltype_ = static_cast(ACMCodecDB::database_[i].pltype); - } - } - } - - if (InitializeReceiverSafe() < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Cannot initialize receiver"); - } - WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceAudioCoding, id, "Created"); -} - -AudioCodingModuleImpl::~AudioCodingModuleImpl() { - { - CriticalSectionScoped lock(acm_crit_sect_); - current_send_codec_idx_ = -1; - - for (int i = 0; i < ACMCodecDB::kMaxNumCodecs; i++) { - if (codecs_[i] != NULL) { - // True stereo codecs share the same memory for master and - // slave, so slave codec need to be nullified here, since the - // memory will be deleted. - if (slave_codecs_[i] == codecs_[i]) { - slave_codecs_[i] = NULL; - } - - // Mirror index holds the address of the codec memory. - assert(mirror_codec_idx_[i] > -1); - if (codecs_[mirror_codec_idx_[i]] != NULL) { - delete codecs_[mirror_codec_idx_[i]]; - codecs_[mirror_codec_idx_[i]] = NULL; - } - - codecs_[i] = NULL; - } - - if (slave_codecs_[i] != NULL) { - // Delete memory for stereo usage of mono codecs. - assert(mirror_codec_idx_[i] > -1); - if (slave_codecs_[mirror_codec_idx_[i]] != NULL) { - delete slave_codecs_[mirror_codec_idx_[i]]; - slave_codecs_[mirror_codec_idx_[i]] = NULL; - } - slave_codecs_[i] = NULL; - } - } - - if (dtmf_detector_ != NULL) { - delete dtmf_detector_; - dtmf_detector_ = NULL; - } - if (dummy_rtp_header_ != NULL) { - delete dummy_rtp_header_; - dummy_rtp_header_ = NULL; - } - if (red_buffer_ != NULL) { - delete[] red_buffer_; - red_buffer_ = NULL; - } - } - - delete callback_crit_sect_; - callback_crit_sect_ = NULL; - - delete acm_crit_sect_; - acm_crit_sect_ = NULL; - WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceAudioCoding, id_, - "Destroyed"); -} - -int32_t AudioCodingModuleImpl::ChangeUniqueId(const int32_t id) { - { - CriticalSectionScoped lock(acm_crit_sect_); - id_ = id; - - for (int i = 0; i < ACMCodecDB::kMaxNumCodecs; i++) { - if (codecs_[i] != NULL) { - codecs_[i]->SetUniqueID(id); - } - } - } - - neteq_.set_id(id_); - return 0; -} - -// Returns the number of milliseconds until the module want a -// worker thread to call Process. -int32_t AudioCodingModuleImpl::TimeUntilNextProcess() { - CriticalSectionScoped lock(acm_crit_sect_); - - if (!HaveValidEncoder("TimeUntilNextProcess")) { - return -1; - } - return codecs_[current_send_codec_idx_]->SamplesLeftToEncode() / - (send_codec_inst_.plfreq / 1000); -} - -int32_t AudioCodingModuleImpl::Process() { - bool dual_stream; - { - CriticalSectionScoped lock(acm_crit_sect_); - dual_stream = (secondary_encoder_.get() != NULL); - } - if (dual_stream) { - return ProcessDualStream(); - } - return ProcessSingleStream(); -} - -int AudioCodingModuleImpl::EncodeFragmentation(int fragmentation_index, - int payload_type, - uint32_t current_timestamp, - ACMGenericCodec* encoder, - uint8_t* stream) { - int16_t len_bytes = MAX_PAYLOAD_SIZE_BYTE; - uint32_t rtp_timestamp; - WebRtcACMEncodingType encoding_type; - if (encoder->Encode(stream, &len_bytes, &rtp_timestamp, &encoding_type) < 0) { - return -1; - } - assert(encoding_type == kActiveNormalEncoded); - assert(len_bytes > 0); - - fragmentation_.fragmentationLength[fragmentation_index] = len_bytes; - fragmentation_.fragmentationPlType[fragmentation_index] = payload_type; - fragmentation_.fragmentationTimeDiff[fragmentation_index] = - static_cast(current_timestamp - rtp_timestamp); - fragmentation_.fragmentationVectorSize++; - return len_bytes; -} - -// Primary payloads are sent immediately, whereas a single secondary payload is -// buffered to be combined with "the next payload." -// Normally "the next payload" would be a primary payload. In case two -// consecutive secondary payloads are generated with no primary payload in -// between, then two secondary payloads are packed in one RED. -int AudioCodingModuleImpl::ProcessDualStream() { - uint8_t stream[kMaxNumFragmentationVectors * MAX_PAYLOAD_SIZE_BYTE]; - uint32_t current_timestamp; - int16_t length_bytes = 0; - RTPFragmentationHeader my_fragmentation; - - uint8_t my_red_payload_type; - - { - CriticalSectionScoped lock(acm_crit_sect_); - // Check if there is an encoder before. - if (!HaveValidEncoder("ProcessDualStream") || - secondary_encoder_.get() == NULL) { - return -1; - } - ACMGenericCodec* primary_encoder = codecs_[current_send_codec_idx_]; - // If primary encoder has a full frame of audio to generate payload. - bool primary_ready_to_encode = primary_encoder->HasFrameToEncode(); - // If the secondary encoder has a frame of audio to generate a payload. - bool secondary_ready_to_encode = secondary_encoder_->HasFrameToEncode(); - - if (!primary_ready_to_encode && !secondary_ready_to_encode) { - // Nothing to send. - return 0; - } - int len_bytes_previous_secondary = static_cast( - fragmentation_.fragmentationLength[2]); - assert(len_bytes_previous_secondary <= MAX_PAYLOAD_SIZE_BYTE); - bool has_previous_payload = len_bytes_previous_secondary > 0; - - uint32_t primary_timestamp = primary_encoder->EarliestTimestamp(); - uint32_t secondary_timestamp = secondary_encoder_->EarliestTimestamp(); - - if (!has_previous_payload && !primary_ready_to_encode && - secondary_ready_to_encode) { - // Secondary payload will be the ONLY bit-stream. Encode by secondary - // encoder, store the payload, and return. No packet is sent. - int16_t len_bytes = MAX_PAYLOAD_SIZE_BYTE; - WebRtcACMEncodingType encoding_type; - if (secondary_encoder_->Encode(red_buffer_, &len_bytes, - &last_fec_timestamp_, - &encoding_type) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "ProcessDual(): Encoding of secondary encoder Failed"); - return -1; - } - assert(len_bytes > 0); - assert(encoding_type == kActiveNormalEncoded); - assert(len_bytes <= MAX_PAYLOAD_SIZE_BYTE); - fragmentation_.fragmentationLength[2] = len_bytes; - return 0; - } - - // Initialize with invalid but different values, so later can have sanity - // check if they are different. - int index_primary = -1; - int index_secondary = -2; - int index_previous_secondary = -3; - - if (primary_ready_to_encode) { - index_primary = secondary_ready_to_encode ? - TimestampLessThan(primary_timestamp, secondary_timestamp) : 0; - index_primary += has_previous_payload ? - TimestampLessThan(primary_timestamp, last_fec_timestamp_) : 0; - } - - if (secondary_ready_to_encode) { - // Timestamp of secondary payload can only be less than primary payload, - // but is always larger than the timestamp of previous secondary payload. - index_secondary = primary_ready_to_encode ? - (1 - TimestampLessThan(primary_timestamp, secondary_timestamp)) : 0; - } - - if (has_previous_payload) { - index_previous_secondary = primary_ready_to_encode ? - (1 - TimestampLessThan(primary_timestamp, last_fec_timestamp_)) : 0; - // If secondary is ready it always have a timestamp larger than previous - // secondary. So the index is either 0 or 1. - index_previous_secondary += secondary_ready_to_encode ? 1 : 0; - } - - // Indices must not be equal. - assert(index_primary != index_secondary); - assert(index_primary != index_previous_secondary); - assert(index_secondary != index_previous_secondary); - - // One of the payloads has to be at position zero. - assert(index_primary == 0 || index_secondary == 0 || - index_previous_secondary == 0); - - // Timestamp of the RED payload. - if (index_primary == 0) { - current_timestamp = primary_timestamp; - } else if (index_secondary == 0) { - current_timestamp = secondary_timestamp; - } else { - current_timestamp = last_fec_timestamp_; - } - - fragmentation_.fragmentationVectorSize = 0; - if (has_previous_payload) { - assert(index_previous_secondary >= 0 && - index_previous_secondary < kMaxNumFragmentationVectors); - assert(len_bytes_previous_secondary <= MAX_PAYLOAD_SIZE_BYTE); - memcpy(&stream[index_previous_secondary * MAX_PAYLOAD_SIZE_BYTE], - red_buffer_, sizeof(stream[0]) * len_bytes_previous_secondary); - fragmentation_.fragmentationLength[index_previous_secondary] = - len_bytes_previous_secondary; - fragmentation_.fragmentationPlType[index_previous_secondary] = - secondary_send_codec_inst_.pltype; - fragmentation_.fragmentationTimeDiff[index_previous_secondary] = - static_cast(current_timestamp - last_fec_timestamp_); - fragmentation_.fragmentationVectorSize++; - } - - if (primary_ready_to_encode) { - assert(index_primary >= 0 && index_primary < kMaxNumFragmentationVectors); - int i = index_primary * MAX_PAYLOAD_SIZE_BYTE; - if (EncodeFragmentation(index_primary, send_codec_inst_.pltype, - current_timestamp, primary_encoder, - &stream[i]) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "ProcessDualStream(): Encoding of primary encoder Failed"); - return -1; - } - } - - if (secondary_ready_to_encode) { - assert(index_secondary >= 0 && - index_secondary < kMaxNumFragmentationVectors - 1); - int i = index_secondary * MAX_PAYLOAD_SIZE_BYTE; - if (EncodeFragmentation(index_secondary, - secondary_send_codec_inst_.pltype, - current_timestamp, secondary_encoder_.get(), - &stream[i]) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "ProcessDualStream(): Encoding of secondary encoder " - "Failed"); - return -1; - } - } - // Copy to local variable, as it will be used outside the ACM lock. - my_fragmentation.CopyFrom(fragmentation_); - my_red_payload_type = red_pltype_; - length_bytes = 0; - for (int n = 0; n < fragmentation_.fragmentationVectorSize; n++) { - length_bytes += fragmentation_.fragmentationLength[n]; - } - } - - { - CriticalSectionScoped lock(callback_crit_sect_); - if (packetization_callback_ != NULL) { - // Callback with payload data, including redundant data (FEC/RED). - if (packetization_callback_->SendData(kAudioFrameSpeech, - my_red_payload_type, - current_timestamp, stream, - length_bytes, - &my_fragmentation) < 0) { - return -1; - } - } - } - - { - CriticalSectionScoped lock(acm_crit_sect_); - // Now that data is sent, clean up fragmentation. - ResetFragmentation(0); - } - return 0; -} - -// Process any pending tasks such as timeouts. -int AudioCodingModuleImpl::ProcessSingleStream() { - // Make room for 1 RED payload. - uint8_t stream[2 * MAX_PAYLOAD_SIZE_BYTE]; - int16_t length_bytes = 2 * MAX_PAYLOAD_SIZE_BYTE; - int16_t red_length_bytes = length_bytes; - uint32_t rtp_timestamp; - int16_t status; - WebRtcACMEncodingType encoding_type; - FrameType frame_type = kAudioFrameSpeech; - uint8_t current_payload_type = 0; - bool has_data_to_send = false; - bool fec_active = false; - RTPFragmentationHeader my_fragmentation; - - // Keep the scope of the ACM critical section limited. - { - CriticalSectionScoped lock(acm_crit_sect_); - // Check if there is an encoder before. - if (!HaveValidEncoder("ProcessSingleStream")) { - return -1; - } - status = codecs_[current_send_codec_idx_]->Encode(stream, &length_bytes, - &rtp_timestamp, - &encoding_type); - if (status < 0) { - // Encode failed. - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "ProcessSingleStream(): Encoding Failed"); - length_bytes = 0; - return -1; - } else if (status == 0) { - // Not enough data. - return 0; - } else { - switch (encoding_type) { - case kNoEncoding: { - current_payload_type = previous_pltype_; - frame_type = kFrameEmpty; - length_bytes = 0; - break; - } - case kActiveNormalEncoded: - case kPassiveNormalEncoded: { - current_payload_type = static_cast(send_codec_inst_.pltype); - frame_type = kAudioFrameSpeech; - break; - } - case kPassiveDTXNB: { - current_payload_type = cng_nb_pltype_; - frame_type = kAudioFrameCN; - is_first_red_ = true; - break; - } - case kPassiveDTXWB: { - current_payload_type = cng_wb_pltype_; - frame_type = kAudioFrameCN; - is_first_red_ = true; - break; - } - case kPassiveDTXSWB: { - current_payload_type = cng_swb_pltype_; - frame_type = kAudioFrameCN; - is_first_red_ = true; - break; - } - case kPassiveDTXFB: { - current_payload_type = cng_fb_pltype_; - frame_type = kAudioFrameCN; - is_first_red_ = true; - break; - } - } - has_data_to_send = true; - previous_pltype_ = current_payload_type; - - // Redundancy encode is done here. The two bitstreams packetized into - // one RTP packet and the fragmentation points are set. - // Only apply RED on speech data. - if ((fec_enabled_) && - ((encoding_type == kActiveNormalEncoded) || - (encoding_type == kPassiveNormalEncoded))) { - // FEC is enabled within this scope. - // - // Note that, a special solution exists for iSAC since it is the only - // codec for which GetRedPayload has a non-empty implementation. - // - // Summary of the FEC scheme below (use iSAC as example): - // - // 1st (is_first_red_ is true) encoded iSAC frame (primary #1) => - // - call GetRedPayload() and store redundancy for packet #1 in - // second fragment of RED buffer (old data) - // - drop the primary iSAC frame - // - don't call SendData - // 2nd (is_first_red_ is false) encoded iSAC frame (primary #2) => - // - store primary #2 in 1st fragment of RED buffer and send the - // combined packet - // - the transmitted packet contains primary #2 (new) and - // reduncancy for packet #1 (old) - // - call GetRed_Payload() and store redundancy for packet #2 in - // second fragment of RED buffer - // - // ... - // - // Nth encoded iSAC frame (primary #N) => - // - store primary #N in 1st fragment of RED buffer and send the - // combined packet - // - the transmitted packet contains primary #N (new) and - // reduncancy for packet #(N-1) (old) - // - call GetRedPayload() and store redundancy for packet #N in - // second fragment of RED buffer - // - // For all other codecs, GetRedPayload does nothing and returns -1 => - // redundant data is only a copy. - // - // First combined packet contains : #2 (new) and #1 (old) - // Second combined packet contains: #3 (new) and #2 (old) - // Third combined packet contains : #4 (new) and #3 (old) - // - // Hence, even if every second packet is dropped, perfect - // reconstruction is possible. - fec_active = true; - - has_data_to_send = false; - // Skip the following part for the first packet in a RED session. - if (!is_first_red_) { - // Rearrange stream such that FEC packets are included. - // Replace stream now that we have stored current stream. - memcpy(stream + fragmentation_.fragmentationOffset[1], red_buffer_, - fragmentation_.fragmentationLength[1]); - // Update the fragmentation time difference vector, in number of - // timestamps. - uint16_t time_since_last = static_cast(rtp_timestamp - - last_fec_timestamp_); - - // Update fragmentation vectors. - fragmentation_.fragmentationPlType[1] = - fragmentation_.fragmentationPlType[0]; - fragmentation_.fragmentationTimeDiff[1] = time_since_last; - has_data_to_send = true; - } - - // Insert new packet length. - fragmentation_.fragmentationLength[0] = length_bytes; - - // Insert new packet payload type. - fragmentation_.fragmentationPlType[0] = current_payload_type; - last_fec_timestamp_ = rtp_timestamp; - - // Can be modified by the GetRedPayload() call if iSAC is utilized. - red_length_bytes = length_bytes; - - // A fragmentation header is provided => packetization according to - // RFC 2198 (RTP Payload for Redundant Audio Data) will be used. - // First fragment is the current data (new). - // Second fragment is the previous data (old). - length_bytes = static_cast( - fragmentation_.fragmentationLength[0] + - fragmentation_.fragmentationLength[1]); - - // Get, and store, redundant data from the encoder based on the recently - // encoded frame. - // NOTE - only iSAC contains an implementation; all other codecs does - // nothing and returns -1. - if (codecs_[current_send_codec_idx_]->GetRedPayload( - red_buffer_, - &red_length_bytes) == -1) { - // The codec was not iSAC => use current encoder output as redundant - // data instead (trivial FEC scheme). - memcpy(red_buffer_, stream, red_length_bytes); - } - - is_first_red_ = false; - // Update payload type with RED payload type. - current_payload_type = red_pltype_; - // We have packed 2 payloads. - fragmentation_.fragmentationVectorSize = kNumFecFragmentationVectors; - - // Copy to local variable, as it will be used outside ACM lock. - my_fragmentation.CopyFrom(fragmentation_); - // Store RED length. - fragmentation_.fragmentationLength[1] = red_length_bytes; - } - } - } - - if (has_data_to_send) { - CriticalSectionScoped lock(callback_crit_sect_); - - if (packetization_callback_ != NULL) { - if (fec_active) { - // Callback with payload data, including redundant data (FEC/RED). - packetization_callback_->SendData(frame_type, current_payload_type, - rtp_timestamp, stream, - length_bytes, - &my_fragmentation); - } else { - // Callback with payload data. - packetization_callback_->SendData(frame_type, current_payload_type, - rtp_timestamp, stream, - length_bytes, NULL); - } - } - - if (vad_callback_ != NULL) { - // Callback with VAD decision. - vad_callback_->InFrameType(static_cast(encoding_type)); - } - } - return length_bytes; -} - -///////////////////////////////////////// -// Sender -// - -// Initialize send codec. -int32_t AudioCodingModuleImpl::InitializeSender() { - CriticalSectionScoped lock(acm_crit_sect_); - - // Start with invalid values. - send_codec_registered_ = false; - current_send_codec_idx_ = -1; - send_codec_inst_.plname[0] = '\0'; - - // Delete all encoders to start fresh. - for (int id = 0; id < ACMCodecDB::kMaxNumCodecs; id++) { - if (codecs_[id] != NULL) { - codecs_[id]->DestructEncoder(); - } - } - - // Initialize FEC/RED. - is_first_red_ = true; - if (fec_enabled_ || secondary_encoder_.get() != NULL) { - if (red_buffer_ != NULL) { - memset(red_buffer_, 0, MAX_PAYLOAD_SIZE_BYTE); - } - if (fec_enabled_) { - ResetFragmentation(kNumFecFragmentationVectors); - } else { - ResetFragmentation(0); - } - } - - return 0; -} - -int32_t AudioCodingModuleImpl::ResetEncoder() { - CriticalSectionScoped lock(acm_crit_sect_); - if (!HaveValidEncoder("ResetEncoder")) { - return -1; - } - return codecs_[current_send_codec_idx_]->ResetEncoder(); -} - -void AudioCodingModuleImpl::UnregisterSendCodec() { - CriticalSectionScoped lock(acm_crit_sect_); - send_codec_registered_ = false; - current_send_codec_idx_ = -1; - // If send Codec is unregistered then remove the secondary codec as well. - if (secondary_encoder_.get() != NULL) - secondary_encoder_.reset(); - return; -} - -ACMGenericCodec* AudioCodingModuleImpl::CreateCodec(const CodecInst& codec) { - ACMGenericCodec* my_codec = NULL; - - my_codec = ACMCodecDB::CreateCodecInstance(&codec); - if (my_codec == NULL) { - // Error, could not create the codec. - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "ACMCodecDB::CreateCodecInstance() failed in CreateCodec()"); - return my_codec; - } - my_codec->SetUniqueID(id_); - my_codec->SetNetEqDecodeLock(neteq_.DecodeLock()); - - return my_codec; -} - -// Check if the given codec is a valid to be registered as send codec. -static int IsValidSendCodec(const CodecInst& send_codec, - bool is_primary_encoder, - int acm_id, - int* mirror_id) { - if ((send_codec.channels != 1) && (send_codec.channels != 2)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, acm_id, - "Wrong number of channels (%d, only mono and stereo are " - "supported) for %s encoder", send_codec.channels, - is_primary_encoder ? "primary" : "secondary"); - return -1; - } - - int codec_id = ACMCodecDB::CodecNumber(&send_codec, mirror_id); - if (codec_id < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, acm_id, - "Invalid settings for the send codec."); - return -1; - } - - // TODO(tlegrand): Remove this check. Already taken care of in - // ACMCodecDB::CodecNumber(). - // Check if the payload-type is valid - if (!ACMCodecDB::ValidPayloadType(send_codec.pltype)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, acm_id, - "Invalid payload-type %d for %s.", send_codec.pltype, - send_codec.plname); - return -1; - } - - // Telephone-event cannot be a send codec. - if (!STR_CASE_CMP(send_codec.plname, "telephone-event")) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, acm_id, - "telephone-event cannot be a send codec"); - *mirror_id = -1; - return -1; - } - - if (ACMCodecDB::codec_settings_[codec_id].channel_support - < send_codec.channels) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, acm_id, - "%d number of channels not supportedn for %s.", - send_codec.channels, send_codec.plname); - *mirror_id = -1; - return -1; - } - - if (!is_primary_encoder) { - // If registering the secondary encoder, then RED and CN are not valid - // choices as encoder. - if (IsCodecRED(&send_codec)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, acm_id, - "RED cannot be secondary codec"); - *mirror_id = -1; - return -1; - } - - if (IsCodecCN(&send_codec)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, acm_id, - "DTX cannot be secondary codec"); - *mirror_id = -1; - return -1; - } - } - return codec_id; -} - -int AudioCodingModuleImpl::RegisterSecondarySendCodec( - const CodecInst& send_codec) { - CriticalSectionScoped lock(acm_crit_sect_); - if (!send_codec_registered_) { - return -1; - } - // Primary and Secondary codecs should have the same sampling rates. - if (send_codec.plfreq != send_codec_inst_.plfreq) { - return -1; - } - int mirror_id; - int codec_id = IsValidSendCodec(send_codec, false, id_, &mirror_id); - if (codec_id < 0) { - return -1; - } - ACMGenericCodec* encoder = CreateCodec(send_codec); - WebRtcACMCodecParams codec_params; - // Initialize the codec before registering. For secondary codec VAD & DTX are - // disabled. - memcpy(&(codec_params.codec_inst), &send_codec, sizeof(CodecInst)); - codec_params.enable_vad = false; - codec_params.enable_dtx = false; - codec_params.vad_mode = VADNormal; - // Force initialization. - if (encoder->InitEncoder(&codec_params, true) < 0) { - // Could not initialize, therefore cannot be registered. - delete encoder; - return -1; - } - secondary_encoder_.reset(encoder); - memcpy(&secondary_send_codec_inst_, &send_codec, sizeof(send_codec)); - - // Disable VAD & DTX. - SetVADSafe(false, false, VADNormal); - - // Cleaning. - if (red_buffer_) { - memset(red_buffer_, 0, MAX_PAYLOAD_SIZE_BYTE); - } - ResetFragmentation(0); - return 0; -} - -void AudioCodingModuleImpl::UnregisterSecondarySendCodec() { - CriticalSectionScoped lock(acm_crit_sect_); - if (secondary_encoder_.get() == NULL) { - return; - } - secondary_encoder_.reset(); - ResetFragmentation(0); -} - -int AudioCodingModuleImpl::SecondarySendCodec( - CodecInst* secondary_codec) const { - CriticalSectionScoped lock(acm_crit_sect_); - if (secondary_encoder_.get() == NULL) { - return -1; - } - memcpy(secondary_codec, &secondary_send_codec_inst_, - sizeof(secondary_send_codec_inst_)); - return 0; -} - -// Can be called multiple times for Codec, CNG, RED. -int32_t AudioCodingModuleImpl::RegisterSendCodec( - const CodecInst& send_codec) { - int mirror_id; - int codec_id = IsValidSendCodec(send_codec, true, id_, &mirror_id); - - CriticalSectionScoped lock(acm_crit_sect_); - - // Check for reported errors from function IsValidSendCodec(). - if (codec_id < 0) { - if (!send_codec_registered_) { - // This values has to be NULL if there is no codec registered. - current_send_codec_idx_ = -1; - } - return -1; - } - - // RED can be registered with other payload type. If not registered a default - // payload type is used. - if (IsCodecRED(&send_codec)) { - // TODO(tlegrand): Remove this check. Already taken care of in - // ACMCodecDB::CodecNumber(). - // Check if the payload-type is valid - if (!ACMCodecDB::ValidPayloadType(send_codec.pltype)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Invalid payload-type %d for %s.", send_codec.pltype, - send_codec.plname); - return -1; - } - // Set RED payload type. - red_pltype_ = static_cast(send_codec.pltype); - return 0; - } - - // CNG can be registered with other payload type. If not registered the - // default payload types from codec database will be used. - if (IsCodecCN(&send_codec)) { - // CNG is registered. - switch (send_codec.plfreq) { - case 8000: { - cng_nb_pltype_ = static_cast(send_codec.pltype); - break; - } - case 16000: { - cng_wb_pltype_ = static_cast(send_codec.pltype); - break; - } - case 32000: { - cng_swb_pltype_ = static_cast(send_codec.pltype); - break; - } - case 48000: { - cng_fb_pltype_ = static_cast(send_codec.pltype); - break; - } - default: { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "RegisterSendCodec() failed, invalid frequency for CNG " - "registration"); - return -1; - } - } - return 0; - } - - // Set Stereo, and make sure VAD and DTX is turned off. - if (send_codec.channels == 2) { - stereo_send_ = true; - if (vad_enabled_ || dtx_enabled_) { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, id_, - "VAD/DTX is turned off, not supported when sending stereo."); - } - vad_enabled_ = false; - dtx_enabled_ = false; - } else { - stereo_send_ = false; - } - - // Check if the codec is already registered as send codec. - bool is_send_codec; - if (send_codec_registered_) { - int send_codec_mirror_id; - int send_codec_id = ACMCodecDB::CodecNumber(&send_codec_inst_, - &send_codec_mirror_id); - assert(send_codec_id >= 0); - is_send_codec = (send_codec_id == codec_id) || - (mirror_id == send_codec_mirror_id); - } else { - is_send_codec = false; - } - - // If there is secondary codec registered and the new send codec has a - // sampling rate different than that of secondary codec, then unregister the - // secondary codec. - if (secondary_encoder_.get() != NULL && - secondary_send_codec_inst_.plfreq != send_codec.plfreq) { - secondary_encoder_.reset(); - ResetFragmentation(0); - } - - // If new codec, or new settings, register. - if (!is_send_codec) { - if (codecs_[mirror_id] == NULL) { - codecs_[mirror_id] = CreateCodec(send_codec); - if (codecs_[mirror_id] == NULL) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Cannot Create the codec"); - return -1; - } - mirror_codec_idx_[mirror_id] = mirror_id; - } - - if (mirror_id != codec_id) { - codecs_[codec_id] = codecs_[mirror_id]; - mirror_codec_idx_[codec_id] = mirror_id; - } - - ACMGenericCodec* codec_ptr = codecs_[codec_id]; - WebRtcACMCodecParams codec_params; - - memcpy(&(codec_params.codec_inst), &send_codec, sizeof(CodecInst)); - codec_params.enable_vad = vad_enabled_; - codec_params.enable_dtx = dtx_enabled_; - codec_params.vad_mode = vad_mode_; - // Force initialization. - if (codec_ptr->InitEncoder(&codec_params, true) < 0) { - // Could not initialize the encoder. - - // Check if already have a registered codec. - // Depending on that different messages are logged. - if (!send_codec_registered_) { - current_send_codec_idx_ = -1; - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Cannot Initialize the encoder No Encoder is registered"); - } else { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Cannot Initialize the encoder, continue encoding with " - "the previously registered codec"); - } - return -1; - } - - // Update states. - dtx_enabled_ = codec_params.enable_dtx; - vad_enabled_ = codec_params.enable_vad; - vad_mode_ = codec_params.vad_mode; - - // Everything is fine so we can replace the previous codec with this one. - if (send_codec_registered_) { - // If we change codec we start fresh with FEC. - // This is not strictly required by the standard. - is_first_red_ = true; - - codec_ptr->SetVAD(&dtx_enabled_, &vad_enabled_, &vad_mode_); - } - - current_send_codec_idx_ = codec_id; - send_codec_registered_ = true; - memcpy(&send_codec_inst_, &send_codec, sizeof(CodecInst)); - previous_pltype_ = send_codec_inst_.pltype; - return 0; - } else { - // If codec is the same as already registered check if any parameters - // has changed compared to the current values. - // If any parameter is valid then apply it and record. - bool force_init = false; - - if (mirror_id != codec_id) { - codecs_[codec_id] = codecs_[mirror_id]; - mirror_codec_idx_[codec_id] = mirror_id; - } - - // Check the payload type. - if (send_codec.pltype != send_codec_inst_.pltype) { - // At this point check if the given payload type is valid. - // Record it later when the sampling frequency is changed - // successfully. - if (!ACMCodecDB::ValidPayloadType(send_codec.pltype)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Out of range payload type"); - return -1; - } - } - - // If there is a codec that ONE instance of codec supports multiple - // sampling frequencies, then we need to take care of it here. - // one such a codec is iSAC. Both WB and SWB are encoded and decoded - // with one iSAC instance. Therefore, we need to update the encoder - // frequency if required. - if (send_codec_inst_.plfreq != send_codec.plfreq) { - force_init = true; - - // If sampling frequency is changed we have to start fresh with RED. - is_first_red_ = true; - } - - // If packet size or number of channels has changed, we need to - // re-initialize the encoder. - if (send_codec_inst_.pacsize != send_codec.pacsize) { - force_init = true; - } - if (send_codec_inst_.channels != send_codec.channels) { - force_init = true; - } - - if (force_init) { - WebRtcACMCodecParams codec_params; - - memcpy(&(codec_params.codec_inst), &send_codec, sizeof(CodecInst)); - codec_params.enable_vad = vad_enabled_; - codec_params.enable_dtx = dtx_enabled_; - codec_params.vad_mode = vad_mode_; - - // Force initialization. - if (codecs_[current_send_codec_idx_]->InitEncoder(&codec_params, - true) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Could not change the codec packet-size."); - return -1; - } - - send_codec_inst_.plfreq = send_codec.plfreq; - send_codec_inst_.pacsize = send_codec.pacsize; - send_codec_inst_.channels = send_codec.channels; - } - - // If the change of sampling frequency has been successful then - // we store the payload-type. - send_codec_inst_.pltype = send_codec.pltype; - - // Check if a change in Rate is required. - if (send_codec.rate != send_codec_inst_.rate) { - if (codecs_[codec_id]->SetBitRate(send_codec.rate) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Could not change the codec rate."); - return -1; - } - send_codec_inst_.rate = send_codec.rate; - } - previous_pltype_ = send_codec_inst_.pltype; - - return 0; - } -} - -// Get current send codec. -int32_t AudioCodingModuleImpl::SendCodec( - CodecInst* current_codec) const { - WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_, - "SendCodec()"); - CriticalSectionScoped lock(acm_crit_sect_); - - assert(current_codec); - if (!send_codec_registered_) { - WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_, - "SendCodec Failed, no codec is registered"); - - return -1; - } - WebRtcACMCodecParams encoder_param; - codecs_[current_send_codec_idx_]->EncoderParams(&encoder_param); - encoder_param.codec_inst.pltype = send_codec_inst_.pltype; - memcpy(current_codec, &(encoder_param.codec_inst), sizeof(CodecInst)); - - return 0; -} - -// Get current send frequency. -int32_t AudioCodingModuleImpl::SendFrequency() const { - WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_, - "SendFrequency()"); - CriticalSectionScoped lock(acm_crit_sect_); - - if (!send_codec_registered_) { - WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_, - "SendFrequency Failed, no codec is registered"); - - return -1; - } - - return send_codec_inst_.plfreq; -} - -// Get encode bitrate. -// Adaptive rate codecs return their current encode target rate, while other -// codecs return there longterm avarage or their fixed rate. -int32_t AudioCodingModuleImpl::SendBitrate() const { - CriticalSectionScoped lock(acm_crit_sect_); - - if (!send_codec_registered_) { - WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_, - "SendBitrate Failed, no codec is registered"); - - return -1; - } - - WebRtcACMCodecParams encoder_param; - codecs_[current_send_codec_idx_]->EncoderParams(&encoder_param); - - return encoder_param.codec_inst.rate; -} - -// Set available bandwidth, inform the encoder about the estimated bandwidth -// received from the remote party. -int32_t AudioCodingModuleImpl::SetReceivedEstimatedBandwidth( - const int32_t bw) { - return codecs_[current_send_codec_idx_]->SetEstimatedBandwidth(bw); -} - -// Register a transport callback which will be called to deliver -// the encoded buffers. -int32_t AudioCodingModuleImpl::RegisterTransportCallback( - AudioPacketizationCallback* transport) { - CriticalSectionScoped lock(callback_crit_sect_); - packetization_callback_ = transport; - return 0; -} - -// Add 10MS of raw (PCM) audio data to the encoder. -int32_t AudioCodingModuleImpl::Add10MsData( - const AudioFrame& audio_frame) { - if (audio_frame.samples_per_channel_ <= 0) { - assert(false); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Cannot Add 10 ms audio, payload length is negative or " - "zero"); - return -1; - } - - if (audio_frame.sample_rate_hz_ > 48000) { - assert(false); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Cannot Add 10 ms audio, input frequency not valid"); - return -1; - } - - // If the length and frequency matches. We currently just support raw PCM. - if ((audio_frame.sample_rate_hz_ / 100) - != audio_frame.samples_per_channel_) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Cannot Add 10 ms audio, input frequency and length doesn't" - " match"); - return -1; - } - - if (audio_frame.num_channels_ != 1 && audio_frame.num_channels_ != 2) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Cannot Add 10 ms audio, invalid number of channels."); - return -1; - } - - CriticalSectionScoped lock(acm_crit_sect_); - // Do we have a codec registered? - if (!HaveValidEncoder("Add10MsData")) { - return -1; - } - - const AudioFrame* ptr_frame; - // Perform a resampling, also down-mix if it is required and can be - // performed before resampling (a down mix prior to resampling will take - // place if both primary and secondary encoders are mono and input is in - // stereo). - if (PreprocessToAddData(audio_frame, &ptr_frame) < 0) { - return -1; - } - TRACE_EVENT_ASYNC_BEGIN1("webrtc", "Audio", ptr_frame->timestamp_, - "now", clock_->TimeInMilliseconds()); - - // Check whether we need an up-mix or down-mix? - bool remix = ptr_frame->num_channels_ != send_codec_inst_.channels; - if (secondary_encoder_.get() != NULL) { - remix = remix || - (ptr_frame->num_channels_ != secondary_send_codec_inst_.channels); - } - - // If a re-mix is required (up or down), this buffer will store re-mixed - // version of the input. - int16_t buffer[WEBRTC_10MS_PCM_AUDIO]; - if (remix) { - if (ptr_frame->num_channels_ == 1) { - if (UpMix(*ptr_frame, WEBRTC_10MS_PCM_AUDIO, buffer) < 0) - return -1; - } else { - if (DownMix(*ptr_frame, WEBRTC_10MS_PCM_AUDIO, buffer) < 0) - return -1; - } - } - - // When adding data to encoders this pointer is pointing to an audio buffer - // with correct number of channels. - const int16_t* ptr_audio = ptr_frame->data_; - - // For pushing data to primary, point the |ptr_audio| to correct buffer. - if (send_codec_inst_.channels != ptr_frame->num_channels_) - ptr_audio = buffer; - - if (codecs_[current_send_codec_idx_]->Add10MsData( - ptr_frame->timestamp_, ptr_audio, ptr_frame->samples_per_channel_, - send_codec_inst_.channels) < 0) - return -1; - - if (secondary_encoder_.get() != NULL) { - // For pushing data to secondary, point the |ptr_audio| to correct buffer. - ptr_audio = ptr_frame->data_; - if (secondary_send_codec_inst_.channels != ptr_frame->num_channels_) - ptr_audio = buffer; - - if (secondary_encoder_->Add10MsData( - ptr_frame->timestamp_, ptr_audio, ptr_frame->samples_per_channel_, - secondary_send_codec_inst_.channels) < 0) - return -1; - } - - return 0; -} - -// Perform a resampling and down-mix if required. We down-mix only if -// encoder is mono and input is stereo. In case of dual-streaming, both -// encoders has to be mono for down-mix to take place. -// |*ptr_out| will point to the pre-processed audio-frame. If no pre-processing -// is required, |*ptr_out| points to |in_frame|. -int AudioCodingModuleImpl::PreprocessToAddData(const AudioFrame& in_frame, - const AudioFrame** ptr_out) { - // Primary and secondary (if exists) should have the same sampling rate. - assert((secondary_encoder_.get() != NULL) ? - secondary_send_codec_inst_.plfreq == send_codec_inst_.plfreq : true); - - bool resample = static_cast(in_frame.sample_rate_hz_) != - send_codec_inst_.plfreq; - - // This variable is true if primary codec and secondary codec (if exists) - // are both mono and input is stereo. - bool down_mix; - if (secondary_encoder_.get() != NULL) { - down_mix = (in_frame.num_channels_ == 2) && - (send_codec_inst_.channels == 1) && - (secondary_send_codec_inst_.channels == 1); - } else { - down_mix = (in_frame.num_channels_ == 2) && - (send_codec_inst_.channels == 1); - } - - if (!down_mix && !resample) { - // No pre-processing is required. - last_in_timestamp_ = in_frame.timestamp_; - last_timestamp_ = in_frame.timestamp_; - *ptr_out = &in_frame; - return 0; - } - - *ptr_out = &preprocess_frame_; - preprocess_frame_.num_channels_ = in_frame.num_channels_; - int16_t audio[WEBRTC_10MS_PCM_AUDIO]; - const int16_t* src_ptr_audio = in_frame.data_; - int16_t* dest_ptr_audio = preprocess_frame_.data_; - if (down_mix) { - // If a resampling is required the output of a down-mix is written into a - // local buffer, otherwise, it will be written to the output frame. - if (resample) - dest_ptr_audio = audio; - if (DownMix(in_frame, WEBRTC_10MS_PCM_AUDIO, dest_ptr_audio) < 0) - return -1; - preprocess_frame_.num_channels_ = 1; - // Set the input of the resampler is the down-mixed signal. - src_ptr_audio = audio; - } - - preprocess_frame_.timestamp_ = in_frame.timestamp_; - preprocess_frame_.samples_per_channel_ = in_frame.samples_per_channel_; - preprocess_frame_.sample_rate_hz_ = in_frame.sample_rate_hz_; - // If it is required, we have to do a resampling. - if (resample) { - // The result of the resampler is written to output frame. - dest_ptr_audio = preprocess_frame_.data_; - - uint32_t timestamp_diff; - - // Calculate the timestamp of this frame. - if (last_in_timestamp_ > in_frame.timestamp_) { - // A wrap around has happened. - timestamp_diff = (static_cast(0xFFFFFFFF) - last_in_timestamp_) - + in_frame.timestamp_; - } else { - timestamp_diff = in_frame.timestamp_ - last_in_timestamp_; - } - preprocess_frame_.timestamp_ = last_timestamp_ + - static_cast(timestamp_diff * - (static_cast(send_codec_inst_.plfreq) / - static_cast(in_frame.sample_rate_hz_))); - - preprocess_frame_.samples_per_channel_ = input_resampler_.Resample10Msec( - src_ptr_audio, in_frame.sample_rate_hz_, dest_ptr_audio, - send_codec_inst_.plfreq, preprocess_frame_.num_channels_); - - if (preprocess_frame_.samples_per_channel_ < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Cannot add 10 ms audio, resampling failed"); - return -1; - } - preprocess_frame_.sample_rate_hz_ = send_codec_inst_.plfreq; - } - last_in_timestamp_ = in_frame.timestamp_; - last_timestamp_ = preprocess_frame_.timestamp_; - - return 0; -} - -///////////////////////////////////////// -// (FEC) Forward Error Correction -// - -bool AudioCodingModuleImpl::FECStatus() const { - CriticalSectionScoped lock(acm_crit_sect_); - return fec_enabled_; -} - -// Configure FEC status i.e on/off. -int32_t -AudioCodingModuleImpl::SetFECStatus( -#ifdef WEBRTC_CODEC_RED - const bool enable_fec) { - CriticalSectionScoped lock(acm_crit_sect_); - - if (fec_enabled_ != enable_fec) { - // Reset the RED buffer. - memset(red_buffer_, 0, MAX_PAYLOAD_SIZE_BYTE); - - // Reset fragmentation buffers. - ResetFragmentation(kNumFecFragmentationVectors); - // Set fec_enabled_. - fec_enabled_ = enable_fec; - } - is_first_red_ = true; // Make sure we restart FEC. - return 0; -#else - const bool /* enable_fec */) { - fec_enabled_ = false; - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, id_, - " WEBRTC_CODEC_RED is undefined => fec_enabled_ = %d", - fec_enabled_); - return -1; -#endif -} - -///////////////////////////////////////// -// (VAD) Voice Activity Detection -// -int32_t AudioCodingModuleImpl::SetVAD(bool enable_dtx, bool enable_vad, - ACMVADMode mode) { - CriticalSectionScoped lock(acm_crit_sect_); - return SetVADSafe(enable_dtx, enable_vad, mode); -} - -int AudioCodingModuleImpl::SetVADSafe(bool enable_dtx, bool enable_vad, - ACMVADMode mode) { - // Sanity check of the mode. - if ((mode != VADNormal) && (mode != VADLowBitrate) - && (mode != VADAggr) && (mode != VADVeryAggr)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Invalid VAD Mode %d, no change is made to VAD/DTX status", - static_cast(mode)); - return -1; - } - - // Check that the send codec is mono. We don't support VAD/DTX for stereo - // sending. - if ((enable_dtx || enable_vad) && stereo_send_) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "VAD/DTX not supported for stereo sending."); - dtx_enabled_ = false; - vad_enabled_ = false; - vad_mode_ = mode; - return -1; - } - - // We don't support VAD/DTX when dual-streaming is enabled, i.e. - // secondary-encoder is registered. - if ((enable_dtx || enable_vad) && secondary_encoder_.get() != NULL) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "VAD/DTX not supported when dual-streaming is enabled."); - dtx_enabled_ = false; - vad_enabled_ = false; - vad_mode_ = mode; - return -1; - } - - // Store VAD/DTX settings. Values can be changed in the call to "SetVAD" - // below. - dtx_enabled_ = enable_dtx; - vad_enabled_ = enable_vad; - vad_mode_ = mode; - - // If a send codec is registered, set VAD/DTX for the codec. - if (HaveValidEncoder("SetVAD")) { - if (codecs_[current_send_codec_idx_]->SetVAD(&dtx_enabled_, &vad_enabled_, - &vad_mode_) < 0) { - // SetVAD failed. - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "SetVAD failed"); - dtx_enabled_ = false; - vad_enabled_ = false; - return -1; - } - } - - return 0; -} - -// Get VAD/DTX settings. -// TODO(tlegrand): Change this method to void. -int32_t AudioCodingModuleImpl::VAD(bool* dtx_enabled, bool* vad_enabled, - ACMVADMode* mode) const { - CriticalSectionScoped lock(acm_crit_sect_); - - *dtx_enabled = dtx_enabled_; - *vad_enabled = vad_enabled_; - *mode = vad_mode_; - - return 0; -} - -///////////////////////////////////////// -// Receiver -// - -int32_t AudioCodingModuleImpl::InitializeReceiver() { - CriticalSectionScoped lock(acm_crit_sect_); - return InitializeReceiverSafe(); -} - -// Initialize receiver, resets codec database etc. -int32_t AudioCodingModuleImpl::InitializeReceiverSafe() { - initial_delay_ms_ = 0; - num_packets_accumulated_ = 0; - num_bytes_accumulated_ = 0; - accumulated_audio_ms_ = 0; - first_payload_received_ = 0; - last_incoming_send_timestamp_ = 0; - track_neteq_buffer_ = false; - playout_ts_ = 0; - // If the receiver is already initialized then we want to destroy any - // existing decoders. After a call to this function, we should have a clean - // start-up. - if (receiver_initialized_) { - for (int i = 0; i < ACMCodecDB::kNumCodecs; i++) { - if (UnregisterReceiveCodecSafe(i) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "InitializeReceiver() failed, Could not unregister codec"); - return -1; - } - } - } - if (neteq_.Init() != 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "InitializeReceiver() failed, Could not initialize NetEQ"); - return -1; - } - neteq_.set_id(id_); - if (neteq_.AllocatePacketBuffer(ACMCodecDB::NetEQDecoders(), - ACMCodecDB::kNumCodecs) != 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "NetEQ cannot allocate_packet Buffer"); - return -1; - } - - // Register RED and CN. - for (int i = 0; i < ACMCodecDB::kNumCodecs; i++) { - if (IsCodecRED(i) || IsCodecCN(i)) { - if (RegisterRecCodecMSSafe(ACMCodecDB::database_[i], i, i, - ACMNetEQ::kMasterJb) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Cannot register master codec."); - return -1; - } - registered_pltypes_[i] = ACMCodecDB::database_[i].pltype; - } - } - - receiver_initialized_ = true; - return 0; -} - -// Reset the decoder state. -int32_t AudioCodingModuleImpl::ResetDecoder() { - CriticalSectionScoped lock(acm_crit_sect_); - - for (int id = 0; id < ACMCodecDB::kMaxNumCodecs; id++) { - if ((codecs_[id] != NULL) && (registered_pltypes_[id] != -1)) { - if (codecs_[id]->ResetDecoder(registered_pltypes_[id]) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "ResetDecoder failed:"); - return -1; - } - } - } - return neteq_.FlushBuffers(); -} - -// Get current receive frequency. -int32_t AudioCodingModuleImpl::ReceiveFrequency() const { - WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_, - "ReceiveFrequency()"); - WebRtcACMCodecParams codec_params; - - CriticalSectionScoped lock(acm_crit_sect_); - if (DecoderParamByPlType(last_recv_audio_codec_pltype_, codec_params) < 0) { - return neteq_.CurrentSampFreqHz(); - } else if (codec_params.codec_inst.plfreq == 48000) { - // TODO(tlegrand): Remove this option when we have full 48 kHz support. - return 32000; - } else { - return codec_params.codec_inst.plfreq; - } -} - -// Get current playout frequency. -int32_t AudioCodingModuleImpl::PlayoutFrequency() const { - WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_, - "PlayoutFrequency()"); - - CriticalSectionScoped lock(acm_crit_sect_); - - return neteq_.CurrentSampFreqHz(); -} - -// Register possible receive codecs, can be called multiple times, -// for codecs, CNG (NB, WB and SWB), DTMF, RED. -int32_t AudioCodingModuleImpl::RegisterReceiveCodec( - const CodecInst& receive_codec) { - CriticalSectionScoped lock(acm_crit_sect_); - - if (receive_codec.channels > 2) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "More than 2 audio channel is not supported."); - return -1; - } - - int mirror_id; - int codec_id = ACMCodecDB::ReceiverCodecNumber(&receive_codec, &mirror_id); - - if (codec_id < 0 || codec_id >= ACMCodecDB::kNumCodecs) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Wrong codec params to be registered as receive codec"); - return -1; - } - // Check if the payload-type is valid. - if (!ACMCodecDB::ValidPayloadType(receive_codec.pltype)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Invalid payload-type %d for %s.", receive_codec.pltype, - receive_codec.plname); - return -1; - } - - if (!receiver_initialized_) { - if (InitializeReceiverSafe() < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Cannot initialize reciver, so failed registering a codec."); - return -1; - } - } - - // If codec already registered, unregister. Except for CN where we only - // unregister if payload type is changing. - if ((registered_pltypes_[codec_id] == receive_codec.pltype) - && IsCodecCN(&receive_codec)) { - // Codec already registered as receiver with this payload type. Nothing - // to be done. - return 0; - } else if (registered_pltypes_[codec_id] != -1) { - if (UnregisterReceiveCodecSafe(codec_id) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Cannot register master codec."); - return -1; - } - } - - if (RegisterRecCodecMSSafe(receive_codec, codec_id, mirror_id, - ACMNetEQ::kMasterJb) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Cannot register master codec."); - return -1; - } - - // TODO(andrew): Refactor how the slave is initialized. Can we instead - // always start up a slave and pre-register CN and RED? We should be able - // to get rid of stereo_receive_registered_. - // http://code.google.com/p/webrtc/issues/detail?id=453 - - // Register stereo codecs with the slave, or, if we've had already seen a - // stereo codec, register CN or RED as a special case. - if (receive_codec.channels == 2 || - (stereo_receive_registered_ && (IsCodecCN(&receive_codec) || - IsCodecRED(&receive_codec)))) { - // TODO(andrew): refactor this block to combine with InitStereoSlave(). - - if (!stereo_receive_registered_) { - // This is the first time a stereo codec has been registered. Make - // some stereo preparations. - - // Add a stereo slave. - assert(neteq_.num_slaves() == 0); - if (neteq_.AddSlave(ACMCodecDB::NetEQDecoders(), - ACMCodecDB::kNumCodecs) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Cannot add slave jitter buffer to NetEQ."); - return -1; - } - - // Register any existing CN or RED codecs with the slave and as stereo. - for (int i = 0; i < ACMCodecDB::kNumCodecs; i++) { - if (registered_pltypes_[i] != -1 && (IsCodecRED(i) || IsCodecCN(i))) { - stereo_receive_[i] = true; - - CodecInst codec; - memcpy(&codec, &ACMCodecDB::database_[i], sizeof(CodecInst)); - codec.pltype = registered_pltypes_[i]; - if (RegisterRecCodecMSSafe(codec, i, i, ACMNetEQ::kSlaveJb) < 0) { - WEBRTC_TRACE(kTraceError, kTraceAudioCoding, id_, - "Cannot register slave codec."); - return -1; - } - } - } - } - - if (RegisterRecCodecMSSafe(receive_codec, codec_id, mirror_id, - ACMNetEQ::kSlaveJb) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Cannot register slave codec."); - return -1; - } - - if (!stereo_receive_[codec_id] && - (last_recv_audio_codec_pltype_ == receive_codec.pltype)) { - // The last received payload type is the same as the one we are - // registering. Expected number of channels to receive is one (mono), - // but we are now registering the receiving codec as stereo (number of - // channels is 2). - // Set |last_recv_audio_coded_pltype_| to invalid value to trigger a - // flush in NetEq, and a reset of expected number of channels next time a - // packet is received in AudioCodingModuleImpl::IncomingPacket(). - last_recv_audio_codec_pltype_ = -1; - } - - stereo_receive_[codec_id] = true; - stereo_receive_registered_ = true; - } else { - if (last_recv_audio_codec_pltype_ == receive_codec.pltype && - expected_channels_ == 2) { - // The last received payload type is the same as the one we are - // registering. Expected number of channels to receive is two (stereo), - // but we are now registering the receiving codec as mono (number of - // channels is 1). - // Set |last_recv_audio_coded_pl_type_| to invalid value to trigger a - // flush in NetEq, and a reset of expected number of channels next time a - // packet is received in AudioCodingModuleImpl::IncomingPacket(). - last_recv_audio_codec_pltype_ = -1; - } - stereo_receive_[codec_id] = false; - } - - registered_pltypes_[codec_id] = receive_codec.pltype; - - if (IsCodecRED(&receive_codec)) { - receive_red_pltype_ = receive_codec.pltype; - } - return 0; -} - -int32_t AudioCodingModuleImpl::RegisterRecCodecMSSafe( - const CodecInst& receive_codec, int16_t codec_id, - int16_t mirror_id, ACMNetEQ::JitterBuffer jitter_buffer) { - ACMGenericCodec** codecs; - if (jitter_buffer == ACMNetEQ::kMasterJb) { - codecs = &codecs_[0]; - } else if (jitter_buffer == ACMNetEQ::kSlaveJb) { - codecs = &slave_codecs_[0]; - if (codecs_[codec_id]->IsTrueStereoCodec()) { - // True stereo codecs need to use the same codec memory - // for both master and slave. - slave_codecs_[mirror_id] = codecs_[mirror_id]; - mirror_codec_idx_[mirror_id] = mirror_id; - } - } else { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "RegisterReceiveCodecMSSafe failed, jitter_buffer is neither " - "master or slave "); - return -1; - } - - if (codecs[mirror_id] == NULL) { - codecs[mirror_id] = CreateCodec(receive_codec); - if (codecs[mirror_id] == NULL) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Cannot create codec to register as receive codec"); - return -1; - } - mirror_codec_idx_[mirror_id] = mirror_id; - } - if (mirror_id != codec_id) { - codecs[codec_id] = codecs[mirror_id]; - mirror_codec_idx_[codec_id] = mirror_id; - } - - codecs[codec_id]->SetIsMaster(jitter_buffer == ACMNetEQ::kMasterJb); - - int16_t status = 0; - WebRtcACMCodecParams codec_params; - memcpy(&(codec_params.codec_inst), &receive_codec, sizeof(CodecInst)); - codec_params.enable_vad = false; - codec_params.enable_dtx = false; - codec_params.vad_mode = VADNormal; - if (!codecs[codec_id]->DecoderInitialized()) { - // Force initialization. - status = codecs[codec_id]->InitDecoder(&codec_params, true); - if (status < 0) { - // Could not initialize the decoder, we don't want to - // continue if we could not initialize properly. - WEBRTC_TRACE( - webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "could not initialize the receive codec, codec not registered"); - - return -1; - } - } else if (mirror_id != codec_id) { - // Currently this only happens for iSAC. - // We have to store the decoder parameters. - codecs[codec_id]->SaveDecoderParam(&codec_params); - } - - if (codecs[codec_id]->RegisterInNetEq(&neteq_, receive_codec) != 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Receive codec could not be registered in NetEQ"); - return -1; - } - // Guarantee that the same payload-type that is - // registered in NetEQ is stored in the codec. - codecs[codec_id]->SaveDecoderParam(&codec_params); - - return status; -} - -// Get current received codec. -int32_t AudioCodingModuleImpl::ReceiveCodec( - CodecInst* current_codec) const { - WebRtcACMCodecParams decoder_param; - CriticalSectionScoped lock(acm_crit_sect_); - - for (int id = 0; id < ACMCodecDB::kMaxNumCodecs; id++) { - if (codecs_[id] != NULL) { - if (codecs_[id]->DecoderInitialized()) { - if (codecs_[id]->DecoderParams(&decoder_param, - last_recv_audio_codec_pltype_)) { - memcpy(current_codec, &decoder_param.codec_inst, - sizeof(CodecInst)); - return 0; - } - } - } - } - - // If we are here then we haven't found any codec. Set codec pltype to -1 to - // indicate that the structure is invalid and return -1. - current_codec->pltype = -1; - return -1; -} - -// Incoming packet from network parsed and ready for decode. -int32_t AudioCodingModuleImpl::IncomingPacket( - const uint8_t* incoming_payload, - const int32_t payload_length, - const WebRtcRTPHeader& rtp_info) { - WebRtcRTPHeader rtp_header; - - memcpy(&rtp_header, &rtp_info, sizeof(WebRtcRTPHeader)); - - if (payload_length < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "IncomingPacket() Error, payload-length cannot be negative"); - return -1; - } - - { - // Store the payload Type. This will be used to retrieve "received codec" - // and "received frequency." - CriticalSectionScoped lock(acm_crit_sect_); - - // Check there are packets missed between the last injected packet, and the - // latest received packet. If so and we are in AV-sync mode then we would - // like to fill the gap. Shouldn't be the first payload. - if (av_sync_ && first_payload_received_ && - rtp_info.header.sequenceNumber > last_sequence_number_ + 1) { - // If the last packet pushed was sync-packet account for all missing - // packets. Otherwise leave some room for PLC. - if (last_packet_was_sync_) { - while (rtp_info.header.sequenceNumber > last_sequence_number_ + 2) { - PushSyncPacketSafe(); - } - } else { - // Leave two packet room for NetEq perform PLC. - if (rtp_info.header.sequenceNumber > last_sequence_number_ + 3) { - last_sequence_number_ += 2; - last_incoming_send_timestamp_ += last_timestamp_diff_ * 2; - last_receive_timestamp_ += 2 * last_timestamp_diff_; - while (rtp_info.header.sequenceNumber > last_sequence_number_ + 1) - PushSyncPacketSafe(); - } - } - } - - uint8_t my_payload_type; - - // Check if this is an RED payload. - if (rtp_info.header.payloadType == receive_red_pltype_) { - // Get the primary payload-type. - my_payload_type = incoming_payload[0] & 0x7F; - } else { - my_payload_type = rtp_info.header.payloadType; - } - - // If payload is audio, check if received payload is different from - // previous. - if (!rtp_info.type.Audio.isCNG) { - // This is Audio not CNG. - - if (my_payload_type != last_recv_audio_codec_pltype_) { - // We detect a change in payload type. It is necessary for iSAC - // we are going to use ONE iSAC instance for decoding both WB and - // SWB payloads. If payload is changed there might be a need to reset - // sampling rate of decoder. depending what we have received "now". - for (int i = 0; i < ACMCodecDB::kMaxNumCodecs; i++) { - if (registered_pltypes_[i] == my_payload_type) { - if (UpdateUponReceivingCodec(i) != 0) - return -1; - break; - } - } - // Codec is changed, there might be a jump in timestamp, therefore, - // we have to reset some variables that track NetEq buffer. - if (track_neteq_buffer_ || av_sync_) { - last_incoming_send_timestamp_ = rtp_info.header.timestamp; - } - - if (nack_enabled_) { - assert(nack_.get()); - // Codec is changed, reset NACK and update sampling rate. - nack_->Reset(); - nack_->UpdateSampleRate( - ACMCodecDB::database_[current_receive_codec_idx_].plfreq); - } - } - last_recv_audio_codec_pltype_ = my_payload_type; - } - - // Current timestamp based on the receiver sampling frequency. - last_receive_timestamp_ = NowTimestamp(current_receive_codec_idx_); - - if (nack_enabled_) { - assert(nack_.get()); - nack_->UpdateLastReceivedPacket(rtp_header.header.sequenceNumber, - rtp_header.header.timestamp); - } - } - - int per_neteq_payload_length = payload_length; - // Split the payload for stereo packets, so that first half of payload - // vector holds left channel, and second half holds right channel. - if (expected_channels_ == 2) { - if (!rtp_info.type.Audio.isCNG) { - // Create a new vector for the payload, maximum payload size. - int32_t length = payload_length; - uint8_t payload[kMaxPacketSize]; - assert(payload_length <= kMaxPacketSize); - memcpy(payload, incoming_payload, payload_length); - codecs_[current_receive_codec_idx_]->SplitStereoPacket(payload, &length); - rtp_header.type.Audio.channel = 2; - per_neteq_payload_length = length / 2; - // Insert packet into NetEQ. - if (neteq_.RecIn(payload, length, rtp_header, - last_receive_timestamp_) < 0) - return -1; - } else { - // If we receive a CNG packet while expecting stereo, we ignore the - // packet and continue. CNG is not supported for stereo. - return 0; - } - } else { - if (neteq_.RecIn(incoming_payload, payload_length, rtp_header, - last_receive_timestamp_) < 0) - return -1; - } - - { - CriticalSectionScoped lock(acm_crit_sect_); - - // Update buffering uses |last_incoming_send_timestamp_| so it should be - // before the next block. - if (track_neteq_buffer_) - UpdateBufferingSafe(rtp_header, per_neteq_payload_length); - - if (av_sync_) { - if (rtp_info.header.sequenceNumber == last_sequence_number_ + 1) { - last_timestamp_diff_ = rtp_info.header.timestamp - - last_incoming_send_timestamp_; - } - last_sequence_number_ = rtp_info.header.sequenceNumber; - last_ssrc_ = rtp_info.header.ssrc; - last_packet_was_sync_ = false; - } - - if (av_sync_ || track_neteq_buffer_) { - last_incoming_send_timestamp_ = rtp_info.header.timestamp; - } - - // Set the following regardless of tracking NetEq buffer or being in - // AV-sync mode. Only if the received packet is not CNG. - if (!rtp_info.type.Audio.isCNG) - first_payload_received_ = true; - } - return 0; -} - -int AudioCodingModuleImpl::UpdateUponReceivingCodec(int index) { - if (codecs_[index] == NULL) { - WEBRTC_TRACE(kTraceError, kTraceAudioCoding, id_, - "IncomingPacket() error: payload type found but " - "corresponding codec is NULL"); - return -1; - } - codecs_[index]->UpdateDecoderSampFreq(index); - neteq_.set_received_stereo(stereo_receive_[index]); - current_receive_codec_idx_ = index; - - // If we have a change in the expected number of channels, flush packet - // buffers in NetEQ. - if ((stereo_receive_[index] && (expected_channels_ == 1)) || - (!stereo_receive_[index] && (expected_channels_ == 2))) { - neteq_.FlushBuffers(); - codecs_[index]->ResetDecoder(registered_pltypes_[index]); - } - - if (stereo_receive_[index] && (expected_channels_ == 1)) { - // When switching from a mono to stereo codec reset the slave. - if (InitStereoSlave() != 0) - return -1; - } - - // Store number of channels we expect to receive for the current payload type. - if (stereo_receive_[index]) { - expected_channels_ = 2; - } else { - expected_channels_ = 1; - } - - // Reset previous received channel. - prev_received_channel_ = 0; - return 0; -} - -bool AudioCodingModuleImpl::IsCodecForSlave(int index) const { - return (registered_pltypes_[index] != -1 && stereo_receive_[index]); -} - -int AudioCodingModuleImpl::InitStereoSlave() { - neteq_.RemoveSlaves(); - - if (neteq_.AddSlave(ACMCodecDB::NetEQDecoders(), - ACMCodecDB::kNumCodecs) < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Cannot add slave jitter buffer to NetEQ."); - return -1; - } - - // Register all needed codecs with slave. - for (int i = 0; i < ACMCodecDB::kNumCodecs; i++) { - if (codecs_[i] != NULL && IsCodecForSlave(i)) { - WebRtcACMCodecParams decoder_params; - if (codecs_[i]->DecoderParams(&decoder_params, registered_pltypes_[i])) { - if (RegisterRecCodecMSSafe(decoder_params.codec_inst, - i, ACMCodecDB::MirrorID(i), - ACMNetEQ::kSlaveJb) < 0) { - WEBRTC_TRACE(kTraceError, kTraceAudioCoding, id_, - "Cannot register slave codec."); - return -1; - } - } - } - } - return 0; -} - -int AudioCodingModuleImpl::SetMinimumPlayoutDelay(int time_ms) { - { - CriticalSectionScoped lock(acm_crit_sect_); - // Don't let the extra delay modified while accumulating buffers in NetEq. - if (track_neteq_buffer_ && first_payload_received_) - return 0; - } - return neteq_.SetMinimumDelay(time_ms); -} - -int AudioCodingModuleImpl::SetMaximumPlayoutDelay(int time_ms) { - return neteq_.SetMaximumDelay(time_ms); -} - -// Get Dtmf playout status. -bool AudioCodingModuleImpl::DtmfPlayoutStatus() const { -#ifndef WEBRTC_CODEC_AVT - return false; -#else - return neteq_.avt_playout(); -#endif -} - -// Configure Dtmf playout status i.e on/off playout the incoming outband -// Dtmf tone. -int32_t AudioCodingModuleImpl::SetDtmfPlayoutStatus( -#ifndef WEBRTC_CODEC_AVT - const bool /* enable */) { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, id_, - "SetDtmfPlayoutStatus() failed: AVT is not supported."); - return -1; -#else - const bool enable) { - return neteq_.SetAVTPlayout(enable); -#endif -} - -// 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 AudioCodingModuleImpl::DecoderEstimatedBandwidth() const { - CodecInst codec; - int16_t codec_id = -1; - int pltype_wb; - int pltype_swb; - - // Get iSAC settings. - for (int id = 0; id < ACMCodecDB::kNumCodecs; id++) { - // Store codec settings for codec number "codeCntr" in the output struct. - ACMCodecDB::Codec(id, &codec); - - if (!STR_CASE_CMP(codec.plname, "isac")) { - codec_id = 1; - pltype_wb = codec.pltype; - - ACMCodecDB::Codec(id + 1, &codec); - pltype_swb = codec.pltype; - - break; - } - } - - if (codec_id < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "DecoderEstimatedBandwidth failed"); - return -1; - } - - if ((last_recv_audio_codec_pltype_ == pltype_wb) || - (last_recv_audio_codec_pltype_ == pltype_swb)) { - return codecs_[codec_id]->GetEstimatedBandwidth(); - } else { - return -1; - } -} - -// Set playout mode for: voice, fax, or streaming. -int32_t AudioCodingModuleImpl::SetPlayoutMode( - const AudioPlayoutMode mode) { - if ((mode != voice) && (mode != fax) && (mode != streaming) && - (mode != off)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Invalid playout mode."); - return -1; - } - return neteq_.SetPlayoutMode(mode); -} - -// Get playout mode voice, fax. -AudioPlayoutMode AudioCodingModuleImpl::PlayoutMode() const { - return neteq_.playout_mode(); -} - -// Get 10 milliseconds of raw audio data to play out. -// Automatic resample to the requested frequency. -int32_t AudioCodingModuleImpl::PlayoutData10Ms( - int32_t desired_freq_hz, AudioFrame* audio_frame) { - TRACE_EVENT_ASYNC_BEGIN0("webrtc", "ACM::PlayoutData10Ms", this); - bool stereo_mode; - - if (GetSilence(desired_freq_hz, audio_frame)) { - TRACE_EVENT_ASYNC_END1("webrtc", "ACM::PlayoutData10Ms", this, - "silence", true); - return 0; // Silence is generated, return. - } - - // RecOut always returns 10 ms. - if (neteq_.RecOut(audio_frame_) != 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "PlayoutData failed, RecOut Failed"); - return -1; - } - int decoded_seq_num; - uint32_t decoded_timestamp; - bool update_nack = - neteq_.DecodedRtpInfo(&decoded_seq_num, &decoded_timestamp); - - // Master and Slave samples are interleaved starting with Master. - uint16_t receive_freq; - bool tone_detected = false; - int16_t last_detected_tone; - int16_t tone; - - // Limit the scope of ACM Critical section. - { - CriticalSectionScoped lock(acm_crit_sect_); - - audio_frame->num_channels_ = audio_frame_.num_channels_; - audio_frame->vad_activity_ = audio_frame_.vad_activity_; - audio_frame->speech_type_ = audio_frame_.speech_type_; - - stereo_mode = (audio_frame_.num_channels_ > 1); - - receive_freq = static_cast(audio_frame_.sample_rate_hz_); - // Update call statistics. - call_stats_.DecodedByNetEq(audio_frame->speech_type_); - - if (nack_enabled_ && update_nack) { - assert(nack_.get()); - nack_->UpdateLastDecodedPacket(decoded_seq_num, decoded_timestamp); - } - - // If we are in AV-sync and have already received an audio packet, but the - // latest packet is too late, then insert sync packet. - if (av_sync_ && first_payload_received_ && - NowTimestamp(current_receive_codec_idx_) > 5 * last_timestamp_diff_ + - last_receive_timestamp_) { - if (!last_packet_was_sync_) { - // If the last packet inserted has been a regular packet Skip two - // packets to give room for PLC. - last_incoming_send_timestamp_ += 2 * last_timestamp_diff_; - last_sequence_number_ += 2; - last_receive_timestamp_ += 2 * last_timestamp_diff_; - } - - // One sync packet. - if (PushSyncPacketSafe() < 0) - return -1; - } - - if ((receive_freq != desired_freq_hz) && (desired_freq_hz != -1)) { - TRACE_EVENT_ASYNC_END2("webrtc", "ACM::PlayoutData10Ms", this, - "seqnum", decoded_seq_num, - "now", clock_->TimeInMilliseconds()); - // Resample payload_data. - int16_t temp_len = output_resampler_.Resample10Msec( - audio_frame_.data_, receive_freq, audio_frame->data_, - desired_freq_hz, audio_frame_.num_channels_); - - if (temp_len < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "PlayoutData failed, resampler failed"); - return -1; - } - - // Set the payload data length from the resampler. - audio_frame->samples_per_channel_ = static_cast(temp_len); - // Set the sampling frequency. - audio_frame->sample_rate_hz_ = desired_freq_hz; - } else { - TRACE_EVENT_ASYNC_END2("webrtc", "ACM::PlayoutData10Ms", this, - "seqnum", decoded_seq_num, - "now", clock_->TimeInMilliseconds()); - memcpy(audio_frame->data_, audio_frame_.data_, - audio_frame_.samples_per_channel_ * audio_frame->num_channels_ - * sizeof(int16_t)); - // Set the payload length. - audio_frame->samples_per_channel_ = - audio_frame_.samples_per_channel_; - // Set the sampling frequency. - audio_frame->sample_rate_hz_ = receive_freq; - } - - // Tone detection done for master channel. - if (dtmf_detector_ != NULL) { - // Dtmf Detection. - if (audio_frame->sample_rate_hz_ == 8000) { - // Use audio_frame->data_ then Dtmf detector doesn't - // need resampling. - if (!stereo_mode) { - dtmf_detector_->Detect(audio_frame->data_, - audio_frame->samples_per_channel_, - audio_frame->sample_rate_hz_, tone_detected, - tone); - } else { - // We are in 8 kHz so the master channel needs only 80 samples. - int16_t master_channel[80]; - for (int n = 0; n < 80; n++) { - master_channel[n] = audio_frame->data_[n << 1]; - } - dtmf_detector_->Detect(master_channel, - audio_frame->samples_per_channel_, - audio_frame->sample_rate_hz_, tone_detected, - tone); - } - } else { - // Do the detection on the audio that we got from NetEQ (audio_frame_). - if (!stereo_mode) { - dtmf_detector_->Detect(audio_frame_.data_, - audio_frame_.samples_per_channel_, - receive_freq, tone_detected, tone); - } else { - int16_t master_channel[WEBRTC_10MS_PCM_AUDIO]; - for (int n = 0; n < audio_frame_.samples_per_channel_; n++) { - master_channel[n] = audio_frame_.data_[n << 1]; - } - dtmf_detector_->Detect(master_channel, - audio_frame_.samples_per_channel_, - receive_freq, tone_detected, tone); - } - } - } - - // We want to do this while we are in acm_crit_sect_. - // (Doesn't really need to initialize the following - // variable but Linux complains if we don't.) - last_detected_tone = kACMToneEnd; - if (tone_detected) { - last_detected_tone = last_detected_tone_; - last_detected_tone_ = tone; - } - } - - if (tone_detected) { - // We will deal with callback here, so enter callback critical section. - CriticalSectionScoped lock(callback_crit_sect_); - - if (dtmf_callback_ != NULL) { - if (tone != kACMToneEnd) { - // just a tone - dtmf_callback_->IncomingDtmf(static_cast(tone), false); - } else if ((tone == kACMToneEnd) && (last_detected_tone != kACMToneEnd)) { - // The tone is "END" and the previously detected tone is - // not "END," so call fir an end. - dtmf_callback_->IncomingDtmf(static_cast(last_detected_tone), - true); - } - } - } - - audio_frame->id_ = id_; - audio_frame->energy_ = -1; - audio_frame->timestamp_ = 0; - - return 0; -} - -///////////////////////////////////////// -// Statistics -// - -int32_t AudioCodingModuleImpl::NetworkStatistics( - ACMNetworkStatistics* statistics) { - int32_t status; - status = neteq_.NetworkStatistics(statistics); - return status; -} - -void AudioCodingModuleImpl::DestructEncoderInst(void* inst) { - WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, id_, - "DestructEncoderInst()"); - if (!HaveValidEncoder("DestructEncoderInst")) { - return; - } - - codecs_[current_send_codec_idx_]->DestructEncoderInst(inst); -} - -int16_t AudioCodingModuleImpl::AudioBuffer( - WebRtcACMAudioBuff& buffer) { - WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, id_, - "AudioBuffer()"); - if (!HaveValidEncoder("AudioBuffer")) { - return -1; - } - buffer.last_in_timestamp = last_in_timestamp_; - return codecs_[current_send_codec_idx_]->AudioBuffer(buffer); -} - -int16_t AudioCodingModuleImpl::SetAudioBuffer( - WebRtcACMAudioBuff& buffer) { - WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, id_, - "SetAudioBuffer()"); - if (!HaveValidEncoder("SetAudioBuffer")) { - return -1; - } - return codecs_[current_send_codec_idx_]->SetAudioBuffer(buffer); -} - -uint32_t AudioCodingModuleImpl::EarliestTimestamp() const { - WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, id_, - "EarliestTimestamp()"); - if (!HaveValidEncoder("EarliestTimestamp")) { - return -1; - } - return codecs_[current_send_codec_idx_]->EarliestTimestamp(); -} - -int32_t AudioCodingModuleImpl::RegisterVADCallback( - ACMVADCallback* vad_callback) { - WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, id_, - "RegisterVADCallback()"); - CriticalSectionScoped lock(callback_crit_sect_); - vad_callback_ = vad_callback; - return 0; -} - -// TODO(turajs): Remove this API if it is not used. -// TODO(tlegrand): Modify this function to work for stereo, and add tests. -// TODO(turajs): Receive timestamp in this method is incremented by frame-size -// and does not reflect the true receive frame-size. Therefore, subsequent -// jitter computations are not accurate. -int32_t AudioCodingModuleImpl::IncomingPayload( - const uint8_t* incoming_payload, const int32_t payload_length, - const uint8_t payload_type, const uint32_t timestamp) { - if (payload_length < 0) { - // Log error in trace file. - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "IncomingPacket() Error, payload-length cannot be negative"); - return -1; - } - - if (dummy_rtp_header_ == NULL) { - // This is the first time that we are using |dummy_rtp_header_| - // so we have to create it. - WebRtcACMCodecParams codec_params; - dummy_rtp_header_ = new WebRtcRTPHeader; - if (dummy_rtp_header_ == NULL) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "IncomingPayload() Error, out of memory"); - return -1; - } - dummy_rtp_header_->header.payloadType = payload_type; - // Don't matter in this case. - dummy_rtp_header_->header.ssrc = 0; - dummy_rtp_header_->header.markerBit = false; - // Start with random numbers. - dummy_rtp_header_->header.sequenceNumber = rand(); - dummy_rtp_header_->header.timestamp = - (static_cast(rand()) << 16) + - static_cast(rand()); - dummy_rtp_header_->type.Audio.channel = 1; - - if (DecoderParamByPlType(payload_type, codec_params) < 0) { - // We didn't find a codec with the given payload. - // Something is wrong we exit, but we delete |dummy_rtp_header_| - // and set it to NULL to start clean next time. - delete dummy_rtp_header_; - dummy_rtp_header_ = NULL; - return -1; - } - recv_pl_frame_size_smpls_ = codec_params.codec_inst.pacsize; - } - - if (payload_type != dummy_rtp_header_->header.payloadType) { - // Payload type has changed since the last time we might need to - // update the frame-size. - WebRtcACMCodecParams codec_params; - if (DecoderParamByPlType(payload_type, codec_params) < 0) { - // We didn't find a codec with the given payload. - return -1; - } - recv_pl_frame_size_smpls_ = codec_params.codec_inst.pacsize; - dummy_rtp_header_->header.payloadType = payload_type; - } - - if (timestamp > 0) { - dummy_rtp_header_->header.timestamp = timestamp; - } - - // Store the payload Type. this will be used to retrieve "received codec" - // and "received frequency." - last_recv_audio_codec_pltype_ = payload_type; - - last_receive_timestamp_ += recv_pl_frame_size_smpls_; - // Insert in NetEQ. - if (neteq_.RecIn(incoming_payload, payload_length, *dummy_rtp_header_, - last_receive_timestamp_) < 0) { - return -1; - } - - // Get ready for the next payload. - dummy_rtp_header_->header.sequenceNumber++; - dummy_rtp_header_->header.timestamp += recv_pl_frame_size_smpls_; - return 0; -} - -int16_t AudioCodingModuleImpl::DecoderParamByPlType( - const uint8_t payload_type, - WebRtcACMCodecParams& codec_params) const { - CriticalSectionScoped lock(acm_crit_sect_); - for (int16_t id = 0; id < ACMCodecDB::kMaxNumCodecs; - id++) { - if (codecs_[id] != NULL) { - if (codecs_[id]->DecoderInitialized()) { - if (codecs_[id]->DecoderParams(&codec_params, payload_type)) { - return 0; - } - } - } - } - // If we are here it means that we could not find a - // codec with that payload type. reset the values to - // not acceptable values and return -1. - codec_params.codec_inst.plname[0] = '\0'; - codec_params.codec_inst.pacsize = 0; - codec_params.codec_inst.rate = 0; - codec_params.codec_inst.pltype = -1; - return -1; -} - -int16_t AudioCodingModuleImpl::DecoderListIDByPlName( - const char* name, const uint16_t frequency) const { - WebRtcACMCodecParams codec_params; - CriticalSectionScoped lock(acm_crit_sect_); - for (int16_t id = 0; id < ACMCodecDB::kMaxNumCodecs; id++) { - if ((codecs_[id] != NULL)) { - if (codecs_[id]->DecoderInitialized()) { - assert(registered_pltypes_[id] >= 0); - assert(registered_pltypes_[id] <= 255); - codecs_[id]->DecoderParams( - &codec_params, static_cast(registered_pltypes_[id])); - if (!STR_CASE_CMP(codec_params.codec_inst.plname, name)) { - // Check if the given sampling frequency matches. - // A zero sampling frequency means we matching the names - // is sufficient and we don't need to check for the - // frequencies. - // Currently it is only iSAC which has one name but two - // sampling frequencies. - if ((frequency == 0)|| - (codec_params.codec_inst.plfreq == frequency)) { - return id; - } - } - } - } - } - // If we are here it means that we could not find a - // codec with that payload type. return -1. - return -1; -} - -int32_t AudioCodingModuleImpl::LastEncodedTimestamp( - uint32_t& timestamp) const { - CriticalSectionScoped lock(acm_crit_sect_); - if (!HaveValidEncoder("LastEncodedTimestamp")) { - return -1; - } - timestamp = codecs_[current_send_codec_idx_]->LastEncodedTimestamp(); - return 0; -} - -int32_t AudioCodingModuleImpl::ReplaceInternalDTXWithWebRtc( - bool use_webrtc_dtx) { - CriticalSectionScoped lock(acm_crit_sect_); - - if (!HaveValidEncoder("ReplaceInternalDTXWithWebRtc")) { - WEBRTC_TRACE( - webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Cannot replace codec internal DTX when no send codec is registered."); - return -1; - } - - int32_t res = codecs_[current_send_codec_idx_]->ReplaceInternalDTX( - use_webrtc_dtx); - // Check if VAD is turned on, or if there is any error. - if (res == 1) { - vad_enabled_ = true; - } else if (res < 0) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Failed to set ReplaceInternalDTXWithWebRtc(%d)", - use_webrtc_dtx); - return res; - } - - return 0; -} - -int32_t AudioCodingModuleImpl::IsInternalDTXReplacedWithWebRtc( - bool* uses_webrtc_dtx) { - CriticalSectionScoped lock(acm_crit_sect_); - - if (!HaveValidEncoder("IsInternalDTXReplacedWithWebRtc")) { - return -1; - } - if (codecs_[current_send_codec_idx_]->IsInternalDTXReplaced(uses_webrtc_dtx) - < 0) { - return -1; - } - return 0; -} - -int AudioCodingModuleImpl::SetISACMaxRate(int max_bit_per_sec) { - CriticalSectionScoped lock(acm_crit_sect_); - - if (!HaveValidEncoder("SetISACMaxRate")) { - return -1; - } - - return codecs_[current_send_codec_idx_]->SetISACMaxRate(max_bit_per_sec); -} - -int AudioCodingModuleImpl::SetISACMaxPayloadSize(int max_size_bytes) { - CriticalSectionScoped lock(acm_crit_sect_); - - if (!HaveValidEncoder("SetISACMaxPayloadSize")) { - return -1; - } - - return codecs_[current_send_codec_idx_]->SetISACMaxPayloadSize( - max_size_bytes); -} - -int32_t AudioCodingModuleImpl::ConfigISACBandwidthEstimator( - int frame_size_ms, - int rate_bit_per_sec, - bool enforce_frame_size) { - CriticalSectionScoped lock(acm_crit_sect_); - - if (!HaveValidEncoder("ConfigISACBandwidthEstimator")) { - return -1; - } - - return codecs_[current_send_codec_idx_]->ConfigISACBandwidthEstimator( - frame_size_ms, rate_bit_per_sec, enforce_frame_size); -} - -int32_t AudioCodingModuleImpl::PlayoutTimestamp( - uint32_t* timestamp) { - WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_, - "PlayoutTimestamp()"); - { - CriticalSectionScoped lock(acm_crit_sect_); - if (track_neteq_buffer_) { - *timestamp = playout_ts_; - return 0; - } - } - return neteq_.PlayoutTimestamp(*timestamp); -} - -bool AudioCodingModuleImpl::HaveValidEncoder(const char* caller_name) const { - if ((!send_codec_registered_) || (current_send_codec_idx_ < 0) || - (current_send_codec_idx_ >= ACMCodecDB::kNumCodecs)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "%s failed: No send codec is registered.", caller_name); - return false; - } - if ((current_send_codec_idx_ < 0) || - (current_send_codec_idx_ >= ACMCodecDB::kNumCodecs)) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "%s failed: Send codec index out of range.", caller_name); - return false; - } - if (codecs_[current_send_codec_idx_] == NULL) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "%s failed: Send codec is NULL pointer.", caller_name); - return false; - } - return true; -} - -int AudioCodingModuleImpl::UnregisterReceiveCodec(uint8_t payload_type) { - CriticalSectionScoped lock(acm_crit_sect_); - int id; - - // Search through the list of registered payload types. - for (id = 0; id < ACMCodecDB::kMaxNumCodecs; id++) { - if (registered_pltypes_[id] == payload_type) { - // We have found the id registered with the payload type. - break; - } - } - - if (id >= ACMCodecDB::kNumCodecs) { - // Payload type was not registered. No need to unregister. - return 0; - } - - // Unregister the codec with the given payload type. - return UnregisterReceiveCodecSafe(id); -} - -int32_t AudioCodingModuleImpl::UnregisterReceiveCodecSafe( - const int16_t codec_id) { - const WebRtcNetEQDecoder *neteq_decoder = ACMCodecDB::NetEQDecoders(); - int16_t mirror_id = ACMCodecDB::MirrorID(codec_id); - bool stereo_receiver = false; - - if (codecs_[codec_id] != NULL) { - if (registered_pltypes_[codec_id] != -1) { - // Store stereo information for future use. - stereo_receiver = stereo_receive_[codec_id]; - - // Before deleting the decoder instance unregister from NetEQ. - if (neteq_.RemoveCodec(neteq_decoder[codec_id], - stereo_receive_[codec_id]) < 0) { - CodecInst codec; - ACMCodecDB::Codec(codec_id, &codec); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "Unregistering %s-%d from NetEQ failed.", codec.plname, - codec.plfreq); - return -1; - } - - // CN is a special case for NetEQ, all three sampling frequencies - // are unregistered if one is deleted. - if (IsCodecCN(codec_id)) { - for (int i = 0; i < ACMCodecDB::kNumCodecs; i++) { - if (IsCodecCN(i)) { - stereo_receive_[i] = false; - registered_pltypes_[i] = -1; - } - } - } else { - if (codec_id == mirror_id) { - codecs_[codec_id]->DestructDecoder(); - if (stereo_receive_[codec_id]) { - slave_codecs_[codec_id]->DestructDecoder(); - stereo_receive_[codec_id] = false; - } - } - } - - // Check if this is the last registered stereo receive codec. - if (stereo_receiver) { - bool no_stereo = true; - - for (int i = 0; i < ACMCodecDB::kNumCodecs; i++) { - if (stereo_receive_[i]) { - // We still have stereo codecs registered. - no_stereo = false; - break; - } - } - - // If we don't have any stereo codecs left, change status. - if (no_stereo) { - neteq_.RemoveSlaves(); // No longer need the slave. - stereo_receive_registered_ = false; - } - } - } - } - - if (registered_pltypes_[codec_id] == receive_red_pltype_) { - // RED is going to be unregistered, set to an invalid value. - receive_red_pltype_ = 255; - } - registered_pltypes_[codec_id] = -1; - - return 0; -} - -int32_t AudioCodingModuleImpl::REDPayloadISAC( - const int32_t isac_rate, const int16_t isac_bw_estimate, - uint8_t* payload, int16_t* length_bytes) { - if (!HaveValidEncoder("EncodeData")) { - return -1; - } - int16_t status; - status = codecs_[current_send_codec_idx_]->REDPayloadISAC(isac_rate, - isac_bw_estimate, - payload, - length_bytes); - return status; -} - -void AudioCodingModuleImpl::ResetFragmentation(int vector_size) { - for (int n = 0; n < kMaxNumFragmentationVectors; n++) { - fragmentation_.fragmentationOffset[n] = n * MAX_PAYLOAD_SIZE_BYTE; - } - memset(fragmentation_.fragmentationLength, 0, kMaxNumFragmentationVectors * - sizeof(fragmentation_.fragmentationLength[0])); - memset(fragmentation_.fragmentationTimeDiff, 0, kMaxNumFragmentationVectors * - sizeof(fragmentation_.fragmentationTimeDiff[0])); - memset(fragmentation_.fragmentationPlType, 0, kMaxNumFragmentationVectors * - sizeof(fragmentation_.fragmentationPlType[0])); - fragmentation_.fragmentationVectorSize = - static_cast(vector_size); -} - -// TODO(turajs): Add second parameter to enable/disable AV-sync. -int AudioCodingModuleImpl::SetInitialPlayoutDelay(int delay_ms) { - if (delay_ms < 0 || delay_ms > 10000) { - return -1; - } - - CriticalSectionScoped lock(acm_crit_sect_); - - // Receiver should be initialized before this call processed. - if (!receiver_initialized_) { - InitializeReceiverSafe(); - } - - if (first_payload_received_) { - // Too late for this API. Only works before a call is started. - return -1; - } - initial_delay_ms_ = delay_ms; - - // If initial delay is zero, NetEq buffer should not be tracked, also we - // don't want to be in AV-sync mode. - track_neteq_buffer_ = delay_ms > 0; - av_sync_ = delay_ms > 0; - - neteq_.EnableAVSync(av_sync_); - return neteq_.SetMinimumDelay(delay_ms); -} - -bool AudioCodingModuleImpl::GetSilence(int desired_sample_rate_hz, - AudioFrame* frame) { - CriticalSectionScoped lock(acm_crit_sect_); - if (initial_delay_ms_ == 0 || !track_neteq_buffer_) { - return false; - } - - if (accumulated_audio_ms_ >= initial_delay_ms_) { - // We have enough data stored that match our initial delay target. - track_neteq_buffer_ = false; - return false; - } - - // Record call to silence generator. - call_stats_.DecodedBySilenceGenerator(); - - // We stop accumulating packets, if the number of packets or the total size - // exceeds a threshold. - int max_num_packets; - int buffer_size_bytes; - int per_payload_overhead_bytes; - neteq_.BufferSpec(max_num_packets, buffer_size_bytes, - per_payload_overhead_bytes); - int total_bytes_accumulated = num_bytes_accumulated_ + - num_packets_accumulated_ * per_payload_overhead_bytes; - if (num_packets_accumulated_ > max_num_packets * 0.9 || - total_bytes_accumulated > buffer_size_bytes * 0.9) { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, id_, - "GetSilence: Initial delay couldn't be achieved." - " num_packets_accumulated=%d, total_bytes_accumulated=%d", - num_packets_accumulated_, num_bytes_accumulated_); - track_neteq_buffer_ = false; - return false; - } - - if (desired_sample_rate_hz > 0) { - frame->sample_rate_hz_ = desired_sample_rate_hz; - } else { - frame->sample_rate_hz_ = 0; - if (current_receive_codec_idx_ >= 0) { - frame->sample_rate_hz_ = - ACMCodecDB::database_[current_receive_codec_idx_].plfreq; - } else { - // No payload received yet, use the default sampling rate of NetEq. - frame->sample_rate_hz_ = neteq_.CurrentSampFreqHz(); - } - } - frame->num_channels_ = expected_channels_; - frame->samples_per_channel_ = frame->sample_rate_hz_ / 100; // Always 10 ms. - frame->speech_type_ = AudioFrame::kCNG; - frame->vad_activity_ = AudioFrame::kVadPassive; - frame->energy_ = 0; - int samples = frame->samples_per_channel_ * frame->num_channels_; - memset(frame->data_, 0, samples * sizeof(int16_t)); - return true; -} - -// Must be called within the scope of ACM critical section. -int AudioCodingModuleImpl::PushSyncPacketSafe() { - assert(av_sync_); - last_sequence_number_++; - last_incoming_send_timestamp_ += last_timestamp_diff_; - last_receive_timestamp_ += last_timestamp_diff_; - - WebRtcRTPHeader rtp_info; - rtp_info.header.payloadType = last_recv_audio_codec_pltype_; - rtp_info.header.ssrc = last_ssrc_; - rtp_info.header.markerBit = false; - rtp_info.header.sequenceNumber = last_sequence_number_; - rtp_info.header.timestamp = last_incoming_send_timestamp_; - rtp_info.type.Audio.channel = stereo_receive_[current_receive_codec_idx_] ? - 2 : 1; - last_packet_was_sync_ = true; - int payload_len_bytes = neteq_.RecIn(rtp_info, last_receive_timestamp_); - - if (payload_len_bytes < 0) - return -1; - - // This is to account for sync packets inserted during the buffering phase. - if (track_neteq_buffer_) - UpdateBufferingSafe(rtp_info, payload_len_bytes); - - return 0; -} - -// Must be called within the scope of ACM critical section. -void AudioCodingModuleImpl::UpdateBufferingSafe(const WebRtcRTPHeader& rtp_info, - int payload_len_bytes) { - const int in_sample_rate_khz = - (ACMCodecDB::database_[current_receive_codec_idx_].plfreq / 1000); - if (first_payload_received_ && - rtp_info.header.timestamp > last_incoming_send_timestamp_ && - in_sample_rate_khz > 0) { - accumulated_audio_ms_ += (rtp_info.header.timestamp - - last_incoming_send_timestamp_) / in_sample_rate_khz; - } - - num_packets_accumulated_++; - num_bytes_accumulated_ += payload_len_bytes; - - playout_ts_ = static_cast( - rtp_info.header.timestamp - static_cast( - initial_delay_ms_ * in_sample_rate_khz)); -} - -uint32_t AudioCodingModuleImpl::NowTimestamp(int codec_id) { - // Down-cast the time to (32-6)-bit since we only care about - // the least significant bits. (32-6) bits cover 2^(32-6) = 67108864 ms. - // we masked 6 most significant bits of 32-bit so we don't lose resolution - // when do the following multiplication. - int sample_rate_khz = ACMCodecDB::database_[codec_id].plfreq / 1000; - const uint32_t now_in_ms = static_cast( - clock_->TimeInMilliseconds() & kMaskTimestamp); - return static_cast(sample_rate_khz * now_in_ms); -} - -std::vector AudioCodingModuleImpl::GetNackList( - int round_trip_time_ms) const { - CriticalSectionScoped lock(acm_crit_sect_); - if (round_trip_time_ms < 0) { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, id_, - "GetNackList: round trip time cannot be negative." - " round_trip_time_ms=%d", round_trip_time_ms); - } - if (nack_enabled_ && round_trip_time_ms >= 0) { - assert(nack_.get()); - return nack_->GetNackList(round_trip_time_ms); - } - std::vector empty_list; - return empty_list; -} - -int AudioCodingModuleImpl::LeastRequiredDelayMs() const { - return std::max(neteq_.LeastRequiredDelayMs(), initial_delay_ms_); -} - -int AudioCodingModuleImpl::EnableNack(size_t max_nack_list_size) { - // Don't do anything if |max_nack_list_size| is out of range. - if (max_nack_list_size == 0 || - max_nack_list_size > acm2::Nack::kNackListSizeLimit) - return -1; - - CriticalSectionScoped lock(acm_crit_sect_); - if (!nack_enabled_) { - nack_.reset(acm2::Nack::Create(kNackThresholdPackets)); - nack_enabled_ = true; - - // Sampling rate might need to be updated if we change from disable to - // enable. Do it if the receive codec is valid. - if (current_receive_codec_idx_ >= 0) { - nack_->UpdateSampleRate( - ACMCodecDB::database_[current_receive_codec_idx_].plfreq); - } - } - return nack_->SetMaxNackListSize(max_nack_list_size); -} - -void AudioCodingModuleImpl::DisableNack() { - CriticalSectionScoped lock(acm_crit_sect_); - nack_.reset(); // Memory is released. - nack_enabled_ = false; -} - -void AudioCodingModuleImpl::GetDecodingCallStatistics( - AudioDecodingCallStats* call_stats) const { - CriticalSectionScoped lock(acm_crit_sect_); - *call_stats = call_stats_.GetDecodingStatistics(); -} - -} // namespace acm1 - -} // namespace webrtc diff --git a/webrtc/modules/audio_coding/main/source/audio_coding_module_impl.h b/webrtc/modules/audio_coding/main/source/audio_coding_module_impl.h deleted file mode 100644 index b99e5acad..000000000 --- a/webrtc/modules/audio_coding/main/source/audio_coding_module_impl.h +++ /dev/null @@ -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 - -#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 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 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 nack_; - bool nack_enabled_; - - acm2::CallStatistics call_stats_; -}; - -} // namespace acm1 - -} // namespace webrtc - -#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_AUDIO_CODING_MODULE_IMPL_H_