Mailing List Archive

cx18: Will the buffer be moving in to the driver?
Hi Andy,

My apologies for not getting back with the pci details, I've been away from
the hardware that has the problem for a few weeks (and using my other box).
I'm now getting back at it.

I wanted to followup on your suggestion that I use mplayer with a 16MB
buffer to play the stream if reading directly off /dev/video0.

While that works, I was curious if there are any plans, or if it is even
possible, to do some buffering on the driver side so that the resulting
native TS is more stable. VLC really chokes on it if you try and play it
directly, due to late picture and late sound.

Thanks,

-Jeff
Re: cx18: Will the buffer be moving in to the driver? [ In reply to ]
On Fri, 2008-10-31 at 15:46 -0400, Jeff Campbell wrote:
> Hi Andy,
>
> My apologies for not getting back with the pci details, I've been away
> from the hardware that has the problem for a few weeks (and using my
> other box). I'm now getting back at it.
>
> I wanted to followup on your suggestion that I use mplayer with a 16MB
> buffer to play the stream if reading directly off /dev/video0.
>
> While that works, I was curious if there are any plans, or if it is
> even possible, to do some buffering on the driver side so that the
> resulting native TS is more stable.

First what do you mean by native TS? Analog captures default to an MPEG
PS, but supposedly the chip can also be set to do a TS for analog
capture (I haven't tested it yet). Digital captures are just a
pass-through of the TS from another chip.

Well, I have some plans for buffers changes, but buffering up 8 or 16 MB
in kernel space wasn't one of them. The problem is one of non-uniform
rate of delivery of audio and video buffers, I think.

I don't know how to get the chip to transfer 1 video buffer per frame,
so the solution is to use smaller transfer buffers to get the chip to
hand them over sooner. The problem is the driver is simply written to
stay with in the buffer count limit of 63 buffers usable by the firmware
at any one time. Making the buffers smaller to smooth out transfers
while staying under 63 buffers makes for a very small overall buffer.

I plan to change the driver to manage more than 63 buffers per stream
and let the user control buffer sizes to meet their latency needs. But
right now I investigating some interrupt and mailbox problems to try to
resolve problems with simultaneous analog and digital capture.
Hopefully that will make things better too.



> VLC really chokes on it if you try and play it directly, due to late
> picture and late sound.

OK. I never tested VLC.

I've been away for the better part of two weeks, so I'm catching up on
things (home, family, and linux hobby) as I can.


Regards,
Andy

> Thanks,
>
> -Jeff



_______________________________________________
ivtv-devel mailing list
ivtv-devel@ivtvdriver.org
http://ivtvdriver.org/mailman/listinfo/ivtv-devel
Re: cx18: Will the buffer be moving in to the driver? [ In reply to ]
Welcome back Andy.

On Sat, Nov 1, 2008 at 8:54 AM, Andy Walls <awalls@radix.net> wrote:

> On Fri, 2008-10-31 at 15:46 -0400, Jeff Campbell wrote:
> > Hi Andy,
> >
> > My apologies for not getting back with the pci details, I've been away
> > from the hardware that has the problem for a few weeks (and using my
> > other box). I'm now getting back at it.
> >
> > I wanted to followup on your suggestion that I use mplayer with a 16MB
> > buffer to play the stream if reading directly off /dev/video0.
> >
> > While that works, I was curious if there are any plans, or if it is
> > even possible, to do some buffering on the driver side so that the
> > resulting native TS is more stable.
>
> First what do you mean by native TS? Analog captures default to an MPEG
> PS, but supposedly the chip can also be set to do a TS for analog
> capture (I haven't tested it yet). Digital captures are just a
> pass-through of the TS from another chip.
>

Let me give an update here. By setting the stream_type=1, you can get
native TS from the card/driver. This is something Hans added support for a
few months ago.

This does in fact work and I have successfully multicasted it and played it
back. It was generally watchable for test purposes but did suffer from the
jitter problem. Ultimately I ended up experiencing significant audio/video
sync issues (over time) with the audio falling multiple seconds behind the
video. The actual video frame rate seemed fine (my input source was a DVD
player) and the audio, as I recall, was good but suffered occasional
dropouts. I am looking in to a way to pre-buffer this before transmitting
it to try and smooth it out.

I have had some success adjusting buffer sizes on the client side that is
joining the multicast, but nothing conclusive yet due to various other
factors.

I am doing more testing tonight and will report any material findings. So
far I've had no audio and audio sync issues, but there are a lot of
variables in my test setup so I don't want to say its the card or driver
just yet.

I am going to build the latest version of the driver as well as a
2.6.27.4kernel later tonight to test against.



>
> Well, I have some plans for buffers changes, but buffering up 8 or 16 MB
> in kernel space wasn't one of them. The problem is one of non-uniform
> rate of delivery of audio and video buffers, I think.
>

Your description of non-uniform rate of deliver sounds correct and seems to
match the errors that I see in the messages window in the vlc client while
playing back a stream.


>
> I don't know how to get the chip to transfer 1 video buffer per frame,
> so the solution is to use smaller transfer buffers to get the chip to
> hand them over sooner. The problem is the driver is simply written to
> stay with in the buffer count limit of 63 buffers usable by the firmware
> at any one time. Making the buffers smaller to smooth out transfers
> while staying under 63 buffers makes for a very small overall buffer.
>
> I plan to change the driver to manage more than 63 buffers per stream
> and let the user control buffer sizes to meet their latency needs. But
> right now I investigating some interrupt and mailbox problems to try to
> resolve problems with simultaneous analog and digital capture.
> Hopefully that will make things better too.
>

We all appreciate your efforts. I'll try and do some more structured
testing and report back on what I find.

Great news about the pending improvements on simultaneous analog and digital
capture.


>
>
>
> > VLC really chokes on it if you try and play it directly, due to late
> > picture and late sound.
>
> OK. I never tested VLC.


I've been using 0.8.6 under linux but also install 0.9.4 under Vista today,
so I'll report anything that seems material.

-Jeff
Re: cx18: Will the buffer be moving in to the driver? [ In reply to ]
On Sat, 2008-11-01 at 18:36 -0400, Jeff Campbell wrote:
> Welcome back Andy.
>
> On Sat, Nov 1, 2008 at 8:54 AM, Andy Walls <awalls@radix.net> wrote:
> On Fri, 2008-10-31 at 15:46 -0400, Jeff Campbell wrote:

> Let me give an update here. By setting the stream_type=1, you can get
> native TS from the card/driver. This is something Hans added support
> for a few months ago.

Ah, thanks for the details. I knew he had, but I never tested.



> I have had some success adjusting buffer sizes on the client side that
> is joining the multicast, but nothing conclusive yet due to various
> other factors.
>
> I am doing more testing tonight and will report any material findings.
> So far I've had no audio and audio sync issues, but there are a lot of
> variables in my test setup so I don't want to say its the card or
> driver just yet.

Oh, I know the driver contributes. Audio can come up to a few seconds
ahead of the video. See below...


> I am going to build the latest version of the driver as well as a
> 2.6.27.4 kernel later tonight to test against.
>

Here is a patch I submitted but was rejected by the v4l-dvb maintainer:

http://linuxtv.org/hg/~awalls/v4l-dvb/rev/a81c3fdf53e8

It changes the buffer handling and some of the module parameter
semantics/units (which is why it was rejected) to allow a user to
specify arbitrary buffer sizes. Using individual MPEG buffer sizes
around 8k smoothed out the PS rather well. Occasional frames with very
small payload still jittered, but overall watchable without buffering.



> Well, I have some plans for buffers changes, but buffering up
> 8 or 16 MB
> in kernel space wasn't one of them. The problem is one of
> non-uniform
> rate of delivery of audio and video buffers, I think.
>
> Your description of non-uniform rate of deliver sounds correct and
> seems to match the errors that I see in the messages window in the vlc
> client while playing back a stream.
>

As I recall from watching mplayer's status line, the problem is the
audio gets ahead of the video. Watch the seconds of audio decoded (A:)
seconds of video decoded (V:) and the difference (A-V:) on the mplayer
line. You'll see that A-V: can get several seconds into the positive.




> Great news about the pending improvements on simultaneous analog and
> digital capture.

Many of the outstanding problems and my VBI problems seem to be related
to interrupts and the mailboxes. I'm hoping a few things get resolved
at once.



Regards,
Andy


_______________________________________________
ivtv-devel mailing list
ivtv-devel@ivtvdriver.org
http://ivtvdriver.org/mailman/listinfo/ivtv-devel
Re: cx18: Will the buffer be moving in to the driver? [ In reply to ]
On Sat, Nov 1, 2008 at 6:36 PM, Andy Walls <awalls@radix.net> wrote:

> On Sat, 2008-11-01 at 18:36 -0400, Jeff Campbell wrote:
> > Welcome back Andy.
> >
> > On Sat, Nov 1, 2008 at 8:54 AM, Andy Walls <awalls@radix.net> wrote:
> > On Fri, 2008-10-31 at 15:46 -0400, Jeff Campbell wrote:
>
> > Let me give an update here. By setting the stream_type=1, you can get
> > native TS from the card/driver. This is something Hans added support
> > for a few months ago.
>
> Ah, thanks for the details. I knew he had, but I never tested.
>
>
It appears to be much less watchable than the PS though. I'm going to stick
to working with the PS for now and circle back with the TS once that is
resolved.


>
> > I have had some success adjusting buffer sizes on the client side that
> > is joining the multicast, but nothing conclusive yet due to various
> > other factors.
> >
> > I am doing more testing tonight and will report any material findings.
> > So far I've had no audio and audio sync issues, but there are a lot of
> > variables in my test setup so I don't want to say its the card or
> > driver just yet.
>
> Oh, I know the driver contributes. Audio can come up to a few seconds
> ahead of the video. See below...
>
>
> > I am going to build the latest version of the driver as well as a
> > 2.6.27.4 kernel later tonight to test against.
> >
>
> Here is a patch I submitted but was rejected by the v4l-dvb maintainer:
>
> http://linuxtv.org/hg/~awalls/v4l-dvb/rev/a81c3fdf53e8<http://linuxtv.org/hg/%7Eawalls/v4l-dvb/rev/a81c3fdf53e8>
>
> It changes the buffer handling and some of the module parameter
> semantics/units (which is why it was rejected) to allow a user to
> specify arbitrary buffer sizes. Using individual MPEG buffer sizes
> around 8k smoothed out the PS rather well. Occasional frames with very
> small payload still jittered, but overall watchable without buffering.
>
>
Do you happen to have the syntax for the buffer settings on insert or from
module.options that I could copy? I'm going to try this tonight.

-Jeff
Re: cx18: Will the buffer be moving in to the driver? [ In reply to ]
On Mon, 2008-11-03 at 17:00 -0500, Jeff Campbell wrote:
>
>
> On Sat, Nov 1, 2008 at 6:36 PM, Andy Walls <awalls@radix.net> wrote:
> On Sat, 2008-11-01 at 18:36 -0400, Jeff Campbell wrote:

> Here is a patch I submitted but was rejected by the v4l-dvb
> maintainer:
>
> http://linuxtv.org/hg/~awalls/v4l-dvb/rev/a81c3fdf53e8
>
> It changes the buffer handling and some of the module
> parameter
> semantics/units (which is why it was rejected) to allow a user
> to
> specify arbitrary buffer sizes. Using individual MPEG buffer
> sizes
> around 8k smoothed out the PS rather well. Occasional frames
> with very
> small payload still jittered, but overall watchable without
> buffering.
>
>
>
> Do you happen to have the syntax for the buffer settings on insert or
> from module.options that I could copy? I'm going to try this tonight.
>

With the patch applied and the module installed under /lib/modules/.....

# modprobe -r cx18
# modinfo cx18
# modprobe cx18 enc_mpg_bufsize=8 enc_mpg_bufs=63

63 buffers of 8 kB each. Not a lot of buffer depth, but with the
default buffer size (of 32 kB IIRC) you didn't get very deep buffer
usage anyway. I've only observed 11 buffers x 32 kB as a maximum burst
from the chip when MythTV or mplayer couldn't keep up.


-Andy


_______________________________________________
ivtv-devel mailing list
ivtv-devel@ivtvdriver.org
http://ivtvdriver.org/mailman/listinfo/ivtv-devel
Re: cx18: Will the buffer be moving in to the driver? [ In reply to ]
>
> With the patch applied and the module installed under /lib/modules/.....
>
> # modprobe -r cx18
> # modinfo cx18
> # modprobe cx18 enc_mpg_bufsize=8 enc_mpg_bufs=63
>
> 63 buffers of 8 kB each. Not a lot of buffer depth, but with the
> default buffer size (of 32 kB IIRC) you didn't get very deep buffer
> usage anyway. I've only observed 11 buffers x 32 kB as a maximum burst
> from the chip when MythTV or mplayer couldn't keep up.
>

Hi Andy,

I got your patch compiled and loaded.

My audio dropouts when watching the multicast via vlc are still about 1 per
every second or so, but the number of complaints in the vlc messages window
is way down, so it definitely has made an improvement but there is a still a
material issue.

I'd like to help, is there any testing I can do and document to be of
assistance?

-Jeff
Re: cx18: Will the buffer be moving in to the driver? [ In reply to ]
On Tue, Nov 4, 2008 at 12:54 AM, Jeff Campbell <jac1dlists@gmail.com> wrote:

> With the patch applied and the module installed under /lib/modules/.....
>>
>> # modprobe -r cx18
>> # modinfo cx18
>> # modprobe cx18 enc_mpg_bufsize=8 enc_mpg_bufs=63
>>
>> 63 buffers of 8 kB each. Not a lot of buffer depth, but with the
>> default buffer size (of 32 kB IIRC) you didn't get very deep buffer
>> usage anyway. I've only observed 11 buffers x 32 kB as a maximum burst
>> from the chip when MythTV or mplayer couldn't keep up.
>>
>
> Hi Andy,
>
> I got your patch compiled and loaded.
>
> My audio dropouts when watching the multicast via vlc are still about 1 per
> every second or so, but the number of complaints in the vlc messages window
> is way down, so it definitely has made an improvement but there is a still a
> material issue.
>
> I'd like to help, is there any testing I can do and document to be of
> assistance?
>
> -Jeff
>

I have installed mplayer from the debian multimedia repos and have tried
your suggestion of the -cache 16348 option. For various reasons I can't
play video on the machine right now (it is console only) but I can listen to
the audio jack so I did

# mplayer -cache 16384 /dev/video0

-The stream starts at 20% cache fill,so 3.2M in this case
-The cache lasted almost exactly 2 minutes before the audio drops stated due
to a starved buffer. This results in the same effect we're seeing playing
the audio directly from /dev/video0.

This was with the v4l repo driver, not your patched one that allows more
buffer adjustments.

I was not able to get any materially better performance by adjusting the
buffers in that branch that you sent.

What else should I try to help chase this down?

-Jeff
Re: cx18: Will the buffer be moving in to the driver? [ In reply to ]
On Wed, 2008-11-05 at 00:30 -0500, Jeff Campbell wrote:
>
>
> On Tue, Nov 4, 2008 at 12:54 AM, Jeff Campbell <jac1dlists@gmail.com>
> wrote:
> With the patch applied and the module installed
> under /lib/modules/.....
>
> # modprobe -r cx18
> # modinfo cx18
> # modprobe cx18 enc_mpg_bufsize=8 enc_mpg_bufs=63
>
> 63 buffers of 8 kB each. Not a lot of buffer depth,
> but with the
> default buffer size (of 32 kB IIRC) you didn't get
> very deep buffer
> usage anyway. I've only observed 11 buffers x 32 kB
> as a maximum burst
> from the chip when MythTV or mplayer couldn't keep up.
>
>
> Hi Andy,
>
> I got your patch compiled and loaded.
>
> My audio dropouts when watching the multicast via vlc are
> still about 1 per every second or so, but the number of
> complaints in the vlc messages window is way down, so it
> definitely has made an improvement but there is a still a
> material issue.
>
> I'd like to help, is there any testing I can do and document
> to be of assistance?
>
> -Jeff
>
> I have installed mplayer from the debian multimedia repos and have
> tried your suggestion of the -cache 16348 option. For various reasons
> I can't play video on the machine right now (it is console only) but I
> can listen to the audio jack so I did
>
> # mplayer -cache 16384 /dev/video0
>
> -The stream starts at 20% cache fill,so 3.2M in this case
> -The cache lasted almost exactly 2 minutes before the audio drops
> stated due to a starved buffer. This results in the same effect we're
> seeing playing the audio directly from /dev/video0.
>
> This was with the v4l repo driver, not your patched one that allows
> more buffer adjustments.
>
> I was not able to get any materially better performance by adjusting
> the buffers in that branch that you sent.
>
> What else should I try to help chase this down?

Jeff,

Well, there's not much to be done at the moment. I know the problem is
a non-uniform rate of buffers being received from the CX23418 chip.
Until I can determine how to make the buffers come at a uniform rate
(like 1 frame per second), the best that can be done is to give the chip
smaller buffers and fix up the driver mailbox handling as much as
possible.

Which leads me to ask if you would be so kind as to test my latest
changes at

http://linuxtv.org/hg/~awalls/cx18-bugfix

I have made numerous changes in how the interrupts and mailboxes are
handled. I didn't achieve my goal making the dual capture problems go
away, but my (wishful?) perception is that unbuffered analog capture is
much better.


Hans,

Could you please glance at my latest changes? I changed the workqueue
to the kernel default workqueue as you suggested. I also added mutexes
for the outgoing command mailboxes, changed outgoing mailbox ack's not
to be so picky about what they ack'ed, and changed polling for incoming
acks to now wait on waitqueues instead.

With all that, I suspect I screwed something up. :) Removal of the
"in_atomic()" checks was most worrying, followed by the length of the
timeout for "wait_event_interruptable_timeout()" and the behavior on
timeout or interruption of the wait.


Regards,
Andy


_______________________________________________
ivtv-devel mailing list
ivtv-devel@ivtvdriver.org
http://ivtvdriver.org/mailman/listinfo/ivtv-devel
Re: cx18: Will the buffer be moving in to the driver? [ In reply to ]
On Thursday 06 November 2008 05:47:08 Andy Walls wrote:
> On Wed, 2008-11-05 at 00:30 -0500, Jeff Campbell wrote:
> >
> >
> > On Tue, Nov 4, 2008 at 12:54 AM, Jeff Campbell
<jac1dlists@gmail.com>
> > wrote:
> > With the patch applied and the module installed
> > under /lib/modules/.....
> >
> > # modprobe -r cx18
> > # modinfo cx18
> > # modprobe cx18 enc_mpg_bufsize=8 enc_mpg_bufs=63
> >
> > 63 buffers of 8 kB each. Not a lot of buffer depth,
> > but with the
> > default buffer size (of 32 kB IIRC) you didn't get
> > very deep buffer
> > usage anyway. I've only observed 11 buffers x 32 kB
> > as a maximum burst
> > from the chip when MythTV or mplayer couldn't keep
up.
> >
> >
> > Hi Andy,
> >
> > I got your patch compiled and loaded.
> >
> > My audio dropouts when watching the multicast via vlc are
> > still about 1 per every second or so, but the number of
> > complaints in the vlc messages window is way down, so it
> > definitely has made an improvement but there is a still a
> > material issue.
> >
> > I'd like to help, is there any testing I can do and document
> > to be of assistance?
> >
> > -Jeff
> >
> > I have installed mplayer from the debian multimedia repos and have
> > tried your suggestion of the -cache 16348 option. For various
reasons
> > I can't play video on the machine right now (it is console only) but
I
> > can listen to the audio jack so I did
> >
> > # mplayer -cache 16384 /dev/video0
> >
> > -The stream starts at 20% cache fill,so 3.2M in this case
> > -The cache lasted almost exactly 2 minutes before the audio drops
> > stated due to a starved buffer. This results in the same effect
we're
> > seeing playing the audio directly from /dev/video0.
> >
> > This was with the v4l repo driver, not your patched one that allows
> > more buffer adjustments.
> >
> > I was not able to get any materially better performance by adjusting
> > the buffers in that branch that you sent.
> >
> > What else should I try to help chase this down?
>
> Jeff,
>
> Well, there's not much to be done at the moment. I know the problem
is
> a non-uniform rate of buffers being received from the CX23418 chip.
> Until I can determine how to make the buffers come at a uniform rate
> (like 1 frame per second), the best that can be done is to give the
chip
> smaller buffers and fix up the driver mailbox handling as much as
> possible.
>
> Which leads me to ask if you would be so kind as to test my latest
> changes at
>
> http://linuxtv.org/hg/~awalls/cx18-bugfix
>
> I have made numerous changes in how the interrupts and mailboxes are
> handled. I didn't achieve my goal making the dual capture problems go
> away, but my (wishful?) perception is that unbuffered analog capture
is
> much better.
>
>
> Hans,
>
> Could you please glance at my latest changes? I changed the workqueue
> to the kernel default workqueue as you suggested. I also added
mutexes
> for the outgoing command mailboxes, changed outgoing mailbox ack's not
> to be so picky about what they ack'ed, and changed polling for
incoming
> acks to now wait on waitqueues instead.
>
> With all that, I suspect I screwed something up. :) Removal of the
> "in_atomic()" checks was most worrying, followed by the length of the
> timeout for "wait_event_interruptable_timeout()" and the behavior on
> timeout or interruption of the wait.

Reviewed-by: Hans Verkuil <hverkuil@xs4all.nl>

Looked good to me!

Regards,

Hans

_______________________________________________
ivtv-devel mailing list
ivtv-devel@ivtvdriver.org
http://ivtvdriver.org/mailman/listinfo/ivtv-devel
Re: cx18: Will the buffer be moving in to the driver? [ In reply to ]
Andy, Hans,

I'm trying to wrap my head around this stuttering audio issue. I think it
is likely the same reason the TS off the driver is not usable right now.

If it is a buffering issue, and given that the stream is muxed when it is
read in to the driver buffers from the chip, how is it that the video is so
stable? I have near perfect video with the current driver, reading direct
from the device, but in less than a minute of playing it with mplayer I get
10s of drift between the video decoded and the audio decoded.

Is it possible there is some kind of sampling rate issue with the audio
stream before it ever hits the driver read buffer?

I understand that the video has both PTS and DTS stamps, which helps a
player put the stream back together for decode and presentation, but I would
expect to see errors if the video was wildly out of order or ahead or behind
schedule materially and I see almost no complaints about the video. The
audio only has PTS stamps.

Just thinking out loud, but to get up to an apparent 10s of drift between
the video and audio seems like the problem must be before the buffered reads
in the driver given that the frames being read contain both video and audio?


