FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions | Variables
h264.c File Reference

H.264 / AVC / MPEG4 part10 codec. More...

#include "libavutil/avassert.h"
#include "libavutil/display.h"
#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
#include "libavutil/stereo3d.h"
#include "libavutil/timer.h"
#include "internal.h"
#include "bytestream.h"
#include "cabac.h"
#include "cabac_functions.h"
#include "error_resilience.h"
#include "avcodec.h"
#include "h264.h"
#include "h264data.h"
#include "h264chroma.h"
#include "h264_mvpred.h"
#include "golomb.h"
#include "mathops.h"
#include "me_cmp.h"
#include "mpegutils.h"
#include "profiles.h"
#include "rectangle.h"
#include "thread.h"
#include "vdpau_compat.h"

Go to the source code of this file.

Macros

#define UNCHECKED_BITSTREAM_READER   1
 
#define STARTCODE_TEST
 
#define OFFSET(x)   offsetof(H264Context, x)
 
#define VD   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
 

Functions

static int h264_decode_end (AVCodecContext *avctx)
 
int avpriv_h264_has_num_reorder_frames (AVCodecContext *avctx)
 
static void h264_er_decode_mb (void *opaque, int ref, int mv_dir, int mv_type, int(*mv)[2][4][2], int mb_x, int mb_y, int mb_intra, int mb_skipped)
 
void ff_h264_draw_horiz_band (const H264Context *h, H264SliceContext *sl, int y, int height)
 
const uint8_tff_h264_decode_nal (H264Context *h, H264SliceContext *sl, const uint8_t *src, int *dst_length, int *consumed, int length)
 Decode a network abstraction layer unit. More...
 
static int decode_rbsp_trailing (H264Context *h, const uint8_t *src)
 Identify the exact end of the bitstream. More...
 
void ff_h264_free_tables (H264Context *h)
 
int ff_h264_alloc_tables (H264Context *h)
 Allocate tables. More...
 
int ff_h264_slice_context_init (H264Context *h, H264SliceContext *sl)
 Init context Allocate buffers which are not shared amongst multiple threads. More...
 
static int decode_nal_units (H264Context *h, const uint8_t *buf, int buf_size, int parse_extradata)
 
static int decode_extradata_ps_mp4 (H264Context *h, const uint8_t *buf, int buf_size)
 
int ff_h264_decode_extradata (H264Context *h, const uint8_t *buf, int size)
 
static int h264_init_context (AVCodecContext *avctx, H264Context *h)
 
av_cold int ff_h264_decode_init (AVCodecContext *avctx)
 
static void decode_postinit (H264Context *h, int setup_finished)
 Run setup operations that must be run after slice header decoding. More...
 
static void idr (H264Context *h)
 instantaneous decoder refresh. More...
 
void ff_h264_flush_change (H264Context *h)
 
static void flush_dpb (AVCodecContext *avctx)
 
int ff_init_poc (H264Context *h, int pic_field_poc[2], int *pic_poc)
 
int ff_h264_get_profile (SPS *sps)
 Compute profile from profile_idc and constraint_set?_flags. More...
 
int ff_set_ref_count (H264Context *h, H264SliceContext *sl)
 
static int get_bit_length (H264Context *h, const uint8_t *buf, const uint8_t *ptr, int dst_length, int i, int next_avc)
 
static int get_last_needed_nal (H264Context *h, const uint8_t *buf, int buf_size)
 
static int get_consumed_bytes (int pos, int buf_size)
 Return the number of bytes consumed for building the current frame. More...
 
static int output_frame (H264Context *h, AVFrame *dst, H264Picture *srcp)
 
static int is_extra (const uint8_t *buf, int buf_size)
 
static int h264_decode_frame (AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
 
av_cold void ff_h264_free_context (H264Context *h)
 Free any data that may have been allocated in the H264 context like SPS, PPS etc. More...
 

Variables

const uint16_t ff_h264_mb_sizes [4] = { 256, 384, 512, 768 }
 
static AVOnce h264_vlc_init = AV_ONCE_INIT
 
static const uint8_t start_code [] = { 0x00, 0x00, 0x01 }
 
static const AVOption h264_options []
 
static const AVClass h264_class
 
AVCodec ff_h264_decoder
 

Detailed Description

H.264 / AVC / MPEG4 part10 codec.

Author
Michael Niedermayer micha.nosp@m.elni.nosp@m.@gmx..nosp@m.at

Definition in file h264.c.

Macro Definition Documentation

#define UNCHECKED_BITSTREAM_READER   1

Definition at line 28 of file h264.c.

#define STARTCODE_TEST
Value:
if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \
if (src[i + 2] != 3 && src[i + 2] != 0) { \
/* startcode, so we must be past the end */ \
length = i; \
} \
break; \
}
GLsizei GLsizei * length
Definition: opengl_enc.c:115
#define src
Definition: vp9dsp.c:530
if(ret< 0)
Definition: vf_mcdeint.c:282

