diff --git a/demux/packet.c b/demux/packet.c index 7751f36354..dbea70f567 100644 --- a/demux/packet.c +++ b/demux/packet.c @@ -85,13 +85,13 @@ void demux_packet_unref(struct demux_packet *dp) static struct demux_packet *packet_create(struct demux_packet_pool *pool) { struct demux_packet *dp = pool ? demux_packet_pool_pop(pool) : NULL; - struct AVPacket *avpkt = dp ? dp->avpacket : NULL; if (!dp) { dp = talloc(NULL, struct demux_packet); talloc_set_destructor(dp, packet_destroy); + set_packet_defaults(dp); } - set_packet_defaults(dp); - dp->avpacket = avpkt ? avpkt : av_packet_alloc(); + if (!dp->avpacket) + dp->avpacket = av_packet_alloc(); MP_HANDLE_OOM(dp->avpacket); return dp; } diff --git a/demux/packet_pool.c b/demux/packet_pool.c index 5bfd80bc66..22e5b33eb5 100644 --- a/demux/packet_pool.c +++ b/demux/packet_pool.c @@ -120,11 +120,7 @@ struct demux_packet *demux_packet_pool_pop(struct demux_packet_pool *pool) // a single packet at a time. This avoids the need to clear potentially // hundreds of thousands of packets at once when file playback is stopped, // which would require a significant amount of time to iterate over all packets. - if (dp) { - if (dp->avpacket) - av_packet_unref(dp->avpacket); - ta_free_children(dp); - } + demux_packet_unref(dp); return dp; } diff --git a/demux/packet_pool.h b/demux/packet_pool.h index 9fdccdce75..cedff80b63 100644 --- a/demux/packet_pool.h +++ b/demux/packet_pool.h @@ -82,6 +82,9 @@ void demux_packet_pool_prepend(struct demux_packet_pool *pool, * This function removes and returns the first packet from the pool's * linked list. This function is thread-safe. * + * The packet's contents are cleared of any external references before + * being returned. + * * @param pool Pointer to the demux packet pool. * @return Pointer to the demux packet, or NULL if the pool is empty. */