]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/concat.c
Check mp3 header before calling avpriv_mpegaudio_decode_header().
[ffmpeg] / libavformat / concat.c
index 3a19d0a2ff793791deb8df5424fd5d2161cd3fb6..416bbf5fc3bef1fcc36846f7c7fcc4194597836f 100644 (file)
@@ -4,26 +4,27 @@
  * Copyright (c) 2007 Wolfram Gloger
  * Copyright (c) 2010 Michele OrrĂ¹
  *
- * This file is part of FFmpeg.
+ * This file is part of Libav.
  *
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include "avformat.h"
 #include "libavutil/avstring.h"
 #include "libavutil/mem.h"
+#include "url.h"
 
 #define AV_CAT_SEPARATOR "|"
 
@@ -46,31 +47,25 @@ static av_cold int concat_close(URLContext *h)
     struct concat_nodes *nodes = data->nodes;
 
     for (i = 0; i != data->length; i++)
-        err |= url_close(nodes[i].uc);
+        err |= ffurl_close(nodes[i].uc);
 
     av_freep(&data->nodes);
-    av_freep(&h->priv_data);
 
     return err < 0 ? -1 : 0;
 }
 
 static av_cold int concat_open(URLContext *h, const char *uri, int flags)
 {
-    char *node_uri = NULL, *tmp_uri;
+    char *node_uri = NULL;
     int err = 0;
     int64_t size;
     size_t  len, i;
     URLContext *uc;
-    struct concat_data  *data;
+    struct concat_data  *data = h->priv_data;
     struct concat_nodes *nodes;
 
     av_strstart(uri, "concat:", &uri);
 
-    /* creating data */
-    if (!(data = av_mallocz(sizeof(*data))))
-        return AVERROR(ENOMEM);
-    h->priv_data = data;
-
     for (i = 0, len = 1; uri[i]; i++)
         if (uri[i] == *AV_CAT_SEPARATOR)
             /* integer overflow */
@@ -79,8 +74,7 @@ static av_cold int concat_open(URLContext *h, const char *uri, int flags)
                 return AVERROR(ENAMETOOLONG);
             }
 
-    if (!(nodes = av_malloc(sizeof(*nodes) * len))) {
-        av_freep(&h->priv_data);
+    if (!(nodes = av_realloc(NULL, sizeof(*nodes) * len))) {
         return AVERROR(ENOMEM);
     } else
         data->nodes = nodes;
@@ -91,21 +85,19 @@ static av_cold int concat_open(URLContext *h, const char *uri, int flags)
     for (i = 0; *uri; i++) {
         /* parsing uri */
         len = strcspn(uri, AV_CAT_SEPARATOR);
-        if (!(tmp_uri = av_realloc(node_uri, len+1))) {
-            err = AVERROR(ENOMEM);
+        if ((err = av_reallocp(&node_uri, len + 1)) < 0)
             break;
-        } else
-            node_uri = tmp_uri;
         av_strlcpy(node_uri, uri, len+1);
         uri += len + strspn(uri+len, AV_CAT_SEPARATOR);
 
         /* creating URLContext */
-        if ((err = url_open(&uc, node_uri, flags)) < 0)
+        if ((err = ffurl_open(&uc, node_uri, flags,
+                              &h->interrupt_callback, NULL)) < 0)
             break;
 
         /* creating size */
-        if ((size = url_filesize(uc)) < 0) {
-            url_close(uc);
+        if ((size = ffurl_size(uc)) < 0) {
+            ffurl_close(uc);
             err = AVERROR(ENOSYS);
             break;
         }
@@ -119,10 +111,9 @@ static av_cold int concat_open(URLContext *h, const char *uri, int flags)
 
     if (err < 0)
         concat_close(h);
-    else if (!(nodes = av_realloc(nodes, data->length * sizeof(*nodes)))) {
+    else if ((err = av_reallocp(&nodes, data->length * sizeof(*nodes))) < 0)
         concat_close(h);
-        err = AVERROR(ENOMEM);
-    } else
+    else
         data->nodes = nodes;
     return err;
 }
@@ -135,12 +126,12 @@ static int concat_read(URLContext *h, unsigned char *buf, int size)
     size_t i = data->current;
 
     while (size > 0) {
-        result = url_read(nodes[i].uc, buf, size);
+        result = ffurl_read(nodes[i].uc, buf, size);
         if (result < 0)
             return total ? total : result;
         if (!result)
             if (i + 1 == data->length ||
-                url_seek(nodes[++i].uc, 0, SEEK_SET) < 0)
+                ffurl_seek(nodes[++i].uc, 0, SEEK_SET) < 0)
                 break;
         total += result;
         buf   += result;
@@ -168,7 +159,7 @@ static int64_t concat_seek(URLContext *h, int64_t pos, int whence)
         /* get the absolute position */
         for (i = 0; i != data->current; i++)
             pos += nodes[i].size;
-        pos += url_seek(nodes[i].uc, 0, SEEK_CUR);
+        pos += ffurl_seek(nodes[i].uc, 0, SEEK_CUR);
         whence = SEEK_SET;
         /* fall through with the absolute position */
     case SEEK_SET:
@@ -179,7 +170,7 @@ static int64_t concat_seek(URLContext *h, int64_t pos, int whence)
         return AVERROR(EINVAL);
     }
 
-    result = url_seek(nodes[i].uc, pos, whence);
+    result = ffurl_seek(nodes[i].uc, pos, whence);
     if (result >= 0) {
         data->current = i;
         while (i)
@@ -188,11 +179,11 @@ static int64_t concat_seek(URLContext *h, int64_t pos, int whence)
     return result;
 }
 
-URLProtocol concat_protocol = {
-    "concat",
-    concat_open,
-    concat_read,
-    NULL,
-    concat_seek,
-    concat_close,
+URLProtocol ff_concat_protocol = {
+    .name           = "concat",
+    .url_open       = concat_open,
+    .url_read       = concat_read,
+    .url_seek       = concat_seek,
+    .url_close      = concat_close,
+    .priv_data_size = sizeof(struct concat_data),
 };