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 8,
106 0 + 0 * 8, 1 + 1 * 8, 1 + 2 * 8, 2 + 2 * 8,
107 4 + 1 * 8, 0 + 5 * 8, 3 + 3 * 8, 7 + 0 * 8,
108 3 + 4 * 8, 1 + 7 * 8, 5 + 3 * 8, 6 + 3 * 8,
109 2 + 7 * 8, 6 + 4 * 8, 5 + 6 * 8, 7 + 5 * 8,
110 1 + 0 * 8, 2 + 0 * 8, 0 + 3 * 8, 3 + 1 * 8,
111 3 + 2 * 8, 0 + 6 * 8, 4 + 2 * 8, 6 + 1 * 8,
112 2 + 5 * 8, 2 + 6 * 8, 6 + 2 * 8, 5 + 4 * 8,
113 3 + 7 * 8, 7 + 3 * 8, 4 + 7 * 8, 7 + 6 * 8,
114 0 + 1 * 8, 3 + 0 * 8, 0 + 4 * 8, 4 + 0 * 8,
115 2 + 3 * 8, 1 + 5 * 8, 5 + 1 * 8, 5 + 2 * 8,
116 1 + 6 * 8, 3 + 5 * 8, 7 + 1 * 8, 4 + 5 * 8,
117 4 + 6 * 8, 7 + 4 * 8, 5 + 7 * 8, 6 + 7 * 8,
118 0 + 2 * 8, 2 + 1 * 8, 1 + 3 * 8, 5 + 0 * 8,
119 1 + 4 * 8, 2 + 4 * 8, 6 + 0 * 8, 4 + 3 * 8,
120 0 + 7 * 8, 4 + 4 * 8, 7 + 2 * 8, 3 + 6 * 8,
121 5 + 5 * 8, 6 + 5 * 8, 6 + 6 * 8, 7 + 7 * 8,
134 0, 3, 4, 3, 3, 1, 5, 1, 4, 5, 2, 5, 3, 1, 5, 1
138 { 20, 18, 32, 19, 25, 24 },
139 { 22, 19, 35, 21, 28, 26 },
140 { 26, 23, 42, 24, 33, 31 },
141 { 28, 25, 45, 26, 35, 33 },
142 { 32, 28, 51, 30, 40, 38 },
143 { 36, 32, 58, 34, 46, 43 },
147 #if CONFIG_H264_DXVA2_HWACCEL
150 #if CONFIG_H264_VAAPI_HWACCEL
153 #if CONFIG_H264_VDA_HWACCEL
157 #if CONFIG_H264_VDPAU_HWACCEL
165 #if CONFIG_H264_DXVA2_HWACCEL
168 #if CONFIG_H264_VAAPI_HWACCEL
171 #if CONFIG_H264_VDA_HWACCEL
175 #if CONFIG_H264_VDPAU_HWACCEL
221 const int b4_stride = h->
mb_width * 4 + 1;
222 const int b4_array_size = b4_stride * h->
mb_height * 4;
284 for (i = 0; i < 2; i++) {
297 return (ret < 0) ? ret :
AVERROR(ENOMEM);
317 if (i == H264_MAX_PICTURE_COUNT)
334 for (i = 0; i < 6; i++) {
336 for (j = 0; j < i; j++)
345 for (q = 0; q < max_qp + 1; q++) {
348 for (x = 0; x < 64; x++)
360 for (i = 0; i < 6; i++) {
362 for (j = 0; j < i; j++)
371 for (q = 0; q < max_qp + 1; q++) {
372 int shift =
div6[q] + 2;
374 for (x = 0; x < 16; x++)
389 for (i = 0; i < 6; i++)
390 for (x = 0; x < 16; x++)
393 for (i = 0; i < 6; i++)
394 for (x = 0; x < 64; x++)
424 #define IN_RANGE(a, b, size) (((a) >= (b)) && ((a) < ((b) + (size))))
425 #undef REBASE_PICTURE
426 #define REBASE_PICTURE(pic, new_ctx, old_ctx) \
427 ((pic && pic >= old_ctx->DPB && \
428 pic < old_ctx->DPB + H264_MAX_PICTURE_COUNT) ? \
429 &new_ctx->DPB[pic - old_ctx->DPB] : NULL)
437 for (i = 0; i < count; i++) {
438 assert((
IN_RANGE(from[i], old_base,
sizeof(*old_base)) ||
450 for (i = 0; i < count; i++) {
451 if (to[i] && !from[i]) {
453 }
else if (from[i] && !to[i]) {
460 memcpy(to[i], from[i], size);
466 #define copy_fields(to, from, start_field, end_field) \
467 memcpy(&to->start_field, &from->start_field, \
468 (char *)&to->end_field - (char *)&to->start_field)
477 int context_reinitialized = 0;
480 if (dst == src || !h1->context_initialized)
484 (h->
width != h1->width ||
485 h->
height != h1->height ||
499 h->
width = h1->width;
511 context_reinitialized = 1;
529 memcpy(h, h1,
sizeof(*h1));
532 memset(&h->
er, 0,
sizeof(h->
er));
533 memset(&h->
mb, 0,
sizeof(h->
mb));
560 for (i = 0; i < 2; i++) {
585 if (h1->DPB[i].f.buf[0] &&
592 if (h1->cur_pic.f.buf[0]) {
613 (
void **)h1->sps_buffers,
618 (
void **)h1->pps_buffers,
625 copy_fields(h, h1, dequant4_buffer, dequant4_coeff);
627 for (i = 0; i < 6; i++)
629 (h1->dequant4_coeff[i] - h1->dequant4_buffer[0]);
631 for (i = 0; i < 6; i++)
633 (h1->dequant8_coeff[i] - h1->dequant8_buffer[0]);
650 if (context_reinitialized)
712 for (i = 0; i < 16; i++) {
716 for (i = 0; i < 16; i++) {
754 int linesize,
int uvlinesize,
764 src_cb -= uvlinesize;
765 src_cr -= uvlinesize;
771 AV_COPY128(top_border, src_y + 15 * linesize);
773 AV_COPY128(top_border + 16, src_y + 15 * linesize + 16);
777 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
778 AV_COPY128(top_border + 48, src_cb + 15 * uvlinesize + 16);
779 AV_COPY128(top_border + 64, src_cr + 15 * uvlinesize);
780 AV_COPY128(top_border + 80, src_cr + 15 * uvlinesize + 16);
782 AV_COPY128(top_border + 16, src_cb + 15 * uvlinesize);
783 AV_COPY128(top_border + 32, src_cr + 15 * uvlinesize);
785 }
else if (chroma422) {
787 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
788 AV_COPY128(top_border + 48, src_cr + 15 * uvlinesize);
790 AV_COPY64(top_border + 16, src_cb + 15 * uvlinesize);
791 AV_COPY64(top_border + 24, src_cr + 15 * uvlinesize);
795 AV_COPY128(top_border + 32, src_cb + 7 * uvlinesize);
796 AV_COPY128(top_border + 48, src_cr + 7 * uvlinesize);
798 AV_COPY64(top_border + 16, src_cb + 7 * uvlinesize);
799 AV_COPY64(top_border + 24, src_cr + 7 * uvlinesize);
813 AV_COPY128(top_border, src_y + 16 * linesize);
815 AV_COPY128(top_border + 16, src_y + 16 * linesize + 16);
820 AV_COPY128(top_border + 32, src_cb + 16 * linesize);
821 AV_COPY128(top_border + 48, src_cb + 16 * linesize + 16);
822 AV_COPY128(top_border + 64, src_cr + 16 * linesize);
823 AV_COPY128(top_border + 80, src_cr + 16 * linesize + 16);
825 AV_COPY128(top_border + 16, src_cb + 16 * linesize);
826 AV_COPY128(top_border + 32, src_cr + 16 * linesize);
828 }
else if (chroma422) {
830 AV_COPY128(top_border + 32, src_cb + 16 * uvlinesize);
831 AV_COPY128(top_border + 48, src_cr + 16 * uvlinesize);
833 AV_COPY64(top_border + 16, src_cb + 16 * uvlinesize);
834 AV_COPY64(top_border + 24, src_cr + 16 * uvlinesize);
838 AV_COPY128(top_border + 32, src_cb + 8 * uvlinesize);
839 AV_COPY128(top_border + 48, src_cr + 8 * uvlinesize);
841 AV_COPY64(top_border + 16, src_cb + 8 * uvlinesize);
842 AV_COPY64(top_border + 24, src_cr + 8 * uvlinesize);
855 int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1;
857 for (i = 0; i < 2; i++) {
889 for (ref0 = ref_start; ref0 < ref_count0; ref0++) {
891 for (ref1 = ref_start; ref1 < ref_count1; ref1++) {
895 int td = av_clip(poc1 - poc0, -128, 127);
897 int tb = av_clip(cur_poc - poc0, -128, 127);
898 int tx = (16384 + (
FFABS(td) >> 1)) / td;
899 int dist_scale_factor = (tb * tx + 32) >> 8;
900 if (dist_scale_factor >= -64 && dist_scale_factor <= 128)
901 w = 64 - dist_scale_factor;
920 for (i = 0; i < 16; i++) {
921 #define TRANSPOSE(x) (x >> 2) | ((x << 2) & 0xF)
926 for (i = 0; i < 64; i++) {
927 #define TRANSPOSE(x) (x >> 3) | ((x & 7) << 3)
1054 if (width <= 0 || height <= 0) {
1117 " reducing to %d\n", nb_slices, max_slices);
1118 nb_slices = max_slices;
1191 unsigned int first_mb_in_slice;
1192 unsigned int pps_id;
1194 unsigned int slice_type, tmp, i, j;
1195 int default_ref_list_done = 0;
1196 int last_pic_structure, last_pic_droppable;
1197 int needs_reinit = 0;
1198 int field_pic_flag, bottom_field_flag;
1205 if (first_mb_in_slice == 0) {
1222 "A new picture can only be started in the first slice thread\n");
1227 if (slice_type > 9) {
1229 "slice type %d too large at %d %d\n",
1233 if (slice_type > 4) {
1242 default_ref_list_done = 1;
1263 "non-existing PPS %u referenced\n",
1271 "non-existing SPS %u referenced\n",
1332 "changing width %d -> %d / height %d -> %d on "
1351 "h264_slice_header_init() failed\n");
1358 "Cannot (re-)initialize context during parallel decoding.\n");
1368 "h264_slice_header_init() failed\n");
1389 if (field_pic_flag) {
1403 "Changing field mode (%d -> %d) between slices is not allowed\n",
1410 "unset cur_pic_ptr on slice %d\n",
1421 if (unwrap_prev_frame_num > h->
frame_num)
1422 unwrap_prev_frame_num -= max_frame_num;
1426 if (unwrap_prev_frame_num < 0)
1427 unwrap_prev_frame_num += max_frame_num;
1447 if (!last_pic_droppable && last_pic_structure !=
PICT_FRAME) {
1457 if (!last_pic_droppable && last_pic_structure !=
PICT_FRAME) {
1468 "Invalid field mode combination %d/%d\n",
1473 }
else if (last_pic_droppable != h->
droppable) {
1475 "Found reference and non-reference fields in the same frame, which");
1581 first_mb_in_slice >= h->
mb_num) {
1626 default_ref_list_done = 0;
1628 if (!default_ref_list_done)
1648 for (i = 0; i < 2; i++) {
1712 "deblocking_filter_idc %u out of range\n", tmp);
1727 "deblocking filter parameters %d %d out of range\n",
1752 "Cannot parallelize deblocking type 1, decoding such frames in sequential order\n");
1757 "Deblocking switched inside frame.\n");
1773 "Too many slices, increase MAX_SLICES and recompile\n");
1776 for (j = 0; j < 2; j++) {
1779 for (i = 0; i < 16; i++) {
1781 if (j < h->list_count && i < h->ref_count[j] &&
1800 for (i = 0; i < 16; i++)
1803 ref2frm[18 + 1] = -1;
1804 for (i = 16; i < 48; i++)
1805 ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] +
1811 "slice:%d %s mb:%d %c%s%s pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n",
1852 int mb_type,
int top_xy,
1855 int left_type[LEFT_MBS],
1856 int mb_xy,
int list)
1863 const int b_xy = h->
mb2b_xy[top_xy] + 3 * b_stride;
1864 const int b8_xy = 4 * top_xy + 2;
1867 ref_cache[0 - 1 * 8] =
1868 ref_cache[1 - 1 * 8] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 0]];
1869 ref_cache[2 - 1 * 8] =
1870 ref_cache[3 - 1 * 8] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 1]];
1879 const int b8_xy = 4 * left_xy[
LTOP] + 1;
1886 ref_cache[-1 + 8] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 2 * 0]];
1887 ref_cache[-1 + 16] =
1888 ref_cache[-1 + 24] = ref2frm[list][h->
cur_pic.
ref_index[list][b8_xy + 2 * 1]];
1896 ref_cache[-1 + 16] =
1914 uint32_t ref01 = (
pack16to32(ref2frm[list][ref[0]], ref2frm[list][ref[1]]) & 0x00FF00FF) * 0x0101;
1915 uint32_t ref23 = (
pack16to32(ref2frm[list][ref[2]], ref2frm[list][ref[3]]) & 0x00FF00FF) * 0x0101;
1916 AV_WN32A(&ref_cache[0 * 8], ref01);
1917 AV_WN32A(&ref_cache[1 * 8], ref01);
1918 AV_WN32A(&ref_cache[2 * 8], ref23);
1919 AV_WN32A(&ref_cache[3 * 8], ref23);
1924 AV_COPY128(mv_dst + 8 * 0, mv_src + 0 * b_stride);
1925 AV_COPY128(mv_dst + 8 * 1, mv_src + 1 * b_stride);
1926 AV_COPY128(mv_dst + 8 * 2, mv_src + 2 * b_stride);
1927 AV_COPY128(mv_dst + 8 * 3, mv_src + 3 * b_stride);
1937 const int mb_xy = h->
mb_xy;
1948 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy - 1;
1953 if (left_mb_field_flag != curr_mb_field_flag)
1956 if (curr_mb_field_flag)
1959 if (left_mb_field_flag != curr_mb_field_flag)
1973 if (qp <= qp_thresh &&
1974 (left_xy[
LTOP] < 0 ||
1980 if ((left_xy[
LTOP] < 0 ||
1995 left_type[
LTOP] = left_type[
LBOT] = 0;
2000 left_type[
LTOP] = left_type[
LBOT] = 0;
2010 top_type, left_type, mb_xy, 0);
2013 top_type, left_type, mb_xy, 1);
2017 AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]);
2018 AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]);
2019 AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]);
2020 AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]);
2025 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[3 * 4]);
2028 if (left_type[
LTOP]) {
2030 nnz_cache[3 + 8 * 1] = nnz[3 + 0 * 4];
2031 nnz_cache[3 + 8 * 2] = nnz[3 + 1 * 4];
2032 nnz_cache[3 + 8 * 3] = nnz[3 + 2 * 4];
2033 nnz_cache[3 + 8 * 4] = nnz[3 + 3 * 4];
2040 nnz_cache[4 + 8 * 0] =
2041 nnz_cache[5 + 8 * 0] = (h->
cbp_table[top_xy] & 0x4000) >> 12;
2042 nnz_cache[6 + 8 * 0] =
2043 nnz_cache[7 + 8 * 0] = (h->
cbp_table[top_xy] & 0x8000) >> 12;
2046 nnz_cache[3 + 8 * 1] =
2047 nnz_cache[3 + 8 * 2] = (h->
cbp_table[left_xy[
LTOP]] & 0x2000) >> 12;
2050 nnz_cache[3 + 8 * 3] =
2051 nnz_cache[3 + 8 * 4] = (h->
cbp_table[left_xy[
LBOT]] & 0x8000) >> 12;
2055 nnz_cache[
scan8[0]] =
2056 nnz_cache[scan8[1]] =
2057 nnz_cache[scan8[2]] =
2058 nnz_cache[scan8[3]] = (h->
cbp & 0x1000) >> 12;
2060 nnz_cache[scan8[0 + 4]] =
2061 nnz_cache[scan8[1 + 4]] =
2062 nnz_cache[scan8[2 + 4]] =
2063 nnz_cache[scan8[3 + 4]] = (h->
cbp & 0x2000) >> 12;
2065 nnz_cache[scan8[0 + 8]] =
2066 nnz_cache[scan8[1 + 8]] =
2067 nnz_cache[scan8[2 + 8]] =
2068 nnz_cache[scan8[3 + 8]] = (h->
cbp & 0x4000) >> 12;
2070 nnz_cache[scan8[0 + 12]] =
2071 nnz_cache[scan8[1 + 12]] =
2072 nnz_cache[scan8[2 + 12]] =
2073 nnz_cache[scan8[3 + 12]] = (h->
cbp & 0x8000) >> 12;
2082 uint8_t *dest_y, *dest_cb, *dest_cr;
2083 int linesize, uvlinesize, mb_x, mb_y;
2090 for (mb_x = start_x; mb_x < end_x; mb_x++)
2091 for (mb_y = end_mb_y -
FRAME_MBAFF(h); mb_y <= end_mb_y; mb_y++) {
2105 ((mb_x << pixel_shift) + mb_y * h->
linesize) * 16;
2107 (mb_x << pixel_shift) * (8 <<
CHROMA444(h)) +
2110 (mb_x << pixel_shift) * (8 <<
CHROMA444(h)) +
2135 linesize, uvlinesize);
2138 dest_cr, linesize, uvlinesize);
2170 if ((top + height) >= pic_height)
2171 height += deblock_border;
2172 top -= deblock_border;
2175 if (top >= pic_height || (top + height) < 0)
2178 height =
FFMIN(height, pic_height - top);
2194 int endx,
int endy,
int status)
2196 #if CONFIG_ERROR_RESILIENCE
2207 int lf_x_start = h->
mb_x;
2251 if (h->
mb_x >= lf_x_start)
2257 "error while decoding MB %d %d, bytestream %td\n",
2267 h->
mb_x = lf_x_start = 0;
2282 if (h->
mb_x > lf_x_start)
2306 "error while decoding MB %d %d\n", h->
mb_x, h->
mb_y);
2314 h->
mb_x = lf_x_start = 0;
2347 if (h->
mb_x > lf_x_start)
2376 "Input contains more MB rows than the frame height.\n");
2382 if (context_count == 1) {
2385 for (i = 1; i < context_count; i++) {
2391 NULL, context_count,
sizeof(
void *));
2399 for (i = 1; i < context_count; i++)
void ff_h264_direct_dist_scale_factor(H264Context *const h)
int video_signal_type_present_flag
int ff_h264_decode_mb_cabac(H264Context *h)
Decode a CABAC coded macroblock.
void ff_h264_unref_picture(H264Context *h, H264Picture *pic)
const struct AVCodec * codec
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
discard all frames except keyframes
uint8_t * edge_emu_buffer
void ff_h264_flush_change(H264Context *h)
static const uint8_t dequant8_coeff_init[6][6]
int long_ref
1->long term reference 0->short term reference
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int single_decode_warning
1 if the single thread fallback warning has already been displayed, 0 otherwise.
void ff_h264_free_tables(H264Context *h, int free_rbsp)
#define CODEC_FLAG2_FAST
Allow non spec compliant speedup tricks.
static int get_se_golomb(GetBitContext *gb)
read signed exp golomb code.
int coded_width
Bitstream width / height, may be different from width/height e.g.
#define H264_MAX_PICTURE_COUNT
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
int chroma_qp_index_offset[2]
const uint8_t * bytestream_end
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
static const uint8_t zigzag_scan8x8_cavlc[64]
H264ChromaContext h264chroma
int luma_weight_flag[2]
7.4.3.2 luma_weight_lX_flag
MMCO mmco[MAX_MMCO_COUNT]
memory management control operations buffer.
void h264_init_dequant_tables(H264Context *h)
enum AVColorRange color_range
MPEG vs JPEG YUV range.
static void implicit_weight_table(H264Context *h, int field)
Initialize implicit_weight table.
static void decode_finish_row(H264Context *h)
Draw edges and report progress for the last MB row.
AVBufferRef * mb_type_buf
#define AV_PIX_FMT_GBRP10
AVBufferPool * mb_type_pool
HW decoding through VA API, Picture.data[3] contains a vaapi_render_state struct which contains the b...
qpel_mc_func(* qpel_put)[16]
static void clone_tables(H264Context *dst, H264Context *src, int i)
Mimic alloc_tables(), but for every context thread.
int16_t(*[2] motion_val)[2]
const uint8_t * field_scan8x8_q0
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
H264Picture * delayed_pic[MAX_DELAYED_PIC_COUNT+2]
int is_avc
Used to parse AVC variant of h264.
AVBufferPool * ref_index_pool
static const uint8_t dequant4_coeff_init[6][3]
uint8_t zigzag_scan8x8_cavlc[64]
int ff_h264_get_profile(SPS *sps)
Compute profile from profile_idc and constraint_set?_flags.
uint32_t dequant8_buffer[6][QP_MAX_NUM+1][64]
int16_t mv_cache[2][5 *8][2]
Motion vector cache.
int prev_poc_msb
poc_msb of the last reference pic for POC type 0
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
uint32_t num_units_in_tick
void ff_thread_await_progress(ThreadFrame *f, int n, int field)
Wait for earlier decoding threads to finish reference pictures.
H264Picture * long_ref[32]
int slice_type_nos
S free slice type (SI/SP are remapped to I/P)
static av_always_inline uint32_t pack16to32(int a, int b)
static const uint8_t zigzag_scan[16]
#define IN_RANGE(a, b, size)
void ff_h264_init_cabac_states(H264Context *h)
static const uint8_t field_scan8x8_cavlc[64]
#define REBASE_PICTURE(pic, new_ctx, old_ctx)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
int ff_h264_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
uint8_t * chroma_pred_mode_table
int ff_h264_decode_ref_pic_list_reordering(H264Context *h)
static const uint8_t golomb_to_pict_type[5]
struct AVHWAccel * hwaccel
Hardware accelerator in use.
unsigned int crop_top
frame_cropping_rect_top_offset
#define USES_LIST(a, list)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
uint8_t scaling_matrix4[6][16]
static int fill_filter_caches(H264Context *h, int mb_type)
const uint8_t * bytestream
int ref2frm[MAX_SLICES][2][64]
reference to frame number lists, used in the loop filter, the first 2 are for -2,-1 ...
int deblocking_filter_parameters_present
deblocking_filter_parameters_present_flag
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static int copy_parameter_set(void **to, void **from, int count, int size)
uint32_t(*[6] dequant4_coeff)[16]
static enum AVPixelFormat h264_hwaccel_pixfmt_list_jpeg_420[]
int prev_frame_num_offset
for POC type 2
unsigned int crop_left
frame_cropping_rect_left_offset
int field_picture
whether or not picture was encoded in separate fields
#define FF_DEBUG_PICT_INFO
static void init_dequant4_coeff_table(H264Context *h)
enum AVColorPrimaries color_primaries
Multithreading support functions.
int cabac
entropy_coding_mode_flag
static const uint8_t dequant8_coeff_init_scan[16]
static void init_dequant8_coeff_table(H264Context *h)
unsigned int ref_count[2]
num_ref_idx_l0/1_active_minus1 + 1
unsigned int crop_right
frame_cropping_rect_right_offset
void ff_h264_fill_mbaff_ref_list(H264Context *h)
int frame_recovered
Initial frame has been completely recovered.
#define PICT_BOTTOM_FIELD
int transform_bypass
qpprime_y_zero_transform_bypass_flag
H264Picture default_ref_list[2][32]
base reference list for all slices of a coded picture
static void predict_field_decoding_flag(H264Context *h)
static int get_bits_count(const GetBitContext *s)
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
qpel_mc_func(* qpel_avg)[16]
int redundant_pic_cnt_present
redundant_pic_cnt_present_flag
#define MAX_DELAYED_PIC_COUNT
AVBufferRef * qscale_table_buf
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)
high precision timer, useful to profile code
int recovered
picture at IDR or recovery point + recovery count
int luma_log2_weight_denom
qpel_mc_func avg_h264_qpel_pixels_tab[4][16]
static int h264_frame_start(H264Context *h)
const uint8_t * zigzag_scan8x8_cavlc_q0
H.264 / AVC / MPEG4 part10 codec.
static int clone_slice(H264Context *dst, H264Context *src)
Replicate H264 "master" context to thread contexts.
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 int get_bits_left(GetBitContext *gb)
int mb_aff
mb_adaptive_frame_field_flag
enum AVColorTransferCharacteristic color_trc
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int16_t mb_luma_dc[3][16 *2]
static int get_ue_golomb(GetBitContext *gb)
read unsigned exp golomb code.
const uint8_t * zigzag_scan_q0
int ff_h264_get_slice_type(const H264Context *h)
Reconstruct bitstream slice_type.
int poc_type
pic_order_cnt_type
void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy, int status)
Add a slice.
discard all bidirectional frames
void ff_h264_direct_ref_list_init(H264Context *const h)
static av_always_inline int get_chroma_qp(H264Context *h, int t, int qscale)
Get the chroma qp.
void * hwaccel_picture_private
hardware accelerator private data
int active_thread_type
Which multithreading methods are in use by the codec.
int mb_field_decoding_flag
int ff_init_poc(H264Context *h, int pic_field_poc[2], int *pic_poc)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static int init_dimensions(H264Context *h)
uint8_t(*[2] mvd_table)[2]
int prev_interlaced_frame
Complement sei_pic_struct SEI_PIC_STRUCT_TOP_BOTTOM and SEI_PIC_STRUCT_BOTTOM_TOP indicate interlaced...
int direct_spatial_mv_pred
simple assert() macros that are a bit more flexible than ISO C assert().
int weighted_pred
weighted_pred_flag
void av_log(void *avcl, int level, const char *fmt,...)
#define AV_PIX_FMT_YUV444P10
int ff_h264_decode_mb_cavlc(H264Context *h)
Decode a macroblock.
HW acceleration through VDA, data[3] contains a CVPixelBufferRef.
int frame_num
frame_num (raw frame_num from slice header)
static const uint8_t field_scan8x8[64]
uint8_t * list_counts
Array of list_count per MB specifying the slice type.
qpel_mc_func put_h264_qpel_pixels_tab[4][16]
int delta_pic_order_always_zero_flag
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
int new
flag to keep track if the decoder context needs re-init due to changed SPS
#define FIELD_OR_MBAFF_PICTURE(h)
uint8_t zigzag_scan8x8[64]
AVBufferRef * hwaccel_priv_buf
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
static const uint8_t scan8[16 *3+3]
int crop
frame_cropping_flag
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
int ff_pred_weight_table(H264Context *h)
uint8_t scaling_matrix8[6][64]
useful rectangle filling function
#define AV_PIX_FMT_YUV422P9
int refs
number of reference frames
static const uint8_t field_scan[16]
AVBufferRef * motion_val_buf[2]
int ref_frame_count
num_ref_frames
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
void ff_h264_filter_mb(H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize)
int frame_num_offset
for POC type 2
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
#define FF_THREAD_FRAME
Decode more than one frame at once.
int needs_realloc
picture needs to be reallocated (eg due to a frame size change)
uint16_t * slice_table
slice_table_base + 2*mb_stride + 1
static void copy_picture_range(H264Picture **to, H264Picture **from, int count, H264Context *new_base, H264Context *old_base)
uint8_t field_scan8x8_cavlc[64]
int colour_description_present_flag
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
int width
picture width / height.
int long_ref_count
number of actual long term references
static enum AVPixelFormat h264_hwaccel_pixfmt_list_420[]
int ff_h264_ref_picture(H264Context *h, H264Picture *dst, H264Picture *src)
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
PPS * pps_buffers[MAX_PPS_COUNT]
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
static void fill_rectangle(SDL_Surface *screen, int x, int y, int w, int h, int color)
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
Context Adaptive Binary Arithmetic Coder inline functions.
H264Picture ref_list[2][48]
0..15: frame refs, 16..47: mbaff field refs.
int init_qp
pic_init_qp_minus26 + 26
uint8_t * bipred_scratchpad
int max_pic_num
max_frame_num or 2 * max_frame_num for field pics.
int ff_generate_sliding_window_mmcos(H264Context *h, int first_slice)
static int pic_is_unused(H264Context *h, H264Picture *pic)
static void loop_filter(H264Context *h, int start_x, int end_x)
int ff_set_ref_count(H264Context *h)
const uint8_t * zigzag_scan8x8_q0
int curr_pic_num
frame_num for frames or 2 * frame_num + 1 for field pics.
static void init_scan_tables(H264Context *h)
initialize scan tables
static int av_unused get_cabac_terminate(CABACContext *c)
#define AV_PIX_FMT_YUV444P9
#define DELAYED_PIC_REF
Value of Picture.reference when Picture is not a reference picture, but is held for delayed output...
av_cold void ff_h264_pred_init(H264PredContext *h, int codec_id, const int bit_depth, const int chroma_format_idc)
Set the intra prediction function pointers.
uint32_t dequant4_buffer[6][QP_MAX_NUM+1][16]
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
the normal 2^n-1 "JPEG" YUV ranges
static int init_table_pools(H264Context *h)
if(ac->has_optimized_func)
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
int dequant_coeff_pps
reinit tables when pps changes
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
int pic_order_present
pic_order_present_flag
struct H264Context * thread_context[H264_MAX_THREADS]
SPS * sps_buffers[MAX_SPS_COUNT]
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
int chroma_log2_weight_denom
int bit_depth_luma
luma bit depth from sps to detect changes
int chroma_format_idc
chroma format from sps to detect changes
int timing_info_present_flag
int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count)
Execute the reference picture marking (memory management control operations).
int coded_picture_number
picture number in bitstream order
#define AV_LOG_INFO
Standard information.
Libavcodec external API header.
H264 / AVC / MPEG4 part10 codec data table
int slice_alpha_c0_offset
static int get_ue_golomb_31(GetBitContext *gb)
read unsigned exp golomb code, constraint to a max of 31.
int prev_frame_num
frame_num of the last pic for POC type 1/2
int ff_h264_set_parameter_from_sps(H264Context *h)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
H264Picture * short_ref[32]
int field_poc[2]
top/bottom POC
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
int implicit_weight[48][48][2]
int max_contexts
Max number of threads / contexts.
int recovery_frame
recovery_frame is the frame_num at which the next frame should be fully constructed.
main external API structure.
uint8_t * data
The data buffer.
int ff_h264_alloc_tables(H264Context *h)
Allocate tables.
int16_t mb[16 *48 *2]
as a dct coeffecient is int32_t in high depth, we need to reserve twice the space.
AVBufferRef * av_buffer_allocz(int size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
static unsigned int get_bits1(GetBitContext *s)
#define AV_PIX_FMT_YUV420P10
const uint8_t * field_scan8x8_cavlc_q0
uint32_t(*[6] dequant8_coeff)[64]
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
int qp_thresh
QP threshold to skip loopfilter.
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
A reference counted buffer type.
int pixel_shift
0 for 8-bit H264, 1 for high-bit-depth H264
int mmco_reset
MMCO_RESET set this 1.
static const uint8_t rem6[QP_MAX_NUM+1]
int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb, int first_slice)
H264Picture * cur_pic_ptr
const uint8_t ff_zigzag_direct[64]
int16_t mb_padding[256 *2]
as mb is addressed by scantable[i] and scantable is uint8_t we can either check that i is not too lar...
#define AV_PIX_FMT_YUV420P9
int log2_max_poc_lsb
log2_max_pic_order_cnt_lsb_minus4
int ff_h264_decode_slice_header(H264Context *h, H264Context *h0)
Decode a slice header.
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer. ...
void ff_h264_draw_horiz_band(H264Context *h, int y, int height)
static int alloc_picture(H264Context *h, H264Picture *pic)
int block_offset[2 *(16 *3)]
block_offset[ 0..23] for frame macroblocks block_offset[24..47] for field macroblocks ...
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int transform_8x8_mode
transform_8x8_mode_flag
#define AV_PIX_FMT_YUV422P10
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static void release_unused_pictures(H264Context *h, int remove_current)
void ff_h264_filter_mb_fast(H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize)
the normal 219*2^(n-8) "MPEG" YUV ranges
#define copy_fields(to, from, start_field, end_field)
hardware decoding through VDA
discard all non reference
AVBufferPool * qscale_table_pool
H264Picture * next_output_pic
int mb_height
pic_height_in_map_units_minus1 + 1
AVBufferPool * motion_val_pool
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
AVBufferPool * av_buffer_pool_init(int size, AVBufferRef *(*alloc)(int size))
Allocate and initialize a buffer pool.
#define CODEC_FLAG_GRAY
Only decode/encode grayscale.
ptrdiff_t mb_linesize
may be equal to s->linesize or s->linesize * 2, for mbaff
int ff_h264_field_end(H264Context *h, int in_setup)
int log2_max_frame_num
log2_max_frame_num_minus4 + 4
H.264 / AVC / MPEG4 part10 motion vector predicion.
FF_ENABLE_DEPRECATION_WARNINGS int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
int ff_h264_context_init(H264Context *h)
Init context Allocate buffers which are not shared amongst multiple threads.
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
enum AVDiscard skip_loop_filter
static int h264_slice_header_init(H264Context *h, int reinit)
int bit_depth_luma
bit_depth_luma_minus8 + 8
static const uint8_t div6[QP_MAX_NUM+1]
int prev_poc_lsb
poc_lsb of the last reference pic for POC type 0
int ff_h264_execute_decode_slices(H264Context *h, unsigned context_count)
Call decode_slice() for each context.
void ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size)
int(* execute)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size)
The codec may call this to execute several independent things.
static void er_add_slice(H264Context *h, int startx, int starty, int endx, int endy, int status)
uint8_t non_zero_count_cache[15 *8]
non zero coeff count cache.
int frame_priv_data_size
Size of per-frame hardware accelerator private data.
uint8_t(*[2] top_borders)[(16 *3)*2]
int key_frame
1 -> keyframe, 0-> not
enum AVPictureType pict_type
static int find_unused_picture(H264Context *h)
int current_slice
current slice number, used to initalize slice_num of each thread/context
static const uint8_t * align_get_bits(GetBitContext *s)
int mb_width
pic_width_in_mbs_minus1 + 1
AVBufferRef * ref_index_buf[2]
const uint8_t * field_scan_q0
static int alloc_scratch_buffers(H264Context *h, int linesize)
int ff_h264_fill_default_ref_list(H264Context *h)
Fill the default_ref_list.
void ff_er_frame_start(ERContext *s)
uint8_t field_scan8x8[64]
int chroma_weight_flag[2]
7.4.3.2 chroma_weight_lX_flag
int8_t * intra4x4_pred_mode
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
static int decode_slice(struct AVCodecContext *avctx, void *arg)
int deblocking_filter
disable_deblocking_filter_idc with 1 <-> 0
static enum AVPixelFormat get_pixel_format(H264Context *h)
uint8_t(* non_zero_count)[48]
unsigned int crop_bottom
frame_cropping_rect_bottom_offset
AVPixelFormat
Pixel format.
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
void ff_h264_hl_decode_mb(H264Context *h)
unsigned int rbsp_buffer_size[2]
Context Adaptive Binary Arithmetic Coder.
int8_t ref_cache[2][5 *8]
int mb_mbaff
mb_aff_frame && mb_field_decoding_flag
int short_ref_count
number of actual short term references
enum AVColorSpace colorspace