linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@collabora.com>
To: Ezequiel Garcia <ezequiel@collabora.com>
Cc: Hans Verkuil <hverkuil@xs4all.nl>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hans.verkuil@cisco.com>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Sakari Ailus <sakari.ailus@iki.fi>,
	linux-media@vger.kernel.org, kernel@collabora.com
Subject: Re: [PATCH] media: v4l2: Initialize mpeg slice controls
Date: Wed, 29 May 2019 19:06:52 +0200	[thread overview]
Message-ID: <20190529190652.4f4cf157@collabora.com> (raw)
In-Reply-To: <87ee90d1f42dfbaff43ac29ecadcb5c1d5748230.camel@collabora.com>

On Wed, 29 May 2019 13:59:50 -0300
Ezequiel Garcia <ezequiel@collabora.com> wrote:

> On Wed, 2019-05-29 at 18:06 +0200, Boris Brezillon wrote:
> > On Wed, 29 May 2019 17:42:58 +0200
> > Hans Verkuil <hverkuil@xs4all.nl> wrote:
> >   
> > > On 5/29/19 5:36 PM, Ezequiel Garcia wrote:  
> > > > On Wed, 2019-05-29 at 16:41 +0200, Hans Verkuil wrote:    
> > > > > On 5/3/19 1:42 PM, Boris Brezillon wrote:    
> > > > > > Make sure the default value at least passes the std_validate() tests.
> > > > > > 
> > > > > > Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> > > > > > ---
> > > > > >  drivers/media/v4l2-core/v4l2-ctrls.c | 20 +++++++++++++++++++-
> > > > > >  1 file changed, 19 insertions(+), 1 deletion(-)
> > > > > > 
> > > > > > diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
> > > > > > index b1ae2e555c68..19d40cc6e565 100644
> > > > > > --- a/drivers/media/v4l2-core/v4l2-ctrls.c
> > > > > > +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
> > > > > > @@ -1461,7 +1461,14 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,
> > > > > >  static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
> > > > > >  		     union v4l2_ctrl_ptr ptr)
> > > > > >  {
> > > > > > -	switch (ctrl->type) {
> > > > > > +	struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
> > > > > > +
> > > > > > +	/*
> > > > > > +	 * The cast is needed to get rid of a gcc warning complaining that
> > > > > > +	 * V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS is not part of the
> > > > > > +	 * v4l2_ctrl_type enum.
> > > > > > +	 */
> > > > > > +	switch ((u32)ctrl->type) {
> > > > > >  	case V4L2_CTRL_TYPE_STRING:
> > > > > >  		idx *= ctrl->elem_size;
> > > > > >  		memset(ptr.p_char + idx, ' ', ctrl->minimum);
> > > > > > @@ -1486,6 +1493,17 @@ static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
> > > > > >  	case V4L2_CTRL_TYPE_U32:
> > > > > >  		ptr.p_u32[idx] = ctrl->default_value;
> > > > > >  		break;
> > > > > > +	case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS:
> > > > > > +		p_mpeg2_slice_params = ptr.p;
> > > > > > +		/* 4:2:0 */
> > > > > > +		p_mpeg2_slice_params->sequence.chroma_format = 1;
> > > > > > +		/* 8 bits */
> > > > > > +		p_mpeg2_slice_params->picture.intra_dc_precision = 0;
> > > > > > +		/* interlaced top field */
> > > > > > +		p_mpeg2_slice_params->picture.picture_structure = 1;
> > > > > > +		p_mpeg2_slice_params->picture.picture_coding_type =
> > > > > > +					V4L2_MPEG2_PICTURE_CODING_TYPE_I;    
> > > > > 
> > > > > Oops, this isn't complete. It should still zero the p_mpeg2_slice_params
> > > > > struct first. Right now any fields not explicitly set just have whatever
> > > > > was in memory.  
> > 
> > Oops.
> >   
> > > > > Can you post a patch fixing this?
> > > > > 
> > > > >    
> > > > 
> > > > I was wondering if we want to zero all the cases, and not just
> > > > the struct types ones.    
> > > 
> > > The others either overwrite the data with the default_value, or memset
> > > the whole control (default case). It's only for these compound controls
> > > that something special needs to be done.
> > > 
> > > The code can be restructured, though: instead of break do return in all
> > > the simple type cases.
> > > 
> > > Then call memset followed by a new switch for the compound types where you
> > > need to set some fields to non-zero.  
> > 
> > memset(0) will fix the undefined val issue, the question is, is it the
> > default we want? I haven't worked on MPEG2 (just posted patches
> > Ezequiel worked on) so I can't tell.
> >   
> 
> Well, any fields where zero is not a good default, should be assigned here.
> 

That's my point: I've only assigned fields that were checked by the core
and where 0 is not a valid value. That doesn't necessarily make 0 a good
default for the other fields :P. Hence my suggestion to have someone
that knows about MPEG2 (you :)) check the other fields.

      reply	other threads:[~2019-05-29 17:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-03 11:42 [PATCH] media: v4l2: Initialize mpeg slice controls Boris Brezillon
2019-05-29 14:41 ` Hans Verkuil
2019-05-29 15:36   ` Ezequiel Garcia
2019-05-29 15:42     ` Hans Verkuil
2019-05-29 16:06       ` Boris Brezillon
2019-05-29 16:59         ` Ezequiel Garcia
2019-05-29 17:06           ` Boris Brezillon [this message]

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=20190529190652.4f4cf157@collabora.com \
    --to=boris.brezillon@collabora.com \
    --cc=ezequiel@collabora.com \
    --cc=hans.verkuil@cisco.com \
    --cc=hverkuil@xs4all.nl \
    --cc=kernel@collabora.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@iki.fi \
    /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).