Mailing List Archive

cx18: problems changing channel in MythTV
Hi All,

I'm testing a new card GoTView PCI DVD3 with patch Alexey Chernov
provided recently. I have problem changing channel in MythTV but it
seems that it's not because of this patch. The problem is that cx18
driver rejects standard changing if there are some active analog
streams. I filed ticket in MythTV trac
http://svn.mythtv.org/trac/ticket/9191. Could somebody take a look at
it?
I wonder if it's possible to stop streams on standard change? That
would solve the problem.

_______________________________________________
ivtv-devel mailing list
ivtv-devel@ivtvdriver.org
http://ivtvdriver.org/mailman/listinfo/ivtv-devel
Re: cx18: problems changing channel in MythTV [ In reply to ]
On Sat, 2010-11-13 at 16:59 +0200, Artem Astafyev wrote:
> Hi All,

Hi.

> I'm testing a new card GoTView PCI DVD3 with patch Alexey Chernov
> provided recently. I have problem changing channel in MythTV but it
> seems that it's not because of this patch. The problem is that cx18
> driver rejects standard changing if there are some active analog
> streams.

That is valid behavior per the V4L2 API:

http://linuxtv.org/downloads/v4l-dvb-apis/vidioc-g-std.html

the driver is allowed to return an errno of EBUSY when it is busy.

That check exists, because it is not possible to change the capture and
MPEG encoding engine between a 525 line standard (NTSC), 625 line
stanadrd (PAL, SECAM), or audio only (FM radio) capture in mid-stream.

Note, the CX23415/6/7/8 chips can only handle one incoming analog video
and audio source at a time.

> I filed ticket in MythTV trac
> http://svn.mythtv.org/trac/ticket/9191. Could somebody take a look at
> it?

Since at least Apr 27, 2007, when ivtv went into the mainline kernel,
ivtv has always returned EBUSY for this case. cx18 has always returned
EBUSY for this case as well.

Unless MythTV doesn't call close() once on the MPEG stream's file handle
before trying to switch standards, I suspect the MythTV devs will close
it without action. MythTV needs to close() the MPEG file descriptor, if
trying to switch standards on ivtv and cx18 type devices.

BTW, VIDIOC_STREAMOFF is only supported for Streaming I/O methods. The
cx18 driver only supports the read() method. Calling close() once on
all *active* analog capture stream (MPEG, YUV/HM12, PCM, and/or VBI)
file descriptors is required to free up the CX23418's encoding engine.

http://linuxtv.org/downloads/v4l-dvb-apis/func-close.html


> I wonder if it's possible to stop streams on standard change? That
> would solve the problem.

The application, i.e. MythTV, needs to be the one to do that. Also note
that if you are using the cx18-alsa.ko module, pulseaudio *may* have the
PCM analog stream open.

There really is only one analog video and audio stream being processed
by the CX23418 chip. You can get it in multiple output formats - MPEG,
YUV/HM12, PCM audio only - at the same time, but it's still the same
video and audio stream.

The cx18 driver automatically closing all analog streams (MPEG,
YUV/HM12, PCM, VBI) when someone calls a VIDIOC_S_STD ioctl() on a
device node would be considered a non-compliance with the V4L2 API. I'm
not sure it would be a desirable feature either.

I hope that helps.

Regards,
Andy


_______________________________________________
ivtv-devel mailing list
ivtv-devel@ivtvdriver.org
http://ivtvdriver.org/mailman/listinfo/ivtv-devel
Re: cx18: problems changing channel in MythTV [ In reply to ]
Andy,

Thanks for your quick and exhaustive response. I really appreciate it.
Now I know that problem is in the way how MythTV does standard switch
on ivtv-cards.
I'll copy your answer in comment to MythTV bugreport.

> There really is only one analog video and audio stream being processed
> by the CX23418 chip.  You can get it in multiple output formats - MPEG,
> YUV/HM12, PCM audio only - at the same time, but it's still the same
> video and audio stream.
>
> The cx18 driver automatically closing all analog streams (MPEG,
> YUV/HM12, PCM, VBI) when someone calls a VIDIOC_S_STD ioctl() on a
> device node would be considered a non-compliance with the V4L2 API.  I'm
> not sure it would be a desirable feature either.

Thanks,
Artem

