FFmpeg  4.0
Data Structures | Macros | Functions | Variables
vp3.c File Reference

On2 VP3 Video Decoder. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libavutil/imgutils.h"
#include "avcodec.h"
#include "get_bits.h"
#include "hpeldsp.h"
#include "internal.h"
#include "mathops.h"
#include "thread.h"
#include "videodsp.h"
#include "vp3data.h"
#include "vp3dsp.h"
#include "xiph.h"

Go to the source code of this file.

Data Structures

struct  Vp3Fragment
 
struct  Vp3DecodeContext
 

Macros

#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))
 

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 unpack_vectors (Vp3DecodeContext *s, GetBitContext *gb)
 
static int unpack_block_qpis (Vp3DecodeContext *s, GetBitContext *gb)
 
static int unpack_vlcs (Vp3DecodeContext *s, GetBitContext *gb, 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, 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, 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 int allocate_tables (AVCodecContext *avctx)
 Allocate tables for per-frame data in Vp3DecodeContext. More...
 
static av_cold int init_frames (Vp3DecodeContext *s)
 
static av_cold int vp3_decode_init (AVCodecContext *avctx)
 
static int update_frames (AVCodecContext *avctx)
 Release and shuffle frames after decode finishes. More...
 
static int ref_frame (Vp3DecodeContext *s, ThreadFrame *dst, ThreadFrame *src)
 
static int ref_frames (Vp3DecodeContext *dst, Vp3DecodeContext *src)
 
static int vp3_decode_frame (AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
 
static int read_huffman_tree (AVCodecContext *avctx, GetBitContext *gb)
 

Variables

static const int ModeAlphabet [6][CODING_MODE_COUNT]
 
static const uint8_t hilbert_offset [16][2]
 
AVCodec ff_vp3_decoder
 

Detailed Description

On2 VP3 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

◆ FRAGMENT_PIXELS

#define FRAGMENT_PIXELS   8

Definition at line 49 of file vp3.c.

Referenced by vp3_decode_init().

◆ SB_NOT_CODED

#define SB_NOT_CODED   0

Definition at line 58 of file vp3.c.

Referenced by unpack_superblocks().

◆ SB_PARTIALLY_CODED

#define SB_PARTIALLY_CODED   1

Definition at line 59 of file vp3.c.

Referenced by unpack_superblocks().

◆ SB_FULLY_CODED

#define SB_FULLY_CODED   2

Definition at line 60 of file vp3.c.

Referenced by unpack_superblocks().

◆ MAXIMUM_LONG_BIT_RUN

#define MAXIMUM_LONG_BIT_RUN   4129

Definition at line 65 of file vp3.c.

Referenced by unpack_block_qpis(), and unpack_superblocks().

◆ MODE_INTER_NO_MV

#define MODE_INTER_NO_MV   0

Definition at line 67 of file vp3.c.

Referenced by unpack_modes(), and unpack_superblocks().

◆ MODE_INTRA

#define MODE_INTRA   1

Definition at line 68 of file vp3.c.

Referenced by render_slice(), and unpack_modes().

◆ MODE_INTER_PLUS_MV

#define MODE_INTER_PLUS_MV   2

Definition at line 69 of file vp3.c.

Referenced by unpack_vectors().

◆ MODE_INTER_LAST_MV

#define MODE_INTER_LAST_MV   3

Definition at line 70 of file vp3.c.

Referenced by unpack_vectors().

◆ MODE_INTER_PRIOR_LAST

#define MODE_INTER_PRIOR_LAST   4

Definition at line 71 of file vp3.c.

Referenced by unpack_vectors().

◆ MODE_USING_GOLDEN

#define MODE_USING_GOLDEN   5

Definition at line 72 of file vp3.c.

Referenced by await_reference_row(), and render_slice().

◆ MODE_GOLDEN_MV

#define MODE_GOLDEN_MV   6

Definition at line 73 of file vp3.c.

Referenced by await_reference_row(), render_slice(), and unpack_vectors().

◆ MODE_INTER_FOURMV

#define MODE_INTER_FOURMV   7

Definition at line 74 of file vp3.c.

Referenced by unpack_vectors().

◆ CODING_MODE_COUNT

#define CODING_MODE_COUNT   8

Definition at line 75 of file vp3.c.

Referenced by unpack_modes().

◆ MODE_COPY

#define MODE_COPY   8

◆ MIN_DEQUANT_VAL

#define MIN_DEQUANT_VAL   2

Definition at line 130 of file vp3.c.

◆ TOKEN_EOB

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

Definition at line 211 of file vp3.c.

Referenced by unpack_vlcs().

◆ TOKEN_ZERO_RUN

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

Definition at line 212 of file vp3.c.

Referenced by unpack_vlcs().

◆ TOKEN_COEFF

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

Definition at line 213 of file vp3.c.

Referenced by unpack_vlcs().

◆ BLOCK_X

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

Referenced by unpack_modes(), and unpack_vectors().

◆ BLOCK_Y

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

Referenced by unpack_modes(), and unpack_vectors().

◆ 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;
const char * s
Definition: avisynth_c.h:768
#define MODE_COPY
Definition: vp3.c:78

Referenced by unpack_modes().

◆ COMPATIBLE_FRAME

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

Definition at line 1164 of file vp3.c.

Referenced by reverse_dc_prediction().

◆ DC_COEFF

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

Definition at line 1166 of file vp3.c.

Referenced by reverse_dc_prediction().

◆ PUL

#define PUL   8

Referenced by reverse_dc_prediction().

◆ PU

#define PU   4

Referenced by reverse_dc_prediction().

◆ PUR

#define PUR   2

Referenced by reverse_dc_prediction().

◆ PL

#define PL   1

Referenced by reverse_dc_prediction().

◆ TRANSPOSE

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

Referenced by vp3_decode_init().

Function Documentation

◆ theora_decode_header()

static int theora_decode_header ( AVCodecContext avctx,
GetBitContext gb 
)
static

◆ theora_decode_tables()

static int theora_decode_tables ( AVCodecContext avctx,
GetBitContext gb 
)
static

◆ free_tables()

static av_cold void free_tables ( AVCodecContext avctx)
static

Definition at line 268 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 282 of file vp3.c.

Referenced by read_huffman_tree(), and vp3_decode_end().

◆ vp3_decode_end()

static av_cold int vp3_decode_end ( AVCodecContext avctx)
static

Definition at line 294 of file vp3.c.

Referenced by allocate_tables(), read_huffman_tree(), and 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 336 of file vp3.c.

Referenced by allocate_tables().

◆ init_dequantizer()

static void init_dequantizer ( Vp3DecodeContext s,
int  qpi 
)
static

Definition at line 370 of file vp3.c.

Referenced by vp3_decode_frame().

◆ init_loop_filter()

static void init_loop_filter ( Vp3DecodeContext s)
static

Definition at line 412 of file vp3.c.

Referenced by vp3_decode_frame().

◆ unpack_superblocks()

static int unpack_superblocks ( Vp3DecodeContext s,
GetBitContext gb 
)
static

Definition at line 441 of file vp3.c.

Referenced by vp3_decode_frame().

◆ unpack_modes()

static int unpack_modes ( Vp3DecodeContext s,
GetBitContext gb 
)
static

Definition at line 593 of file vp3.c.

Referenced by vp3_decode_frame().

◆ unpack_vectors()

static int unpack_vectors ( Vp3DecodeContext s,
GetBitContext gb 
)
static

Definition at line 702 of file vp3.c.

Referenced by vp3_decode_frame().

◆ unpack_block_qpis()

static int unpack_block_qpis ( Vp3DecodeContext s,
GetBitContext gb 
)
static

Definition at line 880 of file vp3.c.

Referenced by vp3_decode_frame().

◆ unpack_vlcs()

static int unpack_vlcs ( Vp3DecodeContext s,
GetBitContext gb,
VLC table,
int  coeff_index,
int  plane,
int  eob_run 
)
static

Definition at line 934 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 1168 of file vp3.c.

Referenced by unpack_dct_coeffs(), and unpack_vlcs().

◆ unpack_dct_coeffs()

static int unpack_dct_coeffs ( Vp3DecodeContext s,
GetBitContext gb 
)
static

Definition at line 1066 of file vp3.c.

Referenced by vp3_decode_frame().

◆ apply_loop_filter()

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

Definition at line 1318 of file vp3.c.

Referenced by render_slice(), vc1_decode_p_blocks(), and vp3_decode_frame().

◆ vp3_dequant()

static int vp3_dequant ( Vp3DecodeContext s,
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 1385 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 1430 of file vp3.c.

Referenced by render_slice(), and vp3_decode_frame().

◆ await_reference_row()

static void await_reference_row ( Vp3DecodeContext s,
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 1472 of file vp3.c.

Referenced by render_slice().

◆ render_slice()

static void render_slice ( Vp3DecodeContext s,
int  slice 
)
static

Definition at line 1495 of file vp3.c.

Referenced by vp3_decode_frame().

◆ allocate_tables()

static av_cold int allocate_tables ( AVCodecContext avctx)
static

Allocate tables for per-frame data in Vp3DecodeContext.

Definition at line 1675 of file vp3.c.

Referenced by ref_frames(), and vp3_decode_init().

◆ init_frames()

static av_cold int init_frames ( Vp3DecodeContext s)
static

Definition at line 1712 of file vp3.c.

Referenced by read_huffman_tree(), and vp3_decode_init().

◆ vp3_decode_init()

static av_cold int vp3_decode_init ( AVCodecContext avctx)
static

Definition at line 1728 of file vp3.c.

Referenced by read_huffman_tree(), and vp3_decode_frame().

◆ update_frames()

static int update_frames ( AVCodecContext avctx)
static

Release and shuffle frames after decode finishes.

Definition at line 1908 of file vp3.c.

Referenced by ref_frames(), and vp3_decode_frame().

◆ ref_frame()

static int ref_frame ( Vp3DecodeContext s,
ThreadFrame dst,
ThreadFrame src 
)
static

Definition at line 1929 of file vp3.c.

Referenced by await_reference_row(), ref_frames(), vp56_add_predictors_dc(), and vp56_render_mb().

◆ ref_frames()

static int ref_frames ( Vp3DecodeContext dst,
Vp3DecodeContext src 
)
static

Definition at line 1937 of file vp3.c.

◆ vp3_decode_frame()

static int vp3_decode_frame ( AVCodecContext avctx,
void data,
int got_frame,
AVPacket avpkt 
)
static

Definition at line 2009 of file vp3.c.

Referenced by read_huffman_tree().

◆ read_huffman_tree()

static int read_huffman_tree ( AVCodecContext avctx,
GetBitContext gb 
)
static

Definition at line 2212 of file vp3.c.

Variable Documentation

◆ ModeAlphabet

const int ModeAlphabet[6][CODING_MODE_COUNT]
static

Definition at line 85 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 123 of file vp3.c.

Referenced by init_block_mapping(), and render_slice().

◆ ff_vp3_decoder

AVCodec ff_vp3_decoder
Initial value:
= {
.name = "vp3",
.long_name = NULL_IF_CONFIG_SMALL("On2 VP3"),
.priv_data_size = sizeof(Vp3DecodeContext),
.close = vp3_decode_end,
.init_thread_copy = ONLY_IF_THREADS_ENABLED(vp3_init_thread_copy),
.update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context),
}
static void flush(AVCodecContext *avctx)
static int init_thread_copy(AVCodecContext *avctx)
Definition: tta.c:392
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static av_cold int vp3_decode_init(AVCodecContext *avctx)
Definition: vp3.c:1728
static av_cold int vp3_decode_end(AVCodecContext *avctx)
Definition: vp3.c:294
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:42
static void vp3_decode_flush(AVCodecContext *avctx)
Definition: vp3.c:282
static int vp3_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: vp3.c:2009
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:1015
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
Definition: internal.h:225
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
Definition: avcodec.h:953
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:959

Definition at line 2579 of file vp3.c.