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()
|
||||
{
|
||||
if (ptr) {
|
||||
if (ptr->shared_count == 0) {
|
||||
srs_freep(ptr);
|
||||
} else {
|
||||
if (ptr->shared_count > 0) {
|
||||
ptr->shared_count--;
|
||||
ptr = NULL;
|
||||
} else {
|
||||
srs_freep(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -778,11 +778,6 @@ void SrsRtpHeader::set_ssrc(uint32_t v)
|
|||
ssrc = v;
|
||||
}
|
||||
|
||||
uint32_t SrsRtpHeader::get_ssrc() const
|
||||
{
|
||||
return ssrc;
|
||||
}
|
||||
|
||||
void SrsRtpHeader::set_padding(uint8_t v)
|
||||
{
|
||||
padding_length = v;
|
||||
|
@ -835,21 +830,21 @@ void SrsRtpPacket2::recycle_payload()
|
|||
return;
|
||||
}
|
||||
|
||||
if (_srs_rtp_raw_cache->enabled() || _srs_rtp_fua_cache->enabled()) {
|
||||
// Only recycle some common payloads.
|
||||
if (payload_type_ == SrsRtpPacketPayloadTypeRaw) {
|
||||
if (payload_type_ == SrsRtpPacketPayloadTypeRaw && _srs_rtp_raw_cache->enabled()) {
|
||||
_srs_rtp_raw_cache->recycle((SrsRtpRawPayload*)payload_);
|
||||
} else if (payload_type_ == SrsRtpPacketPayloadTypeFUA2) {
|
||||
_srs_rtp_fua_cache->recycle((SrsRtpFUAPayload2*)payload_);
|
||||
} else {
|
||||
srs_freep(payload_);
|
||||
}
|
||||
} else {
|
||||
srs_freep(payload_);
|
||||
payload_ = NULL;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// Reset the payload and its type.
|
||||
if (payload_type_ == SrsRtpPacketPayloadTypeFUA2 && _srs_rtp_fua_cache->enabled()) {
|
||||
_srs_rtp_fua_cache->recycle((SrsRtpFUAPayload2*)payload_);
|
||||
payload_ = NULL;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
srs_freep(payload_);
|
||||
|
||||
cleanup:
|
||||
payload_type_ = SrsRtpPacketPayloadTypeUnknown;
|
||||
}
|
||||
|
||||
|
@ -859,20 +854,22 @@ void SrsRtpPacket2::recycle_shared_msg()
|
|||
return;
|
||||
}
|
||||
|
||||
// Recycle the real owner of message, clear the reference.
|
||||
if (_srs_rtp_msg_cache_buffers->enabled() || _srs_rtp_msg_cache_objs->enabled()) {
|
||||
// We only recycle the RTC UDP packet messages.
|
||||
if (shared_msg->payload && shared_msg->size == kRtpPacketSize && shared_msg->count() == 0) {
|
||||
_srs_rtp_msg_cache_buffers->recycle(shared_msg);
|
||||
} else {
|
||||
if (!shared_msg->payload || shared_msg->size != kRtpPacketSize || shared_msg->count() > 0) {
|
||||
shared_msg->unwrap();
|
||||
_srs_rtp_msg_cache_objs->recycle(shared_msg);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
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()
|
||||
|
@ -948,8 +945,12 @@ SrsRtpPacket2* SrsRtpPacket2::copy()
|
|||
SrsRtpPacket2* cp = _srs_rtp_cache->allocate();
|
||||
|
||||
// We got packet from cache, so we must recycle it.
|
||||
if (cp->payload_) {
|
||||
cp->recycle_payload();
|
||||
}
|
||||
if (cp->shared_msg) {
|
||||
cp->recycle_shared_msg();
|
||||
}
|
||||
|
||||
cp->header = header;
|
||||
cp->payload_ = payload_? payload_->copy():NULL;
|
||||
|
|
|
@ -250,7 +250,10 @@ public:
|
|||
void set_timestamp(uint32_t v);
|
||||
uint32_t get_timestamp() const;
|
||||
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);
|
||||
uint8_t get_padding() const;
|
||||
void set_extensions(const SrsRtpExtensionTypes* extmap);
|
||||
|
@ -400,7 +403,7 @@ public:
|
|||
}
|
||||
// Get the status of object cache.
|
||||
// SrsRtpObjectCacheManager::enabled
|
||||
bool enabled() {
|
||||
inline bool enabled() {
|
||||
return enabled_;
|
||||
}
|
||||
// SrsRtpObjectCacheManager::size
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue