public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@infradead.org>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: Javier Martinez Canillas <martinez.javier@gmail.com>,
	Sakari Ailus <sakari.ailus@iki.fi>,
	linux-media@vger.kernel.org,
	laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Enrico <ebutera@users.berlios.de>,
	Gary Thomas <gary@mlbassoc.com>
Subject: Re: [PATCH 3/3] [media] tvp5150: Migrate to media-controller framework and add video format detection
Date: Mon, 03 Oct 2011 15:53:54 -0300	[thread overview]
Message-ID: <4E8A04C2.5000508@infradead.org> (raw)
In-Reply-To: <201110030830.25364.hverkuil@xs4all.nl>

Em 03-10-2011 03:30, Hans Verkuil escreveu:
> On Monday, October 03, 2011 04:17:06 Mauro Carvalho Chehab wrote:
>> Em 02-10-2011 18:18, Javier Martinez Canillas escreveu:
>>> On Sun, Oct 2, 2011 at 6:30 PM, Sakari Ailus <sakari.ailus@iki.fi> wrote:
>>>> Hi Javier,
>>>>
>>>> Thanks for the patch! It's very interesting to see a driver for a video
>>>> decoder using the MC interface. Before this we've had just image sensors.
>>>>
>>>
>>> Hello Sakari,
>>>
>>> Thanks for your comments.
>>>
>>>> Javier Martinez Canillas wrote:
>>>>> +             /* use the standard status register */
>>>>> +             std_status = tvp5150_read(sd, TVP5150_STATUS_REG_5);
>>>>> +     else
>>>>> +             /* use the standard register itself */
>>>>> +             std_status = std;
>>>>
>>>> Braces would be nice here.
>>>>
>>>
>>> Ok.
>>>
>>>>> +     switch (std_status & VIDEO_STD_MASK) {
>>>>> +     case VIDEO_STD_NTSC_MJ_BIT:
>>>>> +     case VIDEO_STD_NTSC_MJ_BIT_AS:
>>>>> +             return STD_NTSC_MJ;
>>>>> +
>>>>> +     case VIDEO_STD_PAL_BDGHIN_BIT:
>>>>> +     case VIDEO_STD_PAL_BDGHIN_BIT_AS:
>>>>> +             return STD_PAL_BDGHIN;
>>>>> +
>>>>> +     default:
>>>>> +             return STD_INVALID;
>>>>> +     }
>>>>> +
>>>>> +     return STD_INVALID;
>>>>
>>>> This return won't do anything.
>>>>
>>>
>>> Yes, will clean this.
>>>
>>>>> @@ -704,19 +812,19 @@ static int tvp5150_set_std(struct v4l2_subdev *sd, v4l2_std_id std)
>>>>>       if (std == V4L2_STD_ALL) {
>>>>>               fmt = 0;        /* Autodetect mode */
>>>>>       } else if (std & V4L2_STD_NTSC_443) {
>>>>> -             fmt = 0xa;
>>>>> +             fmt = VIDEO_STD_NTSC_4_43_BIT;
>>>>>       } else if (std & V4L2_STD_PAL_M) {
>>>>> -             fmt = 0x6;
>>>>> +             fmt = VIDEO_STD_PAL_M_BIT;
>>>>>       } else if (std & (V4L2_STD_PAL_N | V4L2_STD_PAL_Nc)) {
>>>>> -             fmt = 0x8;
>>>>> +             fmt = VIDEO_STD_PAL_COMBINATION_N_BIT;
>>>>>       } else {
>>>>>               /* Then, test against generic ones */
>>>>>               if (std & V4L2_STD_NTSC)
>>>>> -                     fmt = 0x2;
>>>>> +                     fmt = VIDEO_STD_NTSC_MJ_BIT;
>>>>>               else if (std & V4L2_STD_PAL)
>>>>> -                     fmt = 0x4;
>>>>> +                     fmt = VIDEO_STD_PAL_BDGHIN_BIT;
>>>>>               else if (std & V4L2_STD_SECAM)
>>>>> -                     fmt = 0xc;
>>>>> +                     fmt = VIDEO_STD_SECAM_BIT;
>>>>>       }
>>>>
>>>> Excellent! Less magic numbers...
>>>>
>>>>>
>>>>> +static struct v4l2_mbus_framefmt *
>>>>> +__tvp5150_get_pad_format(struct tvp5150 *tvp5150, struct v4l2_subdev_fh *fh,
>>>>> +                      unsigned int pad, enum v4l2_subdev_format_whence which)
>>>>> +{
>>>>> +     switch (which) {
>>>>> +     case V4L2_SUBDEV_FORMAT_TRY:
>>>>> +             return v4l2_subdev_get_try_format(fh, pad);
>>>>> +     case V4L2_SUBDEV_FORMAT_ACTIVE:
>>>>> +             return tvp5150->format;
>>>>> +     default:
>>>>> +             return NULL;
>>>>
>>>> Hmm. This will never happen, but is returning NULL the right thing to
>>>> do? An easy alternative is to just replace this with if (which may only
>>>> have either of the two values).
>>>>
>>>
>>> Ok I'll cleanup, I was being a bit paranoid there :)
>>>
>>>>> +
>>>>> +static int tvp5150_set_pad_format(struct v4l2_subdev *subdev,
>>>>> +                           struct v4l2_subdev_fh *fh,
>>>>> +                           struct v4l2_subdev_format *format)
>>>>> +{
>>>>> +     struct tvp5150 *tvp5150 = to_tvp5150(subdev);
>>>>> +     tvp5150->std_idx = STD_INVALID;
>>>>
>>>> The above assignment will always be overwritten immediately.
>>>>
>>>
>>> Yes, since tvp515x_query_current_std() already returns STD_INVALID on
>>> error the assignment is not needed. Will change that.
>>>
>>>>> +     tvp5150->std_idx = tvp515x_query_current_std(subdev);
>>>>> +     if (tvp5150->std_idx == STD_INVALID) {
>>>>> +             v4l2_err(subdev, "Unable to query std\n");
>>>>> +             return 0;
>>>>
>>>> Isn't this an error?
>>>>
>>>
>>> Yes, I'll change to report the error to the caller.
>>>
>>>>> + * tvp515x_mbus_fmt_cap() - V4L2 decoder interface handler for try/s/g_mbus_fmt
>>>>
>>>> The name of the function is different.
>>>>
>>>
>>> Yes, I'll change that.
>>>
>>>>>  static const struct v4l2_subdev_video_ops tvp5150_video_ops = {
>>>>>       .s_routing = tvp5150_s_routing,
>>>>> +     .s_stream = tvp515x_s_stream,
>>>>> +     .enum_mbus_fmt = tvp515x_enum_mbus_fmt,
>>>>> +     .g_mbus_fmt = tvp515x_mbus_fmt,
>>>>> +     .try_mbus_fmt = tvp515x_mbus_fmt,
>>>>> +     .s_mbus_fmt = tvp515x_mbus_fmt,
>>>>> +     .g_parm = tvp515x_g_parm,
>>>>> +     .s_parm = tvp515x_s_parm,
>>>>> +     .s_std_output = tvp5150_s_std,
>>>>
>>>> Do we really need both video and pad format ops?
>>>>
>>>
>>> Good question, I don't know. Can this device be used as a standalone
>>> v4l2 device? Or is supposed to always be a part of a video streaming
>>> pipeline as a sub-device with a source pad? Sorry if my questions are
>>> silly but as I stated before, I'm a newbie with v4l2 and MCF.
>>
>> The tvp5150 driver is used on some em28xx devices. It is nice to add auto-detection
>> code to the driver, but converting it to the media bus should be done with
>> enough care to not break support for the existing devices.
> 
> So in other words, the tvp5150 driver needs both pad and non-pad ops.
> Eventually all non-pad variants in subdev drivers should be replaced by the
> pad variants so you don't have duplication of ops. But that will take a lot
> more work.
> 
>> Also, as I've argued with Laurent before, the expected behavior is that the standards
>> format selection should be done via the video node, and not via the media 
>> controller node. The V4L2 API has enough support for all you need to do with the
>> video decoder, so there's no excuse to duplicate it with any other API.
> 
> This is relevant for bridge drivers, not for subdev drivers.
> 
>> The media controller API is there not to replace V4L2, but to complement
>> it where needed.
> 
> That will be a nice discussion during the workshop :-)
> 
>> In the specific code of standards auto-detection, a few drivers currently support
>> this feature. They're (or should be) coded to do is:
>>
>> If V4L2_STD_ALL is used, the driver should autodetect the video standard of the
>> currently tuned channel.
> 
> Actually, this is optional. As per the spec:
> 
> "When the standard set is ambiguous drivers may return EINVAL or choose any of
> the requested standards."

Yes. The entire auto-detection thing is optional. Several devices aren't capable of
auto-detecting standards. Btw, userspace support for standards auto-detection is
another chapter. I don't think they implement standards auto-detection.

There are even some applications (qv4l2 and tvtime, for example) that aren't capable of 
refreshing the maximum height when the standard changes.

> Nor does the spec say anything about doing an autodetect when STD_ALL is passed
> in. Most drivers will just set the std to PAL or NTSC in this case.

Auto-detection is device specific. That's why most applications don't handle it 
well (or don't even care on trying to do it). Btw, I did some tests with autodetection
on a device with a saa7115, and I found some bugs. Just sent a fix for it.

> If you want to autodetect, then use QUERYSTD. Applications cannot rely on drivers
> to handle V4L2_STD_ALL the way you say.
> 
>> The detected standard can be returned to userspace via VIDIOC_G_STD.
> 
> No! G_STD always returns the current *selected* standard. Only QUERYSTD returns
> the detected standard.

Yes, you're right. I should not try to answer emails when I'm lazy enough to not
look in to the code ;)

Anyway, the thing is that V4L2 API has enough support for auto-detection. There's
no need to duplicate stuff with MC API.

Regards,
Mauro

  parent reply	other threads:[~2011-10-03 18:54 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-01  0:33 [PATCH 0/3] [media] tvp5150: Migrate to media-controller framework and add video format detection Javier Martinez Canillas
2011-10-01  0:33 ` [PATCH 1/3] [media] tvp5150: Add constants for PAL and NTSC video standards Javier Martinez Canillas
2011-10-01  0:33 ` [PATCH 2/3] [media] tvp5150: Add video format registers configuration values Javier Martinez Canillas
2011-10-01  0:33 ` [PATCH 3/3] [media] tvp5150: Migrate to media-controller framework and add video format detection Javier Martinez Canillas
2011-10-02 16:30   ` Sakari Ailus
2011-10-02 21:18     ` Javier Martinez Canillas
2011-10-03  2:17       ` Mauro Carvalho Chehab
2011-10-03  6:30         ` Hans Verkuil
2011-10-03  7:11           ` Javier Martinez Canillas
2011-10-03 18:58             ` Mauro Carvalho Chehab
2011-10-03  8:39           ` Laurent Pinchart
2011-10-03  9:53             ` Javier Martinez Canillas
2011-10-03 11:53               ` Laurent Pinchart
2011-10-03 19:16                 ` Mauro Carvalho Chehab
2011-10-03 21:44                   ` Laurent Pinchart
2011-10-03 21:56                     ` Mauro Carvalho Chehab
2011-10-03 22:37                       ` Javier Martinez Canillas
2011-10-04  5:31                         ` Mauro Carvalho Chehab
2011-10-04  7:03                           ` Hans Verkuil
2011-10-04 10:35                             ` Mauro Carvalho Chehab
2011-10-05 20:54                             ` Laurent Pinchart
2011-10-05 21:48                               ` Mauro Carvalho Chehab
2011-10-05 22:30                                 ` Javier Martinez Canillas
2011-10-04  7:34                           ` Javier Martinez Canillas
2011-10-05 20:21                         ` Laurent Pinchart
2011-10-05 20:08                       ` Laurent Pinchart
2011-10-05 21:41                         ` Mauro Carvalho Chehab
2011-10-05 23:14                           ` Sakari Ailus
2011-10-06  0:32                             ` Mauro Carvalho Chehab
2011-10-06  7:09                               ` Hans Verkuil
2011-10-06  7:23                                 ` Hans Verkuil
2011-10-06 11:51                                   ` Mauro Carvalho Chehab
2011-10-06 12:06                                     ` Hans Verkuil
2011-10-06 13:13                                       ` Mauro Carvalho Chehab
2011-10-06 13:31                                       ` Sylwester Nawrocki
2011-10-03 19:06               ` Mauro Carvalho Chehab
2011-10-03 21:39                 ` Laurent Pinchart
2011-10-05 23:20                   ` Sakari Ailus
2011-10-03 18:53           ` Mauro Carvalho Chehab [this message]
2011-10-03 19:01             ` Sakari Ailus
2011-10-03 19:36               ` Mauro Carvalho Chehab
2011-10-05 23:41                 ` Sakari Ailus
2011-10-06  1:41                   ` Mauro Carvalho Chehab
2011-10-06 12:02                     ` Laurent Pinchart
2011-10-03 10:26       ` Sakari Ailus
2011-10-01 13:34 ` [PATCH 0/3] " Gary Thomas
2011-10-01 15:55   ` Javier Martinez Canillas
2011-10-01 16:39     ` Enrico
2011-10-01 17:27       ` Javier Martinez Canillas
2011-10-01 17:46         ` Enrico
2011-10-02 13:08           ` Javier Martinez Canillas
2011-10-03 10:33       ` Gary Thomas

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=4E8A04C2.5000508@infradead.org \
    --to=mchehab@infradead.org \
    --cc=ebutera@users.berlios.de \
    --cc=gary@mlbassoc.com \
    --cc=hverkuil@xs4all.nl \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=martinez.javier@gmail.com \
    --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