mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
avcodec/av1dec: expose skip mode frame index
Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org> Co-authored-by: James Almer <jamrial@gmail.com>
This commit is contained in:
parent
f6dc285fb5
commit
e1efff8906
@ -145,6 +145,78 @@ static void global_motion_params(AV1DecContext *s)
|
||||
}
|
||||
}
|
||||
|
||||
static int get_relative_dist(const AV1RawSequenceHeader *seq,
|
||||
unsigned int a, unsigned int b)
|
||||
{
|
||||
unsigned int diff = a - b;
|
||||
unsigned int m = 1 << seq->order_hint_bits_minus_1;
|
||||
return (diff & (m - 1)) - (diff & m);
|
||||
}
|
||||
|
||||
static void skip_mode_params(AV1DecContext *s)
|
||||
{
|
||||
const AV1RawFrameHeader *header = s->raw_frame_header;
|
||||
const AV1RawSequenceHeader *seq = s->raw_seq;
|
||||
|
||||
int forward_idx, backward_idx;
|
||||
int forward_hint, backward_hint;
|
||||
int second_forward_idx, second_forward_hint;
|
||||
int ref_hint, dist, i;
|
||||
|
||||
if (!header->skip_mode_present)
|
||||
return;
|
||||
|
||||
forward_idx = -1;
|
||||
backward_idx = -1;
|
||||
for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
|
||||
ref_hint = s->ref[header->ref_frame_idx[i]].order_hint;
|
||||
dist = get_relative_dist(seq, ref_hint, header->order_hint);
|
||||
if (dist < 0) {
|
||||
if (forward_idx < 0 ||
|
||||
get_relative_dist(seq, ref_hint, forward_hint) > 0) {
|
||||
forward_idx = i;
|
||||
forward_hint = ref_hint;
|
||||
}
|
||||
} else if (dist > 0) {
|
||||
if (backward_idx < 0 ||
|
||||
get_relative_dist(seq, ref_hint, backward_hint) < 0) {
|
||||
backward_idx = i;
|
||||
backward_hint = ref_hint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (forward_idx < 0) {
|
||||
return;
|
||||
} else if (backward_idx >= 0) {
|
||||
s->cur_frame.skip_mode_frame_idx[0] =
|
||||
AV1_REF_FRAME_LAST + FFMIN(forward_idx, backward_idx);
|
||||
s->cur_frame.skip_mode_frame_idx[1] =
|
||||
AV1_REF_FRAME_LAST + FFMAX(forward_idx, backward_idx);
|
||||
return;
|
||||
}
|
||||
|
||||
second_forward_idx = -1;
|
||||
for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
|
||||
ref_hint = s->ref[header->ref_frame_idx[i]].order_hint;
|
||||
if (get_relative_dist(seq, ref_hint, forward_hint) < 0) {
|
||||
if (second_forward_idx < 0 ||
|
||||
get_relative_dist(seq, ref_hint, second_forward_hint) > 0) {
|
||||
second_forward_idx = i;
|
||||
second_forward_hint = ref_hint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (second_forward_idx < 0)
|
||||
return;
|
||||
|
||||
s->cur_frame.skip_mode_frame_idx[0] =
|
||||
AV1_REF_FRAME_LAST + FFMIN(forward_idx, second_forward_idx);
|
||||
s->cur_frame.skip_mode_frame_idx[1] =
|
||||
AV1_REF_FRAME_LAST + FFMAX(forward_idx, second_forward_idx);
|
||||
}
|
||||
|
||||
static int init_tile_data(AV1DecContext *s)
|
||||
|
||||
{
|
||||
@ -318,6 +390,9 @@ static void av1_frame_unref(AVCodecContext *avctx, AV1Frame *f)
|
||||
av_buffer_unref(&f->hwaccel_priv_buf);
|
||||
f->hwaccel_picture_private = NULL;
|
||||
f->spatial_id = f->temporal_id = 0;
|
||||
f->order_hint = 0;
|
||||
memset(f->skip_mode_frame_idx, 0,
|
||||
2 * sizeof(uint8_t));
|
||||
}
|
||||
|
||||
static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *src)
|
||||
@ -343,6 +418,10 @@ static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *s
|
||||
memcpy(dst->gm_params,
|
||||
src->gm_params,
|
||||
AV1_NUM_REF_FRAMES * 6 * sizeof(int32_t));
|
||||
dst->order_hint = src->order_hint;
|
||||
memcpy(dst->skip_mode_frame_idx,
|
||||
src->skip_mode_frame_idx,
|
||||
2 * sizeof(uint8_t));
|
||||
|
||||
return 0;
|
||||
|
||||
@ -613,6 +692,7 @@ static int get_current_frame(AVCodecContext *avctx)
|
||||
}
|
||||
|
||||
global_motion_params(s);
|
||||
skip_mode_params(s);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -740,6 +820,8 @@ static int av1_decode_frame(AVCodecContext *avctx, void *frame,
|
||||
s->cur_frame.spatial_id = header->spatial_id;
|
||||
s->cur_frame.temporal_id = header->temporal_id;
|
||||
|
||||
s->cur_frame.order_hint = s->raw_frame_header->order_hint;
|
||||
|
||||
if (avctx->hwaccel) {
|
||||
ret = avctx->hwaccel->start_frame(avctx, unit->data,
|
||||
unit->data_size);
|
||||
|
@ -41,6 +41,9 @@ typedef struct AV1Frame {
|
||||
|
||||
uint8_t gm_type[AV1_NUM_REF_FRAMES];
|
||||
int32_t gm_params[AV1_NUM_REF_FRAMES][6];
|
||||
|
||||
uint8_t order_hint;
|
||||
uint8_t skip_mode_frame_idx[2];
|
||||
} AV1Frame;
|
||||
|
||||
typedef struct TileGroupInfo {
|
||||
|
Loading…
Reference in New Issue
Block a user