_______________________________________________
ivtv-devel mailing list
ivtv-devel@ivtvdriver.org
http://ivtvdriver.org/mailman/listinfo/ivtv-devel
Re: cx18: problems changing channel in MythTV [ In reply to ]
On Sat, 2010-11-13 at 17:23 -0500, Devin Heitmueller wrote:
> On Sat, Nov 13, 2010 at 3:06 PM, Andy Walls <awalls@md.metrocast.net> wrote:
> > On Sat, 2010-11-13 at 16:59 +0200, Artem Astafyev wrote:
> >> Hi All,
> >
> > Hi.
> >
> >> I'm testing a new card GoTView PCI DVD3 with patch Alexey Chernov
> >> provided recently. I have problem changing channel in MythTV but it
> >> seems that it's not because of this patch. The problem is that cx18
> >> driver rejects standard changing if there are some active analog
> >> streams.
> >
> > That is valid behavior per the V4L2 API:
> >
> > http://linuxtv.org/downloads/v4l-dvb-apis/vidioc-g-std.html
> >
> > the driver is allowed to return an errno of EBUSY when it is busy.
> >
> > That check exists, because it is not possible to change the capture and
> > MPEG encoding engine between a 525 line standard (NTSC), 625 line
> > stanadrd (PAL, SECAM), or audio only (FM radio) capture in mid-stream.
>
> Wow, so the only way to change channels is to close and reopen all
> descriptors pointing to the device? Ouch.

No, there is another way to stop the stream, that MythTV actually uses
for ivtv:

VIDIOC_ENC_CMD with V4L2_ENC_CMD_STOP

but that is marked as "experimental" in the API document. close() is
not "experimental". ;)

> I don't doubt that's how the cx18 works, but it's kind of a bitch for
> application developers, especially since we have other drivers which
> will put the tuner to sleep on v4l close (requiring a firmware reload
> when it gets woken up).

VIDIOC_STREAMOFF should be usable for drivers using the streaming IO
method. MythTV does that too.


> I guess it's less surprising to me now that the MythTV codebase is
> littered with checks based on the driver and version it is interacting
> with.

MythTV should be looking at the capabilities flags being sent from the
driver in response to VIDIOC_G_CAPABILITES (or whatever the call is).

But I'll wager a $1 that those are inconsistent across all drivers.

> There's got to be a less dumb way to deal with this issue. I can
> understand the goal behind not allowing the user to change the
> standard in the middle of streaming (returning EBUSY), but there
> really should be some way to accomplish this without having to have
> the application close all the filehandles

No all filehandles. MythTV actually keeps two filehandles open on the
same device node: one for control ioctl()s and one for read()s. It only
would need to close and reopen 1 of them. Or use VIDIOC_ENC_CMD_STOP as
it currently does for ivtv.


> (and in some cases this
> isn't even practical - think of users who run something like mplayer
> to view the video and ZVBI to get captions).

Changing the analog TV standard while the capture unit is pumping data
along is what is not allowed. Changing the tuner channel does not mean
you have to stop the user space app caturing VBI to switch the tuner
channel on mplayer. If you're swithcing from SECAM-D/K to PAL-B/G (both
625 line/50 Hz) then yes, you need to stop your both the MPEG and VBI
streams.

Having the a driver automatically kill the VBI stream when the MPEG
stream stopped would be an anti-feature however. People (i.e. me) do
sometimes just capture VBI, but occasionally start and stop the video
program to check it. The driver can't know what's going on in userspace
in every use case. EBUSY indicates the device is in use, user and/or
userspce needs to stop what is keeping the driver busy.


> I guess this is less of an issue for those devices that let you
> explicitly stop streaming, although I realize that interface is
> typically associated with the "streaming" interface as opposed to the
> read() interface.

Yes, the read() interface is pretty basic.

Regards,
Andy

> Devin
>



_______________________________________________
ivtv-devel mailing list
ivtv-devel@ivtvdriver.org
http://ivtvdriver.org/mailman/listinfo/ivtv-devel
Re: cx18: problems changing channel in MythTV [ In reply to ]
On Sat, 2010-11-13 at 16:52 -0500, Andy Walls wrote:
> On Sat, 2010-11-13 at 17:23 -0500, Devin Heitmueller wrote:
> > On Sat, Nov 13, 2010 at 3:06 PM, Andy Walls <awalls@md.metrocast.net> wrote:
> >
> > There's got to be a less dumb way to deal with this issue. I can
> > understand the goal behind not allowing the user to change the
> > standard in the middle of streaming (returning EBUSY), but there
> > really should be some way to accomplish this without having to have
> > the application close all the filehandles
>
> No all filehandles. MythTV actually keeps two filehandles open on the
> same device node: one for control ioctl()s and one for read()s. It only
> would need to close and reopen 1 of them. Or use VIDIOC_ENC_CMD_STOP as
> it currently does for ivtv.

Typo. That should be "Not all filehandles".



> Having the a driver automatically kill the VBI stream when the MPEG
> stream stopped would be an anti-feature however. People (i.e. me) do
> sometimes just capture VBI, but occasionally start and stop the video
> program to check it. The driver can't know what's going on in userspace
> in every use case. EBUSY indicates the device is in use, user and/or
> userspce needs to stop what is keeping the driver busy.

I should clarify that I can only do that with the ivtv cards. The
CX23418 firmware stalls the VBI data stream when a video data stream is
not active as well. (Well, actually it transfers the first 4 buffers of
VBI data and then stops.)

Regards,
Andy


_______________________________________________
ivtv-devel mailing list
ivtv-devel@ivtvdriver.org
http://ivtvdriver.org/mailman/listinfo/ivtv-devel
Re: cx18: problems changing channel in MythTV [ In reply to ]
On Sat, Nov 13, 2010 at 3:06 PM, Andy Walls <awalls@md.metrocast.net> wrote:
> On Sat, 2010-11-13 at 16:59 +0200, Artem Astafyev wrote:
>> Hi All,
>
> Hi.
>
>> I'm testing a new card GoTView PCI DVD3 with patch Alexey Chernov
>> provided recently. I have problem changing channel in MythTV but it
>> seems that it's not because of this patch. The problem is that cx18
>> driver rejects standard changing if there are some active analog
>> streams.
>
> That is valid behavior per the V4L2 API:
>
> http://linuxtv.org/downloads/v4l-dvb-apis/vidioc-g-std.html
>
> the driver is allowed to return an errno of EBUSY when it is busy.
>
> That check exists, because it is not possible to change the capture and
> MPEG encoding engine between a 525 line standard (NTSC), 625 line
> stanadrd (PAL, SECAM), or audio only (FM radio) capture in mid-stream.

Wow, so the only way to change channels is to close and reopen all
descriptors pointing to the device? Ouch.

I don't doubt that's how the cx18 works, but it's kind of a bitch for
application developers, especially since we have other drivers which
will put the tuner to sleep on v4l close (requiring a firmware reload
when it gets woken up).

I guess it's less surprising to me now that the MythTV codebase is
littered with checks based on the driver and version it is interacting
with.

There's got to be a less dumb way to deal with this issue. I can
understand the goal behind not allowing the user to change the
standard in the middle of streaming (returning EBUSY), but there
really should be some way to accomplish this without having to have
the application close all the filehandles (and in some cases this
isn't even practical - think of users who run something like mplayer
to view the video and ZVBI to get captions).

I guess this is less of an issue for those devices that let you
explicitly stop streaming, although I realize that interface is
typically associated with the "streaming" interface as opposed to the
read() interface.

Devin

--
Devin J. Heitmueller - Kernel Labs
http://www.kernellabs.com

_______________________________________________
ivtv-devel mailing list
ivtv-devel@ivtvdriver.org
http://ivtvdriver.org/mailman/listinfo/ivtv-devel
Re: cx18: problems changing channel in MythTV [ In reply to ]
Hi everybody,

just a few comments from an application developer :-)


> From: Andy Walls <awalls@md.metrocast.net>

> That is valid behavior per the V4L2 API:
> http://linuxtv.org/downloads/v4l-dvb-apis/vidioc-g-std.html
> the driver is allowed to return an errno of EBUSY when it is busy.

Unfortunately the API is not precise enough and allows different handling.
Can you imagine this with a DVB driver? No, once you have a driver for a DVB
card you can use the card with any DVB application.
But not so with analogue encoder cards: The application needs to know the
specialities of the driver.

> BTW, VIDIOC_STREAMOFF is only supported for Streaming I/O methods. The
> cx18 driver only supports the read() method. Calling close() once on
> all active analog capture stream (MPEG, YUV/HM12, PCM, and/or VBI)
> file descriptors is required to free up the CX23418's encoding engine.

But we can't close the device without stopping the read thread before.

> The cx18 driver automatically closing all analog streams (MPEG,
> YUV/HM12, PCM, VBI) when someone calls a VIDIOC_S_STD ioctl() on a
> device node would be considered a non-compliance with the V4L2 API. I'm
> not sure it would be a desirable feature either.

The cx88-blackbird driver (also cx2341x) internally calls an enoder stop
firmware command (CX2341X_ENC_STOP_CAPTURE) before changing frequency.
(But unfortunately, due to a driver bug, it never starts the encoder again...
but this is a different issue)

There are only a few cases where the driver returns EBUSY on channel switches.
It depends on a standard change, an input change and switch between radio/TV.
Instead of doing a lot of checks most applications (mythv and vdr plugin
pvrinput) will handle each channel switch equal.

So we have different methods for changing channels:

1. stop reading, close, re-open, set frequency/change input, start reading
2. use VIDIOC_STREAMOFF /VIDIOC_STREAMON (buggy at least for ivtv and pvrusb2)
3. use V4L2_ENC_CMD_STOP / V4L2_ENC_CMD_START if the driver supports these
ioctl (only ivtv, cx18 and hdpvr does)
4. call only VIDIOC_S_FREQUENCY and let the driver do all necessary (only
HVR1300/blackbird has this concept, but unfortunately the driver is so buggy
that using the encoder on this card is impossible)