Referenced by ff_h264_decode_nal().

#define OFFSET (   x)    offsetof(H264Context, x)

Definition at line 1880 of file h264.c.

Definition at line 1881 of file h264.c.

Function Documentation

static av_cold int h264_decode_end ( AVCodecContext avctx)
static

Definition at line 1865 of file h264.c.

Referenced by ff_h264_decode_init().

int avpriv_h264_has_num_reorder_frames ( AVCodecContext avctx)

Definition at line 59 of file h264.c.

Referenced by has_decode_delay_been_guessed().

static void h264_er_decode_mb ( void opaque,
int  ref,
int  mv_dir,
int  mv_type,
int(*)  mv[2][4][2],
int  mb_x,
int  mb_y,
int  mb_intra,
int  mb_skipped 
)
static

Definition at line 65 of file h264.c.

Referenced by ff_h264_slice_context_init().

void ff_h264_draw_horiz_band ( const H264Context h,
H264SliceContext sl,
int  y,
int  height 
)
const uint8_t* ff_h264_decode_nal ( H264Context h,
H264SliceContext sl,
const uint8_t src,
int *  dst_length,
int *  consumed,
int  length 
)

Decode a network abstraction layer unit.

Parameters
consumedis the number of bytes used as input
lengthis the length of the array
dst_lengthis the number of decoded bytes FIXME here or a decode rbsp tailing?
Returns
decoded bytes, might be src+1 if no escapes

Definition at line 136 of file h264.c.

Referenced by decode_nal_units(), get_last_needed_nal(), and parse_nal_units().

static int decode_rbsp_trailing ( H264Context h,
const uint8_t src 
)
static

Identify the exact end of the bitstream.

Returns
the length of the trailing, or 0 if damaged

Definition at line 250 of file h264.c.

Referenced by get_bit_length().

void ff_h264_free_tables ( H264Context h)
int ff_h264_alloc_tables ( H264Context h)

Allocate tables.

needs width/height

Definition at line 308 of file h264.c.

Referenced by h264_slice_header_init().

int ff_h264_slice_context_init ( H264Context h,
H264SliceContext sl 
)

Init context Allocate buffers which are not shared amongst multiple threads.

Definition at line 369 of file h264.c.

Referenced by h264_slice_header_init().

static int decode_nal_units ( H264Context h,
const uint8_t buf,
int  buf_size,
int  parse_extradata 
)
static

< number of NALs that need decoding before the next frame thread starts

Definition at line 1267 of file h264.c.

Referenced by decode_extradata_ps_mp4(), ff_h264_decode_extradata(), and h264_decode_frame().

static int decode_extradata_ps_mp4 ( H264Context h,
const uint8_t buf,
int  buf_size 
)
static

Definition at line 441 of file h264.c.

Referenced by ff_h264_decode_extradata().

int ff_h264_decode_extradata ( H264Context h,
const uint8_t buf,
int  size 
)

Definition at line 486 of file h264.c.

Referenced by ff_h264_decode_init(), h264_decode_frame(), and h264_parse().

static int h264_init_context ( AVCodecContext avctx,
H264Context h 
)
static

Definition at line 548 of file h264.c.

Referenced by ff_h264_decode_init().

av_cold int ff_h264_decode_init ( AVCodecContext avctx)

Definition at line 608 of file h264.c.

static void decode_postinit ( H264Context h,
int  setup_finished 
)
static

Run setup operations that must be run after slice header decoding.

This includes finding the next displayed frame.

Parameters
hh264 master context
setup_finishedenough NALs have been read that we can call ff_thread_finish_setup()

Definition at line 696 of file h264.c.

Referenced by decode_nal_units(), and h264_decode_frame().

static void idr ( H264Context h)
static

instantaneous decoder refresh.

Definition at line 961 of file h264.c.

Referenced by decode_nal_units(), ff_h264_flush_change(), and h264_probe().

void ff_h264_flush_change ( H264Context h)

Definition at line 974 of file h264.c.

Referenced by ff_h264_decode_init(), ff_h264_decode_slice_header(), and flush_dpb().

static void flush_dpb ( AVCodecContext avctx)
static

Definition at line 1003 of file h264.c.

int ff_init_poc ( H264Context h,
int  pic_field_poc[2],
int *  pic_poc 
)

