28 #include "config_components.h"
52 0 + 0 * 4, 0 + 1 * 4, 1 + 0 * 4, 0 + 2 * 4,
53 0 + 3 * 4, 1 + 1 * 4, 1 + 2 * 4, 1 + 3 * 4,
54 2 + 0 * 4, 2 + 1 * 4, 2 + 2 * 4, 2 + 3 * 4,
55 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4, 3 + 3 * 4,
59 0 + 0 * 8, 0 + 1 * 8, 0 + 2 * 8, 1 + 0 * 8,
60 1 + 1 * 8, 0 + 3 * 8, 0 + 4 * 8, 1 + 2 * 8,
61 2 + 0 * 8, 1 + 3 * 8, 0 + 5 * 8, 0 + 6 * 8,
62 0 + 7 * 8, 1 + 4 * 8, 2 + 1 * 8, 3 + 0 * 8,
63 2 + 2 * 8, 1 + 5 * 8, 1 + 6 * 8, 1 + 7 * 8,
64 2 + 3 * 8, 3 + 1 * 8, 4 + 0 * 8, 3 + 2 * 8,
65 2 + 4 * 8, 2 + 5 * 8, 2 + 6 * 8, 2 + 7 * 8,
66 3 + 3 * 8, 4 + 1 * 8, 5 + 0 * 8, 4 + 2 * 8,
67 3 + 4 * 8, 3 + 5 * 8, 3 + 6 * 8, 3 + 7 * 8,
68 4 + 3 * 8, 5 + 1 * 8, 6 + 0 * 8, 5 + 2 * 8,
69 4 + 4 * 8, 4 + 5 * 8, 4 + 6 * 8, 4 + 7 * 8,
70 5 + 3 * 8, 6 + 1 * 8, 6 + 2 * 8, 5 + 4 * 8,
71 5 + 5 * 8, 5 + 6 * 8, 5 + 7 * 8, 6 + 3 * 8,
72 7 + 0 * 8, 7 + 1 * 8, 6 + 4 * 8, 6 + 5 * 8,
73 6 + 6 * 8, 6 + 7 * 8, 7 + 2 * 8, 7 + 3 * 8,
74 7 + 4 * 8, 7 + 5 * 8, 7 + 6 * 8, 7 + 7 * 8,
78 0 + 0 * 8, 1 + 1 * 8, 2 + 0 * 8, 0 + 7 * 8,
79 2 + 2 * 8, 2 + 3 * 8, 2 + 4 * 8, 3 + 3 * 8,
80 3 + 4 * 8, 4 + 3 * 8, 4 + 4 * 8, 5 + 3 * 8,
81 5 + 5 * 8, 7 + 0 * 8, 6 + 6 * 8, 7 + 4 * 8,
82 0 + 1 * 8, 0 + 3 * 8, 1 + 3 * 8, 1 + 4 * 8,
83 1 + 5 * 8, 3 + 1 * 8, 2 + 5 * 8, 4 + 1 * 8,
84 3 + 5 * 8, 5 + 1 * 8, 4 + 5 * 8, 6 + 1 * 8,
85 5 + 6 * 8, 7 + 1 * 8, 6 + 7 * 8, 7 + 5 * 8,
86 0 + 2 * 8, 0 + 4 * 8, 0 + 5 * 8, 2 + 1 * 8,
87 1 + 6 * 8, 4 + 0 * 8, 2 + 6 * 8, 5 + 0 * 8,
88 3 + 6 * 8, 6 + 0 * 8, 4 + 6 * 8, 6 + 2 * 8,
89 5 + 7 * 8, 6 + 4 * 8, 7 + 2 * 8, 7 + 6 * 8,
90 1 + 0 * 8, 1 + 2 * 8, 0 + 6 * 8, 3 + 0 * 8,
91 1 + 7 * 8, 3 + 2 * 8, 2 + 7 * 8, 4 + 2 * 8,
92 3 + 7 * 8, 5 + 2 * 8, 4 + 7 * 8, 5 + 4 * 8,
93 6 + 3 * 8, 6 + 5 * 8, 7 + 3 * 8, 7 + 7 * 8,
98 0 + 0 * 8, 1 + 1 * 8, 1 + 2 * 8, 2 + 2 * 8,
99 4 + 1 * 8, 0 + 5 * 8, 3 + 3 * 8, 7 + 0 * 8,
100 3 + 4 * 8, 1 + 7 * 8, 5 + 3 * 8, 6 + 3 * 8,
101 2 + 7 * 8, 6 + 4 * 8, 5 + 6 * 8, 7 + 5 * 8,
102 1 + 0 * 8, 2 + 0 * 8, 0 + 3 * 8, 3 + 1 * 8,
103 3 + 2 * 8, 0 + 6 * 8, 4 + 2 * 8, 6 + 1 * 8,
104 2 + 5 * 8, 2 + 6 * 8, 6 + 2 * 8, 5 + 4 * 8,
105 3 + 7 * 8, 7 + 3 * 8, 4 + 7 * 8, 7 + 6 * 8,
106 0 + 1 * 8, 3 + 0 * 8, 0 + 4 * 8, 4 + 0 * 8,
107 2 + 3 * 8, 1 + 5 * 8, 5 + 1 * 8, 5 + 2 * 8,
108 1 + 6 * 8, 3 + 5 * 8, 7 + 1 * 8, 4 + 5 * 8,
109 4 + 6 * 8, 7 + 4 * 8, 5 + 7 * 8, 6 + 7 * 8,
110 0 + 2 * 8, 2 + 1 * 8, 1 + 3 * 8, 5 + 0 * 8,
111 1 + 4 * 8, 2 + 4 * 8, 6 + 0 * 8, 4 + 3 * 8,
112 0 + 7 * 8, 4 + 4 * 8, 7 + 2 * 8, 3 + 6 * 8,
113 5 + 5 * 8, 6 + 5 * 8, 6 + 6 * 8, 7 + 7 * 8,
122 if (
h->DPB[
i].f->buf[0] && !
h->DPB[
i].reference &&
123 (remove_current || &
h->DPB[
i] !=
h->cur_pic_ptr)) {
140 h->mb_width * 16 * 3 *
sizeof(uint8_t) * 2);
142 h->mb_width * 16 * 3 *
sizeof(uint8_t) * 2);
163 const int big_mb_num =
h->mb_stride * (
h->mb_height + 1) + 1;
164 const int mb_array_size =
h->mb_stride *
h->mb_height;
165 const int b4_stride =
h->mb_width * 4 + 1;
166 const int b4_array_size = b4_stride *
h->mb_height * 4;
176 if (!
h->qscale_table_pool || !
h->mb_type_pool || !
h->motion_val_pool ||
177 !
h->ref_index_pool) {
213 if (
h->decode_error_flags_pool) {
221 int h_chroma_shift, v_chroma_shift;
223 &h_chroma_shift, &v_chroma_shift);
233 if (!
h->qscale_table_pool) {
274 if (!
h->DPB[
i].f->buf[0])
281 #define IN_RANGE(a, b, size) (((void*)(a) >= (void*)(b)) && ((void*)(a) < (void*)((b) + (size))))
283 #define REBASE_PICTURE(pic, new_ctx, old_ctx) \
284 (((pic) && (pic) >= (old_ctx)->DPB && \
285 (pic) < (old_ctx)->DPB + H264_MAX_PICTURE_COUNT) ? \
286 &(new_ctx)->DPB[(pic) - (old_ctx)->DPB] : NULL)
293 for (
i = 0;
i < count;
i++) {
307 for (
int p = 0; p <
desc->nb_components; p++) {
309 int is_chroma = p == 1 || p == 2;
312 if (
desc->comp[0].depth >= 9) {
313 ((uint16_t*)dst)[0] =
c[p];
316 for (
int y = 1; y <
height; y++) {
321 for (
int y = 0; y <
height; y++) {
322 memset(dst,
c[p], bytes);
335 int inited =
h->context_initialized, err = 0;
342 if (inited && !h1->ps.sps)
346 (
h->width != h1->width ||
347 h->height != h1->height ||
348 h->mb_width != h1->mb_width ||
349 h->mb_height != h1->mb_height ||
351 h->ps.sps->bit_depth_luma != h1->ps.sps->bit_depth_luma ||
352 h->ps.sps->chroma_format_idc != h1->ps.sps->chroma_format_idc ||
353 h->ps.sps->vui.matrix_coeffs != h1->ps.sps->vui.matrix_coeffs)) {
358 memcpy(
h->block_offset, h1->block_offset,
sizeof(
h->block_offset));
367 h->ps.sps = h1->ps.sps;
369 if (need_reinit || !inited) {
370 h->width = h1->width;
371 h->height = h1->height;
372 h->mb_height = h1->mb_height;
373 h->mb_width = h1->mb_width;
374 h->mb_num = h1->mb_num;
375 h->mb_stride = h1->mb_stride;
376 h->b_stride = h1->b_stride;
377 h->x264_build = h1->x264_build;
379 if (
h->context_initialized || h1->context_initialized) {
387 memcpy(
h->block_offset, h1->block_offset,
sizeof(
h->block_offset));
390 h->width_from_caller = h1->width_from_caller;
391 h->height_from_caller = h1->height_from_caller;
392 h->coded_picture_number = h1->coded_picture_number;
393 h->first_field = h1->first_field;
394 h->picture_structure = h1->picture_structure;
395 h->mb_aff_frame = h1->mb_aff_frame;
396 h->droppable = h1->droppable;
409 h->enable_er = h1->enable_er;
410 h->workaround_bugs = h1->workaround_bugs;
411 h->droppable = h1->droppable;
414 h->is_avc = h1->is_avc;
415 h->nal_length_size = h1->nal_length_size;
417 memcpy(&
h->poc, &h1->poc,
sizeof(
h->poc));
419 memcpy(
h->short_ref, h1->short_ref,
sizeof(
h->short_ref));
420 memcpy(
h->long_ref, h1->long_ref,
sizeof(
h->long_ref));
421 memcpy(
h->delayed_pic, h1->delayed_pic,
sizeof(
h->delayed_pic));
422 memcpy(
h->last_pocs, h1->last_pocs,
sizeof(
h->last_pocs));
424 h->next_output_pic = h1->next_output_pic;
425 h->next_outputed_poc = h1->next_outputed_poc;
426 h->poc_offset = h1->poc_offset;
428 memcpy(
h->mmco, h1->mmco,
sizeof(
h->mmco));
429 h->nb_mmco = h1->nb_mmco;
430 h->mmco_reset = h1->mmco_reset;
431 h->explicit_ref_marking = h1->explicit_ref_marking;
432 h->long_ref_count = h1->long_ref_count;
433 h->short_ref_count = h1->short_ref_count;
440 h->frame_recovered = h1->frame_recovered;
446 h->sei.common.unregistered.x264_build = h1->sei.common.unregistered.x264_build;
447 h->sei.common.mastering_display = h1->sei.common.mastering_display;
448 h->sei.common.content_light = h1->sei.common.content_light;
455 h->poc.prev_poc_msb =
h->poc.poc_msb;
456 h->poc.prev_poc_lsb =
h->poc.poc_lsb;
458 h->poc.prev_frame_num_offset =
h->poc.frame_num_offset;
459 h->poc.prev_frame_num =
h->poc.frame_num;
461 h->recovery_frame = h1->recovery_frame;
482 const int pixel_shift =
h->pixel_shift;
490 h->cur_pic_ptr =
NULL;
499 pic->
reference =
h->droppable ? 0 :
h->picture_structure;
500 #if FF_API_FRAME_PICTURE_NUMBER
525 pic->
needs_fg =
h->sei.common.film_grain_characteristics.present && !
h->avctx->hwaccel &&
531 h->cur_pic_ptr = pic;
533 if (CONFIG_ERROR_RESILIENCE) {
540 for (
i = 0;
i <
h->nb_slice_ctx;
i++) {
541 h->slice_ctx[
i].linesize =
h->cur_pic_ptr->f->linesize[0];
542 h->slice_ctx[
i].uvlinesize =
h->cur_pic_ptr->f->linesize[1];
545 if (CONFIG_ERROR_RESILIENCE &&
h->enable_er) {
551 for (
i = 0;
i < 16;
i++) {
555 for (
i = 0;
i < 16;
i++) {
556 h->block_offset[16 +
i] =
558 h->block_offset[48 + 16 +
i] =
566 h->cur_pic_ptr->reference = 0;
568 h->cur_pic_ptr->field_poc[0] =
h->cur_pic_ptr->field_poc[1] = INT_MAX;
570 h->next_output_pic =
NULL;
572 h->postpone_filter = 0;
574 h->mb_aff_frame =
h->ps.sps->mb_aff && (
h->picture_structure ==
PICT_FRAME);
576 if (
h->sei.common.unregistered.x264_build >= 0)
577 h->x264_build =
h->sei.common.unregistered.x264_build;
579 assert(
h->cur_pic_ptr->long_ref == 0);
585 const uint8_t *src_y,
586 const uint8_t *src_cb,
const uint8_t *src_cr,
587 int linesize,
int uvlinesize,
592 const int pixel_shift =
h->pixel_shift;
597 src_cb -= uvlinesize;
598 src_cr -= uvlinesize;
604 AV_COPY128(top_border, src_y + 15 * linesize);
606 AV_COPY128(top_border + 16, src_y + 15 * linesize + 16);
610 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
611 AV_COPY128(top_border + 48, src_cb + 15 * uvlinesize + 16);
612 AV_COPY128(top_border + 64, src_cr + 15 * uvlinesize);
613 AV_COPY128(top_border + 80, src_cr + 15 * uvlinesize + 16);
615 AV_COPY128(top_border + 16, src_cb + 15 * uvlinesize);
616 AV_COPY128(top_border + 32, src_cr + 15 * uvlinesize);
618 }
else if (chroma422) {
620 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
621 AV_COPY128(top_border + 48, src_cr + 15 * uvlinesize);
623 AV_COPY64(top_border + 16, src_cb + 15 * uvlinesize);
624 AV_COPY64(top_border + 24, src_cr + 15 * uvlinesize);
628 AV_COPY128(top_border + 32, src_cb + 7 * uvlinesize);
629 AV_COPY128(top_border + 48, src_cr + 7 * uvlinesize);
631 AV_COPY64(top_border + 16, src_cb + 7 * uvlinesize);
632 AV_COPY64(top_border + 24, src_cr + 7 * uvlinesize);
646 AV_COPY128(top_border, src_y + 16 * linesize);
648 AV_COPY128(top_border + 16, src_y + 16 * linesize + 16);
653 AV_COPY128(top_border + 32, src_cb + 16 * linesize);
654 AV_COPY128(top_border + 48, src_cb + 16 * linesize + 16);
655 AV_COPY128(top_border + 64, src_cr + 16 * linesize);
656 AV_COPY128(top_border + 80, src_cr + 16 * linesize + 16);
658 AV_COPY128(top_border + 16, src_cb + 16 * linesize);
659 AV_COPY128(top_border + 32, src_cr + 16 * linesize);
661 }
else if (chroma422) {
663 AV_COPY128(top_border + 32, src_cb + 16 * uvlinesize);
664 AV_COPY128(top_border + 48, src_cr + 16 * uvlinesize);
666 AV_COPY64(top_border + 16, src_cb + 16 * uvlinesize);
667 AV_COPY64(top_border + 24, src_cr + 16 * uvlinesize);
671 AV_COPY128(top_border + 32, src_cb + 8 * uvlinesize);
672 AV_COPY128(top_border + 48, src_cr + 8 * uvlinesize);
674 AV_COPY64(top_border + 16, src_cb + 8 * uvlinesize);
675 AV_COPY64(top_border + 24, src_cr + 8 * uvlinesize);
688 int ref0, ref1,
i, cur_poc, ref_start, ref_count0, ref_count1;
690 for (
i = 0;
i < 2;
i++) {
697 cur_poc =
h->cur_pic_ptr->poc;
699 cur_poc =
h->cur_pic_ptr->field_poc[
h->picture_structure - 1];
711 cur_poc =
h->cur_pic_ptr->field_poc[
field];
722 for (ref0 = ref_start; ref0 < ref_count0; ref0++) {
724 for (ref1 = ref_start; ref1 < ref_count1; ref1++) {
731 int tx = (16384 + (
FFABS(
td) >> 1)) /
td;
732 int dist_scale_factor = (
tb * tx + 32) >> 8;
733 if (dist_scale_factor >= -64 && dist_scale_factor <= 128)
734 w = 64 - dist_scale_factor;
753 for (
i = 0;
i < 16;
i++) {
754 #define TRANSPOSE(x) ((x) >> 2) | (((x) << 2) & 0xF)
759 for (
i = 0;
i < 64;
i++) {
760 #define TRANSPOSE(x) ((x) >> 3) | (((x) & 7) << 3)
767 if (
h->ps.sps->transform_bypass) {
771 memcpy(
h->field_scan_q0 ,
field_scan ,
sizeof(
h->field_scan_q0 ));
772 memcpy(
h->field_scan8x8_q0 ,
field_scan8x8 ,
sizeof(
h->field_scan8x8_q0 ));
775 memcpy(
h->zigzag_scan_q0 ,
h->zigzag_scan ,
sizeof(
h->zigzag_scan_q0 ));
776 memcpy(
h->zigzag_scan8x8_q0 ,
h->zigzag_scan8x8 ,
sizeof(
h->zigzag_scan8x8_q0 ));
777 memcpy(
h->zigzag_scan8x8_cavlc_q0 ,
h->zigzag_scan8x8_cavlc ,
sizeof(
h->zigzag_scan8x8_cavlc_q0));
778 memcpy(
h->field_scan_q0 ,
h->field_scan ,
sizeof(
h->field_scan_q0 ));
779 memcpy(
h->field_scan8x8_q0 ,
h->field_scan8x8 ,
sizeof(
h->field_scan8x8_q0 ));
780 memcpy(
h->field_scan8x8_cavlc_q0 ,
h->field_scan8x8_cavlc ,
sizeof(
h->field_scan8x8_cavlc_q0 ));
786 #define HWACCEL_MAX (CONFIG_H264_DXVA2_HWACCEL + \
787 (CONFIG_H264_D3D11VA_HWACCEL * 2) + \
788 CONFIG_H264_NVDEC_HWACCEL + \
789 CONFIG_H264_VAAPI_HWACCEL + \
790 CONFIG_H264_VIDEOTOOLBOX_HWACCEL + \
791 CONFIG_H264_VDPAU_HWACCEL + \
792 CONFIG_H264_VULKAN_HWACCEL)
795 switch (
h->ps.sps->bit_depth_luma) {
808 #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL
812 #if CONFIG_H264_VULKAN_HWACCEL
823 #if CONFIG_H264_VAAPI_HWACCEL
833 #if CONFIG_H264_VULKAN_HWACCEL
858 #if CONFIG_H264_VDPAU_HWACCEL
861 #if CONFIG_H264_VULKAN_HWACCEL
864 #if CONFIG_H264_NVDEC_HWACCEL
867 #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL
884 #if CONFIG_H264_DXVA2_HWACCEL
887 #if CONFIG_H264_D3D11VA_HWACCEL
891 #if CONFIG_H264_VAAPI_HWACCEL
902 "Unsupported bit depth %d\n",
h->ps.sps->bit_depth_luma);
909 if (
pix_fmts[
i] ==
h->avctx->pix_fmt && !force_callback)
918 int cr =
sps->crop_right;
919 int cl =
sps->crop_left;
920 int ct =
sps->crop_top;
921 int cb =
sps->crop_bottom;
928 if (
h->width_from_caller > 0 &&
h->height_from_caller > 0 &&
929 !
sps->crop_top && !
sps->crop_left &&
932 h->width_from_caller <=
width &&
933 h->height_from_caller <=
height) {
934 width =
h->width_from_caller;
935 height =
h->height_from_caller;
941 h->width_from_caller = 0;
942 h->height_from_caller = 0;
945 h->avctx->coded_width =
h->width;
946 h->avctx->coded_height =
h->height;
967 &
h->chroma_x_shift, &
h->chroma_y_shift);
969 if (
sps->timing_info_present_flag) {
970 int64_t den =
sps->time_scale;
971 if (
h->x264_build < 44
U)
973 av_reduce(&
h->avctx->framerate.den, &
h->avctx->framerate.num,
974 sps->num_units_in_tick * 2, den, 1 << 30);
980 h->prev_interlaced_frame = 1;
989 if (
sps->bit_depth_luma < 8 ||
sps->bit_depth_luma > 14 ||
990 sps->bit_depth_luma == 11 ||
sps->bit_depth_luma == 13
993 sps->bit_depth_luma);
998 h->cur_bit_depth_luma =
999 h->avctx->bits_per_raw_sample =
sps->bit_depth_luma;
1000 h->cur_chroma_format_idc =
sps->chroma_format_idc;
1001 h->pixel_shift =
sps->bit_depth_luma > 8;
1002 h->chroma_format_idc =
sps->chroma_format_idc;
1003 h->bit_depth_luma =
sps->bit_depth_luma;
1006 sps->chroma_format_idc);
1010 sps->chroma_format_idc);
1016 for (
i = 0;
i <
h->nb_slice_ctx;
i++) {
1021 sl->
mvd_table[0] =
h->mvd_table[0] +
i * 8 * 2 *
h->mb_stride;
1022 sl->
mvd_table[1] =
h->mvd_table[1] +
i * 8 * 2 *
h->mb_stride;
1028 h->context_initialized = 1;
1033 h->context_initialized = 0;
1051 int needs_reinit = 0, must_reinit,
ret;
1056 if (
h->ps.sps !=
h->ps.pps->sps) {
1057 h->ps.sps =
h->ps.pps->sps;
1059 if (
h->mb_width !=
h->ps.sps->mb_width ||
1060 h->mb_height !=
h->ps.sps->mb_height ||
1061 h->cur_bit_depth_luma !=
h->ps.sps->bit_depth_luma ||
1062 h->cur_chroma_format_idc !=
h->ps.sps->chroma_format_idc
1066 if (
h->bit_depth_luma !=
h->ps.sps->bit_depth_luma ||
1067 h->chroma_format_idc !=
h->ps.sps->chroma_format_idc)
1072 must_reinit = (
h->context_initialized &&
1073 ( 16*
sps->mb_width !=
h->avctx->coded_width
1074 || 16*
sps->mb_height !=
h->avctx->coded_height
1075 ||
h->cur_bit_depth_luma !=
sps->bit_depth_luma
1076 ||
h->cur_chroma_format_idc !=
sps->chroma_format_idc
1077 ||
h->mb_width !=
sps->mb_width
1078 ||
h->mb_height !=
sps->mb_height
1084 if (first_slice &&
av_cmp_q(
sps->vui.sar,
h->avctx->sample_aspect_ratio))
1087 if (!
h->setup_finished) {
1089 h->avctx->level =
sps->level_idc;
1090 h->avctx->refs =
sps->ref_frame_count;
1092 h->mb_width =
sps->mb_width;
1093 h->mb_height =
sps->mb_height;
1094 h->mb_num =
h->mb_width *
h->mb_height;
1095 h->mb_stride =
h->mb_width + 1;
1097 h->b_stride =
h->mb_width * 4;
1099 h->chroma_y_shift =
sps->chroma_format_idc <= 1;
1101 h->width = 16 *
h->mb_width;
1102 h->height = 16 *
h->mb_height;
1106 if (
sps->vui.video_signal_type_present_flag) {
1109 if (
sps->vui.colour_description_present_flag) {
1110 if (
h->avctx->colorspace !=
sps->vui.matrix_coeffs)
1112 h->avctx->color_primaries =
sps->vui.colour_primaries;
1113 h->avctx->color_trc =
sps->vui.transfer_characteristics;
1114 h->avctx->colorspace =
sps->vui.matrix_coeffs;
1118 if (
h->sei.common.alternative_transfer.present &&
1121 h->avctx->color_trc =
h->sei.common.alternative_transfer.preferred_transfer_characteristics;
1124 h->avctx->chroma_sample_location =
sps->vui.chroma_location;
1126 if (!
h->context_initialized || must_reinit || needs_reinit) {
1127 int flush_changes =
h->context_initialized;
1128 h->context_initialized = 0;
1129 if (sl !=
h->slice_ctx) {
1131 "changing width %d -> %d / height %d -> %d on "
1133 h->width,
h->avctx->coded_width,
1134 h->height,
h->avctx->coded_height,
1135 h->current_slice + 1);
1146 h->avctx->pix_fmt =
ret;
1153 "h264_slice_header_init() failed\n");
1166 int interlaced_frame = 0, top_field_first = 0;
1170 out->repeat_pict = 0;
1175 if (
h->sei.picture_timing.present) {
1182 h->sei.picture_timing.present = 0;
1186 if (
sps->pic_struct_present_flag &&
h->sei.picture_timing.present) {
1188 switch (
pt->pic_struct) {
1193 interlaced_frame = 1;
1198 interlaced_frame = 1;
1201 interlaced_frame = !!
h->prev_interlaced_frame;
1208 out->repeat_pict = 1;
1211 out->repeat_pict = 2;
1214 out->repeat_pict = 4;
1218 if ((
pt->ct_type & 3) &&
1220 interlaced_frame = ((
pt->ct_type & (1 << 1)) != 0);
1225 h->prev_interlaced_frame = interlaced_frame;
1231 if (
sps->pic_struct_present_flag &&
h->sei.picture_timing.present) {
1236 top_field_first = 1;
1237 }
else if (interlaced_frame) {
1240 top_field_first = 1;
1249 &
sps->vui,
sps->bit_depth_luma,
sps->bit_depth_chroma,
1250 cur->
poc + (
unsigned)(
h->poc_offset << 5));
1254 if (
h->sei.picture_timing.timecode_cnt > 0) {
1260 sizeof(uint32_t)*4);
1264 tc_sd = (uint32_t*)tcside->
data;
1265 tc_sd[0] =
h->sei.picture_timing.timecode_cnt;
1267 for (
int i = 0;
i < tc_sd[0];
i++) {
1268 int drop =
h->sei.picture_timing.timecode[
i].dropframe;
1269 int hh =
h->sei.picture_timing.timecode[
i].hours;
1270 int mm =
h->sei.picture_timing.timecode[
i].minutes;
1271 int ss =
h->sei.picture_timing.timecode[
i].seconds;
1272 int ff =
h->sei.picture_timing.timecode[
i].frame;
1278 h->sei.picture_timing.timecode_cnt = 0;
1289 int i, pics, out_of_order, out_idx;
1294 if (
sps->bitstream_restriction_flag ||
1296 h->avctx->has_b_frames =
FFMAX(
h->avctx->has_b_frames,
sps->num_reorder_frames);
1299 for (
i = 0; 1;
i++) {
1302 h->last_pocs[
i-1] = cur->
poc;
1305 h->last_pocs[
i-1]=
h->last_pocs[
i];
1311 out_of_order =
FFMAX(out_of_order, 1);
1315 h->last_pocs[
i] = INT_MIN;
1316 h->last_pocs[0] = cur->
poc;
1318 }
else if(
h->avctx->has_b_frames < out_of_order && !
sps->bitstream_restriction_flag){
1320 av_log(
h->avctx, loglevel,
"Increasing reorder buffer to %d\n", out_of_order);
1321 h->avctx->has_b_frames = out_of_order;
1325 while (
h->delayed_pic[pics])
1330 h->delayed_pic[pics++] = cur;
1334 out =
h->delayed_pic[0];
1336 for (
i = 1;
h->delayed_pic[
i] &&
1338 !
h->delayed_pic[
i]->mmco_reset;
1340 if (
h->delayed_pic[
i]->poc <
out->poc) {
1341 out =
h->delayed_pic[
i];
1344 if (
h->avctx->has_b_frames == 0 &&
1346 h->next_outputed_poc = INT_MIN;
1347 out_of_order =
out->poc <
h->next_outputed_poc;
1349 if (out_of_order || pics >
h->avctx->has_b_frames) {
1351 for (
i = out_idx;
h->delayed_pic[
i];
i++)
1352 h->delayed_pic[
i] =
h->delayed_pic[
i + 1];
1354 if (!out_of_order && pics >
h->avctx->has_b_frames) {
1355 h->next_output_pic =
out;
1356 if (out_idx == 0 &&
h->delayed_pic[0] && ((
h->delayed_pic[0]->f->flags &
AV_FRAME_FLAG_KEY) ||
h->delayed_pic[0]->mmco_reset)) {
1357 h->next_outputed_poc = INT_MIN;
1359 h->next_outputed_poc =
out->poc;
1361 if (
out->recovered) {
1368 if (!
out->recovered) {
1371 h->next_output_pic =
NULL;
1388 const H2645NAL *nal,
int first_slice)
1393 int last_pic_structure, last_pic_droppable,
ret;
1401 if (
sps &&
sps->bitstream_restriction_flag &&
1402 h->avctx->has_b_frames <
sps->num_reorder_frames) {
1403 h->avctx->has_b_frames =
sps->num_reorder_frames;
1406 last_pic_droppable =
h->droppable;
1407 last_pic_structure =
h->picture_structure;
1408 h->droppable = (nal->
ref_idc == 0);
1419 else if (
h->picture_intra_only)
1424 if (
h->poc.frame_num !=
h->poc.prev_frame_num) {
1425 int unwrap_prev_frame_num =
h->poc.prev_frame_num;
1426 int max_frame_num = 1 <<
sps->log2_max_frame_num;
1428 if (unwrap_prev_frame_num >
h->poc.frame_num)
1429 unwrap_prev_frame_num -= max_frame_num;
1431 if ((
h->poc.frame_num - unwrap_prev_frame_num) >
sps->ref_frame_count) {
1432 unwrap_prev_frame_num = (
h->poc.frame_num -
sps->ref_frame_count) - 1;
1433 if (unwrap_prev_frame_num < 0)
1434 unwrap_prev_frame_num += max_frame_num;
1436 h->poc.prev_frame_num = unwrap_prev_frame_num;
1445 if (
h->first_field) {
1452 if (
h->cur_pic_ptr->tf.owner[last_field] ==
h->avctx) {
1457 if (!
FIELD_PICTURE(
h) ||
h->picture_structure == last_pic_structure) {
1465 if (
h->cur_pic_ptr->frame_num !=
h->poc.frame_num) {
1481 "Invalid field mode combination %d/%d\n",
1482 last_pic_structure,
h->picture_structure);
1483 h->picture_structure = last_pic_structure;
1484 h->droppable = last_pic_droppable;
1486 }
else if (last_pic_droppable !=
h->droppable) {
1488 "Found reference and non-reference fields in the same frame, which");
1489 h->picture_structure = last_pic_structure;
1490 h->droppable = last_pic_droppable;
1497 while (
h->poc.frame_num !=
h->poc.prev_frame_num && !
h->first_field &&
1498 h->poc.frame_num != (
h->poc.prev_frame_num + 1) % (1 <<
sps->log2_max_frame_num)) {
1501 h->poc.frame_num,
h->poc.prev_frame_num);
1502 if (!
sps->gaps_in_frame_num_allowed_flag)
1504 h->last_pocs[
i] = INT_MIN;
1511 h->poc.prev_frame_num++;
1512 h->poc.prev_frame_num %= 1 <<
sps->log2_max_frame_num;
1513 h->cur_pic_ptr->frame_num =
h->poc.prev_frame_num;
1514 h->cur_pic_ptr->invalid_gap = !
sps->gaps_in_frame_num_allowed_flag;
1518 h->explicit_ref_marking = 0;
1529 if (
h->short_ref_count) {
1531 1<<(
h->ps.sps->bit_depth_luma-1),
1532 1<<(
h->ps.sps->bit_depth_chroma-1),
1533 1<<(
h->ps.sps->bit_depth_chroma-1),
1538 h->short_ref[0]->f->width == prev->
f->
width &&
1539 h->short_ref[0]->f->height == prev->
f->
height &&
1540 h->short_ref[0]->f->format == prev->
f->
format) {
1545 h->short_ref[0]->tf.f =
h->short_ref[0]->f;
1549 h->short_ref[0]->poc = prev->
poc + 2
U;
1551 if (
h->short_ref[0]->field_picture)
1553 }
else if (!
h->frame_recovered && !
h->avctx->hwaccel)
1555 h->short_ref[0]->frame_num =
h->poc.prev_frame_num;
1562 if (
h->first_field) {
1568 if (!
FIELD_PICTURE(
h) ||
h->picture_structure == last_pic_structure) {
1571 h->missing_fields ++;
1572 h->cur_pic_ptr =
NULL;
1575 h->missing_fields = 0;
1576 if (
h->cur_pic_ptr->frame_num !=
h->poc.frame_num) {
1583 h->cur_pic_ptr =
NULL;
1589 h->cur_pic_ptr =
NULL;
1608 h->cur_pic_ptr->tf.owner[
field] =
h->avctx;
1614 memset(
h->slice_table +
i*
h->mb_stride, -1, (
h->mb_stride - (
i+1==
h->mb_height)) *
sizeof(*
h->slice_table));
1616 memset(
h->slice_table, -1,
1617 (
h->mb_height *
h->mb_stride - 1) *
sizeof(*
h->slice_table));
1621 h->ps.sps, &
h->poc,
h->picture_structure, nal->
ref_idc);
1631 if (
h->sei.recovery_point.recovery_frame_cnt >= 0) {
1632 const int sei_recovery_frame_cnt =
h->sei.recovery_point.recovery_frame_cnt;
1635 h->valid_recovery_point = 1;
1637 if (
h->recovery_frame < 0
1638 ||
av_mod_uintp2(
h->recovery_frame -
h->poc.frame_num,
h->ps.sps->log2_max_frame_num) > sei_recovery_frame_cnt) {
1639 h->recovery_frame =
av_mod_uintp2(
h->poc.frame_num + sei_recovery_frame_cnt,
h->ps.sps->log2_max_frame_num);
1641 if (!
h->valid_recovery_point)
1642 h->recovery_frame =
h->poc.frame_num;
1649 (
h->recovery_frame ==
h->poc.frame_num && nal->
ref_idc)) {
1650 h->recovery_frame = -1;
1651 h->cur_pic_ptr->recovered = 1;
1658 h->cur_pic_ptr->recovered |=
h->frame_recovered;
1685 unsigned int slice_type,
tmp,
i;
1686 int field_pic_flag, bottom_field_flag;
1687 int first_slice = sl ==
h->slice_ctx && !
h->current_slice;
1688 int picture_structure;
1696 if (slice_type > 9) {
1698 "slice type %d too large at %d\n",
1702 if (slice_type > 4) {
1723 if (!
h->ps.pps_list[sl->
pps_id]) {
1725 "non-existing PPS %u referenced\n",
1743 if (
sps->frame_mbs_only_flag) {
1747 av_log(
h->avctx,
AV_LOG_ERROR,
"This stream was generated by a broken encoder, invalid 8x8 inference\n");
1751 if (field_pic_flag) {
1771 if (idr_pic_id < 65536) {
1779 if (
sps->poc_type == 0) {
1782 if (
pps->pic_order_present == 1 && picture_structure ==
PICT_FRAME)
1787 if (
sps->poc_type == 1 && !
sps->delta_pic_order_always_zero_flag) {
1790 if (
pps->pic_order_present == 1 && picture_structure ==
PICT_FRAME)
1795 if (
pps->redundant_pic_cnt_present)
1803 picture_structure,
h->avctx);
1816 for (
i = 0;
i < 2;
i++) {
1821 (
pps->weighted_bipred_idc == 1 &&
1825 picture_structure,
h->avctx);
1848 if (
tmp > 51 + 6 * (
sps->bit_depth_luma - 8)) {
1865 if (
pps->deblocking_filter_parameters_present) {
1869 "deblocking_filter_idc %u out of range\n",
tmp);
1879 if (slice_alpha_c0_offset_div2 > 6 ||
1880 slice_alpha_c0_offset_div2 < -6 ||
1881 slice_beta_offset_div2 > 6 ||
1882 slice_beta_offset_div2 < -6) {
1884 "deblocking filter parameters %d %d out of range\n",
1885 slice_alpha_c0_offset_div2, slice_beta_offset_div2);
1925 if (
h->ps.pps->weighted_bipred_idc == 2 &&
1936 if (!
h->setup_finished)
1956 h->postpone_filter = 1;
1962 h->ps.pps->chroma_qp_index_offset[0],
1963 h->ps.pps->chroma_qp_index_offset[1]) +
1964 6 * (
h->ps.sps->bit_depth_luma - 8);
1977 for (j = 0; j < 2; j++) {
1980 for (
i = 0;
i < 16;
i++) {
1982 if (j < sl->list_count && i < sl->ref_count[j] &&
1986 for (k = 0; k <
h->short_ref_count; k++)
1987 if (
h->short_ref[k]->f->buf[0]->buffer == buf) {
1991 for (k = 0; k <
h->long_ref_count; k++)
1992 if (
h->long_ref[k] &&
h->long_ref[k]->f->buf[0]->buffer == buf) {
1993 id_list[
i] =
h->short_ref_count + k;
2001 for (
i = 0;
i < 16;
i++)
2004 ref2frm[18 + 1] = -1;
2005 for (
i = 16;
i < 48;
i++)
2006 ref2frm[
i + 4] = 4 * id_list[(
i - 16) >> 1] +
2012 "slice:%d %c mb:%d %c%s%s frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n",
2020 h->cur_pic_ptr->field_poc[0],
2021 h->cur_pic_ptr->field_poc[1],
2037 int first_slice = sl ==
h->slice_ctx && !
h->current_slice;
2053 if (
h->setup_finished) {
2060 if (
h->current_slice) {
2063 if (
h->nb_slice_ctx_queued) {
2070 memcpy(&tmp_ctx,
h->slice_ctx,
sizeof(tmp_ctx));
2071 memcpy(
h->slice_ctx, sl,
sizeof(tmp_ctx));
2072 memcpy(sl, &tmp_ctx,
sizeof(tmp_ctx));
2085 h->cur_pic_ptr =
NULL;
2092 if (!
h->first_field) {
2093 if (
h->cur_pic_ptr && !
h->droppable) {
2097 h->cur_pic_ptr =
NULL;
2101 if (!
h->current_slice)
2104 if (
h->current_slice == 0 && !
h->first_field) {
2118 if (
h->ps.pps->sps_id !=
pps->sps_id ||
2119 h->ps.pps->transform_8x8_mode !=
pps->transform_8x8_mode
2124 if (
h->ps.sps !=
pps->sps) {
2126 "SPS changed in the middle of the frame\n");
2131 if (
h->current_slice == 0) {
2137 h->droppable != (nal->
ref_idc == 0)) {
2139 "Changing field mode (%d -> %d) between slices is not allowed\n",
2142 }
else if (!
h->cur_pic_ptr) {
2144 "unset cur_pic_ptr on slice %d\n",
2145 h->current_slice + 1);
2154 h->nb_slice_ctx_queued++;
2179 int mb_type,
int top_xy,
2183 int mb_xy,
int list)
2185 int b_stride =
h->b_stride;
2190 const int b_xy =
h->mb2b_xy[top_xy] + 3 * b_stride;
2191 const int b8_xy = 4 * top_xy + 2;
2194 ref_cache[0 - 1 * 8] =
2195 ref_cache[1 - 1 * 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 0]];
2196 ref_cache[2 - 1 * 8] =
2197 ref_cache[3 - 1 * 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 1]];
2205 const int b_xy =
h->mb2b_xy[left_xy[
LTOP]] + 3;
2206 const int b8_xy = 4 * left_xy[
LTOP] + 1;
2208 AV_COPY32(mv_dst - 1 + 0,
h->cur_pic.motion_val[
list][b_xy + b_stride * 0]);
2209 AV_COPY32(mv_dst - 1 + 8,
h->cur_pic.motion_val[
list][b_xy + b_stride * 1]);
2210 AV_COPY32(mv_dst - 1 + 16,
h->cur_pic.motion_val[
list][b_xy + b_stride * 2]);
2211 AV_COPY32(mv_dst - 1 + 24,
h->cur_pic.motion_val[
list][b_xy + b_stride * 3]);
2213 ref_cache[-1 + 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 2 * 0]];
2214 ref_cache[-1 + 16] =
2215 ref_cache[-1 + 24] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 2 * 1]];
2223 ref_cache[-1 + 16] =
2239 const int8_t *
ref = &
h->cur_pic.ref_index[
list][4 * mb_xy];
2241 uint32_t ref01 = (
pack16to32(ref2frm[
ref[0]], ref2frm[
ref[1]]) & 0x00FF00FF) * 0x0101;
2242 uint32_t ref23 = (
pack16to32(ref2frm[
ref[2]], ref2frm[
ref[3]]) & 0x00FF00FF) * 0x0101;
2243 AV_WN32A(&ref_cache[0 * 8], ref01);
2244 AV_WN32A(&ref_cache[1 * 8], ref01);
2245 AV_WN32A(&ref_cache[2 * 8], ref23);
2246 AV_WN32A(&ref_cache[3 * 8], ref23);
2250 int16_t(*mv_src)[2] = &
h->cur_pic.motion_val[
list][4 * sl->
mb_x + 4 * sl->
mb_y * b_stride];
2251 AV_COPY128(mv_dst + 8 * 0, mv_src + 0 * b_stride);
2252 AV_COPY128(mv_dst + 8 * 1, mv_src + 1 * b_stride);
2253 AV_COPY128(mv_dst + 8 * 2, mv_src + 2 * b_stride);
2254 AV_COPY128(mv_dst + 8 * 3, mv_src + 3 * b_stride);
2263 const int mb_xy = sl->
mb_xy;
2269 top_xy = mb_xy - (
h->mb_stride <<
MB_FIELD(sl));
2271 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy - 1;
2273 const int left_mb_field_flag =
IS_INTERLACED(
h->cur_pic.mb_type[mb_xy - 1]);
2276 if (left_mb_field_flag != curr_mb_field_flag)
2277 left_xy[
LTOP] -=
h->mb_stride;
2279 if (curr_mb_field_flag)
2280 top_xy +=
h->mb_stride &
2281 (((
h->cur_pic.mb_type[top_xy] >> 7) & 1) - 1);
2282 if (left_mb_field_flag != curr_mb_field_flag)
2283 left_xy[
LBOT] +=
h->mb_stride;
2295 int qp =
h->cur_pic.qscale_table[mb_xy];
2296 if (qp <= qp_thresh &&
2297 (left_xy[
LTOP] < 0 ||
2298 ((qp +
h->cur_pic.qscale_table[left_xy[
LTOP]] + 1) >> 1) <= qp_thresh) &&
2300 ((qp +
h->cur_pic.qscale_table[top_xy] + 1) >> 1) <= qp_thresh)) {
2303 if ((left_xy[
LTOP] < 0 ||
2304 ((qp +
h->cur_pic.qscale_table[left_xy[
LBOT]] + 1) >> 1) <= qp_thresh) &&
2305 (top_xy <
h->mb_stride ||
2306 ((qp +
h->cur_pic.qscale_table[top_xy -
h->mb_stride] + 1) >> 1) <= qp_thresh))
2311 top_type =
h->cur_pic.mb_type[top_xy];
2312 left_type[
LTOP] =
h->cur_pic.mb_type[left_xy[
LTOP]];
2313 left_type[
LBOT] =
h->cur_pic.mb_type[left_xy[
LBOT]];
2318 left_type[
LTOP] = left_type[
LBOT] = 0;
2320 if (
h->slice_table[top_xy] == 0xFFFF)
2322 if (
h->slice_table[left_xy[
LBOT]] == 0xFFFF)
2323 left_type[
LTOP] = left_type[
LBOT] = 0;
2333 top_type, left_type, mb_xy, 0);
2336 top_type, left_type, mb_xy, 1);
2338 nnz =
h->non_zero_count[mb_xy];
2340 AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]);
2341 AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]);
2342 AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]);
2343 AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]);
2344 sl->
cbp =
h->cbp_table[mb_xy];
2347 nnz =
h->non_zero_count[top_xy];
2348 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[3 * 4]);
2351 if (left_type[
LTOP]) {
2352 nnz =
h->non_zero_count[left_xy[
LTOP]];
2353 nnz_cache[3 + 8 * 1] = nnz[3 + 0 * 4];
2354 nnz_cache[3 + 8 * 2] = nnz[3 + 1 * 4];
2355 nnz_cache[3 + 8 * 3] = nnz[3 + 2 * 4];
2356 nnz_cache[3 + 8 * 4] = nnz[3 + 3 * 4];
2361 if (!
CABAC(
h) &&
h->ps.pps->transform_8x8_mode) {
2363 nnz_cache[4 + 8 * 0] =
2364 nnz_cache[5 + 8 * 0] = (
h->cbp_table[top_xy] & 0x4000) >> 12;
2365 nnz_cache[6 + 8 * 0] =
2366 nnz_cache[7 + 8 * 0] = (
h->cbp_table[top_xy] & 0x8000) >> 12;
2369 nnz_cache[3 + 8 * 1] =
2370 nnz_cache[3 + 8 * 2] = (
h->cbp_table[left_xy[
LTOP]] & 0x2000) >> 12;
2373 nnz_cache[3 + 8 * 3] =
2374 nnz_cache[3 + 8 * 4] = (
h->cbp_table[left_xy[
LBOT]] & 0x8000) >> 12;
2378 nnz_cache[
scan8[0]] =
2379 nnz_cache[
scan8[1]] =
2380 nnz_cache[
scan8[2]] =
2381 nnz_cache[
scan8[3]] = (sl->
cbp & 0x1000) >> 12;
2383 nnz_cache[
scan8[0 + 4]] =
2384 nnz_cache[
scan8[1 + 4]] =
2385 nnz_cache[
scan8[2 + 4]] =
2386 nnz_cache[
scan8[3 + 4]] = (sl->
cbp & 0x2000) >> 12;
2388 nnz_cache[
scan8[0 + 8]] =
2389 nnz_cache[
scan8[1 + 8]] =
2390 nnz_cache[
scan8[2 + 8]] =
2391 nnz_cache[
scan8[3 + 8]] = (sl->
cbp & 0x4000) >> 12;
2393 nnz_cache[
scan8[0 + 12]] =
2394 nnz_cache[
scan8[1 + 12]] =
2395 nnz_cache[
scan8[2 + 12]] =
2396 nnz_cache[
scan8[3 + 12]] = (sl->
cbp & 0x8000) >> 12;
2405 uint8_t *dest_y, *dest_cb, *dest_cr;
2406 int linesize, uvlinesize, mb_x, mb_y;
2409 const int pixel_shift =
h->pixel_shift;
2410 const int block_h = 16 >>
h->chroma_y_shift;
2412 if (
h->postpone_filter)
2416 for (mb_x = start_x; mb_x < end_x; mb_x++)
2417 for (mb_y = end_mb_y -
FRAME_MBAFF(
h); mb_y <= end_mb_y; mb_y++) {
2419 mb_xy = sl->
mb_xy = mb_x + mb_y *
h->mb_stride;
2420 mb_type =
h->cur_pic.mb_type[mb_xy];
2428 dest_y =
h->cur_pic.f->data[0] +
2429 ((mb_x << pixel_shift) + mb_y * sl->
linesize) * 16;
2430 dest_cb =
h->cur_pic.f->data[1] +
2431 (mb_x << pixel_shift) * (8 <<
CHROMA444(
h)) +
2433 dest_cr =
h->cur_pic.f->data[2] +
2434 (mb_x << pixel_shift) * (8 <<
CHROMA444(
h)) +
2459 linesize, uvlinesize);
2462 dest_cr, linesize, uvlinesize);
2475 const int mb_xy = sl->
mb_x + sl->
mb_y *
h->mb_stride;
2476 int mb_type = (
h->slice_table[mb_xy - 1] == sl->
slice_num) ?
2477 h->cur_pic.mb_type[mb_xy - 1] :
2478 (
h->slice_table[mb_xy -
h->mb_stride] == sl->
slice_num) ?
2479 h->cur_pic.mb_type[mb_xy -
h->mb_stride] : 0;
2494 if ((top +
height) >= pic_height)
2495 height += deblock_border;
2496 top -= deblock_border;
2499 if (top >= pic_height || (top +
height) < 0)
2510 if (
h->droppable ||
h->er.error_occurred)
2518 int startx,
int starty,
2519 int endx,
int endy,
int status)
2524 if (CONFIG_ERROR_RESILIENCE) {
2533 int lf_x_start = sl->
mb_x;
2537 sl->
linesize =
h->cur_pic_ptr->f->linesize[0];
2548 if (
h->postpone_filter)
2564 if (
h->ps.pps->cabac) {
2608 if (sl->
mb_x >= lf_x_start)
2624 if (++sl->
mb_x >=
h->mb_width) {
2626 sl->
mb_x = lf_x_start = 0;
2636 if (eos || sl->
mb_y >=
h->mb_height) {
2637 ff_tlog(
h->avctx,
"slice end %d %d\n",
2641 if (sl->
mb_x > lf_x_start)
2675 "error while decoding MB %d %d\n", sl->
mb_x, sl->
mb_y);
2681 if (++sl->
mb_x >=
h->mb_width) {
2683 sl->
mb_x = lf_x_start = 0;
2691 if (sl->
mb_y >=
h->mb_height) {
2692 ff_tlog(
h->avctx,
"slice end %d %d\n",
2711 ff_tlog(
h->avctx,
"slice end %d %d\n",
2717 if (sl->
mb_x > lf_x_start)
2745 int context_count =
h->nb_slice_ctx_queued;
2749 h->slice_ctx[0].next_slice_idx = INT_MAX;
2751 if (
h->avctx->hwaccel || context_count < 1)
2754 av_assert0(context_count &&
h->slice_ctx[context_count - 1].mb_y <
h->mb_height);
2756 if (context_count == 1) {
2758 h->slice_ctx[0].next_slice_idx =
h->mb_width *
h->mb_height;
2759 h->postpone_filter = 0;
2762 h->mb_y =
h->slice_ctx[0].mb_y;
2767 for (
i = 0;
i < context_count;
i++) {
2768 int next_slice_idx =
h->mb_width *
h->mb_height;
2771 sl = &
h->slice_ctx[
i];
2774 slice_idx = sl->
mb_y *
h->mb_width + sl->
mb_x;
2775 for (j = 0; j < context_count; j++) {
2777 int slice_idx2 = sl2->
mb_y *
h->mb_width + sl2->
mb_x;
2779 if (
i == j || slice_idx2 < slice_idx)
2781 next_slice_idx =
FFMIN(next_slice_idx, slice_idx2);
2787 NULL, context_count,
sizeof(
h->slice_ctx[0]));
2790 sl = &
h->slice_ctx[context_count - 1];
2793 if (
h->postpone_filter) {
2794 h->postpone_filter = 0;
2796 for (
i = 0;
i < context_count;
i++) {
2799 sl = &
h->slice_ctx[
i];
2801 x_end = (sl->
mb_y >=
h->mb_height) ?
h->mb_width : sl->
mb_x;
2806 j == y_end - 1 ? x_end :
h->mb_width);
2813 h->nb_slice_ctx_queued = 0;