]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/mimic.c
aacdec: Drop some unused function arguments
[ffmpeg] / libavcodec / mimic.c
index 0f3ae596ed98fac9012eb990e053bbb8bd8e4aac..fd7efef34344d1f80a198ad78a1627548d73d226 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005  Ole André Vadla Ravnås <oleavr@gmail.com>
+ * Copyright (C) 2005  Ole André Vadla Ravnås <oleavr@gmail.com>
  * Copyright (C) 2008  Ramiro Polla
  *
  * This file is part of Libav.
@@ -24,6 +24,7 @@
 #include <stdint.h>
 
 #include "avcodec.h"
+#include "internal.h"
 #include "get_bits.h"
 #include "bytestream.h"
 #include "dsputil.h"
@@ -120,7 +121,7 @@ static av_cold int mimic_decode_init(AVCodecContext *avctx)
         av_log(avctx, AV_LOG_ERROR, "error initializing vlc table\n");
         return -1;
     }
-    dsputil_init(&ctx->dsp, avctx);
+    ff_dsputil_init(&ctx->dsp, avctx);
     ff_init_scantable(ctx->dsp.idct_permutation, &ctx->scantable, col_zag);
 
     return 0;
@@ -258,8 +259,8 @@ static int decode(MimicContext *ctx, int quality, int num_coeffs,
                         int index = (ctx->cur_index+backref)&15;
                         uint8_t *p = ctx->flipped_ptrs[index].data[0];
 
-                        ff_thread_await_progress(&ctx->buf_ptrs[index], cur_row, 0);
-                        if(p) {
+                        if (index != ctx->cur_index && p) {
+                            ff_thread_await_progress(&ctx->buf_ptrs[index], cur_row, 0);
                             p += src -
                                 ctx->flipped_ptrs[ctx->prev_index].data[plane];
                             ctx->dsp.put_pixels_tab[1][0](dst, p, stride, 8);
@@ -305,24 +306,27 @@ static int mimic_decode_frame(AVCodecContext *avctx, void *data,
     const uint8_t *buf = avpkt->data;
     int buf_size = avpkt->size;
     MimicContext *ctx = avctx->priv_data;
+    GetByteContext gb;
     int is_pframe;
     int width, height;
     int quality, num_coeffs;
     int swap_buf_size = buf_size - MIMIC_HEADER_SIZE;
+    int res;
 
-    if(buf_size < MIMIC_HEADER_SIZE) {
+    if (buf_size <= MIMIC_HEADER_SIZE) {
         av_log(avctx, AV_LOG_ERROR, "insufficient data\n");
         return -1;
     }
 
-    buf       += 2; /* some constant (always 256) */
-    quality    = bytestream_get_le16(&buf);
-    width      = bytestream_get_le16(&buf);
-    height     = bytestream_get_le16(&buf);
-    buf       += 4; /* some constant */
-    is_pframe  = bytestream_get_le32(&buf);
-    num_coeffs = bytestream_get_byte(&buf);
-    buf       += 3; /* some constant */
+    bytestream2_init(&gb, buf, MIMIC_HEADER_SIZE);
+    bytestream2_skip(&gb, 2); /* some constant (always 256) */
+    quality    = bytestream2_get_le16u(&gb);
+    width      = bytestream2_get_le16u(&gb);
+    height     = bytestream2_get_le16u(&gb);
+    bytestream2_skip(&gb, 4); /* some constant */
+    is_pframe  = bytestream2_get_le32u(&gb);
+    num_coeffs = bytestream2_get_byteu(&gb);
+    bytestream2_skip(&gb, 3); /* some constant */
 
     if(!ctx->avctx) {
         int i;
@@ -336,7 +340,7 @@ static int mimic_decode_frame(AVCodecContext *avctx, void *data,
         ctx->avctx     = avctx;
         avctx->width   = width;
         avctx->height  = height;
-        avctx->pix_fmt = PIX_FMT_YUV420P;
+        avctx->pix_fmt = AV_PIX_FMT_YUV420P;
         for(i = 0; i < 3; i++) {
             ctx->num_vblocks[i] = -((-height) >> (3 + !!i));
             ctx->num_hblocks[i] =     width   >> (3 + !!i) ;
@@ -352,7 +356,7 @@ static int mimic_decode_frame(AVCodecContext *avctx, void *data,
     }
 
     ctx->buf_ptrs[ctx->cur_index].reference = 1;
-    ctx->buf_ptrs[ctx->cur_index].pict_type = is_pframe ? FF_P_TYPE:FF_I_TYPE;
+    ctx->buf_ptrs[ctx->cur_index].pict_type = is_pframe ? AV_PICTURE_TYPE_P:AV_PICTURE_TYPE_I;
     if(ff_thread_get_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index])) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return -1;
@@ -372,14 +376,14 @@ static int mimic_decode_frame(AVCodecContext *avctx, void *data,
         return AVERROR(ENOMEM);
 
     ctx->dsp.bswap_buf(ctx->swap_buf,
-                        (const uint32_t*) buf,
+                        (const uint32_t*) (buf + MIMIC_HEADER_SIZE),
                         swap_buf_size>>2);
     init_get_bits(&ctx->gb, ctx->swap_buf, swap_buf_size << 3);
 
-    if(!decode(ctx, quality, num_coeffs, !is_pframe)) {
-        if (avctx->active_thread_type&FF_THREAD_FRAME)
-            ff_thread_report_progress(&ctx->buf_ptrs[ctx->cur_index], INT_MAX, 0);
-        else {
+    res = decode(ctx, quality, num_coeffs, !is_pframe);
+    ff_thread_report_progress(&ctx->buf_ptrs[ctx->cur_index], INT_MAX, 0);
+    if (!res) {
+        if (!(avctx->active_thread_type & FF_THREAD_FRAME)) {
             ff_thread_release_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index]);
             return -1;
         }
@@ -405,26 +409,26 @@ static av_cold int mimic_decode_end(AVCodecContext *avctx)
 
     av_free(ctx->swap_buf);
 
-    if(avctx->is_copy) return 0;
+    if (avctx->internal->is_copy)
+        return 0;
 
     for(i = 0; i < 16; i++)
         if(ctx->buf_ptrs[i].data[0])
             ff_thread_release_buffer(avctx, &ctx->buf_ptrs[i]);
-    free_vlc(&ctx->vlc);
+    ff_free_vlc(&ctx->vlc);
 
     return 0;
 }
 
 AVCodec ff_mimic_decoder = {
-    "mimic",
-    AVMEDIA_TYPE_VIDEO,
-    CODEC_ID_MIMIC,
-    sizeof(MimicContext),
-    mimic_decode_init,
-    NULL,
-    mimic_decode_end,
-    mimic_decode_frame,
-    CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
-    .long_name = NULL_IF_CONFIG_SMALL("Mimic"),
+    .name                  = "mimic",
+    .type                  = AVMEDIA_TYPE_VIDEO,
+    .id                    = AV_CODEC_ID_MIMIC,
+    .priv_data_size        = sizeof(MimicContext),
+    .init                  = mimic_decode_init,
+    .close                 = mimic_decode_end,
+    .decode                = mimic_decode_frame,
+    .capabilities          = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
+    .long_name             = NULL_IF_CONFIG_SMALL("Mimic"),
     .update_thread_context = ONLY_IF_THREADS_ENABLED(mimic_decode_update_thread_context)
 };