media: cedrus: choose default pixelformat in try_fmt
If an unsupported pixelformat is passed to try_fmt, then pick the first valid pixelformat instead. This is more standard V4L2 behavior. Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Reviewed-by: Jernej Skrabec <jernej.skrabec@siol.net> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
This commit is contained in:
parent
ae0688f659
commit
dec555256f
@ -62,33 +62,30 @@ static inline struct cedrus_ctx *cedrus_file2ctx(struct file *file)
|
|||||||
static struct cedrus_format *cedrus_find_format(u32 pixelformat, u32 directions,
|
static struct cedrus_format *cedrus_find_format(u32 pixelformat, u32 directions,
|
||||||
unsigned int capabilities)
|
unsigned int capabilities)
|
||||||
{
|
{
|
||||||
|
struct cedrus_format *first_valid_fmt = NULL;
|
||||||
struct cedrus_format *fmt;
|
struct cedrus_format *fmt;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < CEDRUS_FORMATS_COUNT; i++) {
|
for (i = 0; i < CEDRUS_FORMATS_COUNT; i++) {
|
||||||
fmt = &cedrus_formats[i];
|
fmt = &cedrus_formats[i];
|
||||||
|
|
||||||
if (fmt->capabilities && (fmt->capabilities & capabilities) !=
|
if ((fmt->capabilities & capabilities) != fmt->capabilities ||
|
||||||
fmt->capabilities)
|
!(fmt->directions & directions))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (fmt->pixelformat == pixelformat &&
|
if (fmt->pixelformat == pixelformat)
|
||||||
(fmt->directions & directions) != 0)
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if (!first_valid_fmt)
|
||||||
|
first_valid_fmt = fmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == CEDRUS_FORMATS_COUNT)
|
if (i == CEDRUS_FORMATS_COUNT)
|
||||||
return NULL;
|
return first_valid_fmt;
|
||||||
|
|
||||||
return &cedrus_formats[i];
|
return &cedrus_formats[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool cedrus_check_format(u32 pixelformat, u32 directions,
|
|
||||||
unsigned int capabilities)
|
|
||||||
{
|
|
||||||
return cedrus_find_format(pixelformat, directions, capabilities);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cedrus_prepare_format(struct v4l2_pix_format *pix_fmt)
|
static void cedrus_prepare_format(struct v4l2_pix_format *pix_fmt)
|
||||||
{
|
{
|
||||||
unsigned int width = pix_fmt->width;
|
unsigned int width = pix_fmt->width;
|
||||||
@ -252,11 +249,14 @@ static int cedrus_try_fmt_vid_cap(struct file *file, void *priv,
|
|||||||
struct cedrus_ctx *ctx = cedrus_file2ctx(file);
|
struct cedrus_ctx *ctx = cedrus_file2ctx(file);
|
||||||
struct cedrus_dev *dev = ctx->dev;
|
struct cedrus_dev *dev = ctx->dev;
|
||||||
struct v4l2_pix_format *pix_fmt = &f->fmt.pix;
|
struct v4l2_pix_format *pix_fmt = &f->fmt.pix;
|
||||||
|
struct cedrus_format *fmt =
|
||||||
|
cedrus_find_format(pix_fmt->pixelformat, CEDRUS_DECODE_DST,
|
||||||
|
dev->capabilities);
|
||||||
|
|
||||||
if (!cedrus_check_format(pix_fmt->pixelformat, CEDRUS_DECODE_DST,
|
if (!fmt)
|
||||||
dev->capabilities))
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
pix_fmt->pixelformat = fmt->pixelformat;
|
||||||
cedrus_prepare_format(pix_fmt);
|
cedrus_prepare_format(pix_fmt);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -268,15 +268,18 @@ static int cedrus_try_fmt_vid_out(struct file *file, void *priv,
|
|||||||
struct cedrus_ctx *ctx = cedrus_file2ctx(file);
|
struct cedrus_ctx *ctx = cedrus_file2ctx(file);
|
||||||
struct cedrus_dev *dev = ctx->dev;
|
struct cedrus_dev *dev = ctx->dev;
|
||||||
struct v4l2_pix_format *pix_fmt = &f->fmt.pix;
|
struct v4l2_pix_format *pix_fmt = &f->fmt.pix;
|
||||||
|
struct cedrus_format *fmt =
|
||||||
|
cedrus_find_format(pix_fmt->pixelformat, CEDRUS_DECODE_SRC,
|
||||||
|
dev->capabilities);
|
||||||
|
|
||||||
if (!cedrus_check_format(pix_fmt->pixelformat, CEDRUS_DECODE_SRC,
|
if (!fmt)
|
||||||
dev->capabilities))
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
/* Source image size has to be provided by userspace. */
|
/* Source image size has to be provided by userspace. */
|
||||||
if (pix_fmt->sizeimage == 0)
|
if (pix_fmt->sizeimage == 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
pix_fmt->pixelformat = fmt->pixelformat;
|
||||||
cedrus_prepare_format(pix_fmt);
|
cedrus_prepare_format(pix_fmt);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -364,21 +367,12 @@ static int cedrus_queue_setup(struct vb2_queue *vq, unsigned int *nbufs,
|
|||||||
struct device *alloc_devs[])
|
struct device *alloc_devs[])
|
||||||
{
|
{
|
||||||
struct cedrus_ctx *ctx = vb2_get_drv_priv(vq);
|
struct cedrus_ctx *ctx = vb2_get_drv_priv(vq);
|
||||||
struct cedrus_dev *dev = ctx->dev;
|
|
||||||
struct v4l2_pix_format *pix_fmt;
|
struct v4l2_pix_format *pix_fmt;
|
||||||
u32 directions;
|
|
||||||
|
|
||||||
if (V4L2_TYPE_IS_OUTPUT(vq->type)) {
|
if (V4L2_TYPE_IS_OUTPUT(vq->type))
|
||||||
directions = CEDRUS_DECODE_SRC;
|
|
||||||
pix_fmt = &ctx->src_fmt;
|
pix_fmt = &ctx->src_fmt;
|
||||||
} else {
|
else
|
||||||
directions = CEDRUS_DECODE_DST;
|
|
||||||
pix_fmt = &ctx->dst_fmt;
|
pix_fmt = &ctx->dst_fmt;
|
||||||
}
|
|
||||||
|
|
||||||
if (!cedrus_check_format(pix_fmt->pixelformat, directions,
|
|
||||||
dev->capabilities))
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
if (*nplanes) {
|
if (*nplanes) {
|
||||||
if (sizes[0] < pix_fmt->sizeimage)
|
if (sizes[0] < pix_fmt->sizeimage)
|
||||||
|
Loading…
Reference in New Issue
Block a user