mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
Perf: Refine the recycle RTP packet, user should reset it
This commit is contained in:
parent
b71cafea58
commit
8de201b635
4 changed files with 27 additions and 8 deletions
|
@ -1130,6 +1130,9 @@ srs_error_t SrsRtcPublishStream::on_rtp_plaintext(char* plaintext, int nb_plaint
|
|||
// Allocate packet form cache.
|
||||
SrsRtpPacket2* pkt = _srs_rtp_cache->allocate();
|
||||
|
||||
// It's better to reset it before decode it.
|
||||
pkt->reset();
|
||||
|
||||
// Copy the packet body.
|
||||
char* p = pkt->wrap(plaintext, nb_plaintext);
|
||||
|
||||
|
|
|
@ -589,6 +589,9 @@ std::vector<SrsRtcTrackDescription*> SrsRtcStream::get_track_desc(std::string ty
|
|||
SrsRtpPacketCacheHelper::SrsRtpPacketCacheHelper()
|
||||
{
|
||||
pkt = _srs_rtp_cache->allocate();
|
||||
|
||||
// We MUST reset the packet, when got from cache.
|
||||
pkt->reset();
|
||||
}
|
||||
|
||||
SrsRtpPacketCacheHelper::~SrsRtpPacketCacheHelper()
|
||||
|
|
|
@ -866,6 +866,21 @@ SrsRtpPacket2::~SrsRtpPacket2()
|
|||
recycle_shared_msg();
|
||||
}
|
||||
|
||||
void SrsRtpPacket2::reset()
|
||||
{
|
||||
nalu_type = SrsAvcNaluTypeReserved;
|
||||
frame_type = SrsFrameTypeReserved;
|
||||
cached_payload_size = 0;
|
||||
decode_handler = NULL;
|
||||
|
||||
// It's important to reset the header.
|
||||
header.reset();
|
||||
|
||||
// Recyle the payload again, to ensure the packet is new one.
|
||||
recycle_payload();
|
||||
recycle_shared_msg();
|
||||
}
|
||||
|
||||
void SrsRtpPacket2::recycle_payload()
|
||||
{
|
||||
if (!payload_) {
|
||||
|
@ -916,16 +931,10 @@ cleanup:
|
|||
|
||||
bool SrsRtpPacket2::recycle()
|
||||
{
|
||||
nalu_type = SrsAvcNaluTypeReserved;
|
||||
frame_type = SrsFrameTypeReserved;
|
||||
cached_payload_size = 0;
|
||||
decode_handler = NULL;
|
||||
|
||||
header.reset();
|
||||
|
||||
// We only recycle the payload and shared messages,
|
||||
// for header and fields, user will reset or copy it.
|
||||
recycle_payload();
|
||||
recycle_shared_msg();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -324,6 +324,10 @@ private:
|
|||
public:
|
||||
SrsRtpPacket2();
|
||||
virtual ~SrsRtpPacket2();
|
||||
public:
|
||||
// User MUST reset the packet if got from cache,
|
||||
// except copy(we will assign the header and copy payload).
|
||||
void reset();
|
||||
private:
|
||||
void recycle_payload();
|
||||
void recycle_shared_msg();
|
||||
|
|
Loading…
Reference in a new issue