diff src/wma/libffwma/futils.c @ 508:1e5df88b631d trunk

[svn] - newvfs probing
author nenolod
date Mon, 22 Jan 2007 01:00:29 -0800
parents 3da1b8942b8b
children
line wrap: on
line diff
--- a/src/wma/libffwma/futils.c	Sun Jan 21 22:18:40 2007 -0800
+++ b/src/wma/libffwma/futils.c	Mon Jan 22 01:00:29 2007 -0800
@@ -438,6 +438,73 @@
     
 }
 
+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;
+    uint8_t buf[PROBE_BUF_SIZE];
+    AVProbeData probe_data, *pd = &probe_data;
+    ByteIOContext pb1, *pb = &pb1;
+    
+    file_opened = 0;
+    pd->filename = "";
+    if (filename)
+        pd->filename = filename;
+    pd->buf = buf;
+    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;
+    }
+
+    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);
+        }
+        if (!fmt) {
+            /* read probe data */
+            pd->buf_size = get_buffer(pb, buf, PROBE_BUF_SIZE);
+            url_fseek(pb, 0, SEEK_SET);
+        }
+    }
+    
+    /* guess file format */
+    if (!fmt) {
+        fmt = av_probe_input_format(pd, 1);
+    }
+
+    /* if still no format found, error */
+    if (!fmt) {
+        err = AVERROR_NOFMT;
+        goto fail;
+    }
+        
+    err = av_open_input_stream(ic_ptr, pb, filename, fmt, ap);
+    if (err)
+        goto fail;
+    return 0;
+ fail:
+    *ic_ptr = NULL;
+    return err;
+    
+}
+
 /*******************************************************/
 
 /**