Mailing List Archive

MythTV Ticket 9191 (Re: cx18: problems changing channel in MythTV)
On Sat, 2010-11-13 at 15:06 -0500, Andy Walls wrote:
> On Sat, 2010-11-13 at 16:59 +0200, Artem Astafyev wrote:
> > Hi All,

> > 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.

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.

Hope that helps.

Regards,
Andy


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

You are right. I've checked 0.23.1 tree and it has the same code in
lib/libmythtv/mpegrecorder.cpp.
It seems that we have driver name 'cx18' for cx18-based cards and we
need special case for (driver == "cx18").
I changed
has_buggy_vbi = requires_special_pause = false;
to
has_buggy_vbi = requires_special_pause = true;
and now channel switching works fine.
But now I have another problem :) After switching channel I have
distorted picture. It looks like b/w picture with vertical RGB lines.
Also there is no sound, only noise. As tuning was fine this channel
become default. If I restart LiveTV it looks fine. Below is usecase:
1. Default channel 1.
2. Start LiveTV. Tuning to default channel 1. Picture and sound fine.
3. Switch to channel 2. Tuning fine, but picture distorted, noise.
4. Channel 2 become default.
5. Stop LiveTV. Start LiveTV. Tuning to default channel 2. Picture and
sound fine.
6. Switch to channel 1. Tuning fine, but picture distorted, noise.
7. Swicth any channel. Tuning fine, but picture distorted, noise.
So I can get normal picture and sound only after LiveTV restart.
It looks like there is some issue with mpeg encoder restart.

>> >  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.
>
> 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.

Thanks,
Artem Astafyev

_______________________________________________
ivtv-devel mailing list
ivtv-devel@ivtvdriver.org
http://ivtvdriver.org/mailman/listinfo/ivtv-devel
Re: MythTV Ticket 9191 (Re: cx18: problems changing channel in MythTV) [ In reply to ]
On Sun, 2010-11-14 at 20:08 +0200, Artem Astafyev wrote:
> Andy,
>
> You are right. I've checked 0.23.1 tree and it has the same code in
> lib/libmythtv/mpegrecorder.cpp.
> It seems that we have driver name 'cx18' for cx18-based cards and we
> need special case for (driver == "cx18").
> I changed
> has_buggy_vbi = requires_special_pause = false;
> to
> has_buggy_vbi = requires_special_pause = true;
> and now channel switching works fine.
> But now I have another problem :) After switching channel I have
> distorted picture. It looks like b/w picture with vertical RGB lines.
> Also there is no sound, only noise. As tuning was fine this channel
> become default. If I restart LiveTV it looks fine. Below is usecase:
> 1. Default channel 1.
> 2. Start LiveTV. Tuning to default channel 1. Picture and sound fine.
> 3. Switch to channel 2. Tuning fine, but picture distorted, noise.
> 4. Channel 2 become default.
> 5. Stop LiveTV. Start LiveTV. Tuning to default channel 2. Picture and
> sound fine.
> 6. Switch to channel 1. Tuning fine, but picture distorted, noise.
> 7. Swicth any channel. Tuning fine, but picture distorted, noise.
> So I can get normal picture and sound only after LiveTV restart.
> It looks like there is some issue with mpeg encoder restart.

Hmmm....

cx18_v4l2_ioctl()
mutex_lock(&cx->serialize_lock)
video_ioctl2()
cx18_encoder_cmd(..., .. V4L2_ENC_CMD_STOP)
cx18_stop_capture()
cx18_stop_v4l2_encode_stream()
cx18_vapi(..., CX18_CPU_CAPTURE_STOP, ...)
cx18_vapi(..., CX18_CPU_DE_RELEASE_MDL, ...)
^^^ tell firmware to give back all buffers
cx18_vapi(..., CX18_DESTROY_TASK, ...)
cx18_release_stream()
cx18_flush_queues()
cx18_queue_flush(..., &s->q_busy, &s->q_free)
cx18_queue_flush(..., &s->q_full, &s->q_free)
^^^ move the MDLs to q_free
^^^ The above steps are also done for the IDX and/or VBI streams if needed
mutex_unlock(&cx->serialize_lock)


cx18_v4l2_ioctl()
mutex_lock(&cx->serialize_lock)
video_ioctl2()
cx18_encoder_cmd(..., .. V4L2_ENC_CMD_START)
cx18_start_capture()
cx18_start_v4l2_encode_stream()
cx18_vapi(..., CX18_CREATE_TASK, ...)
cx18_vapi(..., CX18_CPU_SET_CHANNEL_TYPE, ...)
cx18_vapi() ... more calls to set up the encoder
cx18_vbi_setup()
(set up A/V decoder and make a cx18_vapi() call)
cx18_vapi_result(..., CX18_CPU_SET_INDEXTABLE, ...)
cx2341x_update()
(even more cx18_vapi() calls to set up encoder)
cx18_api(..., CX18_CPU_DE_SET_MDL_ACK, ...)
cx18_stream_configure_mdls()
cx18_unload_queues()
cx18_queue_flush(..., &s->q_busy, q_idle)
cx18_queue_flush(..., &s->q_full, q_idle)
cx18_queue_flush(..., &s->q_free, q_idle)
move all buffers back to the buffer pool
cx18_load_queues()
reload usable MDLs/buffers back to q_free
_cx18_stream_load_fw_queue()
iteratively pop an MDL off of q_free
_cx18_stream_put_mdl_fw()
put the MDL on q_busy
sync the memory for device DMA
cx18_vapi(..., CX18_CPU_DE_SET_MDL, ...)
cx18_vapi(..., CX18_CPU_CAPTURE_START, ...)
^^^ Repeat the above steps for the IDX or VBI stream, if needed
mutex_unlock(&cx->serialize_lock)

I was going to guess it is a race or a bug involving
cx18_unload_queues(). But now I'm not so sure, since the
&cx->serialize_lock is held.


You probably should set the "debug=" module parameter to the cx18 and
see if you see any races in the log. You'll want to turn on the high
volume, mailbox, dma, ioctl, warn, and info debug flags.
See /sbin/modinfo cx18 .

Or you might just want to add a 3 second delay before libmythtv calls
VIDIOC_ENC_CMD, V4L2_ENC_CMD_START and see if that makes the problem go
away. That would indicate a race in the cx18 driver or firmware if the
problem does go away.

Regards,
Andy

> Thanks,
> Artem Astafyev



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

I'll try debugging a bit later but I have some additional info that
may help. I made changes that Danielk suggested: modified line 454 of
mpegencoder.cpp in such way
ok = SetV4L2DeviceOptions(chanfd);" to "(void) SetV4L2DeviceOptions(chanfd);

This works without requires_special_pause = true. And picture is not
distorted! With this fix all works as expected. The only little
inconvenience is that I can see all that garbage during channel
switches.

2010/11/14 Andy Walls <awalls@md.metrocast.net>:
> You probably should set the "debug=" module parameter to the cx18 and
> see if you see any races in the log.  You'll want to turn on the high
> volume, mailbox, dma, ioctl, warn, and info debug flags.
> See /sbin/modinfo cx18 .
>
> Or you might just want to add a 3 second delay before libmythtv calls
> VIDIOC_ENC_CMD, V4L2_ENC_CMD_START and see if that makes the problem go
> away.  That would indicate a race in the cx18 driver or firmware if the
> problem does go away.

Thanks,
Artem Astafyev

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