28 #include "config_components.h"
54 0 + 0 * 4, 0 + 1 * 4, 1 + 0 * 4, 0 + 2 * 4,
55 0 + 3 * 4, 1 + 1 * 4, 1 + 2 * 4, 1 + 3 * 4,
56 2 + 0 * 4, 2 + 1 * 4, 2 + 2 * 4, 2 + 3 * 4,
57 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4, 3 + 3 * 4,
61 0 + 0 * 8, 0 + 1 * 8, 0 + 2 * 8, 1 + 0 * 8,
62 1 + 1 * 8, 0 + 3 * 8, 0 + 4 * 8, 1 + 2 * 8,
63 2 + 0 * 8, 1 + 3 * 8, 0 + 5 * 8, 0 + 6 * 8,
64 0 + 7 * 8, 1 + 4 * 8, 2 + 1 * 8, 3 + 0 * 8,
65 2 + 2 * 8, 1 + 5 * 8, 1 + 6 * 8, 1 + 7 * 8,
66 2 + 3 * 8, 3 + 1 * 8, 4 + 0 * 8, 3 + 2 * 8,
67 2 + 4 * 8, 2 + 5 * 8, 2 + 6 * 8, 2 + 7 * 8,
68 3 + 3 * 8, 4 + 1 * 8, 5 + 0 * 8, 4 + 2 * 8,
69 3 + 4 * 8, 3 + 5 * 8, 3 + 6 * 8, 3 + 7 * 8,
70 4 + 3 * 8, 5 + 1 * 8, 6 + 0 * 8, 5 + 2 * 8,
71 4 + 4 * 8, 4 + 5 * 8, 4 + 6 * 8, 4 + 7 * 8,
72 5 + 3 * 8, 6 + 1 * 8, 6 + 2 * 8, 5 + 4 * 8,
73 5 + 5 * 8, 5 + 6 * 8, 5 + 7 * 8, 6 + 3 * 8,
74 7 + 0 * 8, 7 + 1 * 8, 6 + 4 * 8, 6 + 5 * 8,
75 6 + 6 * 8, 6 + 7 * 8, 7 + 2 * 8, 7 + 3 * 8,
76 7 + 4 * 8, 7 + 5 * 8, 7 + 6 * 8, 7 + 7 * 8,
80 0 + 0 * 8, 1 + 1 * 8, 2 + 0 * 8, 0 + 7 * 8,
81 2 + 2 * 8, 2 + 3 * 8, 2 + 4 * 8, 3 + 3 * 8,
82 3 + 4 * 8, 4 + 3 * 8, 4 + 4 * 8, 5 + 3 * 8,
83 5 + 5 * 8, 7 + 0 * 8, 6 + 6 * 8, 7 + 4 * 8,
84 0 + 1 * 8, 0 + 3 * 8, 1 + 3 * 8, 1 + 4 * 8,
85 1 + 5 * 8, 3 + 1 * 8, 2 + 5 * 8, 4 + 1 * 8,
86 3 + 5 * 8, 5 + 1 * 8, 4 + 5 * 8, 6 + 1 * 8,
87 5 + 6 * 8, 7 + 1 * 8, 6 + 7 * 8, 7 + 5 * 8,
88 0 + 2 * 8, 0 + 4 * 8, 0 + 5 * 8, 2 + 1 * 8,
89 1 + 6 * 8, 4 + 0 * 8, 2 + 6 * 8, 5 + 0 * 8,
90 3 + 6 * 8, 6 + 0 * 8, 4 + 6 * 8, 6 + 2 * 8,
91 5 + 7 * 8, 6 + 4 * 8, 7 + 2 * 8, 7 + 6 * 8,
92 1 + 0 * 8, 1 + 2 * 8, 0 + 6 * 8, 3 + 0 * 8,
93 1 + 7 * 8, 3 + 2 * 8, 2 + 7 * 8, 4 + 2 * 8,
94 3 + 7 * 8, 5 + 2 * 8, 4 + 7 * 8, 5 + 4 * 8,
95 6 + 3 * 8, 6 + 5 * 8, 7 + 3 * 8, 7 + 7 * 8,
100 0 + 0 * 8, 1 + 1 * 8, 1 + 2 * 8, 2 + 2 * 8,
101 4 + 1 * 8, 0 + 5 * 8, 3 + 3 * 8, 7 + 0 * 8,
102 3 + 4 * 8, 1 + 7 * 8, 5 + 3 * 8, 6 + 3 * 8,
103 2 + 7 * 8, 6 + 4 * 8, 5 + 6 * 8, 7 + 5 * 8,
104 1 + 0 * 8, 2 + 0 * 8, 0 + 3 * 8, 3 + 1 * 8,
105 3 + 2 * 8, 0 + 6 * 8, 4 + 2 * 8, 6 + 1 * 8,
106 2 + 5 * 8, 2 + 6 * 8, 6 + 2 * 8, 5 + 4 * 8,
107 3 + 7 * 8, 7 + 3 * 8, 4 + 7 * 8, 7 + 6 * 8,
108 0 + 1 * 8, 3 + 0 * 8, 0 + 4 * 8, 4 + 0 * 8,
109 2 + 3 * 8, 1 + 5 * 8, 5 + 1 * 8, 5 + 2 * 8,
110 1 + 6 * 8, 3 + 5 * 8, 7 + 1 * 8, 4 + 5 * 8,
111 4 + 6 * 8, 7 + 4 * 8, 5 + 7 * 8, 6 + 7 * 8,
112 0 + 2 * 8, 2 + 1 * 8, 1 + 3 * 8, 5 + 0 * 8,
113 1 + 4 * 8, 2 + 4 * 8, 6 + 0 * 8, 4 + 3 * 8,
114 0 + 7 * 8, 4 + 4 * 8, 7 + 2 * 8, 3 + 6 * 8,
115 5 + 5 * 8, 6 + 5 * 8, 6 + 6 * 8, 7 + 7 * 8,
124 if (
h->DPB[
i].f->buf[0] && !
h->DPB[
i].reference &&
125 (remove_current || &
h->DPB[
i] !=
h->cur_pic_ptr)) {
142 h->mb_width * 16 * 3 *
sizeof(uint8_t) * 2);
144 h->mb_width * 16 * 3 *
sizeof(uint8_t) * 2);
165 const int big_mb_num =
h->mb_stride * (
h->mb_height + 1) + 1;
166 const int mb_array_size =
h->mb_stride *
h->mb_height;
167 const int b4_stride =
h->mb_width * 4 + 1;
168 const int b4_array_size = b4_stride *
h->mb_height * 4;
178 if (!
h->qscale_table_pool || !
h->mb_type_pool || !
h->motion_val_pool ||
179 !
h->ref_index_pool) {
211 if (
h->avctx->hwaccel) {
222 int h_chroma_shift, v_chroma_shift;
224 &h_chroma_shift, &v_chroma_shift);
234 if (!
h->qscale_table_pool) {
278 if (!
h->DPB[
i].f->buf[0])
285 #define IN_RANGE(a, b, size) (((void*)(a) >= (void*)(b)) && ((void*)(a) < (void*)((b) + (size))))
287 #define REBASE_PICTURE(pic, new_ctx, old_ctx) \
288 (((pic) && (pic) >= (old_ctx)->DPB && \
289 (pic) < (old_ctx)->DPB + H264_MAX_PICTURE_COUNT) ? \
290 &(new_ctx)->DPB[(pic) - (old_ctx)->DPB] : NULL)
298 for (
i = 0;
i < count;
i++) {
312 int inited =
h->context_initialized, err = 0;
319 if (inited && !h1->ps.sps)
323 (
h->width != h1->width ||
324 h->height != h1->height ||
325 h->mb_width != h1->mb_width ||
326 h->mb_height != h1->mb_height ||
328 h->ps.sps->bit_depth_luma != h1->ps.sps->bit_depth_luma ||
329 h->ps.sps->chroma_format_idc != h1->ps.sps->chroma_format_idc ||
330 h->ps.sps->colorspace != h1->ps.sps->colorspace)) {
335 memcpy(
h->block_offset, h1->block_offset,
sizeof(
h->block_offset));
354 if (h1->ps.pps_ref) {
355 h->ps.pps = (
const PPS*)
h->ps.pps_ref->data;
356 h->ps.sps =
h->ps.pps->sps;
359 if (need_reinit || !inited) {
360 h->width = h1->width;
361 h->height = h1->height;
362 h->mb_height = h1->mb_height;
363 h->mb_width = h1->mb_width;
364 h->mb_num = h1->mb_num;
365 h->mb_stride = h1->mb_stride;
366 h->b_stride = h1->b_stride;
367 h->x264_build = h1->x264_build;
369 if (
h->context_initialized || h1->context_initialized) {
377 memcpy(
h->block_offset, h1->block_offset,
sizeof(
h->block_offset));
380 h->avctx->coded_height = h1->avctx->coded_height;
381 h->avctx->coded_width = h1->avctx->coded_width;
382 h->avctx->width = h1->avctx->width;
383 h->avctx->height = h1->avctx->height;
384 h->width_from_caller = h1->width_from_caller;
385 h->height_from_caller = h1->height_from_caller;
386 h->coded_picture_number = h1->coded_picture_number;
387 h->first_field = h1->first_field;
388 h->picture_structure = h1->picture_structure;
389 h->mb_aff_frame = h1->mb_aff_frame;
390 h->droppable = h1->droppable;
403 h->enable_er = h1->enable_er;
404 h->workaround_bugs = h1->workaround_bugs;
405 h->droppable = h1->droppable;
408 h->is_avc = h1->is_avc;
409 h->nal_length_size = h1->nal_length_size;
411 memcpy(&
h->poc, &h1->poc,
sizeof(
h->poc));
413 memcpy(
h->short_ref, h1->short_ref,
sizeof(
h->short_ref));
414 memcpy(
h->long_ref, h1->long_ref,
sizeof(
h->long_ref));
415 memcpy(
h->delayed_pic, h1->delayed_pic,
sizeof(
h->delayed_pic));
416 memcpy(
h->last_pocs, h1->last_pocs,
sizeof(
h->last_pocs));
418 h->next_output_pic = h1->next_output_pic;
419 h->next_outputed_poc = h1->next_outputed_poc;
420 h->poc_offset = h1->poc_offset;
422 memcpy(
h->mmco, h1->mmco,
sizeof(
h->mmco));
423 h->nb_mmco = h1->nb_mmco;
424 h->mmco_reset = h1->mmco_reset;
425 h->explicit_ref_marking = h1->explicit_ref_marking;
426 h->long_ref_count = h1->long_ref_count;
427 h->short_ref_count = h1->short_ref_count;
434 h->frame_recovered = h1->frame_recovered;
440 for (
i = 0;
i <
h->sei.unregistered.nb_buf_ref;
i++)
442 h->sei.unregistered.nb_buf_ref = 0;
444 if (h1->sei.unregistered.nb_buf_ref) {
446 h1->sei.unregistered.nb_buf_ref,
447 sizeof(*
h->sei.unregistered.buf_ref));
451 for (
i = 0;
i < h1->sei.unregistered.nb_buf_ref;
i++) {
452 h->sei.unregistered.buf_ref[
i] =
av_buffer_ref(h1->sei.unregistered.buf_ref[
i]);
453 if (!
h->sei.unregistered.buf_ref[
i])
455 h->sei.unregistered.nb_buf_ref++;
458 h->sei.unregistered.x264_build = h1->sei.unregistered.x264_build;
465 h->poc.prev_poc_msb =
h->poc.poc_msb;
466 h->poc.prev_poc_lsb =
h->poc.poc_lsb;
468 h->poc.prev_frame_num_offset =
h->poc.frame_num_offset;
469 h->poc.prev_frame_num =
h->poc.frame_num;
471 h->recovery_frame = h1->recovery_frame;
492 const int pixel_shift =
h->pixel_shift;
500 h->cur_pic_ptr =
NULL;
509 pic->
reference =
h->droppable ? 0 :
h->picture_structure;
531 pic->
needs_fg =
h->sei.film_grain_characteristics.present && !
h->avctx->hwaccel &&
537 h->cur_pic_ptr = pic;
539 if (CONFIG_ERROR_RESILIENCE) {
546 for (
i = 0;
i <
h->nb_slice_ctx;
i++) {
547 h->slice_ctx[
i].linesize =
h->cur_pic_ptr->f->linesize[0];
548 h->slice_ctx[
i].uvlinesize =
h->cur_pic_ptr->f->linesize[1];
551 if (CONFIG_ERROR_RESILIENCE &&
h->enable_er) {
557 for (
i = 0;
i < 16;
i++) {
561 for (
i = 0;
i < 16;
i++) {
562 h->block_offset[16 +
i] =
564 h->block_offset[48 + 16 +
i] =
572 h->cur_pic_ptr->reference = 0;
574 h->cur_pic_ptr->field_poc[0] =
h->cur_pic_ptr->field_poc[1] = INT_MAX;
576 h->next_output_pic =
NULL;
578 h->postpone_filter = 0;
580 h->mb_aff_frame =
h->ps.sps->mb_aff && (
h->picture_structure ==
PICT_FRAME);
582 if (
h->sei.unregistered.x264_build >= 0)
583 h->x264_build =
h->sei.unregistered.x264_build;
585 assert(
h->cur_pic_ptr->long_ref == 0);
592 uint8_t *src_cb, uint8_t *src_cr,
593 int linesize,
int uvlinesize,
598 const int pixel_shift =
h->pixel_shift;
603 src_cb -= uvlinesize;
604 src_cr -= uvlinesize;
610 AV_COPY128(top_border, src_y + 15 * linesize);
612 AV_COPY128(top_border + 16, src_y + 15 * linesize + 16);
616 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
617 AV_COPY128(top_border + 48, src_cb + 15 * uvlinesize + 16);
618 AV_COPY128(top_border + 64, src_cr + 15 * uvlinesize);
619 AV_COPY128(top_border + 80, src_cr + 15 * uvlinesize + 16);
621 AV_COPY128(top_border + 16, src_cb + 15 * uvlinesize);
622 AV_COPY128(top_border + 32, src_cr + 15 * uvlinesize);
624 }
else if (chroma422) {
626 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
627 AV_COPY128(top_border + 48, src_cr + 15 * uvlinesize);
629 AV_COPY64(top_border + 16, src_cb + 15 * uvlinesize);
630 AV_COPY64(top_border + 24, src_cr + 15 * uvlinesize);
634 AV_COPY128(top_border + 32, src_cb + 7 * uvlinesize);
635 AV_COPY128(top_border + 48, src_cr + 7 * uvlinesize);
637 AV_COPY64(top_border + 16, src_cb + 7 * uvlinesize);
638 AV_COPY64(top_border + 24, src_cr + 7 * uvlinesize);
652 AV_COPY128(top_border, src_y + 16 * linesize);
654 AV_COPY128(top_border + 16, src_y + 16 * linesize + 16);
659 AV_COPY128(top_border + 32, src_cb + 16 * linesize);
660 AV_COPY128(top_border + 48, src_cb + 16 * linesize + 16);
661 AV_COPY128(top_border + 64, src_cr + 16 * linesize);
662 AV_COPY128(top_border + 80, src_cr + 16 * linesize + 16);
664 AV_COPY128(top_border + 16, src_cb + 16 * linesize);
665 AV_COPY128(top_border + 32, src_cr + 16 * linesize);
667 }
else if (chroma422) {
669 AV_COPY128(top_border + 32, src_cb + 16 * uvlinesize);
670 AV_COPY128(top_border + 48, src_cr + 16 * uvlinesize);
672 AV_COPY64(top_border + 16, src_cb + 16 * uvlinesize);
673 AV_COPY64(top_border + 24, src_cr + 16 * uvlinesize);
677 AV_COPY128(top_border + 32, src_cb + 8 * uvlinesize);
678 AV_COPY128(top_border + 48, src_cr + 8 * uvlinesize);
680 AV_COPY64(top_border + 16, src_cb + 8 * uvlinesize);
681 AV_COPY64(top_border + 24, src_cr + 8 * uvlinesize);
694 int ref0, ref1,
i, cur_poc, ref_start, ref_count0, ref_count1;
696 for (
i = 0;
i < 2;
i++) {
703 cur_poc =
h->cur_pic_ptr->poc;
705 cur_poc =
h->cur_pic_ptr->field_poc[
h->picture_structure - 1];
717 cur_poc =
h->cur_pic_ptr->field_poc[
field];
728 for (ref0 = ref_start; ref0 < ref_count0; ref0++) {
730 for (ref1 = ref_start; ref1 < ref_count1; ref1++) {
737 int tx = (16384 + (
FFABS(
td) >> 1)) /
td;
738 int dist_scale_factor = (
tb * tx + 32) >> 8;
739 if (dist_scale_factor >= -64 && dist_scale_factor <= 128)
740 w = 64 - dist_scale_factor;
759 for (
i = 0;
i < 16;
i++) {
760 #define TRANSPOSE(x) ((x) >> 2) | (((x) << 2) & 0xF)
765 for (
i = 0;
i < 64;
i++) {
766 #define TRANSPOSE(x) ((x) >> 3) | (((x) & 7) << 3)
773 if (
h->ps.sps->transform_bypass) {
777 memcpy(
h->field_scan_q0 ,
field_scan ,
sizeof(
h->field_scan_q0 ));
778 memcpy(
h->field_scan8x8_q0 ,
field_scan8x8 ,
sizeof(
h->field_scan8x8_q0 ));
781 memcpy(
h->zigzag_scan_q0 ,
h->zigzag_scan ,
sizeof(
h->zigzag_scan_q0 ));
782 memcpy(
h->zigzag_scan8x8_q0 ,
h->zigzag_scan8x8 ,
sizeof(
h->zigzag_scan8x8_q0 ));
783 memcpy(
h->zigzag_scan8x8_cavlc_q0 ,
h->zigzag_scan8x8_cavlc ,
sizeof(
h->zigzag_scan8x8_cavlc_q0));
784 memcpy(
h->field_scan_q0 ,
h->field_scan ,
sizeof(
h->field_scan_q0 ));
785 memcpy(
h->field_scan8x8_q0 ,
h->field_scan8x8 ,
sizeof(
h->field_scan8x8_q0 ));
786 memcpy(
h->field_scan8x8_cavlc_q0 ,
h->field_scan8x8_cavlc ,
sizeof(
h->field_scan8x8_cavlc_q0 ));
792 #define HWACCEL_MAX (CONFIG_H264_DXVA2_HWACCEL + \
793 (CONFIG_H264_D3D11VA_HWACCEL * 2) + \
794 CONFIG_H264_NVDEC_HWACCEL + \
795 CONFIG_H264_VAAPI_HWACCEL + \
796 CONFIG_H264_VIDEOTOOLBOX_HWACCEL + \
797 CONFIG_H264_VDPAU_HWACCEL)
802 switch (
h->ps.sps->bit_depth_luma) {
815 #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL
852 #if CONFIG_H264_VDPAU_HWACCEL
855 #if CONFIG_H264_NVDEC_HWACCEL
858 #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL
875 #if CONFIG_H264_DXVA2_HWACCEL
878 #if CONFIG_H264_D3D11VA_HWACCEL
882 #if CONFIG_H264_VAAPI_HWACCEL
885 if (
h->avctx->codec->pix_fmts)
886 choices =
h->avctx->codec->pix_fmts;
895 "Unsupported bit depth %d\n",
h->ps.sps->bit_depth_luma);
902 if (choices[
i] ==
h->avctx->pix_fmt && !force_callback)
911 int cr =
sps->crop_right;
912 int cl =
sps->crop_left;
913 int ct =
sps->crop_top;
914 int cb =
sps->crop_bottom;
921 if (
h->width_from_caller > 0 &&
h->height_from_caller > 0 &&
922 !
sps->crop_top && !
sps->crop_left &&
925 h->width_from_caller <=
width &&
926 h->height_from_caller <=
height) {
927 width =
h->width_from_caller;
928 height =
h->height_from_caller;
934 h->width_from_caller = 0;
935 h->height_from_caller = 0;
938 h->avctx->coded_width =
h->width;
939 h->avctx->coded_height =
h->height;
960 &
h->chroma_x_shift, &
h->chroma_y_shift);
962 if (
sps->timing_info_present_flag) {
963 int64_t den =
sps->time_scale;
964 if (
h->x264_build < 44
U)
966 av_reduce(&
h->avctx->framerate.den, &
h->avctx->framerate.num,
967 sps->num_units_in_tick *
h->avctx->ticks_per_frame, den, 1 << 30);
973 h->prev_interlaced_frame = 1;
982 if (
sps->bit_depth_luma < 8 ||
sps->bit_depth_luma > 14 ||
983 sps->bit_depth_luma == 11 ||
sps->bit_depth_luma == 13
986 sps->bit_depth_luma);
991 h->cur_bit_depth_luma =
992 h->avctx->bits_per_raw_sample =
sps->bit_depth_luma;
993 h->cur_chroma_format_idc =
sps->chroma_format_idc;
994 h->pixel_shift =
sps->bit_depth_luma > 8;
995 h->chroma_format_idc =
sps->chroma_format_idc;
996 h->bit_depth_luma =
sps->bit_depth_luma;
999 sps->chroma_format_idc);
1003 sps->chroma_format_idc);
1009 for (
i = 0;
i <
h->nb_slice_ctx;
i++) {
1014 sl->
mvd_table[0] =
h->mvd_table[0] +
i * 8 * 2 *
h->mb_stride;
1015 sl->
mvd_table[1] =
h->mvd_table[1] +
i * 8 * 2 *
h->mb_stride;
1021 h->context_initialized = 1;
1026 h->context_initialized = 0;
1044 int needs_reinit = 0, must_reinit,
ret;
1052 h->ps.pps = (
const PPS*)
h->ps.pps_ref->data;
1055 if (
h->ps.sps !=
h->ps.pps->sps) {
1056 h->ps.sps = (
const SPS*)
h->ps.pps->sps;
1058 if (
h->mb_width !=
h->ps.sps->mb_width ||
1059 h->mb_height !=
h->ps.sps->mb_height ||
1060 h->cur_bit_depth_luma !=
h->ps.sps->bit_depth_luma ||
1061 h->cur_chroma_format_idc !=
h->ps.sps->chroma_format_idc
1065 if (
h->bit_depth_luma !=
h->ps.sps->bit_depth_luma ||
1066 h->chroma_format_idc !=
h->ps.sps->chroma_format_idc)
1071 must_reinit = (
h->context_initialized &&
1072 ( 16*
sps->mb_width !=
h->avctx->coded_width
1073 || 16*
sps->mb_height !=
h->avctx->coded_height
1074 ||
h->cur_bit_depth_luma !=
sps->bit_depth_luma
1075 ||
h->cur_chroma_format_idc !=
sps->chroma_format_idc
1076 ||
h->mb_width !=
sps->mb_width
1077 ||
h->mb_height !=
sps->mb_height
1083 if (first_slice &&
av_cmp_q(
sps->sar,
h->avctx->sample_aspect_ratio))
1086 if (!
h->setup_finished) {
1088 h->avctx->level =
sps->level_idc;
1089 h->avctx->refs =
sps->ref_frame_count;
1091 h->mb_width =
sps->mb_width;
1092 h->mb_height =
sps->mb_height;
1093 h->mb_num =
h->mb_width *
h->mb_height;
1094 h->mb_stride =
h->mb_width + 1;
1096 h->b_stride =
h->mb_width * 4;
1098 h->chroma_y_shift =
sps->chroma_format_idc <= 1;
1100 h->width = 16 *
h->mb_width;
1101 h->height = 16 *
h->mb_height;
1105 if (
sps->video_signal_type_present_flag) {
1108 if (
sps->colour_description_present_flag) {
1109 if (
h->avctx->colorspace !=
sps->colorspace)
1111 h->avctx->color_primaries =
sps->color_primaries;
1112 h->avctx->color_trc =
sps->color_trc;
1113 h->avctx->colorspace =
sps->colorspace;
1117 if (
h->sei.alternative_transfer.present &&
1120 h->avctx->color_trc =
h->sei.alternative_transfer.preferred_transfer_characteristics;
1123 h->avctx->chroma_sample_location =
sps->chroma_location;
1125 if (!
h->context_initialized || must_reinit || needs_reinit) {
1126 int flush_changes =
h->context_initialized;
1127 h->context_initialized = 0;
1128 if (sl !=
h->slice_ctx) {
1130 "changing width %d -> %d / height %d -> %d on "
1132 h->width,
h->avctx->coded_width,
1133 h->height,
h->avctx->coded_height,
1134 h->current_slice + 1);
1145 h->avctx->pix_fmt =
ret;
1152 "h264_slice_header_init() failed\n");
1166 out->interlaced_frame = 0;
1167 out->repeat_pict = 0;
1172 if (
h->sei.picture_timing.present) {
1179 h->sei.picture_timing.present = 0;
1183 if (
sps->pic_struct_present_flag &&
h->sei.picture_timing.present) {
1185 switch (
pt->pic_struct) {
1190 out->interlaced_frame = 1;
1195 out->interlaced_frame = 1;
1198 out->interlaced_frame =
h->prev_interlaced_frame;
1205 out->repeat_pict = 1;
1208 out->repeat_pict = 2;
1211 out->repeat_pict = 4;
1215 if ((
pt->ct_type & 3) &&
1217 out->interlaced_frame = (
pt->ct_type & (1 << 1)) != 0;
1222 h->prev_interlaced_frame =
out->interlaced_frame;
1228 if (
sps->pic_struct_present_flag &&
h->sei.picture_timing.present) {
1233 out->top_field_first = 1;
1235 out->top_field_first = 0;
1236 }
else if (
out->interlaced_frame) {
1239 out->top_field_first = 1;
1242 out->top_field_first = 0;
1246 if (
h->sei.frame_packing.present &&
1247 h->sei.frame_packing.arrangement_type <= 6 &&
1248 h->sei.frame_packing.content_interpretation_type > 0 &&
1249 h->sei.frame_packing.content_interpretation_type < 3) {
1253 switch (
fp->arrangement_type) {
1264 if (
fp->quincunx_sampling_flag)
1280 if (
fp->content_interpretation_type == 2)
1284 if (
fp->current_frame_is_frame0_flag)
1292 if (
h->sei.display_orientation.present &&
1293 (
h->sei.display_orientation.anticlockwise_rotation ||
1294 h->sei.display_orientation.hflip ||
1295 h->sei.display_orientation.vflip)) {
1310 angle = -angle * (1 - 2 * !!o->
hflip) * (1 - 2 * !!o->
vflip);
1317 if (
h->sei.afd.present) {
1322 *sd->
data =
h->sei.afd.active_format_description;
1323 h->sei.afd.present = 0;
1327 if (
h->sei.a53_caption.buf_ref) {
1338 for (
int i = 0;
i <
h->sei.unregistered.nb_buf_ref;
i++) {
1350 h->sei.unregistered.nb_buf_ref = 0;
1352 if (
h->sei.film_grain_characteristics.present) {
1359 fgp->
seed = cur->
poc + (
h->poc_offset << 5);
1372 if (
sps->video_signal_type_present_flag)
1376 if (
sps->colour_description_present_flag) {
1407 if (
h->sei.picture_timing.timecode_cnt > 0) {
1413 sizeof(uint32_t)*4);
1417 tc_sd = (uint32_t*)tcside->
data;
1418 tc_sd[0] =
h->sei.picture_timing.timecode_cnt;
1420 for (
int i = 0;
i < tc_sd[0];
i++) {
1421 int drop =
h->sei.picture_timing.timecode[
i].dropframe;
1422 int hh =
h->sei.picture_timing.timecode[
i].hours;
1423 int mm =
h->sei.picture_timing.timecode[
i].minutes;
1424 int ss =
h->sei.picture_timing.timecode[
i].seconds;
1425 int ff =
h->sei.picture_timing.timecode[
i].frame;
1431 h->sei.picture_timing.timecode_cnt = 0;
1442 int i, pics, out_of_order, out_idx;
1447 if (
sps->bitstream_restriction_flag ||
1449 h->avctx->has_b_frames =
FFMAX(
h->avctx->has_b_frames,
sps->num_reorder_frames);
1452 for (
i = 0; 1;
i++) {
1455 h->last_pocs[
i-1] = cur->
poc;
1458 h->last_pocs[
i-1]=
h->last_pocs[
i];
1464 out_of_order =
FFMAX(out_of_order, 1);
1468 h->last_pocs[
i] = INT_MIN;
1469 h->last_pocs[0] = cur->
poc;
1471 }
else if(
h->avctx->has_b_frames < out_of_order && !
sps->bitstream_restriction_flag){
1473 av_log(
h->avctx, loglevel,
"Increasing reorder buffer to %d\n", out_of_order);
1474 h->avctx->has_b_frames = out_of_order;
1478 while (
h->delayed_pic[pics])
1483 h->delayed_pic[pics++] = cur;
1487 out =
h->delayed_pic[0];
1489 for (
i = 1;
h->delayed_pic[
i] &&
1490 !
h->delayed_pic[
i]->f->key_frame &&
1491 !
h->delayed_pic[
i]->mmco_reset;
1493 if (
h->delayed_pic[
i]->poc <
out->poc) {
1494 out =
h->delayed_pic[
i];
1497 if (
h->avctx->has_b_frames == 0 &&
1498 (
h->delayed_pic[0]->f->key_frame ||
h->delayed_pic[0]->mmco_reset))
1499 h->next_outputed_poc = INT_MIN;
1500 out_of_order =
out->poc <
h->next_outputed_poc;
1502 if (out_of_order || pics >
h->avctx->has_b_frames) {
1504 for (
i = out_idx;
h->delayed_pic[
i];
i++)
1505 h->delayed_pic[
i] =
h->delayed_pic[
i + 1];
1507 if (!out_of_order && pics >
h->avctx->has_b_frames) {
1508 h->next_output_pic =
out;
1509 if (out_idx == 0 &&
h->delayed_pic[0] && (
h->delayed_pic[0]->f->key_frame ||
h->delayed_pic[0]->mmco_reset)) {
1510 h->next_outputed_poc = INT_MIN;
1512 h->next_outputed_poc =
out->poc;
1514 if (
out->recovered) {
1521 if (!
out->recovered) {
1524 h->next_output_pic =
NULL;
1541 const H2645NAL *nal,
int first_slice)
1546 int last_pic_structure, last_pic_droppable,
ret;
1554 if (
sps &&
sps->bitstream_restriction_flag &&
1555 h->avctx->has_b_frames <
sps->num_reorder_frames) {
1556 h->avctx->has_b_frames =
sps->num_reorder_frames;
1559 last_pic_droppable =
h->droppable;
1560 last_pic_structure =
h->picture_structure;
1561 h->droppable = (nal->
ref_idc == 0);
1572 else if (
h->picture_intra_only)
1577 if (
h->poc.frame_num !=
h->poc.prev_frame_num) {
1578 int unwrap_prev_frame_num =
h->poc.prev_frame_num;
1579 int max_frame_num = 1 <<
sps->log2_max_frame_num;
1581 if (unwrap_prev_frame_num >
h->poc.frame_num)
1582 unwrap_prev_frame_num -= max_frame_num;
1584 if ((
h->poc.frame_num - unwrap_prev_frame_num) >
sps->ref_frame_count) {
1585 unwrap_prev_frame_num = (
h->poc.frame_num -
sps->ref_frame_count) - 1;
1586 if (unwrap_prev_frame_num < 0)
1587 unwrap_prev_frame_num += max_frame_num;
1589 h->poc.prev_frame_num = unwrap_prev_frame_num;
1598 if (
h->first_field) {
1605 if (
h->cur_pic_ptr->tf.owner[last_field] ==
h->avctx) {
1610 if (!
FIELD_PICTURE(
h) ||
h->picture_structure == last_pic_structure) {
1618 if (
h->cur_pic_ptr->frame_num !=
h->poc.frame_num) {
1634 "Invalid field mode combination %d/%d\n",
1635 last_pic_structure,
h->picture_structure);
1636 h->picture_structure = last_pic_structure;
1637 h->droppable = last_pic_droppable;
1639 }
else if (last_pic_droppable !=
h->droppable) {
1641 "Found reference and non-reference fields in the same frame, which");
1642 h->picture_structure = last_pic_structure;
1643 h->droppable = last_pic_droppable;
1650 while (
h->poc.frame_num !=
h->poc.prev_frame_num && !
h->first_field &&
1651 h->poc.frame_num != (
h->poc.prev_frame_num + 1) % (1 <<
sps->log2_max_frame_num)) {
1654 h->poc.frame_num,
h->poc.prev_frame_num);
1655 if (!
sps->gaps_in_frame_num_allowed_flag)
1657 h->last_pocs[
i] = INT_MIN;
1664 h->poc.prev_frame_num++;
1665 h->poc.prev_frame_num %= 1 <<
sps->log2_max_frame_num;
1666 h->cur_pic_ptr->frame_num =
h->poc.prev_frame_num;
1667 h->cur_pic_ptr->invalid_gap = !
sps->gaps_in_frame_num_allowed_flag;
1671 h->explicit_ref_marking = 0;
1682 if (
h->short_ref_count) {
1684 1<<(
h->ps.sps->bit_depth_luma-1),
1685 1<<(
h->ps.sps->bit_depth_chroma-1),
1686 1<<(
h->ps.sps->bit_depth_chroma-1),
1691 h->short_ref[0]->f->width == prev->
f->
width &&
1692 h->short_ref[0]->f->height == prev->
f->
height &&
1693 h->short_ref[0]->f->format == prev->
f->
format) {
1698 h->short_ref[0]->tf.f =
h->short_ref[0]->f;
1702 h->short_ref[0]->poc = prev->
poc + 2
U;
1704 if (
h->short_ref[0]->field_picture)
1706 }
else if (!
h->frame_recovered && !
h->avctx->hwaccel)
1708 h->short_ref[0]->frame_num =
h->poc.prev_frame_num;
1715 if (
h->first_field) {
1721 if (!
FIELD_PICTURE(
h) ||
h->picture_structure == last_pic_structure) {
1724 h->missing_fields ++;
1725 h->cur_pic_ptr =
NULL;
1728 h->missing_fields = 0;
1729 if (
h->cur_pic_ptr->frame_num !=
h->poc.frame_num) {
1736 h->cur_pic_ptr =
NULL;
1742 h->cur_pic_ptr =
NULL;
1761 h->cur_pic_ptr->tf.owner[
field] =
h->avctx;
1767 memset(
h->slice_table +
i*
h->mb_stride, -1, (
h->mb_stride - (
i+1==
h->mb_height)) *
sizeof(*
h->slice_table));
1769 memset(
h->slice_table, -1,
1770 (
h->mb_height *
h->mb_stride - 1) *
sizeof(*
h->slice_table));
1774 h->ps.sps, &
h->poc,
h->picture_structure, nal->
ref_idc);
1784 if (
h->sei.recovery_point.recovery_frame_cnt >= 0) {
1785 const int sei_recovery_frame_cnt =
h->sei.recovery_point.recovery_frame_cnt;
1788 h->valid_recovery_point = 1;
1790 if (
h->recovery_frame < 0
1791 ||
av_mod_uintp2(
h->recovery_frame -
h->poc.frame_num,
h->ps.sps->log2_max_frame_num) > sei_recovery_frame_cnt) {
1792 h->recovery_frame =
av_mod_uintp2(
h->poc.frame_num + sei_recovery_frame_cnt,
h->ps.sps->log2_max_frame_num);
1794 if (!
h->valid_recovery_point)
1795 h->recovery_frame =
h->poc.frame_num;
1802 (
h->recovery_frame ==
h->poc.frame_num && nal->
ref_idc)) {
1803 h->recovery_frame = -1;
1804 h->cur_pic_ptr->recovered = 1;
1811 h->cur_pic_ptr->recovered |=
h->frame_recovered;
1838 unsigned int slice_type,
tmp,
i;
1839 int field_pic_flag, bottom_field_flag;
1840 int first_slice = sl ==
h->slice_ctx && !
h->current_slice;
1841 int picture_structure;
1849 if (slice_type > 9) {
1851 "slice type %d too large at %d\n",
1855 if (slice_type > 4) {
1876 if (!
h->ps.pps_list[sl->
pps_id]) {
1878 "non-existing PPS %u referenced\n",
1896 if (
sps->frame_mbs_only_flag) {
1900 av_log(
h->avctx,
AV_LOG_ERROR,
"This stream was generated by a broken encoder, invalid 8x8 inference\n");
1904 if (field_pic_flag) {
1924 if (idr_pic_id < 65536) {
1932 if (
sps->poc_type == 0) {
1935 if (
pps->pic_order_present == 1 && picture_structure ==
PICT_FRAME)
1940 if (
sps->poc_type == 1 && !
sps->delta_pic_order_always_zero_flag) {
1943 if (
pps->pic_order_present == 1 && picture_structure ==
PICT_FRAME)
1948 if (
pps->redundant_pic_cnt_present)
1956 picture_structure,
h->avctx);
1969 for (
i = 0;
i < 2;
i++) {
1974 (
pps->weighted_bipred_idc == 1 &&
1978 picture_structure,
h->avctx);
2001 if (
tmp > 51 + 6 * (
sps->bit_depth_luma - 8)) {
2018 if (
pps->deblocking_filter_parameters_present) {
2022 "deblocking_filter_idc %u out of range\n",
tmp);
2032 if (slice_alpha_c0_offset_div2 > 6 ||
2033 slice_alpha_c0_offset_div2 < -6 ||
2034 slice_beta_offset_div2 > 6 ||
2035 slice_beta_offset_div2 < -6) {
2037 "deblocking filter parameters %d %d out of range\n",
2038 slice_alpha_c0_offset_div2, slice_beta_offset_div2);
2078 if (
h->ps.pps->weighted_bipred_idc == 2 &&
2089 if (!
h->setup_finished)
2109 h->postpone_filter = 1;
2115 h->ps.pps->chroma_qp_index_offset[0],
2116 h->ps.pps->chroma_qp_index_offset[1]) +
2117 6 * (
h->ps.sps->bit_depth_luma - 8);
2130 for (j = 0; j < 2; j++) {
2133 for (
i = 0;
i < 16;
i++) {
2135 if (j < sl->list_count && i < sl->ref_count[j] &&
2139 for (k = 0; k <
h->short_ref_count; k++)
2140 if (
h->short_ref[k]->f->buf[0]->buffer == buf) {
2144 for (k = 0; k <
h->long_ref_count; k++)
2145 if (
h->long_ref[k] &&
h->long_ref[k]->f->buf[0]->buffer == buf) {
2146 id_list[
i] =
h->short_ref_count + k;
2154 for (
i = 0;
i < 16;
i++)
2157 ref2frm[18 + 1] = -1;
2158 for (
i = 16;
i < 48;
i++)
2159 ref2frm[
i + 4] = 4 * id_list[(
i - 16) >> 1] +
2165 "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",
2173 h->cur_pic_ptr->field_poc[0],
2174 h->cur_pic_ptr->field_poc[1],
2190 int first_slice = sl ==
h->slice_ctx && !
h->current_slice;
2206 if (
h->setup_finished) {
2213 if (
h->current_slice) {
2216 if (
h->nb_slice_ctx_queued) {
2223 memcpy(&tmp_ctx,
h->slice_ctx,
sizeof(tmp_ctx));
2224 memcpy(
h->slice_ctx, sl,
sizeof(tmp_ctx));
2225 memcpy(sl, &tmp_ctx,
sizeof(tmp_ctx));
2238 h->cur_pic_ptr =
NULL;
2245 if (!
h->first_field) {
2246 if (
h->cur_pic_ptr && !
h->droppable) {
2250 h->cur_pic_ptr =
NULL;
2254 if (!
h->current_slice)
2257 if (
h->current_slice == 0 && !
h->first_field) {
2271 if (
h->ps.pps->sps_id !=
pps->sps_id ||
2272 h->ps.pps->transform_8x8_mode !=
pps->transform_8x8_mode
2277 if (
h->ps.sps !=
pps->sps) {
2279 "SPS changed in the middle of the frame\n");
2284 if (
h->current_slice == 0) {
2290 h->droppable != (nal->
ref_idc == 0)) {
2292 "Changing field mode (%d -> %d) between slices is not allowed\n",
2295 }
else if (!
h->cur_pic_ptr) {
2297 "unset cur_pic_ptr on slice %d\n",
2298 h->current_slice + 1);
2307 h->nb_slice_ctx_queued++;
2332 int mb_type,
int top_xy,
2336 int mb_xy,
int list)
2338 int b_stride =
h->b_stride;
2343 const int b_xy =
h->mb2b_xy[top_xy] + 3 * b_stride;
2344 const int b8_xy = 4 * top_xy + 2;
2347 ref_cache[0 - 1 * 8] =
2348 ref_cache[1 - 1 * 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 0]];
2349 ref_cache[2 - 1 * 8] =
2350 ref_cache[3 - 1 * 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 1]];
2358 const int b_xy =
h->mb2b_xy[left_xy[
LTOP]] + 3;
2359 const int b8_xy = 4 * left_xy[
LTOP] + 1;
2361 AV_COPY32(mv_dst - 1 + 0,
h->cur_pic.motion_val[
list][b_xy + b_stride * 0]);
2362 AV_COPY32(mv_dst - 1 + 8,
h->cur_pic.motion_val[
list][b_xy + b_stride * 1]);
2363 AV_COPY32(mv_dst - 1 + 16,
h->cur_pic.motion_val[
list][b_xy + b_stride * 2]);
2364 AV_COPY32(mv_dst - 1 + 24,
h->cur_pic.motion_val[
list][b_xy + b_stride * 3]);
2366 ref_cache[-1 + 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 2 * 0]];
2367 ref_cache[-1 + 16] =
2368 ref_cache[-1 + 24] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 2 * 1]];
2376 ref_cache[-1 + 16] =
2392 int8_t *
ref = &
h->cur_pic.ref_index[
list][4 * mb_xy];
2394 uint32_t ref01 = (
pack16to32(ref2frm[
ref[0]], ref2frm[
ref[1]]) & 0x00FF00FF) * 0x0101;
2395 uint32_t ref23 = (
pack16to32(ref2frm[
ref[2]], ref2frm[
ref[3]]) & 0x00FF00FF) * 0x0101;
2396 AV_WN32A(&ref_cache[0 * 8], ref01);
2397 AV_WN32A(&ref_cache[1 * 8], ref01);
2398 AV_WN32A(&ref_cache[2 * 8], ref23);
2399 AV_WN32A(&ref_cache[3 * 8], ref23);
2403 int16_t(*mv_src)[2] = &
h->cur_pic.motion_val[
list][4 * sl->
mb_x + 4 * sl->
mb_y * b_stride];
2404 AV_COPY128(mv_dst + 8 * 0, mv_src + 0 * b_stride);
2405 AV_COPY128(mv_dst + 8 * 1, mv_src + 1 * b_stride);
2406 AV_COPY128(mv_dst + 8 * 2, mv_src + 2 * b_stride);
2407 AV_COPY128(mv_dst + 8 * 3, mv_src + 3 * b_stride);
2416 const int mb_xy = sl->
mb_xy;
2422 top_xy = mb_xy - (
h->mb_stride <<
MB_FIELD(sl));
2424 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy - 1;
2426 const int left_mb_field_flag =
IS_INTERLACED(
h->cur_pic.mb_type[mb_xy - 1]);
2429 if (left_mb_field_flag != curr_mb_field_flag)
2430 left_xy[
LTOP] -=
h->mb_stride;
2432 if (curr_mb_field_flag)
2433 top_xy +=
h->mb_stride &
2434 (((
h->cur_pic.mb_type[top_xy] >> 7) & 1) - 1);
2435 if (left_mb_field_flag != curr_mb_field_flag)
2436 left_xy[
LBOT] +=
h->mb_stride;
2448 int qp =
h->cur_pic.qscale_table[mb_xy];
2449 if (qp <= qp_thresh &&
2450 (left_xy[
LTOP] < 0 ||
2451 ((qp +
h->cur_pic.qscale_table[left_xy[
LTOP]] + 1) >> 1) <= qp_thresh) &&
2453 ((qp +
h->cur_pic.qscale_table[top_xy] + 1) >> 1) <= qp_thresh)) {
2456 if ((left_xy[
LTOP] < 0 ||
2457 ((qp +
h->cur_pic.qscale_table[left_xy[
LBOT]] + 1) >> 1) <= qp_thresh) &&
2458 (top_xy <
h->mb_stride ||
2459 ((qp +
h->cur_pic.qscale_table[top_xy -
h->mb_stride] + 1) >> 1) <= qp_thresh))
2464 top_type =
h->cur_pic.mb_type[top_xy];
2465 left_type[
LTOP] =
h->cur_pic.mb_type[left_xy[
LTOP]];
2466 left_type[
LBOT] =
h->cur_pic.mb_type[left_xy[
LBOT]];
2471 left_type[
LTOP] = left_type[
LBOT] = 0;
2473 if (
h->slice_table[top_xy] == 0xFFFF)
2475 if (
h->slice_table[left_xy[
LBOT]] == 0xFFFF)
2476 left_type[
LTOP] = left_type[
LBOT] = 0;
2486 top_type, left_type, mb_xy, 0);
2489 top_type, left_type, mb_xy, 1);
2491 nnz =
h->non_zero_count[mb_xy];
2493 AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]);
2494 AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]);
2495 AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]);
2496 AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]);
2497 sl->
cbp =
h->cbp_table[mb_xy];
2500 nnz =
h->non_zero_count[top_xy];
2501 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[3 * 4]);
2504 if (left_type[
LTOP]) {
2505 nnz =
h->non_zero_count[left_xy[
LTOP]];
2506 nnz_cache[3 + 8 * 1] = nnz[3 + 0 * 4];
2507 nnz_cache[3 + 8 * 2] = nnz[3 + 1 * 4];
2508 nnz_cache[3 + 8 * 3] = nnz[3 + 2 * 4];
2509 nnz_cache[3 + 8 * 4] = nnz[3 + 3 * 4];
2514 if (!
CABAC(
h) &&
h->ps.pps->transform_8x8_mode) {
2516 nnz_cache[4 + 8 * 0] =
2517 nnz_cache[5 + 8 * 0] = (
h->cbp_table[top_xy] & 0x4000) >> 12;
2518 nnz_cache[6 + 8 * 0] =
2519 nnz_cache[7 + 8 * 0] = (
h->cbp_table[top_xy] & 0x8000) >> 12;
2522 nnz_cache[3 + 8 * 1] =
2523 nnz_cache[3 + 8 * 2] = (
h->cbp_table[left_xy[
LTOP]] & 0x2000) >> 12;
2526 nnz_cache[3 + 8 * 3] =
2527 nnz_cache[3 + 8 * 4] = (
h->cbp_table[left_xy[
LBOT]] & 0x8000) >> 12;
2531 nnz_cache[
scan8[0]] =
2532 nnz_cache[
scan8[1]] =
2533 nnz_cache[
scan8[2]] =
2534 nnz_cache[
scan8[3]] = (sl->
cbp & 0x1000) >> 12;
2536 nnz_cache[
scan8[0 + 4]] =
2537 nnz_cache[
scan8[1 + 4]] =
2538 nnz_cache[
scan8[2 + 4]] =
2539 nnz_cache[
scan8[3 + 4]] = (sl->
cbp & 0x2000) >> 12;
2541 nnz_cache[
scan8[0 + 8]] =
2542 nnz_cache[
scan8[1 + 8]] =
2543 nnz_cache[
scan8[2 + 8]] =
2544 nnz_cache[
scan8[3 + 8]] = (sl->
cbp & 0x4000) >> 12;
2546 nnz_cache[
scan8[0 + 12]] =
2547 nnz_cache[
scan8[1 + 12]] =
2548 nnz_cache[
scan8[2 + 12]] =
2549 nnz_cache[
scan8[3 + 12]] = (sl->
cbp & 0x8000) >> 12;
2558 uint8_t *dest_y, *dest_cb, *dest_cr;
2559 int linesize, uvlinesize, mb_x, mb_y;
2562 const int pixel_shift =
h->pixel_shift;
2563 const int block_h = 16 >>
h->chroma_y_shift;
2565 if (
h->postpone_filter)
2569 for (mb_x = start_x; mb_x < end_x; mb_x++)
2570 for (mb_y = end_mb_y -
FRAME_MBAFF(
h); mb_y <= end_mb_y; mb_y++) {
2572 mb_xy = sl->
mb_xy = mb_x + mb_y *
h->mb_stride;
2573 mb_type =
h->cur_pic.mb_type[mb_xy];
2581 dest_y =
h->cur_pic.f->data[0] +
2582 ((mb_x << pixel_shift) + mb_y * sl->
linesize) * 16;
2583 dest_cb =
h->cur_pic.f->data[1] +
2584 (mb_x << pixel_shift) * (8 <<
CHROMA444(
h)) +
2586 dest_cr =
h->cur_pic.f->data[2] +
2587 (mb_x << pixel_shift) * (8 <<
CHROMA444(
h)) +
2612 linesize, uvlinesize);
2615 dest_cr, linesize, uvlinesize);
2628 const int mb_xy = sl->
mb_x + sl->
mb_y *
h->mb_stride;
2629 int mb_type = (
h->slice_table[mb_xy - 1] == sl->
slice_num) ?
2630 h->cur_pic.mb_type[mb_xy - 1] :
2631 (
h->slice_table[mb_xy -
h->mb_stride] == sl->
slice_num) ?
2632 h->cur_pic.mb_type[mb_xy -
h->mb_stride] : 0;
2647 if ((top +
height) >= pic_height)
2648 height += deblock_border;
2649 top -= deblock_border;
2652 if (top >= pic_height || (top +
height) < 0)
2663 if (
h->droppable ||
h->er.error_occurred)
2671 int startx,
int starty,
2672 int endx,
int endy,
int status)
2677 if (CONFIG_ERROR_RESILIENCE) {
2686 int lf_x_start = sl->
mb_x;
2690 sl->
linesize =
h->cur_pic_ptr->f->linesize[0];
2701 if (
h->postpone_filter)
2717 if (
h->ps.pps->cabac) {
2761 if (sl->
mb_x >= lf_x_start)
2777 if (++sl->
mb_x >=
h->mb_width) {
2779 sl->
mb_x = lf_x_start = 0;
2789 if (eos || sl->
mb_y >=
h->mb_height) {
2790 ff_tlog(
h->avctx,
"slice end %d %d\n",
2794 if (sl->
mb_x > lf_x_start)
2828 "error while decoding MB %d %d\n", sl->
mb_x, sl->
mb_y);
2834 if (++sl->
mb_x >=
h->mb_width) {
2836 sl->
mb_x = lf_x_start = 0;
2844 if (sl->
mb_y >=
h->mb_height) {
2845 ff_tlog(
h->avctx,
"slice end %d %d\n",
2864 ff_tlog(
h->avctx,
"slice end %d %d\n",
2870 if (sl->
mb_x > lf_x_start)
2898 int context_count =
h->nb_slice_ctx_queued;
2902 h->slice_ctx[0].next_slice_idx = INT_MAX;
2904 if (
h->avctx->hwaccel || context_count < 1)
2907 av_assert0(context_count &&
h->slice_ctx[context_count - 1].mb_y <
h->mb_height);
2909 if (context_count == 1) {
2911 h->slice_ctx[0].next_slice_idx =
h->mb_width *
h->mb_height;
2912 h->postpone_filter = 0;
2915 h->mb_y =
h->slice_ctx[0].mb_y;
2920 for (
i = 0;
i < context_count;
i++) {
2921 int next_slice_idx =
h->mb_width *
h->mb_height;
2924 sl = &
h->slice_ctx[
i];
2927 slice_idx = sl->
mb_y *
h->mb_width + sl->
mb_x;
2928 for (j = 0; j < context_count; j++) {
2930 int slice_idx2 = sl2->
mb_y *
h->mb_width + sl2->
mb_x;
2932 if (
i == j || slice_idx2 < slice_idx)
2934 next_slice_idx =
FFMIN(next_slice_idx, slice_idx2);
2940 NULL, context_count,
sizeof(
h->slice_ctx[0]));
2943 sl = &
h->slice_ctx[context_count - 1];
2946 if (
h->postpone_filter) {
2947 h->postpone_filter = 0;
2949 for (
i = 0;
i < context_count;
i++) {
2952 sl = &
h->slice_ctx[
i];
2954 x_end = (sl->
mb_y >=
h->mb_height) ?
h->mb_width : sl->
mb_x;
2959 j == y_end - 1 ? x_end :
h->mb_width);
2966 h->nb_slice_ctx_queued = 0;