From: Hans Verkuil <hverkuil-ci...@xs4all.nl>

Report the full list of supported decoder formats until the
format encoded in the bitstream is known. After that only
report the formats compatible with that initial format.

Signed-off-by: Hans Verkuil <hverkuil-ci...@xs4all.nl>
---
 drivers/media/platform/vicodec/vicodec-core.c | 23 +++++++++++--------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/vicodec/vicodec-core.c 
b/drivers/media/platform/vicodec/vicodec-core.c
index a9a0f6a1b69e..21000cc2f395 100644
--- a/drivers/media/platform/vicodec/vicodec-core.c
+++ b/drivers/media/platform/vicodec/vicodec-core.c
@@ -671,7 +671,6 @@ static int job_ready(void *priv)
                        v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
 
                update_capture_data_from_header(ctx);
-               ctx->first_source_change_sent = true;
                v4l2_event_queue_fh(&ctx->fh, &rs_event);
                set_last_buffer(dst_buf, src_buf, ctx);
                ctx->source_changed = true;
@@ -718,7 +717,7 @@ static int enum_fmt(struct v4l2_fmtdesc *f, struct 
vicodec_ctx *ctx,
                const struct v4l2_fwht_pixfmt_info *info =
                                        get_q_data(ctx, f->type)->info;
 
-               if (!info || ctx->is_enc)
+               if (!ctx->first_source_change_sent || ctx->is_enc)
                        info = v4l2_fwht_get_pixfmt(f->index);
                else
                        info = v4l2_fwht_find_nth_fmt(info->width_div,
@@ -769,9 +768,6 @@ static int vidioc_g_fmt(struct vicodec_ctx *ctx, struct 
v4l2_format *f)
        q_data = get_q_data(ctx, f->type);
        info = q_data->info;
 
-       if (!info)
-               info = v4l2_fwht_get_pixfmt(0);
-
        switch (f->type) {
        case V4L2_BUF_TYPE_VIDEO_CAPTURE:
        case V4L2_BUF_TYPE_VIDEO_OUTPUT:
@@ -1371,6 +1367,16 @@ static int vicodec_subscribe_event(struct v4l2_fh *fh,
        }
 }
 
+static int vicodec_streamon(struct file *file, void *fh, enum v4l2_buf_type i)
+{
+       struct vicodec_ctx *ctx = container_of(fh, struct vicodec_ctx, fh);
+       int ret = v4l2_m2m_ioctl_streamon(file, fh, i);
+
+       if (!ret && !ctx->is_enc && V4L2_TYPE_IS_OUTPUT(i))
+               ctx->first_source_change_sent = true;
+       return ret;
+}
+
 static const struct v4l2_ioctl_ops vicodec_ioctl_ops = {
        .vidioc_querycap        = vidioc_querycap,
 
@@ -1402,7 +1408,7 @@ static const struct v4l2_ioctl_ops vicodec_ioctl_ops = {
        .vidioc_create_bufs     = v4l2_m2m_ioctl_create_bufs,
        .vidioc_expbuf          = v4l2_m2m_ioctl_expbuf,
 
-       .vidioc_streamon        = v4l2_m2m_ioctl_streamon,
+       .vidioc_streamon        = vicodec_streamon,
        .vidioc_streamoff       = v4l2_m2m_ioctl_streamoff,
 
        .vidioc_g_selection     = vidioc_g_selection,
@@ -1618,9 +1624,6 @@ static int vicodec_start_streaming(struct vb2_queue *q,
        unsigned int total_planes_size;
        u8 *new_comp_frame = NULL;
 
-       if (!info)
-               return -EINVAL;
-
        chroma_div = info->width_div * info->height_div;
        q_data->sequence = 0;
 
@@ -1726,6 +1729,8 @@ static void vicodec_stop_streaming(struct vb2_queue *q)
                        ctx->next_is_last = false;
                }
        }
+       if (!ctx->is_enc && V4L2_TYPE_IS_OUTPUT(q->type))
+               ctx->first_source_change_sent = false;
 
        if ((!V4L2_TYPE_IS_OUTPUT(q->type) && !ctx->is_enc) ||
            (V4L2_TYPE_IS_OUTPUT(q->type) && ctx->is_enc)) {
-- 
2.17.1

Reply via email to