[FFmpeg-soc] [soc]: r5073 - in concat/libavformat: concatgen.c playlist.c

gkovacs subversion at mplayerhq.hu
Thu Aug 13 12:30:52 CEST 2009


Author: gkovacs
Date: Thu Aug 13 12:30:51 2009
New Revision: 5073

Log:
read packets from packet_buffer to ensure that none are lost after switching streams

Modified:
   concat/libavformat/concatgen.c
   concat/libavformat/playlist.c

Modified: concat/libavformat/concatgen.c
==============================================================================
--- concat/libavformat/concatgen.c	Thu Aug 13 12:24:10 2009	(r5072)
+++ concat/libavformat/concatgen.c	Thu Aug 13 12:30:51 2009	(r5073)
@@ -42,11 +42,16 @@ int ff_concatgen_read_packet(AVFormatCon
     stream_index = 0;
     for (;;) {
         ic = ctx->icl[ctx->pe_curidx];
-        ret = ic->iformat->read_packet(ic, pkt);
-        s->cur_st = ic->cur_st;
+        av_init_packet(pkt);
+        if (s->packet_buffer) {
+            *pkt = s->packet_buffer->pkt;
+            s->packet_buffer = s->packet_buffer->next;
+            ret = 0;
+        } else {
+            ret = ic->iformat->read_packet(ic, pkt);
+        }
         if (ret >= 0) {
             if (pkt) {
-                pkt->stream = ic->streams[pkt->stream_index];
                 stream_index = pkt->stream_index;
                 pkt->index_offset = ff_playlist_streams_offset_from_playidx(ctx, ctx->pe_curidx);
                 pkt->stream_index += pkt->index_offset;
@@ -60,10 +65,10 @@ int ff_concatgen_read_packet(AVFormatCon
             break;
         } else {
             if (!have_switched_streams &&
-                ctx->pe_curidx < ctx->pelist_size - 1 &&
-                ic->cur_st) {
+                ctx->pe_curidx < ctx->pelist_size - 1) {
             // TODO switch from AVERROR_EOF to AVERROR_EOS
             // -32 AVERROR_EOF for avi, -51 for ogg
+
                 av_log(ic, AV_LOG_DEBUG, "Switching stream %d to %d\n", stream_index, ctx->pe_curidx+1);
                 ctx->durations[ctx->pe_curidx] = ic->duration;
                 ctx->pe_curidx = ff_playlist_stream_index_from_time(ctx,

Modified: concat/libavformat/playlist.c
==============================================================================
--- concat/libavformat/playlist.c	Thu Aug 13 12:24:10 2009	(r5072)
+++ concat/libavformat/playlist.c	Thu Aug 13 12:30:51 2009	(r5073)
@@ -55,6 +55,27 @@ void ff_playlist_populate_context(Playli
     ctx->nb_streams_list[pe_curidx] = ctx->icl[pe_curidx]->nb_streams;
 }
 
+static void flush_packet_queue(AVFormatContext *s)
+{
+    AVPacketList *pktl;
+
+    for(;;) {
+        pktl = s->packet_buffer;
+        if (!pktl)
+            break;
+        s->packet_buffer = pktl->next;
+        av_free_packet(&pktl->pkt);
+        av_free(pktl);
+    }
+    while(s->raw_packet_buffer){
+        pktl = s->raw_packet_buffer;
+        s->raw_packet_buffer = pktl->next;
+        av_free_packet(&pktl->pkt);
+        av_free(pktl);
+    }
+    s->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
+}
+
 void ff_playlist_set_streams(AVFormatContext *s)
 {
     int i;
@@ -63,9 +84,10 @@ void ff_playlist_set_streams(AVFormatCon
     PlaylistContext *ctx = s->priv_data;
     ic = ctx->icl[ctx->pe_curidx];
     offset = ff_playlist_streams_offset_from_playidx(ctx, ctx->pe_curidx);
+    ic->iformat->read_header(ic, NULL);
     for (i = 0; i < ic->nb_streams; ++i) {
         s->streams[offset + i] = ic->streams[i];
-//        ic->streams[i]->index += offset;
+        ic->streams[i]->index += offset;
         if (!ic->streams[i]->codec->codec) {
             AVCodec *codec = avcodec_find_decoder(ic->streams[i]->codec->codec_id);
             if (!codec) {
@@ -80,12 +102,9 @@ void ff_playlist_set_streams(AVFormatCon
              }
         }
     }
-    s->nb_streams = ic->nb_streams + offset;
-    s->cur_st = ic->cur_st;
-    if (ic->packet_buffer && ic->packet_buffer->pkt.data && ic->packet_buffer->pkt.stream_index >= offset && ic->packet_buffer->pkt.stream_index < ic->nb_streams + offset)
-        s->packet_buffer = ic->packet_buffer;
-    if (ic->packet_buffer_end && ic->packet_buffer_end->pkt.data && ic->packet_buffer_end->pkt.stream_index >= offset && ic->packet_buffer_end->pkt.stream_index < ic->nb_streams + offset);
-        s->packet_buffer_end = ic->packet_buffer_end;
+    s->nb_streams                       = ic->nb_streams + offset;
+    s->packet_buffer                    = ic->packet_buffer;
+    s->packet_buffer_end                = ic->packet_buffer_end;
 }
 
 PlaylistContext *ff_playlist_get_context(AVFormatContext *ic)


More information about the FFmpeg-soc mailing list