Skip to contentSkip to conversation

media: qcom: camss: Power pipeline only when streaming

PATCH In review Richard Acayan 4 participants 5 messages May 26, 2025 – Jun 13, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: qcom: camss: Power pipeline only when streaming

The libcamera plugin for Pipewire may keep an open file descriptor to the video device, even while streaming. This simplifies its operation, as it only needs to keep track of a number instead of a file path. When the video device is open but not streaming, the pipeline can be powered off. Move the pipeline power management to the prepare_streaming and unprepare_streaming functions.

---
 .../media/platform/qcom/camss/camss-video.c   | 39 ++++++++++++-------
 1 file changed, 25 insertions(+), 14 deletions(-)
drivers/media/platform/qcom/camss/camss-video.c +25 -14
index aa021fd5e123..8d05802d1735 100644
@@ -225,6 +225,21 @@ static int video_check_format(struct camss_video *video)
 	return 0;
 }
 
+static int video_prepare_streaming(struct vb2_queue *q)
+{
+	struct camss_video *video = vb2_get_drv_priv(q);
+	struct video_device *vdev = &video->vdev;
+	int ret;
+
+	ret = v4l2_pipeline_pm_get(&vdev->entity);
+	if (ret < 0) {
+		dev_err(video->camss->dev, "Failed to power up pipeline: %d\n",
+			ret);
+	}
+
+	return ret;
+}
+
 static int video_start_streaming(struct vb2_queue *q, unsigned int count)
 {
 	struct camss_video *video = vb2_get_drv_priv(q);
@@ -308,13 +323,23 @@ static void video_stop_streaming(struct vb2_queue *q)
 	video->ops->flush_buffers(video, VB2_BUF_STATE_ERROR);
 }
 
+static void video_unprepare_streaming(struct vb2_queue *q)
+{
+	struct camss_video *video = vb2_get_drv_priv(q);
+	struct video_device *vdev = &video->vdev;
+
+	v4l2_pipeline_pm_put(&vdev->entity);
+}
+
 static const struct vb2_ops msm_video_vb2_q_ops = {
 	.queue_setup     = video_queue_setup,
 	.buf_init        = video_buf_init,
 	.buf_prepare     = video_buf_prepare,
 	.buf_queue       = video_buf_queue,
+	.prepare_streaming = video_prepare_streaming,
 	.start_streaming = video_start_streaming,
 	.stop_streaming  = video_stop_streaming,
+	.unprepare_streaming = video_unprepare_streaming,
 };
 
 /* -----------------------------------------------------------------------------
@@ -599,20 +624,10 @@ static int video_open(struct file *file)
 
 	file->private_data = vfh;
 
-	ret = v4l2_pipeline_pm_get(&vdev->entity);
-	if (ret < 0) {
-		dev_err(video->camss->dev, "Failed to power up pipeline: %d\n",
-			ret);
-		goto error_pm_use;
-	}
-
 	mutex_unlock(&video->lock);
 
 	return 0;
 
-error_pm_use:
-	v4l2_fh_release(file);
-
 error_alloc:
 	mutex_unlock(&video->lock);
 
@@ -621,12 +636,8 @@ static int video_open(struct file *file)
 
 static int video_release(struct file *file)
 {
-	struct video_device *vdev = video_devdata(file);
-
 	vb2_fop_release(file);
 
-	v4l2_pipeline_pm_put(&vdev->entity);
-
 	file->private_data = NULL;
 
 	return 0;
Signature · 1 line
2.49.0
reviewer
#1 lore raw
Quoted 7 lines · Richard Acayan

The libcamera plugin for Pipewire may keep an open file descriptor to the video device, even while streaming. This simplifies its operation, as it only needs to keep track of a number instead of a file path. When the video device is open but not streaming, the pipeline can be powered off. Move the pipeline power management to the prepare_streaming and unprepare_streaming functions.

It seems to affect more than just this specific driver then? According to the documentation in v4l2-mc.h, v4l2_pipeline_pm_get() is intended to be called during video node open. If we're changing that behavior, we should also update the function's documentation accordingly so the change can be properly discussed and understood by a broader audience.

Quoted 94 lines
---
 .../media/platform/qcom/camss/camss-video.c   | 39 ++++++++++++-------
 1 file changed, 25 insertions(+), 14 deletions(-)
drivers/media/platform/qcom/camss/camss-video.c +25 -15
index aa021fd5e123..8d05802d1735 100644
@@ -225,6 +225,21 @@ static int video_check_format(struct camss_video *video)
        return 0;
 }
 
+static int video_prepare_streaming(struct vb2_queue *q)
+{
+       struct camss_video *video = vb2_get_drv_priv(q);
+       struct video_device *vdev = &video->vdev;
+       int ret;
+
+       ret = v4l2_pipeline_pm_get(&vdev->entity);
+       if (ret < 0) {
+               dev_err(video->camss->dev, "Failed to power up pipeline: %d\n",
+                       ret);
+       }
+
+       return ret;
+}
+
 static int video_start_streaming(struct vb2_queue *q, unsigned int count)
 {
        struct camss_video *video = vb2_get_drv_priv(q);
@@ -308,13 +323,23 @@ static void video_stop_streaming(struct vb2_queue *q)
        video->ops->flush_buffers(video, VB2_BUF_STATE_ERROR);
 }
 
+static void video_unprepare_streaming(struct vb2_queue *q)
+{
+       struct camss_video *video = vb2_get_drv_priv(q);
+       struct video_device *vdev = &video->vdev;
+
+       v4l2_pipeline_pm_put(&vdev->entity);
+}
+
 static const struct vb2_ops msm_video_vb2_q_ops = {
        .queue_setup     = video_queue_setup,
        .buf_init        = video_buf_init,
        .buf_prepare     = video_buf_prepare,
        .buf_queue       = video_buf_queue,
+       .prepare_streaming = video_prepare_streaming,
        .start_streaming = video_start_streaming,
        .stop_streaming  = video_stop_streaming,
+       .unprepare_streaming = video_unprepare_streaming,
 };
 
 /* -----------------------------------------------------------------------------
@@ -599,20 +624,10 @@ static int video_open(struct file *file)
 
        file->private_data = vfh;
 
-       ret = v4l2_pipeline_pm_get(&vdev->entity);
-       if (ret < 0) {
-               dev_err(video->camss->dev, "Failed to power up pipeline: %d\n",
-                       ret);
-               goto error_pm_use;
-       }
-
        mutex_unlock(&video->lock);
 
        return 0;
 
-error_pm_use:
-       v4l2_fh_release(file);
-
 error_alloc:
        mutex_unlock(&video->lock);
 
@@ -621,12 +636,8 @@ static int video_open(struct file *file)
 
 static int video_release(struct file *file)
 {
-       struct video_device *vdev = video_devdata(file);
-
        vb2_fop_release(file);
 
-       v4l2_pipeline_pm_put(&vdev->entity);
-
        file->private_data = NULL;
 
        return 0;
--

2.49.0

maintainer
#2 lore raw
Quoted 7 lines · Loic Poulain
Quoted 6 lines · Richard Acayan

The libcamera plugin for Pipewire may keep an open file descriptor to the video device, even while streaming. This simplifies its operation, as it only needs to keep track of a number instead of a file path. When the video device is open but not streaming, the pipeline can be powered off. Move the pipeline power management to the prepare_streaming and unprepare_streaming functions.

Quoted 5 lines

It seems to affect more than just this specific driver then? According to the documentation in v4l2-mc.h, v4l2_pipeline_pm_get() is intended to be called during video node open. If we're changing that behavior, we should also update the function's documentation accordingly so the change can be properly discussed and understood by a broader audience.

True but then the patch that added that comment also contains

@@ -999,7 +996,7 @@ rkisp1_vb2_start_streaming(struct vb2_queue *queue, unsigned int count)

                dev_err(cap->rkisp1->dev, "power up failed %d\n", ret);
                goto err_destroy_dummy;
        }

- ret = v4l2_pipeline_pm_use(entity, 1);
+ ret = v4l2_pipeline_pm_get(entity);

Seems to me like a perfectly valid use-case to have a persistent handle but only want to power-up the pipeline when you have work to-do.

---
bod

maintainer Reviewed-by Tested-by on v1 1/1
#3 lore raw
In reply to Richard Acayan
Quoted 86 lines · Richard Acayan

The libcamera plugin for Pipewire may keep an open file descriptor to the video device, even while streaming. This simplifies its operation, as it only needs to keep track of a number instead of a file path. When the video device is open but not streaming, the pipeline can be powered off. Move the pipeline power management to the prepare_streaming and unprepare_streaming functions.

---
  .../media/platform/qcom/camss/camss-video.c   | 39 ++++++++++++-------
  1 file changed, 25 insertions(+), 14 deletions(-)
drivers/media/platform/qcom/camss/camss-video.c +25 -10
index aa021fd5e123..8d05802d1735 100644
@@ -225,6 +225,21 @@ static int video_check_format(struct camss_video *video)
  	return 0;
  }
 
+static int video_prepare_streaming(struct vb2_queue *q)
+{
+	struct camss_video *video = vb2_get_drv_priv(q);
+	struct video_device *vdev = &video->vdev;
+	int ret;
+
+	ret = v4l2_pipeline_pm_get(&vdev->entity);
+	if (ret < 0) {
+		dev_err(video->camss->dev, "Failed to power up pipeline: %d\n",
+			ret);
+	}
+
+	return ret;
+}
+
  static int video_start_streaming(struct vb2_queue *q, unsigned int count)
  {
  	struct camss_video *video = vb2_get_drv_priv(q);
@@ -308,13 +323,23 @@ static void video_stop_streaming(struct vb2_queue *q)
  	video->ops->flush_buffers(video, VB2_BUF_STATE_ERROR);
  }
 
+static void video_unprepare_streaming(struct vb2_queue *q)
+{
+	struct camss_video *video = vb2_get_drv_priv(q);
+	struct video_device *vdev = &video->vdev;
+
+	v4l2_pipeline_pm_put(&vdev->entity);
+}
+
  static const struct vb2_ops msm_video_vb2_q_ops = {
  	.queue_setup     = video_queue_setup,
  	.buf_init        = video_buf_init,
  	.buf_prepare     = video_buf_prepare,
  	.buf_queue       = video_buf_queue,
+	.prepare_streaming = video_prepare_streaming,
  	.start_streaming = video_start_streaming,
  	.stop_streaming  = video_stop_streaming,
+	.unprepare_streaming = video_unprepare_streaming,
  };
 
  /* -----------------------------------------------------------------------------
@@ -599,20 +624,10 @@ static int video_open(struct file *file)
 
  	file->private_data = vfh;
 
-	ret = v4l2_pipeline_pm_get(&vdev->entity);
-	if (ret < 0) {
-		dev_err(video->camss->dev, "Failed to power up pipeline: %d\n",
-			ret);
-		goto error_pm_use;
-	}
-
  	mutex_unlock(&video->lock);
 
  	return 0;
 
-error_pm_use:
-	v4l2_fh_release(file);
-
  error_alloc:
  	mutex_unlock(&video->lock);
 
@@ -621,12 +636,8 @@ static int video_open(struct file *file)
 
  static int video_release(struct file *file)

drivers/media/platform/qcom/camss/camss-video.c static int video_open(struct file *file) · line 643

Quoted 10 lines
drivers/media/platform/qcom/camss/camss-video.c +0 -4
  {
-	struct video_device *vdev = video_devdata(file);
-
  	vb2_fop_release(file);
 
-	v4l2_pipeline_pm_put(&vdev->entity);
-
  	file->private_data = NULL;
 
  	return 0;
reviewer Reviewed-by on v1 1/1
#4 lore raw
In reply to Richard Acayan
Quoted 8 lines · Richard Acayan

The libcamera plugin for Pipewire may keep an open file descriptor to the video device, even while streaming. This simplifies its operation, as it only needs to keep track of a number instead of a file path. When the video device is open but not streaming, the pipeline can be powered off. Move the pipeline power management to the prepare_streaming and unprepare_streaming functions.

--
Best wishes,
Vladimir