]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/vp56.c
set the previous tag size correctly in flv files
[ffmpeg] / libavcodec / vp56.c
index c69b1201d11f94afe7246dd05cf8040fd8b3c9b1..e3634c8261782443ad43a98a58fc3cfb718e6ea8 100644 (file)
@@ -4,19 +4,21 @@
  *
  * Copyright (C) 2006  Aurelien Jacobs <aurel@gnuage.org>
  *
- * This library is free software; you can redistribute it and/or
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
- * This library is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include "avcodec.h"
@@ -306,8 +308,8 @@ static void vp56_edge_filter(vp56_context_t *s, uint8_t *yuv,
     for (i=0; i<12; i++) {
         v = (yuv[-pix2_inc] + 3*(yuv[0]-yuv[-pix_inc]) - yuv[pix_inc] + 4) >>3;
         v = s->adjust(v, t);
-        yuv[-pix_inc] = clip_uint8(yuv[-pix_inc] + v);
-        yuv[0] = clip_uint8(yuv[0] - v);
+        yuv[-pix_inc] = av_clip_uint8(yuv[-pix_inc] + v);
+        yuv[0] = av_clip_uint8(yuv[0] - v);
         yuv += line_inc;
     }
 }
@@ -324,7 +326,7 @@ static void vp56_mc(vp56_context_t *s, int b, uint8_t *src,
                     int stride, int x, int y)
 {
     int plane = vp56_b6to3[b];
-    uint8_t *dst= s->frames[VP56_FRAME_CURRENT].data[plane]+s->block_offset[b];
+    uint8_t *dst=s->framep[VP56_FRAME_CURRENT]->data[plane]+s->block_offset[b];
     uint8_t *src_block;
     int src_offset;
     int overlap_offset = 0;
@@ -335,7 +337,7 @@ static void vp56_mc(vp56_context_t *s, int b, uint8_t *src,
 
     if (s->avctx->skip_loop_filter >= AVDISCARD_ALL ||
         (s->avctx->skip_loop_filter >= AVDISCARD_NONKEY
-         && !s->frames[VP56_FRAME_CURRENT].key_frame))
+         && !s->framep[VP56_FRAME_CURRENT]->key_frame))
         deblock_filtering = 0;
 
     dx = s->mv[b].x / s->vp56_coord_div[b];