I prefer the first method. This way all internal buffers are cleared, we
start on the new channel with an i-frame and have smooth channel switching
(like a DVB receiver) without any artefacts. So it is really **useful** to
stop read thread and encoder for channel switchings.

> Ah, I found the problem in MythTV 0.21 source code.
>
> Look at
>
> lib/libmythtv/mpegrecorder.cpp:MpegRecorder::OpenV4L2DeviceAsInput()
>
> if (CardUtil::GetV4LInfo(chanfd, card, driver, version))
> {
> if (driver == "ivtv")
> {
> usingv4l2 = (version >= IVTV_KERNEL_VERSION(0, 8, 0));
> has_v4l2_vbi = (version >= IVTV_KERNEL_VERSION(0, 3, 8));
> has_buggy_vbi = true;
> requires_special_pause =
> (version >= IVTV_KERNEL_VERSION(0, 10, 0));
> }
> else
> {
> VERBOSE(VB_IMPORTANT, "\n\nNot ivtv driver??\n\n");
> usingv4l2 = has_v4l2_vbi = true;
> has_buggy_vbi = requires_special_pause = false;
> }
> }
>
> Like all modern ivtv driver versions, I'm very confident all cx18 driver
> versions require
>
> requires_special_pause = true;
>
> to be set. Then libmythtv will send the VIDIOC_ENC_CMD,
> V4L2_ENC_CMD_STOP that is required. Although the above code snippet is
> from 0.21, I suspect it is still the same in 0.23.
>
> I'm not sure what "has_buggy_vbi" means and whether or not it needs to
> be set for the cx18 driver.

If I remember right, there is probably something wrong with vbi (closed
captions?) in the ivtv (and probably cx18) kernel driver. This is why some
mythtv guys still prefer the old standalone ivtv driver
see change in 02/2008:
http://svn.mythtv.org/trac/changeset/15734/trunk/mythtv/libs/libmythtv/mpegrecorder.cpp
"This also updates Hans' VBI bugs warning for ivtv drivers before 0.10.0 and
after 0.10.5 due to new VBI bugs in more recent ivtv drivers."

>
> VIDIOC_ENC_CMD with V4L2_ENC_CMD_STOP
>
> but that is marked as "experimental" in the API document. close() is
> not "experimental". ;)

They were experimental in 2007 when Hans Verkuil introduced them. But now they
should be a must for every mpeg encoder driver.

Greets,
Martin

_______________________________________________
ivtv-devel mailing list
ivtv-devel@ivtvdriver.org
http://ivtvdriver.org/mailman/listinfo/ivtv-devel
Re: cx18: problems changing channel in MythTV [ In reply to ]
On Sunday, November 14, 2010 11:14:54 Martin Dauskardt wrote:
> Hi everybody,
>
> just a few comments from an application developer :-)
>
>
> > From: Andy Walls <awalls@md.metrocast.net>
>
> > That is valid behavior per the V4L2 API:
> > http://linuxtv.org/downloads/v4l-dvb-apis/vidioc-g-std.html
> > the driver is allowed to return an errno of EBUSY when it is busy.
>
> Unfortunately the API is not precise enough and allows different handling.
> Can you imagine this with a DVB driver? No, once you have a driver for a DVB
> card you can use the card with any DVB application.
> But not so with analogue encoder cards: The application needs to know the
> specialities of the driver.

The problem here is that even though the spec clearly stated that drivers
may return EBUSY applications never heeded this warning. For a long time all
analog video drivers actually supported in hardware changing channels on the
fly, but then some drivers (ivtv) appeared where the hardware wasn't able to
handle that properly.

It might have been better if the spec had been written so that changing
channels on the fly would have been made impossible, but I'm sure that there
were already applications doing just that.

Part of the problem is simply that V4L has to cater to a far wider variety
of video hardware than DVB. By and large the creators of the V4L spec did a
pretty good job, but there are problems and this is one of them.

> > BTW, VIDIOC_STREAMOFF is only supported for Streaming I/O methods. The
> > cx18 driver only supports the read() method. Calling close() once on
> > all active analog capture stream (MPEG, YUV/HM12, PCM, and/or VBI)
> > file descriptors is required to free up the CX23418's encoding engine.
>
> But we can't close the device without stopping the read thread before.

I hope that once the videobuf2 framework is merged cx18 and possibly ivtv
can move over to videobuf2 as well. Although this may be wishful thinking
since it is a huge conversion job. But then cx18/ivtv would finally support
streaming I/O.

