]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/blobdiff - libavcodec/vp5.c
Fix segault
[frescor/ffmpeg.git] / libavcodec / vp5.c
index 544135006965869943b3add7c689e173ca8524c9..1f8434c731db408356f4189dda3e34f47dca1d03 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * @file vp5.c
+ * @file libavcodec/vp5.c
  * VP5 compatible video decoder
  *
  * Copyright (C) 2006  Aurelien Jacobs <aurel@gnuage.org>
 
 #include "avcodec.h"
 #include "dsputil.h"
-#include "bitstream.h"
-#include "mpegvideo.h"
+#include "get_bits.h"
 
 #include "vp56.h"
 #include "vp56data.h"
 #include "vp5data.h"
 
 
-static int vp5_parse_header(vp56_context_t *s, uint8_t *buf, int buf_size,
+static int vp5_parse_header(VP56Context *s, const uint8_t *buf, int buf_size,
                             int *golden_frame)
 {
-    vp56_range_coder_t *c = &s->c;
+    VP56RangeCoder *c = &s->c;
     int rows, cols;
 
     vp56_init_range_decoder(&s->c, buf, buf_size);
@@ -59,12 +58,14 @@ static int vp5_parse_header(vp56_context_t *s, uint8_t *buf, int buf_size,
         vp56_rac_gets(c, 8);  /* number of displayed macroblock rows */
         vp56_rac_gets(c, 8);  /* number of displayed macroblock cols */
         vp56_rac_gets(c, 2);
-        if (16*cols != s->avctx->coded_width ||
+        if (!s->macroblocks || /* first frame */
+            16*cols != s->avctx->coded_width ||
             16*rows != s->avctx->coded_height) {
             avcodec_set_dimensions(s->avctx, 16*cols, 16*rows);
             return 2;
         }
-    }
+    } else if (!s->macroblocks)
+        return 0;
     return 1;
 }
 
@@ -85,10 +86,10 @@ static int vp5_adjust(int v, int t)
     return v;
 }
 
-static void vp5_parse_vector_adjustment(vp56_context_t *s, vp56_mv_t *vect)
+static void vp5_parse_vector_adjustment(VP56Context *s, VP56mv *vect)
 {
-    vp56_range_coder_t *c = &s->c;
-    vp56_model_t *model = s->modelp;
+    VP56RangeCoder *c = &s->c;
+    VP56Model *model = s->modelp;
     int comp, di;
 
     for (comp=0; comp<2; comp++) {
@@ -109,10 +110,10 @@ static void vp5_parse_vector_adjustment(vp56_context_t *s, vp56_mv_t *vect)
     }
 }
 
-static void vp5_parse_vector_models(vp56_context_t *s)
+static void vp5_parse_vector_models(VP56Context *s)
 {
-    vp56_range_coder_t *c = &s->c;
-    vp56_model_t *model = s->modelp;
+    VP56RangeCoder *c = &s->c;
+    VP56Model *model = s->modelp;
     int comp, node;
 
     for (comp=0; comp<2; comp++) {
@@ -132,10 +133,10 @@ static void vp5_parse_vector_models(vp56_context_t *s)
                 model->vector_pdv[comp][node] = vp56_rac_gets_nn(c, 7);
 }
 
-static void vp5_parse_coeff_models(vp56_context_t *s)
+static void vp5_parse_coeff_models(VP56Context *s)
 {
-    vp56_range_coder_t *c = &s->c;
-    vp56_model_t *model = s->modelp;
+    VP56RangeCoder *c = &s->c;
+    VP56Model *model = s->modelp;
     uint8_t def_prob[11];
     int node, cg, ctx;
     int ct;    /* code type */
@@ -178,10 +179,10 @@ static void vp5_parse_coeff_models(vp56_context_t *s)
                         model->coeff_acct[pt][ct][cg][ctx][node] = av_clip(((model->coeff_ract[pt][ct][cg][node] * vp5_ract_lc[ct][cg][node][ctx][0] + 128) >> 8) + vp5_ract_lc[ct][cg][node][ctx][1], 1, 254);
 }
 
-static void vp5_parse_coeff(vp56_context_t *s)
+static void vp5_parse_coeff(VP56Context *s)
 {
-    vp56_range_coder_t *c = &s->c;
-    vp56_model_t *model = s->modelp;
+    VP56RangeCoder *c = &s->c;
+    VP56Model *model = s->modelp;
     uint8_t *permute = s->scantable.permutated;
     uint8_t *model1, *model2;
     int coeff, sign, coeff_idx;
@@ -205,7 +206,7 @@ static void vp5_parse_coeff(vp56_context_t *s)
                         s->coeff_ctx[vp56_b6to4[b]][coeff_idx] = 4;
                         idx = vp56_rac_get_tree(c, vp56_pc_tree, model1);
                         sign = vp56_rac_get(c);
-                        coeff = vp56_coeff_bias[idx];
+                        coeff = vp56_coeff_bias[idx+5];
                         for (i=vp56_coeff_bit_length[idx]; i>=0; i--)
                             coeff += vp56_rac_get_prob(c, vp56_coeff_parse_table[idx][i]) << i;
                     } else {
@@ -251,9 +252,9 @@ static void vp5_parse_coeff(vp56_context_t *s)
     }
 }
 
-static void vp5_default_models_init(vp56_context_t *s)
+static void vp5_default_models_init(VP56Context *s)
 {
-    vp56_model_t *model = s->modelp;
+    VP56Model *model = s->modelp;
     int i;
 
     for (i=0; i<2; i++) {
@@ -266,11 +267,11 @@ static void vp5_default_models_init(vp56_context_t *s)
     memset(model->vector_pdv, 0x80, sizeof(model->vector_pdv));
 }
 
-static int vp5_decode_init(AVCodecContext *avctx)
+static av_cold int vp5_decode_init(AVCodecContext *avctx)
 {
-    vp56_context_t *s = avctx->priv_data;
+    VP56Context *s = avctx->priv_data;
 
-    vp56_init(avctx, 1);
+    vp56_init(avctx, 1, 0);
     s->vp56_coord_div = vp5_coord_div;
     s->parse_vector_adjustment = vp5_parse_vector_adjustment;
     s->adjust = vp5_adjust;
@@ -287,10 +288,11 @@ AVCodec vp5_decoder = {
     "vp5",
     CODEC_TYPE_VIDEO,
     CODEC_ID_VP5,
-    sizeof(vp56_context_t),
+    sizeof(VP56Context),
     vp5_decode_init,
     NULL,
     vp56_free,
     vp56_decode_frame,
     CODEC_CAP_DR1,
+    .long_name = NULL_IF_CONFIG_SMALL("On2 VP5"),
 };