28 #include "config_components.h"
55 0 + 0 * 4, 0 + 1 * 4, 1 + 0 * 4, 0 + 2 * 4,
56 0 + 3 * 4, 1 + 1 * 4, 1 + 2 * 4, 1 + 3 * 4,
57 2 + 0 * 4, 2 + 1 * 4, 2 + 2 * 4, 2 + 3 * 4,
58 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4, 3 + 3 * 4,
62 0 + 0 * 8, 0 + 1 * 8, 0 + 2 * 8, 1 + 0 * 8,
63 1 + 1 * 8, 0 + 3 * 8, 0 + 4 * 8, 1 + 2 * 8,
64 2 + 0 * 8, 1 + 3 * 8, 0 + 5 * 8, 0 + 6 * 8,
65 0 + 7 * 8, 1 + 4 * 8, 2 + 1 * 8, 3 + 0 * 8,
66 2 + 2 * 8, 1 + 5 * 8, 1 + 6 * 8, 1 + 7 * 8,
67 2 + 3 * 8, 3 + 1 * 8, 4 + 0 * 8, 3 + 2 * 8,
68 2 + 4 * 8, 2 + 5 * 8, 2 + 6 * 8, 2 + 7 * 8,
69 3 + 3 * 8, 4 + 1 * 8, 5 + 0 * 8, 4 + 2 * 8,
70 3 + 4 * 8, 3 + 5 * 8, 3 + 6 * 8, 3 + 7 * 8,
71 4 + 3 * 8, 5 + 1 * 8, 6 + 0 * 8, 5 + 2 * 8,
72 4 + 4 * 8, 4 + 5 * 8, 4 + 6 * 8, 4 + 7 * 8,
73 5 + 3 * 8, 6 + 1 * 8, 6 + 2 * 8, 5 + 4 * 8,
74 5 + 5 * 8, 5 + 6 * 8, 5 + 7 * 8, 6 + 3 * 8,
75 7 + 0 * 8, 7 + 1 * 8, 6 + 4 * 8, 6 + 5 * 8,
76 6 + 6 * 8, 6 + 7 * 8, 7 + 2 * 8, 7 + 3 * 8,
77 7 + 4 * 8, 7 + 5 * 8, 7 + 6 * 8, 7 + 7 * 8,
81 0 + 0 * 8, 1 + 1 * 8, 2 + 0 * 8, 0 + 7 * 8,
82 2 + 2 * 8, 2 + 3 * 8, 2 + 4 * 8, 3 + 3 * 8,
83 3 + 4 * 8, 4 + 3 * 8, 4 + 4 * 8, 5 + 3 * 8,
84 5 + 5 * 8, 7 + 0 * 8, 6 + 6 * 8, 7 + 4 * 8,
85 0 + 1 * 8, 0 + 3 * 8, 1 + 3 * 8, 1 + 4 * 8,
86 1 + 5 * 8, 3 + 1 * 8, 2 + 5 * 8, 4 + 1 * 8,
87 3 + 5 * 8, 5 + 1 * 8, 4 + 5 * 8, 6 + 1 * 8,
88 5 + 6 * 8, 7 + 1 * 8, 6 + 7 * 8, 7 + 5 * 8,
89 0 + 2 * 8, 0 + 4 * 8, 0 + 5 * 8, 2 + 1 * 8,
90 1 + 6 * 8, 4 + 0 * 8, 2 + 6 * 8, 5 + 0 * 8,
91 3 + 6 * 8, 6 + 0 * 8, 4 + 6 * 8, 6 + 2 * 8,
92 5 + 7 * 8, 6 + 4 * 8, 7 + 2 * 8, 7 + 6 * 8,
93 1 + 0 * 8, 1 + 2 * 8, 0 + 6 * 8, 3 + 0 * 8,
94 1 + 7 * 8, 3 + 2 * 8, 2 + 7 * 8, 4 + 2 * 8,
95 3 + 7 * 8, 5 + 2 * 8, 4 + 7 * 8, 5 + 4 * 8,
96 6 + 3 * 8, 6 + 5 * 8, 7 + 3 * 8, 7 + 7 * 8,
101 0 + 0 * 8, 1 + 1 * 8, 1 + 2 * 8, 2 + 2 * 8,
102 4 + 1 * 8, 0 + 5 * 8, 3 + 3 * 8, 7 + 0 * 8,
103 3 + 4 * 8, 1 + 7 * 8, 5 + 3 * 8, 6 + 3 * 8,
104 2 + 7 * 8, 6 + 4 * 8, 5 + 6 * 8, 7 + 5 * 8,
105 1 + 0 * 8, 2 + 0 * 8, 0 + 3 * 8, 3 + 1 * 8,
106 3 + 2 * 8, 0 + 6 * 8, 4 + 2 * 8, 6 + 1 * 8,
107 2 + 5 * 8, 2 + 6 * 8, 6 + 2 * 8, 5 + 4 * 8,
108 3 + 7 * 8, 7 + 3 * 8, 4 + 7 * 8, 7 + 6 * 8,
109 0 + 1 * 8, 3 + 0 * 8, 0 + 4 * 8, 4 + 0 * 8,
110 2 + 3 * 8, 1 + 5 * 8, 5 + 1 * 8, 5 + 2 * 8,
111 1 + 6 * 8, 3 + 5 * 8, 7 + 1 * 8, 4 + 5 * 8,
112 4 + 6 * 8, 7 + 4 * 8, 5 + 7 * 8, 6 + 7 * 8,
113 0 + 2 * 8, 2 + 1 * 8, 1 + 3 * 8, 5 + 0 * 8,
114 1 + 4 * 8, 2 + 4 * 8, 6 + 0 * 8, 4 + 3 * 8,
115 0 + 7 * 8, 4 + 4 * 8, 7 + 2 * 8, 3 + 6 * 8,
116 5 + 5 * 8, 6 + 5 * 8, 6 + 6 * 8, 7 + 7 * 8,
125 if (
h->DPB[
i].f->buf[0] && !
h->DPB[
i].reference &&
126 (remove_current || &
h->DPB[
i] !=
h->cur_pic_ptr)) {
143 h->mb_width * 16 * 3 *
sizeof(uint8_t) * 2);
145 h->mb_width * 16 * 3 *
sizeof(uint8_t) * 2);
166 const int big_mb_num =
h->mb_stride * (
h->mb_height + 1) + 1;
167 const int mb_array_size =
h->mb_stride *
h->mb_height;
168 const int b4_stride =
h->mb_width * 4 + 1;
169 const int b4_array_size = b4_stride *
h->mb_height * 4;
179 if (!
h->qscale_table_pool || !
h->mb_type_pool || !
h->motion_val_pool ||
180 !
h->ref_index_pool) {
212 if (
h->avctx->hwaccel) {
223 int h_chroma_shift, v_chroma_shift;
225 &h_chroma_shift, &v_chroma_shift);
235 if (!
h->qscale_table_pool) {
279 if (!
h->DPB[
i].f->buf[0])
286 #define IN_RANGE(a, b, size) (((void*)(a) >= (void*)(b)) && ((void*)(a) < (void*)((b) + (size))))
288 #define REBASE_PICTURE(pic, new_ctx, old_ctx) \
289 (((pic) && (pic) >= (old_ctx)->DPB && \
290 (pic) < (old_ctx)->DPB + H264_MAX_PICTURE_COUNT) ? \
291 &(new_ctx)->DPB[(pic) - (old_ctx)->DPB] : NULL)
299 for (
i = 0;
i < count;
i++) {
313 int inited =
h->context_initialized, err = 0;
320 if (inited && !h1->ps.sps)
324 (
h->width != h1->width ||
325 h->height != h1->height ||
326 h->mb_width != h1->mb_width ||
327 h->mb_height != h1->mb_height ||
329 h->ps.sps->bit_depth_luma != h1->ps.sps->bit_depth_luma ||
330 h->ps.sps->chroma_format_idc != h1->ps.sps->chroma_format_idc ||
331 h->ps.sps->vui.matrix_coeffs != h1->ps.sps->vui.matrix_coeffs)) {
336 memcpy(
h->block_offset, h1->block_offset,
sizeof(
h->block_offset));
355 if (h1->ps.pps_ref) {
356 h->ps.pps = (
const PPS*)
h->ps.pps_ref->data;
357 h->ps.sps =
h->ps.pps->sps;
360 if (need_reinit || !inited) {
361 h->width = h1->width;
362 h->height = h1->height;
363 h->mb_height = h1->mb_height;
364 h->mb_width = h1->mb_width;
365 h->mb_num = h1->mb_num;
366 h->mb_stride = h1->mb_stride;
367 h->b_stride = h1->b_stride;
368 h->x264_build = h1->x264_build;
370 if (
h->context_initialized || h1->context_initialized) {
378 memcpy(
h->block_offset, h1->block_offset,
sizeof(
h->block_offset));
381 h->avctx->coded_height = h1->avctx->coded_height;
382 h->avctx->coded_width = h1->avctx->coded_width;
383 h->avctx->width = h1->avctx->width;
384 h->avctx->height = h1->avctx->height;
385 h->width_from_caller = h1->width_from_caller;
386 h->height_from_caller = h1->height_from_caller;
387 h->coded_picture_number = h1->coded_picture_number;
388 h->first_field = h1->first_field;
389 h->picture_structure = h1->picture_structure;
390 h->mb_aff_frame = h1->mb_aff_frame;
391 h->droppable = h1->droppable;
404 h->enable_er = h1->enable_er;
405 h->workaround_bugs = h1->workaround_bugs;
406 h->droppable = h1->droppable;
409 h->is_avc = h1->is_avc;
410 h->nal_length_size = h1->nal_length_size;
412 memcpy(&
h->poc, &h1->poc,
sizeof(
h->poc));
414 memcpy(
h->short_ref, h1->short_ref,
sizeof(
h->short_ref));
415 memcpy(
h->long_ref, h1->long_ref,
sizeof(
h->long_ref));
416 memcpy(
h->delayed_pic, h1->delayed_pic,
sizeof(
h->delayed_pic));
417 memcpy(
h->last_pocs, h1->last_pocs,
sizeof(
h->last_pocs));
419 h->next_output_pic = h1->next_output_pic;
420 h->next_outputed_poc = h1->next_outputed_poc;
421 h->poc_offset = h1->poc_offset;
423 memcpy(
h->mmco, h1->mmco,
sizeof(
h->mmco));
424 h->nb_mmco = h1->nb_mmco;
425 h->mmco_reset = h1->mmco_reset;
426 h->explicit_ref_marking = h1->explicit_ref_marking;
427 h->long_ref_count = h1->long_ref_count;
428 h->short_ref_count = h1->short_ref_count;
435 h->frame_recovered = h1->frame_recovered;
441 h->sei.common.unregistered.x264_build = h1->sei.common.unregistered.x264_build;
448 h->poc.prev_poc_msb =
h->poc.poc_msb;
449 h->poc.prev_poc_lsb =
h->poc.poc_lsb;
451 h->poc.prev_frame_num_offset =
h->poc.frame_num_offset;
452 h->poc.prev_frame_num =
h->poc.frame_num;
454 h->recovery_frame = h1->recovery_frame;
475 const int pixel_shift =
h->pixel_shift;
483 h->cur_pic_ptr =
NULL;
492 pic->
reference =
h->droppable ? 0 :
h->picture_structure;
493 #if FF_API_FRAME_PICTURE_NUMBER
518 pic->
needs_fg =
h->sei.common.film_grain_characteristics.present && !
h->avctx->hwaccel &&
524 h->cur_pic_ptr = pic;
526 if (CONFIG_ERROR_RESILIENCE) {
533 for (
i = 0;
i <
h->nb_slice_ctx;
i++) {
534 h->slice_ctx[
i].linesize =
h->cur_pic_ptr->f->linesize[0];
535 h->slice_ctx[
i].uvlinesize =
h->cur_pic_ptr->f->linesize[1];
538 if (CONFIG_ERROR_RESILIENCE &&
h->enable_er) {
544 for (
i = 0;
i < 16;
i++) {
548 for (
i = 0;
i < 16;
i++) {
549 h->block_offset[16 +
i] =
551 h->block_offset[48 + 16 +
i] =
559 h->cur_pic_ptr->reference = 0;
561 h->cur_pic_ptr->field_poc[0] =
h->cur_pic_ptr->field_poc[1] = INT_MAX;
563 h->next_output_pic =
NULL;
565 h->postpone_filter = 0;
567 h->mb_aff_frame =
h->ps.sps->mb_aff && (
h->picture_structure ==
PICT_FRAME);
569 if (
h->sei.common.unregistered.x264_build >= 0)
570 h->x264_build =
h->sei.common.unregistered.x264_build;
572 assert(
h->cur_pic_ptr->long_ref == 0);
579 uint8_t *src_cb, uint8_t *src_cr,
580 int linesize,
int uvlinesize,
585 const int pixel_shift =
h->pixel_shift;
590 src_cb -= uvlinesize;
591 src_cr -= uvlinesize;
597 AV_COPY128(top_border, src_y + 15 * linesize);
599 AV_COPY128(top_border + 16, src_y + 15 * linesize + 16);
603 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
604 AV_COPY128(top_border + 48, src_cb + 15 * uvlinesize + 16);
605 AV_COPY128(top_border + 64, src_cr + 15 * uvlinesize);
606 AV_COPY128(top_border + 80, src_cr + 15 * uvlinesize + 16);
608 AV_COPY128(top_border + 16, src_cb + 15 * uvlinesize);
609 AV_COPY128(top_border + 32, src_cr + 15 * uvlinesize);
611 }
else if (chroma422) {
613 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
614 AV_COPY128(top_border + 48, src_cr + 15 * uvlinesize);
616 AV_COPY64(top_border + 16, src_cb + 15 * uvlinesize);
617 AV_COPY64(top_border + 24, src_cr + 15 * uvlinesize);
621 AV_COPY128(top_border + 32, src_cb + 7 * uvlinesize);
622 AV_COPY128(top_border + 48, src_cr + 7 * uvlinesize);
624 AV_COPY64(top_border + 16, src_cb + 7 * uvlinesize);
625 AV_COPY64(top_border + 24, src_cr + 7 * uvlinesize);
639 AV_COPY128(top_border, src_y + 16 * linesize);
641 AV_COPY128(top_border + 16, src_y + 16 * linesize + 16);
646 AV_COPY128(top_border + 32, src_cb + 16 * linesize);
647 AV_COPY128(top_border + 48, src_cb + 16 * linesize + 16);
648 AV_COPY128(top_border + 64, src_cr + 16 * linesize);
649 AV_COPY128(top_border + 80, src_cr + 16 * linesize + 16);
651 AV_COPY128(top_border + 16, src_cb + 16 * linesize);
652 AV_COPY128(top_border + 32, src_cr + 16 * linesize);
654 }
else if (chroma422) {
656 AV_COPY128(top_border + 32, src_cb + 16 * uvlinesize);
657 AV_COPY128(top_border + 48, src_cr + 16 * uvlinesize);
659 AV_COPY64(top_border + 16, src_cb + 16 * uvlinesize);
660 AV_COPY64(top_border + 24, src_cr + 16 * uvlinesize);
664 AV_COPY128(top_border + 32, src_cb + 8 * uvlinesize);
665 AV_COPY128(top_border + 48, src_cr + 8 * uvlinesize);
667 AV_COPY64(top_border + 16, src_cb + 8 * uvlinesize);
668 AV_COPY64(top_border + 24, src_cr + 8 * uvlinesize);
681 int ref0, ref1,
i, cur_poc, ref_start, ref_count0, ref_count1;
683 for (
i = 0;
i < 2;
i++) {
690 cur_poc =
h->cur_pic_ptr->poc;
692 cur_poc =
h->cur_pic_ptr->field_poc[
h->picture_structure - 1];
704 cur_poc =
h->cur_pic_ptr->field_poc[
field];
715 for (ref0 = ref_start; ref0 < ref_count0; ref0++) {
717 for (ref1 = ref_start; ref1 < ref_count1; ref1++) {
724 int tx = (16384 + (
FFABS(
td) >> 1)) /
td;
725 int dist_scale_factor = (
tb * tx + 32) >> 8;
726 if (dist_scale_factor >= -64 && dist_scale_factor <= 128)
727 w = 64 - dist_scale_factor;
746 for (
i = 0;
i < 16;
i++) {
747 #define TRANSPOSE(x) ((x) >> 2) | (((x) << 2) & 0xF)
752 for (
i = 0;
i < 64;
i++) {
753 #define TRANSPOSE(x) ((x) >> 3) | (((x) & 7) << 3)
760 if (
h->ps.sps->transform_bypass) {
764 memcpy(
h->field_scan_q0 ,
field_scan ,
sizeof(
h->field_scan_q0 ));
765 memcpy(
h->field_scan8x8_q0 ,
field_scan8x8 ,
sizeof(
h->field_scan8x8_q0 ));
768 memcpy(
h->zigzag_scan_q0 ,
h->zigzag_scan ,
sizeof(
h->zigzag_scan_q0 ));
769 memcpy(
h->zigzag_scan8x8_q0 ,
h->zigzag_scan8x8 ,
sizeof(
h->zigzag_scan8x8_q0 ));
770 memcpy(
h->zigzag_scan8x8_cavlc_q0 ,
h->zigzag_scan8x8_cavlc ,
sizeof(
h->zigzag_scan8x8_cavlc_q0));
771 memcpy(
h->field_scan_q0 ,
h->field_scan ,
sizeof(
h->field_scan_q0 ));
772 memcpy(
h->field_scan8x8_q0 ,
h->field_scan8x8 ,
sizeof(
h->field_scan8x8_q0 ));
773 memcpy(
h->field_scan8x8_cavlc_q0 ,
h->field_scan8x8_cavlc ,
sizeof(
h->field_scan8x8_cavlc_q0 ));
779 #define HWACCEL_MAX (CONFIG_H264_DXVA2_HWACCEL + \
780 (CONFIG_H264_D3D11VA_HWACCEL * 2) + \
781 CONFIG_H264_NVDEC_HWACCEL + \
782 CONFIG_H264_VAAPI_HWACCEL + \
783 CONFIG_H264_VIDEOTOOLBOX_HWACCEL + \
784 CONFIG_H264_VDPAU_HWACCEL + \
785 CONFIG_H264_VULKAN_HWACCEL)
790 switch (
h->ps.sps->bit_depth_luma) {
803 #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL
807 #if CONFIG_H264_VULKAN_HWACCEL
818 #if CONFIG_H264_VAAPI_HWACCEL
828 #if CONFIG_H264_VULKAN_HWACCEL
853 #if CONFIG_H264_VDPAU_HWACCEL
856 #if CONFIG_H264_VULKAN_HWACCEL
859 #if CONFIG_H264_NVDEC_HWACCEL
862 #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL
879 #if CONFIG_H264_DXVA2_HWACCEL
882 #if CONFIG_H264_D3D11VA_HWACCEL
886 #if CONFIG_H264_VAAPI_HWACCEL
889 if (
h->avctx->codec->pix_fmts)
890 choices =
h->avctx->codec->pix_fmts;
899 "Unsupported bit depth %d\n",
h->ps.sps->bit_depth_luma);
906 if (choices[
i] ==
h->avctx->pix_fmt && !force_callback)
915 int cr =
sps->crop_right;
916 int cl =
sps->crop_left;
917 int ct =
sps->crop_top;
918 int cb =
sps->crop_bottom;
925 if (
h->width_from_caller > 0 &&
h->height_from_caller > 0 &&
926 !
sps->crop_top && !
sps->crop_left &&
929 h->width_from_caller <=
width &&
930 h->height_from_caller <=
height) {
931 width =
h->width_from_caller;
932 height =
h->height_from_caller;
938 h->width_from_caller = 0;
939 h->height_from_caller = 0;
942 h->avctx->coded_width =
h->width;
943 h->avctx->coded_height =
h->height;
964 &
h->chroma_x_shift, &
h->chroma_y_shift);
966 if (
sps->timing_info_present_flag) {
967 int64_t den =
sps->time_scale;
968 if (
h->x264_build < 44
U)
970 av_reduce(&
h->avctx->framerate.den, &
h->avctx->framerate.num,
971 sps->num_units_in_tick * 2, den, 1 << 30);
977 h->prev_interlaced_frame = 1;
986 if (
sps->bit_depth_luma < 8 ||
sps->bit_depth_luma > 14 ||
987 sps->bit_depth_luma == 11 ||
sps->bit_depth_luma == 13
990 sps->bit_depth_luma);
995 h->cur_bit_depth_luma =
996 h->avctx->bits_per_raw_sample =
sps->bit_depth_luma;
997 h->cur_chroma_format_idc =
sps->chroma_format_idc;
998 h->pixel_shift =
sps->bit_depth_luma > 8;
999 h->chroma_format_idc =
sps->chroma_format_idc;
1000 h->bit_depth_luma =
sps->bit_depth_luma;
1003 sps->chroma_format_idc);
1007 sps->chroma_format_idc);
1013 for (
i = 0;
i <
h->nb_slice_ctx;
i++) {
1018 sl->
mvd_table[0] =
h->mvd_table[0] +
i * 8 * 2 *
h->mb_stride;
1019 sl->
mvd_table[1] =
h->mvd_table[1] +
i * 8 * 2 *
h->mb_stride;
1025 h->context_initialized = 1;
1030 h->context_initialized = 0;
1048 int needs_reinit = 0, must_reinit,
ret;
1056 h->ps.pps = (
const PPS*)
h->ps.pps_ref->data;
1059 if (
h->ps.sps !=
h->ps.pps->sps) {
1060 h->ps.sps = (
const SPS*)
h->ps.pps->sps;
1062 if (
h->mb_width !=
h->ps.sps->mb_width ||
1063 h->mb_height !=
h->ps.sps->mb_height ||
1064 h->cur_bit_depth_luma !=
h->ps.sps->bit_depth_luma ||
1065 h->cur_chroma_format_idc !=
h->ps.sps->chroma_format_idc
1069 if (
h->bit_depth_luma !=
h->ps.sps->bit_depth_luma ||
1070 h->chroma_format_idc !=
h->ps.sps->chroma_format_idc)
1075 must_reinit = (
h->context_initialized &&
1076 ( 16*
sps->mb_width !=
h->avctx->coded_width
1077 || 16*
sps->mb_height !=
h->avctx->coded_height
1078 ||
h->cur_bit_depth_luma !=
sps->bit_depth_luma
1079 ||
h->cur_chroma_format_idc !=
sps->chroma_format_idc
1080 ||
h->mb_width !=
sps->mb_width
1081 ||
h->mb_height !=
sps->mb_height
1087 if (first_slice &&
av_cmp_q(
sps->vui.sar,
h->avctx->sample_aspect_ratio))
1090 if (!
h->setup_finished) {
1092 h->avctx->level =
sps->level_idc;
1093 h->avctx->refs =
sps->ref_frame_count;
1095 h->mb_width =
sps->mb_width;
1096 h->mb_height =
sps->mb_height;
1097 h->mb_num =
h->mb_width *
h->mb_height;
1098 h->mb_stride =
h->mb_width + 1;
1100 h->b_stride =
h->mb_width * 4;
1102 h->chroma_y_shift =
sps->chroma_format_idc <= 1;
1104 h->width = 16 *
h->mb_width;
1105 h->height = 16 *
h->mb_height;
1109 if (
sps->vui.video_signal_type_present_flag) {
1112 if (
sps->vui.colour_description_present_flag) {
1113 if (
h->avctx->colorspace !=
sps->vui.matrix_coeffs)
1115 h->avctx->color_primaries =
sps->vui.colour_primaries;
1116 h->avctx->color_trc =
sps->vui.transfer_characteristics;
1117 h->avctx->colorspace =
sps->vui.matrix_coeffs;
1121 if (
h->sei.common.alternative_transfer.present &&
1124 h->avctx->color_trc =
h->sei.common.alternative_transfer.preferred_transfer_characteristics;
1127 h->avctx->chroma_sample_location =
sps->vui.chroma_location;
1129 if (!
h->context_initialized || must_reinit || needs_reinit) {
1130 int flush_changes =
h->context_initialized;
1131 h->context_initialized = 0;
1132 if (sl !=
h->slice_ctx) {
1134 "changing width %d -> %d / height %d -> %d on "
1136 h->width,
h->avctx->coded_width,
1137 h->height,
h->avctx->coded_height,
1138 h->current_slice + 1);
1149 h->avctx->pix_fmt =
ret;
1156 "h264_slice_header_init() failed\n");
1169 int interlaced_frame = 0, top_field_first = 0;
1173 out->repeat_pict = 0;
1178 if (
h->sei.picture_timing.present) {
1185 h->sei.picture_timing.present = 0;
1189 if (
sps->pic_struct_present_flag &&
h->sei.picture_timing.present) {
1191 switch (
pt->pic_struct) {
1196 interlaced_frame = 1;
1201 interlaced_frame = 1;
1204 interlaced_frame = !!
h->prev_interlaced_frame;
1211 out->repeat_pict = 1;
1214 out->repeat_pict = 2;
1217 out->repeat_pict = 4;
1221 if ((
pt->ct_type & 3) &&
1223 interlaced_frame = ((
pt->ct_type & (1 << 1)) != 0);
1228 h->prev_interlaced_frame = interlaced_frame;
1234 if (
sps->pic_struct_present_flag &&
h->sei.picture_timing.present) {
1239 top_field_first = 1;
1240 }
else if (interlaced_frame) {
1243 top_field_first = 1;
1252 &
sps->vui,
sps->bit_depth_luma,
sps->bit_depth_chroma,
1253 cur->
poc + (
unsigned)(
h->poc_offset << 5));
1257 if (
h->sei.picture_timing.timecode_cnt > 0) {
1263 sizeof(uint32_t)*4);
1267 tc_sd = (uint32_t*)tcside->
data;
1268 tc_sd[0] =
h->sei.picture_timing.timecode_cnt;
1270 for (
int i = 0;
i < tc_sd[0];
i++) {
1271 int drop =
h->sei.picture_timing.timecode[
i].dropframe;
1272 int hh =
h->sei.picture_timing.timecode[
i].hours;
1273 int mm =
h->sei.picture_timing.timecode[
i].minutes;
1274 int ss =
h->sei.picture_timing.timecode[
i].seconds;
1275 int ff =
h->sei.picture_timing.timecode[
i].frame;
1281 h->sei.picture_timing.timecode_cnt = 0;
1292 int i, pics, out_of_order, out_idx;
1297 if (
sps->bitstream_restriction_flag ||
1299 h->avctx->has_b_frames =
FFMAX(
h->avctx->has_b_frames,
sps->num_reorder_frames);
1302 for (
i = 0; 1;
i++) {
1305 h->last_pocs[
i-1] = cur->
poc;
1308 h->last_pocs[
i-1]=
h->last_pocs[
i];
1314 out_of_order =
FFMAX(out_of_order, 1);
1318 h->last_pocs[
i] = INT_MIN;
1319 h->last_pocs[0] = cur->
poc;
1321 }
else if(
h->avctx->has_b_frames < out_of_order && !
sps->bitstream_restriction_flag){
1323 av_log(
h->avctx, loglevel,
"Increasing reorder buffer to %d\n", out_of_order);
1324 h->avctx->has_b_frames = out_of_order;
1328 while (
h->delayed_pic[pics])
1333 h->delayed_pic[pics++] = cur;
1337 out =
h->delayed_pic[0];
1339 for (
i = 1;
h->delayed_pic[
i] &&
1341 !
h->delayed_pic[
i]->mmco_reset;
1343 if (
h->delayed_pic[
i]->poc <
out->poc) {
1344 out =
h->delayed_pic[
i];
1347 if (
h->avctx->has_b_frames == 0 &&
1349 h->next_outputed_poc = INT_MIN;
1350 out_of_order =
out->poc <
h->next_outputed_poc;
1352 if (out_of_order || pics >
h->avctx->has_b_frames) {
1354 for (
i = out_idx;
h->delayed_pic[
i];
i++)
1355 h->delayed_pic[
i] =
h->delayed_pic[
i + 1];
1357 if (!out_of_order && pics >
h->avctx->has_b_frames) {
1358 h->next_output_pic =
out;
1359 if (out_idx == 0 &&
h->delayed_pic[0] && ((
h->delayed_pic[0]->f->flags &
AV_FRAME_FLAG_KEY) ||
h->delayed_pic[0]->mmco_reset)) {
1360 h->next_outputed_poc = INT_MIN;
1362 h->next_outputed_poc =
out->poc;
1364 if (
out->recovered) {
1371 if (!
out->recovered) {
1374 h->next_output_pic =
NULL;
1391 const H2645NAL *nal,
int first_slice)
1396 int last_pic_structure, last_pic_droppable,
ret;
1404 if (
sps &&
sps->bitstream_restriction_flag &&
1405 h->avctx->has_b_frames <
sps->num_reorder_frames) {
1406 h->avctx->has_b_frames =
sps->num_reorder_frames;
1409 last_pic_droppable =
h->droppable;
1410 last_pic_structure =
h->picture_structure;
1411 h->droppable = (nal->
ref_idc == 0);
1422 else if (
h->picture_intra_only)
1427 if (
h->poc.frame_num !=
h->poc.prev_frame_num) {
1428 int unwrap_prev_frame_num =
h->poc.prev_frame_num;
1429 int max_frame_num = 1 <<
sps->log2_max_frame_num;
1431 if (unwrap_prev_frame_num >
h->poc.frame_num)
1432 unwrap_prev_frame_num -= max_frame_num;
1434 if ((
h->poc.frame_num - unwrap_prev_frame_num) >
sps->ref_frame_count) {
1435 unwrap_prev_frame_num = (
h->poc.frame_num -
sps->ref_frame_count) - 1;
1436 if (unwrap_prev_frame_num < 0)
1437 unwrap_prev_frame_num += max_frame_num;
1439 h->poc.prev_frame_num = unwrap_prev_frame_num;
1448 if (
h->first_field) {
1455 if (
h->cur_pic_ptr->tf.owner[last_field] ==
h->avctx) {
1460 if (!
FIELD_PICTURE(
h) ||
h->picture_structure == last_pic_structure) {
1468 if (
h->cur_pic_ptr->frame_num !=
h->poc.frame_num) {
1484 "Invalid field mode combination %d/%d\n",
1485 last_pic_structure,
h->picture_structure);
1486 h->picture_structure = last_pic_structure;
1487 h->droppable = last_pic_droppable;
1489 }
else if (last_pic_droppable !=
h->droppable) {
1491 "Found reference and non-reference fields in the same frame, which");
1492 h->picture_structure = last_pic_structure;
1493 h->droppable = last_pic_droppable;
1500 while (
h->poc.frame_num !=
h->poc.prev_frame_num && !
h->first_field &&
1501 h->poc.frame_num != (
h->poc.prev_frame_num + 1) % (1 <<
sps->log2_max_frame_num)) {
1504 h->poc.frame_num,
h->poc.prev_frame_num);
1505 if (!
sps->gaps_in_frame_num_allowed_flag)
1507 h->last_pocs[
i] = INT_MIN;
1514 h->poc.prev_frame_num++;
1515 h->poc.prev_frame_num %= 1 <<
sps->log2_max_frame_num;
1516 h->cur_pic_ptr->frame_num =
h->poc.prev_frame_num;
1517 h->cur_pic_ptr->invalid_gap = !
sps->gaps_in_frame_num_allowed_flag;
1521 h->explicit_ref_marking = 0;
1532 if (
h->short_ref_count) {
1534 1<<(
h->ps.sps->bit_depth_luma-1),
1535 1<<(
h->ps.sps->bit_depth_chroma-1),
1536 1<<(
h->ps.sps->bit_depth_chroma-1),
1541 h->short_ref[0]->f->width == prev->
f->
width &&
1542 h->short_ref[0]->f->height == prev->
f->
height &&
1543 h->short_ref[0]->f->format == prev->
f->
format) {
1548 h->short_ref[0]->tf.f =
h->short_ref[0]->f;
1552 h->short_ref[0]->poc = prev->
poc + 2
U;
1554 if (
h->short_ref[0]->field_picture)
1556 }
else if (!
h->frame_recovered && !
h->avctx->hwaccel)
1558 h->short_ref[0]->frame_num =
h->poc.prev_frame_num;
1565 if (
h->first_field) {
1571 if (!
FIELD_PICTURE(
h) ||
h->picture_structure == last_pic_structure) {
1574 h->missing_fields ++;
1575 h->cur_pic_ptr =
NULL;
1578 h->missing_fields = 0;
1579 if (
h->cur_pic_ptr->frame_num !=
h->poc.frame_num) {
1586 h->cur_pic_ptr =
NULL;
1592 h->cur_pic_ptr =
NULL;
1611 h->cur_pic_ptr->tf.owner[
field] =
h->avctx;
1617 memset(
h->slice_table +
i*
h->mb_stride, -1, (
h->mb_stride - (
i+1==
h->mb_height)) *
sizeof(*
h->slice_table));
1619 memset(
h->slice_table, -1,
1620 (
h->mb_height *
h->mb_stride - 1) *
sizeof(*
h->slice_table));
1624 h->ps.sps, &
h->poc,
h->picture_structure, nal->
ref_idc);
1634 if (
h->sei.recovery_point.recovery_frame_cnt >= 0) {
1635 const int sei_recovery_frame_cnt =
h->sei.recovery_point.recovery_frame_cnt;
1638 h->valid_recovery_point = 1;
1640 if (
h->recovery_frame < 0
1641 ||
av_mod_uintp2(
h->recovery_frame -
h->poc.frame_num,
h->ps.sps->log2_max_frame_num) > sei_recovery_frame_cnt) {
1642 h->recovery_frame =
av_mod_uintp2(
h->poc.frame_num + sei_recovery_frame_cnt,
h->ps.sps->log2_max_frame_num);
1644 if (!
h->valid_recovery_point)
1645 h->recovery_frame =
h->poc.frame_num;
1652 (
h->recovery_frame ==
h->poc.frame_num && nal->
ref_idc)) {
1653 h->recovery_frame = -1;
1654 h->cur_pic_ptr->recovered = 1;
1661 h->cur_pic_ptr->recovered |=
h->frame_recovered;
1688 unsigned int slice_type,
tmp,
i;
1689 int field_pic_flag, bottom_field_flag;
1690 int first_slice = sl ==
h->slice_ctx && !
h->current_slice;
1691 int picture_structure;
1699 if (slice_type > 9) {
1701 "slice type %d too large at %d\n",
1705 if (slice_type > 4) {
1726 if (!
h->ps.pps_list[sl->
pps_id]) {
1728 "non-existing PPS %u referenced\n",
1746 if (
sps->frame_mbs_only_flag) {
1750 av_log(
h->avctx,
AV_LOG_ERROR,
"This stream was generated by a broken encoder, invalid 8x8 inference\n");
1754 if (field_pic_flag) {
1774 if (idr_pic_id < 65536) {
1782 if (
sps->poc_type == 0) {
1785 if (
pps->pic_order_present == 1 && picture_structure ==
PICT_FRAME)
1790 if (
sps->poc_type == 1 && !
sps->delta_pic_order_always_zero_flag) {
1793 if (
pps->pic_order_present == 1 && picture_structure ==
PICT_FRAME)
1798 if (
pps->redundant_pic_cnt_present)
1806 picture_structure,
h->avctx);
1819 for (
i = 0;
i < 2;
i++) {
1824 (
pps->weighted_bipred_idc == 1 &&
1828 picture_structure,
h->avctx);
1851 if (
tmp > 51 + 6 * (
sps->bit_depth_luma - 8)) {
1868 if (
pps->deblocking_filter_parameters_present) {
1872 "deblocking_filter_idc %u out of range\n",
tmp);
1882 if (slice_alpha_c0_offset_div2 > 6 ||
1883 slice_alpha_c0_offset_div2 < -6 ||
1884 slice_beta_offset_div2 > 6 ||
1885 slice_beta_offset_div2 < -6) {
1887 "deblocking filter parameters %d %d out of range\n",
1888 slice_alpha_c0_offset_div2, slice_beta_offset_div2);
1928 if (
h->ps.pps->weighted_bipred_idc == 2 &&
1939 if (!
h->setup_finished)
1959 h->postpone_filter = 1;
1965 h->ps.pps->chroma_qp_index_offset[0],
1966 h->ps.pps->chroma_qp_index_offset[1]) +
1967 6 * (
h->ps.sps->bit_depth_luma - 8);
1980 for (j = 0; j < 2; j++) {
1983 for (
i = 0;
i < 16;
i++) {
1985 if (j < sl->list_count && i < sl->ref_count[j] &&
1989 for (k = 0; k <
h->short_ref_count; k++)
1990 if (
h->short_ref[k]->f->buf[0]->buffer == buf) {
1994 for (k = 0; k <
h->long_ref_count; k++)
1995 if (
h->long_ref[k] &&
h->long_ref[k]->f->buf[0]->buffer == buf) {
1996 id_list[
i] =
h->short_ref_count + k;
2004 for (
i = 0;
i < 16;
i++)
2007 ref2frm[18 + 1] = -1;
2008 for (
i = 16;
i < 48;
i++)
2009 ref2frm[
i + 4] = 4 * id_list[(
i - 16) >> 1] +
2015 "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",
2023 h->cur_pic_ptr->field_poc[0],
2024 h->cur_pic_ptr->field_poc[1],
2040 int first_slice = sl ==
h->slice_ctx && !
h->current_slice;
2056 if (
h->setup_finished) {
2063 if (
h->current_slice) {
2066 if (
h->nb_slice_ctx_queued) {
2073 memcpy(&tmp_ctx,
h->slice_ctx,
sizeof(tmp_ctx));
2074 memcpy(
h->slice_ctx, sl,
sizeof(tmp_ctx));
2075 memcpy(sl, &tmp_ctx,
sizeof(tmp_ctx));
2088 h->cur_pic_ptr =
NULL;
2095 if (!
h->first_field) {
2096 if (
h->cur_pic_ptr && !
h->droppable) {
2100 h->cur_pic_ptr =
NULL;
2104 if (!
h->current_slice)
2107 if (
h->current_slice == 0 && !
h->first_field) {
2121 if (
h->ps.pps->sps_id !=
pps->sps_id ||
2122 h->ps.pps->transform_8x8_mode !=
pps->transform_8x8_mode
2127 if (
h->ps.sps !=
pps->sps) {
2129 "SPS changed in the middle of the frame\n");
2134 if (
h->current_slice == 0) {
2140 h->droppable != (nal->
ref_idc == 0)) {
2142 "Changing field mode (%d -> %d) between slices is not allowed\n",
2145 }
else if (!
h->cur_pic_ptr) {
2147 "unset cur_pic_ptr on slice %d\n",
2148 h->current_slice + 1);
2157 h->nb_slice_ctx_queued++;
2182 int mb_type,
int top_xy,
2186 int mb_xy,
int list)
2188 int b_stride =
h->b_stride;
2193 const int b_xy =
h->mb2b_xy[top_xy] + 3 * b_stride;
2194 const int b8_xy = 4 * top_xy + 2;
2197 ref_cache[0 - 1 * 8] =
2198 ref_cache[1 - 1 * 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 0]];
2199 ref_cache[2 - 1 * 8] =
2200 ref_cache[3 - 1 * 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 1]];
2208 const int b_xy =
h->mb2b_xy[left_xy[
LTOP]] + 3;
2209 const int b8_xy = 4 * left_xy[
LTOP] + 1;
2211 AV_COPY32(mv_dst - 1 + 0,
h->cur_pic.motion_val[
list][b_xy + b_stride * 0]);
2212 AV_COPY32(mv_dst - 1 + 8,
h->cur_pic.motion_val[
list][b_xy + b_stride * 1]);
2213 AV_COPY32(mv_dst - 1 + 16,
h->cur_pic.motion_val[
list][b_xy + b_stride * 2]);
2214 AV_COPY32(mv_dst - 1 + 24,
h->cur_pic.motion_val[
list][b_xy + b_stride * 3]);
2216 ref_cache[-1 + 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 2 * 0]];
2217 ref_cache[-1 + 16] =
2218 ref_cache[-1 + 24] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 2 * 1]];
2226 ref_cache[-1 + 16] =
2242 int8_t *
ref = &
h->cur_pic.ref_index[
list][4 * mb_xy];
2244 uint32_t ref01 = (
pack16to32(ref2frm[
ref[0]], ref2frm[
ref[1]]) & 0x00FF00FF) * 0x0101;
2245 uint32_t ref23 = (
pack16to32(ref2frm[
ref[2]], ref2frm[
ref[3]]) & 0x00FF00FF) * 0x0101;
2246 AV_WN32A(&ref_cache[0 * 8], ref01);
2247 AV_WN32A(&ref_cache[1 * 8], ref01);
2248 AV_WN32A(&ref_cache[2 * 8], ref23);
2249 AV_WN32A(&ref_cache[3 * 8], ref23);
2253 int16_t(*mv_src)[2] = &
h->cur_pic.motion_val[
list][4 * sl->
mb_x + 4 * sl->
mb_y * b_stride];
2254 AV_COPY128(mv_dst + 8 * 0, mv_src + 0 * b_stride);
2255 AV_COPY128(mv_dst + 8 * 1, mv_src + 1 * b_stride);
2256 AV_COPY128(mv_dst + 8 * 2, mv_src + 2 * b_stride);
2257 AV_COPY128(mv_dst + 8 * 3, mv_src + 3 * b_stride);
2266 const int mb_xy = sl->
mb_xy;
2272 top_xy = mb_xy - (
h->mb_stride <<
MB_FIELD(sl));
2274 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy - 1;
2276 const int left_mb_field_flag =
IS_INTERLACED(
h->cur_pic.mb_type[mb_xy - 1]);
2279 if (left_mb_field_flag != curr_mb_field_flag)
2280 left_xy[
LTOP] -=
h->mb_stride;
2282 if (curr_mb_field_flag)
2283 top_xy +=
h->mb_stride &
2284 (((
h->cur_pic.mb_type[top_xy] >> 7) & 1) - 1);
2285 if (left_mb_field_flag != curr_mb_field_flag)
2286 left_xy[
LBOT] +=
h->mb_stride;
2298 int qp =
h->cur_pic.qscale_table[mb_xy];
2299 if (qp <= qp_thresh &&
2300 (left_xy[
LTOP] < 0 ||
2301 ((qp +
h->cur_pic.qscale_table[left_xy[
LTOP]] + 1) >> 1) <= qp_thresh) &&
2303 ((qp +
h->cur_pic.qscale_table[top_xy] + 1) >> 1) <= qp_thresh)) {
2306 if ((left_xy[
LTOP] < 0 ||
2307 ((qp +
h->cur_pic.qscale_table[left_xy[
LBOT]] + 1) >> 1) <= qp_thresh) &&
2308 (top_xy <
h->mb_stride ||
2309 ((qp +
h->cur_pic.qscale_table[top_xy -
h->mb_stride] + 1) >> 1) <= qp_thresh))
2314 top_type =
h->cur_pic.mb_type[top_xy];
2315 left_type[
LTOP] =
h->cur_pic.mb_type[left_xy[
LTOP]];
2316 left_type[
LBOT] =
h->cur_pic.mb_type[left_xy[
LBOT]];
2321 left_type[
LTOP] = left_type[
LBOT] = 0;
2323 if (
h->slice_table[top_xy] == 0xFFFF)
2325 if (
h->slice_table[left_xy[
LBOT]] == 0xFFFF)
2326 left_type[
LTOP] = left_type[
LBOT] = 0;
2336 top_type, left_type, mb_xy, 0);
2339 top_type, left_type, mb_xy, 1);
2341 nnz =
h->non_zero_count[mb_xy];
2343 AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]);
2344 AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]);
2345 AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]);
2346 AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]);
2347 sl->
cbp =
h->cbp_table[mb_xy];
2350 nnz =
h->non_zero_count[top_xy];
2351 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[3 * 4]);
2354 if (left_type[
LTOP]) {
2355 nnz =
h->non_zero_count[left_xy[
LTOP]];
2356 nnz_cache[3 + 8 * 1] = nnz[3 + 0 * 4];
2357 nnz_cache[3 + 8 * 2] = nnz[3 + 1 * 4];
2358 nnz_cache[3 + 8 * 3] = nnz[3 + 2 * 4];
2359 nnz_cache[3 + 8 * 4] = nnz[3 + 3 * 4];
2364 if (!
CABAC(
h) &&
h->ps.pps->transform_8x8_mode) {
2366 nnz_cache[4 + 8 * 0] =
2367 nnz_cache[5 + 8 * 0] = (
h->cbp_table[top_xy] & 0x4000) >> 12;
2368 nnz_cache[6 + 8 * 0] =
2369 nnz_cache[7 + 8 * 0] = (
h->cbp_table[top_xy] & 0x8000) >> 12;
2372 nnz_cache[3 + 8 * 1] =
2373 nnz_cache[3 + 8 * 2] = (
h->cbp_table[left_xy[
LTOP]] & 0x2000) >> 12;
2376 nnz_cache[3 + 8 * 3] =
2377 nnz_cache[3 + 8 * 4] = (
h->cbp_table[left_xy[
LBOT]] & 0x8000) >> 12;
2381 nnz_cache[
scan8[0]] =
2382 nnz_cache[
scan8[1]] =
2383 nnz_cache[
scan8[2]] =
2384 nnz_cache[
scan8[3]] = (sl->
cbp & 0x1000) >> 12;
2386 nnz_cache[
scan8[0 + 4]] =
2387 nnz_cache[
scan8[1 + 4]] =
2388 nnz_cache[
scan8[2 + 4]] =
2389 nnz_cache[
scan8[3 + 4]] = (sl->
cbp & 0x2000) >> 12;
2391 nnz_cache[
scan8[0 + 8]] =
2392 nnz_cache[
scan8[1 + 8]] =
2393 nnz_cache[
scan8[2 + 8]] =
2394 nnz_cache[
scan8[3 + 8]] = (sl->
cbp & 0x4000) >> 12;
2396 nnz_cache[
scan8[0 + 12]] =
2397 nnz_cache[
scan8[1 + 12]] =
2398 nnz_cache[
scan8[2 + 12]] =
2399 nnz_cache[
scan8[3 + 12]] = (sl->
cbp & 0x8000) >> 12;
2408 uint8_t *dest_y, *dest_cb, *dest_cr;
2409 int linesize, uvlinesize, mb_x, mb_y;
2412 const int pixel_shift =
h->pixel_shift;
2413 const int block_h = 16 >>
h->chroma_y_shift;
2415 if (
h->postpone_filter)
2419 for (mb_x = start_x; mb_x < end_x; mb_x++)
2420 for (mb_y = end_mb_y -
FRAME_MBAFF(
h); mb_y <= end_mb_y; mb_y++) {
2422 mb_xy = sl->
mb_xy = mb_x + mb_y *
h->mb_stride;
2423 mb_type =
h->cur_pic.mb_type[mb_xy];
2431 dest_y =
h->cur_pic.f->data[0] +
2432 ((mb_x << pixel_shift) + mb_y * sl->
linesize) * 16;
2433 dest_cb =
h->cur_pic.f->data[1] +
2434 (mb_x << pixel_shift) * (8 <<
CHROMA444(
h)) +
2436 dest_cr =
h->cur_pic.f->data[2] +
2437 (mb_x << pixel_shift) * (8 <<
CHROMA444(
h)) +
2462 linesize, uvlinesize);
2465 dest_cr, linesize, uvlinesize);
2478 const int mb_xy = sl->
mb_x + sl->
mb_y *
h->mb_stride;
2479 int mb_type = (
h->slice_table[mb_xy - 1] == sl->
slice_num) ?
2480 h->cur_pic.mb_type[mb_xy - 1] :
2481 (
h->slice_table[mb_xy -
h->mb_stride] == sl->
slice_num) ?
2482 h->cur_pic.mb_type[mb_xy -
h->mb_stride] : 0;
2497 if ((top +
height) >= pic_height)
2498 height += deblock_border;
2499 top -= deblock_border;
2502 if (top >= pic_height || (top +
height) < 0)
2513 if (
h->droppable ||
h->er.error_occurred)
2521 int startx,
int starty,
2522 int endx,
int endy,
int status)
2527 if (CONFIG_ERROR_RESILIENCE) {
2536 int lf_x_start = sl->
mb_x;
2540 sl->
linesize =
h->cur_pic_ptr->f->linesize[0];
2551 if (
h->postpone_filter)
2567 if (
h->ps.pps->cabac) {
2611 if (sl->
mb_x >= lf_x_start)
2627 if (++sl->
mb_x >=
h->mb_width) {
2629 sl->
mb_x = lf_x_start = 0;
2639 if (eos || sl->
mb_y >=
h->mb_height) {
2640 ff_tlog(
h->avctx,
"slice end %d %d\n",
2644 if (sl->
mb_x > lf_x_start)
2678 "error while decoding MB %d %d\n", sl->
mb_x, sl->
mb_y);
2684 if (++sl->
mb_x >=
h->mb_width) {
2686 sl->
mb_x = lf_x_start = 0;
2694 if (sl->
mb_y >=
h->mb_height) {
2695 ff_tlog(
h->avctx,
"slice end %d %d\n",
2714 ff_tlog(
h->avctx,
"slice end %d %d\n",
2720 if (sl->
mb_x > lf_x_start)
2748 int context_count =
h->nb_slice_ctx_queued;
2752 h->slice_ctx[0].next_slice_idx = INT_MAX;
2754 if (
h->avctx->hwaccel || context_count < 1)
2757 av_assert0(context_count &&
h->slice_ctx[context_count - 1].mb_y <
h->mb_height);
2759 if (context_count == 1) {
2761 h->slice_ctx[0].next_slice_idx =
h->mb_width *
h->mb_height;
2762 h->postpone_filter = 0;
2765 h->mb_y =
h->slice_ctx[0].mb_y;
2770 for (
i = 0;
i < context_count;
i++) {
2771 int next_slice_idx =
h->mb_width *
h->mb_height;
2774 sl = &
h->slice_ctx[
i];
2777 slice_idx = sl->
mb_y *
h->mb_width + sl->
mb_x;
2778 for (j = 0; j < context_count; j++) {
2780 int slice_idx2 = sl2->
mb_y *
h->mb_width + sl2->
mb_x;
2782 if (
i == j || slice_idx2 < slice_idx)
2784 next_slice_idx =
FFMIN(next_slice_idx, slice_idx2);
2790 NULL, context_count,
sizeof(
h->slice_ctx[0]));
2793 sl = &
h->slice_ctx[context_count - 1];
2796 if (
h->postpone_filter) {
2797 h->postpone_filter = 0;
2799 for (
i = 0;
i < context_count;
i++) {
2802 sl = &
h->slice_ctx[
i];
2804 x_end = (sl->
mb_y >=
h->mb_height) ?
h->mb_width : sl->
mb_x;
2809 j == y_end - 1 ? x_end :
h->mb_width);
2816 h->nb_slice_ctx_queued = 0;