> > The cx18 driver automatically closing all analog streams (MPEG,
> > YUV/HM12, PCM, VBI) when someone calls a VIDIOC_S_STD ioctl() on a
> > device node would be considered a non-compliance with the V4L2 API. I'm
> > not sure it would be a desirable feature either.
>
> The cx88-blackbird driver (also cx2341x) internally calls an enoder stop
> firmware command (CX2341X_ENC_STOP_CAPTURE) before changing frequency.
> (But unfortunately, due to a driver bug, it never starts the encoder again...
> but this is a different issue)
>
> There are only a few cases where the driver returns EBUSY on channel switches.
> It depends on a standard change, an input change and switch between radio/TV.
> Instead of doing a lot of checks most applications (mythv and vdr plugin
> pvrinput) will handle each channel switch equal.
>
> So we have different methods for changing channels:
>
> 1. stop reading, close, re-open, set frequency/change input, start reading
> 2. use VIDIOC_STREAMOFF /VIDIOC_STREAMON (buggy at least for ivtv and pvrusb2)
> 3. use V4L2_ENC_CMD_STOP / V4L2_ENC_CMD_START if the driver supports these
> ioctl (only ivtv, cx18 and hdpvr does)
> 4. call only VIDIOC_S_FREQUENCY and let the driver do all necessary (only
> HVR1300/blackbird has this concept, but unfortunately the driver is so buggy
> that using the encoder on this card is impossible)
>
> I prefer the first method. This way all internal buffers are cleared, we
> start on the new channel with an i-frame and have smooth channel switching
> (like a DVB receiver) without any artefacts. So it is really **useful** to
> stop read thread and encoder for channel switchings.

I agree. The first method will work everywhere and always. The second method
is suspect due to videobuf bugs in the STREAMOFF implementation :-(
The third method works fine, but few drivers support it. If someone would be
willing to work on this, then it can be extended to all drivers that do MPEG.
The last method is probably not possible. It is not a good idea to stop and
restart as a side-effect of changing a channel since this will interrupt the
mpeg stream, and will cause issues with time stamping, etc.

>
> > Ah, I found the problem in MythTV 0.21 source code.
> >
> > Look at
> >
> > lib/libmythtv/mpegrecorder.cpp:MpegRecorder::OpenV4L2DeviceAsInput()
> >
> > if (CardUtil::GetV4LInfo(chanfd, card, driver, version))
> > {
> > if (driver == "ivtv")
> > {
> > usingv4l2 = (version >= IVTV_KERNEL_VERSION(0, 8, 0));
> > has_v4l2_vbi = (version >= IVTV_KERNEL_VERSION(0, 3, 8));
> > has_buggy_vbi = true;
> > requires_special_pause =
> > (version >= IVTV_KERNEL_VERSION(0, 10, 0));
> > }
> > else
> > {
> > VERBOSE(VB_IMPORTANT, "\n\nNot ivtv driver??\n\n");
> > usingv4l2 = has_v4l2_vbi = true;
> > has_buggy_vbi = requires_special_pause = false;
> > }
> > }
> >
> > Like all modern ivtv driver versions, I'm very confident all cx18 driver
> > versions require
> >
> > requires_special_pause = true;
> >
> > to be set. Then libmythtv will send the VIDIOC_ENC_CMD,
> > V4L2_ENC_CMD_STOP that is required. Although the above code snippet is
> > from 0.21, I suspect it is still the same in 0.23.
> >
> > I'm not sure what "has_buggy_vbi" means and whether or not it needs to
> > be set for the cx18 driver.
>
> If I remember right, there is probably something wrong with vbi (closed
> captions?) in the ivtv (and probably cx18) kernel driver. This is why some
> mythtv guys still prefer the old standalone ivtv driver
> see change in 02/2008:
> http://svn.mythtv.org/trac/changeset/15734/trunk/mythtv/libs/libmythtv/mpegrecorder.cpp
> "This also updates Hans' VBI bugs warning for ivtv drivers before 0.10.0 and
> after 0.10.5 due to new VBI bugs in more recent ivtv drivers."

While there has been a period where vbi was broken in ivtv, that has been
fixed about 2 years ago (mid-2008).

> >
> > VIDIOC_ENC_CMD with V4L2_ENC_CMD_STOP
> >
> > but that is marked as "experimental" in the API document. close() is
> > not "experimental". ;)
>
> They were experimental in 2007 when Hans Verkuil introduced them. But now they
> should be a must for every mpeg encoder driver.

Yeah, it's time to scan the spec for 'experimental' and remove it where that is
no longer relevant.

Regards,

Hans

--
Hans Verkuil - video4linux developer - sponsored by Cisco

_______________________________________________
ivtv-devel mailing list
ivtv-devel@ivtvdriver.org
http://ivtvdriver.org/mailman/listinfo/ivtv-devel
Re: cx18: problems changing channel in MythTV [ In reply to ]
On Sun, 2010-11-14 at 11:14 +0100, Martin Dauskardt wrote:
> Hi everybody,
>
> just a few comments from an application developer :-)
>
>
> > From: Andy Walls <awalls@md.metrocast.net>
>
> > That is valid behavior per the V4L2 API:
> > http://linuxtv.org/downloads/v4l-dvb-apis/vidioc-g-std.html
> > the driver is allowed to return an errno of EBUSY when it is busy.
>
> Unfortunately the API is not precise enough and allows different handling.

