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) {
200 if (
h->avctx->hwaccel) {
211 int h_chroma_shift, v_chroma_shift;
213 &h_chroma_shift, &v_chroma_shift);
223 if (!
h->qscale_table_pool) {
258 if (!
h->DPB[
i].f->buf[0])
265 #define IN_RANGE(a, b, size) (((void*)(a) >= (void*)(b)) && ((void*)(a) < (void*)((b) + (size))))
267 #define REBASE_PICTURE(pic, new_ctx, old_ctx) \
268 (((pic) && (pic) >= (old_ctx)->DPB && \
269 (pic) < (old_ctx)->DPB + H264_MAX_PICTURE_COUNT) ? \
270 &(new_ctx)->DPB[(pic) - (old_ctx)->DPB] : NULL)
292 int inited =
h->context_initialized, err = 0;
299 if (inited && !h1->ps.sps)
303 (
h->width != h1->width ||
304 h->height != h1->height ||
305 h->mb_width != h1->mb_width ||
306 h->mb_height != h1->mb_height ||
308 h->ps.sps->bit_depth_luma != h1->ps.sps->bit_depth_luma ||
309 h->ps.sps->chroma_format_idc != h1->ps.sps->chroma_format_idc ||
310 h->ps.sps->colorspace != h1->ps.sps->colorspace)) {
315 memcpy(
h->block_offset, h1->block_offset,
sizeof(
h->block_offset));
320 if (h1->ps.sps_list[
i]) {
322 if (!
h->ps.sps_list[
i])
328 if (h1->ps.pps_list[
i]) {
330 if (!
h->ps.pps_list[
i])
339 if (h1->ps.pps_ref) {
343 h->ps.pps = (
const PPS*)
h->ps.pps_ref->data;
345 if (h1->ps.sps_ref) {
349 h->ps.sps = (
const SPS*)
h->ps.sps_ref->data;
352 if (need_reinit || !inited) {
353 h->width = h1->width;
354 h->height = h1->height;
355 h->mb_height = h1->mb_height;
356 h->mb_width = h1->mb_width;
357 h->mb_num = h1->mb_num;
358 h->mb_stride = h1->mb_stride;
359 h->b_stride = h1->b_stride;
360 h->x264_build = h1->x264_build;
362 if (
h->context_initialized || h1->context_initialized) {
370 memcpy(
h->block_offset, h1->block_offset,
sizeof(
h->block_offset));
373 h->avctx->coded_height = h1->avctx->coded_height;
374 h->avctx->coded_width = h1->avctx->coded_width;
375 h->avctx->width = h1->avctx->width;
376 h->avctx->height = h1->avctx->height;
377 h->width_from_caller = h1->width_from_caller;
378 h->height_from_caller = h1->height_from_caller;
379 h->coded_picture_number = h1->coded_picture_number;
380 h->first_field = h1->first_field;
381 h->picture_structure = h1->picture_structure;
382 h->mb_aff_frame = h1->mb_aff_frame;
383 h->droppable = h1->droppable;
387 if (h1->DPB[
i].f->buf[0] &&
394 if (h1->cur_pic.f->buf[0]) {
400 h->enable_er = h1->enable_er;
401 h->workaround_bugs = h1->workaround_bugs;
402 h->droppable = h1->droppable;
405 h->is_avc = h1->is_avc;
406 h->nal_length_size = h1->nal_length_size;
408 memcpy(&
h->poc, &h1->poc,
sizeof(
h->poc));
410 memcpy(
h->short_ref, h1->short_ref,
sizeof(
h->short_ref));
411 memcpy(
h->long_ref, h1->long_ref,
sizeof(
h->long_ref));
412 memcpy(
h->delayed_pic, h1->delayed_pic,
sizeof(
h->delayed_pic));
413 memcpy(
h->last_pocs, h1->last_pocs,
sizeof(
h->last_pocs));
415 h->next_output_pic = h1->next_output_pic;
416 h->next_outputed_poc = h1->next_outputed_poc;
418 memcpy(
h->mmco, h1->mmco,
sizeof(
h->mmco));
419 h->nb_mmco = h1->nb_mmco;
420 h->mmco_reset = h1->mmco_reset;
421 h->explicit_ref_marking = h1->explicit_ref_marking;
422 h->long_ref_count = h1->long_ref_count;
423 h->short_ref_count = h1->short_ref_count;
430 h->frame_recovered = h1->frame_recovered;
433 if (h1->sei.a53_caption.buf_ref) {
434 h->sei.a53_caption.buf_ref =
av_buffer_ref(h1->sei.a53_caption.buf_ref);
435 if (!
h->sei.a53_caption.buf_ref)
444 h->poc.prev_poc_msb =
h->poc.poc_msb;
445 h->poc.prev_poc_lsb =
h->poc.poc_lsb;
447 h->poc.prev_frame_num_offset =
h->poc.frame_num_offset;
448 h->poc.prev_frame_num =
h->poc.frame_num;
450 h->recovery_frame = h1->recovery_frame;
459 const int pixel_shift =
h->pixel_shift;
461 1<<(
h->ps.sps->bit_depth_luma-1),
462 1<<(
h->ps.sps->bit_depth_chroma-1),
463 1<<(
h->ps.sps->bit_depth_chroma-1),
473 h->cur_pic_ptr =
NULL;
482 pic->
reference =
h->droppable ? 0 :
h->picture_structure;
506 if(!
h->frame_recovered && !
h->avctx->hwaccel)
509 h->cur_pic_ptr = pic;
511 if (CONFIG_ERROR_RESILIENCE) {
518 for (
i = 0;
i <
h->nb_slice_ctx;
i++) {
519 h->slice_ctx[
i].linesize =
h->cur_pic_ptr->f->linesize[0];
520 h->slice_ctx[
i].uvlinesize =
h->cur_pic_ptr->f->linesize[1];
523 if (CONFIG_ERROR_RESILIENCE &&
h->enable_er) {
529 for (
i = 0;
i < 16;
i++) {
533 for (
i = 0;
i < 16;
i++) {
534 h->block_offset[16 +
i] =
536 h->block_offset[48 + 16 +
i] =
544 h->cur_pic_ptr->reference = 0;
546 h->cur_pic_ptr->field_poc[0] =
h->cur_pic_ptr->field_poc[1] = INT_MAX;
548 h->next_output_pic =
NULL;
550 h->postpone_filter = 0;
552 h->mb_aff_frame =
h->ps.sps->mb_aff && (
h->picture_structure ==
PICT_FRAME);
554 if (
h->sei.unregistered.x264_build >= 0)
555 h->x264_build =
h->sei.unregistered.x264_build;
557 assert(
h->cur_pic_ptr->long_ref == 0);
565 int linesize,
int uvlinesize,
570 const int pixel_shift =
h->pixel_shift;
575 src_cb -= uvlinesize;
576 src_cr -= uvlinesize;
582 AV_COPY128(top_border, src_y + 15 * linesize);
584 AV_COPY128(top_border + 16, src_y + 15 * linesize + 16);
588 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
589 AV_COPY128(top_border + 48, src_cb + 15 * uvlinesize + 16);
590 AV_COPY128(top_border + 64, src_cr + 15 * uvlinesize);
591 AV_COPY128(top_border + 80, src_cr + 15 * uvlinesize + 16);
593 AV_COPY128(top_border + 16, src_cb + 15 * uvlinesize);
594 AV_COPY128(top_border + 32, src_cr + 15 * uvlinesize);
596 }
else if (chroma422) {
598 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
599 AV_COPY128(top_border + 48, src_cr + 15 * uvlinesize);
601 AV_COPY64(top_border + 16, src_cb + 15 * uvlinesize);
602 AV_COPY64(top_border + 24, src_cr + 15 * uvlinesize);
606 AV_COPY128(top_border + 32, src_cb + 7 * uvlinesize);
607 AV_COPY128(top_border + 48, src_cr + 7 * uvlinesize);
609 AV_COPY64(top_border + 16, src_cb + 7 * uvlinesize);
610 AV_COPY64(top_border + 24, src_cr + 7 * uvlinesize);
624 AV_COPY128(top_border, src_y + 16 * linesize);
626 AV_COPY128(top_border + 16, src_y + 16 * linesize + 16);
631 AV_COPY128(top_border + 32, src_cb + 16 * linesize);
632 AV_COPY128(top_border + 48, src_cb + 16 * linesize + 16);
633 AV_COPY128(top_border + 64, src_cr + 16 * linesize);
634 AV_COPY128(top_border + 80, src_cr + 16 * linesize + 16);
636 AV_COPY128(top_border + 16, src_cb + 16 * linesize);
637 AV_COPY128(top_border + 32, src_cr + 16 * linesize);
639 }
else if (chroma422) {
641 AV_COPY128(top_border + 32, src_cb + 16 * uvlinesize);
642 AV_COPY128(top_border + 48, src_cr + 16 * uvlinesize);
644 AV_COPY64(top_border + 16, src_cb + 16 * uvlinesize);
645 AV_COPY64(top_border + 24, src_cr + 16 * uvlinesize);
649 AV_COPY128(top_border + 32, src_cb + 8 * uvlinesize);
650 AV_COPY128(top_border + 48, src_cr + 8 * uvlinesize);
652 AV_COPY64(top_border + 16, src_cb + 8 * uvlinesize);
653 AV_COPY64(top_border + 24, src_cr + 8 * uvlinesize);
666 int ref0, ref1,
i, cur_poc, ref_start, ref_count0, ref_count1;
668 for (
i = 0;
i < 2;
i++) {
675 cur_poc =
h->cur_pic_ptr->poc;
677 cur_poc =
h->cur_pic_ptr->field_poc[
h->picture_structure - 1];
689 cur_poc =
h->cur_pic_ptr->field_poc[
field];
700 for (ref0 = ref_start; ref0 < ref_count0; ref0++) {
702 for (ref1 = ref_start; ref1 < ref_count1; ref1++) {
706 int td = av_clip_int8(poc1 - poc0);
708 int tb = av_clip_int8(cur_poc - poc0);
709 int tx = (16384 + (
FFABS(
td) >> 1)) /
td;
710 int dist_scale_factor = (
tb * tx + 32) >> 8;
711 if (dist_scale_factor >= -64 && dist_scale_factor <= 128)
712 w = 64 - dist_scale_factor;
731 for (
i = 0;
i < 16;
i++) {
732 #define TRANSPOSE(x) ((x) >> 2) | (((x) << 2) & 0xF)
737 for (
i = 0;
i < 64;
i++) {
738 #define TRANSPOSE(x) ((x) >> 3) | (((x) & 7) << 3)
745 if (
h->ps.sps->transform_bypass) {
749 memcpy(
h->field_scan_q0 ,
field_scan ,
sizeof(
h->field_scan_q0 ));
750 memcpy(
h->field_scan8x8_q0 ,
field_scan8x8 ,
sizeof(
h->field_scan8x8_q0 ));
753 memcpy(
h->zigzag_scan_q0 ,
h->zigzag_scan ,
sizeof(
h->zigzag_scan_q0 ));
754 memcpy(
h->zigzag_scan8x8_q0 ,
h->zigzag_scan8x8 ,
sizeof(
h->zigzag_scan8x8_q0 ));
755 memcpy(
h->zigzag_scan8x8_cavlc_q0 ,
h->zigzag_scan8x8_cavlc ,
sizeof(
h->zigzag_scan8x8_cavlc_q0));
756 memcpy(
h->field_scan_q0 ,
h->field_scan ,
sizeof(
h->field_scan_q0 ));
757 memcpy(
h->field_scan8x8_q0 ,
h->field_scan8x8 ,
sizeof(
h->field_scan8x8_q0 ));
758 memcpy(
h->field_scan8x8_cavlc_q0 ,
h->field_scan8x8_cavlc ,
sizeof(
h->field_scan8x8_cavlc_q0 ));
764 #define HWACCEL_MAX (CONFIG_H264_DXVA2_HWACCEL + \
765 (CONFIG_H264_D3D11VA_HWACCEL * 2) + \
766 CONFIG_H264_NVDEC_HWACCEL + \
767 CONFIG_H264_VAAPI_HWACCEL + \
768 CONFIG_H264_VIDEOTOOLBOX_HWACCEL + \
769 CONFIG_H264_VDPAU_HWACCEL)
774 switch (
h->ps.sps->bit_depth_luma) {
820 #if CONFIG_H264_VDPAU_HWACCEL
823 #if CONFIG_H264_NVDEC_HWACCEL
839 #if CONFIG_H264_DXVA2_HWACCEL
842 #if CONFIG_H264_D3D11VA_HWACCEL
846 #if CONFIG_H264_VAAPI_HWACCEL
849 #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL
852 if (
h->avctx->codec->pix_fmts)
853 choices =
h->avctx->codec->pix_fmts;
862 "Unsupported bit depth %d\n",
h->ps.sps->bit_depth_luma);
869 if (choices[
i] ==
h->avctx->pix_fmt && !force_callback)
878 int cr =
sps->crop_right;
879 int cl =
sps->crop_left;
880 int ct =
sps->crop_top;
881 int cb =
sps->crop_bottom;
888 if (
h->width_from_caller > 0 &&
h->height_from_caller > 0 &&
889 !
sps->crop_top && !
sps->crop_left &&
892 h->width_from_caller <=
width &&
893 h->height_from_caller <=
height) {
894 width =
h->width_from_caller;
895 height =
h->height_from_caller;
901 h->width_from_caller = 0;
902 h->height_from_caller = 0;
905 h->avctx->coded_width =
h->width;
906 h->avctx->coded_height =
h->height;
929 &
h->chroma_x_shift, &
h->chroma_y_shift);
931 if (
sps->timing_info_present_flag) {
932 int64_t den =
sps->time_scale;
933 if (
h->x264_build < 44
U)
935 av_reduce(&
h->avctx->framerate.den, &
h->avctx->framerate.num,
936 sps->num_units_in_tick *
h->avctx->ticks_per_frame, den, 1 << 30);
942 h->prev_interlaced_frame = 1;
951 if (
sps->bit_depth_luma < 8 ||
sps->bit_depth_luma > 14 ||
952 sps->bit_depth_luma == 11 ||
sps->bit_depth_luma == 13
955 sps->bit_depth_luma);
960 h->cur_bit_depth_luma =
961 h->avctx->bits_per_raw_sample =
sps->bit_depth_luma;
962 h->cur_chroma_format_idc =
sps->chroma_format_idc;
963 h->pixel_shift =
sps->bit_depth_luma > 8;
964 h->chroma_format_idc =
sps->chroma_format_idc;
965 h->bit_depth_luma =
sps->bit_depth_luma;
968 sps->chroma_format_idc);
972 sps->chroma_format_idc);
982 for (
i = 0;
i <
h->nb_slice_ctx;
i++) {
987 sl->
mvd_table[0] =
h->mvd_table[0] +
i * 8 * 2 *
h->mb_stride;
988 sl->
mvd_table[1] =
h->mvd_table[1] +
i * 8 * 2 *
h->mb_stride;
997 h->context_initialized = 1;
1002 h->context_initialized = 0;
1020 int needs_reinit = 0, must_reinit,
ret;
1028 h->ps.pps = (
const PPS*)
h->ps.pps_ref->data;
1031 if (
h->ps.sps != (
const SPS*)
h->ps.sps_list[
h->ps.pps->sps_id]->data) {
1037 h->ps.sps = (
const SPS*)
h->ps.sps_ref->data;
1039 if (
h->mb_width !=
h->ps.sps->mb_width ||
1040 h->mb_height !=
h->ps.sps->mb_height ||
1041 h->cur_bit_depth_luma !=
h->ps.sps->bit_depth_luma ||
1042 h->cur_chroma_format_idc !=
h->ps.sps->chroma_format_idc
1046 if (
h->bit_depth_luma !=
h->ps.sps->bit_depth_luma ||
1047 h->chroma_format_idc !=
h->ps.sps->chroma_format_idc)
1052 must_reinit = (
h->context_initialized &&
1053 ( 16*
sps->mb_width !=
h->avctx->coded_width
1054 || 16*
sps->mb_height !=
h->avctx->coded_height
1055 ||
h->cur_bit_depth_luma !=
sps->bit_depth_luma
1056 ||
h->cur_chroma_format_idc !=
sps->chroma_format_idc
1057 ||
h->mb_width !=
sps->mb_width
1058 ||
h->mb_height !=
sps->mb_height
1064 if (first_slice &&
av_cmp_q(
sps->sar,
h->avctx->sample_aspect_ratio))
1067 if (!
h->setup_finished) {
1069 h->avctx->level =
sps->level_idc;
1070 h->avctx->refs =
sps->ref_frame_count;
1072 h->mb_width =
sps->mb_width;
1073 h->mb_height =
sps->mb_height;
1074 h->mb_num =
h->mb_width *
h->mb_height;
1075 h->mb_stride =
h->mb_width + 1;
1077 h->b_stride =
h->mb_width * 4;
1079 h->chroma_y_shift =
sps->chroma_format_idc <= 1;
1081 h->width = 16 *
h->mb_width;
1082 h->height = 16 *
h->mb_height;
1088 if (
sps->video_signal_type_present_flag) {
1091 if (
sps->colour_description_present_flag) {
1092 if (
h->avctx->colorspace !=
sps->colorspace)
1094 h->avctx->color_primaries =
sps->color_primaries;
1095 h->avctx->color_trc =
sps->color_trc;
1096 h->avctx->colorspace =
sps->colorspace;
1100 if (
h->sei.alternative_transfer.present &&
1103 h->avctx->color_trc =
h->sei.alternative_transfer.preferred_transfer_characteristics;
1107 if (!
h->context_initialized || must_reinit || needs_reinit) {
1108 int flush_changes =
h->context_initialized;
1109 h->context_initialized = 0;
1110 if (sl !=
h->slice_ctx) {
1112 "changing width %d -> %d / height %d -> %d on "
1114 h->width,
h->avctx->coded_width,
1115 h->height,
h->avctx->coded_height,
1116 h->current_slice + 1);
1127 h->avctx->pix_fmt =
ret;
1134 "h264_slice_header_init() failed\n");
1154 if (
sps->pic_struct_present_flag &&
h->sei.picture_timing.present) {
1156 switch (
pt->pic_struct) {
1186 if ((
pt->ct_type & 3) &&
1199 if (
sps->pic_struct_present_flag &&
h->sei.picture_timing.present) {
1217 if (
h->sei.frame_packing.present &&
1218 h->sei.frame_packing.arrangement_type <= 6 &&
1219 h->sei.frame_packing.content_interpretation_type > 0 &&
1220 h->sei.frame_packing.content_interpretation_type < 3) {
1224 switch (
fp->arrangement_type) {
1235 if (
fp->quincunx_sampling_flag)
1251 if (
fp->content_interpretation_type == 2)
1255 if (
fp->current_frame_is_frame0_flag)
1263 if (
h->sei.display_orientation.present &&
1264 (
h->sei.display_orientation.anticlockwise_rotation ||
1265 h->sei.display_orientation.hflip ||
1266 h->sei.display_orientation.vflip)) {
1279 if (
h->sei.afd.present) {
1284 *sd->
data =
h->sei.afd.active_format_description;
1285 h->sei.afd.present = 0;
1289 if (
h->sei.a53_caption.buf_ref) {
1300 if (
h->sei.picture_timing.timecode_cnt > 0) {
1306 sizeof(uint32_t)*4);
1310 tc_sd = (uint32_t*)tcside->
data;
1311 tc_sd[0] =
h->sei.picture_timing.timecode_cnt;
1313 for (
int i = 0;
i < tc_sd[0];
i++) {
1319 frames =
h->sei.picture_timing.timecode[
i].frame / 2;
1320 if (
h->sei.picture_timing.timecode[
i].frame % 2 == 1) {
1327 frames =
h->sei.picture_timing.timecode[
i].frame;
1330 tc |=
h->sei.picture_timing.timecode[
i].dropframe << 30;
1333 tc |= (
h->sei.picture_timing.timecode[
i].seconds / 10) << 20;
1334 tc |= (
h->sei.picture_timing.timecode[
i].seconds % 10) << 16;
1335 tc |= (
h->sei.picture_timing.timecode[
i].minutes / 10) << 12;
1336 tc |= (
h->sei.picture_timing.timecode[
i].minutes % 10) << 8;
1337 tc |= (
h->sei.picture_timing.timecode[
i].hours / 10) << 4;
1338 tc |= (
h->sei.picture_timing.timecode[
i].hours % 10);
1342 h->sei.picture_timing.timecode_cnt = 0;
1353 int i, pics, out_of_order, out_idx;
1358 if (
sps->bitstream_restriction_flag ||
1360 h->avctx->has_b_frames =
FFMAX(
h->avctx->has_b_frames,
sps->num_reorder_frames);
1363 for (
i = 0; 1;
i++) {
1366 h->last_pocs[
i-1] = cur->
poc;
1369 h->last_pocs[
i-1]=
h->last_pocs[
i];
1375 out_of_order =
FFMAX(out_of_order, 1);
1379 h->last_pocs[
i] = INT_MIN;
1380 h->last_pocs[0] = cur->
poc;
1382 }
else if(
h->avctx->has_b_frames < out_of_order && !
sps->bitstream_restriction_flag){
1384 av_log(
h->avctx, loglevel,
"Increasing reorder buffer to %d\n", out_of_order);
1385 h->avctx->has_b_frames = out_of_order;
1389 while (
h->delayed_pic[pics])
1394 h->delayed_pic[pics++] = cur;
1398 out =
h->delayed_pic[0];
1400 for (
i = 1;
h->delayed_pic[
i] &&
1401 !
h->delayed_pic[
i]->f->key_frame &&
1402 !
h->delayed_pic[
i]->mmco_reset;
1404 if (
h->delayed_pic[
i]->poc <
out->poc) {
1405 out =
h->delayed_pic[
i];
1408 if (
h->avctx->has_b_frames == 0 &&
1409 (
h->delayed_pic[0]->f->key_frame ||
h->delayed_pic[0]->mmco_reset))
1410 h->next_outputed_poc = INT_MIN;
1411 out_of_order =
out->poc <
h->next_outputed_poc;
1413 if (out_of_order || pics >
h->avctx->has_b_frames) {
1415 for (
i = out_idx;
h->delayed_pic[
i];
i++)
1416 h->delayed_pic[
i] =
h->delayed_pic[
i + 1];
1418 if (!out_of_order && pics >
h->avctx->has_b_frames) {
1419 h->next_output_pic =
out;
1420 if (out_idx == 0 &&
h->delayed_pic[0] && (
h->delayed_pic[0]->f->key_frame ||
h->delayed_pic[0]->mmco_reset)) {
1421 h->next_outputed_poc = INT_MIN;
1423 h->next_outputed_poc =
out->poc;
1425 if (
out->recovered) {
1432 if (!
out->recovered) {
1435 h->next_output_pic =
NULL;
1452 const H2645NAL *nal,
int first_slice)
1457 int last_pic_structure, last_pic_droppable,
ret;
1465 if (
sps &&
sps->bitstream_restriction_flag &&
1466 h->avctx->has_b_frames <
sps->num_reorder_frames) {
1467 h->avctx->has_b_frames =
sps->num_reorder_frames;
1470 last_pic_droppable =
h->droppable;
1471 last_pic_structure =
h->picture_structure;
1472 h->droppable = (nal->
ref_idc == 0);
1483 if (
h->poc.frame_num !=
h->poc.prev_frame_num) {
1484 int unwrap_prev_frame_num =
h->poc.prev_frame_num;
1485 int max_frame_num = 1 <<
sps->log2_max_frame_num;
1487 if (unwrap_prev_frame_num >
h->poc.frame_num)
1488 unwrap_prev_frame_num -= max_frame_num;
1490 if ((
h->poc.frame_num - unwrap_prev_frame_num) >
sps->ref_frame_count) {
1491 unwrap_prev_frame_num = (
h->poc.frame_num -
sps->ref_frame_count) - 1;
1492 if (unwrap_prev_frame_num < 0)
1493 unwrap_prev_frame_num += max_frame_num;
1495 h->poc.prev_frame_num = unwrap_prev_frame_num;
1504 if (
h->first_field) {
1511 if (
h->cur_pic_ptr->tf.owner[last_field] ==
h->avctx) {
1516 if (!
FIELD_PICTURE(
h) ||
h->picture_structure == last_pic_structure) {
1524 if (
h->cur_pic_ptr->frame_num !=
h->poc.frame_num) {
1540 "Invalid field mode combination %d/%d\n",
1541 last_pic_structure,
h->picture_structure);
1542 h->picture_structure = last_pic_structure;
1543 h->droppable = last_pic_droppable;
1545 }
else if (last_pic_droppable !=
h->droppable) {
1547 "Found reference and non-reference fields in the same frame, which");
1548 h->picture_structure = last_pic_structure;
1549 h->droppable = last_pic_droppable;
1556 while (
h->poc.frame_num !=
h->poc.prev_frame_num && !
h->first_field &&
1557 h->poc.frame_num != (
h->poc.prev_frame_num + 1) % (1 <<
sps->log2_max_frame_num)) {
1560 h->poc.frame_num,
h->poc.prev_frame_num);
1561 if (!
sps->gaps_in_frame_num_allowed_flag)
1563 h->last_pocs[
i] = INT_MIN;
1570 h->poc.prev_frame_num++;
1571 h->poc.prev_frame_num %= 1 <<
sps->log2_max_frame_num;
1572 h->cur_pic_ptr->frame_num =
h->poc.prev_frame_num;
1573 h->cur_pic_ptr->invalid_gap = !
sps->gaps_in_frame_num_allowed_flag;
1577 h->explicit_ref_marking = 0;
1588 if (
h->short_ref_count) {
1590 h->short_ref[0]->f->width == prev->
f->
width &&
1591 h->short_ref[0]->f->height == prev->
f->
height &&
1592 h->short_ref[0]->f->format == prev->
f->
format) {
1597 h->short_ref[0]->f->linesize,
1603 h->short_ref[0]->poc = prev->
poc + 2;
1605 h->short_ref[0]->frame_num =
h->poc.prev_frame_num;
1612 if (
h->first_field) {
1618 if (!
FIELD_PICTURE(
h) ||
h->picture_structure == last_pic_structure) {
1621 h->missing_fields ++;
1622 h->cur_pic_ptr =
NULL;
1625 h->missing_fields = 0;
1626 if (
h->cur_pic_ptr->frame_num !=
h->poc.frame_num) {
1633 h->cur_pic_ptr =
NULL;
1639 h->cur_pic_ptr =
NULL;
1658 h->cur_pic_ptr->tf.owner[
field] =
h->avctx;
1664 memset(
h->slice_table +
i*
h->mb_stride, -1, (
h->mb_stride - (
i+1==
h->mb_height)) *
sizeof(*
h->slice_table));
1666 memset(
h->slice_table, -1,
1667 (
h->mb_height *
h->mb_stride - 1) *
sizeof(*
h->slice_table));
1671 h->ps.sps, &
h->poc,
h->picture_structure, nal->
ref_idc);
1681 if (
h->sei.recovery_point.recovery_frame_cnt >= 0) {
1682 const int sei_recovery_frame_cnt =
h->sei.recovery_point.recovery_frame_cnt;
1685 h->valid_recovery_point = 1;
1687 if (
h->recovery_frame < 0
1688 || av_mod_uintp2(
h->recovery_frame -
h->poc.frame_num,
h->ps.sps->log2_max_frame_num) > sei_recovery_frame_cnt) {
1689 h->recovery_frame = av_mod_uintp2(
h->poc.frame_num + sei_recovery_frame_cnt,
h->ps.sps->log2_max_frame_num);
1691 if (!
h->valid_recovery_point)
1692 h->recovery_frame =
h->poc.frame_num;
1699 (
h->recovery_frame ==
h->poc.frame_num && nal->
ref_idc)) {
1700 h->recovery_frame = -1;
1701 h->cur_pic_ptr->recovered = 1;
1708 h->cur_pic_ptr->recovered |=
h->frame_recovered;
1735 unsigned int slice_type,
tmp,
i;
1736 int field_pic_flag, bottom_field_flag;
1737 int first_slice = sl ==
h->slice_ctx && !
h->current_slice;
1738 int picture_structure;
1746 if (slice_type > 9) {
1748 "slice type %d too large at %d\n",
1752 if (slice_type > 4) {
1773 if (!
h->ps.pps_list[sl->
pps_id]) {
1775 "non-existing PPS %u referenced\n",
1781 if (!
h->ps.sps_list[
pps->sps_id]) {
1783 "non-existing SPS %u referenced\n",
pps->sps_id);
1786 sps = (
const SPS*)
h->ps.sps_list[
pps->sps_id]->data;
1799 if (
sps->frame_mbs_only_flag) {
1803 av_log(
h->avctx,
AV_LOG_ERROR,
"This stream was generated by a broken encoder, invalid 8x8 inference\n");
1807 if (field_pic_flag) {
1828 if (
sps->poc_type == 0) {
1831 if (
pps->pic_order_present == 1 && picture_structure ==
PICT_FRAME)
1835 if (
sps->poc_type == 1 && !
sps->delta_pic_order_always_zero_flag) {
1838 if (
pps->pic_order_present == 1 && picture_structure ==
PICT_FRAME)
1843 if (
pps->redundant_pic_cnt_present)
1851 picture_structure,
h->avctx);
1864 for (
i = 0;
i < 2;
i++) {
1869 (
pps->weighted_bipred_idc == 1 &&
1873 picture_structure,
h->avctx);
1896 if (
tmp > 51 + 6 * (
sps->bit_depth_luma - 8)) {
1913 if (
pps->deblocking_filter_parameters_present) {
1917 "deblocking_filter_idc %u out of range\n",
tmp);
1927 if (slice_alpha_c0_offset_div2 > 6 ||
1928 slice_alpha_c0_offset_div2 < -6 ||
1929 slice_beta_offset_div2 > 6 ||
1930 slice_beta_offset_div2 < -6) {
1932 "deblocking filter parameters %d %d out of range\n",
1933 slice_alpha_c0_offset_div2, slice_beta_offset_div2);
1973 if (
h->ps.pps->weighted_bipred_idc == 2 &&
1984 if (!
h->setup_finished)
2004 h->postpone_filter = 1;
2010 h->ps.pps->chroma_qp_index_offset[0],
2011 h->ps.pps->chroma_qp_index_offset[1]) +
2012 6 * (
h->ps.sps->bit_depth_luma - 8);
2025 for (j = 0; j < 2; j++) {
2028 for (
i = 0;
i < 16;
i++) {
2030 if (j < sl->list_count && i < sl->ref_count[j] &&
2034 for (k = 0; k <
h->short_ref_count; k++)
2035 if (
h->short_ref[k]->f->buf[0]->buffer ==
buf) {
2039 for (k = 0; k <
h->long_ref_count; k++)
2040 if (
h->long_ref[k] &&
h->long_ref[k]->f->buf[0]->buffer ==
buf) {
2041 id_list[
i] =
h->short_ref_count + k;
2049 for (
i = 0;
i < 16;
i++)
2052 ref2frm[18 + 1] = -1;
2053 for (
i = 16;
i < 48;
i++)
2054 ref2frm[
i + 4] = 4 * id_list[(
i - 16) >> 1] +
2060 "slice:%d %s mb:%d %c%s%s frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n",
2068 h->cur_pic_ptr->field_poc[0],
2069 h->cur_pic_ptr->field_poc[1],
2085 int first_slice = sl ==
h->slice_ctx && !
h->current_slice;
2101 if (
h->setup_finished) {
2108 if (
h->current_slice) {
2111 if (
h->nb_slice_ctx_queued) {
2118 memcpy(&tmp_ctx,
h->slice_ctx,
sizeof(tmp_ctx));
2119 memcpy(
h->slice_ctx, sl,
sizeof(tmp_ctx));
2120 memcpy(sl, &tmp_ctx,
sizeof(tmp_ctx));
2133 h->cur_pic_ptr =
NULL;
2140 if (!
h->first_field) {
2141 if (
h->cur_pic_ptr && !
h->droppable) {
2145 h->cur_pic_ptr =
NULL;
2149 if (!
h->current_slice)
2152 if (
h->current_slice == 0 && !
h->first_field) {
2166 if (
h->ps.pps->sps_id !=
pps->sps_id ||
2167 h->ps.pps->transform_8x8_mode !=
pps->transform_8x8_mode
2172 if (
h->ps.sps != (
const SPS*)
h->ps.sps_list[
h->ps.pps->sps_id]->data) {
2174 "SPS changed in the middle of the frame\n");
2179 if (
h->current_slice == 0) {
2185 h->droppable != (nal->
ref_idc == 0)) {
2187 "Changing field mode (%d -> %d) between slices is not allowed\n",
2190 }
else if (!
h->cur_pic_ptr) {
2192 "unset cur_pic_ptr on slice %d\n",
2193 h->current_slice + 1);
2202 h->nb_slice_ctx_queued++;
2227 int mb_type,
int top_xy,
2231 int mb_xy,
int list)
2233 int b_stride =
h->b_stride;
2238 const int b_xy =
h->mb2b_xy[top_xy] + 3 * b_stride;
2239 const int b8_xy = 4 * top_xy + 2;
2242 ref_cache[0 - 1 * 8] =
2243 ref_cache[1 - 1 * 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 0]];
2244 ref_cache[2 - 1 * 8] =
2245 ref_cache[3 - 1 * 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 1]];
2253 const int b_xy =
h->mb2b_xy[left_xy[
LTOP]] + 3;
2254 const int b8_xy = 4 * left_xy[
LTOP] + 1;
2256 AV_COPY32(mv_dst - 1 + 0,
h->cur_pic.motion_val[
list][b_xy + b_stride * 0]);
2257 AV_COPY32(mv_dst - 1 + 8,
h->cur_pic.motion_val[
list][b_xy + b_stride * 1]);
2258 AV_COPY32(mv_dst - 1 + 16,
h->cur_pic.motion_val[
list][b_xy + b_stride * 2]);
2259 AV_COPY32(mv_dst - 1 + 24,
h->cur_pic.motion_val[
list][b_xy + b_stride * 3]);
2261 ref_cache[-1 + 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 2 * 0]];
2262 ref_cache[-1 + 16] =
2263 ref_cache[-1 + 24] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 2 * 1]];
2271 ref_cache[-1 + 16] =
2287 int8_t *
ref = &
h->cur_pic.ref_index[
list][4 * mb_xy];
2289 uint32_t ref01 = (
pack16to32(ref2frm[
ref[0]], ref2frm[
ref[1]]) & 0x00FF00FF) * 0x0101;
2290 uint32_t ref23 = (
pack16to32(ref2frm[
ref[2]], ref2frm[
ref[3]]) & 0x00FF00FF) * 0x0101;
2291 AV_WN32A(&ref_cache[0 * 8], ref01);
2292 AV_WN32A(&ref_cache[1 * 8], ref01);
2293 AV_WN32A(&ref_cache[2 * 8], ref23);
2294 AV_WN32A(&ref_cache[3 * 8], ref23);
2298 int16_t(*mv_src)[2] = &
h->cur_pic.motion_val[
list][4 * sl->
mb_x + 4 * sl->
mb_y * b_stride];
2299 AV_COPY128(mv_dst + 8 * 0, mv_src + 0 * b_stride);
2300 AV_COPY128(mv_dst + 8 * 1, mv_src + 1 * b_stride);
2301 AV_COPY128(mv_dst + 8 * 2, mv_src + 2 * b_stride);
2302 AV_COPY128(mv_dst + 8 * 3, mv_src + 3 * b_stride);
2311 const int mb_xy = sl->
mb_xy;
2317 top_xy = mb_xy - (
h->mb_stride <<
MB_FIELD(sl));
2319 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy - 1;
2321 const int left_mb_field_flag =
IS_INTERLACED(
h->cur_pic.mb_type[mb_xy - 1]);
2324 if (left_mb_field_flag != curr_mb_field_flag)
2325 left_xy[
LTOP] -=
h->mb_stride;
2327 if (curr_mb_field_flag)
2328 top_xy +=
h->mb_stride &
2329 (((
h->cur_pic.mb_type[top_xy] >> 7) & 1) - 1);
2330 if (left_mb_field_flag != curr_mb_field_flag)
2331 left_xy[
LBOT] +=
h->mb_stride;
2343 int qp =
h->cur_pic.qscale_table[mb_xy];
2344 if (qp <= qp_thresh &&
2345 (left_xy[
LTOP] < 0 ||
2346 ((qp +
h->cur_pic.qscale_table[left_xy[
LTOP]] + 1) >> 1) <= qp_thresh) &&
2348 ((qp +
h->cur_pic.qscale_table[top_xy] + 1) >> 1) <= qp_thresh)) {
2351 if ((left_xy[
LTOP] < 0 ||
2352 ((qp +
h->cur_pic.qscale_table[left_xy[
LBOT]] + 1) >> 1) <= qp_thresh) &&
2353 (top_xy <
h->mb_stride ||
2354 ((qp +
h->cur_pic.qscale_table[top_xy -
h->mb_stride] + 1) >> 1) <= qp_thresh))
2359 top_type =
h->cur_pic.mb_type[top_xy];
2360 left_type[
LTOP] =
h->cur_pic.mb_type[left_xy[
LTOP]];
2361 left_type[
LBOT] =
h->cur_pic.mb_type[left_xy[
LBOT]];
2366 left_type[
LTOP] = left_type[
LBOT] = 0;
2368 if (
h->slice_table[top_xy] == 0xFFFF)
2370 if (
h->slice_table[left_xy[
LBOT]] == 0xFFFF)
2371 left_type[
LTOP] = left_type[
LBOT] = 0;
2381 top_type, left_type, mb_xy, 0);
2384 top_type, left_type, mb_xy, 1);
2386 nnz =
h->non_zero_count[mb_xy];
2388 AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]);
2389 AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]);
2390 AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]);
2391 AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]);
2392 sl->
cbp =
h->cbp_table[mb_xy];
2395 nnz =
h->non_zero_count[top_xy];
2396 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[3 * 4]);
2399 if (left_type[
LTOP]) {
2400 nnz =
h->non_zero_count[left_xy[
LTOP]];
2401 nnz_cache[3 + 8 * 1] = nnz[3 + 0 * 4];
2402 nnz_cache[3 + 8 * 2] = nnz[3 + 1 * 4];
2403 nnz_cache[3 + 8 * 3] = nnz[3 + 2 * 4];
2404 nnz_cache[3 + 8 * 4] = nnz[3 + 3 * 4];
2409 if (!
CABAC(
h) &&
h->ps.pps->transform_8x8_mode) {
2411 nnz_cache[4 + 8 * 0] =
2412 nnz_cache[5 + 8 * 0] = (
h->cbp_table[top_xy] & 0x4000) >> 12;
2413 nnz_cache[6 + 8 * 0] =
2414 nnz_cache[7 + 8 * 0] = (
h->cbp_table[top_xy] & 0x8000) >> 12;
2417 nnz_cache[3 + 8 * 1] =
2418 nnz_cache[3 + 8 * 2] = (
h->cbp_table[left_xy[
LTOP]] & 0x2000) >> 12;
2421 nnz_cache[3 + 8 * 3] =
2422 nnz_cache[3 + 8 * 4] = (
h->cbp_table[left_xy[
LBOT]] & 0x8000) >> 12;
2426 nnz_cache[
scan8[0]] =
2427 nnz_cache[
scan8[1]] =
2428 nnz_cache[
scan8[2]] =
2429 nnz_cache[
scan8[3]] = (sl->
cbp & 0x1000) >> 12;
2431 nnz_cache[
scan8[0 + 4]] =
2432 nnz_cache[
scan8[1 + 4]] =
2433 nnz_cache[
scan8[2 + 4]] =
2434 nnz_cache[
scan8[3 + 4]] = (sl->
cbp & 0x2000) >> 12;
2436 nnz_cache[
scan8[0 + 8]] =
2437 nnz_cache[
scan8[1 + 8]] =
2438 nnz_cache[
scan8[2 + 8]] =
2439 nnz_cache[
scan8[3 + 8]] = (sl->
cbp & 0x4000) >> 12;
2441 nnz_cache[
scan8[0 + 12]] =
2442 nnz_cache[
scan8[1 + 12]] =
2443 nnz_cache[
scan8[2 + 12]] =
2444 nnz_cache[
scan8[3 + 12]] = (sl->
cbp & 0x8000) >> 12;
2453 uint8_t *dest_y, *dest_cb, *dest_cr;
2454 int linesize, uvlinesize, mb_x, mb_y;
2457 const int pixel_shift =
h->pixel_shift;
2458 const int block_h = 16 >>
h->chroma_y_shift;
2460 if (
h->postpone_filter)
2464 for (mb_x = start_x; mb_x < end_x; mb_x++)
2465 for (mb_y = end_mb_y -
FRAME_MBAFF(
h); mb_y <= end_mb_y; mb_y++) {
2467 mb_xy = sl->
mb_xy = mb_x + mb_y *
h->mb_stride;
2468 mb_type =
h->cur_pic.mb_type[mb_xy];
2476 dest_y =
h->cur_pic.f->data[0] +
2477 ((mb_x << pixel_shift) + mb_y * sl->
linesize) * 16;
2478 dest_cb =
h->cur_pic.f->data[1] +
2479 (mb_x << pixel_shift) * (8 <<
CHROMA444(
h)) +
2481 dest_cr =
h->cur_pic.f->data[2] +
2482 (mb_x << pixel_shift) * (8 <<
CHROMA444(
h)) +
2507 linesize, uvlinesize);
2510 dest_cr, linesize, uvlinesize);
2523 const int mb_xy = sl->
mb_x + sl->
mb_y *
h->mb_stride;
2524 int mb_type = (
h->slice_table[mb_xy - 1] == sl->
slice_num) ?
2525 h->cur_pic.mb_type[mb_xy - 1] :
2526 (
h->slice_table[mb_xy -
h->mb_stride] == sl->
slice_num) ?
2527 h->cur_pic.mb_type[mb_xy -
h->mb_stride] : 0;
2542 if ((top +
height) >= pic_height)
2543 height += deblock_border;
2544 top -= deblock_border;
2547 if (top >= pic_height || (top +
height) < 0)
2566 int startx,
int starty,
2567 int endx,
int endy,
int status)
2572 if (CONFIG_ERROR_RESILIENCE) {
2583 int lf_x_start = sl->
mb_x;
2587 sl->
linesize =
h->cur_pic_ptr->f->linesize[0];
2598 if (
h->postpone_filter)
2604 if (!(
h->avctx->active_thread_type &
FF_THREAD_SLICE) &&
h->picture_structure ==
PICT_FRAME &&
h->slice_ctx[0].er.error_status_table) {
2607 int prev_status =
h->slice_ctx[0].er.error_status_table[
h->slice_ctx[0].er.mb_index2xy[start_i - 1]];
2610 h->slice_ctx[0].er.error_occurred = 1;
2614 if (
h->ps.pps->cabac) {
2660 if (sl->
mb_x >= lf_x_start)
2676 if (++sl->
mb_x >=
h->mb_width) {
2678 sl->
mb_x = lf_x_start = 0;
2688 if (eos || sl->
mb_y >=
h->mb_height) {
2689 ff_tlog(
h->avctx,
"slice end %d %d\n",
2693 if (sl->
mb_x > lf_x_start)
2727 "error while decoding MB %d %d\n", sl->
mb_x, sl->
mb_y);
2733 if (++sl->
mb_x >=
h->mb_width) {
2735 sl->
mb_x = lf_x_start = 0;
2743 if (sl->
mb_y >=
h->mb_height) {
2744 ff_tlog(
h->avctx,
"slice end %d %d\n",
2763 ff_tlog(
h->avctx,
"slice end %d %d\n",
2769 if (sl->
mb_x > lf_x_start)
2797 int context_count =
h->nb_slice_ctx_queued;
2801 h->slice_ctx[0].next_slice_idx = INT_MAX;
2803 if (
h->avctx->hwaccel || context_count < 1)
2806 av_assert0(context_count &&
h->slice_ctx[context_count - 1].mb_y <
h->mb_height);
2808 if (context_count == 1) {
2810 h->slice_ctx[0].next_slice_idx =
h->mb_width *
h->mb_height;
2811 h->postpone_filter = 0;
2814 h->mb_y =
h->slice_ctx[0].mb_y;
2819 for (
i = 0;
i < context_count;
i++) {
2820 int next_slice_idx =
h->mb_width *
h->mb_height;
2823 sl = &
h->slice_ctx[
i];
2824 if (CONFIG_ERROR_RESILIENCE) {
2829 slice_idx = sl->
mb_y *
h->mb_width + sl->
mb_x;
2830 for (j = 0; j < context_count; j++) {
2832 int slice_idx2 = sl2->
mb_y *
h->mb_width + sl2->
mb_x;
2834 if (
i == j || slice_idx2 < slice_idx)
2836 next_slice_idx =
FFMIN(next_slice_idx, slice_idx2);
2842 NULL, context_count,
sizeof(
h->slice_ctx[0]));
2845 sl = &
h->slice_ctx[context_count - 1];
2847 if (CONFIG_ERROR_RESILIENCE) {
2848 for (
i = 1;
i < context_count;
i++)
2849 h->slice_ctx[0].er.error_count +=
h->slice_ctx[
i].er.error_count;
2852 if (
h->postpone_filter) {
2853 h->postpone_filter = 0;
2855 for (
i = 0;
i < context_count;
i++) {
2858 sl = &
h->slice_ctx[
i];
2860 x_end = (sl->
mb_y >=
h->mb_height) ?
h->mb_width : sl->
mb_x;
2865 j == y_end - 1 ? x_end :
h->mb_width);
2872 h->nb_slice_ctx_queued = 0;