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->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->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];
81 *C = h->mv_cache[
list][i - 8 - 1];
82 return h->ref_cache[
list][i - 8 - 1];
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);
158 int *
const mx,
int *
const my)
161 const int top_ref = h->ref_cache[
list][
scan8[0] - 8];
162 const int16_t *
const B = h->mv_cache[
list][
scan8[0] - 8];
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) {
173 const int left_ref = h->ref_cache[
list][
scan8[8] - 1];
174 const int16_t *
const A = h->mv_cache[
list][
scan8[8] - 1];
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) {
198 int *
const mx,
int *
const my)
201 const int left_ref = h->ref_cache[
list][
scan8[0] - 1];
202 const int16_t *
const A = h->mv_cache[
list][
scan8[0] - 1];
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) \ 233 if (FRAME_MBAFF(h)) { \ 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++) {
535 nnz_cache = h->non_zero_count_cache;
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(h) && !
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(h) && !
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++) {
603 int8_t *ref_cache = &h->ref_cache[
list][
scan8[0]];
605 int16_t(*mv_cache)[2] = &h->mv_cache[
list][
scan8[0]];
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;
unsigned int top_samples_available
unsigned int topleft_samples_available
FIXME Range Coding of cr are ref
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)
#define DECLARE_ALIGNED(n, t, v)
static av_always_inline void write_back_motion(H264Context *h, int mb_type)
static void fill_decode_caches(H264Context *h, int mb_type)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining list
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 av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define SET_DIAG_MV(MV_OP, REF_OP, XY, Y4)
static void av_unused decode_mb_skip(H264Context *h)
decodes a P_SKIP or B_SKIP macroblock
static void fill_rectangle(SDL_Surface *screen, int x, int y, int w, int h, int color, int update)
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
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
simple assert() macros that are a bit more flexible than ISO C assert().
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
#define MB_TYPE_INTERLACED
int16_t(*[2] motion_val)[2]
int8_t intra4x4_pred_mode_cache[5 *8]
unsigned int topright_samples_available
#define PART_NOT_AVAILABLE
static const int8_t mv[256][2]
static void fill_decode_neighbors(H264Context *h, int mb_type)
synthesis window for stochastic i
common internal api header.
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.
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