diff options
Diffstat (limited to 'demux/packet.c')
-rw-r--r-- | demux/packet.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/demux/packet.c b/demux/packet.c index 60c3e6aba0..32d799f9ce 100644 --- a/demux/packet.c +++ b/demux/packet.c @@ -31,10 +31,25 @@ #include "packet.h" +// Free any refcounted data dp holds (but don't free dp itself). This does not +// care about pointers that are _not_ refcounted (like demux_packet.codec). +// Normally, a user should use talloc_free(dp). This function is only for +// annoyingly specific obscure use cases. +void demux_packet_unref_contents(struct demux_packet *dp) +{ + if (dp->avpacket) { + av_packet_unref(dp->avpacket); + assert(!dp->is_cached); + dp->avpacket = NULL; + dp->buffer = NULL; + dp->len = 0; + } +} + static void packet_destroy(void *ptr) { struct demux_packet *dp = ptr; - av_packet_unref(dp->avpacket); + demux_packet_unref_contents(dp); } // This actually preserves only data and side data, not PTS/DTS/pos/etc. @@ -161,8 +176,9 @@ struct demux_packet *demux_copy_packet(struct demux_packet *dp) size_t demux_packet_estimate_total_size(struct demux_packet *dp) { size_t size = ROUND_ALLOC(sizeof(struct demux_packet)); - size += ROUND_ALLOC(dp->len); if (dp->avpacket) { + assert(!dp->is_cached); + size += ROUND_ALLOC(dp->len); size += ROUND_ALLOC(sizeof(AVPacket)); size += ROUND_ALLOC(sizeof(AVBufferRef)); size += 64; // upper bound estimate on sizeof(AVBuffer) |