]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/cdgraphics.c
avcodec: Constify AVCodecs
[ffmpeg] / libavcodec / cdgraphics.c
index be85e542887872af1c99145a729bec7b2bc00f7b..faa43c1c83437acc94a63091898ed4fb6c80bda7 100644 (file)
@@ -81,11 +81,8 @@ static av_cold int cdg_decode_init(AVCodecContext *avctx)
         return AVERROR(ENOMEM);
     cc->transparency = -1;
 
-    avctx->width   = CDG_FULL_WIDTH;
-    avctx->height  = CDG_FULL_HEIGHT;
     avctx->pix_fmt = AV_PIX_FMT_PAL8;
-
-    return 0;
+    return ff_set_dimensions(avctx, CDG_FULL_WIDTH, CDG_FULL_HEIGHT);
 }
 
 static void cdg_border_preset(CDGraphicsContext *cc, uint8_t *data)
@@ -286,7 +283,7 @@ static int cdg_decode_frame(AVCodecContext *avctx,
 
     bytestream2_init(&gb, avpkt->data, avpkt->size);
 
-    if ((ret = ff_reget_buffer(avctx, cc->frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, cc->frame, 0)) < 0)
         return ret;
     if (!cc->cleared) {
         memset(cc->frame->data[0], 0, cc->frame->linesize[0] * avctx->height);
@@ -368,6 +365,18 @@ static int cdg_decode_frame(AVCodecContext *avctx,
     return avpkt->size;
 }
 
+static void cdg_decode_flush(AVCodecContext *avctx)
+{
+    CDGraphicsContext *cc = avctx->priv_data;
+
+    if (!cc->frame->data[0])
+        return;
+
+    memset(cc->frame->data[0], 0, cc->frame->linesize[0] * avctx->height);
+    if (!avctx->frame_number)
+        memset(cc->frame->data[1], 0, AVPALETTE_SIZE);
+}
+
 static av_cold int cdg_decode_end(AVCodecContext *avctx)
 {
     CDGraphicsContext *cc = avctx->priv_data;
@@ -377,7 +386,7 @@ static av_cold int cdg_decode_end(AVCodecContext *avctx)
     return 0;
 }
 
-AVCodec ff_cdgraphics_decoder = {
+const AVCodec ff_cdgraphics_decoder = {
     .name           = "cdgraphics",
     .long_name      = NULL_IF_CONFIG_SMALL("CD Graphics video"),
     .type           = AVMEDIA_TYPE_VIDEO,
@@ -386,5 +395,6 @@ AVCodec ff_cdgraphics_decoder = {
     .init           = cdg_decode_init,
     .close          = cdg_decode_end,
     .decode         = cdg_decode_frame,
+    .flush          = cdg_decode_flush,
     .capabilities   = AV_CODEC_CAP_DR1,
 };