38 int poc,
int poc1,
int i)
41 int td = av_clip_int8(poc1 - poc0);
45 int tb = av_clip_int8(poc - poc0);
46 int tx = (16384 + (
FFABS(td) >> 1)) /
td;
47 return av_clip_intp2((tb * tx + 32) >> 6, 10);
60 for (field = 0; field < 2; field++) {
63 for (i = 0; i < 2 * sl->
ref_count[0]; i++)
73 int map[2][16 + 32],
int list,
74 int field,
int colfield,
int mbafi)
77 int j, old_ref, rfield;
78 int start = mbafi ? 16 : 0;
83 memset(map[list], 0,
sizeof(map[list]));
85 for (rfield = 0; rfield < 2; rfield++) {
86 for (old_ref = 0; old_ref < ref1->
ref_count[colfield][list]; old_ref++) {
87 int poc = ref1->
ref_poc[colfield][list][old_ref];
92 else if (interl && (poc & 3) == 3)
93 poc = (poc & ~3) + rfield + 1;
95 for (j = start; j <
end; j++) {
98 int cur_ref = mbafi ? (j - 16) ^ field : j;
100 map[list][2 * old_ref + (rfield ^ field) + 16] = cur_ref;
101 if (rfield == field || !interl)
102 map[list][old_ref] = cur_ref;
116 int ref1sidx = (ref1->
reference & 1) ^ 1;
118 for (list = 0; list < sl->
list_count; list++) {
120 for (j = 0; j < sl->
ref_count[list]; j++)
141 FFABS(col_poc[1] - cur_poc));
153 for (list = 0; list < 2; list++) {
156 for (field = 0; field < 2; field++)
167 int ref_height = 16 * h->
mb_height >> ref_field_picture;
176 FFMIN(16 * mb_y >> ref_field_picture,
178 ref_field_picture && ref_field);
188 const int16_t (*l1mv0)[2], (*l1mv1)[2];
189 const int8_t *l1ref0, *l1ref1;
190 const int is_b8x8 =
IS_8X8(*mb_type);
202 #define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16 | MB_TYPE_INTRA4x4 | \
203 MB_TYPE_INTRA16x16 | MB_TYPE_INTRA_PCM)
206 for (list = 0; list < 2; list++) {
215 ref[list] =
FFMIN3((
unsigned)left_ref,
218 if (ref[list] >= 0) {
224 int match_count = (left_ref == ref[list]) +
225 (top_ref == ref[list]) +
228 if (match_count > 1) {
232 assert(match_count == 1);
233 if (left_ref == ref[list])
235 else if (top_ref == ref[list])
250 if (ref[0] < 0 && ref[1] < 0) {
257 if (!(is_b8x8 | mv[0] | mv[1])) {
281 mb_y = sl->
mb_y & ~1;
309 }
else if (!is_b8x8 &&
334 l1mv0 += 2 * b4_stride;
335 l1mv1 += 2 * b4_stride;
341 for (i8 = 0; i8 < 4; i8++) {
344 int xy8 = x8 + y8 * b8_stride;
345 int xy4 = x8 * 3 + y8 * b4_stride;
357 ((l1ref0[xy8] == 0 &&
358 FFABS(l1mv0[xy4][0]) <= 1 &&
359 FFABS(l1mv0[xy4][1]) <= 1) ||
362 FFABS(l1mv1[xy4][0]) <= 1 &&
363 FFABS(l1mv1[xy4][1]) <= 1))) {
378 if (!is_b8x8 && !(n & 3))
389 FFABS(l1mv0[0][0]) <= 1 &&
390 FFABS(l1mv0[0][1]) <= 1) ||
391 (l1ref0[0] < 0 && !l1ref1[0] &&
392 FFABS(l1mv1[0][0]) <= 1 &&
393 FFABS(l1mv1[0][1]) <= 1 &&
408 for (i8 = 0; i8 < 4; i8++) {
409 const int x8 = i8 & 1;
410 const int y8 = i8 >> 1;
423 assert(b8_stride == 2);
430 const int16_t (*l1mv)[2] = l1ref0[i8] == 0 ? l1mv0 : l1mv1;
432 const int16_t *mv_col = l1mv[x8 * 3 + y8 * 3 * b4_stride];
433 if (
FFABS(mv_col[0]) <= 1 &&
FFABS(mv_col[1]) <= 1) {
444 for (i4 = 0; i4 < 4; i4++) {
445 const int16_t *mv_col = l1mv[x8 * 2 + (i4 & 1) +
446 (y8 * 2 + (i4 >> 1)) * b4_stride];
447 if (
FFABS(mv_col[0]) <= 1 &&
FFABS(mv_col[1]) <= 1) {
461 if (!is_b8x8 && !(n & 15))
475 const int16_t (*l1mv0)[2], (*l1mv1)[2];
476 const int8_t *l1ref0, *l1ref1;
477 const int is_b8x8 =
IS_8X8(*mb_type);
478 unsigned int sub_mb_type;
499 mb_y = sl->
mb_y & ~1;
532 }
else if (!is_b8x8 &&
558 l1mv0 += 2 * b4_stride;
559 l1mv1 += 2 * b4_stride;
580 for (i8 = 0; i8 < 4; i8++) {
581 const int x8 = i8 & 1;
582 const int y8 = i8 >> 1;
584 const int16_t (*l1mv)[2] = l1mv0;
598 ref0 = l1ref0[x8 + y8 * b8_stride];
600 ref0 = map_col_to_list0[0][ref0 + ref_offset];
602 ref0 = map_col_to_list0[1][l1ref1[x8 + y8 * b8_stride] +
606 scale = dist_scale_factor[ref0];
611 const int16_t *mv_col = l1mv[x8 * 3 + y8 * b4_stride];
612 int my_col = (mv_col[1] << y_shift) / 2;
613 int mx = (scale * mv_col[0] + 128) >> 8;
614 int my = (scale * my_col + 128) >> 8;
633 const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset]
634 : map_col_to_list0[1][l1ref1[0] + ref_offset];
635 const int scale = dist_scale_factor[ref0];
636 const int16_t *mv_col = l1ref0[0] >= 0 ? l1mv0[0] : l1mv1[0];
638 mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
639 mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
642 mv1 =
pack16to32(mv_l0[0] - mv_col[0], mv_l0[1] - mv_col[1]);
648 for (i8 = 0; i8 < 4; i8++) {
649 const int x8 = i8 & 1;
650 const int y8 = i8 >> 1;
652 const int16_t (*l1mv)[2] = l1mv0;
665 assert(b8_stride == 2);
668 ref0 = map_col_to_list0[0][ref0 + ref_offset];
670 ref0 = map_col_to_list0[1][l1ref1[i8] + ref_offset];
673 scale = dist_scale_factor[ref0];
678 const int16_t *mv_col = l1mv[x8 * 3 + y8 * 3 * b4_stride];
679 int mx = (scale * mv_col[0] + 128) >> 8;
680 int my = (scale * mv_col[1] + 128) >> 8;
684 pack16to32(mx - mv_col[0], my - mv_col[1]), 4);
686 for (i4 = 0; i4 < 4; i4++) {
687 const int16_t *mv_col = l1mv[x8 * 2 + (i4 & 1) +
688 (y8 * 2 + (i4 >> 1)) * b4_stride];
690 mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
691 mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
694 mv_l0[1] - mv_col[1]));
static void pred_spatial_direct_motion(const H264Context *const h, H264SliceContext *sl, int *mb_type)
int long_ref
1->long term reference 0->short term reference
int16_t mv_cache[2][5 *8][2]
Motion vector cache.
int dist_scale_factor[32]
int16_t(*[2] motion_val)[2]
void ff_h264_pred_direct_motion(const H264Context *const h, H264SliceContext *sl, int *mb_type)
void ff_thread_await_progress(ThreadFrame *f, int n, int field)
Wait for earlier decoding threads to finish reference pictures.
unsigned int ref_count[2]
num_ref_idx_l0/1_active_minus1 + 1
uint16_t sub_mb_type[4]
as a dct coefficient is int32_t in high depth, we need to reserve twice the space.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
int field_picture
whether or not picture was encoded in separate fields
static av_cold int end(AVCodecContext *avctx)
Multithreading support functions.
int map_col_to_list0_field[2][2][16+32]
#define PICT_BOTTOM_FIELD
static void fill_rectangle(SDL_Surface *screen, int x, int y, int w, int h, int color, int update)
void ff_h264_direct_ref_list_init(const H264Context *const h, H264SliceContext *sl)
H.264 / AVC / MPEG4 part10 codec.
static void await_reference_mb_row(const H264Context *const h, H264Ref *ref, int mb_y)
static const uint16_t mask[17]
int map_col_to_list0[2][16+32]
int active_thread_type
Which multithreading methods are in use by the codec.
int ref_poc[2][2][32]
POCs of the frames/fields used as reference (FIXME need per slice)
int direct_spatial_mv_pred
int frame_num
frame_num (raw frame_num from slice header)
static av_always_inline uint32_t pack16to32(unsigned a, unsigned b)
Libavcodec external API header.
#define MB_TYPE_16x16_OR_INTRA
int slice_type_nos
S free slice type (SI/SP are remapped to I/P)
static const uint8_t scan8[16 *3+3]
useful rectangle filling function
static void pred_temp_direct_motion(const H264Context *const h, H264SliceContext *sl, int *mb_type)
#define MB_TYPE_INTERLACED
int direct_8x8_inference_flag
#define PART_NOT_AVAILABLE
static int get_scale_factor(H264SliceContext *sl, int poc, int poc1, int i)
static const int8_t mv[256][2]
int field_poc[2]
top/bottom POC
#define FF_THREAD_FRAME
Decode more than one frame at once.
H264Picture * cur_pic_ptr
static void fill_colmap(const H264Context *h, H264SliceContext *sl, int map[2][16+32], int list, int field, int colfield, int mbafi)
int mbaff
1 -> MBAFF frame 0-> not MBAFF
common internal api header.
int8_t ref_cache[2][5 *8]
H264Ref ref_list[2][48]
0..15: frame refs, 16..47: mbaff field refs.
int ref_count[2][2]
number of entries in ref_poc (FIXME need per slice)
int dist_scale_factor_field[2][32]
void ff_h264_direct_dist_scale_factor(const H264Context *const h, H264SliceContext *sl)