Skip to content

Commit

Permalink
fixup allocate refcounted packet via av_new_packet
Browse files Browse the repository at this point in the history
  • Loading branch information
rom1v committed Jul 29, 2019
1 parent 7c64707 commit 0aa9828
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions app/src/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,17 @@ stream_recv_packet(struct stream *stream, AVPacket *packet) {
uint32_t len = buffer_read32be(&header[8]);
SDL_assert(len);

void *buf = av_malloc(len);
if (!buf) {
LOGE("Could not allocate packet buffer");
if (av_new_packet(packet, len)) {
LOGE("Could not allocate packet");
return false;
}

r = net_recv_all(stream->socket, buf, len);
r = net_recv_all(stream->socket, packet->data, len);
if (r < len) {
av_free(buf);
av_packet_unref(packet);
return false;
}

packet->data = buf;
packet->size = len;
packet->pts = pts != NO_PTS ? pts : AV_NOPTS_VALUE;

return true;
Expand Down Expand Up @@ -225,15 +222,14 @@ run_stream(void *data) {

for (;;) {
AVPacket packet;
av_init_packet(&packet);
bool ok = stream_recv_packet(stream, &packet);
if (!ok) {
// end of stream
break;
}

ok = stream_push_packet(stream, &packet);
av_free(packet.data);
av_packet_unref(&packet);
if (!ok) {
// cannot process packet (error already logged)
break;
Expand Down

0 comments on commit 0aa9828

Please sign in to comment.