summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-05-03 23:24:09 +0200
committerwm4 <wm4@nowhere>2013-05-05 18:44:24 +0200
commit5165e19a238cce0f7170ae80707ede814a630d66 (patch)
tree3626ab8b7a410d8c4b2fd7ce0725db1eddc73ffa /demux
parente4837b2d423e728bc294fb77c0d01b957c78848f (diff)
downloadmpv-5165e19a238cce0f7170ae80707ede814a630d66.tar.bz2
mpv-5165e19a238cce0f7170ae80707ede814a630d66.tar.xz
demux: use talloc for packets
No functional change.
Diffstat (limited to 'demux')
-rw-r--r--demux/demux.c34
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)