]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/ansi.c
utvideodec: Convert to the new bitstream reader
[ffmpeg] / libavcodec / ansi.c
index b99826b3a5cd20fc302425ed15d01bdfbb88ca95..65e2e16faef9e04b55966c07e59677a229cdbcb7 100644 (file)
@@ -49,7 +49,7 @@ static const uint8_t ansi_to_cga[16] = {
     0,  4,  2,  6,  1,  5,  3, 7, 8, 12, 10, 14,  9, 13, 11, 15
 };
 
-typedef struct {
+typedef struct AnsiContext {
     AVFrame *frame;
     int x;                /**< x cursor position (pixels) */
     int y;                /**< y cursor position (pixels) */
@@ -88,9 +88,11 @@ static av_cold int decode_init(AVCodecContext *avctx)
     s->fg          = DEFAULT_FG_COLOR;
     s->bg          = DEFAULT_BG_COLOR;
 
-    if (!avctx->width || !avctx->height)
-        avcodec_set_dimensions(avctx, 80<<3, 25<<4);
-
+    if (!avctx->width || !avctx->height) {
+        int ret = ff_set_dimensions(avctx, 80 << 3, 25 << 4);
+        if (ret < 0)
+            return ret;
+    }
     return 0;
 }
 
@@ -165,7 +167,10 @@ static void draw_char(AVCodecContext *avctx, int c)
 static int execute_code(AVCodecContext * avctx, int c)
 {
     AnsiContext *s = avctx->priv_data;
-    int ret, i, width, height;
+    int ret, i;
+    int width = 0;
+    int height = 0;
+
     switch(c) {
     case 'A': //Cursor Up
         s->y = FFMAX(s->y - (s->nb_args > 0 ? s->args[0]*s->font_height : s->font_height), 0);
@@ -184,7 +189,7 @@ static int execute_code(AVCodecContext * avctx, int c)
         s->y = s->nb_args > 0 ? av_clip((s->args[0] - 1)*s->font_height, 0, avctx->height - s->font_height) : 0;
         s->x = s->nb_args > 1 ? av_clip((s->args[1] - 1)*FONT_WIDTH,     0, avctx->width  - FONT_WIDTH) : 0;
         break;
-    case 'h': //set creen mode
+    case 'h': //set screen mode
     case 'l': //reset screen mode
         if (s->nb_args < 2)
             s->args[0] = DEFAULT_SCREEN_MODE;
@@ -222,11 +227,14 @@ static int execute_code(AVCodecContext * avctx, int c)
             height = 60<<4;
             break;
         default:
-            av_log_ask_for_sample(avctx, "unsupported screen mode\n");
+            avpriv_request_sample(avctx, "Unsupported screen mode");
         }
-        if (width != avctx->width || height != avctx->height) {
+        if (width != 0 && height != 0 &&
+            (width != avctx->width || height != avctx->height)) {
             av_frame_unref(s->frame);
-            avcodec_set_dimensions(avctx, width, height);
+            ret = ff_set_dimensions(avctx, width, height);
+            if (ret < 0)
+                return ret;
             ret = ff_get_buffer(avctx, s->frame, AV_GET_BUFFER_FLAG_REF);
             if (ret < 0) {
                 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
@@ -291,7 +299,7 @@ static int execute_code(AVCodecContext * avctx, int c)
             } else if (m == 49) {
                 s->fg = ansi_to_cga[DEFAULT_BG_COLOR];
             } else {
-                av_log_ask_for_sample(avctx, "unsupported rendition parameter\n");
+                avpriv_request_sample(avctx, "Unsupported rendition parameter");
             }
         }
         break;
@@ -308,7 +316,7 @@ static int execute_code(AVCodecContext * avctx, int c)
         s->y = av_clip(s->sy, 0, avctx->height - s->font_height);
         break;
     default:
-        av_log_ask_for_sample(avctx, "unsupported escape code\n");
+        avpriv_request_sample(avctx, "Unknown escape code");
         break;
     }
     return 0;
@@ -435,12 +443,12 @@ static av_cold int decode_close(AVCodecContext *avctx)
 
 AVCodec ff_ansi_decoder = {
     .name           = "ansi",
+    .long_name      = NULL_IF_CONFIG_SMALL("ASCII/ANSI art"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_ANSI,
     .priv_data_size = sizeof(AnsiContext),
     .init           = decode_init,
     .close          = decode_close,
     .decode         = decode_frame,
-    .capabilities   = CODEC_CAP_DR1,
-    .long_name      = NULL_IF_CONFIG_SMALL("ASCII/ANSI art"),
+    .capabilities   = AV_CODEC_CAP_DR1,
 };