@@ -358,14 +360,11 @@ static void vp56_mc(vp56_context_t *s, int b, uint8_t *src,
         src_block = s->edge_emu_buffer;
         src_offset = 2 + 2*stride;
     } else if (deblock_filtering) {
-        int i;
-        src_block = s->edge_emu_buffer;
-        src += s->block_offset[b] + (dy-2)*stride + (dx-2);
-        for (i=0; i<12; i++) {
-            memcpy(src_block, src, 12);
-            src_block += stride;
-            src += stride;
-        }
+        /* only need a 12x12 block, but there is no such dsp function, */
+        /* so copy a 16x12 block */
+        s->dsp.put_pixels_tab[0][0](s->edge_emu_buffer,
+                                    src + s->block_offset[b] + (dy-2)*stride + (dx-2),
+                                    stride, 12);
         src_block = s->edge_emu_buffer;
         src_offset = 2 + 2*stride;
     } else {
@@ -401,7 +400,7 @@ static void vp56_decode_mb(vp56_context_t *s, int row, int col)
     vp56_frame_t ref_frame;
     int b, plan, off;
 
-    if (s->frames[VP56_FRAME_CURRENT].key_frame)
+    if (s->framep[VP56_FRAME_CURRENT]->key_frame)
         mb_type = VP56_MB_INTRA;
     else
         mb_type = vp56_decode_mv(s, row, col);
@@ -413,8 +412,8 @@ static void vp56_decode_mb(vp56_context_t *s, int row, int col)
 
     vp56_add_predictors_dc(s, ref_frame);
 
-    frame_current = &s->frames[VP56_FRAME_CURRENT];
-    frame_ref = &s->frames[ref_frame];
+    frame_current = s->framep[VP56_FRAME_CURRENT];
+    frame_ref = s->framep[ref_frame];
 
     switch (mb_type) {
         case VP56_MB_INTRA:
@@ -460,19 +459,19 @@ static void vp56_decode_mb(vp56_context_t *s, int row, int col)
 
 static int vp56_size_changed(AVCodecContext *avctx, vp56_context_t *s)
 {
-    int stride = s->frames[VP56_FRAME_CURRENT].linesize[0];
+    int stride = s->framep[VP56_FRAME_CURRENT]->linesize[0];
     int i;
 
-    s->plane_width[0] = s->avctx->width;
-    s->plane_width[1] = s->plane_width[2] = s->avctx->width/2;
-    s->plane_height[0] = s->avctx->height;
-    s->plane_height[1] = s->plane_height[2] = s->avctx->height/2;
+    s->plane_width[0] = s->avctx->coded_width;
+    s->plane_width[1] = s->plane_width[2] = s->avctx->coded_width/2;
+    s->plane_height[0] = s->avctx->coded_height;
+    s->plane_height[1] = s->plane_height[2] = s->avctx->coded_height/2;
 
     for (i=0; i<3; i++)
-        s->stride[i] = s->flip * s->frames[VP56_FRAME_CURRENT].linesize[i];
+        s->stride[i] = s->flip * s->framep[VP56_FRAME_CURRENT]->linesize[i];
 
-    s->mb_width = (s->avctx->width+15) / 16;
-    s->mb_height = (s->avctx->height+15) / 16;
+    s->mb_width = (s->avctx->coded_width+15) / 16;
+    s->mb_height = (s->avctx->coded_height+15) / 16;
 
     if (s->mb_width > 1000 || s->mb_height > 1000) {
         av_log(avctx, AV_LOG_ERROR, "picture too big\n");
@@ -483,7 +482,8 @@ static int vp56_size_changed(AVCodecContext *avctx, vp56_context_t *s)
                                  (4*s->mb_width+6) * sizeof(*s->above_blocks));
     s->macroblocks = av_realloc(s->macroblocks,
                                 s->mb_width*s->mb_height*sizeof(*s->macroblocks));
-    s->edge_emu_buffer_alloc = av_realloc(s->edge_emu_buffer_alloc, 16*stride);
+    av_free(s->edge_emu_buffer_alloc);
+    s->edge_emu_buffer_alloc = av_malloc(16*stride);
     s->edge_emu_buffer = s->edge_emu_buffer_alloc;
     if (s->flip < 0)
         s->edge_emu_buffer += 15 * stride;
@@ -495,8 +495,7 @@ int vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
                       uint8_t *buf, int buf_size)
 {
     vp56_context_t *s = avctx->priv_data;
-    AVFrame *const p = &s->frames[VP56_FRAME_CURRENT];
-    AVFrame *picture = data;
+    AVFrame *const p = s->framep[VP56_FRAME_CURRENT];
     int mb_row, mb_col, mb_row_flip, mb_offset = 0;
     int block, y, uv, stride_y, stride_uv;
     int golden_frame = 0;
@@ -594,20 +593,21 @@ int vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
         }
     }
 
-    if (s->frames[VP56_FRAME_PREVIOUS].data[0]
-        && (s->frames[VP56_FRAME_PREVIOUS].data[0]
-            != s->frames[VP56_FRAME_GOLDEN].data[0])) {
-        avctx->release_buffer(avctx, &s->frames[VP56_FRAME_PREVIOUS]);
-    }
+    if (s->framep[VP56_FRAME_PREVIOUS] == s->framep[VP56_FRAME_GOLDEN])
+        FFSWAP(AVFrame *, s->framep[VP56_FRAME_PREVIOUS],
+                          s->framep[VP56_FRAME_UNUSED]);
+    else if (s->framep[VP56_FRAME_PREVIOUS]->data[0])
+        avctx->release_buffer(avctx, s->framep[VP56_FRAME_PREVIOUS]);
     if (p->key_frame || golden_frame) {
-        if (s->frames[VP56_FRAME_GOLDEN].data[0])
-            avctx->release_buffer(avctx, &s->frames[VP56_FRAME_GOLDEN]);
-        s->frames[VP56_FRAME_GOLDEN] = *p;
+        if (s->framep[VP56_FRAME_GOLDEN]->data[0])
+            avctx->release_buffer(avctx, s->framep[VP56_FRAME_GOLDEN]);
+        s->framep[VP56_FRAME_GOLDEN] = p;
     }
-    s->frames[VP56_FRAME_PREVIOUS] = *p;
+    FFSWAP(AVFrame *, s->framep[VP56_FRAME_CURRENT],
+                      s->framep[VP56_FRAME_PREVIOUS]);
 
-    *picture = *p;
-    *data_size = sizeof(AVPicture);
+    *(AVFrame*)data = *p;
+    *data_size = sizeof(AVFrame);
 
     return buf_size;
 }
@@ -627,7 +627,8 @@ void vp56_init(vp56_context_t *s, AVCodecContext *avctx, int flip)
     avcodec_set_dimensions(s->avctx, 0, 0);
 
     for (i=0; i<3; i++)
-        s->frames[i].data[0] = NULL;
+        s->framep[i] = &s->frames[i];
+    s->framep[VP56_FRAME_UNUSED] = s->framep[VP56_FRAME_GOLDEN];
     s->edge_emu_buffer_alloc = NULL;
 
     s->above_blocks = NULL;
@@ -655,11 +656,10 @@ int vp56_free(AVCodecContext *avctx)
     av_free(s->above_blocks);
     av_free(s->macroblocks);
     av_free(s->edge_emu_buffer_alloc);
-    if (s->frames[VP56_FRAME_GOLDEN].data[0]
-        && (s->frames[VP56_FRAME_PREVIOUS].data[0]
-            != s->frames[VP56_FRAME_GOLDEN].data[0]))
-        avctx->release_buffer(avctx, &s->frames[VP56_FRAME_GOLDEN]);
-    if (s->frames[VP56_FRAME_PREVIOUS].data[0])
-        avctx->release_buffer(avctx, &s->frames[VP56_FRAME_PREVIOUS]);
+    if (s->framep[VP56_FRAME_GOLDEN]->data[0]
+        && (s->framep[VP56_FRAME_PREVIOUS] != s->framep[VP56_FRAME_GOLDEN]))
+        avctx->release_buffer(avctx, s->framep[VP56_FRAME_GOLDEN]);
+    if (s->framep[VP56_FRAME_PREVIOUS]->data[0])
+        avctx->release_buffer(avctx, s->framep[VP56_FRAME_PREVIOUS]);
     return 0;
 }