39 int poc,
int poc1,
int i)
45 if (pocdiff != (
int)pocdiff)
55 if (pocdiff0 != (
int)pocdiff0)
66 :
h->cur_pic_ptr->poc;
71 for (field = 0; field < 2; field++) {
72 const int poc =
h->cur_pic_ptr->field_poc[field];
84 int map[2][16 + 32],
int list,
85 int field,
int colfield,
int mbafi)
88 int j, old_ref, rfield;
89 int start = mbafi ? 16 : 0;
91 int interl = mbafi ||
h->picture_structure !=
PICT_FRAME;
94 memset(
map[list], 0,
sizeof(
map[list]));
96 for (rfield = 0; rfield < 2; rfield++) {
97 for (old_ref = 0; old_ref < ref1->
ref_count[colfield][list]; old_ref++) {
98 int poc = ref1->
ref_poc[colfield][list][old_ref];
103 else if (interl && (poc & 3) == 3)
104 poc = (poc & ~3) + rfield + 1;
106 for (j = start; j < end; j++) {
109 int cur_ref = mbafi ? (j - 16) ^ field : j;
111 map[list][2 * old_ref + (rfield ^ field) + 16] = cur_ref;
112 if (rfield == field || !interl)
113 map[list][old_ref] = cur_ref;
126 int sidx = (
h->picture_structure & 1) ^ 1;
127 int ref1sidx = (ref1->
reference & 1) ^ 1;
131 if (!
h->setup_finished) {
132 for (list = 0; list < sl->
list_count; list++) {
134 for (
int j = 0; j < sl->
ref_count[list]; j++)
144 if (
h->current_slice == 0) {
157 int cur_poc =
h->cur_pic_ptr->poc;
159 if (col_poc[0] == INT_MAX && col_poc[1] == INT_MAX) {
176 for (list = 0; list < 2; list++) {
179 for (field = 0; field < 2; field++)
188 int ref_field =
ref->reference - 1;
189 int ref_field_picture =
ref->parent->field_picture;
190 int ref_height = 16 *
h->mb_height >> ref_field_picture;
199 FFMIN(16 * mb_y >> ref_field_picture,
201 ref_field_picture && ref_field);
208 int b4_stride =
h->b_stride;
211 const int16_t (*l1mv0)[2], (*l1mv1)[2];
212 const int8_t *l1ref0, *l1ref1;
213 const int is_b8x8 =
IS_8X8(*mb_type);
225 #define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16 | MB_TYPE_INTRA4x4 | \
226 MB_TYPE_INTRA16x16 | MB_TYPE_INTRA_PCM)
229 for (list = 0; list < 2; list++) {
241 if (
ref[list] >= 0) {
247 int match_count = (left_ref ==
ref[list]) +
248 (top_ref ==
ref[list]) +
251 if (match_count > 1) {
255 assert(match_count == 1);
256 if (left_ref ==
ref[list])
258 else if (top_ref ==
ref[list])
273 if (
ref[0] < 0 &&
ref[1] < 0) {
280 if (!(is_b8x8 |
mv[0] |
mv[1])) {
304 mb_y = sl->
mb_y & ~1;
305 mb_xy = (sl->
mb_y & ~1) *
h->mb_stride + sl->
mb_x;
308 b8_stride = 2 + 4 *
h->mb_stride;
332 }
else if (!is_b8x8 &&
337 if (!
h->ps.sps->direct_8x8_inference_flag) {
357 l1mv0 += 2 * b4_stride;
358 l1mv1 += 2 * b4_stride;
364 for (i8 = 0; i8 < 4; i8++) {
367 int xy8 = x8 + y8 * b8_stride;
368 int xy4 = x8 * 3 + y8 * b4_stride;
380 ((l1ref0[xy8] == 0 &&
381 FFABS(l1mv0[xy4][0]) <= 1 &&
382 FFABS(l1mv0[xy4][1]) <= 1) ||
385 FFABS(l1mv1[xy4][0]) <= 1 &&
386 FFABS(l1mv1[xy4][1]) <= 1))) {
401 if (!is_b8x8 && !(n & 3))
412 FFABS(l1mv0[0][0]) <= 1 &&
413 FFABS(l1mv0[0][1]) <= 1) ||
414 (l1ref0[0] < 0 && !l1ref1[0] &&
415 FFABS(l1mv1[0][0]) <= 1 &&
416 FFABS(l1mv1[0][1]) <= 1 &&
417 h->x264_build > 33U))) {
431 for (i8 = 0; i8 < 4; i8++) {
432 const int x8 = i8 & 1;
433 const int y8 = i8 >> 1;
446 assert(b8_stride == 2);
452 h->x264_build > 33U))) {
453 const int16_t (*l1mv)[2] = l1ref0[i8] == 0 ? l1mv0 : l1mv1;
455 const int16_t *mv_col = l1mv[x8 * 3 + y8 * 3 * b4_stride];
456 if (
FFABS(mv_col[0]) <= 1 &&
FFABS(mv_col[1]) <= 1) {
467 for (i4 = 0; i4 < 4; i4++) {
468 const int16_t *mv_col = l1mv[x8 * 2 + (i4 & 1) +
469 (y8 * 2 + (i4 >> 1)) * b4_stride];
470 if (
FFABS(mv_col[0]) <= 1 &&
FFABS(mv_col[1]) <= 1) {
484 if (!is_b8x8 && !(n & 15))
495 int b4_stride =
h->b_stride;
498 const int16_t (*l1mv0)[2], (*l1mv1)[2];
499 const int8_t *l1ref0, *l1ref1;
500 const int is_b8x8 =
IS_8X8(*mb_type);
501 unsigned int sub_mb_type;
522 mb_y = sl->
mb_y & ~1;
523 mb_xy = sl->
mb_x + (sl->
mb_y & ~1) *
h->mb_stride;
526 b8_stride = 2 + 4 *
h->mb_stride;
555 }
else if (!is_b8x8 &&
560 if (!
h->ps.sps->direct_8x8_inference_flag) {
581 l1mv0 += 2 * b4_stride;
582 l1mv1 += 2 * b4_stride;
601 assert(
h->ps.sps->direct_8x8_inference_flag);
603 for (i8 = 0; i8 < 4; i8++) {
604 const int x8 = i8 & 1;
605 const int y8 = i8 >> 1;
607 const int16_t (*l1mv)[2] = l1mv0;
621 ref0 = l1ref0[x8 + y8 * b8_stride];
623 ref0 = map_col_to_list0[0][ref0 + ref_offset];
625 ref0 = map_col_to_list0[1][l1ref1[x8 + y8 * b8_stride] +
629 scale = dist_scale_factor[ref0];
634 const int16_t *mv_col = l1mv[x8 * 3 + y8 * b4_stride];
635 int my_col = (mv_col[1] * (1 << y_shift)) / 2;
636 int mx = (scale * mv_col[0] + 128) >> 8;
637 int my = (scale * my_col + 128) >> 8;
656 const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset]
657 : map_col_to_list0[1][l1ref1[0] + ref_offset];
658 const int scale = dist_scale_factor[ref0];
659 const int16_t *mv_col = l1ref0[0] >= 0 ? l1mv0[0] : l1mv1[0];
661 mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
662 mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
665 mv1 =
pack16to32(mv_l0[0] - mv_col[0], mv_l0[1] - mv_col[1]);
671 for (i8 = 0; i8 < 4; i8++) {
672 const int x8 = i8 & 1;
673 const int y8 = i8 >> 1;
675 const int16_t (*l1mv)[2] = l1mv0;
688 assert(b8_stride == 2);
691 ref0 = map_col_to_list0[0][ref0 + ref_offset];
693 ref0 = map_col_to_list0[1][l1ref1[i8] + ref_offset];
696 scale = dist_scale_factor[ref0];
701 const int16_t *mv_col = l1mv[x8 * 3 + y8 * 3 * b4_stride];
702 int mx = (scale * mv_col[0] + 128) >> 8;
703 int my = (scale * mv_col[1] + 128) >> 8;
707 pack16to32(mx - mv_col[0], my - mv_col[1]), 4);
709 for (i4 = 0; i4 < 4; i4++) {
710 const int16_t *mv_col = l1mv[x8 * 2 + (i4 & 1) +
711 (y8 * 2 + (i4 >> 1)) * b4_stride];
713 mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
714 mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
717 mv_l0[1] - mv_col[1]));
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define FF_THREAD_FRAME
Decode more than one frame at once.
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static void fill_rectangle(int x, int y, int w, int h)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
void ff_h264_direct_ref_list_init(const H264Context *const h, H264SliceContext *sl)
static int get_scale_factor(H264SliceContext *sl, int poc, int poc1, int i)
static void pred_spatial_direct_motion(const H264Context *const h, H264SliceContext *sl, int *mb_type)
static void await_reference_mb_row(const H264Context *const h, H264Ref *ref, int mb_y)
static void fill_colmap(const H264Context *h, H264SliceContext *sl, int map[2][16+32], int list, int field, int colfield, int mbafi)
static void pred_temp_direct_motion(const H264Context *const h, H264SliceContext *sl, int *mb_type)
void ff_h264_direct_dist_scale_factor(const H264Context *const h, H264SliceContext *sl)
void ff_h264_pred_direct_motion(const H264Context *const h, H264SliceContext *sl, int *mb_type)
#define MB_TYPE_16x16_OR_INTRA
H.264 parameter set handling.
H.264 / AVC / MPEG-4 part10 codec.
static const uint8_t scan8[16 *3+3]
static av_always_inline uint32_t pack16to32(unsigned a, unsigned b)
#define PART_NOT_AVAILABLE
const VDPAUPixFmtMap * map
static const int8_t mv[256][2]
common internal API header
static const uint16_t mask[17]
#define MB_TYPE_INTERLACED
#define PICT_BOTTOM_FIELD
void ff_thread_await_progress(ThreadFrame *f, int n, int field)
Wait for earlier decoding threads to finish reference pictures.
useful rectangle filling function
int ref_count[2][2]
number of entries in ref_poc (FIXME need per slice)
int16_t(*[2] motion_val)[2]
int frame_num
frame_num (raw frame_num from slice header)
int long_ref
1->long term reference 0->short term reference
int ref_poc[2][2][32]
POCs of the frames/fields used as reference (FIXME need per slice)
int field_poc[2]
top/bottom POC
int mbaff
1 -> MBAFF frame 0-> not MBAFF
int8_t ref_cache[2][5 *8]
int dist_scale_factor_field[2][32]
uint16_t sub_mb_type[4]
as a DCT coefficient is int32_t in high depth, we need to reserve twice the space.
int dist_scale_factor[32]
int16_t mv_cache[2][5 *8][2]
Motion vector cache.
struct H264Context * h264
int map_col_to_list0[2][16+32]
int slice_type_nos
S free slice type (SI/SP are remapped to I/P)
H264Ref ref_list[2][48]
0..15: frame refs, 16..47: mbaff field refs.
int direct_spatial_mv_pred
int map_col_to_list0_field[2][2][16+32]
unsigned int ref_count[2]
num_ref_idx_l0/1_active_minus1 + 1
#define avpriv_request_sample(...)
static int ref[MAX_W *MAX_W]