1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 20:01:56 +00:00

Perf: Refine RTP packet copy

This commit is contained in:
winlin 2021-02-27 23:03:08 +08:00
parent 8de201b635
commit 4058249d67

View file

@ -931,10 +931,16 @@ cleanup:
bool SrsRtpPacket2::recycle() bool SrsRtpPacket2::recycle()
{ {
// Clear the cache size, it may change when reuse it.
cached_payload_size = 0;
// Reset the handler, for decode only.
decode_handler = NULL;
// We only recycle the payload and shared messages, // We only recycle the payload and shared messages,
// for header and fields, user will reset or copy it. // for header and fields, user will reset or copy it.
recycle_payload(); recycle_payload();
recycle_shared_msg(); recycle_shared_msg();
return true; return true;
} }
@ -995,13 +1001,10 @@ SrsRtpPacket2* SrsRtpPacket2::copy()
{ {
SrsRtpPacket2* cp = _srs_rtp_cache->allocate(); SrsRtpPacket2* cp = _srs_rtp_cache->allocate();
// We got packet from cache, so we must recycle it. // We got packet from cache, the payload and message MUST be NULL,
if (cp->payload_) { // because we had clear it in recycle.
cp->recycle_payload(); //srs_assert(!cp->payload_);
} //srs_assert(!cp->shared_msg);
if (cp->shared_msg) {
cp->recycle_shared_msg();
}
cp->header.assign(header); cp->header.assign(header);
cp->payload_ = payload_? payload_->copy():NULL; cp->payload_ = payload_? payload_->copy():NULL;
@ -1011,8 +1014,9 @@ SrsRtpPacket2* SrsRtpPacket2::copy()
cp->shared_msg = shared_msg->copy(); cp->shared_msg = shared_msg->copy();
cp->frame_type = frame_type; cp->frame_type = frame_type;
cp->cached_payload_size = cached_payload_size; // For performance issue, do not copy the unused field.
cp->decode_handler = decode_handler; //cp->cached_payload_size = cached_payload_size;
//cp->decode_handler = decode_handler;
return cp; return cp;
} }