-Jeff
Re: cx18: Will the buffer be moving in to the driver? [ In reply to ]
A quick question:

Was this audio problem present from the start of the driver development or
is their a significantly earlier version that doesn't have this problem?
I'd like to help hunt for "what might have changed" if there was a time when
the audio was smooth when reading (non-cached) direct from the driver to a
player.

Thanks,

-Jeff

On Thu, Nov 6, 2008 at 10:56 PM, Jeff Campbell <jac1dlists@gmail.com> wrote:

> Andy, Hans,
>
> I'm trying to wrap my head around this stuttering audio issue. I think it
> is likely the same reason the TS off the driver is not usable right now.
>
> If it is a buffering issue, and given that the stream is muxed when it is
> read in to the driver buffers from the chip, how is it that the video is so
> stable? I have near perfect video with the current driver, reading direct
> from the device, but in less than a minute of playing it with mplayer I get
> 10s of drift between the video decoded and the audio decoded.
>
> Is it possible there is some kind of sampling rate issue with the audio
> stream before it ever hits the driver read buffer?
>
> I understand that the video has both PTS and DTS stamps, which helps a
> player put the stream back together for decode and presentation, but I would
> expect to see errors if the video was wildly out of order or ahead or behind
> schedule materially and I see almost no complaints about the video. The
> audio only has PTS stamps.
>
> Just thinking out loud, but to get up to an apparent 10s of drift between
> the video and audio seems like the problem must be before the buffered reads
> in the driver given that the frames being read contain both video and audio?
>
>
> -Jeff
>
>
Re: cx18: Will the buffer be moving in to the driver? [ In reply to ]
On Fri, 2008-11-07 at 01:06 -0500, Jeff Campbell wrote:
> A quick question:
>
> Was this audio problem present from the start of the driver
> development or is their a significantly earlier version that doesn't
> have this problem? I'd like to help hunt for "what might have
> changed" if there was a time when the audio was smooth when reading
> (non-cached) direct from the driver to a player.

It's always been there for me. "Always for me" means since I first got
the HVR-1600 in early Feb 2008.


> Thanks,
>
> -Jeff
>
> On Thu, Nov 6, 2008 at 10:56 PM, Jeff Campbell <jac1dlists@gmail.com>
> wrote:
> Andy, Hans,
>
> I'm trying to wrap my head around this stuttering audio issue.
> I think it is likely the same reason the TS off the driver is
> not usable right now.
>
> If it is a buffering issue, and given that the stream is muxed
> when it is read in to the driver buffers from the chip, how is
> it that the video is so stable? I have near perfect video
> with the current driver, reading direct from the device, but
> in less than a minute of playing it with mplayer I get 10s of
> drift between the video decoded and the audio decoded.

You need to separate out what is application (mplayer) induced and what
is not (i.e. what is driver induced). From my observations it appears
that mplayer plays the "audio" it has on hand and will then cut the
audio waiting for the video to catch up. The net effects to me appear
to be smooth video with choppy audio that happens in advance of the
video. Those are just my perceptions. I have not examined mplayer's
source.



> Is it possible there is some kind of sampling rate issue with
> the audio stream before it ever hits the driver read buffer?

We set up the cx18 AV core to do the proper sample rates similar to the
cx25840 driver. I made a change where I actually made sure the audio
sample clock (the AUX_PLL) is over the long term locked to the video
sample clock in an effort to fix this problem. So going into the
encoder the audio samples are going at the nominal rate with minor
jittering by the hardware to stay locked to the video samples to
maintain a constant rate of audio/video samples on a frame by frame
basis. See the CX25840/1/2/3 data sheet and cx18-av-audio.c and look
for the EN_AV_LOCK comments.

