# HG changeset patch # User bcoudurier # Date 1233569076 0 # Node ID b889db531b8f68b8bf4bb7b515cd2ddc4d304a1c # Parent 501d1dd1902191aad61fb2fe05b407d7b2b06fa5 fix flush and interleaving by edit units diff -r 501d1dd19021 -r b889db531b8f mxfenc.c --- a/mxfenc.c Mon Feb 02 10:03:38 2009 +0000 +++ b/mxfenc.c Mon Feb 02 10:04:36 2009 +0000 @@ -1296,25 +1296,37 @@ if (stream_count && (s->nb_streams == stream_count || flush)) { pktl = s->packet_buffer; - *out = pktl->pkt; - //av_log(s, AV_LOG_DEBUG, "out st:%d dts:%lld\n", (*out).stream_index, (*out).dts); - s->packet_buffer = pktl->next; - av_freep(&pktl); - - if (flush && stream_count < s->nb_streams) { + if (s->nb_streams != stream_count) { + MXFContext *mxf = s->priv_data; + AVPacketList *first = NULL; + // find first packet in edit unit + while (pktl) { + AVStream *st = s->streams[pktl->pkt.stream_index]; + if (st->index == mxf->edit_unit_start) + break; + else if (!first) + first = pktl; + pktl = pktl->next; + } // purge packet queue - pktl = s->packet_buffer; while (pktl) { AVPacketList *next = pktl->next; av_free_packet(&pktl->pkt); av_freep(&pktl); pktl = next; } - s->packet_buffer = NULL; + if (!first) + goto out; + pktl = first; } + *out = pktl->pkt; + //av_log(s, AV_LOG_DEBUG, "out st:%d dts:%lld\n", (*out).stream_index, (*out).dts); + s->packet_buffer = pktl->next; + av_freep(&pktl); return 1; } else { + out: av_init_packet(out); return 0; }