mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Perf: Refine the stat
This commit is contained in:
parent
d6c0117870
commit
e79293a3bc
6 changed files with 75 additions and 43 deletions
|
@ -39,6 +39,7 @@ using namespace std;
|
|||
#include <srs_kernel_codec.hpp>
|
||||
#include <srs_kernel_utility.hpp>
|
||||
#include <srs_core_autofree.hpp>
|
||||
#include <srs_kernel_rtc_rtp.hpp>
|
||||
|
||||
#include <srs_kernel_kbps.hpp>
|
||||
|
||||
|
@ -286,10 +287,24 @@ void SrsSharedPtrMessage::wrap(char* payload, int size)
|
|||
this->size = ptr->size;
|
||||
}
|
||||
|
||||
void SrsSharedPtrMessage::unwrap()
|
||||
{
|
||||
if (ptr) {
|
||||
if (ptr->shared_count == 0) {
|
||||
srs_freep(ptr);
|
||||
} else {
|
||||
ptr->shared_count--;
|
||||
ptr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
payload = NULL;
|
||||
size = 0;
|
||||
}
|
||||
|
||||
int SrsSharedPtrMessage::count()
|
||||
{
|
||||
srs_assert(ptr);
|
||||
return ptr->shared_count;
|
||||
return ptr? ptr->shared_count : 0;
|
||||
}
|
||||
|
||||
bool SrsSharedPtrMessage::check(int stream_id)
|
||||
|
@ -346,7 +361,7 @@ SrsSharedPtrMessage* SrsSharedPtrMessage::copy()
|
|||
{
|
||||
srs_assert(ptr);
|
||||
|
||||
SrsSharedPtrMessage* copy = new SrsSharedPtrMessage();
|
||||
SrsSharedPtrMessage* copy = _srs_rtp_msg_cache->allocate();
|
||||
|
||||
copy->ptr = ptr;
|
||||
ptr->shared_count++;
|
||||
|
|
|
@ -328,6 +328,8 @@ public:
|
|||
// Create shared ptr message from RAW payload.
|
||||
// @remark Note that the header is set to zero.
|
||||
virtual void wrap(char* payload, int size);
|
||||
// Decrease the reference, if the last one, free it.
|
||||
void unwrap();
|
||||
// Get current reference count.
|
||||
// when this object created, count set to 0.
|
||||
// if copy() this object, count increase 1.
|
||||
|
|
|
@ -40,6 +40,7 @@ SrsPps* _srs_pps_objs_rtps = new SrsPps();
|
|||
SrsPps* _srs_pps_objs_rraw = new SrsPps();
|
||||
SrsPps* _srs_pps_objs_rfua = new SrsPps();
|
||||
SrsPps* _srs_pps_objs_rbuf = new SrsPps();
|
||||
SrsPps* _srs_pps_objs_rothers = new SrsPps();
|
||||
|
||||
/* @see https://tools.ietf.org/html/rfc1889#section-5.1
|
||||
0 1 2 3
|
||||
|
@ -819,26 +820,11 @@ SrsRtpPacket2::SrsRtpPacket2()
|
|||
|
||||
SrsRtpPacket2::~SrsRtpPacket2()
|
||||
{
|
||||
srs_freep(payload);
|
||||
|
||||
// Recyle the real owner of message, no other reference object.
|
||||
if (shared_msg && shared_msg->count() == 0) {
|
||||
_srs_rtp_msg_cache->recycle(shared_msg);
|
||||
shared_msg = NULL;
|
||||
} else {
|
||||
srs_freep(shared_msg);
|
||||
}
|
||||
reuse();
|
||||
}
|
||||
|
||||
bool SrsRtpPacket2::reset()
|
||||
void SrsRtpPacket2::reuse()
|
||||
{
|
||||
nalu_type = SrsAvcNaluTypeReserved;
|
||||
frame_type = SrsFrameTypeReserved;
|
||||
cached_payload_size = 0;
|
||||
decode_handler = NULL;
|
||||
|
||||
header.reset();
|
||||
|
||||
// Only recycle some common payloads.
|
||||
SrsRtpRawPayload* raw_payload;
|
||||
SrsRtpFUAPayload2* fua_payload;
|
||||
|
@ -853,13 +839,27 @@ bool SrsRtpPacket2::reset()
|
|||
srs_freep(payload);
|
||||
}
|
||||
|
||||
// Recyle the real owner of message, no other reference object.
|
||||
if (shared_msg && shared_msg->count() == 0) {
|
||||
// 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;
|
||||
} else {
|
||||
srs_freep(shared_msg);
|
||||
}
|
||||
}
|
||||
|
||||
bool SrsRtpPacket2::reset()
|
||||
{
|
||||
nalu_type = SrsAvcNaluTypeReserved;
|
||||
frame_type = SrsFrameTypeReserved;
|
||||
cached_payload_size = 0;
|
||||
decode_handler = NULL;
|
||||
|
||||
header.reset();
|
||||
|
||||
// Reset and reuse the payload and shared message.
|
||||
reuse();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1095,6 +1095,8 @@ SrsRtpRawNALUs::SrsRtpRawNALUs()
|
|||
{
|
||||
cursor = 0;
|
||||
nn_bytes = 0;
|
||||
|
||||
++_srs_pps_objs_rothers->sugar;
|
||||
}
|
||||
|
||||
SrsRtpRawNALUs::~SrsRtpRawNALUs()
|
||||
|
@ -1232,6 +1234,8 @@ ISrsRtpPayloader* SrsRtpRawNALUs::copy()
|
|||
SrsRtpSTAPPayload::SrsRtpSTAPPayload()
|
||||
{
|
||||
nri = (SrsAvcNaluType)0;
|
||||
|
||||
++_srs_pps_objs_rothers->sugar;
|
||||
}
|
||||
|
||||
SrsRtpSTAPPayload::~SrsRtpSTAPPayload()
|
||||
|
@ -1381,7 +1385,7 @@ SrsRtpFUAPayload::SrsRtpFUAPayload()
|
|||
start = end = false;
|
||||
nri = nalu_type = (SrsAvcNaluType)0;
|
||||
|
||||
++_srs_pps_objs_rfua->sugar;
|
||||
++_srs_pps_objs_rothers->sugar;
|
||||
}
|
||||
|
||||
SrsRtpFUAPayload::~SrsRtpFUAPayload()
|
||||
|
|
|
@ -302,6 +302,8 @@ private:
|
|||
public:
|
||||
SrsRtpPacket2();
|
||||
virtual ~SrsRtpPacket2();
|
||||
private:
|
||||
void reuse();
|
||||
public:
|
||||
// Reset the object to reuse it.
|
||||
virtual bool reset();
|
||||
|
@ -356,6 +358,9 @@ public:
|
|||
bool enabled() {
|
||||
return enabled_;
|
||||
}
|
||||
int size() {
|
||||
return (int)cache_objs_.size();
|
||||
}
|
||||
// Try to allocate from cache, create new object if no cache.
|
||||
T* allocate() {
|
||||
while (true) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue