*/
#define BITSTREAM_READER_LE
+#include "libavutil/attributes.h"
#include "avcodec.h"
#include "get_bits.h"
+#include "mathops.h"
#include "ivi_common.h"
-#include "libavutil/common.h"
#include "ivi_dsp.h"
extern const IVIHuffDesc ff_ivi_mb_huff_desc[8]; ///< static macroblock huffman tables
uint16_t res;
if (nbits <= 8) {
- res = av_reverse[val] >> (8-nbits);
+ res = ff_reverse[val] >> (8-nbits);
} else
- res = ((av_reverse[val & 0xFF] << 8) + (av_reverse[val >> 8])) >> (16-nbits);
+ res = ((ff_reverse[val & 0xFF] << 8) + (ff_reverse[val >> 8])) >> (16-nbits);
return res;
}
return 0;
}
-void ff_ivi_process_empty_tile(AVCodecContext *avctx, IVIBandDesc *band,
- IVITile *tile, int32_t mv_scale)
+/**
+ * Handle empty tiles by performing data copying and motion
+ * compensation respectively.
+ *
+ * @param[in] avctx ptr to the AVCodecContext
+ * @param[in] band pointer to the band descriptor
+ * @param[in] tile pointer to the tile descriptor
+ * @param[in] mv_scale scaling factor for motion vectors
+ */
+static int ivi_process_empty_tile(AVCodecContext *avctx, IVIBandDesc *band,
+ IVITile *tile, int32_t mv_scale)
{
int x, y, need_mc, mbn, blk, num_blocks, mv_x, mv_y, mc_type;
int offs, mb_offset, row_offset;
void (*mc_no_delta_func)(int16_t *buf, const int16_t *ref_buf, uint32_t pitch,
int mc_type);
+ if (tile->num_MBs != IVI_MBs_PER_TILE(tile->width, tile->height, band->mb_size)) {
+ av_log(avctx, AV_LOG_ERROR, "Allocated tile size %d mismatches "
+ "parameters %d in ivi_process_empty_tile()\n",
+ tile->num_MBs, IVI_MBs_PER_TILE(tile->width, tile->height, band->mb_size));
+ return AVERROR_INVALIDDATA;
+ }
+
offs = tile->ypos * band->pitch + tile->xpos;
mb = tile->mbs;
ref_mb = tile->ref_mbs;
dst += band->pitch;
}
}
+
+ return 0;
}
#ifdef DEBUG
-uint16_t ivi_calc_band_checksum (IVIBandDesc *band)
+static uint16_t ivi_calc_band_checksum(IVIBandDesc *band)
{
int x, y;
int16_t *src, checksum;
return checksum;
}
-
-int ivi_check_band (IVIBandDesc *band, const uint8_t *ref, int pitch)
-{
- int x, y, result;
- uint8_t t1, t2;
- int16_t *src;
-
- src = band->buf;
- result = 0;
-
- for (y = 0; y < band->height; src += band->pitch, y++) {
- for (x = 0; x < band->width; x++) {
- t1 = av_clip(src[x] + 128, 0, 255);
- t2 = ref[x];
- if (t1 != t2) {
- av_log(NULL, AV_LOG_ERROR, "Data mismatch: row %d, column %d\n",
- y / band->blk_size, x / band->blk_size);
- result = -1;
- }
- }
- ref += pitch;
- }
-
- return result;
-}
#endif
void ff_ivi_output_plane(IVIPlaneDesc *plane, uint8_t *dst, int dst_pitch)
* @param[in] avctx ptr to the AVCodecContext
* @return result code: 0 = OK, -1 = error
*/
-static int decode_band(IVI45DecContext *ctx, int plane_num,
+static int decode_band(IVI45DecContext *ctx,
IVIBandDesc *band, AVCodecContext *avctx)
{
int result, i, t, idx1, idx2, pos;
}
tile->is_empty = get_bits1(&ctx->gb);
if (tile->is_empty) {
- ff_ivi_process_empty_tile(avctx, band, tile,
+ result = ivi_process_empty_tile(avctx, band, tile,
(ctx->planes[0].bands[0].mb_size >> 3) - (band->mb_size >> 3));
+ if (result < 0)
+ break;
av_dlog(avctx, "Empty tile encountered!\n");
} else {
tile->data_size = ff_ivi_dec_tile_data_size(&ctx->gb);
"Error while decoding picture header: %d\n", result);
return -1;
}
+ if (ctx->gop_invalid)
+ return AVERROR_INVALIDDATA;
if (ctx->gop_flags & IVI5_IS_PROTECTED) {
av_log(avctx, AV_LOG_ERROR, "Password-protected clip!\n");
if (ctx->is_nonnull_frame(ctx)) {
for (p = 0; p < 3; p++) {
for (b = 0; b < ctx->planes[p].num_bands; b++) {
- result = decode_band(ctx, p, &ctx->planes[p].bands[b], avctx);
+ result = decode_band(ctx, &ctx->planes[p].bands[b], avctx);
if (result) {
av_log(avctx, AV_LOG_ERROR,
"Error while decoding band: %d, plane: %d\n", b, p);
/* If the bidirectional mode is enabled, next I and the following P frame will */
/* be sent together. Unfortunately the approach below seems to be the only way */
/* to handle the B-frames mode. That's exactly the same Intel decoders do. */
- if (avctx->codec_id == CODEC_ID_INDEO4 && ctx->frame_type == 0/*FRAMETYPE_INTRA*/) {
+ if (avctx->codec_id == AV_CODEC_ID_INDEO4 && ctx->frame_type == 0/*FRAMETYPE_INTRA*/) {
while (get_bits(&ctx->gb, 8)); // skip version string
skip_bits_long(&ctx->gb, 64); // skip padding, TODO: implement correct 8-bytes alignment
if (get_bits_left(&ctx->gb) > 18 && show_bits(&ctx->gb, 18) == 0x3FFF8)
avctx->release_buffer(avctx, &ctx->frame);
ctx->frame.reference = 0;
+ avcodec_set_dimensions(avctx, ctx->planes[0].width, ctx->planes[0].height);
if ((result = avctx->get_buffer(avctx, &ctx->frame)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return result;
}
if (ctx->is_scalable) {
- if (avctx->codec_id == CODEC_ID_INDEO4)
- ff_ivi_recompose_haar(&ctx->planes[0], ctx->frame.data[0], ctx->frame.linesize[0], 4);
+ if (avctx->codec_id == AV_CODEC_ID_INDEO4)
+ ff_ivi_recompose_haar(&ctx->planes[0], ctx->frame.data[0], ctx->frame.linesize[0]);
else
- ff_ivi_recompose53 (&ctx->planes[0], ctx->frame.data[0], ctx->frame.linesize[0], 4);
+ ff_ivi_recompose53 (&ctx->planes[0], ctx->frame.data[0], ctx->frame.linesize[0]);
} else {
ff_ivi_output_plane(&ctx->planes[0], ctx->frame.data[0], ctx->frame.linesize[0]);
}
avctx->release_buffer(avctx, &ctx->frame);
#if IVI4_STREAM_ANALYSER
- if (avctx->codec_id == CODEC_ID_INDEO4) {
+ if (avctx->codec_id == AV_CODEC_ID_INDEO4) {
if (ctx->is_scalable)
av_log(avctx, AV_LOG_ERROR, "This video uses scalability mode!\n");
if (ctx->uses_tiling)