Revision e07b882b

View differences:

libavformat/avformat.h
452 452
    int probe_packets;
453 453

  
454 454
    /**
455
     * Number of packets in packet_buffer for this stream when muxing.
455
     * last packet in packet_buffer for this stream when muxing.
456 456
     * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav*
457 457
     */
458
    int num_in_packet_buffer;
458
    struct AVPacketList *last_in_packet_buffer;
459 459
} AVStream;
460 460

  
461 461
#define AV_PROGRAM_RUNNING 1
libavformat/mxfenc.c
1836 1836
            // purge packet queue
1837 1837
            while (pktl) {
1838 1838
                AVPacketList *next = pktl->next;
1839

  
1840
                if(s->streams[pktl->pkt.stream_index]->last_in_packet_buffer == pktl)
1841
                    s->streams[pktl->pkt.stream_index]->last_in_packet_buffer= NULL;
1839 1842
                av_free_packet(&pktl->pkt);
1840 1843
                av_freep(&pktl);
1841 1844
                pktl = next;
......
1844 1847
                last->next = NULL;
1845 1848
            else {
1846 1849
                s->packet_buffer = NULL;
1850
                s->packet_buffer_end= NULL;
1847 1851
                goto out;
1848 1852
            }
1849 1853
            pktl = s->packet_buffer;
......
1852 1856
        *out = pktl->pkt;
1853 1857
        //av_log(s, AV_LOG_DEBUG, "out st:%d dts:%lld\n", (*out).stream_index, (*out).dts);
1854 1858
        s->packet_buffer = pktl->next;
1859
        if(s->streams[pktl->pkt.stream_index]->last_in_packet_buffer == pktl)
1860
            s->streams[pktl->pkt.stream_index]->last_in_packet_buffer= NULL;
1861
        if(!s->packet_buffer)
1862
            s->packet_buffer_end= NULL;
1855 1863
        av_freep(&pktl);
1856 1864
        return 1;
1857 1865
    } else {
libavformat/oggenc.c
261 261
            OGGStreamContext *ogg = s->streams[out->stream_index]->priv_data;
262 262
            ogg->eos = 1;
263 263
        }
264
        if(!s->packet_buffer)
265
            s->packet_buffer_end= NULL;
266

  
267
        if(s->streams[out->stream_index]->last_in_packet_buffer == pktl)
268
            s->streams[out->stream_index]->last_in_packet_buffer= NULL;
269

  
264 270
        av_freep(&pktl);
265 271
        return 1;
266 272
    } else {
libavformat/utils.c
2657 2657
    pkt->destruct= NULL;             // do not free original but only the copy
2658 2658
    av_dup_packet(&this_pktl->pkt);  // duplicate the packet if it uses non-alloced memory
2659 2659

  
2660
    if(!s->packet_buffer_end || compare(s, &s->packet_buffer_end->pkt, pkt)){
2660
    if(s->streams[pkt->stream_index]->last_in_packet_buffer){
2661
        next_point = &(s->streams[pkt->stream_index]->last_in_packet_buffer->next);
2662
    }else
2661 2663
        next_point = &s->packet_buffer;
2662
        while(*next_point){
2663
            if(compare(s, &(*next_point)->pkt, pkt))
2664
                break;
2664

  
2665
    if(*next_point){
2666
        if(compare(s, &s->packet_buffer_end->pkt, pkt)){
2667
            while(!compare(s, &(*next_point)->pkt, pkt)){
2665 2668
            next_point= &(*next_point)->next;
2666 2669
        }
2670
            goto next_non_null;
2667 2671
    }else{
2668 2672
        next_point = &(s->packet_buffer_end->next);
2669
        assert(!*next_point);
2673
        }
2670 2674
    }
2671
    this_pktl->next= *next_point;
2675
        assert(!*next_point);
2672 2676

  
2673
    if(!*next_point)
2674 2677
        s->packet_buffer_end= this_pktl;
2678
next_non_null:
2675 2679

  
2676
    *next_point= this_pktl;
2680
    this_pktl->next= *next_point;
2677 2681

  
2678
    s->streams[pkt->stream_index]->num_in_packet_buffer++;
2682
    s->streams[pkt->stream_index]->last_in_packet_buffer=
2683
    *next_point= this_pktl;
2679 2684
}
2680 2685

  
2681 2686
int ff_interleave_compare_dts(AVFormatContext *s, AVPacket *next, AVPacket *pkt)
......
2701 2706
    }
2702 2707

  
2703 2708
    for(i=0; i < s->nb_streams; i++)
2704
        stream_count+= !!s->streams[i]->num_in_packet_buffer;
2709
        stream_count+= !!s->streams[i]->last_in_packet_buffer;
2705 2710

  
2706 2711
    if(stream_count && (s->nb_streams == stream_count || flush)){
2707 2712
        pktl= s->packet_buffer;
......
2711 2716
        if(!s->packet_buffer)
2712 2717
            s->packet_buffer_end= NULL;
2713 2718

  
2714
        s->streams[out->stream_index]->num_in_packet_buffer--;
2719
        if(s->streams[out->stream_index]->last_in_packet_buffer == pktl)
2720
            s->streams[out->stream_index]->last_in_packet_buffer= NULL;
2715 2721
        av_freep(&pktl);
2716 2722
        return 1;
2717 2723
    }else{

Also available in: Unified diff