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];
45 #define SET_DIAG_MV(MV_OP, REF_OP, XY, Y4) \
46 const int xy = XY, y4 = Y4; \
47 const int mb_type = mb_types[xy + (y4 >> 2) * h->mb_stride]; \
48 if (!USES_LIST(mb_type, list)) \
49 return LIST_NOT_USED; \
50 mv = h->cur_pic_ptr->f.motion_val[list][h->mb2b_xy[xy] + 3 + y4 * h->b_stride]; \
51 h->mv_cache[list][scan8[0] - 2][0] = mv[0]; \
52 h->mv_cache[list][scan8[0] - 2][1] = mv[1] MV_OP; \
53 return h->cur_pic_ptr->f.ref_index[list][4 * xy + 1 + (y4 & ~1)] REF_OP;
56 && i >=
scan8[0] + 8 && (i & 7) == 4
65 (h->
mb_y & 1) * 2 + (i >> 5));
76 *C = h->
mv_cache[list][i - 8 + part_width];
94 int part_width,
int list,
int ref,
95 int *
const mx,
int *
const my)
97 const int index8 =
scan8[n];
98 const int top_ref = h->
ref_cache[list][index8 - 8];
99 const int left_ref = h->
ref_cache[list][index8 - 1];
100 const int16_t *
const A = h->
mv_cache[list][index8 - 1];
101 const int16_t *
const B = h->
mv_cache[list][index8 - 8];
103 int diagonal_ref, match_count;
105 av_assert2(part_width == 1 || part_width == 2 || part_width == 4);
116 match_count = (diagonal_ref == ref) + (top_ref == ref) + (left_ref == ref);
117 tprintf(h->
avctx,
"pred_motion match_count=%d\n", match_count);
118 if (match_count > 1) {
121 }
else if (match_count == 1) {
122 if (left_ref == ref) {
125 }
else if (top_ref == ref) {
145 "pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n",
146 top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref,
147 A[0], A[1], ref, *mx, *my, h->
mb_x, h->
mb_y, n, list);
157 int n,
int list,
int ref,
158 int *
const mx,
int *
const my)
164 tprintf(h->
avctx,
"pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
165 top_ref, B[0], B[1], h->
mb_x, h->
mb_y, n, list);
167 if (top_ref == ref) {
176 tprintf(h->
avctx,
"pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
177 left_ref, A[0], A[1], h->
mb_x, h->
mb_y, n, list);
179 if (left_ref == ref) {
197 int n,
int list,
int ref,
198 int *
const mx,
int *
const my)
204 tprintf(h->
avctx,
"pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
205 left_ref, A[0], A[1], h->
mb_x, h->
mb_y, n, list);
207 if (left_ref == ref) {
218 tprintf(h->
avctx,
"pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
219 diagonal_ref, C[0], C[1], h->
mb_x, h->
mb_y, n, list);
221 if (diagonal_ref == ref) {
232 #define FIX_MV_MBAFF(type, refn, mvn, idx) \
235 if (!IS_INTERLACED(type)) { \
237 AV_COPY32(mvbuf[idx], mvn); \
238 mvbuf[idx][1] /= 2; \
242 if (IS_INTERLACED(type)) { \
244 AV_COPY32(mvbuf[idx], mvn); \
245 mvbuf[idx][1] <<= 1; \
257 int top_ref, left_ref, diagonal_ref, match_count, mx, my;
258 const int16_t *
A, *
B, *
C;
295 top_ref, left_ref, h->
mb_x, h->
mb_y);
320 match_count = !diagonal_ref + !top_ref + !left_ref;
321 tprintf(h->
avctx,
"pred_pskip_motion match_count=%d\n", match_count);
322 if (match_count > 1) {
325 }
else if (match_count == 1) {
329 }
else if (!top_ref) {
351 const int mb_xy = h->
mb_xy;
352 int topleft_xy, top_xy, topright_xy, left_xy[
LEFT_MBS];
353 static const uint8_t left_block_options[4][32] = {
354 { 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 },
355 { 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 },
356 { 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 },
357 { 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 }
367 topleft_xy = top_xy - 1;
368 topright_xy = top_xy + 1;
369 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy - 1;
375 if (left_mb_field_flag != curr_mb_field_flag) {
377 if (curr_mb_field_flag) {
389 if (curr_mb_field_flag) {
394 if (left_mb_field_flag != curr_mb_field_flag) {
395 if (curr_mb_field_flag) {
440 int topleft_xy, top_xy, topright_xy, left_xy[
LEFT_MBS];
441 int topleft_type, top_type, topright_type, left_type[
LEFT_MBS];
466 if (!(top_type & type_mask)) {
473 if (!(left_type[LTOP] & type_mask)) {
477 if (!(left_type[
LBOT] & type_mask)) {
485 if (!((left_typei & type_mask) && (left_type[LTOP] & type_mask))) {
491 if (!(left_type[LTOP] & type_mask)) {
497 if (!(topleft_type & type_mask))
500 if (!(topright_type & type_mask))
512 for (i = 0; i < 2; i++) {
538 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]);
540 AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 7]);
541 AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]);
543 AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 5]);
544 AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 9]);
547 uint32_t top_empty =
CABAC && !
IS_INTRA(mb_type) ? 0 : 0x40404040;
548 AV_WN32A(&nnz_cache[4 + 8 * 0], top_empty);
549 AV_WN32A(&nnz_cache[4 + 8 * 5], top_empty);
550 AV_WN32A(&nnz_cache[4 + 8 * 10], top_empty);
553 for (i = 0; i < 2; i++) {
554 if (left_type[
LEFT(i)]) {
556 nnz_cache[3 + 8 * 1 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i]];
557 nnz_cache[3 + 8 * 2 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i]];
559 nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 4 * 4];
560 nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 4 * 4];
561 nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 8 * 4];
562 nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 8 * 4];
564 nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 4 * 4];
565 nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 4 * 4];
566 nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 8 * 4];
567 nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 8 * 4];
569 nnz_cache[3 + 8 * 6 + 8 * i] = nnz[left_block[8 + 4 + 2 * i]];
570 nnz_cache[3 + 8 * 11 + 8 * i] = nnz[left_block[8 + 5 + 2 * i]];
573 nnz_cache[3 + 8 * 1 + 2 * 8 * i] =
574 nnz_cache[3 + 8 * 2 + 2 * 8 * i] =
575 nnz_cache[3 + 8 * 6 + 2 * 8 * i] =
576 nnz_cache[3 + 8 * 7 + 2 * 8 * i] =
577 nnz_cache[3 + 8 * 11 + 2 * 8 * i] =
578 nnz_cache[3 + 8 * 12 + 2 * 8 * i] =
CABAC && !
IS_INTRA(mb_type) ? 0 : 64;
589 if (left_type[
LTOP]) {
591 ((h->
cbp_table[left_xy[LTOP]] >> (left_block[0] & (~1))) & 2) |
592 (((h->
cbp_table[left_xy[
LBOT]] >> (left_block[2] & (~1))) & 2) << 2);
602 for (list = 0; list < h->
list_count; list++) {
612 const int b_xy = h->
mb2b_xy[top_xy] + 3 * b_stride;
614 ref_cache[0 - 1 * 8] =
615 ref_cache[1 - 1 * 8] = ref[4 * top_xy + 2];
616 ref_cache[2 - 1 * 8] =
617 ref_cache[3 - 1 * 8] = ref[4 * top_xy + 3];
625 for (i = 0; i < 2; i++) {
626 int cache_idx = -1 + i * 2 * 8;
629 const int b8_xy = 4 * left_xy[
LEFT(i)] + 1;
631 mv[b_xy + b_stride * left_block[0 + i * 2]]);
633 mv[b_xy + b_stride * left_block[1 + i * 2]]);
634 ref_cache[cache_idx] = ref[b8_xy + (left_block[0 + i * 2] & ~1)];
635 ref_cache[cache_idx + 8] = ref[b8_xy + (left_block[1 + i * 2] & ~1)];
639 ref_cache[cache_idx] =
647 const int b8_xy = 4 * left_xy[
LTOP] + 1;
648 AV_COPY32(mv_cache[-1],
mv[b_xy + b_stride * left_block[0]]);
649 ref_cache[-1] = ref[b8_xy + (left_block[0] & ~1)];
658 const int b_xy = h->
mb2b_xy[topright_xy] + 3 * b_stride;
660 ref_cache[4 - 1 * 8] = ref[4 * topright_xy + 2];
666 if(ref_cache[2 - 1*8] < 0 || ref_cache[4 - 1*8] < 0){
668 const int b_xy = h->
mb2b_xy[topleft_xy] + 3 + b_stride +
672 ref_cache[-1 - 1 * 8] = ref[b8_xy];
686 ref_cache[2 + 8 * 0] =
693 const int b_xy = h->
mb2br_xy[top_xy];
694 AV_COPY64(mvd_cache[0 - 1 * 8], mvd[b_xy + 0]);
700 AV_COPY16(mvd_cache[-1 + 0 * 8], mvd[b_xy - left_block[0]]);
701 AV_COPY16(mvd_cache[-1 + 1 * 8], mvd[b_xy - left_block[1]]);
708 AV_COPY16(mvd_cache[-1 + 2 * 8], mvd[b_xy - left_block[2]]);
709 AV_COPY16(mvd_cache[-1 + 3 * 8], mvd[b_xy - left_block[3]]);
724 }
else if (
IS_8X8(top_type)) {
725 int b8_xy = 4 * top_xy;
726 direct_cache[0 - 1 * 8] = direct_table[b8_xy + 2];
727 direct_cache[2 - 1 * 8] = direct_table[b8_xy + 3];
735 else if (
IS_8X8(left_type[LTOP]))
736 direct_cache[-1 + 0 * 8] = direct_table[4 * left_xy[
LTOP] + 1 + (left_block[0] & ~1)];
742 else if (
IS_8X8(left_type[LBOT]))
743 direct_cache[-1 + 2 * 8] = direct_table[4 * left_xy[LBOT] + 1 + (left_block[2] & ~1)];
751 MAP_F2F(scan8[0] - 1 - 1 * 8, topleft_type) \
752 MAP_F2F(scan8[0] + 0 - 1 * 8, top_type) \
753 MAP_F2F(scan8[0] + 1 - 1 * 8, top_type) \
754 MAP_F2F(scan8[0] + 2 - 1 * 8, top_type) \
755 MAP_F2F(scan8[0] + 3 - 1 * 8, top_type) \
756 MAP_F2F(scan8[0] + 4 - 1 * 8, topright_type) \
757 MAP_F2F(scan8[0] - 1 + 0 * 8, left_type[LTOP]) \
758 MAP_F2F(scan8[0] - 1 + 1 * 8, left_type[LTOP]) \
759 MAP_F2F(scan8[0] - 1 + 2 * 8, left_type[LBOT]) \
760 MAP_F2F(scan8[0] - 1 + 3 * 8, left_type[LBOT])
765 #define MAP_F2F(idx, mb_type) \
766 if (!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \
767 h->ref_cache[list][idx] <<= 1; \
768 h->mv_cache[list][idx][1] /= 2; \
769 h->mvd_cache[list][idx][1] >>= 1; \
776 #define MAP_F2F(idx, mb_type) \
777 if (IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \
778 h->ref_cache[list][idx] >>= 1; \
779 h->mv_cache[list][idx][1] <<= 1; \
780 h->mvd_cache[list][idx][1] <<= 1; \
798 const int mb_xy = h->
mb_xy;