FFmpeg
Loading...
Searching...
No Matches
h264_slice.c File Reference

H.264 / AVC / MPEG-4 part10 codec. More...

#include "config_components.h"
#include "libavutil/avassert.h"
#include "libavutil/mem.h"
#include "libavutil/pixdesc.h"
#include "libavutil/timecode.h"
#include "decode.h"
#include "cabac.h"
#include "cabac_functions.h"
#include "error_resilience.h"
#include "avcodec.h"
#include "h264.h"
#include "h264dec.h"
#include "h264data.h"
#include "h264chroma.h"
#include "h264_ps.h"
#include "h274.h"
#include "golomb.h"
#include "mathops.h"
#include "mpegutils.h"
#include "rectangle.h"
#include "libavutil/refstruct.h"
#include "thread.h"
#include "threadframe.h"

Go to the source code of this file.

Macros

#define IN_RANGE(a, b, size)
 
#define REBASE_PICTURE(pic, new_ctx, old_ctx)
 
#define TRANSPOSE(x)
 
#define TRANSPOSE(x)
 
#define HWACCEL_MAX
 

Functions

static void release_unused_pictures (H264Context *h, int remove_current)
 
static int alloc_scratch_buffers (H264SliceContext *sl, int linesize)
 
static int init_table_pools (H264Context *h)
 
static int alloc_picture (H264Context *h, H264Picture *pic)
 
static int find_unused_picture (const H264Context *h)
 
static void copy_picture_range (H264Picture **to, H264Picture *const *from, int count, H264Context *new_base, const H264Context *old_base)
 
static void color_frame (AVFrame *frame, const int c[4])
 
static int h264_slice_header_init (H264Context *h)
 
int ff_h264_update_thread_context (AVCodecContext *dst, const AVCodecContext *src)
 
int ff_h264_update_thread_context_for_user (AVCodecContext *dst, const AVCodecContext *src)
 
static int h264_frame_start (H264Context *h)
 
static av_always_inline void backup_mb_border (const H264Context *h, H264SliceContext *sl, const uint8_t *src_y, const uint8_t *src_cb, const uint8_t *src_cr, int linesize, int uvlinesize, int simple)
 
static void implicit_weight_table (const H264Context *h, H264SliceContext *sl, int field)
 Initialize implicit_weight table.
 
static void init_scan_tables (H264Context *h)
 initialize scan tables
 
static enum AVPixelFormat get_pixel_format (H264Context *h, int force_callback, int data_partitioning)
 
static void init_dimensions (H264Context *h)
 
static enum AVPixelFormat non_j_pixfmt (enum AVPixelFormat a)
 
static void update_sps_depth (H264Context *h, const SPS *sps)
 
static int h264_init_ps (H264Context *h, const H264SliceContext *sl, int first_slice)
 
static int h264_export_frame_props (H264Context *h)
 
static int h264_select_output_frame (H264Context *h)
 
static int h264_field_start (H264Context *h, const H264SliceContext *sl, const H2645NAL *nal, int first_slice)
 
static int h264_slice_header_parse (const H264Context *h, H264SliceContext *sl, const H2645NAL *nal)
 
static int h264_slice_init (H264Context *h, H264SliceContext *sl, const H2645NAL *nal)
 
static int h264_parse_slice_id (const H264Context *h, H264SliceContext *sl)
 
int ff_h264_attach_slice_partition (const H264Context *h, H264SliceContext *sl, const H2645NAL *nal)
 Attach a slice data partition B or C to the slice started by partition A.
 
int ff_h264_queue_decode_slice (H264Context *h, const H2645NAL *nal, H264SliceContext **queued)
 Submit a slice for decoding.
 
int ff_h264_get_slice_type (const H264SliceContext *sl)
 Reconstruct bitstream slice_type.
 
static av_always_inline void fill_filter_caches_inter (const H264Context *h, H264SliceContext *sl, int mb_type, int top_xy, const int left_xy[LEFT_MBS], int top_type, const int left_type[LEFT_MBS], int mb_xy, int list)
 
static int fill_filter_caches (const H264Context *h, H264SliceContext *sl, int mb_type)
 
static void loop_filter (const H264Context *h, H264SliceContext *sl, int start_x, int end_x)
 
static void predict_field_decoding_flag (const H264Context *h, H264SliceContext *sl)
 
static void decode_finish_row (const H264Context *h, H264SliceContext *sl)
 Draw edges and report progress for the last MB row.
 
static void er_add_slice (H264SliceContext *sl, int startx, int starty, int endx, int endy, int status)
 
static int decode_slice (struct AVCodecContext *avctx, void *arg)
 
int ff_h264_execute_decode_slices (H264Context *h)
 Call decode_slice() for each context.
 

Variables

static const uint8_t field_scan [16+1]
 
static const uint8_t field_scan8x8 [64+1]
 
static const uint8_t field_scan8x8_cavlc [64+1]
 
static const uint8_t zigzag_scan8x8_cavlc [64+1]
 

Detailed Description

H.264 / AVC / MPEG-4 part10 codec.

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

Definition in file h264_slice.c.

Macro Definition Documentation

◆ IN_RANGE

#define IN_RANGE ( a,
b,
size )
Value:
(((void*)(a) >= (void*)(b)) && ((void*)(a) < (void*)((b) + (size))))
int a
#define b
Definition input.c:43
int size

Definition at line 288 of file h264_slice.c.

Referenced by copy_picture_range().

◆ REBASE_PICTURE

#define REBASE_PICTURE ( pic,
new_ctx,
old_ctx )
Value:
(((pic) && (pic) >= (old_ctx)->DPB && \
(pic) < (old_ctx)->DPB + H264_MAX_PICTURE_COUNT) ? \
&(new_ctx)->DPB[(pic) - (old_ctx)->DPB] : NULL)
#define NULL
Definition coverity.c:32
#define H264_MAX_PICTURE_COUNT
Definition h264dec.h:47

Definition at line 290 of file h264_slice.c.

Referenced by copy_picture_range(), and ff_h264_update_thread_context().

◆ TRANSPOSE [1/2]

#define TRANSPOSE ( x)
Value:
((x) >> 2) | (((x) << 2) & 0xF)

Referenced by init_scan_tables().

◆ TRANSPOSE [2/2]

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

◆ HWACCEL_MAX

#define HWACCEL_MAX
Value:
(CONFIG_H264_DXVA2_HWACCEL + \
(CONFIG_H264_D3D11VA_HWACCEL * 2) + \
CONFIG_H264_D3D12VA_HWACCEL + \
CONFIG_H264_NVDEC_HWACCEL + \
CONFIG_H264_NVDEC_CUARRAY_HWACCEL + \
CONFIG_H264_VAAPI_HWACCEL + \
CONFIG_H264_VIDEOTOOLBOX_HWACCEL + \
CONFIG_H264_VDPAU_HWACCEL + \
CONFIG_H264_VULKAN_HWACCEL)

Function Documentation

◆ release_unused_pictures()

static void release_unused_pictures ( H264Context * h,
int remove_current )
static

Definition at line 118 of file h264_slice.c.

Referenced by h264_field_start(), and h264_frame_start().

◆ alloc_scratch_buffers()

static int alloc_scratch_buffers ( H264SliceContext * sl,
int linesize )
static

Definition at line 131 of file h264_slice.c.

Referenced by decode_slice().

◆ init_table_pools()

static int init_table_pools ( H264Context * h)
static

Definition at line 163 of file h264_slice.c.

Referenced by alloc_picture().

◆ alloc_picture()

static int alloc_picture ( H264Context * h,
H264Picture * pic )
static

Definition at line 189 of file h264_slice.c.

Referenced by h264_frame_start().

◆ find_unused_picture()

static int find_unused_picture ( const H264Context * h)
static

Definition at line 276 of file h264_slice.c.

Referenced by h264_frame_start().

◆ copy_picture_range()

static void copy_picture_range ( H264Picture ** to,
H264Picture *const * from,
int count,
H264Context * new_base,
const H264Context * old_base )
static

Definition at line 295 of file h264_slice.c.

Referenced by ff_h264_update_thread_context().

◆ color_frame()

static void color_frame ( AVFrame * frame,
const int c[4] )
static

Definition at line 308 of file h264_slice.c.

Referenced by h264_field_start().

◆ h264_slice_header_init()

static int h264_slice_header_init ( H264Context * h)
static

Definition at line 993 of file h264_slice.c.

Referenced by ff_h264_update_thread_context(), and h264_init_ps().

◆ ff_h264_update_thread_context()

int ff_h264_update_thread_context ( AVCodecContext * dst,
const AVCodecContext * src )

Definition at line 340 of file h264_slice.c.

