media: vimc: propagate pixel format in the stream
PATCH v3 1/1 media: vimc: propagate pixel format in the stream
Media bus codes were being mapped to pixelformats, which causes a limitation on vimc because not all pixelformats can be mapped to media bus codes.
Also, media bus codes are an internal configuration from the device. Userspace only assures media bus codes matches between pads and expects the image in a given pixelformat. So we can allow almost any media bus format to be configured between pads, except for debayer that expects a media bus code of type bayer in the sink pad.
---
The series depends on
"[PATCH] media: Introduce helpers to fill pixel format structs "
Changes in v3:
- s/pixftm/pixfmt
Changes in v2:
- use __u32 for vimc_mbus_list[] as it is compared with userspace objects
- remove struct vimc_pix_map and vimc_pix_map_*() function scopes from header that are not required anymore.
- fix failing "v4l2-compliance -m0" tests by adding vimc_mbus_code_supported() and checking the mbus code given by userspace in set_fmt functions.
drivers/media/platform/vimc/vimc-capture.c | 76 +++-- drivers/media/platform/vimc/vimc-common.c | 309 ++++++++------------ drivers/media/platform/vimc/vimc-common.h | 58 ++-- drivers/media/platform/vimc/vimc-debayer.c | 81 +++-- drivers/media/platform/vimc/vimc-scaler.c | 63 ++-- drivers/media/platform/vimc/vimc-sensor.c | 51 +--- drivers/media/platform/vimc/vimc-streamer.c | 2 + drivers/media/platform/vimc/vimc-streamer.h | 6 + 8 files changed, 304 insertions(+), 342 deletions(-)
drivers/media/platform/vimc/vimc-capture.c +50 -26
@@ -28,6 +28,32 @@#define VIMC_CAP_DRV_NAME "vimc-capture" +static const u32 vimc_cap_supported_pixfmt[] = { +V4L2_PIX_FMT_BGR24 , +V4L2_PIX_FMT_RGB24 , +V4L2_PIX_FMT_ARGB32 , +V4L2_PIX_FMT_SBGGR8 , +V4L2_PIX_FMT_SGBRG8 , +V4L2_PIX_FMT_SGRBG8 , +V4L2_PIX_FMT_SRGGB8 , +V4L2_PIX_FMT_SBGGR10 , +V4L2_PIX_FMT_SGBRG10 , +V4L2_PIX_FMT_SGRBG10 , +V4L2_PIX_FMT_SRGGB10 , +V4L2_PIX_FMT_SBGGR10ALAW8 , +V4L2_PIX_FMT_SGBRG10ALAW8 , +V4L2_PIX_FMT_SGRBG10ALAW8 , +V4L2_PIX_FMT_SRGGB10ALAW8 , +V4L2_PIX_FMT_SBGGR10DPCM8 , +V4L2_PIX_FMT_SGBRG10DPCM8 , +V4L2_PIX_FMT_SGRBG10DPCM8 , +V4L2_PIX_FMT_SRGGB10DPCM8 , +V4L2_PIX_FMT_SBGGR12 , +V4L2_PIX_FMT_SGBRG12 , +V4L2_PIX_FMT_SGRBG12 , +V4L2_PIX_FMT_SRGGB12 , +}; +struct vimc_cap_device {struct vimc_ent_device ved;struct video_device vdev;
@@ -101,29 +127,25 @@ static int vimc_cap_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) {struct v4l2_pix_format *format = &f->fmt.pix; -const struct vimc_pix_map *vpix; format->width =clamp_t (u32, format->width,VIMC_FRAME_MIN_WIDTH ,VIMC_FRAME_MAX_WIDTH ) & ~1 ; format->height =clamp_t (u32, format->height,VIMC_FRAME_MIN_HEIGHT ,VIMC_FRAME_MAX_HEIGHT ) & ~1 ; -/* Don't accept a pixelformat that is not on the table */ - vpix =vimc_pix_map_by_pixelformat (format->pixelformat); -if (!vpix) { - format->pixelformat = fmt_default.pixelformat; - vpix =vimc_pix_map_by_pixelformat (format->pixelformat); - } -/* TODO: Add support for custom bytesperline values */ - format->bytesperline = format->width * vpix->bpp; - format->sizeimage = format->bytesperline * format->height; +vimc_colorimetry_clamp (format);if (format->field ==V4L2_FIELD_ANY ) format->field = fmt_default.field; -vimc_colorimetry_clamp (format); +/* TODO: Add support for custom bytesperline values */ -return 0 ; +/* Don't accept a pixelformat that is not on the table */ +if (!v4l2_format_info (format->pixelformat)) + format->pixelformat = fmt_default.pixelformat; + +return v4l2_fill_pixfmt (format, format->pixelformat, + format->width, format->height); } static int vimc_cap_s_fmt_vid_cap(struct file *file, void *priv,
@@ -159,27 +181,31 @@ static int vimc_cap_s_fmt_vid_cap(struct file *file, void *priv,static int vimc_cap_enum_fmt_vid_cap (struct file *file,void *priv,struct v4l2_fmtdesc *f) { -const struct vimc_pix_map *vpix =vimc_pix_map_by_index (f->index); - -if (!vpix) +if (f->index >=ARRAY_SIZE (vimc_cap_supported_pixfmt))return -EINVAL ; - f->pixelformat = vpix->pixelformat; + f->pixelformat = vimc_cap_supported_pixfmt[f->index];return 0 ; } +static bool vimc_cap_is_pixfmt_supported (u32 pixelformat) +{ +unsigned int i; + +for (i =0 ; i <ARRAY_SIZE (vimc_cap_supported_pixfmt); i++) +if (vimc_cap_supported_pixfmt[i] == pixelformat) +return true; +return false; +} +static int vimc_cap_enum_framesizes (struct file *file,void *fh,struct v4l2_frmsizeenum *fsize) { -const struct vimc_pix_map *vpix; -if (fsize->index)return -EINVAL ; -/* Only accept code in the pix map table */ - vpix =vimc_pix_map_by_code (fsize->pixel_format); -if (!vpix) +if (!vimc_cap_is_pixfmt_supported (fsize->pixel_format))return -EINVAL ; fsize->type =V4L2_FRMSIZE_TYPE_CONTINUOUS ;
@@ -253,6 +279,7 @@ static int vimc_cap_start_streaming(struct vb2_queue *vq, unsigned int count)return ret; } + vcap->stream.producer_pixfmt = vcap->format.pixelformat; ret =vimc_streamer_s_stream (&vcap->stream, &vcap->ved,1 );if (ret) {media_pipeline_stop (entity);
@@ -403,7 +430,6 @@ static int vimc_cap_comp_bind(struct device *comp, struct device *master, {struct v4l2_device *v4l2_dev = master_data;struct vimc_platform_data *pdata = comp->platform_data; -const struct vimc_pix_map *vpix;struct vimc_cap_device *vcap;struct video_device *vdev;struct vb2_queue *q;
@@ -458,10 +484,8 @@ static int vimc_cap_comp_bind(struct device *comp, struct device *master,/* Set default frame format */ vcap->format = fmt_default; - vpix =vimc_pix_map_by_pixelformat (vcap->format.pixelformat); - vcap->format.bytesperline = vcap->format.width * vpix->bpp; - vcap->format.sizeimage = vcap->format.bytesperline * - vcap->format.height; +v4l2_fill_pixfmt (&vcap->format, vcap->format.pixelformat, + vcap->format.width, vcap->format.height);/* Fill the vimc_ent_device struct */ vcap->ved.ent = &vcap->vdev.entity;
drivers/media/platform/vimc/vimc-common.c +129 -180
344 lines not on this page · raw message
drivers/media/platform/vimc/vimc-common.h +20 -38
88 lines not on this page · raw message
drivers/media/platform/vimc/vimc-debayer.c +52 -29
229 lines not on this page · raw message
drivers/media/platform/vimc/vimc-scaler.c +30 -33
118 lines not on this page · raw message
drivers/media/platform/vimc/vimc-sensor.c +15 -36
104 lines not on this page · raw message
drivers/media/platform/vimc/vimc-streamer.c +2 -0
@@ -52,6 +52,7 @@ static void vimc_streamer_pipeline_terminate(struct vimc_stream *stream)while (stream->pipe_size) { stream->pipe_size--; ved = stream->ved_pipeline[stream->pipe_size]; + ved->stream =NULL ; stream->ved_pipeline[stream->pipe_size] =NULL ;if (!is_media_entity_v4l2_subdev (ved->ent))
@@ -87,6 +88,7 @@ static int vimc_streamer_pipeline_init(struct vimc_stream *stream,return -EINVAL ; } stream->ved_pipeline[stream->pipe_size++] = ved; + ved->stream = stream;if (is_media_entity_v4l2_subdev (ved->ent)) { sd =media_entity_to_v4l2_subdev (ved->ent);
drivers/media/platform/vimc/vimc-streamer.h +6 -0
@@ -25,6 +25,11 @@* processed in the pipeline. * @pipe_size: size of @ved_pipeline * @kthread: thread that generates the frames of the stream. +* @producer_pixfmt: the pixel format requested from the pipeline. This must +* be set just before calling vimc_streamer_s_stream(ent, 1). This value is +* propagated up to the source of the base image (usually a sensor node) and +* can be modified by entities during s_stream callback to request a different +* format from rest of the pipeline. * * When the user call stream_on in a video device, struct vimc_stream is * used to keep track of all entities and subdevices that generates and
@@ -35,6 +40,7 @@ struct vimc_stream {struct vimc_ent_device *ved_pipeline[VIMC_STREAMER_PIPELINE_MAX_SIZE ];unsigned int pipe_size;struct task_struct *kthread; +u32 producer_pixfmt; };/**
Signature · 1 line
2.20.1