Commit 75480ebf authored by Philipp Zabel's avatar Philipp Zabel Committed by Mauro Carvalho Chehab

media: coda: set codec earlier

The chosen codec depends on the coded format, which is known as soon as
the S_FMT call on the coded queue. This allows to use the codec in
callbacks that may be called before start_streaming, such as buf_queue.
Signed-off-by: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent d65842f7
...@@ -764,6 +764,7 @@ static int coda_s_fmt_vid_cap(struct file *file, void *priv, ...@@ -764,6 +764,7 @@ static int coda_s_fmt_vid_cap(struct file *file, void *priv,
{ {
struct coda_ctx *ctx = fh_to_ctx(priv); struct coda_ctx *ctx = fh_to_ctx(priv);
struct coda_q_data *q_data_src; struct coda_q_data *q_data_src;
const struct coda_codec *codec;
struct v4l2_rect r; struct v4l2_rect r;
int ret; int ret;
...@@ -784,6 +785,15 @@ static int coda_s_fmt_vid_cap(struct file *file, void *priv, ...@@ -784,6 +785,15 @@ static int coda_s_fmt_vid_cap(struct file *file, void *priv,
if (ctx->inst_type != CODA_INST_ENCODER) if (ctx->inst_type != CODA_INST_ENCODER)
return 0; return 0;
/* Setting the coded format determines the selected codec */
codec = coda_find_codec(ctx->dev, q_data_src->fourcc,
f->fmt.pix.pixelformat);
if (!codec) {
v4l2_err(&ctx->dev->v4l2_dev, "failed to determine codec\n");
return -EINVAL;
}
ctx->codec = codec;
ctx->colorspace = f->fmt.pix.colorspace; ctx->colorspace = f->fmt.pix.colorspace;
ctx->xfer_func = f->fmt.pix.xfer_func; ctx->xfer_func = f->fmt.pix.xfer_func;
ctx->ycbcr_enc = f->fmt.pix.ycbcr_enc; ctx->ycbcr_enc = f->fmt.pix.ycbcr_enc;
...@@ -796,6 +806,7 @@ static int coda_s_fmt_vid_out(struct file *file, void *priv, ...@@ -796,6 +806,7 @@ static int coda_s_fmt_vid_out(struct file *file, void *priv,
struct v4l2_format *f) struct v4l2_format *f)
{ {
struct coda_ctx *ctx = fh_to_ctx(priv); struct coda_ctx *ctx = fh_to_ctx(priv);
const struct coda_codec *codec;
struct v4l2_format f_cap; struct v4l2_format f_cap;
struct vb2_queue *dst_vq; struct vb2_queue *dst_vq;
int ret; int ret;
...@@ -811,6 +822,15 @@ static int coda_s_fmt_vid_out(struct file *file, void *priv, ...@@ -811,6 +822,15 @@ static int coda_s_fmt_vid_out(struct file *file, void *priv,
if (ctx->inst_type != CODA_INST_DECODER) if (ctx->inst_type != CODA_INST_DECODER)
return 0; return 0;
/* Setting the coded format determines the selected codec */
codec = coda_find_codec(ctx->dev, f->fmt.pix.pixelformat,
V4L2_PIX_FMT_YUV420);
if (!codec) {
v4l2_err(&ctx->dev->v4l2_dev, "failed to determine codec\n");
return -EINVAL;
}
ctx->codec = codec;
ctx->colorspace = f->fmt.pix.colorspace; ctx->colorspace = f->fmt.pix.colorspace;
ctx->xfer_func = f->fmt.pix.xfer_func; ctx->xfer_func = f->fmt.pix.xfer_func;
ctx->ycbcr_enc = f->fmt.pix.ycbcr_enc; ctx->ycbcr_enc = f->fmt.pix.ycbcr_enc;
...@@ -1680,14 +1700,6 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count) ...@@ -1680,14 +1700,6 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
ctx->gopcounter = ctx->params.gop_size - 1; ctx->gopcounter = ctx->params.gop_size - 1;
ctx->codec = coda_find_codec(ctx->dev, q_data_src->fourcc,
q_data_dst->fourcc);
if (!ctx->codec) {
v4l2_err(v4l2_dev, "couldn't tell instance type.\n");
ret = -EINVAL;
goto err;
}
if (q_data_dst->fourcc == V4L2_PIX_FMT_JPEG) if (q_data_dst->fourcc == V4L2_PIX_FMT_JPEG)
ctx->params.gop_size = 1; ctx->params.gop_size = 1;
ctx->gopcounter = ctx->params.gop_size - 1; ctx->gopcounter = ctx->params.gop_size - 1;
......
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