I would certainly say in this case that the API provides *too many* ways
of stopping streams.

Every optional method an application writer and driver writer has of
performing an action is an opportunity for interoperability problems.



> Can you imagine this with a DVB driver? No, once you have a driver for a DVB
> card you can use the card with any DVB application.
> But not so with analogue encoder cards: The application needs to know the
> specialities of the driver.
>
> > BTW, VIDIOC_STREAMOFF is only supported for Streaming I/O methods. The
> > cx18 driver only supports the read() method. Calling close() once on
> > all active analog capture stream (MPEG, YUV/HM12, PCM, and/or VBI)
> > file descriptors is required to free up the CX23418's encoding engine.
>
> But we can't close the device without stopping the read thread before.

Correct, unless you don't mind the read thread receiving EBADF on the
next read(). :P


> > The cx18 driver automatically closing all analog streams (MPEG,
> > YUV/HM12, PCM, VBI) when someone calls a VIDIOC_S_STD ioctl() on a
> > device node would be considered a non-compliance with the V4L2 API. I'm
> > not sure it would be a desirable feature either.
>
> The cx88-blackbird driver (also cx2341x) internally calls an enoder stop
> firmware command (CX2341X_ENC_STOP_CAPTURE) before changing frequency.
> (But unfortunately, due to a driver bug, it never starts the encoder again...
> but this is a different issue)
>
> There are only a few cases where the driver returns EBUSY on channel switches.
> It depends on a standard change, an input change and switch between radio/TV.
> Instead of doing a lot of checks most applications (mythv and vdr plugin
> pvrinput) will handle each channel switch equal.

Yes, I was thinking of allowing 625/50 -> 625/50 and 525/60 -> 525/60
standards changes to happen without returning EBUSY, but that doesn't
cover every case, so applications still have to deal with EBUSY from
S_STD.


> So we have different methods for changing channels:
>
> 1. stop reading, close, re-open, set frequency/change input, start reading
> 2. use VIDIOC_STREAMOFF /VIDIOC_STREAMON (buggy at least for ivtv and pvrusb2)
> 3. use V4L2_ENC_CMD_STOP / V4L2_ENC_CMD_START if the driver supports these
> ioctl (only ivtv, cx18 and hdpvr does)
> 4. call only VIDIOC_S_FREQUENCY and let the driver do all necessary (only
> HVR1300/blackbird has this concept, but unfortunately the driver is so buggy
> that using the encoder on this card is impossible)
>
> I prefer the first method. This way all internal buffers are cleared, we
> start on the new channel with an i-frame and have smooth channel switching
> (like a DVB receiver) without any artefacts. So it is really **useful** to
> stop read thread and encoder for channel switchings.

Right. People will gravitate to the most reliable mechanism. Which is
a very good argument for getting rid of the mechanisms that don't always
work and cutting down on API complexity.

I'm thinking along tha same lines as Hans in getting rid of the read()
methiod as a primary I/O method for any driver. I was stalling until
videobuf2 was done.

VIDIOC_ENC_COMMAND should probably be discouraged for new
designs/implementations of both drivers and applications. Then we would
have one less "approved" way to start and stop the stream.


> > Ah, I found the problem in MythTV 0.21 source code.
> >
> > Look at
> >
> > lib/libmythtv/mpegrecorder.cpp:MpegRecorder::OpenV4L2DeviceAsInput()


> > I'm not sure what "has_buggy_vbi" means and whether or not it needs to
> > be set for the cx18 driver.

> If I remember right, there is probably something wrong with vbi (closed
> captions?) in the ivtv (and probably cx18) kernel driver. This is why some
> mythtv guys still prefer the old standalone ivtv driver
> see change in 02/2008:
> http://svn.mythtv.org/trac/changeset/15734/trunk/mythtv/libs/libmythtv/mpegrecorder.cpp
> "This also updates Hans' VBI bugs warning for ivtv drivers before 0.10.0 and
> after 0.10.5 due to new VBI bugs in more recent ivtv drivers."

So the has_buggy_vbi flag comment really refers to old ivtv driver
versions, or modern ivtv driver versions only with the PVR-250 and
PVR-350.

Last time I checked the PVR-350 with a modern ivtv driver, zvbi worked
with /dev/vbi0 just fine. I'll have to check MythTV playback of PVR-350
MPEG streams with ivtv VBI packets.



> > VIDIOC_ENC_CMD with V4L2_ENC_CMD_STOP
> >
> > but that is marked as "experimental" in the API document. close() is
> > not "experimental". ;)
>
> They were experimental in 2007 when Hans Verkuil introduced them. But now they
> should be a must for every mpeg encoder driver.

They certainly should not be experimental anymore if MythTV has been
relying on them for 3 years.

