]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/ulti.c
mpeg12dec: move setting first_field to mpeg_field_start()
[ffmpeg] / libavcodec / ulti.c
index 8168aa973979398a37bc9714f8b1fad1cc24fb90..46aa27d5d0852e5fd80f3bd7d906a65dba0c3c27 100644 (file)
 
 #include "avcodec.h"
 #include "bytestream.h"
+#include "internal.h"
 
 #include "ulti_cb.h"
 
 typedef struct UltimotionDecodeContext {
     AVCodecContext *avctx;
     int width, height, blocks;
-    AVFrame frame;
+    AVFrame *frame;
     const uint8_t *ulti_codebook;
     GetByteContext gb;
 } UltimotionDecodeContext;
@@ -49,19 +50,20 @@ static av_cold int ulti_decode_init(AVCodecContext *avctx)
     s->width = avctx->width;
     s->height = avctx->height;
     s->blocks = (s->width / 8) * (s->height / 8);
-    avctx->pix_fmt = PIX_FMT_YUV410P;
-    avctx->coded_frame = &s->frame;
+    avctx->pix_fmt = AV_PIX_FMT_YUV410P;
     s->ulti_codebook = ulti_codebook;
 
+    s->frame = av_frame_alloc();
+    if (!s->frame)
+        return AVERROR(ENOMEM);
+
     return 0;
 }
 
 static av_cold int ulti_decode_end(AVCodecContext *avctx){
     UltimotionDecodeContext *s = avctx->priv_data;
-    AVFrame *pic = &s->frame;
 
-    if (pic->data[0])
-        avctx->release_buffer(avctx, pic);
+    av_frame_free(&s->frame);
 
     return 0;
 }
@@ -209,7 +211,7 @@ static void ulti_grad(AVFrame *frame, int x, int y, uint8_t *Y, int chroma, int
 }
 
 static int ulti_decode_frame(AVCodecContext *avctx,
-                             void *data, int *data_size,
+                             void *data, int *got_frame,
                              AVPacket *avpkt)
 {
     const uint8_t *buf = avpkt->data;
@@ -221,15 +223,13 @@ static int ulti_decode_frame(AVCodecContext *avctx,
     int blocks = 0;
     int done = 0;
     int x = 0, y = 0;
-    int i;
+    int i, ret;
     int skip;
     int tmp;
 
-    s->frame.reference = 1;
-    s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
-    if (avctx->reget_buffer(avctx, &s->frame) < 0) {
+    if ((ret = ff_reget_buffer(avctx, s->frame)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
-        return -1;
+        return ret;
     }
 
     bytestream2_init(&s->gb, buf, buf_size);
@@ -370,7 +370,7 @@ static int ulti_decode_frame(AVCodecContext *avctx,
                         Luma[14] = (tmp >> 6) & 0x3F;
                         Luma[15] = tmp & 0x3F;
 
-                        ulti_convert_yuv(&s->frame, tx, ty, Luma, chroma);
+                        ulti_convert_yuv(s->frame, tx, ty, Luma, chroma);
                     } else {
                         if (bytestream2_get_bytes_left(&s->gb) < 4)
                             goto err;
@@ -382,20 +382,19 @@ static int ulti_decode_frame(AVCodecContext *avctx,
                             Y[1] = tmp & 0x3F;
                             Y[2] = bytestream2_get_byteu(&s->gb) & 0x3F;
                             Y[3] = bytestream2_get_byteu(&s->gb) & 0x3F;
-                            ulti_grad(&s->frame, tx, ty, Y, chroma, angle); //draw block
+                            ulti_grad(s->frame, tx, ty, Y, chroma, angle); //draw block
                         } else { // some patterns
-                            int f0, f1;
-                            f0 = bytestream2_get_byteu(&s->gb);
-                            f1 = tmp;
+                            int f0 = tmp;
+                            int f1 = bytestream2_get_byteu(&s->gb);
                             Y[0] = bytestream2_get_byteu(&s->gb) & 0x3F;
                             Y[1] = bytestream2_get_byteu(&s->gb) & 0x3F;
-                            ulti_pattern(&s->frame, tx, ty, f1, f0, Y[0], Y[1], chroma);
+                            ulti_pattern(s->frame, tx, ty, f0, f1, Y[0], Y[1], chroma);
                         }
                     }
                     break;
                 }
                 if(code != 3)
-                    ulti_grad(&s->frame, tx, ty, Y, chroma, angle); // draw block
+                    ulti_grad(s->frame, tx, ty, Y, chroma, angle); // draw block
             }
             blocks++;
                 x += 8;
@@ -406,8 +405,9 @@ static int ulti_decode_frame(AVCodecContext *avctx,
         }
     }
 
-    *data_size=sizeof(AVFrame);
-    *(AVFrame*)data= s->frame;
+    *got_frame = 1;
+    if ((ret = av_frame_ref(data, s->frame)) < 0)
+        return ret;
 
     return buf_size;
 
@@ -419,12 +419,12 @@ err:
 
 AVCodec ff_ulti_decoder = {
     .name           = "ultimotion",
+    .long_name      = NULL_IF_CONFIG_SMALL("IBM UltiMotion"),
     .type           = AVMEDIA_TYPE_VIDEO,
-    .id             = CODEC_ID_ULTI,
+    .id             = AV_CODEC_ID_ULTI,
     .priv_data_size = sizeof(UltimotionDecodeContext),
     .init           = ulti_decode_init,
     .close          = ulti_decode_end,
     .decode         = ulti_decode_frame,
-    .capabilities   = CODEC_CAP_DR1,
-    .long_name      = NULL_IF_CONFIG_SMALL("IBM UltiMotion"),
+    .capabilities   = AV_CODEC_CAP_DR1,
 };