28 #include "config_components.h"
53 0 + 0 * 4, 0 + 1 * 4, 1 + 0 * 4, 0 + 2 * 4,
54 0 + 3 * 4, 1 + 1 * 4, 1 + 2 * 4, 1 + 3 * 4,
55 2 + 0 * 4, 2 + 1 * 4, 2 + 2 * 4, 2 + 3 * 4,
56 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4, 3 + 3 * 4,
60 0 + 0 * 8, 0 + 1 * 8, 0 + 2 * 8, 1 + 0 * 8,
61 1 + 1 * 8, 0 + 3 * 8, 0 + 4 * 8, 1 + 2 * 8,
62 2 + 0 * 8, 1 + 3 * 8, 0 + 5 * 8, 0 + 6 * 8,
63 0 + 7 * 8, 1 + 4 * 8, 2 + 1 * 8, 3 + 0 * 8,
64 2 + 2 * 8, 1 + 5 * 8, 1 + 6 * 8, 1 + 7 * 8,
65 2 + 3 * 8, 3 + 1 * 8, 4 + 0 * 8, 3 + 2 * 8,
66 2 + 4 * 8, 2 + 5 * 8, 2 + 6 * 8, 2 + 7 * 8,
67 3 + 3 * 8, 4 + 1 * 8, 5 + 0 * 8, 4 + 2 * 8,
68 3 + 4 * 8, 3 + 5 * 8, 3 + 6 * 8, 3 + 7 * 8,
69 4 + 3 * 8, 5 + 1 * 8, 6 + 0 * 8, 5 + 2 * 8,
70 4 + 4 * 8, 4 + 5 * 8, 4 + 6 * 8, 4 + 7 * 8,
71 5 + 3 * 8, 6 + 1 * 8, 6 + 2 * 8, 5 + 4 * 8,
72 5 + 5 * 8, 5 + 6 * 8, 5 + 7 * 8, 6 + 3 * 8,
73 7 + 0 * 8, 7 + 1 * 8, 6 + 4 * 8, 6 + 5 * 8,
74 6 + 6 * 8, 6 + 7 * 8, 7 + 2 * 8, 7 + 3 * 8,
75 7 + 4 * 8, 7 + 5 * 8, 7 + 6 * 8, 7 + 7 * 8,
79 0 + 0 * 8, 1 + 1 * 8, 2 + 0 * 8, 0 + 7 * 8,
80 2 + 2 * 8, 2 + 3 * 8, 2 + 4 * 8, 3 + 3 * 8,
81 3 + 4 * 8, 4 + 3 * 8, 4 + 4 * 8, 5 + 3 * 8,
82 5 + 5 * 8, 7 + 0 * 8, 6 + 6 * 8, 7 + 4 * 8,
83 0 + 1 * 8, 0 + 3 * 8, 1 + 3 * 8, 1 + 4 * 8,
84 1 + 5 * 8, 3 + 1 * 8, 2 + 5 * 8, 4 + 1 * 8,
85 3 + 5 * 8, 5 + 1 * 8, 4 + 5 * 8, 6 + 1 * 8,
86 5 + 6 * 8, 7 + 1 * 8, 6 + 7 * 8, 7 + 5 * 8,
87 0 + 2 * 8, 0 + 4 * 8, 0 + 5 * 8, 2 + 1 * 8,
88 1 + 6 * 8, 4 + 0 * 8, 2 + 6 * 8, 5 + 0 * 8,
89 3 + 6 * 8, 6 + 0 * 8, 4 + 6 * 8, 6 + 2 * 8,
90 5 + 7 * 8, 6 + 4 * 8, 7 + 2 * 8, 7 + 6 * 8,
91 1 + 0 * 8, 1 + 2 * 8, 0 + 6 * 8, 3 + 0 * 8,
92 1 + 7 * 8, 3 + 2 * 8, 2 + 7 * 8, 4 + 2 * 8,
93 3 + 7 * 8, 5 + 2 * 8, 4 + 7 * 8, 5 + 4 * 8,
94 6 + 3 * 8, 6 + 5 * 8, 7 + 3 * 8, 7 + 7 * 8,
99 0 + 0 * 8, 1 + 1 * 8, 1 + 2 * 8, 2 + 2 * 8,
100 4 + 1 * 8, 0 + 5 * 8, 3 + 3 * 8, 7 + 0 * 8,
101 3 + 4 * 8, 1 + 7 * 8, 5 + 3 * 8, 6 + 3 * 8,
102 2 + 7 * 8, 6 + 4 * 8, 5 + 6 * 8, 7 + 5 * 8,
103 1 + 0 * 8, 2 + 0 * 8, 0 + 3 * 8, 3 + 1 * 8,
104 3 + 2 * 8, 0 + 6 * 8, 4 + 2 * 8, 6 + 1 * 8,
105 2 + 5 * 8, 2 + 6 * 8, 6 + 2 * 8, 5 + 4 * 8,
106 3 + 7 * 8, 7 + 3 * 8, 4 + 7 * 8, 7 + 6 * 8,
107 0 + 1 * 8, 3 + 0 * 8, 0 + 4 * 8, 4 + 0 * 8,
108 2 + 3 * 8, 1 + 5 * 8, 5 + 1 * 8, 5 + 2 * 8,
109 1 + 6 * 8, 3 + 5 * 8, 7 + 1 * 8, 4 + 5 * 8,
110 4 + 6 * 8, 7 + 4 * 8, 5 + 7 * 8, 6 + 7 * 8,
111 0 + 2 * 8, 2 + 1 * 8, 1 + 3 * 8, 5 + 0 * 8,
112 1 + 4 * 8, 2 + 4 * 8, 6 + 0 * 8, 4 + 3 * 8,
113 0 + 7 * 8, 4 + 4 * 8, 7 + 2 * 8, 3 + 6 * 8,
114 5 + 5 * 8, 6 + 5 * 8, 6 + 6 * 8, 7 + 7 * 8,
123 if (
h->DPB[
i].f->buf[0] && !
h->DPB[
i].reference &&
124 (remove_current || &
h->DPB[
i] !=
h->cur_pic_ptr)) {
141 h->mb_width * 16 * 3 *
sizeof(uint8_t) * 2);
143 h->mb_width * 16 * 3 *
sizeof(uint8_t) * 2);
164 const int big_mb_num =
h->mb_stride * (
h->mb_height + 1) + 1;
165 const int mb_array_size =
h->mb_stride *
h->mb_height;
166 const int b4_stride =
h->mb_width * 4 + 1;
167 const int b4_array_size = b4_stride *
h->mb_height * 4;
171 sizeof(uint32_t), 0);
176 if (!
h->qscale_table_pool || !
h->mb_type_pool || !
h->motion_val_pool ||
177 !
h->ref_index_pool) {
194 if (
h->sei.common.itut_t35.lcevc) {
219 if (
h->decode_error_flags_pool) {
227 int h_chroma_shift, v_chroma_shift;
229 &h_chroma_shift, &v_chroma_shift);
239 if (!
h->qscale_table_pool) {
253 for (
i = 0;
i < 2;
i++) {
279 if (!
h->DPB[
i].f->buf[0])
286 #define IN_RANGE(a, b, size) (((void*)(a) >= (void*)(b)) && ((void*)(a) < (void*)((b) + (size))))
288 #define REBASE_PICTURE(pic, new_ctx, old_ctx) \
289 (((pic) && (pic) >= (old_ctx)->DPB && \
290 (pic) < (old_ctx)->DPB + H264_MAX_PICTURE_COUNT) ? \
291 &(new_ctx)->DPB[(pic) - (old_ctx)->DPB] : NULL)
298 for (
i = 0;
i < count;
i++) {
312 for (
int p = 0;
p <
desc->nb_components;
p++) {
314 int is_chroma =
p == 1 ||
p == 2;
317 if (
desc->comp[0].depth >= 9) {
319 ((uint16_t*)
dst)[0] =
c[
p];
323 for (
int y = 1; y <
height; y++) {
328 for (
int y = 0; y <
height; y++) {
329 memset(
dst,
c[
p], bytes);
342 int inited =
h->context_initialized, err = 0;
349 if (inited && !h1->ps.sps)
353 (
h->width != h1->width ||
354 h->height != h1->height ||
355 h->mb_width != h1->mb_width ||
356 h->mb_height != h1->mb_height ||
358 h->ps.sps->bit_depth_luma != h1->ps.sps->bit_depth_luma ||
359 h->ps.sps->chroma_format_idc != h1->ps.sps->chroma_format_idc ||
360 h->ps.sps->vui.matrix_coeffs != h1->ps.sps->vui.matrix_coeffs)) {
365 memcpy(
h->block_offset, h1->block_offset,
sizeof(
h->block_offset));
374 h->ps.sps = h1->ps.sps;
376 if (need_reinit || !inited) {
377 h->width = h1->width;
378 h->height = h1->height;
379 h->mb_height = h1->mb_height;
380 h->mb_width = h1->mb_width;
381 h->mb_num = h1->mb_num;
382 h->mb_stride = h1->mb_stride;
383 h->b_stride = h1->b_stride;
384 h->x264_build = h1->x264_build;
386 if (
h->context_initialized || h1->context_initialized) {
394 memcpy(
h->block_offset, h1->block_offset,
sizeof(
h->block_offset));
397 h->width_from_caller = h1->width_from_caller;
398 h->height_from_caller = h1->height_from_caller;
399 h->first_field = h1->first_field;
400 h->picture_structure = h1->picture_structure;
401 h->mb_aff_frame = h1->mb_aff_frame;
402 h->droppable = h1->droppable;
415 h->enable_er = h1->enable_er;
416 h->workaround_bugs = h1->workaround_bugs;
417 h->droppable = h1->droppable;
420 h->is_avc = h1->is_avc;
421 h->nal_length_size = h1->nal_length_size;
423 memcpy(&
h->poc, &h1->poc,
sizeof(
h->poc));
425 memcpy(
h->short_ref, h1->short_ref,
sizeof(
h->short_ref));
426 memcpy(
h->long_ref, h1->long_ref,
sizeof(
h->long_ref));
427 memcpy(
h->delayed_pic, h1->delayed_pic,
sizeof(
h->delayed_pic));
428 memcpy(
h->last_pocs, h1->last_pocs,
sizeof(
h->last_pocs));
430 h->next_output_pic = h1->next_output_pic;
431 h->next_outputed_poc = h1->next_outputed_poc;
432 h->poc_offset = h1->poc_offset;
434 memcpy(
h->mmco, h1->mmco,
sizeof(
h->mmco));
435 h->nb_mmco = h1->nb_mmco;
436 h->mmco_reset = h1->mmco_reset;
437 h->explicit_ref_marking = h1->explicit_ref_marking;
438 h->long_ref_count = h1->long_ref_count;
439 h->short_ref_count = h1->short_ref_count;
446 h->frame_recovered = h1->frame_recovered;
452 h->sei.common.unregistered.x264_build = h1->sei.common.unregistered.x264_build;
459 h->poc.prev_poc_msb =
h->poc.poc_msb;
460 h->poc.prev_poc_lsb =
h->poc.poc_lsb;
462 h->poc.prev_frame_num_offset =
h->poc.frame_num_offset;
463 h->poc.prev_frame_num =
h->poc.frame_num;
465 h->recovery_frame = h1->recovery_frame;
466 h->non_gray = h1->non_gray;
487 const int pixel_shift =
h->pixel_shift;
495 h->cur_pic_ptr =
NULL;
504 pic->
reference =
h->droppable ? 0 :
h->picture_structure;
526 h->sei.common.film_grain_characteristics &&
527 h->sei.common.film_grain_characteristics->present &&
528 !
h->avctx->hwaccel &&
534 h->cur_pic_ptr = pic;
536 if (CONFIG_ERROR_RESILIENCE) {
543 for (
i = 0;
i <
h->nb_slice_ctx;
i++) {
544 h->slice_ctx[
i].linesize =
h->cur_pic_ptr->f->linesize[0];
545 h->slice_ctx[
i].uvlinesize =
h->cur_pic_ptr->f->linesize[1];
548 if (CONFIG_ERROR_RESILIENCE &&
h->enable_er) {
554 for (
i = 0;
i < 16;
i++) {
558 for (
i = 0;
i < 16;
i++) {
559 h->block_offset[16 +
i] =
561 h->block_offset[48 + 16 +
i] =
569 h->cur_pic_ptr->reference = 0;
571 h->cur_pic_ptr->field_poc[0] =
h->cur_pic_ptr->field_poc[1] = INT_MAX;
573 h->next_output_pic =
NULL;
575 h->postpone_filter = 0;
577 h->mb_aff_frame =
h->ps.sps->mb_aff && (
h->picture_structure ==
PICT_FRAME);
579 if (
h->sei.common.unregistered.x264_build >= 0)
580 h->x264_build =
h->sei.common.unregistered.x264_build;
582 assert(
h->cur_pic_ptr->long_ref == 0);
588 const uint8_t *src_y,
589 const uint8_t *src_cb,
const uint8_t *src_cr,
590 int linesize,
int uvlinesize,
595 const int pixel_shift =
h->pixel_shift;
600 src_cb -= uvlinesize;
601 src_cr -= uvlinesize;
607 AV_COPY128(top_border, src_y + 15 * linesize);
609 AV_COPY128(top_border + 16, src_y + 15 * linesize + 16);
613 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
614 AV_COPY128(top_border + 48, src_cb + 15 * uvlinesize + 16);
615 AV_COPY128(top_border + 64, src_cr + 15 * uvlinesize);
616 AV_COPY128(top_border + 80, src_cr + 15 * uvlinesize + 16);
618 AV_COPY128(top_border + 16, src_cb + 15 * uvlinesize);
619 AV_COPY128(top_border + 32, src_cr + 15 * uvlinesize);
621 }
else if (chroma422) {
623 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
624 AV_COPY128(top_border + 48, src_cr + 15 * uvlinesize);
626 AV_COPY64(top_border + 16, src_cb + 15 * uvlinesize);
627 AV_COPY64(top_border + 24, src_cr + 15 * uvlinesize);
631 AV_COPY128(top_border + 32, src_cb + 7 * uvlinesize);
632 AV_COPY128(top_border + 48, src_cr + 7 * uvlinesize);
634 AV_COPY64(top_border + 16, src_cb + 7 * uvlinesize);
635 AV_COPY64(top_border + 24, src_cr + 7 * uvlinesize);
649 AV_COPY128(top_border, src_y + 16 * linesize);
651 AV_COPY128(top_border + 16, src_y + 16 * linesize + 16);
656 AV_COPY128(top_border + 32, src_cb + 16 * linesize);
657 AV_COPY128(top_border + 48, src_cb + 16 * linesize + 16);
658 AV_COPY128(top_border + 64, src_cr + 16 * linesize);
659 AV_COPY128(top_border + 80, src_cr + 16 * linesize + 16);
661 AV_COPY128(top_border + 16, src_cb + 16 * linesize);
662 AV_COPY128(top_border + 32, src_cr + 16 * linesize);
664 }
else if (chroma422) {
666 AV_COPY128(top_border + 32, src_cb + 16 * uvlinesize);
667 AV_COPY128(top_border + 48, src_cr + 16 * uvlinesize);
669 AV_COPY64(top_border + 16, src_cb + 16 * uvlinesize);
670 AV_COPY64(top_border + 24, src_cr + 16 * uvlinesize);
674 AV_COPY128(top_border + 32, src_cb + 8 * uvlinesize);
675 AV_COPY128(top_border + 48, src_cr + 8 * uvlinesize);
677 AV_COPY64(top_border + 16, src_cb + 8 * uvlinesize);
678 AV_COPY64(top_border + 24, src_cr + 8 * uvlinesize);
691 int ref0, ref1,
i, cur_poc, ref_start, ref_count0, ref_count1;
693 for (
i = 0;
i < 2;
i++) {
700 cur_poc =
h->cur_pic_ptr->poc;
702 cur_poc =
h->cur_pic_ptr->field_poc[
h->picture_structure - 1];
714 cur_poc =
h->cur_pic_ptr->field_poc[
field];
725 for (ref0 = ref_start; ref0 < ref_count0; ref0++) {
727 for (ref1 = ref_start; ref1 < ref_count1; ref1++) {
734 int tx = (16384 + (
FFABS(td) >> 1)) / td;
735 int dist_scale_factor = (tb * tx + 32) >> 8;
736 if (dist_scale_factor >= -64 && dist_scale_factor <= 128)
737 w = 64 - dist_scale_factor;
756 for (
i = 0;
i < 16;
i++) {
757 #define TRANSPOSE(x) ((x) >> 2) | (((x) << 2) & 0xF)
762 for (
i = 0;
i < 64;
i++) {
763 #define TRANSPOSE(x) ((x) >> 3) | (((x) & 7) << 3)
770 if (
h->ps.sps->transform_bypass) {
774 memcpy(
h->field_scan_q0 ,
field_scan ,
sizeof(
h->field_scan_q0 ));
775 memcpy(
h->field_scan8x8_q0 ,
field_scan8x8 ,
sizeof(
h->field_scan8x8_q0 ));
778 memcpy(
h->zigzag_scan_q0 ,
h->zigzag_scan ,
sizeof(
h->zigzag_scan_q0 ));
779 memcpy(
h->zigzag_scan8x8_q0 ,
h->zigzag_scan8x8 ,
sizeof(
h->zigzag_scan8x8_q0 ));
780 memcpy(
h->zigzag_scan8x8_cavlc_q0 ,
h->zigzag_scan8x8_cavlc ,
sizeof(
h->zigzag_scan8x8_cavlc_q0));
781 memcpy(
h->field_scan_q0 ,
h->field_scan ,
sizeof(
h->field_scan_q0 ));
782 memcpy(
h->field_scan8x8_q0 ,
h->field_scan8x8 ,
sizeof(
h->field_scan8x8_q0 ));
783 memcpy(
h->field_scan8x8_cavlc_q0 ,
h->field_scan8x8_cavlc ,
sizeof(
h->field_scan8x8_cavlc_q0 ));
789 #define HWACCEL_MAX (CONFIG_H264_DXVA2_HWACCEL + \
790 (CONFIG_H264_D3D11VA_HWACCEL * 2) + \
791 CONFIG_H264_D3D12VA_HWACCEL + \
792 CONFIG_H264_NVDEC_HWACCEL + \
793 CONFIG_H264_NVDEC_CUARRAY_HWACCEL + \
794 CONFIG_H264_VAAPI_HWACCEL + \
795 CONFIG_H264_VIDEOTOOLBOX_HWACCEL + \
796 CONFIG_H264_VDPAU_HWACCEL + \
797 CONFIG_H264_VULKAN_HWACCEL)
800 switch (
h->ps.sps->bit_depth_luma) {
813 #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL
817 #if CONFIG_H264_VULKAN_HWACCEL
820 #if CONFIG_H264_NVDEC_HWACCEL
823 #if CONFIG_H264_NVDEC_CUARRAY_HWACCEL
834 #if CONFIG_H264_VAAPI_HWACCEL
844 #if CONFIG_H264_VULKAN_HWACCEL
869 #if CONFIG_H264_VDPAU_HWACCEL
872 #if CONFIG_H264_VULKAN_HWACCEL
875 #if CONFIG_H264_NVDEC_HWACCEL
878 #if CONFIG_H264_NVDEC_CUARRAY_HWACCEL
881 #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL
898 #if CONFIG_H264_DXVA2_HWACCEL
901 #if CONFIG_H264_D3D11VA_HWACCEL
905 #if CONFIG_H264_D3D12VA_HWACCEL
908 #if CONFIG_H264_VAAPI_HWACCEL
919 "Unsupported bit depth %d\n",
h->ps.sps->bit_depth_luma);
926 if (
pix_fmts[
i] ==
h->avctx->pix_fmt && !force_callback)
935 int cr =
sps->crop_right;
936 int cl =
sps->crop_left;
937 int ct =
sps->crop_top;
938 int cb =
sps->crop_bottom;
945 if (
h->width_from_caller > 0 &&
h->height_from_caller > 0 &&
946 !
sps->crop_top && !
sps->crop_left &&
949 h->width_from_caller <=
width &&
950 h->height_from_caller <=
height) {
951 width =
h->width_from_caller;
952 height =
h->height_from_caller;
958 h->width_from_caller = 0;
959 h->height_from_caller = 0;
962 h->avctx->coded_width =
h->width;
963 h->avctx->coded_height =
h->height;
984 &
h->chroma_x_shift, &
h->chroma_y_shift);
986 if (
sps->timing_info_present_flag) {
988 if (
h->x264_build < 44
U)
990 av_reduce(&
h->avctx->framerate.den, &
h->avctx->framerate.num,
991 sps->num_units_in_tick * 2, den, 1 << 30);
997 h->prev_interlaced_frame = 1;
1006 if (
sps->bit_depth_luma < 8 ||
sps->bit_depth_luma > 14 ||
1007 sps->bit_depth_luma == 11 ||
sps->bit_depth_luma == 13
1010 sps->bit_depth_luma);
1015 h->cur_bit_depth_luma =
1016 h->avctx->bits_per_raw_sample =
sps->bit_depth_luma;
1017 h->cur_chroma_format_idc =
sps->chroma_format_idc;
1018 h->pixel_shift =
sps->bit_depth_luma > 8;
1019 h->chroma_format_idc =
sps->chroma_format_idc;
1020 h->bit_depth_luma =
sps->bit_depth_luma;
1023 sps->chroma_format_idc);
1027 sps->chroma_format_idc);
1033 for (
i = 0;
i <
h->nb_slice_ctx;
i++) {
1038 sl->
mvd_table[0] =
h->mvd_table[0] +
i * 8 * 2 *
h->mb_stride;
1039 sl->
mvd_table[1] =
h->mvd_table[1] +
i * 8 * 2 *
h->mb_stride;
1045 h->context_initialized = 1;
1050 h->context_initialized = 0;
1068 int needs_reinit = 0, must_reinit,
ret;
1073 if (
h->ps.sps !=
h->ps.pps->sps) {
1074 h->ps.sps =
h->ps.pps->sps;
1076 if (
h->mb_width !=
h->ps.sps->mb_width ||
1077 h->mb_height !=
h->ps.sps->mb_height ||
1078 h->cur_bit_depth_luma !=
h->ps.sps->bit_depth_luma ||
1079 h->cur_chroma_format_idc !=
h->ps.sps->chroma_format_idc
1083 if (
h->bit_depth_luma !=
h->ps.sps->bit_depth_luma ||
1084 h->chroma_format_idc !=
h->ps.sps->chroma_format_idc)
1089 must_reinit = (
h->context_initialized &&
1090 ( 16*
sps->mb_width !=
h->avctx->coded_width
1091 || 16*
sps->mb_height !=
h->avctx->coded_height
1092 ||
h->cur_bit_depth_luma !=
sps->bit_depth_luma
1093 ||
h->cur_chroma_format_idc !=
sps->chroma_format_idc
1094 ||
h->mb_width !=
sps->mb_width
1095 ||
h->mb_height !=
sps->mb_height
1101 if (first_slice &&
av_cmp_q(
sps->vui.sar,
h->avctx->sample_aspect_ratio))
1104 if (!
h->setup_finished) {
1106 h->avctx->level =
sps->level_idc;
1107 h->avctx->refs =
sps->ref_frame_count;
1109 h->mb_width =
sps->mb_width;
1110 h->mb_height =
sps->mb_height;
1111 h->mb_num =
h->mb_width *
h->mb_height;
1112 h->mb_stride =
h->mb_width + 1;
1114 h->b_stride =
h->mb_width * 4;
1116 h->chroma_y_shift =
sps->chroma_format_idc <= 1;
1118 h->width = 16 *
h->mb_width;
1119 h->height = 16 *
h->mb_height;
1123 if (
sps->vui.video_signal_type_present_flag) {
1126 if (
sps->vui.colour_description_present_flag) {
1127 if (
h->avctx->colorspace !=
sps->vui.matrix_coeffs)
1129 h->avctx->color_primaries =
sps->vui.colour_primaries;
1130 h->avctx->color_trc =
sps->vui.transfer_characteristics;
1131 h->avctx->colorspace =
sps->vui.matrix_coeffs;
1135 if (
h->sei.common.alternative_transfer.present &&
1138 h->avctx->color_trc =
h->sei.common.alternative_transfer.preferred_transfer_characteristics;
1141 h->avctx->chroma_sample_location =
sps->vui.chroma_location;
1143 if (!
h->context_initialized || must_reinit || needs_reinit) {
1144 int flush_changes =
h->context_initialized;
1145 h->context_initialized = 0;
1146 if (sl !=
h->slice_ctx) {
1148 "changing width %d -> %d / height %d -> %d on "
1150 h->width,
h->avctx->coded_width,
1151 h->height,
h->avctx->coded_height,
1152 h->current_slice + 1);
1163 h->avctx->pix_fmt =
ret;
1170 "h264_slice_header_init() failed\n");
1183 int interlaced_frame = 0, top_field_first = 0;
1187 out->repeat_pict = 0;
1192 if (
h->sei.picture_timing.present) {
1199 h->sei.picture_timing.present = 0;
1203 if (
sps->pic_struct_present_flag &&
h->sei.picture_timing.present) {
1205 switch (
pt->pic_struct) {
1210 interlaced_frame = 1;
1215 interlaced_frame = 1;
1218 interlaced_frame = !!
h->prev_interlaced_frame;
1225 out->repeat_pict = 1;
1228 out->repeat_pict = 2;
1231 out->repeat_pict = 4;
1235 if ((
pt->ct_type & 3) &&
1237 interlaced_frame = ((
pt->ct_type & (1 << 1)) != 0);
1242 h->prev_interlaced_frame = interlaced_frame;
1248 if (
sps->pic_struct_present_flag &&
h->sei.picture_timing.present) {
1253 top_field_first = 1;
1254 }
else if (interlaced_frame) {
1257 top_field_first = 1;
1266 &
sps->vui,
sps->bit_depth_luma,
sps->bit_depth_chroma,
1267 cur->
poc + (
unsigned)(
h->poc_offset << 5));
1271 if (
h->sei.picture_timing.timecode_cnt > 0) {
1276 sizeof(uint32_t)*4, &tcside);
1281 tc_sd = (uint32_t*)tcside->
data;
1282 tc_sd[0] =
h->sei.picture_timing.timecode_cnt;
1284 for (
int i = 0;
i < tc_sd[0];
i++) {
1285 int drop =
h->sei.picture_timing.timecode[
i].dropframe;
1286 int hh =
h->sei.picture_timing.timecode[
i].hours;
1287 int mm =
h->sei.picture_timing.timecode[
i].minutes;
1288 int ss =
h->sei.picture_timing.timecode[
i].seconds;
1289 int ff =
h->sei.picture_timing.timecode[
i].frame;
1296 h->sei.picture_timing.timecode_cnt = 0;
1307 int i, pics, out_of_order, out_idx;
1312 if (
sps->bitstream_restriction_flag ||
1314 h->avctx->has_b_frames =
FFMAX(
h->avctx->has_b_frames,
sps->num_reorder_frames);
1317 for (
i = 0; 1;
i++) {
1320 h->last_pocs[
i-1] = cur->
poc;
1323 h->last_pocs[
i-1]=
h->last_pocs[
i];
1329 out_of_order =
FFMAX(out_of_order, 1);
1333 h->last_pocs[
i] = INT_MIN;
1334 h->last_pocs[0] = cur->
poc;
1336 }
else if(
h->avctx->has_b_frames < out_of_order && !
sps->bitstream_restriction_flag){
1338 av_log(
h->avctx, loglevel,
"Increasing reorder buffer to %d\n", out_of_order);
1339 h->avctx->has_b_frames = out_of_order;
1343 while (
h->delayed_pic[pics])
1348 h->delayed_pic[pics++] = cur;
1352 out =
h->delayed_pic[0];
1354 for (
i = 1;
h->delayed_pic[
i] &&
1356 !
h->delayed_pic[
i]->mmco_reset;
1358 if (
h->delayed_pic[
i]->poc <
out->poc) {
1359 out =
h->delayed_pic[
i];
1362 if (
h->avctx->has_b_frames == 0 &&
1364 h->next_outputed_poc = INT_MIN;
1365 out_of_order =
out->poc <
h->next_outputed_poc;
1367 if (out_of_order || pics >
h->avctx->has_b_frames) {
1369 for (
i = out_idx;
h->delayed_pic[
i];
i++)
1370 h->delayed_pic[
i] =
h->delayed_pic[
i + 1];
1372 if (!out_of_order && pics >
h->avctx->has_b_frames) {
1373 h->next_output_pic =
out;
1374 if (out_idx == 0 &&
h->delayed_pic[0] && ((
h->delayed_pic[0]->f->flags &
AV_FRAME_FLAG_KEY) ||
h->delayed_pic[0]->mmco_reset)) {
1375 h->next_outputed_poc = INT_MIN;
1377 h->next_outputed_poc =
out->poc;
1381 h->frame_recovered |=
out->recovered;
1385 if (!
out->recovered) {
1388 h->next_output_pic =
NULL;
1410 int last_pic_structure, last_pic_droppable,
ret;
1418 if (
sps->bitstream_restriction_flag &&
1419 h->avctx->has_b_frames <
sps->num_reorder_frames) {
1420 h->avctx->has_b_frames =
sps->num_reorder_frames;
1423 last_pic_droppable =
h->droppable;
1424 last_pic_structure =
h->picture_structure;
1425 h->droppable = (
nal->ref_idc == 0);
1436 else if (
h->picture_intra_only)
1441 if (
h->poc.frame_num !=
h->poc.prev_frame_num) {
1442 int unwrap_prev_frame_num =
h->poc.prev_frame_num;
1443 int max_frame_num = 1 <<
sps->log2_max_frame_num;
1445 if (unwrap_prev_frame_num >
h->poc.frame_num)
1446 unwrap_prev_frame_num -= max_frame_num;
1448 if ((
h->poc.frame_num - unwrap_prev_frame_num) >
sps->ref_frame_count) {
1449 unwrap_prev_frame_num = (
h->poc.frame_num -
sps->ref_frame_count) - 1;
1450 if (unwrap_prev_frame_num < 0)
1451 unwrap_prev_frame_num += max_frame_num;
1453 h->poc.prev_frame_num = unwrap_prev_frame_num;
1462 if (
h->first_field) {
1469 if (
h->cur_pic_ptr->tf.owner[last_field] ==
h->avctx) {
1474 if (!
FIELD_PICTURE(
h) ||
h->picture_structure == last_pic_structure) {
1482 if (
h->cur_pic_ptr->frame_num !=
h->poc.frame_num) {
1498 "Invalid field mode combination %d/%d\n",
1499 last_pic_structure,
h->picture_structure);
1500 h->picture_structure = last_pic_structure;
1501 h->droppable = last_pic_droppable;
1503 }
else if (last_pic_droppable !=
h->droppable) {
1505 "Found reference and non-reference fields in the same frame, which");
1506 h->picture_structure = last_pic_structure;
1507 h->droppable = last_pic_droppable;
1514 while (
h->poc.frame_num !=
h->poc.prev_frame_num && !
h->first_field &&
1515 h->poc.frame_num != (
h->poc.prev_frame_num + 1) % (1 <<
sps->log2_max_frame_num)) {
1518 h->poc.frame_num,
h->poc.prev_frame_num);
1519 if (!
sps->gaps_in_frame_num_allowed_flag)
1521 h->last_pocs[
i] = INT_MIN;
1528 h->poc.prev_frame_num++;
1529 h->poc.prev_frame_num %= 1 <<
sps->log2_max_frame_num;
1530 h->cur_pic_ptr->frame_num =
h->poc.prev_frame_num;
1531 h->cur_pic_ptr->invalid_gap = !
sps->gaps_in_frame_num_allowed_flag;
1535 h->explicit_ref_marking = 0;
1546 if (
h->short_ref_count) {
1548 1<<(
h->ps.sps->bit_depth_luma-1),
1549 1<<(
h->ps.sps->bit_depth_chroma-1),
1550 1<<(
h->ps.sps->bit_depth_chroma-1),
1555 h->short_ref[0]->f->width == prev->
f->
width &&
1556 h->short_ref[0]->f->height == prev->
f->
height &&
1557 h->short_ref[0]->f->format == prev->
f->
format) {
1562 h->short_ref[0]->tf.f =
h->short_ref[0]->f;
1566 h->short_ref[0]->poc = prev->
poc + 2
U;
1567 h->short_ref[0]->gray = prev->
gray;
1569 if (
h->short_ref[0]->field_picture)
1571 }
else if (!
h->frame_recovered) {
1572 if (!
h->avctx->hwaccel)
1574 h->short_ref[0]->gray = 1;
1576 h->short_ref[0]->frame_num =
h->poc.prev_frame_num;
1583 if (
h->first_field) {
1589 if (!
FIELD_PICTURE(
h) ||
h->picture_structure == last_pic_structure) {
1592 h->missing_fields ++;
1593 h->cur_pic_ptr =
NULL;
1596 h->missing_fields = 0;
1597 if (
h->cur_pic_ptr->frame_num !=
h->poc.frame_num) {
1604 h->cur_pic_ptr =
NULL;
1610 h->cur_pic_ptr =
NULL;
1629 h->cur_pic_ptr->tf.owner[
field] =
h->avctx;
1635 memset(
h->slice_table +
i*
h->mb_stride, -1, (
h->mb_stride - (
i+1==
h->mb_height)) *
sizeof(*
h->slice_table));
1637 memset(
h->slice_table, -1,
1638 (
h->mb_height *
h->mb_stride - 1) *
sizeof(*
h->slice_table));
1642 h->ps.sps, &
h->poc,
h->picture_structure,
nal->ref_idc);
1652 if (
h->sei.recovery_point.recovery_frame_cnt >= 0) {
1653 const int sei_recovery_frame_cnt =
h->sei.recovery_point.recovery_frame_cnt;
1656 h->valid_recovery_point = 1;
1658 if (
h->recovery_frame < 0
1659 ||
av_zero_extend(
h->recovery_frame -
h->poc.frame_num,
h->ps.sps->log2_max_frame_num) > sei_recovery_frame_cnt) {
1660 h->recovery_frame =
av_zero_extend(
h->poc.frame_num + sei_recovery_frame_cnt,
h->ps.sps->log2_max_frame_num);
1662 if (!
h->valid_recovery_point)
1663 h->recovery_frame =
h->poc.frame_num;
1676 if (
h->recovery_frame ==
h->poc.frame_num &&
nal->ref_idc) {
1677 h->recovery_frame = -1;
1682 h->cur_pic_ptr->recovered |=
h->frame_recovered;
1709 unsigned int slice_type,
tmp,
i;
1710 int field_pic_flag, bottom_field_flag;
1711 int first_slice = sl ==
h->slice_ctx && !
h->current_slice;
1712 int picture_structure;
1720 if (slice_type > 9) {
1722 "slice type %d too large at %d\n",
1726 if (slice_type > 4) {
1747 if (!
h->ps.pps_list[sl->
pps_id]) {
1749 "non-existing PPS %u referenced\n",
1767 if (
sps->frame_mbs_only_flag) {
1771 av_log(
h->avctx,
AV_LOG_ERROR,
"This stream was generated by a broken encoder, invalid 8x8 inference\n");
1775 if (field_pic_flag) {
1795 if (idr_pic_id < 65536) {
1803 if (
sps->poc_type == 0) {
1806 if (
pps->pic_order_present == 1 && picture_structure ==
PICT_FRAME)
1811 if (
sps->poc_type == 1 && !
sps->delta_pic_order_always_zero_flag) {
1814 if (
pps->pic_order_present == 1 && picture_structure ==
PICT_FRAME)
1819 if (
pps->redundant_pic_cnt_present)
1827 picture_structure,
h->avctx);
1840 for (
i = 0;
i < 2;
i++) {
1845 (
pps->weighted_bipred_idc == 1 &&
1849 picture_structure,
h->avctx);
1872 if (
tmp > 51 + 6 * (
sps->bit_depth_luma - 8)) {
1889 if (
pps->deblocking_filter_parameters_present) {
1893 "deblocking_filter_idc %u out of range\n",
tmp);
1903 if (slice_alpha_c0_offset_div2 > 6 ||
1904 slice_alpha_c0_offset_div2 < -6 ||
1905 slice_beta_offset_div2 > 6 ||
1906 slice_beta_offset_div2 < -6) {
1908 "deblocking filter parameters %d %d out of range\n",
1909 slice_alpha_c0_offset_div2, slice_beta_offset_div2);
1949 if (
h->ps.pps->weighted_bipred_idc == 2 &&
1979 h->postpone_filter = 1;
1985 h->ps.pps->chroma_qp_index_offset[0],
1986 h->ps.pps->chroma_qp_index_offset[1]) +
1987 6 * (
h->ps.sps->bit_depth_luma - 8);
1990 if (
h->current_slice >= 0xFFFE) {
2006 for (j = 0; j < 2; j++) {
2009 for (
i = 0;
i < 16;
i++) {
2011 if (j < sl->list_count && i < sl->ref_count[j] &&
2015 for (k = 0; k <
h->short_ref_count; k++)
2016 if (
h->short_ref[k]->f->buf[0]->buffer == buf) {
2020 for (k = 0; k <
h->long_ref_count; k++)
2021 if (
h->long_ref[k] &&
h->long_ref[k]->f->buf[0]->buffer == buf) {
2022 id_list[
i] =
h->short_ref_count + k;
2030 for (
i = 0;
i < 16;
i++)
2033 ref2frm[18 + 1] = -1;
2034 for (
i = 16;
i < 48;
i++)
2035 ref2frm[
i + 4] = 4 * id_list[(
i - 16) >> 1] +
2040 h->cur_pic_ptr->gray = 0;
2049 h->cur_pic_ptr->gray =
gray;
2054 "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",
2062 h->cur_pic_ptr->field_poc[0],
2063 h->cur_pic_ptr->field_poc[1],
2079 int first_slice = sl ==
h->slice_ctx && !
h->current_slice;
2095 if (
h->setup_finished) {
2102 if (
h->current_slice) {
2105 if (
h->nb_slice_ctx_queued) {
2112 memcpy(&tmp_ctx,
h->slice_ctx,
sizeof(tmp_ctx));
2113 memcpy(
h->slice_ctx, sl,
sizeof(tmp_ctx));
2114 memcpy(sl, &tmp_ctx,
sizeof(tmp_ctx));
2127 h->cur_pic_ptr =
NULL;
2134 if (!
h->first_field) {
2135 if (
h->cur_pic_ptr && !
h->droppable) {
2139 h->cur_pic_ptr =
NULL;
2143 if (!
h->current_slice)
2146 if (
h->current_slice == 0 && !
h->first_field) {
2160 if (
h->ps.pps->sps_id !=
pps->sps_id ||
2161 h->ps.pps->transform_8x8_mode !=
pps->transform_8x8_mode
2166 if (
h->ps.sps !=
pps->sps) {
2168 "SPS changed in the middle of the frame\n");
2173 if (
h->current_slice == 0) {
2179 h->droppable != (
nal->ref_idc == 0)) {
2181 "Changing field mode (%d -> %d) between slices is not allowed\n",
2184 }
else if (!
h->cur_pic_ptr) {
2186 "unset cur_pic_ptr on slice %d\n",
2187 h->current_slice + 1);
2196 h->nb_slice_ctx_queued++;
2221 int mb_type,
int top_xy,
2225 int mb_xy,
int list)
2227 int b_stride =
h->b_stride;
2232 const int b_xy =
h->mb2b_xy[top_xy] + 3 * b_stride;
2233 const int b8_xy = 4 * top_xy + 2;
2236 ref_cache[0 - 1 * 8] =
2237 ref_cache[1 - 1 * 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 0]];
2238 ref_cache[2 - 1 * 8] =
2239 ref_cache[3 - 1 * 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 1]];
2247 const int b_xy =
h->mb2b_xy[left_xy[
LTOP]] + 3;
2248 const int b8_xy = 4 * left_xy[
LTOP] + 1;
2250 AV_COPY32(mv_dst - 1 + 0,
h->cur_pic.motion_val[
list][b_xy + b_stride * 0]);
2251 AV_COPY32(mv_dst - 1 + 8,
h->cur_pic.motion_val[
list][b_xy + b_stride * 1]);
2252 AV_COPY32(mv_dst - 1 + 16,
h->cur_pic.motion_val[
list][b_xy + b_stride * 2]);
2253 AV_COPY32(mv_dst - 1 + 24,
h->cur_pic.motion_val[
list][b_xy + b_stride * 3]);
2255 ref_cache[-1 + 8] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 2 * 0]];
2256 ref_cache[-1 + 16] =
2257 ref_cache[-1 + 24] = ref2frm[
h->cur_pic.ref_index[
list][b8_xy + 2 * 1]];
2265 ref_cache[-1 + 16] =
2281 const int8_t *
ref = &
h->cur_pic.ref_index[
list][4 * mb_xy];
2283 uint32_t ref01 = (
pack16to32(ref2frm[
ref[0]], ref2frm[
ref[1]]) & 0x00FF00FF) * 0x0101;
2284 uint32_t ref23 = (
pack16to32(ref2frm[
ref[2]], ref2frm[
ref[3]]) & 0x00FF00FF) * 0x0101;
2285 AV_WN32A(&ref_cache[0 * 8], ref01);
2286 AV_WN32A(&ref_cache[1 * 8], ref01);
2287 AV_WN32A(&ref_cache[2 * 8], ref23);
2288 AV_WN32A(&ref_cache[3 * 8], ref23);
2292 int16_t(*mv_src)[2] = &
h->cur_pic.motion_val[
list][4 * sl->
mb_x + 4 * sl->
mb_y * b_stride];
2293 AV_COPY128(mv_dst + 8 * 0, mv_src + 0 * b_stride);
2294 AV_COPY128(mv_dst + 8 * 1, mv_src + 1 * b_stride);
2295 AV_COPY128(mv_dst + 8 * 2, mv_src + 2 * b_stride);
2296 AV_COPY128(mv_dst + 8 * 3, mv_src + 3 * b_stride);
2305 const int mb_xy = sl->
mb_xy;
2311 top_xy = mb_xy - (
h->mb_stride <<
MB_FIELD(sl));
2313 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy - 1;
2315 const int left_mb_field_flag =
IS_INTERLACED(
h->cur_pic.mb_type[mb_xy - 1]);
2318 if (left_mb_field_flag != curr_mb_field_flag)
2319 left_xy[
LTOP] -=
h->mb_stride;
2321 if (curr_mb_field_flag)
2322 top_xy +=
h->mb_stride &
2323 (((
h->cur_pic.mb_type[top_xy] >> 7) & 1) - 1);
2324 if (left_mb_field_flag != curr_mb_field_flag)
2325 left_xy[
LBOT] +=
h->mb_stride;
2337 int qp =
h->cur_pic.qscale_table[mb_xy];
2338 if (qp <= qp_thresh &&
2339 (left_xy[
LTOP] < 0 ||
2340 ((qp +
h->cur_pic.qscale_table[left_xy[
LTOP]] + 1) >> 1) <= qp_thresh) &&
2342 ((qp +
h->cur_pic.qscale_table[top_xy] + 1) >> 1) <= qp_thresh)) {
2345 if ((left_xy[
LTOP] < 0 ||
2346 ((qp +
h->cur_pic.qscale_table[left_xy[
LBOT]] + 1) >> 1) <= qp_thresh) &&
2347 (top_xy <
h->mb_stride ||
2348 ((qp +
h->cur_pic.qscale_table[top_xy -
h->mb_stride] + 1) >> 1) <= qp_thresh))
2353 top_type =
h->cur_pic.mb_type[top_xy];
2354 left_type[
LTOP] =
h->cur_pic.mb_type[left_xy[
LTOP]];
2355 left_type[
LBOT] =
h->cur_pic.mb_type[left_xy[
LBOT]];
2360 left_type[
LTOP] = left_type[
LBOT] = 0;
2362 if (
h->slice_table[top_xy] == 0xFFFF)
2364 if (
h->slice_table[left_xy[
LBOT]] == 0xFFFF)
2365 left_type[
LTOP] = left_type[
LBOT] = 0;
2375 top_type, left_type, mb_xy, 0);
2378 top_type, left_type, mb_xy, 1);
2380 nnz =
h->non_zero_count[mb_xy];
2382 AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]);
2383 AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]);
2384 AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]);
2385 AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]);
2386 sl->
cbp =
h->cbp_table[mb_xy];
2389 nnz =
h->non_zero_count[top_xy];
2390 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[3 * 4]);
2393 if (left_type[
LTOP]) {
2394 nnz =
h->non_zero_count[left_xy[
LTOP]];
2395 nnz_cache[3 + 8 * 1] = nnz[3 + 0 * 4];
2396 nnz_cache[3 + 8 * 2] = nnz[3 + 1 * 4];
2397 nnz_cache[3 + 8 * 3] = nnz[3 + 2 * 4];
2398 nnz_cache[3 + 8 * 4] = nnz[3 + 3 * 4];
2403 if (!
CABAC(
h) &&
h->ps.pps->transform_8x8_mode) {
2405 nnz_cache[4 + 8 * 0] =
2406 nnz_cache[5 + 8 * 0] = (
h->cbp_table[top_xy] & 0x4000) >> 12;
2407 nnz_cache[6 + 8 * 0] =
2408 nnz_cache[7 + 8 * 0] = (
h->cbp_table[top_xy] & 0x8000) >> 12;
2411 nnz_cache[3 + 8 * 1] =
2412 nnz_cache[3 + 8 * 2] = (
h->cbp_table[left_xy[
LTOP]] & 0x2000) >> 12;
2415 nnz_cache[3 + 8 * 3] =
2416 nnz_cache[3 + 8 * 4] = (
h->cbp_table[left_xy[
LBOT]] & 0x8000) >> 12;
2420 nnz_cache[
scan8[0]] =
2421 nnz_cache[
scan8[1]] =
2422 nnz_cache[
scan8[2]] =
2423 nnz_cache[
scan8[3]] = (sl->
cbp & 0x1000) >> 12;
2425 nnz_cache[
scan8[0 + 4]] =
2426 nnz_cache[
scan8[1 + 4]] =
2427 nnz_cache[
scan8[2 + 4]] =
2428 nnz_cache[
scan8[3 + 4]] = (sl->
cbp & 0x2000) >> 12;
2430 nnz_cache[
scan8[0 + 8]] =
2431 nnz_cache[
scan8[1 + 8]] =
2432 nnz_cache[
scan8[2 + 8]] =
2433 nnz_cache[
scan8[3 + 8]] = (sl->
cbp & 0x4000) >> 12;
2435 nnz_cache[
scan8[0 + 12]] =
2436 nnz_cache[
scan8[1 + 12]] =
2437 nnz_cache[
scan8[2 + 12]] =
2438 nnz_cache[
scan8[3 + 12]] = (sl->
cbp & 0x8000) >> 12;
2447 uint8_t *dest_y, *dest_cb, *dest_cr;
2448 int linesize, uvlinesize, mb_x, mb_y;
2451 const int pixel_shift =
h->pixel_shift;
2452 const int block_h = 16 >>
h->chroma_y_shift;
2454 if (
h->postpone_filter)
2458 for (mb_x = start_x; mb_x < end_x; mb_x++)
2459 for (mb_y = end_mb_y -
FRAME_MBAFF(
h); mb_y <= end_mb_y; mb_y++) {
2461 mb_xy = sl->
mb_xy = mb_x + mb_y *
h->mb_stride;
2462 mb_type =
h->cur_pic.mb_type[mb_xy];
2470 dest_y =
h->cur_pic.f->data[0] +
2471 ((mb_x << pixel_shift) + mb_y * sl->
linesize) * 16;
2472 dest_cb =
h->cur_pic.f->data[1] +
2473 (mb_x << pixel_shift) * (8 <<
CHROMA444(
h)) +
2475 dest_cr =
h->cur_pic.f->data[2] +
2476 (mb_x << pixel_shift) * (8 <<
CHROMA444(
h)) +
2501 linesize, uvlinesize);
2504 dest_cr, linesize, uvlinesize);
2517 const int mb_xy = sl->
mb_x + sl->
mb_y *
h->mb_stride;
2518 int mb_type = (
h->slice_table[mb_xy - 1] == sl->
slice_num) ?
2519 h->cur_pic.mb_type[mb_xy - 1] :
2520 (
h->slice_table[mb_xy -
h->mb_stride] == sl->
slice_num) ?
2521 h->cur_pic.mb_type[mb_xy -
h->mb_stride] : 0;
2536 if ((top +
height) >= pic_height)
2537 height += deblock_border;
2538 top -= deblock_border;
2541 if (top >= pic_height || (top +
height) < 0)
2552 if (
h->droppable ||
h->er.error_occurred)
2560 int startx,
int starty,
2561 int endx,
int endy,
int status)
2566 if (CONFIG_ERROR_RESILIENCE) {
2575 int lf_x_start = sl->
mb_x;
2579 sl->
linesize =
h->cur_pic_ptr->f->linesize[0];
2590 if (
h->postpone_filter)
2606 if (
h->ps.pps->cabac) {
2650 if (sl->
mb_x >= lf_x_start)
2658 "error while decoding MB %d %d, bytestream %td\n",
2666 if (++sl->
mb_x >=
h->mb_width) {
2668 sl->
mb_x = lf_x_start = 0;
2678 if (eos || sl->
mb_y >=
h->mb_height) {
2679 ff_tlog(
h->avctx,
"slice end %d %d\n",
2683 if (sl->
mb_x > lf_x_start)
2717 "error while decoding MB %d %d\n", sl->
mb_x, sl->
mb_y);
2723 if (++sl->
mb_x >=
h->mb_width) {
2725 sl->
mb_x = lf_x_start = 0;
2733 if (sl->
mb_y >=
h->mb_height) {
2734 ff_tlog(
h->avctx,
"slice end %d %d\n",
2753 ff_tlog(
h->avctx,
"slice end %d %d\n",
2759 if (sl->
mb_x > lf_x_start)
2787 int context_count =
h->nb_slice_ctx_queued;
2791 h->slice_ctx[0].next_slice_idx = INT_MAX;
2793 if (
h->avctx->hwaccel || context_count < 1)
2796 av_assert0(context_count &&
h->slice_ctx[context_count - 1].mb_y <
h->mb_height);
2798 if (context_count == 1) {
2800 h->slice_ctx[0].next_slice_idx =
h->mb_width *
h->mb_height;
2801 h->postpone_filter = 0;
2804 h->mb_y =
h->slice_ctx[0].mb_y;
2809 for (
i = 0;
i < context_count;
i++) {
2810 int next_slice_idx =
h->mb_width *
h->mb_height;
2813 sl = &
h->slice_ctx[
i];
2816 slice_idx = sl->
mb_y *
h->mb_width + sl->
mb_x;
2817 for (j = 0; j < context_count; j++) {
2819 int slice_idx2 = sl2->
mb_y *
h->mb_width + sl2->
mb_x;
2821 if (
i == j || slice_idx2 < slice_idx)
2823 next_slice_idx =
FFMIN(next_slice_idx, slice_idx2);
2829 NULL, context_count,
sizeof(
h->slice_ctx[0]));
2832 sl = &
h->slice_ctx[context_count - 1];
2835 if (
h->postpone_filter) {
2836 h->postpone_filter = 0;
2838 for (
i = 0;
i < context_count;
i++) {
2841 sl = &
h->slice_ctx[
i];
2843 x_end = (sl->
mb_y >=
h->mb_height) ?
h->mb_width : sl->
mb_x;
2848 j == y_end - 1 ? x_end :
h->mb_width);
2855 h->nb_slice_ctx_queued = 0;