- fixes for pvqa_pcap project - lazy creation of codecs + compare timespec structures
This commit is contained in:
parent
b5d0242c74
commit
c45c686582
|
|
@ -15,3 +15,39 @@ double now_ms(void)
|
||||||
return 1000.0 * res.tv_sec + (double) res.tv_nsec / 1e6;
|
return 1000.0 * res.tv_sec + (double) res.tv_nsec / 1e6;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int compare_timespec(const timespec& lhs, const timespec& rhs)
|
||||||
|
{
|
||||||
|
if (lhs.tv_sec < rhs.tv_sec)
|
||||||
|
return -1;
|
||||||
|
if (lhs.tv_sec > rhs.tv_sec)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (lhs.tv_nsec < rhs.tv_nsec)
|
||||||
|
return -1;
|
||||||
|
if (lhs.tv_nsec > rhs.tv_nsec)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator < (const timespec& lhs, const timespec& rhs)
|
||||||
|
{
|
||||||
|
return compare_timespec(lhs, rhs) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator == (const timespec& lhs, const timespec& rhs)
|
||||||
|
{
|
||||||
|
return compare_timespec(lhs, rhs) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator > (const timespec& lhs, const timespec& rhs)
|
||||||
|
{
|
||||||
|
return compare_timespec(lhs, rhs) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_zero(const timespec& ts)
|
||||||
|
{
|
||||||
|
return !ts.tv_sec && !ts.tv_nsec;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,17 @@
|
||||||
#ifndef __HELPER_TIME_H
|
#ifndef __HELPER_TIME_H
|
||||||
#define __HELPER_TIME_H
|
#define __HELPER_TIME_H
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
// Return current monotonic number of milliseconds starting from some point
|
||||||
extern double now_ms();
|
extern double now_ms();
|
||||||
|
|
||||||
|
// Compare the timespec.
|
||||||
|
// Returns -1 if lhs < rhs, 1 if lhs > rhs, 0 if equal
|
||||||
|
extern int compare_timespec(const timespec& lhs, const timespec& rhs);
|
||||||
|
extern bool operator < (const timespec& lhs, const timespec& rhs);
|
||||||
|
extern bool operator == (const timespec& lhs, const timespec& rhs);
|
||||||
|
extern bool operator > (const timespec& lhs, const timespec& rhs);
|
||||||
|
extern bool is_zero(const timespec& ts);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -420,13 +420,10 @@ bool AudioReceiver::add(const std::shared_ptr<jrtplib::RTPPacket>& p, Codec** co
|
||||||
return false; // Reject packet with unknown payload type
|
return false; // Reject packet with unknown payload type
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if codec is created actually
|
// Check if codec is creating lazily
|
||||||
if (!codecIter->second)
|
if (!codecIter->second)
|
||||||
{
|
{
|
||||||
// Look for ptype
|
codecIter->second = mCodecList.createCodecByPayloadType(ptype);
|
||||||
for (int codecIndex = 0; codecIndex < mCodecList.count(); codecIndex++)
|
|
||||||
if (mCodecList.codecAt(codecIndex).payloadType() == p->GetPayloadType())
|
|
||||||
codecIter->second = mCodecList.codecAt(codecIndex).create();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return pointer to codec if needed.get()
|
// Return pointer to codec if needed.get()
|
||||||
|
|
|
||||||
|
|
@ -407,11 +407,21 @@ void CodecList::fillCodecMap(CodecMap& cm)
|
||||||
for (auto& factory: mFactoryList)
|
for (auto& factory: mFactoryList)
|
||||||
{
|
{
|
||||||
// Create codec here. Although they are not needed right now - they can be needed to find codec's info.
|
// Create codec here. Although they are not needed right now - they can be needed to find codec's info.
|
||||||
PCodec c = factory->create();
|
// PCodec c = factory->create();
|
||||||
cm.insert({factory->payloadType(), c});
|
cm.insert({factory->payloadType(), PCodec()});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PCodec CodecList::createCodecByPayloadType(int payloadType)
|
||||||
|
{
|
||||||
|
for (auto& factory: mFactoryList)
|
||||||
|
{
|
||||||
|
if (factory->payloadType() == payloadType)
|
||||||
|
return factory->create();
|
||||||
|
}
|
||||||
|
return PCodec();
|
||||||
|
}
|
||||||
|
|
||||||
CodecListPriority::CodecListPriority()
|
CodecListPriority::CodecListPriority()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,7 @@ public:
|
||||||
Codec::Factory& codecAt(int index) const;
|
Codec::Factory& codecAt(int index) const;
|
||||||
int findCodec(const std::string& name) const;
|
int findCodec(const std::string& name) const;
|
||||||
void fillCodecMap(CodecMap& cm);
|
void fillCodecMap(CodecMap& cm);
|
||||||
|
PCodec createCodecByPayloadType(int payloadType);
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue