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

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

#include "libavutil/avassert.h"
#include "libavutil/imgutils.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 "mpegutils.h"
#include "rectangle.h"
#include "thread.h"

Go to the source code of this file.

Macros

#define IN_RANGE(a, b, size)   (((a) >= (b)) && ((a) < ((b) + (size))))
 
#define REBASE_PICTURE(pic, new_ctx, old_ctx)
 
#define copy_fields(to, from, start_field, end_field)
 
#define TRANSPOSE(x)   ((x) >> 2) | (((x) << 2) & 0xF)
 
#define TRANSPOSE(x)   ((x) >> 3) | (((x) & 7) << 3)
 
#define HWACCEL_MAX
 

Functions

static void release_unused_pictures (H264Context *h, int remove_current)
 
static int alloc_scratch_buffers (H264Context *h, int linesize)
 
static int init_table_pools (H264Context *h)
 
static int alloc_picture (H264Context *h, H264Picture *pic)
 
static int pic_is_unused (H264Context *h, H264Picture *pic)
 
static int find_unused_picture (H264Context *h)
 
static void init_dequant8_coeff_table (H264Context *h)
 
static void init_dequant4_coeff_table (H264Context *h)
 
void ff_h264_init_dequant_tables (H264Context *h)
 
static void clone_tables (H264Context *dst, H264Context *src, int i)
 Mimic alloc_tables(), but for every context thread.
 
static void copy_picture_range (H264Picture **to, H264Picture **from, int count, H264Context *new_base, H264Context *old_base)
 
static int copy_parameter_set (void **to, void **from, int count, int size)
 
static int h264_slice_header_init (H264Context *h, int reinit)
 
int ff_h264_update_thread_context (AVCodecContext *dst, const AVCodecContext *src)
 
static int h264_frame_start (H264Context *h)
 
static av_always_inline void backup_mb_border (H264Context *h, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr, int linesize, int uvlinesize, int simple)
 
static void implicit_weight_table (H264Context *h, int field)
 Initialize implicit_weight table.
 
static void init_scan_tables (H264Context *h)
 initialize scan tables
 
static int clone_slice (H264Context *dst, H264Context *src)
 Replicate H264 "master" context to thread contexts.
 
static enum AVPixelFormat get_pixel_format (H264Context *h, int force_callback)
 
static int init_dimensions (H264Context *h)
 
static enum AVPixelFormat non_j_pixfmt (enum AVPixelFormat a)
 
int ff_h264_decode_slice_header (H264Context *h, H264Context *h0)
 Decode a slice header.
 
int ff_h264_get_slice_type (const H264Context *h)
 Reconstruct bitstream slice_type.
 
static av_always_inline void fill_filter_caches_inter (H264Context *h, int mb_type, int top_xy, int left_xy[LEFT_MBS], int top_type, int left_type[LEFT_MBS], int mb_xy, int list)
 
static int fill_filter_caches (H264Context *h, int mb_type)
 
static void loop_filter (H264Context *h, int start_x, int end_x)
 
static void predict_field_decoding_flag (H264Context *h)
 
static void decode_finish_row (H264Context *h)
 Draw edges and report progress for the last MB row.
 
static void er_add_slice (H264Context *h, 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, unsigned context_count)
 Call decode_slice() for each context.
 

Variables

static const uint8_t rem6 [QP_MAX_NUM+1]
 
static const uint8_t div6 [QP_MAX_NUM+1]
 
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]
 
static const uint8_t dequant4_coeff_init [6][3]
 
static const uint8_t dequant8_coeff_init_scan [16]
 
static const uint8_t dequant8_coeff_init [6][6]
 

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_slice.c.

Macro Definition Documentation

#define IN_RANGE (   a,
  b,
  size 
)    (((a) >= (b)) && ((a) < ((b) + (size))))

Definition at line 409 of file h264_slice.c.

Referenced by copy_picture_range().

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

Definition at line 411 of file h264_slice.c.

Referenced by copy_picture_range(), ff_h264_update_thread_context(), and ff_mpeg_update_thread_context().

#define copy_fields (   to,
  from,
  start_field,
  end_field 
)
Value:
memcpy(&(to)->start_field, &(from)->start_field, \
(char *)&(to)->end_field - (char *)&(to)->start_field)

