bcm27xx: add support for linux v5.15
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.15 / 950-0384-staging-bcm2835-codec-Set-the-colourspace-appropriat.patch
1 From f540950062dc13d81cf3cf5d34195bc4948d0c55 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Thu, 4 Feb 2021 19:08:23 +0000
4 Subject: [PATCH] staging/bcm2835-codec: Set the colourspace
5 appropriately for RGB formats
6
7 Video decode supports YUV and RGB formats. YUV needs to report SMPTE170M
8 or REC709 appropriately, whilst RGB should report SRGB.
9
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
11 ---
12 .../bcm2835-codec/bcm2835-v4l2-codec.c | 51 +++++++++++++------
13 1 file changed, 36 insertions(+), 15 deletions(-)
14
15 --- a/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
16 +++ b/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
17 @@ -930,23 +930,43 @@ static void send_eos_event(struct bcm283
18 v4l2_event_queue_fh(&ctx->fh, &ev);
19 }
20
21 -static void color_mmal2v4l(struct bcm2835_codec_ctx *ctx, u32 mmal_color_space)
22 +static void color_mmal2v4l(struct bcm2835_codec_ctx *ctx, u32 encoding,
23 + u32 color_space)
24 {
25 - switch (mmal_color_space) {
26 - case MMAL_COLOR_SPACE_ITUR_BT601:
27 - ctx->colorspace = V4L2_COLORSPACE_REC709;
28 - ctx->xfer_func = V4L2_XFER_FUNC_709;
29 - ctx->ycbcr_enc = V4L2_YCBCR_ENC_601;
30 - ctx->quant = V4L2_QUANTIZATION_LIM_RANGE;
31 - break;
32 + int is_rgb;
33
34 - case MMAL_COLOR_SPACE_ITUR_BT709:
35 - ctx->colorspace = V4L2_COLORSPACE_REC709;
36 - ctx->xfer_func = V4L2_XFER_FUNC_709;
37 - ctx->ycbcr_enc = V4L2_YCBCR_ENC_709;
38 - ctx->quant = V4L2_QUANTIZATION_LIM_RANGE;
39 + switch (encoding) {
40 + case MMAL_ENCODING_I420:
41 + case MMAL_ENCODING_YV12:
42 + case MMAL_ENCODING_NV12:
43 + case MMAL_ENCODING_NV21:
44 + case V4L2_PIX_FMT_YUYV:
45 + case V4L2_PIX_FMT_YVYU:
46 + case V4L2_PIX_FMT_UYVY:
47 + case V4L2_PIX_FMT_VYUY:
48 + /* YUV based colourspaces */
49 + switch (color_space) {
50 + case MMAL_COLOR_SPACE_ITUR_BT601:
51 + ctx->colorspace = V4L2_COLORSPACE_SMPTE170M;
52 + break;
53 +
54 + case MMAL_COLOR_SPACE_ITUR_BT709:
55 + ctx->colorspace = V4L2_COLORSPACE_REC709;
56 + break;
57 + default:
58 + break;
59 + }
60 + break;
61 + default:
62 + /* RGB based colourspaces */
63 + ctx->colorspace = V4L2_COLORSPACE_SRGB;
64 break;
65 }
66 + ctx->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(ctx->colorspace);
67 + ctx->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(ctx->colorspace);
68 + is_rgb = ctx->colorspace == V4L2_COLORSPACE_SRGB;
69 + ctx->quant = V4L2_MAP_QUANTIZATION_DEFAULT(is_rgb, ctx->colorspace,
70 + ctx->ycbcr_enc);
71 }
72
73 static void handle_fmt_changed(struct bcm2835_codec_ctx *ctx,
74 @@ -985,7 +1005,8 @@ static void handle_fmt_changed(struct bc
75 q_data->height = format->es.video.height;
76 q_data->sizeimage = format->buffer_size_min;
77 if (format->es.video.color_space)
78 - color_mmal2v4l(ctx, format->es.video.color_space);
79 + color_mmal2v4l(ctx, format->format.encoding,
80 + format->es.video.color_space);
81
82 q_data->aspect_ratio.numerator = format->es.video.par.num;
83 q_data->aspect_ratio.denominator = format->es.video.par.den;