]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/wc3movie.c
avformat: Constify all muxer/demuxers
[ffmpeg] / libavformat / wc3movie.c
index cb4d4d933ba3a37e674c1bbc49519b8c6e28cc41..dfb2462072a9baee81ecc526cede8f7b16e6b641 100644 (file)
@@ -69,11 +69,20 @@ typedef struct Wc3DemuxContext {
     int video_stream_index;
     int audio_stream_index;
 
-    AVPacket vpkt;
+    AVPacket *vpkt;
 
 } Wc3DemuxContext;
 
-static int wc3_probe(AVProbeData *p)
+static int wc3_read_close(AVFormatContext *s)
+{
+    Wc3DemuxContext *wc3 = s->priv_data;
+
+    av_packet_free(&wc3->vpkt);
+
+    return 0;
+}
+
+static int wc3_probe(const AVProbeData *p)
 {
     if (p->buf_size < 12)
         return 0;
@@ -100,8 +109,9 @@ static int wc3_read_header(AVFormatContext *s)
     wc3->height = WC3_DEFAULT_HEIGHT;
     wc3->pts = 0;
     wc3->video_stream_index = wc3->audio_stream_index = 0;
-    av_init_packet(&wc3->vpkt);
-    wc3->vpkt.data = NULL; wc3->vpkt.size = 0;
+    wc3->vpkt = av_packet_alloc();
+    if (!wc3->vpkt)
+        return AVERROR(ENOMEM);
 
     /* skip the first 3 32-bit numbers */
     avio_skip(pb, 12);
@@ -129,9 +139,15 @@ static int wc3_read_header(AVFormatContext *s)
             /* load up the name */
             buffer = av_malloc(size+1);
             if (!buffer)
-                return AVERROR(ENOMEM);
-            if ((ret = avio_read(pb, buffer, size)) != size)
-                return AVERROR(EIO);
+            if (!buffer) {
+                ret = AVERROR(ENOMEM);
+                goto fail;
+            }
+            if ((ret = avio_read(pb, buffer, size)) != size) {
+                av_freep(&buffer);
+                ret =  AVERROR(EIO);
+                goto fail;
+            }
             buffer[size] = 0;
             av_dict_set(&s->metadata, "title", buffer,
                                    AV_DICT_DONT_STRDUP_VAL);
@@ -146,27 +162,32 @@ static int wc3_read_header(AVFormatContext *s)
         case PALT_TAG:
             /* one of several palettes */
             avio_seek(pb, -8, SEEK_CUR);
-            av_append_packet(pb, &wc3->vpkt, 8 + PALETTE_SIZE);
+            av_append_packet(pb, wc3->vpkt, 8 + PALETTE_SIZE);
             break;
 
         default:
             av_log(s, AV_LOG_ERROR, "unrecognized WC3 chunk: %s\n",
                    av_fourcc2str(fourcc_tag));
-            return AVERROR_INVALIDDATA;
+            ret = AVERROR_INVALIDDATA;
+            goto fail;
         }
 
         fourcc_tag = avio_rl32(pb);
         /* chunk sizes are 16-bit aligned */
         size = (avio_rb32(pb) + 1) & (~1);
-        if (avio_feof(pb))
-            return AVERROR(EIO);
+        if (avio_feof(pb)) {
+            ret = AVERROR(EIO);
+            goto fail;
+        }
 
     } while (fourcc_tag != BRCH_TAG);
 
     /* initialize the decoder streams */
     st = avformat_new_stream(s, NULL);
-    if (!st)
-        return AVERROR(ENOMEM);
+    if (!st) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
     avpriv_set_pts_info(st, 33, 1, WC3_FRAME_FPS);
     wc3->video_stream_index = st->index;
     st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
@@ -176,8 +197,10 @@ static int wc3_read_header(AVFormatContext *s)
     st->codecpar->height = wc3->height;
 
     st = avformat_new_stream(s, NULL);
-    if (!st)
-        return AVERROR(ENOMEM);
+    if (!st) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
     avpriv_set_pts_info(st, 33, 1, WC3_FRAME_FPS);
     wc3->audio_stream_index = st->index;
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -192,6 +215,9 @@ static int wc3_read_header(AVFormatContext *s)
     st->codecpar->block_align = WC3_AUDIO_BITS * WC3_AUDIO_CHANNELS;
 
     return 0;
+fail:
+    wc3_read_close(s);
+    return ret;
 }
 
 static int wc3_read_packet(AVFormatContext *s,
@@ -222,18 +248,17 @@ static int wc3_read_packet(AVFormatContext *s,
         case SHOT_TAG:
             /* load up new palette */
             avio_seek(pb, -8, SEEK_CUR);
-            av_append_packet(pb, &wc3->vpkt, 8 + 4);
+            av_append_packet(pb, wc3->vpkt, 8 + 4);
             break;
 
         case VGA__TAG:
             /* send out video chunk */
             avio_seek(pb, -8, SEEK_CUR);
-            ret= av_append_packet(pb, &wc3->vpkt, 8 + size);
+            ret= av_append_packet(pb, wc3->vpkt, 8 + size);
             // ignore error if we have some data
-            if (wc3->vpkt.size > 0)
+            if (wc3->vpkt->size > 0)
                 ret = 0;
-            *pkt = wc3->vpkt;
-            wc3->vpkt.data = NULL; wc3->vpkt.size = 0;
+            av_packet_move_ref(pkt, wc3->vpkt);
             pkt->stream_index = wc3->video_stream_index;
             pkt->pts = wc3->pts;
             packet_read = 1;
@@ -284,17 +309,7 @@ static int wc3_read_packet(AVFormatContext *s,
     return ret;
 }
 
-static int wc3_read_close(AVFormatContext *s)
-{
-    Wc3DemuxContext *wc3 = s->priv_data;
-
-    if (wc3->vpkt.size > 0)
-        av_packet_unref(&wc3->vpkt);
-
-    return 0;
-}
-
-AVInputFormat ff_wc3_demuxer = {
+const AVInputFormat ff_wc3_demuxer = {
     .name           = "wc3movie",
     .long_name      = NULL_IF_CONFIG_SMALL("Wing Commander III movie"),
     .priv_data_size = sizeof(Wc3DemuxContext),