diff options
author | 2013-05-03 23:24:09 +0200 | |
---|---|---|
committer | 2013-05-05 18:44:24 +0200 | |
commit | 5165e19a238cce0f7170ae80707ede814a630d66 (patch) | |
tree | 3626ab8b7a410d8c4b2fd7ce0725db1eddc73ffa | |
parent | e4837b2d423e728bc294fb77c0d01b957c78848f (diff) |
demux: use talloc for packets
No functional change.
-rw-r--r-- | demux/demux.c | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/demux/demux.c b/demux/demux.c index 06b1a35d0f..e16933e729 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -101,6 +101,16 @@ const demuxer_desc_t *const demuxer_list[] = { NULL }; +static int packet_destroy(void *ptr) +{ + struct demux_packet *dp = ptr; + if (dp->avpacket) + talloc_free(dp->avpacket); + else + free(dp->buffer); + return 0; +} + static struct demux_packet *create_packet(size_t len) { if (len > 1000000000) { @@ -108,16 +118,14 @@ static struct demux_packet *create_packet(size_t len) "over 1 GB!\n"); abort(); } - struct demux_packet *dp = malloc(sizeof(struct demux_packet)); - dp->len = len; - dp->next = NULL; - dp->pts = MP_NOPTS_VALUE; - dp->duration = -1; - dp->stream_pts = MP_NOPTS_VALUE; - dp->pos = 0; - dp->keyframe = false; - dp->buffer = NULL; - dp->avpacket = NULL; + struct demux_packet *dp = talloc(NULL, struct demux_packet); + talloc_set_destructor(dp, packet_destroy); + *dp = (struct demux_packet) { + .len = len, + .pts = MP_NOPTS_VALUE, + .duration = -1, + .stream_pts = MP_NOPTS_VALUE, + }; return dp; } @@ -166,11 +174,7 @@ void resize_demux_packet(struct demux_packet *dp, size_t len) void free_demux_packet(struct demux_packet *dp) { - if (dp->avpacket) - talloc_free(dp->avpacket); - else - free(dp->buffer); - free(dp); + talloc_free(dp); } static void free_demuxer_stream(struct demux_stream *ds) |