28 #include "config_components.h"
53 0 + 0 * 4, 0 + 1 * 4, 1 + 0 * 4, 0 + 2 * 4,
54 0 + 3 * 4, 1 + 1 * 4, 1 + 2 * 4, 1 + 3 * 4,
55 2 + 0 * 4, 2 + 1 * 4, 2 + 2 * 4, 2 + 3 * 4,
56 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4, 3 + 3 * 4,
60 0 + 0 * 8, 0 + 1 * 8, 0 + 2 * 8, 1 + 0 * 8,
61 1 + 1 * 8, 0 + 3 * 8, 0 + 4 * 8, 1 + 2 * 8,
62 2 + 0 * 8, 1 + 3 * 8, 0 + 5 * 8, 0 + 6 * 8,
63 0 + 7 * 8, 1 + 4 * 8, 2 + 1 * 8, 3 + 0 * 8,
64 2 + 2 * 8, 1 + 5 * 8, 1 + 6 * 8, 1 + 7 * 8,
65 2 + 3 * 8, 3 + 1 * 8, 4 + 0 * 8, 3 + 2 * 8,
66 2 + 4 * 8, 2 + 5 * 8, 2 + 6 * 8, 2 + 7 * 8,
67 3 + 3 * 8, 4 + 1 * 8, 5 + 0 * 8, 4 + 2 * 8,
68 3 + 4 * 8, 3 + 5 * 8, 3 + 6 * 8, 3 + 7 * 8,
69 4 + 3 * 8, 5 + 1 * 8, 6 + 0 * 8, 5 + 2 * 8,
70 4 + 4 * 8, 4 + 5 * 8, 4 + 6 * 8, 4 + 7 * 8,
71 5 + 3 * 8, 6 + 1 * 8, 6 + 2 * 8, 5 + 4 * 8,
72 5 + 5 * 8, 5 + 6 * 8, 5 + 7 * 8, 6 + 3 * 8,
73 7 + 0 * 8, 7 + 1 * 8, 6 + 4 * 8, 6 + 5 * 8,
74 6 + 6 * 8, 6 + 7 * 8, 7 + 2 * 8, 7 + 3 * 8,
75 7 + 4 * 8, 7 + 5 * 8, 7 + 6 * 8, 7 + 7 * 8,
79 0 + 0 * 8, 1 + 1 * 8, 2 + 0 * 8, 0 + 7 * 8,
80 2 + 2 * 8, 2 + 3 * 8, 2 + 4 * 8, 3 + 3 * 8,
81 3 + 4 * 8, 4 + 3 * 8, 4 + 4 * 8, 5 + 3 * 8,
82 5 + 5 * 8, 7 + 0 * 8, 6 + 6 * 8, 7 + 4 * 8,
83 0 + 1 * 8, 0 + 3 * 8, 1 + 3 * 8, 1 + 4 * 8,
84 1 + 5 * 8, 3 + 1 * 8, 2 + 5 * 8, 4 + 1 * 8,
85 3 + 5 * 8, 5 + 1 * 8, 4 + 5 * 8, 6 + 1 * 8,
86 5 + 6 * 8, 7 + 1 * 8, 6 + 7 * 8, 7 + 5 * 8,
87 0 + 2 * 8, 0 + 4 * 8, 0 + 5 * 8, 2 + 1 * 8,
88 1 + 6 * 8, 4 + 0 * 8, 2 + 6 * 8, 5 + 0 * 8,
89 3 + 6 * 8, 6 + 0 * 8, 4 + 6 * 8, 6 + 2 * 8,
90 5 + 7 * 8, 6 + 4 * 8, 7 + 2 * 8, 7 + 6 * 8,
91 1 + 0 * 8, 1 + 2 * 8, 0 + 6 * 8, 3 + 0 * 8,
92 1 + 7 * 8, 3 + 2 * 8, 2 + 7 * 8, 4 + 2 * 8,
93 3 + 7 * 8, 5 + 2 * 8, 4 + 7 * 8, 5 + 4 * 8,
94 6 + 3 * 8, 6 + 5 * 8, 7 + 3 * 8, 7 + 7 * 8,
99 0 + 0 * 8, 1 + 1 * 8, 1 + 2 * 8, 2 + 2 * 8,
100 4 + 1 * 8, 0 + 5 * 8, 3 + 3 * 8, 7 + 0 * 8,
101 3 + 4 * 8, 1 + 7 * 8, 5 + 3 * 8, 6 + 3 * 8,
102 2 + 7 * 8, 6 + 4 * 8, 5 + 6 * 8, 7 + 5 * 8,
103 1 + 0 * 8, 2 + 0 * 8, 0 + 3 * 8, 3 + 1 * 8,
104 3 + 2 * 8, 0 + 6 * 8, 4 + 2 * 8, 6 + 1 * 8,
105 2 + 5 * 8, 2 + 6 * 8, 6 + 2 * 8, 5 + 4 * 8,
106 3 + 7 * 8, 7 + 3 * 8, 4 + 7 * 8, 7 + 6 * 8,
107 0 + 1 * 8, 3 + 0 * 8, 0 + 4 * 8, 4 + 0 * 8,
108 2 + 3 * 8, 1 + 5 * 8, 5 + 1 * 8, 5 + 2 * 8,
109 1 + 6 * 8, 3 + 5 * 8, 7 + 1 * 8, 4 + 5 * 8,
110 4 + 6 * 8, 7 + 4 * 8, 5 + 7 * 8, 6 + 7 * 8,
111 0 + 2 * 8, 2 + 1 * 8, 1 + 3 * 8, 5 + 0 * 8,
112 1 + 4 * 8, 2 + 4 * 8, 6 + 0 * 8, 4 + 3 * 8,
113 0 + 7 * 8, 4 + 4 * 8, 7 + 2 * 8, 3 + 6 * 8,
114 5 + 5 * 8, 6 + 5 * 8, 6 + 6 * 8, 7 + 7 * 8,
123 if (
h->DPB[
i].f->buf[0] && !
h->DPB[
i].reference &&
124 (remove_current || &
h->DPB[
i] !=
h->cur_pic_ptr)) {
141 h->mb_width * 16 * 3 *
sizeof(uint8_t) * 2);
143 h->mb_width * 16 * 3 *
sizeof(uint8_t) * 2);
164 const int big_mb_num =
h->mb_stride * (
h->mb_height + 1) + 1;
165 const int mb_array_size =
h->mb_stride *
h->mb_height;
166 const int b4_stride =
h->mb_width * 4 + 1;
167 const int b4_array_size = b4_stride *
h->mb_height * 4;
171 sizeof(uint32_t), 0);
176 if (!
h->qscale_table_pool || !
h->mb_type_pool || !
h->motion_val_pool ||
177 !
h->ref_index_pool) {
194 if (
h->sei.common.lcevc.info) {
220 if (
h->decode_error_flags_pool) {
228 int h_chroma_shift, v_chroma_shift;
230 &h_chroma_shift, &v_chroma_shift);
240 if (!
h->qscale_table_pool) {
254 for (
i = 0;
i < 2;
i++) {
280 if (!
h->DPB[
i].f->buf[0])
287 #define IN_RANGE(a, b, size) (((void*)(a) >= (void*)(b)) && ((void*)(a) < (void*)((b) + (size))))
289 #define REBASE_PICTURE(pic, new_ctx, old_ctx) \
290 (((pic) && (pic) >= (old_ctx)->DPB && \
291 (pic) < (old_ctx)->DPB + H264_MAX_PICTURE_COUNT) ? \
292 &(new_ctx)->DPB[(pic) - (old_ctx)->DPB] : NULL)
299 for (
i = 0;
i < count;
i++) {
313 for (
int p = 0; p <
desc->nb_components; p++) {
315 int is_chroma = p == 1 || p == 2;
318 if (
desc->comp[0].depth >= 9) {
319 ((uint16_t*)
dst)[0] =
c[p];
322 for (
int y = 1; y <
height; y++) {
323 memcpy(
dst,
frame->data[p], 2*bytes);
327 for (
int y = 0; y <
height; y++) {
328 memset(
dst,
c[p], bytes);
341 int inited =
h->context_initialized, err = 0;
348 if (inited && !h1->ps.sps)
352 (
h->width != h1->width ||
353 h->height != h1->height ||
354 h->mb_width != h1->mb_width ||
355 h->mb_height != h1->mb_height ||
357 h->ps.sps->bit_depth_luma != h1->ps.sps->bit_depth_luma ||
358 h->ps.sps->chroma_format_idc != h1->ps.sps->chroma_format_idc ||
359 h->ps.sps->vui.matrix_coeffs != h1->ps.sps->vui.matrix_coeffs)) {
364 memcpy(
h->block_offset, h1->block_offset,
sizeof(
h->block_offset));
373 h->ps.sps = h1->ps.sps;
375 if (need_reinit || !inited) {
376 h->width = h1->width;
377 h->height = h1->height;
378 h->mb_height = h1->mb_height;
379 h->mb_width = h1->mb_width;
380 h->mb_num = h1->mb_num;
381 h->mb_stride = h1->mb_stride;
382 h->b_stride = h1->b_stride;
383 h->x264_build = h1->x264_build;
385 if (
h->context_initialized || h1->context_initialized) {
393 memcpy(
h->block_offset, h1->block_offset,
sizeof(
h->block_offset));
396 h->width_from_caller = h1->width_from_caller;
397 h->height_from_caller = h1->height_from_caller;
398 h->first_field = h1->first_field;
399 h->picture_structure = h1->picture_structure;
400 h->mb_aff_frame = h1->mb_aff_frame;
401 h->droppable = h1->droppable;
414 h->enable_er = h1->enable_er;
415 h->workaround_bugs = h1->workaround_bugs;
416 h->droppable = h1->droppable;
419 h->is_avc = h1->is_avc;
420 h->nal_length_size = h1->nal_length_size;
422 memcpy(&
h->poc, &h1->poc,
sizeof(
h->poc));
424 memcpy(
h->short_ref, h1->short_ref,
sizeof(
h->short_ref));
425 memcpy(
h->long_ref, h1->long_ref,
sizeof(
h->long_ref));
426 memcpy(
h->delayed_pic, h1->delayed_pic,
sizeof(
h->delayed_pic));
427 memcpy(
h->last_pocs, h1->last_pocs,
sizeof(
h->last_pocs));
429 h->next_output_pic = h1->next_output_pic;
430 h->next_outputed_poc = h1->next_outputed_poc;
431 h->poc_offset = h1->poc_offset;
433 memcpy(
h->mmco, h1->mmco,
sizeof(
h->mmco));
434 h->nb_mmco = h1->nb_mmco;
435 h->mmco_reset = h1->mmco_reset;
436 h->explicit_ref_marking = h1->explicit_ref_marking;
437 h->long_ref_count = h1->long_ref_count;
438 h->short_ref_count = h1->short_ref_count;
445 h->frame_recovered = h1->frame_recovered;
451 h->sei.common.unregistered.x264_build = h1->sei.common.unregistered.x264_build;
458 h->poc.prev_poc_msb =
h->poc.poc_msb;
459 h->poc.prev_poc_lsb =
h->poc.poc_lsb;
461 h->poc.prev_frame_num_offset =
h->poc.frame_num_offset;
462 h->poc.prev_frame_num =
h->poc.frame_num;
464 h->recovery_frame = h1->recovery_frame;
465 h->non_gray = h1->non_gray;
486 const int pixel_shift =
h->pixel_shift;
494 h->cur_pic_ptr =
NULL;
503 pic->
reference =
h->droppable ? 0 :
h->picture_structure;
525 h->sei.common.film_grain_characteristics &&
526 h->sei.common.film_grain_characteristics->present &&
527 !
h->avctx->hwaccel &&
533 h->cur_pic_ptr = pic;
535 if (CONFIG_ERROR_RESILIENCE) {
542 for (
i = 0;
i <
h->nb_slice_ctx;
i++) {
543 h->slice_ctx[
i].linesize =
h->cur_pic_ptr->f->linesize[0];
544 h->slice_ctx[
i].uvlinesize =
h->cur_pic_ptr->f->linesize[1];
547 if (CONFIG_ERROR_RESILIENCE &&
h->enable_er) {
553 for (
i = 0;
i < 16;
i++) {
557 for (
i = 0;
i < 16;
i++) {
558 h->block_offset[16 +
i] =
560 h->block_offset[48 + 16 +
i] =
568 h->cur_pic_ptr->reference = 0;
570 h->cur_pic_ptr->field_poc[0] =
h->cur_pic_ptr->field_poc[1] = INT_MAX;
572 h->next_output_pic =
NULL;
574 h->postpone_filter = 0;
576 h->mb_aff_frame =
h->ps.sps->mb_aff && (
h->picture_structure ==
PICT_FRAME);
578 if (
h->sei.common.unregistered.x264_build >= 0)
579 h->x264_build =
h->sei.common.unregistered.x264_build;
581 assert(
h->cur_pic_ptr->long_ref == 0);
587 const uint8_t *src_y,
588 const uint8_t *src_cb,
const uint8_t *src_cr,
589 int linesize,
int uvlinesize,
594 const int pixel_shift =
h->pixel_shift;
599 src_cb -= uvlinesize;
600 src_cr -= uvlinesize;
606 AV_COPY128(top_border, src_y + 15 * linesize);
608 AV_COPY128(top_border + 16, src_y + 15 * linesize + 16);
612 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
613 AV_COPY128(top_border + 48, src_cb + 15 * uvlinesize + 16);
614 AV_COPY128(top_border + 64, src_cr + 15 * uvlinesize);
615 AV_COPY128(top_border + 80, src_cr + 15 * uvlinesize + 16);
617 AV_COPY128(top_border + 16, src_cb + 15 * uvlinesize);
618 AV_COPY128(top_border + 32, src_cr + 15 * uvlinesize);
620 }
else if (chroma422) {
622 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
623 AV_COPY128(top_border + 48, src_cr + 15 * uvlinesize);
625 AV_COPY64(top_border + 16, src_cb + 15 * uvlinesize);
626 AV_COPY64(top_border + 24, src_cr + 15 * uvlinesize);
630 AV_COPY128(top_border + 32, src_cb + 7 * uvlinesize);
631 AV_COPY128(top_border + 48, src_cr + 7 * uvlinesize);
633 AV_COPY64(top_border + 16, src_cb + 7 * uvlinesize);
634 AV_COPY64(top_border + 24, src_cr + 7 * uvlinesize);
648 AV_COPY128(top_border, src_y + 16 * linesize);
650 AV_COPY128(top_border + 16, src_y + 16 * linesize + 16);
655 AV_COPY128(top_border + 32, src_cb + 16 * linesize);
656 AV_COPY128(top_border + 48, src_cb + 16 * linesize + 16);
657 AV_COPY128(top_border + 64, src_cr + 16 * linesize);
658 AV_COPY128(top_border + 80, src_cr + 16 * linesize + 16);
660 AV_COPY128(top_border + 16, src_cb + 16 * linesize);
661 AV_COPY128(top_border + 32, src_cr + 16 * linesize);
663 }
else if (chroma422) {
665 AV_COPY128(top_border + 32, src_cb + 16 * uvlinesize);
666 AV_COPY128(top_border + 48, src_cr + 16 * uvlinesize);
668 AV_COPY64(top_border + 16, src_cb + 16 * uvlinesize);
669 AV_COPY64(top_border + 24, src_cr + 16 * uvlinesize);
673 AV_COPY128(top_border + 32, src_cb + 8 * uvlinesize);
674 AV_COPY128(top_border + 48, src_cr + 8 * uvlinesize);
676 AV_COPY64(top_border + 16, src_cb + 8 * uvlinesize);
677 AV_COPY64(top_border + 24, src_cr + 8 * uvlinesize);
690 int ref0, ref1,
i, cur_poc, ref_start, ref_count0, ref_count1;
692 for (
i = 0;
i < 2;
i++) {
699 cur_poc =
h->cur_pic_ptr->poc;
701 cur_poc =
h->cur_pic_ptr->field_poc[
h->picture_structure - 1];
713 cur_poc =
h->cur_pic_ptr->field_poc[
field];
724 for (ref0 = ref_start; ref0 < ref_count0; ref0++) {
726 for (ref1 = ref_start; ref1 < ref_count1; ref1++) {
733 int tx = (16384 + (
FFABS(td) >> 1)) / td;
734 int dist_scale_factor = (tb * tx + 32) >> 8;
735 if (dist_scale_factor >= -64 && dist_scale_factor <= 128)
736 w = 64 - dist_scale_factor;
755 for (
i = 0;
i < 16;
i++) {
756 #define TRANSPOSE(x) ((x) >> 2) | (((x) << 2) & 0xF)
761 for (
i = 0;
i < 64;
i++) {
762 #define TRANSPOSE(x) ((x) >> 3) | (((x) & 7) << 3)
769 if (
h->ps.sps->transform_bypass) {
773 memcpy(
h->field_scan_q0 ,
field_scan ,
sizeof(
h->field_scan_q0 ));
774 memcpy(
h->field_scan8x8_q0 ,
field_scan8x8 ,
sizeof(
h->field_scan8x8_q0 ));
777 memcpy(
h->zigzag_scan_q0 ,
h->zigzag_scan ,
sizeof(
h->zigzag_scan_q0 ));
778 memcpy(
h->zigzag_scan8x8_q0 ,
h->zigzag_scan8x8 ,
sizeof(
h->zigzag_scan8x8_q0 ));
779 memcpy(
h->zigzag_scan8x8_cavlc_q0 ,
h->zigzag_scan8x8_cavlc ,
sizeof(
h->zigzag_scan8x8_cavlc_q0));
780 memcpy(
h->field_scan_q0 ,
h->field_scan ,
sizeof(
h->field_scan_q0 ));
781 memcpy(
h->field_scan8x8_q0 ,
h->field_scan8x8 ,
sizeof(
h->field_scan8x8_q0 ));
782 memcpy(
h->field_scan8x8_cavlc_q0 ,
h->field_scan8x8_cavlc ,
sizeof(
h->field_scan8x8_cavlc_q0 ));
788 #define HWACCEL_MAX (CONFIG_H264_DXVA2_HWACCEL + \
789 (CONFIG_H264_D3D11VA_HWACCEL * 2) + \
790 CONFIG_H264_D3D12VA_HWACCEL + \
791 CONFIG_H264_NVDEC_HWACCEL + \
792 CONFIG_H264_VAAPI_HWACCEL + \
793 CONFIG_H264_VIDEOTOOLBOX_HWACCEL + \
794 CONFIG_H264_VDPAU_HWACCEL + \
795 CONFIG_H264_VULKAN_HWACCEL)
798 switch (
h->ps.sps->bit_depth_luma) {
811 #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL
815 #if CONFIG_H264_VULKAN_HWACCEL
818 #if CONFIG_H264_NVDEC_HWACCEL
829 #if CONFIG_H264_VAAPI_HWACCEL
839 #if CONFIG_H264_VULKAN_HWACCEL
864 #if CONFIG_H264_VDPAU_HWACCEL
867 #if CONFIG_H264_VULKAN_HWACCEL
870 #if CONFIG_H264_NVDEC_HWACCEL
873 #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL
890 #if CONFIG_H264_DXVA2_HWACCEL
893 #if CONFIG_H264_D3D11VA_HWACCEL
897 #if CONFIG_H264_D3D12VA_HWACCEL
900 #if CONFIG_H264_VAAPI_HWACCEL
911 "Unsupported bit depth %d\n",
h->ps.sps->bit_depth_luma);
918 if (
pix_fmts[
i] ==
h->avctx->pix_fmt && !force_callback)
927 int cr =
sps->crop_right;
928 int cl =
sps->crop_left;
929 int ct =
sps->crop_top;
930 int cb =
sps->crop_bottom;
937 if (
h->width_from_caller > 0 &&
h->height_from_caller > 0 &&
938 !
sps->crop_top && !
sps->crop_left &&
941 h->width_from_caller <=
width &&
942 h->height_from_caller <=
height) {
943 width =
h->width_from_caller;
944 height =
h->height_from_caller;
950 h->width_from_caller = 0;
951 h->height_from_caller = 0;
954 h->avctx->coded_width =
h->width;
955 h->avctx->coded_height =
h->height;
976 &
h->chroma_x_shift, &
h->chroma_y_shift);
978 if (
sps->timing_info_present_flag) {
980 if (
h->x264_build < 44
U)
982 av_reduce(&
h->avctx->framerate.den, &
h->avctx->framerate.num,
983 sps->num_units_in_tick * 2, den, 1 << 30);
989 h->prev_interlaced_frame = 1;
998 if (
sps->bit_depth_luma < 8 ||
sps->bit_depth_luma > 14 ||
999 sps->bit_depth_luma == 11 ||
sps->bit_depth_luma == 13
1002 sps->bit_depth_luma);
1007 h->cur_bit_depth_luma =
1008 h->avctx->bits_per_raw_sample =
sps->bit_depth_luma;
1009 h->cur_chroma_format_idc =
sps->chroma_format_idc;
1010 h->pixel_shift =
sps->bit_depth_luma > 8;
1011 h->chroma_format_idc =
sps->chroma_format_idc;
1012 h->bit_depth_luma =
sps->bit_depth_luma;
1015 sps->chroma_format_idc);
1019 sps->chroma_format_idc);
1025 for (
i = 0;
i <
h->nb_slice_ctx;
i++) {
1030 sl->
mvd_table[0] =
h->mvd_table[0] +
i * 8 * 2 *
h->mb_stride;
1031 sl->
mvd_table[1] =
h->mvd_table[1] +
i * 8 * 2 *
h->mb_stride;
1037 h->context_initialized = 1;
1042 h->context_initialized = 0;
1060 int needs_reinit = 0, must_reinit,
ret;
1065 if (
h->ps.sps !=
h->ps.pps->sps) {
1066 h->ps.sps =
h->ps.pps->sps;
1068 if (
h->mb_width !=
h->ps.sps->mb_width ||
1069 h->mb_height !=
h->ps.sps->mb_height ||
1070 h->cur_bit_depth_luma !=
h->ps.sps->bit_depth_luma ||
1071 h->cur_chroma_format_idc !=
h->ps.sps->chroma_format_idc
1075 if (
h->bit_depth_luma !=
h->ps.sps->bit_depth_luma ||
1076 h->chroma_format_idc !=
h->ps.sps->chroma_format_idc)
1081 must_reinit = (
h->context_initialized &&
1082 ( 16*
sps->mb_width !=
h->avctx->coded_width
1083 || 16*
sps->mb_height !=
h->avctx->coded_height
1084 ||
h->cur_bit_depth_luma !=
sps->bit_depth_luma
1085 ||
h->cur_chroma_format_idc !=
sps->chroma_format_idc
1086 ||
h->mb_width !=
sps->mb_width
1087 ||
h->mb_height !=
sps->mb_height
1093 if (first_slice &&
av_cmp_q(
sps->vui.sar,
h->avctx->sample_aspect_ratio))
1096 if (!
h->setup_finished) {
1098 h->avctx->level =
sps->level_idc;
1099 h->avctx->refs =
sps->ref_frame_count;
1101 h->mb_width =
sps->mb_width;
1102 h->mb_height =
sps->mb_height;
1103 h->mb_num =
h->mb_width *
h->mb_height;
1104 h->mb_stride =
h->mb_width + 1;
1106 h->b_stride =
h->mb_width * 4;
1108 h->chroma_y_shift =
sps->chroma_format_idc <= 1;
1110 h->width = 16 *
h->mb_width;
1111 h->height = 16 *
h->mb_height;
1115 if (
sps->vui.video_signal_type_present_flag) {
1118 if (
sps->vui.colour_description_present_flag) {
1119 if (
h->avctx->colorspace !=
sps->vui.matrix_coeffs)
1121 h->avctx->color_primaries =
sps->vui.colour_primaries;
1122 h->avctx->color_trc =
sps->vui.transfer_characteristics;
1123 h->avctx->colorspace =
sps->vui.matrix_coeffs;
1127 if (
h->sei.common.alternative_transfer.present &&
1130 h->avctx->color_trc =
h->sei.common.alternative_transfer.preferred_transfer_characteristics;
1133 h->avctx->chroma_sample_location =
sps->vui.chroma_location;
1135 if (!
h->context_initialized || must_reinit || needs_reinit) {
1136 int flush_changes =
h->context_initialized;
1137 h->context_initialized = 0;
1138 if (sl !=
h->slice_ctx) {
1140 "changing width %d -> %d / height %d -> %d on "
1142 h->width,
h->avctx->coded_width,
1143 h->height,
h->avctx->coded_height,
1144 h->current_slice + 1);
1155 h->avctx->pix_fmt =
ret;
1162 "h264_slice_header_init() failed\n");
1175 int interlaced_frame = 0, top_field_first = 0;
1179 out->repeat_pict = 0;
1184 if (
h->sei.picture_timing.present) {
1191 h->sei.picture_timing.present = 0;
1195 if (
sps->pic_struct_present_flag &&
h->sei.picture_timing.present) {
1197 switch (
pt->pic_struct) {
1202 interlaced_frame = 1;
1207 interlaced_frame = 1;
1210 interlaced_frame = !!
h->prev_interlaced_frame;
1217 out->repeat_pict = 1;
1220 out->repeat_pict = 2;
1223 out->repeat_pict = 4;
1227 if ((
pt->ct_type & 3) &&
1229 interlaced_frame = ((
pt->ct_type & (1 << 1)) != 0);
1234 h->prev_interlaced_frame = interlaced_frame;
1240 if (
sps->pic_struct_present_flag &&
h->sei.picture_timing.present) {
1245 top_field_first = 1;
1246 }
else if (interlaced_frame) {
1249 top_field_first = 1;
1258 &
sps->vui,
sps->bit_depth_luma,
sps->bit_depth_chroma,
1259 cur->
poc + (
unsigned)(
h->poc_offset << 5));
1263 if (
h->sei.picture_timing.timecode_cnt > 0) {
1268 sizeof(uint32_t)*4, &tcside);
1273 tc_sd = (uint32_t*)tcside->
data;
1274 tc_sd[0] =
h->sei.picture_timing.timecode_cnt;
1276 for (
int i = 0;
i < tc_sd[0];
i++) {
1277 int drop =
h->sei.picture_timing.timecode[
i].dropframe;
1278 int hh =
h->sei.picture_timing.timecode[
i].hours;
1279 int mm =
h->sei.picture_timing.timecode[
i].minutes;
1280 int ss =
h->sei.picture_timing.timecode[
i].seconds;
1281 int ff =
h->sei.picture_timing.timecode[
i].frame;
1288 h->sei.picture_timing.timecode_cnt = 0;
1299 int i, pics, out_of_order, out_idx;
1304 if (
sps->bitstream_restriction_flag ||
1306 h->avctx->has_b_frames =
FFMAX(
h->avctx->has_b_frames,
sps->num_reorder_frames);
1309 for (
i = 0; 1;
i++) {
1312 h->last_pocs[
i-1] = cur->
poc;
1315 h->last_pocs[
i-1]=
h->last_pocs[
i];
1321 out_of_order =
FFMAX(out_of_order, 1);
1325 h->last_pocs[
i] = INT_MIN;
1326 h->last_pocs[0] = cur->
poc;
1328 }
else if(
h->avctx->has_b_frames < out_of_order && !
sps->bitstream_restriction_flag){
1330 av_log(
h->avctx, loglevel,
"Increasing reorder buffer to %d\n", out_of_order);
1331 h->avctx->has_b_frames = out_of_order;
1335 while (
h->delayed_pic[pics])
1340 h->delayed_pic[pics++] = cur;
1344 out =
h->delayed_pic[0];
1346 for (
i = 1;
h->delayed_pic[
i] &&
1348 !
h->delayed_pic[
i]->mmco_reset;
1350 if (
h->delayed_pic[
i]->poc <
out->poc) {
1351 out =
h->delayed_pic[
i];
1354 if (
h->avctx->has_b_frames == 0 &&
1356 h->next_outputed_poc = INT_MIN;
1357 out_of_order =
out->poc <
h->next_outputed_poc;
1359 if (out_of_order || pics >
h->avctx->has_b_frames) {
1361 for (
i = out_idx;
h->delayed_pic[
i];
i++)
1362 h->delayed_pic[
i] =
h->delayed_pic[
i + 1];
1364 if (!out_of_order && pics >
h->avctx->has_b_frames) {
1365 h->next_output_pic =
out;
1366 if (out_idx == 0 &&
h->delayed_pic[0] && ((
h->delayed_pic[0]->f->flags &
AV_FRAME_FLAG_KEY) ||
h->delayed_pic[0]->mmco_reset)) {
1367 h->next_outputed_poc = INT_MIN;
1369 h->next_outputed_poc =
out->poc;
1373 h->frame_recovered |=
out->recovered;
1377 if (!
out->recovered) {
1380 h->next_output_pic =
NULL;
1397 const H2645NAL *nal,
int first_slice)
1402 int last_pic_structure, last_pic_droppable,
ret;
1410 if (
sps->bitstream_restriction_flag &&
1411 h->avctx->has_b_frames <
sps->num_reorder_frames) {
1412 h->avctx->has_b_frames =
sps->num_reorder_frames;
1415 last_pic_droppable =
h->droppable;
1416 last_pic_structure =
h->picture_structure;
1417 h->droppable = (nal->
ref_idc == 0);
1428 else if (
h->picture_intra_only)
1433 if (
h->poc.frame_num !=
h->poc.prev_frame_num) {
1434 int unwrap_prev_frame_num =
h->poc.prev_frame_num;
1435 int max_frame_num = 1 <<
sps->log2_max_frame_num;
1437 if (unwrap_prev_frame_num >
h->poc.frame_num)
1438 unwrap_prev_frame_num -= max_frame_num;
1440 if ((
h->poc.frame_num - unwrap_prev_frame_num) >
sps->ref_frame_count) {
1441 unwrap_prev_frame_num = (
h->poc.frame_num -
sps->ref_frame_count) - 1;
1442 if (unwrap_prev_frame_num < 0)
1443 unwrap_prev_frame_num += max_frame_num;
1445 h->poc.prev_frame_num = unwrap_prev_frame_num;
1454 if (
h->first_field) {
1461 if (
h->cur_pic_ptr->tf.owner[last_field] ==
h->avctx) {
1466 if (!
FIELD_PICTURE(
h) ||
h->picture_structure == last_pic_structure) {
1474 if (
h->cur_pic_ptr->frame_num !=
h->poc.frame_num) {
1490 "Invalid field mode combination %d/%d\n",
1491 last_pic_structure,
h->picture_structure);
1492 h->picture_structure = last_pic_structure;
1493 h->droppable = last_pic_droppable;
1495 }
else if (last_pic_droppable !=
h->droppable) {
1497 "Found reference and non-reference fields in the same frame, which");
1498 h->picture_structure = last_pic_structure;
1499 h->droppable = last_pic_droppable;
1506 while (
h->poc.frame_num !=
h->poc.prev_frame_num && !
h->first_field &&
1507 h->poc.frame_num != (
h->poc.prev_frame_num + 1) % (1 <<
sps->log2_max_frame_num)) {
1510 h->poc.frame_num,
h->poc.prev_frame_num);
1511 if (!
sps->gaps_in_frame_num_allowed_flag)
1513 h->last_pocs[
i] = INT_MIN;
1520 h->poc.prev_frame_num++;
1521 h->poc.prev_frame_num %= 1 <<
sps->log2_max_frame_num;
1522 h->cur_pic_ptr->frame_num =
h->poc.prev_frame_num;
1523 h->cur_pic_ptr->invalid_gap = !
sps->gaps_in_frame_num_allowed_flag;
1527 h->explicit_ref_marking = 0;
1538 if (
h->short_ref_count) {
1540 1<<(
h->ps.sps->bit_depth_luma-1),
1541 1<<(
h->ps.sps->bit_depth_chroma-1),
1542 1<<(
h->ps.sps->bit_depth_chroma-1),
1547 h->short_ref[0]->f->width == prev->
f->
width &&
1548 h->short_ref[0]->f->height == prev->
f->
height &&
1549 h->short_ref[0]->f->format == prev->
f->
format) {
1554 h->short_ref[0]->tf.f =
h->short_ref[0]->f;
1558 h->short_ref[0]->poc = prev->
poc + 2
U;
1559 h->short_ref[0]->gray = prev->
gray;
1561 if (
h->short_ref[0]->field_picture)
1563 }
else if (!
h->frame_recovered) {
1564 if (!
h->avctx->hwaccel)
1566 h->short_ref[0]->gray = 1;
1568 h->short_ref[0]->frame_num =
h->poc.prev_frame_num;
1575 if (
h->first_field) {
1581 if (!
FIELD_PICTURE(
h) ||
h->picture_structure == last_pic_structure) {
1584 h->missing_fields ++;
1585 h->cur_pic_ptr =
NULL;
1588 h->missing_fields = 0;
1589 if (
h->cur_pic_ptr->frame_num !=
h->poc.frame_num) {
1596 h->cur_pic_ptr =
NULL;
1602 h->cur_pic_ptr =
NULL;
1621 h->cur_pic_ptr->tf.owner[
field] =
h->avctx;
1627 memset(
h->slice_table +
i*
h->mb_stride, -1, (
h->mb_stride - (
i+1==
h->mb_height)) *
sizeof(*
h->slice_table));
1629 memset(
h->slice_table, -1,
1630 (
h->mb_height *
h->mb_stride - 1) *
sizeof(*
h->slice_table));
1634 h->ps.sps, &
h->poc,
h->picture_structure, nal->
ref_idc);
1644 if (
h->sei.recovery_point.recovery_frame_cnt >= 0) {
1645 const int sei_recovery_frame_cnt =
h->sei.recovery_point.recovery_frame_cnt;
1648 h->valid_recovery_point = 1;
1650 if (
h->recovery_frame < 0
1651 ||
av_zero_extend(
h->recovery_frame -
h->poc.frame_num,
h->ps.sps->log2_max_frame_num) > sei_recovery_frame_cnt) {
1652 h->recovery_frame =
av_zero_extend(
h->poc.frame_num + sei_recovery_frame_cnt,
h->ps.sps->log2_max_frame_num);
1654 if (!
h->valid_recovery_point)
1655 h->recovery_frame =
h->poc.frame_num;
1668 if (
h->recovery_frame ==
h->poc.frame_num && nal->
ref_idc) {
1669 h->recovery_frame = -1;
1674 h->cur_pic_ptr->recovered |=
h->frame_recovered;
1701 unsigned int slice_type,
tmp,
i;
1702 int field_pic_flag, bottom_field_flag;
1703 int first_slice = sl ==
h->slice_ctx && !
h->current_slice;
1704 int picture_structure;
1712 if (slice_type > 9) {
1714 "slice type %d too large at %d\n",
1718 if (slice_type > 4) {
1739 if (!
h->ps.pps_list[sl->
pps_id]) {
1741 "non-existing PPS %u referenced\n",
1759 if (
sps->frame_mbs_only_flag) {
1763 av_log(
h->avctx,
AV_LOG_ERROR,
"This stream was generated by a broken encoder, invalid 8x8 inference\n");
1767 if (field_pic_flag) {
1787 if (idr_pic_id < 65536) {
1795 if (
sps->poc_type == 0) {
1798 if (
pps->pic_order_present == 1 && picture_structure ==
PICT_FRAME)
1803 if (
sps->poc_type == 1 && !
sps->delta_pic_order_always_zero_flag) {
1806 if (
pps->pic_order_present == 1 && picture_structure ==
PICT_FRAME)
1811 if (
pps->redundant_pic_cnt_present)
1819 picture_structure,
h->avctx);
1832 for (
i = 0;
i < 2;
i++) {
1837 (
pps->weighted_bipred_idc == 1 &&
1841 picture_structure,
h->avctx);
1864 if (
tmp > 51 + 6 * (
sps->bit_depth_luma - 8)) {
1881 if (
pps->deblocking_filter_parameters_present) {
1885 "deblocking_filter_idc %u out of range\n",
tmp);
1895 if (slice_alpha_c0_offset_div2 > 6 ||
1896 slice_alpha_c0_offset_div2 < -6 ||
1897 slice_beta_offset_div2 > 6 ||
1898 slice_beta_offset_div2 < -6) {
1900 "deblocking filter parameters %d %d out of range\n",
1901 slice_alpha_c0_offset_div2, slice_beta_offset_div2);
1941 if (
h->ps.pps->weighted_bipred_idc == 2 &&
1952 if (!
h->setup_finished)
1972 h->postpone_filter = 1;
1978 h->ps.pps->chroma_qp_index_offset[0],
1979 h->ps.pps->chroma_qp_index_offset[1]) +
1980 6 * (
h->ps.sps->bit_depth_luma - 8);
1993 for (j = 0; j < 2; j++) {
1996 for (
i = 0;
i < 16;
i++) {
1998 if (j < sl->list_count && i < sl->ref_count[j] &&
2002 for (k = 0; k <
h->short_ref_count; k++)
2003 if (
h->short_ref[k]->f->buf[0]->buffer == buf) {
2007 for (k = 0; k <
h->long_ref_count; k++)
2008 if (
h->long_ref[k] &&
h->long_ref[k]->f->buf[0]->buffer == buf) {
2009 id_list[
i] =
h->short_ref_count + k;
2017 for (
i = 0;
i < 16;
i++)
2020 ref2frm[18 + 1] = -1;
2021 for (
i = 16;
i < 48;
i++)
2022 ref2frm[
i + 4] = 4 * id_list[(
i - 16) >> 1] +
2027 h->cur_pic_ptr->gray = 0;
2036 h->cur_pic_ptr->gray =
gray;
2041 "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",
2049 h->cur_pic_ptr->field_poc[0],
2050 h->cur_pic_ptr->field_poc[1],
2066 int first_slice = sl ==
h->slice_ctx && !
h->current_slice;
2082 if (
h->setup_finished) {
2089 if (
h->current_slice) {
2092 if (
h->nb_slice_ctx_queued) {
2099 memcpy(&tmp_ctx,
h->slice_ctx,
sizeof(tmp_ctx));
2100 memcpy(
h->slice_ctx, sl,
sizeof(tmp_ctx));
2101 memcpy(sl, &tmp_ctx,
sizeof(tmp_ctx));
2114 h->cur_pic_ptr =
NULL;
2121 if (!
h->first_field) {
2122 if (
h->cur_pic_ptr && !
h->droppable) {
2126 h->cur_pic_ptr =
NULL;
2130 if (!
h->current_slice)
2133 if (
h->current_slice == 0 && !
h->first_field) {
2147 if (
h->ps.pps->sps_id !=
pps->sps_id ||
2148 h->ps.pps->transform_8x8_mode !=
pps->transform_8x8_mode
2153 if (
h->ps.sps !=
pps->sps) {
2155 "SPS changed in the middle of the frame\n");
2160 if (
h->current_slice == 0) {
2166 h->droppable != (nal->
ref_idc == 0)) {
2168 "Changing field mode (%d -> %d) between slices is not allowed\n",
2171 }
else if (!
h->cur_pic_ptr) {
2173 "unset cur_pic_ptr on slice %d\n",
2174 h->current_slice + 1);
2183 h->nb_slice_ctx_queued++;
2208 int mb_type,
int top_xy,
2212 int mb_xy,
int list)
2214 int b_stride =
h->b_stride;
2219 const int b_xy =
h->mb2b_xy[top_xy] + 3 * b_stride;
2220 const int b8_xy = 4 * top_xy + 2;
2223 ref_cache[0 - 1 * 8] =
2224 ref_cache[1 - 1 * 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 0]];
2225 ref_cache[2 - 1 * 8] =
2226 ref_cache[3 - 1 * 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 1]];
2234 const int b_xy =
h->mb2b_xy[left_xy[
LTOP]] + 3;
2235 const int b8_xy = 4 * left_xy[
LTOP] + 1;
2237 AV_COPY32(mv_dst - 1 + 0,
h->cur_pic.motion_val[
list][b_xy + b_stride * 0]);
2238 AV_COPY32(mv_dst - 1 + 8,
h->cur_pic.motion_val[
list][b_xy + b_stride * 1]);
2239 AV_COPY32(mv_dst - 1 + 16,
h->cur_pic.motion_val[
list][b_xy + b_stride * 2]);
2240 AV_COPY32(mv_dst - 1 + 24,
h->cur_pic.motion_val[
list][b_xy + b_stride * 3]);
2242 ref_cache[-1 + 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 2 * 0]];
2243 ref_cache[-1 + 16] =
2244 ref_cache[-1 + 24] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 2 * 1]];
2252 ref_cache[-1 + 16] =
2268 const int8_t *
ref = &
h->cur_pic.ref_index[
list][4 * mb_xy];
2270 uint32_t ref01 = (
pack16to32(ref2frm[
ref[0]], ref2frm[
ref[1]]) & 0x00FF00FF) * 0x0101;
2271 uint32_t ref23 = (
pack16to32(ref2frm[
ref[2]], ref2frm[
ref[3]]) & 0x00FF00FF) * 0x0101;
2272 AV_WN32A(&ref_cache[0 * 8], ref01);
2273 AV_WN32A(&ref_cache[1 * 8], ref01);
2274 AV_WN32A(&ref_cache[2 * 8], ref23);
2275 AV_WN32A(&ref_cache[3 * 8], ref23);
2279 int16_t(*mv_src)[2] = &
h->cur_pic.motion_val[
list][4 * sl->
mb_x + 4 * sl->
mb_y * b_stride];
2280 AV_COPY128(mv_dst + 8 * 0, mv_src + 0 * b_stride);
2281 AV_COPY128(mv_dst + 8 * 1, mv_src + 1 * b_stride);
2282 AV_COPY128(mv_dst + 8 * 2, mv_src + 2 * b_stride);
2283 AV_COPY128(mv_dst + 8 * 3, mv_src + 3 * b_stride);
2292 const int mb_xy = sl->
mb_xy;
2298 top_xy = mb_xy - (
h->mb_stride <<
MB_FIELD(sl));
2300 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy - 1;
2302 const int left_mb_field_flag =
IS_INTERLACED(
h->cur_pic.mb_type[mb_xy - 1]);
2305 if (left_mb_field_flag != curr_mb_field_flag)
2306 left_xy[
LTOP] -=
h->mb_stride;
2308 if (curr_mb_field_flag)
2309 top_xy +=
h->mb_stride &
2310 (((
h->cur_pic.mb_type[top_xy] >> 7) & 1) - 1);
2311 if (left_mb_field_flag != curr_mb_field_flag)
2312 left_xy[
LBOT] +=
h->mb_stride;
2324 int qp =
h->cur_pic.qscale_table[mb_xy];
2325 if (qp <= qp_thresh &&
2326 (left_xy[
LTOP] < 0 ||
2327 ((qp +
h->cur_pic.qscale_table[left_xy[
LTOP]] + 1) >> 1) <= qp_thresh) &&
2329 ((qp +
h->cur_pic.qscale_table[top_xy] + 1) >> 1) <= qp_thresh)) {
2332 if ((left_xy[
LTOP] < 0 ||
2333 ((qp +
h->cur_pic.qscale_table[left_xy[
LBOT]] + 1) >> 1) <= qp_thresh) &&
2334 (top_xy <
h->mb_stride ||
2335 ((qp +
h->cur_pic.qscale_table[top_xy -
h->mb_stride] + 1) >> 1) <= qp_thresh))
2340 top_type =
h->cur_pic.mb_type[top_xy];
2341 left_type[
LTOP] =
h->cur_pic.mb_type[left_xy[
LTOP]];
2342 left_type[
LBOT] =
h->cur_pic.mb_type[left_xy[
LBOT]];
2347 left_type[
LTOP] = left_type[
LBOT] = 0;
2349 if (
h->slice_table[top_xy] == 0xFFFF)
2351 if (
h->slice_table[left_xy[
LBOT]] == 0xFFFF)
2352 left_type[
LTOP] = left_type[
LBOT] = 0;
2362 top_type, left_type, mb_xy, 0);
2365 top_type, left_type, mb_xy, 1);
2367 nnz =
h->non_zero_count[mb_xy];
2369 AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]);
2370 AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]);
2371 AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]);
2372 AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]);
2373 sl->
cbp =
h->cbp_table[mb_xy];
2376 nnz =
h->non_zero_count[top_xy];
2377 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[3 * 4]);
2380 if (left_type[
LTOP]) {
2381 nnz =
h->non_zero_count[left_xy[
LTOP]];
2382 nnz_cache[3 + 8 * 1] = nnz[3 + 0 * 4];
2383 nnz_cache[3 + 8 * 2] = nnz[3 + 1 * 4];
2384 nnz_cache[3 + 8 * 3] = nnz[3 + 2 * 4];
2385 nnz_cache[3 + 8 * 4] = nnz[3 + 3 * 4];
2390 if (!
CABAC(
h) &&
h->ps.pps->transform_8x8_mode) {
2392 nnz_cache[4 + 8 * 0] =
2393 nnz_cache[5 + 8 * 0] = (
h->cbp_table[top_xy] & 0x4000) >> 12;
2394 nnz_cache[6 + 8 * 0] =
2395 nnz_cache[7 + 8 * 0] = (
h->cbp_table[top_xy] & 0x8000) >> 12;
2398 nnz_cache[3 + 8 * 1] =
2399 nnz_cache[3 + 8 * 2] = (
h->cbp_table[left_xy[
LTOP]] & 0x2000) >> 12;
2402 nnz_cache[3 + 8 * 3] =
2403 nnz_cache[3 + 8 * 4] = (
h->cbp_table[left_xy[
LBOT]] & 0x8000) >> 12;
2407 nnz_cache[
scan8[0]] =
2408 nnz_cache[
scan8[1]] =
2409 nnz_cache[
scan8[2]] =
2410 nnz_cache[
scan8[3]] = (sl->
cbp & 0x1000) >> 12;
2412 nnz_cache[
scan8[0 + 4]] =
2413 nnz_cache[
scan8[1 + 4]] =
2414 nnz_cache[
scan8[2 + 4]] =
2415 nnz_cache[
scan8[3 + 4]] = (sl->
cbp & 0x2000) >> 12;
2417 nnz_cache[
scan8[0 + 8]] =
2418 nnz_cache[
scan8[1 + 8]] =
2419 nnz_cache[
scan8[2 + 8]] =
2420 nnz_cache[
scan8[3 + 8]] = (sl->
cbp & 0x4000) >> 12;
2422 nnz_cache[
scan8[0 + 12]] =
2423 nnz_cache[
scan8[1 + 12]] =
2424 nnz_cache[
scan8[2 + 12]] =
2425 nnz_cache[
scan8[3 + 12]] = (sl->
cbp & 0x8000) >> 12;
2434 uint8_t *dest_y, *dest_cb, *dest_cr;
2435 int linesize, uvlinesize, mb_x, mb_y;
2438 const int pixel_shift =
h->pixel_shift;
2439 const int block_h = 16 >>
h->chroma_y_shift;
2441 if (
h->postpone_filter)
2445 for (mb_x = start_x; mb_x < end_x; mb_x++)
2446 for (mb_y = end_mb_y -
FRAME_MBAFF(
h); mb_y <= end_mb_y; mb_y++) {
2448 mb_xy = sl->
mb_xy = mb_x + mb_y *
h->mb_stride;
2449 mb_type =
h->cur_pic.mb_type[mb_xy];
2457 dest_y =
h->cur_pic.f->data[0] +
2458 ((mb_x << pixel_shift) + mb_y * sl->
linesize) * 16;
2459 dest_cb =
h->cur_pic.f->data[1] +
2460 (mb_x << pixel_shift) * (8 <<
CHROMA444(
h)) +
2462 dest_cr =
h->cur_pic.f->data[2] +
2463 (mb_x << pixel_shift) * (8 <<
CHROMA444(
h)) +
2488 linesize, uvlinesize);
2491 dest_cr, linesize, uvlinesize);
2504 const int mb_xy = sl->
mb_x + sl->
mb_y *
h->mb_stride;
2505 int mb_type = (
h->slice_table[mb_xy - 1] == sl->
slice_num) ?
2506 h->cur_pic.mb_type[mb_xy - 1] :
2507 (
h->slice_table[mb_xy -
h->mb_stride] == sl->
slice_num) ?
2508 h->cur_pic.mb_type[mb_xy -
h->mb_stride] : 0;
2523 if ((top +
height) >= pic_height)
2524 height += deblock_border;
2525 top -= deblock_border;
2528 if (top >= pic_height || (top +
height) < 0)
2539 if (
h->droppable ||
h->er.error_occurred)
2547 int startx,
int starty,
2548 int endx,
int endy,
int status)
2553 if (CONFIG_ERROR_RESILIENCE) {
2562 int lf_x_start = sl->
mb_x;
2566 sl->
linesize =
h->cur_pic_ptr->f->linesize[0];
2577 if (
h->postpone_filter)
2593 if (
h->ps.pps->cabac) {
2637 if (sl->
mb_x >= lf_x_start)
2653 if (++sl->
mb_x >=
h->mb_width) {
2655 sl->
mb_x = lf_x_start = 0;
2665 if (eos || sl->
mb_y >=
h->mb_height) {
2666 ff_tlog(
h->avctx,
"slice end %d %d\n",
2670 if (sl->
mb_x > lf_x_start)
2704 "error while decoding MB %d %d\n", sl->
mb_x, sl->
mb_y);
2710 if (++sl->
mb_x >=
h->mb_width) {
2712 sl->
mb_x = lf_x_start = 0;
2720 if (sl->
mb_y >=
h->mb_height) {
2721 ff_tlog(
h->avctx,
"slice end %d %d\n",
2740 ff_tlog(
h->avctx,
"slice end %d %d\n",
2746 if (sl->
mb_x > lf_x_start)
2774 int context_count =
h->nb_slice_ctx_queued;
2778 h->slice_ctx[0].next_slice_idx = INT_MAX;
2780 if (
h->avctx->hwaccel || context_count < 1)
2783 av_assert0(context_count &&
h->slice_ctx[context_count - 1].mb_y <
h->mb_height);
2785 if (context_count == 1) {
2787 h->slice_ctx[0].next_slice_idx =
h->mb_width *
h->mb_height;
2788 h->postpone_filter = 0;
2791 h->mb_y =
h->slice_ctx[0].mb_y;
2796 for (
i = 0;
i < context_count;
i++) {
2797 int next_slice_idx =
h->mb_width *
h->mb_height;
2800 sl = &
h->slice_ctx[
i];
2803 slice_idx = sl->
mb_y *
h->mb_width + sl->
mb_x;
2804 for (j = 0; j < context_count; j++) {
2806 int slice_idx2 = sl2->
mb_y *
h->mb_width + sl2->
mb_x;
2808 if (
i == j || slice_idx2 < slice_idx)
2810 next_slice_idx =
FFMIN(next_slice_idx, slice_idx2);
2816 NULL, context_count,
sizeof(
h->slice_ctx[0]));
2819 sl = &
h->slice_ctx[context_count - 1];
2822 if (
h->postpone_filter) {
2823 h->postpone_filter = 0;
2825 for (
i = 0;
i < context_count;
i++) {
2828 sl = &
h->slice_ctx[
i];
2830 x_end = (sl->
mb_y >=
h->mb_height) ?
h->mb_width : sl->
mb_x;
2835 j == y_end - 1 ? x_end :
h->mb_width);
2842 h->nb_slice_ctx_queued = 0;