Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions drivers/media/platform/apple/avd/avd-h264-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,31 @@ static void avd_slice_fits_test(struct kunit *test)
c->fits);
}

static void avd_scaling_flat_test(struct kunit *test)
{
struct v4l2_ctrl_h264_pps pps = {};
struct v4l2_ctrl_h264_scaling_matrix *m;

m = kunit_kzalloc(test, sizeof(*m), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, m);
memset(m->scaling_list_4x4, 16, sizeof(m->scaling_list_4x4));
memset(m->scaling_list_8x8, 16, sizeof(m->scaling_list_8x8));
KUNIT_EXPECT_TRUE(test, avd_h264_scaling_is_flat(&pps, m));

/* The 8x8 lists only count with transform_8x8_mode. */
m->scaling_list_8x8[1][63] = 17;
KUNIT_EXPECT_TRUE(test, avd_h264_scaling_is_flat(&pps, m));
pps.flags = V4L2_H264_PPS_FLAG_TRANSFORM_8X8_MODE;
KUNIT_EXPECT_FALSE(test, avd_h264_scaling_is_flat(&pps, m));

m->scaling_list_8x8[1][63] = 16;
KUNIT_EXPECT_TRUE(test, avd_h264_scaling_is_flat(&pps, m));
m->scaling_list_4x4[5][15] = 6;
KUNIT_EXPECT_FALSE(test, avd_h264_scaling_is_flat(&pps, m));
}

static struct kunit_case avd_h264_test_cases[] = {
KUNIT_CASE(avd_scaling_flat_test),
KUNIT_CASE_PARAM(avd_slice_data_test, avd_slice_data_gen_params),
KUNIT_CASE_PARAM(avd_slice_fits_test, avd_slice_fits_gen_params),
{}
Expand Down
29 changes: 28 additions & 1 deletion drivers/media/platform/apple/avd/avd-h264.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,31 @@ static void stream_scaling(struct avd_ctx *ctx, struct avd_h264_run *run)
}
}

/*
* A scaling matrix whose used lists are all 16 is Flat_4x4_16/Flat_8x8_16,
* which is what the decoder applies when no list is loaded (H.264 7.4.2.1.1).
* FFmpeg and the VA path always hand one over, so loading it per picture
* costs PP time for nothing; macOS leaves the list section empty here.
*/
VISIBLE_IF_KUNIT bool
avd_h264_scaling_is_flat(const struct v4l2_ctrl_h264_pps *pps,
const struct v4l2_ctrl_h264_scaling_matrix *scaling)
{
for (int i = 0; i < 6; i++)
for (int j = 0; j < 16; j++)
if (scaling->scaling_list_4x4[i][j] != 16)
return false;

if (pps->flags & V4L2_H264_PPS_FLAG_TRANSFORM_8X8_MODE)
for (int i = 0; i < 2; i++)
for (int j = 0; j < 64; j++)
if (scaling->scaling_list_8x8[i][j] != 16)
return false;

return true;
}
EXPORT_SYMBOL_IF_KUNIT(avd_h264_scaling_is_flat);

static bool avd_h264_intra_header(const struct avd_h264_run *run)
{
/*
Expand Down Expand Up @@ -336,7 +361,8 @@ static void stream_hdr(struct avd_ctx *ctx, struct avd_h264_run *run)
if (!intra_header)
stream_refs(ctx, run);

if (pps->flags & V4L2_H264_PPS_FLAG_SCALING_MATRIX_PRESENT)
if ((pps->flags & V4L2_H264_PPS_FLAG_SCALING_MATRIX_PRESENT) &&
!avd_h264_scaling_is_flat(pps, run->scaling_matrix))
stream_scaling(ctx, run);
else
push(0, "cm3_mark_end_section_scl");
Expand Down Expand Up @@ -541,6 +567,7 @@ static void stream_slice(struct avd_ctx *ctx, struct avd_h264_run *run)
push(AVD_OP_SL_REF | AVD_OP_SL_REF_FLAG_CABAC(sl->cabac_init_idc == 1) |
AVD_OP_SL_REF_FLAG1(sl->cabac_init_idc == 2) |
AVD_OP_SL_REF_FLAG2(
sl->slice_type == V4L2_H264_SLICE_TYPE_B &&
!(sl->flags &
V4L2_H264_SLICE_FLAG_DIRECT_SPATIAL_MV_PRED)) |
AVD_OP_SL_REF_NUM_L0(sl->num_ref_idx_l0_active_minus1) |
Expand Down
1 change: 1 addition & 0 deletions drivers/media/platform/apple/avd/avd-hevc.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ static void stream_slice_mv(struct avd_ctx *ctx, struct avd_hevc_run *run,
!(sl->flags &
V4L2_HEVC_SLICE_PARAMS_FLAG_COLLOCATED_FROM_L0)) |
AVD_OP_SL_REF_FLAG1(
sl->slice_type == V4L2_HEVC_SLICE_TYPE_B &&
!(sl->flags &
V4L2_HEVC_SLICE_PARAMS_FLAG_MVD_L1_ZERO)) |
AVD_OP_SL_REF_FLAG2(
Expand Down
2 changes: 2 additions & 0 deletions drivers/media/platform/apple/avd/avd.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ bool avd_h264_find_slice_data(const u8 *data, u32 len, u32 header_len,
u32 *off);
bool avd_h264_slice_fits(const struct v4l2_ctrl_h264_sps *sps, size_t held,
size_t held_bytes, u32 len, size_t decoded_size);
bool avd_h264_scaling_is_flat(const struct v4l2_ctrl_h264_pps *pps,
const struct v4l2_ctrl_h264_scaling_matrix *scaling);
#endif

extern const struct avd_coded_fmt_ops avd_h264_fmt_ops;
Expand Down
11 changes: 11 additions & 0 deletions drivers/media/platform/apple/avd/tests/program-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
#define DIV_ROUND_UP(n,d) (((n)+(d)-1)/(d))
#define VISIBLE_IF_KUNIT
#define EXPORT_SYMBOL_IF_KUNIT(sym)
#define AVD_QUIRK_LSR 1
#define AVD_QUIRK_NO_PIPE_STATE 2
#define AVD_QUIRK_H264_MV_128 (1U << 4)
Expand Down Expand Up @@ -728,6 +729,16 @@ def conformance(out):
data = subprocess.check_output([str(exe)], text=True)
programs[label] = dict(line.split(' ', 1) for line in data.splitlines())
(out / (label + '.json')).write_text(json.dumps(programs[label], indent=2) + '\n')
# The baseline set the temporal-direct bit (15) of the slice reference
# header word for every slice; it belongs to B slices only. Clear it in
# the baseline I/P programs so the checks below compare everything else.
for key, program in programs['before'].items():
parts = key.split('/')
if len(parts) == 5 and parts[0].isdigit() and parts[2] != '1':
programs['before'][key] = ' '.join(
f'{int(w, 16) & ~0x8000:08x}'
if len(w) == 8 and int(w, 16) >> 18 == 0x2d << 6 else w
for w in program.split())
unchanged = sparse = normalized = 0
for key, program in programs['after'].items():
if key.startswith('guard/type/'):
Expand Down
Loading