The only real improvement here could be to run the PLL's in the middle
of there range at 400 MHz (200-600 MHz) as opposed to the 300 MHz or so
I know we run the AUX_PLL when using 32 ksps.

After that, it's up to the APU and CPU on the CX23418 to handle it
properly.

> I understand that the video has both PTS and DTS stamps, which
> helps a player put the stream back together for decode and
> presentation, but I would expect to see errors if the video
> was wildly out of order or ahead or behind schedule materially
> and I see almost no complaints about the video. The audio
> only has PTS stamps.

That's interesting.

Note that if you capture to a file with "cat /dev/video0 > foo.mpg" and
then "mplayer foo.mpg" you get very smooth playback. The stream is
ultimately well-formed, it's a matter of delivery and decoding in
real-time..



> Just thinking out loud, but to get up to an apparent 10s of
> drift between the video and audio seems like the problem must
> be before the buffered reads in the driver given that the
> frames being read contain both video and audio?

Again, you would need to separate out how much of that 10s is
application induced.

Regards,
Andy


>


_______________________________________________
ivtv-devel mailing list
ivtv-devel@ivtvdriver.org
http://ivtvdriver.org/mailman/listinfo/ivtv-devel
Re: cx18: Will the buffer be moving in to the driver? [ In reply to ]
On Fri, Nov 7, 2008 at 7:46 AM, Andy Walls <awalls@radix.net> wrote:

