On Sat, 21 Jun 2008 15:13:07 -0400, Stas Oskin <[EMAIL PROTECTED]>
wrote:
> Hi.
>
>> So, the only way to be sure that things work for all kinds of
>> demuxer is to pull one packet from the stream, and then either
>> dup or free it before getting the next packet. av_dup_packet
>> and av_free_packet are each smart enough to do the right thing
>> for the situation.
>
> av_free_packet seems to simply free the data - how it's useful in this
> case?
>
Well, I was illustratng the point that the name of the function is related
to how you are supposed to use it, rather than related to what the
function actually does.
From avformat.h:
static inline void av_free_packet(AVPacket *pkt)
{
if (pkt && pkt->destruct) {
pkt->destruct(pkt);
}
}
So you see, whatever function created the packet will choose an
appropriate way to clean up when the packet is no longer used. The packet
points to this function, and av_free_packet calls it. (However, there is
still no guarantee that the packet will be usable after the next call to
av_read_frame. The packet is not guaranteed to be an object, just your
view into some data managed by the demuxer.)
If the packet data was dynamically allocated, then av_free_packet will
probably call 'free()' on its data. If the packet refers to data used by
the demuxer, then av_free_packet might just set some flags in the
demuxer. If nothing needs done, av_free_packet will do nothing at all.
av_dup_packet is a function that guarantees that the packet will now
contain dynamically allocated data which will be usable for as long as you
want. After a call to av_dup_packet, the packet behaves like a proper
object.
--
Michael Conrad
IntelliTree Solutions llc.
513-552-6362
[EMAIL PROTECTED]
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user