Definition at line 1023 of file h264.c.

Referenced by ff_h264_decode_slice_header(), and parse_nal_units().

int ff_h264_get_profile ( SPS sps)

Compute profile from profile_idc and constraint_set?_flags.

compute profile from sps

Parameters
spsSPS
Returns
profile as defined by FF_PROFILE_H264_*

Definition at line 1108 of file h264.c.

Referenced by ff_h264_decode_slice_header(), and parse_nal_units().

int ff_set_ref_count ( H264Context h,
H264SliceContext sl 
)

Definition at line 1128 of file h264.c.

Referenced by ff_h264_decode_slice_header(), and scan_mmco_reset().

static int get_bit_length ( H264Context h,
const uint8_t buf,
const uint8_t ptr,
int  dst_length,
int  i,
int  next_avc 
)
static

Definition at line 1184 of file h264.c.

Referenced by decode_nal_units(), and get_last_needed_nal().

static int get_last_needed_nal ( H264Context h,
const uint8_t buf,
int  buf_size 
)
static

Definition at line 1203 of file h264.c.

Referenced by decode_nal_units().

static int get_consumed_bytes ( int  pos,
int  buf_size 
)
static

Return the number of bytes consumed for building the current frame.

Definition at line 1618 of file h264.c.

Referenced by h264_decode_frame().

static int output_frame ( H264Context h,
AVFrame dst,
H264Picture srcp 
)
static
Examples:
transcode_aac.c.

Definition at line 1628 of file h264.c.

Referenced by h264_decode_frame(), load_encode_and_write(), and scale_vaapi_filter_frame().

static int is_extra ( const uint8_t buf,
int  buf_size 
)
static

Definition at line 1662 of file h264.c.

Referenced by h264_decode_frame().

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

Definition at line 1684 of file h264.c.

av_cold void ff_h264_free_context ( H264Context h)

Free any data that may have been allocated in the H264 context like SPS, PPS etc.

Definition at line 1836 of file h264.c.

Referenced by h264_close(), and h264_decode_end().

Variable Documentation

const uint16_t ff_h264_mb_sizes[4] = { 256, 384, 512, 768 }

Definition at line 57 of file h264.c.

Referenced by ff_h264_decode_mb_cabac(), ff_h264_decode_mb_cavlc(), and hl_decode_mb().

AVOnce h264_vlc_init = AV_ONCE_INIT
static

Definition at line 606 of file h264.c.

const uint8_t start_code[] = { 0x00, 0x00, 0x01 }
static
const AVOption h264_options[]
static
Initial value:
= {
{"is_avc", "is avc", 0x42, AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, 0},
{"nal_length_size", "nal_length_size", 0x42, AV_OPT_TYPE_INT, {.i64 = 0}, 0, 4, 0},
{ "enable_er", "Enable error resilience on damaged frames (unsafe)", OFFSET(enable_er), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VD },
{ NULL },
}
#define NULL
Definition: coverity.c:32
#define OFFSET(x)
Definition: h264.c:1880
#define VD
Definition: h264.c:1881

Definition at line 1882 of file h264.c.

const AVClass h264_class
static
Initial value:
= {
.class_name = "H264 Decoder",
.item_name = av_default_item_name,
.option = h264_options,
}
#define LIBAVUTIL_VERSION_INT
Definition: version.h:70
av_default_item_name
static const AVOption h264_options[]
Definition: h264.c:1882

Definition at line 1889 of file h264.c.

AVCodec ff_h264_decoder
Initial value:
= {
.name = "h264",
.long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
.priv_data_size = sizeof(H264Context),
.close = h264_decode_end,
.capabilities = AV_CODEC_CAP_DR1 |
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
.init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy),
.priv_class = &h264_class,
}
static const AVClass h264_class
Definition: h264.c:1889
static void flush(AVCodecContext *avctx)
static int init_thread_copy(AVCodecContext *avctx)
Definition: tta.c:390
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
av_cold int ff_h264_decode_init(AVCodecContext *avctx)
Definition: h264.c:608
H264Context.
Definition: h264.h:513
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:975
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:40
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
static void flush_dpb(AVCodecContext *avctx)
Definition: h264.c:1003
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:1013
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
Definition: internal.h:215
static int h264_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: h264.c:1684
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: avcodec.h:1017
int ff_h264_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
Definition: h264_slice.c:393
static int h264_decode_end(AVCodecContext *avctx)
Definition: h264.c:1865
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
Definition: ccaption_dec.c:722
const AVProfile ff_h264_profiles[]
Definition: profiles.c:49
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:950

Definition at line 1896 of file h264.c.