]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/mpc.c
pcmdec: remove dependency from rawdec
[ffmpeg] / libavformat / mpc.c
index 8faa0f7320d161e253f1c22d2b1204a2884f74e7..fbf8e92fd905ae2e8bd700c60b0dfa13a6fadfff 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "libavcodec/get_bits.h"
 #include "avformat.h"
+#include "internal.h"
 #include "apetag.h"
 #include "id3v1.h"
 #include "libavutil/dict.h"
@@ -51,24 +52,24 @@ static int mpc_probe(AVProbeData *p)
     return 0;
 }
 
-static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap)
+static int mpc_read_header(AVFormatContext *s)
 {
     MPCContext *c = s->priv_data;
     AVStream *st;
 
     if(avio_rl24(s->pb) != MKTAG('M', 'P', '+', 0)){
         av_log(s, AV_LOG_ERROR, "Not a Musepack file\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
     c->ver = avio_r8(s->pb);
     if(c->ver != 0x07 && c->ver != 0x17){
         av_log(s, AV_LOG_ERROR, "Can demux Musepack SV7, got version %02X\n", c->ver);
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
     c->fcount = avio_rl32(s->pb);
     if((int64_t)c->fcount * sizeof(MPCFrame) >= UINT_MAX){
         av_log(s, AV_LOG_ERROR, "Too many frames, seeking is not possible\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
     if(c->fcount){
         c->frames = av_malloc(c->fcount * sizeof(MPCFrame));
@@ -84,11 +85,11 @@ static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap)
     c->curbits = 8;
     c->frames_noted = 0;
 
-    st = av_new_stream(s, 0);
+    st = avformat_new_stream(s, NULL);
     if (!st)
         return AVERROR(ENOMEM);
     st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
-    st->codec->codec_id = CODEC_ID_MUSEPACK7;
+    st->codec->codec_id = AV_CODEC_ID_MUSEPACK7;
     st->codec->channels = 2;
     st->codec->bits_per_coded_sample = 16;
 
@@ -96,7 +97,7 @@ static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap)
     st->codec->extradata = av_mallocz(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE);
     avio_read(s->pb, st->codec->extradata, 16);
     st->codec->sample_rate = mpc_rate[st->codec->extradata[2] & 3];
-    av_set_pts_info(st, 32, MPC_FRAMESIZE, st->codec->sample_rate);
+    avpriv_set_pts_info(st, 32, MPC_FRAMESIZE, st->codec->sample_rate);
     /* scan for seekpoints */
     st->start_time = 0;
     st->duration = c->fcount;
@@ -117,10 +118,11 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     MPCContext *c = s->priv_data;
     int ret, size, size2, curbits, cur = c->curframe;
-    int64_t tmp, pos;
+    unsigned tmp;
+    int64_t pos;
 
     if (c->curframe >= c->fcount && c->fcount)
-        return -1;
+        return AVERROR_EOF;
 
     if(c->curframe != c->lastframe + 1){
         avio_seek(s->pb, c->frames[c->curframe].pos, SEEK_SET);
@@ -134,8 +136,7 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt)
     if(curbits <= 12){
         size2 = (tmp >> (12 - curbits)) & 0xFFFFF;
     }else{
-        tmp = (tmp << 32) | avio_rl32(s->pb);
-        size2 = (tmp >> (44 - curbits)) & 0xFFFFF;
+        size2 = (tmp << (curbits - 12) | avio_rl32(s->pb) >> (44 - curbits)) & 0xFFFFF;
     }
     curbits += 20;
     avio_seek(s->pb, pos, SEEK_SET);
@@ -150,8 +151,8 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt)
     }
     c->curbits = (curbits + size2) & 0x1F;
 
-    if (av_new_packet(pkt, size) < 0)
-        return AVERROR(EIO);
+    if ((ret = av_new_packet(pkt, size)) < 0)
+        return ret;
 
     pkt->data[0] = curbits;
     pkt->data[1] = (c->curframe > c->fcount) && c->fcount;
@@ -165,7 +166,7 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt)
         avio_seek(s->pb, -4, SEEK_CUR);
     if(ret < size){
         av_free_packet(pkt);
-        return AVERROR(EIO);
+        return ret < 0 ? ret : AVERROR(EIO);
     }
     pkt->size = ret + 4;
 
@@ -213,7 +214,7 @@ static int mpc_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
         ret = av_read_frame(s, pkt);
         if (ret < 0){
             c->curframe = lastframe;
-            return -1;
+            return ret;
         }
         av_free_packet(pkt);
     }
@@ -230,5 +231,5 @@ AVInputFormat ff_mpc_demuxer = {
     .read_packet    = mpc_read_packet,
     .read_close     = mpc_read_close,
     .read_seek      = mpc_read_seek,
-    .extensions = "mpc",
+    .extensions     = "mpc",
 };