From: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
To: Helen Koike <helen.koike@collabora.com>
Cc: linux-media@vger.kernel.org, libcamera-devel@lists.libcamera.org,
Dafna Hirschfeld <dafna.hirschfeld@collabora.com>
Subject: Re: [PATCH 1/3] vimc: Add usage count to subdevices
Date: Mon, 16 Mar 2020 21:32:00 +0100 [thread overview]
Message-ID: <20200316203200.GA2324872@oden.dyn.berto.se> (raw)
In-Reply-To: <69c63e0a-d46a-d553-5308-9feb16e49353@collabora.com>
Hi Helen,
Thanks for your notification.
On 2020-03-16 16:40:54 -0300, Helen Koike wrote:
> Hi Niklas,
>
> On 5/17/19 10:07 PM, Niklas Söderlund wrote:
> > Prepare for multiple video streams from the same sensor by adding a use
> > counter to each subdevice. The counter is increase for every s_stream(1)
> > and decremented for every s_stream(0) call.
> >
> > The subdevice stream is not started or stopped unless the usage count go
> > from 0 to 1 (started) or from 1 to 0 (stopped). This allow for multiple
> > s_stream() calls to try to either start or stop the device while only
> > the first/last call will actually effect the state of the device.
> >
> > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
>
> This patch won't be required if the following series gets accepted
> https://patchwork.linuxtv.org/cover/62233/
>
> Since helpers takes care that s_stream(true) won't be called twice without
> s_stream(false) (and the opposite is also true).
Sweet, it will be nice to get multiple stream support upstream for VIMC!
>
> Regards,
> Helen
>
> > ---
> > drivers/media/platform/vimc/vimc-debayer.c | 8 ++++++++
> > drivers/media/platform/vimc/vimc-scaler.c | 8 ++++++++
> > drivers/media/platform/vimc/vimc-sensor.c | 7 +++++++
> > 3 files changed, 23 insertions(+)
> >
> > diff --git a/drivers/media/platform/vimc/vimc-debayer.c b/drivers/media/platform/vimc/vimc-debayer.c
> > index 281f9c1a7249ad1d..624fc23ce3077d40 100644
> > --- a/drivers/media/platform/vimc/vimc-debayer.c
> > +++ b/drivers/media/platform/vimc/vimc-debayer.c
> > @@ -56,6 +56,7 @@ struct vimc_deb_device {
> > struct vimc_ent_device ved;
> > struct v4l2_subdev sd;
> > struct device *dev;
> > + atomic_t use_count;
> > /* The active format */
> > struct v4l2_mbus_framefmt sink_fmt;
> > u32 src_code;
> > @@ -337,6 +338,9 @@ static int vimc_deb_s_stream(struct v4l2_subdev *sd, int enable)
> > const struct v4l2_format_info *pix_info;
> > unsigned int frame_size;
> >
> > + if (atomic_inc_return(&vdeb->use_count) != 1)
> > + return 0;
> > +
> > if (vdeb->src_frame)
> > return 0;
> >
> > @@ -374,6 +378,9 @@ static int vimc_deb_s_stream(struct v4l2_subdev *sd, int enable)
> > return -ENOMEM;
> >
> > } else {
> > + if (atomic_dec_return(&vdeb->use_count) != 0)
> > + return 0;
> > +
> > if (!vdeb->src_frame)
> > return 0;
> >
> > @@ -562,6 +569,7 @@ static int vimc_deb_comp_bind(struct device *comp, struct device *master,
> > vdeb->ved.process_frame = vimc_deb_process_frame;
> > dev_set_drvdata(comp, &vdeb->ved);
> > vdeb->dev = comp;
> > + atomic_set(&vdeb->use_count, 0);
> >
> > /* Initialize the frame format */
> > vdeb->sink_fmt = sink_fmt_default;
> > diff --git a/drivers/media/platform/vimc/vimc-scaler.c b/drivers/media/platform/vimc/vimc-scaler.c
> > index 8aecf8e920310608..37d2020d987a7d80 100644
> > --- a/drivers/media/platform/vimc/vimc-scaler.c
> > +++ b/drivers/media/platform/vimc/vimc-scaler.c
> > @@ -45,6 +45,7 @@ struct vimc_sca_device {
> > struct vimc_ent_device ved;
> > struct v4l2_subdev sd;
> > struct device *dev;
> > + atomic_t use_count;
> > /* NOTE: the source fmt is the same as the sink
> > * with the width and hight multiplied by mult
> > */
> > @@ -213,6 +214,9 @@ static int vimc_sca_s_stream(struct v4l2_subdev *sd, int enable)
> > const struct v4l2_format_info *pix_info;
> > unsigned int frame_size;
> >
> > + if (atomic_inc_return(&vsca->use_count) != 1)
> > + return 0;
> > +
> > if (vsca->src_frame)
> > return 0;
> >
> > @@ -242,6 +246,9 @@ static int vimc_sca_s_stream(struct v4l2_subdev *sd, int enable)
> > return -ENOMEM;
> >
> > } else {
> > + if (atomic_dec_return(&vsca->use_count) != 0)
> > + return 0;
> > +
> > if (!vsca->src_frame)
> > return 0;
> >
> > @@ -396,6 +403,7 @@ static int vimc_sca_comp_bind(struct device *comp, struct device *master,
> > vsca->ved.process_frame = vimc_sca_process_frame;
> > dev_set_drvdata(comp, &vsca->ved);
> > vsca->dev = comp;
> > + atomic_set(&vsca->use_count, 0);
> >
> > /* Initialize the frame format */
> > vsca->sink_fmt = sink_fmt_default;
> > diff --git a/drivers/media/platform/vimc/vimc-sensor.c b/drivers/media/platform/vimc/vimc-sensor.c
> > index baca9ca67ce0af0b..36c3cea85a185f4b 100644
> > --- a/drivers/media/platform/vimc/vimc-sensor.c
> > +++ b/drivers/media/platform/vimc/vimc-sensor.c
> > @@ -34,6 +34,7 @@ struct vimc_sen_device {
> > struct vimc_ent_device ved;
> > struct v4l2_subdev sd;
> > struct device *dev;
> > + atomic_t use_count;
> > struct tpg_data tpg;
> > struct task_struct *kthread_sen;
> > u8 *frame;
> > @@ -197,6 +198,9 @@ static int vimc_sen_s_stream(struct v4l2_subdev *sd, int enable)
> > const struct v4l2_format_info *pix_info;
> > unsigned int frame_size;
> >
> > + if (atomic_inc_return(&vsen->use_count) != 1)
> > + return 0;
> > +
> > if (vsen->kthread_sen)
> > /* tpg is already executing */
> > return 0;
> > @@ -218,6 +222,8 @@ static int vimc_sen_s_stream(struct v4l2_subdev *sd, int enable)
> > vimc_sen_tpg_s_format(vsen);
> >
> > } else {
> > + if (atomic_dec_return(&vsen->use_count) != 0)
> > + return 0;
> >
> > vfree(vsen->frame);
> > vsen->frame = NULL;
> > @@ -367,6 +373,7 @@ static int vimc_sen_comp_bind(struct device *comp, struct device *master,
> > vsen->ved.process_frame = vimc_sen_process_frame;
> > dev_set_drvdata(comp, &vsen->ved);
> > vsen->dev = comp;
> > + atomic_set(&vsen->use_count, 0);
> >
> > /* Initialize the frame format */
> > vsen->mbus_format = fmt_default;
> >
--
Regards,
Niklas Söderlund
next prev parent reply other threads:[~2020-03-16 20:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-18 1:07 [PATCH 0/3] vimc: Allow multiple capture devices to use the same sensor Niklas Söderlund
2019-05-18 1:07 ` [PATCH 1/3] vimc: Add usage count to subdevices Niklas Söderlund
2020-03-16 19:40 ` Helen Koike
2020-03-16 20:32 ` Niklas Söderlund [this message]
2019-05-18 1:07 ` [PATCH 2/3] vimc: Serialize vimc_streamer_s_stream() Niklas Söderlund
2019-05-18 1:07 ` [PATCH 3/3] vimc: Join pipeline if one already exists Niklas Söderlund
2019-07-09 18:24 ` Helen Koike
2019-07-11 4:35 ` Niklas Söderlund
2019-10-23 7:01 ` [PATCH 0/3] vimc: Allow multiple capture devices to use the same sensor Hans Verkuil
2019-10-23 10:22 ` Niklas Söderlund
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200316203200.GA2324872@oden.dyn.berto.se \
--to=niklas.soderlund+renesas@ragnatech.se \
--cc=dafna.hirschfeld@collabora.com \
--cc=helen.koike@collabora.com \
--cc=libcamera-devel@lists.libcamera.org \
--cc=linux-media@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).