00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00028 #ifndef AVCODEC_H264_MVPRED_H
00029 #define AVCODEC_H264_MVPRED_H
00030
00031 #include "internal.h"
00032 #include "avcodec.h"
00033 #include "h264.h"
00034
00035
00036 #include <assert.h>
00037
00038 static av_always_inline int fetch_diagonal_mv(H264Context *h, const int16_t **C,
00039 int i, int list, int part_width)
00040 {
00041 const int topright_ref = h->ref_cache[list][i - 8 + part_width];
00042 MpegEncContext *s = &h->s;
00043
00044
00045
00046 if (FRAME_MBAFF) {
00047 #define SET_DIAG_MV(MV_OP, REF_OP, XY, Y4) \
00048 const int xy = XY, y4 = Y4; \
00049 const int mb_type = mb_types[xy + (y4 >> 2) * s->mb_stride]; \
00050 if (!USES_LIST(mb_type, list)) \
00051 return LIST_NOT_USED; \
00052 mv = s->current_picture_ptr->f.motion_val[list][h->mb2b_xy[xy] + 3 + y4 * h->b_stride]; \
00053 h->mv_cache[list][scan8[0] - 2][0] = mv[0]; \
00054 h->mv_cache[list][scan8[0] - 2][1] = mv[1] MV_OP; \
00055 return s->current_picture_ptr->f.ref_index[list][4 * xy + 1 + (y4 & ~1)] REF_OP;
00056
00057 if (topright_ref == PART_NOT_AVAILABLE
00058 && i >= scan8[0] + 8 && (i & 7) == 4
00059 && h->ref_cache[list][scan8[0] - 1] != PART_NOT_AVAILABLE) {
00060 const uint32_t *mb_types = s->current_picture_ptr->f.mb_type;
00061 const int16_t *mv;
00062 AV_ZERO32(h->mv_cache[list][scan8[0] - 2]);
00063 *C = h->mv_cache[list][scan8[0] - 2];
00064
00065 if (!MB_FIELD && IS_INTERLACED(h->left_type[0])) {
00066 SET_DIAG_MV(* 2, >> 1, h->left_mb_xy[0] + s->mb_stride,
00067 (s->mb_y & 1) * 2 + (i >> 5));
00068 }
00069 if (MB_FIELD && !IS_INTERLACED(h->left_type[0])) {
00070
00071 SET_DIAG_MV(/ 2, << 1, h->left_mb_xy[i >= 36], ((i >> 2)) & 3);
00072 }
00073 }
00074 #undef SET_DIAG_MV
00075 }
00076
00077 if (topright_ref != PART_NOT_AVAILABLE) {
00078 *C = h->mv_cache[list][i - 8 + part_width];
00079 return topright_ref;
00080 } else {
00081 tprintf(s->avctx, "topright MV not available\n");
00082
00083 *C = h->mv_cache[list][i - 8 - 1];
00084 return h->ref_cache[list][i - 8 - 1];
00085 }
00086 }
00087
00095 static av_always_inline void pred_motion(H264Context *const h, int n,
00096 int part_width, int list, int ref,
00097 int *const mx, int *const my)
00098 {
00099 const int index8 = scan8[n];
00100 const int top_ref = h->ref_cache[list][index8 - 8];
00101 const int left_ref = h->ref_cache[list][index8 - 1];
00102 const int16_t *const A = h->mv_cache[list][index8 - 1];
00103 const int16_t *const B = h->mv_cache[list][index8 - 8];
00104 const int16_t *C;
00105 int diagonal_ref, match_count;
00106
00107 assert(part_width == 1 || part_width == 2 || part_width == 4);
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 diagonal_ref = fetch_diagonal_mv(h, &C, index8, list, part_width);
00118 match_count = (diagonal_ref == ref) + (top_ref == ref) + (left_ref == ref);
00119 tprintf(h->s.avctx, "pred_motion match_count=%d\n", match_count);
00120 if (match_count > 1) {
00121 *mx = mid_pred(A[0], B[0], C[0]);
00122 *my = mid_pred(A[1], B[1], C[1]);
00123 } else if (match_count == 1) {
00124 if (left_ref == ref) {
00125 *mx = A[0];
00126 *my = A[1];
00127 } else if (top_ref == ref) {
00128 *mx = B[0];
00129 *my = B[1];
00130 } else {
00131 *mx = C[0];
00132 *my = C[1];
00133 }
00134 } else {
00135 if (top_ref == PART_NOT_AVAILABLE &&
00136 diagonal_ref == PART_NOT_AVAILABLE &&
00137 left_ref != PART_NOT_AVAILABLE) {
00138 *mx = A[0];
00139 *my = A[1];
00140 } else {
00141 *mx = mid_pred(A[0], B[0], C[0]);
00142 *my = mid_pred(A[1], B[1], C[1]);
00143 }
00144 }
00145
00146 tprintf(h->s.avctx,
00147 "pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n",
00148 top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref,
00149 A[0], A[1], ref, *mx, *my, h->s.mb_x, h->s.mb_y, n, list);
00150 }
00151
00158 static av_always_inline void pred_16x8_motion(H264Context *const h,
00159 int n, int list, int ref,
00160 int *const mx, int *const my)
00161 {
00162 if (n == 0) {
00163 const int top_ref = h->ref_cache[list][scan8[0] - 8];
00164 const int16_t *const B = h->mv_cache[list][scan8[0] - 8];
00165
00166 tprintf(h->s.avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
00167 top_ref, B[0], B[1], h->s.mb_x, h->s.mb_y, n, list);
00168
00169 if (top_ref == ref) {
00170 *mx = B[0];
00171 *my = B[1];
00172 return;
00173 }
00174 } else {
00175 const int left_ref = h->ref_cache[list][scan8[8] - 1];
00176 const int16_t *const A = h->mv_cache[list][scan8[8] - 1];
00177
00178 tprintf(h->s.avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
00179 left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list);
00180
00181 if (left_ref == ref) {
00182 *mx = A[0];
00183 *my = A[1];
00184 return;
00185 }
00186 }
00187
00188
00189 pred_motion(h, n, 4, list, ref, mx, my);
00190 }
00191
00198 static av_always_inline void pred_8x16_motion(H264Context *const h,
00199 int n, int list, int ref,
00200 int *const mx, int *const my)
00201 {
00202 if (n == 0) {
00203 const int left_ref = h->ref_cache[list][scan8[0] - 1];
00204 const int16_t *const A = h->mv_cache[list][scan8[0] - 1];
00205
00206 tprintf(h->s.avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
00207 left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list);
00208
00209 if (left_ref == ref) {
00210 *mx = A[0];
00211 *my = A[1];
00212 return;
00213 }
00214 } else {
00215 const int16_t *C;
00216 int diagonal_ref;
00217
00218 diagonal_ref = fetch_diagonal_mv(h, &C, scan8[4], list, 2);
00219
00220 tprintf(h->s.avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
00221 diagonal_ref, C[0], C[1], h->s.mb_x, h->s.mb_y, n, list);
00222
00223 if (diagonal_ref == ref) {
00224 *mx = C[0];
00225 *my = C[1];
00226 return;
00227 }
00228 }
00229
00230
00231 pred_motion(h, n, 2, list, ref, mx, my);
00232 }
00233
00234 #define FIX_MV_MBAFF(type, refn, mvn, idx) \
00235 if (FRAME_MBAFF) { \
00236 if (MB_FIELD) { \
00237 if (!IS_INTERLACED(type)) { \
00238 refn <<= 1; \
00239 AV_COPY32(mvbuf[idx], mvn); \
00240 mvbuf[idx][1] /= 2; \
00241 mvn = mvbuf[idx]; \
00242 } \
00243 } else { \
00244 if (IS_INTERLACED(type)) { \
00245 refn >>= 1; \
00246 AV_COPY32(mvbuf[idx], mvn); \
00247 mvbuf[idx][1] <<= 1; \
00248 mvn = mvbuf[idx]; \
00249 } \
00250 } \
00251 }
00252
00253 static av_always_inline void pred_pskip_motion(H264Context *const h)
00254 {
00255 DECLARE_ALIGNED(4, static const int16_t, zeromv)[2] = { 0 };
00256 DECLARE_ALIGNED(4, int16_t, mvbuf)[3][2];
00257 MpegEncContext *const s = &h->s;
00258 int8_t *ref = s->current_picture.f.ref_index[0];
00259 int16_t(*mv)[2] = s->current_picture.f.motion_val[0];
00260 int top_ref, left_ref, diagonal_ref, match_count, mx, my;
00261 const int16_t *A, *B, *C;
00262 int b_stride = h->b_stride;
00263
00264 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1);
00265
00266
00267
00268
00269
00270
00271 if (USES_LIST(h->left_type[LTOP], 0)) {
00272 left_ref = ref[4 * h->left_mb_xy[LTOP] + 1 + (h->left_block[0] & ~1)];
00273 A = mv[h->mb2b_xy[h->left_mb_xy[LTOP]] + 3 + b_stride * h->left_block[0]];
00274 FIX_MV_MBAFF(h->left_type[LTOP], left_ref, A, 0);
00275 if (!(left_ref | AV_RN32A(A)))
00276 goto zeromv;
00277 } else if (h->left_type[LTOP]) {
00278 left_ref = LIST_NOT_USED;
00279 A = zeromv;
00280 } else {
00281 goto zeromv;
00282 }
00283
00284 if (USES_LIST(h->top_type, 0)) {
00285 top_ref = ref[4 * h->top_mb_xy + 2];
00286 B = mv[h->mb2b_xy[h->top_mb_xy] + 3 * b_stride];
00287 FIX_MV_MBAFF(h->top_type, top_ref, B, 1);
00288 if (!(top_ref | AV_RN32A(B)))
00289 goto zeromv;
00290 } else if (h->top_type) {
00291 top_ref = LIST_NOT_USED;
00292 B = zeromv;
00293 } else {
00294 goto zeromv;
00295 }
00296
00297 tprintf(h->s.avctx, "pred_pskip: (%d) (%d) at %2d %2d\n",
00298 top_ref, left_ref, h->s.mb_x, h->s.mb_y);
00299
00300 if (USES_LIST(h->topright_type, 0)) {
00301 diagonal_ref = ref[4 * h->topright_mb_xy + 2];
00302 C = mv[h->mb2b_xy[h->topright_mb_xy] + 3 * b_stride];
00303 FIX_MV_MBAFF(h->topright_type, diagonal_ref, C, 2);
00304 } else if (h->topright_type) {
00305 diagonal_ref = LIST_NOT_USED;
00306 C = zeromv;
00307 } else {
00308 if (USES_LIST(h->topleft_type, 0)) {
00309 diagonal_ref = ref[4 * h->topleft_mb_xy + 1 +
00310 (h->topleft_partition & 2)];
00311 C = mv[h->mb2b_xy[h->topleft_mb_xy] + 3 + b_stride +
00312 (h->topleft_partition & 2 * b_stride)];
00313 FIX_MV_MBAFF(h->topleft_type, diagonal_ref, C, 2);
00314 } else if (h->topleft_type) {
00315 diagonal_ref = LIST_NOT_USED;
00316 C = zeromv;
00317 } else {
00318 diagonal_ref = PART_NOT_AVAILABLE;
00319 C = zeromv;
00320 }
00321 }
00322
00323 match_count = !diagonal_ref + !top_ref + !left_ref;
00324 tprintf(h->s.avctx, "pred_pskip_motion match_count=%d\n", match_count);
00325 if (match_count > 1) {
00326 mx = mid_pred(A[0], B[0], C[0]);
00327 my = mid_pred(A[1], B[1], C[1]);
00328 } else if (match_count == 1) {
00329 if (!left_ref) {
00330 mx = A[0];
00331 my = A[1];
00332 } else if (!top_ref) {
00333 mx = B[0];
00334 my = B[1];
00335 } else {
00336 mx = C[0];
00337 my = C[1];
00338 }
00339 } else {
00340 mx = mid_pred(A[0], B[0], C[0]);
00341 my = mid_pred(A[1], B[1], C[1]);
00342 }
00343
00344 fill_rectangle(h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx, my), 4);
00345 return;
00346
00347 zeromv:
00348 fill_rectangle(h->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4);
00349 return;
00350 }
00351
00352 static void fill_decode_neighbors(H264Context *h, int mb_type)
00353 {
00354 MpegEncContext *const s = &h->s;
00355 const int mb_xy = h->mb_xy;
00356 int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
00357 static const uint8_t left_block_options[4][32] = {
00358 { 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 },
00359 { 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 },
00360 { 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 },
00361 { 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 }
00362 };
00363
00364 h->topleft_partition = -1;
00365
00366 top_xy = mb_xy - (s->mb_stride << MB_FIELD);
00367
00368
00369
00370
00371 topleft_xy = top_xy - 1;
00372 topright_xy = top_xy + 1;
00373 left_xy[LBOT] = left_xy[LTOP] = mb_xy - 1;
00374 h->left_block = left_block_options[0];
00375 if (FRAME_MBAFF) {
00376 const int left_mb_field_flag = IS_INTERLACED(s->current_picture.f.mb_type[mb_xy - 1]);
00377 const int curr_mb_field_flag = IS_INTERLACED(mb_type);
00378 if (s->mb_y & 1) {
00379 if (left_mb_field_flag != curr_mb_field_flag) {
00380 left_xy[LBOT] = left_xy[LTOP] = mb_xy - s->mb_stride - 1;
00381 if (curr_mb_field_flag) {
00382 left_xy[LBOT] += s->mb_stride;
00383 h->left_block = left_block_options[3];
00384 } else {
00385 topleft_xy += s->mb_stride;
00386
00387
00388 h->topleft_partition = 0;
00389 h->left_block = left_block_options[1];
00390 }
00391 }
00392 } else {
00393 if (curr_mb_field_flag) {
00394 topleft_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy - 1] >> 7) & 1) - 1);
00395 topright_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy + 1] >> 7) & 1) - 1);
00396 top_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy] >> 7) & 1) - 1);
00397 }
00398 if (left_mb_field_flag != curr_mb_field_flag) {
00399 if (curr_mb_field_flag) {
00400 left_xy[LBOT] += s->mb_stride;
00401 h->left_block = left_block_options[3];
00402 } else {
00403 h->left_block = left_block_options[2];
00404 }
00405 }
00406 }
00407 }
00408
00409 h->topleft_mb_xy = topleft_xy;
00410 h->top_mb_xy = top_xy;
00411 h->topright_mb_xy = topright_xy;
00412 h->left_mb_xy[LTOP] = left_xy[LTOP];
00413 h->left_mb_xy[LBOT] = left_xy[LBOT];
00414
00415
00416 h->topleft_type = s->current_picture.f.mb_type[topleft_xy];
00417 h->top_type = s->current_picture.f.mb_type[top_xy];
00418 h->topright_type = s->current_picture.f.mb_type[topright_xy];
00419 h->left_type[LTOP] = s->current_picture.f.mb_type[left_xy[LTOP]];
00420 h->left_type[LBOT] = s->current_picture.f.mb_type[left_xy[LBOT]];
00421
00422 if (FMO) {
00423 if (h->slice_table[topleft_xy] != h->slice_num)
00424 h->topleft_type = 0;
00425 if (h->slice_table[top_xy] != h->slice_num)
00426 h->top_type = 0;
00427 if (h->slice_table[left_xy[LTOP]] != h->slice_num)
00428 h->left_type[LTOP] = h->left_type[LBOT] = 0;
00429 } else {
00430 if (h->slice_table[topleft_xy] != h->slice_num) {
00431 h->topleft_type = 0;
00432 if (h->slice_table[top_xy] != h->slice_num)
00433 h->top_type = 0;
00434 if (h->slice_table[left_xy[LTOP]] != h->slice_num)
00435 h->left_type[LTOP] = h->left_type[LBOT] = 0;
00436 }
00437 }
00438 if (h->slice_table[topright_xy] != h->slice_num)
00439 h->topright_type = 0;
00440 }
00441
00442 static void fill_decode_caches(H264Context *h, int mb_type)
00443 {
00444 MpegEncContext *const s = &h->s;
00445 int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
00446 int topleft_type, top_type, topright_type, left_type[LEFT_MBS];
00447 const uint8_t *left_block = h->left_block;
00448 int i;
00449 uint8_t *nnz;
00450 uint8_t *nnz_cache;
00451
00452 topleft_xy = h->topleft_mb_xy;
00453 top_xy = h->top_mb_xy;
00454 topright_xy = h->topright_mb_xy;
00455 left_xy[LTOP] = h->left_mb_xy[LTOP];
00456 left_xy[LBOT] = h->left_mb_xy[LBOT];
00457 topleft_type = h->topleft_type;
00458 top_type = h->top_type;
00459 topright_type = h->topright_type;
00460 left_type[LTOP] = h->left_type[LTOP];
00461 left_type[LBOT] = h->left_type[LBOT];
00462
00463 if (!IS_SKIP(mb_type)) {
00464 if (IS_INTRA(mb_type)) {
00465 int type_mask = h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;
00466 h->topleft_samples_available =
00467 h->top_samples_available =
00468 h->left_samples_available = 0xFFFF;
00469 h->topright_samples_available = 0xEEEA;
00470
00471 if (!(top_type & type_mask)) {
00472 h->topleft_samples_available = 0xB3FF;
00473 h->top_samples_available = 0x33FF;
00474 h->topright_samples_available = 0x26EA;
00475 }
00476 if (IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])) {
00477 if (IS_INTERLACED(mb_type)) {
00478 if (!(left_type[LTOP] & type_mask)) {
00479 h->topleft_samples_available &= 0xDFFF;
00480 h->left_samples_available &= 0x5FFF;
00481 }
00482 if (!(left_type[LBOT] & type_mask)) {
00483 h->topleft_samples_available &= 0xFF5F;
00484 h->left_samples_available &= 0xFF5F;
00485 }
00486 } else {
00487 int left_typei = s->current_picture.f.mb_type[left_xy[LTOP] + s->mb_stride];
00488
00489 assert(left_xy[LTOP] == left_xy[LBOT]);
00490 if (!((left_typei & type_mask) && (left_type[LTOP] & type_mask))) {
00491 h->topleft_samples_available &= 0xDF5F;
00492 h->left_samples_available &= 0x5F5F;
00493 }
00494 }
00495 } else {
00496 if (!(left_type[LTOP] & type_mask)) {
00497 h->topleft_samples_available &= 0xDF5F;
00498 h->left_samples_available &= 0x5F5F;
00499 }
00500 }
00501
00502 if (!(topleft_type & type_mask))
00503 h->topleft_samples_available &= 0x7FFF;
00504
00505 if (!(topright_type & type_mask))
00506 h->topright_samples_available &= 0xFBFF;
00507
00508 if (IS_INTRA4x4(mb_type)) {
00509 if (IS_INTRA4x4(top_type)) {
00510 AV_COPY32(h->intra4x4_pred_mode_cache + 4 + 8 * 0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]);
00511 } else {
00512 h->intra4x4_pred_mode_cache[4 + 8 * 0] =
00513 h->intra4x4_pred_mode_cache[5 + 8 * 0] =
00514 h->intra4x4_pred_mode_cache[6 + 8 * 0] =
00515 h->intra4x4_pred_mode_cache[7 + 8 * 0] = 2 - 3 * !(top_type & type_mask);
00516 }
00517 for (i = 0; i < 2; i++) {
00518 if (IS_INTRA4x4(left_type[LEFT(i)])) {
00519 int8_t *mode = h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];
00520 h->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] = mode[6 - left_block[0 + 2 * i]];
00521 h->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = mode[6 - left_block[1 + 2 * i]];
00522 } else {
00523 h->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] =
00524 h->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = 2 - 3 * !(left_type[LEFT(i)] & type_mask);
00525 }
00526 }
00527 }
00528 }
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540 nnz_cache = h->non_zero_count_cache;
00541 if (top_type) {
00542 nnz = h->non_zero_count[top_xy];
00543 AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]);
00544 if (!s->chroma_y_shift) {
00545 AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 7]);
00546 AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]);
00547 } else {
00548 AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 5]);
00549 AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 9]);
00550 }
00551 } else {
00552 uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;
00553 AV_WN32A(&nnz_cache[4 + 8 * 0], top_empty);
00554 AV_WN32A(&nnz_cache[4 + 8 * 5], top_empty);
00555 AV_WN32A(&nnz_cache[4 + 8 * 10], top_empty);
00556 }
00557
00558 for (i = 0; i < 2; i++) {
00559 if (left_type[LEFT(i)]) {
00560 nnz = h->non_zero_count[left_xy[LEFT(i)]];
00561 nnz_cache[3 + 8 * 1 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i]];
00562 nnz_cache[3 + 8 * 2 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i]];
00563 if (CHROMA444) {
00564 nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 4 * 4];
00565 nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 4 * 4];
00566 nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 8 * 4];
00567 nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 8 * 4];
00568 } else if (CHROMA422) {
00569 nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 4 * 4];
00570 nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 4 * 4];
00571 nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 8 * 4];
00572 nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 8 * 4];
00573 } else {
00574 nnz_cache[3 + 8 * 6 + 8 * i] = nnz[left_block[8 + 4 + 2 * i]];
00575 nnz_cache[3 + 8 * 11 + 8 * i] = nnz[left_block[8 + 5 + 2 * i]];
00576 }
00577 } else {
00578 nnz_cache[3 + 8 * 1 + 2 * 8 * i] =
00579 nnz_cache[3 + 8 * 2 + 2 * 8 * i] =
00580 nnz_cache[3 + 8 * 6 + 2 * 8 * i] =
00581 nnz_cache[3 + 8 * 7 + 2 * 8 * i] =
00582 nnz_cache[3 + 8 * 11 + 2 * 8 * i] =
00583 nnz_cache[3 + 8 * 12 + 2 * 8 * i] = CABAC && !IS_INTRA(mb_type) ? 0 : 64;
00584 }
00585 }
00586
00587 if (CABAC) {
00588
00589 if (top_type)
00590 h->top_cbp = h->cbp_table[top_xy];
00591 else
00592 h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
00593
00594 if (left_type[LTOP]) {
00595 h->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0) |
00596 ((h->cbp_table[left_xy[LTOP]] >> (left_block[0] & (~1))) & 2) |
00597 (((h->cbp_table[left_xy[LBOT]] >> (left_block[2] & (~1))) & 2) << 2);
00598 } else {
00599 h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
00600 }
00601 }
00602 }
00603
00604 if (IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)) {
00605 int list;
00606 int b_stride = h->b_stride;
00607 for (list = 0; list < h->list_count; list++) {
00608 int8_t *ref_cache = &h->ref_cache[list][scan8[0]];
00609 int8_t *ref = s->current_picture.f.ref_index[list];
00610 int16_t(*mv_cache)[2] = &h->mv_cache[list][scan8[0]];
00611 int16_t(*mv)[2] = s->current_picture.f.motion_val[list];
00612 if (!USES_LIST(mb_type, list))
00613 continue;
00614 assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));
00615
00616 if (USES_LIST(top_type, list)) {
00617 const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride;
00618 AV_COPY128(mv_cache[0 - 1 * 8], mv[b_xy + 0]);
00619 ref_cache[0 - 1 * 8] =
00620 ref_cache[1 - 1 * 8] = ref[4 * top_xy + 2];
00621 ref_cache[2 - 1 * 8] =
00622 ref_cache[3 - 1 * 8] = ref[4 * top_xy + 3];
00623 } else {
00624 AV_ZERO128(mv_cache[0 - 1 * 8]);
00625 AV_WN32A(&ref_cache[0 - 1 * 8],
00626 ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE) & 0xFF) * 0x01010101u);
00627 }
00628
00629 if (mb_type & (MB_TYPE_16x8 | MB_TYPE_8x8)) {
00630 for (i = 0; i < 2; i++) {
00631 int cache_idx = -1 + i * 2 * 8;
00632 if (USES_LIST(left_type[LEFT(i)], list)) {
00633 const int b_xy = h->mb2b_xy[left_xy[LEFT(i)]] + 3;
00634 const int b8_xy = 4 * left_xy[LEFT(i)] + 1;
00635 AV_COPY32(mv_cache[cache_idx],
00636 mv[b_xy + b_stride * left_block[0 + i * 2]]);
00637 AV_COPY32(mv_cache[cache_idx + 8],
00638 mv[b_xy + b_stride * left_block[1 + i * 2]]);
00639 ref_cache[cache_idx] = ref[b8_xy + (left_block[0 + i * 2] & ~1)];
00640 ref_cache[cache_idx + 8] = ref[b8_xy + (left_block[1 + i * 2] & ~1)];
00641 } else {
00642 AV_ZERO32(mv_cache[cache_idx]);
00643 AV_ZERO32(mv_cache[cache_idx + 8]);
00644 ref_cache[cache_idx] =
00645 ref_cache[cache_idx + 8] = (left_type[LEFT(i)]) ? LIST_NOT_USED
00646 : PART_NOT_AVAILABLE;
00647 }
00648 }
00649 } else {
00650 if (USES_LIST(left_type[LTOP], list)) {
00651 const int b_xy = h->mb2b_xy[left_xy[LTOP]] + 3;
00652 const int b8_xy = 4 * left_xy[LTOP] + 1;
00653 AV_COPY32(mv_cache[-1], mv[b_xy + b_stride * left_block[0]]);
00654 ref_cache[-1] = ref[b8_xy + (left_block[0] & ~1)];
00655 } else {
00656 AV_ZERO32(mv_cache[-1]);
00657 ref_cache[-1] = left_type[LTOP] ? LIST_NOT_USED
00658 : PART_NOT_AVAILABLE;
00659 }
00660 }
00661
00662 if (USES_LIST(topright_type, list)) {
00663 const int b_xy = h->mb2b_xy[topright_xy] + 3 * b_stride;
00664 AV_COPY32(mv_cache[4 - 1 * 8], mv[b_xy]);
00665 ref_cache[4 - 1 * 8] = ref[4 * topright_xy + 2];
00666 } else {
00667 AV_ZERO32(mv_cache[4 - 1 * 8]);
00668 ref_cache[4 - 1 * 8] = topright_type ? LIST_NOT_USED
00669 : PART_NOT_AVAILABLE;
00670 }
00671 if(ref_cache[2 - 1*8] < 0 || ref_cache[4 - 1*8] < 0){
00672 if (USES_LIST(topleft_type, list)) {
00673 const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride +
00674 (h->topleft_partition & 2 * b_stride);
00675 const int b8_xy = 4 * topleft_xy + 1 + (h->topleft_partition & 2);
00676 AV_COPY32(mv_cache[-1 - 1 * 8], mv[b_xy]);
00677 ref_cache[-1 - 1 * 8] = ref[b8_xy];
00678 } else {
00679 AV_ZERO32(mv_cache[-1 - 1 * 8]);
00680 ref_cache[-1 - 1 * 8] = topleft_type ? LIST_NOT_USED
00681 : PART_NOT_AVAILABLE;
00682 }
00683 }
00684
00685 if ((mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2)) && !FRAME_MBAFF)
00686 continue;
00687
00688 if (!(mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2))) {
00689 uint8_t(*mvd_cache)[2] = &h->mvd_cache[list][scan8[0]];
00690 uint8_t(*mvd)[2] = h->mvd_table[list];
00691 ref_cache[2 + 8 * 0] =
00692 ref_cache[2 + 8 * 2] = PART_NOT_AVAILABLE;
00693 AV_ZERO32(mv_cache[2 + 8 * 0]);
00694 AV_ZERO32(mv_cache[2 + 8 * 2]);
00695
00696 if (CABAC) {
00697 if (USES_LIST(top_type, list)) {
00698 const int b_xy = h->mb2br_xy[top_xy];
00699 AV_COPY64(mvd_cache[0 - 1 * 8], mvd[b_xy + 0]);
00700 } else {
00701 AV_ZERO64(mvd_cache[0 - 1 * 8]);
00702 }
00703 if (USES_LIST(left_type[LTOP], list)) {
00704 const int b_xy = h->mb2br_xy[left_xy[LTOP]] + 6;
00705 AV_COPY16(mvd_cache[-1 + 0 * 8], mvd[b_xy - left_block[0]]);
00706 AV_COPY16(mvd_cache[-1 + 1 * 8], mvd[b_xy - left_block[1]]);
00707 } else {
00708 AV_ZERO16(mvd_cache[-1 + 0 * 8]);
00709 AV_ZERO16(mvd_cache[-1 + 1 * 8]);
00710 }
00711 if (USES_LIST(left_type[LBOT], list)) {
00712 const int b_xy = h->mb2br_xy[left_xy[LBOT]] + 6;
00713 AV_COPY16(mvd_cache[-1 + 2 * 8], mvd[b_xy - left_block[2]]);
00714 AV_COPY16(mvd_cache[-1 + 3 * 8], mvd[b_xy - left_block[3]]);
00715 } else {
00716 AV_ZERO16(mvd_cache[-1 + 2 * 8]);
00717 AV_ZERO16(mvd_cache[-1 + 3 * 8]);
00718 }
00719 AV_ZERO16(mvd_cache[2 + 8 * 0]);
00720 AV_ZERO16(mvd_cache[2 + 8 * 2]);
00721 if (h->slice_type_nos == AV_PICTURE_TYPE_B) {
00722 uint8_t *direct_cache = &h->direct_cache[scan8[0]];
00723 uint8_t *direct_table = h->direct_table;
00724 fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16 >> 1, 1);
00725
00726 if (IS_DIRECT(top_type)) {
00727 AV_WN32A(&direct_cache[-1 * 8],
00728 0x01010101u * (MB_TYPE_DIRECT2 >> 1));
00729 } else if (IS_8X8(top_type)) {
00730 int b8_xy = 4 * top_xy;
00731 direct_cache[0 - 1 * 8] = direct_table[b8_xy + 2];
00732 direct_cache[2 - 1 * 8] = direct_table[b8_xy + 3];
00733 } else {
00734 AV_WN32A(&direct_cache[-1 * 8],
00735 0x01010101 * (MB_TYPE_16x16 >> 1));
00736 }
00737
00738 if (IS_DIRECT(left_type[LTOP]))
00739 direct_cache[-1 + 0 * 8] = MB_TYPE_DIRECT2 >> 1;
00740 else if (IS_8X8(left_type[LTOP]))
00741 direct_cache[-1 + 0 * 8] = direct_table[4 * left_xy[LTOP] + 1 + (left_block[0] & ~1)];
00742 else
00743 direct_cache[-1 + 0 * 8] = MB_TYPE_16x16 >> 1;
00744
00745 if (IS_DIRECT(left_type[LBOT]))
00746 direct_cache[-1 + 2 * 8] = MB_TYPE_DIRECT2 >> 1;
00747 else if (IS_8X8(left_type[LBOT]))
00748 direct_cache[-1 + 2 * 8] = direct_table[4 * left_xy[LBOT] + 1 + (left_block[2] & ~1)];
00749 else
00750 direct_cache[-1 + 2 * 8] = MB_TYPE_16x16 >> 1;
00751 }
00752 }
00753 }
00754
00755 #define MAP_MVS \
00756 MAP_F2F(scan8[0] - 1 - 1 * 8, topleft_type) \
00757 MAP_F2F(scan8[0] + 0 - 1 * 8, top_type) \
00758 MAP_F2F(scan8[0] + 1 - 1 * 8, top_type) \
00759 MAP_F2F(scan8[0] + 2 - 1 * 8, top_type) \
00760 MAP_F2F(scan8[0] + 3 - 1 * 8, top_type) \
00761 MAP_F2F(scan8[0] + 4 - 1 * 8, topright_type) \
00762 MAP_F2F(scan8[0] - 1 + 0 * 8, left_type[LTOP]) \
00763 MAP_F2F(scan8[0] - 1 + 1 * 8, left_type[LTOP]) \
00764 MAP_F2F(scan8[0] - 1 + 2 * 8, left_type[LBOT]) \
00765 MAP_F2F(scan8[0] - 1 + 3 * 8, left_type[LBOT])
00766
00767 if (FRAME_MBAFF) {
00768 if (MB_FIELD) {
00769
00770 #define MAP_F2F(idx, mb_type) \
00771 if (!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \
00772 h->ref_cache[list][idx] <<= 1; \
00773 h->mv_cache[list][idx][1] /= 2; \
00774 h->mvd_cache[list][idx][1] >>= 1; \
00775 }
00776
00777 MAP_MVS
00778 } else {
00779
00780 #undef MAP_F2F
00781 #define MAP_F2F(idx, mb_type) \
00782 if (IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \
00783 h->ref_cache[list][idx] >>= 1; \
00784 h->mv_cache[list][idx][1] <<= 1; \
00785 h->mvd_cache[list][idx][1] <<= 1; \
00786 }
00787
00788 MAP_MVS
00789 #undef MAP_F2F
00790 }
00791 }
00792 }
00793 }
00794
00795 h->neighbor_transform_size = !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);
00796 }
00797
00801 static void av_unused decode_mb_skip(H264Context *h)
00802 {
00803 MpegEncContext *const s = &h->s;
00804 const int mb_xy = h->mb_xy;
00805 int mb_type = 0;
00806
00807 memset(h->non_zero_count[mb_xy], 0, 48);
00808
00809 if (MB_FIELD)
00810 mb_type |= MB_TYPE_INTERLACED;
00811
00812 if (h->slice_type_nos == AV_PICTURE_TYPE_B) {
00813
00814 mb_type |= MB_TYPE_L0L1 | MB_TYPE_DIRECT2 | MB_TYPE_SKIP;
00815 if (h->direct_spatial_mv_pred) {
00816 fill_decode_neighbors(h, mb_type);
00817 fill_decode_caches(h, mb_type);
00818 }
00819 ff_h264_pred_direct_motion(h, &mb_type);
00820 mb_type |= MB_TYPE_SKIP;
00821 } else {
00822 mb_type |= MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P1L0 | MB_TYPE_SKIP;
00823
00824 fill_decode_neighbors(h, mb_type);
00825 pred_pskip_motion(h);
00826 }
00827
00828 write_back_motion(h, mb_type);
00829 s->current_picture.f.mb_type[mb_xy] = mb_type;
00830 s->current_picture.f.qscale_table[mb_xy] = s->qscale;
00831 h->slice_table[mb_xy] = h->slice_num;
00832 h->prev_mb_skipped = 1;
00833 }
00834
00835 #endif