28 #include "config_components.h"
53 0 + 0 * 4, 0 + 1 * 4, 1 + 0 * 4, 0 + 2 * 4,
54 0 + 3 * 4, 1 + 1 * 4, 1 + 2 * 4, 1 + 3 * 4,
55 2 + 0 * 4, 2 + 1 * 4, 2 + 2 * 4, 2 + 3 * 4,
56 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4, 3 + 3 * 4,
60 0 + 0 * 8, 0 + 1 * 8, 0 + 2 * 8, 1 + 0 * 8,
61 1 + 1 * 8, 0 + 3 * 8, 0 + 4 * 8, 1 + 2 * 8,
62 2 + 0 * 8, 1 + 3 * 8, 0 + 5 * 8, 0 + 6 * 8,
63 0 + 7 * 8, 1 + 4 * 8, 2 + 1 * 8, 3 + 0 * 8,
64 2 + 2 * 8, 1 + 5 * 8, 1 + 6 * 8, 1 + 7 * 8,
65 2 + 3 * 8, 3 + 1 * 8, 4 + 0 * 8, 3 + 2 * 8,
66 2 + 4 * 8, 2 + 5 * 8, 2 + 6 * 8, 2 + 7 * 8,
67 3 + 3 * 8, 4 + 1 * 8, 5 + 0 * 8, 4 + 2 * 8,
68 3 + 4 * 8, 3 + 5 * 8, 3 + 6 * 8, 3 + 7 * 8,
69 4 + 3 * 8, 5 + 1 * 8, 6 + 0 * 8, 5 + 2 * 8,
70 4 + 4 * 8, 4 + 5 * 8, 4 + 6 * 8, 4 + 7 * 8,
71 5 + 3 * 8, 6 + 1 * 8, 6 + 2 * 8, 5 + 4 * 8,
72 5 + 5 * 8, 5 + 6 * 8, 5 + 7 * 8, 6 + 3 * 8,
73 7 + 0 * 8, 7 + 1 * 8, 6 + 4 * 8, 6 + 5 * 8,
74 6 + 6 * 8, 6 + 7 * 8, 7 + 2 * 8, 7 + 3 * 8,
75 7 + 4 * 8, 7 + 5 * 8, 7 + 6 * 8, 7 + 7 * 8,
79 0 + 0 * 8, 1 + 1 * 8, 2 + 0 * 8, 0 + 7 * 8,
80 2 + 2 * 8, 2 + 3 * 8, 2 + 4 * 8, 3 + 3 * 8,
81 3 + 4 * 8, 4 + 3 * 8, 4 + 4 * 8, 5 + 3 * 8,
82 5 + 5 * 8, 7 + 0 * 8, 6 + 6 * 8, 7 + 4 * 8,
83 0 + 1 * 8, 0 + 3 * 8, 1 + 3 * 8, 1 + 4 * 8,
84 1 + 5 * 8, 3 + 1 * 8, 2 + 5 * 8, 4 + 1 * 8,
85 3 + 5 * 8, 5 + 1 * 8, 4 + 5 * 8, 6 + 1 * 8,
86 5 + 6 * 8, 7 + 1 * 8, 6 + 7 * 8, 7 + 5 * 8,
87 0 + 2 * 8, 0 + 4 * 8, 0 + 5 * 8, 2 + 1 * 8,
88 1 + 6 * 8, 4 + 0 * 8, 2 + 6 * 8, 5 + 0 * 8,
89 3 + 6 * 8, 6 + 0 * 8, 4 + 6 * 8, 6 + 2 * 8,
90 5 + 7 * 8, 6 + 4 * 8, 7 + 2 * 8, 7 + 6 * 8,
91 1 + 0 * 8, 1 + 2 * 8, 0 + 6 * 8, 3 + 0 * 8,
92 1 + 7 * 8, 3 + 2 * 8, 2 + 7 * 8, 4 + 2 * 8,
93 3 + 7 * 8, 5 + 2 * 8, 4 + 7 * 8, 5 + 4 * 8,
94 6 + 3 * 8, 6 + 5 * 8, 7 + 3 * 8, 7 + 7 * 8,
99 0 + 0 * 8, 1 + 1 * 8, 1 + 2 * 8, 2 + 2 * 8,
100 4 + 1 * 8, 0 + 5 * 8, 3 + 3 * 8, 7 + 0 * 8,
101 3 + 4 * 8, 1 + 7 * 8, 5 + 3 * 8, 6 + 3 * 8,
102 2 + 7 * 8, 6 + 4 * 8, 5 + 6 * 8, 7 + 5 * 8,
103 1 + 0 * 8, 2 + 0 * 8, 0 + 3 * 8, 3 + 1 * 8,
104 3 + 2 * 8, 0 + 6 * 8, 4 + 2 * 8, 6 + 1 * 8,
105 2 + 5 * 8, 2 + 6 * 8, 6 + 2 * 8, 5 + 4 * 8,
106 3 + 7 * 8, 7 + 3 * 8, 4 + 7 * 8, 7 + 6 * 8,
107 0 + 1 * 8, 3 + 0 * 8, 0 + 4 * 8, 4 + 0 * 8,
108 2 + 3 * 8, 1 + 5 * 8, 5 + 1 * 8, 5 + 2 * 8,
109 1 + 6 * 8, 3 + 5 * 8, 7 + 1 * 8, 4 + 5 * 8,
110 4 + 6 * 8, 7 + 4 * 8, 5 + 7 * 8, 6 + 7 * 8,
111 0 + 2 * 8, 2 + 1 * 8, 1 + 3 * 8, 5 + 0 * 8,
112 1 + 4 * 8, 2 + 4 * 8, 6 + 0 * 8, 4 + 3 * 8,
113 0 + 7 * 8, 4 + 4 * 8, 7 + 2 * 8, 3 + 6 * 8,
114 5 + 5 * 8, 6 + 5 * 8, 6 + 6 * 8, 7 + 7 * 8,
123 if (
h->DPB[
i].f->buf[0] && !
h->DPB[
i].reference &&
124 (remove_current || &
h->DPB[
i] !=
h->cur_pic_ptr)) {
141 h->mb_width * 16 * 3 *
sizeof(uint8_t) * 2);
143 h->mb_width * 16 * 3 *
sizeof(uint8_t) * 2);
164 const int big_mb_num =
h->mb_stride * (
h->mb_height + 1) + 1;
165 const int mb_array_size =
h->mb_stride *
h->mb_height;
166 const int b4_stride =
h->mb_width * 4 + 1;
167 const int b4_array_size = b4_stride *
h->mb_height * 4;
171 sizeof(uint32_t), 0);
176 if (!
h->qscale_table_pool || !
h->mb_type_pool || !
h->motion_val_pool ||
177 !
h->ref_index_pool) {
194 if (
h->sei.common.itut_t35.lcevc) {
219 if (
h->decode_error_flags_pool) {
227 int h_chroma_shift, v_chroma_shift;
229 &h_chroma_shift, &v_chroma_shift);
239 if (!
h->qscale_table_pool) {
253 for (
i = 0;
i < 2;
i++) {
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)
298 for (
i = 0;
i < count;
i++) {
312 for (
int p = 0;
p <
desc->nb_components;
p++) {
314 int is_chroma =
p == 1 ||
p == 2;
317 if (
desc->comp[0].depth >= 9) {
319 ((uint16_t*)
dst)[0] =
c[
p];
323 for (
int y = 1; y <
height; y++) {
328 for (
int y = 0; y <
height; y++) {
329 memset(
dst,
c[
p], bytes);
342 int inited =
h->context_initialized, err = 0;
349 if (inited && !h1->ps.sps)
353 (
h->width != h1->width ||
354 h->height != h1->height ||
355 h->mb_width != h1->mb_width ||
356 h->mb_height != h1->mb_height ||
358 h->ps.sps->bit_depth_luma != h1->ps.sps->bit_depth_luma ||
359 h->ps.sps->chroma_format_idc != h1->ps.sps->chroma_format_idc ||
360 h->ps.sps->vui.matrix_coeffs != h1->ps.sps->vui.matrix_coeffs)) {
365 memcpy(
h->block_offset, h1->block_offset,
sizeof(
h->block_offset));
374 h->ps.sps = h1->ps.sps;
376 if (need_reinit || !inited) {
377 h->width = h1->width;
378 h->height = h1->height;
379 h->mb_height = h1->mb_height;
380 h->mb_width = h1->mb_width;
381 h->mb_num = h1->mb_num;
382 h->mb_stride = h1->mb_stride;
383 h->b_stride = h1->b_stride;
384 h->x264_build = h1->x264_build;
386 if (
h->context_initialized || h1->context_initialized) {
394 memcpy(
h->block_offset, h1->block_offset,
sizeof(
h->block_offset));
397 h->width_from_caller = h1->width_from_caller;
398 h->height_from_caller = h1->height_from_caller;
399 h->first_field = h1->first_field;
400 h->picture_structure = h1->picture_structure;
401 h->mb_aff_frame = h1->mb_aff_frame;
402 h->droppable = h1->droppable;
415 h->enable_er = h1->enable_er;
416 h->workaround_bugs = h1->workaround_bugs;
417 h->droppable = h1->droppable;
420 h->is_avc = h1->is_avc;
421 h->nal_length_size = h1->nal_length_size;
423 memcpy(&
h->poc, &h1->poc,
sizeof(
h->poc));
425 memcpy(
h->short_ref, h1->short_ref,
sizeof(
h->short_ref));
426 memcpy(
h->long_ref, h1->long_ref,
sizeof(
h->long_ref));
427 memcpy(
h->delayed_pic, h1->delayed_pic,
sizeof(
h->delayed_pic));
428 memcpy(
h->last_pocs, h1->last_pocs,
sizeof(
h->last_pocs));
430 h->next_output_pic = h1->next_output_pic;
431 h->next_outputed_poc = h1->next_outputed_poc;
432 h->poc_offset = h1->poc_offset;
434 memcpy(
h->mmco, h1->mmco,
sizeof(
h->mmco));
435 h->nb_mmco = h1->nb_mmco;
436 h->mmco_reset = h1->mmco_reset;
437 h->explicit_ref_marking = h1->explicit_ref_marking;
438 h->long_ref_count = h1->long_ref_count;
439 h->short_ref_count = h1->short_ref_count;
446 h->frame_recovered = h1->frame_recovered;
452 h->sei.common.unregistered.x264_build = h1->sei.common.unregistered.x264_build;
459 h->poc.prev_poc_msb =
h->poc.poc_msb;
460 h->poc.prev_poc_lsb =
h->poc.poc_lsb;
462 h->poc.prev_frame_num_offset =
h->poc.frame_num_offset;
463 h->poc.prev_frame_num =
h->poc.frame_num;
465 h->recovery_frame = h1->recovery_frame;
466 h->non_gray = h1->non_gray;
487 const int pixel_shift =
h->pixel_shift;
495 h->cur_pic_ptr =
NULL;
504 pic->
reference =
h->droppable ? 0 :
h->picture_structure;
526 h->sei.common.film_grain_characteristics &&
527 h->sei.common.film_grain_characteristics->present &&
528 !
h->avctx->hwaccel &&
534 h->cur_pic_ptr = pic;
536 if (CONFIG_ERROR_RESILIENCE) {
543 for (
i = 0;
i <
h->nb_slice_ctx;
i++) {
544 h->slice_ctx[
i].linesize =
h->cur_pic_ptr->f->linesize[0];
545 h->slice_ctx[
i].uvlinesize =
h->cur_pic_ptr->f->linesize[1];
548 if (CONFIG_ERROR_RESILIENCE &&
h->enable_er) {
554 for (
i = 0;
i < 16;
i++) {
558 for (
i = 0;
i < 16;
i++) {
559 h->block_offset[16 +
i] =
561 h->block_offset[48 + 16 +
i] =
569 h->cur_pic_ptr->reference = 0;
571 h->cur_pic_ptr->field_poc[0] =
h->cur_pic_ptr->field_poc[1] = INT_MAX;
573 h->next_output_pic =
NULL;
575 h->postpone_filter = 0;
577 h->mb_aff_frame =
h->ps.sps->mb_aff && (
h->picture_structure ==
PICT_FRAME);
579 if (
h->sei.common.unregistered.x264_build >= 0)
580 h->x264_build =
h->sei.common.unregistered.x264_build;
582 assert(
h->cur_pic_ptr->long_ref == 0);
588 const uint8_t *src_y,
589 const uint8_t *src_cb,
const uint8_t *src_cr,
590 int linesize,
int uvlinesize,
595 const int pixel_shift =
h->pixel_shift;
600 src_cb -= uvlinesize;
601 src_cr -= uvlinesize;
607 AV_COPY128(top_border, src_y + 15 * linesize);
609 AV_COPY128(top_border + 16, src_y + 15 * linesize + 16);
613 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
614 AV_COPY128(top_border + 48, src_cb + 15 * uvlinesize + 16);
615 AV_COPY128(top_border + 64, src_cr + 15 * uvlinesize);
616 AV_COPY128(top_border + 80, src_cr + 15 * uvlinesize + 16);
618 AV_COPY128(top_border + 16, src_cb + 15 * uvlinesize);
619 AV_COPY128(top_border + 32, src_cr + 15 * uvlinesize);
621 }
else if (chroma422) {
623 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
624 AV_COPY128(top_border + 48, src_cr + 15 * uvlinesize);
626 AV_COPY64(top_border + 16, src_cb + 15 * uvlinesize);
627 AV_COPY64(top_border + 24, src_cr + 15 * uvlinesize);
631 AV_COPY128(top_border + 32, src_cb + 7 * uvlinesize);
632 AV_COPY128(top_border + 48, src_cr + 7 * uvlinesize);
634 AV_COPY64(top_border + 16, src_cb + 7 * uvlinesize);
635 AV_COPY64(top_border + 24, src_cr + 7 * uvlinesize);
649 AV_COPY128(top_border, src_y + 16 * linesize);
651 AV_COPY128(top_border + 16, src_y + 16 * linesize + 16);
656 AV_COPY128(top_border + 32, src_cb + 16 * linesize);
657 AV_COPY128(top_border + 48, src_cb + 16 * linesize + 16);
658 AV_COPY128(top_border + 64, src_cr + 16 * linesize);
659 AV_COPY128(top_border + 80, src_cr + 16 * linesize + 16);
661 AV_COPY128(top_border + 16, src_cb + 16 * linesize);
662 AV_COPY128(top_border + 32, src_cr + 16 * linesize);
664 }
else if (chroma422) {
666 AV_COPY128(top_border + 32, src_cb + 16 * uvlinesize);
667 AV_COPY128(top_border + 48, src_cr + 16 * uvlinesize);
669 AV_COPY64(top_border + 16, src_cb + 16 * uvlinesize);
670 AV_COPY64(top_border + 24, src_cr + 16 * uvlinesize);
674 AV_COPY128(top_border + 32, src_cb + 8 * uvlinesize);
675 AV_COPY128(top_border + 48, src_cr + 8 * uvlinesize);
677 AV_COPY64(top_border + 16, src_cb + 8 * uvlinesize);
678 AV_COPY64(top_border + 24, src_cr + 8 * uvlinesize);
691 int ref0, ref1,
i, cur_poc, ref_start, ref_count0, ref_count1;
693 for (
i = 0;
i < 2;
i++) {
700 cur_poc =
h->cur_pic_ptr->poc;
702 cur_poc =
h->cur_pic_ptr->field_poc[
h->picture_structure - 1];
714 cur_poc =
h->cur_pic_ptr->field_poc[
field];
725 for (ref0 = ref_start; ref0 < ref_count0; ref0++) {
727 for (ref1 = ref_start; ref1 < ref_count1; ref1++) {
734 int tx = (16384 + (
FFABS(td) >> 1)) / td;
735 int dist_scale_factor = (tb * tx + 32) >> 8;
736 if (dist_scale_factor >= -64 && dist_scale_factor <= 128)
737 w = 64 - dist_scale_factor;
756 for (
i = 0;
i < 16;
i++) {
757 #define TRANSPOSE(x) ((x) >> 2) | (((x) << 2) & 0xF)
762 for (
i = 0;
i < 64;
i++) {
763 #define TRANSPOSE(x) ((x) >> 3) | (((x) & 7) << 3)
770 if (
h->ps.sps->transform_bypass) {
774 memcpy(
h->field_scan_q0 ,
field_scan ,
sizeof(
h->field_scan_q0 ));
775 memcpy(
h->field_scan8x8_q0 ,
field_scan8x8 ,
sizeof(
h->field_scan8x8_q0 ));
778 memcpy(
h->zigzag_scan_q0 ,
h->zigzag_scan ,
sizeof(
h->zigzag_scan_q0 ));
779 memcpy(
h->zigzag_scan8x8_q0 ,
h->zigzag_scan8x8 ,
sizeof(
h->zigzag_scan8x8_q0 ));
780 memcpy(
h->zigzag_scan8x8_cavlc_q0 ,
h->zigzag_scan8x8_cavlc ,
sizeof(
h->zigzag_scan8x8_cavlc_q0));
781 memcpy(
h->field_scan_q0 ,
h->field_scan ,
sizeof(
h->field_scan_q0 ));
782 memcpy(
h->field_scan8x8_q0 ,
h->field_scan8x8 ,
sizeof(
h->field_scan8x8_q0 ));
783 memcpy(
h->field_scan8x8_cavlc_q0 ,
h->field_scan8x8_cavlc ,
sizeof(
h->field_scan8x8_cavlc_q0 ));
789 #define HWACCEL_MAX (CONFIG_H264_DXVA2_HWACCEL + \
790 (CONFIG_H264_D3D11VA_HWACCEL * 2) + \
791 CONFIG_H264_D3D12VA_HWACCEL + \
792 CONFIG_H264_NVDEC_HWACCEL + \
793 CONFIG_H264_VAAPI_HWACCEL + \
794 CONFIG_H264_VIDEOTOOLBOX_HWACCEL + \
795 CONFIG_H264_VDPAU_HWACCEL + \
796 CONFIG_H264_VULKAN_HWACCEL)
799 switch (
h->ps.sps->bit_depth_luma) {
812 #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL
816 #if CONFIG_H264_VULKAN_HWACCEL
819 #if CONFIG_H264_NVDEC_HWACCEL
830 #if CONFIG_H264_VAAPI_HWACCEL
840 #if CONFIG_H264_VULKAN_HWACCEL
865 #if CONFIG_H264_VDPAU_HWACCEL
868 #if CONFIG_H264_VULKAN_HWACCEL
871 #if CONFIG_H264_NVDEC_HWACCEL
874 #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL
891 #if CONFIG_H264_DXVA2_HWACCEL
894 #if CONFIG_H264_D3D11VA_HWACCEL
898 #if CONFIG_H264_D3D12VA_HWACCEL
901 #if CONFIG_H264_VAAPI_HWACCEL
912 "Unsupported bit depth %d\n",
h->ps.sps->bit_depth_luma);
919 if (
pix_fmts[
i] ==
h->avctx->pix_fmt && !force_callback)
928 int cr =
sps->crop_right;
929 int cl =
sps->crop_left;
930 int ct =
sps->crop_top;
931 int cb =
sps->crop_bottom;
938 if (
h->width_from_caller > 0 &&
h->height_from_caller > 0 &&
939 !
sps->crop_top && !
sps->crop_left &&
942 h->width_from_caller <=
width &&
943 h->height_from_caller <=
height) {
944 width =
h->width_from_caller;
945 height =
h->height_from_caller;
951 h->width_from_caller = 0;
952 h->height_from_caller = 0;
955 h->avctx->coded_width =
h->width;
956 h->avctx->coded_height =
h->height;
977 &
h->chroma_x_shift, &
h->chroma_y_shift);
979 if (
sps->timing_info_present_flag) {
981 if (
h->x264_build < 44
U)
983 av_reduce(&
h->avctx->framerate.den, &
h->avctx->framerate.num,
984 sps->num_units_in_tick * 2, den, 1 << 30);
990 h->prev_interlaced_frame = 1;
999 if (
sps->bit_depth_luma < 8 ||
sps->bit_depth_luma > 14 ||
1000 sps->bit_depth_luma == 11 ||
sps->bit_depth_luma == 13
1003 sps->bit_depth_luma);
1008 h->cur_bit_depth_luma =
1009 h->avctx->bits_per_raw_sample =
sps->bit_depth_luma;
1010 h->cur_chroma_format_idc =
sps->chroma_format_idc;
1011 h->pixel_shift =
sps->bit_depth_luma > 8;
1012 h->chroma_format_idc =
sps->chroma_format_idc;
1013 h->bit_depth_luma =
sps->bit_depth_luma;
1016 sps->chroma_format_idc);
1020 sps->chroma_format_idc);
1026 for (
i = 0;
i <
h->nb_slice_ctx;
i++) {
1031 sl->
mvd_table[0] =
h->mvd_table[0] +
i * 8 * 2 *
h->mb_stride;
1032 sl->
mvd_table[1] =
h->mvd_table[1] +
i * 8 * 2 *
h->mb_stride;
1038 h->context_initialized = 1;
1043 h->context_initialized = 0;
1061 int needs_reinit = 0, must_reinit,
ret;
1066 if (
h->ps.sps !=
h->ps.pps->sps) {
1067 h->ps.sps =
h->ps.pps->sps;
1069 if (
h->mb_width !=
h->ps.sps->mb_width ||
1070 h->mb_height !=
h->ps.sps->mb_height ||
1071 h->cur_bit_depth_luma !=
h->ps.sps->bit_depth_luma ||
1072 h->cur_chroma_format_idc !=
h->ps.sps->chroma_format_idc
1076 if (
h->bit_depth_luma !=
h->ps.sps->bit_depth_luma ||
1077 h->chroma_format_idc !=
h->ps.sps->chroma_format_idc)
1082 must_reinit = (
h->context_initialized &&
1083 ( 16*
sps->mb_width !=
h->avctx->coded_width
1084 || 16*
sps->mb_height !=
h->avctx->coded_height
1085 ||
h->cur_bit_depth_luma !=
sps->bit_depth_luma
1086 ||
h->cur_chroma_format_idc !=
sps->chroma_format_idc
1087 ||
h->mb_width !=
sps->mb_width
1088 ||
h->mb_height !=
sps->mb_height
1094 if (first_slice &&
av_cmp_q(
sps->vui.sar,
h->avctx->sample_aspect_ratio))
1097 if (!
h->setup_finished) {
1099 h->avctx->level =
sps->level_idc;
1100 h->avctx->refs =
sps->ref_frame_count;
1102 h->mb_width =
sps->mb_width;
1103 h->mb_height =
sps->mb_height;
1104 h->mb_num =
h->mb_width *
h->mb_height;
1105 h->mb_stride =
h->mb_width + 1;
1107 h->b_stride =
h->mb_width * 4;
1109 h->chroma_y_shift =
sps->chroma_format_idc <= 1;
1111 h->width = 16 *
h->mb_width;
1112 h->height = 16 *
h->mb_height;
1116 if (
sps->vui.video_signal_type_present_flag) {
1119 if (
sps->vui.colour_description_present_flag) {
1120 if (
h->avctx->colorspace !=
sps->vui.matrix_coeffs)
1122 h->avctx->color_primaries =
sps->vui.colour_primaries;
1123 h->avctx->color_trc =
sps->vui.transfer_characteristics;
1124 h->avctx->colorspace =
sps->vui.matrix_coeffs;
1128 if (
h->sei.common.alternative_transfer.present &&
1131 h->avctx->color_trc =
h->sei.common.alternative_transfer.preferred_transfer_characteristics;
1134 h->avctx->chroma_sample_location =
sps->vui.chroma_location;
1136 if (!
h->context_initialized || must_reinit || needs_reinit) {
1137 int flush_changes =
h->context_initialized;
1138 h->context_initialized = 0;
1139 if (sl !=
h->slice_ctx) {
1141 "changing width %d -> %d / height %d -> %d on "
1143 h->width,
h->avctx->coded_width,
1144 h->height,
h->avctx->coded_height,
1145 h->current_slice + 1);
1156 h->avctx->pix_fmt =
ret;
1163 "h264_slice_header_init() failed\n");
1176 int interlaced_frame = 0, top_field_first = 0;
1180 out->repeat_pict = 0;
1185 if (
h->sei.picture_timing.present) {
1192 h->sei.picture_timing.present = 0;
1196 if (
sps->pic_struct_present_flag &&
h->sei.picture_timing.present) {
1198 switch (
pt->pic_struct) {
1203 interlaced_frame = 1;
1208 interlaced_frame = 1;
1211 interlaced_frame = !!
h->prev_interlaced_frame;
1218 out->repeat_pict = 1;
1221 out->repeat_pict = 2;
1224 out->repeat_pict = 4;
1228 if ((
pt->ct_type & 3) &&
1230 interlaced_frame = ((
pt->ct_type & (1 << 1)) != 0);
1235 h->prev_interlaced_frame = interlaced_frame;
1241 if (
sps->pic_struct_present_flag &&
h->sei.picture_timing.present) {
1246 top_field_first = 1;
1247 }
else if (interlaced_frame) {
1250 top_field_first = 1;
1259 &
sps->vui,
sps->bit_depth_luma,
sps->bit_depth_chroma,
1260 cur->
poc + (
unsigned)(
h->poc_offset << 5));
1264 if (
h->sei.picture_timing.timecode_cnt > 0) {
1269 sizeof(uint32_t)*4, &tcside);
1274 tc_sd = (uint32_t*)tcside->
data;
1275 tc_sd[0] =
h->sei.picture_timing.timecode_cnt;
1277 for (
int i = 0;
i < tc_sd[0];
i++) {
1278 int drop =
h->sei.picture_timing.timecode[
i].dropframe;
1279 int hh =
h->sei.picture_timing.timecode[
i].hours;
1280 int mm =
h->sei.picture_timing.timecode[
i].minutes;
1281 int ss =
h->sei.picture_timing.timecode[
i].seconds;
1282 int ff =
h->sei.picture_timing.timecode[
i].frame;
1289 h->sei.picture_timing.timecode_cnt = 0;
1300 int i, pics, out_of_order, out_idx;
1305 if (
sps->bitstream_restriction_flag ||
1307 h->avctx->has_b_frames =
FFMAX(
h->avctx->has_b_frames,
sps->num_reorder_frames);
1310 for (
i = 0; 1;
i++) {
1313 h->last_pocs[
i-1] = cur->
poc;
1316 h->last_pocs[
i-1]=
h->last_pocs[
i];
1322 out_of_order =
FFMAX(out_of_order, 1);
1326 h->last_pocs[
i] = INT_MIN;
1327 h->last_pocs[0] = cur->
poc;
1329 }
else if(
h->avctx->has_b_frames < out_of_order && !
sps->bitstream_restriction_flag){
1331 av_log(
h->avctx, loglevel,
"Increasing reorder buffer to %d\n", out_of_order);
1332 h->avctx->has_b_frames = out_of_order;
1336 while (
h->delayed_pic[pics])
1341 h->delayed_pic[pics++] = cur;
1345 out =
h->delayed_pic[0];
1347 for (
i = 1;
h->delayed_pic[
i] &&
1349 !
h->delayed_pic[
i]->mmco_reset;
1351 if (
h->delayed_pic[
i]->poc <
out->poc) {
1352 out =
h->delayed_pic[
i];
1355 if (
h->avctx->has_b_frames == 0 &&
1357 h->next_outputed_poc = INT_MIN;
1358 out_of_order =
out->poc <
h->next_outputed_poc;
1360 if (out_of_order || pics >
h->avctx->has_b_frames) {
1362 for (
i = out_idx;
h->delayed_pic[
i];
i++)
1363 h->delayed_pic[
i] =
h->delayed_pic[
i + 1];
1365 if (!out_of_order && pics >
h->avctx->has_b_frames) {
1366 h->next_output_pic =
out;
1367 if (out_idx == 0 &&
h->delayed_pic[0] && ((
h->delayed_pic[0]->f->flags &
AV_FRAME_FLAG_KEY) ||
h->delayed_pic[0]->mmco_reset)) {
1368 h->next_outputed_poc = INT_MIN;
1370 h->next_outputed_poc =
out->poc;
1374 h->frame_recovered |=
out->recovered;
1378 if (!
out->recovered) {
1381 h->next_output_pic =
NULL;
1403 int last_pic_structure, last_pic_droppable,
ret;
1411 if (
sps->bitstream_restriction_flag &&
1412 h->avctx->has_b_frames <
sps->num_reorder_frames) {
1413 h->avctx->has_b_frames =
sps->num_reorder_frames;
1416 last_pic_droppable =
h->droppable;
1417 last_pic_structure =
h->picture_structure;
1418 h->droppable = (
nal->ref_idc == 0);
1429 else if (
h->picture_intra_only)
1434 if (
h->poc.frame_num !=
h->poc.prev_frame_num) {
1435 int unwrap_prev_frame_num =
h->poc.prev_frame_num;
1436 int max_frame_num = 1 <<
sps->log2_max_frame_num;
1438 if (unwrap_prev_frame_num >
h->poc.frame_num)
1439 unwrap_prev_frame_num -= max_frame_num;
1441 if ((
h->poc.frame_num - unwrap_prev_frame_num) >
sps->ref_frame_count) {
1442 unwrap_prev_frame_num = (
h->poc.frame_num -
sps->ref_frame_count) - 1;
1443 if (unwrap_prev_frame_num < 0)
1444 unwrap_prev_frame_num += max_frame_num;
1446 h->poc.prev_frame_num = unwrap_prev_frame_num;
1455 if (
h->first_field) {
1462 if (
h->cur_pic_ptr->tf.owner[last_field] ==
h->avctx) {
1467 if (!
FIELD_PICTURE(
h) ||
h->picture_structure == last_pic_structure) {
1475 if (
h->cur_pic_ptr->frame_num !=
h->poc.frame_num) {
1491 "Invalid field mode combination %d/%d\n",
1492 last_pic_structure,
h->picture_structure);
1493 h->picture_structure = last_pic_structure;
1494 h->droppable = last_pic_droppable;
1496 }
else if (last_pic_droppable !=
h->droppable) {
1498 "Found reference and non-reference fields in the same frame, which");
1499 h->picture_structure = last_pic_structure;
1500 h->droppable = last_pic_droppable;
1507 while (
h->poc.frame_num !=
h->poc.prev_frame_num && !
h->first_field &&
1508 h->poc.frame_num != (
h->poc.prev_frame_num + 1) % (1 <<
sps->log2_max_frame_num)) {
1511 h->poc.frame_num,
h->poc.prev_frame_num);
1512 if (!
sps->gaps_in_frame_num_allowed_flag)
1514 h->last_pocs[
i] = INT_MIN;
1521 h->poc.prev_frame_num++;
1522 h->poc.prev_frame_num %= 1 <<
sps->log2_max_frame_num;
1523 h->cur_pic_ptr->frame_num =
h->poc.prev_frame_num;
1524 h->cur_pic_ptr->invalid_gap = !
sps->gaps_in_frame_num_allowed_flag;
1528 h->explicit_ref_marking = 0;
1539 if (
h->short_ref_count) {
1541 1<<(
h->ps.sps->bit_depth_luma-1),
1542 1<<(
h->ps.sps->bit_depth_chroma-1),
1543 1<<(
h->ps.sps->bit_depth_chroma-1),
1548 h->short_ref[0]->f->width == prev->
f->
width &&
1549 h->short_ref[0]->f->height == prev->
f->
height &&
1550 h->short_ref[0]->f->format == prev->
f->
format) {
1555 h->short_ref[0]->tf.f =
h->short_ref[0]->f;
1559 h->short_ref[0]->poc = prev->
poc + 2
U;
1560 h->short_ref[0]->gray = prev->
gray;
1562 if (
h->short_ref[0]->field_picture)
1564 }
else if (!
h->frame_recovered) {
1565 if (!
h->avctx->hwaccel)
1567 h->short_ref[0]->gray = 1;
1569 h->short_ref[0]->frame_num =
h->poc.prev_frame_num;
1576 if (
h->first_field) {
1582 if (!
FIELD_PICTURE(
h) ||
h->picture_structure == last_pic_structure) {
1585 h->missing_fields ++;
1586 h->cur_pic_ptr =
NULL;
1589 h->missing_fields = 0;
1590 if (
h->cur_pic_ptr->frame_num !=
h->poc.frame_num) {
1597 h->cur_pic_ptr =
NULL;
1603 h->cur_pic_ptr =
NULL;
1622 h->cur_pic_ptr->tf.owner[
field] =
h->avctx;
1628 memset(
h->slice_table +
i*
h->mb_stride, -1, (
h->mb_stride - (
i+1==
h->mb_height)) *
sizeof(*
h->slice_table));
1630 memset(
h->slice_table, -1,
1631 (
h->mb_height *
h->mb_stride - 1) *
sizeof(*
h->slice_table));
1635 h->ps.sps, &
h->poc,
h->picture_structure,
nal->ref_idc);
1645 if (
h->sei.recovery_point.recovery_frame_cnt >= 0) {
1646 const int sei_recovery_frame_cnt =
h->sei.recovery_point.recovery_frame_cnt;
1649 h->valid_recovery_point = 1;
1651 if (
h->recovery_frame < 0
1652 ||
av_zero_extend(
h->recovery_frame -
h->poc.frame_num,
h->ps.sps->log2_max_frame_num) > sei_recovery_frame_cnt) {
1653 h->recovery_frame =
av_zero_extend(
h->poc.frame_num + sei_recovery_frame_cnt,
h->ps.sps->log2_max_frame_num);
1655 if (!
h->valid_recovery_point)
1656 h->recovery_frame =
h->poc.frame_num;
1669 if (
h->recovery_frame ==
h->poc.frame_num &&
nal->ref_idc) {
1670 h->recovery_frame = -1;
1675 h->cur_pic_ptr->recovered |=
h->frame_recovered;
1702 unsigned int slice_type,
tmp,
i;
1703 int field_pic_flag, bottom_field_flag;
1704 int first_slice = sl ==
h->slice_ctx && !
h->current_slice;
1705 int picture_structure;
1713 if (slice_type > 9) {
1715 "slice type %d too large at %d\n",
1719 if (slice_type > 4) {
1740 if (!
h->ps.pps_list[sl->
pps_id]) {
1742 "non-existing PPS %u referenced\n",
1760 if (
sps->frame_mbs_only_flag) {
1764 av_log(
h->avctx,
AV_LOG_ERROR,
"This stream was generated by a broken encoder, invalid 8x8 inference\n");
1768 if (field_pic_flag) {
1788 if (idr_pic_id < 65536) {
1796 if (
sps->poc_type == 0) {
1799 if (
pps->pic_order_present == 1 && picture_structure ==
PICT_FRAME)
1804 if (
sps->poc_type == 1 && !
sps->delta_pic_order_always_zero_flag) {
1807 if (
pps->pic_order_present == 1 && picture_structure ==
PICT_FRAME)
1812 if (
pps->redundant_pic_cnt_present)
1820 picture_structure,
h->avctx);
1833 for (
i = 0;
i < 2;
i++) {
1838 (
pps->weighted_bipred_idc == 1 &&
1842 picture_structure,
h->avctx);
1865 if (
tmp > 51 + 6 * (
sps->bit_depth_luma - 8)) {
1882 if (
pps->deblocking_filter_parameters_present) {
1886 "deblocking_filter_idc %u out of range\n",
tmp);
1896 if (slice_alpha_c0_offset_div2 > 6 ||
1897 slice_alpha_c0_offset_div2 < -6 ||
1898 slice_beta_offset_div2 > 6 ||
1899 slice_beta_offset_div2 < -6) {
1901 "deblocking filter parameters %d %d out of range\n",
1902 slice_alpha_c0_offset_div2, slice_beta_offset_div2);
1942 if (
h->ps.pps->weighted_bipred_idc == 2 &&
1972 h->postpone_filter = 1;
1978 h->ps.pps->chroma_qp_index_offset[0],
1979 h->ps.pps->chroma_qp_index_offset[1]) +
1980 6 * (
h->ps.sps->bit_depth_luma - 8);
1983 if (
h->current_slice >= 0xFFFE) {
1999 for (j = 0; j < 2; j++) {
2002 for (
i = 0;
i < 16;
i++) {
2004 if (j < sl->list_count && i < sl->ref_count[j] &&
2008 for (k = 0; k <
h->short_ref_count; k++)
2009 if (
h->short_ref[k]->f->buf[0]->buffer == buf) {
2013 for (k = 0; k <
h->long_ref_count; k++)
2014 if (
h->long_ref[k] &&
h->long_ref[k]->f->buf[0]->buffer == buf) {
2015 id_list[
i] =
h->short_ref_count + k;
2023 for (
i = 0;
i < 16;
i++)
2026 ref2frm[18 + 1] = -1;
2027 for (
i = 16;
i < 48;
i++)
2028 ref2frm[
i + 4] = 4 * id_list[(
i - 16) >> 1] +
2033 h->cur_pic_ptr->gray = 0;
2042 h->cur_pic_ptr->gray =
gray;
2047 "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",
2055 h->cur_pic_ptr->field_poc[0],
2056 h->cur_pic_ptr->field_poc[1],
2072 int first_slice = sl ==
h->slice_ctx && !
h->current_slice;
2088 if (
h->setup_finished) {
2095 if (
h->current_slice) {
2098 if (
h->nb_slice_ctx_queued) {
2105 memcpy(&tmp_ctx,
h->slice_ctx,
sizeof(tmp_ctx));
2106 memcpy(
h->slice_ctx, sl,
sizeof(tmp_ctx));
2107 memcpy(sl, &tmp_ctx,
sizeof(tmp_ctx));
2120 h->cur_pic_ptr =
NULL;
2127 if (!
h->first_field) {
2128 if (
h->cur_pic_ptr && !
h->droppable) {
2132 h->cur_pic_ptr =
NULL;
2136 if (!
h->current_slice)
2139 if (
h->current_slice == 0 && !
h->first_field) {
2153 if (
h->ps.pps->sps_id !=
pps->sps_id ||
2154 h->ps.pps->transform_8x8_mode !=
pps->transform_8x8_mode
2159 if (
h->ps.sps !=
pps->sps) {
2161 "SPS changed in the middle of the frame\n");
2166 if (
h->current_slice == 0) {
2172 h->droppable != (
nal->ref_idc == 0)) {
2174 "Changing field mode (%d -> %d) between slices is not allowed\n",
2177 }
else if (!
h->cur_pic_ptr) {
2179 "unset cur_pic_ptr on slice %d\n",
2180 h->current_slice + 1);
2189 h->nb_slice_ctx_queued++;
2214 int mb_type,
int top_xy,
2218 int mb_xy,
int list)
2220 int b_stride =
h->b_stride;
2225 const int b_xy =
h->mb2b_xy[top_xy] + 3 * b_stride;
2226 const int b8_xy = 4 * top_xy + 2;
2229 ref_cache[0 - 1 * 8] =
2230 ref_cache[1 - 1 * 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 0]];
2231 ref_cache[2 - 1 * 8] =
2232 ref_cache[3 - 1 * 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 1]];
2240 const int b_xy =
h->mb2b_xy[left_xy[
LTOP]] + 3;
2241 const int b8_xy = 4 * left_xy[
LTOP] + 1;
2243 AV_COPY32(mv_dst - 1 + 0,
h->cur_pic.motion_val[
list][b_xy + b_stride * 0]);
2244 AV_COPY32(mv_dst - 1 + 8,
h->cur_pic.motion_val[
list][b_xy + b_stride * 1]);
2245 AV_COPY32(mv_dst - 1 + 16,
h->cur_pic.motion_val[
list][b_xy + b_stride * 2]);
2246 AV_COPY32(mv_dst - 1 + 24,
h->cur_pic.motion_val[
list][b_xy + b_stride * 3]);
2248 ref_cache[-1 + 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 2 * 0]];
2249 ref_cache[-1 + 16] =
2250 ref_cache[-1 + 24] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 2 * 1]];
2258 ref_cache[-1 + 16] =
2274 const int8_t *
ref = &
h->cur_pic.ref_index[
list][4 * mb_xy];
2276 uint32_t ref01 = (
pack16to32(ref2frm[
ref[0]], ref2frm[
ref[1]]) & 0x00FF00FF) * 0x0101;
2277 uint32_t ref23 = (
pack16to32(ref2frm[
ref[2]], ref2frm[
ref[3]]) & 0x00FF00FF) * 0x0101;
2278 AV_WN32A(&ref_cache[0 * 8], ref01);
2279 AV_WN32A(&ref_cache[1 * 8], ref01);
2280 AV_WN32A(&ref_cache[2 * 8], ref23);
2281 AV_WN32A(&ref_cache[3 * 8], ref23);
2285 int16_t(*mv_src)[2] = &
h->cur_pic.motion_val[
list][4 * sl->
mb_x + 4 * sl->
mb_y * b_stride];
2286 AV_COPY128(mv_dst + 8 * 0, mv_src + 0 * b_stride);
2287 AV_COPY128(mv_dst + 8 * 1, mv_src + 1 * b_stride);
2288 AV_COPY128(mv_dst + 8 * 2, mv_src + 2 * b_stride);
2289 AV_COPY128(mv_dst + 8 * 3, mv_src + 3 * b_stride);
2298 const int mb_xy = sl->
mb_xy;
2304 top_xy = mb_xy - (
h->mb_stride <<
MB_FIELD(sl));
2306 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy - 1;
2308 const int left_mb_field_flag =
IS_INTERLACED(
h->cur_pic.mb_type[mb_xy - 1]);
2311 if (left_mb_field_flag != curr_mb_field_flag)
2312 left_xy[
LTOP] -=
h->mb_stride;
2314 if (curr_mb_field_flag)
2315 top_xy +=
h->mb_stride &
2316 (((
h->cur_pic.mb_type[top_xy] >> 7) & 1) - 1);
2317 if (left_mb_field_flag != curr_mb_field_flag)
2318 left_xy[
LBOT] +=
h->mb_stride;
2330 int qp =
h->cur_pic.qscale_table[mb_xy];
2331 if (qp <= qp_thresh &&
2332 (left_xy[
LTOP] < 0 ||
2333 ((qp +
h->cur_pic.qscale_table[left_xy[
LTOP]] + 1) >> 1) <= qp_thresh) &&
2335 ((qp +
h->cur_pic.qscale_table[top_xy] + 1) >> 1) <= qp_thresh)) {
2338 if ((left_xy[
LTOP] < 0 ||
2339 ((qp +
h->cur_pic.qscale_table[left_xy[
LBOT]] + 1) >> 1) <= qp_thresh) &&
2340 (top_xy <
h->mb_stride ||
2341 ((qp +
h->cur_pic.qscale_table[top_xy -
h->mb_stride] + 1) >> 1) <= qp_thresh))
2346 top_type =
h->cur_pic.mb_type[top_xy];
2347 left_type[
LTOP] =
h->cur_pic.mb_type[left_xy[
LTOP]];
2348 left_type[
LBOT] =
h->cur_pic.mb_type[left_xy[
LBOT]];
2353 left_type[
LTOP] = left_type[
LBOT] = 0;
2355 if (
h->slice_table[top_xy] == 0xFFFF)
2357 if (
h->slice_table[left_xy[
LBOT]] == 0xFFFF)
2358 left_type[
LTOP] = left_type[
LBOT] = 0;
2368 top_type, left_type, mb_xy, 0);
2371 top_type, left_type, mb_xy, 1);
2373 nnz =
h->non_zero_count[mb_xy];
2375 AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]);
2376 AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]);
2377 AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]);
2378 AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]);
2379 sl->
cbp =
h->cbp_table[mb_xy];
2382 nnz =
h->non_zero_count[top_xy];
2383 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[3 * 4]);
2386 if (left_type[
LTOP]) {
2387 nnz =
h->non_zero_count[left_xy[
LTOP]];
2388 nnz_cache[3 + 8 * 1] = nnz[3 + 0 * 4];
2389 nnz_cache[3 + 8 * 2] = nnz[3 + 1 * 4];
2390 nnz_cache[3 + 8 * 3] = nnz[3 + 2 * 4];
2391 nnz_cache[3 + 8 * 4] = nnz[3 + 3 * 4];
2396 if (!
CABAC(
h) &&
h->ps.pps->transform_8x8_mode) {
2398 nnz_cache[4 + 8 * 0] =
2399 nnz_cache[5 + 8 * 0] = (
h->cbp_table[top_xy] & 0x4000) >> 12;
2400 nnz_cache[6 + 8 * 0] =
2401 nnz_cache[7 + 8 * 0] = (
h->cbp_table[top_xy] & 0x8000) >> 12;
2404 nnz_cache[3 + 8 * 1] =
2405 nnz_cache[3 + 8 * 2] = (
h->cbp_table[left_xy[
LTOP]] & 0x2000) >> 12;
2408 nnz_cache[3 + 8 * 3] =
2409 nnz_cache[3 + 8 * 4] = (
h->cbp_table[left_xy[
LBOT]] & 0x8000) >> 12;
2413 nnz_cache[
scan8[0]] =
2414 nnz_cache[
scan8[1]] =
2415 nnz_cache[
scan8[2]] =
2416 nnz_cache[
scan8[3]] = (sl->
cbp & 0x1000) >> 12;
2418 nnz_cache[
scan8[0 + 4]] =
2419 nnz_cache[
scan8[1 + 4]] =
2420 nnz_cache[
scan8[2 + 4]] =
2421 nnz_cache[
scan8[3 + 4]] = (sl->
cbp & 0x2000) >> 12;
2423 nnz_cache[
scan8[0 + 8]] =
2424 nnz_cache[
scan8[1 + 8]] =
2425 nnz_cache[
scan8[2 + 8]] =
2426 nnz_cache[
scan8[3 + 8]] = (sl->
cbp & 0x4000) >> 12;
2428 nnz_cache[
scan8[0 + 12]] =
2429 nnz_cache[
scan8[1 + 12]] =
2430 nnz_cache[
scan8[2 + 12]] =
2431 nnz_cache[
scan8[3 + 12]] = (sl->
cbp & 0x8000) >> 12;
2440 uint8_t *dest_y, *dest_cb, *dest_cr;
2441 int linesize, uvlinesize, mb_x, mb_y;
2444 const int pixel_shift =
h->pixel_shift;
2445 const int block_h = 16 >>
h->chroma_y_shift;
2447 if (
h->postpone_filter)
2451 for (mb_x = start_x; mb_x < end_x; mb_x++)
2452 for (mb_y = end_mb_y -
FRAME_MBAFF(
h); mb_y <= end_mb_y; mb_y++) {
2454 mb_xy = sl->
mb_xy = mb_x + mb_y *
h->mb_stride;
2455 mb_type =
h->cur_pic.mb_type[mb_xy];
2463 dest_y =
h->cur_pic.f->data[0] +
2464 ((mb_x << pixel_shift) + mb_y * sl->
linesize) * 16;
2465 dest_cb =
h->cur_pic.f->data[1] +
2466 (mb_x << pixel_shift) * (8 <<
CHROMA444(
h)) +
2468 dest_cr =
h->cur_pic.f->data[2] +
2469 (mb_x << pixel_shift) * (8 <<
CHROMA444(
h)) +
2494 linesize, uvlinesize);
2497 dest_cr, linesize, uvlinesize);
2510 const int mb_xy = sl->
mb_x + sl->
mb_y *
h->mb_stride;
2511 int mb_type = (
h->slice_table[mb_xy - 1] == sl->
slice_num) ?
2512 h->cur_pic.mb_type[mb_xy - 1] :
2513 (
h->slice_table[mb_xy -
h->mb_stride] == sl->
slice_num) ?
2514 h->cur_pic.mb_type[mb_xy -
h->mb_stride] : 0;
2529 if ((top +
height) >= pic_height)
2530 height += deblock_border;
2531 top -= deblock_border;
2534 if (top >= pic_height || (top +
height) < 0)
2545 if (
h->droppable ||
h->er.error_occurred)
2553 int startx,
int starty,
2554 int endx,
int endy,
int status)
2559 if (CONFIG_ERROR_RESILIENCE) {
2568 int lf_x_start = sl->
mb_x;
2572 sl->
linesize =
h->cur_pic_ptr->f->linesize[0];
2583 if (
h->postpone_filter)
2599 if (
h->ps.pps->cabac) {
2643 if (sl->
mb_x >= lf_x_start)
2651 "error while decoding MB %d %d, bytestream %td\n",
2659 if (++sl->
mb_x >=
h->mb_width) {
2661 sl->
mb_x = lf_x_start = 0;
2671 if (eos || sl->
mb_y >=
h->mb_height) {
2672 ff_tlog(
h->avctx,
"slice end %d %d\n",
2676 if (sl->
mb_x > lf_x_start)
2710 "error while decoding MB %d %d\n", sl->
mb_x, sl->
mb_y);
2716 if (++sl->
mb_x >=
h->mb_width) {
2718 sl->
mb_x = lf_x_start = 0;
2726 if (sl->
mb_y >=
h->mb_height) {
2727 ff_tlog(
h->avctx,
"slice end %d %d\n",
2746 ff_tlog(
h->avctx,
"slice end %d %d\n",
2752 if (sl->
mb_x > lf_x_start)
2780 int context_count =
h->nb_slice_ctx_queued;
2784 h->slice_ctx[0].next_slice_idx = INT_MAX;
2786 if (
h->avctx->hwaccel || context_count < 1)
2789 av_assert0(context_count &&
h->slice_ctx[context_count - 1].mb_y <
h->mb_height);
2791 if (context_count == 1) {
2793 h->slice_ctx[0].next_slice_idx =
h->mb_width *
h->mb_height;
2794 h->postpone_filter = 0;
2797 h->mb_y =
h->slice_ctx[0].mb_y;
2802 for (
i = 0;
i < context_count;
i++) {
2803 int next_slice_idx =
h->mb_width *
h->mb_height;
2806 sl = &
h->slice_ctx[
i];
2809 slice_idx = sl->
mb_y *
h->mb_width + sl->
mb_x;
2810 for (j = 0; j < context_count; j++) {
2812 int slice_idx2 = sl2->
mb_y *
h->mb_width + sl2->
mb_x;
2814 if (
i == j || slice_idx2 < slice_idx)
2816 next_slice_idx =
FFMIN(next_slice_idx, slice_idx2);
2822 NULL, context_count,
sizeof(
h->slice_ctx[0]));
2825 sl = &
h->slice_ctx[context_count - 1];
2828 if (
h->postpone_filter) {
2829 h->postpone_filter = 0;
2831 for (
i = 0;
i < context_count;
i++) {
2834 sl = &
h->slice_ctx[
i];
2836 x_end = (sl->
mb_y >=
h->mb_height) ?
h->mb_width : sl->
mb_x;
2841 j == y_end - 1 ? x_end :
h->mb_width);
2848 h->nb_slice_ctx_queued = 0;