<div dir="ltr"><div dir="ltr">Hi,<div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, May 18, 2019 at 4:16 AM Niklas Söderlund <<a href="mailto:niklas.soderlund%2Brenesas@ragnatech.se">niklas.soderlund+renesas@ragnatech.se</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Prepare for multiple video streams from the same sensor by adding a use<br>
counter to each subdevice. The counter is increase for every s_stream(1)<br>
and decremented for every s_stream(0) call.<br>
<br>
The subdevice stream is not started or stopped unless the usage count go<br>
from 0 to 1 (started) or from 1 to 0 (stopped). This allow for multiple<br>
s_stream() calls to try to either start or stop the device while only<br>
the first/last call will actually effect the state of the device.<br>
<br>
Signed-off-by: Niklas Söderlund <<a href="mailto:niklas.soderlund@ragnatech.se" target="_blank">niklas.soderlund@ragnatech.se</a>><br>
---<br>
drivers/media/platform/vimc/vimc-debayer.c | 8 ++++++++<br>
drivers/media/platform/vimc/vimc-scaler.c | 8 ++++++++<br>
drivers/media/platform/vimc/vimc-sensor.c | 7 +++++++<br>
3 files changed, 23 insertions(+)<br>
<br>
diff --git a/drivers/media/platform/vimc/vimc-debayer.c b/drivers/media/platform/vimc/vimc-debayer.c<br>
index 281f9c1a7249ad1d..624fc23ce3077d40 100644<br>
--- a/drivers/media/platform/vimc/vimc-debayer.c<br>
+++ b/drivers/media/platform/vimc/vimc-debayer.c<br>
@@ -56,6 +56,7 @@ struct vimc_deb_device {<br>
struct vimc_ent_device ved;<br>
struct v4l2_subdev sd;<br>
struct device *dev;<br>
+ atomic_t use_count;<br>
/* The active format */<br>
struct v4l2_mbus_framefmt sink_fmt;<br>
u32 src_code;<br>
@@ -337,6 +338,9 @@ static int vimc_deb_s_stream(struct v4l2_subdev *sd, int enable)<br>
const struct v4l2_format_info *pix_info;<br>
unsigned int frame_size;<br>
<br>
+ if (atomic_inc_return(&vdeb->use_count) != 1)<br>
+ return 0;<br>
+<br></blockquote><div><br></div>I guess the use_count should decrease in case this function fails to allocate the frame,this also applies to the other s_stream callbacks in this patch.</div><div class="gmail_quote"> <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
if (vdeb->src_frame)<br>
return 0;<br>
<br>
@@ -374,6 +378,9 @@ static int vimc_deb_s_stream(struct v4l2_subdev *sd, int enable)<br>
return -ENOMEM;<br>
<br>
} else {<br>
+ if (atomic_dec_return(&vdeb->use_count) != 0)<br>
+ return 0;<br>
+<br>
if (!vdeb->src_frame)<br>
return 0;<br>
<br>
@@ -562,6 +569,7 @@ static int vimc_deb_comp_bind(struct device *comp, struct device *master,<br>
vdeb->ved.process_frame = vimc_deb_process_frame;<br>
dev_set_drvdata(comp, &vdeb->ved);<br>
vdeb->dev = comp;<br>
+ atomic_set(&vdeb->use_count, 0);<br>
<br>
/* Initialize the frame format */<br>
vdeb->sink_fmt = sink_fmt_default;<br>
diff --git a/drivers/media/platform/vimc/vimc-scaler.c b/drivers/media/platform/vimc/vimc-scaler.c<br>
index 8aecf8e920310608..37d2020d987a7d80 100644<br>
--- a/drivers/media/platform/vimc/vimc-scaler.c<br>
+++ b/drivers/media/platform/vimc/vimc-scaler.c<br>
@@ -45,6 +45,7 @@ struct vimc_sca_device {<br>
struct vimc_ent_device ved;<br>
struct v4l2_subdev sd;<br>
struct device *dev;<br>
+ atomic_t use_count;<br>
/* NOTE: the source fmt is the same as the sink<br>
* with the width and hight multiplied by mult<br>
*/<br>
@@ -213,6 +214,9 @@ static int vimc_sca_s_stream(struct v4l2_subdev *sd, int enable)<br>
const struct v4l2_format_info *pix_info;<br>
unsigned int frame_size;<br>
<br>
+ if (atomic_inc_return(&vsca->use_count) != 1)<br>
+ return 0;<br>
+<br>
if (vsca->src_frame)<br>
return 0;<br>
<br>
@@ -242,6 +246,9 @@ static int vimc_sca_s_stream(struct v4l2_subdev *sd, int enable)<br>
return -ENOMEM;<br>
<br>
} else {<br>
+ if (atomic_dec_return(&vsca->use_count) != 0)<br>
+ return 0;<br>
+<br>
if (!vsca->src_frame)<br>
return 0;<br>
<br>
@@ -396,6 +403,7 @@ static int vimc_sca_comp_bind(struct device *comp, struct device *master,<br>
vsca->ved.process_frame = vimc_sca_process_frame;<br>
dev_set_drvdata(comp, &vsca->ved);<br>
vsca->dev = comp;<br>
+ atomic_set(&vsca->use_count, 0);<br>
<br>
/* Initialize the frame format */<br>
vsca->sink_fmt = sink_fmt_default;<br>
diff --git a/drivers/media/platform/vimc/vimc-sensor.c b/drivers/media/platform/vimc/vimc-sensor.c<br>
index baca9ca67ce0af0b..36c3cea85a185f4b 100644<br>
--- a/drivers/media/platform/vimc/vimc-sensor.c<br>
+++ b/drivers/media/platform/vimc/vimc-sensor.c<br>
@@ -34,6 +34,7 @@ struct vimc_sen_device {<br>
struct vimc_ent_device ved;<br>
struct v4l2_subdev sd;<br>
struct device *dev;<br>
+ atomic_t use_count;<br>
struct tpg_data tpg;<br>
struct task_struct *kthread_sen;<br>
u8 *frame;<br>
@@ -197,6 +198,9 @@ static int vimc_sen_s_stream(struct v4l2_subdev *sd, int enable)<br>
const struct v4l2_format_info *pix_info;<br>
unsigned int frame_size;<br>
<br>
+ if (atomic_inc_return(&vsen->use_count) != 1)<br>
+ return 0;<br>
+<br>
if (vsen->kthread_sen)<br>
/* tpg is already executing */<br>
return 0;<br>
@@ -218,6 +222,8 @@ static int vimc_sen_s_stream(struct v4l2_subdev *sd, int enable)<br>
vimc_sen_tpg_s_format(vsen);<br>
<br>
} else {<br>
+ if (atomic_dec_return(&vsen->use_count) != 0)<br>
+ return 0;<br>
<br>
vfree(vsen->frame);<br>
vsen->frame = NULL;<br>
@@ -367,6 +373,7 @@ static int vimc_sen_comp_bind(struct device *comp, struct device *master,<br>
vsen->ved.process_frame = vimc_sen_process_frame;<br>
dev_set_drvdata(comp, &vsen->ved);<br>
vsen->dev = comp;<br>
+ atomic_set(&vsen->use_count, 0);<br>
<br>
/* Initialize the frame format */<br>
vsen->mbus_format = fmt_default;<br>
-- <br></blockquote>maybe it is enough to check if the entity.pipe pointer of each vimc subdevice is NULL, since the media-contoller</div><div class="gmail_quote">follows the streaming count with stream_count field and set the pipe pointer to null if it is 0.Then there is no need</div><div class="gmail_quote">to add use_count field to each vimc entity.</div><div class="gmail_quote"><br></div><div class="gmail_quote">Thanks,</div><div class="gmail_quote">Dafna<br><br><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
2.21.0<br>
<br>
</blockquote></div></div>