> On Fri, 2008-11-07 at 01:06 -0500, Jeff Campbell wrote:
> > A quick question:
> >
> > Was this audio problem present from the start of the driver
> > development or is their a significantly earlier version that doesn't
> > have this problem? I'd like to help hunt for "what might have
> > changed" if there was a time when the audio was smooth when reading
> > (non-cached) direct from the driver to a player.
>
> It's always been there for me. "Always for me" means since I first got
> the HVR-1600 in early Feb 2008.
>
>
> > Thanks,
> >
> > -Jeff
> >
> > On Thu, Nov 6, 2008 at 10:56 PM, Jeff Campbell <jac1dlists@gmail.com>
> > wrote:
> > Andy, Hans,
> >
> > I'm trying to wrap my head around this stuttering audio issue.
> > I think it is likely the same reason the TS off the driver is
> > not usable right now.
> >
> > If it is a buffering issue, and given that the stream is muxed
> > when it is read in to the driver buffers from the chip, how is
> > it that the video is so stable? I have near perfect video
> > with the current driver, reading direct from the device, but
> > in less than a minute of playing it with mplayer I get 10s of
> > drift between the video decoded and the audio decoded.
>
> You need to separate out what is application (mplayer) induced and what
> is not (i.e. what is driver induced). From my observations it appears
> that mplayer plays the "audio" it has on hand and will then cut the
> audio waiting for the video to catch up. The net effects to me appear
> to be smooth video with choppy audio that happens in advance of the
> video. Those are just my perceptions. I have not examined mplayer's
> source.
>
>
>
> > Is it possible there is some kind of sampling rate issue with
> > the audio stream before it ever hits the driver read buffer?
>
> We set up the cx18 AV core to do the proper sample rates similar to the
> cx25840 driver. I made a change where I actually made sure the audio
> sample clock (the AUX_PLL) is over the long term locked to the video
> sample clock in an effort to fix this problem. So going into the
> encoder the audio samples are going at the nominal rate with minor
> jittering by the hardware to stay locked to the video samples to
> maintain a constant rate of audio/video samples on a frame by frame
> basis. See the CX25840/1/2/3 data sheet and cx18-av-audio.c and look
> for the EN_AV_LOCK comments.
>
> The only real improvement here could be to run the PLL's in the middle
> of there range at 400 MHz (200-600 MHz) as opposed to the 300 MHz or so
> I know we run the AUX_PLL when using 32 ksps.
>
> After that, it's up to the APU and CPU on the CX23418 to handle it
> properly.
>
> > I understand that the video has both PTS and DTS stamps, which
> > helps a player put the stream back together for decode and
> > presentation, but I would expect to see errors if the video
> > was wildly out of order or ahead or behind schedule materially
> > and I see almost no complaints about the video. The audio
> > only has PTS stamps.
>
> That's interesting.
>
> Note that if you capture to a file with "cat /dev/video0 > foo.mpg" and
> then "mplayer foo.mpg" you get very smooth playback. The stream is
> ultimately well-formed, it's a matter of delivery and decoding in
> real-time..
>
>
>
> > Just thinking out loud, but to get up to an apparent 10s of
> > drift between the video and audio seems like the problem must
> > be before the buffered reads in the driver given that the
> > frames being read contain both video and audio?
>
> Again, you would need to separate out how much of that 10s is
> application induced.
>
> Regards,
> Andy
>

