On Fri, 20 Jun 2008 10:02:36 -0400, Paul Kelly <[EMAIL PROTECTED]> wrote:
> On Thu, 19 Jun 2008, Stas Oskin wrote: >> >> From what I found av_dup_packet() takes the memory shared by 2 >> packets, and make it non/shared via mem_cpy(). Is it correct? ... > packet did. Any change to this location in memory will affect both > packets. If you want to reuse the old AVPacket but keep a copy of the new > packet, you must create a duplicate copy of the packet buffer using > av_dup_packet(). I would go one step further, and say that you cannot reliably hold on to the old packet after the next call to av_read_frame. Sometimes the packet you are given is dynamically allocated, and so you must free it or get a memory leak. In this case yes, you can hold on to it. But other times, the demuxer *could* hand you pointers to its own data buffers, which it will change after further calls to av_read_frame. In this case, the packet doesn't need freed. 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. Note that this same concept applies to video frames returned by avcodec_decode_video. -- Michael Conrad IntelliTree Solutions llc. 513-552-6362 [EMAIL PROTECTED] _______________________________________________ libav-user mailing list [email protected] https://lists.mplayerhq.hu/mailman/listinfo/libav-user
