]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: subdev: Add v4l2_subdev_is_streaming()
authorTomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Wed, 24 Apr 2024 15:39:09 +0000 (18:39 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 2 May 2025 05:50:37 +0000 (07:50 +0200)
[ Upstream commit 5f3ce14fae742d1d23061c3122d93edb879ebf53 ]

Add a helper function which returns whether the subdevice is streaming,
i.e. if .s_stream or .enable_streams has been called successfully.

Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Umang Jain <umang.jain@ideasonboard.com>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Stable-dep-of: 36cef585e2a3 ("media: vimc: skip .s_stream() for stopped entities")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/media/v4l2-core/v4l2-subdev.c
include/media/v4l2-subdev.h

index f555fd3c4b76dc2f0aa02a0521583804c60f437f..5f115438d07228abfa8d95c732c70800e2f509c0 100644 (file)
@@ -2240,6 +2240,31 @@ void v4l2_subdev_notify_event(struct v4l2_subdev *sd,
 }
 EXPORT_SYMBOL_GPL(v4l2_subdev_notify_event);
 
+bool v4l2_subdev_is_streaming(struct v4l2_subdev *sd)
+{
+       struct v4l2_subdev_state *state;
+
+       if (!v4l2_subdev_has_op(sd, pad, enable_streams))
+               return sd->s_stream_enabled;
+
+       if (!(sd->flags & V4L2_SUBDEV_FL_STREAMS))
+               return !!sd->enabled_pads;
+
+       state = v4l2_subdev_get_locked_active_state(sd);
+
+       for (unsigned int i = 0; i < state->stream_configs.num_configs; ++i) {
+               const struct v4l2_subdev_stream_config *cfg;
+
+               cfg = &state->stream_configs.configs[i];
+
+               if (cfg->enabled)
+                       return true;
+       }
+
+       return false;
+}
+EXPORT_SYMBOL_GPL(v4l2_subdev_is_streaming);
+
 int v4l2_subdev_get_privacy_led(struct v4l2_subdev *sd)
 {
 #if IS_REACHABLE(CONFIG_LEDS_CLASS)
index 0a8d75b009ea2cda3e790542763ff6be88d26de7..b4fcd0164048eda90131b7e86cad754e610cf3ac 100644 (file)
@@ -1918,4 +1918,17 @@ extern const struct v4l2_subdev_ops v4l2_subdev_call_wrappers;
 void v4l2_subdev_notify_event(struct v4l2_subdev *sd,
                              const struct v4l2_event *ev);
 
+/**
+ * v4l2_subdev_is_streaming() - Returns if the subdevice is streaming
+ * @sd: The subdevice
+ *
+ * v4l2_subdev_is_streaming() tells if the subdevice is currently streaming.
+ * "Streaming" here means whether .s_stream() or .enable_streams() has been
+ * successfully called, and the streaming has not yet been disabled.
+ *
+ * If the subdevice implements .enable_streams() this function must be called
+ * while holding the active state lock.
+ */
+bool v4l2_subdev_is_streaming(struct v4l2_subdev *sd);
+
 #endif /* _V4L2_SUBDEV_H */