I've got some great news.

A colleague and I have been working on this for the past week or so and we
believe we have isolated and corrected the problem.

I apologize, but we are not familiar with the proper way to diff this and
add it with mercurial so I'm going to submit the complete file here as an
attachment and hopefully someone can merge it in to the tree.

Essentially, the clock timing mentioned above was causing the issue. Once
removed, the TS and PS streams off the driver are stable and usable in real
time with no audio drift or dropouts. We also adjusted some of the clock
timings to match the windows driver and some other minor trimming.

There is appears to be an occasional hiccup with packet ordering or missing
audio but its so minor all the players and set top boxes we tested against
could adjust for it.

Please review the changes, test and hopefully include in a future release.

Thanks,

-Jeff
Re: cx18: Will the buffer be moving in to the driver? [ In reply to ]
On Mon, 2008-11-10 at 10:33 -0500, Jeff Campbell wrote:
> On Fri, Nov 7, 2008 at 7:46 AM, Andy Walls <awalls@radix.net> wrote:

>
> We set up the cx18 AV core to do the proper sample rates
> similar to the
> cx25840 driver. I made a change where I actually made sure
> the audio
> sample clock (the AUX_PLL) is over the long term locked to the
> video
> sample clock in an effort to fix this problem. So going into
> the
> encoder the audio samples are going at the nominal rate with
> minor
> jittering by the hardware to stay locked to the video samples
> to
> maintain a constant rate of audio/video samples on a frame by
> frame
> basis. See the CX25840/1/2/3 data sheet and cx18-av-audio.c
> and look
> for the EN_AV_LOCK comments.
>
> The only real improvement here could be to run the PLL's in
> the middle
> of there range at 400 MHz (200-600 MHz) as opposed to the 300
> MHz or so
> I know we run the AUX_PLL when using 32 ksps.
>
> After that, it's up to the APU and CPU on the CX23418 to
> handle it
> properly.
>