◆ ff_h264_update_thread_context_for_user()

int ff_h264_update_thread_context_for_user ( AVCodecContext * dst,
const AVCodecContext * src )

Definition at line 476 of file h264_slice.c.

◆ h264_frame_start()

static int h264_frame_start ( H264Context * h)
static

Definition at line 488 of file h264_slice.c.

Referenced by h264_field_start().

◆ backup_mb_border()

static av_always_inline void backup_mb_border ( const H264Context * h,
H264SliceContext * sl,
const uint8_t * src_y,
const uint8_t * src_cb,
const uint8_t * src_cr,
int linesize,
int uvlinesize,
int simple )
static

Definition at line 601 of file h264_slice.c.

Referenced by loop_filter().

◆ implicit_weight_table()

static void implicit_weight_table ( const H264Context * h,
H264SliceContext * sl,
int field )
static

Initialize implicit_weight table.

Parameters
field0/1 initialize the weight for interlaced MBAFF -1 initializes the rest

Definition at line 703 of file h264_slice.c.

Referenced by h264_slice_init().

◆ init_scan_tables()

static void init_scan_tables ( H264Context * h)
static

initialize scan tables

Definition at line 767 of file h264_slice.c.

Referenced by h264_slice_header_init().

◆ get_pixel_format()

static enum AVPixelFormat get_pixel_format ( H264Context * h,
int force_callback,
int data_partitioning )
static

Definition at line 801 of file h264_slice.c.

Referenced by h264_init_ps().

◆ init_dimensions()

static void init_dimensions ( H264Context * h)
static

Definition at line 953 of file h264_slice.c.

Referenced by h264_init_ps().

◆ non_j_pixfmt()

static enum AVPixelFormat non_j_pixfmt ( enum AVPixelFormat a)
static

Definition at line 1075 of file h264_slice.c.

Referenced by h264_init_ps().

◆ update_sps_depth()

static void update_sps_depth ( H264Context * h,
const SPS * sps )
static

Definition at line 1086 of file h264_slice.c.

Referenced by h264_init_ps().

◆ h264_init_ps()

static int h264_init_ps ( H264Context * h,
const H264SliceContext * sl,
int first_slice )
static

Definition at line 1121 of file h264_slice.c.

Referenced by h264_field_start().

◆ h264_export_frame_props()

static int h264_export_frame_props ( H264Context * h)
static

Definition at line 1239 of file h264_slice.c.

Referenced by h264_field_start().

◆ h264_select_output_frame()

static int h264_select_output_frame ( H264Context * h)
static

Definition at line 1363 of file h264_slice.c.

Referenced by h264_field_start().

◆ h264_field_start()

static int h264_field_start ( H264Context * h,
const H264SliceContext * sl,
const H2645NAL * nal,
int first_slice )
static

Definition at line 1465 of file h264_slice.c.

Referenced by ff_h264_queue_decode_slice().

◆ h264_slice_header_parse()

static int h264_slice_header_parse ( const H264Context * h,
H264SliceContext * sl,
const H2645NAL * nal )
static

Definition at line 1778 of file h264_slice.c.

Referenced by ff_h264_queue_decode_slice().

◆ h264_slice_init()

static int h264_slice_init ( H264Context * h,
H264SliceContext * sl,
const H2645NAL * nal )
static

Definition at line 1997 of file h264_slice.c.

Referenced by ff_h264_queue_decode_slice().

◆ h264_parse_slice_id()

static int h264_parse_slice_id ( const H264Context * h,
H264SliceContext * sl )
static

Definition at line 2152 of file h264_slice.c.

Referenced by ff_h264_queue_decode_slice().

◆ ff_h264_attach_slice_partition()

int ff_h264_attach_slice_partition ( const H264Context * h,
H264SliceContext * sl,
const H2645NAL * nal )

Attach a slice data partition B or C to the slice started by partition A.

Definition at line 2177 of file h264_slice.c.

Referenced by h264_attach_partitions().

◆ ff_h264_queue_decode_slice()

int ff_h264_queue_decode_slice ( H264Context * h,
const H2645NAL * nal,
H264SliceContext ** queued )

Submit a slice for decoding.

Parse the slice header, starting a new field/frame if necessary. If any slices are queued for the previous field, they are decoded.

Parameters
queuedset to the queued context, or NULL if the slice was discarded

Definition at line 2218 of file h264_slice.c.

Referenced by decode_nal_units().

