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) {
210 if (
h->avctx->hwaccel) {
221 int h_chroma_shift, v_chroma_shift;
223 &h_chroma_shift, &v_chroma_shift);
233 if (!
h->qscale_table_pool) {
277 if (!
h->DPB[
i].f->buf[0])
284 #define IN_RANGE(a, b, size) (((void*)(a) >= (void*)(b)) && ((void*)(a) < (void*)((b) + (size))))
286 #define REBASE_PICTURE(pic, new_ctx, old_ctx) \
287 (((pic) && (pic) >= (old_ctx)->DPB && \
288 (pic) < (old_ctx)->DPB + H264_MAX_PICTURE_COUNT) ? \
289 &(new_ctx)->DPB[(pic) - (old_ctx)->DPB] : NULL)
297 for (
i = 0;
i < count;
i++) {
311 int inited =
h->context_initialized, err = 0;
318 if (inited && !h1->ps.sps)
322 (
h->width != h1->width ||
323 h->height != h1->height ||
324 h->mb_width != h1->mb_width ||
325 h->mb_height != h1->mb_height ||
327 h->ps.sps->bit_depth_luma != h1->ps.sps->bit_depth_luma ||
328 h->ps.sps->chroma_format_idc != h1->ps.sps->chroma_format_idc ||
329 h->ps.sps->colorspace != h1->ps.sps->colorspace)) {
334 memcpy(
h->block_offset, h1->block_offset,
sizeof(
h->block_offset));
353 if (h1->ps.pps_ref) {
354 h->ps.pps = (
const PPS*)
h->ps.pps_ref->data;
355 h->ps.sps =
h->ps.pps->sps;
358 if (need_reinit || !inited) {
359 h->width = h1->width;
360 h->height = h1->height;
361 h->mb_height = h1->mb_height;
362 h->mb_width = h1->mb_width;
363 h->mb_num = h1->mb_num;
364 h->mb_stride = h1->mb_stride;
365 h->b_stride = h1->b_stride;
366 h->x264_build = h1->x264_build;
368 if (
h->context_initialized || h1->context_initialized) {
376 memcpy(
h->block_offset, h1->block_offset,
sizeof(
h->block_offset));
379 h->avctx->coded_height = h1->avctx->coded_height;
380 h->avctx->coded_width = h1->avctx->coded_width;
381 h->avctx->width = h1->avctx->width;
382 h->avctx->height = h1->avctx->height;
383 h->width_from_caller = h1->width_from_caller;
384 h->height_from_caller = h1->height_from_caller;
385 h->coded_picture_number = h1->coded_picture_number;
386 h->first_field = h1->first_field;
387 h->picture_structure = h1->picture_structure;
388 h->mb_aff_frame = h1->mb_aff_frame;
389 h->droppable = h1->droppable;
402 h->enable_er = h1->enable_er;
403 h->workaround_bugs = h1->workaround_bugs;
404 h->droppable = h1->droppable;
407 h->is_avc = h1->is_avc;
408 h->nal_length_size = h1->nal_length_size;
410 memcpy(&
h->poc, &h1->poc,
sizeof(
h->poc));
412 memcpy(
h->short_ref, h1->short_ref,
sizeof(
h->short_ref));
413 memcpy(
h->long_ref, h1->long_ref,
sizeof(
h->long_ref));
414 memcpy(
h->delayed_pic, h1->delayed_pic,
sizeof(
h->delayed_pic));
415 memcpy(
h->last_pocs, h1->last_pocs,
sizeof(
h->last_pocs));
417 h->next_output_pic = h1->next_output_pic;
418 h->next_outputed_poc = h1->next_outputed_poc;
419 h->poc_offset = h1->poc_offset;
421 memcpy(
h->mmco, h1->mmco,
sizeof(
h->mmco));
422 h->nb_mmco = h1->nb_mmco;
423 h->mmco_reset = h1->mmco_reset;
424 h->explicit_ref_marking = h1->explicit_ref_marking;
425 h->long_ref_count = h1->long_ref_count;
426 h->short_ref_count = h1->short_ref_count;
433 h->frame_recovered = h1->frame_recovered;
439 for (
i = 0;
i <
h->sei.unregistered.nb_buf_ref;
i++)
441 h->sei.unregistered.nb_buf_ref = 0;
443 if (h1->sei.unregistered.nb_buf_ref) {
445 h1->sei.unregistered.nb_buf_ref,
446 sizeof(*
h->sei.unregistered.buf_ref));
450 for (
i = 0;
i < h1->sei.unregistered.nb_buf_ref;
i++) {
451 h->sei.unregistered.buf_ref[
i] =
av_buffer_ref(h1->sei.unregistered.buf_ref[
i]);
452 if (!
h->sei.unregistered.buf_ref[
i])
454 h->sei.unregistered.nb_buf_ref++;
457 h->sei.unregistered.x264_build = h1->sei.unregistered.x264_build;
464 h->poc.prev_poc_msb =
h->poc.poc_msb;
465 h->poc.prev_poc_lsb =
h->poc.poc_lsb;
467 h->poc.prev_frame_num_offset =
h->poc.frame_num_offset;
468 h->poc.prev_frame_num =
h->poc.frame_num;
470 h->recovery_frame = h1->recovery_frame;
491 const int pixel_shift =
h->pixel_shift;
499 h->cur_pic_ptr =
NULL;
508 pic->
reference =
h->droppable ? 0 :
h->picture_structure;
530 pic->
needs_fg =
h->sei.film_grain_characteristics.present && !
h->avctx->hwaccel &&
536 h->cur_pic_ptr = pic;
538 if (CONFIG_ERROR_RESILIENCE) {
545 for (
i = 0;
i <
h->nb_slice_ctx;
i++) {
546 h->slice_ctx[
i].linesize =
h->cur_pic_ptr->f->linesize[0];
547 h->slice_ctx[
i].uvlinesize =
h->cur_pic_ptr->f->linesize[1];
550 if (CONFIG_ERROR_RESILIENCE &&
h->enable_er) {
556 for (
i = 0;
i < 16;
i++) {
560 for (
i = 0;
i < 16;
i++) {
561 h->block_offset[16 +
i] =
563 h->block_offset[48 + 16 +
i] =
571 h->cur_pic_ptr->reference = 0;
573 h->cur_pic_ptr->field_poc[0] =
h->cur_pic_ptr->field_poc[1] = INT_MAX;
575 h->next_output_pic =
NULL;
577 h->postpone_filter = 0;
579 h->mb_aff_frame =
h->ps.sps->mb_aff && (
h->picture_structure ==
PICT_FRAME);
581 if (
h->sei.unregistered.x264_build >= 0)
582 h->x264_build =
h->sei.unregistered.x264_build;
584 assert(
h->cur_pic_ptr->long_ref == 0);
591 uint8_t *src_cb, uint8_t *src_cr,
592 int linesize,
int uvlinesize,
597 const int pixel_shift =
h->pixel_shift;
602 src_cb -= uvlinesize;
603 src_cr -= uvlinesize;
609 AV_COPY128(top_border, src_y + 15 * linesize);
611 AV_COPY128(top_border + 16, src_y + 15 * linesize + 16);
615 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
616 AV_COPY128(top_border + 48, src_cb + 15 * uvlinesize + 16);
617 AV_COPY128(top_border + 64, src_cr + 15 * uvlinesize);
618 AV_COPY128(top_border + 80, src_cr + 15 * uvlinesize + 16);
620 AV_COPY128(top_border + 16, src_cb + 15 * uvlinesize);
621 AV_COPY128(top_border + 32, src_cr + 15 * uvlinesize);
623 }
else if (chroma422) {
625 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
626 AV_COPY128(top_border + 48, src_cr + 15 * uvlinesize);
628 AV_COPY64(top_border + 16, src_cb + 15 * uvlinesize);
629 AV_COPY64(top_border + 24, src_cr + 15 * uvlinesize);
633 AV_COPY128(top_border + 32, src_cb + 7 * uvlinesize);
634 AV_COPY128(top_border + 48, src_cr + 7 * uvlinesize);
636 AV_COPY64(top_border + 16, src_cb + 7 * uvlinesize);
637 AV_COPY64(top_border + 24, src_cr + 7 * uvlinesize);
651 AV_COPY128(top_border, src_y + 16 * linesize);
653 AV_COPY128(top_border + 16, src_y + 16 * linesize + 16);
658 AV_COPY128(top_border + 32, src_cb + 16 * linesize);
659 AV_COPY128(top_border + 48, src_cb + 16 * linesize + 16);
660 AV_COPY128(top_border + 64, src_cr + 16 * linesize);
661 AV_COPY128(top_border + 80, src_cr + 16 * linesize + 16);
663 AV_COPY128(top_border + 16, src_cb + 16 * linesize);
664 AV_COPY128(top_border + 32, src_cr + 16 * linesize);
666 }
else if (chroma422) {
668 AV_COPY128(top_border + 32, src_cb + 16 * uvlinesize);
669 AV_COPY128(top_border + 48, src_cr + 16 * uvlinesize);
671 AV_COPY64(top_border + 16, src_cb + 16 * uvlinesize);
672 AV_COPY64(top_border + 24, src_cr + 16 * uvlinesize);
676 AV_COPY128(top_border + 32, src_cb + 8 * uvlinesize);
677 AV_COPY128(top_border + 48, src_cr + 8 * uvlinesize);
679 AV_COPY64(top_border + 16, src_cb + 8 * uvlinesize);
680 AV_COPY64(top_border + 24, src_cr + 8 * uvlinesize);
693 int ref0, ref1,
i, cur_poc, ref_start, ref_count0, ref_count1;
695 for (
i = 0;
i < 2;
i++) {
702 cur_poc =
h->cur_pic_ptr->poc;
704 cur_poc =
h->cur_pic_ptr->field_poc[
h->picture_structure - 1];
716 cur_poc =
h->cur_pic_ptr->field_poc[
field];
727 for (ref0 = ref_start; ref0 < ref_count0; ref0++) {
729 for (ref1 = ref_start; ref1 < ref_count1; ref1++) {
736 int tx = (16384 + (
FFABS(
td) >> 1)) /
td;
737 int dist_scale_factor = (
tb * tx + 32) >> 8;
738 if (dist_scale_factor >= -64 && dist_scale_factor <= 128)
739 w = 64 - dist_scale_factor;
758 for (
i = 0;
i < 16;
i++) {
759 #define TRANSPOSE(x) ((x) >> 2) | (((x) << 2) & 0xF)
764 for (
i = 0;
i < 64;
i++) {
765 #define TRANSPOSE(x) ((x) >> 3) | (((x) & 7) << 3)
772 if (
h->ps.sps->transform_bypass) {
776 memcpy(
h->field_scan_q0 ,
field_scan ,
sizeof(
h->field_scan_q0 ));
777 memcpy(
h->field_scan8x8_q0 ,
field_scan8x8 ,
sizeof(
h->field_scan8x8_q0 ));
780 memcpy(
h->zigzag_scan_q0 ,
h->zigzag_scan ,
sizeof(
h->zigzag_scan_q0 ));
781 memcpy(
h->zigzag_scan8x8_q0 ,
h->zigzag_scan8x8 ,
sizeof(
h->zigzag_scan8x8_q0 ));
782 memcpy(
h->zigzag_scan8x8_cavlc_q0 ,
h->zigzag_scan8x8_cavlc ,
sizeof(
h->zigzag_scan8x8_cavlc_q0));
783 memcpy(
h->field_scan_q0 ,
h->field_scan ,
sizeof(
h->field_scan_q0 ));
784 memcpy(
h->field_scan8x8_q0 ,
h->field_scan8x8 ,
sizeof(
h->field_scan8x8_q0 ));
785 memcpy(
h->field_scan8x8_cavlc_q0 ,
h->field_scan8x8_cavlc ,
sizeof(
h->field_scan8x8_cavlc_q0 ));
791 #define HWACCEL_MAX (CONFIG_H264_DXVA2_HWACCEL + \
792 (CONFIG_H264_D3D11VA_HWACCEL * 2) + \
793 CONFIG_H264_NVDEC_HWACCEL + \
794 CONFIG_H264_VAAPI_HWACCEL + \
795 CONFIG_H264_VIDEOTOOLBOX_HWACCEL + \
796 CONFIG_H264_VDPAU_HWACCEL)
801 switch (
h->ps.sps->bit_depth_luma) {
814 #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL
851 #if CONFIG_H264_VDPAU_HWACCEL
854 #if CONFIG_H264_NVDEC_HWACCEL
857 #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL
874 #if CONFIG_H264_DXVA2_HWACCEL
877 #if CONFIG_H264_D3D11VA_HWACCEL
881 #if CONFIG_H264_VAAPI_HWACCEL
884 if (
h->avctx->codec->pix_fmts)
885 choices =
h->avctx->codec->pix_fmts;
894 "Unsupported bit depth %d\n",
h->ps.sps->bit_depth_luma);
901 if (choices[
i] ==
h->avctx->pix_fmt && !force_callback)
910 int cr =
sps->crop_right;
911 int cl =
sps->crop_left;
912 int ct =
sps->crop_top;
913 int cb =
sps->crop_bottom;
920 if (
h->width_from_caller > 0 &&
h->height_from_caller > 0 &&
921 !
sps->crop_top && !
sps->crop_left &&
924 h->width_from_caller <=
width &&
925 h->height_from_caller <=
height) {
926 width =
h->width_from_caller;
927 height =
h->height_from_caller;
933 h->width_from_caller = 0;
934 h->height_from_caller = 0;
937 h->avctx->coded_width =
h->width;
938 h->avctx->coded_height =
h->height;
959 &
h->chroma_x_shift, &
h->chroma_y_shift);
961 if (
sps->timing_info_present_flag) {
962 int64_t den =
sps->time_scale;
963 if (
h->x264_build < 44
U)
965 av_reduce(&
h->avctx->framerate.den, &
h->avctx->framerate.num,
966 sps->num_units_in_tick *
h->avctx->ticks_per_frame, den, 1 << 30);
972 h->prev_interlaced_frame = 1;
981 if (
sps->bit_depth_luma < 8 ||
sps->bit_depth_luma > 14 ||
982 sps->bit_depth_luma == 11 ||
sps->bit_depth_luma == 13
985 sps->bit_depth_luma);
990 h->cur_bit_depth_luma =
991 h->avctx->bits_per_raw_sample =
sps->bit_depth_luma;
992 h->cur_chroma_format_idc =
sps->chroma_format_idc;
993 h->pixel_shift =
sps->bit_depth_luma > 8;
994 h->chroma_format_idc =
sps->chroma_format_idc;
995 h->bit_depth_luma =
sps->bit_depth_luma;
998 sps->chroma_format_idc);
1002 sps->chroma_format_idc);
1012 for (
i = 0;
i <
h->nb_slice_ctx;
i++) {
1017 sl->
mvd_table[0] =
h->mvd_table[0] +
i * 8 * 2 *
h->mb_stride;
1018 sl->
mvd_table[1] =
h->mvd_table[1] +
i * 8 * 2 *
h->mb_stride;
1027 h->context_initialized = 1;
1032 h->context_initialized = 0;
1050 int needs_reinit = 0, must_reinit,
ret;
1058 h->ps.pps = (
const PPS*)
h->ps.pps_ref->data;
1061 if (
h->ps.sps !=
h->ps.pps->sps) {
1062 h->ps.sps = (
const SPS*)
h->ps.pps->sps;
1064 if (
h->mb_width !=
h->ps.sps->mb_width ||
1065 h->mb_height !=
h->ps.sps->mb_height ||
1066 h->cur_bit_depth_luma !=
h->ps.sps->bit_depth_luma ||
1067 h->cur_chroma_format_idc !=
h->ps.sps->chroma_format_idc
1071 if (
h->bit_depth_luma !=
h->ps.sps->bit_depth_luma ||
1072 h->chroma_format_idc !=
h->ps.sps->chroma_format_idc)
1077 must_reinit = (
h->context_initialized &&
1078 ( 16*
sps->mb_width !=
h->avctx->coded_width
1079 || 16*
sps->mb_height !=
h->avctx->coded_height
1080 ||
h->cur_bit_depth_luma !=
sps->bit_depth_luma
1081 ||
h->cur_chroma_format_idc !=
sps->chroma_format_idc
1082 ||
h->mb_width !=
sps->mb_width
1083 ||
h->mb_height !=
sps->mb_height
1089 if (first_slice &&
av_cmp_q(
sps->sar,
h->avctx->sample_aspect_ratio))
1092 if (!
h->setup_finished) {
1094 h->avctx->level =
sps->level_idc;
1095 h->avctx->refs =
sps->ref_frame_count;
1097 h->mb_width =
sps->mb_width;
1098 h->mb_height =
sps->mb_height;
1099 h->mb_num =
h->mb_width *
h->mb_height;
1100 h->mb_stride =
h->mb_width + 1;
1102 h->b_stride =
h->mb_width * 4;
1104 h->chroma_y_shift =
sps->chroma_format_idc <= 1;
1106 h->width = 16 *
h->mb_width;
1107 h->height = 16 *
h->mb_height;
1111 if (
sps->video_signal_type_present_flag) {
1114 if (
sps->colour_description_present_flag) {
1115 if (
h->avctx->colorspace !=
sps->colorspace)
1117 h->avctx->color_primaries =
sps->color_primaries;
1118 h->avctx->color_trc =
sps->color_trc;
1119 h->avctx->colorspace =
sps->colorspace;
1123 if (
h->sei.alternative_transfer.present &&
1126 h->avctx->color_trc =
h->sei.alternative_transfer.preferred_transfer_characteristics;
1129 h->avctx->chroma_sample_location =
sps->chroma_location;
1131 if (!
h->context_initialized || must_reinit || needs_reinit) {
1132 int flush_changes =
h->context_initialized;
1133 h->context_initialized = 0;
1134 if (sl !=
h->slice_ctx) {
1136 "changing width %d -> %d / height %d -> %d on "
1138 h->width,
h->avctx->coded_width,
1139 h->height,
h->avctx->coded_height,
1140 h->current_slice + 1);
1151 h->avctx->pix_fmt =
ret;
1158 "h264_slice_header_init() failed\n");
1172 out->interlaced_frame = 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 out->interlaced_frame = 1;
1201 out->interlaced_frame = 1;
1204 out->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 out->interlaced_frame = (
pt->ct_type & (1 << 1)) != 0;
1228 h->prev_interlaced_frame =
out->interlaced_frame;
1234 if (
sps->pic_struct_present_flag &&
h->sei.picture_timing.present) {
1239 out->top_field_first = 1;
1241 out->top_field_first = 0;
1242 }
else if (
out->interlaced_frame) {
1245 out->top_field_first = 1;
1248 out->top_field_first = 0;
1252 if (
h->sei.frame_packing.present &&
1253 h->sei.frame_packing.arrangement_type <= 6 &&
1254 h->sei.frame_packing.content_interpretation_type > 0 &&
1255 h->sei.frame_packing.content_interpretation_type < 3) {
1259 switch (
fp->arrangement_type) {
1270 if (
fp->quincunx_sampling_flag)
1286 if (
fp->content_interpretation_type == 2)
1290 if (
fp->current_frame_is_frame0_flag)
1298 if (
h->sei.display_orientation.present &&
1299 (
h->sei.display_orientation.anticlockwise_rotation ||
1300 h->sei.display_orientation.hflip ||
1301 h->sei.display_orientation.vflip)) {
1316 angle = -angle * (1 - 2 * !!o->
hflip) * (1 - 2 * !!o->
vflip);
1323 if (
h->sei.afd.present) {
1328 *sd->
data =
h->sei.afd.active_format_description;
1329 h->sei.afd.present = 0;
1333 if (
h->sei.a53_caption.buf_ref) {
1344 for (
int i = 0;
i <
h->sei.unregistered.nb_buf_ref;
i++) {
1356 h->sei.unregistered.nb_buf_ref = 0;
1358 if (
h->sei.film_grain_characteristics.present) {
1365 fgp->
seed = cur->
poc + (
h->poc_offset << 5);
1378 if (
sps->video_signal_type_present_flag)
1382 if (
sps->colour_description_present_flag) {
1413 if (
h->sei.picture_timing.timecode_cnt > 0) {
1419 sizeof(uint32_t)*4);
1423 tc_sd = (uint32_t*)tcside->
data;
1424 tc_sd[0] =
h->sei.picture_timing.timecode_cnt;
1426 for (
int i = 0;
i < tc_sd[0];
i++) {
1427 int drop =
h->sei.picture_timing.timecode[
i].dropframe;
1428 int hh =
h->sei.picture_timing.timecode[
i].hours;
1429 int mm =
h->sei.picture_timing.timecode[
i].minutes;
1430 int ss =
h->sei.picture_timing.timecode[
i].seconds;
1431 int ff =
h->sei.picture_timing.timecode[
i].frame;
1437 h->sei.picture_timing.timecode_cnt = 0;
1448 int i, pics, out_of_order, out_idx;
1453 if (
sps->bitstream_restriction_flag ||
1455 h->avctx->has_b_frames =
FFMAX(
h->avctx->has_b_frames,
sps->num_reorder_frames);
1458 for (
i = 0; 1;
i++) {
1461 h->last_pocs[
i-1] = cur->
poc;
1464 h->last_pocs[
i-1]=
h->last_pocs[
i];
1470 out_of_order =
FFMAX(out_of_order, 1);
1474 h->last_pocs[
i] = INT_MIN;
1475 h->last_pocs[0] = cur->
poc;
1477 }
else if(
h->avctx->has_b_frames < out_of_order && !
sps->bitstream_restriction_flag){
1479 av_log(
h->avctx, loglevel,
"Increasing reorder buffer to %d\n", out_of_order);
1480 h->avctx->has_b_frames = out_of_order;
1484 while (
h->delayed_pic[pics])
1489 h->delayed_pic[pics++] = cur;
1493 out =
h->delayed_pic[0];
1495 for (
i = 1;
h->delayed_pic[
i] &&
1496 !
h->delayed_pic[
i]->f->key_frame &&
1497 !
h->delayed_pic[
i]->mmco_reset;
1499 if (
h->delayed_pic[
i]->poc <
out->poc) {
1500 out =
h->delayed_pic[
i];
1503 if (
h->avctx->has_b_frames == 0 &&
1504 (
h->delayed_pic[0]->f->key_frame ||
h->delayed_pic[0]->mmco_reset))
1505 h->next_outputed_poc = INT_MIN;
1506 out_of_order =
out->poc <
h->next_outputed_poc;
1508 if (out_of_order || pics >
h->avctx->has_b_frames) {
1510 for (
i = out_idx;
h->delayed_pic[
i];
i++)
1511 h->delayed_pic[
i] =
h->delayed_pic[
i + 1];
1513 if (!out_of_order && pics >
h->avctx->has_b_frames) {
1514 h->next_output_pic =
out;
1515 if (out_idx == 0 &&
h->delayed_pic[0] && (
h->delayed_pic[0]->f->key_frame ||
h->delayed_pic[0]->mmco_reset)) {
1516 h->next_outputed_poc = INT_MIN;
1518 h->next_outputed_poc =
out->poc;
1520 if (
out->recovered) {
1527 if (!
out->recovered) {
1530 h->next_output_pic =
NULL;
1547 const H2645NAL *nal,
int first_slice)
1552 int last_pic_structure, last_pic_droppable,
ret;
1560 if (
sps &&
sps->bitstream_restriction_flag &&
1561 h->avctx->has_b_frames <
sps->num_reorder_frames) {
1562 h->avctx->has_b_frames =
sps->num_reorder_frames;
1565 last_pic_droppable =
h->droppable;
1566 last_pic_structure =
h->picture_structure;
1567 h->droppable = (nal->
ref_idc == 0);
1578 else if (
h->picture_intra_only)
1583 if (
h->poc.frame_num !=
h->poc.prev_frame_num) {
1584 int unwrap_prev_frame_num =
h->poc.prev_frame_num;
1585 int max_frame_num = 1 <<
sps->log2_max_frame_num;
1587 if (unwrap_prev_frame_num >
h->poc.frame_num)
1588 unwrap_prev_frame_num -= max_frame_num;
1590 if ((
h->poc.frame_num - unwrap_prev_frame_num) >
sps->ref_frame_count) {
1591 unwrap_prev_frame_num = (
h->poc.frame_num -
sps->ref_frame_count) - 1;
1592 if (unwrap_prev_frame_num < 0)
1593 unwrap_prev_frame_num += max_frame_num;
1595 h->poc.prev_frame_num = unwrap_prev_frame_num;
1604 if (
h->first_field) {
1611 if (
h->cur_pic_ptr->tf.owner[last_field] ==
h->avctx) {
1616 if (!
FIELD_PICTURE(
h) ||
h->picture_structure == last_pic_structure) {
1624 if (
h->cur_pic_ptr->frame_num !=
h->poc.frame_num) {
1640 "Invalid field mode combination %d/%d\n",
1641 last_pic_structure,
h->picture_structure);
1642 h->picture_structure = last_pic_structure;
1643 h->droppable = last_pic_droppable;
1645 }
else if (last_pic_droppable !=
h->droppable) {
1647 "Found reference and non-reference fields in the same frame, which");
1648 h->picture_structure = last_pic_structure;
1649 h->droppable = last_pic_droppable;
1656 while (
h->poc.frame_num !=
h->poc.prev_frame_num && !
h->first_field &&
1657 h->poc.frame_num != (
h->poc.prev_frame_num + 1) % (1 <<
sps->log2_max_frame_num)) {
1660 h->poc.frame_num,
h->poc.prev_frame_num);
1661 if (!
sps->gaps_in_frame_num_allowed_flag)
1663 h->last_pocs[
i] = INT_MIN;
1670 h->poc.prev_frame_num++;
1671 h->poc.prev_frame_num %= 1 <<
sps->log2_max_frame_num;
1672 h->cur_pic_ptr->frame_num =
h->poc.prev_frame_num;
1673 h->cur_pic_ptr->invalid_gap = !
sps->gaps_in_frame_num_allowed_flag;
1677 h->explicit_ref_marking = 0;
1688 if (
h->short_ref_count) {
1690 1<<(
h->ps.sps->bit_depth_luma-1),
1691 1<<(
h->ps.sps->bit_depth_chroma-1),
1692 1<<(
h->ps.sps->bit_depth_chroma-1),
1697 h->short_ref[0]->f->width == prev->
f->
width &&
1698 h->short_ref[0]->f->height == prev->
f->
height &&
1699 h->short_ref[0]->f->format == prev->
f->
format) {
1704 h->short_ref[0]->tf.f =
h->short_ref[0]->f;
1708 h->short_ref[0]->poc = prev->
poc + 2
U;
1710 if (
h->short_ref[0]->field_picture)
1712 }
else if (!
h->frame_recovered && !
h->avctx->hwaccel)
1714 h->short_ref[0]->frame_num =
h->poc.prev_frame_num;
1721 if (
h->first_field) {
1727 if (!
FIELD_PICTURE(
h) ||
h->picture_structure == last_pic_structure) {
1730 h->missing_fields ++;
1731 h->cur_pic_ptr =
NULL;
1734 h->missing_fields = 0;
1735 if (
h->cur_pic_ptr->frame_num !=
h->poc.frame_num) {
1742 h->cur_pic_ptr =
NULL;
1748 h->cur_pic_ptr =
NULL;
1767 h->cur_pic_ptr->tf.owner[
field] =
h->avctx;
1773 memset(
h->slice_table +
i*
h->mb_stride, -1, (
h->mb_stride - (
i+1==
h->mb_height)) *
sizeof(*
h->slice_table));
1775 memset(
h->slice_table, -1,
1776 (
h->mb_height *
h->mb_stride - 1) *
sizeof(*
h->slice_table));
1780 h->ps.sps, &
h->poc,
h->picture_structure, nal->
ref_idc);
1790 if (
h->sei.recovery_point.recovery_frame_cnt >= 0) {
1791 const int sei_recovery_frame_cnt =
h->sei.recovery_point.recovery_frame_cnt;
1794 h->valid_recovery_point = 1;
1796 if (
h->recovery_frame < 0
1797 ||
av_mod_uintp2(
h->recovery_frame -
h->poc.frame_num,
h->ps.sps->log2_max_frame_num) > sei_recovery_frame_cnt) {
1798 h->recovery_frame =
av_mod_uintp2(
h->poc.frame_num + sei_recovery_frame_cnt,
h->ps.sps->log2_max_frame_num);
1800 if (!
h->valid_recovery_point)
1801 h->recovery_frame =
h->poc.frame_num;
1808 (
h->recovery_frame ==
h->poc.frame_num && nal->
ref_idc)) {
1809 h->recovery_frame = -1;
1810 h->cur_pic_ptr->recovered = 1;
1817 h->cur_pic_ptr->recovered |=
h->frame_recovered;
1844 unsigned int slice_type,
tmp,
i;
1845 int field_pic_flag, bottom_field_flag;
1846 int first_slice = sl ==
h->slice_ctx && !
h->current_slice;
1847 int picture_structure;
1855 if (slice_type > 9) {
1857 "slice type %d too large at %d\n",
1861 if (slice_type > 4) {
1882 if (!
h->ps.pps_list[sl->
pps_id]) {
1884 "non-existing PPS %u referenced\n",
1902 if (
sps->frame_mbs_only_flag) {
1906 av_log(
h->avctx,
AV_LOG_ERROR,
"This stream was generated by a broken encoder, invalid 8x8 inference\n");
1910 if (field_pic_flag) {
1930 if (idr_pic_id < 65536) {
1938 if (
sps->poc_type == 0) {
1941 if (
pps->pic_order_present == 1 && picture_structure ==
PICT_FRAME)
1946 if (
sps->poc_type == 1 && !
sps->delta_pic_order_always_zero_flag) {
1949 if (
pps->pic_order_present == 1 && picture_structure ==
PICT_FRAME)
1954 if (
pps->redundant_pic_cnt_present)
1962 picture_structure,
h->avctx);
1975 for (
i = 0;
i < 2;
i++) {
1980 (
pps->weighted_bipred_idc == 1 &&
1984 picture_structure,
h->avctx);
2007 if (
tmp > 51 + 6 * (
sps->bit_depth_luma - 8)) {
2024 if (
pps->deblocking_filter_parameters_present) {
2028 "deblocking_filter_idc %u out of range\n",
tmp);
2038 if (slice_alpha_c0_offset_div2 > 6 ||
2039 slice_alpha_c0_offset_div2 < -6 ||
2040 slice_beta_offset_div2 > 6 ||
2041 slice_beta_offset_div2 < -6) {
2043 "deblocking filter parameters %d %d out of range\n",
2044 slice_alpha_c0_offset_div2, slice_beta_offset_div2);
2084 if (
h->ps.pps->weighted_bipred_idc == 2 &&
2095 if (!
h->setup_finished)
2115 h->postpone_filter = 1;
2121 h->ps.pps->chroma_qp_index_offset[0],
2122 h->ps.pps->chroma_qp_index_offset[1]) +
2123 6 * (
h->ps.sps->bit_depth_luma - 8);
2136 for (j = 0; j < 2; j++) {
2139 for (
i = 0;
i < 16;
i++) {
2141 if (j < sl->list_count && i < sl->ref_count[j] &&
2145 for (k = 0; k <
h->short_ref_count; k++)
2146 if (
h->short_ref[k]->f->buf[0]->buffer == buf) {
2150 for (k = 0; k <
h->long_ref_count; k++)
2151 if (
h->long_ref[k] &&
h->long_ref[k]->f->buf[0]->buffer == buf) {
2152 id_list[
i] =
h->short_ref_count + k;
2160 for (
i = 0;
i < 16;
i++)
2163 ref2frm[18 + 1] = -1;
2164 for (
i = 16;
i < 48;
i++)
2165 ref2frm[
i + 4] = 4 * id_list[(
i - 16) >> 1] +
2171 "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",
2179 h->cur_pic_ptr->field_poc[0],
2180 h->cur_pic_ptr->field_poc[1],
2196 int first_slice = sl ==
h->slice_ctx && !
h->current_slice;
2212 if (
h->setup_finished) {
2219 if (
h->current_slice) {
2222 if (
h->nb_slice_ctx_queued) {
2229 memcpy(&tmp_ctx,
h->slice_ctx,
sizeof(tmp_ctx));
2230 memcpy(
h->slice_ctx, sl,
sizeof(tmp_ctx));
2231 memcpy(sl, &tmp_ctx,
sizeof(tmp_ctx));
2244 h->cur_pic_ptr =
NULL;
2251 if (!
h->first_field) {
2252 if (
h->cur_pic_ptr && !
h->droppable) {
2256 h->cur_pic_ptr =
NULL;
2260 if (!
h->current_slice)
2263 if (
h->current_slice == 0 && !
h->first_field) {
2277 if (
h->ps.pps->sps_id !=
pps->sps_id ||
2278 h->ps.pps->transform_8x8_mode !=
pps->transform_8x8_mode
2283 if (
h->ps.sps !=
pps->sps) {
2285 "SPS changed in the middle of the frame\n");
2290 if (
h->current_slice == 0) {
2296 h->droppable != (nal->
ref_idc == 0)) {
2298 "Changing field mode (%d -> %d) between slices is not allowed\n",
2301 }
else if (!
h->cur_pic_ptr) {
2303 "unset cur_pic_ptr on slice %d\n",
2304 h->current_slice + 1);
2313 h->nb_slice_ctx_queued++;
2338 int mb_type,
int top_xy,
2342 int mb_xy,
int list)
2344 int b_stride =
h->b_stride;
2349 const int b_xy =
h->mb2b_xy[top_xy] + 3 * b_stride;
2350 const int b8_xy = 4 * top_xy + 2;
2353 ref_cache[0 - 1 * 8] =
2354 ref_cache[1 - 1 * 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 0]];
2355 ref_cache[2 - 1 * 8] =
2356 ref_cache[3 - 1 * 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 1]];
2364 const int b_xy =
h->mb2b_xy[left_xy[
LTOP]] + 3;
2365 const int b8_xy = 4 * left_xy[
LTOP] + 1;
2367 AV_COPY32(mv_dst - 1 + 0,
h->cur_pic.motion_val[
list][b_xy + b_stride * 0]);
2368 AV_COPY32(mv_dst - 1 + 8,
h->cur_pic.motion_val[
list][b_xy + b_stride * 1]);
2369 AV_COPY32(mv_dst - 1 + 16,
h->cur_pic.motion_val[
list][b_xy + b_stride * 2]);
2370 AV_COPY32(mv_dst - 1 + 24,
h->cur_pic.motion_val[
list][b_xy + b_stride * 3]);
2372 ref_cache[-1 + 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 2 * 0]];
2373 ref_cache[-1 + 16] =
2374 ref_cache[-1 + 24] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 2 * 1]];
2382 ref_cache[-1 + 16] =
2398 int8_t *
ref = &
h->cur_pic.ref_index[
list][4 * mb_xy];
2400 uint32_t ref01 = (
pack16to32(ref2frm[
ref[0]], ref2frm[
ref[1]]) & 0x00FF00FF) * 0x0101;
2401 uint32_t ref23 = (
pack16to32(ref2frm[
ref[2]], ref2frm[
ref[3]]) & 0x00FF00FF) * 0x0101;
2402 AV_WN32A(&ref_cache[0 * 8], ref01);
2403 AV_WN32A(&ref_cache[1 * 8], ref01);
2404 AV_WN32A(&ref_cache[2 * 8], ref23);
2405 AV_WN32A(&ref_cache[3 * 8], ref23);
2409 int16_t(*mv_src)[2] = &
h->cur_pic.motion_val[
list][4 * sl->
mb_x + 4 * sl->
mb_y * b_stride];
2410 AV_COPY128(mv_dst + 8 * 0, mv_src + 0 * b_stride);
2411 AV_COPY128(mv_dst + 8 * 1, mv_src + 1 * b_stride);
2412 AV_COPY128(mv_dst + 8 * 2, mv_src + 2 * b_stride);
2413 AV_COPY128(mv_dst + 8 * 3, mv_src + 3 * b_stride);
2422 const int mb_xy = sl->
mb_xy;
2428 top_xy = mb_xy - (
h->mb_stride <<
MB_FIELD(sl));
2430 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy - 1;
2432 const int left_mb_field_flag =
IS_INTERLACED(
h->cur_pic.mb_type[mb_xy - 1]);
2435 if (left_mb_field_flag != curr_mb_field_flag)
2436 left_xy[
LTOP] -=
h->mb_stride;
2438 if (curr_mb_field_flag)
2439 top_xy +=
h->mb_stride &
2440 (((
h->cur_pic.mb_type[top_xy] >> 7) & 1) - 1);
2441 if (left_mb_field_flag != curr_mb_field_flag)
2442 left_xy[
LBOT] +=
h->mb_stride;
2454 int qp =
h->cur_pic.qscale_table[mb_xy];
2455 if (qp <= qp_thresh &&
2456 (left_xy[
LTOP] < 0 ||
2457 ((qp +
h->cur_pic.qscale_table[left_xy[
LTOP]] + 1) >> 1) <= qp_thresh) &&
2459 ((qp +
h->cur_pic.qscale_table[top_xy] + 1) >> 1) <= qp_thresh)) {
2462 if ((left_xy[
LTOP] < 0 ||
2463 ((qp +
h->cur_pic.qscale_table[left_xy[
LBOT]] + 1) >> 1) <= qp_thresh) &&
2464 (top_xy <
h->mb_stride ||
2465 ((qp +
h->cur_pic.qscale_table[top_xy -
h->mb_stride] + 1) >> 1) <= qp_thresh))
2470 top_type =
h->cur_pic.mb_type[top_xy];
2471 left_type[
LTOP] =
h->cur_pic.mb_type[left_xy[
LTOP]];
2472 left_type[
LBOT] =
h->cur_pic.mb_type[left_xy[
LBOT]];
2477 left_type[
LTOP] = left_type[
LBOT] = 0;
2479 if (
h->slice_table[top_xy] == 0xFFFF)
2481 if (
h->slice_table[left_xy[
LBOT]] == 0xFFFF)
2482 left_type[
LTOP] = left_type[
LBOT] = 0;
2492 top_type, left_type, mb_xy, 0);
2495 top_type, left_type, mb_xy, 1);
2497 nnz =
h->non_zero_count[mb_xy];
2499 AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]);
2500 AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]);
2501 AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]);
2502 AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]);
2503 sl->
cbp =
h->cbp_table[mb_xy];
2506 nnz =
h->non_zero_count[top_xy];
2507 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[3 * 4]);
2510 if (left_type[
LTOP]) {
2511 nnz =
h->non_zero_count[left_xy[
LTOP]];
2512 nnz_cache[3 + 8 * 1] = nnz[3 + 0 * 4];
2513 nnz_cache[3 + 8 * 2] = nnz[3 + 1 * 4];
2514 nnz_cache[3 + 8 * 3] = nnz[3 + 2 * 4];
2515 nnz_cache[3 + 8 * 4] = nnz[3 + 3 * 4];
2520 if (!
CABAC(
h) &&
h->ps.pps->transform_8x8_mode) {
2522 nnz_cache[4 + 8 * 0] =
2523 nnz_cache[5 + 8 * 0] = (
h->cbp_table[top_xy] & 0x4000) >> 12;
2524 nnz_cache[6 + 8 * 0] =
2525 nnz_cache[7 + 8 * 0] = (
h->cbp_table[top_xy] & 0x8000) >> 12;
2528 nnz_cache[3 + 8 * 1] =
2529 nnz_cache[3 + 8 * 2] = (
h->cbp_table[left_xy[
LTOP]] & 0x2000) >> 12;
2532 nnz_cache[3 + 8 * 3] =
2533 nnz_cache[3 + 8 * 4] = (
h->cbp_table[left_xy[
LBOT]] & 0x8000) >> 12;
2537 nnz_cache[
scan8[0]] =
2538 nnz_cache[
scan8[1]] =
2539 nnz_cache[
scan8[2]] =
2540 nnz_cache[
scan8[3]] = (sl->
cbp & 0x1000) >> 12;
2542 nnz_cache[
scan8[0 + 4]] =
2543 nnz_cache[
scan8[1 + 4]] =
2544 nnz_cache[
scan8[2 + 4]] =
2545 nnz_cache[
scan8[3 + 4]] = (sl->
cbp & 0x2000) >> 12;
2547 nnz_cache[
scan8[0 + 8]] =
2548 nnz_cache[
scan8[1 + 8]] =
2549 nnz_cache[
scan8[2 + 8]] =
2550 nnz_cache[
scan8[3 + 8]] = (sl->
cbp & 0x4000) >> 12;
2552 nnz_cache[
scan8[0 + 12]] =
2553 nnz_cache[
scan8[1 + 12]] =
2554 nnz_cache[
scan8[2 + 12]] =
2555 nnz_cache[
scan8[3 + 12]] = (sl->
cbp & 0x8000) >> 12;
2564 uint8_t *dest_y, *dest_cb, *dest_cr;
2565 int linesize, uvlinesize, mb_x, mb_y;
2568 const int pixel_shift =
h->pixel_shift;
2569 const int block_h = 16 >>
h->chroma_y_shift;
2571 if (
h->postpone_filter)
2575 for (mb_x = start_x; mb_x < end_x; mb_x++)
2576 for (mb_y = end_mb_y -
FRAME_MBAFF(
h); mb_y <= end_mb_y; mb_y++) {
2578 mb_xy = sl->
mb_xy = mb_x + mb_y *
h->mb_stride;
2579 mb_type =
h->cur_pic.mb_type[mb_xy];
2587 dest_y =
h->cur_pic.f->data[0] +
2588 ((mb_x << pixel_shift) + mb_y * sl->
linesize) * 16;
2589 dest_cb =
h->cur_pic.f->data[1] +
2590 (mb_x << pixel_shift) * (8 <<
CHROMA444(
h)) +
2592 dest_cr =
h->cur_pic.f->data[2] +
2593 (mb_x << pixel_shift) * (8 <<
CHROMA444(
h)) +
2618 linesize, uvlinesize);
2621 dest_cr, linesize, uvlinesize);
2634 const int mb_xy = sl->
mb_x + sl->
mb_y *
h->mb_stride;
2635 int mb_type = (
h->slice_table[mb_xy - 1] == sl->
slice_num) ?
2636 h->cur_pic.mb_type[mb_xy - 1] :
2637 (
h->slice_table[mb_xy -
h->mb_stride] == sl->
slice_num) ?
2638 h->cur_pic.mb_type[mb_xy -
h->mb_stride] : 0;
2653 if ((top +
height) >= pic_height)
2654 height += deblock_border;
2655 top -= deblock_border;
2658 if (top >= pic_height || (top +
height) < 0)
2677 int startx,
int starty,
2678 int endx,
int endy,
int status)
2683 if (CONFIG_ERROR_RESILIENCE) {
2694 int lf_x_start = sl->
mb_x;
2698 sl->
linesize =
h->cur_pic_ptr->f->linesize[0];
2709 if (
h->postpone_filter)
2715 if (!(
h->avctx->active_thread_type &
FF_THREAD_SLICE) &&
h->picture_structure ==
PICT_FRAME &&
h->slice_ctx[0].er.error_status_table) {
2718 int prev_status =
h->slice_ctx[0].er.error_status_table[
h->slice_ctx[0].er.mb_index2xy[start_i - 1]];
2721 h->slice_ctx[0].er.error_occurred = 1;
2725 if (
h->ps.pps->cabac) {
2769 if (sl->
mb_x >= lf_x_start)
2785 if (++sl->
mb_x >=
h->mb_width) {
2787 sl->
mb_x = lf_x_start = 0;
2797 if (eos || sl->
mb_y >=
h->mb_height) {
2798 ff_tlog(
h->avctx,
"slice end %d %d\n",
2802 if (sl->
mb_x > lf_x_start)
2836 "error while decoding MB %d %d\n", sl->
mb_x, sl->
mb_y);
2842 if (++sl->
mb_x >=
h->mb_width) {
2844 sl->
mb_x = lf_x_start = 0;
2852 if (sl->
mb_y >=
h->mb_height) {
2853 ff_tlog(
h->avctx,
"slice end %d %d\n",
2872 ff_tlog(
h->avctx,
"slice end %d %d\n",
2878 if (sl->
mb_x > lf_x_start)
2906 int context_count =
h->nb_slice_ctx_queued;
2910 h->slice_ctx[0].next_slice_idx = INT_MAX;
2912 if (
h->avctx->hwaccel || context_count < 1)
2915 av_assert0(context_count &&
h->slice_ctx[context_count - 1].mb_y <
h->mb_height);
2917 if (context_count == 1) {
2919 h->slice_ctx[0].next_slice_idx =
h->mb_width *
h->mb_height;
2920 h->postpone_filter = 0;
2923 h->mb_y =
h->slice_ctx[0].mb_y;
2928 for (
i = 0;
i < context_count;
i++) {
2929 int next_slice_idx =
h->mb_width *
h->mb_height;
2932 sl = &
h->slice_ctx[
i];
2933 if (CONFIG_ERROR_RESILIENCE) {
2938 slice_idx = sl->
mb_y *
h->mb_width + sl->
mb_x;
2939 for (j = 0; j < context_count; j++) {
2941 int slice_idx2 = sl2->
mb_y *
h->mb_width + sl2->
mb_x;
2943 if (
i == j || slice_idx2 < slice_idx)
2945 next_slice_idx =
FFMIN(next_slice_idx, slice_idx2);
2951 NULL, context_count,
sizeof(
h->slice_ctx[0]));
2954 sl = &
h->slice_ctx[context_count - 1];
2956 if (CONFIG_ERROR_RESILIENCE) {
2957 for (
i = 1;
i < context_count;
i++)
2958 h->slice_ctx[0].er.error_count +=
h->slice_ctx[
i].er.error_count;
2961 if (
h->postpone_filter) {
2962 h->postpone_filter = 0;
2964 for (
i = 0;
i < context_count;
i++) {
2967 sl = &
h->slice_ctx[
i];
2969 x_end = (sl->
mb_y >=
h->mb_height) ?
h->mb_width : sl->
mb_x;
2974 j == y_end - 1 ? x_end :
h->mb_width);
2981 h->nb_slice_ctx_queued = 0;