> I've got some great news.
>
> A colleague and I have been working on this for the past week or so
> and we believe we have isolated and corrected the problem.
>
> I apologize, but we are not familiar with the proper way to diff this
> and add it with mercurial

If you cloned it with hg (hg clone http://linuxtv.org/hg/...) then "hg
diff" will show you a diff.


> so I'm going to submit the complete file here as an attachment and
> hopefully someone can merge it in to the tree.

That's for looking into this and taking initiative!

Now, just working my way through the differences and thinking out
loud...

1. The VIDIOC_G_CTRL ioctl case framed with the same code as
VIDIOC_INT_AUDIO_CLOCK_FREQ. This looks like an error to me. Stopping
the microcontroller and muting the audio system doesn't seem necessarily
or desirable for checking the state of audio controls.


2. No need to comment out the setting of AUD_COUNT or VID_COUNT, simply
setting the ENV_AV_LOCK bit to 0 in register 0x12b should do. For
example instead of this:

//cx18_av_write4(cx, 0x128, 0xa11d4bf8);

just do this:

cx18_av_write4(cx, 0x128, 0xa01d4bf8);


3. The changes of cx18_av_write(cx, reg, val) to
cx18_av_and_or(cx,reg,0xff,val) like this:

- cx18_av_write(cx, 0x127, 0x54);
+ cx18_av_and_or(cx, 0x127, 0xff, 0x54); // wmdb

make no difference AFAICT, as 0xff means change all the bits in this
byte register and all the bits are always explicitly set to 0x50 (a
subset of 0x50 and 0x54) at the beginning of the function.


4. The tweaks of the AUX_PLL_FRAC-tional part a really minor and depend
really on what value you assume for the crystal

case 48000:
/* VID_PLL and AUX_PLL */
cx18_av_write4(cx, 0x108, 0x100a040f);

/* AUX_PLL_FRAC */
/* 0xa.4c6b6ea * 28,636,363.63 / 0x10 = 48000 * 384 */
- cx18_av_write4(cx, 0x110, 0x0098d6dd);
+ cx18_av_write4(cx, 0x110, 0x0098D6E5);


When computing the original value I used the ideal crystal value of:

4.5 MHz/286*455/2*8 = 28.63636363... MHz


But due to rounding, you can back figure the "original" crystal value to
be:

28.636363661 MHz (about .025 Hz off the ideal value)


And back figuring the "new" crystal value from the updated number you
selected gives:

28.636362998 MHz (about .638 Hz off the ideal value)

In other words the Windows driver writers used an improperly rounded
crystal value of 28.63636300 MHz to compute their fractional divider
value.

But either way, the values are so close and probably well within the
error tolerance of an off-the-shelf crystal, that these refinements
shouldn't make a difference.


(I have attached a spreadsheet that you may find useful [or not]. N.B.
we only use BT.656 mode and not the square pixel modes.)


> Essentially, the clock timing mentioned above was causing the issue.
> Once removed, the TS and PS streams off the driver are stable and
> usable in real time with no audio drift or dropouts. We also adjusted
> some of the clock timings to match the windows driver and some other
> minor trimming.


So the only relevant change I see in the patch is the disabling
(actually not enabling) of EN_AV_LOCK in the high byte of register 0x128
(i.e. register 0x12b).

So now to get the changes you really that really fix you problem into
the driver, could you be so kind as to isolate which of the changes you
made actually fixes your problem? If you could start with the original
file and incrementally add in changes, testing to see which ones really
effect a solution, maybe going in this order:

1. Disabling EN_AV_LOCK
2. Changing the fractional divider values
3. Not changing AUD_COUNT and VID_COUNT from the chip defaults
4. Using cx18_av_and_or() instead of cx18_av_write() to set register
0x127
5. Stopping and muting the audio section to check the status of audio
controls

Thanks.

> There is appears to be an occasional hiccup with packet ordering or
> missing audio but its so minor all the players and set top boxes we
> tested against could adjust for it.

Please continue to test (I will too). I've have been lulled into
thinking my actions have fixed the problem before.

My impression is that the problem is dependent on the video content and
the MPEG encoder's internal state. Video that doesn't compress well
(snowy background, lots of things changing) seems to have less of an
issue than video that compresses extremely well (news anchor behind a
desk, talk show host & guest) in my experience. Also it seems like once
the encoder has been working on a particular scene for a while, the
audio jitter symptom doesn't seem as bad (maybe the application is
smoothing things out though).

If you have a canned video source, so you can replay the same video
again and again into the encoder while trying different changes, that
may help.



> Please review the changes, test and hopefully include in a future
> release.

Again thanks for working on this. Don't get discouraged. I appreciate
the help.

Regards,
Andy

> Thanks,
>
> -Jeff