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
5 changes: 3 additions & 2 deletions drivers/media/platform/apple/avd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
apple-avd-y := avd-drv.o avd-v4l2.o avd-hw.o avd-pm.o avd-h264.o avd-vp9.o \
avd-hevc.o avd-av1.o avd-av1-entropymode.o avd-queue.o avd-backend-open.o \
avd-backend-apple.o avd-backend-queue.o avd-backend-kopsia.o
apple-avd-$(CONFIG_VIDEO_APPLE_AVD_KUNIT_TEST) += avd-h264-test.o avd-queue-test.o \
avd-pm-test.o
apple-avd-$(CONFIG_VIDEO_APPLE_AVD_KUNIT_TEST) += avd-h264-test.o \
avd-queue-test.o avd-pm-test.o avd-hevc-test.o avd-job-test.o \
avd-vp9-test.o
obj-$(CONFIG_VIDEO_APPLE_AVD) += apple-avd.o
3 changes: 3 additions & 0 deletions drivers/media/platform/apple/avd/avd-backend-open.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ int avd_open_build_program(struct avd_ctx *ctx)

if (!f || !job->segments)
return -EINVAL;
/* The builder ran past the table or a segment; nothing fits. */
if (job->overflow || job->num >= job->max)
return -EOVERFLOW;
for (i = 0; i <= job->num; i++) {
if (job->segments[i].num > AVD_MAX_INST ||
check_add_overflow(count, job->segments[i].num + !!i, &count))
Expand Down
2 changes: 2 additions & 0 deletions drivers/media/platform/apple/avd/avd-drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ int avd_init_job(struct avd_ctx *ctx, enum avd_codec codec, size_t segments)

job->codec = codec;
job->num = 0;
job->overflow = false;
/* A table that was built but never submitted still belongs to us. */
kvfree(job->segments);
job->segments = kvcalloc(segments, sizeof(*job->segments), GFP_KERNEL);
job->max = job->segments ? segments : 0;
if (!job->segments)
ret = -ENOMEM;
return ret;
Expand Down
1 change: 1 addition & 0 deletions drivers/media/platform/apple/avd/avd-h264.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,7 @@ static int avd_h264_realloc_slices(struct avd_ctx *ctx, size_t max_slices)

memcpy(ctx->job.segments, tmp,
sizeof(*ctx->job.segments) * (ctx->job.num + 1));
ctx->job.max = alloc_slice_num + 1;
kvfree(tmp);

return 0;
Expand Down
182 changes: 182 additions & 0 deletions drivers/media/platform/apple/avd/avd-hevc-test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
// SPDX-License-Identifier: GPL-2.0
/*
* KUnit tests for the HEVC picture, tile and slice checks of the Apple video
* decoder.
*/

#include <kunit/test.h>

#include "avd.h"

/* 64x64 luma samples in 16x16 CTBs: 4x4 CTBs. */
static void avd_hevc_test_sps(struct v4l2_ctrl_hevc_sps *sps)
{
*sps = (struct v4l2_ctrl_hevc_sps) {
.pic_width_in_luma_samples = 64,
.pic_height_in_luma_samples = 64,
.log2_min_luma_coding_block_size_minus3 = 0,
.log2_diff_max_min_luma_coding_block_size = 1,
};
}

struct avd_hevc_geometry_case {
const char *desc;
u16 width;
u16 height;
u8 min_cb_minus3;
u8 diff;
int ret;
};

static const struct avd_hevc_geometry_case avd_hevc_geometry_cases[] = {
{ "16x16 CTBs", 64, 64, 0, 1, 0 },
{ "32x32 CTBs", 1920, 1080, 0, 2, 0 },
{ "64x64 CTBs", 4096, 2160, 0, 3, 0 },
{ "64x64 CTBs from 16x16 coding blocks", 4096, 2160, 1, 2, 0 },
{ "8x8 CTBs", 64, 64, 0, 0, -EINVAL },
{ "128x128 CTBs", 64, 64, 0, 4, -EINVAL },
{ "coding block size beyond any CTB", 64, 64, 255, 255, -EINVAL },
{ "zero width", 0, 64, 0, 1, -EINVAL },
{ "zero height", 64, 0, 0, 1, -EINVAL },
};

KUNIT_ARRAY_PARAM_DESC(avd_hevc_geometry, avd_hevc_geometry_cases, desc);

static void avd_hevc_geometry_test(struct kunit *test)
{
const struct avd_hevc_geometry_case *c = test->param_value;
struct v4l2_ctrl_hevc_sps sps = {
.pic_width_in_luma_samples = c->width,
.pic_height_in_luma_samples = c->height,
.log2_min_luma_coding_block_size_minus3 = c->min_cb_minus3,
.log2_diff_max_min_luma_coding_block_size = c->diff,
};

KUNIT_EXPECT_EQ(test, avd_hevc_check_sps_geometry(&sps), c->ret);
}

struct avd_hevc_tiles_case {
const char *desc;
bool uniform;
u8 cols_minus1;
u8 rows_minus1;
u8 col_width_minus1[2];
u8 row_height_minus1[2];
int ret;
/* tile id of every CTB in tile scan order, if accepted */
u32 ids[16];
};

static const struct avd_hevc_tiles_case avd_hevc_tiles_cases[] = {
{ "explicit 2x2 tiles", false, 1, 1, { 0 }, { 1 }, 0,
{ 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3 } },
{ "explicit 3x1 tiles", false, 2, 0, { 1, 0 }, { 0 }, 0,
{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2 } },
{ "uniform 3x1 tiles", true, 2, 0, { 0 }, { 0 }, 0,
{ 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2 } },
{ "uniform 4x4 tiles", true, 3, 3, { 0 }, { 0 }, 0,
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } },
{ "explicit columns leave the last one empty", false, 1, 0, { 3 },
{ 0 }, -EINVAL },
{ "explicit columns wider than the picture", false, 1, 0, { 4 },
{ 0 }, -EINVAL },
{ "explicit columns far wider than the picture", false, 2, 0,
{ 200, 200 }, { 0 }, -EINVAL },
{ "explicit rows taller than the picture", false, 0, 1, { 0 },
{ 4 }, -EINVAL },
{ "explicit rows leave the last one empty", false, 0, 2, { 0 },
{ 1, 1 }, -EINVAL },
{ "uniform, more columns than CTBs", true, 4, 0, { 0 }, { 0 },
-EINVAL },
{ "uniform, more rows than CTBs", true, 0, 4, { 0 }, { 0 },
-EINVAL },
};

