FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
indeo3.c File Reference
#include "libavutil/imgutils.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "libavutil/thread.h"
#include "avcodec.h"
#include "codec_internal.h"
#include "decode.h"
#include "copy_block.h"
#include "bytestream.h"
#include "get_bits.h"
#include "hpeldsp.h"
#include "indeo3data.h"

Go to the source code of this file.

Data Structures

struct  Plane
 
struct  Cell
 
struct  Indeo3DecodeContext
 

Macros

#define BS_8BIT_PEL   (1 << 1)
 8-bit pixel bitdepth indicator More...
 
#define BS_KEYFRAME   (1 << 2)
 intra frame indicator More...
 
#define BS_MV_Y_HALF   (1 << 4)
 vertical mv halfpel resolution indicator More...
 
#define BS_MV_X_HALF   (1 << 5)
 horizontal mv halfpel resolution indicator More...
 
#define BS_NONREF   (1 << 8)
 nonref (discardable) frame indicator More...
 
#define BS_BUFFER   9
 indicates which of two frame buffers should be used More...
 
#define CELL_STACK_MAX   20
 
#define AVG_32(dst, src, ref)   AV_WN32A(dst, ((AV_RN32(src) + AV_RN32(ref)) >> 1) & 0x7F7F7F7FUL)
 
#define AVG_64(dst, src, ref)   AV_WN64A(dst, ((AV_RN64(src) + AV_RN64(ref)) >> 1) & 0x7F7F7F7F7F7F7F7FULL)
 
#define BUFFER_PRECHECK
 
#define RLE_BLOCK_COPY
 
#define RLE_BLOCK_COPY_8
 
#define RLE_LINES_COPY   copy_block4(dst, ref, row_offset, row_offset, num_lines << v_zoom)
 
#define RLE_LINES_COPY_M10
 
#define APPLY_DELTA_4
 
#define APPLY_DELTA_8
 
#define APPLY_DELTA_1011_INTER
 
#define SPLIT_CELL(size, new_size)   (new_size) = ((size) > 2) ? ((((size) + 2) >> 2) << 1) : 1
 
#define UPDATE_BITPOS(n)
 
#define RESYNC_BITSTREAM
 
#define CHECK_CELL
 
#define OS_HDR_ID   MKBETAG('F', 'R', 'M', 'H')
 

Enumerations

enum  {
  RLE_ESC_F9 = 249, RLE_ESC_FA = 250, RLE_ESC_FB = 251, RLE_ESC_FC = 252,
  RLE_ESC_FD = 253, RLE_ESC_FE = 254, RLE_ESC_FF = 255
}
 
enum  {
  IV3_NOERR = 0, IV3_BAD_RLE = 1, IV3_BAD_DATA = 2, IV3_BAD_COUNTER = 3,
  IV3_UNSUPPORTED = 4, IV3_OUT_OF_DATA = 5
}
 
enum  { H_SPLIT = 0, V_SPLIT = 1, INTRA_NULL = 2, INTER_DATA = 3 }
 

Functions

static av_cold void build_requant_tab (void)
 
static av_cold void free_frame_buffers (Indeo3DecodeContext *ctx)
 
static av_cold int allocate_frame_buffers (Indeo3DecodeContext *ctx, AVCodecContext *avctx, int luma_width, int luma_height)
 
static int copy_cell (Indeo3DecodeContext *ctx, Plane *plane, Cell *cell)
 Copy pixels of the cell(x + mv_x, y + mv_y) from the previous frame into the cell(x, y) in the current frame. More...
 
static uint64_t replicate64 (uint64_t a)
 
static uint32_t replicate32 (uint32_t a)
 
static void fill_64 (uint8_t *dst, const uint64_t pix, int32_t n, int32_t row_offset)
 
static int decode_cell_data (Indeo3DecodeContext *ctx, Cell *cell, uint8_t *block, uint8_t *ref_block, ptrdiff_t row_offset, int h_zoom, int v_zoom, int mode, const vqEntry *delta[2], int swap_quads[2], const uint8_t **data_ptr, const uint8_t *last_ptr)
 
static int decode_cell (Indeo3DecodeContext *ctx, AVCodecContext *avctx, Plane *plane, Cell *cell, const uint8_t *data_ptr, const uint8_t *last_ptr)
 Decode a vector-quantized cell. More...
 
static int parse_bintree (Indeo3DecodeContext *ctx, AVCodecContext *avctx, Plane *plane, int code, Cell *ref_cell, const int depth, const int strip_width)
 
static int decode_plane (Indeo3DecodeContext *ctx, AVCodecContext *avctx, Plane *plane, const uint8_t *data, int32_t data_size, int32_t strip_width)
 
static int decode_frame_headers (Indeo3DecodeContext *ctx, AVCodecContext *avctx, const uint8_t *buf, int buf_size)
 
static void output_plane (const Plane *plane, int buf_sel, uint8_t *dst, ptrdiff_t dst_pitch, int dst_height)
 Convert and output the current plane. More...
 
static av_cold int decode_init (AVCodecContext *avctx)
 
static int decode_frame (AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
 
static av_cold int decode_close (AVCodecContext *avctx)
 

Variables

static uint8_t requant_tab [8][128]
 
const FFCodec ff_indeo3_decoder
 

Detailed Description

This is a decoder for Intel Indeo Video v3. It is based on vector quantization, run-length coding and motion compensation. Known container formats: .avi and .mov Known FOURCCs: 'IV31', 'IV32'

See also
http://wiki.multimedia.cx/index.php?title=Indeo_3

Definition in file indeo3.c.

Macro Definition Documentation

◆ BS_8BIT_PEL

#define BS_8BIT_PEL   (1 << 1)

8-bit pixel bitdepth indicator

Definition at line 59 of file indeo3.c.

◆ BS_KEYFRAME

#define BS_KEYFRAME   (1 << 2)

intra frame indicator

Definition at line 60 of file indeo3.c.

◆ BS_MV_Y_HALF

#define BS_MV_Y_HALF   (1 << 4)

vertical mv halfpel resolution indicator

Definition at line 61 of file indeo3.c.

◆ BS_MV_X_HALF

#define BS_MV_X_HALF   (1 << 5)

horizontal mv halfpel resolution indicator

Definition at line 62 of file indeo3.c.

◆ BS_NONREF

#define BS_NONREF   (1 << 8)

nonref (discardable) frame indicator

Definition at line 63 of file indeo3.c.

◆ BS_BUFFER

#define BS_BUFFER   9

indicates which of two frame buffers should be used

Definition at line 64 of file indeo3.c.

◆ CELL_STACK_MAX

#define CELL_STACK_MAX   20

Definition at line 75 of file indeo3.c.

◆ AVG_32

#define AVG_32 (   dst,
  src,
  ref 
)    AV_WN32A(dst, ((AV_RN32(src) + AV_RN32(ref)) >> 1) & 0x7F7F7F7FUL)

Definition at line 291 of file indeo3.c.

◆ AVG_64

#define AVG_64 (   dst,
  src,
  ref 
)    AV_WN64A(dst, ((AV_RN64(src) + AV_RN64(ref)) >> 1) & 0x7F7F7F7F7F7F7F7FULL)

Definition at line 294 of file indeo3.c.

◆ BUFFER_PRECHECK

#define BUFFER_PRECHECK
Value:
if (*data_ptr >= last_ptr) \
return IV3_OUT_OF_DATA; \

Definition at line 345 of file indeo3.c.

◆ RLE_BLOCK_COPY

#define RLE_BLOCK_COPY
Value:
if (cell->mv_ptr || !skip_flag) \
copy_block4(dst, ref, row_offset, row_offset, 4 << v_zoom)

Definition at line 349 of file indeo3.c.

◆ RLE_BLOCK_COPY_8

