mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 20:01:56 +00:00
RTC: Only cache the UDP packet message
This commit is contained in:
parent
e79293a3bc
commit
30809aee60
6 changed files with 34 additions and 11 deletions
|
@ -393,7 +393,7 @@ srs_error_t SrsHybridServer::notify(int event, srs_utime_t interval, srs_utime_t
|
||||||
|
|
||||||
string cache_desc;
|
string cache_desc;
|
||||||
if (true) {
|
if (true) {
|
||||||
snprintf(buf, sizeof(buf), ", cache=%d,%d,%d,%d", _srs_rtp_cache->size(), _srs_rtp_raw_cache->size(), _srs_rtp_fua_cache->size(), _srs_rtp_msg_cache->size());
|
snprintf(buf, sizeof(buf), ", cache=%d,%d,%d,%d,%d", _srs_rtp_cache->size(), _srs_rtp_raw_cache->size(), _srs_rtp_fua_cache->size(), _srs_rtp_msg_cache->size(), _srs_rtp_msg_cache2->size());
|
||||||
cache_desc = buf;
|
cache_desc = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -286,6 +286,7 @@ srs_error_t SrsRtcServer::initialize()
|
||||||
|
|
||||||
bool rtp_msg_cache = _srs_config->get_rtc_server_rtp_msg_cache();
|
bool rtp_msg_cache = _srs_config->get_rtc_server_rtp_msg_cache();
|
||||||
_srs_rtp_msg_cache->set_enabled(rtp_msg_cache);
|
_srs_rtp_msg_cache->set_enabled(rtp_msg_cache);
|
||||||
|
_srs_rtp_msg_cache2->set_enabled(rtp_msg_cache);
|
||||||
|
|
||||||
srs_trace("RTC server init ok, rc=%d, rmc=%d", rtp_cache, rtp_msg_cache);
|
srs_trace("RTC server init ok, rc=%d, rmc=%d", rtp_cache, rtp_msg_cache);
|
||||||
|
|
||||||
|
|
|
@ -361,8 +361,12 @@ SrsSharedPtrMessage* SrsSharedPtrMessage::copy()
|
||||||
{
|
{
|
||||||
srs_assert(ptr);
|
srs_assert(ptr);
|
||||||
|
|
||||||
SrsSharedPtrMessage* copy = _srs_rtp_msg_cache->allocate();
|
SrsSharedPtrMessage* copy = _srs_rtp_msg_cache2->allocate();
|
||||||
|
|
||||||
|
// We got an object from cache, the ptr might exists, so unwrap it.
|
||||||
|
copy->unwrap();
|
||||||
|
|
||||||
|
// Reference to this message instead.
|
||||||
copy->ptr = ptr;
|
copy->ptr = ptr;
|
||||||
ptr->shared_count++;
|
ptr->shared_count++;
|
||||||
|
|
||||||
|
|
|
@ -290,7 +290,7 @@ public:
|
||||||
// video/audio packet use raw bytes, no video/audio packet.
|
// video/audio packet use raw bytes, no video/audio packet.
|
||||||
char* payload;
|
char* payload;
|
||||||
|
|
||||||
private:
|
public:
|
||||||
class SrsSharedPtrPayload
|
class SrsSharedPtrPayload
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -840,13 +840,24 @@ void SrsRtpPacket2::reuse()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recycle the real owner of message, clear the reference.
|
// Recycle the real owner of message, clear the reference.
|
||||||
if (shared_msg) {
|
reuse_shared_msg();
|
||||||
if (shared_msg->count() > 0) {
|
}
|
||||||
shared_msg->unwrap();
|
|
||||||
|
void SrsRtpPacket2::reuse_shared_msg()
|
||||||
|
{
|
||||||
|
if (!shared_msg) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We only recycle the RTC UDP packet messages.
|
||||||
|
if (shared_msg->payload && shared_msg->size == kRtpPacketSize && shared_msg->count() == 0) {
|
||||||
_srs_rtp_msg_cache->recycle(shared_msg);
|
_srs_rtp_msg_cache->recycle(shared_msg);
|
||||||
shared_msg = NULL;
|
} else {
|
||||||
|
shared_msg->unwrap();
|
||||||
|
_srs_rtp_msg_cache2->recycle(shared_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shared_msg = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsRtpPacket2::reset()
|
bool SrsRtpPacket2::reset()
|
||||||
|
@ -879,6 +890,7 @@ char* SrsRtpPacket2::wrap(int size)
|
||||||
// If got a cached message(which has payload), but it's too small,
|
// If got a cached message(which has payload), but it's too small,
|
||||||
// we free it and allocate a larger one.
|
// we free it and allocate a larger one.
|
||||||
if (shared_msg->payload && shared_msg->size < size) {
|
if (shared_msg->payload && shared_msg->size < size) {
|
||||||
|
++_srs_pps_objs_rothers->sugar;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -907,7 +919,10 @@ char* SrsRtpPacket2::wrap(char* data, int size)
|
||||||
|
|
||||||
char* SrsRtpPacket2::wrap(SrsSharedPtrMessage* msg)
|
char* SrsRtpPacket2::wrap(SrsSharedPtrMessage* msg)
|
||||||
{
|
{
|
||||||
srs_freep(shared_msg);
|
// Recycle the shared message.
|
||||||
|
reuse_shared_msg();
|
||||||
|
|
||||||
|
// Copy from the new message.
|
||||||
shared_msg = msg->copy();
|
shared_msg = msg->copy();
|
||||||
|
|
||||||
return msg->payload;
|
return msg->payload;
|
||||||
|
@ -1036,6 +1051,7 @@ SrsRtpObjectCacheManager<SrsRtpRawPayload>* _srs_rtp_raw_cache = new SrsRtpObjec
|
||||||
SrsRtpObjectCacheManager<SrsRtpFUAPayload2>* _srs_rtp_fua_cache = new SrsRtpObjectCacheManager<SrsRtpFUAPayload2>();
|
SrsRtpObjectCacheManager<SrsRtpFUAPayload2>* _srs_rtp_fua_cache = new SrsRtpObjectCacheManager<SrsRtpFUAPayload2>();
|
||||||
|
|
||||||
SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _srs_rtp_msg_cache = new SrsRtpObjectCacheManager<SrsSharedPtrMessage>();
|
SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _srs_rtp_msg_cache = new SrsRtpObjectCacheManager<SrsSharedPtrMessage>();
|
||||||
|
SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _srs_rtp_msg_cache2 = new SrsRtpObjectCacheManager<SrsSharedPtrMessage>();
|
||||||
|
|
||||||
SrsRtpRawPayload::SrsRtpRawPayload()
|
SrsRtpRawPayload::SrsRtpRawPayload()
|
||||||
{
|
{
|
||||||
|
|
|
@ -304,6 +304,7 @@ public:
|
||||||
virtual ~SrsRtpPacket2();
|
virtual ~SrsRtpPacket2();
|
||||||
private:
|
private:
|
||||||
void reuse();
|
void reuse();
|
||||||
|
void reuse_shared_msg();
|
||||||
public:
|
public:
|
||||||
// Reset the object to reuse it.
|
// Reset the object to reuse it.
|
||||||
virtual bool reset();
|
virtual bool reset();
|
||||||
|
@ -527,5 +528,6 @@ extern SrsRtpObjectCacheManager<SrsRtpFUAPayload2>* _srs_rtp_fua_cache;
|
||||||
|
|
||||||
// For RTP packet shared messages cache.
|
// For RTP packet shared messages cache.
|
||||||
extern SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _srs_rtp_msg_cache;
|
extern SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _srs_rtp_msg_cache;
|
||||||
|
extern SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _srs_rtp_msg_cache2;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue