FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
vp3.c File Reference
#include "config_components.h"
#include <stddef.h>
#include <string.h>
#include "libavutil/emms.h"
#include "libavutil/imgutils.h"
#include "libavutil/mem.h"
#include "libavutil/mem_internal.h"
#include "libavutil/thread.h"
#include "avcodec.h"
#include "codec_internal.h"
#include "decode.h"
#include "get_bits.h"
#include "hpeldsp.h"
#include "internal.h"
#include "jpegquanttables.h"
#include "mathops.h"
#include "progressframe.h"
#include "refstruct.h"
#include "thread.h"
#include "videodsp.h"
#include "vp3data.h"
#include "vp4data.h"
#include "vp3dsp.h"
#include "xiph.h"

Go to the source code of this file.

Data Structures

struct  Vp3Fragment
 
struct  VP4Predictor
 
struct  HuffEntry
 
struct  HuffTable
 Used to store optimal huffman encoding results. More...
 
struct  CoeffVLCs
 
struct  Vp3DecodeContext
 

Macros

#define VP3_MV_VLC_BITS   6
 
#define VP4_MV_VLC_BITS   6
 
#define SUPERBLOCK_VLC_BITS   6
 
#define FRAGMENT_PIXELS   8
 
#define SB_NOT_CODED   0
 
#define SB_PARTIALLY_CODED   1
 
#define SB_FULLY_CODED   2
 
#define MAXIMUM_LONG_BIT_RUN   4129
 
#define MODE_INTER_NO_MV   0
 
#define MODE_INTRA   1
 
#define MODE_INTER_PLUS_MV   2
 
#define MODE_INTER_LAST_MV   3
 
#define MODE_INTER_PRIOR_LAST   4
 
#define MODE_USING_GOLDEN   5
 
#define MODE_GOLDEN_MV   6
 
#define MODE_INTER_FOURMV   7
 
#define CODING_MODE_COUNT   8
 
#define MODE_COPY   8
 
#define MIN_DEQUANT_VAL   2
 
#define TOKEN_EOB(eob_run)   ((eob_run) << 2)
 
#define TOKEN_ZERO_RUN(coeff, zero_run)   (((coeff) * 512) + ((zero_run) << 2) + 1)
 
#define TOKEN_COEFF(coeff)   (((coeff) * 4) + 2)
 
#define BLOCK_X   (2 * mb_x + (k & 1))
 
#define BLOCK_Y   (2 * mb_y + (k >> 1))
 
#define SET_CHROMA_MODES
 
#define COMPATIBLE_FRAME(x)   (compatible_frame[s->all_fragments[x].coding_method] == current_frame_type)
 
#define DC_COEFF(u)   s->all_fragments[u].dc
 
#define PUL   8
 
#define PU   4
 
#define PUR   2
 
#define PL   1
 
#define TRANSPOSE(x)   (((x) >> 3) | (((x) & 7) << 3))
 

Enumerations

enum  {
  VP4_DC_INTRA = 0, VP4_DC_INTER = 1, VP4_DC_GOLDEN = 2, NB_VP4_DC_TYPES,
  VP4_DC_UNDEFINED = NB_VP4_DC_TYPES
}
 

Functions

static int theora_decode_header (AVCodecContext *avctx, GetBitContext *gb)
 
static int theora_decode_tables (AVCodecContext *avctx, GetBitContext *gb)
 
static av_cold void free_tables (AVCodecContext *avctx)
 
static void vp3_decode_flush (AVCodecContext *avctx)
 
static av_cold int vp3_decode_end (AVCodecContext *avctx)
 
static int init_block_mapping (Vp3DecodeContext *s)
 This function sets up all of the various blocks mappings: superblocks <-> fragments, macroblocks <-> fragments, superblocks <-> macroblocks. More...
 
static void init_dequantizer (Vp3DecodeContext *s, int qpi)
 
static void init_loop_filter (Vp3DecodeContext *s)
 
static int unpack_superblocks (Vp3DecodeContext *s, GetBitContext *gb)
 
static int unpack_modes (Vp3DecodeContext *s, GetBitContext *gb)
 
static int vp4_get_mv (GetBitContext *gb, int axis, int last_motion)
 
static int unpack_vectors (Vp3DecodeContext *s, GetBitContext *gb)
 
static int unpack_block_qpis (Vp3DecodeContext *s, GetBitContext *gb)
 
static int get_eob_run (GetBitContext *gb, int token)
 
static int get_coeff (GetBitContext *gb, int token, int16_t *coeff)
 
static int unpack_vlcs (Vp3DecodeContext *s, GetBitContext *gb, const VLCElem *vlc_table, int coeff_index, int plane, int eob_run)
 
static void reverse_dc_prediction (Vp3DecodeContext *s, int first_fragment, int fragment_width, int fragment_height)
 
static int unpack_dct_coeffs (Vp3DecodeContext *s, GetBitContext *gb)
 
static void apply_loop_filter (Vp3DecodeContext *s, int plane, int ystart, int yend)
 
static int vp3_dequant (Vp3DecodeContext *s, const Vp3Fragment *frag, int plane, int inter, int16_t block[64])
 Pull DCT tokens from the 64 levels to decode and dequant the coefficients for the next block in coding order. More...
 
static void vp3_draw_horiz_band (Vp3DecodeContext *s, int y)
 called when all pixels up to row y are complete More...
 
static void await_reference_row (Vp3DecodeContext *s, const Vp3Fragment *fragment, int motion_y, int y)
 Wait for the reference frame of the current fragment. More...
 
static void render_slice (Vp3DecodeContext *s, int slice)
 
static av_cold void init_tables_once (void)
 
static av_cold int allocate_tables (AVCodecContext *avctx)
 Allocate tables for per-frame data in Vp3DecodeContext. More...
 
static av_cold void free_vlc_tables (FFRefStructOpaque unused, void *obj)
 
static av_cold int vp3_decode_init (AVCodecContext *avctx)
 
static void update_frames (AVCodecContext *avctx)
 Release and shuffle frames after decode finishes. More...
 
static int vp3_decode_frame (AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
 
static int read_huffman_tree (HuffTable *huff, GetBitContext *gb, int length, AVCodecContext *avctx)
 

Variables

static const int ModeAlphabet [6][CODING_MODE_COUNT]
 
static const uint8_t hilbert_offset [16][2]
 
static const uint8_t vp4_pred_block_type_map [8]
 
static VLCElem superblock_run_length_vlc [88]
 
static VLCElem fragment_run_length_vlc [56]
 
static VLCElem motion_vector_vlc [112]
 
static VLCElem mode_code_vlc [24+2108 *CONFIG_VP4_DECODER]
 
const FFCodec ff_vp3_decoder
 

Detailed Description

On2 VP3/VP4 Video Decoder

VP3 Video Decoder by Mike Melanson (mike at multimedia.cx) For more information about the VP3 coding process, visit: http://wiki.multimedia.cx/index.php?title=On2_VP3

Theora decoder by Alex Beregszaszi

Definition in file vp3.c.

Macro Definition Documentation

◆ VP3_MV_VLC_BITS

#define VP3_MV_VLC_BITS   6

Definition at line 61 of file vp3.c.

◆ VP4_MV_VLC_BITS

#define VP4_MV_VLC_BITS   6

Definition at line 62 of file vp3.c.

◆ SUPERBLOCK_VLC_BITS

#define SUPERBLOCK_VLC_BITS   6

Definition at line 63 of file vp3.c.

◆ FRAGMENT_PIXELS

#define FRAGMENT_PIXELS   8

Definition at line 65 of file vp3.c.

◆ SB_NOT_CODED

#define SB_NOT_CODED   0

Definition at line 74 of file vp3.c.

◆ SB_PARTIALLY_CODED

#define SB_PARTIALLY_CODED   1

Definition at line 75 of file vp3.c.

◆ SB_FULLY_CODED

#define SB_FULLY_CODED   2

Definition at line 76 of file vp3.c.

◆ MAXIMUM_LONG_BIT_RUN

#define MAXIMUM_LONG_BIT_RUN   4129

Definition at line 81 of file vp3.c.

◆ MODE_INTER_NO_MV

#define MODE_INTER_NO_MV   0

Definition at line 83 of file vp3.c.

◆ MODE_INTRA

#define MODE_INTRA   1

Definition at line 84 of file vp3.c.

◆ MODE_INTER_PLUS_MV

#define MODE_INTER_PLUS_MV   2

Definition at line 85 of file vp3.c.

◆ MODE_INTER_LAST_MV

#define MODE_INTER_LAST_MV   3

Definition at line 86 of file vp3.c.

◆ MODE_INTER_PRIOR_LAST

#define MODE_INTER_PRIOR_LAST   4

Definition at line 87 of file vp3.c.

◆ MODE_USING_GOLDEN

#define MODE_USING_GOLDEN   5

Definition at line 88 of file vp3.c.

◆ MODE_GOLDEN_MV

#define MODE_GOLDEN_MV   6

Definition at line 89 of file vp3.c.

◆ MODE_INTER_FOURMV

#define MODE_INTER_FOURMV   7

Definition at line 90 of file vp3.c.

◆ CODING_MODE_COUNT

#define CODING_MODE_COUNT   8

Definition at line 91 of file vp3.c.

◆ MODE_COPY

#define MODE_COPY   8

Definition at line 94 of file vp3.c.

◆ MIN_DEQUANT_VAL

#define MIN_DEQUANT_VAL   2

Definition at line 182 of file vp3.c.

◆ TOKEN_EOB

#define TOKEN_EOB (   eob_run)    ((eob_run) << 2)

Definition at line 281 of file vp3.c.

◆ TOKEN_ZERO_RUN

#define TOKEN_ZERO_RUN (   coeff,
  zero_run 
)    (((coeff) * 512) + ((zero_run) << 2) + 1)

Definition at line 282 of file vp3.c.

◆ TOKEN_COEFF

#define TOKEN_COEFF (   coeff)    (((coeff) * 4) + 2)

Definition at line 283 of file vp3.c.

◆ BLOCK_X

#define BLOCK_X   (2 * mb_x + (k & 1))

Definition at line 642 of file vp3.c.

◆ BLOCK_Y

#define BLOCK_Y   (2 * mb_y + (k >> 1))

Definition at line 643 of file vp3.c.

◆ SET_CHROMA_MODES

#define SET_CHROMA_MODES
Value:
if (frag[s->fragment_start[1]].coding_method != MODE_COPY) \
frag[s->fragment_start[1]].coding_method = coding_mode; \
if (frag[s->fragment_start[2]].coding_method != MODE_COPY) \
frag[s->fragment_start[2]].coding_method = coding_mode;

◆ COMPATIBLE_FRAME

#define COMPATIBLE_FRAME (   x)    (compatible_frame[s->all_fragments[x].coding_method] == current_frame_type)

Definition at line 1630 of file vp3.c.

◆ DC_COEFF

#define DC_COEFF (   u)    s->all_fragments[u].dc

Definition at line 1632 of file vp3.c.

◆ PUL

#define PUL   8

◆ PU

#define PU   4

◆ PUR

#define PUR   2

◆ PL

#define PL   1

◆ TRANSPOSE

#define TRANSPOSE (   x)    (((x) >> 3) | (((x) & 7) << 3))

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
VP4_DC_INTRA 
VP4_DC_INTER 
VP4_DC_GOLDEN 
NB_VP4_DC_TYPES 
VP4_DC_UNDEFINED 

Definition at line 146 of file vp3.c.

Function Documentation

◆ theora_decode_header()

static int theora_decode_header ( AVCodecContext avctx,
GetBitContext gb 
)
static

Referenced by vp3_decode_frame().

◆ theora_decode_tables()

static int theora_decode_tables ( AVCodecContext avctx,
GetBitContext gb 
)
static

Referenced by vp3_decode_frame().

◆ free_tables()

static av_cold void free_tables ( AVCodecContext avctx)
static

Definition at line 336 of file vp3.c.

Referenced by allocate_tables(), and vp3_decode_end().

◆ vp3_decode_flush()

static void vp3_decode_flush ( AVCodecContext avctx)
static

Definition at line 352 of file vp3.c.

Referenced by vp3_decode_end().

◆ vp3_decode_end()

static av_cold int vp3_decode_end ( AVCodecContext avctx)
static

Definition at line 361 of file vp3.c.

Referenced by vp3_decode_frame().

◆ init_block_mapping()

static int init_block_mapping ( Vp3DecodeContext s)
static

This function sets up all of the various blocks mappings: superblocks <-> fragments, macroblocks <-> fragments, superblocks <-> macroblocks.

Returns
0 is successful; returns 1 if anything went wrong.

Definition at line 385 of file vp3.c.

Referenced by allocate_tables().

◆ init_dequantizer()

static void init_dequantizer ( Vp3DecodeContext s,
int  qpi 
)
static

Definition at line 418 of file vp3.c.

◆ init_loop_filter()

static void init_loop_filter ( Vp3DecodeContext s)
static

Definition at line 460 of file vp3.c.

◆ unpack_superblocks()

static int unpack_superblocks ( Vp3DecodeContext s,
GetBitContext gb 
)
static

Definition at line 469 of file vp3.c.

◆ unpack_modes()

static int unpack_modes ( Vp3DecodeContext s,
GetBitContext gb 
)
static

Definition at line 785 of file vp3.c.

◆ vp4_get_mv()

static int vp4_get_mv ( GetBitContext gb,
int  axis,
int  last_motion 
)
static

Definition at line 888 of file vp3.c.

Referenced by unpack_vectors().

◆ unpack_vectors()

static int unpack_vectors ( Vp3DecodeContext s,
GetBitContext gb 
)
static

Definition at line 903 of file vp3.c.

◆ unpack_block_qpis()

static int unpack_block_qpis ( Vp3DecodeContext s,
GetBitContext gb 
)
static

Definition at line 1100 of file vp3.c.

◆ get_eob_run()

static int get_eob_run ( GetBitContext gb,
int  token 
)
inlinestatic

Definition at line 1143 of file vp3.c.

Referenced by unpack_vlcs().

◆ get_coeff()

static int get_coeff ( GetBitContext gb,
int  token,
int16_t *  coeff 
)
inlinestatic

Definition at line 1151 of file vp3.c.

Referenced by unpack_vlcs().

◆ unpack_vlcs()

static int unpack_vlcs ( Vp3DecodeContext s,
GetBitContext gb,
const VLCElem vlc_table,
int  coeff_index,
int  plane,
int  eob_run 
)
static

Definition at line 1179 of file vp3.c.

Referenced by unpack_dct_coeffs().

◆ reverse_dc_prediction()

static void reverse_dc_prediction ( Vp3DecodeContext s,
int  first_fragment,
int  fragment_width,
int  fragment_height 
)
static

Definition at line 1634 of file vp3.c.

Referenced by unpack_dct_coeffs().

◆ unpack_dct_coeffs()

static int unpack_dct_coeffs ( Vp3DecodeContext s,
GetBitContext gb 
)
static

Definition at line 1299 of file vp3.c.

◆ apply_loop_filter()

static void apply_loop_filter ( Vp3DecodeContext s,
int  plane,
int  ystart,
int  yend 
)
static

Definition at line 1783 of file vp3.c.

Referenced by render_slice(), and vc1_decode_p_blocks().

◆ vp3_dequant()

static int vp3_dequant ( Vp3DecodeContext s,
const Vp3Fragment frag,
int  plane,
int  inter,
int16_t  block[64] 
)
inlinestatic

Pull DCT tokens from the 64 levels to decode and dequant the coefficients for the next block in coding order.

Definition at line 1849 of file vp3.c.

Referenced by render_slice().

◆ vp3_draw_horiz_band()

static void vp3_draw_horiz_band ( Vp3DecodeContext s,
int  y 
)
static

called when all pixels up to row y are complete

Definition at line 1894 of file vp3.c.

Referenced by render_slice().

◆ await_reference_row()

static void await_reference_row ( Vp3DecodeContext s,
const Vp3Fragment fragment,
int  motion_y,
int  y 
)
static

Wait for the reference frame of the current fragment.

The progress value is in luma pixel rows.

Definition at line 1935 of file vp3.c.

Referenced by render_slice().

◆ render_slice()

static void render_slice ( Vp3DecodeContext s,
int  slice 
)
static

Definition at line 2056 of file vp3.c.

◆ init_tables_once()

static av_cold void init_tables_once ( void  )
static

Definition at line 2262 of file vp3.c.

Referenced by vp3_decode_init().

◆ allocate_tables()

static av_cold int allocate_tables ( AVCodecContext avctx)
static

Allocate tables for per-frame data in Vp3DecodeContext.

Definition at line 2305 of file vp3.c.

Referenced by vp3_decode_init().

◆ free_vlc_tables()

static av_cold void free_vlc_tables ( FFRefStructOpaque  unused,
void *  obj 
)
static

Definition at line 2349 of file vp3.c.

Referenced by vp3_decode_init().

◆ vp3_decode_init()

static av_cold int vp3_decode_init ( AVCodecContext avctx)
static

Definition at line 2357 of file vp3.c.

Referenced by vp3_decode_frame().

◆ update_frames()

static void update_frames ( AVCodecContext avctx)
static

Release and shuffle frames after decode finishes.

Definition at line 2504 of file vp3.c.

◆ vp3_decode_frame()

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

