diff src/ffmpeg/libavformat/utils.c @ 825:3cbdc6e19d7c trunk

[svn] - make this compile again
author nenolod
date Mon, 12 Mar 2007 14:37:31 -0700
parents 07107d476f32
children 68562d99230f
line wrap: on
line diff
--- a/src/ffmpeg/libavformat/utils.c	Mon Mar 12 14:19:59 2007 -0700
+++ b/src/ffmpeg/libavformat/utils.c	Mon Mar 12 14:37:31 2007 -0700
@@ -534,6 +534,99 @@
 
 }
 
+int av_open_input_vfsfile(AVFormatContext **ic_ptr, const char *filename, VFSFile *fd,
+                       AVInputFormat *fmt,
+                       int buf_size,
+                       AVFormatParameters *ap)
+{
+    int err, must_open_file, file_opened, probe_size;
+    AVProbeData probe_data, *pd = &probe_data;
+    ByteIOContext pb1, *pb = &pb1;
+
+    file_opened = 0;
+    pd->filename = "";
+    if (filename)
+        pd->filename = filename;
+    pd->buf = NULL;
+    pd->buf_size = 0;
+
+    if (!fmt) {
+        /* guess format if no file can be opened  */
+        fmt = av_probe_input_format(pd, 0);
+    }
+
+    /* do not open file if the format does not need it. XXX: specific
+       hack needed to handle RTSP/TCP */
+    must_open_file = 1;
+    if (fmt && (fmt->flags & AVFMT_NOFILE)) {
+        must_open_file = 0;
+        pb= NULL; //FIXME this or memset(pb, 0, sizeof(ByteIOContext)); otherwise its uninitalized
+    }
+
+    if (!fmt || must_open_file) {
+        /* if no file needed do not try to open one */
+        if (url_vfdopen(pb, fd) < 0) {
+            err = AVERROR_IO;
+            goto fail;
+        }
+        file_opened = 1;
+        if (buf_size > 0) {
+            url_setbufsize(pb, buf_size);
+        }
+
+        for(probe_size= PROBE_BUF_MIN; probe_size<=PROBE_BUF_MAX && !fmt; probe_size<<=1){
+            /* read probe data */
+            pd->buf= av_realloc(pd->buf, probe_size);
+            pd->buf_size = get_buffer(pb, pd->buf, probe_size);
+            if (url_fseek(pb, 0, SEEK_SET) == (offset_t)-EPIPE) {
+                url_fclose(pb);
+                if (url_fopen(pb, filename, URL_RDONLY) < 0) {
+                    file_opened = 0;
+                    err = AVERROR_IO;
+                    goto fail;
+                }
+            }
+            /* guess file format */
+            fmt = av_probe_input_format(pd, 1);
+        }
+        av_freep(&pd->buf);
+    }
+
+    /* if still no format found, error */
+    if (!fmt) {
+        err = AVERROR_NOFMT;
+        goto fail;
+    }
+
+    /* XXX: suppress this hack for redirectors */
+#ifdef CONFIG_NETWORK
+    if (fmt == &redir_demuxer) {
+        err = redir_open(ic_ptr, pb);
+        url_fclose(pb);
+        return err;
+    }
+#endif
+
+    /* check filename in case of an image number is expected */
+    if (fmt->flags & AVFMT_NEEDNUMBER) {
+        if (!av_filename_number_test(filename)) {
+            err = AVERROR_NUMEXPECTED;
+            goto fail;
+        }
+    }
+    err = av_open_input_stream(ic_ptr, pb, filename, fmt, ap);
+    if (err)
+        goto fail;
+    return 0;
+ fail:
+    av_freep(&pd->buf);
+    if (file_opened)
+        url_fclose(pb);
+    *ic_ptr = NULL;
+    return err;
+
+}
+
 /*******************************************************/
 
 /**