mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Refine code
This commit is contained in:
parent
f83a47a0fc
commit
55696ce871
3 changed files with 42 additions and 38 deletions
|
@ -290,11 +290,11 @@ void SrsSharedPtrMessage::wrap(char* payload, int size)
|
||||||
void SrsSharedPtrMessage::unwrap()
|
void SrsSharedPtrMessage::unwrap()
|
||||||
{
|
{
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
if (ptr->shared_count == 0) {
|
if (ptr->shared_count > 0) {
|
||||||
srs_freep(ptr);
|
|
||||||
} else {
|
|
||||||
ptr->shared_count--;
|
ptr->shared_count--;
|
||||||
ptr = NULL;
|
ptr = NULL;
|
||||||
|
} else {
|
||||||
|
srs_freep(ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -778,11 +778,6 @@ void SrsRtpHeader::set_ssrc(uint32_t v)
|
||||||
ssrc = v;
|
ssrc = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t SrsRtpHeader::get_ssrc() const
|
|
||||||
{
|
|
||||||
return ssrc;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SrsRtpHeader::set_padding(uint8_t v)
|
void SrsRtpHeader::set_padding(uint8_t v)
|
||||||
{
|
{
|
||||||
padding_length = v;
|
padding_length = v;
|
||||||
|
@ -835,21 +830,21 @@ void SrsRtpPacket2::recycle_payload()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_srs_rtp_raw_cache->enabled() || _srs_rtp_fua_cache->enabled()) {
|
if (payload_type_ == SrsRtpPacketPayloadTypeRaw && _srs_rtp_raw_cache->enabled()) {
|
||||||
// Only recycle some common payloads.
|
_srs_rtp_raw_cache->recycle((SrsRtpRawPayload*)payload_);
|
||||||
if (payload_type_ == SrsRtpPacketPayloadTypeRaw) {
|
payload_ = NULL;
|
||||||
_srs_rtp_raw_cache->recycle((SrsRtpRawPayload*)payload_);
|
goto cleanup;
|
||||||
} else if (payload_type_ == SrsRtpPacketPayloadTypeFUA2) {
|
|
||||||
_srs_rtp_fua_cache->recycle((SrsRtpFUAPayload2*)payload_);
|
|
||||||
} else {
|
|
||||||
srs_freep(payload_);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
srs_freep(payload_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the payload and its type.
|
if (payload_type_ == SrsRtpPacketPayloadTypeFUA2 && _srs_rtp_fua_cache->enabled()) {
|
||||||
payload_ = NULL;
|
_srs_rtp_fua_cache->recycle((SrsRtpFUAPayload2*)payload_);
|
||||||
|
payload_ = NULL;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
srs_freep(payload_);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
payload_type_ = SrsRtpPacketPayloadTypeUnknown;
|
payload_type_ = SrsRtpPacketPayloadTypeUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -859,20 +854,22 @@ void SrsRtpPacket2::recycle_shared_msg()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recycle the real owner of message, clear the reference.
|
if (!shared_msg->payload || shared_msg->size != kRtpPacketSize || shared_msg->count() > 0) {
|
||||||
if (_srs_rtp_msg_cache_buffers->enabled() || _srs_rtp_msg_cache_objs->enabled()) {
|
shared_msg->unwrap();
|
||||||
// We only recycle the RTC UDP packet messages.
|
_srs_rtp_msg_cache_objs->recycle(shared_msg);
|
||||||
if (shared_msg->payload && shared_msg->size == kRtpPacketSize && shared_msg->count() == 0) {
|
goto cleanup;
|
||||||
_srs_rtp_msg_cache_buffers->recycle(shared_msg);
|
|
||||||
} else {
|
|
||||||
shared_msg->unwrap();
|
|
||||||
_srs_rtp_msg_cache_objs->recycle(shared_msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
shared_msg = NULL;
|
|
||||||
} else {
|
|
||||||
srs_freep(shared_msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_srs_rtp_msg_cache_buffers->enabled()) {
|
||||||
|
_srs_rtp_msg_cache_buffers->recycle(shared_msg);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
srs_freep(shared_msg);
|
||||||
|
return;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
shared_msg = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsRtpPacket2::recycle()
|
bool SrsRtpPacket2::recycle()
|
||||||
|
@ -948,8 +945,12 @@ 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, so we must recycle it.
|
||||||
cp->recycle_payload();
|
if (cp->payload_) {
|
||||||
cp->recycle_shared_msg();
|
cp->recycle_payload();
|
||||||
|
}
|
||||||
|
if (cp->shared_msg) {
|
||||||
|
cp->recycle_shared_msg();
|
||||||
|
}
|
||||||
|
|
||||||
cp->header = header;
|
cp->header = header;
|
||||||
cp->payload_ = payload_? payload_->copy():NULL;
|
cp->payload_ = payload_? payload_->copy():NULL;
|
||||||
|
|
|
@ -250,7 +250,10 @@ public:
|
||||||
void set_timestamp(uint32_t v);
|
void set_timestamp(uint32_t v);
|
||||||
uint32_t get_timestamp() const;
|
uint32_t get_timestamp() const;
|
||||||
void set_ssrc(uint32_t v);
|
void set_ssrc(uint32_t v);
|
||||||
uint32_t get_ssrc() const;
|
// SrsRtpHeader::get_ssrc
|
||||||
|
inline uint32_t get_ssrc() const {
|
||||||
|
return ssrc;
|
||||||
|
}
|
||||||
void set_padding(uint8_t v);
|
void set_padding(uint8_t v);
|
||||||
uint8_t get_padding() const;
|
uint8_t get_padding() const;
|
||||||
void set_extensions(const SrsRtpExtensionTypes* extmap);
|
void set_extensions(const SrsRtpExtensionTypes* extmap);
|
||||||
|
@ -400,7 +403,7 @@ public:
|
||||||
}
|
}
|
||||||
// Get the status of object cache.
|
// Get the status of object cache.
|
||||||
// SrsRtpObjectCacheManager::enabled
|
// SrsRtpObjectCacheManager::enabled
|
||||||
bool enabled() {
|
inline bool enabled() {
|
||||||
return enabled_;
|
return enabled_;
|
||||||
}
|
}
|
||||||
// SrsRtpObjectCacheManager::size
|
// SrsRtpObjectCacheManager::size
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue