Skip to contentSkip to conversation

media: staging: rkisp1: allow simultaneous streaming from multiple capture devices

PATCH In review Helen Koike 2 participants 4 messages Mar 16, 2020 – Jun 10, 2020

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

v2 cover media: staging: rkisp1: allow simultaneous streaming from multiple capture devices

Hi,

This series adds support for simultaneous streaming from both capture devices (rkisp1_selfpath and rkisp1_mainpath).

It depends on the following series for multistream to work properly, but it doesn't mean it can't be merged before:

	"media: add v4l2_pipeline_stream_{enable,disable} helpers"
	https://patchwork.linuxtv.org/cover/62233/

And it is also available at:

https://gitlab.collabora.com/koike/linux/tree/rockchip/isp/multistream

Patch 1/2 fixes return error handling from pm functions, which was preventing the second stream to start.

Patch 2/2 serializes start/stop streaming calls, since they both and modify shared variables.

Changes in v2:
- Rebased on media/master
- Removed the following patch from the series:
"media: staging: rkisp1: do not call s_stream if the entity is still in use" It was replaced by "media: add v4l2_pipeline_stream_{enable,disable} helpers"
https://patchwork.linuxtv.org/cover/62233/

This series was tested with:
============================

SEN_DEV=/dev/v4l-subdev3
ISP_DEV=/dev/v4l-subdev0
RSZ_SP_DEV=/dev/v4l-subdev2
RSZ_MP_DEV=/dev/v4l-subdev1
CAP_SP_DEV=/dev/video1
CAP_MP_DEV=/dev/video0

WIDTH=1920
HEIGHT=1080
RAW_CODE=SRGGB10_1X10
YUV_CODE=YUYV8_2X8

v4l2-ctl --set-subdev-fmt pad=0,width=$WIDTH,height=$HEIGHT,code=$RAW_CODE -d $SEN_DEV

v4l2-ctl --set-subdev-fmt pad=0,width=$WIDTH,height=$HEIGHT,code=$RAW_CODE -d $ISP_DEV v4l2-ctl --set-subdev-selection pad=0,target=crop,top=0,left=0,width=$WIDTH,height=$HEIGHT -d $ISP_DEV

v4l2-ctl --set-subdev-selection pad=2,target=crop,top=0,left=0,width=$WIDTH,height=$HEIGHT -d $ISP_DEV v4l2-ctl --set-subdev-fmt pad=2,width=$WIDTH,height=$HEIGHT,code=$YUV_CODE -d $ISP_DEV

v4l2-ctl --set-subdev-fmt pad=0,width=$WIDTH,height=$HEIGHT,code=$YUV_CODE -d $RSZ_SP_DEV v4l2-ctl --set-subdev-fmt pad=1,width=$WIDTH,height=$HEIGHT,code=$YUV_CODE -d $RSZ_SP_DEV

v4l2-ctl --set-subdev-selection pad=0,target=crop,top=0,left=0,width=$WIDTH,height=$HEIGHT -d $RSZ_SP_DEV

v4l2-ctl --set-subdev-fmt pad=0,width=$WIDTH,height=$HEIGHT,code=$YUV_CODE -d $RSZ_MP_DEV v4l2-ctl --set-subdev-fmt pad=1,width=$WIDTH,height=$HEIGHT,code=$YUV_CODE -d $RSZ_MP_DEV

v4l2-ctl --set-subdev-selection pad=0,target=crop,top=0,left=0,width=$WIDTH,height=$HEIGHT -d $RSZ_MP_DEV

v4l2-ctl -v width=$WIDTH,height=$HEIGHT,pixelformat=NV12 -d $CAP_SP_DEV v4l2-ctl -v width=$WIDTH,height=$HEIGHT,pixelformat=NV12 -d $CAP_MP_DEV

sleep 1

v4l2-ctl --stream-mmap --stream-count=100 -d $CAP_SP_DEV --stream-to=/tmp/test_sp.raw & v4l2-ctl --stream-mmap --stream-count=100 -d $CAP_MP_DEV --stream-to=/tmp/test_mp.raw &

wait
echo "Completed"

Helen Koike (2):
media: staging: rkisp1: cap: fix return values from pm functions
media: staging: rkisp1: cap: serialize start/stop stream

 drivers/staging/media/rkisp1/rkisp1-capture.c | 13 +++++++++++--
 drivers/staging/media/rkisp1/rkisp1-common.h  |  2 ++
 drivers/staging/media/rkisp1/rkisp1-dev.c     |  2 ++
 3 files changed, 15 insertions(+), 2 deletions(-)
Signature · 1 line
2.25.0
#1 lore raw

PATCH v2 1/2 media: staging: rkisp1: cap: fix return values from pm functions

If no errors occurs, pm functions return usage counters, so they can return positive numbers.
This happens when streaming from multiple capture devices (mainpath and selfpath).

Fix simultaneous streaming from mainpath and selfpath by not failing when pm usage counters returns a positive number.

---

Changes in v2:
- Rebased on media/master

 drivers/staging/media/rkisp1/rkisp1-capture.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/media/rkisp1/rkisp1-capture.c +2 -2
index 24fe6a7888aa..967bd05b4507 100644
@@ -939,7 +939,7 @@ static void rkisp1_vb2_stop_streaming(struct vb2_queue *queue)
 
 	v4l2_pipeline_pm_put(&node->vdev.entity);
 	ret = pm_runtime_put(rkisp1->dev);
-	if (ret)
+	if (ret < 0)
 		dev_err(rkisp1->dev, "power down failed error:%d\n", ret);
 
 	rkisp1_dummy_buf_destroy(cap);
@@ -992,7 +992,7 @@ rkisp1_vb2_start_streaming(struct vb2_queue *queue, unsigned int count)
 		goto err_ret_buffers;
 
 	ret = pm_runtime_get_sync(cap->rkisp1->dev);
-	if (ret) {
+	if (ret < 0) {
 		dev_err(cap->rkisp1->dev, "power up failed %d\n", ret);
 		goto err_destroy_dummy;
 	}
Signature · 1 line
2.25.0
#2 lore raw

PATCH v2 2/2 media: staging: rkisp1: cap: serialize start/stop stream

In reply to Helen Koike

In order to support simultaneous streaming from both capture devices, start/stop vb2 calls need to be serialized to allow multiple concurrent calls.

---

Changes in v2:
- Rebased with media/master

 drivers/staging/media/rkisp1/rkisp1-capture.c | 9 +++++++++
 drivers/staging/media/rkisp1/rkisp1-common.h  | 2 ++
 drivers/staging/media/rkisp1/rkisp1-dev.c     | 2 ++
 3 files changed, 13 insertions(+)
drivers/staging/media/rkisp1/rkisp1-capture.c +9 -0
index 967bd05b4507..f3c4f2a198ca 100644
@@ -927,6 +927,8 @@ static void rkisp1_vb2_stop_streaming(struct vb2_queue *queue)
 	struct rkisp1_device *rkisp1 = cap->rkisp1;
 	int ret;
 
+	mutex_lock(&cap->rkisp1->stream_lock);
+
 	rkisp1_stream_stop(cap);
 	media_pipeline_stop(&node->vdev.entity);
 	ret = rkisp1_pipeline_sink_walk(&node->vdev.entity, NULL,
@@ -943,6 +945,8 @@ static void rkisp1_vb2_stop_streaming(struct vb2_queue *queue)
 		dev_err(rkisp1->dev, "power down failed error:%d\n", ret);
 
 	rkisp1_dummy_buf_destroy(cap);
+
+	mutex_unlock(&cap->rkisp1->stream_lock);
 }
 
 /*
@@ -987,6 +991,8 @@ rkisp1_vb2_start_streaming(struct vb2_queue *queue, unsigned int count)
 	struct media_entity *entity = &cap->vnode.vdev.entity;
 	int ret;
 
+	mutex_lock(&cap->rkisp1->stream_lock);
+
 	ret = rkisp1_dummy_buf_create(cap);
 	if (ret)
 		goto err_ret_buffers;
@@ -1016,6 +1022,8 @@ rkisp1_vb2_start_streaming(struct vb2_queue *queue, unsigned int count)
 		goto err_pipe_disable;
 	}
 
+	mutex_unlock(&cap->rkisp1->stream_lock);
+
 	return 0;
 
 err_pipe_disable:
@@ -1029,6 +1037,7 @@ rkisp1_vb2_start_streaming(struct vb2_queue *queue, unsigned int count)
 	rkisp1_dummy_buf_destroy(cap);
 err_ret_buffers:
 	rkisp1_return_all_buffers(cap, VB2_BUF_STATE_QUEUED);
+	mutex_unlock(&cap->rkisp1->stream_lock);
 
 	return ret;
 }
drivers/staging/media/rkisp1/rkisp1-common.h +2 -0
index b291cc60de8e..4ec5aae9694a 100644
@@ -247,6 +247,7 @@ struct rkisp1_debug {
  * @rkisp1_capture: capture video device
  * @stats: ISP statistics output device
  * @params: ISP input parameters device
+ * @stream_lock: lock to serialize start/stop streaming in capture devices.
  */
 struct rkisp1_device {
 	void __iomem *base_addr;
@@ -266,6 +267,7 @@ struct rkisp1_device {
 	struct rkisp1_params params;
 	struct media_pipeline pipe;
 	struct vb2_alloc_ctx *alloc_ctx;
+	struct mutex stream_lock;
 	struct rkisp1_debug debug;
 };
 
drivers/staging/media/rkisp1/rkisp1-dev.c +2 -0
index b1b3c058e957..3e3a3925b019 100644
@@ -471,6 +471,8 @@ static int rkisp1_probe(struct platform_device *pdev)
 	dev_set_drvdata(dev, rkisp1);
 	rkisp1->dev = dev;
 
+	mutex_init(&rkisp1->stream_lock);
+
 	rkisp1->base_addr = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(rkisp1->base_addr))
 		return PTR_ERR(rkisp1->base_addr);
Signature · 1 line
2.25.0
Reviewed-by on the v2 series
#3 lore raw
In reply to Helen Koike
Quoted 21 lines · Helen Koike

Hi,

This series adds support for simultaneous streaming from both capture devices (rkisp1_selfpath and rkisp1_mainpath).

It depends on the following series for multistream to work properly, but it doesn't mean it can't be merged before:

	"media: add v4l2_pipeline_stream_{enable,disable} helpers"
	https://patchwork.linuxtv.org/cover/62233/

And it is also available at:

https://gitlab.collabora.com/koike/linux/tree/rockchip/isp/multistream

Patch 1/2 fixes return error handling from pm functions, which was preventing the second stream to start.

Patch 2/2 serializes start/stop streaming calls, since they both and modify shared variables.

Quoted 7 lines

Changes in v2:
- Rebased on media/master
- Removed the following patch from the series:
"media: staging: rkisp1: do not call s_stream if the entity is still in use" It was replaced by "media: add v4l2_pipeline_stream_{enable,disable} helpers"
https://patchwork.linuxtv.org/cover/62233/

For the whole series:

Best regards,
Tomasz