1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00

Refacor STAP RTP packet

This commit is contained in:
winlin 2020-04-12 01:05:11 +08:00
parent ca027ca5cb
commit acbbdf51d6
2 changed files with 14 additions and 9 deletions

View file

@ -212,21 +212,25 @@ srs_error_t SrsRtpRawPayload::encode(SrsBuffer* buf)
SrsRtpSTAPPayload::SrsRtpSTAPPayload() SrsRtpSTAPPayload::SrsRtpSTAPPayload()
{ {
nri = (SrsAvcNaluType)0; nri = (SrsAvcNaluType)0;
nalus = NULL;
nn_nalus = 0;
} }
SrsRtpSTAPPayload::~SrsRtpSTAPPayload() SrsRtpSTAPPayload::~SrsRtpSTAPPayload()
{ {
srs_freepa(nalus); vector<SrsSample*>::iterator it;
for (it = nalus.begin(); it != nalus.end(); ++it) {
SrsSample* p = *it;
srs_freep(p);
}
nalus.clear();
} }
int SrsRtpSTAPPayload::nb_bytes() int SrsRtpSTAPPayload::nb_bytes()
{ {
int size = 1; int size = 1;
for (int i = 0; i < nn_nalus; i++) { vector<SrsSample*>::iterator it;
SrsSample* p = nalus + i; for (it = nalus.begin(); it != nalus.end(); ++it) {
SrsSample* p = *it;
size += 2 + p->size; size += 2 + p->size;
} }
@ -246,8 +250,9 @@ srs_error_t SrsRtpSTAPPayload::encode(SrsBuffer* buf)
buf->write_1bytes(v); buf->write_1bytes(v);
// NALUs. // NALUs.
for (int i = 0; i < nn_nalus; i++) { vector<SrsSample*>::iterator it;
SrsSample* p = nalus + i; for (it = nalus.begin(); it != nalus.end(); ++it) {
SrsSample* p = *it;
if (!buf->require(2 + p->size)) { if (!buf->require(2 + p->size)) {
return srs_error_new(ERROR_RTC_RTP_MUXER, "requires %d bytes", 2 + p->size); return srs_error_new(ERROR_RTC_RTP_MUXER, "requires %d bytes", 2 + p->size);
} }
@ -272,6 +277,7 @@ SrsRtpFUAPayload::~SrsRtpFUAPayload()
SrsSample* p = *it; SrsSample* p = *it;
srs_freep(p); srs_freep(p);
} }
nalus.clear();
} }
int SrsRtpFUAPayload::nb_bytes() int SrsRtpFUAPayload::nb_bytes()

View file

@ -110,8 +110,7 @@ public:
SrsAvcNaluType nri; SrsAvcNaluType nri;
// The NALU samples. // The NALU samples.
// @remark We only refer to the memory, user must free its bytes. // @remark We only refer to the memory, user must free its bytes.
SrsSample* nalus; std::vector<SrsSample*> nalus;
int nn_nalus;
public: public:
SrsRtpSTAPPayload(); SrsRtpSTAPPayload();
virtual ~SrsRtpSTAPPayload(); virtual ~SrsRtpSTAPPayload();