#define RLE_BLOCK_COPY_8
Value:
pix64 = AV_RN64(ref);\
if (is_first_row) {/* special prediction case: top line of a cell */\
pix64 = replicate64(pix64);\
fill_64(dst + row_offset, pix64, 7, row_offset);\
AVG_64(dst, ref, dst + row_offset);\
fill_64(dst, pix64, 8, row_offset)

Definition at line 353 of file indeo3.c.

◆ RLE_LINES_COPY

#define RLE_LINES_COPY   copy_block4(dst, ref, row_offset, row_offset, num_lines << v_zoom)

Definition at line 362 of file indeo3.c.

◆ RLE_LINES_COPY_M10

#define RLE_LINES_COPY_M10
Value:
pix64 = AV_RN64(ref);\
if (is_top_of_cell) {\
pix64 = replicate64(pix64);\
fill_64(dst + row_offset, pix64, (num_lines << 1) - 1, row_offset);\
AVG_64(dst, ref, dst + row_offset);\
fill_64(dst, pix64, num_lines << 1, row_offset)

Definition at line 365 of file indeo3.c.

◆ APPLY_DELTA_4

#define APPLY_DELTA_4
Value:
AV_WN16A(dst + line_offset ,\
(AV_RN16(ref ) + delta_tab->deltas[dyad1]) & 0x7F7F);\
AV_WN16A(dst + line_offset + 2,\
(AV_RN16(ref + 2) + delta_tab->deltas[dyad2]) & 0x7F7F);\
if (mode >= 3) {\
if (is_top_of_cell && !cell->ypos) {\
AV_COPY32U(dst, dst + row_offset);\
} else {\
AVG_32(dst, ref, dst + row_offset);\
}\
}

Definition at line 374 of file indeo3.c.

◆ APPLY_DELTA_8

#define APPLY_DELTA_8
Value:
/* apply two 32-bit VQ deltas to next even line */\
if (is_top_of_cell) { \
AV_WN32A(dst + row_offset , \
(replicate32(AV_RN32(ref )) + delta_tab->deltas_m10[dyad1]) & 0x7F7F7F7F);\
AV_WN32A(dst + row_offset + 4, \
(replicate32(AV_RN32(ref + 4)) + delta_tab->deltas_m10[dyad2]) & 0x7F7F7F7F);\
} else { \
AV_WN32A(dst + row_offset , \
(AV_RN32(ref ) + delta_tab->deltas_m10[dyad1]) & 0x7F7F7F7F);\
AV_WN32A(dst + row_offset + 4, \
(AV_RN32(ref + 4) + delta_tab->deltas_m10[dyad2]) & 0x7F7F7F7F);\
} \
/* odd lines are not coded but rather interpolated/replicated */\
/* first line of the cell on the top of image? - replicate */\
/* otherwise - interpolate */\
if (is_top_of_cell && !cell->ypos) {\
AV_COPY64U(dst, dst + row_offset);\
AVG_64(dst, ref, dst + row_offset);

Definition at line 387 of file indeo3.c.

◆ APPLY_DELTA_1011_INTER

#define APPLY_DELTA_1011_INTER
Value:
if (mode == 10) { \
AV_WN32A(dst , \
(AV_RN32(dst ) + delta_tab->deltas_m10[dyad1]) & 0x7F7F7F7F);\
AV_WN32A(dst + 4 , \
(AV_RN32(dst + 4 ) + delta_tab->deltas_m10[dyad2]) & 0x7F7F7F7F);\
AV_WN32A(dst + row_offset , \
(AV_RN32(dst + row_offset ) + delta_tab->deltas_m10[dyad1]) & 0x7F7F7F7F);\
AV_WN32A(dst + row_offset + 4, \
(AV_RN32(dst + row_offset + 4) + delta_tab->deltas_m10[dyad2]) & 0x7F7F7F7F);\
} else { \
AV_WN16A(dst , \
(AV_RN16(dst ) + delta_tab->deltas[dyad1]) & 0x7F7F);\
AV_WN16A(dst + 2 , \
(AV_RN16(dst + 2 ) + delta_tab->deltas[dyad2]) & 0x7F7F);\
AV_WN16A(dst + row_offset , \
(AV_RN16(dst + row_offset ) + delta_tab->deltas[dyad1]) & 0x7F7F);\
AV_WN16A(dst + row_offset + 2, \
(AV_RN16(dst + row_offset + 2) + delta_tab->deltas[dyad2]) & 0x7F7F);\
}

Definition at line 409 of file indeo3.c.

◆ SPLIT_CELL

#define SPLIT_CELL (   size,
  new_size 
)    (new_size) = ((size) > 2) ? ((((size) + 2) >> 2) << 1) : 1

Definition at line 736 of file indeo3.c.

◆ UPDATE_BITPOS

#define UPDATE_BITPOS (   n)
Value:
ctx->skip_bits += (n); \
ctx->need_resync = 1

Definition at line 738 of file indeo3.c.

◆ RESYNC_BITSTREAM

#define RESYNC_BITSTREAM
Value:
if (ctx->need_resync && !(get_bits_count(&ctx->gb) & 7)) { \
skip_bits_long(&ctx->gb, ctx->skip_bits); \
ctx->skip_bits = 0; \
ctx->need_resync = 0; \
}

Definition at line 742 of file indeo3.c.

◆ CHECK_CELL

#define CHECK_CELL
Value:
if (curr_cell.xpos + curr_cell.width > (plane->width >> 2) || \
curr_cell.ypos + curr_cell.height > (plane->height >> 2)) { \
av_log(avctx, AV_LOG_ERROR, "Invalid cell: x=%d, y=%d, w=%d, h=%d\n", \
curr_cell.xpos, curr_cell.ypos, curr_cell.width, curr_cell.height); \
}

Definition at line 749 of file indeo3.c.

◆ OS_HDR_ID

#define OS_HDR_ID   MKBETAG('F', 'R', 'M', 'H')

Definition at line 898 of file indeo3.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
RLE_ESC_F9 

same as RLE_ESC_FA + do the same with next block

RLE_ESC_FA 

INTRA: skip block, INTER: copy data from reference.

RLE_ESC_FB 

apply null delta to N blocks / skip N blocks

RLE_ESC_FC 

same as RLE_ESC_FD + do the same with next block

RLE_ESC_FD 

apply null delta to all remaining lines of this block

RLE_ESC_FE 

apply null delta to all lines up to the 3rd line

RLE_ESC_FF 

apply null delta to all lines up to the 2nd line

Definition at line 47 of file indeo3.c.

◆ anonymous enum

anonymous enum
Enumerator
IV3_NOERR 
IV3_BAD_RLE 
IV3_BAD_DATA 
IV3_BAD_COUNTER 
IV3_UNSUPPORTED 
IV3_OUT_OF_DATA 

Definition at line 335 of file indeo3.c.

◆ anonymous enum

anonymous enum
Enumerator
H_SPLIT 
V_SPLIT 
INTRA_NULL 
INTER_DATA 

Definition at line 728 of file indeo3.c.

Function Documentation

◆ build_requant_tab()

static av_cold void build_requant_tab ( void  )
static

Definition at line 122 of file indeo3.c.

Referenced by decode_init().

◆ free_frame_buffers()

static av_cold void free_frame_buffers ( Indeo3DecodeContext ctx)
static

Definition at line 154 of file indeo3.c.

Referenced by decode_close(), and decode_frame_headers().

◆ allocate_frame_buffers()

static av_cold int allocate_frame_buffers ( Indeo3DecodeContext ctx,
AVCodecContext avctx,
int  luma_width,
int  luma_height 
)
static

Definition at line 168 of file indeo3.c.

Referenced by decode_frame_headers(), and decode_init().

◆ copy_cell()

static int copy_cell ( Indeo3DecodeContext ctx,
Plane plane,
Cell cell 
)
static

Copy pixels of the cell(x + mv_x, y + mv_y) from the previous frame into the cell(x, y) in the current frame.

Parameters
ctxpointer to the decoder context
planepointer to the plane descriptor
cellpointer to the cell descriptor

Definition at line 237 of file indeo3.c.

Referenced by decode_cell(), and parse_bintree().

◆ replicate64()

static uint64_t replicate64 ( uint64_t  a)
inlinestatic

Definition at line 302 of file indeo3.c.

◆ replicate32()

static uint32_t replicate32 ( uint32_t  a)
inlinestatic

Definition at line 313 of file indeo3.c.

◆ fill_64()

static void fill_64 ( uint8_t *  dst,
const uint64_t  pix,
int32_t  n,
int32_t  row_offset 
)
inlinestatic

Definition at line 326 of file indeo3.c.

◆ decode_cell_data()

static int decode_cell_data ( Indeo3DecodeContext ctx,
Cell cell,
uint8_t *  block,
uint8_t *  ref_block,
ptrdiff_t  row_offset,
int  h_zoom,
int  v_zoom,
int  mode,
const vqEntry delta[2],
int  swap_quads[2],
const uint8_t **  data_ptr,
const uint8_t *  last_ptr 
)
static

Definition at line 431 of file indeo3.c.

Referenced by decode_cell().

◆ decode_cell()

static int decode_cell ( Indeo3DecodeContext ctx,
AVCodecContext avctx,
Plane plane,
Cell cell,
const uint8_t *  data_ptr,
const uint8_t *  last_ptr 
)
static

Decode a vector-quantized cell.

It consists of several routines, each of which handles one or more "modes" with which a cell can be encoded.

Parameters
ctxpointer to the decoder context
avctxptr to the AVCodecContext
planepointer to the plane descriptor
cellpointer to the cell descriptor
data_ptrpointer to the compressed data
last_ptrpointer to the last byte to catch reads past end of buffer
Returns
number of consumed bytes or negative number in case of error

Definition at line 587 of file indeo3.c.

Referenced by parse_bintree().

◆ parse_bintree()

static int parse_bintree ( Indeo3DecodeContext ctx,
AVCodecContext avctx,
Plane plane,
int  code,
Cell ref_cell,
const int  depth,
const int  strip_width 
)
static

Definition at line 758 of file indeo3.c.

Referenced by decode_plane().

◆ decode_plane()

static int decode_plane ( Indeo3DecodeContext ctx,
AVCodecContext avctx,
Plane plane,
const uint8_t *  data,
int32_t  data_size,
int32_t  strip_width 
)
static

Definition at line 859 of file indeo3.c.

Referenced by decode_frame().

◆ decode_frame_headers()

static int decode_frame_headers ( Indeo3DecodeContext ctx,
AVCodecContext avctx,
const uint8_t *  buf,
int  buf_size 
)
static

Definition at line 900 of file indeo3.c.

Referenced by decode_frame().

◆ output_plane()

static void output_plane ( const Plane plane,
int  buf_sel,
uint8_t *  dst,
ptrdiff_t  dst_pitch,
int  dst_height 
)
static

Convert and output the current plane.

All pixel values will be upsampled by shifting right by one bit.

Parameters
[in]planepointer to the descriptor of the plane being processed
[in]buf_selindicates which frame buffer the input data stored in
[out]dstpointer to the buffer receiving converted pixels
[in]dst_pitchpitch for moving to the next y line
[in]dst_heightoutput plane height

Definition at line 1031 of file indeo3.c.

Referenced by decode_frame(), and render_slice().

◆ decode_init()

static av_cold int decode_init ( AVCodecContext avctx)
static

Definition at line 1056 of file indeo3.c.

◆ decode_frame()

static int decode_frame ( AVCodecContext avctx,
AVFrame frame,
int *  got_frame,
AVPacket avpkt 
)
static

Definition at line 1072 of file indeo3.c.

◆ decode_close()

static av_cold int decode_close ( AVCodecContext avctx)
static

Definition at line 1133 of file indeo3.c.

Variable Documentation

◆ requant_tab

uint8_t requant_tab[8][128]
static

Definition at line 115 of file indeo3.c.

Referenced by build_requant_tab(), and decode_cell().

◆ ff_indeo3_decoder

const FFCodec ff_indeo3_decoder
Initial value:
= {
.p.name = "indeo3",
CODEC_LONG_NAME("Intel Indeo 3"),
.p.type = AVMEDIA_TYPE_VIDEO,
.priv_data_size = sizeof(Indeo3DecodeContext),
.close = decode_close,
.p.capabilities = AV_CODEC_CAP_DR1,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}

Definition at line 1140 of file indeo3.c.

FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:43
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:266
decode_close
static av_cold int decode_close(AVCodecContext *avctx)
Definition: indeo3.c:1133
AV_RN16
#define AV_RN16(p)
Definition: intreadwrite.h:356
mode
Definition: swscale.c:52
AV_RN64
#define AV_RN64(p)
Definition: intreadwrite.h:364
AV_CODEC_ID_INDEO3
@ AV_CODEC_ID_INDEO3
Definition: codec_id.h:80
decode_frame
static int decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
Definition: indeo3.c:1072
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:311
ctx
AVFormatContext * ctx
Definition: movenc.c:49
decode_init
static av_cold int decode_init(AVCodecContext *avctx)
Definition: indeo3.c:1056
IV3_OUT_OF_DATA
@ IV3_OUT_OF_DATA
Definition: indeo3.c:341
AV_WN16A
#define AV_WN16A(p, v)
Definition: intreadwrite.h:530
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
AV_RN32
#define AV_RN32(p)
Definition: intreadwrite.h:360
Indeo3DecodeContext
Definition: indeo3.c:86
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
replicate64
static uint64_t replicate64(uint64_t a)
Definition: indeo3.c:302
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:117
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
replicate32
static uint32_t replicate32(uint32_t a)
Definition: indeo3.c:313
AVG_64
#define AVG_64(dst, src, ref)
Definition: indeo3.c:294
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
is_first_row
static int is_first_row(const VVCFrameContext *fc, const int rx, const int ry)
Definition: thread.c:169
fill_64
static void fill_64(uint8_t *dst, const uint64_t pix, int32_t n, int32_t row_offset)
Definition: indeo3.c:326