Definition at line 2566 of file vp3.c.

◆ read_huffman_tree()

static int read_huffman_tree ( HuffTable huff,
GetBitContext gb,
int  length,
AVCodecContext avctx 
)
static

Definition at line 2825 of file vp3.c.

Variable Documentation

◆ ModeAlphabet

const int ModeAlphabet[6][CODING_MODE_COUNT]
static

Definition at line 101 of file vp3.c.

Referenced by unpack_modes().

◆ hilbert_offset

const uint8_t hilbert_offset[16][2]
static
Initial value:
= {
{ 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 },
{ 0, 2 }, { 0, 3 }, { 1, 3 }, { 1, 2 },
{ 2, 2 }, { 2, 3 }, { 3, 3 }, { 3, 2 },
{ 3, 1 }, { 2, 1 }, { 2, 0 }, { 3, 0 }
}

Definition at line 139 of file vp3.c.

Referenced by init_block_mapping(), and render_slice().

◆ vp4_pred_block_type_map

const uint8_t vp4_pred_block_type_map[8]
static

◆ superblock_run_length_vlc

VLCElem superblock_run_length_vlc[88]
static

Definition at line 165 of file vp3.c.

Referenced by init_tables_once(), unpack_block_qpis(), and unpack_superblocks().

◆ fragment_run_length_vlc

VLCElem fragment_run_length_vlc[56]
static

Definition at line 166 of file vp3.c.

Referenced by init_tables_once(), and unpack_superblocks().

◆ motion_vector_vlc

VLCElem motion_vector_vlc[112]
static

Definition at line 167 of file vp3.c.

Referenced by init_tables_once(), and unpack_vectors().

◆ mode_code_vlc

VLCElem mode_code_vlc[24+2108 *CONFIG_VP4_DECODER]
static

Definition at line 170 of file vp3.c.

Referenced by init_tables_once(), and unpack_modes().

◆ ff_vp3_decoder

const FFCodec ff_vp3_decoder
Initial value:

Definition at line 3172 of file vp3.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
vp3_decode_flush
static void vp3_decode_flush(AVCodecContext *avctx)
Definition: vp3.c:352
MODE_INTER_PRIOR_LAST
#define MODE_INTER_PRIOR_LAST
Definition: vp3.c:87
VP4_DC_GOLDEN
@ VP4_DC_GOLDEN
Definition: vp3.c:149
VP4_DC_INTER
@ VP4_DC_INTER
Definition: vp3.c:148
MODE_INTER_LAST_MV
#define MODE_INTER_LAST_MV
Definition: vp3.c:86
FF_CODEC_CAP_USES_PROGRESSFRAMES
#define FF_CODEC_CAP_USES_PROGRESSFRAMES
The decoder might make use of the ProgressFrame API.
Definition: codec_internal.h:69
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:311
s
#define s(width, name)
Definition: cbs_vp9.c:198
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
MODE_USING_GOLDEN
#define MODE_USING_GOLDEN
Definition: vp3.c:88
MODE_INTER_FOURMV
#define MODE_INTER_FOURMV
Definition: vp3.c:90
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:110
VP4_DC_INTRA
@ VP4_DC_INTRA
Definition: vp3.c:147
UPDATE_THREAD_CONTEXT
#define UPDATE_THREAD_CONTEXT(func)
Definition: codec_internal.h:305
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
AV_CODEC_ID_VP3
@ AV_CODEC_ID_VP3
Definition: codec_id.h:81
MODE_INTRA
#define MODE_INTRA
Definition: vp3.c:84
vp3_decode_frame
static int vp3_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
Definition: vp3.c:2566
MODE_INTER_PLUS_MV
#define MODE_INTER_PLUS_MV
Definition: vp3.c:85
Vp3DecodeContext
Definition: vp3.c:198
MODE_COPY
#define MODE_COPY
Definition: vp3.c:94
MODE_GOLDEN_MV
#define MODE_GOLDEN_MV
Definition: vp3.c:89
MODE_INTER_NO_MV
#define MODE_INTER_NO_MV
Definition: vp3.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
vp3_decode_init
static av_cold int vp3_decode_init(AVCodecContext *avctx)
Definition: vp3.c:2357
AV_CODEC_CAP_DRAW_HORIZ_BAND
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
Definition: codec.h:44
vp3_decode_end
static av_cold int vp3_decode_end(AVCodecContext *avctx)
Definition: vp3.c:361