Definition at line 451 of file h264_slice.c.

Referenced by ff_h264_update_thread_context(), update_context_from_user(), and vp3_update_thread_context().

#define TRANSPOSE (   x)    ((x) >> 2) | (((x) << 2) & 0xF)
#define TRANSPOSE (   x)    ((x) >> 3) | (((x) & 7) << 3)
#define HWACCEL_MAX
Value:
(CONFIG_H264_DXVA2_HWACCEL + \
CONFIG_H264_VAAPI_HWACCEL + \
(CONFIG_H264_VDA_HWACCEL * 2) + \
CONFIG_H264_VDPAU_HWACCEL)

Referenced by get_pixel_format(), and set_sps().

Function Documentation

static void release_unused_pictures ( H264Context h,
int  remove_current 
)
static

Definition at line 151 of file h264_slice.c.

Referenced by ff_h264_decode_slice_header(), and h264_frame_start().

static int alloc_scratch_buffers ( H264Context h,
int  linesize 
)
static

Definition at line 164 of file h264_slice.c.

Referenced by ff_h264_decode_slice_header().

static int init_table_pools ( H264Context h)
static

Definition at line 185 of file h264_slice.c.

Referenced by alloc_picture().

static int alloc_picture ( H264Context h,
H264Picture pic 
)
static

Definition at line 212 of file h264_slice.c.

Referenced by h264_frame_start().

static int pic_is_unused ( H264Context h,
H264Picture pic 
)
inlinestatic

Definition at line 283 of file h264_slice.c.

Referenced by find_unused_picture().

static int find_unused_picture ( H264Context h)
static

Definition at line 292 of file h264_slice.c.

Referenced by h264_frame_start().

static void init_dequant8_coeff_table ( H264Context h)
static

Definition at line 312 of file h264_slice.c.

Referenced by ff_h264_init_dequant_tables().

static void init_dequant4_coeff_table ( H264Context h)
static

Definition at line 339 of file h264_slice.c.

Referenced by ff_h264_init_dequant_tables().

void ff_h264_init_dequant_tables ( H264Context h)

Definition at line 365 of file h264_slice.c.

Referenced by ff_h264_alloc_tables(), and ff_h264_decode_slice_header().

static void clone_tables ( H264Context dst,
H264Context src,
int  i 
)
static

Mimic alloc_tables(), but for every context thread.

Definition at line 387 of file h264_slice.c.

Referenced by h264_slice_header_init().

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

Definition at line 416 of file h264_slice.c.

Referenced by ff_h264_update_thread_context().

static int copy_parameter_set ( void **  to,
void **  from,
int  count,
int  size 
)
static

Definition at line 431 of file h264_slice.c.

Referenced by ff_h264_update_thread_context().

static int h264_slice_header_init ( H264Context h,
int  reinit 
)
static

Definition at line 1155 of file h264_slice.c.

Referenced by ff_h264_decode_slice_header(), and ff_h264_update_thread_context().

int ff_h264_update_thread_context ( AVCodecContext dst,
const AVCodecContext src 
)

Definition at line 457 of file h264_slice.c.

static int h264_frame_start ( H264Context h)
static

Definition at line 688 of file h264_slice.c.

Referenced by ff_h264_decode_slice_header().

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

Definition at line 779 of file h264_slice.c.

Referenced by loop_filter().

static void implicit_weight_table ( H264Context h,
int  field 
)
static

Initialize implicit_weight table.

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

Definition at line 880 of file h264_slice.c.

Referenced by ff_h264_decode_slice_header().

static void init_scan_tables ( H264Context h)
static

initialize scan tables

Definition at line 944 of file h264_slice.c.

Referenced by h264_slice_header_init().

static int clone_slice ( H264Context dst,
H264Context src 
)
static

Replicate H264 "master" context to thread contexts.

Definition at line 981 of file h264_slice.c.

Referenced by ff_h264_decode_slice_header().

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

Definition at line 1006 of file h264_slice.c.

Referenced by ff_h264_decode_slice_header().

static int init_dimensions ( H264Context h)
static

Definition at line 1113 of file h264_slice.c.

Referenced by ff_h264_decode_slice_header().

static enum AVPixelFormat non_j_pixfmt ( enum AVPixelFormat  a)
static

