]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/tscc2.c
h264: Use AVERROR return codes instead of -1
[ffmpeg] / libavcodec / tscc2.c
index 439de91b40d1d5795362a8a74e7eba5ff3d42d75..d83ccd9d11b5c185d636041a3245847cc9fad9f7 100644 (file)
@@ -24,6 +24,8 @@
  * TechSmith Screen Codec 2 decoder
  */
 
+#include <inttypes.h>
+
 #define BITSTREAM_READER_LE
 #include "avcodec.h"
 #include "get_bits.h"
@@ -33,7 +35,7 @@
 
 typedef struct TSCC2Context {
     AVCodecContext *avctx;
-    AVFrame        pic;
+    AVFrame       *pic;
     int            mb_width, mb_height;
     uint8_t        *slice_quants;
     int            quant[2];
@@ -200,9 +202,9 @@ static int tscc2_decode_slice(TSCC2Context *c, int mb_y,
         if (q == 0 || q == 3) // skip block
             continue;
         for (i = 0; i < 3; i++) {
-            off = mb_x * 16 + mb_y * 8 * c->pic.linesize[i];
+            off = mb_x * 16 + mb_y * 8 * c->pic->linesize[i];
             ret = tscc2_decode_mb(c, c->q[q - 1], c->quant[q - 1] - 2,
-                                  c->pic.data[i] + off, c->pic.linesize[i], i);
+                                  c->pic->data[i] + off, c->pic->linesize[i], i);
             if (ret)
                 return ret;
         }
@@ -226,18 +228,19 @@ static int tscc2_decode_frame(AVCodecContext *avctx, void *data,
     bytestream2_init(&gb, buf, buf_size);
     frame_type = bytestream2_get_byte(&gb);
     if (frame_type > 1) {
-        av_log(avctx, AV_LOG_ERROR, "Incorrect frame type %d\n", frame_type);
+        av_log(avctx, AV_LOG_ERROR, "Incorrect frame type %"PRIu32"\n",
+               frame_type);
         return AVERROR_INVALIDDATA;
     }
 
-    if ((ret = ff_reget_buffer(avctx, &c->pic)) < 0) {
+    if ((ret = ff_reget_buffer(avctx, c->pic)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
         return ret;
     }
 
     if (frame_type == 0) {
         *got_frame      = 1;
-        if ((ret = av_frame_ref(data, &c->pic)) < 0)
+        if ((ret = av_frame_ref(data, c->pic)) < 0)
             return ret;
 
         return buf_size;
@@ -309,7 +312,7 @@ static int tscc2_decode_frame(AVCodecContext *avctx, void *data,
             }
         }
         if (bytestream2_get_bytes_left(&gb) < size) {
-            av_log(avctx, AV_LOG_ERROR, "Invalid slice size (%d/%d)\n",
+            av_log(avctx, AV_LOG_ERROR, "Invalid slice size (%"PRIu32"/%u)\n",
                    size, bytestream2_get_bytes_left(&gb));
             return AVERROR_INVALIDDATA;
         }
@@ -322,13 +325,24 @@ static int tscc2_decode_frame(AVCodecContext *avctx, void *data,
     }
 
     *got_frame      = 1;
-    if ((ret = av_frame_ref(data, &c->pic)) < 0)
+    if ((ret = av_frame_ref(data, c->pic)) < 0)
         return ret;
 
     /* always report that the buffer was completely consumed */
     return buf_size;
 }
 
+static av_cold int tscc2_decode_end(AVCodecContext *avctx)
+{
+    TSCC2Context * const c = avctx->priv_data;
+
+    av_frame_free(&c->pic);
+    av_freep(&c->slice_quants);
+    free_vlcs(c);
+
+    return 0;
+}
+
 static av_cold int tscc2_decode_init(AVCodecContext *avctx)
 {
     TSCC2Context * const c = avctx->priv_data;
@@ -352,28 +366,23 @@ static av_cold int tscc2_decode_init(AVCodecContext *avctx)
         return AVERROR(ENOMEM);
     }
 
-    return 0;
-}
-
-static av_cold int tscc2_decode_end(AVCodecContext *avctx)
-{
-    TSCC2Context * const c = avctx->priv_data;
-
-    av_frame_unref(&c->pic);
-    av_freep(&c->slice_quants);
-    free_vlcs(c);
+    c->pic = av_frame_alloc();
+    if (!c->pic) {
+        tscc2_decode_end(avctx);
+        return AVERROR(ENOMEM);
+    }
 
     return 0;
 }
 
 AVCodec ff_tscc2_decoder = {
     .name           = "tscc2",
+    .long_name      = NULL_IF_CONFIG_SMALL("TechSmith Screen Codec 2"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_TSCC2,
     .priv_data_size = sizeof(TSCC2Context),
     .init           = tscc2_decode_init,
     .close          = tscc2_decode_end,
     .decode         = tscc2_decode_frame,
-    .capabilities   = CODEC_CAP_DR1,
-    .long_name      = NULL_IF_CONFIG_SMALL("TechSmith Screen Codec 2"),
+    .capabilities   = AV_CODEC_CAP_DR1,
 };