Commit 29f0133e authored by Stanimir Varbanov's avatar Stanimir Varbanov Committed by Mauro Carvalho Chehab

media: venus: use helper function to check supported codecs

Use the helper function in decoder and encoder find_format
to runtime check supported codecs.
Signed-off-by: default avatarStanimir Varbanov <stanimir.varbanov@linaro.org>
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent d8db57c2
...@@ -102,7 +102,8 @@ static const struct venus_format vdec_formats[] = { ...@@ -102,7 +102,8 @@ static const struct venus_format vdec_formats[] = {
}, },
}; };
static const struct venus_format *find_format(u32 pixfmt, u32 type) static const struct venus_format *
find_format(struct venus_inst *inst, u32 pixfmt, u32 type)
{ {
const struct venus_format *fmt = vdec_formats; const struct venus_format *fmt = vdec_formats;
unsigned int size = ARRAY_SIZE(vdec_formats); unsigned int size = ARRAY_SIZE(vdec_formats);
...@@ -116,11 +117,15 @@ static const struct venus_format *find_format(u32 pixfmt, u32 type) ...@@ -116,11 +117,15 @@ static const struct venus_format *find_format(u32 pixfmt, u32 type)
if (i == size || fmt[i].type != type) if (i == size || fmt[i].type != type)
return NULL; return NULL;
if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE &&
!venus_helper_check_codec(inst, fmt[i].pixfmt))
return NULL;
return &fmt[i]; return &fmt[i];
} }
static const struct venus_format * static const struct venus_format *
find_format_by_index(unsigned int index, u32 type) find_format_by_index(struct venus_inst *inst, unsigned int index, u32 type)
{ {
const struct venus_format *fmt = vdec_formats; const struct venus_format *fmt = vdec_formats;
unsigned int size = ARRAY_SIZE(vdec_formats); unsigned int size = ARRAY_SIZE(vdec_formats);
...@@ -140,6 +145,10 @@ find_format_by_index(unsigned int index, u32 type) ...@@ -140,6 +145,10 @@ find_format_by_index(unsigned int index, u32 type)
if (i == size) if (i == size)
return NULL; return NULL;
if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE &&
!venus_helper_check_codec(inst, fmt[i].pixfmt))
return NULL;
return &fmt[i]; return &fmt[i];
} }
...@@ -154,7 +163,7 @@ vdec_try_fmt_common(struct venus_inst *inst, struct v4l2_format *f) ...@@ -154,7 +163,7 @@ vdec_try_fmt_common(struct venus_inst *inst, struct v4l2_format *f)
memset(pfmt[0].reserved, 0, sizeof(pfmt[0].reserved)); memset(pfmt[0].reserved, 0, sizeof(pfmt[0].reserved));
memset(pixmp->reserved, 0, sizeof(pixmp->reserved)); memset(pixmp->reserved, 0, sizeof(pixmp->reserved));
fmt = find_format(pixmp->pixelformat, f->type); fmt = find_format(inst, pixmp->pixelformat, f->type);
if (!fmt) { if (!fmt) {
if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
pixmp->pixelformat = V4L2_PIX_FMT_NV12; pixmp->pixelformat = V4L2_PIX_FMT_NV12;
...@@ -162,7 +171,7 @@ vdec_try_fmt_common(struct venus_inst *inst, struct v4l2_format *f) ...@@ -162,7 +171,7 @@ vdec_try_fmt_common(struct venus_inst *inst, struct v4l2_format *f)
pixmp->pixelformat = V4L2_PIX_FMT_H264; pixmp->pixelformat = V4L2_PIX_FMT_H264;
else else
return NULL; return NULL;
fmt = find_format(pixmp->pixelformat, f->type); fmt = find_format(inst, pixmp->pixelformat, f->type);
pixmp->width = 1280; pixmp->width = 1280;
pixmp->height = 720; pixmp->height = 720;
} }
...@@ -364,11 +373,12 @@ vdec_querycap(struct file *file, void *fh, struct v4l2_capability *cap) ...@@ -364,11 +373,12 @@ vdec_querycap(struct file *file, void *fh, struct v4l2_capability *cap)
static int vdec_enum_fmt(struct file *file, void *fh, struct v4l2_fmtdesc *f) static int vdec_enum_fmt(struct file *file, void *fh, struct v4l2_fmtdesc *f)
{ {
struct venus_inst *inst = to_inst(file);
const struct venus_format *fmt; const struct venus_format *fmt;
memset(f->reserved, 0, sizeof(f->reserved)); memset(f->reserved, 0, sizeof(f->reserved));
fmt = find_format_by_index(f->index, f->type); fmt = find_format_by_index(inst, f->index, f->type);
if (!fmt) if (!fmt)
return -EINVAL; return -EINVAL;
...@@ -417,10 +427,10 @@ static int vdec_enum_framesizes(struct file *file, void *fh, ...@@ -417,10 +427,10 @@ static int vdec_enum_framesizes(struct file *file, void *fh,
struct venus_inst *inst = to_inst(file); struct venus_inst *inst = to_inst(file);
const struct venus_format *fmt; const struct venus_format *fmt;
fmt = find_format(fsize->pixel_format, fmt = find_format(inst, fsize->pixel_format,
V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
if (!fmt) { if (!fmt) {
fmt = find_format(fsize->pixel_format, fmt = find_format(inst, fsize->pixel_format,
V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
if (!fmt) if (!fmt)
return -EINVAL; return -EINVAL;
......
...@@ -91,7 +91,8 @@ static const struct venus_format venc_formats[] = { ...@@ -91,7 +91,8 @@ static const struct venus_format venc_formats[] = {
}, },
}; };
static const struct venus_format *find_format(u32 pixfmt, u32 type) static const struct venus_format *
find_format(struct venus_inst *inst, u32 pixfmt, u32 type)
{ {
const struct venus_format *fmt = venc_formats; const struct venus_format *fmt = venc_formats;
unsigned int size = ARRAY_SIZE(venc_formats); unsigned int size = ARRAY_SIZE(venc_formats);
...@@ -105,11 +106,15 @@ static const struct venus_format *find_format(u32 pixfmt, u32 type) ...@@ -105,11 +106,15 @@ static const struct venus_format *find_format(u32 pixfmt, u32 type)
if (i == size || fmt[i].type != type) if (i == size || fmt[i].type != type)
return NULL; return NULL;
if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE &&
!venus_helper_check_codec(inst, fmt[i].pixfmt))
return NULL;
return &fmt[i]; return &fmt[i];
} }
static const struct venus_format * static const struct venus_format *
find_format_by_index(unsigned int index, u32 type) find_format_by_index(struct venus_inst *inst, unsigned int index, u32 type)
{ {
const struct venus_format *fmt = venc_formats; const struct venus_format *fmt = venc_formats;
unsigned int size = ARRAY_SIZE(venc_formats); unsigned int size = ARRAY_SIZE(venc_formats);
...@@ -129,6 +134,10 @@ find_format_by_index(unsigned int index, u32 type) ...@@ -129,6 +134,10 @@ find_format_by_index(unsigned int index, u32 type)
if (i == size) if (i == size)
return NULL; return NULL;
if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE &&
!venus_helper_check_codec(inst, fmt[i].pixfmt))
return NULL;
return &fmt[i]; return &fmt[i];
} }
...@@ -246,9 +255,10 @@ venc_querycap(struct file *file, void *fh, struct v4l2_capability *cap) ...@@ -246,9 +255,10 @@ venc_querycap(struct file *file, void *fh, struct v4l2_capability *cap)
static int venc_enum_fmt(struct file *file, void *fh, struct v4l2_fmtdesc *f) static int venc_enum_fmt(struct file *file, void *fh, struct v4l2_fmtdesc *f)
{ {
struct venus_inst *inst = to_inst(file);
const struct venus_format *fmt; const struct venus_format *fmt;
fmt = find_format_by_index(f->index, f->type); fmt = find_format_by_index(inst, f->index, f->type);
memset(f->reserved, 0, sizeof(f->reserved)); memset(f->reserved, 0, sizeof(f->reserved));
...@@ -271,7 +281,7 @@ venc_try_fmt_common(struct venus_inst *inst, struct v4l2_format *f) ...@@ -271,7 +281,7 @@ venc_try_fmt_common(struct venus_inst *inst, struct v4l2_format *f)
memset(pfmt[0].reserved, 0, sizeof(pfmt[0].reserved)); memset(pfmt[0].reserved, 0, sizeof(pfmt[0].reserved));
memset(pixmp->reserved, 0, sizeof(pixmp->reserved)); memset(pixmp->reserved, 0, sizeof(pixmp->reserved));
fmt = find_format(pixmp->pixelformat, f->type); fmt = find_format(inst, pixmp->pixelformat, f->type);
if (!fmt) { if (!fmt) {
if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
pixmp->pixelformat = V4L2_PIX_FMT_H264; pixmp->pixelformat = V4L2_PIX_FMT_H264;
...@@ -279,7 +289,7 @@ venc_try_fmt_common(struct venus_inst *inst, struct v4l2_format *f) ...@@ -279,7 +289,7 @@ venc_try_fmt_common(struct venus_inst *inst, struct v4l2_format *f)
pixmp->pixelformat = V4L2_PIX_FMT_NV12; pixmp->pixelformat = V4L2_PIX_FMT_NV12;
else else
return NULL; return NULL;
fmt = find_format(pixmp->pixelformat, f->type); fmt = find_format(inst, pixmp->pixelformat, f->type);
pixmp->width = 1280; pixmp->width = 1280;
pixmp->height = 720; pixmp->height = 720;
} }
...@@ -524,10 +534,10 @@ static int venc_enum_framesizes(struct file *file, void *fh, ...@@ -524,10 +534,10 @@ static int venc_enum_framesizes(struct file *file, void *fh,
fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE; fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
fmt = find_format(fsize->pixel_format, fmt = find_format(inst, fsize->pixel_format,
V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
if (!fmt) { if (!fmt) {
fmt = find_format(fsize->pixel_format, fmt = find_format(inst, fsize->pixel_format,
V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
if (!fmt) if (!fmt)
return -EINVAL; return -EINVAL;
...@@ -554,10 +564,10 @@ static int venc_enum_frameintervals(struct file *file, void *fh, ...@@ -554,10 +564,10 @@ static int venc_enum_frameintervals(struct file *file, void *fh,
fival->type = V4L2_FRMIVAL_TYPE_STEPWISE; fival->type = V4L2_FRMIVAL_TYPE_STEPWISE;
fmt = find_format(fival->pixel_format, fmt = find_format(inst, fival->pixel_format,
V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
if (!fmt) { if (!fmt) {
fmt = find_format(fival->pixel_format, fmt = find_format(inst, fival->pixel_format,
V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
if (!fmt) if (!fmt)
return -EINVAL; return -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment