demux: simplify packet resizing

Actually we don't need to resize packets; we just need to make them
shorter.
This commit is contained in:
wm4 2014-06-13 02:02:30 +02:00
parent ee2e91dce1
commit 7e7ff4b0ea
3 changed files with 5 additions and 15 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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;