28 #ifndef AVCODEC_H264_MVPRED_H 29 #define AVCODEC_H264_MVPRED_H 40 int i,
int list,
int part_width)
42 const int topright_ref = sl->
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) * 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
67 (sl->
mb_y & 1) * 2 + (i >> 5));
78 *C = sl->
mv_cache[list][i - 8 + part_width];
98 int part_width,
int list,
int ref,
99 int *
const mx,
int *
const my)
101 const int index8 =
scan8[
n];
102 const int top_ref = sl->
ref_cache[list][index8 - 8];
103 const int left_ref = sl->
ref_cache[list][index8 - 1];
104 const int16_t *
const A = sl->
mv_cache[list][index8 - 1];
105 const int16_t *
const B = sl->
mv_cache[list][index8 - 8];
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,
151 A[0], A[1], ref, *mx, *my, sl->
mb_x, sl->
mb_y, n, list);
162 int n,
int list,
int 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",
170 top_ref, B[0], B[1], sl->
mb_x, sl->
mb_y, n, list);
172 if (top_ref == ref) {
181 ff_tlog(h->
avctx,
"pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
182 left_ref, A[0], A[1], sl->
mb_x, sl->
mb_y, n, list);
184 if (left_ref == ref) {
203 int n,
int list,
int 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",
211 left_ref, A[0], A[1], sl->
mb_x, sl->
mb_y, n, list);
213 if (left_ref == ref) {
224 ff_tlog(h->
avctx,
"pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
225 diagonal_ref, C[0], C[1], sl->
mb_x, sl->
mb_y, n, list);
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; \ 264 int top_ref, left_ref, diagonal_ref, match_count, mx, my;
265 const int16_t *
A, *
B, *
C;
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 }
374 topleft_xy = top_xy - 1;
375 topright_xy = top_xy + 1;
376 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy - 1;
382 if (left_mb_field_flag != curr_mb_field_flag) {
384 if (curr_mb_field_flag) {
396 if (curr_mb_field_flag) {
401 if (left_mb_field_flag != curr_mb_field_flag) {
402 if (curr_mb_field_flag) {
447 int topleft_xy, top_xy, topright_xy, left_xy[
LEFT_MBS];
448 int topleft_type, top_type, topright_type, left_type[
LEFT_MBS];
473 if (!(top_type & type_mask)) {
480 if (!(left_type[LTOP] & type_mask)) {
484 if (!(left_type[
LBOT] & type_mask)) {
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++) {
545 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]);
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)]) {
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);
609 for (list = 0; list < sl->
list_count; 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;
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] =
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]);
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]]);
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]]);
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];
742 else if (
IS_8X8(left_type[LTOP]))
743 direct_cache[-1 + 0 * 8] = direct_table[4 * left_xy[
LTOP] + 1 + (left_block[0] & ~1)];
749 else if (
IS_8X8(left_type[LBOT]))
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;
const uint8_t * left_block
int16_t mv_cache[2][5 *8][2]
Motion vector cache.
int neighbor_transform_size
number of neighbors (top and/or left) that used 8x8 dct
#define FIX_MV_MBAFF(type, refn, mvn, idx)
unsigned int topleft_samples_available
uint8_t mvd_cache[2][5 *8][2]
int16_t(*[2] motion_val)[2]
void ff_h264_pred_direct_motion(const H264Context *const h, H264SliceContext *sl, int *mb_type)
#define USES_LIST(a, list)
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define SET_DIAG_MV(MV_OP, REF_OP, XY, Y4)
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
static av_always_inline void write_back_motion(const H264Context *h, H264SliceContext *sl, int mb_type)
unsigned int topright_samples_available
static av_always_inline void pred_pskip_motion(const H264Context *const h, H264SliceContext *sl)
int constrained_intra_pred
constrained_intra_pred_flag
int8_t intra4x4_pred_mode_cache[5 *8]
static av_always_inline void pred_16x8_motion(const H264Context *const h, H264SliceContext *sl, int n, int list, int ref, int *const mx, int *const my)
Get the directionally predicted 16x8 MV.
simple assert() macros that are a bit more flexible than ISO C assert().
int direct_spatial_mv_pred
unsigned int top_samples_available
int slice_type_nos
S free slice type (SI/SP are remapped to I/P)
uint16_t * slice_table
slice_table_base + 2*mb_stride + 1
static av_always_inline void pred_8x16_motion(const H264Context *const h, H264SliceContext *sl, int n, int list, int ref, int *const mx, int *const my)
Get the directionally predicted 8x16 MV.
H.264 / AVC / MPEG-4 part10 codec.
static void fill_rectangle(int x, int y, int w, int h)
#define MB_TYPE_INTERLACED
static const int8_t mv[256][2]
Libavcodec external API header.
static const uint8_t scan8[16 *3+3]
uint8_t non_zero_count_cache[15 *8]
non zero coeff count cache.
static av_always_inline uint32_t pack16to32(unsigned a, unsigned b)
H264Picture * cur_pic_ptr
uint8_t direct_cache[5 *8]
static void fill_decode_caches(const H264Context *h, H264SliceContext *sl, int mb_type)
common internal api header.
static int ref[MAX_W *MAX_W]
static void fill_decode_neighbors(const H264Context *h, H264SliceContext *sl, int mb_type)
int8_t * intra4x4_pred_mode
int8_t ref_cache[2][5 *8]
static av_always_inline int fetch_diagonal_mv(const H264Context *h, H264SliceContext *sl, const int16_t **C, int i, int list, int part_width)
#define PART_NOT_AVAILABLE
static void av_unused decode_mb_skip(const H264Context *h, H264SliceContext *sl)
decodes a P_SKIP or B_SKIP macroblock
unsigned int left_samples_available
uint8_t(*[2] mvd_table)[2]
uint8_t(* non_zero_count)[48]
mode
Use these values in ebur128_init (or'ed).
static av_always_inline void pred_motion(const H264Context *const h, H264SliceContext *sl, int n, int part_width, int list, int ref, int *const mx, int *const my)
Get the predicted MV.