◆ ff_h264_get_slice_type()

int ff_h264_get_slice_type ( const H264SliceContext * sl)

Reconstruct bitstream slice_type.

Definition at line 2356 of file h264_slice.c.

Referenced by fill_slice_long(), and vaapi_h264_decode_slice().

◆ fill_filter_caches_inter()

static av_always_inline void fill_filter_caches_inter ( const H264Context * h,
H264SliceContext * sl,
int mb_type,
int top_xy,
const int left_xy[LEFT_MBS],
int top_type,
const int left_type[LEFT_MBS],
int mb_xy,
int list )
static

Definition at line 2374 of file h264_slice.c.

Referenced by fill_filter_caches().

◆ fill_filter_caches()

static int fill_filter_caches ( const H264Context * h,
H264SliceContext * sl,
int mb_type )
static
Returns
non zero if the loop filter can be skipped

Definition at line 2458 of file h264_slice.c.

Referenced by loop_filter().

◆ loop_filter()

static void loop_filter ( const H264Context * h,
H264SliceContext * sl,
int start_x,
int end_x )
static

◆ predict_field_decoding_flag()

static void predict_field_decoding_flag ( const H264Context * h,
H264SliceContext * sl )
static

Definition at line 2670 of file h264_slice.c.

Referenced by decode_slice().

◆ decode_finish_row()

static void decode_finish_row ( const H264Context * h,
H264SliceContext * sl )
static

Draw edges and report progress for the last MB row.

Definition at line 2683 of file h264_slice.c.

Referenced by decode_slice().

◆ er_add_slice()

static void er_add_slice ( H264SliceContext * sl,
int startx,
int starty,
int endx,
int endy,
int status )
static

Definition at line 2714 of file h264_slice.c.

Referenced by decode_slice().

◆ decode_slice()

static int decode_slice ( struct AVCodecContext * avctx,
void * arg )
static

Definition at line 2726 of file h264_slice.c.

Referenced by ff_h264_execute_decode_slices().

◆ ff_h264_execute_decode_slices()

int ff_h264_execute_decode_slices ( H264Context * h)

Call decode_slice() for each context.

Parameters
hh264 master context

Definition at line 2938 of file h264_slice.c.

Referenced by decode_nal_units(), and ff_h264_queue_decode_slice().

Variable Documentation

◆ field_scan

const uint8_t field_scan[16+1]
static
Initial value:
= {
0 + 0 * 4, 0 + 1 * 4, 1 + 0 * 4, 0 + 2 * 4,
0 + 3 * 4, 1 + 1 * 4, 1 + 2 * 4, 1 + 3 * 4,
2 + 0 * 4, 2 + 1 * 4, 2 + 2 * 4, 2 + 3 * 4,
3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4, 3 + 3 * 4,
}

Definition at line 53 of file h264_slice.c.

Referenced by init_scan_tables().

◆ field_scan8x8

const uint8_t field_scan8x8[64+1]
static
Initial value:
= {
0 + 0 * 8, 0 + 1 * 8, 0 + 2 * 8, 1 + 0 * 8,
1 + 1 * 8, 0 + 3 * 8, 0 + 4 * 8, 1 + 2 * 8,
2 + 0 * 8, 1 + 3 * 8, 0 + 5 * 8, 0 + 6 * 8,
0 + 7 * 8, 1 + 4 * 8, 2 + 1 * 8, 3 + 0 * 8,
2 + 2 * 8, 1 + 5 * 8, 1 + 6 * 8, 1 + 7 * 8,
2 + 3 * 8, 3 + 1 * 8, 4 + 0 * 8, 3 + 2 * 8,
2 + 4 * 8, 2 + 5 * 8, 2 + 6 * 8, 2 + 7 * 8,
3 + 3 * 8, 4 + 1 * 8, 5 + 0 * 8, 4 + 2 * 8,
3 + 4 * 8, 3 + 5 * 8, 3 + 6 * 8, 3 + 7 * 8,
4 + 3 * 8, 5 + 1 * 8, 6 + 0 * 8, 5 + 2 * 8,
4 + 4 * 8, 4 + 5 * 8, 4 + 6 * 8, 4 + 7 * 8,
5 + 3 * 8, 6 + 1 * 8, 6 + 2 * 8, 5 + 4 * 8,
5 + 5 * 8, 5 + 6 * 8, 5 + 7 * 8, 6 + 3 * 8,
7 + 0 * 8, 7 + 1 * 8, 6 + 4 * 8, 6 + 5 * 8,
6 + 6 * 8, 6 + 7 * 8, 7 + 2 * 8, 7 + 3 * 8,
7 + 4 * 8, 7 + 5 * 8, 7 + 6 * 8, 7 + 7 * 8,
}

