]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/svq1dec.c
pthread: validate_thread_parameters() ignored slice-threading being intentionally off
[ffmpeg] / libavcodec / svq1dec.c
index f31b69f2a19ab07cdae75c2ee44ee07db7885909..5439abbf75089a70d1937b86a020653c9014a159 100644 (file)
@@ -8,25 +8,25 @@
  *
  * SVQ1 Encoder (c) 2004 Mike Melanson <melanson@pcisys.net>
  *
- * This file is part of FFmpeg.
+ * This file is part of Libav.
  *
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav 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.
  *
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav 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 FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 /**
- * @file libavcodec/svq1.c
+ * @file
  * Sorenson Vector Quantizer #1 (SVQ1) video codec.
  * For more information of the SVQ1 algorithm, visit:
  *   http://www.pcisys.net/~melanson/codecs/
@@ -650,6 +650,7 @@ static int svq1_decode_frame(AVCodecContext *avctx,
   uint8_t        *current, *previous;
   int             result, i, x, y, width, height;
   AVFrame *pict = data;
+  svq1_pmv *pmv;
 
   /* initialize bit buffer */
   init_get_bits(&s->gb,buf,buf_size*8);
@@ -683,7 +684,9 @@ static int svq1_decode_frame(AVCodecContext *avctx,
   //this should be removed after libavcodec can handle more flexible picture types & ordering
   if(s->pict_type==FF_B_TYPE && s->last_picture_ptr==NULL) return buf_size;
 
+#if FF_API_HURRY_UP
   if(avctx->hurry_up && s->pict_type==FF_B_TYPE) return buf_size;
+#endif
   if(  (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==FF_B_TYPE)
      ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=FF_I_TYPE)
      || avctx->skip_frame >= AVDISCARD_ALL)
@@ -692,17 +695,21 @@ static int svq1_decode_frame(AVCodecContext *avctx,
   if(MPV_frame_start(s, avctx) < 0)
       return -1;
 
+  pmv = av_malloc((FFALIGN(s->width, 16)/8 + 3) * sizeof(*pmv));
+  if (!pmv)
+      return -1;
+
   /* decode y, u and v components */
   for (i=0; i < 3; i++) {
     int linesize;
     if (i == 0) {
-      width  = (s->width+15)&~15;
-      height = (s->height+15)&~15;
+      width  = FFALIGN(s->width, 16);
+      height = FFALIGN(s->height, 16);
       linesize= s->linesize;
     } else {
       if(s->flags&CODEC_FLAG_GRAY) break;
-      width  = (s->width/4+15)&~15;
-      height = (s->height/4+15)&~15;
+      width  = FFALIGN(s->width/4, 16);
+      height = FFALIGN(s->height/4, 16);
       linesize= s->uvlinesize;
     }
 
@@ -724,13 +731,12 @@ static int svq1_decode_frame(AVCodecContext *avctx,
 //#ifdef DEBUG_SVQ1
             av_log(s->avctx, AV_LOG_INFO, "Error in svq1_decode_block %i (keyframe)\n",result);
 //#endif
-            return result;
+            goto err;
           }
         }
         current += 16*linesize;
       }
     } else {
-      svq1_pmv pmv[width/8+3];
       /* delta frame */
       memset (pmv, 0, ((width / 8) + 3) * sizeof(svq1_pmv));
 
@@ -743,7 +749,7 @@ static int svq1_decode_frame(AVCodecContext *avctx,
 #ifdef DEBUG_SVQ1
     av_log(s->avctx, AV_LOG_INFO, "Error in svq1_decode_delta_block %i\n",result);
 #endif
-            return result;
+            goto err;
           }
         }
 
