]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/commitdiff
Implement url_open_protocol(), which is basiclly the former url_open() but which...
authorrbultje <rbultje@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Tue, 19 Aug 2008 23:44:23 +0000 (23:44 +0000)
committerrbultje <rbultje@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Tue, 19 Aug 2008 23:44:23 +0000 (23:44 +0000)
git-svn-id: file:///var/local/repositories/ffmpeg/trunk@14857 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b

libavformat/avio.c
libavformat/avio.h

index 743cc88e98a6ad82dc11570c4b76247831daf40f..12788278026eb1f4cfd95f3c05cfccdff6454531 100644 (file)
@@ -59,41 +59,12 @@ int register_protocol(URLProtocol *protocol)
     return 0;
 }
 
-int url_open(URLContext **puc, const char *filename, int flags)
+int url_open_protocol (URLContext **puc, struct URLProtocol *up,
+                       const char *filename, int flags)
 {
     URLContext *uc;
-    URLProtocol *up;
-    const char *p;
-    char proto_str[128], *q;
     int err;
 
-    p = filename;
-    q = proto_str;
-    while (*p != '\0' && *p != ':') {
-        /* protocols can only contain alphabetic chars */
-        if (!isalpha(*p))
-            goto file_proto;
-        if ((q - proto_str) < sizeof(proto_str) - 1)
-            *q++ = *p;
-        p++;
-    }
-    /* if the protocol has length 1, we consider it is a dos drive */
-    if (*p == '\0' || (q - proto_str) <= 1) {
-    file_proto:
-        strcpy(proto_str, "file");
-    } else {
-        *q = '\0';
-    }
-
-    up = first_protocol;
-    while (up != NULL) {
-        if (!strcmp(proto_str, up->name))
-            goto found;
-        up = up->next;
-    }
-    err = AVERROR(ENOENT);
-    goto fail;
- found:
     uc = av_malloc(sizeof(URLContext) + strlen(filename) + 1);
     if (!uc) {
         err = AVERROR(ENOMEM);
@@ -117,7 +88,7 @@ int url_open(URLContext **puc, const char *filename, int flags)
 
     //We must be carefull here as url_seek() could be slow, for example for http
     if(   (flags & (URL_WRONLY | URL_RDWR))
-       || !strcmp(proto_str, "file"))
+       || !strcmp(up->name, "file"))
         if(!uc->is_streamed && url_seek(uc, 0, SEEK_SET) < 0)
             uc->is_streamed= 1;
     *puc = uc;
@@ -127,6 +98,40 @@ int url_open(URLContext **puc, const char *filename, int flags)
     return err;
 }
 
+int url_open(URLContext **puc, const char *filename, int flags)
+{
+    URLProtocol *up;
+    const char *p;
+    char proto_str[128], *q;
+
+    p = filename;
+    q = proto_str;
+    while (*p != '\0' && *p != ':') {
+        /* protocols can only contain alphabetic chars */
+        if (!isalpha(*p))
+            goto file_proto;
+        if ((q - proto_str) < sizeof(proto_str) - 1)
+            *q++ = *p;
+        p++;
+    }
+    /* if the protocol has length 1, we consider it is a dos drive */
+    if (*p == '\0' || (q - proto_str) <= 1) {
+    file_proto:
+        strcpy(proto_str, "file");
+    } else {
+        *q = '\0';
+    }
+
+    up = first_protocol;
+    while (up != NULL) {
+        if (!strcmp(proto_str, up->name))
+            return url_open_protocol (puc, up, filename, flags);
+        up = up->next;
+    }
+    *puc = NULL;
+    return AVERROR(ENOENT);
+}
+
 int url_read(URLContext *h, unsigned char *buf, int size)
 {
     int ret;
index 2d2e26999da27788a266ac306e8f04c421c2f697..8137cb54dc331ae9790fd3cffda6fc61a30dc4f3 100644 (file)
@@ -62,6 +62,8 @@ typedef struct URLPollEntry {
 
 typedef int URLInterruptCB(void);
 
+int url_open_protocol (URLContext **puc, struct URLProtocol *up,
+                       const char *filename, int flags);
 int url_open(URLContext **h, const char *filename, int flags);
 int url_read(URLContext *h, unsigned char *buf, int size);
 int url_write(URLContext *h, unsigned char *buf, int size);