KUNIT_ARRAY_PARAM_DESC(avd_hevc_tiles, avd_hevc_tiles_cases, desc);

static void avd_hevc_tiles_test(struct kunit *test)
{
const struct avd_hevc_tiles_case *c = test->param_value;
struct v4l2_ctrl_hevc_sps sps;
struct v4l2_ctrl_hevc_pps pps = {
.flags = V4L2_HEVC_PPS_FLAG_TILES_ENABLED |
(c->uniform ? V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING : 0),
.num_tile_columns_minus1 = c->cols_minus1,
.num_tile_rows_minus1 = c->rows_minus1,
};
u32 ids[16];

avd_hevc_test_sps(&sps);
memcpy(pps.column_width_minus1, c->col_width_minus1,
sizeof(c->col_width_minus1));
memcpy(pps.row_height_minus1, c->row_height_minus1,
sizeof(c->row_height_minus1));

KUNIT_EXPECT_EQ(test, avd_hevc_check_tiles(&sps, &pps), c->ret);

/* The table builder must refuse the same layouts, before any write. */
memset(ids, 0xff, sizeof(ids));
KUNIT_ASSERT_EQ(test,
avd_hevc_kunit_compute_tiles(&sps, &pps, ids,
ARRAY_SIZE(ids)),
c->ret);
if (!c->ret)
KUNIT_EXPECT_MEMEQ(test, ids, c->ids, sizeof(ids));
}

/*
* More tile columns or rows than the PPS control has size entries for are
* refused by the check itself, even for a picture wide or tall enough.
*/
static void avd_hevc_tiles_array_test(struct kunit *test)
{
struct v4l2_ctrl_hevc_sps sps;
struct v4l2_ctrl_hevc_pps pps = {
.flags = V4L2_HEVC_PPS_FLAG_TILES_ENABLED |
V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING,
};

avd_hevc_test_sps(&sps);
sps.pic_width_in_luma_samples = 8192;
sps.pic_height_in_luma_samples = 4320;

pps.num_tile_columns_minus1 = ARRAY_SIZE(pps.column_width_minus1) - 1;
pps.num_tile_rows_minus1 = ARRAY_SIZE(pps.row_height_minus1) - 1;
KUNIT_EXPECT_EQ(test, avd_hevc_check_tiles(&sps, &pps), 0);

pps.num_tile_columns_minus1 = ARRAY_SIZE(pps.column_width_minus1);
KUNIT_EXPECT_EQ(test, avd_hevc_check_tiles(&sps, &pps), -EINVAL);

pps.num_tile_columns_minus1 = ARRAY_SIZE(pps.column_width_minus1) - 1;
pps.num_tile_rows_minus1 = ARRAY_SIZE(pps.row_height_minus1);
KUNIT_EXPECT_EQ(test, avd_hevc_check_tiles(&sps, &pps), -EINVAL);
}

static void avd_hevc_no_tiles_test(struct kunit *test)
{
struct v4l2_ctrl_hevc_sps sps;
struct v4l2_ctrl_hevc_pps pps = {};
u32 ids[16];

avd_hevc_test_sps(&sps);
KUNIT_EXPECT_EQ(test, avd_hevc_check_tiles(&sps, &pps), 0);
KUNIT_EXPECT_EQ(test,
avd_hevc_kunit_compute_tiles(&sps, &pps, ids,
ARRAY_SIZE(ids)),
0);
}

static struct kunit_case avd_hevc_test_cases[] = {
KUNIT_CASE_PARAM(avd_hevc_geometry_test, avd_hevc_geometry_gen_params),
KUNIT_CASE_PARAM(avd_hevc_tiles_test, avd_hevc_tiles_gen_params),
KUNIT_CASE(avd_hevc_tiles_array_test),
KUNIT_CASE(avd_hevc_no_tiles_test),
{}
};

static struct kunit_suite avd_hevc_test_suite = {
.name = "apple-avd-hevc",
.test_cases = avd_hevc_test_cases,
};

kunit_test_suite(avd_hevc_test_suite);
Loading
Loading