- refactoring
This commit is contained in:
@@ -6,6 +6,7 @@ set (CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# Produce PIC code always
|
||||
set (CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
option (USE_RESIP_INTEGRATION "Use some resiprocate specific routines" OFF)
|
||||
|
||||
set (SOURCES
|
||||
MT_Statistics.cpp
|
||||
|
||||
@@ -228,11 +228,11 @@ int G729Codec::plc(int lostFrames, void* output, int outputCapacity)
|
||||
|
||||
#if defined(USE_OPUS_CODEC)
|
||||
// -------------- Opus -------------------
|
||||
#define OPUS_CODEC_NAME "OPUS"
|
||||
#define OPUS_CODEC_RATE 16000
|
||||
#define OPUS_TARGET_BITRATE 64000
|
||||
#define OPUS_PACKET_LOSS 30
|
||||
#define OPUS_CODEC_COMPLEXITY 2
|
||||
#define OPUS_CODEC_NAME "OPUS"
|
||||
#define OPUS_CODEC_RATE 16000
|
||||
#define OPUS_TARGET_BITRATE 64000
|
||||
#define OPUS_PACKET_LOSS 10
|
||||
#define OPUS_CODEC_COMPLEXITY 2
|
||||
|
||||
OpusCodec::Params::Params()
|
||||
:mUseDtx(false), mUseInbandFec(true), mStereo(true), mPtime(20)
|
||||
@@ -321,7 +321,7 @@ void OpusCodec::Params::parse(const resip::Data ¶ms)
|
||||
mStereo = paramIter->mValue == "1";
|
||||
else
|
||||
if (paramIter->mName == "ptime")
|
||||
mPtime = StringHelper::toInt(paramIter->mValue.c_str(), 20);
|
||||
mPtime = strx::toInt(paramIter->mValue.c_str(), 20);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -233,7 +233,7 @@ RtpBuffer::FetchResult RtpBuffer::fetch(ResultList& rl)
|
||||
unsigned seqno = mPacketList.front()->rtp()->GetExtendedSequenceNumber();
|
||||
|
||||
// Gap between new packet and previous on
|
||||
int gap = seqno - mFetchedPacket->rtp()->GetSequenceNumber() - 1;
|
||||
int gap = (int64_t)seqno - (int64_t)mFetchedPacket->rtp()->GetExtendedSequenceNumber() - 1;
|
||||
gap = std::min(gap, 127);
|
||||
if (gap > 0 && mPacketList.empty())
|
||||
{
|
||||
@@ -354,6 +354,18 @@ AudioReceiver::~AudioReceiver()
|
||||
mDecodedDump.reset();
|
||||
}
|
||||
|
||||
// Update codec settings
|
||||
void AudioReceiver::setCodecSettings(const CodecList::Settings& codecSettings)
|
||||
{
|
||||
if (mCodecSettings == codecSettings)
|
||||
return;
|
||||
|
||||
mCodecSettings = codecSettings;
|
||||
mCodecMap.clear();
|
||||
mCodecList.setSettings(mCodecSettings);
|
||||
mCodecList.fillCodecMap(mCodecMap);
|
||||
}
|
||||
|
||||
size_t decode_packet(Codec& codec, RTPPacket& p, void* output_buffer, size_t output_capacity)
|
||||
{
|
||||
// How much data was produced
|
||||
|
||||
@@ -125,6 +125,9 @@ namespace MT
|
||||
AudioReceiver(const CodecList::Settings& codecSettings, Statistics& stat);
|
||||
~AudioReceiver();
|
||||
|
||||
// Update codec settings
|
||||
void setCodecSettings(const CodecList::Settings& codecSettings);
|
||||
|
||||
// Returns false when packet is rejected as illegal. codec parameter will show codec which will be used for decoding.
|
||||
// Lifetime of pointer to codec is limited by lifetime of AudioReceiver (it is container).
|
||||
bool add(const std::shared_ptr<jrtplib::RTPPacket>& p, Codec** codec = nullptr);
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
using namespace MT;
|
||||
|
||||
using strx = StringHelper;
|
||||
using strx = strx;
|
||||
|
||||
// ---------------- EvsSpec ---------------
|
||||
|
||||
@@ -125,13 +125,80 @@ CodecList::Settings::OpusSpec CodecList::Settings::OpusSpec::parse(const std::st
|
||||
return result;
|
||||
}
|
||||
|
||||
CodecList::Settings CodecList::Settings::parseSdp(const std::list<resip::Codec>& codeclist)
|
||||
{
|
||||
CodecList::Settings r{DefaultSettings};
|
||||
|
||||
for (auto& c: codeclist)
|
||||
{
|
||||
std::string codec_name = strx::uppercase(c.getName().c_str());
|
||||
int samplerate = c.getRate();
|
||||
int ptype = c.payloadType();
|
||||
|
||||
// Dynamic payload type codecs only - ISAC / iLBC / Speex / etc.
|
||||
if (codec_name == "OPUS")
|
||||
{
|
||||
// Check the parameters
|
||||
auto enc_params = c.encodingParameters(); // This must channels number for Opus codec
|
||||
auto params = c.parameters();
|
||||
int channels = strx::toInt(enc_params.c_str(), 1);
|
||||
r.mOpusSpec.push_back({ptype, samplerate, channels});
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
bool CodecList::Settings::operator == (const Settings& rhs) const
|
||||
{
|
||||
if (std::tie(mWrapIuUP, mSkipDecode, mIsac16KPayloadType, mIsac32KPayloadType, mIlbc20PayloadType, mIlbc30PayloadType, mGsmFrPayloadType, mGsmFrPayloadLength, mGsmEfrPayloadType, mGsmHrPayloadType) !=
|
||||
std::tie(rhs.mWrapIuUP, rhs.mSkipDecode, rhs.mIsac16KPayloadType, rhs.mIsac32KPayloadType, rhs.mIlbc20PayloadType, rhs.mIlbc30PayloadType, rhs.mGsmFrPayloadType, rhs.mGsmFrPayloadLength, rhs.mGsmEfrPayloadType, rhs.mGsmHrPayloadType))
|
||||
return false;
|
||||
|
||||
if (mAmrNbOctetPayloadType != rhs.mAmrNbOctetPayloadType)
|
||||
return false;
|
||||
|
||||
if (mAmrNbPayloadType != rhs.mAmrNbPayloadType)
|
||||
return false;
|
||||
|
||||
if (mAmrWbOctetPayloadType != rhs.mAmrWbOctetPayloadType)
|
||||
return false;
|
||||
|
||||
if (mAmrWbPayloadType != rhs.mAmrWbPayloadType)
|
||||
return false;
|
||||
|
||||
// ToDo: compare EVS and Opus specs
|
||||
if (mEvsSpec.size() != rhs.mEvsSpec.size())
|
||||
return false;
|
||||
|
||||
for (size_t i = 0; i < mEvsSpec.size(); i++)
|
||||
if (mEvsSpec[i] != rhs.mEvsSpec[i])
|
||||
return false;
|
||||
|
||||
if (mOpusSpec.size() != rhs.mOpusSpec.size())
|
||||
return false;
|
||||
|
||||
for (size_t i = 0; i < mOpusSpec.size(); i++)
|
||||
if (mOpusSpec[i] != rhs.mOpusSpec[i])
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------
|
||||
CodecList::Settings CodecList::Settings::DefaultSettings;
|
||||
|
||||
CodecList::CodecList(const Settings& settings)
|
||||
:mSettings(settings)
|
||||
{
|
||||
//mFactoryList.push_back(new OpusCodec::OpusFactory(16000, 1));
|
||||
init(mSettings);
|
||||
}
|
||||
|
||||
void CodecList::init(const Settings& settings)
|
||||
{
|
||||
for (auto f: mFactoryList)
|
||||
delete f;
|
||||
mFactoryList.clear();
|
||||
|
||||
#if defined(USE_OPUS_CODEC)
|
||||
if (settings.mOpusSpec.empty())
|
||||
@@ -191,8 +258,8 @@ CodecList::CodecList(const Settings& settings)
|
||||
|
||||
CodecList::~CodecList()
|
||||
{
|
||||
for (FactoryList::size_type i=0; i<mFactoryList.size(); i++)
|
||||
delete mFactoryList[i];
|
||||
for (auto f: mFactoryList)
|
||||
delete f;
|
||||
}
|
||||
|
||||
int CodecList::count() const
|
||||
@@ -217,10 +284,12 @@ int CodecList::findCodec(const std::string &name) const
|
||||
|
||||
void CodecList::fillCodecMap(CodecMap& cm)
|
||||
{
|
||||
cm.clear();
|
||||
for (auto& factory: mFactoryList)
|
||||
{
|
||||
// Create codec here. Although they are not needed right now - they can be needed to find codec's info.
|
||||
cm[factory->payloadType()] = factory->create();
|
||||
PCodec c = factory->create();
|
||||
cm.insert({factory->payloadType(), c});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,10 @@ public:
|
||||
Encoding mEncodingType = Encoding_MIME;
|
||||
bool isValid() const;
|
||||
static EvsSpec parse(const std::string& spec);
|
||||
|
||||
bool operator == (const EvsSpec& rhs) const { return std::tie(mPayloadType, mBandwidth, mEncodingType) == std::tie(rhs.mPayloadType, rhs.mBandwidth, rhs.mEncodingType);}
|
||||
bool operator != (const EvsSpec& rhs) const { return ! (operator ==) (rhs);};
|
||||
|
||||
};
|
||||
|
||||
std::vector<EvsSpec> mEvsSpec;
|
||||
@@ -79,7 +83,14 @@ public:
|
||||
int mRate = -1;
|
||||
int mChannels = -1;
|
||||
|
||||
OpusSpec(int ptype = -1, int rate = -1, int channels = -1)
|
||||
:mPayloadType(ptype), mRate(rate), mChannels(channels)
|
||||
{}
|
||||
|
||||
bool isValid() const;
|
||||
bool operator == (const OpusSpec& rhs) const { return std::tie(mPayloadType, mRate, mChannels) == std::tie(rhs.mPayloadType, rhs.mRate, rhs.mChannels);}
|
||||
bool operator != (const OpusSpec& rhs) const { return ! (operator ==) (rhs);};
|
||||
|
||||
static OpusSpec parse(const std::string& spec);
|
||||
};
|
||||
std::vector<OpusSpec> mOpusSpec;
|
||||
@@ -88,20 +99,29 @@ public:
|
||||
std::string toString() const;
|
||||
|
||||
static Settings DefaultSettings;
|
||||
|
||||
#if defined(USE_RESIP_INTEGRATION)
|
||||
static Settings parseSdp(const std::list<resip::Codec>& codeclist);
|
||||
#endif
|
||||
bool operator == (const Settings& rhs) const;
|
||||
};
|
||||
|
||||
CodecList(const Settings& settings);
|
||||
~CodecList();
|
||||
void setSettings(const Settings& settings) { init(settings); }
|
||||
|
||||
int count() const;
|
||||
Codec::Factory& codecAt(int index) const;
|
||||
int findCodec(const std::string& name) const;
|
||||
void fillCodecMap(CodecMap& cm);
|
||||
|
||||
|
||||
protected:
|
||||
typedef std::vector<Codec::Factory*> FactoryList;
|
||||
FactoryList mFactoryList;
|
||||
Settings mSettings;
|
||||
|
||||
void init(const Settings& settings);
|
||||
};
|
||||
|
||||
class CodecListPriority
|
||||
|
||||
Reference in New Issue
Block a user