FFmpeg
Data Structures | Macros | Functions | Variables
bitstream.c File Reference
#include <inttypes.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "libavutil/avassert.h"
#include "libavutil/bswap.h"
#include "libavutil/common.h"
#include "libavutil/error.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/log.h"
#include "libavutil/mem.h"
#include "libavutil/qsort.h"
#include "mathops.h"
#include "put_bits.h"
#include "vlc.h"

Go to the source code of this file.

Data Structures

struct  VLCcode
 

Macros

#define GET_DATA(v, table, i, wrap, size)
 
#define LOCALBUF_ELEMS   1500
 
#define COPY(condition)
 

Functions

void ff_put_string (PutBitContext *pb, const char *string, int terminate_string)
 Put the string string in the bitstream. More...
 
void ff_copy_bits (PutBitContext *pb, const uint8_t *src, int length)
 Copy the content of src to the bitstream. More...
 
static int alloc_table (VLC *vlc, int size, int use_static)
 
static int vlc_common_init (VLC *vlc_arg, int nb_bits, int nb_codes, VLC **vlc, VLC *localvlc, VLCcode **buf, int flags)
 
static int compare_vlcspec (const void *a, const void *b)
 
static int build_table (VLC *vlc, int table_nb_bits, int nb_codes, VLCcode *codes, int flags)
 Build VLC decoding tables suitable for use with get_vlc(). More...
 
static int vlc_common_end (VLC *vlc, int nb_bits, int nb_codes, VLCcode *codes, int flags, VLC *vlc_arg, VLCcode localbuf[LOCALBUF_ELEMS])
 
int ff_init_vlc_sparse (VLC *vlc_arg, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags)
 
int ff_init_vlc_from_lengths (VLC *vlc_arg, int nb_bits, int nb_codes, const int8_t *lens, int lens_wrap, const void *symbols, int symbols_wrap, int symbols_size, int offset, int flags, void *logctx)
 Build VLC decoding tables suitable for use with get_vlc2() More...
 
void ff_free_vlc (VLC *vlc)
 

Variables

const uint8_t ff_log2_run [41]
 

Detailed Description

bitstream api.

Definition in file bitstream.c.

Macro Definition Documentation

◆ GET_DATA

#define GET_DATA (   v,
  table,
  i,
  wrap,
  size 
)
Value:
{ \
const uint8_t *ptr = (const uint8_t *)table + i * wrap; \
switch(size) { \
case 1: \
v = *(const uint8_t *)ptr; \
break; \
case 2: \
v = *(const uint16_t *)ptr; \
break; \
case 4: \
default: \
av_assert1(size == 4); \
v = *(const uint32_t *)ptr; \
break; \
} \
}

Definition at line 96 of file bitstream.c.

◆ LOCALBUF_ELEMS

#define LOCALBUF_ELEMS   1500

Definition at line 135 of file bitstream.c.

◆ COPY

#define COPY (   condition)
Value:
for (i = 0; i < nb_codes; i++) { \
unsigned len; \
GET_DATA(len, bits, i, bits_wrap, bits_size); \
if (!(condition)) \
continue; \
if (len > 3*nb_bits || len > 32) { \
av_log(NULL, AV_LOG_ERROR, "Too long VLC (%u) in init_vlc\n", len);\
if (buf != localbuf) \
av_free(buf); \
return AVERROR(EINVAL); \
} \
buf[j].bits = len; \
GET_DATA(buf[j].code, codes, i, codes_wrap, codes_size); \
if (buf[j].code >= (1LL<<buf[j].bits)) { \
av_log(NULL, AV_LOG_ERROR, "Invalid code %"PRIx32" for %d in " \
"init_vlc\n", buf[j].code, i); \
if (buf != localbuf) \
av_free(buf); \
return AVERROR(EINVAL); \
} \
buf[j].code = bitswap_32(buf[j].code); \
else \
buf[j].code <<= 32 - buf[j].bits; \
if (symbols) \
GET_DATA(buf[j].symbol, symbols, i, symbols_wrap, symbols_size) \
else \
buf[j].symbol = i; \
j++; \
}

Function Documentation

◆ ff_put_string()

void ff_put_string ( PutBitContext pb,
const char *  string,
int  terminate_string 
)

Put the string string in the bitstream.

Parameters
terminate_string0-terminates the written string if value is 1

Definition at line 59 of file bitstream.c.

Referenced by encode_frame(), encode_parse_info(), jpeg_put_comments(), mpeg4_encode_vol_header(), and put_pce().

◆ ff_copy_bits()

void ff_copy_bits ( PutBitContext pb,
const uint8_t *  src,
int  length 
)

Copy the content of src to the bitstream.

Parameters
lengththe number of bits of src to copy

Definition at line 69 of file bitstream.c.

Referenced by copy_bits(), encode_thread(), ff_mpeg4_merge_partitions(), merge_context_after_encode(), save_bits(), and svq1_encode_plane().

◆ alloc_table()

static int alloc_table ( VLC vlc,
int  size,
int  use_static 
)
static

Definition at line 115 of file bitstream.c.

Referenced by build_table(), and mp_decode_layer2().

◆ vlc_common_init()

static int vlc_common_init ( VLC vlc_arg,
int  nb_bits,
int  nb_codes,
VLC **  vlc,
VLC localvlc,
VLCcode **  buf,
int  flags 
)
static

