]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/huffyuvdec.c
hpel_motion_search: move code used for asserts under correct #if
[ffmpeg] / libavcodec / huffyuvdec.c
index 0946d3d47e72cf98e7b6264b28207d52d8296a77..9c92bf3875de005e024e8c6921788831ebfd674a 100644 (file)
@@ -6,20 +6,20 @@
  * see http://www.pcisys.net/~melanson/codecs/huffyuv.txt for a description of
  * the algorithm used
  *
- * This file is part of Libav.
+ * This file is part of FFmpeg.
  *
- * Libav is free software; you can redistribute it and/or
+ * 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.
  *
- * Libav 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 Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 static const unsigned char classic_shift_luma[classic_shift_luma_table_size + FF_INPUT_BUFFER_PADDING_SIZE] = {
   34,36,35,69,135,232,9,16,10,24,11,23,12,16,13,10,14,8,15,8,
   16,8,17,20,16,10,207,206,205,236,11,8,10,21,9,23,8,8,199,70,
-  69,68, 0
+  69,68, 0,
+  0,0,0,0,0,0,0,0,
 };
 
 #define classic_shift_chroma_table_size 59
 static const unsigned char classic_shift_chroma[classic_shift_chroma_table_size + FF_INPUT_BUFFER_PADDING_SIZE] = {
   66,36,37,38,39,40,41,75,76,77,110,239,144,81,82,83,84,85,118,183,
   56,57,88,89,56,89,154,57,58,57,26,141,57,56,58,57,58,57,184,119,
-  214,245,116,83,82,49,80,79,78,77,44,75,41,40,39,38,37,36,34, 0
+  214,245,116,83,82,49,80,79,78,77,44,75,41,40,39,38,37,36,34, 0,
+  0,0,0,0,0,0,0,0,
 };
 
 static const unsigned char classic_add_luma[256] = {
@@ -243,6 +245,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
     memset(s->vlc, 0, 3 * sizeof(VLC));
 
     avctx->coded_frame = &s->picture;
+    avcodec_get_frame_defaults(&s->picture);
     s->interlaced = s->height > 288;
 
     s->bgr32 = 1;
@@ -274,7 +277,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
         if ( read_huffman_tables(s, ((uint8_t*)avctx->extradata) + 4,
                                  avctx->extradata_size - 4) < 0)
-            return -1;
+            return AVERROR_INVALIDDATA;
     }else{
         switch (avctx->bits_per_coded_sample & 7) {
         case 1:
@@ -302,7 +305,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
         s->context = 0;
 
         if (read_old_huffman_tables(s) < 0)
-            return -1;
+            return AVERROR_INVALIDDATA;
     }
 
     switch (s->bitstream_bpp) {
@@ -328,7 +331,18 @@ static av_cold int decode_init(AVCodecContext *avctx)
         return AVERROR_INVALIDDATA;
     }
 
-    ff_huffyuv_alloc_temp(s);
+    if ((avctx->pix_fmt == AV_PIX_FMT_YUV422P || avctx->pix_fmt == AV_PIX_FMT_YUV420P) && avctx->width & 1) {
+        av_log(avctx, AV_LOG_ERROR, "width must be even for this colorspace\n");
+        return AVERROR_INVALIDDATA;
+    }
+    if (s->predictor == MEDIAN && avctx->pix_fmt == AV_PIX_FMT_YUV422P && avctx->width%4) {
+        av_log(avctx, AV_LOG_ERROR, "width must be a multiple of 4 this colorspace and predictor\n");
+        return AVERROR_INVALIDDATA;
+    }
+    if (ff_huffyuv_alloc_temp(s)) {
+        ff_huffyuv_common_end(s);
+        return AVERROR(ENOMEM);
+    }
 
     return 0;
 }
@@ -339,7 +353,10 @@ static av_cold int decode_init_thread_copy(AVCodecContext *avctx)
     int i;
 
     avctx->coded_frame= &s->picture;
-    ff_huffyuv_alloc_temp(s);
+    if (ff_huffyuv_alloc_temp(s)) {
+        ff_huffyuv_common_end(s);
+        return AVERROR(ENOMEM);
+    }
 
     for (i = 0; i < 6; i++)
         s->vlc[i].table = NULL;
@@ -347,10 +364,10 @@ static av_cold int decode_init_thread_copy(AVCodecContext *avctx)
     if (s->version == 2) {
         if (read_huffman_tables(s, ((uint8_t*)avctx->extradata) + 4,
                                 avctx->extradata_size) < 0)
-            return -1;
+            return AVERROR_INVALIDDATA;
     } else {
         if (read_old_huffman_tables(s) < 0)
-            return -1;
+            return AVERROR_INVALIDDATA;
     }
 
     return 0;
@@ -484,17 +501,16 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     const int height = s->height;
     int fake_ystride, fake_ustride, fake_vstride;
     AVFrame * const p = &s->picture;
-    int table_size = 0;
+    int table_size = 0, ret;
 
     AVFrame *picture = data;
 
-    av_fast_malloc(&s->bitstream_buffer,
+    av_fast_padded_malloc(&s->bitstream_buffer,
                    &s->bitstream_buffer_size,
-                   buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
+                   buf_size);
     if (!s->bitstream_buffer)
         return AVERROR(ENOMEM);
 
-    memset(s->bitstream_buffer + buf_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
     s->dsp.bswap_buf((uint32_t*)s->bitstream_buffer,
                      (const uint32_t*)buf, buf_size / 4);
 
@@ -502,19 +518,19 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
         ff_thread_release_buffer(avctx, p);
 
     p->reference = 0;
-    if (ff_thread_get_buffer(avctx, p) < 0) {
+    if ((ret = ff_thread_get_buffer(avctx, p)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
-        return -1;
+        return ret;
     }
 
     if (s->context) {
         table_size = read_huffman_tables(s, s->bitstream_buffer, buf_size);
         if (table_size < 0)
-            return -1;
+            return AVERROR_INVALIDDATA;
     }
 
     if ((unsigned)(buf_size-table_size) >= INT_MAX / 8)
-        return -1;
+        return AVERROR_INVALIDDATA;
 
     init_get_bits(&s->gb, s->bitstream_buffer+table_size,
                   (buf_size-table_size) * 8);
@@ -538,7 +554,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
 
             av_log(avctx, AV_LOG_ERROR,
                    "YUY2 output is not implemented yet\n");
-            return -1;
+            return AVERROR_PATCHWELCOME;
         } else {
 
             leftv = p->data[2][0] = get_bits(&s->gb, 8);
@@ -720,7 +736,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
         }else{
             av_log(avctx, AV_LOG_ERROR,
                    "BGR24 output is not implemented yet\n");
-            return -1;
+            return AVERROR_PATCHWELCOME;
         }
     }
     emms_c();