[FFmpeg-devel] [PATCH] make stream-switching work with MOV demuxer

Reimar Döffinger Reimar.Doeffinger
Wed Jun 24 10:32:51 CEST 2009


On Wed, Jun 24, 2009 at 12:50:20AM -0700, Baptiste Coudurier wrote:
> Reimar D?ffinger wrote:
> > On Tue, Jun 23, 2009 at 01:06:58PM -0700, Baptiste Coudurier wrote:
> >> The other patch looks ok, and it is not uglier IMHO, it will allow sc =
> >> msc removal since sc == st->priv_data, and sc->ffindex will no longer be
> >> needed.
> > 
> > Ok, let's get that part out of the way, see attached patch.
> > Personally I'd even suggest making a
> > AVIndexEntry *find_next_sample(AVFormatContext *s, AVStream **st);
> > or similar that contains the whole for loop, making mov_read_packet
> > a bit more self-documenting.
> 
> Yes good idea and patch ok.

Not sure if the idea is that good, but here is a patch for that extra
function, too.
Names, as always, are of course open for improvements.
-------------- next part --------------
Index: libavformat/mov.c
===================================================================
--- libavformat/mov.c	(revision 19261)
+++ libavformat/mov.c	(working copy)
@@ -2055,15 +2055,11 @@
     return 0;
 }
 
-static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
+static AVIndexEntry *find_next_sample(AVFormatContext *s, AVStream **st)
 {
-    MOVContext *mov = s->priv_data;
-    MOVStreamContext *sc = 0;
-    AVIndexEntry *sample = 0;
-    AVStream *st = NULL;
+    AVIndexEntry *sample = NULL;
     int64_t best_dts = INT64_MAX;
-    int i, ret;
- retry:
+    int i;
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *avst = s->streams[i];
         MOVStreamContext *msc = avst->priv_data;
@@ -2078,10 +2074,22 @@
                   (FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts)))))) {
                 sample = current_sample;
                 best_dts = dts;
-                st = avst;
+                *st = avst;
             }
         }
     }
+    return sample;
+}
+
+static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    MOVContext *mov = s->priv_data;
+    MOVStreamContext *sc;
+    AVIndexEntry *sample;
+    AVStream *st = NULL;
+    int ret;
+ retry:
+    sample = find_next_sample(s, &st);
     if (!sample) {
         mov->found_mdat = 0;
         if (!url_is_streamed(s->pb) ||



More information about the ffmpeg-devel mailing list