RTC: Refine publisher memory allocate, by packet itself

pull/2252/head
winlin 4 years ago
parent 001a6a33ce
commit 2ae7e22469

@ -1193,19 +1193,11 @@ srs_error_t SrsRtcPublishStream::on_rtp_plaintext(char* plaintext, int nb_plaint
SrsRtpPacket2* pkt = new SrsRtpPacket2();
SrsAutoFree(SrsRtpPacket2, pkt);
if (true) {
pkt->set_decode_handler(this);
pkt->set_extension_types(&extension_types_);
pkt->shared_msg = new SrsSharedPtrMessage();
char* buf = new char[nb_plaintext];
memcpy(buf, plaintext, nb_plaintext);
pkt->shared_msg->wrap(buf, nb_plaintext);
SrsBuffer b(buf, nb_plaintext);
if ((err = pkt->decode(&b)) != srs_success) {
return srs_error_wrap(err, "decode rtp packet");
}
pkt->set_decode_handler(this);
pkt->set_extension_types(&extension_types_);
pkt->wrap(plaintext, nb_plaintext);
if ((err = pkt->decode(pkt->cache_buffer())) != srs_success) {
return srs_error_wrap(err, "decode rtp packet");
}
// For source to consume packet.

@ -768,6 +768,7 @@ SrsRtpPacket2::SrsRtpPacket2()
nalu_type = SrsAvcNaluTypeReserved;
shared_msg = NULL;
cache_buffer_ = NULL;
frame_type = SrsFrameTypeReserved;
cached_payload_size = 0;
@ -778,6 +779,25 @@ SrsRtpPacket2::~SrsRtpPacket2()
{
srs_freep(payload);
srs_freep(shared_msg);
srs_freep(cache_buffer_);
}
void SrsRtpPacket2::wrap(char* data, int size)
{
srs_freep(shared_msg);
shared_msg = new SrsSharedPtrMessage();
char* buf = new char[size];
memcpy(buf, data, size);
shared_msg->wrap(buf, size);
srs_freep(cache_buffer_);
cache_buffer_ = new SrsBuffer(buf, size);
}
SrsBuffer* SrsRtpPacket2::cache_buffer()
{
return cache_buffer_;
}
void SrsRtpPacket2::set_padding(int size)

@ -268,6 +268,7 @@ class SrsRtpPacket2
public:
SrsRtpHeader header;
ISrsRtpPayloader* payload;
SrsBuffer* cache_buffer_;
// Helper fields.
public:
// The first byte as nalu type, for video decoder only.
@ -285,6 +286,10 @@ private:
public:
SrsRtpPacket2();
virtual ~SrsRtpPacket2();
public:
// Wrap buffer to shared_message, which is managed by us.
void wrap(char* data, int size);
SrsBuffer* cache_buffer();
public:
// Set the padding of RTP packet.
void set_padding(int size);

Loading…
Cancel
Save