Libav
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/stereo3d.h"
#include "libavutil/timer.h"
#include "internal.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 "rectangle.h"
#include "svq3.h"
#include "thread.h"
#include <assert.h>

Go to the source code of this file.

Macros

#define STARTCODE_TEST
 

Functions

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 (H264Context *h, int y, int height)
 
int ff_h264_check_intra4x4_pred_mode (H264Context *h)
 Check if the top & left blocks are available if needed and change the dc mode so it only uses the available blocks. More...
 
int ff_h264_check_intra_pred_mode (H264Context *h, int mode, int is_chroma)
 Check if the top & left blocks are available if needed and change the dc mode so it only uses the available blocks. More...
 
const uint8_tff_h264_decode_nal (H264Context *h, 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 free_rbsp)
 
int ff_h264_alloc_tables (H264Context *h)
 Allocate tables. More...
 
int ff_h264_context_init (H264Context *h)
 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)
 
int ff_h264_decode_extradata (H264Context *h)
 
av_cold int ff_h264_decode_init (AVCodecContext *avctx)
 
static int decode_init_thread_copy (AVCodecContext *avctx)
 
static void decode_postinit (H264Context *h, int setup_finished)
 Run setup operations that must be run after slice header decoding. More...
 
int ff_pred_weight_table (H264Context *h)
 
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_h264_set_parameter_from_sps (H264Context *h)
 
int ff_set_ref_count (H264Context *h)
 
static int find_start_code (const uint8_t *buf, int buf_size, int buf_index, int next_avc)
 
static int get_avc_nalsize (H264Context *h, const uint8_t *buf, int buf_size, int *buf_index)
 
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, AVFrame *src)
 
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...
 
static av_cold int h264_decode_end (AVCodecContext *avctx)
 

Variables

const uint16_t ff_h264_mb_sizes [4] = { 256, 384, 512, 768 }
 
static const AVProfile profiles []
 
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

§ STARTCODE_TEST

#define STARTCODE_TEST
Value:
if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \
if (src[i + 2] != 3) { \
/* startcode, so we must be past the end */ \
length = i; \
} \
break; \
}

Referenced by ff_h264_decode_nal().

Function Documentation

§ h264_er_decode_mb()

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 54 of file h264.c.

Referenced by ff_h264_context_init().

§ ff_h264_draw_horiz_band()

void ff_h264_draw_horiz_band ( H264Context h,
int  y,
int  height 
)

§ ff_h264_check_intra4x4_pred_mode()

int ff_h264_check_intra4x4_pred_mode ( H264Context h)

Check if the top & left blocks are available if needed and change the dc mode so it only uses the available blocks.

Check if the top & left blocks are available if needed & change the dc mode so it only uses the available blocks.

Definition at line 128 of file h264.c.

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

§ ff_h264_check_intra_pred_mode()

int ff_h264_check_intra_pred_mode ( H264Context h,
int  mode,
int  is_chroma 
)

Check if the top & left blocks are available if needed and change the dc mode so it only uses the available blocks.

Check if the top & left blocks are available if needed & change the dc mode so it only uses the available blocks.

Definition at line 175 of file h264.c.

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

§ ff_h264_decode_nal()

