mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 20:01:56 +00:00
RTC: Fast copy shared message for RTP
This commit is contained in:
parent
9ee0ed919a
commit
4e474a24ce
4 changed files with 23 additions and 10 deletions
|
@ -361,14 +361,7 @@ SrsSharedPtrMessage* SrsSharedPtrMessage::copy()
|
||||||
{
|
{
|
||||||
srs_assert(ptr);
|
srs_assert(ptr);
|
||||||
|
|
||||||
SrsSharedPtrMessage* copy = _srs_rtp_msg_cache_objs->allocate();
|
SrsSharedPtrMessage* copy = copy2();
|
||||||
|
|
||||||
// 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++;
|
|
||||||
|
|
||||||
copy->timestamp = timestamp;
|
copy->timestamp = timestamp;
|
||||||
copy->stream_id = stream_id;
|
copy->stream_id = stream_id;
|
||||||
|
@ -378,6 +371,20 @@ SrsSharedPtrMessage* SrsSharedPtrMessage::copy()
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SrsSharedPtrMessage* SrsSharedPtrMessage::copy2()
|
||||||
|
{
|
||||||
|
SrsSharedPtrMessage* copy = _srs_rtp_msg_cache_objs->allocate();
|
||||||
|
|
||||||
|
// We got an object from cache, the ptr might exists, so unwrap it.
|
||||||
|
//srs_assert(!copy->ptr);
|
||||||
|
|
||||||
|
// Reference to this message instead.
|
||||||
|
copy->ptr = ptr;
|
||||||
|
ptr->shared_count++;
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
SrsFlvTransmuxer::SrsFlvTransmuxer()
|
SrsFlvTransmuxer::SrsFlvTransmuxer()
|
||||||
{
|
{
|
||||||
writer = NULL;
|
writer = NULL;
|
||||||
|
|
|
@ -351,6 +351,8 @@ public:
|
||||||
// copy current shared ptr message, use ref-count.
|
// copy current shared ptr message, use ref-count.
|
||||||
// @remark, assert object is created.
|
// @remark, assert object is created.
|
||||||
virtual SrsSharedPtrMessage* copy();
|
virtual SrsSharedPtrMessage* copy();
|
||||||
|
// Only copy the buffer, without header fields.
|
||||||
|
virtual SrsSharedPtrMessage* copy2();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Transmux RTMP packets to FLV stream.
|
// Transmux RTMP packets to FLV stream.
|
||||||
|
|
|
@ -910,6 +910,8 @@ void SrsRtpPacket2::recycle_shared_msg()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shared_msg->payload || shared_msg->size != kRtpPacketSize || shared_msg->count() > 0) {
|
if (!shared_msg->payload || shared_msg->size != kRtpPacketSize || shared_msg->count() > 0) {
|
||||||
|
// Note that we must unwrap the shared message, because this object pool only cache the
|
||||||
|
// shared message itself without payload.
|
||||||
shared_msg->unwrap();
|
shared_msg->unwrap();
|
||||||
_srs_rtp_msg_cache_objs->recycle(shared_msg);
|
_srs_rtp_msg_cache_objs->recycle(shared_msg);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -1007,7 +1009,7 @@ SrsRtpPacket2* SrsRtpPacket2::copy()
|
||||||
cp->payload_type_ = payload_type_;
|
cp->payload_type_ = payload_type_;
|
||||||
|
|
||||||
cp->nalu_type = nalu_type;
|
cp->nalu_type = nalu_type;
|
||||||
cp->shared_msg = shared_msg->copy();
|
cp->shared_msg = shared_msg->copy2();
|
||||||
cp->frame_type = frame_type;
|
cp->frame_type = frame_type;
|
||||||
|
|
||||||
// For performance issue, do not copy the unused field.
|
// For performance issue, do not copy the unused field.
|
||||||
|
|
|
@ -591,8 +591,10 @@ extern SrsRtpObjectCacheManager<SrsRtpPacket2>* _srs_rtp_cache;
|
||||||
extern SrsRtpObjectCacheManager<SrsRtpRawPayload>* _srs_rtp_raw_cache;
|
extern SrsRtpObjectCacheManager<SrsRtpRawPayload>* _srs_rtp_raw_cache;
|
||||||
extern SrsRtpObjectCacheManager<SrsRtpFUAPayload2>* _srs_rtp_fua_cache;
|
extern SrsRtpObjectCacheManager<SrsRtpFUAPayload2>* _srs_rtp_fua_cache;
|
||||||
|
|
||||||
// For RTP packet shared messages cache.
|
// For shared message cache, with payload.
|
||||||
extern SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _srs_rtp_msg_cache_buffers;
|
extern SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _srs_rtp_msg_cache_buffers;
|
||||||
|
// For shared message cache, without payload.
|
||||||
|
// Note that user must unwrap the shared message, before recycle it.
|
||||||
extern SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _srs_rtp_msg_cache_objs;
|
extern SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _srs_rtp_msg_cache_objs;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue