]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/libmodplug.c
avdevice/avdevice: Constify av_*_device_next API
[ffmpeg] / libavformat / libmodplug.c
index f18c610c4624dc607013d3356bdc5892f9cdb8a2..b85269341b7b1815103bc2c70e66760e63a82990 100644 (file)
@@ -99,6 +99,14 @@ static const AVOption options[] = {
     {NULL},
 };
 
+static int modplug_read_close(AVFormatContext *s)
+{
+    ModPlugContext *modplug = s->priv_data;
+    ModPlug_Unload(modplug->f);
+    av_freep(&modplug->buf);
+    return 0;
+}
+
 #define SET_OPT_IF_REQUESTED(libopt, opt, flag) do {        \
     if (modplug->opt) {                                     \
         settings.libopt  = modplug->opt;                    \
@@ -168,6 +176,7 @@ static int modplug_read_header(AVFormatContext *s)
     ModPlug_Settings settings;
     ModPlugContext *modplug = s->priv_data;
     int64_t sz = avio_size(pb);
+    int ret;
 
     if (sz < 0) {
         av_log(s, AV_LOG_WARNING, "Could not determine file size\n");
@@ -216,12 +225,15 @@ static int modplug_read_header(AVFormatContext *s)
     ModPlug_SetSettings(&settings);
 
     modplug->f = ModPlug_Load(modplug->buf, sz);
-    if (!modplug->f)
+    if (!modplug->f) {
+        av_freep(&modplug->buf);
         return AVERROR_INVALIDDATA;
-
+    }
     st = avformat_new_stream(s, NULL);
-    if (!st)
-        return AVERROR(ENOMEM);
+    if (!st) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
     avpriv_set_pts_info(st, 64, 1, 1000);
     st->duration = ModPlug_GetLength(modplug->f);
     st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
@@ -234,8 +246,10 @@ static int modplug_read_header(AVFormatContext *s)
 
     if (modplug->video_stream) {
         AVStream *vst = avformat_new_stream(s, NULL);
-        if (!vst)
-            return AVERROR(ENOMEM);
+        if (!vst) {
+            ret = AVERROR(ENOMEM);
+            goto fail;
+        }
         avpriv_set_pts_info(vst, 64, 1, 1000);
         vst->duration = st->duration;
         vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
@@ -246,7 +260,13 @@ static int modplug_read_header(AVFormatContext *s)
         modplug->fsize    = modplug->linesize * modplug->h;
     }
 
-    return modplug_load_metadata(s);
+    ret = modplug_load_metadata(s);
+    if (ret < 0)
+        goto fail;
+    return 0;
+fail:
+    modplug_read_close(s);
+    return ret;
 }
 
 static void write_text(uint8_t *dst, const char *s, int linesize, int x, int y)
@@ -269,6 +289,7 @@ static void write_text(uint8_t *dst, const char *s, int linesize, int x, int y)
 static int modplug_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     ModPlugContext *modplug = s->priv_data;
+    int ret;
 
     if (modplug->video_stream) {
         modplug->video_switch ^= 1; // one video packet for one audio packet
@@ -284,8 +305,8 @@ static int modplug_read_packet(AVFormatContext *s, AVPacket *pkt)
             var_values[VAR_PATTERN] = ModPlug_GetCurrentPattern(modplug->f);
             var_values[VAR_ROW    ] = ModPlug_GetCurrentRow    (modplug->f);
 
-            if (av_new_packet(pkt, modplug->fsize) < 0)
-                return AVERROR(ENOMEM);
+            if ((ret = av_new_packet(pkt, modplug->fsize)) < 0)
+                return ret;
             pkt->stream_index = 1;
             memset(pkt->data, 0, modplug->fsize);
 
@@ -317,28 +338,19 @@ static int modplug_read_packet(AVFormatContext *s, AVPacket *pkt)
         }
     }
 
-    if (av_new_packet(pkt, AUDIO_PKT_SIZE) < 0)
-        return AVERROR(ENOMEM);
+    if ((ret = av_new_packet(pkt, AUDIO_PKT_SIZE)) < 0)
+        return ret;
 
     if (modplug->video_stream)
         pkt->pts = pkt->dts = modplug->packet_count++ * modplug->ts_per_packet;
 
     pkt->size = ModPlug_Read(modplug->f, pkt->data, AUDIO_PKT_SIZE);
     if (pkt->size <= 0) {
-        av_packet_unref(pkt);
         return pkt->size == 0 ? AVERROR_EOF : AVERROR(EIO);
     }
     return 0;
 }
 
-static int modplug_read_close(AVFormatContext *s)
-{
-    ModPlugContext *modplug = s->priv_data;
-    ModPlug_Unload(modplug->f);
-    av_freep(&modplug->buf);
-    return 0;
-}
-
 static int modplug_read_seek(AVFormatContext *s, int stream_idx, int64_t ts, int flags)
 {
     ModPlugContext *modplug = s->priv_data;
@@ -350,7 +362,7 @@ static int modplug_read_seek(AVFormatContext *s, int stream_idx, int64_t ts, int
 
 static const char modplug_extensions[] = "669,abc,amf,ams,dbm,dmf,dsm,far,it,mdl,med,mid,mod,mt2,mtm,okt,psm,ptm,s3m,stm,ult,umx,xm,itgz,itr,itz,mdgz,mdr,mdz,s3gz,s3r,s3z,xmgz,xmr,xmz";
 
-static int modplug_probe(AVProbeData *p)
+static int modplug_probe(const AVProbeData *p)
 {
     if (av_match_ext(p->filename, modplug_extensions)) {
         if (p->buf_size < 16384)