- cleanup old non-used code + migration to std::chrono

This commit is contained in:
2026-04-20 22:09:44 +03:00
parent 6caabf285c
commit cfdf1a0c77
5 changed files with 82 additions and 55 deletions
+5 -5
View File
@@ -72,20 +72,20 @@ static uint64_t TimestampStartPoint = duration_cast<milliseconds>(steady_clock::
static time_t TimestampBase = time(nullptr);
// Returns number of milliseconds starting from 01 Jan 1970 GMT
uint64_t chronox::getTimestamp()
std::chrono::milliseconds chronox::getTimestamp()
{
time_point<steady_clock> t = steady_clock::now();
uint64_t ms = duration_cast< milliseconds >(t.time_since_epoch()).count();
return ms - TimestampStartPoint + TimestampBase * 1000;
return std::chrono::milliseconds(ms - TimestampStartPoint + TimestampBase * 1000);
}
uint64_t chronox::getUptime()
std::chrono::milliseconds chronox::getUptime()
{
time_point<steady_clock> t = steady_clock::now();
uint64_t ms = duration_cast< milliseconds >(t.time_since_epoch()).count();
return ms - TimestampStartPoint;
return std::chrono::milliseconds(ms - TimestampStartPoint);
}
uint32_t chronox::getDelta(uint32_t later, uint32_t earlier)
@@ -132,7 +132,7 @@ chronox::ExecutionTime::ExecutionTime()
mStart = chronox::getTimestamp();
}
uint64_t chronox::ExecutionTime::getSpentTime() const
std::chrono::milliseconds chronox::ExecutionTime::getSpentTime() const
{
return chronox::getTimestamp() - mStart;
}
+4 -4
View File
@@ -54,10 +54,10 @@ class chronox
{
public:
// Returns current timestamp in milliseconds
static uint64_t getTimestamp();
static std::chrono::milliseconds getTimestamp();
// Returns uptime (of calling process) in milliseconds
static uint64_t getUptime();
static std::chrono::milliseconds getUptime();
// Finds time delta between 'later' and 'earlier' time points.
// Handles cases when clock is wrapped.
@@ -75,9 +75,9 @@ public:
{
public:
ExecutionTime();
uint64_t getSpentTime() const;
std::chrono::milliseconds getSpentTime() const;
protected:
uint64_t mStart;
std::chrono::milliseconds mStart;
};
};
+52 -32
View File
@@ -416,8 +416,10 @@ size_t decode_packet(Codec& codec, RTPPacket& p, void* output_buffer, size_t out
return result;
}
bool AudioReceiver::add(const std::shared_ptr<jrtplib::RTPPacket>& p, Codec** detectedCodec)
Codec* AudioReceiver::add(const std::shared_ptr<jrtplib::RTPPacket>& p)
{
Codec* codec = nullptr;
// Estimate time length
int time_length = 0,
samplerate = 8000,
@@ -432,14 +434,13 @@ bool AudioReceiver::add(const std::shared_ptr<jrtplib::RTPPacket>& p, Codec** de
// Check if we deal with telephone-event
if (p->GetPayloadType() == mCodecSettings.mTelephoneEvent)
{
*detectedCodec = nullptr;
codec = nullptr;
mDtmfBuffer.add(p, 10ms, 8000);
}
else
{
// Look for codec
// Check if codec can be handled
Codec* codec = nullptr;
auto codecIter = mCodecMap.find(ptype);
if (codecIter != mCodecMap.end())
{
@@ -451,9 +452,6 @@ bool AudioReceiver::add(const std::shared_ptr<jrtplib::RTPPacket>& p, Codec** de
codec = codecIter->second.get();
// Return pointer to codec if needed.get()
if (detectedCodec)
*detectedCodec = codec;
if (mStat.mCodecName.empty() && codec)
mStat.mCodecName = codec->name();
@@ -475,26 +473,25 @@ bool AudioReceiver::add(const std::shared_ptr<jrtplib::RTPPacket>& p, Codec** de
mStat.mJitter = static_cast<float>(mJitterStats.get());
if (!codec)
return false; // There is no sense to add this packet into jitter buffer - we can't decode this
return nullptr;
// Check if packet is CNG
if (payloadLength >= 1 && payloadLength <= 6 && (ptype == 0 || ptype == 8))
time_length = mLastPacketTimeLength ? mLastPacketTimeLength : 20;
else
// Check if packet is too short from time length side
// Check if packet is too short from time length side - smth strange with found codec...
if (time_length < 2)
{
// It will cause statistics to report about bad RTP packet
// I have to replay last packet payload here to avoid report about lost packet
mBuffer.add(p, std::chrono::milliseconds(time_length), samplerate);
return false;
return nullptr;
}
// Queue packet to buffer
auto packet = mBuffer.add(p, std::chrono::milliseconds(time_length), samplerate).get();
return packet;
mBuffer.add(p, std::chrono::milliseconds(time_length), samplerate).get();
}
return {};
return codec;
}
void AudioReceiver::processDecoded(Audio::DataWindow& output, DecodeOptions options)
@@ -930,15 +927,15 @@ int AudioReceiver::getSize() const
return result;
}
int AudioReceiver::timelengthFor(jrtplib::RTPPacket& p)
AudioReceiver::MediaInfo AudioReceiver::infoFor(jrtplib::RTPPacket& p)
{
CodecMap::iterator codecIter = mCodecMap.find(p.GetPayloadType());
if (codecIter == mCodecMap.end())
return 0;
return {};
PCodec codec = codecIter->second;
if (codec)
{
if (!codec)
return {};
int frame_count = 0;
if (codec->rtpLength() != 0)
{
@@ -949,24 +946,47 @@ int AudioReceiver::timelengthFor(jrtplib::RTPPacket& p)
else
frame_count = 1;
return frame_count * codec->frameTime();
}
else
return 0;
return {std::chrono::milliseconds(frame_count * codec->frameTime()), codec->samplerate()};
}
int AudioReceiver::samplerateFor(jrtplib::RTPPacket& p)
{
CodecMap::iterator codecIter = mCodecMap.find(p.GetPayloadType());
if (codecIter != mCodecMap.end())
{
PCodec codec = codecIter->second;
if (codec)
return codec->samplerate();
}
// int AudioReceiver::timelengthFor(jrtplib::RTPPacket& p)
// {
// CodecMap::iterator codecIter = mCodecMap.find(p.GetPayloadType());
// if (codecIter == mCodecMap.end())
// return 0;
return 8000;
}
// PCodec codec = codecIter->second;
// if (codec)
// {
// int frame_count = 0;
// if (codec->rtpLength() != 0)
// {
// frame_count = static_cast<int>(p.GetPayloadLength() / codec->rtpLength());
// if (p.GetPayloadType() == 9/*G729A silence*/ && p.GetPayloadLength() % codec->rtpLength())
// frame_count++;
// }
// else
// frame_count = 1;
// return frame_count * codec->frameTime();
// }
// else
// return 0;
// }
// int AudioReceiver::samplerateFor(jrtplib::RTPPacket& p)
// {
// CodecMap::iterator codecIter = mCodecMap.find(p.GetPayloadType());
// if (codecIter != mCodecMap.end())
// {
// PCodec codec = codecIter->second;
// if (codec)
// return codec->samplerate();
// }
// return 8000;
// }
// ----------------------- DtmfReceiver -------------------
DtmfReceiver::DtmfReceiver(Statistics& stat)
+12 -5
View File
@@ -165,7 +165,7 @@ public:
// 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);
Codec* add(const std::shared_ptr<jrtplib::RTPPacket>& p);
struct DecodeOptions
{
@@ -198,11 +198,18 @@ public:
// Returns size of AudioReceiver's instance in bytes (including size of all data + codecs + etc.)
int getSize() const;
// Returns timelength for given packet
int timelengthFor(jrtplib::RTPPacket& p);
struct MediaInfo
{
std::chrono::milliseconds mTimeLength = 0ms;
int mSamplerate = 0;
};
MediaInfo infoFor(jrtplib::RTPPacket& p);
// Return samplerate for given packet
int samplerateFor(jrtplib::RTPPacket& p);
// // Returns timelength for given packet
// int timelengthFor(jrtplib::RTPPacket& p);
// // Return samplerate for given packet
// int samplerateFor(jrtplib::RTPPacket& p);
protected:
RtpBuffer mBuffer; // Jitter buffer itself
+1 -1
View File
@@ -85,7 +85,7 @@ public:
mPacketInterval; // Average interval between packet adding to jitter buffer
std::map<int,int> mLoss; // Every item is number of loss of corresping length
size_t mAudioTime = 0; // Decoded/found time in milliseconds
std::chrono::milliseconds mAudioTime = 0ms; // Decoded/found time in milliseconds
size_t mDecodedSize = 0; // Number of decoded bytes
uint16_t mSsrc = 0; // Last known SSRC ID in a RTP stream
ice::NetworkAddress mRemotePeer; // Last known remote RTP address