cx88: fix oops on rmmod and implement stereo detection
PATCH 1/1 cx88: fix oops on rmmod and implement stereo detection
Here are the updated versions of my cx88 patches (I only sent the old versions to the linux-dvb list, and they did not draw too much attention there) maybe better luck here...
The first is a simple fix for a possible Oops on the removal of cx88xx module caused by the IR worker. This patch is independent from the other two.
The second and the third patches are enhachments of the cx88 audio code, I tried to implement the detection of stereo TV channels for A2 mode. I had no idea how to detect it, and falling back to EN_A2_AUTO_STEREO instead of EN_A2_FORCE_MONO1 did not help either. (The card changed the audio mode periodically on both mono and stereo channels) Forcing STEREO mode also did not help, because it resulted a loud static noise on mono tv channels.
Testing proved that AUD_NICAM_STATUS1 and AUD_NICAM_STATUS2 registers change randomly if and only if the second audio channel is missing, so if these registers are constant (Usually 0x0000 and 0x01), we can assume that the tv channel has two audio channels, so we can use STEREO mode. This method seems a bit ugly, but nicam detection works the same way, so to avoid further msleep()-ing, the A2 stereo detection code is in the nicam detection function.
By the way, the audio thread in the cx88 code is totally useless, in fact, it occaisonally sets the audio to MONO after starting a TV application, so i think it should be removed. My patch does NOT fix cx88_get_stereo, and even if it would, the audio thread would not work as expected, because core->audiomode_current is not set in cx88_set_tvaudio, and AUTO stereo modes (EN_BTSC_AUTO_STEREO, EN_NICAM_AUTO_STEREO) would also cause problems, the autodetected audio mode should be set to core->audiomode_current to make it work.
Who is now the cx88 maintainer? I should send him a copy of the patches...
Regards,
Marton Balint
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
PATCH 1/1 cx88: detect stereo output instead of mono fallback in A2 sound system
# HG changeset patch
# User Marton Balint <[email protected]>
# Date 1206489018 -3600
# Node ID 1fabe9b19f0c356704aad5bbb0ce045ff3e05947
# Parent 2c020dc87db5511e6cbaae05389e3bda225d4879
cx88: detect stereo output instead of mono fallback in A2 sound system
From: Marton Balint <[email protected]>
Testing proved that AUD_NICAM_STATUS1 and AUD_NICAM_STATUS2 registers change randomly if and only if the second audio channel is missing, so if these registers are constant (Usually 0x0000 and 0x01), we can assume that the tv channel has two audio channels, so we can use STEREO mode. This method seems a bit ugly, but nicam detection works the same way. And now stereo channel detection also works for me.
Since my cable TV provider only broadcasts in PAL BG mode with A2 sound system, i couldn't test other systems, but they should work just like before.
linux/drivers/media/video/cx88/cx88-tvaudio.c +35 -18
@@ -725,31 +725,47 @@ static void set_audio_standard_FM(struct/* ----------------------------------------------------------- */ -static int cx88_detect_nicam (struct cx88_core *core) -{ -int i, j =0 ; +static int cx88_detect_nicam_or_stereo (struct cx88_core *core) +{ +int i, stereo =0 ; +u32 status1, status2; +u32 last_status1, last_status2;dprintk ("start nicam autodetect.\n" ); - -for (i =0 ; i <6 ; i++) { + last_status1 =cx_read (AUD_NICAM_STATUS1 ); + last_status2 =cx_read (AUD_NICAM_STATUS2 ); + +/* wait here max 50 ms or if stereo is ambigous then max 70 ms */ +for (i =0 ; i <5 || (stereo >0 && stereo <3 && i <7 ); i++) { +/* wait a little bit for next reading status */ +msleep (10 ); + + status1 =cx_read (AUD_NICAM_STATUS1 ); + status2 =cx_read (AUD_NICAM_STATUS2 ); +/* if bit1=1 then nicam is detected */ - j += ((cx_read (AUD_NICAM_STATUS2 ) &0x02 ) >>1 ); - -if (j ==1 ) { +if (status2 &0x02 ) {dprintk ("nicam is detected.\n" );return 1 ; } -/* wait a little bit for next reading status */ -msleep (10 ); - } - +if (last_status1 == status1 && last_status2 == status2) + stereo++; +else + stereo =0 ; + last_status1 = status1; + last_status2 = status2; + } + +dprintk ("stereo detection result: %d\n" , stereo);dprintk ("nicam is not detected.\n" ); -return 0 ; +return stereo >=3 ?2 :0 ; }void cx88_set_tvaudio (struct cx88_core *core) { +int nicam_or_stereo; +switch (core->tvaudio) {case WW_BTSC :set_audio_standard_BTSC (core,0 ,EN_BTSC_AUTO_STEREO );
@@ -764,12 +780,13 @@ void cx88_set_tvaudio(struct cx88_core */* set nicam mode - otherwise AUD_NICAM_STATUS2 contains wrong values */ set_audio_standard_NICAM (core,EN_NICAM_AUTO_STEREO ); -if (0 ==cx88_detect_nicam (core)) { -/* fall back to fm / am mono */ -set_audio_standard_A2 (core,EN_A2_FORCE_MONO1 ); + nicam_or_stereo =cx88_detect_nicam_or_stereo (core); +if (nicam_or_stereo ==1 ) { + core->use_nicam =1 ; + }else { +/* fall back to fm / am stereo or mono */ +set_audio_standard_A2 (core, nicam_or_stereo ==2 ?EN_A2_FORCE_STEREO :EN_A2_FORCE_MONO1 ); core->use_nicam =0 ; - }else { - core->use_nicam =1 ; }break ;case WW_EIAJ :
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
PATCH 1/1 cx88: fix stereo dematrix for A2 sound system
In reply to Marton Balint# HG changeset patch
# User Marton Balint <[email protected]>
# Date 1206488442 -3600
# Node ID 2c020dc87db5511e6cbaae05389e3bda225d4879 # Parent 54d0fc010ab0225fbed97df3267d26e91aa03a2a
cx88: fix stereo dematrix for A2 sound system
From: Marton Balint <[email protected]>
Using A2 sound system, in stereo mode, the first sound channel is L+R, the second channel is 2*R. So the dematrix control should be SUMR instead of SUMDIFF. Let's use SUMR for stereo mode, and use SUMDIFF for everything else, just like before.
linux/drivers/media/video/cx88/cx88-tvaudio.c +6 -1
@@ -632,7 +632,12 @@ static void set_audio_standard_A2(structbreak ; }; - mode |=EN_FMRADIO_EN_RDS |EN_DMTRX_SUMDIFF ; + mode |=EN_FMRADIO_EN_RDS ; +if ((mode &0x3f ) ==EN_A2_FORCE_STEREO ) + mode |=EN_DMTRX_SUMR ; +else + mode |=EN_DMTRX_SUMDIFF ; +set_audio_finish (core, mode); }
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
PATCH 1/1 cx88: fix oops on module removal caused by IR worker
In reply to Marton Balint# HG changeset patch
# User Marton Balint <[email protected]>
# Date 1206487800 -3600
# Node ID 54d0fc010ab0225fbed97df3267d26e91aa03a2a # Parent cc6c65fe4ce0543e14afdd2b850c991081f7b9ac
cx88: fix oops on module removal caused by IR worker
From: Marton Balint <[email protected]>
If the IR worker is not stopped before the removal of the cx88xx module, an OOPS may occur, because the worker function cx88_ir_work gets called. So stop the ir worker.
linux/drivers/media/video/cx88/cx88-video.c +3 -0
@@ -2221,6 +2221,9 @@ static void __devexit cx8800_finidev(str core->kthread =NULL ; } +if (core->ir) +cx88_ir_stop (core, core->ir); +cx88_shutdown (core);/* FIXME */ pci_disable_device (pci_dev);
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
Mauro Carvalho Chehab
AppliedRe: [PATCH 1 of 3] cx88: fix oops on module removal caused by IR worker
Quoted 6 lines · On Wed, 26 Mar 2008 03:07:35 +0100 Marton Balint <[email protected]> wrote:
# HG changeset patch
# User Marton Balint <[email protected]>
# Date 1206487800 -3600
# Node ID54d0fc010ab0225fbed97df3267d26e91aa03a2a# Parentcc6c65fe4ce0543e14afdd2b850c991081f7b9ac
cx88: fix oops on module removal caused by IR worker
Applied, thanks.
I'll wait for some conclusions about the other two patches.
Cheers,
Mauro
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
Hello there,
I am interested in ability to get stereo channels working with my avertv studio 303 which is a cx88 based.
I am not a developer nor I understand this stuff very well but anyway I'd like to try this out if it may help. With current v4l builds I am getting mono sound each time tv app is started (I am using mplayer btw).
So here are a few questions hopefully it's not a problem to ask them here:
1) are these patches already included in some repository? If not how should I go about applying them? Is the diff command the right way? What branch are they against?
2) The comments below indicates audio functionality for cx88 is not working as it should. So shal I be able to get stereo sound after applying these patches?
3) are there any tunner settings required in order to get stereo sound? or perhaps settings for some other modules?
Thanks
Peter
Marton Balint wrote / napísal(a):
Quoted 35 lines
Here are the updated versions of my cx88 patches (I only sent the old versions to the linux-dvb list, and they did not draw too much attention there) maybe better luck here...
The first is a simple fix for a possible Oops on the removal of cx88xx module caused by the IR worker. This patch is independent from the other two.
The second and the third patches are enhachments of the cx88 audio code, I tried to implement the detection of stereo TV channels for A2 mode. I had no idea how to detect it, and falling back to
EN_A2_AUTO_STEREOinstead ofEN_A2_FORCE_MONO1did not help either. (The card changed the audio mode periodically on both mono and stereo channels) Forcing STEREO mode also did not help, because it resulted a loud static noise on mono tv channels.Testing proved that
AUD_NICAM_STATUS1andAUD_NICAM_STATUS2registers change randomly if and only if the second audio channel is missing, so if these registers are constant (Usually0x0000and0x01), we can assume that the tv channel has two audio channels, so we can use STEREO mode. This method seems a bit ugly, but nicam detection works the same way, so to avoid further msleep()-ing, the A2 stereo detection code is in the nicam detection function.By the way, the audio thread in the cx88 code is totally useless, in fact, it occaisonally sets the audio to MONO after starting a TV application, so i think it should be removed. My patch does NOT fix
cx88_get_stereo, and even if it would, the audio thread would not work as expected, becausecore->audiomode_currentis not set incx88_set_tvaudio, and AUTO stereo modes (EN_BTSC_AUTO_STEREO,EN_NICAM_AUTO_STEREO) would also cause problems, the autodetected audio mode should be set tocore->audiomode_currentto make it work.Who is now the cx88 maintainer? I should send him a copy of the patches...
Regards,
Quoted 7 lines
Marton Balint
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
Quoted 3 lines · Peter Vágner
1) are these patches already included in some repository? If not how should I go about applying them? Is the diff command the right way? What branch are they against?
The patches are not inculded in any public repository. You can apply them using the patch command. The patches are against the current v4l-dvb tree:
http://linuxtv.org/hg/v4l-dvb
Quoted 2 lines
2) The comments below indicates audio functionality for cx88 is not working as it should. So shal I be able to get stereo sound after applying these patches?
Yes. Maybe the first tv channel after you start mplayer will be mono (because of the buggy audio thread), but after you change the channel, auto detection should work.
Quoted 2 lines
3) are there any tunner settings required in order to get stereo sound? or perhaps settings for some other modules?
No.
Quoted 1 line
Thanks
You are welcome! Happy testing! :)
Regards,
Marton
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
Hello,
Quoted 4 lines · Balint Marton
Yes. Maybe the first tv channel after you start mplayer will be mono (because of the buggy audio thread), but after you change the channel, auto detection should work.
Thanks a lot. I am very happy this works at least partially. I see there will be problems while recording because when starting mencoder in the scheduler I won't be able to switch channels to detect the stereo reliably. I am just wondering might there be a way to fix also this issue? Sometimes it works even at startup of the player but more frequently it does not.
thanks once again
Peter
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
Quoted 3 lines
I am just wondering might there be a way to fix also this issue? Sometimes it works even at startup of the player but more frequently it does not.
Try the attached patch. It disables the audio thread completely.
Regards,
Marton
linux/drivers/media/video/cx88/cx88-video.c +2 -0
@@ -2181,6 +2181,7 @@ static int __devinit cx8800_initdev(strucx88_video_mux (core,0 );mutex_unlock (&core->lock); +#if 0 /* start tvaudio thread */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) if (core->board.tuner_type != TUNER_ABSENT) {
@@ -2198,6 +2199,7 @@ static int __devinit cx8800_initdev(stru core->kthread =NULL ;#endif +#endif return 0 ; fail_unreg:
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
Hello,
Balint Marton wrote / napísal(a):
Quoted 2 lines
Try the attached patch. It disables the audio thread completely.
Thanks now this is wonderfull for recording.
Based on some comments posted to this list I have tryed to let the tv runing for a few hours and I am getting no unusual behaviour nor distorted sound. Here in slovakia all the channels I can tune to are also pal-BG. Literally I can tune no mono channels here. Their are either broadcasting stereo, or dual (2 independent language track per audio channel) or they are sending the same mono track to each channel So I am really not woried about the mono audio. The only thing which is not very confortable is stereo versus dual audio detection. If it's forced to stereo, I am getting both the audio tracks when it changes during a viewing session. Ideally it would be nice to be able to switch this on the fly. Or perhaps mplayer has some filter where I can temporarily enable left or right channel only based off my actual preference. I have to look into this further. I am saying it's fine for the recording because in that case both language tracks are great if stereo is not broadcasted. It can be processed later.
thanks much again Now I think I can get more from this card using v4l than I was used to do under windows. E.G. channel switching is almost instantaneous.
Peter
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
Re: [PATCH 0 of 3] cx88: fix oops on rmmod and implement stereodetection
In reply to Marton BalintQuoted 6 lines
The second and the third patches are enhachments of the cx88 audio code, I tried to implement the detection of stereo TV channels for A2 mode. I had no idea how to detect it, and falling back to
EN_A2_AUTO_STEREOinstead ofEN_A2_FORCE_MONO1did not help either. (The card changed the audio mode periodically on both mono and stereo channels) Forcing STEREO mode also did not help, because it resulted a loud static noise on mono tv channels.
It's a bug of the audio dsp part.
Quoted 9 lines
Testing proved that
AUD_NICAM_STATUS1andAUD_NICAM_STATUS2registers change randomly if and only if the second audio channel is missing, so if these registers are constant (Usually0x0000and0x01), we can assume that the
tv channel has two audio channels, so we can use STEREO mode. This method seems a bit ugly, but nicam detection works the same way, so to avoid further msleep()-ing, the A2 stereo detection code is in the nicam detection
function.
No, the Nicam_Status_Regs contain only and only if Nicam is forced before. Your patch _can_ work for B/G, but I don't think so for others, like D/K etc.
Quoted 9 lines
By the way, the audio thread in the cx88 code is totally useless, in fact, it occaisonally sets the audio to MONO after starting a TV application, so i think it should be removed. My patch does NOT fix
cx88_get_stereo, and even if it would, the audio thread would not work as expected, becausecore->audiomode_currentis not set incx88_set_tvaudio, and AUTO stereo modes (EN_BTSC_AUTO_STEREO,EN_NICAM_AUTO_STEREO) would also cause problems, the autodetected audio mode should be set tocore->audiomode_current
to make it work.
Sorry, not an native english speaker here.
If it were easy it would already be done. ;)
I am the one who did that in cx88-tvaudio.c. With Mauro's and many others help I have moved this part from DScaler project where I am from into this file.
Still not finished as you can see in comments. There is much more to do if you want to get safe mono/stereo or a2/nicam/btsc detection.
I did many things trying to understand on how audio things are going on on this chip. Together witht some others from this list I have learned from m$ driver how it really works by using de-asm/debuggers tools. To make a long story short: The only way is to take some audio samples into memory, compare it to tables and do some calculations depands on video-mode.
Torsten
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
Re: [PATCH 0 of 3] cx88: fix oops on rmmod and implement stereodetection
Quoted 3 lines
No, the
Nicam_Status_Regscontain only and only if Nicam is forced before. Your patch _can_ work for B/G, but I don't think so for others, like D/K etc.
It works for me on B/G. Unfortunately i can't test the others, because my cable tv provider only uses B/G. Anyway, if it really doesn't work on other sound systems, we can use the mono fallback there, like before, and use the stereo detection based on Nicam_Status regs only for B/G mode.
Quoted 8 lines
Still not finished as you can see in comments. There is much more to do if you want to get safe mono/stereo or a2/nicam/btsc detection.
I did many things trying to understand on how audio things are going on on this chip. Together witht some others from this list I have learned from m$ driver how it really works by using de-asm/debuggers tools. To make a long story short: The only way is to take some audio samples into memory, compare it to tables and do some calculations depands on video-mode.
I don't see much chance anyone will ever going to do it. On top of that, taking audio samples is not easy, if the tuner card is connected to a sound card input... Considering what you said, detecting the audio mode properly in the audio thread seems impossible to me. So I still think the audio thread should be removed, unless someone came up with a better idea.
Regards,
Marton
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
Hi!
Mauro, have you come to a decision about patch 2 and patch 3?
Unfotunately I can't test other sound systems than BG, so it is still unknown if the detection also works on other systems, or not. I only confirmed one thing with the help of an old video casette
recorder: mono DK sound is not misdetected as stereo.
Another question is the audio thread. Like I explained in my original post, it does more harm than good, because it occaisonally sets the audio to mono after starting a TV application. Altough my patches are not dependant on the removal of the thread, I think it should be removed. What would be the correct way to do that? Delete the relevant lines, or just #ifdef them out?
Regards,
Marton Balint
Quoted 35 lines
Here are the updated versions of my cx88 patches (I only sent the old versions to the linux-dvb list, and they did not draw too much attention there) maybe better luck here...
The first is a simple fix for a possible Oops on the removal of cx88xx module caused by the IR worker. This patch is independent from the other two.
The second and the third patches are enhachments of the cx88 audio code, I tried to implement the detection of stereo TV channels for A2 mode. I had no idea how to detect it, and falling back to
EN_A2_AUTO_STEREOinstead ofEN_A2_FORCE_MONO1did not help either. (The card changed the audio mode periodically on both mono and stereo channels) Forcing STEREO mode also did not help, because it resulted a loud static noise on mono tv channels.Testing proved that
AUD_NICAM_STATUS1andAUD_NICAM_STATUS2registers change randomly if and only if the second audio channel is missing, so if these registers are constant (Usually0x0000and0x01), we can assume that the tv channel has two audio channels, so we can use STEREO mode. This method seems a bit ugly, but nicam detection works the same way, so to avoid further msleep()-ing, the A2 stereo detection code is in the nicam detection function.By the way, the audio thread in the cx88 code is totally useless, in fact, it occaisonally sets the audio to MONO after starting a TV application, so i think it should be removed. My patch does NOT fix
cx88_get_stereo, and even if it would, the audio thread would not work as expected, becausecore->audiomode_currentis not set incx88_set_tvaudio, and AUTO stereo modes (EN_BTSC_AUTO_STEREO,EN_NICAM_AUTO_STEREO) would also cause problems, the autodetected audio mode should be set tocore->audiomode_currentto make it work.Who is now the cx88 maintainer? I should send him a copy of the patches...
Regards,
Quoted 8 lines
Marton Balint
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list