mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 20:01:56 +00:00
RTC: Cache the RTP payload objects
This commit is contained in:
parent
4d0863468a
commit
fc4d7080c6
4 changed files with 38 additions and 19 deletions
|
@ -286,6 +286,8 @@ srs_error_t SrsRtcServer::initialize()
|
||||||
|
|
||||||
bool rtp_cache = _srs_config->get_rtc_server_rtp_cache();
|
bool rtp_cache = _srs_config->get_rtc_server_rtp_cache();
|
||||||
_srs_rtp_cache->set_enabled(rtp_cache);
|
_srs_rtp_cache->set_enabled(rtp_cache);
|
||||||
|
_srs_rtp_raw_cache->set_enabled(rtp_cache);
|
||||||
|
_srs_rtp_fua_cache->set_enabled(rtp_cache);
|
||||||
|
|
||||||
bool rtp_msg_cache = _srs_config->get_rtc_server_rtp_msg_cache();
|
bool rtp_msg_cache = _srs_config->get_rtc_server_rtp_msg_cache();
|
||||||
_srs_rtp_msg_cache->set_enabled(rtp_msg_cache);
|
_srs_rtp_msg_cache->set_enabled(rtp_msg_cache);
|
||||||
|
|
|
@ -825,7 +825,7 @@ srs_error_t SrsRtcFromRtmpBridger::package_opus(char* data, int size, SrsRtpPack
|
||||||
// TODO: FIXME: Why 960? Need Refactoring?
|
// TODO: FIXME: Why 960? Need Refactoring?
|
||||||
audio_timestamp += 960;
|
audio_timestamp += 960;
|
||||||
|
|
||||||
SrsRtpRawPayload* raw = new SrsRtpRawPayload();
|
SrsRtpRawPayload* raw = _srs_rtp_raw_cache->allocate();
|
||||||
pkt->payload = raw;
|
pkt->payload = raw;
|
||||||
|
|
||||||
raw->payload = pkt->wrap(data, size);
|
raw->payload = pkt->wrap(data, size);
|
||||||
|
@ -1107,7 +1107,7 @@ srs_error_t SrsRtcFromRtmpBridger::package_single_nalu(SrsSharedPtrMessage* msg,
|
||||||
pkt->header.set_sequence(video_sequence++);
|
pkt->header.set_sequence(video_sequence++);
|
||||||
pkt->header.set_timestamp(msg->timestamp * 90);
|
pkt->header.set_timestamp(msg->timestamp * 90);
|
||||||
|
|
||||||
SrsRtpRawPayload* raw = new SrsRtpRawPayload();
|
SrsRtpRawPayload* raw = _srs_rtp_raw_cache->allocate();
|
||||||
pkt->payload = raw;
|
pkt->payload = raw;
|
||||||
|
|
||||||
raw->payload = sample->bytes;
|
raw->payload = sample->bytes;
|
||||||
|
@ -1141,7 +1141,7 @@ srs_error_t SrsRtcFromRtmpBridger::package_fu_a(SrsSharedPtrMessage* msg, SrsSam
|
||||||
pkt->header.set_sequence(video_sequence++);
|
pkt->header.set_sequence(video_sequence++);
|
||||||
pkt->header.set_timestamp(msg->timestamp * 90);
|
pkt->header.set_timestamp(msg->timestamp * 90);
|
||||||
|
|
||||||
SrsRtpFUAPayload2* fua = new SrsRtpFUAPayload2();
|
SrsRtpFUAPayload2* fua = _srs_rtp_fua_cache->allocate();
|
||||||
pkt->payload = fua;
|
pkt->payload = fua;
|
||||||
|
|
||||||
fua->nri = (SrsAvcNaluType)header;
|
fua->nri = (SrsAvcNaluType)header;
|
||||||
|
@ -1861,7 +1861,7 @@ void SrsRtcAudioRecvTrack::on_before_decode_payload(SrsRtpPacket2* pkt, SrsBuffe
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
*ppayload = new SrsRtpRawPayload();
|
*ppayload = _srs_rtp_raw_cache->allocate();
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcAudioRecvTrack::on_rtp(SrsRtcStream* source, SrsRtpPacket2* pkt, bool nack_enabled)
|
srs_error_t SrsRtcAudioRecvTrack::on_rtp(SrsRtcStream* source, SrsRtpPacket2* pkt, bool nack_enabled)
|
||||||
|
@ -1921,9 +1921,9 @@ void SrsRtcVideoRecvTrack::on_before_decode_payload(SrsRtpPacket2* pkt, SrsBuffe
|
||||||
if (v == kStapA) {
|
if (v == kStapA) {
|
||||||
*ppayload = new SrsRtpSTAPPayload();
|
*ppayload = new SrsRtpSTAPPayload();
|
||||||
} else if (v == kFuA) {
|
} else if (v == kFuA) {
|
||||||
*ppayload = new SrsRtpFUAPayload2();
|
*ppayload = _srs_rtp_fua_cache->allocate();
|
||||||
} else {
|
} else {
|
||||||
*ppayload = new SrsRtpRawPayload();
|
*ppayload = _srs_rtp_raw_cache->allocate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -839,10 +839,19 @@ bool SrsRtpPacket2::reset()
|
||||||
|
|
||||||
header.reset();
|
header.reset();
|
||||||
|
|
||||||
// We do not cache the payload, it will be created even
|
// Only recycle some common payloads.
|
||||||
// we cache it, because it only stores pointers to the shared message,
|
SrsRtpRawPayload* raw_payload;
|
||||||
// and it's different for each packet.
|
SrsRtpFUAPayload2* fua_payload;
|
||||||
|
|
||||||
|
if ((raw_payload = dynamic_cast<SrsRtpRawPayload*>(payload)) != NULL) {
|
||||||
|
_srs_rtp_raw_cache->recycle(raw_payload);
|
||||||
|
payload = NULL;
|
||||||
|
} else if ((fua_payload = dynamic_cast<SrsRtpFUAPayload2*>(payload)) != NULL) {
|
||||||
|
_srs_rtp_fua_cache->recycle(fua_payload);
|
||||||
|
payload = NULL;
|
||||||
|
} else {
|
||||||
srs_freep(payload);
|
srs_freep(payload);
|
||||||
|
}
|
||||||
|
|
||||||
// Recyle the real owner of message, no other reference object.
|
// Recyle the real owner of message, no other reference object.
|
||||||
if (shared_msg && shared_msg->count() == 0) {
|
if (shared_msg && shared_msg->count() == 0) {
|
||||||
|
@ -1012,7 +1021,7 @@ srs_error_t SrsRtpPacket2::decode(SrsBuffer* buf)
|
||||||
|
|
||||||
// By default, we always use the RAW payload.
|
// By default, we always use the RAW payload.
|
||||||
if (!payload) {
|
if (!payload) {
|
||||||
payload = new SrsRtpRawPayload();
|
payload = _srs_rtp_raw_cache->allocate();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = payload->decode(buf)) != srs_success) {
|
if ((err = payload->decode(buf)) != srs_success) {
|
||||||
|
@ -1023,6 +1032,8 @@ srs_error_t SrsRtpPacket2::decode(SrsBuffer* buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtpObjectCacheManager<SrsRtpPacket2>* _srs_rtp_cache = new SrsRtpObjectCacheManager<SrsRtpPacket2>();
|
SrsRtpObjectCacheManager<SrsRtpPacket2>* _srs_rtp_cache = new SrsRtpObjectCacheManager<SrsRtpPacket2>();
|
||||||
|
SrsRtpObjectCacheManager<SrsRtpRawPayload>* _srs_rtp_raw_cache = new SrsRtpObjectCacheManager<SrsRtpRawPayload>();
|
||||||
|
SrsRtpObjectCacheManager<SrsRtpFUAPayload2>* _srs_rtp_fua_cache = new SrsRtpObjectCacheManager<SrsRtpFUAPayload2>();
|
||||||
|
|
||||||
SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _srs_rtp_msg_cache = new SrsRtpObjectCacheManager<SrsSharedPtrMessage>();
|
SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _srs_rtp_msg_cache = new SrsRtpObjectCacheManager<SrsSharedPtrMessage>();
|
||||||
|
|
||||||
|
@ -1072,7 +1083,7 @@ srs_error_t SrsRtpRawPayload::decode(SrsBuffer* buf)
|
||||||
|
|
||||||
ISrsRtpPayloader* SrsRtpRawPayload::copy()
|
ISrsRtpPayloader* SrsRtpRawPayload::copy()
|
||||||
{
|
{
|
||||||
SrsRtpRawPayload* cp = new SrsRtpRawPayload();
|
SrsRtpRawPayload* cp = _srs_rtp_raw_cache->allocate();
|
||||||
|
|
||||||
cp->payload = payload;
|
cp->payload = payload;
|
||||||
cp->nn_payload = nn_payload;
|
cp->nn_payload = nn_payload;
|
||||||
|
@ -1561,7 +1572,7 @@ srs_error_t SrsRtpFUAPayload2::decode(SrsBuffer* buf)
|
||||||
|
|
||||||
ISrsRtpPayloader* SrsRtpFUAPayload2::copy()
|
ISrsRtpPayloader* SrsRtpFUAPayload2::copy()
|
||||||
{
|
{
|
||||||
SrsRtpFUAPayload2* cp = new SrsRtpFUAPayload2();
|
SrsRtpFUAPayload2* cp = _srs_rtp_fua_cache->allocate();
|
||||||
|
|
||||||
cp->nri = nri;
|
cp->nri = nri;
|
||||||
cp->start = start;
|
cp->start = start;
|
||||||
|
|
|
@ -394,12 +394,6 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// For RTP packets cache.
|
|
||||||
extern SrsRtpObjectCacheManager<SrsRtpPacket2>* _srs_rtp_cache;
|
|
||||||
|
|
||||||
// For RTP packet shared messages cache.
|
|
||||||
extern SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _srs_rtp_msg_cache;
|
|
||||||
|
|
||||||
// Single payload data.
|
// Single payload data.
|
||||||
class SrsRtpRawPayload : public ISrsRtpPayloader
|
class SrsRtpRawPayload : public ISrsRtpPayloader
|
||||||
{
|
{
|
||||||
|
@ -411,6 +405,8 @@ public:
|
||||||
public:
|
public:
|
||||||
SrsRtpRawPayload();
|
SrsRtpRawPayload();
|
||||||
virtual ~SrsRtpRawPayload();
|
virtual ~SrsRtpRawPayload();
|
||||||
|
public:
|
||||||
|
bool reset() { return true; }
|
||||||
// interface ISrsRtpPayloader
|
// interface ISrsRtpPayloader
|
||||||
public:
|
public:
|
||||||
virtual uint64_t nb_bytes();
|
virtual uint64_t nb_bytes();
|
||||||
|
@ -509,6 +505,8 @@ public:
|
||||||
public:
|
public:
|
||||||
SrsRtpFUAPayload2();
|
SrsRtpFUAPayload2();
|
||||||
virtual ~SrsRtpFUAPayload2();
|
virtual ~SrsRtpFUAPayload2();
|
||||||
|
public:
|
||||||
|
bool reset() { return true; }
|
||||||
// interface ISrsRtpPayloader
|
// interface ISrsRtpPayloader
|
||||||
public:
|
public:
|
||||||
virtual uint64_t nb_bytes();
|
virtual uint64_t nb_bytes();
|
||||||
|
@ -517,4 +515,12 @@ public:
|
||||||
virtual ISrsRtpPayloader* copy();
|
virtual ISrsRtpPayloader* copy();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// For RTP packets cache.
|
||||||
|
extern SrsRtpObjectCacheManager<SrsRtpPacket2>* _srs_rtp_cache;
|
||||||
|
extern SrsRtpObjectCacheManager<SrsRtpRawPayload>* _srs_rtp_raw_cache;
|
||||||
|
extern SrsRtpObjectCacheManager<SrsRtpFUAPayload2>* _srs_rtp_fua_cache;
|
||||||
|
|
||||||
|
// For RTP packet shared messages cache.
|
||||||
|
extern SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _srs_rtp_msg_cache;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue