]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/bink.c
Add stereo rematrixing support to the AC-3 encoders.
[ffmpeg] / libavcodec / bink.c
index 1d59ea3118e25e8e932231c4a35a5cf529ba3996..5f2fc312bc77ded9274ebc58ca544cb13fe3525d 100644 (file)
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavcore/imgutils.h"
 #include "avcodec.h"
 #include "dsputil.h"
 #include "binkdata.h"
@@ -43,7 +44,7 @@ enum Sources {
     BINK_SRC_X_OFF,           ///< X components of motion value
     BINK_SRC_Y_OFF,           ///< Y components of motion value
     BINK_SRC_INTRA_DC,        ///< DC values for intrablocks with DCT
-    BINK_SRC_INTER_DC,        ///< DC values for intrablocks with DCT
+    BINK_SRC_INTER_DC,        ///< DC values for interblocks with DCT
     BINK_SRC_RUN,             ///< run lengths for special fill block
 
     BINK_NB_SRC
@@ -106,7 +107,7 @@ enum BlockTypes {
 };
 
 /**
- * Initializes length length in all bundles.
+ * Initialize length length in all bundles.
  *
  * @param c     decoder context
  * @param width plane width
@@ -131,7 +132,7 @@ static void init_lengths(BinkContext *c, int width, int bw)
 }
 
 /**
- * Allocates memory for bundles.
+ * Allocate memory for bundles.
  *
  * @param c decoder context
  */
@@ -151,7 +152,7 @@ static av_cold void init_bundles(BinkContext *c)
 }
 
 /**
- * Frees memory used by bundles.
+ * Free memory used by bundles.
  *
  * @param c decoder context
  */
@@ -163,7 +164,7 @@ static av_cold void free_bundles(BinkContext *c)
 }
 
 /**
- * Merges two consequent lists of equal size depending on bits read.
+ * Merge two consequent lists of equal size depending on bits read.
  *
  * @param gb   context for reading bits
  * @param dst  buffer where merged list will be written to
@@ -192,7 +193,7 @@ static void merge(GetBitContext *gb, uint8_t *dst, uint8_t *src, int size)
 }
 
 /**
- * Reads information about Huffman tree used to decode data.
+ * Read information about Huffman tree used to decode data.
  *
  * @param gb   context for reading bits
  * @param tree pointer for storing tree data
@@ -233,7 +234,7 @@ static void read_tree(GetBitContext *gb, Tree *tree)
 }
 
 /**
- * Prepares bundle for decoding data.
+ * Prepare bundle for decoding data.
  *
  * @param gb          context for reading bits
  * @param c           decoder context
@@ -324,7 +325,7 @@ static int read_motion_values(AVCodecContext *avctx, GetBitContext *gb, Bundle *
     return 0;
 }
 
-const uint8_t bink_rlelens[4] = { 4, 8, 12, 32 };
+static const uint8_t bink_rlelens[4] = { 4, 8, 12, 32 };
 
 static int read_block_types(AVCodecContext *avctx, GetBitContext *gb, Bundle *b)
 {
@@ -462,7 +463,7 @@ static int read_dcs(AVCodecContext *avctx, GetBitContext *gb, Bundle *b,
 }
 
 /**
- * Retrieves next value from bundle.
+ * Retrieve next value from bundle.
  *
  * @param c      decoder context
  * @param bundle bundle number
@@ -481,7 +482,7 @@ static inline int get_value(BinkContext *c, int bundle)
 }
 
 /**
- * Reads 8x8 block of DCT coefficients.
+ * Read 8x8 block of DCT coefficients.
  *
  * @param gb       context for reading bits
  * @param block    place for storing coefficients
@@ -583,7 +584,7 @@ static int read_dct_coeffs(GetBitContext *gb, DCTELEM block[64], const uint8_t *
 }
 
 /**
- * Reads 8x8 block with residue after motion compensation.
+ * Read 8x8 block with residue after motion compensation.
  *
  * @param gb          context for reading bits
  * @param block       place to store read data
@@ -681,8 +682,8 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
     int v, col[2];
     const uint8_t *scan;
     int xoff, yoff;
-    DECLARE_ALIGNED_16(DCTELEM, block[64]);
-    DECLARE_ALIGNED_16(uint8_t, ublock[64]);
+    LOCAL_ALIGNED_16(DCTELEM, block, [64]);
+    LOCAL_ALIGNED_16(uint8_t, ublock, [64]);
     int coordmap[64];
 
     const int stride = c->pic.linesize[plane_idx];
@@ -911,12 +912,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
 
     init_get_bits(&gb, pkt->data, bits_count);
     if (c->has_alpha) {
-        int aplane_bits = get_bits_long(&gb, 32) << 3;
-        if (aplane_bits <= 32 || (aplane_bits & 0x1F)) {
-            av_log(avctx, AV_LOG_ERROR, "Incorrect alpha plane size %d\n", aplane_bits);
+        if (c->version >= 'i')
+            skip_bits_long(&gb, 32);
+        if (bink_decode_plane(c, &gb, 3, 0) < 0)
             return -1;
-        }
-        skip_bits_long(&gb, aplane_bits - 32);
     }
     if (c->version >= 'i')
         skip_bits_long(&gb, 32);
@@ -958,7 +957,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
     }
     flags = AV_RL32(avctx->extradata);
     c->has_alpha = flags & BINK_FLAG_ALPHA;
-    c->swap_planes = c->version >= 'i';
+    c->swap_planes = c->version >= 'h';
     if (!bink_trees[15].table) {
         for (i = 0; i < 16; i++) {
             const int maxbits = bink_tree_lens[i][15];
@@ -973,11 +972,11 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
     c->pic.data[0] = NULL;
 
-    if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) {
+    if (av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0) {
         return 1;
     }
 
-    avctx->pix_fmt = PIX_FMT_YUV420P;
+    avctx->pix_fmt = c->has_alpha ? PIX_FMT_YUVA420P : PIX_FMT_YUV420P;
 
     avctx->idct_algo = FF_IDCT_BINK;
     dsputil_init(&c->dsp, avctx);
@@ -1003,7 +1002,7 @@ static av_cold int decode_end(AVCodecContext *avctx)
 
 AVCodec bink_decoder = {
     "binkvideo",
-    CODEC_TYPE_VIDEO,
+    AVMEDIA_TYPE_VIDEO,
     CODEC_ID_BINKVIDEO,
     sizeof(BinkContext),
     decode_init,