]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/mpc.c
avformat: Constify all muxer/demuxers
[ffmpeg] / libavformat / mpc.c
index af333746e3a96c9714d8c8b8850597c2e87474cb..9eaf7de0bc885dd49275f31094b3b2d06cd92455 100644 (file)
@@ -45,7 +45,7 @@ typedef struct MPCContext {
     int frames_noted;
 } MPCContext;
 
-static int mpc_probe(AVProbeData *p)
+static int mpc_probe(const AVProbeData *p)
 {
     const uint8_t *d = p->buf;
     if (d[0] == 'M' && d[1] == 'P' && d[2] == '+' && (d[3] == 0x17 || d[3] == 0x7))
@@ -57,6 +57,7 @@ static int mpc_read_header(AVFormatContext *s)
 {
     MPCContext *c = s->priv_data;
     AVStream *st;
+    int ret;
 
     if(avio_rl24(s->pb) != MKTAG('M', 'P', '+', 0)){
         av_log(s, AV_LOG_ERROR, "Not a Musepack file\n");
@@ -72,15 +73,6 @@ static int mpc_read_header(AVFormatContext *s)
         av_log(s, AV_LOG_ERROR, "Too many frames, seeking is not possible\n");
         return AVERROR_INVALIDDATA;
     }
-    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;
@@ -89,14 +81,26 @@ static int mpc_read_header(AVFormatContext *s)
     st = avformat_new_stream(s, NULL);
     if (!st)
         return AVERROR(ENOMEM);
+
+    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);
+        }
+        st->priv_data = c->frames;
+    } else {
+        av_log(s, AV_LOG_WARNING, "Container reports no frames\n");
+    }
+
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id = AV_CODEC_ID_MUSEPACK7;
     st->codecpar->channels = 2;
     st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
     st->codecpar->bits_per_coded_sample = 16;
 
-    if (ff_get_extradata(s, st->codecpar, s->pb, 16) < 0)
-        return AVERROR(ENOMEM);
+    if ((ret = ff_get_extradata(s, st->codecpar, s->pb, 16)) < 0)
+        return ret;
     st->codecpar->sample_rate = mpc_rate[st->codecpar->extradata[2] & 3];
     avpriv_set_pts_info(st, 32, MPC_FRAMESIZE, st->codecpar->sample_rate);
     /* scan for seekpoints */
@@ -166,7 +170,6 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt)
     if(c->curbits)
         avio_seek(s->pb, -4, SEEK_CUR);
     if(ret < size){
-        av_packet_unref(pkt);
         return ret < 0 ? ret : AVERROR(EIO);
     }
     pkt->size = ret + 4;
@@ -174,14 +177,6 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt)
     return 0;
 }
 
-static int mpc_read_close(AVFormatContext *s)
-{
-    MPCContext *c = s->priv_data;
-
-    av_freep(&c->frames);
-    return 0;
-}
-
 /**
  * Seek to the given position
  * If position is unknown but is within the limits of file
@@ -199,8 +194,8 @@ static int mpc_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
     uint32_t lastframe;
 
     /* if found, seek there */
-    if (index >= 0 && st->index_entries[st->nb_index_entries-1].timestamp >= timestamp - DELAY_FRAMES){
-        c->curframe = st->index_entries[index].pos;
+    if (index >= 0 && st->internal->index_entries[st->internal->nb_index_entries-1].timestamp >= timestamp - DELAY_FRAMES){
+        c->curframe = st->internal->index_entries[index].pos;
         return 0;
     }
     /* if timestamp is out of bounds, return error */
@@ -223,14 +218,13 @@ static int mpc_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
 }
 
 
-AVInputFormat ff_mpc_demuxer = {
+const AVInputFormat ff_mpc_demuxer = {
     .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",
 };