git-svn-id: http://webrtc.googlecode.com/svn/trunk@4 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
629
modules/audio_coding/NetEQ/main/test/NETEQTEST_CodecClass.cc
Normal file
629
modules/audio_coding/NetEQ/main/test/NETEQTEST_CodecClass.cc
Normal file
@@ -0,0 +1,629 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "NETEQTEST_CodecClass.h"
|
||||
#include "webrtc_neteq_help_macros.h"
|
||||
|
||||
NETEQTEST_Decoder::NETEQTEST_Decoder(enum WebRtcNetEQDecoder type, WebRtc_UWord16 fs, const char * name, WebRtc_UWord8 pt)
|
||||
:
|
||||
_decoder(NULL),
|
||||
_decoderType(type),
|
||||
_pt(pt),
|
||||
_fs(fs),
|
||||
_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
int NETEQTEST_Decoder::loadToNetEQ(NETEQTEST_NetEQClass & neteq, WebRtcNetEQ_CodecDef & codecInst)
|
||||
{
|
||||
SET_CODEC_PAR(codecInst, _decoderType, _pt, _decoder, _fs);
|
||||
int err = neteq.loadCodec(codecInst);
|
||||
|
||||
if (err)
|
||||
{
|
||||
printf("Error loading codec %s into NetEQ database\n", _name.c_str());
|
||||
}
|
||||
|
||||
return(err);
|
||||
}
|
||||
|
||||
|
||||
// iSAC
|
||||
#ifdef CODEC_ISAC
|
||||
#include "isac.h"
|
||||
|
||||
decoder_iSAC::decoder_iSAC(WebRtc_UWord8 pt)
|
||||
:
|
||||
NETEQTEST_Decoder(kDecoderISAC, 16000, "iSAC", pt)
|
||||
{
|
||||
WebRtc_Word16 err = WebRtcIsac_Create((ISACStruct **) &_decoder);
|
||||
if (err)
|
||||
{
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
WebRtcIsac_EncoderInit((ISACStruct *) _decoder, 0);
|
||||
WebRtcIsac_SetDecSampRate((ISACStruct *) _decoder, kIsacWideband);
|
||||
}
|
||||
|
||||
|
||||
decoder_iSAC::~decoder_iSAC()
|
||||
{
|
||||
if (_decoder)
|
||||
{
|
||||
WebRtcIsac_Free((ISACStruct *) _decoder);
|
||||
_decoder = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int decoder_iSAC::loadToNetEQ(NETEQTEST_NetEQClass & neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_ISAC_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CODEC_ISAC_SWB
|
||||
decoder_iSACSWB::decoder_iSACSWB(WebRtc_UWord8 pt)
|
||||
:
|
||||
NETEQTEST_Decoder(kDecoderISACswb, 32000, "iSAC swb", pt)
|
||||
{
|
||||
WebRtc_Word16 err = WebRtcIsac_Create((ISACStruct **) &_decoder);
|
||||
if (err)
|
||||
{
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
WebRtcIsac_EncoderInit((ISACStruct *) _decoder, 0);
|
||||
WebRtcIsac_SetDecSampRate((ISACStruct *) _decoder, kIsacSuperWideband);
|
||||
}
|
||||
|
||||
decoder_iSACSWB::~decoder_iSACSWB()
|
||||
{
|
||||
if (_decoder)
|
||||
{
|
||||
WebRtcIsac_Free((ISACStruct *) _decoder);
|
||||
_decoder = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int decoder_iSACSWB::loadToNetEQ(NETEQTEST_NetEQClass & neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_ISACSWB_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
// PCM u/A
|
||||
#ifdef CODEC_G711
|
||||
#include "g711_interface.h"
|
||||
|
||||
decoder_PCMU::decoder_PCMU(WebRtc_UWord8 pt)
|
||||
:
|
||||
NETEQTEST_Decoder(kDecoderPCMu, 8000, "G.711-u", pt)
|
||||
{
|
||||
// no state to crate or init
|
||||
}
|
||||
|
||||
int decoder_PCMU::loadToNetEQ(NETEQTEST_NetEQClass & neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_PCMU_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
|
||||
}
|
||||
|
||||
decoder_PCMA::decoder_PCMA(WebRtc_UWord8 pt)
|
||||
:
|
||||
NETEQTEST_Decoder(kDecoderPCMa, 8000, "G.711-A", pt)
|
||||
{
|
||||
// no state to crate or init
|
||||
}
|
||||
|
||||
int decoder_PCMA::loadToNetEQ(NETEQTEST_NetEQClass & neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_PCMA_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Linear PCM16b
|
||||
#if (defined(CODEC_PCM16B) || defined(CODEC_PCM16B_WB) || \
|
||||
defined(CODEC_PCM16B_32KHZ) || defined(CODEC_PCM16B_48KHZ))
|
||||
#include "pcm16b.h"
|
||||
#endif
|
||||
|
||||
#ifdef CODEC_PCM16B
|
||||
int decoder_PCM16B_NB::loadToNetEQ(NETEQTEST_NetEQClass &neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_PCM16B_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CODEC_PCM16B_WB
|
||||
int decoder_PCM16B_WB::loadToNetEQ(NETEQTEST_NetEQClass &neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_PCM16B_WB_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CODEC_PCM16B_32KHZ
|
||||
int decoder_PCM16B_SWB32::loadToNetEQ(NETEQTEST_NetEQClass &neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_PCM16B_SWB32_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CODEC_PCM16B_48KHZ
|
||||
int decoder_PCM16B_SWB48::loadToNetEQ(NETEQTEST_NetEQClass &neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_PCM16B_SWB48_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CODEC_ILBC
|
||||
#include "ilbc.h"
|
||||
decoder_ILBC::decoder_ILBC(WebRtc_UWord8 pt)
|
||||
:
|
||||
NETEQTEST_Decoder(kDecoderILBC, 8000, "iLBC", pt)
|
||||
{
|
||||
WebRtc_Word16 err = WebRtcIlbcfix_DecoderCreate((iLBC_decinst_t **) &_decoder);
|
||||
if (err)
|
||||
{
|
||||
throw std::exception();
|
||||
}
|
||||
}
|
||||
|
||||
decoder_ILBC::~decoder_ILBC()
|
||||
{
|
||||
WebRtcIlbcfix_DecoderFree((iLBC_decinst_t *) _decoder);
|
||||
}
|
||||
|
||||
int decoder_ILBC::loadToNetEQ(NETEQTEST_NetEQClass & neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_ILBC_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CODEC_G729
|
||||
#include "G729Interface.h"
|
||||
decoder_G729::decoder_G729(WebRtc_UWord8 pt)
|
||||
:
|
||||
NETEQTEST_Decoder(kDecoderG729, 8000, "G.729", pt)
|
||||
{
|
||||
WebRtc_Word16 err = WebRtcG729_CreateDec((G729_decinst_t **) &_decoder);
|
||||
if (err)
|
||||
{
|
||||
throw std::exception();
|
||||
}
|
||||
}
|
||||
|
||||
decoder_G729::~decoder_G729()
|
||||
{
|
||||
WebRtcG729_FreeDec((G729_decinst_t *) _decoder);
|
||||
}
|
||||
|
||||
int decoder_G729::loadToNetEQ(NETEQTEST_NetEQClass & neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_G729_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CODEC_G729_1
|
||||
#include "G729_1Interface.h"
|
||||
decoder_G729_1::decoder_G729_1(WebRtc_UWord8 pt)
|
||||
:
|
||||
NETEQTEST_Decoder(kDecoderG729_1, 16000, "G.729.1", pt)
|
||||
{
|
||||
WebRtc_Word16 err = WebRtcG7291_Create((G729_1_inst_t **) &_decoder);
|
||||
if (err)
|
||||
{
|
||||
throw std::exception();
|
||||
}
|
||||
}
|
||||
|
||||
decoder_G729_1::~decoder_G729_1()
|
||||
{
|
||||
WebRtcG7291_Free((G729_1_inst_t *) _decoder);
|
||||
}
|
||||
|
||||
int decoder_G729_1::loadToNetEQ(NETEQTEST_NetEQClass & neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_G729_1_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CODEC_G722
|
||||
#include "g722_interface.h"
|
||||
decoder_G722::decoder_G722(WebRtc_UWord8 pt)
|
||||
:
|
||||
NETEQTEST_Decoder(kDecoderG722, 16000, "G.722", pt)
|
||||
{
|
||||
WebRtc_Word16 err = WebRtcG722_CreateDecoder((G722DecInst **) &_decoder);
|
||||
if (err)
|
||||
{
|
||||
throw std::exception();
|
||||
}
|
||||
}
|
||||
|
||||
decoder_G722::~decoder_G722()
|
||||
{
|
||||
WebRtcG722_FreeDecoder((G722DecInst *) _decoder);
|
||||
}
|
||||
|
||||
int decoder_G722::loadToNetEQ(NETEQTEST_NetEQClass & neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_G722_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (defined(CODEC_G722_1_16) || defined(CODEC_G722_1_24) || \
|
||||
defined(CODEC_G722_1_32) || defined(CODEC_G722_1C_24) || \
|
||||
defined(CODEC_G722_1C_32) || defined(CODEC_G722_1C_48))
|
||||
#include "G722_1Interface.h"
|
||||
#endif
|
||||
|
||||
#ifdef CODEC_G722_1_16
|
||||
decoder_G722_1_16::decoder_G722_1_16(WebRtc_UWord8 pt)
|
||||
:
|
||||
NETEQTEST_Decoder(kDecoderG722_1_16, 16000, "G.722.1 (16 kbps)", pt)
|
||||
{
|
||||
if (WebRtcG7221_CreateDec16((G722_1_16_decinst_t **) &_decoder))
|
||||
{
|
||||
throw std::exception();
|
||||
}
|
||||
}
|
||||
|
||||
decoder_G722_1_16::~decoder_G722_1_16()
|
||||
{
|
||||
WebRtcG7221_FreeDec16((G722_1_16_decinst_t *) _decoder);
|
||||
}
|
||||
|
||||
int decoder_G722_1_16::loadToNetEQ(NETEQTEST_NetEQClass & neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_G722_1_16_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CODEC_G722_1_24
|
||||
decoder_G722_1_24::decoder_G722_1_24(WebRtc_UWord8 pt)
|
||||
:
|
||||
NETEQTEST_Decoder(kDecoderG722_1_24, 16000, "G.722.1 (24 kbps)", pt)
|
||||
{
|
||||
if (WebRtcG7221_CreateDec24((G722_1_24_decinst_t **) &_decoder))
|
||||
{
|
||||
throw std::exception();
|
||||
}
|
||||
}
|
||||
|
||||
decoder_G722_1_24::~decoder_G722_1_24()
|
||||
{
|
||||
WebRtcG7221_FreeDec24((G722_1_24_decinst_t *) _decoder);
|
||||
}
|
||||
|
||||
int decoder_G722_1_24::loadToNetEQ(NETEQTEST_NetEQClass & neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_G722_1_24_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CODEC_G722_1_32
|
||||
decoder_G722_1_32::decoder_G722_1_32(WebRtc_UWord8 pt)
|
||||
:
|
||||
NETEQTEST_Decoder(kDecoderG722_1_32, 16000, "G.722.1 (32 kbps)", pt)
|
||||
{
|
||||
if (WebRtcG7221_CreateDec32((G722_1_32_decinst_t **) &_decoder))
|
||||
{
|
||||
throw std::exception();
|
||||
}
|
||||
}
|
||||
|
||||
decoder_G722_1_32::~decoder_G722_1_32()
|
||||
{
|
||||
WebRtcG7221_FreeDec32((G722_1_32_decinst_t *) _decoder);
|
||||
}
|
||||
|
||||
int decoder_G722_1_32::loadToNetEQ(NETEQTEST_NetEQClass & neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_G722_1_32_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CODEC_G722_1C_24
|
||||
decoder_G722_1C_24::decoder_G722_1C_24(WebRtc_UWord8 pt)
|
||||
:
|
||||
NETEQTEST_Decoder(kDecoderG722_1C_24, 32000, "G.722.1C (24 kbps)", pt)
|
||||
{
|
||||
if (WebRtcG7221C_CreateDec24((G722_1C_24_decinst_t **) &_decoder))
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
decoder_G722_1C_24::~decoder_G722_1C_24()
|
||||
{
|
||||
WebRtcG7221C_FreeDec24((G722_1C_24_decinst_t *) _decoder);
|
||||
}
|
||||
|
||||
int decoder_G722_1C_24::loadToNetEQ(NETEQTEST_NetEQClass & neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_G722_1C_24_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CODEC_G722_1C_32
|
||||
decoder_G722_1C_32::decoder_G722_1C_32(WebRtc_UWord8 pt)
|
||||
:
|
||||
NETEQTEST_Decoder(kDecoderG722_1C_32, 32000, "G.722.1C (32 kbps)", pt)
|
||||
{
|
||||
if (WebRtcG7221C_CreateDec32((G722_1C_32_decinst_t **) &_decoder))
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
decoder_G722_1C_32::~decoder_G722_1C_32()
|
||||
{
|
||||
WebRtcG7221C_FreeDec32((G722_1C_32_decinst_t *) _decoder);
|
||||
}
|
||||
|
||||
int decoder_G722_1C_32::loadToNetEQ(NETEQTEST_NetEQClass & neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_G722_1C_32_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CODEC_G722_1C_48
|
||||
decoder_G722_1C_48::decoder_G722_1C_48(WebRtc_UWord8 pt)
|
||||
:
|
||||
NETEQTEST_Decoder(kDecoderG722_1C_48, 32000, "G.722.1C (48 kbps)", pt)
|
||||
{
|
||||
if (WebRtcG7221C_CreateDec48((G722_1C_48_decinst_t **) &_decoder))
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
decoder_G722_1C_48::~decoder_G722_1C_48()
|
||||
{
|
||||
WebRtcG7221C_FreeDec48((G722_1C_48_decinst_t *) _decoder);
|
||||
}
|
||||
|
||||
int decoder_G722_1C_48::loadToNetEQ(NETEQTEST_NetEQClass & neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_G722_1C_48_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CODEC_AMR
|
||||
#include "AMRInterface.h"
|
||||
#include "AMRCreation.h"
|
||||
decoder_AMR::decoder_AMR(WebRtc_UWord8 pt)
|
||||
:
|
||||
NETEQTEST_Decoder(kDecoderAMR, 8000, "AMR", pt)
|
||||
{
|
||||
if (WebRtcAmr_CreateDec((AMR_decinst_t **) &_decoder))
|
||||
throw std::exception();
|
||||
|
||||
WebRtcAmr_DecodeBitmode((AMR_decinst_t *) _decoder, AMRBandwidthEfficient);
|
||||
}
|
||||
|
||||
decoder_AMR::~decoder_AMR()
|
||||
{
|
||||
WebRtcAmr_FreeDec((AMR_decinst_t *) _decoder);
|
||||
}
|
||||
|
||||
int decoder_AMR::loadToNetEQ(NETEQTEST_NetEQClass & neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_AMR_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CODEC_AMRWB
|
||||
#include "AMRWBInterface.h"
|
||||
#include "AMRWBCreation.h"
|
||||
decoder_AMRWB::decoder_AMRWB(WebRtc_UWord8 pt)
|
||||
:
|
||||
NETEQTEST_Decoder(kDecoderAMRWB, 16000, "AMR wb", pt)
|
||||
{
|
||||
if (WebRtcAmrWb_CreateDec((AMRWB_decinst_t **) &_decoder))
|
||||
throw std::exception();
|
||||
|
||||
WebRtcAmrWb_DecodeBitmode((AMRWB_decinst_t *) _decoder, AMRBandwidthEfficient);
|
||||
}
|
||||
|
||||
decoder_AMRWB::~decoder_AMRWB()
|
||||
{
|
||||
WebRtcAmrWb_FreeDec((AMRWB_decinst_t *) _decoder);
|
||||
}
|
||||
|
||||
int decoder_AMRWB::loadToNetEQ(NETEQTEST_NetEQClass & neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_AMRWB_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CODEC_GSMFR
|
||||
#include "GSMFRInterface.h"
|
||||
#include "GSMFRCreation.h"
|
||||
decoder_GSMFR::decoder_GSMFR(WebRtc_UWord8 pt)
|
||||
:
|
||||
NETEQTEST_Decoder(kDecoderGSMFR, 8000, "GSM-FR", pt)
|
||||
{
|
||||
if (WebRtcGSMFR_CreateDec((GSMFR_decinst_t **) &_decoder))
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
decoder_GSMFR::~decoder_GSMFR()
|
||||
{
|
||||
WebRtcGSMFR_FreeDec((GSMFR_decinst_t *) _decoder);
|
||||
}
|
||||
|
||||
int decoder_GSMFR::loadToNetEQ(NETEQTEST_NetEQClass & neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_GSMFR_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (defined(CODEC_SPEEX_8) || defined (CODEC_SPEEX_16))
|
||||
#include "SpeexInterface.h"
|
||||
decoder_SPEEX::decoder_SPEEX(WebRtc_UWord8 pt, WebRtc_UWord16 fs)
|
||||
:
|
||||
NETEQTEST_Decoder(fs == 8000 ? kDecoderSPEEX_8 : kDecoderSPEEX_16,
|
||||
fs, "SPEEX " + fs/1000, pt)
|
||||
{
|
||||
if (fs != 8000 && fs != 16000)
|
||||
throw std::exception("Wrong sample rate for SPEEX");
|
||||
|
||||
if (WebRtcSpeex_CreateDec((SPEEX_decinst_t **) &_decoder, fs, 1))
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
decoder_SPEEX::~decoder_SPEEX()
|
||||
{
|
||||
WebRtcSpeex_FreeDec((SPEEX_decinst_t *) _decoder);
|
||||
}
|
||||
|
||||
int decoder_SPEEX::loadToNetEQ(NETEQTEST_NetEQClass & neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_SPEEX_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CODEC_RED
|
||||
int decoder_RED::loadToNetEQ(NETEQTEST_NetEQClass & neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_RED_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CODEC_ATEVENT_DECODE
|
||||
int decoder_AVT::loadToNetEQ(NETEQTEST_NetEQClass & neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_AVT_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \
|
||||
defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48))
|
||||
#include "webrtc_cng.h"
|
||||
decoder_CNG::decoder_CNG(WebRtc_UWord8 pt, WebRtc_UWord16 fs)
|
||||
:
|
||||
NETEQTEST_Decoder(kDecoderCNG, fs, "CNG " + fs/1000, pt)
|
||||
{
|
||||
if (fs != 8000 && fs != 16000 && fs != 32000 && fs != 48000)
|
||||
throw std::exception();
|
||||
|
||||
if (WebRtcCng_CreateDec((CNG_dec_inst **) &_decoder))
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
decoder_CNG::~decoder_CNG()
|
||||
{
|
||||
WebRtcCng_FreeDec((CNG_dec_inst *) _decoder);
|
||||
}
|
||||
|
||||
int decoder_CNG::loadToNetEQ(NETEQTEST_NetEQClass & neteq)
|
||||
{
|
||||
WebRtcNetEQ_CodecDef codecInst;
|
||||
|
||||
SET_CNG_FUNCTIONS(codecInst);
|
||||
|
||||
return(NETEQTEST_Decoder::loadToNetEQ(neteq, codecInst));
|
||||
}
|
||||
#endif
|
||||
293
modules/audio_coding/NetEQ/main/test/NETEQTEST_CodecClass.h
Normal file
293
modules/audio_coding/NetEQ/main/test/NETEQTEST_CodecClass.h
Normal file
@@ -0,0 +1,293 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef NETEQTEST_CODECCLASS_H
|
||||
#define NETEQTEST_CODECCLASS_H
|
||||
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
|
||||
#include "typedefs.h"
|
||||
#include "webrtc_neteq.h"
|
||||
#include "NETEQTEST_NetEQClass.h"
|
||||
|
||||
class NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
NETEQTEST_Decoder(enum WebRtcNetEQDecoder type, WebRtc_UWord16 fs, const char * name, WebRtc_UWord8 pt = 0);
|
||||
virtual ~NETEQTEST_Decoder() {};
|
||||
|
||||
virtual int loadToNetEQ(NETEQTEST_NetEQClass & neteq) = 0;
|
||||
|
||||
int getName(char * name, int maxLen) const { strncpy( name, _name.c_str(), maxLen ); return 0;};
|
||||
|
||||
void setPT(WebRtc_UWord8 pt) { _pt = pt; };
|
||||
WebRtc_UWord16 getFs() const { return (_fs); };
|
||||
enum WebRtcNetEQDecoder getType() const { return (_decoderType); };
|
||||
WebRtc_UWord8 getPT() const { return (_pt); };
|
||||
|
||||
protected:
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq, WebRtcNetEQ_CodecDef & codecInst);
|
||||
|
||||
void * _decoder;
|
||||
enum WebRtcNetEQDecoder _decoderType;
|
||||
WebRtc_UWord8 _pt;
|
||||
WebRtc_UWord16 _fs;
|
||||
std::string _name;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
class decoder_iSAC : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_iSAC(WebRtc_UWord8 pt = 0);
|
||||
virtual ~decoder_iSAC();
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
|
||||
class decoder_iSACSWB : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_iSACSWB(WebRtc_UWord8 pt = 0);
|
||||
virtual ~decoder_iSACSWB();
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
|
||||
class decoder_PCMU : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_PCMU(WebRtc_UWord8 pt = 0);
|
||||
virtual ~decoder_PCMU() {};
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
|
||||
class decoder_PCMA : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_PCMA(WebRtc_UWord8 pt = 0);
|
||||
virtual ~decoder_PCMA() {};
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
class decoder_PCM16B_NB : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_PCM16B_NB(WebRtc_UWord8 pt = 0) : NETEQTEST_Decoder(kDecoderPCM16B, 8000, "PCM16 nb", pt) {};
|
||||
virtual ~decoder_PCM16B_NB() {};
|
||||
virtual int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
class decoder_PCM16B_WB : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_PCM16B_WB(WebRtc_UWord8 pt = 0) : NETEQTEST_Decoder(kDecoderPCM16Bwb, 16000, "PCM16 wb", pt) {};
|
||||
virtual ~decoder_PCM16B_WB() {};
|
||||
virtual int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
class decoder_PCM16B_SWB32 : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_PCM16B_SWB32(WebRtc_UWord8 pt = 0) : NETEQTEST_Decoder(kDecoderPCM16Bswb32kHz, 32000, "PCM16 swb32", pt) {};
|
||||
virtual ~decoder_PCM16B_SWB32() {};
|
||||
virtual int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
class decoder_PCM16B_SWB48 : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_PCM16B_SWB48(WebRtc_UWord8 pt = 0) : NETEQTEST_Decoder(kDecoderPCM16Bswb48kHz, 48000, "PCM16 swb48", pt) {};
|
||||
virtual ~decoder_PCM16B_SWB48() {};
|
||||
virtual int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
|
||||
class decoder_ILBC : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_ILBC(WebRtc_UWord8 pt = 0);
|
||||
virtual ~decoder_ILBC();
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
|
||||
class decoder_G729 : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_G729(WebRtc_UWord8 pt = 0);
|
||||
virtual ~decoder_G729();
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
class decoder_G729_1 : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_G729_1(WebRtc_UWord8 pt = 0);
|
||||
virtual ~decoder_G729_1();
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
|
||||
class decoder_G722 : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_G722(WebRtc_UWord8 pt = 0);
|
||||
virtual ~decoder_G722();
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
|
||||
class decoder_G722_1_16 : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_G722_1_16(WebRtc_UWord8 pt = 0);
|
||||
virtual ~decoder_G722_1_16();
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
class decoder_G722_1_24 : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_G722_1_24(WebRtc_UWord8 pt = 0);
|
||||
virtual ~decoder_G722_1_24();
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
class decoder_G722_1_32 : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_G722_1_32(WebRtc_UWord8 pt = 0);
|
||||
virtual ~decoder_G722_1_32();
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
|
||||
class decoder_G722_1C_24 : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_G722_1C_24(WebRtc_UWord8 pt = 0);
|
||||
virtual ~decoder_G722_1C_24();
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
class decoder_G722_1C_32 : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_G722_1C_32(WebRtc_UWord8 pt = 0);
|
||||
virtual ~decoder_G722_1C_32();
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
class decoder_G722_1C_48 : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_G722_1C_48(WebRtc_UWord8 pt = 0);
|
||||
virtual ~decoder_G722_1C_48();
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
|
||||
class decoder_AMR : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_AMR(WebRtc_UWord8 pt = 0);
|
||||
virtual ~decoder_AMR();
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
class decoder_AMRWB : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_AMRWB(WebRtc_UWord8 pt = 0);
|
||||
virtual ~decoder_AMRWB();
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
class decoder_GSMFR : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_GSMFR(WebRtc_UWord8 pt = 0);
|
||||
virtual ~decoder_GSMFR();
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
class decoder_G726 : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
//virtual decoder_G726(WebRtc_UWord8 pt = 0) = 0;
|
||||
decoder_G726(enum WebRtcNetEQDecoder type, const char * name, WebRtc_UWord8 pt = 0);
|
||||
virtual ~decoder_G726();
|
||||
virtual int loadToNetEQ(NETEQTEST_NetEQClass & neteq) = 0;
|
||||
};
|
||||
|
||||
class decoder_G726_16 : public decoder_G726
|
||||
{
|
||||
public:
|
||||
decoder_G726_16(WebRtc_UWord8 pt = 0) : decoder_G726(kDecoderG726_16, "G.726 (16 kbps)", pt) {};
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
class decoder_G726_24 : public decoder_G726
|
||||
{
|
||||
public:
|
||||
decoder_G726_24(WebRtc_UWord8 pt = 0) : decoder_G726(kDecoderG726_24, "G.726 (24 kbps)", pt) {};
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
class decoder_G726_32 : public decoder_G726
|
||||
{
|
||||
public:
|
||||
decoder_G726_32(WebRtc_UWord8 pt = 0) : decoder_G726(kDecoderG726_32, "G.726 (32 kbps)", pt) {};
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
class decoder_G726_40 : public decoder_G726
|
||||
{
|
||||
public:
|
||||
decoder_G726_40(WebRtc_UWord8 pt = 0) : decoder_G726(kDecoderG726_40, "G.726 (40 kbps)", pt) {};
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
class decoder_SPEEX : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_SPEEX(WebRtc_UWord8 pt = 0, WebRtc_UWord16 fs = 8000);
|
||||
virtual ~decoder_SPEEX();
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
class decoder_RED : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_RED(WebRtc_UWord8 pt = 0) : NETEQTEST_Decoder(kDecoderRED, 8000, "RED", pt) {};
|
||||
virtual ~decoder_RED() {};
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
class decoder_AVT : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_AVT(WebRtc_UWord8 pt = 0) : NETEQTEST_Decoder(kDecoderAVT, 8000, "AVT", pt) {};
|
||||
virtual ~decoder_AVT() {};
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
|
||||
class decoder_CNG : public NETEQTEST_Decoder
|
||||
{
|
||||
public:
|
||||
decoder_CNG(WebRtc_UWord8 pt = 0, WebRtc_UWord16 fs = 8000);
|
||||
virtual ~decoder_CNG();
|
||||
int loadToNetEQ(NETEQTEST_NetEQClass & neteq);
|
||||
};
|
||||
|
||||
#endif //NETEQTEST_CODECCLASS_H
|
||||
370
modules/audio_coding/NetEQ/main/test/NETEQTEST_NetEQClass.cc
Normal file
370
modules/audio_coding/NetEQ/main/test/NETEQTEST_NetEQClass.cc
Normal file
@@ -0,0 +1,370 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <memory.h>
|
||||
|
||||
#include "NETEQTEST_NetEQClass.h"
|
||||
|
||||
|
||||
NETEQTEST_NetEQClass::NETEQTEST_NetEQClass()
|
||||
:
|
||||
_inst(NULL),
|
||||
_instMem(NULL),
|
||||
_bufferMem(NULL),
|
||||
_preparseRTP(false),
|
||||
_fsmult(1),
|
||||
_isMaster(true)
|
||||
{
|
||||
#ifdef WINDOWS_TIMING
|
||||
_totTimeRecIn.QuadPart = 0;
|
||||
_totTimeRecOut.QuadPart = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
NETEQTEST_NetEQClass::NETEQTEST_NetEQClass(enum WebRtcNetEQDecoder *usedCodec, int noOfCodecs,
|
||||
WebRtc_UWord16 fs, WebRtcNetEQNetworkType nwType)
|
||||
:
|
||||
_inst(NULL),
|
||||
_instMem(NULL),
|
||||
_bufferMem(NULL),
|
||||
_preparseRTP(false),
|
||||
_fsmult(1),
|
||||
_isMaster(true)
|
||||
{
|
||||
#ifdef WINDOWS_TIMING
|
||||
_totTimeRecIn.QuadPart = 0;
|
||||
_totTimeRecOut.QuadPart = 0;
|
||||
#endif
|
||||
|
||||
if (assign() == 0)
|
||||
{
|
||||
if (init(fs) == 0)
|
||||
{
|
||||
assignBuffer(usedCodec, noOfCodecs, nwType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NETEQTEST_NetEQClass::~NETEQTEST_NetEQClass()
|
||||
{
|
||||
if (_instMem)
|
||||
{
|
||||
delete [] _instMem;
|
||||
_instMem = NULL;
|
||||
}
|
||||
|
||||
if (_bufferMem)
|
||||
{
|
||||
delete [] _bufferMem;
|
||||
_bufferMem = NULL;
|
||||
}
|
||||
|
||||
_inst = NULL;
|
||||
}
|
||||
|
||||
int NETEQTEST_NetEQClass::assign()
|
||||
{
|
||||
int memSize;
|
||||
|
||||
WebRtcNetEQ_AssignSize(&memSize);
|
||||
|
||||
if (_instMem)
|
||||
{
|
||||
delete [] _instMem;
|
||||
_instMem = NULL;
|
||||
}
|
||||
|
||||
_instMem = new WebRtc_Word8[memSize];
|
||||
|
||||
int ret = WebRtcNetEQ_Assign(&_inst, _instMem);
|
||||
|
||||
if (ret)
|
||||
{
|
||||
printError();
|
||||
}
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
|
||||
int NETEQTEST_NetEQClass::init(WebRtc_UWord16 fs)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!_inst)
|
||||
{
|
||||
// not assigned
|
||||
ret = assign();
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
printError();
|
||||
return (ret);
|
||||
}
|
||||
}
|
||||
|
||||
ret = WebRtcNetEQ_Init(_inst, fs);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
printError();
|
||||
}
|
||||
|
||||
return (ret);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int NETEQTEST_NetEQClass::assignBuffer(enum WebRtcNetEQDecoder *usedCodec, int noOfCodecs, WebRtcNetEQNetworkType nwType)
|
||||
{
|
||||
int numPackets, memSize, ret;
|
||||
|
||||
if (!_inst)
|
||||
{
|
||||
// not assigned
|
||||
ret = assign();
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
printError();
|
||||
return (ret);
|
||||
}
|
||||
|
||||
ret = init();
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
printError();
|
||||
return (ret);
|
||||
}
|
||||
}
|
||||
|
||||
ret = WebRtcNetEQ_GetRecommendedBufferSize(_inst, usedCodec, noOfCodecs, nwType, &numPackets, &memSize);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
printError();
|
||||
return (ret);
|
||||
}
|
||||
|
||||
if (_bufferMem)
|
||||
{
|
||||
delete [] _bufferMem;
|
||||
_bufferMem = NULL;
|
||||
}
|
||||
|
||||
_bufferMem = new WebRtc_Word8[memSize];
|
||||
|
||||
memset(_bufferMem, -1, memSize);
|
||||
|
||||
ret = WebRtcNetEQ_AssignBuffer(_inst, numPackets, _bufferMem, memSize);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
printError();
|
||||
}
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int NETEQTEST_NetEQClass::loadCodec(WebRtcNetEQ_CodecDef &codecInst)
|
||||
{
|
||||
int err = WebRtcNetEQ_CodecDbAdd(_inst, &codecInst);
|
||||
|
||||
if (err)
|
||||
{
|
||||
printError();
|
||||
}
|
||||
|
||||
return (err);
|
||||
}
|
||||
|
||||
void NETEQTEST_NetEQClass::printError()
|
||||
{
|
||||
if (_inst)
|
||||
{
|
||||
int errorCode = WebRtcNetEQ_GetErrorCode(_inst);
|
||||
|
||||
if (errorCode)
|
||||
{
|
||||
char errorName[WEBRTC_NETEQ_MAX_ERROR_NAME];
|
||||
|
||||
WebRtcNetEQ_GetErrorName(errorCode, errorName, WEBRTC_NETEQ_MAX_ERROR_NAME);
|
||||
|
||||
printf("Error %i: %s\n", errorCode, errorName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NETEQTEST_NetEQClass::printError(NETEQTEST_RTPpacket &rtp)
|
||||
{
|
||||
// print regular error info
|
||||
printError();
|
||||
|
||||
// print extra info from packet
|
||||
printf("\tRTP: TS=%lu, SN=%u, PT=%u, M=%i, len=%i\n",
|
||||
rtp.timeStamp(), rtp.sequenceNumber(), rtp.payloadType(),
|
||||
rtp.markerBit(), rtp.payloadLen());
|
||||
|
||||
}
|
||||
|
||||
int NETEQTEST_NetEQClass::recIn(NETEQTEST_RTPpacket &rtp)
|
||||
{
|
||||
|
||||
int err;
|
||||
#ifdef WINDOWS_TIMING
|
||||
LARGE_INTEGER countA, countB;
|
||||
#endif
|
||||
|
||||
if (_preparseRTP)
|
||||
{
|
||||
WebRtcNetEQ_RTPInfo rtpInfo;
|
||||
// parse RTP header
|
||||
rtp.parseHeader(rtpInfo);
|
||||
|
||||
#ifdef WINDOWS_TIMING
|
||||
QueryPerformanceCounter(&countA); // get start count for processor
|
||||
#endif
|
||||
|
||||
err = WebRtcNetEQ_RecInRTPStruct(_inst, &rtpInfo, rtp.payload(), rtp.payloadLen(), rtp.time() * _fsmult * 8);
|
||||
|
||||
#ifdef WINDOWS_TIMING
|
||||
QueryPerformanceCounter(&countB); // get stop count for processor
|
||||
_totTimeRecIn.QuadPart += (countB.QuadPart - countA.QuadPart);
|
||||
#endif
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
#ifdef WINDOWS_TIMING
|
||||
QueryPerformanceCounter(&countA); // get start count for processor
|
||||
#endif
|
||||
|
||||
err = WebRtcNetEQ_RecIn(_inst, (WebRtc_Word16 *) rtp.datagram(), rtp.dataLen(), rtp.time() * _fsmult * 8);
|
||||
|
||||
#ifdef WINDOWS_TIMING
|
||||
QueryPerformanceCounter(&countB); // get stop count for processor
|
||||
_totTimeRecIn.QuadPart += (countB.QuadPart - countA.QuadPart);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
if (err)
|
||||
{
|
||||
printError(rtp);
|
||||
}
|
||||
|
||||
return (err);
|
||||
|
||||
}
|
||||
|
||||
|
||||
WebRtc_Word16 NETEQTEST_NetEQClass::recOut(WebRtc_Word16 *outData, void *msInfo, enum WebRtcNetEQOutputType *outputType)
|
||||
{
|
||||
int err;
|
||||
WebRtc_Word16 outLen = 0;
|
||||
#ifdef WINDOWS_TIMING
|
||||
LARGE_INTEGER countA, countB;
|
||||
#endif
|
||||
|
||||
#ifdef WINDOWS_TIMING
|
||||
QueryPerformanceCounter(&countA); // get start count for processor
|
||||
#endif
|
||||
|
||||
if (!msInfo)
|
||||
{
|
||||
// no msInfo given, do mono mode
|
||||
err = WebRtcNetEQ_RecOut(_inst, outData, &outLen);
|
||||
}
|
||||
else
|
||||
{
|
||||
// master/slave mode
|
||||
err = WebRtcNetEQ_RecOutMasterSlave(_inst, outData, &outLen, msInfo, static_cast<WebRtc_Word16>(_isMaster));
|
||||
}
|
||||
|
||||
#ifdef WINDOWS_TIMING
|
||||
QueryPerformanceCounter(&countB); // get stop count for processor
|
||||
_totTimeRecOut.QuadPart += (countB.QuadPart - countA.QuadPart);
|
||||
#endif
|
||||
|
||||
if (err)
|
||||
{
|
||||
printError();
|
||||
}
|
||||
else
|
||||
{
|
||||
int newfsmult = static_cast<int>(outLen / 80);
|
||||
|
||||
if (newfsmult != _fsmult)
|
||||
{
|
||||
printf("Warning: output sample rate changed\n");
|
||||
_fsmult = newfsmult;
|
||||
}
|
||||
}
|
||||
|
||||
if (outputType != NULL)
|
||||
{
|
||||
err = WebRtcNetEQ_GetSpeechOutputType(_inst, outputType);
|
||||
|
||||
if (err)
|
||||
{
|
||||
printError();
|
||||
}
|
||||
}
|
||||
|
||||
return (outLen);
|
||||
}
|
||||
|
||||
|
||||
WebRtc_UWord32 NETEQTEST_NetEQClass::getSpeechTimeStamp()
|
||||
{
|
||||
|
||||
WebRtc_UWord32 ts = 0;
|
||||
int err;
|
||||
|
||||
err = WebRtcNetEQ_GetSpeechTimeStamp(_inst, &ts);
|
||||
|
||||
if (err)
|
||||
{
|
||||
printError();
|
||||
ts = 0;
|
||||
}
|
||||
|
||||
return (ts);
|
||||
|
||||
}
|
||||
|
||||
//NETEQTEST_NetEQVector::NETEQTEST_NetEQVector(int numChannels)
|
||||
//:
|
||||
//channels(numChannels, new NETEQTEST_NetEQClass())
|
||||
//{
|
||||
// //for (int i = 0; i < numChannels; i++)
|
||||
// //{
|
||||
// // channels.push_back(new NETEQTEST_NetEQClass());
|
||||
// //}
|
||||
//}
|
||||
//
|
||||
//NETEQTEST_NetEQVector::NETEQTEST_NetEQVector(int numChannels, enum WebRtcNetEQDecoder *usedCodec, int noOfCodecs,
|
||||
// WebRtc_UWord16 fs, WebRtcNetEQNetworkType nwType)
|
||||
// :
|
||||
//channels(numChannels, new NETEQTEST_NetEQClass(usedCodec, noOfCodecs, fs, nwType))
|
||||
//{
|
||||
// //for (int i = 0; i < numChannels; i++)
|
||||
// //{
|
||||
// // channels.push_back(new NETEQTEST_NetEQClass(usedCodec, noOfCodecs, fs, nwType));
|
||||
// //}
|
||||
//}
|
||||
//
|
||||
//NETEQTEST_NetEQVector::~NETEQTEST_NetEQVector()
|
||||
//{
|
||||
//}
|
||||
|
||||
91
modules/audio_coding/NetEQ/main/test/NETEQTEST_NetEQClass.h
Normal file
91
modules/audio_coding/NetEQ/main/test/NETEQTEST_NetEQClass.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef NETEQTEST_NETEQCLASS_H
|
||||
#define NETEQTEST_NETEQCLASS_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
|
||||
#include "webrtc_neteq.h"
|
||||
#include "webrtc_neteq_internal.h"
|
||||
|
||||
#include "NETEQTEST_RTPpacket.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#define WINDOWS_TIMING // complexity measurement only implemented for windows
|
||||
//TODO(hlundin):Add complexity testing for Linux.
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
class NETEQTEST_NetEQClass
|
||||
{
|
||||
public:
|
||||
NETEQTEST_NetEQClass();
|
||||
NETEQTEST_NetEQClass(enum WebRtcNetEQDecoder *usedCodec, int noOfCodecs,
|
||||
WebRtc_UWord16 fs = 8000, WebRtcNetEQNetworkType nwType = kTCPLargeJitter);
|
||||
~NETEQTEST_NetEQClass();
|
||||
|
||||
int assign();
|
||||
int init(WebRtc_UWord16 fs = 8000);
|
||||
int assignBuffer(enum WebRtcNetEQDecoder *usedCodec, int noOfCodecs, WebRtcNetEQNetworkType nwType = kTCPLargeJitter);
|
||||
int loadCodec(WebRtcNetEQ_CodecDef & codecInst);
|
||||
int recIn(NETEQTEST_RTPpacket & rtp);
|
||||
WebRtc_Word16 recOut(WebRtc_Word16 *outData, void *msInfo = NULL, enum WebRtcNetEQOutputType *outputType = NULL);
|
||||
WebRtc_UWord32 getSpeechTimeStamp();
|
||||
|
||||
void * instance() { return (_inst); };
|
||||
void usePreparseRTP( bool useIt = true ) { _preparseRTP = useIt; };
|
||||
bool usingPreparseRTP() { return (_preparseRTP); };
|
||||
void setMaster( bool isMaster = true ) { _isMaster = isMaster; };
|
||||
void setSlave() { _isMaster = false; };
|
||||
bool isMaster() { return (_isMaster); };
|
||||
bool isSlave() { return (!_isMaster); };
|
||||
|
||||
#ifdef WINDOWS_TIMING
|
||||
double getRecInTime() { return (static_cast<double>( _totTimeRecIn.QuadPart )); };
|
||||
double getRecOutTime() { return (static_cast<double>( _totTimeRecOut.QuadPart )); };
|
||||
#else
|
||||
double getRecInTime() { return (0.0); };
|
||||
double getRecOutTime() { return (0.0); };
|
||||
|
||||
#endif
|
||||
|
||||
void printError();
|
||||
void printError(NETEQTEST_RTPpacket & rtp);
|
||||
|
||||
private:
|
||||
void * _inst;
|
||||
WebRtc_Word8 * _instMem;
|
||||
WebRtc_Word8 * _bufferMem;
|
||||
bool _preparseRTP;
|
||||
int _fsmult;
|
||||
bool _isMaster;
|
||||
#ifdef WINDOWS_TIMING
|
||||
LARGE_INTEGER _totTimeRecIn;
|
||||
LARGE_INTEGER _totTimeRecOut;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
//class NETEQTEST_NetEQVector
|
||||
//{
|
||||
//public:
|
||||
// NETEQTEST_NetEQVector(int numChannels);
|
||||
// NETEQTEST_NetEQVector(int numChannels, enum WebRtcNetEQDecoder *usedCodec, int noOfCodecs,
|
||||
// WebRtc_UWord16 fs = 8000, WebRtcNetEQNetworkType nwType = kTCPLargeJitter);
|
||||
// ~NETEQTEST_NetEQVector();
|
||||
//
|
||||
//private:
|
||||
// std::vector<NETEQTEST_NetEQClass *> channels;
|
||||
//};
|
||||
|
||||
#endif //NETEQTEST_NETEQCLASS_H
|
||||
766
modules/audio_coding/NetEQ/main/test/NETEQTEST_RTPpacket.cc
Normal file
766
modules/audio_coding/NetEQ/main/test/NETEQTEST_RTPpacket.cc
Normal file
@@ -0,0 +1,766 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "NETEQTEST_RTPpacket.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <netinet/in.h> // for htons, htonl, etc
|
||||
#endif
|
||||
|
||||
#define HDR_SIZE 8 // rtpplay packet header size in bytes
|
||||
|
||||
|
||||
NETEQTEST_RTPpacket::NETEQTEST_RTPpacket()
|
||||
:
|
||||
_datagram(NULL),
|
||||
_payloadPtr(NULL),
|
||||
_memSize(0),
|
||||
_datagramLen(-1),
|
||||
_payloadLen(0),
|
||||
_rtpParsed(false),
|
||||
_receiveTime(0),
|
||||
_lost(false)
|
||||
{
|
||||
memset(&_rtpInfo, 0, sizeof(_rtpInfo));
|
||||
_blockList.clear();
|
||||
}
|
||||
|
||||
NETEQTEST_RTPpacket::NETEQTEST_RTPpacket(const NETEQTEST_RTPpacket& copyFromMe)
|
||||
{
|
||||
|
||||
memcpy(this, ©FromMe, sizeof(NETEQTEST_RTPpacket));
|
||||
|
||||
_datagram = NULL;
|
||||
_payloadPtr = NULL;
|
||||
|
||||
if(copyFromMe._datagram)
|
||||
{
|
||||
_datagram = new WebRtc_UWord8[_memSize];
|
||||
|
||||
if(_datagram)
|
||||
{
|
||||
memcpy(_datagram, copyFromMe._datagram, _memSize);
|
||||
}
|
||||
}
|
||||
|
||||
if(copyFromMe._payloadPtr)
|
||||
{
|
||||
_payloadPtr = _datagram + (copyFromMe._payloadPtr - copyFromMe._datagram);
|
||||
}
|
||||
|
||||
_blockList = copyFromMe._blockList;
|
||||
|
||||
}
|
||||
|
||||
|
||||
NETEQTEST_RTPpacket & NETEQTEST_RTPpacket::operator = (const NETEQTEST_RTPpacket & other)
|
||||
{
|
||||
if (this != &other) // protect against invalid self-assignment
|
||||
{
|
||||
|
||||
// deallocate datagram memory if allocated
|
||||
if(_datagram)
|
||||
{
|
||||
delete[] _datagram;
|
||||
}
|
||||
|
||||
// do shallow copy
|
||||
memcpy(this, &other, sizeof(NETEQTEST_RTPpacket));
|
||||
|
||||
// reset pointers
|
||||
_datagram = NULL;
|
||||
_payloadPtr = NULL;
|
||||
|
||||
if(other._datagram)
|
||||
{
|
||||
_datagram = new WebRtc_UWord8[other._memSize];
|
||||
_memSize = other._memSize;
|
||||
|
||||
if(_datagram)
|
||||
{
|
||||
memcpy(_datagram, other._datagram, _memSize);
|
||||
}
|
||||
}
|
||||
|
||||
if(other._payloadPtr)
|
||||
{
|
||||
_payloadPtr = _datagram + (other._payloadPtr - other._datagram);
|
||||
}
|
||||
|
||||
// copy the blocking list (map)
|
||||
_blockList = other._blockList;
|
||||
|
||||
}
|
||||
|
||||
// by convention, always return *this
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NETEQTEST_RTPpacket::~NETEQTEST_RTPpacket()
|
||||
{
|
||||
if(_datagram)
|
||||
{
|
||||
delete _datagram;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NETEQTEST_RTPpacket::reset()
|
||||
{
|
||||
if(_datagram) {
|
||||
delete _datagram;
|
||||
}
|
||||
_datagram = NULL;
|
||||
_memSize = 0;
|
||||
_datagramLen = -1;
|
||||
_payloadLen = 0;
|
||||
_payloadPtr = NULL;
|
||||
_receiveTime = 0;
|
||||
memset(&_rtpInfo, 0, sizeof(_rtpInfo));
|
||||
_rtpParsed = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int NETEQTEST_RTPpacket::readFromFile(FILE *fp)
|
||||
{
|
||||
if(!fp)
|
||||
{
|
||||
return(-1);
|
||||
}
|
||||
|
||||
WebRtc_UWord16 length, plen;
|
||||
WebRtc_UWord32 offset;
|
||||
|
||||
if (fread(&length,2,1,fp)==0)
|
||||
{
|
||||
reset();
|
||||
return(-2);
|
||||
}
|
||||
length = ntohs(length);
|
||||
|
||||
if (fread(&plen,2,1,fp)==0)
|
||||
{
|
||||
reset();
|
||||
return(-1);
|
||||
}
|
||||
int packetLen = ntohs(plen);
|
||||
|
||||
if (fread(&offset,4,1,fp)==0)
|
||||
{
|
||||
reset();
|
||||
return(-1);
|
||||
}
|
||||
WebRtc_UWord32 receiveTime = ntohl(offset); // store in local variable until we have passed the reset below
|
||||
|
||||
// Use length here because a plen of 0 specifies rtcp
|
||||
length = (WebRtc_UWord16) (length - HDR_SIZE);
|
||||
|
||||
// check buffer size
|
||||
if (_datagram && _memSize < length)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
if (!_datagram)
|
||||
{
|
||||
_datagram = new WebRtc_UWord8[length];
|
||||
_memSize = length;
|
||||
}
|
||||
|
||||
if (fread((unsigned short *) _datagram,1,length,fp) != length)
|
||||
{
|
||||
reset();
|
||||
return(-1);
|
||||
}
|
||||
|
||||
_datagramLen = length;
|
||||
_receiveTime = receiveTime;
|
||||
|
||||
if (!_blockList.empty() && _blockList.count(payloadType()) > 0)
|
||||
{
|
||||
// discard this payload
|
||||
return(readFromFile(fp));
|
||||
}
|
||||
|
||||
return(packetLen);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int NETEQTEST_RTPpacket::readFixedFromFile(FILE *fp, int length)
|
||||
{
|
||||
if(!fp)
|
||||
{
|
||||
return(-1);
|
||||
}
|
||||
|
||||
// check buffer size
|
||||
if (_datagram && _memSize < length)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
if (!_datagram)
|
||||
{
|
||||
_datagram = new WebRtc_UWord8[length];
|
||||
_memSize = length;
|
||||
}
|
||||
|
||||
if (fread((unsigned short *) _datagram,1,length,fp) != length)
|
||||
{
|
||||
reset();
|
||||
return(-1);
|
||||
}
|
||||
|
||||
_datagramLen = length;
|
||||
_receiveTime = 0;
|
||||
|
||||
if (!_blockList.empty() && _blockList.count(payloadType()) > 0)
|
||||
{
|
||||
// discard this payload
|
||||
return(readFromFile(fp));
|
||||
}
|
||||
|
||||
return(length);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int NETEQTEST_RTPpacket::writeToFile(FILE *fp)
|
||||
{
|
||||
if(!fp)
|
||||
{
|
||||
return(-1);
|
||||
}
|
||||
|
||||
WebRtc_UWord16 length, plen;
|
||||
WebRtc_UWord32 offset;
|
||||
|
||||
// length including RTPplay header
|
||||
length = htons(_datagramLen + HDR_SIZE);
|
||||
if (fwrite(&length, 2, 1, fp) != 1)
|
||||
{
|
||||
return(-1);
|
||||
}
|
||||
|
||||
// payload length
|
||||
plen = htons(_datagramLen);
|
||||
if (fwrite(&plen, 2, 1, fp) != 1)
|
||||
{
|
||||
return(-1);
|
||||
}
|
||||
|
||||
// offset (=receive time)
|
||||
offset = htonl(_receiveTime);
|
||||
if (fwrite(&offset, 4, 1, fp) != 1)
|
||||
{
|
||||
return(-1);
|
||||
}
|
||||
|
||||
|
||||
// write packet data
|
||||
if (fwrite((unsigned short *) _datagram, 1, _datagramLen, fp) != _datagramLen)
|
||||
{
|
||||
return(-1);
|
||||
}
|
||||
|
||||
return(_datagramLen + HDR_SIZE); // total number of bytes written
|
||||
|
||||
}
|
||||
|
||||
|
||||
void NETEQTEST_RTPpacket::blockPT(WebRtc_UWord8 pt)
|
||||
{
|
||||
_blockList[pt] = true;
|
||||
}
|
||||
|
||||
|
||||
void NETEQTEST_RTPpacket::parseHeader()
|
||||
{
|
||||
if (_rtpParsed)
|
||||
{
|
||||
// nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
if (_datagramLen < 12)
|
||||
{
|
||||
// corrupt packet?
|
||||
return;
|
||||
}
|
||||
|
||||
_payloadLen = parseRTPheader(_datagram, _datagramLen, &_rtpInfo, &_payloadPtr);
|
||||
|
||||
_rtpParsed = true;
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
void NETEQTEST_RTPpacket::parseHeader(WebRtcNetEQ_RTPInfo & rtpInfo)
|
||||
{
|
||||
if (!_rtpParsed)
|
||||
{
|
||||
// parse the header
|
||||
parseHeader();
|
||||
}
|
||||
|
||||
memcpy(&rtpInfo, &_rtpInfo, sizeof(WebRtcNetEQ_RTPInfo));
|
||||
}
|
||||
|
||||
WebRtcNetEQ_RTPInfo const * NETEQTEST_RTPpacket::RTPinfo() const
|
||||
{
|
||||
if (_rtpParsed)
|
||||
{
|
||||
return &_rtpInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
WebRtc_UWord8 * NETEQTEST_RTPpacket::datagram() const
|
||||
{
|
||||
if (_datagramLen > 0)
|
||||
{
|
||||
return _datagram;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
WebRtc_UWord8 * NETEQTEST_RTPpacket::payload() const
|
||||
{
|
||||
if (_payloadLen > 0)
|
||||
{
|
||||
return _payloadPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
WebRtc_Word16 NETEQTEST_RTPpacket::payloadLen() const
|
||||
{
|
||||
return _payloadLen;
|
||||
}
|
||||
|
||||
WebRtc_Word16 NETEQTEST_RTPpacket::dataLen() const
|
||||
{
|
||||
return _datagramLen;
|
||||
}
|
||||
|
||||
bool NETEQTEST_RTPpacket::isParsed() const
|
||||
{
|
||||
return _rtpParsed;
|
||||
}
|
||||
|
||||
bool NETEQTEST_RTPpacket::isLost() const
|
||||
{
|
||||
return _lost;
|
||||
}
|
||||
|
||||
WebRtc_UWord8 NETEQTEST_RTPpacket::payloadType() const
|
||||
{
|
||||
WebRtcNetEQ_RTPInfo tempRTPinfo;
|
||||
|
||||
if(_datagram)
|
||||
{
|
||||
parseRTPheader(_datagram, _datagramLen, &tempRTPinfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return tempRTPinfo.payloadType;
|
||||
}
|
||||
|
||||
WebRtc_UWord16 NETEQTEST_RTPpacket::sequenceNumber() const
|
||||
{
|
||||
WebRtcNetEQ_RTPInfo tempRTPinfo;
|
||||
|
||||
if(_datagram)
|
||||
{
|
||||
parseRTPheader(_datagram, _datagramLen, &tempRTPinfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return tempRTPinfo.sequenceNumber;
|
||||
}
|
||||
|
||||
WebRtc_UWord32 NETEQTEST_RTPpacket::timeStamp() const
|
||||
{
|
||||
WebRtcNetEQ_RTPInfo tempRTPinfo;
|
||||
|
||||
if(_datagram)
|
||||
{
|
||||
parseRTPheader(_datagram, _datagramLen, &tempRTPinfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return tempRTPinfo.timeStamp;
|
||||
}
|
||||
|
||||
WebRtc_UWord32 NETEQTEST_RTPpacket::SSRC() const
|
||||
{
|
||||
WebRtcNetEQ_RTPInfo tempRTPinfo;
|
||||
|
||||
if(_datagram)
|
||||
{
|
||||
parseRTPheader(_datagram, _datagramLen, &tempRTPinfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return tempRTPinfo.SSRC;
|
||||
}
|
||||
|
||||
WebRtc_UWord8 NETEQTEST_RTPpacket::markerBit() const
|
||||
{
|
||||
WebRtcNetEQ_RTPInfo tempRTPinfo;
|
||||
|
||||
if(_datagram)
|
||||
{
|
||||
parseRTPheader(_datagram, _datagramLen, &tempRTPinfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return tempRTPinfo.markerBit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int NETEQTEST_RTPpacket::setPayloadType(WebRtc_UWord8 pt)
|
||||
{
|
||||
|
||||
if (_datagramLen < 12)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!_rtpParsed)
|
||||
{
|
||||
_rtpInfo.payloadType = pt;
|
||||
}
|
||||
|
||||
_datagram[1]=(unsigned char)(pt & 0xFF);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int NETEQTEST_RTPpacket::setSequenceNumber(WebRtc_UWord16 sn)
|
||||
{
|
||||
|
||||
if (_datagramLen < 12)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!_rtpParsed)
|
||||
{
|
||||
_rtpInfo.sequenceNumber = sn;
|
||||
}
|
||||
|
||||
_datagram[2]=(unsigned char)((sn>>8)&0xFF);
|
||||
_datagram[3]=(unsigned char)((sn)&0xFF);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int NETEQTEST_RTPpacket::setTimeStamp(WebRtc_UWord32 ts)
|
||||
{
|
||||
|
||||
if (_datagramLen < 12)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!_rtpParsed)
|
||||
{
|
||||
_rtpInfo.timeStamp = ts;
|
||||
}
|
||||
|
||||
_datagram[4]=(unsigned char)((ts>>24)&0xFF);
|
||||
_datagram[5]=(unsigned char)((ts>>16)&0xFF);
|
||||
_datagram[6]=(unsigned char)((ts>>8)&0xFF);
|
||||
_datagram[7]=(unsigned char)(ts & 0xFF);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int NETEQTEST_RTPpacket::setSSRC(WebRtc_UWord32 ssrc)
|
||||
{
|
||||
|
||||
if (_datagramLen < 12)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!_rtpParsed)
|
||||
{
|
||||
_rtpInfo.SSRC = ssrc;
|
||||
}
|
||||
|
||||
_datagram[8]=(unsigned char)((ssrc>>24)&0xFF);
|
||||
_datagram[9]=(unsigned char)((ssrc>>16)&0xFF);
|
||||
_datagram[10]=(unsigned char)((ssrc>>8)&0xFF);
|
||||
_datagram[11]=(unsigned char)(ssrc & 0xFF);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int NETEQTEST_RTPpacket::setMarkerBit(WebRtc_UWord8 mb)
|
||||
{
|
||||
|
||||
if (_datagramLen < 12)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (_rtpParsed)
|
||||
{
|
||||
_rtpInfo.markerBit = mb;
|
||||
}
|
||||
|
||||
if (mb)
|
||||
{
|
||||
_datagram[0] |= 0x01;
|
||||
}
|
||||
else
|
||||
{
|
||||
_datagram[0] &= 0xFE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int NETEQTEST_RTPpacket::setRTPheader(const WebRtcNetEQ_RTPInfo *RTPinfo)
|
||||
{
|
||||
if (_datagramLen < 12)
|
||||
{
|
||||
// this packet is not ok
|
||||
return -1;
|
||||
}
|
||||
|
||||
makeRTPheader(_datagram,
|
||||
RTPinfo->payloadType,
|
||||
RTPinfo->sequenceNumber,
|
||||
RTPinfo->timeStamp,
|
||||
RTPinfo->SSRC,
|
||||
RTPinfo->markerBit);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int NETEQTEST_RTPpacket::splitStereo(NETEQTEST_RTPpacket& slaveRtp, enum stereoModes mode)
|
||||
{
|
||||
// if mono, do nothing
|
||||
if (mode == stereoModeMono)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// check that the RTP header info is parsed
|
||||
parseHeader();
|
||||
|
||||
// start by copying the main rtp packet
|
||||
slaveRtp = *this;
|
||||
|
||||
if(_payloadLen == 0)
|
||||
{
|
||||
// do no more
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(_payloadLen%2 != 0)
|
||||
{
|
||||
// length must be a factor of 2
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
case stereoModeSample1:
|
||||
{
|
||||
// sample based codec with 1-byte samples
|
||||
splitStereoSample(slaveRtp, 1 /* 1 byte/sample */);
|
||||
break;
|
||||
}
|
||||
case stereoModeSample2:
|
||||
{
|
||||
// sample based codec with 2-byte samples
|
||||
splitStereoSample(slaveRtp, 2 /* 2 bytes/sample */);
|
||||
break;
|
||||
}
|
||||
case stereoModeFrame:
|
||||
{
|
||||
// frame based codec
|
||||
splitStereoFrame(slaveRtp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void NETEQTEST_RTPpacket::makeRTPheader(unsigned char* rtp_data, WebRtc_UWord8 payloadType, WebRtc_UWord16 seqNo, WebRtc_UWord32 timestamp, WebRtc_UWord32 ssrc, WebRtc_UWord8 markerBit) const
|
||||
{
|
||||
rtp_data[0]=(unsigned char)0x80;
|
||||
if (markerBit)
|
||||
{
|
||||
rtp_data[0] |= 0x01;
|
||||
}
|
||||
else
|
||||
{
|
||||
rtp_data[0] &= 0xFE;
|
||||
}
|
||||
rtp_data[1]=(unsigned char)(payloadType & 0xFF);
|
||||
rtp_data[2]=(unsigned char)((seqNo>>8)&0xFF);
|
||||
rtp_data[3]=(unsigned char)((seqNo)&0xFF);
|
||||
rtp_data[4]=(unsigned char)((timestamp>>24)&0xFF);
|
||||
rtp_data[5]=(unsigned char)((timestamp>>16)&0xFF);
|
||||
|
||||
rtp_data[6]=(unsigned char)((timestamp>>8)&0xFF);
|
||||
rtp_data[7]=(unsigned char)(timestamp & 0xFF);
|
||||
|
||||
rtp_data[8]=(unsigned char)((ssrc>>24)&0xFF);
|
||||
rtp_data[9]=(unsigned char)((ssrc>>16)&0xFF);
|
||||
|
||||
rtp_data[10]=(unsigned char)((ssrc>>8)&0xFF);
|
||||
rtp_data[11]=(unsigned char)(ssrc & 0xFF);
|
||||
}
|
||||
|
||||
|
||||
WebRtc_UWord16 NETEQTEST_RTPpacket::parseRTPheader(const WebRtc_UWord8 *datagram, int datagramLen, WebRtcNetEQ_RTPInfo *RTPinfo, WebRtc_UWord8 **payloadPtr) const
|
||||
{
|
||||
WebRtc_Word16 *rtp_data = (WebRtc_Word16 *) datagram;
|
||||
int i_P, i_X, i_CC, i_extlength=-1, i_padlength=0, i_startPosition;
|
||||
|
||||
i_P=(((WebRtc_UWord16)(rtp_data[0] & 0x20))>>5); /* Extract the P bit */
|
||||
i_X=(((WebRtc_UWord16)(rtp_data[0] & 0x10))>>4); /* Extract the X bit */
|
||||
i_CC=(WebRtc_UWord16)(rtp_data[0] & 0xF); /* Get the CC number */
|
||||
RTPinfo->markerBit = (WebRtc_UWord8) ((rtp_data[0] >> 15) & 0x01); /* Get the marker bit */
|
||||
RTPinfo->payloadType = (WebRtc_UWord8) ((rtp_data[0] >> 8) & 0x7F); /* Get the coder type */
|
||||
RTPinfo->sequenceNumber = ((( ((WebRtc_UWord16)rtp_data[1]) >> 8) & 0xFF) |
|
||||
( ((WebRtc_UWord16)(rtp_data[1] & 0xFF)) << 8)); /* Get the packet number */
|
||||
RTPinfo->timeStamp = ((((WebRtc_UWord16)rtp_data[2]) & 0xFF) << 24) |
|
||||
((((WebRtc_UWord16)rtp_data[2]) & 0xFF00) << 8) |
|
||||
((((WebRtc_UWord16)rtp_data[3]) >> 8) & 0xFF) |
|
||||
((((WebRtc_UWord16)rtp_data[3]) & 0xFF) << 8); /* Get timestamp */
|
||||
RTPinfo->SSRC=((((WebRtc_UWord16)rtp_data[4]) & 0xFF) << 24) |
|
||||
((((WebRtc_UWord16)rtp_data[4]) & 0xFF00) << 8) |
|
||||
((((WebRtc_UWord16)rtp_data[5]) >> 8) & 0xFF) |
|
||||
((((WebRtc_UWord16)rtp_data[5]) & 0xFF) << 8); /* Get the SSRC */
|
||||
|
||||
if (i_X==1) {
|
||||
/* Extention header exists. Find out how many WebRtc_Word32 it consists of */
|
||||
i_extlength=((( ((WebRtc_UWord16)rtp_data[7+2*i_CC]) >> 8) & 0xFF) |
|
||||
( ((WebRtc_UWord16)(rtp_data[7+2*i_CC]&0xFF)) << 8));
|
||||
}
|
||||
if (i_P==1) {
|
||||
/* Padding exists. Find out how many bytes the padding consists of */
|
||||
if (datagramLen & 0x1) {
|
||||
/* odd number of bytes => last byte in higher byte */
|
||||
i_padlength=(rtp_data[datagramLen>>1] & 0xFF);
|
||||
} else {
|
||||
/* even number of bytes => last byte in lower byte */
|
||||
i_padlength=(((WebRtc_UWord16)rtp_data[(datagramLen>>1)-1]) >> 8);
|
||||
}
|
||||
}
|
||||
|
||||
i_startPosition=12+4*(i_extlength+1)+4*i_CC;
|
||||
|
||||
if (payloadPtr) {
|
||||
*payloadPtr = (WebRtc_UWord8*) &rtp_data[i_startPosition>>1];
|
||||
}
|
||||
|
||||
return (WebRtc_UWord16) (datagramLen-i_startPosition-i_padlength);
|
||||
}
|
||||
|
||||
//void NETEQTEST_RTPpacket::splitStereoSample(WebRtc_UWord8 *data, WebRtc_UWord16 *lenBytes, WebRtc_UWord8 *slaveData, WebRtc_UWord16 *slaveLenBytes, int stride)
|
||||
void NETEQTEST_RTPpacket::splitStereoSample(NETEQTEST_RTPpacket& slaveRtp, int stride)
|
||||
{
|
||||
if(!_payloadPtr || !slaveRtp._payloadPtr
|
||||
|| _payloadLen <= 0 || slaveRtp._memSize < _memSize)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
WebRtc_UWord8 *readDataPtr = _payloadPtr;
|
||||
WebRtc_UWord8 *writeDataPtr = _payloadPtr;
|
||||
WebRtc_UWord8 *slaveData = slaveRtp._payloadPtr;
|
||||
|
||||
while (readDataPtr - _payloadPtr < _payloadLen)
|
||||
{
|
||||
// master data
|
||||
for (int ix = 0; ix < stride; ix++) {
|
||||
*writeDataPtr = *readDataPtr;
|
||||
writeDataPtr++;
|
||||
readDataPtr++;
|
||||
}
|
||||
|
||||
// slave data
|
||||
for (int ix = 0; ix < stride; ix++) {
|
||||
*slaveData = *readDataPtr;
|
||||
slaveData++;
|
||||
readDataPtr++;
|
||||
}
|
||||
}
|
||||
|
||||
_payloadLen /= 2;
|
||||
slaveRtp._payloadLen = _payloadLen;
|
||||
}
|
||||
|
||||
|
||||
//void NETEQTEST_RTPpacket::splitStereoFrame(WebRtc_UWord8 *data, WebRtc_UWord16 *lenBytes, WebRtc_UWord8 *slaveData, WebRtc_UWord16 *slaveLenBytes)
|
||||
void NETEQTEST_RTPpacket::splitStereoFrame(NETEQTEST_RTPpacket& slaveRtp)
|
||||
{
|
||||
if(!_payloadPtr || !slaveRtp._payloadPtr
|
||||
|| _payloadLen <= 0 || slaveRtp._memSize < _memSize)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
memmove(slaveRtp._payloadPtr, _payloadPtr + _payloadLen/2, _payloadLen/2);
|
||||
|
||||
_payloadLen /= 2;
|
||||
slaveRtp._payloadLen = _payloadLen;
|
||||
}
|
||||
|
||||
86
modules/audio_coding/NetEQ/main/test/NETEQTEST_RTPpacket.h
Normal file
86
modules/audio_coding/NetEQ/main/test/NETEQTEST_RTPpacket.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef NETEQTEST_RTPPACKET_H
|
||||
#define NETEQTEST_RTPPACKET_H
|
||||
|
||||
#include <map>
|
||||
#include <stdio.h>
|
||||
#include "typedefs.h"
|
||||
#include "webrtc_neteq_internal.h"
|
||||
|
||||
enum stereoModes {
|
||||
stereoModeMono,
|
||||
stereoModeSample1,
|
||||
stereoModeSample2,
|
||||
stereoModeFrame
|
||||
};
|
||||
|
||||
class NETEQTEST_RTPpacket
|
||||
{
|
||||
public:
|
||||
NETEQTEST_RTPpacket();
|
||||
NETEQTEST_RTPpacket(const NETEQTEST_RTPpacket& copyFromMe);
|
||||
NETEQTEST_RTPpacket & operator = (const NETEQTEST_RTPpacket & other);
|
||||
bool operator !() const { return (dataLen() < 0); };
|
||||
~NETEQTEST_RTPpacket();
|
||||
void reset();
|
||||
int readFromFile(FILE *fp);
|
||||
int readFixedFromFile(FILE *fp, int len);
|
||||
int writeToFile(FILE *fp);
|
||||
void blockPT(WebRtc_UWord8 pt);
|
||||
//WebRtc_Word16 payloadType();
|
||||
void parseHeader();
|
||||
void parseHeader(WebRtcNetEQ_RTPInfo & rtpInfo);
|
||||
WebRtcNetEQ_RTPInfo const * RTPinfo() const;
|
||||
WebRtc_UWord8 * datagram() const;
|
||||
WebRtc_UWord8 * payload() const;
|
||||
WebRtc_Word16 payloadLen() const;
|
||||
WebRtc_Word16 dataLen() const;
|
||||
bool isParsed() const;
|
||||
bool isLost() const;
|
||||
WebRtc_UWord32 time() const { return _receiveTime; };
|
||||
|
||||
WebRtc_UWord8 payloadType() const;
|
||||
WebRtc_UWord16 sequenceNumber() const;
|
||||
WebRtc_UWord32 timeStamp() const;
|
||||
WebRtc_UWord32 SSRC() const;
|
||||
WebRtc_UWord8 markerBit() const;
|
||||
|
||||
int setPayloadType(WebRtc_UWord8 pt);
|
||||
int setSequenceNumber(WebRtc_UWord16 sn);
|
||||
int setTimeStamp(WebRtc_UWord32 ts);
|
||||
int setSSRC(WebRtc_UWord32 ssrc);
|
||||
int setMarkerBit(WebRtc_UWord8 mb);
|
||||
void setTime(WebRtc_UWord32 receiveTime) { _receiveTime = receiveTime; };
|
||||
|
||||
int setRTPheader(const WebRtcNetEQ_RTPInfo *RTPinfo);
|
||||
|
||||
int splitStereo(NETEQTEST_RTPpacket& slaveRtp, enum stereoModes mode);
|
||||
|
||||
WebRtc_UWord8 * _datagram;
|
||||
WebRtc_UWord8 * _payloadPtr;
|
||||
int _memSize;
|
||||
WebRtc_Word16 _datagramLen;
|
||||
WebRtc_Word16 _payloadLen;
|
||||
WebRtcNetEQ_RTPInfo _rtpInfo;
|
||||
bool _rtpParsed;
|
||||
WebRtc_UWord32 _receiveTime;
|
||||
bool _lost;
|
||||
std::map<WebRtc_UWord8, bool> _blockList;
|
||||
|
||||
private:
|
||||
void makeRTPheader(unsigned char* rtp_data, WebRtc_UWord8 payloadType, WebRtc_UWord16 seqNo, WebRtc_UWord32 timestamp, WebRtc_UWord32 ssrc, WebRtc_UWord8 markerBit) const;
|
||||
WebRtc_UWord16 parseRTPheader(const WebRtc_UWord8 *datagram, int datagramLen, WebRtcNetEQ_RTPInfo *RTPinfo, WebRtc_UWord8 **payloadPtr = NULL) const;
|
||||
void splitStereoSample(NETEQTEST_RTPpacket& slaveRtp, int stride);
|
||||
void splitStereoFrame(NETEQTEST_RTPpacket& slaveRtp);
|
||||
};
|
||||
|
||||
#endif //NETEQTEST_RTPPACKET_H
|
||||
1753
modules/audio_coding/NetEQ/main/test/NetEqRTPplay.cc
Normal file
1753
modules/audio_coding/NetEQ/main/test/NetEqRTPplay.cc
Normal file
File diff suppressed because it is too large
Load Diff
76
modules/audio_coding/NetEQ/main/test/PayloadTypes.h
Normal file
76
modules/audio_coding/NetEQ/main/test/PayloadTypes.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* PayloadTypes.h */
|
||||
/* Used by NetEqRTPplay application */
|
||||
|
||||
/* RTP defined codepoints */
|
||||
#define NETEQ_CODEC_PCMU_PT 0
|
||||
#define NETEQ_CODEC_GSMFR_PT 3
|
||||
#define NETEQ_CODEC_G723_PT 4
|
||||
#define NETEQ_CODEC_DVI4_PT 125 // 8 kHz version
|
||||
//#define NETEQ_CODEC_DVI4_16_PT 6 // 16 kHz version
|
||||
#define NETEQ_CODEC_PCMA_PT 8
|
||||
#define NETEQ_CODEC_G722_PT 9
|
||||
#define NETEQ_CODEC_CN_PT 13
|
||||
//#define NETEQ_CODEC_G728_PT 15
|
||||
//#define NETEQ_CODEC_DVI4_11_PT 16 // 11.025 kHz version
|
||||
//#define NETEQ_CODEC_DVI4_22_PT 17 // 22.050 kHz version
|
||||
#define NETEQ_CODEC_G729_PT 18
|
||||
|
||||
/* Dynamic RTP codepoints as defined in VoiceEngine (file VEAPI.cpp) */
|
||||
#define NETEQ_CODEC_IPCMWB_PT 97
|
||||
#define NETEQ_CODEC_SPEEX8_PT 98
|
||||
#define NETEQ_CODEC_SPEEX16_PT 99
|
||||
#define NETEQ_CODEC_EG711U_PT 100
|
||||
#define NETEQ_CODEC_EG711A_PT 101
|
||||
#define NETEQ_CODEC_ILBC_PT 102
|
||||
#define NETEQ_CODEC_ISAC_PT 103
|
||||
#define NETEQ_CODEC_ISACLC_PT 119
|
||||
#define NETEQ_CODEC_ISACSWB_PT 104
|
||||
#define NETEQ_CODEC_AVT_PT 106
|
||||
#define NETEQ_CODEC_G722_1_16_PT 108
|
||||
#define NETEQ_CODEC_G722_1_24_PT 109
|
||||
#define NETEQ_CODEC_G722_1_32_PT 110
|
||||
#define NETEQ_CODEC_SC3_PT 111
|
||||
#define NETEQ_CODEC_AMR_PT 112
|
||||
#define NETEQ_CODEC_GSMEFR_PT 113
|
||||
//#define NETEQ_CODEC_ILBCRCU_PT 114
|
||||
#define NETEQ_CODEC_G726_16_PT 115
|
||||
#define NETEQ_CODEC_G726_24_PT 116
|
||||
#define NETEQ_CODEC_G726_32_PT 121
|
||||
#define NETEQ_CODEC_RED_PT 117
|
||||
#define NETEQ_CODEC_G726_40_PT 118
|
||||
//#define NETEQ_CODEC_ENERGY_PT 120
|
||||
#define NETEQ_CODEC_CN_WB_PT 105
|
||||
#define NETEQ_CODEC_CN_SWB_PT 126
|
||||
#define NETEQ_CODEC_G729_1_PT 107
|
||||
#define NETEQ_CODEC_G729D_PT 123
|
||||
#define NETEQ_CODEC_MELPE_PT 124
|
||||
|
||||
/* Extra dynamic codepoints */
|
||||
#define NETEQ_CODEC_AMRWB_PT 120
|
||||
#define NETEQ_CODEC_PCM16B_PT 93
|
||||
#define NETEQ_CODEC_PCM16B_WB_PT 94
|
||||
#define NETEQ_CODEC_PCM16B_SWB32KHZ_PT 95
|
||||
#define NETEQ_CODEC_PCM16B_SWB48KHZ_PT 96
|
||||
#define NETEQ_CODEC_MPEG4AAC_PT 122
|
||||
|
||||
|
||||
/* Not default in VoiceEngine */
|
||||
#define NETEQ_CODEC_G722_1C_24_PT 84
|
||||
#define NETEQ_CODEC_G722_1C_32_PT 85
|
||||
#define NETEQ_CODEC_G722_1C_48_PT 86
|
||||
|
||||
#define NETEQ_CODEC_SILK_8_PT 80
|
||||
#define NETEQ_CODEC_SILK_12_PT 81
|
||||
#define NETEQ_CODEC_SILK_16_PT 82
|
||||
#define NETEQ_CODEC_SILK_24_PT 83
|
||||
|
||||
64
modules/audio_coding/NetEQ/main/test/RTPanalyze.cc
Normal file
64
modules/audio_coding/NetEQ/main/test/RTPanalyze.cc
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
|
||||
#include "NETEQTEST_RTPpacket.h"
|
||||
|
||||
|
||||
/*********************/
|
||||
/* Misc. definitions */
|
||||
/*********************/
|
||||
|
||||
#define FIRSTLINELEN 40
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
FILE *inFile=fopen(argv[1],"rb");
|
||||
if (!inFile)
|
||||
{
|
||||
printf("Cannot open input file %s\n", argv[1]);
|
||||
return(-1);
|
||||
}
|
||||
printf("Input file: %s\n",argv[1]);
|
||||
|
||||
FILE *outFile=fopen(argv[2],"wt");
|
||||
if (!outFile)
|
||||
{
|
||||
printf("Cannot open output file %s\n", argv[2]);
|
||||
return(-1);
|
||||
}
|
||||
printf("Output file: %s\n\n",argv[2]);
|
||||
|
||||
// print file header
|
||||
fprintf(outFile, "SeqNo TimeStamp SendTime Size\n");
|
||||
|
||||
|
||||
// read file header
|
||||
char firstline[FIRSTLINELEN];
|
||||
fgets(firstline, FIRSTLINELEN, inFile);
|
||||
fread(firstline, 4+4+4+2+2, 1, inFile); // start_sec + start_usec + source + port + padding
|
||||
|
||||
NETEQTEST_RTPpacket packet;
|
||||
|
||||
while (packet.readFromFile(inFile) >= 0)
|
||||
{
|
||||
// write packet data to file
|
||||
fprintf(outFile, "%5hu %10lu %10lu %5hi\n",
|
||||
packet.sequenceNumber(), packet.timeStamp(), packet.time(), packet.dataLen());
|
||||
}
|
||||
|
||||
fclose(inFile);
|
||||
fclose(outFile);
|
||||
|
||||
return 0;
|
||||
}
|
||||
87
modules/audio_coding/NetEQ/main/test/RTPcat.cc
Normal file
87
modules/audio_coding/NetEQ/main/test/RTPcat.cc
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
|
||||
#include "NETEQTEST_RTPpacket.h"
|
||||
|
||||
/*********************/
|
||||
/* Misc. definitions */
|
||||
/*********************/
|
||||
|
||||
#define FIRSTLINELEN 40
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc < 3) {
|
||||
printf("Usage: RTPcat in1.rtp int2.rtp [...] out.rtp\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
FILE *inFile = fopen(argv[1], "rb");
|
||||
if (!inFile) {
|
||||
printf("Cannot open input file %s\n", argv[1]);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
FILE *outFile = fopen(argv[argc - 1], "wb"); // last parameter is output file
|
||||
if (!outFile) {
|
||||
printf("Cannot open output file %s\n", argv[argc - 1]);
|
||||
return (-1);
|
||||
}
|
||||
printf("Output RTP file: %s\n\n", argv[argc - 1]);
|
||||
|
||||
// read file header and write directly to output file
|
||||
char firstline[FIRSTLINELEN];
|
||||
fgets(firstline, FIRSTLINELEN, inFile);
|
||||
fputs(firstline, outFile);
|
||||
fread(firstline, 4 + 4 + 4 + 2 + 2, 1, inFile); // start_sec + start_usec + source + port + padding
|
||||
fwrite(firstline, 4 + 4 + 4 + 2 + 2, 1, outFile);
|
||||
|
||||
// close input file and re-open it later (easier to write the loop below)
|
||||
fclose(inFile);
|
||||
|
||||
for (int i = 1; i < argc - 1; i++) {
|
||||
|
||||
inFile = fopen(argv[i], "rb");
|
||||
if (!inFile) {
|
||||
printf("Cannot open input file %s\n", argv[i]);
|
||||
return (-1);
|
||||
}
|
||||
printf("Input RTP file: %s\n", argv[i]);
|
||||
|
||||
// skip file header
|
||||
fgets(firstline, FIRSTLINELEN, inFile);
|
||||
fread(firstline, 4 + 4 + 4 + 2 + 2, 1, inFile); // start_sec + start_usec + source + port + padding
|
||||
|
||||
NETEQTEST_RTPpacket packet;
|
||||
int packLen = packet.readFromFile(inFile);
|
||||
if (packLen < 0) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while (packLen >= 0) {
|
||||
|
||||
packet.writeToFile(outFile);
|
||||
|
||||
packLen = packet.readFromFile(inFile);
|
||||
|
||||
}
|
||||
|
||||
fclose(inFile);
|
||||
|
||||
}
|
||||
|
||||
fclose(outFile);
|
||||
|
||||
return 0;
|
||||
}
|
||||
136
modules/audio_coding/NetEQ/main/test/RTPchange.cc
Normal file
136
modules/audio_coding/NetEQ/main/test/RTPchange.cc
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
|
||||
#include "NETEQTEST_RTPpacket.h"
|
||||
|
||||
|
||||
/*********************/
|
||||
/* Misc. definitions */
|
||||
/*********************/
|
||||
|
||||
#define FIRSTLINELEN 40
|
||||
|
||||
bool pktCmp (NETEQTEST_RTPpacket *a, NETEQTEST_RTPpacket *b)
|
||||
{
|
||||
return (a->time() < b->time());
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
FILE *inFile=fopen(argv[1],"rb");
|
||||
if (!inFile)
|
||||
{
|
||||
printf("Cannot open input file %s\n", argv[1]);
|
||||
return(-1);
|
||||
}
|
||||
printf("Input RTP file: %s\n",argv[1]);
|
||||
|
||||
FILE *statFile=fopen(argv[2],"rt");
|
||||
if (!statFile)
|
||||
{
|
||||
printf("Cannot open timing file %s\n", argv[2]);
|
||||
return(-1);
|
||||
}
|
||||
printf("Timing file: %s\n",argv[2]);
|
||||
|
||||
FILE *outFile=fopen(argv[3],"wb");
|
||||
if (!outFile)
|
||||
{
|
||||
printf("Cannot open output file %s\n", argv[3]);
|
||||
return(-1);
|
||||
}
|
||||
printf("Output RTP file: %s\n\n",argv[3]);
|
||||
|
||||
// read all statistics and insert into map
|
||||
// read first line
|
||||
char tempStr[100];
|
||||
fgets(tempStr, 100, statFile);
|
||||
|
||||
// define map
|
||||
std::map<std::pair<WebRtc_UWord16, WebRtc_UWord32>, WebRtc_Word32> packetStats;
|
||||
WebRtc_UWord16 seqNo;
|
||||
WebRtc_UWord32 ts;
|
||||
WebRtc_Word32 sendTime;
|
||||
|
||||
while(fscanf(statFile, "%hu %lu %ld\n", &seqNo, &ts, &sendTime) == 3)
|
||||
{
|
||||
std::pair<WebRtc_UWord16, WebRtc_UWord32> tempPair = std::pair<WebRtc_UWord16, WebRtc_UWord32>(seqNo, ts);
|
||||
|
||||
packetStats[tempPair] = sendTime;
|
||||
}
|
||||
|
||||
fclose(statFile);
|
||||
|
||||
// read file header and write directly to output file
|
||||
char firstline[FIRSTLINELEN];
|
||||
fgets(firstline, FIRSTLINELEN, inFile);
|
||||
fputs(firstline, outFile);
|
||||
fread(firstline, 4+4+4+2+2, 1, inFile); // start_sec + start_usec + source + port + padding
|
||||
fwrite(firstline, 4+4+4+2+2, 1, outFile);
|
||||
|
||||
std::vector<NETEQTEST_RTPpacket *> packetVec;
|
||||
int i = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
// insert in vector
|
||||
NETEQTEST_RTPpacket *newPacket = new NETEQTEST_RTPpacket();
|
||||
if (newPacket->readFromFile(inFile) < 0)
|
||||
{
|
||||
// end of file
|
||||
break;
|
||||
}
|
||||
|
||||
// look for new send time in statistics vector
|
||||
std::pair<WebRtc_UWord16, WebRtc_UWord32> tempPair =
|
||||
std::pair<WebRtc_UWord16, WebRtc_UWord32>(newPacket->sequenceNumber(), newPacket->timeStamp());
|
||||
|
||||
WebRtc_Word32 newSendTime = packetStats[tempPair];
|
||||
if (newSendTime >= 0)
|
||||
{
|
||||
newPacket->setTime(newSendTime); // set new send time
|
||||
packetVec.push_back(newPacket); // insert in vector
|
||||
}
|
||||
else
|
||||
{
|
||||
// negative value represents lost packet
|
||||
// don't insert, but delete packet object
|
||||
delete newPacket;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// sort the vector according to send times
|
||||
std::sort(packetVec.begin(), packetVec.end(), pktCmp);
|
||||
|
||||
std::vector<NETEQTEST_RTPpacket *>::iterator it;
|
||||
for (it = packetVec.begin(); it != packetVec.end(); it++)
|
||||
{
|
||||
// write to out file
|
||||
if ((*it)->writeToFile(outFile) < 0)
|
||||
{
|
||||
printf("Error writing to file\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
// delete packet
|
||||
delete *it;
|
||||
}
|
||||
|
||||
fclose(inFile);
|
||||
fclose(outFile);
|
||||
|
||||
return 0;
|
||||
}
|
||||
1985
modules/audio_coding/NetEQ/main/test/RTPencode.cc
Normal file
1985
modules/audio_coding/NetEQ/main/test/RTPencode.cc
Normal file
File diff suppressed because it is too large
Load Diff
198
modules/audio_coding/NetEQ/main/test/RTPjitter.cc
Normal file
198
modules/audio_coding/NetEQ/main/test/RTPjitter.cc
Normal file
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* header includes */
|
||||
#include "typedefs.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef WIN32
|
||||
#include <winsock2.h>
|
||||
#include <io.h>
|
||||
#endif
|
||||
#ifdef WEBRTC_LINUX
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#include <search.h>
|
||||
#include <float.h>
|
||||
|
||||
/*********************/
|
||||
/* Misc. definitions */
|
||||
/*********************/
|
||||
|
||||
#define FIRSTLINELEN 40
|
||||
#define CHECK_ZERO(a) {int errCode = a; if((errCode)!=0){fprintf(stderr,"\n %s \n line: %d \n error at %s\n Error Code = %d\n",__FILE__,__LINE__,#a, WebRtcNetEQ_GetErrorCode(inst)); exit(0);}}
|
||||
#define CHECK_NOT_NULL(a) if((a)==NULL){fprintf(stderr,"\n %s \n line: %d \nerror at %s\n",__FILE__,__LINE__,#a );return(-1);}
|
||||
|
||||
/********************/
|
||||
/* Global variables */
|
||||
/********************/
|
||||
|
||||
FILE *in_file;
|
||||
FILE *out_file;
|
||||
FILE *dat_file;
|
||||
|
||||
|
||||
struct arr_time {
|
||||
float time;
|
||||
WebRtc_UWord32 ix;
|
||||
};
|
||||
|
||||
int filelen(FILE *fid)
|
||||
{
|
||||
fpos_t cur_pos;
|
||||
int len;
|
||||
|
||||
if (!fid || fgetpos(fid, &cur_pos)) {
|
||||
return(-1);
|
||||
}
|
||||
|
||||
fseek(fid, 0, SEEK_END);
|
||||
len = ftell(fid);
|
||||
|
||||
fsetpos(fid, &cur_pos);
|
||||
|
||||
return (len);
|
||||
}
|
||||
|
||||
int compare_arr_time(const void *x, const void *y);
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
unsigned int dat_len, rtp_len, Npack, k;
|
||||
arr_time *time_vec;
|
||||
char firstline[FIRSTLINELEN];
|
||||
unsigned char *rtp_vec, **packet_ptr, *temp_packet;
|
||||
WebRtc_UWord16 len;
|
||||
WebRtc_UWord32 *offset;
|
||||
|
||||
/* check number of parameters */
|
||||
if (argc != 4) {
|
||||
/* print help text and exit */
|
||||
printf("Apply jitter on RTP stream.\n");
|
||||
printf("The program reads an RTP stream and packet timing from two files.\n");
|
||||
printf("The RTP stream is modified to have the same jitter as described in the timing files.\n");
|
||||
printf("The format of the RTP stream file should be the same as for rtpplay,\n");
|
||||
printf("and can be obtained e.g., from Ethereal by using\n");
|
||||
printf("Statistics -> RTP -> Show All Streams -> [select a stream] -> Save As\n\n");
|
||||
printf("Usage:\n\n");
|
||||
printf("%s RTP_infile dat_file RTP_outfile\n", argv[0]);
|
||||
printf("where:\n");
|
||||
|
||||
printf("RTP_infile : RTP stream input file\n\n");
|
||||
|
||||
printf("dat_file : file with packet arrival times in ms\n\n");
|
||||
|
||||
printf("RTP_outfile : RTP stream output file\n\n");
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
in_file=fopen(argv[1],"rb");
|
||||
CHECK_NOT_NULL(in_file);
|
||||
printf("Input file: %s\n",argv[1]);
|
||||
dat_file=fopen(argv[2],"rb");
|
||||
CHECK_NOT_NULL(dat_file);
|
||||
printf("Dat-file: %s\n",argv[2]);
|
||||
out_file=fopen(argv[3],"wb");
|
||||
CHECK_NOT_NULL(out_file);
|
||||
printf("Output file: %s\n\n",argv[3]);
|
||||
|
||||
time_vec = (arr_time *) malloc(sizeof(arr_time)*(filelen(dat_file)/sizeof(float)) + 1000); // add 1000 bytes to avoid (rare) strange error
|
||||
if (time_vec==NULL) {
|
||||
fprintf(stderr, "Error: could not allocate memory for reading dat file\n");
|
||||
goto closing;
|
||||
}
|
||||
|
||||
dat_len=0;
|
||||
while(fread(&(time_vec[dat_len].time),sizeof(float),1,dat_file)>0) {
|
||||
time_vec[dat_len].ix=dat_len;
|
||||
dat_len++;
|
||||
}
|
||||
|
||||
qsort(time_vec,dat_len,sizeof(arr_time),compare_arr_time);
|
||||
|
||||
|
||||
rtp_vec = (unsigned char *) malloc(sizeof(unsigned char)*filelen(in_file));
|
||||
if (rtp_vec==NULL) {
|
||||
fprintf(stderr,"Error: could not allocate memory for reading rtp file\n");
|
||||
goto closing;
|
||||
}
|
||||
|
||||
// read file header and write directly to output file
|
||||
fgets(firstline, FIRSTLINELEN, in_file);
|
||||
fputs(firstline, out_file);
|
||||
fread(firstline, 4+4+4+2+2, 1, in_file); // start_sec + start_usec + source + port + padding
|
||||
fwrite(firstline, 4+4+4+2+2, 1, out_file);
|
||||
|
||||
// read all RTP packets into vector
|
||||
rtp_len=0;
|
||||
Npack=0;
|
||||
len=(WebRtc_UWord16) fread(&rtp_vec[rtp_len], sizeof(unsigned char), 2, in_file); // read length of first packet
|
||||
while(len==2) {
|
||||
len = ntohs(*((WebRtc_UWord16 *)(rtp_vec + rtp_len)));
|
||||
rtp_len += 2;
|
||||
if(fread(&rtp_vec[rtp_len], sizeof(unsigned char), len-2, in_file)!=(unsigned) (len-2)) {
|
||||
fprintf(stderr,"Error: currupt packet length\n");
|
||||
goto closing;
|
||||
}
|
||||
rtp_len += len-2;
|
||||
Npack++;
|
||||
len=(WebRtc_UWord16) fread(&rtp_vec[rtp_len], sizeof(unsigned char), 2, in_file); // read length of next packet
|
||||
}
|
||||
|
||||
packet_ptr = (unsigned char **) malloc(Npack*sizeof(unsigned char*));
|
||||
|
||||
packet_ptr[0]=rtp_vec;
|
||||
k=1;
|
||||
while(k<Npack) {
|
||||
len = ntohs(*((WebRtc_UWord16 *) packet_ptr[k-1]));
|
||||
packet_ptr[k]=packet_ptr[k-1]+len;
|
||||
k++;
|
||||
}
|
||||
|
||||
for(k=0; k<dat_len && k<Npack; k++) {
|
||||
if(time_vec[k].time < FLT_MAX && time_vec[k].ix < Npack){
|
||||
temp_packet = packet_ptr[time_vec[k].ix];
|
||||
offset = (WebRtc_UWord32 *) (temp_packet+4);
|
||||
if ( time_vec[k].time >= 0 ) {
|
||||
*offset = htonl((WebRtc_UWord32) time_vec[k].time);
|
||||
}
|
||||
else {
|
||||
*offset = htonl((WebRtc_UWord32) 0);
|
||||
fprintf(stderr, "Warning: negative receive time in dat file transformed to 0.\n");
|
||||
}
|
||||
|
||||
// write packet to file
|
||||
fwrite(temp_packet, sizeof(unsigned char), ntohs(*((WebRtc_UWord16*) temp_packet)), out_file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
closing:
|
||||
free(time_vec);
|
||||
free(rtp_vec);
|
||||
fclose(in_file);
|
||||
fclose(dat_file);
|
||||
fclose(out_file);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int compare_arr_time(const void *xp, const void *yp) {
|
||||
|
||||
if(((arr_time *)xp)->time == ((arr_time *)yp)->time)
|
||||
return(0);
|
||||
else if(((arr_time *)xp)->time > ((arr_time *)yp)->time)
|
||||
return(1);
|
||||
|
||||
return(-1);
|
||||
}
|
||||
95
modules/audio_coding/NetEQ/main/test/RTPtimeshift.cc
Normal file
95
modules/audio_coding/NetEQ/main/test/RTPtimeshift.cc
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
|
||||
#include "NETEQTEST_RTPpacket.h"
|
||||
|
||||
|
||||
/*********************/
|
||||
/* Misc. definitions */
|
||||
/*********************/
|
||||
|
||||
#define FIRSTLINELEN 40
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if(argc < 4 || argc > 6)
|
||||
{
|
||||
printf("Usage: RTPtimeshift in.rtp out.rtp newStartTS [newStartSN [newStartArrTime]]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
FILE *inFile=fopen(argv[1],"rb");
|
||||
if (!inFile)
|
||||
{
|
||||
printf("Cannot open input file %s\n", argv[1]);
|
||||
return(-1);
|
||||
}
|
||||
printf("Input RTP file: %s\n",argv[1]);
|
||||
|
||||
FILE *outFile=fopen(argv[2],"wb");
|
||||
if (!outFile)
|
||||
{
|
||||
printf("Cannot open output file %s\n", argv[2]);
|
||||
return(-1);
|
||||
}
|
||||
printf("Output RTP file: %s\n\n",argv[2]);
|
||||
|
||||
// read file header and write directly to output file
|
||||
char firstline[FIRSTLINELEN];
|
||||
fgets(firstline, FIRSTLINELEN, inFile);
|
||||
fputs(firstline, outFile);
|
||||
fread(firstline, 4+4+4+2+2, 1, inFile); // start_sec + start_usec + source + port + padding
|
||||
fwrite(firstline, 4+4+4+2+2, 1, outFile);
|
||||
|
||||
NETEQTEST_RTPpacket packet;
|
||||
int packLen = packet.readFromFile(inFile);
|
||||
if (packLen < 0)
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// get new start TS and start SeqNo from arguments
|
||||
WebRtc_UWord32 TSdiff = atoi(argv[3]) - packet.timeStamp();
|
||||
WebRtc_UWord16 SNdiff = 0;
|
||||
WebRtc_UWord32 ATdiff = 0;
|
||||
if (argc > 4)
|
||||
{
|
||||
if (argv[4] >= 0)
|
||||
SNdiff = atoi(argv[4]) - packet.sequenceNumber();
|
||||
if (argc > 5)
|
||||
{
|
||||
if (argv[5] >= 0)
|
||||
ATdiff = atoi(argv[5]) - packet.time();
|
||||
}
|
||||
}
|
||||
|
||||
while (packLen >= 0)
|
||||
{
|
||||
|
||||
packet.setTimeStamp(packet.timeStamp() + TSdiff);
|
||||
packet.setSequenceNumber(packet.sequenceNumber() + SNdiff);
|
||||
packet.setTime(packet.time() + ATdiff);
|
||||
|
||||
packet.writeToFile(outFile);
|
||||
|
||||
packLen = packet.readFromFile(inFile);
|
||||
|
||||
}
|
||||
|
||||
fclose(inFile);
|
||||
fclose(outFile);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
function outStruct = parse_delay_file(file)
|
||||
|
||||
fid = fopen(file, 'rb');
|
||||
if fid == -1
|
||||
error('Cannot open file %s', file);
|
||||
end
|
||||
|
||||
textline = fgetl(fid);
|
||||
if ~strncmp(textline, '#!NetEQ_Delay_Logging', 21)
|
||||
error('Wrong file format');
|
||||
end
|
||||
|
||||
ver = sscanf(textline, '#!NetEQ_Delay_Logging%d.%d');
|
||||
if ~all(ver == [2; 0])
|
||||
error('Wrong version of delay logging function')
|
||||
end
|
||||
|
||||
|
||||
start_pos = ftell(fid);
|
||||
fseek(fid, -12, 'eof');
|
||||
textline = fgetl(fid);
|
||||
if ~strncmp(textline, 'End of file', 21)
|
||||
error('File ending is not correct. Seems like the simulation ended abnormally.');
|
||||
end
|
||||
|
||||
fseek(fid,-12-4, 'eof');
|
||||
Npackets = fread(fid, 1, 'int32');
|
||||
fseek(fid, start_pos, 'bof');
|
||||
|
||||
rtpts = zeros(Npackets, 1);
|
||||
seqno = zeros(Npackets, 1);
|
||||
pt = zeros(Npackets, 1);
|
||||
plen = zeros(Npackets, 1);
|
||||
recin_t = nan*ones(Npackets, 1);
|
||||
decode_t = nan*ones(Npackets, 1);
|
||||
playout_delay = zeros(Npackets, 1);
|
||||
optbuf = zeros(Npackets, 1);
|
||||
|
||||
fs_ix = 1;
|
||||
clock = 0;
|
||||
ts_ix = 1;
|
||||
ended = 0;
|
||||
late_packets = 0;
|
||||
fs_now = 8000;
|
||||
last_decode_k = 0;
|
||||
tot_expand = 0;
|
||||
tot_accelerate = 0;
|
||||
tot_preemptive = 0;
|
||||
|
||||
while not(ended)
|
||||
signal = fread(fid, 1, '*int32');
|
||||
|
||||
switch signal
|
||||
case 3 % NETEQ_DELAY_LOGGING_SIGNAL_CLOCK
|
||||
clock = fread(fid, 1, '*float32');
|
||||
|
||||
% keep on reading batches of M until the signal is no longer "3"
|
||||
% read int32 + float32 in one go
|
||||
% this is to save execution time
|
||||
temp = [3; 0];
|
||||
M = 120;
|
||||
while all(temp(1,:) == 3)
|
||||
fp = ftell(fid);
|
||||
temp = fread(fid, [2 M], '*int32');
|
||||
end
|
||||
|
||||
% back up to last clock event
|
||||
fseek(fid, fp - ftell(fid) + ...
|
||||
(find(temp(1,:) ~= 3, 1 ) - 2) * 2 * 4 + 4, 'cof');
|
||||
% read the last clock value
|
||||
clock = fread(fid, 1, '*float32');
|
||||
|
||||
case 1 % NETEQ_DELAY_LOGGING_SIGNAL_RECIN
|
||||
temp_ts = fread(fid, 1, 'uint32');
|
||||
|
||||
if late_packets > 0
|
||||
temp_ix = ts_ix - 1;
|
||||
while (temp_ix >= 1) && (rtpts(temp_ix) ~= temp_ts)
|
||||
% TODO(hlundin): use matlab vector search instead?
|
||||
temp_ix = temp_ix - 1;
|
||||
end
|
||||
|
||||
if temp_ix >= 1
|
||||
% the ts was found in the vector
|
||||
late_packets = late_packets - 1;
|
||||
else
|
||||
temp_ix = ts_ix;
|
||||
ts_ix = ts_ix + 1;
|
||||
end
|
||||
else
|
||||
temp_ix = ts_ix;
|
||||
ts_ix = ts_ix + 1;
|
||||
end
|
||||
|
||||
rtpts(temp_ix) = temp_ts;
|
||||
seqno(temp_ix) = fread(fid, 1, 'uint16');
|
||||
pt(temp_ix) = fread(fid, 1, 'int32');
|
||||
plen(temp_ix) = fread(fid, 1, 'int16');
|
||||
recin_t(temp_ix) = clock;
|
||||
|
||||
case 2 % NETEQ_DELAY_LOGGING_SIGNAL_FLUSH
|
||||
% do nothing
|
||||
|
||||
case 4 % NETEQ_DELAY_LOGGING_SIGNAL_EOF
|
||||
ended = 1;
|
||||
|
||||
case 5 % NETEQ_DELAY_LOGGING_SIGNAL_DECODE
|
||||
last_decode_ts = fread(fid, 1, 'uint32');
|
||||
temp_delay = fread(fid, 1, 'uint16');
|
||||
|
||||
k = find(rtpts(1:(ts_ix - 1))==last_decode_ts,1,'last');
|
||||
if ~isempty(k)
|
||||
decode_t(k) = clock;
|
||||
playout_delay(k) = temp_delay + ...
|
||||
5 * fs_now / 8000; % add overlap length
|
||||
last_decode_k = k;
|
||||
end
|
||||
|
||||
case 6 % NETEQ_DELAY_LOGGING_SIGNAL_CHANGE_FS
|
||||
fsvec(fs_ix) = fread(fid, 1, 'uint16');
|
||||
fschange_ts(fs_ix) = last_decode_ts;
|
||||
fs_now = fsvec(fs_ix);
|
||||
fs_ix = fs_ix + 1;
|
||||
|
||||
case 7 % NETEQ_DELAY_LOGGING_SIGNAL_MERGE_INFO
|
||||
playout_delay(last_decode_k) = playout_delay(last_decode_k) ...
|
||||
+ fread(fid, 1, 'int32');
|
||||
|
||||
case 8 % NETEQ_DELAY_LOGGING_SIGNAL_EXPAND_INFO
|
||||
temp = fread(fid, 1, 'int32');
|
||||
if last_decode_k ~= 0
|
||||
tot_expand = tot_expand + temp / (fs_now / 1000);
|
||||
end
|
||||
|
||||
case 9 % NETEQ_DELAY_LOGGING_SIGNAL_ACCELERATE_INFO
|
||||
temp = fread(fid, 1, 'int32');
|
||||
if last_decode_k ~= 0
|
||||
tot_accelerate = tot_accelerate + temp / (fs_now / 1000);
|
||||
end
|
||||
|
||||
case 10 % NETEQ_DELAY_LOGGING_SIGNAL_PREEMPTIVE_INFO
|
||||
temp = fread(fid, 1, 'int32');
|
||||
if last_decode_k ~= 0
|
||||
tot_preemptive = tot_preemptive + temp / (fs_now / 1000);
|
||||
end
|
||||
|
||||
case 11 % NETEQ_DELAY_LOGGING_SIGNAL_OPTBUF
|
||||
optbuf(last_decode_k) = fread(fid, 1, 'int32');
|
||||
|
||||
case 12 % NETEQ_DELAY_LOGGING_SIGNAL_DECODE_ONE_DESC
|
||||
last_decode_ts = fread(fid, 1, 'uint32');
|
||||
k = ts_ix - 1;
|
||||
|
||||
while (k >= 1) && (rtpts(k) ~= last_decode_ts)
|
||||
% TODO(hlundin): use matlab vector search instead?
|
||||
k = k - 1;
|
||||
end
|
||||
|
||||
if k < 1
|
||||
% packet not received yet
|
||||
k = ts_ix;
|
||||
rtpts(ts_ix) = last_decode_ts;
|
||||
late_packets = late_packets + 1;
|
||||
end
|
||||
|
||||
decode_t(k) = clock;
|
||||
playout_delay(k) = fread(fid, 1, 'uint16') + ...
|
||||
5 * fs_now / 8000; % add overlap length
|
||||
last_decode_k = k;
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
fclose(fid);
|
||||
|
||||
outStruct = struct(...
|
||||
'ts', rtpts, ...
|
||||
'sn', seqno, ...
|
||||
'pt', pt,...
|
||||
'plen', plen,...
|
||||
'arrival', recin_t,...
|
||||
'decode', decode_t,...
|
||||
'fs', fsvec(:),...
|
||||
'fschange_ts', fschange_ts(:),...
|
||||
'playout_delay', playout_delay,...
|
||||
'tot_expand', tot_expand,...
|
||||
'tot_accelerate', tot_accelerate,...
|
||||
'tot_preemptive', tot_preemptive,...
|
||||
'optbuf', optbuf);
|
||||
@@ -0,0 +1,187 @@
|
||||
function [delay_struct, delayvalues] = plot_neteq_delay(delayfile, varargin)
|
||||
|
||||
% InfoStruct = plot_neteq_delay(delayfile)
|
||||
% InfoStruct = plot_neteq_delay(delayfile, 'skipdelay', skip_seconds)
|
||||
%
|
||||
% Henrik Lundin, 2006-11-17
|
||||
% Henrik Lundin, 2011-05-17
|
||||
%
|
||||
|
||||
try
|
||||
s = parse_delay_file(delayfile);
|
||||
catch
|
||||
error(lasterr);
|
||||
end
|
||||
|
||||
delayskip=0;
|
||||
noplot=0;
|
||||
arg_ptr=1;
|
||||
delaypoints=[];
|
||||
|
||||
s.sn=unwrap_seqno(s.sn);
|
||||
|
||||
while arg_ptr+1 <= nargin
|
||||
switch lower(varargin{arg_ptr})
|
||||
case {'skipdelay', 'delayskip'}
|
||||
% skip a number of seconds in the beginning when calculating delays
|
||||
delayskip = varargin{arg_ptr+1};
|
||||
arg_ptr = arg_ptr + 2;
|
||||
case 'noplot'
|
||||
noplot=1;
|
||||
arg_ptr = arg_ptr + 1;
|
||||
case {'get_delay', 'getdelay'}
|
||||
% return a vector of delay values for the points in the given vector
|
||||
delaypoints = varargin{arg_ptr+1};
|
||||
arg_ptr = arg_ptr + 2;
|
||||
otherwise
|
||||
warning('Unknown switch %s\n', varargin{arg_ptr});
|
||||
arg_ptr = arg_ptr + 1;
|
||||
end
|
||||
end
|
||||
|
||||
% find lost frames that were covered by one-descriptor decoding
|
||||
one_desc_ix=find(isnan(s.arrival));
|
||||
for k=1:length(one_desc_ix)
|
||||
ix=find(s.ts==max(s.ts(s.ts(one_desc_ix(k))>s.ts)));
|
||||
s.sn(one_desc_ix(k))=s.sn(ix)+1;
|
||||
s.pt(one_desc_ix(k))=s.pt(ix);
|
||||
s.arrival(one_desc_ix(k))=s.arrival(ix)+s.decode(one_desc_ix(k))-s.decode(ix);
|
||||
end
|
||||
|
||||
% remove duplicate received frames that were never decoded (RED codec)
|
||||
if length(unique(s.ts(isfinite(s.ts)))) < length(s.ts(isfinite(s.ts)))
|
||||
ix=find(isfinite(s.decode));
|
||||
s.sn=s.sn(ix);
|
||||
s.ts=s.ts(ix);
|
||||
s.arrival=s.arrival(ix);
|
||||
s.playout_delay=s.playout_delay(ix);
|
||||
s.pt=s.pt(ix);
|
||||
s.optbuf=s.optbuf(ix);
|
||||
plen=plen(ix);
|
||||
s.decode=s.decode(ix);
|
||||
end
|
||||
|
||||
% find non-unique sequence numbers
|
||||
[~,un_ix]=unique(s.sn);
|
||||
nonun_ix=setdiff(1:length(s.sn),un_ix);
|
||||
if ~isempty(nonun_ix)
|
||||
warning('RTP sequence numbers are in error');
|
||||
end
|
||||
|
||||
% sort vectors
|
||||
[s.sn,sort_ix]=sort(s.sn);
|
||||
s.ts=s.ts(sort_ix);
|
||||
s.arrival=s.arrival(sort_ix);
|
||||
s.decode=s.decode(sort_ix);
|
||||
s.playout_delay=s.playout_delay(sort_ix);
|
||||
s.pt=s.pt(sort_ix);
|
||||
|
||||
send_t=s.ts-s.ts(1);
|
||||
if length(s.fs)<1
|
||||
warning('No info about sample rate found in file. Using default 8000.');
|
||||
s.fs(1)=8000;
|
||||
s.fschange_ts(1)=min(s.ts);
|
||||
elseif s.fschange_ts(1)>min(s.ts)
|
||||
s.fschange_ts(1)=min(s.ts);
|
||||
end
|
||||
|
||||
end_ix=length(send_t);
|
||||
for k=length(s.fs):-1:1
|
||||
start_ix=find(s.ts==s.fschange_ts(k));
|
||||
send_t(start_ix:end_ix)=send_t(start_ix:end_ix)/s.fs(k)*1000;
|
||||
s.playout_delay(start_ix:end_ix)=s.playout_delay(start_ix:end_ix)/s.fs(k)*1000;
|
||||
s.optbuf(start_ix:end_ix)=s.optbuf(start_ix:end_ix)/s.fs(k)*1000;
|
||||
end_ix=start_ix-1;
|
||||
end
|
||||
|
||||
tot_time=max(send_t)-min(send_t);
|
||||
|
||||
seq_ix=s.sn-min(s.sn)+1;
|
||||
send_t=send_t+max(min(s.arrival-send_t),0);
|
||||
|
||||
plot_send_t=nan*ones(max(seq_ix),1);
|
||||
plot_send_t(seq_ix)=send_t;
|
||||
plot_nw_delay=nan*ones(max(seq_ix),1);
|
||||
plot_nw_delay(seq_ix)=s.arrival-send_t;
|
||||
|
||||
cng_ix=find(s.pt~=13); % find those packets that are not CNG/SID
|
||||
|
||||
if noplot==0
|
||||
h=plot(plot_send_t/1000,plot_nw_delay);
|
||||
set(h,'color',0.75*[1 1 1]);
|
||||
hold on
|
||||
if any(s.optbuf~=0)
|
||||
peak_ix=find(s.optbuf(cng_ix)<0); % peak mode is labeled with negative values
|
||||
no_peak_ix=find(s.optbuf(cng_ix)>0); %setdiff(1:length(cng_ix),peak_ix);
|
||||
h1=plot(send_t(cng_ix(peak_ix))/1000,...
|
||||
s.arrival(cng_ix(peak_ix))+abs(s.optbuf(cng_ix(peak_ix)))-send_t(cng_ix(peak_ix)),...
|
||||
'r.');
|
||||
h2=plot(send_t(cng_ix(no_peak_ix))/1000,...
|
||||
s.arrival(cng_ix(no_peak_ix))+abs(s.optbuf(cng_ix(no_peak_ix)))-send_t(cng_ix(no_peak_ix)),...
|
||||
'g.');
|
||||
set([h1, h2],'markersize',1)
|
||||
end
|
||||
%h=plot(send_t(seq_ix)/1000,s.decode+s.playout_delay-send_t(seq_ix));
|
||||
h=plot(send_t(cng_ix)/1000,s.decode(cng_ix)+s.playout_delay(cng_ix)-send_t(cng_ix));
|
||||
set(h,'linew',1.5);
|
||||
hold off
|
||||
ax1=axis;
|
||||
axis tight
|
||||
ax2=axis;
|
||||
axis([ax2(1:3) ax1(4)])
|
||||
end
|
||||
|
||||
|
||||
% calculate delays and other parameters
|
||||
|
||||
delayskip_ix = find(send_t-send_t(1)>=delayskip*1000, 1 );
|
||||
|
||||
use_ix = intersect(cng_ix,... % use those that are not CNG/SID frames...
|
||||
intersect(find(isfinite(s.decode)),... % ... that did arrive ...
|
||||
(delayskip_ix:length(s.decode))')); % ... and are sent after delayskip seconds
|
||||
|
||||
mean_delay = mean(s.decode(use_ix)+s.playout_delay(use_ix)-send_t(use_ix));
|
||||
neteq_delay = mean(s.decode(use_ix)+s.playout_delay(use_ix)-s.arrival(use_ix));
|
||||
|
||||
Npack=max(s.sn(delayskip_ix:end))-min(s.sn(delayskip_ix:end))+1;
|
||||
nw_lossrate=(Npack-length(s.sn(delayskip_ix:end)))/Npack;
|
||||
neteq_lossrate=(length(s.sn(delayskip_ix:end))-length(use_ix))/Npack;
|
||||
|
||||
delay_struct=struct('mean_delay',mean_delay,'neteq_delay',neteq_delay,...
|
||||
'nw_lossrate',nw_lossrate,'neteq_lossrate',neteq_lossrate,...
|
||||
'tot_expand',round(s.tot_expand),'tot_accelerate',round(s.tot_accelerate),...
|
||||
'tot_preemptive',round(s.tot_preemptive),'tot_time',tot_time,...
|
||||
'filename',delayfile,'units','ms','fs',unique(s.fs));
|
||||
|
||||
if not(isempty(delaypoints))
|
||||
delayvalues=interp1(send_t(cng_ix),...
|
||||
s.decode(cng_ix)+s.playout_delay(cng_ix)-send_t(cng_ix),...
|
||||
delaypoints,'nearest',NaN);
|
||||
else
|
||||
delayvalues=[];
|
||||
end
|
||||
|
||||
|
||||
|
||||
% SUBFUNCTIONS %
|
||||
|
||||
function y=unwrap_seqno(x)
|
||||
|
||||
jumps=find(abs((diff(x)-1))>65000);
|
||||
|
||||
while ~isempty(jumps)
|
||||
n=jumps(1);
|
||||
if x(n+1)-x(n) < 0
|
||||
% negative jump
|
||||
x(n+1:end)=x(n+1:end)+65536;
|
||||
else
|
||||
% positive jump
|
||||
x(n+1:end)=x(n+1:end)-65536;
|
||||
end
|
||||
|
||||
jumps=find(abs((diff(x(n+1:end))-1))>65000);
|
||||
end
|
||||
|
||||
y=x;
|
||||
|
||||
return;
|
||||
47
modules/audio_coding/NetEQ/main/test/ptypes.txt
Normal file
47
modules/audio_coding/NetEQ/main/test/ptypes.txt
Normal file
@@ -0,0 +1,47 @@
|
||||
pcmu 0
|
||||
gsmfr 3
|
||||
g723 4
|
||||
dvi4 125
|
||||
pcma 8
|
||||
g722 9
|
||||
cn 13
|
||||
g729 18
|
||||
ipcmwb 97
|
||||
speex8 98
|
||||
speex16 99
|
||||
eg711u 100
|
||||
eg711a 101
|
||||
ilbc 102
|
||||
isac 103
|
||||
isaclc 119
|
||||
isacswb 104
|
||||
avt 106
|
||||
g722_1_16 108
|
||||
g722_1_24 109
|
||||
g722_1_32 110
|
||||
g722_1c_24 84
|
||||
g722_1c_32 85
|
||||
g722_1c_48 86
|
||||
//sc3 111
|
||||
amr 112
|
||||
gsmefr 113
|
||||
g726_16 115
|
||||
g726_24 116
|
||||
g726_32 121
|
||||
red 117
|
||||
g726_40 118
|
||||
cn_wb 105
|
||||
cn_swb32 126
|
||||
g729_1 107
|
||||
//g729d 123
|
||||
amrwb 120
|
||||
pcm16b 93
|
||||
pcm16b_wb 94
|
||||
pcm16b_swb32khz 95
|
||||
//pcm16b_swb48khz 96
|
||||
//mpeg4aac 122
|
||||
silk8 80
|
||||
silk12 81
|
||||
silk16 82
|
||||
silk24 83
|
||||
melpe 124
|
||||
Reference in New Issue
Block a user