From ea13e57252ee6bd8221a94e2daadae43929f05d7 Mon Sep 17 00:00:00 2001 From: Dave Stevenson Date: Mon, 1 Feb 2021 18:48:47 +0000 Subject: [PATCH 1/5] media/v4l2_m2m: In buffered mode run jobs if either port is streaming In order to get the intended behaviour of the stateful video decoder API where only the OUTPUT queue needs to be enabled and fed buffers in order to get the SOURCE_CHANGED event that configures the CAPTURE queue, we want the device to run should either queue be streaming. Signed-off-by: Dave Stevenson --- drivers/media/v4l2-core/v4l2-mem2mem.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c index 34dd8ba5469f25..329dc316934eed 100644 --- a/drivers/media/v4l2-core/v4l2-mem2mem.c +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c @@ -301,9 +301,10 @@ static void __v4l2_m2m_try_queue(struct v4l2_m2m_dev *m2m_dev, dprintk("Trying to schedule a job for m2m_ctx: %p\n", m2m_ctx); - if (!m2m_ctx->out_q_ctx.q.streaming - || !m2m_ctx->cap_q_ctx.q.streaming) { - dprintk("Streaming needs to be on for both queues\n"); + if (!(m2m_ctx->out_q_ctx.q.streaming && + m2m_ctx->cap_q_ctx.q.streaming) && + !(m2m_ctx->out_q_ctx.buffered && m2m_ctx->out_q_ctx.q.streaming)) { + dprintk("Streaming needs to be on for both queues, or buffered and OUTPUT streaming\n"); return; } From ff583bb76dda73b88fa9f53c2a0782b3fd6e093d Mon Sep 17 00:00:00 2001 From: Dave Stevenson Date: Mon, 1 Feb 2021 18:55:37 +0000 Subject: [PATCH 2/5] staging/bcm2835-codec: Correct logging of size_t to %zu Fixes: "staging/bcm2835-codec: Log the number of excess supported formats" Which used %u for printing a size_t, and 64bit builds then log a warning. Signed-off-by: Dave Stevenson --- .../staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c b/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c index 94691ab7175aa6..0c4d8bf77b9162 100644 --- a/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c +++ b/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c @@ -2837,7 +2837,7 @@ static int bcm2835_codec_get_supported_fmts(struct bcm2835_codec_dev *dev) if (ret) { if (ret == MMAL_MSG_STATUS_ENOSPC) { v4l2_err(&dev->v4l2_dev, - "%s: port has more encodings than we provided space for. Some are dropped (%u vs %u).\n", + "%s: port has more encodings than we provided space for. Some are dropped (%zu vs %u).\n", __func__, param_size / sizeof(u32), MAX_SUPPORTED_ENCODINGS); num_encodings = MAX_SUPPORTED_ENCODINGS; @@ -2883,7 +2883,7 @@ static int bcm2835_codec_get_supported_fmts(struct bcm2835_codec_dev *dev) if (ret) { if (ret == MMAL_MSG_STATUS_ENOSPC) { v4l2_err(&dev->v4l2_dev, - "%s: port has more encodings than we provided space for. Some are dropped (%u vs %u).\n", + "%s: port has more encodings than we provided space for. Some are dropped (%zu vs %u).\n", __func__, param_size / sizeof(u32), MAX_SUPPORTED_ENCODINGS); num_encodings = MAX_SUPPORTED_ENCODINGS; From bf6d809a0bb52b645f6b598b34fb434051d499a2 Mon Sep 17 00:00:00 2001 From: Dave Stevenson Date: Tue, 2 Feb 2021 15:50:18 +0000 Subject: [PATCH 3/5] staging/bcm2835-codec: Add support for pixel aspect ratio If the format is detected by the driver and a V4L2_EVENT_SOURCE_CHANGE event is generated, then pass on the pixel aspect ratio as well. Signed-off-by: Dave Stevenson --- .../bcm2835-codec/bcm2835-v4l2-codec.c | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c b/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c index 0c4d8bf77b9162..46f659e55f180c 100644 --- a/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c +++ b/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c @@ -602,6 +602,7 @@ struct bcm2835_codec_q_data { unsigned int crop_width; unsigned int crop_height; bool selection_set; + struct v4l2_fract aspect_ratio; unsigned int sizeimage; unsigned int sequence; @@ -981,6 +982,9 @@ static void handle_fmt_changed(struct bcm2835_codec_ctx *ctx, if (format->es.video.color_space) color_mmal2v4l(ctx, format->es.video.color_space); + q_data->aspect_ratio.numerator = format->es.video.par.num; + q_data->aspect_ratio.denominator = format->es.video.par.den; + queue_res_chg_event(ctx); } @@ -1657,6 +1661,29 @@ static int vidioc_g_parm(struct file *file, void *priv, return 0; } +static int vidioc_g_pixelaspect(struct file *file, void *fh, int type, + struct v4l2_fract *f) +{ + struct bcm2835_codec_ctx *ctx = file2ctx(file); + + /* + * The selection API takes V4L2_BUF_TYPE_VIDEO_CAPTURE and + * V4L2_BUF_TYPE_VIDEO_OUTPUT, even if the device implements the MPLANE + * API. The V4L2 core will have converted the MPLANE variants to + * non-MPLANE. + * Open code this instead of using get_q_data in this case. + */ + if (ctx->dev->role != DECODE) + return -ENOIOCTLCMD; + + if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) + return -EINVAL; + + *f = ctx->q_data[V4L2_M2M_DST].aspect_ratio; + + return 0; +} + static int vidioc_subscribe_evt(struct v4l2_fh *fh, const struct v4l2_event_subscription *sub) { @@ -2082,6 +2109,8 @@ static const struct v4l2_ioctl_ops bcm2835_codec_ioctl_ops = { .vidioc_g_parm = vidioc_g_parm, .vidioc_s_parm = vidioc_s_parm, + .vidioc_g_pixelaspect = vidioc_g_pixelaspect, + .vidioc_subscribe_event = vidioc_subscribe_evt, .vidioc_unsubscribe_event = v4l2_event_unsubscribe, @@ -2640,6 +2669,8 @@ static int bcm2835_codec_open(struct file *file) ctx->q_data[V4L2_M2M_DST].crop_width, ctx->q_data[V4L2_M2M_DST].height, ctx->q_data[V4L2_M2M_DST].fmt); + ctx->q_data[V4L2_M2M_DST].aspect_ratio.numerator = 1; + ctx->q_data[V4L2_M2M_DST].aspect_ratio.denominator = 1; ctx->colorspace = V4L2_COLORSPACE_REC709; ctx->bitrate = 10 * 1000 * 1000; From 420578c70243db34004e8a73b12c45050a5a4077 Mon Sep 17 00:00:00 2001 From: Dave Stevenson Date: Tue, 2 Feb 2021 16:46:39 +0000 Subject: [PATCH 4/5] staging/bcm2835-codec: Implement additional g_selection calls for decode v4l_cropcap calls our vidioc_g_pixelaspect function to get the pixel aspect ratio, but also calls g_selection for V4L2_SEL_TGT_CROP_BOUNDS and V4L2_SEL_TGT_CROP_DEFAULT. Whilst it allows for vidioc_g_pixelaspect not to be implemented, it doesn't allow for either of the other two. Add in support for the additional selection targets. Signed-off-by: Dave Stevenson --- .../vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c b/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c index 46f659e55f180c..7aa6c53e279ed3 100644 --- a/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c +++ b/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c @@ -1517,6 +1517,14 @@ static int vidioc_g_selection(struct file *file, void *priv, s->r.width = q_data->crop_width; s->r.height = q_data->crop_height; break; + case V4L2_SEL_TGT_CROP_BOUNDS: + case V4L2_SEL_TGT_CROP_DEFAULT: + s->r.left = 0; + s->r.top = 0; + s->r.width = (q_data->bytesperline << 3) / + q_data->fmt->depth; + s->r.height = q_data->height; + break; default: return -EINVAL; } From 084084d7c8c690d4fd7027875dff064ed61738fe Mon Sep 17 00:00:00 2001 From: Dave Stevenson Date: Wed, 10 Mar 2021 19:07:48 +0000 Subject: [PATCH 5/5] staging/bcm2835-codec: Add VC-1 support. Providing the relevant licence has been purchased, then Pi0-3 can decode VC-1. Signed-off-by: Dave Stevenson --- .../vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c b/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c index 7aa6c53e279ed3..5729a8a7d94e16 100644 --- a/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c +++ b/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c @@ -576,7 +576,12 @@ static const struct bcm2835_codec_fmt supported_formats[] = { .depth = 0, .flags = V4L2_FMT_FLAG_COMPRESSED, .mmal_fmt = MMAL_ENCODING_VP8, - }, + }, { + .fourcc = V4L2_PIX_FMT_VC1_ANNEX_G, + .depth = 0, + .flags = V4L2_FMT_FLAG_COMPRESSED, + .mmal_fmt = MMAL_ENCODING_WVC1, + } }; struct bcm2835_codec_fmt_list {