mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
SquashSRS4: Remove object cache and stat api
This commit is contained in:
parent
f711eb79ed
commit
6a980683f7
44 changed files with 141 additions and 1277 deletions
|
@ -41,7 +41,6 @@ SrsPps* _srs_pps_objs_rraw = NULL;
|
|||
SrsPps* _srs_pps_objs_rfua = NULL;
|
||||
SrsPps* _srs_pps_objs_rbuf = NULL;
|
||||
SrsPps* _srs_pps_objs_rothers = NULL;
|
||||
SrsPps* _srs_pps_objs_drop = NULL;
|
||||
|
||||
/* @see https://tools.ietf.org/html/rfc1889#section-5.1
|
||||
0 1 2 3
|
||||
|
@ -786,89 +785,8 @@ SrsRtpPacket2::SrsRtpPacket2()
|
|||
|
||||
SrsRtpPacket2::~SrsRtpPacket2()
|
||||
{
|
||||
recycle_payload();
|
||||
recycle_shared_buffer();
|
||||
}
|
||||
|
||||
void SrsRtpPacket2::reset()
|
||||
{
|
||||
nalu_type = SrsAvcNaluTypeReserved;
|
||||
frame_type = SrsFrameTypeReserved;
|
||||
cached_payload_size = 0;
|
||||
decode_handler = NULL;
|
||||
|
||||
// It's important to reset the header.
|
||||
header = SrsRtpHeader();
|
||||
|
||||
// Recyle the payload again, to ensure the packet is new one.
|
||||
recycle_payload();
|
||||
recycle_shared_buffer();
|
||||
}
|
||||
|
||||
void SrsRtpPacket2::recycle_payload()
|
||||
{
|
||||
if (!payload_) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (payload_type_ == SrsRtpPacketPayloadTypeRaw && _srs_rtp_raw_cache->enabled()) {
|
||||
_srs_rtp_raw_cache->recycle((SrsRtpRawPayload*)payload_);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (payload_type_ == SrsRtpPacketPayloadTypeFUA2 && _srs_rtp_fua_cache->enabled()) {
|
||||
_srs_rtp_fua_cache->recycle((SrsRtpFUAPayload2*)payload_);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
srs_freep(payload_);
|
||||
|
||||
cleanup:
|
||||
payload_ = NULL;
|
||||
payload_type_ = SrsRtpPacketPayloadTypeUnknown;
|
||||
}
|
||||
|
||||
void SrsRtpPacket2::recycle_shared_buffer()
|
||||
{
|
||||
if (!shared_buffer_) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Only recycle the message for UDP packets.
|
||||
if (shared_buffer_->payload && shared_buffer_->size == kRtpPacketSize) {
|
||||
if (_srs_rtp_msg_cache_objs->enabled() && shared_buffer_->count() > 0) {
|
||||
// Recycle the small shared message objects.
|
||||
_srs_rtp_msg_cache_objs->recycle(shared_buffer_);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (_srs_rtp_msg_cache_buffers->enabled() && shared_buffer_->count() == 0) {
|
||||
// Recycle the UDP large buffer.
|
||||
_srs_rtp_msg_cache_buffers->recycle(shared_buffer_);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
srs_freep(shared_buffer_);
|
||||
|
||||
cleanup:
|
||||
shared_buffer_ = NULL;
|
||||
actual_buffer_size_ = 0;
|
||||
}
|
||||
|
||||
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,
|
||||
// for header and fields, user will reset or copy it.
|
||||
recycle_payload();
|
||||
recycle_shared_buffer();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
char* SrsRtpPacket2::wrap(int size)
|
||||
|
@ -882,29 +800,16 @@ char* SrsRtpPacket2::wrap(int size)
|
|||
}
|
||||
|
||||
// Create a large enough message, with under-layer buffer.
|
||||
while (true) {
|
||||
srs_freep(shared_buffer_);
|
||||
shared_buffer_ = _srs_rtp_msg_cache_buffers->allocate();
|
||||
srs_freep(shared_buffer_);
|
||||
shared_buffer_ = new SrsSharedPtrMessage();
|
||||
|
||||
// If got a cached message(which has payload), but it's too small,
|
||||
// we free it and allocate a larger one.
|
||||
if (shared_buffer_->payload && shared_buffer_->size < size) {
|
||||
++_srs_pps_objs_rothers->sugar;
|
||||
continue;
|
||||
}
|
||||
// Create under-layer buffer for new message
|
||||
// For RTC, we use larger under-layer buffer for each packet.
|
||||
int nb_buffer = srs_max(size, kRtpPacketSize);
|
||||
char* buf = new char[nb_buffer];
|
||||
shared_buffer_->wrap(buf, nb_buffer);
|
||||
|
||||
// Create under-layer buffer for new message
|
||||
if (!shared_buffer_->payload) {
|
||||
// For RTC, we use larger under-layer buffer for each packet.
|
||||
int nb_buffer = srs_max(size, kRtpPacketSize);
|
||||
char* buf = new char[nb_buffer];
|
||||
shared_buffer_->wrap(buf, nb_buffer);
|
||||
|
||||
++_srs_pps_objs_rbuf->sugar;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
++_srs_pps_objs_rbuf->sugar;
|
||||
|
||||
return shared_buffer_->payload;
|
||||
}
|
||||
|
@ -933,7 +838,7 @@ char* SrsRtpPacket2::wrap(SrsSharedPtrMessage* msg)
|
|||
|
||||
SrsRtpPacket2* SrsRtpPacket2::copy()
|
||||
{
|
||||
SrsRtpPacket2* cp = _srs_rtp_cache->allocate();
|
||||
SrsRtpPacket2* cp = new SrsRtpPacket2();
|
||||
|
||||
// We got packet from cache, the payload and message MUST be NULL,
|
||||
// because we had clear it in recycle.
|
||||
|
@ -1043,7 +948,7 @@ srs_error_t SrsRtpPacket2::decode(SrsBuffer* buf)
|
|||
|
||||
// By default, we always use the RAW payload.
|
||||
if (!payload_) {
|
||||
payload_ = _srs_rtp_raw_cache->allocate();
|
||||
payload_ = new SrsRtpRawPayload();
|
||||
payload_type_ = SrsRtpPacketPayloadTypeRaw;
|
||||
}
|
||||
|
||||
|
@ -1081,13 +986,6 @@ bool SrsRtpPacket2::is_keyframe()
|
|||
return false;
|
||||
}
|
||||
|
||||
SrsRtpObjectCacheManager<SrsRtpPacket2>* _srs_rtp_cache = NULL;
|
||||
SrsRtpObjectCacheManager<SrsRtpRawPayload>* _srs_rtp_raw_cache = NULL;
|
||||
SrsRtpObjectCacheManager<SrsRtpFUAPayload2>* _srs_rtp_fua_cache = NULL;
|
||||
|
||||
SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _srs_rtp_msg_cache_buffers = NULL;
|
||||
SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _srs_rtp_msg_cache_objs = NULL;
|
||||
|
||||
SrsRtpRawPayload::SrsRtpRawPayload()
|
||||
{
|
||||
payload = NULL;
|
||||
|
@ -1100,12 +998,6 @@ SrsRtpRawPayload::~SrsRtpRawPayload()
|
|||
{
|
||||
}
|
||||
|
||||
bool SrsRtpRawPayload::recycle()
|
||||
{
|
||||
payload=NULL; nn_payload=0;
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64_t SrsRtpRawPayload::nb_bytes()
|
||||
{
|
||||
return nn_payload;
|
||||
|
@ -1140,7 +1032,7 @@ srs_error_t SrsRtpRawPayload::decode(SrsBuffer* buf)
|
|||
|
||||
ISrsRtpPayloader* SrsRtpRawPayload::copy()
|
||||
{
|
||||
SrsRtpRawPayload* cp = _srs_rtp_raw_cache->allocate();
|
||||
SrsRtpRawPayload* cp = new SrsRtpRawPayload();
|
||||
|
||||
cp->payload = payload;
|
||||
cp->nn_payload = nn_payload;
|
||||
|
@ -1566,16 +1458,6 @@ SrsRtpFUAPayload2::~SrsRtpFUAPayload2()
|
|||
{
|
||||
}
|
||||
|
||||
bool SrsRtpFUAPayload2::recycle()
|
||||
{
|
||||
start = end = false;
|
||||
nri = nalu_type = (SrsAvcNaluType)0;
|
||||
|
||||
payload = NULL;
|
||||
size = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64_t SrsRtpFUAPayload2::nb_bytes()
|
||||
{
|
||||
return 2 + size;
|
||||
|
@ -1643,7 +1525,7 @@ srs_error_t SrsRtpFUAPayload2::decode(SrsBuffer* buf)
|
|||
|
||||
ISrsRtpPayloader* SrsRtpFUAPayload2::copy()
|
||||
{
|
||||
SrsRtpFUAPayload2* cp = _srs_rtp_fua_cache->allocate();
|
||||
SrsRtpFUAPayload2* cp = new SrsRtpFUAPayload2();
|
||||
|
||||
cp->nri = nri;
|
||||
cp->start = start;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue