diff --git a/demux/demux.c b/demux/demux.c index b9236832ce..acdee69d4b 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -167,21 +167,11 @@ struct demux_packet *new_demux_packet_from(void *data, size_t len) return dp; } -void resize_demux_packet(struct demux_packet *dp, size_t len) +void demux_packet_shorten(struct demux_packet *dp, size_t len) { - if (len > 1000000000) { - fprintf(stderr, "Attempt to realloc demux packet over 1 GB!\n"); - abort(); - } - assert(dp->allocation); - dp->buffer = realloc(dp->buffer, len + FF_INPUT_BUFFER_PADDING_SIZE); - if (!dp->buffer) { - fprintf(stderr, "Memory allocation failure!\n"); - abort(); - } - memset(dp->buffer + len, 0, FF_INPUT_BUFFER_PADDING_SIZE); + assert(len <= dp->len); dp->len = len; - dp->allocation = dp->buffer; + memset(dp->buffer + dp->len, 0, FF_INPUT_BUFFER_PADDING_SIZE); } void free_demux_packet(struct demux_packet *dp) diff --git a/demux/demux.h b/demux/demux.h index d477bb45a9..222d3b8624 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -223,7 +223,7 @@ struct demux_packet *new_demux_packet(size_t len); // data must already have suitable padding struct demux_packet *new_demux_packet_fromdata(void *data, size_t len); struct demux_packet *new_demux_packet_from(void *data, size_t len); -void resize_demux_packet(struct demux_packet *dp, size_t len); +void demux_packet_shorten(struct demux_packet *dp, size_t len); void free_demux_packet(struct demux_packet *dp); struct demux_packet *demux_copy_packet(struct demux_packet *dp); diff --git a/demux/demux_raw.c b/demux/demux_raw.c index ad0c174c11..888b7ecfa0 100644 --- a/demux/demux_raw.c +++ b/demux/demux_raw.c @@ -231,7 +231,7 @@ static int raw_fill_buffer(demuxer_t *demuxer) dp->pts = (dp->pos / p->frame_size) / p->frame_rate; int len = stream_read(demuxer->stream, dp->buffer, dp->len); - resize_demux_packet(dp, len); + demux_packet_shorten(dp, len); demuxer_add_packet(demuxer, demuxer->streams[0], dp); return 1;