[FFmpeg-devel] [RFC] possible API for opening external demuxer references

Reimar Döffinger Reimar.Doeffinger
Wed Feb 27 14:38:08 CET 2008


Hello,
currently just a flag probably is good enough, but in case someone is
interested in taking things further (maybe even as a way to implement
general playlist support in lavf, including rules like "internet
playlists can only reference internet files and vice versa"?) here is
a first idea of a possible API.
Probably it makes little sense without actually implementing things to
actually see how suitable it is, but since I already got that far...

Greetings,
Reimar D?ffinger
-------------- next part --------------
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index ad186e4..8f0cfa8 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -499,6 +499,12 @@ typedef struct AVFormatContext {
      * demuxing: set by user
      */
     unsigned int max_index_size;
+
+    //! Callback used to open a substream referenced by a container
+    int (*open_stream)(struct AVFormatContext *, ByteIOContext **s,
+                       const uint8_t *resource, int resource_length, int flags);
+    //! Custom user data for use by e.g. open_stream callback
+    void *user_data;
 } AVFormatContext;
 
 typedef struct AVPacketList {
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 0b3c0a4..ba28f39 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1534,11 +1534,15 @@ static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap)
         sc->ffindex = i;
         mov_build_index(mov, st);
 
+        sc->pb = NULL;
         if (sc->dref_id-1 < sc->drefs_count && sc->drefs[sc->dref_id-1].path) {
-            if (url_fopen(&sc->pb, sc->drefs[sc->dref_id-1].path, URL_RDONLY) < 0)
+            if (s->open_stream &&
+                s->open_stream(s, &sc->pb, sc->drefs[sc->dref_id-1].path,
+                            strlen(sc->drefs[sc->dref_id-1].path), URL_RDONLY) < 0)
                 av_log(s, AV_LOG_ERROR, "stream %d, error opening external essence: %s\n",
                        st->index, strerror(errno));
-        } else
+        }
+        if (!sc->pb)
             sc->pb = s->pb;
 
         switch (st->codec->codec_id) {



More information about the ffmpeg-devel mailing list