media: platform: video-mux: propagate format from sink to source
Subsystems (2)
PATCH 1/1 media: platform: video-mux: propagate format from sink to source
Propagate the v4l2_mbus_framefmt to the source pad when either a sink pad is activated or when the format of the active sink pad changes.
--- drivers/media/platform/video-mux.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/media/platform/video-mux.c +15 -1
@@ -45,6 +45,7 @@ static int video_mux_link_setup(struct media_entity *entity, {struct v4l2_subdev *sd =media_entity_to_v4l2_subdev (entity);struct video_mux *vmux =v4l2_subdev_to_video_mux (sd); +u16 source_pad = entity->num_pads -1 ;int ret =0 ;/*
@@ -74,6 +75,9 @@ static int video_mux_link_setup(struct media_entity *entity,if (ret <0 ) goto out; vmux->active = local->index; + +/* Propagate the active format to the source */ + vmux->format_mbus[source_pad] = vmux->format_mbus[vmux->active]; }else {if (vmux->active != local->index) goto out;
@@ -162,14 +166,20 @@ static int video_mux_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_format *sdformat) {struct video_mux *vmux =v4l2_subdev_to_video_mux (sd); -struct v4l2_mbus_framefmt *mbusformat; +struct v4l2_mbus_framefmt *mbusformat, *source_mbusformat;struct media_pad *pad = &vmux->pads[sdformat->pad]; +u16 source_pad = sd->entity.num_pads -1 ; mbusformat =__video_mux_get_pad_format (sd, cfg, sdformat->pad, sdformat->which);if (!mbusformat)return -EINVAL ; + source_mbusformat =__video_mux_get_pad_format (sd, cfg, source_pad, + sdformat->which); +if (!source_mbusformat) +return -EINVAL ; +mutex_lock (&vmux->lock);/* Source pad mirrors active sink pad, no limitations on sink pads */
@@ -178,6 +188,10 @@ static int video_mux_set_format(struct v4l2_subdev *sd, *mbusformat = sdformat->format; +/* Propagate the format from an active sink to source */ +if ((pad->flags &MEDIA_PAD_FL_SINK ) && (pad->index == vmux->active)) + *source_mbusformat = sdformat->format; +mutex_unlock (&vmux->lock);return 0 ;
Signature · 1 line
2.14.3
Hi Chris,
Quoted 2 lines · Chris Lesiak
Propagate the
v4l2_mbus_framefmtto the source pad when either a sink pad is activated or when the format of the active sink pad changes.
Thank you, this fixes the V4L2_SUBDEV_FORMAT_TRY use case as well as propagation of the active format when the user calls VIDIOC_SUBDEV_S_FMT on the sink pad and then only VIDIOC_SUBDEV_G_FMT on the source pad.
Quoted 37 lines
Signed-off-by Chris Lesiak <[email protected]>--- drivers/media/platform/video-mux.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)drivers/media/platform/video-mux.c +6
-1@@ -45,6 +45,7 @@ static int video_mux_link_setup(struct media_entity *entity, {struct v4l2_subdev *sd =media_entity_to_v4l2_subdev (entity);struct video_mux *vmux =v4l2_subdev_to_video_mux (sd); +u16 source_pad = entity->num_pads -1 ;int ret =0 ;/* @@ -74,6 +75,9 @@ static int video_mux_link_setup(struct media_entity *entity,if (ret <0 ) goto out; vmux->active = local->index; + +/* Propagate the active format to the source */ + vmux->format_mbus[source_pad] = vmux->format_mbus[vmux->active]; }else {if (vmux->active != local->index) goto out;@@ -162,14 +166,20 @@ static int video_mux_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_format *sdformat) {struct video_mux *vmux =v4l2_subdev_to_video_mux (sd); -struct v4l2_mbus_framefmt *mbusformat; +struct v4l2_mbus_framefmt *mbusformat, *source_mbusformat;struct media_pad *pad = &vmux->pads[sdformat->pad]; +u16 source_pad = sd->entity.num_pads -1 ; mbusformat = __video_mux_get_pad_format(sd, cfg, sdformat->pad,
drivers/media/platform/video-mux.c static int video_mux_set_format(struct v4l2_subdev *sd, · line 183
Quoted 10 lines
drivers/media/platform/video-mux.c +5
-0sdformat->which);if (!mbusformat)return -EINVAL ; + source_mbusformat =__video_mux_get_pad_format (sd, cfg, source_pad, + sdformat->which); +if (!source_mbusformat) +return -EINVAL ; +mutex_lock (&vmux->lock);
This is superfluous if pad->index != vmux->active and the same as mbusformat for the source pad, but I think to achieve easily readable code, this is ok.
drivers/media/platform/video-mux.c static int video_mux_set_format(struct v4l2_subdev *sd, · line 192
Quoted 7 lines
drivers/media/platform/video-mux.c +2
-0/* Source pad mirrors active sink pad, no limitations on sink pads */ @@ -178,6 +188,10 @@ static int video_mux_set_format(struct v4l2_subdev *sd, *mbusformat = sdformat->format; +/* Propagate the format from an active sink to source */ +if ((pad->flags &MEDIA_PAD_FL_SINK ) && (pad->index == vmux->active))
The flags check could be removed. It is not necessary since vmux->active is never set to the source pad index.
drivers/media/platform/video-mux.c static int video_mux_set_format(struct v4l2_subdev *sd, · line 197
Quoted 5 lines
drivers/media/platform/video-mux.c +2
-0+ *source_mbusformat = sdformat->format; +mutex_unlock (&vmux->lock);return 0 ;
regards
Philipp
Hi Philipp,
Quoted 9 lines · Philipp Zabel
Hi Chris,
Quoted 2 lines · Chris Lesiak
Propagate the
v4l2_mbus_framefmtto the source pad when either a sink pad is activated or when the format of the active sink pad changes.Thank you, this fixes the
V4L2_SUBDEV_FORMAT_TRYuse case as well as propagation of the active format when the user callsVIDIOC_SUBDEV_S_FMTon the sink pad and then onlyVIDIOC_SUBDEV_G_FMTon the source pad.
Yes, I understood that both V4L2_SUBDEV_FORMAT_ACTIVE and V4L2_SUBDEV_FORMAT_TRY use cases would work. Maybe that wasn't clear from the commit message. I think understanding might be improved if the struct video_mux member named "active" were renamed to "selected". Would you consider a patch that did this?
Being able to call VIDIOC_SUBDEV_S_FMT on the sink pad and then only VIDIOC_SUBDEV_G_FMT on the source pad was certainly my goal. It bothered me that the examples that I found for the i.MX5/6 used the media-ctl utility to set the format on the source pads only, relying on internal logic in the utility to duplicate the format on the sink pad at the opposite end of the link. When I attempted to use the APIs to get the format of the source pads and then set them on the sink pads at the opposite end of the links, I found that it didn't work. It was only because of this missing functionality in video-mux.
Quoted 42 lines
Quoted 42 lines
Signed-off-by Chris Lesiak <[email protected]>--- drivers/media/platform/video-mux.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)drivers/media/platform/video-mux.c +6
-1@@ -45,6 +45,7 @@ static int video_mux_link_setup(struct media_entity *entity, {struct v4l2_subdev *sd =media_entity_to_v4l2_subdev (entity);struct video_mux *vmux =v4l2_subdev_to_video_mux (sd); +u16 source_pad = entity->num_pads -1 ;int ret =0 ;/* @@ -74,6 +75,9 @@ static int video_mux_link_setup(struct media_entity *entity,if (ret <0 ) goto out; vmux->active = local->index; + +/* Propagate the active format to the source */ + vmux->format_mbus[source_pad] = vmux->format_mbus[vmux->active]; }else {if (vmux->active != local->index) goto out;@@ -162,14 +166,20 @@ static int video_mux_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_format *sdformat) {struct video_mux *vmux =v4l2_subdev_to_video_mux (sd); -struct v4l2_mbus_framefmt *mbusformat; +struct v4l2_mbus_framefmt *mbusformat, *source_mbusformat;struct media_pad *pad = &vmux->pads[sdformat->pad]; +u16 source_pad = sd->entity.num_pads -1 ; mbusformat =__video_mux_get_pad_format (sd, cfg, sdformat->pad, sdformat->which);if (!mbusformat)return -EINVAL ;
Quoted 10 lines
drivers/media/platform/video-mux.c static int video_mux_set_format(struct v4l2_subdev *sd, · line 183
Quoted 6 lines
drivers/media/platform/video-mux.c +5
-0+ source_mbusformat =__video_mux_get_pad_format (sd, cfg, source_pad, + sdformat->which); +if (!source_mbusformat) +return -EINVAL ; +mutex_lock (&vmux->lock);This is superfluous if
pad->index!=vmux->activeand the same as mbusformat for the source pad, but I think to achieve easily readable code, this is ok.
I tried an alternate version where video_mux_set_format only called one of two new functions: video_mux_set_format_sink and video_mux_set_format_source. The cost was about 30 additional lines. I wasn't sure it was a good trade-off. Would you like to see that version?
Quoted 11 lines
drivers/media/platform/video-mux.c static int video_mux_set_format(struct v4l2_subdev *sd, · line 192
Quoted 8 lines
drivers/media/platform/video-mux.c +2
-0/* Source pad mirrors active sink pad, no limitations on sink pads */ @@ -178,6 +188,10 @@ static int video_mux_set_format(struct v4l2_subdev *sd, *mbusformat = sdformat->format; +/* Propagate the format from an active sink to source */ +if ((pad->flags &MEDIA_PAD_FL_SINK ) && (pad->index == vmux->active))The flags check could be removed. It is not necessary since
vmux->activeis never set to the source pad index.
I will make that change.
Quoted 5 lines
Quoted 5 lines
drivers/media/platform/video-mux.c +2
-0+ *source_mbusformat = sdformat->format; +mutex_unlock (&vmux->lock);
Quoted 7 lines
drivers/media/platform/video-mux.c static int video_mux_set_format(struct v4l2_subdev *sd, · line 197
Quoted 1 line
drivers/media/platform/video-mux.c +0
-0return 0 ;Reviewed-by Philipp Zabel <[email protected]>regards
Philipp
Thanks for the review,
Chris