Definition at line 145 of file bitstream.c.

Referenced by ff_init_vlc_from_lengths(), and ff_init_vlc_sparse().

◆ compare_vlcspec()

static int compare_vlcspec ( const void *  a,
const void *  b 
)
static

Definition at line 170 of file bitstream.c.

Referenced by ff_init_vlc_sparse().

◆ build_table()

static int build_table ( VLC vlc,
int  table_nb_bits,
int  nb_codes,
VLCcode codes,
int  flags 
)
static

Build VLC decoding tables suitable for use with get_vlc().

Parameters
vlcthe context to be initialized
table_nb_bitsmax length of vlc codes to store directly in this table (Longer codes are delegated to subtables.)
nb_codesnumber of elements in codes[]
codesdescriptions of the vlc codes These must be ordered such that codes going into the same subtable are contiguous. Sorting by VLCcode.code is sufficient, though not necessary.

Definition at line 189 of file bitstream.c.

Referenced by vlc_common_end().

◆ vlc_common_end()

static int vlc_common_end ( VLC vlc,
int  nb_bits,
int  nb_codes,
VLCcode codes,
int  flags,
VLC vlc_arg,
VLCcode  localbuf[LOCALBUF_ELEMS] 
)
static

Definition at line 278 of file bitstream.c.

Referenced by ff_init_vlc_from_lengths(), and ff_init_vlc_sparse().

◆ ff_init_vlc_sparse()

int ff_init_vlc_sparse ( VLC vlc_arg,
int  nb_bits,
int  nb_codes,
const void *  bits,
int  bits_wrap,
int  bits_size,
const void *  codes,
int  codes_wrap,
int  codes_size,
const void *  symbols,
int  symbols_wrap,
int  symbols_size,
int  flags 
)

◆ ff_init_vlc_from_lengths()

int ff_init_vlc_from_lengths ( VLC vlc,
int  nb_bits,
int  nb_codes,
const int8_t *  lens,
int  lens_wrap,
const void *  symbols,
int  symbols_wrap,
int  symbols_size,
int  offset,
int  flags,
void *  logctx 
)

Build VLC decoding tables suitable for use with get_vlc2()

This function takes lengths and symbols and calculates the codes from them. For this the input lengths and symbols have to be sorted according to "left nodes in the corresponding tree first".

Parameters
[in,out]vlcThe VLC to be initialized; table and table_allocated must have been set when initializing a static VLC, otherwise this will be treated as uninitialized.
[in]nb_bitsThe number of bits to use for the VLC table; higher values take up more memory and cache, but allow to read codes with fewer reads.
[in]nb_codesThe number of provided length and (if supplied) symbol entries.
[in]lensThe lengths of the codes. Entries > 0 correspond to valid codes; entries == 0 will be skipped and entries with len < 0 indicate that the tree is incomplete and has an open end of length -len at this position.
[in]lens_wrapStride (in bytes) of the lengths.
[in]symbolsThe symbols, i.e. what is returned from get_vlc2() when the corresponding code is encountered. May be NULL, then 0, 1, 2, 3, 4,... will be used.
[in]symbols_wrapStride (in bytes) of the symbols.
[in]symbols_sizeSize of the symbols. 1 and 2 are supported.
[in]offsetAn offset to apply to all the valid symbols.
[in]flagsA combination of the INIT_VLC_* flags; notice that INIT_VLC_INPUT_LE is pointless and ignored.

Definition at line 381 of file bitstream.c.

Referenced by atrac3_init_static_data(), atrac9_init_vlc(), build_canonical_huff(), build_huff(), build_vlc(), clv_init_static(), ff_mjpeg_build_vlc(), huff_build(), imc_init_static(), mobiclip_init_static(), mp_decode_frame(), mpc7_init_static(), mpeg4_init_static(), mpegaudiodec_common_init_static(), mss4_init_vlc(), on2avc_decode_init(), qdmc_init_static_data(), read_code_table(), rv10_build_vlc(), rv40_init_table(), rv40_init_tables(), smacker_decode_header_tree(), smka_decode_frame(), tm2_build_huff_table(), tscc2_init_vlc(), vp3_decode_init(), wma_decode_init(), and x8_init_vlc().

◆ ff_free_vlc()

void ff_free_vlc ( VLC vlc)

Variable Documentation

◆ ff_log2_run

const uint8_t ff_log2_run[41]
Initial value:
={
0, 0, 0, 0, 1, 1, 1, 1,
2, 2, 2, 2, 3, 3, 3, 3,
4, 4, 5, 5, 6, 6, 7, 7,
8, 9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,
24,
}

Definition at line 50 of file bitstream.c.

Referenced by decode_line_TMPL(), encode_line_TMPL(), ls_decode_line(), ls_encode_line(), and ls_encode_run().

AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
bitswap_32
static av_always_inline uint32_t bitswap_32(uint32_t x)
Definition: mathops.h:243
table
static const uint16_t table[]
Definition: prosumer.c:206
wrap
#define wrap(func)
Definition: neontest.h:65
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
bits
uint8_t bits
Definition: vp3data.h:141
NULL
#define NULL
Definition: coverity.c:32
INIT_VLC_INPUT_LE
#define INIT_VLC_INPUT_LE
Definition: vlc.h:91
size
int size
Definition: twinvq_data.h:10344
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
len
int len
Definition: vorbis_enc_data.h:426
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561