- better checks for RTP packet + enable EVS codec + improve thread pool

This commit is contained in:
Dmytro Bogovych 2025-02-03 11:51:11 +03:00
parent 5ce85e3a09
commit 7510ff5697
6 changed files with 54 additions and 42 deletions

View File

@ -52,8 +52,12 @@ bool RtpHelper::isRtp(const void* buffer, size_t length)
if (length < 12) if (length < 12)
return false; return false;
unsigned char _type = reinterpret_cast<const RtpHeader*>(buffer)->pt; const RtpHeader* h = reinterpret_cast<const RtpHeader*>(buffer);
bool rtp = ( (_type & 0x7F) >= 96 && (_type & 0x7F) <= 127) || ((_type & 0x7F) < 35); if (h->version != 0b10)
return false;
unsigned char pt = h->pt;
bool rtp = ( (pt & 0x7F) >= 96 && (pt & 0x7F) <= 127) || ((pt & 0x7F) < 35);
return rtp; return rtp;
} }
@ -62,9 +66,8 @@ bool RtpHelper::isRtpOrRtcp(const void* buffer, size_t length)
{ {
if (length < 12) if (length < 12)
return false; return false;
unsigned char b = ((const unsigned char*)buffer)[0]; const RtcpHeader* h = reinterpret_cast<const RtcpHeader*>(buffer);
return h->version == 0b10;
return (b & 0xC0 ) == 128;
} }
bool RtpHelper::isRtcp(const void* buffer, size_t length) bool RtpHelper::isRtcp(const void* buffer, size_t length)

View File

@ -32,6 +32,11 @@ size_t thread_pool::size()
return this->tasks.size(); return this->tasks.size();
} }
size_t thread_pool::threads()
{
return this->workers.size();
}
// the destructor joins all threads // the destructor joins all threads
thread_pool::~thread_pool() thread_pool::~thread_pool()
{ {

View File

@ -24,6 +24,8 @@ public:
void enqueue(const task& task); void enqueue(const task& task);
void wait(std::chrono::milliseconds interval = std::chrono::milliseconds(50)); void wait(std::chrono::milliseconds interval = std::chrono::milliseconds(50));
size_t size(); size_t size();
size_t threads();
private: private:
// need to keep track of threads so we can join them // need to keep track of threads so we can join them
std::vector< std::thread > workers; std::vector< std::thread > workers;

View File

@ -1,4 +1,4 @@
/* Copyright(C) 2007-2023 VoIPobjects (voipobjects.com) /* Copyright(C) 2007-2025 VoIPobjects (voipobjects.com)
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -172,14 +172,14 @@ CodecList::Settings::EvsSpec CodecList::Settings::EvsSpec::parse(const std::stri
if (bandwidth == "nb" || bandwidth == "NB") if (bandwidth == "nb" || bandwidth == "NB")
result.mBandwidth = Bandwidth_NB; result.mBandwidth = Bandwidth_NB;
else else
if (bandwidth == "wb" || bandwidth == "WB") if (bandwidth == "wb" || bandwidth == "WB")
result.mBandwidth = Bandwidth_WB; result.mBandwidth = Bandwidth_WB;
else else
if (bandwidth == "swb" || bandwidth == "SWB") if (bandwidth == "swb" || bandwidth == "SWB")
result.mBandwidth = Bandwidth_SWB; result.mBandwidth = Bandwidth_SWB;
else else
if (bandwidth == "fb" || bandwidth == "FB") if (bandwidth == "fb" || bandwidth == "FB")
result.mBandwidth = Bandwidth_FB; result.mBandwidth = Bandwidth_FB;
} }
return result; return result;
@ -243,33 +243,36 @@ CodecList::Settings CodecList::Settings::parseSdp(const std::list<resip::Codec>&
r.mOpusSpec.push_back({ptype, samplerate, channels}); r.mOpusSpec.push_back({ptype, samplerate, channels});
} }
else else
if (codec_name == "AMR-WB") if (codec_name == "AMR-WB")
{
int octet_mode = findOctetMode(params.c_str());
if (octet_mode != -1)
{ {
int octet_mode = findOctetMode(params.c_str()); if (octet_mode == 0)
if (octet_mode != -1) r.mAmrWbPayloadType.insert(ptype);
{ else
if (octet_mode == 0) if (octet_mode == 1)
r.mAmrWbPayloadType.insert(ptype); r.mAmrWbOctetPayloadType.insert(ptype);
else
if (octet_mode == 1)
r.mAmrWbOctetPayloadType.insert(ptype);
}
// std::cout << "AMR-WB parameters: " << params.c_str() << ", found octet-mode: " << octet_mode << std::endl;
} }
else }
if (codec_name == "AMR") else
{ if (codec_name == "AMR")
int octet_mode = findOctetMode(params.c_str()); {
if (octet_mode != -1) int octet_mode = findOctetMode(params.c_str());
{ if (octet_mode != -1)
if (octet_mode == 0) {
r.mAmrWbPayloadType.insert(ptype); if (octet_mode == 0)
else r.mAmrWbPayloadType.insert(ptype);
if (octet_mode == 1) else
r.mAmrWbOctetPayloadType.insert(ptype); if (octet_mode == 1)
} r.mAmrWbOctetPayloadType.insert(ptype);
// std::cout << "AMR parameters: " << params.c_str() << ", found octet-mode: " << octet_mode << std::endl; }
} }
else
if (codec_name == "EVS")
{
r.mEvsSpec.push_back({ptype});
}
} }
return r; return r;
} }

View File

@ -59,7 +59,7 @@ public:
Bandwidth_FB Bandwidth_FB
}; };
Bandwidth mBandwidth = Bandwidth_NB; Bandwidth mBandwidth = Bandwidth_FB;
enum Encoding enum Encoding
{ {

View File

@ -146,8 +146,7 @@ PCodec EVSCodec::EVSFactory::create()
} }
EVSCodec::EVSCodec(): EVSCodec(StreamParameters()) EVSCodec::EVSCodec(): EVSCodec(StreamParameters())
{ {}
}
EVSCodec::EVSCodec(const StreamParameters &sp) EVSCodec::EVSCodec(const StreamParameters &sp)
{ {