const uint8_t* ff_h264_decode_nal ( H264Context h,
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 216 of file h264.c.

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

§ decode_rbsp_trailing()

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 328 of file h264.c.

Referenced by get_bit_length().

§ ff_h264_free_tables()

void ff_h264_free_tables ( H264Context h,
int  free_rbsp 
)

§ ff_h264_alloc_tables()

int ff_h264_alloc_tables ( H264Context h)

Allocate tables.

needs width/height

Definition at line 404 of file h264.c.

Referenced by ff_h264_update_thread_context(), h264_slice_header_init(), and svq3_decode_init().

§ ff_h264_context_init()

int ff_h264_context_init ( H264Context h)

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

Definition at line 469 of file h264.c.

Referenced by ff_h264_update_thread_context(), get_dct8x8_allowed(), and h264_slice_header_init().

§ decode_nal_units()

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

< thread context

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

Definition at line 1417 of file h264.c.

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

§ ff_h264_decode_extradata()

int ff_h264_decode_extradata ( H264Context h)

Definition at line 544 of file h264.c.

Referenced by ff_h264_decode_init(), and h264_parse().

§ ff_h264_decode_init()

av_cold int ff_h264_decode_init ( AVCodecContext avctx)

Definition at line 603 of file h264.c.

Referenced by svq3_decode_init().

§ decode_init_thread_copy()

static int decode_init_thread_copy ( AVCodecContext avctx)
static

Definition at line 680 of file h264.c.

§ decode_postinit()

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 707 of file h264.c.

Referenced by decode_nal_units(), and h264_decode_frame().

§ ff_pred_weight_table()

int ff_pred_weight_table ( H264Context h)

Definition at line 980 of file h264.c.

Referenced by ff_h264_decode_slice_header(), get_dct8x8_allowed(), and scan_mmco_reset().

§ idr()

static void idr ( H264Context h)
static

instantaneous decoder refresh.

Definition at line 1045 of file h264.c.

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

§ ff_h264_flush_change()

void ff_h264_flush_change ( H264Context h)

Definition at line 1055 of file h264.c.

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

§ flush_dpb()

static void flush_dpb ( AVCodecContext avctx)
static

Definition at line 1076 of file h264.c.

§ ff_init_poc()

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

Definition at line 1108 of file h264.c.

Referenced by ff_h264_decode_slice_header(), get_dct8x8_allowed(), and parse_nal_units().

§ ff_h264_get_profile()

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 1193 of file h264.c.

Referenced by ff_h264_decode_slice_header(), and parse_nal_units().

§ ff_h264_set_parameter_from_sps()

int ff_h264_set_parameter_from_sps ( H264Context h)

§ ff_set_ref_count()

int ff_set_ref_count ( H264Context h)

Definition at line 1253 of file h264.c.

Referenced by ff_h264_decode_slice_header(), get_dct8x8_allowed(), and scan_mmco_reset().

§ find_start_code()

static int find_start_code ( const uint8_t buf,
int  buf_size,
int  buf_index,
int  next_avc 
)
static

Definition at line 1307 of file h264.c.

Referenced by decode_nal_units(), and get_last_needed_nal().

§ get_avc_nalsize()

static int get_avc_nalsize ( H264Context h,
const uint8_t buf,
int  buf_size,
int *  buf_index 
)
static

Definition at line 1324 of file h264.c.

Referenced by decode_nal_units(), and get_last_needed_nal().

§ get_bit_length()

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 1342 of file h264.c.

Referenced by decode_nal_units(), and get_last_needed_nal().

§ get_last_needed_nal()

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

Definition at line 1361 of file h264.c.

Referenced by decode_nal_units().

§ get_consumed_bytes()

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 1703 of file h264.c.

Referenced by h264_decode_frame().

§ output_frame()

static int output_frame ( H264Context h,
AVFrame dst,
AVFrame src 
)
static

Definition at line 1713 of file h264.c.

Referenced by h264_decode_frame(), and load_encode_and_write().

§ h264_decode_frame()

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

Definition at line 1733 of file h264.c.

§ ff_h264_free_context()

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 1823 of file h264.c.

Referenced by close(), h264_decode_end(), and svq3_decode_end().

§ h264_decode_end()

static av_cold int h264_decode_end ( AVCodecContext avctx)
static

Definition at line 1836 of file h264.c.

Variable Documentation

§ ff_h264_mb_sizes

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

Definition at line 52 of file h264.c.

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

§ profiles

const AVProfile profiles[]
static
Initial value:
= {
{ FF_PROFILE_H264_BASELINE, "Baseline" },
{ FF_PROFILE_H264_CONSTRAINED_BASELINE, "Constrained Baseline" },
{ FF_PROFILE_H264_MAIN, "Main" },
{ FF_PROFILE_H264_EXTENDED, "Extended" },
{ FF_PROFILE_H264_HIGH, "High" },
{ FF_PROFILE_H264_HIGH_10, "High 10" },
{ FF_PROFILE_H264_HIGH_10_INTRA, "High 10 Intra" },
{ FF_PROFILE_H264_HIGH_422, "High 4:2:2" },
{ FF_PROFILE_H264_HIGH_422_INTRA, "High 4:2:2 Intra" },
{ FF_PROFILE_H264_HIGH_444, "High 4:4:4" },
{ FF_PROFILE_H264_HIGH_444_PREDICTIVE, "High 4:4:4 Predictive" },
{ FF_PROFILE_H264_HIGH_444_INTRA, "High 4:4:4 Intra" },
{ FF_PROFILE_H264_CAVLC_444, "CAVLC 4:4:4" },
}
#define FF_PROFILE_H264_MAIN
Definition: avcodec.h:2671
#define FF_PROFILE_H264_CAVLC_444
Definition: avcodec.h:2681
#define FF_PROFILE_H264_HIGH_444_PREDICTIVE
Definition: avcodec.h:2679
#define FF_PROFILE_H264_BASELINE
Definition: avcodec.h:2669
#define FF_PROFILE_H264_EXTENDED
Definition: avcodec.h:2672
#define FF_PROFILE_H264_HIGH_422
Definition: avcodec.h:2676
#define FF_PROFILE_H264_HIGH
Definition: avcodec.h:2673
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:2639
#define FF_PROFILE_H264_HIGH_422_INTRA
Definition: avcodec.h:2677
#define FF_PROFILE_H264_HIGH_10_INTRA
Definition: avcodec.h:2675
#define FF_PROFILE_H264_HIGH_444
Definition: avcodec.h:2678
#define FF_PROFILE_H264_HIGH_444_INTRA
Definition: avcodec.h:2680
#define FF_PROFILE_H264_CONSTRAINED_BASELINE
Definition: avcodec.h:2670
#define FF_PROFILE_H264_HIGH_10
Definition: avcodec.h:2674

Definition at line 1847 of file h264.c.

§ ff_h264_decoder

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),
.capabilities = CODEC_CAP_DR1 |
}
av_cold int ff_h264_decode_init(AVCodecContext *avctx)
Definition: h264.c:603
H264Context.
Definition: h264.h:303
static int decode_init_thread_copy(AVCodecContext *avctx)
Definition: h264.c:680
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:275
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:684
#define 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:713
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:145
static void flush_dpb(AVCodecContext *avctx)
Definition: h264.c:1076
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
Definition: internal.h:185
static int h264_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: h264.c:1733
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:490
int ff_h264_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
Definition: h264_slice.c:472
static av_cold int h264_decode_end(AVCodecContext *avctx)
Definition: h264.c:1836
#define CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: avcodec.h:759
#define CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:755
static av_cold void flush(AVCodecContext *avctx)
Flush (reset) the frame ID after seeking.
Definition: alsdec.c:1797
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:499
static const AVProfile profiles[]
Definition: h264.c:1847

Definition at line 1864 of file h264.c.