Definition at line 1259 of file h264_slice.c.

Referenced by ff_h264_decode_slice_header().

int ff_h264_decode_slice_header ( H264Context h,
H264Context h0 
)

Decode a slice header.

This will (re)intialize the decoder and call h264_frame_start() as needed.

Parameters
hh264context
h0h264 master context (differs from 'h' when doing sliced based parallel decoding)
Returns
0 if okay, <0 if an error occurred, 1 if decoding must not be multithreaded

Definition at line 1280 of file h264_slice.c.

Referenced by decode_nal_units().

int ff_h264_get_slice_type ( const H264Context h)

Reconstruct bitstream slice_type.

Definition at line 2021 of file h264_slice.c.

Referenced by fill_slice_long(), and vaapi_h264_decode_slice().

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

Definition at line 2039 of file h264_slice.c.

Referenced by fill_filter_caches().

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

Definition at line 2123 of file h264_slice.c.

Referenced by loop_filter().

static void loop_filter ( H264Context h,
int  start_x,
int  end_x 
)
static

Definition at line 2268 of file h264_slice.c.

Referenced by decode_slice(), and xmv_read_extradata().

static void predict_field_decoding_flag ( H264Context h)
static

Definition at line 2337 of file h264_slice.c.

Referenced by decode_slice().

static void decode_finish_row ( H264Context h)
static

Draw edges and report progress for the last MB row.

Definition at line 2350 of file h264_slice.c.

Referenced by decode_slice().

static void er_add_slice ( H264Context h,
int  startx,
int  starty,
int  endx,
int  endy,
int  status 
)
static

Definition at line 2381 of file h264_slice.c.

Referenced by decode_slice().

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

Definition at line 2391 of file h264_slice.c.

Referenced by ff_h264_execute_decode_slices().

int ff_h264_execute_decode_slices ( H264Context h,
unsigned  context_count 
)

Call decode_slice() for each context.

Parameters
hh264 master context
context_countnumber of contexts to execute

Definition at line 2570 of file h264_slice.c.

Referenced by decode_nal_units().

Variable Documentation

const uint8_t rem6[QP_MAX_NUM+1]
static
Initial value:
= {
0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2,
3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2,
3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
0, 1, 2, 3,
}

Definition at line 47 of file h264_slice.c.

Referenced by ff_hevc_hls_residual_coding(), init_dequant4_coeff_table(), and init_dequant8_coeff_table().

const uint8_t div6[QP_MAX_NUM+1]
static
Initial value:
= {
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3,
3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,
7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10,
10,10,10,11,11,11,11,11,11,12,12,12,12,12,12,13,13,13, 13, 13, 13,
14,14,14,14,
}

Definition at line 55 of file h264_slice.c.

Referenced by ff_hevc_hls_residual_coding(), init_dequant4_coeff_table(), and init_dequant8_coeff_table().

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 63 of file h264_slice.c.

Referenced by init_scan_tables().

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 70 of file h264_slice.c.

Referenced by init_scan_tables().

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 +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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 109 of file h264_slice.c.

Referenced by init_scan_tables().

const uint8_t dequant4_coeff_init[6][3]
static
Initial value:
= {
{ 10, 13, 16 },
{ 11, 14, 18 },
{ 13, 16, 20 },
{ 14, 18, 23 },
{ 16, 20, 25 },
{ 18, 23, 29 },
}

Definition at line 128 of file h264_slice.c.

Referenced by init_dequant4_coeff_table().

const uint8_t dequant8_coeff_init_scan[16]
static
Initial value:
= {
0, 3, 4, 3, 3, 1, 5, 1, 4, 5, 2, 5, 3, 1, 5, 1
}

Definition at line 137 of file h264_slice.c.

Referenced by init_dequant8_coeff_table().

const uint8_t dequant8_coeff_init[6][6]
static
Initial value:
= {
{ 20, 18, 32, 19, 25, 24 },
{ 22, 19, 35, 21, 28, 26 },
{ 26, 23, 42, 24, 33, 31 },
{ 28, 25, 45, 26, 35, 33 },
{ 32, 28, 51, 30, 40, 38 },
{ 36, 32, 58, 34, 46, 43 },
}

Definition at line 141 of file h264_slice.c.

Referenced by init_dequant8_coeff_table().