Are there use cases for mandating their use in new driver
implementations, if the MPEG drivers are all converted to streaming I/O
methods so that VIDIOC_STREAMON/OFF are supported?

Regards,
Andy

> Greets,
> Martin



_______________________________________________
ivtv-devel mailing list
ivtv-devel@ivtvdriver.org
http://ivtvdriver.org/mailman/listinfo/ivtv-devel
Re: cx18: problems changing channel in MythTV [ In reply to ]
On Sun, 2010-11-14 at 11:53 +0100, Hans Verkuil wrote:
> On Sunday, November 14, 2010 11:14:54 Martin Dauskardt wrote:
> > Hi everybody,
> >
> > just a few comments from an application developer :-)
> >
> >
> > > From: Andy Walls <awalls@md.metrocast.net>
> >
> > > That is valid behavior per the V4L2 API:
> > > http://linuxtv.org/downloads/v4l-dvb-apis/vidioc-g-std.html
> > > the driver is allowed to return an errno of EBUSY when it is busy.
> >
> > Unfortunately the API is not precise enough and allows different handling.
> > Can you imagine this with a DVB driver? No, once you have a driver for a DVB
> > card you can use the card with any DVB application.
> > But not so with analogue encoder cards: The application needs to know the
> > specialities of the driver.
>
> The problem here is that even though the spec clearly stated that drivers
> may return EBUSY applications never heeded this warning.

MythTV does heed it and actually looks for EBUSY. The problem for
MythTV is what to do about it.

That's where all sorts of funny rules get implemented in the application
to accomplish the task. The funny rules come from the different methods
described in the API standard for stopping the stream.

If we can cut down on the options in the API for accomplishing the same
action, then there are less chances for interoperability problems
between applications and drivers. Application programming becomes
simpler.

Hypothetically, even if the only action for stopping a stream was to
close the device and reopen it, that would be unambiguous and
straightforward for application developers. (Although that option alone
is somewhat inelegant.)

I'm all for converting the read() method drivers to videobuf2, and
making the read() method a secondary way of accessing video streams.



> I hope that once the videobuf2 framework is merged cx18 and possibly ivtv
> can move over to videobuf2 as well. Although this may be wishful thinking
> since it is a huge conversion job. But then cx18/ivtv would finally support
> streaming I/O.

It may not be so wishful for cx18. I'll need some time to grok the ivtv
buffer handling. It's a little different. Then of course I'll need
free time... :)



> > > The cx18 driver automatically closing all analog streams (MPEG,
> > > YUV/HM12, PCM, VBI) when someone calls a VIDIOC_S_STD ioctl() on a
> > > device node would be considered a non-compliance with the V4L2 API. I'm
> > > not sure it would be a desirable feature either.
> >
> > The cx88-blackbird driver (also cx2341x) internally calls an enoder stop
> > firmware command (CX2341X_ENC_STOP_CAPTURE) before changing frequency.
> > (But unfortunately, due to a driver bug, it never starts the encoder again...
> > but this is a different issue)
> >
> > There are only a few cases where the driver returns EBUSY on channel switches.
> > It depends on a standard change, an input change and switch between radio/TV.
> > Instead of doing a lot of checks most applications (mythv and vdr plugin
> > pvrinput) will handle each channel switch equal.
> >
> > So we have different methods for changing channels:
> >
> > 1. stop reading, close, re-open, set frequency/change input, start reading
> > 2. use VIDIOC_STREAMOFF /VIDIOC_STREAMON (buggy at least for ivtv and pvrusb2)
> > 3. use V4L2_ENC_CMD_STOP / V4L2_ENC_CMD_START if the driver supports these
> > ioctl (only ivtv, cx18 and hdpvr does)
> > 4. call only VIDIOC_S_FREQUENCY and let the driver do all necessary (only
> > HVR1300/blackbird has this concept, but unfortunately the driver is so buggy
> > that using the encoder on this card is impossible)
> >
> > I prefer the first method. This way all internal buffers are cleared, we
> > start on the new channel with an i-frame and have smooth channel switching
> > (like a DVB receiver) without any artefacts. So it is really **useful** to
> > stop read thread and encoder for channel switchings.
>
> I agree. The first method will work everywhere and always. The second method
> is suspect due to videobuf bugs in the STREAMOFF implementation :-(


> The third method works fine, but few drivers support it.
> If someone would be
> willing to work on this, then it can be extended to all drivers that do MPEG.

If few drivers support it, I'd argue let's plan on keeping it's use
limited to old drivers. Time is probably better spent converting the
old drivers to use videobuf2.


> The last method is probably not possible.
> It is not a good idea to stop and
> restart as a side-effect of changing a channel since this will interrupt the
> mpeg stream, and will cause issues with time stamping, etc.

Agree.

> >
> > > Ah, I found the problem in MythTV 0.21 source code.
> > >
> > > Look at
> > >
> > > lib/libmythtv/mpegrecorder.cpp:MpegRecorder::OpenV4L2DeviceAsInput()
> > >
> > > if (CardUtil::GetV4LInfo(chanfd, card, driver, version))
> > > {
> > > if (driver == "ivtv")
> > > {
> > > usingv4l2 = (version >= IVTV_KERNEL_VERSION(0, 8, 0));
> > > has_v4l2_vbi = (version >= IVTV_KERNEL_VERSION(0, 3, 8));
> > > has_buggy_vbi = true;
> > > requires_special_pause =
> > > (version >= IVTV_KERNEL_VERSION(0, 10, 0));
> > > }
> > > else
> > > {
> > > VERBOSE(VB_IMPORTANT, "\n\nNot ivtv driver??\n\n");
> > > usingv4l2 = has_v4l2_vbi = true;
> > > has_buggy_vbi = requires_special_pause = false;
> > > }
> > > }
> > >
> > > Like all modern ivtv driver versions, I'm very confident all cx18 driver
> > > versions require
> > >
> > > requires_special_pause = true;
> > >
> > > to be set. Then libmythtv will send the VIDIOC_ENC_CMD,
> > > V4L2_ENC_CMD_STOP that is required. Although the above code snippet is
> > > from 0.21, I suspect it is still the same in 0.23.
> > >
> > > I'm not sure what "has_buggy_vbi" means and whether or not it needs to
> > > be set for the cx18 driver.
> >
> > If I remember right, there is probably something wrong with vbi (closed
> > captions?) in the ivtv (and probably cx18) kernel driver. This is why some
> > mythtv guys still prefer the old standalone ivtv driver
> > see change in 02/2008:
> > http://svn.mythtv.org/trac/changeset/15734/trunk/mythtv/libs/libmythtv/mpegrecorder.cpp
> > "This also updates Hans' VBI bugs warning for ivtv drivers before 0.10.0 and
> > after 0.10.5 due to new VBI bugs in more recent ivtv drivers."
>
> While there has been a period where vbi was broken in ivtv, that has been
> fixed about 2 years ago (mid-2008).

The outstanding question posed by the comments in the code is whether
PVR-250/350 VBI is working in modern ivtv drivers with MythTV.

I can test that sometime, when I get the time, but will gladly accept
reports of it working from anyone. ;)

> > > VIDIOC_ENC_CMD with V4L2_ENC_CMD_STOP
> > >
> > > but that is marked as "experimental" in the API document. close() is
> > > not "experimental". ;)
> >
> > They were experimental in 2007 when Hans Verkuil introduced them. But now they
> > should be a must for every mpeg encoder driver.
>
> Yeah, it's time to scan the spec for 'experimental' and remove it where that is
> no longer relevant.

Right, the VIDOIOC_ENC_CMD should not be "experimental" anymore. I
would suggest though that it be marked "not for use in new application
and driver designs". Probably also add a note to use close() instead of
V4L2_ENC_CMD_STOP for drivers that only support the read() I/O method.

Regards,
Andy


_______________________________________________
ivtv-devel mailing list
ivtv-devel@ivtvdriver.org
http://ivtvdriver.org/mailman/listinfo/ivtv-devel
Re: cx18: problems changing channel in MythTV [ In reply to ]
On Sunday, November 14, 2010 13:58:09 Andy Walls wrote:

<snip>

> > > > VIDIOC_ENC_CMD with V4L2_ENC_CMD_STOP
> > > >
> > > > but that is marked as "experimental" in the API document. close() is
> > > > not "experimental". ;)
> > >
> > > They were experimental in 2007 when Hans Verkuil introduced them. But now they
> > > should be a must for every mpeg encoder driver.
> >
> > Yeah, it's time to scan the spec for 'experimental' and remove it where that is
> > no longer relevant.
>
> Right, the VIDOIOC_ENC_CMD should not be "experimental" anymore. I
> would suggest though that it be marked "not for use in new application
> and driver designs". Probably also add a note to use close() instead of
> V4L2_ENC_CMD_STOP for drivers that only support the read() I/O method.

I disagree with that. V4L2_ENC_CMD_STOP is the only way you can stop at the
end of a GOP. It is a real shame that the cx18 firmware is buggy and doesn't
support that, since it works great with ivtv.

If you want to have full control over an encoder, then this ioctl is really
important.

The reason it isn't used more often is that there are few hardware encoders
anyway and in many drivers it was an afterthought to add mpeg encoder support
and so they omitted support for this ioctl. Both ivtv and cx18 have by far the
most complete coverage of the MPEG encoder functionality.

Regards,

Hans

--
Hans Verkuil - video4linux developer - sponsored by Cisco

_______________________________________________
ivtv-devel mailing list
ivtv-devel@ivtvdriver.org
http://ivtvdriver.org/mailman/listinfo/ivtv-devel