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