28 #ifndef AVCODEC_H264_MVPRED_H
29 #define AVCODEC_H264_MVPRED_H
39 int i,
int list,
int part_width)
41 const int topright_ref = h->
ref_cache[list][i - 8 + 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) * s->mb_stride]; \
50 if (!USES_LIST(mb_type, list)) \
51 return LIST_NOT_USED; \
52 mv = s->current_picture_ptr->f.motion_val[list][h->mb2b_xy[xy] + 3 + y4 * h->b_stride]; \
53 h->mv_cache[list][scan8[0] - 2][0] = mv[0]; \
54 h->mv_cache[list][scan8[0] - 2][1] = mv[1] MV_OP; \
55 return s->current_picture_ptr->f.ref_index[list][4 * xy + 1 + (y4 & ~1)] REF_OP;
58 && i >=
scan8[0] + 8 && (i & 7) == 4
67 (s->
mb_y & 1) * 2 + (i >> 5));
78 *C = h->
mv_cache[list][i - 8 + part_width];
96 int part_width,
int list,
int ref,
97 int *
const mx,
int *
const my)
99 const int index8 =
scan8[n];
100 const int top_ref = h->
ref_cache[list][index8 - 8];
101 const int left_ref = h->
ref_cache[list][index8 - 1];
102 const int16_t *
const A = h->
mv_cache[list][index8 - 1];
103 const int16_t *
const B = h->
mv_cache[list][index8 - 8];
105 int diagonal_ref, match_count;
107 assert(part_width == 1 || part_width == 2 || part_width == 4);
118 match_count = (diagonal_ref == ref) + (top_ref == ref) + (left_ref == ref);
119 tprintf(h->
s.
avctx,
"pred_motion match_count=%d\n", match_count);
120 if (match_count > 1) {
123 }
else if (match_count == 1) {
124 if (left_ref == ref) {
127 }
else if (top_ref == ref) {
147 "pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n",
148 top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref,
149 A[0], A[1], ref, *mx, *my, h->
s.
mb_x, h->
s.
mb_y, n, list);
159 int n,
int list,
int ref,
160 int *
const mx,
int *
const my)
166 tprintf(h->
s.
avctx,
"pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
167 top_ref, B[0], B[1], h->
s.
mb_x, h->
s.
mb_y, n, list);
169 if (top_ref == ref) {
178 tprintf(h->
s.
avctx,
"pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
179 left_ref, A[0], A[1], h->
s.
mb_x, h->
s.
mb_y, n, list);
181 if (left_ref == ref) {
199 int n,
int list,
int ref,
200 int *
const mx,
int *
const my)
206 tprintf(h->
s.
avctx,
"pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
207 left_ref, A[0], A[1], h->
s.
mb_x, h->
s.
mb_y, n, list);
209 if (left_ref == ref) {
220 tprintf(h->
s.
avctx,
"pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
221 diagonal_ref, C[0], C[1], h->
s.
mb_x, h->
s.
mb_y, n, list);
223 if (diagonal_ref == ref) {
234 #define FIX_MV_MBAFF(type, refn, mvn, idx) \
237 if (!IS_INTERLACED(type)) { \
239 AV_COPY32(mvbuf[idx], mvn); \
240 mvbuf[idx][1] /= 2; \
244 if (IS_INTERLACED(type)) { \
246 AV_COPY32(mvbuf[idx], mvn); \
247 mvbuf[idx][1] <<= 1; \
260 int top_ref, left_ref, diagonal_ref, match_count, mx, my;
261 const int16_t *
A, *
B, *C;
323 match_count = !diagonal_ref + !top_ref + !left_ref;
324 tprintf(h->
s.
avctx,
"pred_pskip_motion match_count=%d\n", match_count);
325 if (match_count > 1) {
328 }
else if (match_count == 1) {
332 }
else if (!top_ref) {
355 const int mb_xy = h->
mb_xy;
356 int topleft_xy, top_xy, topright_xy, left_xy[
LEFT_MBS];
357 static const uint8_t left_block_options[4][32] = {
358 { 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 },
359 { 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 },
360 { 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 },
361 { 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 }
371 topleft_xy = top_xy - 1;
372 topright_xy = top_xy + 1;
373 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy - 1;
379 if (left_mb_field_flag != curr_mb_field_flag) {
381 if (curr_mb_field_flag) {
393 if (curr_mb_field_flag) {
398 if (left_mb_field_flag != curr_mb_field_flag) {
399 if (curr_mb_field_flag) {
445 int topleft_xy, top_xy, topright_xy, left_xy[
LEFT_MBS];
446 int topleft_type, top_type, topright_type, left_type[
LEFT_MBS];
471 if (!(top_type & type_mask)) {
478 if (!(left_type[LTOP] & type_mask)) {
482 if (!(left_type[
LBOT] & type_mask)) {
489 assert(left_xy[LTOP] == left_xy[
LBOT]);
490 if (!((left_typei & type_mask) && (left_type[LTOP] & type_mask))) {
496 if (!(left_type[LTOP] & type_mask)) {
502 if (!(topleft_type & type_mask))
505 if (!(topright_type & type_mask))
517 for (i = 0; i < 2; i++) {
543 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]);
545 AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 7]);
546 AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]);
548 AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 5]);
549 AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 9]);
552 uint32_t top_empty =
CABAC && !
IS_INTRA(mb_type) ? 0 : 0x40404040;
553 AV_WN32A(&nnz_cache[4 + 8 * 0], top_empty);
554 AV_WN32A(&nnz_cache[4 + 8 * 5], top_empty);
555 AV_WN32A(&nnz_cache[4 + 8 * 10], top_empty);
558 for (i = 0; i < 2; i++) {
559 if (left_type[
LEFT(i)]) {
561 nnz_cache[3 + 8 * 1 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i]];
562 nnz_cache[3 + 8 * 2 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i]];
564 nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 4 * 4];
565 nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 4 * 4];
566 nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 8 * 4];
567 nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 8 * 4];
569 nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 4 * 4];
570 nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 4 * 4];
571 nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 8 * 4];
572 nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 8 * 4];
574 nnz_cache[3 + 8 * 6 + 8 * i] = nnz[left_block[8 + 4 + 2 * i]];
575 nnz_cache[3 + 8 * 11 + 8 * i] = nnz[left_block[8 + 5 + 2 * i]];
578 nnz_cache[3 + 8 * 1 + 2 * 8 * i] =
579 nnz_cache[3 + 8 * 2 + 2 * 8 * i] =
580 nnz_cache[3 + 8 * 6 + 2 * 8 * i] =
581 nnz_cache[3 + 8 * 7 + 2 * 8 * i] =
582 nnz_cache[3 + 8 * 11 + 2 * 8 * i] =
583 nnz_cache[3 + 8 * 12 + 2 * 8 * i] =
CABAC && !
IS_INTRA(mb_type) ? 0 : 64;
594 if (left_type[
LTOP]) {
596 ((h->
cbp_table[left_xy[LTOP]] >> (left_block[0] & (~1))) & 2) |
597 (((h->
cbp_table[left_xy[
LBOT]] >> (left_block[2] & (~1))) & 2) << 2);
607 for (list = 0; list < h->
list_count; list++) {
617 const int b_xy = h->
mb2b_xy[top_xy] + 3 * b_stride;
619 ref_cache[0 - 1 * 8] =
620 ref_cache[1 - 1 * 8] = ref[4 * top_xy + 2];
621 ref_cache[2 - 1 * 8] =
622 ref_cache[3 - 1 * 8] = ref[4 * top_xy + 3];
630 for (i = 0; i < 2; i++) {
631 int cache_idx = -1 + i * 2 * 8;
634 const int b8_xy = 4 * left_xy[
LEFT(i)] + 1;
636 mv[b_xy + b_stride * left_block[0 + i * 2]]);
638 mv[b_xy + b_stride * left_block[1 + i * 2]]);
639 ref_cache[cache_idx] = ref[b8_xy + (left_block[0 + i * 2] & ~1)];
640 ref_cache[cache_idx + 8] = ref[b8_xy + (left_block[1 + i * 2] & ~1)];
644 ref_cache[cache_idx] =
652 const int b8_xy = 4 * left_xy[
LTOP] + 1;
653 AV_COPY32(mv_cache[-1],
mv[b_xy + b_stride * left_block[0]]);
654 ref_cache[-1] = ref[b8_xy + (left_block[0] & ~1)];
663 const int b_xy = h->
mb2b_xy[topright_xy] + 3 * b_stride;
665 ref_cache[4 - 1 * 8] = ref[4 * topright_xy + 2];
671 if (ref_cache[4 - 1 * 8] < 0) {
673 const int b_xy = h->
mb2b_xy[topleft_xy] + 3 + b_stride +
677 ref_cache[-1 - 1 * 8] = ref[b8_xy];
691 ref_cache[2 + 8 * 0] =
698 const int b_xy = h->
mb2br_xy[top_xy];
699 AV_COPY64(mvd_cache[0 - 1 * 8], mvd[b_xy + 0]);
705 AV_COPY16(mvd_cache[-1 + 0 * 8], mvd[b_xy - left_block[0]]);
706 AV_COPY16(mvd_cache[-1 + 1 * 8], mvd[b_xy - left_block[1]]);
713 AV_COPY16(mvd_cache[-1 + 2 * 8], mvd[b_xy - left_block[2]]);
714 AV_COPY16(mvd_cache[-1 + 3 * 8], mvd[b_xy - left_block[3]]);
729 }
else if (
IS_8X8(top_type)) {
730 int b8_xy = 4 * top_xy;
731 direct_cache[0 - 1 * 8] = direct_table[b8_xy + 2];
732 direct_cache[2 - 1 * 8] = direct_table[b8_xy + 3];
740 else if (
IS_8X8(left_type[LTOP]))
741 direct_cache[-1 + 0 * 8] = direct_table[4 * left_xy[
LTOP] + 1 + (left_block[0] & ~1)];
747 else if (
IS_8X8(left_type[LBOT]))
748 direct_cache[-1 + 2 * 8] = direct_table[4 * left_xy[LBOT] + 1 + (left_block[2] & ~1)];
756 MAP_F2F(scan8[0] - 1 - 1 * 8, topleft_type) \
757 MAP_F2F(scan8[0] + 0 - 1 * 8, top_type) \
758 MAP_F2F(scan8[0] + 1 - 1 * 8, top_type) \
759 MAP_F2F(scan8[0] + 2 - 1 * 8, top_type) \
760 MAP_F2F(scan8[0] + 3 - 1 * 8, top_type) \
761 MAP_F2F(scan8[0] + 4 - 1 * 8, topright_type) \
762 MAP_F2F(scan8[0] - 1 + 0 * 8, left_type[LTOP]) \
763 MAP_F2F(scan8[0] - 1 + 1 * 8, left_type[LTOP]) \
764 MAP_F2F(scan8[0] - 1 + 2 * 8, left_type[LBOT]) \
765 MAP_F2F(scan8[0] - 1 + 3 * 8, left_type[LBOT])
770 #define MAP_F2F(idx, mb_type) \
771 if (!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \
772 h->ref_cache[list][idx] <<= 1; \
773 h->mv_cache[list][idx][1] /= 2; \
774 h->mvd_cache[list][idx][1] >>= 1; \
781 #define MAP_F2F(idx, mb_type) \
782 if (IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \
783 h->ref_cache[list][idx] >>= 1; \
784 h->mv_cache[list][idx][1] <<= 1; \
785 h->mvd_cache[list][idx][1] <<= 1; \
804 const int mb_xy = h->
mb_xy;
unsigned int top_samples_available
unsigned int topleft_samples_available
static av_always_inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, int list, int part_width)
#define FIX_MV_MBAFF(type, refn, mvn, idx)
int16_t mv_cache[2][5 *8][2]
Motion vector cache.
static av_always_inline void write_back_motion(H264Context *h, int mb_type)
static void fill_decode_caches(H264Context *h, int mb_type)
int slice_type_nos
S free slice type (SI/SP are remapped to I/P)
static av_always_inline uint32_t pack16to32(int a, int b)
#define USES_LIST(a, list)
does this mb use listX, note does not work if subMBs
#define SET_DIAG_MV(MV_OP, REF_OP, XY, Y4)
Picture current_picture
copy of the current picture structure.
static void av_unused decode_mb_skip(H264Context *h)
decodes a P_SKIP or B_SKIP macroblock
uint8_t direct_cache[5 *8]
H.264 / AVC / MPEG4 part10 codec.
int constrained_intra_pred
constrained_intra_pred_flag
const uint8_t * left_block
#define MB_TYPE_INTERLACED
uint8_t(*[2] mvd_table)[2]
static av_always_inline void pred_8x16_motion(H264Context *const h, int n, int list, int ref, int *const mx, int *const my)
Get the directionally predicted 8x16 MV.
int direct_spatial_mv_pred
static const uint8_t scan8[16 *3+3]
static av_always_inline void pred_motion(H264Context *const h, int n, int part_width, int list, int ref, int *const mx, int *const my)
Get the predicted MV.
void ff_h264_pred_direct_motion(H264Context *const h, int *mb_type)
unsigned int left_samples_available
uint16_t * slice_table
slice_table_base + 2*mb_stride + 1
Picture * current_picture_ptr
pointer to the current picture
uint8_t mvd_cache[2][5 *8][2]
static void fill_rectangle(SDL_Surface *screen, int x, int y, int w, int h, int color)
int8_t intra4x4_pred_mode_cache[5 *8]
unsigned int topright_samples_available
#define PART_NOT_AVAILABLE
static const int8_t mv[256][2]
uint32_t * mb_type
macroblock type table mb_type_base + mb_width + 2
static void fill_decode_neighbors(H264Context *h, int mb_type)
int16_t(*[2] motion_val)[2]
motion vector table
int8_t * ref_index[2]
motion reference frame index the order in which these are stored can depend on the codec...
#define DECLARE_ALIGNED(n, t, v)
int8_t * qscale_table
QP table.
struct AVCodecContext * avctx
common internal api header.
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 ...
static av_always_inline void pred_pskip_motion(H264Context *const h)
static av_always_inline void pred_16x8_motion(H264Context *const h, int n, int list, int ref, int *const mx, int *const my)
Get the directionally predicted 16x8 MV.
uint8_t non_zero_count_cache[15 *8]
non zero coeff count cache.
int8_t * intra4x4_pred_mode
uint8_t(* non_zero_count)[48]
int neighbor_transform_size
number of neighbors (top and/or left) that used 8x8 dct
int8_t ref_cache[2][5 *8]