]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/ivi.c
vc1: skip motion compensation when data for last picture is invalid
[ffmpeg] / libavcodec / ivi.c
index 6086e2e6819eb361da14a709b799a365369c97f3..2ff4824c92db5a983afd712e45a87c65e744eda1 100644 (file)
 
 #include <inttypes.h>
 
-#define BITSTREAM_READER_LE
 #include "libavutil/attributes.h"
 #include "libavutil/timer.h"
+
+#define BITSTREAM_READER_LE
 #include "avcodec.h"
-#include "get_bits.h"
+#include "bitstream.h"
 #include "internal.h"
 #include "mathops.h"
 #include "ivi.h"
@@ -72,10 +73,10 @@ static VLC ivi_mb_vlc_tabs [8]; ///< static macroblock Huffman tables
 static VLC ivi_blk_vlc_tabs[8]; ///< static block Huffman tables
 
 typedef void (*ivi_mc_func) (int16_t *buf, const int16_t *ref_buf,
-                             uint32_t pitch, int mc_type);
+                             ptrdiff_t pitch, int mc_type);
 typedef void (*ivi_mc_avg_func) (int16_t *buf, const int16_t *ref_buf1,
                                  const int16_t *ref_buf2,
-                                 uint32_t pitch, int mc_type, int mc_type2);
+                                 ptrdiff_t pitch, int mc_type, int mc_type2);
 
 static int ivi_mc(IVIBandDesc *band, ivi_mc_func mc, ivi_mc_avg_func mc_avg,
                   int offs, int mv_x, int mv_y, int mv_x2, int mv_y2,
@@ -224,7 +225,7 @@ static int ivi_huff_desc_cmp(const IVIHuffDesc *desc1,
            memcmp(desc1->xbits, desc2->xbits, desc1->num_rows);
 }
 
-int ff_ivi_dec_huff_desc(GetBitContext *gb, int desc_coded, int which_tab,
+int ff_ivi_dec_huff_desc(BitstreamContext *bc, int desc_coded, int which_tab,
                          IVIHuffTab *huff_tab, AVCodecContext *avctx)
 {
     int i, result;
@@ -237,17 +238,17 @@ int ff_ivi_dec_huff_desc(GetBitContext *gb, int desc_coded, int which_tab,
         return 0;
     }
 
-    huff_tab->tab_sel = get_bits(gb, 3);
+    huff_tab->tab_sel = bitstream_read(bc, 3);
     if (huff_tab->tab_sel == 7) {
         /* custom huffman table (explicitly encoded) */
-        new_huff.num_rows = get_bits(gb, 4);
+        new_huff.num_rows = bitstream_read(bc, 4);
         if (!new_huff.num_rows) {
             av_log(avctx, AV_LOG_ERROR, "Empty custom Huffman table!\n");
             return AVERROR_INVALIDDATA;
         }
 
         for (i = 0; i < new_huff.num_rows; i++)
-            new_huff.xbits[i] = get_bits(gb, 4);
+            new_huff.xbits[i] = bitstream_read(bc, 4);
 
         /* Have we got the same custom table? Rebuild if not. */
         if (ivi_huff_desc_cmp(&new_huff, &huff_tab->cust_desc)) {
@@ -460,22 +461,22 @@ av_cold int ff_ivi_init_tiles(IVIPlaneDesc *planes,
  *  if (tile_data_size >= 255) than this field four is byte long: 0xFF X1 X2 X3
  *  where X1-X3 is size of the tile data
  *
- *  @param[in,out]  gb  the GetBit context
+ *  @param[in,out]  bc  the Bitstream context
  *  @return     size of the tile data in bytes
  */
-static int ivi_dec_tile_data_size(GetBitContext *gb)
+static int ivi_dec_tile_data_size(BitstreamContext *bc)
 {
     int    len;
 
     len = 0;
-    if (get_bits1(gb)) {
-        len = get_bits(gb, 8);
+    if (bitstream_read_bit(bc)) {
+        len = bitstream_read(bc, 8);
         if (len == 255)
-            len = get_bits_long(gb, 24);
+            len = bitstream_read(bc, 24);
     }
 
     /* align the bitstream reader on the byte boundary */
-    align_get_bits(gb);
+    bitstream_align(bc);
 
     return len;
 }
@@ -499,7 +500,7 @@ static int ivi_dc_transform(IVIBandDesc *band, int *prev_dc, int buf_offs,
     return 0;
 }
 
-static int ivi_decode_coded_blocks(GetBitContext *gb, IVIBandDesc *band,
+static int ivi_decode_coded_blocks(BitstreamContext *bc, IVIBandDesc *band,
                                    ivi_mc_func mc, ivi_mc_avg_func mc_avg,
                                    int mv_x, int mv_y,
                                    int mv_x2, int mv_y2,
@@ -535,16 +536,15 @@ static int ivi_decode_coded_blocks(GetBitContext *gb, IVIBandDesc *band,
     /* zero column flags */
     memset(col_flags, 0, sizeof(col_flags));
     while (scan_pos <= num_coeffs) {
-        sym = get_vlc2(gb, band->blk_vlc.tab->table,
-                       IVI_VLC_BITS, 1);
+        sym = bitstream_read_vlc(bc, band->blk_vlc.tab->table, IVI_VLC_BITS, 1);
         if (sym == rvmap->eob_sym)
             break; /* End of block */
 
         /* Escape - run/val explicitly coded using 3 vlc codes */
         if (sym == rvmap->esc_sym) {
-            run = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1) + 1;
-            lo  = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1);
-            hi  = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1);
+            run = bitstream_read_vlc(bc, band->blk_vlc.tab->table, IVI_VLC_BITS, 1) + 1;
+            lo  = bitstream_read_vlc(bc, band->blk_vlc.tab->table, IVI_VLC_BITS, 1);
+            hi  = bitstream_read_vlc(bc, band->blk_vlc.tab->table, IVI_VLC_BITS, 1);
             /* merge them and convert into signed val */
             val = IVI_TOSIGNED((hi << 6) | lo);
         } else {
@@ -600,12 +600,12 @@ static int ivi_decode_coded_blocks(GetBitContext *gb, IVIBandDesc *band,
  *  dequantize them, apply inverse transform and motion compensation
  *  in order to reconstruct the picture.
  *
- *  @param[in,out]  gb    the GetBit context
+ *  @param[in,out]  bc    the Bitstream context
  *  @param[in]      band  pointer to the band descriptor
  *  @param[in]      tile  pointer to the tile descriptor
  *  @return     result code: 0 - OK, -1 = error (corrupted blocks data)
  */
-static int ivi_decode_blocks(GetBitContext *gb, IVIBandDesc *band,
+static int ivi_decode_blocks(BitstreamContext *bc, IVIBandDesc *band,
                              IVITile *tile, AVCodecContext *avctx)
 {
     int mbn, blk, num_blocks, blk_size, ret, is_intra;
@@ -709,7 +709,7 @@ static int ivi_decode_blocks(GetBitContext *gb, IVIBandDesc *band,
             }
 
             if (cbp & 1) { /* block coded ? */
-                ret = ivi_decode_coded_blocks(gb, band, mc_with_delta_func,
+                ret = ivi_decode_coded_blocks(bc, band, mc_with_delta_func,
                                               mc_avg_with_delta_func,
                                               mv_x, mv_y, mv_x2, mv_y2,
                                               &prev_dc, is_intra,
@@ -738,7 +738,7 @@ static int ivi_decode_blocks(GetBitContext *gb, IVIBandDesc *band,
         }// for blk
     }// for mbn
 
-    align_get_bits(gb);
+    bitstream_align(bc);
 
     return 0;
 }
@@ -881,11 +881,11 @@ static uint16_t ivi_calc_band_checksum(IVIBandDesc *band)
  *  @param[out]  dst        pointer to the buffer receiving converted pixels
  *  @param[in]   dst_pitch  pitch for moving to the next y line
  */
-static void ivi_output_plane(IVIPlaneDesc *plane, uint8_t *dst, int dst_pitch)
+static void ivi_output_plane(IVIPlaneDesc *plane, uint8_t *dst, ptrdiff_t dst_pitch)
 {
     int             x, y;
     const int16_t   *src  = plane->bands[0].buf;
-    uint32_t        pitch = plane->bands[0].pitch;
+    ptrdiff_t       pitch = plane->bands[0].pitch;
 
     if (!src)
         return;
@@ -924,7 +924,7 @@ static int decode_band(IVI45DecContext *ctx,
         band->ref_buf   = band->bufs[ctx->ref_buf];
         band->b_ref_buf = 0;
     }
-    band->data_ptr  = ctx->frame_data + (get_bits_count(&ctx->gb) >> 3);
+    band->data_ptr  = ctx->frame_data + (bitstream_tell(&ctx->bc) >> 3);
 
     result = ctx->decode_band_hdr(ctx, band, avctx);
     if (result) {
@@ -948,7 +948,7 @@ static int decode_band(IVI45DecContext *ctx,
         FFSWAP(int16_t, band->rv_map->valtab[idx1], band->rv_map->valtab[idx2]);
     }
 
-    pos = get_bits_count(&ctx->gb);
+    pos = bitstream_tell(&ctx->bc);
 
     for (t = 0; t < band->num_tiles; t++) {
         tile = &band->tiles[t];
@@ -958,7 +958,7 @@ static int decode_band(IVI45DecContext *ctx,
                    band->mb_size, tile->mb_size);
             return AVERROR_INVALIDDATA;
         }
-        tile->is_empty = get_bits1(&ctx->gb);
+        tile->is_empty = bitstream_read_bit(&ctx->bc);
         if (tile->is_empty) {
             result = ivi_process_empty_tile(avctx, band, tile,
                                       (ctx->planes[0].bands[0].mb_size >> 3) - (band->mb_size >> 3));
@@ -966,7 +966,7 @@ static int decode_band(IVI45DecContext *ctx,
                 break;
             ff_dlog(avctx, "Empty tile encountered!\n");
         } else {
-            tile->data_size = ivi_dec_tile_data_size(&ctx->gb);
+            tile->data_size = ivi_dec_tile_data_size(&ctx->bc);
             if (!tile->data_size) {
                 av_log(avctx, AV_LOG_ERROR, "Tile data size is zero!\n");
                 return AVERROR_INVALIDDATA;
@@ -976,14 +976,14 @@ static int decode_band(IVI45DecContext *ctx,
             if (result < 0)
                 break;
 
-            result = ivi_decode_blocks(&ctx->gb, band, tile, avctx);
+            result = ivi_decode_blocks(&ctx->bc, band, tile, avctx);
             if (result < 0) {
                 av_log(avctx, AV_LOG_ERROR,
                        "Corrupted tile data encountered!\n");
                 break;
             }
 
-            if (((get_bits_count(&ctx->gb) - pos) >> 3) != tile->data_size) {
+            if (((bitstream_tell(&ctx->bc) - pos) >> 3) != tile->data_size) {
                 av_log(avctx, AV_LOG_ERROR,
                        "Tile data_size mismatch!\n");
                 result = AVERROR_INVALIDDATA;
@@ -1015,7 +1015,7 @@ static int decode_band(IVI45DecContext *ctx,
     }
 #endif
 
-    align_get_bits(&ctx->gb);
+    bitstream_align(&ctx->bc);
 
     return result;
 }
@@ -1029,7 +1029,7 @@ int ff_ivi_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     int             buf_size = avpkt->size;
     int             result, p, b;
 
-    init_get_bits(&ctx->gb, buf, buf_size * 8);
+    bitstream_init8(&ctx->bc, buf, buf_size);
     ctx->frame_data = buf;
     ctx->frame_size = buf_size;
 
@@ -1054,7 +1054,7 @@ int ff_ivi_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     }
 
     if (ctx->gop_flags & IVI5_IS_PROTECTED) {
-        avpriv_report_missing_feature(avctx, "Password-protected clip!\n");
+        avpriv_report_missing_feature(avctx, "Password-protected clip");
         return AVERROR_PATCHWELCOME;
     }
 
@@ -1121,18 +1121,34 @@ int ff_ivi_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     if (ctx->is_indeo4 && ctx->frame_type == IVI4_FRAMETYPE_INTRA) {
         int left;
 
-        while (get_bits(&ctx->gb, 8)); // skip version string
-        left = get_bits_count(&ctx->gb) & 0x18;
-        skip_bits_long(&ctx->gb, 64 - left);
-        if (get_bits_left(&ctx->gb) > 18 &&
-            show_bits_long(&ctx->gb, 21) == 0xBFFF8) { // syncheader + inter type
+        while (bitstream_read(&ctx->bc, 8)); // skip version string
+        left = bitstream_tell(&ctx->bc) & 0x18;
+        bitstream_skip(&ctx->bc, 64 - left);
+        if (bitstream_bits_left(&ctx->bc) > 18 &&
+            bitstream_peek(&ctx->bc, 21) == 0xBFFF8) { // syncheader + inter type
             AVPacket pkt;
-            pkt.data = avpkt->data + (get_bits_count(&ctx->gb) >> 3);
-            pkt.size = get_bits_left(&ctx->gb) >> 3;
+            pkt.data = avpkt->data + (bitstream_tell(&ctx->bc) >> 3);
+            pkt.size = bitstream_bits_left(&ctx->bc) >> 3;
             ff_ivi_decode_frame(avctx, ctx->p_frame, &ctx->got_p_frame, &pkt);
         }
     }
 
+    if (ctx->show_indeo4_info) {
+        if (ctx->is_scalable)
+            av_log(avctx, AV_LOG_DEBUG, "This video uses scalability mode\n");
+        if (ctx->uses_tiling)
+            av_log(avctx, AV_LOG_DEBUG, "This video uses local decoding\n");
+        if (ctx->has_b_frames)
+            av_log(avctx, AV_LOG_DEBUG, "This video contains B-frames\n");
+        if (ctx->has_transp)
+            av_log(avctx, AV_LOG_DEBUG, "Transparency mode is enabled\n");
+        if (ctx->uses_haar)
+            av_log(avctx, AV_LOG_DEBUG, "This video uses Haar transform\n");
+        if (ctx->uses_fullpel)
+            av_log(avctx, AV_LOG_DEBUG, "This video uses fullpel motion vectors\n");
+        ctx->show_indeo4_info = 0;
+    }
+
     return buf_size;
 }
 
@@ -1148,23 +1164,6 @@ av_cold int ff_ivi_decode_close(AVCodecContext *avctx)
     if (ctx->mb_vlc.cust_tab.table)
         ff_free_vlc(&ctx->mb_vlc.cust_tab);
 
-#if IVI4_STREAM_ANALYSER
-    if (ctx->is_indeo4) {
-    if (ctx->is_scalable)
-        av_log(avctx, AV_LOG_ERROR, "This video uses scalability mode!\n");
-    if (ctx->uses_tiling)
-        av_log(avctx, AV_LOG_ERROR, "This video uses local decoding!\n");
-    if (ctx->has_b_frames)
-        av_log(avctx, AV_LOG_ERROR, "This video contains B-frames!\n");
-    if (ctx->has_transp)
-        av_log(avctx, AV_LOG_ERROR, "Transparency mode is enabled!\n");
-    if (ctx->uses_haar)
-        av_log(avctx, AV_LOG_ERROR, "This video uses Haar transform!\n");
-    if (ctx->uses_fullpel)
-        av_log(avctx, AV_LOG_ERROR, "This video uses fullpel motion vectors!\n");
-    }
-#endif
-
     av_frame_free(&ctx->p_frame);
 
     return 0;