@@ -761,13 +767,17 @@ static int svq1_decode_frame(AVCodecContext *avctx,
   MPV_frame_end(s);
 
   *data_size=sizeof(AVFrame);
-  return buf_size;
+  result = buf_size;
+err:
+  av_free(pmv);
+  return result;
 }
 
 static av_cold int svq1_decode_init(AVCodecContext *avctx)
 {
     MpegEncContext *s = avctx->priv_data;
     int i;
+    int offset = 0;
 
     MPV_decode_defaults(s);
 
@@ -780,30 +790,38 @@ static av_cold int svq1_decode_init(AVCodecContext *avctx)
     s->flags= avctx->flags;
     if (MPV_common_init(s) < 0) return -1;
 
-    init_vlc(&svq1_block_type, 2, 4,
+    INIT_VLC_STATIC(&svq1_block_type, 2, 4,
         &ff_svq1_block_type_vlc[0][1], 2, 1,
-        &ff_svq1_block_type_vlc[0][0], 2, 1, INIT_VLC_USE_STATIC);
+        &ff_svq1_block_type_vlc[0][0], 2, 1, 6);
 
-    init_vlc(&svq1_motion_component, 7, 33,
+    INIT_VLC_STATIC(&svq1_motion_component, 7, 33,
         &mvtab[0][1], 2, 1,
-        &mvtab[0][0], 2, 1, INIT_VLC_USE_STATIC);
+        &mvtab[0][0], 2, 1, 176);
 
     for (i = 0; i < 6; i++) {
+        static const uint8_t sizes[2][6] = {{14, 10, 14, 18, 16, 18}, {10, 10, 14, 14, 14, 16}};
+        static VLC_TYPE table[168][2];
+        svq1_intra_multistage[i].table = &table[offset];
+        svq1_intra_multistage[i].table_allocated = sizes[0][i];
+        offset += sizes[0][i];
         init_vlc(&svq1_intra_multistage[i], 3, 8,
             &ff_svq1_intra_multistage_vlc[i][0][1], 2, 1,
-            &ff_svq1_intra_multistage_vlc[i][0][0], 2, 1, INIT_VLC_USE_STATIC);
+            &ff_svq1_intra_multistage_vlc[i][0][0], 2, 1, INIT_VLC_USE_NEW_STATIC);
+        svq1_inter_multistage[i].table = &table[offset];
+        svq1_inter_multistage[i].table_allocated = sizes[1][i];
+        offset += sizes[1][i];
         init_vlc(&svq1_inter_multistage[i], 3, 8,
             &ff_svq1_inter_multistage_vlc[i][0][1], 2, 1,
-            &ff_svq1_inter_multistage_vlc[i][0][0], 2, 1, INIT_VLC_USE_STATIC);
+            &ff_svq1_inter_multistage_vlc[i][0][0], 2, 1, INIT_VLC_USE_NEW_STATIC);
     }
 
-    init_vlc(&svq1_intra_mean, 8, 256,
+    INIT_VLC_STATIC(&svq1_intra_mean, 8, 256,
         &ff_svq1_intra_mean_vlc[0][1], 4, 2,
-        &ff_svq1_intra_mean_vlc[0][0], 4, 2, INIT_VLC_USE_STATIC);
+        &ff_svq1_intra_mean_vlc[0][0], 4, 2, 632);
 
-    init_vlc(&svq1_inter_mean, 9, 512,
+    INIT_VLC_STATIC(&svq1_inter_mean, 9, 512,
         &ff_svq1_inter_mean_vlc[0][1], 4, 2,
-        &ff_svq1_inter_mean_vlc[0][0], 4, 2, INIT_VLC_USE_STATIC);
+        &ff_svq1_inter_mean_vlc[0][0], 4, 2, 1434);
 
     return 0;
 }
@@ -817,9 +835,9 @@ static av_cold int svq1_decode_end(AVCodecContext *avctx)
 }
 
 
-AVCodec svq1_decoder = {
+AVCodec ff_svq1_decoder = {
     "svq1",
-    CODEC_TYPE_VIDEO,
+    AVMEDIA_TYPE_VIDEO,
     CODEC_ID_SVQ1,
     sizeof(MpegEncContext),
     svq1_decode_init,
@@ -828,6 +846,6 @@ AVCodec svq1_decoder = {
     svq1_decode_frame,
     CODEC_CAP_DR1,
     .flush= ff_mpeg_flush,
-    .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV410P, PIX_FMT_NONE},
-    .long_name= NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 1"),
+    .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV410P, PIX_FMT_NONE},
+    .long_name= NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 1 / Sorenson Video 1 / SVQ1"),
 };