mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 11:51:57 +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;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -286,6 +286,7 @@ srs_error_t SrsRtcServer::initialize()
|
|||
|
||||
bool rtp_msg_cache = _srs_config->get_rtc_server_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);
|
||||
|
||||
|
|
|
@ -361,8 +361,12 @@ SrsSharedPtrMessage* SrsSharedPtrMessage::copy()
|
|||
{
|
||||
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;
|
||||
ptr->shared_count++;
|
||||
|
||||
|
|
|
@ -290,7 +290,7 @@ public:
|
|||
// video/audio packet use raw bytes, no video/audio packet.
|
||||
char* payload;
|
||||
|
||||
private:
|
||||
public:
|
||||
class SrsSharedPtrPayload
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -840,13 +840,24 @@ void SrsRtpPacket2::reuse()
|
|||
}
|
||||
|
||||
// Recycle the real owner of message, clear the reference.
|
||||
if (shared_msg) {
|
||||
if (shared_msg->count() > 0) {
|
||||
shared_msg->unwrap();
|
||||
}
|
||||
_srs_rtp_msg_cache->recycle(shared_msg);
|
||||
shared_msg = NULL;
|
||||
reuse_shared_msg();
|
||||
}
|
||||
|
||||
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);
|
||||
} else {
|
||||
shared_msg->unwrap();
|
||||
_srs_rtp_msg_cache2->recycle(shared_msg);
|
||||
}
|
||||
|
||||
shared_msg = NULL;
|
||||
}
|
||||
|
||||
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,
|
||||
// we free it and allocate a larger one.
|
||||
if (shared_msg->payload && shared_msg->size < size) {
|
||||
++_srs_pps_objs_rothers->sugar;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -907,7 +919,10 @@ char* SrsRtpPacket2::wrap(char* data, int size)
|
|||
|
||||
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();
|
||||
|
||||
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<SrsSharedPtrMessage>* _srs_rtp_msg_cache = new SrsRtpObjectCacheManager<SrsSharedPtrMessage>();
|
||||
SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _srs_rtp_msg_cache2 = new SrsRtpObjectCacheManager<SrsSharedPtrMessage>();
|
||||
|
||||
SrsRtpRawPayload::SrsRtpRawPayload()
|
||||
{
|
||||
|
|
|
@ -304,6 +304,7 @@ public:
|
|||
virtual ~SrsRtpPacket2();
|
||||
private:
|
||||
void reuse();
|
||||
void reuse_shared_msg();
|
||||
public:
|
||||
// Reset the object to reuse it.
|
||||
virtual bool reset();
|
||||
|
@ -527,5 +528,6 @@ extern SrsRtpObjectCacheManager<SrsRtpFUAPayload2>* _srs_rtp_fua_cache;
|
|||
|
||||
// For RTP packet shared messages cache.
|
||||
extern SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _srs_rtp_msg_cache;
|
||||
extern SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _srs_rtp_msg_cache2;
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue