- always link AMR & Opus codecs; it reduces number of problems during builds.

This commit is contained in:
Dmytro Bogovych 2019-03-14 13:37:12 +02:00
parent e8963264e9
commit c27d7d2b6c
8 changed files with 488 additions and 497 deletions

View File

@ -4,7 +4,6 @@
#include "../helper/HL_IuUP.h"
#define LOG_SUBSYSTEM "AmrCodec"
#ifdef USE_AMR_CODEC
using namespace MT;
@ -16,37 +15,37 @@ static const uint8_t amr_block_size[16]={ 13, 14, 16, 18, 20, 21, 27, 32,
* Constant of AMR-NB frame lengths in bytes.
*/
const uint8_t amrnb_framelen[16] =
{12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0};
{12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0};
/**
* Constant of AMR-NB frame lengths in bits.
*/
const uint16_t amrnb_framelenbits[9] =
{95, 103, 118, 134, 148, 159, 204, 244, 39};
{95, 103, 118, 134, 148, 159, 204, 244, 39};
/**
* Constant of AMR-NB bitrates.
*/
const uint16_t amrnb_bitrates[8] =
{4750, 5150, 5900, 6700, 7400, 7950, 10200, 12200};
{4750, 5150, 5900, 6700, 7400, 7950, 10200, 12200};
/**
* Constant of AMR-WB frame lengths in bytes.
*/
const uint8_t amrwb_framelen[16] =
{17, 23, 32, 37, 40, 46, 50, 58, 60, 5, 0, 0, 0, 0, 0, 0};
{17, 23, 32, 37, 40, 46, 50, 58, 60, 5, 0, 0, 0, 0, 0, 0};
/**
* Constant of AMR-WB frame lengths in bits.
*/
const uint16_t amrwb_framelenbits[10] =
{132, 177, 253, 285, 317, 365, 397, 461, 477, 40};
{132, 177, 253, 285, 317, 365, 397, 461, 477, 40};
/**
* Constant of AMR-WB bitrates.
*/
const uint16_t amrwb_bitrates[9] =
{6600, 8850, 12650, 14250, 15850, 18250, 19850, 23050, 23850};
{6600, 8850, 12650, 14250, 15850, 18250, 19850, 23050, 23850};
// Helper routines
@ -159,7 +158,9 @@ static AmrPayload parseAmrPayload(AmrPayloadInfo& input)
AmrFrame frame;
frame.mFrameType = FT;
assert (frame.mFrameType < 10);
if (frame.mFrameType < 10)
throw std::runtime_error("Failed to parse AMR frame type");
frame.mMode = FT < SID_FT ? FT : -1;
frame.mGoodQuality = Q == 1;
frame.mTimestamp = input.mCurrentTimestamp;
@ -217,6 +218,8 @@ static AmrPayload parseAmrPayload(AmrPayloadInfo& input)
if (br.count() / 8 != br.position() / 8 &&
br.count() / 8 != br.position() / 8 + 1)
throw std::runtime_error("Failed to parse AMR frame");
return result;
}
/*static void predecodeAmrFrame(AmrFrame& frame, ByteBuffer& data)
@ -401,8 +404,16 @@ int AmrNbCodec::decode(const void* input, int inputBytes, void* output, int outp
info.mWideband = false;
info.mInterleaving = false;
AmrPayload ap = parseAmrPayload(info);
AmrPayload ap;
try
{
ap = parseAmrPayload(info);
}
catch(...)
{
ICELogDebug(<< "Failed to decode AMR payload.");
return 0;
}
// Save current timestamp
mCurrentDecoderTimestamp = info.mCurrentTimestamp;
@ -624,8 +635,16 @@ int AmrWbCodec::decode(const void* input, int inputBytes, void* output, int outp
info.mWideband = true;
info.mInterleaving = false;
AmrPayload ap = parseAmrPayload(info);
AmrPayload ap;
try
{
ap = parseAmrPayload(info);
}
catch(...)
{
ICELogDebug(<< "Failed to decode AMR payload");
return 0;
}
// Save current timestamp
mCurrentDecoderTimestamp = info.mCurrentTimestamp;
@ -654,7 +673,7 @@ int AmrWbCodec::decode(const void* input, int inputBytes, void* output, int outp
int AmrWbCodec::plc(int lostFrames, void* output, int outputCapacity)
{
/* if (outputCapacity < lostFrames * pcmLength())
/* if (outputCapacity < lostFrames * pcmLength())
return 0;
short* dataOut = (short*)output;
@ -850,7 +869,7 @@ const uint16_t gsm690_12_2_bitorder[244] = {
int GsmEfrCodec::decode(const void* input, int inputBytes, void* output, int outputCapacity)
{
/* if (mIuUP)
/* if (mIuUP)
{
// Try to parse IuUP frame
IuUP::Frame frame;
@ -953,6 +972,3 @@ int GsmEfrCodec::plc(int lostFrames, void* output, int outputCapacity)
return lostFrames * pcmLength();
}
#endif

View File

@ -6,7 +6,6 @@
#include "MT_Codec.h"
#include "../helper/HL_Pointer.h"
#if defined(USE_AMR_CODEC)
# include "opencore-amr/amrnb/interf_enc.h"
# include "opencore-amr/amrnb/interf_dec.h"
@ -156,7 +155,6 @@ namespace MT
} // End of MT namespace
#endif
#endif // MT_AMRCODEC_H

View File

@ -227,7 +227,6 @@ int G729Codec::plc(int lostFrames, void* output, int outputCapacity)
}
#ifdef USE_OPUS_CODEC
// -------------- Opus -------------------
#define OPUS_CODEC_NAME "OPUS"
#define OPUS_CODEC_RATE 16000
@ -528,8 +527,6 @@ int OpusCodec::plc(int lostFrames, void* output, int outputCapacity)
return lostFrames * pcmLength();
}
#endif
// -------------- ILBC -------------------
#define ILBC_CODEC_NAME "ILBC"

View File

@ -24,9 +24,7 @@ extern "C"
#include "libg729/g729_typedef.h"
#include "libg729/g729_ld8a.h"
#ifdef USE_OPUS_CODEC
# include "opus.h"
#endif
#include "opus.h"
namespace MT
{
@ -66,8 +64,6 @@ namespace MT
int plc(int lostFrames, void* output, int outputCapacity) override;
};
#ifdef USE_OPUS_CODEC
class OpusCodec: public Codec
{
protected:
@ -124,7 +120,6 @@ namespace MT
int decode(const void* input, int inputBytes, void* output, int outputCapacity);
int plc(int lostFrames, void* output, int outputCapacity);
};
#endif
class IlbcCodec: public Codec
{

View File

@ -12,10 +12,7 @@
#include "../helper/HL_Log.h"
#include "../audio/Audio_Interface.h"
#include "../audio/Audio_Resampler.h"
#if defined(USE_AMR_CODEC)
# include "MT_AmrCodec.h"
#endif
#include "MT_AmrCodec.h"
#include <algorithm>
@ -573,9 +570,7 @@ bool AudioReceiver::getAudio(Audio::DataWindow& output, DecodeOptions options, i
result = mFrameCount > 0;
// Check for bitrate counter
#if defined(USE_AMR_CODEC)
processStatisticsWithAmrCodec(mCodec.get());
#endif
}
else
ICELogMedia(<< "RTP packet with tail.");
@ -692,8 +687,6 @@ float AudioReceiver::calculatePvqaMos(int rate, std::string& report)
}
#endif
#if defined(USE_AMR_CODEC)
void AudioReceiver::processStatisticsWithAmrCodec(Codec* c)
{
AmrNbCodec* nb = dynamic_cast<AmrNbCodec*>(c);
@ -705,7 +698,6 @@ void AudioReceiver::processStatisticsWithAmrCodec(Codec* c)
if (wb != nullptr)
mStat.mBitrateSwitchCounter = wb->getSwitchCounter();
}
#endif
int AudioReceiver::getSize() const
{

View File

@ -182,9 +182,7 @@ namespace MT
std::shared_ptr<Audio::DataWindow> mPvqaBuffer;
#endif
#if defined(USE_AMR_CODEC)
void processStatisticsWithAmrCodec(Codec* c);
#endif
};
class DtmfReceiver: public Receiver

View File

@ -1,4 +1,4 @@
/* Copyright(C) 2007-2017 VoIPobjects (voipobjects.com)
/* Copyright(C) 2007-2019 VoIPobjects (voipobjects.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -18,7 +18,6 @@ CodecList::CodecList(const Settings& settings)
:mSettings(settings)
{
//mFactoryList.push_back(new OpusCodec::OpusFactory(16000, 1));
#ifdef USE_OPUS_CODEC
if (settings.mOpusSpec.empty())
{
mFactoryList.push_back(new OpusCodec::OpusFactory(48000, 2, MT_OPUS_CODEC_PT));
@ -30,8 +29,7 @@ CodecList::CodecList(const Settings& settings)
mFactoryList.push_back(new OpusCodec::OpusFactory(spec.mRate, spec.mChannels, spec.mPayloadType));
}
}
#endif
#ifdef USE_AMR_CODEC
for (int pt: mSettings.mAmrWbPayloadType)
mFactoryList.push_back(new AmrWbCodec::CodecFactory({mSettings.mWrapIuUP, false, pt}));
for (int pt: mSettings.mAmrWbOctetPayloadType)
@ -44,7 +42,6 @@ CodecList::CodecList(const Settings& settings)
mFactoryList.push_back(new GsmEfrCodec::GsmEfrFactory(mSettings.mWrapIuUP, mSettings.mGsmEfrPayloadType));
#endif
//mFactoryList.push_back(new IsacCodec::IsacFactory16K(mSettings.mIsac16KPayloadType));
//mFactoryList.push_back(new IlbcCodec::IlbcFactory(mSettings.mIlbc20PayloadType, mSettings.mIlbc30PayloadType));
mFactoryList.push_back(new G711Codec::AlawFactory());
@ -66,7 +63,7 @@ CodecList::~CodecList()
int CodecList::count() const
{
return (int)mFactoryList.size();
return static_cast<int>(mFactoryList.size());
}
Codec::Factory& CodecList::codecAt(int index) const

View File

@ -258,9 +258,7 @@ Statistics& Statistics::operator += (const Statistics& src)
if (src.mFirstRtpTime.is_initialized())
mFirstRtpTime = src.mFirstRtpTime;
#if defined(USE_AMR_CODEC)
mBitrateSwitchCounter += src.mBitrateSwitchCounter;
#endif
mRemotePeer = src.mRemotePeer;
mSsrc = src.mSsrc;