Definition at line 60 of file h264_slice.c.

Referenced by init_scan_tables().

◆ field_scan8x8_cavlc

const uint8_t field_scan8x8_cavlc[64+1]
static
Initial value:
= {
0 + 0 * 8, 1 + 1 * 8, 2 + 0 * 8, 0 + 7 * 8,
2 + 2 * 8, 2 + 3 * 8, 2 + 4 * 8, 3 + 3 * 8,
3 + 4 * 8, 4 + 3 * 8, 4 + 4 * 8, 5 + 3 * 8,
5 + 5 * 8, 7 + 0 * 8, 6 + 6 * 8, 7 + 4 * 8,
0 + 1 * 8, 0 + 3 * 8, 1 + 3 * 8, 1 + 4 * 8,
1 + 5 * 8, 3 + 1 * 8, 2 + 5 * 8, 4 + 1 * 8,
3 + 5 * 8, 5 + 1 * 8, 4 + 5 * 8, 6 + 1 * 8,
5 + 6 * 8, 7 + 1 * 8, 6 + 7 * 8, 7 + 5 * 8,
0 + 2 * 8, 0 + 4 * 8, 0 + 5 * 8, 2 + 1 * 8,
1 + 6 * 8, 4 + 0 * 8, 2 + 6 * 8, 5 + 0 * 8,
3 + 6 * 8, 6 + 0 * 8, 4 + 6 * 8, 6 + 2 * 8,
5 + 7 * 8, 6 + 4 * 8, 7 + 2 * 8, 7 + 6 * 8,
1 + 0 * 8, 1 + 2 * 8, 0 + 6 * 8, 3 + 0 * 8,
1 + 7 * 8, 3 + 2 * 8, 2 + 7 * 8, 4 + 2 * 8,
3 + 7 * 8, 5 + 2 * 8, 4 + 7 * 8, 5 + 4 * 8,
6 + 3 * 8, 6 + 5 * 8, 7 + 3 * 8, 7 + 7 * 8,
}

Definition at line 79 of file h264_slice.c.

Referenced by init_scan_tables().

◆ zigzag_scan8x8_cavlc

const uint8_t zigzag_scan8x8_cavlc[64+1]
static
Initial value:
= {
0 + 0 * 8, 1 + 1 * 8, 1 + 2 * 8, 2 + 2 * 8,
4 + 1 * 8, 0 + 5 * 8, 3 + 3 * 8, 7 + 0 * 8,
3 + 4 * 8, 1 + 7 * 8, 5 + 3 * 8, 6 + 3 * 8,
2 + 7 * 8, 6 + 4 * 8, 5 + 6 * 8, 7 + 5 * 8,
1 + 0 * 8, 2 + 0 * 8, 0 + 3 * 8, 3 + 1 * 8,
3 + 2 * 8, 0 + 6 * 8, 4 + 2 * 8, 6 + 1 * 8,
2 + 5 * 8, 2 + 6 * 8, 6 + 2 * 8, 5 + 4 * 8,
3 + 7 * 8, 7 + 3 * 8, 4 + 7 * 8, 7 + 6 * 8,
0 + 1 * 8, 3 + 0 * 8, 0 + 4 * 8, 4 + 0 * 8,
2 + 3 * 8, 1 + 5 * 8, 5 + 1 * 8, 5 + 2 * 8,
1 + 6 * 8, 3 + 5 * 8, 7 + 1 * 8, 4 + 5 * 8,
4 + 6 * 8, 7 + 4 * 8, 5 + 7 * 8, 6 + 7 * 8,
0 + 2 * 8, 2 + 1 * 8, 1 + 3 * 8, 5 + 0 * 8,
1 + 4 * 8, 2 + 4 * 8, 6 + 0 * 8, 4 + 3 * 8,
0 + 7 * 8, 4 + 4 * 8, 7 + 2 * 8, 3 + 6 * 8,
5 + 5 * 8, 6 + 5 * 8, 6 + 6 * 8, 7 + 7 * 8,
}

Definition at line 99 of file h264_slice.c.

Referenced by init_scan_tables().