- cleanup old non-used code + migration to std::chrono
This commit is contained in:
@@ -72,20 +72,20 @@ static uint64_t TimestampStartPoint = duration_cast<milliseconds>(steady_clock::
|
|||||||
static time_t TimestampBase = time(nullptr);
|
static time_t TimestampBase = time(nullptr);
|
||||||
|
|
||||||
// Returns number of milliseconds starting from 01 Jan 1970 GMT
|
// 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();
|
time_point<steady_clock> t = steady_clock::now();
|
||||||
uint64_t ms = duration_cast< milliseconds >(t.time_since_epoch()).count();
|
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();
|
time_point<steady_clock> t = steady_clock::now();
|
||||||
|
|
||||||
uint64_t ms = duration_cast< milliseconds >(t.time_since_epoch()).count();
|
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)
|
uint32_t chronox::getDelta(uint32_t later, uint32_t earlier)
|
||||||
@@ -132,7 +132,7 @@ chronox::ExecutionTime::ExecutionTime()
|
|||||||
mStart = chronox::getTimestamp();
|
mStart = chronox::getTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t chronox::ExecutionTime::getSpentTime() const
|
std::chrono::milliseconds chronox::ExecutionTime::getSpentTime() const
|
||||||
{
|
{
|
||||||
return chronox::getTimestamp() - mStart;
|
return chronox::getTimestamp() - mStart;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,10 +54,10 @@ class chronox
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Returns current timestamp in milliseconds
|
// Returns current timestamp in milliseconds
|
||||||
static uint64_t getTimestamp();
|
static std::chrono::milliseconds getTimestamp();
|
||||||
|
|
||||||
// Returns uptime (of calling process) in milliseconds
|
// 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.
|
// Finds time delta between 'later' and 'earlier' time points.
|
||||||
// Handles cases when clock is wrapped.
|
// Handles cases when clock is wrapped.
|
||||||
@@ -75,9 +75,9 @@ public:
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ExecutionTime();
|
ExecutionTime();
|
||||||
uint64_t getSpentTime() const;
|
std::chrono::milliseconds getSpentTime() const;
|
||||||
protected:
|
protected:
|
||||||
uint64_t mStart;
|
std::chrono::milliseconds mStart;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -416,8 +416,10 @@ size_t decode_packet(Codec& codec, RTPPacket& p, void* output_buffer, size_t out
|
|||||||
return result;
|
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
|
// Estimate time length
|
||||||
int time_length = 0,
|
int time_length = 0,
|
||||||
samplerate = 8000,
|
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
|
// Check if we deal with telephone-event
|
||||||
if (p->GetPayloadType() == mCodecSettings.mTelephoneEvent)
|
if (p->GetPayloadType() == mCodecSettings.mTelephoneEvent)
|
||||||
{
|
{
|
||||||
*detectedCodec = nullptr;
|
codec = nullptr;
|
||||||
mDtmfBuffer.add(p, 10ms, 8000);
|
mDtmfBuffer.add(p, 10ms, 8000);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Look for codec
|
// Look for codec
|
||||||
// Check if codec can be handled
|
// Check if codec can be handled
|
||||||
Codec* codec = nullptr;
|
|
||||||
auto codecIter = mCodecMap.find(ptype);
|
auto codecIter = mCodecMap.find(ptype);
|
||||||
if (codecIter != mCodecMap.end())
|
if (codecIter != mCodecMap.end())
|
||||||
{
|
{
|
||||||
@@ -451,9 +452,6 @@ bool AudioReceiver::add(const std::shared_ptr<jrtplib::RTPPacket>& p, Codec** de
|
|||||||
codec = codecIter->second.get();
|
codec = codecIter->second.get();
|
||||||
|
|
||||||
// Return pointer to codec if needed.get()
|
// Return pointer to codec if needed.get()
|
||||||
if (detectedCodec)
|
|
||||||
*detectedCodec = codec;
|
|
||||||
|
|
||||||
if (mStat.mCodecName.empty() && codec)
|
if (mStat.mCodecName.empty() && codec)
|
||||||
mStat.mCodecName = codec->name();
|
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());
|
mStat.mJitter = static_cast<float>(mJitterStats.get());
|
||||||
|
|
||||||
if (!codec)
|
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
|
// Check if packet is CNG
|
||||||
if (payloadLength >= 1 && payloadLength <= 6 && (ptype == 0 || ptype == 8))
|
if (payloadLength >= 1 && payloadLength <= 6 && (ptype == 0 || ptype == 8))
|
||||||
time_length = mLastPacketTimeLength ? mLastPacketTimeLength : 20;
|
time_length = mLastPacketTimeLength ? mLastPacketTimeLength : 20;
|
||||||
else
|
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)
|
if (time_length < 2)
|
||||||
{
|
{
|
||||||
// It will cause statistics to report about bad RTP packet
|
// It will cause statistics to report about bad RTP packet
|
||||||
// I have to replay last packet payload here to avoid report about lost packet
|
// I have to replay last packet payload here to avoid report about lost packet
|
||||||
mBuffer.add(p, std::chrono::milliseconds(time_length), samplerate);
|
mBuffer.add(p, std::chrono::milliseconds(time_length), samplerate);
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Queue packet to buffer
|
// Queue packet to buffer
|
||||||
auto packet = mBuffer.add(p, std::chrono::milliseconds(time_length), samplerate).get();
|
mBuffer.add(p, std::chrono::milliseconds(time_length), samplerate).get();
|
||||||
return packet;
|
|
||||||
}
|
}
|
||||||
return {};
|
return codec;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioReceiver::processDecoded(Audio::DataWindow& output, DecodeOptions options)
|
void AudioReceiver::processDecoded(Audio::DataWindow& output, DecodeOptions options)
|
||||||
@@ -930,43 +927,66 @@ int AudioReceiver::getSize() const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AudioReceiver::timelengthFor(jrtplib::RTPPacket& p)
|
AudioReceiver::MediaInfo AudioReceiver::infoFor(jrtplib::RTPPacket& p)
|
||||||
{
|
{
|
||||||
CodecMap::iterator codecIter = mCodecMap.find(p.GetPayloadType());
|
CodecMap::iterator codecIter = mCodecMap.find(p.GetPayloadType());
|
||||||
if (codecIter == mCodecMap.end())
|
if (codecIter == mCodecMap.end())
|
||||||
return 0;
|
return {};
|
||||||
|
|
||||||
PCodec codec = codecIter->second;
|
PCodec codec = codecIter->second;
|
||||||
if (codec)
|
if (!codec)
|
||||||
{
|
return {};
|
||||||
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();
|
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
|
else
|
||||||
return 0;
|
frame_count = 1;
|
||||||
|
|
||||||
|
|
||||||
|
return {std::chrono::milliseconds(frame_count * codec->frameTime()), codec->samplerate()};
|
||||||
}
|
}
|
||||||
|
|
||||||
int AudioReceiver::samplerateFor(jrtplib::RTPPacket& p)
|
// int AudioReceiver::timelengthFor(jrtplib::RTPPacket& p)
|
||||||
{
|
// {
|
||||||
CodecMap::iterator codecIter = mCodecMap.find(p.GetPayloadType());
|
// CodecMap::iterator codecIter = mCodecMap.find(p.GetPayloadType());
|
||||||
if (codecIter != mCodecMap.end())
|
// if (codecIter == mCodecMap.end())
|
||||||
{
|
// return 0;
|
||||||
PCodec codec = codecIter->second;
|
|
||||||
if (codec)
|
|
||||||
return codec->samplerate();
|
|
||||||
}
|
|
||||||
|
|
||||||
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::DtmfReceiver(Statistics& stat)
|
DtmfReceiver::DtmfReceiver(Statistics& stat)
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ public:
|
|||||||
|
|
||||||
// Returns false when packet is rejected as illegal. codec parameter will show codec which will be used for decoding.
|
// 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).
|
// 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
|
struct DecodeOptions
|
||||||
{
|
{
|
||||||
@@ -198,11 +198,18 @@ public:
|
|||||||
// Returns size of AudioReceiver's instance in bytes (including size of all data + codecs + etc.)
|
// Returns size of AudioReceiver's instance in bytes (including size of all data + codecs + etc.)
|
||||||
int getSize() const;
|
int getSize() const;
|
||||||
|
|
||||||
// Returns timelength for given packet
|
struct MediaInfo
|
||||||
int timelengthFor(jrtplib::RTPPacket& p);
|
{
|
||||||
|
std::chrono::milliseconds mTimeLength = 0ms;
|
||||||
|
int mSamplerate = 0;
|
||||||
|
};
|
||||||
|
MediaInfo infoFor(jrtplib::RTPPacket& p);
|
||||||
|
|
||||||
// Return samplerate for given packet
|
// // Returns timelength for given packet
|
||||||
int samplerateFor(jrtplib::RTPPacket& p);
|
// int timelengthFor(jrtplib::RTPPacket& p);
|
||||||
|
|
||||||
|
// // Return samplerate for given packet
|
||||||
|
// int samplerateFor(jrtplib::RTPPacket& p);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
RtpBuffer mBuffer; // Jitter buffer itself
|
RtpBuffer mBuffer; // Jitter buffer itself
|
||||||
|
|||||||
@@ -84,8 +84,8 @@ public:
|
|||||||
mDecodeRequested, // Average amount of requested audio frames to play
|
mDecodeRequested, // Average amount of requested audio frames to play
|
||||||
mPacketInterval; // Average interval between packet adding to jitter buffer
|
mPacketInterval; // Average interval between packet adding to jitter buffer
|
||||||
|
|
||||||
std::map<int,int> mLoss; // Every item is number of loss of corresping length
|
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
|
size_t mDecodedSize = 0; // Number of decoded bytes
|
||||||
uint16_t mSsrc = 0; // Last known SSRC ID in a RTP stream
|
uint16_t mSsrc = 0; // Last known SSRC ID in a RTP stream
|
||||||
ice::NetworkAddress mRemotePeer; // Last known remote RTP address
|
ice::NetworkAddress mRemotePeer; // Last known remote RTP address
|
||||||
|
|||||||
Reference in New Issue
Block a user