Revision 012dc2c4 libavformat/oggenc.c

View differences:

libavformat/oggenc.c
36 36
    int64_t last_kf_pts;
37 37
    int vrev;
38 38
    int eos;
39
    unsigned packet_count; ///< number of packet buffered
39 40
} OGGStreamContext;
40 41

  
41 42
static void ogg_update_checksum(AVFormatContext *s, int64_t crc_offset)
......
286 287

  
287 288
static int ogg_interleave_per_granule(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush)
288 289
{
289
    AVPacketList *pktl;
290
    int stream_count = 0;
291
    int streams[MAX_STREAMS] = {0};
290
    OGGStreamContext *ogg;
291
    int i, stream_count = 0;
292 292
    int interleaved = 0;
293 293

  
294 294
    if (pkt) {
295 295
        ff_interleave_add_packet(s, pkt, ogg_compare_granule);
296
        ogg = s->streams[pkt->stream_index]->priv_data;
297
        ogg->packet_count++;
296 298
    }
297 299

  
298
    pktl = s->packet_buffer;
299
    while (pktl) {
300
        if (streams[pktl->pkt.stream_index] == 0)
301
            stream_count++;
302
        streams[pktl->pkt.stream_index]++;
303
        // need to buffer at least one packet to set eos flag
304
        if (streams[pktl->pkt.stream_index] == 2)
305
            interleaved++;
306
        pktl = pktl->next;
300
    for (i = 0; i < s->nb_streams; i++) {
301
        ogg = s->streams[i]->priv_data;
302
        stream_count += !!ogg->packet_count;
303
        interleaved += ogg->packet_count > 1;
307 304
    }
308 305

  
309 306
    if ((s->nb_streams == stream_count && interleaved == stream_count) ||
310 307
        (flush && stream_count)) {
311
        pktl= s->packet_buffer;
308
        AVPacketList *pktl= s->packet_buffer;
312 309
        *out= pktl->pkt;
313 310
        s->packet_buffer = pktl->next;
314
        if (flush && streams[out->stream_index] == 1) {
315
            OGGStreamContext *ogg = s->streams[out->stream_index]->priv_data;
311

  
312
        ogg = s->streams[out->stream_index]->priv_data;
313
        if (flush && ogg->packet_count == 1)
316 314
            ogg->eos = 1;
317
        }
315
        ogg->packet_count--;
316

  
318 317
        if(!s->packet_buffer)
319 318
            s->packet_buffer_end= NULL;
320 319

  

Also available in: Unified diff