28 #ifndef AVCODEC_H264_MVPRED_H
29 #define AVCODEC_H264_MVPRED_H
40 int i,
int list,
int part_width)
47 #define SET_DIAG_MV(MV_OP, REF_OP, XY, Y4) \
48 const int xy = XY, y4 = Y4; \
49 const int mb_type = mb_types[xy + (y4 >> 2) * h->mb_stride]; \
50 if (!USES_LIST(mb_type, list)) \
51 return LIST_NOT_USED; \
52 mv = h->cur_pic_ptr->motion_val[list][h->mb2b_xy[xy] + 3 + y4 * h->b_stride]; \
53 sl->mv_cache[list][scan8[0] - 2][0] = mv[0]; \
54 sl->mv_cache[list][scan8[0] - 2][1] = mv[1] MV_OP; \
55 return h->cur_pic_ptr->ref_index[list][4 * xy + 1 + (y4 & ~1)] REF_OP;
58 &&
i >=
scan8[0] + 8 && (
i & 7) == 4
60 const uint32_t *mb_types =
h->cur_pic_ptr->mb_type;
67 (sl->
mb_y & 1) * 2 + (
i >> 5));
81 ff_tlog(
h->avctx,
"topright MV not available\n");
98 int part_width,
int list,
int ref,
99 int *
const mx,
int *
const my)
101 const int index8 =
scan8[
n];
107 int diagonal_ref, match_count;
109 av_assert2(part_width == 1 || part_width == 2 || part_width == 4);
120 match_count = (diagonal_ref ==
ref) + (top_ref ==
ref) + (left_ref ==
ref);
121 ff_tlog(
h->avctx,
"pred_motion match_count=%d\n", match_count);
122 if (match_count > 1) {
125 }
else if (match_count == 1) {
126 if (left_ref ==
ref) {
129 }
else if (top_ref ==
ref) {
149 "pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n",
150 top_ref,
B[0],
B[1], diagonal_ref,
C[0],
C[1], left_ref,
163 int *
const mx,
int *
const my)
169 ff_tlog(
h->avctx,
"pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
172 if (top_ref ==
ref) {
181 ff_tlog(
h->avctx,
"pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
184 if (left_ref ==
ref) {
204 int *
const mx,
int *
const my)
210 ff_tlog(
h->avctx,
"pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
213 if (left_ref ==
ref) {
224 ff_tlog(
h->avctx,
"pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
227 if (diagonal_ref ==
ref) {
238 #define FIX_MV_MBAFF(type, refn, mvn, idx) \
239 if (FRAME_MBAFF(h)) { \
240 if (MB_FIELD(sl)) { \
241 if (!IS_INTERLACED(type)) { \
243 AV_COPY32(mvbuf[idx], mvn); \
244 mvbuf[idx][1] /= 2; \
248 if (IS_INTERLACED(type)) { \
250 AV_COPY32(mvbuf[idx], mvn); \
251 mvbuf[idx][1] *= 2; \
262 int8_t *
ref =
h->cur_pic.ref_index[0];
263 int16_t(*
mv)[2] =
h->cur_pic.motion_val[0];
264 int top_ref, left_ref, diagonal_ref, match_count, mx, my;
265 const int16_t *
A, *
B, *
C;
266 int b_stride =
h->b_stride;
301 ff_tlog(
h->avctx,
"pred_pskip: (%d) (%d) at %2d %2d\n",
302 top_ref, left_ref, sl->
mb_x, sl->
mb_y);
327 match_count = !diagonal_ref + !top_ref + !left_ref;
328 ff_tlog(
h->avctx,
"pred_pskip_motion match_count=%d\n", match_count);
329 if (match_count > 1) {
332 }
else if (match_count == 1) {
336 }
else if (!top_ref) {
358 const int mb_xy = sl->
mb_xy;
359 int topleft_xy, top_xy, topright_xy, left_xy[
LEFT_MBS];
360 static const uint8_t left_block_options[4][32] = {
361 { 0, 1, 2, 3, 7, 10, 8, 11, 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4, 3 + 3 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 5 * 4, 1 + 9 * 4 },
362 { 2, 2, 3, 3, 8, 11, 8, 11, 3 + 2 * 4, 3 + 2 * 4, 3 + 3 * 4, 3 + 3 * 4, 1 + 5 * 4, 1 + 9 * 4, 1 + 5 * 4, 1 + 9 * 4 },
363 { 0, 0, 1, 1, 7, 10, 7, 10, 3 + 0 * 4, 3 + 0 * 4, 3 + 1 * 4, 3 + 1 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 4 * 4, 1 + 8 * 4 },
364 { 0, 2, 0, 2, 7, 10, 7, 10, 3 + 0 * 4, 3 + 2 * 4, 3 + 0 * 4, 3 + 2 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 4 * 4, 1 + 8 * 4 }
369 top_xy = mb_xy - (
h->mb_stride <<
MB_FIELD(sl));
374 topleft_xy = top_xy - 1;
375 topright_xy = top_xy + 1;
376 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy - 1;
379 const int left_mb_field_flag =
IS_INTERLACED(
h->cur_pic.mb_type[mb_xy - 1]);
382 if (left_mb_field_flag != curr_mb_field_flag) {
383 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy -
h->mb_stride - 1;
384 if (curr_mb_field_flag) {
385 left_xy[
LBOT] +=
h->mb_stride;
388 topleft_xy +=
h->mb_stride;
396 if (curr_mb_field_flag) {
397 topleft_xy +=
h->mb_stride & (((
h->cur_pic.mb_type[top_xy - 1] >> 7) & 1) - 1);
398 topright_xy +=
h->mb_stride & (((
h->cur_pic.mb_type[top_xy + 1] >> 7) & 1) - 1);
399 top_xy +=
h->mb_stride & (((
h->cur_pic.mb_type[top_xy] >> 7) & 1) - 1);
401 if (left_mb_field_flag != curr_mb_field_flag) {
402 if (curr_mb_field_flag) {
403 left_xy[
LBOT] +=
h->mb_stride;
420 sl->
top_type =
h->cur_pic.mb_type[top_xy];
426 if (
h->slice_table[topleft_xy] != sl->
slice_num)
433 if (
h->slice_table[topleft_xy] != sl->
slice_num) {
441 if (
h->slice_table[topright_xy] != sl->
slice_num)
447 int topleft_xy, top_xy, topright_xy, left_xy[
LEFT_MBS];
448 int topleft_type, top_type, topright_type, left_type[
LEFT_MBS];
467 int type_mask =
h->ps.pps->constrained_intra_pred ?
IS_INTRA(-1) : -1;
473 if (!(top_type & type_mask)) {
480 if (!(left_type[
LTOP] & type_mask)) {
484 if (!(left_type[
LBOT] & type_mask)) {
489 int left_typei =
h->cur_pic.mb_type[left_xy[
LTOP] +
h->mb_stride];
492 if (!((left_typei & type_mask) && (left_type[
LTOP] & type_mask))) {
498 if (!(left_type[
LTOP] & type_mask)) {
504 if (!(topleft_type & type_mask))
507 if (!(topright_type & type_mask))
519 for (
i = 0;
i < 2;
i++) {
544 nnz =
h->non_zero_count[top_xy];
545 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]);
546 if (!
h->chroma_y_shift) {
547 AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 7]);
548 AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]);
550 AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 5]);
551 AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 9]);
554 uint32_t top_empty =
CABAC(
h) && !
IS_INTRA(mb_type) ? 0 : 0x40404040;
555 AV_WN32A(&nnz_cache[4 + 8 * 0], top_empty);
556 AV_WN32A(&nnz_cache[4 + 8 * 5], top_empty);
557 AV_WN32A(&nnz_cache[4 + 8 * 10], top_empty);
560 for (
i = 0;
i < 2;
i++) {
561 if (left_type[
LEFT(
i)]) {
562 nnz =
h->non_zero_count[left_xy[
LEFT(
i)]];
563 nnz_cache[3 + 8 * 1 + 2 * 8 *
i] = nnz[left_block[8 + 0 + 2 *
i]];
564 nnz_cache[3 + 8 * 2 + 2 * 8 *
i] = nnz[left_block[8 + 1 + 2 *
i]];
566 nnz_cache[3 + 8 * 6 + 2 * 8 *
i] = nnz[left_block[8 + 0 + 2 *
i] + 4 * 4];
567 nnz_cache[3 + 8 * 7 + 2 * 8 *
i] = nnz[left_block[8 + 1 + 2 *
i] + 4 * 4];
568 nnz_cache[3 + 8 * 11 + 2 * 8 *
i] = nnz[left_block[8 + 0 + 2 *
i] + 8 * 4];
569 nnz_cache[3 + 8 * 12 + 2 * 8 *
i] = nnz[left_block[8 + 1 + 2 *
i] + 8 * 4];
571 nnz_cache[3 + 8 * 6 + 2 * 8 *
i] = nnz[left_block[8 + 0 + 2 *
i] - 2 + 4 * 4];
572 nnz_cache[3 + 8 * 7 + 2 * 8 *
i] = nnz[left_block[8 + 1 + 2 *
i] - 2 + 4 * 4];
573 nnz_cache[3 + 8 * 11 + 2 * 8 *
i] = nnz[left_block[8 + 0 + 2 *
i] - 2 + 8 * 4];
574 nnz_cache[3 + 8 * 12 + 2 * 8 *
i] = nnz[left_block[8 + 1 + 2 *
i] - 2 + 8 * 4];
576 nnz_cache[3 + 8 * 6 + 8 *
i] = nnz[left_block[8 + 4 + 2 *
i]];
577 nnz_cache[3 + 8 * 11 + 8 *
i] = nnz[left_block[8 + 5 + 2 *
i]];
580 nnz_cache[3 + 8 * 1 + 2 * 8 *
i] =
581 nnz_cache[3 + 8 * 2 + 2 * 8 *
i] =
582 nnz_cache[3 + 8 * 6 + 2 * 8 *
i] =
583 nnz_cache[3 + 8 * 7 + 2 * 8 *
i] =
584 nnz_cache[3 + 8 * 11 + 2 * 8 *
i] =
585 nnz_cache[3 + 8 * 12 + 2 * 8 *
i] =
CABAC(
h) && !
IS_INTRA(mb_type) ? 0 : 64;
596 if (left_type[
LTOP]) {
598 ((
h->cbp_table[left_xy[
LTOP]] >> (left_block[0] & (~1))) & 2) |
599 (((
h->cbp_table[left_xy[
LBOT]] >> (left_block[2] & (~1))) & 2) << 2);
608 int b_stride =
h->b_stride;
611 int8_t *
ref =
h->cur_pic.ref_index[
list];
613 int16_t(*
mv)[2] =
h->cur_pic.motion_val[
list];
619 const int b_xy =
h->mb2b_xy[top_xy] + 3 * b_stride;
621 ref_cache[0 - 1 * 8] =
622 ref_cache[1 - 1 * 8] =
ref[4 * top_xy + 2];
623 ref_cache[2 - 1 * 8] =
624 ref_cache[3 - 1 * 8] =
ref[4 * top_xy + 3];
632 for (
i = 0;
i < 2;
i++) {
633 int cache_idx = -1 +
i * 2 * 8;
635 const int b_xy =
h->mb2b_xy[left_xy[
LEFT(
i)]] + 3;
636 const int b8_xy = 4 * left_xy[
LEFT(
i)] + 1;
638 mv[b_xy + b_stride * left_block[0 +
i * 2]]);
640 mv[b_xy + b_stride * left_block[1 +
i * 2]]);
641 ref_cache[cache_idx] =
ref[b8_xy + (left_block[0 +
i * 2] & ~1)];
642 ref_cache[cache_idx + 8] =
ref[b8_xy + (left_block[1 +
i * 2] & ~1)];
646 ref_cache[cache_idx] =
653 const int b_xy =
h->mb2b_xy[left_xy[
LTOP]] + 3;
654 const int b8_xy = 4 * left_xy[
LTOP] + 1;
655 AV_COPY32(mv_cache[-1],
mv[b_xy + b_stride * left_block[0]]);
656 ref_cache[-1] =
ref[b8_xy + (left_block[0] & ~1)];
665 const int b_xy =
h->mb2b_xy[topright_xy] + 3 * b_stride;
667 ref_cache[4 - 1 * 8] =
ref[4 * topright_xy + 2];
673 if(ref_cache[2 - 1*8] < 0 || ref_cache[4 - 1 * 8] < 0) {
675 const int b_xy =
h->mb2b_xy[topleft_xy] + 3 + b_stride +
679 ref_cache[-1 - 1 * 8] =
ref[b8_xy];
693 ref_cache[2 + 8 * 0] =
700 const int b_xy =
h->mb2br_xy[top_xy];
701 AV_COPY64(mvd_cache[0 - 1 * 8], mvd[b_xy + 0]);
706 const int b_xy =
h->mb2br_xy[left_xy[
LTOP]] + 6;
707 AV_COPY16(mvd_cache[-1 + 0 * 8], mvd[b_xy - left_block[0]]);
708 AV_COPY16(mvd_cache[-1 + 1 * 8], mvd[b_xy - left_block[1]]);
714 const int b_xy =
h->mb2br_xy[left_xy[
LBOT]] + 6;
715 AV_COPY16(mvd_cache[-1 + 2 * 8], mvd[b_xy - left_block[2]]);
716 AV_COPY16(mvd_cache[-1 + 3 * 8], mvd[b_xy - left_block[3]]);
725 uint8_t *direct_table =
h->direct_table;
731 }
else if (
IS_8X8(top_type)) {
732 int b8_xy = 4 * top_xy;
733 direct_cache[0 - 1 * 8] = direct_table[b8_xy + 2];
734 direct_cache[2 - 1 * 8] = direct_table[b8_xy + 3];
743 direct_cache[-1 + 0 * 8] = direct_table[4 * left_xy[
LTOP] + 1 + (left_block[0] & ~1)];
750 direct_cache[-1 + 2 * 8] = direct_table[4 * left_xy[
LBOT] + 1 + (left_block[2] & ~1)];
758 MAP_F2F(scan8[0] - 1 - 1 * 8, topleft_type) \
759 MAP_F2F(scan8[0] + 0 - 1 * 8, top_type) \
760 MAP_F2F(scan8[0] + 1 - 1 * 8, top_type) \
761 MAP_F2F(scan8[0] + 2 - 1 * 8, top_type) \
762 MAP_F2F(scan8[0] + 3 - 1 * 8, top_type) \
763 MAP_F2F(scan8[0] + 4 - 1 * 8, topright_type) \
764 MAP_F2F(scan8[0] - 1 + 0 * 8, left_type[LTOP]) \
765 MAP_F2F(scan8[0] - 1 + 1 * 8, left_type[LTOP]) \
766 MAP_F2F(scan8[0] - 1 + 2 * 8, left_type[LBOT]) \
767 MAP_F2F(scan8[0] - 1 + 3 * 8, left_type[LBOT])
772 #define MAP_F2F(idx, mb_type) \
773 if (!IS_INTERLACED(mb_type) && sl->ref_cache[list][idx] >= 0) { \
774 sl->ref_cache[list][idx] *= 2; \
775 sl->mv_cache[list][idx][1] /= 2; \
776 sl->mvd_cache[list][idx][1] >>= 1; \
783 #define MAP_F2F(idx, mb_type) \
784 if (IS_INTERLACED(mb_type) && sl->ref_cache[list][idx] >= 0) { \
785 sl->ref_cache[list][idx] >>= 1; \
786 sl->mv_cache[list][idx][1] *= 2; \
787 sl->mvd_cache[list][idx][1] <<= 1; \
805 const int mb_xy = sl->
mb_xy;
808 memset(
h->non_zero_count[mb_xy], 0, 48);
830 h->cur_pic.mb_type[mb_xy] = mb_type;
831 h->cur_pic.qscale_table[mb_xy] = sl->
qscale;