]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/mpc.c
mpc8: Fix return value on EOF
[ffmpeg] / libavformat / mpc.c
index 73217a31ea604d97ff5c59a5ae6e1e8fc787d8a2..8faa0f7320d161e253f1c22d2b1204a2884f74e7 100644 (file)
@@ -2,20 +2,20 @@
  * Musepack demuxer
  * Copyright (c) 2006 Konstantin Shishkov
  *
- * 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
  */
 
@@ -23,6 +23,7 @@
 #include "avformat.h"
 #include "apetag.h"
 #include "id3v1.h"
+#include "libavutil/dict.h"
 
 #define MPC_FRAMESIZE  1152
 #define DELAY_FRAMES   32
@@ -69,7 +70,15 @@ static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap)
         av_log(s, AV_LOG_ERROR, "Too many frames, seeking is not possible\n");
         return -1;
     }
-    c->frames = av_malloc(c->fcount * sizeof(MPCFrame));
+    if(c->fcount){
+        c->frames = av_malloc(c->fcount * sizeof(MPCFrame));
+        if(!c->frames){
+            av_log(s, AV_LOG_ERROR, "Cannot allocate seektable\n");
+            return AVERROR(ENOMEM);
+        }
+    }else{
+        av_log(s, AV_LOG_WARNING, "Container reports no frames\n");
+    }
     c->curframe = 0;
     c->lastframe = -1;
     c->curbits = 8;
@@ -93,12 +102,12 @@ static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap)
     st->duration = c->fcount;
 
     /* try to read APE tags */
-    if (!url_is_streamed(s->pb)) {
-        int64_t pos = url_ftell(s->pb);
+    if (s->pb->seekable) {
+        int64_t pos = avio_tell(s->pb);
         ff_ape_parse_tag(s);
-        if (!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX))
+        if (!av_dict_get(s->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX))
             ff_id3v1_read(s);
-        url_fseek(s->pb, pos, SEEK_SET);
+        avio_seek(s->pb, pos, SEEK_SET);
     }
 
     return 0;
@@ -110,17 +119,17 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt)
     int ret, size, size2, curbits, cur = c->curframe;
     int64_t tmp, pos;
 
-    if (c->curframe >= c->fcount)
+    if (c->curframe >= c->fcount && c->fcount)
         return -1;
 
     if(c->curframe != c->lastframe + 1){
-        url_fseek(s->pb, c->frames[c->curframe].pos, SEEK_SET);
+        avio_seek(s->pb, c->frames[c->curframe].pos, SEEK_SET);
         c->curbits = c->frames[c->curframe].skip;
     }
     c->lastframe = c->curframe;
     c->curframe++;
     curbits = c->curbits;
-    pos = url_ftell(s->pb);
+    pos = avio_tell(s->pb);
     tmp = avio_rl32(s->pb);
     if(curbits <= 12){
         size2 = (tmp >> (12 - curbits)) & 0xFFFFF;
@@ -129,10 +138,10 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt)
         size2 = (tmp >> (44 - curbits)) & 0xFFFFF;
     }
     curbits += 20;
-    url_fseek(s->pb, pos, SEEK_SET);
+    avio_seek(s->pb, pos, SEEK_SET);
 
     size = ((size2 + curbits + 31) & ~31) >> 3;
-    if(cur == c->frames_noted){
+    if(cur == c->frames_noted && c->fcount){
         c->frames[cur].pos = pos;
         c->frames[cur].size = size;
         c->frames[cur].skip = curbits - 20;
@@ -145,7 +154,7 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt)
         return AVERROR(EIO);
 
     pkt->data[0] = curbits;
-    pkt->data[1] = (c->curframe > c->fcount);
+    pkt->data[1] = (c->curframe > c->fcount) && c->fcount;
     pkt->data[2] = 0;
     pkt->data[3] = 0;
 
@@ -153,7 +162,7 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt)
     pkt->pts = cur;
     ret = avio_read(s->pb, pkt->data + 4, size);
     if(c->curbits)
-        url_fseek(s->pb, -4, SEEK_CUR);
+        avio_seek(s->pb, -4, SEEK_CUR);
     if(ret < size){
         av_free_packet(pkt);
         return AVERROR(EIO);
@@ -213,13 +222,13 @@ static int mpc_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
 
 
 AVInputFormat ff_mpc_demuxer = {
-    "mpc",
-    NULL_IF_CONFIG_SMALL("Musepack"),
-    sizeof(MPCContext),
-    mpc_probe,
-    mpc_read_header,
-    mpc_read_packet,
-    mpc_read_close,
-    mpc_read_seek,
+    .name           = "mpc",
+    .long_name      = NULL_IF_CONFIG_SMALL("Musepack"),
+    .priv_data_size = sizeof(MPCContext),
+    .read_probe     = mpc_probe,
+    .read_header    = mpc_read_header,
+    .read_packet    = mpc_read_packet,
+    .read_close     = mpc_read_close,
+    .read_seek      = mpc_read_seek,
     .extensions = "mpc",
 };