28 #ifndef AVCODEC_H264_MVPRED_H
29 #define AVCODEC_H264_MVPRED_H
38 int i,
int list,
int part_width)
40 const int topright_ref = h->
ref_cache[list][i - 8 + part_width];
46 #define SET_DIAG_MV(MV_OP, REF_OP, XY, Y4) \
47 const int xy = XY, y4 = Y4; \
48 const int mb_type = mb_types[xy + (y4 >> 2) * s->mb_stride]; \
49 if (!USES_LIST(mb_type, list)) \
50 return LIST_NOT_USED; \
51 mv = s->current_picture_ptr->f.motion_val[list][h->mb2b_xy[xy] + 3 + y4 * h->b_stride]; \
52 h->mv_cache[list][scan8[0] - 2][0] = mv[0]; \
53 h->mv_cache[list][scan8[0] - 2][1] = mv[1] MV_OP; \
54 return s->current_picture_ptr->f.ref_index[list][4 * xy + 1 + (y4 & ~1)] REF_OP;
57 && i >=
scan8[0] + 8 && (i & 7) == 4
66 (s->
mb_y & 1) * 2 + (i >> 5));
77 *C = h->
mv_cache[list][i - 8 + part_width];
95 int part_width,
int list,
int ref,
96 int *
const mx,
int *
const my)
98 const int index8 =
scan8[n];
99 const int top_ref = h->
ref_cache[list][index8 - 8];
100 const int left_ref = h->
ref_cache[list][index8 - 1];
101 const int16_t *
const A = h->
mv_cache[list][index8 - 1];
102 const int16_t *
const B = h->
mv_cache[list][index8 - 8];
104 int diagonal_ref, match_count;
106 av_assert2(part_width == 1 || part_width == 2 || part_width == 4);
117 match_count = (diagonal_ref == ref) + (top_ref == ref) + (left_ref == ref);
118 tprintf(h->
s.
avctx,
"pred_motion match_count=%d\n", match_count);
119 if (match_count > 1) {
122 }
else if (match_count == 1) {
123 if (left_ref == ref) {
126 }
else if (top_ref == ref) {
146 "pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n",
147 top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref,
148 A[0], A[1], ref, *mx, *my, h->
s.
mb_x, h->
s.
mb_y, n, list);
158 int n,
int list,
int ref,
159 int *
const mx,
int *
const my)
165 tprintf(h->
s.
avctx,
"pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
166 top_ref, B[0], B[1], h->
s.
mb_x, h->
s.
mb_y, n, list);
168 if (top_ref == ref) {
177 tprintf(h->
s.
avctx,
"pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
178 left_ref, A[0], A[1], h->
s.
mb_x, h->
s.
mb_y, n, list);
180 if (left_ref == ref) {
198 int n,
int list,
int ref,
199 int *
const mx,
int *
const my)
205 tprintf(h->
s.
avctx,
"pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
206 left_ref, A[0], A[1], h->
s.
mb_x, h->
s.
mb_y, n, list);
208 if (left_ref == ref) {
219 tprintf(h->
s.
avctx,
"pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
220 diagonal_ref, C[0], C[1], h->
s.
mb_x, h->
s.
mb_y, n, list);
222 if (diagonal_ref == ref) {
233 #define FIX_MV_MBAFF(type, refn, mvn, idx) \
236 if (!IS_INTERLACED(type)) { \
238 AV_COPY32(mvbuf[idx], mvn); \
239 mvbuf[idx][1] /= 2; \
243 if (IS_INTERLACED(type)) { \
245 AV_COPY32(mvbuf[idx], mvn); \
246 mvbuf[idx][1] <<= 1; \
259 int top_ref, left_ref, diagonal_ref, match_count, mx, my;
260 const int16_t *
A, *
B, *
C;
322 match_count = !diagonal_ref + !top_ref + !left_ref;
323 tprintf(h->
s.
avctx,
"pred_pskip_motion match_count=%d\n", match_count);
324 if (match_count > 1) {
327 }
else if (match_count == 1) {
331 }
else if (!top_ref) {
354 const int mb_xy = h->
mb_xy;
355 int topleft_xy, top_xy, topright_xy, left_xy[
LEFT_MBS];
356 static const uint8_t left_block_options[4][32] = {
357 { 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 },
358 { 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 },
359 { 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 },
360 { 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 }
370 topleft_xy = top_xy - 1;
371 topright_xy = top_xy + 1;
372 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy - 1;
378 if (left_mb_field_flag != curr_mb_field_flag) {
380 if (curr_mb_field_flag) {
392 if (curr_mb_field_flag) {
397 if (left_mb_field_flag != curr_mb_field_flag) {
398 if (curr_mb_field_flag) {
444 int topleft_xy, top_xy, topright_xy, left_xy[
LEFT_MBS];
445 int topleft_type, top_type, topright_type, left_type[
LEFT_MBS];
470 if (!(top_type & type_mask)) {
477 if (!(left_type[LTOP] & type_mask)) {
481 if (!(left_type[
LBOT] & type_mask)) {
489 if (!((left_typei & type_mask) && (left_type[LTOP] & type_mask))) {
495 if (!(left_type[LTOP] & type_mask)) {
501 if (!(topleft_type & type_mask))
504 if (!(topright_type & type_mask))
516 for (i = 0; i < 2; i++) {
542 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]);
544 AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 7]);
545 AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]);
547 AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 5]);
548 AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 9]);
551 uint32_t top_empty =
CABAC && !
IS_INTRA(mb_type) ? 0 : 0x40404040;
552 AV_WN32A(&nnz_cache[4 + 8 * 0], top_empty);
553 AV_WN32A(&nnz_cache[4 + 8 * 5], top_empty);
554 AV_WN32A(&nnz_cache[4 + 8 * 10], top_empty);
557 for (i = 0; i < 2; i++) {
558 if (left_type[
LEFT(i)]) {
560 nnz_cache[3 + 8 * 1 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i]];
561 nnz_cache[3 + 8 * 2 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i]];
563 nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 4 * 4];
564 nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 4 * 4];
565 nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 8 * 4];
566 nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 8 * 4];
568 nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 4 * 4];
569 nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 4 * 4];
570 nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 8 * 4];
571 nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 8 * 4];
573 nnz_cache[3 + 8 * 6 + 8 * i] = nnz[left_block[8 + 4 + 2 * i]];
574 nnz_cache[3 + 8 * 11 + 8 * i] = nnz[left_block[8 + 5 + 2 * i]];
577 nnz_cache[3 + 8 * 1 + 2 * 8 * i] =
578 nnz_cache[3 + 8 * 2 + 2 * 8 * i] =
579 nnz_cache[3 + 8 * 6 + 2 * 8 * i] =
580 nnz_cache[3 + 8 * 7 + 2 * 8 * i] =
581 nnz_cache[3 + 8 * 11 + 2 * 8 * i] =
582 nnz_cache[3 + 8 * 12 + 2 * 8 * i] =
CABAC && !
IS_INTRA(mb_type) ? 0 : 64;
593 if (left_type[
LTOP]) {
595 ((h->
cbp_table[left_xy[LTOP]] >> (left_block[0] & (~1))) & 2) |
596 (((h->
cbp_table[left_xy[
LBOT]] >> (left_block[2] & (~1))) & 2) << 2);
606 for (list = 0; list < h->
list_count; list++) {
616 const int b_xy = h->
mb2b_xy[top_xy] + 3 * b_stride;
618 ref_cache[0 - 1 * 8] =
619 ref_cache[1 - 1 * 8] = ref[4 * top_xy + 2];
620 ref_cache[2 - 1 * 8] =
621 ref_cache[3 - 1 * 8] = ref[4 * top_xy + 3];
629 for (i = 0; i < 2; i++) {
630 int cache_idx = -1 + i * 2 * 8;
633 const int b8_xy = 4 * left_xy[
LEFT(i)] + 1;
635 mv[b_xy + b_stride * left_block[0 + i * 2]]);
637 mv[b_xy + b_stride * left_block[1 + i * 2]]);
638 ref_cache[cache_idx] = ref[b8_xy + (left_block[0 + i * 2] & ~1)];
639 ref_cache[cache_idx + 8] = ref[b8_xy + (left_block[1 + i * 2] & ~1)];
643 ref_cache[cache_idx] =
651 const int b8_xy = 4 * left_xy[
LTOP] + 1;
652 AV_COPY32(mv_cache[-1],
mv[b_xy + b_stride * left_block[0]]);
653 ref_cache[-1] = ref[b8_xy + (left_block[0] & ~1)];
662 const int b_xy = h->
mb2b_xy[topright_xy] + 3 * b_stride;
664 ref_cache[4 - 1 * 8] = ref[4 * topright_xy + 2];
670 if(ref_cache[2 - 1*8] < 0 || ref_cache[4 - 1*8] < 0){
672 const int b_xy = h->
mb2b_xy[topleft_xy] + 3 + b_stride +
676 ref_cache[-1 - 1 * 8] = ref[b8_xy];
690 ref_cache[2 + 8 * 0] =
697 const int b_xy = h->
mb2br_xy[top_xy];
698 AV_COPY64(mvd_cache[0 - 1 * 8], mvd[b_xy + 0]);
704 AV_COPY16(mvd_cache[-1 + 0 * 8], mvd[b_xy - left_block[0]]);
705 AV_COPY16(mvd_cache[-1 + 1 * 8], mvd[b_xy - left_block[1]]);
712 AV_COPY16(mvd_cache[-1 + 2 * 8], mvd[b_xy - left_block[2]]);
713 AV_COPY16(mvd_cache[-1 + 3 * 8], mvd[b_xy - left_block[3]]);
728 }
else if (
IS_8X8(top_type)) {
729 int b8_xy = 4 * top_xy;
730 direct_cache[0 - 1 * 8] = direct_table[b8_xy + 2];
731 direct_cache[2 - 1 * 8] = direct_table[b8_xy + 3];
739 else if (
IS_8X8(left_type[LTOP]))
740 direct_cache[-1 + 0 * 8] = direct_table[4 * left_xy[
LTOP] + 1 + (left_block[0] & ~1)];
746 else if (
IS_8X8(left_type[LBOT]))
747 direct_cache[-1 + 2 * 8] = direct_table[4 * left_xy[LBOT] + 1 + (left_block[2] & ~1)];
755 MAP_F2F(scan8[0] - 1 - 1 * 8, topleft_type) \
756 MAP_F2F(scan8[0] + 0 - 1 * 8, top_type) \
757 MAP_F2F(scan8[0] + 1 - 1 * 8, top_type) \
758 MAP_F2F(scan8[0] + 2 - 1 * 8, top_type) \
759 MAP_F2F(scan8[0] + 3 - 1 * 8, top_type) \
760 MAP_F2F(scan8[0] + 4 - 1 * 8, topright_type) \
761 MAP_F2F(scan8[0] - 1 + 0 * 8, left_type[LTOP]) \
762 MAP_F2F(scan8[0] - 1 + 1 * 8, left_type[LTOP]) \
763 MAP_F2F(scan8[0] - 1 + 2 * 8, left_type[LBOT]) \
764 MAP_F2F(scan8[0] - 1 + 3 * 8, left_type[LBOT])
769 #define MAP_F2F(idx, mb_type) \
770 if (!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \
771 h->ref_cache[list][idx] <<= 1; \
772 h->mv_cache[list][idx][1] /= 2; \
773 h->mvd_cache[list][idx][1] >>= 1; \
780 #define MAP_F2F(idx, mb_type) \
781 if (IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \
782 h->ref_cache[list][idx] >>= 1; \
783 h->mv_cache[list][idx][1] <<= 1; \
784 h->mvd_cache[list][idx][1] <<= 1; \
803 const int mb_xy = h->
mb_xy;