diff mbox

[saa7134] do not change mute state for capturing audio

Message ID 4E26AEC0.5000405@infradead.org (mailing list archive)
State Rejected
Headers show

Commit Message

Mauro Carvalho Chehab July 20, 2011, 10:32 a.m. UTC
Em 20-07-2011 02:28, Stas Sergeev escreveu:
> 20.07.2011 04:55, Mauro Carvalho Chehab wrote:
>>> The proposed solution is to have the mute
>>> control, that can be valid for all the cards/drivers.
>>> Presumably, it should have the similar name
>>> for all of them, even though for some it will be
>>> a "virtual" control that will control several items,
>>> and for others - it should map directly to their
>>> single mute control.
>>> If we have such a mute control, any app can use
>>> it,
>> Any app can do it right now via the V4L2 api.
> I am just following your logic, you said that
> ---
> Moving such logic to happen at userspace would be very complex, and will
> break existing applications.
> ---
> To solve that, I proposed adding such mixer control
> to where it is missing right now.
> But if this is no longer a problem and the app
> can just use v4l2 for that instead, then what still
> keeps us from removing the auto-unmute things?

I won't keep discussing something that won't be merged, as it will
cause regressions.

>>> and the auto-unmute logic can be removed
>>> from the alsa driver. v4l2 is left as it is now.
>> What is the sense of capturing data for a device that is not ready
>> for stream?
> This may be a PA's hack, or a user's mistake, or
> whatever, but whatever it is, it shouldn't lead to
> any sounds from speakers. Just starting the capture,
> willingly or by mistake, should never lead to any
> sound from speakers, IMO. So that's the bug too.
> And the simpler one to fix.

If the application is starting streaming, audio should be expected on devices 
where the audio output is internally wired with the capture input.
This seems to be the case of your device. There's nothing that can be
done to fix a bad hardware design or the lack of enough information
from the device manufacturer.

>> The enclosed patch probably does the trick (completely untested).
> I'll be able to test it on avertv 307 the next week-end.

The patch is not that simple. The driver needs to set the device inputs
accordingly, otherwise it will break support for digital audio. 

In the specific case of avertv 307, this patch alone may not work. I suspect
that there is a problem at the GPIO settings for mute on its board entry:

[SAA7134_BOARD_AVERMEDIA_STUDIO_307] = {
...
                .inputs         = {{
                        .name = name_tv,
                        .vmux = 1,
                        .amux = TV,
                        .tv   = 1,
                        .gpio = 0x00,
                },{
...
                .mute  = {
                        .name = name_mute,
                        .amux = LINE1,
                        .gpio = 0x00,
                },


See: mute GPIO's are equal for TV GPIO. That means that it will select the
TV gpio for "mute".

-

[PATCHv2 - BROKEN] saa7134: Don't touch at the analog mute at the alsa driver

Via the alsa driver, it is possible to start capturing from an audio input.
When capture is started, the driver will unmute the audio input associated
with the selected video input, if it were muted. 

However, if the device is using a wire for the audio output, it may produce 
audio at the speakers. This patch changes the mute logic to:
	1) on saa7134, don't touch at the ANALOG_MUTE at alsa unmute call;
	2) don't change the GPIO's.

I suspect, however, that not changing the GPIO's is a very bad idea, and
it will actually break audio for devices with external GPIO-based input
switches, but, as this version was already done, it might be useful for some
tests. A version 3 will follow shortly.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Stas Sergeev July 20, 2011, 10:45 a.m. UTC | #1
20.07.2011 14:32, Mauro Carvalho Chehab wrote:
> I won't keep discussing something that won't be merged, as it will
> cause regressions.
Please explain what regressions it will make!
I am asking that question over and over again, and
every time you either ignore it, or refer to an apps
that use v4l2 ioctls, which are unaffected.
I wonder why you don't want to explain what regressions
do you have in mind...

> If the application is starting streaming, audio should be expected on
> devices
> where the audio output is internally wired with the capture input.
> This seems to be the case of your device. There's nothing that can be
> done to fix a bad hardware design or the lack of enough information
> from the device manufacturer.
Well, until you explain the exact breakage of my proposal,
I won't trust this. :)

> I suspect, however, that not changing the GPIO's is a very bad idea, and
> it will actually break audio for devices with external GPIO-based input
> switches, but, as this version was already done, it might be useful for some
> tests. A version 3 will follow shortly.
I'll test at a week-end whatever we'll have to that date.
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mauro Carvalho Chehab July 20, 2011, 10:48 a.m. UTC | #2
Em 20-07-2011 07:45, Stas Sergeev escreveu:
> 20.07.2011 14:32, Mauro Carvalho Chehab wrote:
>> I won't keep discussing something that won't be merged, as it will
>> cause regressions.
> Please explain what regressions it will make!
> I am asking that question over and over again, and
> every time you either ignore it, or refer to an apps
> that use v4l2 ioctls, which are unaffected.
> I wonder why you don't want to explain what regressions
> do you have in mind...
> 
>> If the application is starting streaming, audio should be expected on
>> devices
>> where the audio output is internally wired with the capture input.
>> This seems to be the case of your device. There's nothing that can be
>> done to fix a bad hardware design or the lack of enough information
>> from the device manufacturer.
> Well, until you explain the exact breakage of my proposal,
> I won't trust this. :)

I've said already: mplayer for example relies on such behavior to work. Reverting
it breaks mplayer. This is enough for me to NACK your patch.

> 
>> I suspect, however, that not changing the GPIO's is a very bad idea, and
>> it will actually break audio for devices with external GPIO-based input
>> switches, but, as this version was already done, it might be useful for some
>> tests. A version 3 will follow shortly.
> I'll test at a week-end whatever we'll have to that date.

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Stas Sergeev July 20, 2011, 10:55 a.m. UTC | #3
20.07.2011 14:48, Mauro Carvalho Chehab wrote:
>> Well, until you explain the exact breakage of my proposal,
>> I won't trust this. :)
> I've said already: mplayer for example relies on such behavior to work. Reverting
> it breaks mplayer. This is enough for me to NACK your patch.
What you said, was:
---
Some applications like mplayer don't use V4L2_CID_AUDIO_MUTE to unmute a
video
device. They assume the current behavior that starting video also
unmutes audio.
---
"starting video also unmutes audio" is what my patch
_does not touch_! And that certainly happens not even
in the alsa driver, but somewhere in the v4l2 code.

So, please please please, could you actually precisely
explain how exactly mplayer breaks with my patch?
That's the only thing I need! :))
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Stas Sergeev July 22, 2011, 7:51 a.m. UTC | #4
Ok, Mauro, so may I take your silence as an evidence
that this reiterating myth about the mplayer breakage
is just a myth?
Look, I spent time on investigating the problem, on
trying the different approaches to fix it, on explaining
the problem to you, etc. So maybe I deserve something
more than just a blunt "NACK, lets fix real bugs" reply
you initially did? :)
Note: that's the first time I got the nack without any
explanation in the very first reply, and with the false
explanations later. My patch doesn't break mplayer: it
can't, since mplayer does not use that interface at all.
And my patch fixes a real problem, so even if it is for
some reasons incorrect, it certainly deserves a better
treatment than the false claims.
I guess you are doing this in order to just push your
own patch, and you'll do that anyway, so this "letter of
disappointment" is going to be my last posting to that
thread, unless you decide to explain your nack after all. :)
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mauro Carvalho Chehab July 22, 2011, 12:28 p.m. UTC | #5
Em 22-07-2011 04:51, Stas Sergeev escreveu:
> Ok, Mauro, so may I take your silence as an evidence
> that this reiterating myth about the mplayer breakage
> is just a myth?

It is due to my lack of time of explaining the obvious for you.
Changing the behavior of the kernel drivers has consequences
on userspace, called regressions. Regressions are not allowed
at the Linux Kernel: a binary that used to run with an old
kernel should keep running on a new kernel.
 
In this specific case, applications like mplayer,
using the alsa parameters for streaming will stop work, as mplayer
won't touch at the mixer or at the V4L mute control. So,
it will have the same practical effect of a kernel bug at the
audio part of the driver.

> Look, I spent time on investigating the problem, on
> trying the different approaches to fix it, on explaining
> the problem to you, etc. So maybe I deserve something
> more than just a blunt "NACK, lets fix real bugs" reply
> you initially did? :)
> Note: that's the first time I got the nack without any
> explanation in the very first reply, and with the false
> explanations later. My patch doesn't break mplayer: it
> can't, since mplayer does not use that interface at all.
> And my patch fixes a real problem, so even if it is for
> some reasons incorrect, it certainly deserves a better
> treatment than the false claims.
> I guess you are doing this in order to just push your
> own patch, and you'll do that anyway, so this "letter of
> disappointment" is going to be my last posting to that
> thread, unless you decide to explain your nack after all. :)

I probably won't push my own patch, at least for now, as it
is not tested, and I'm currently lacking time to install a few
saa7134 boards for testing.


--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Stas Sergeev July 22, 2011, 12:39 p.m. UTC | #6
22.07.2011 16:28, Mauro Carvalho Chehab wrote:
> In this specific case, applications like mplayer,
> using the alsa parameters for streaming will stop work, as mplayer
> won't touch at the mixer or at the V4L mute control. So,
> it will have the same practical effect of a kernel bug at the
> audio part of the driver.
Let me quote you again:
---
Some applications like mplayer don't use V4L2_CID_AUDIO_MUTE to unmute a
video device. They assume the current behavior that starting video also
unmutes audio.
---
Could you please explain how my patch breaks
"starting video also unmutes audio"? I haven't touched
anything related to "starting video", so, if starting video
used to unmute audio, it will keep it that way.
Can you tell me how exactly I can reproduce that breakage?
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mauro Carvalho Chehab July 22, 2011, 12:49 p.m. UTC | #7
Em 22-07-2011 09:39, Stas Sergeev escreveu:
> 22.07.2011 16:28, Mauro Carvalho Chehab wrote:
>> In this specific case, applications like mplayer,
>> using the alsa parameters for streaming will stop work, as mplayer
>> won't touch at the mixer or at the V4L mute control. So,
>> it will have the same practical effect of a kernel bug at the
>> audio part of the driver.
> Let me quote you again:
> ---
> Some applications like mplayer don't use V4L2_CID_AUDIO_MUTE to unmute a
> video device. They assume the current behavior that starting video also
> unmutes audio.

Let me rephase it:
Some applications like mplayer don't use V4L2_CID_AUDIO_MUTE to unmute a
video device. They assume the current behavior that starting audio on a
video board also unmutes audio.

> ---
> Could you please explain how my patch breaks
> "starting video also unmutes audio"? I haven't touched
> anything related to "starting video", so, if starting video
> used to unmute audio, it will keep it that way.
> Can you tell me how exactly I can reproduce that breakage?

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Stas Sergeev July 22, 2011, 12:56 p.m. UTC | #8
22.07.2011 16:49, Mauro Carvalho Chehab wrote:
> Let me rephase it:
> Some applications like mplayer don't use V4L2_CID_AUDIO_MUTE to unmute a
> video device. They assume the current behavior that starting audio on a
> video board also unmutes audio.
Could you please give me a command line I can use
to verify that? Or any pointers to the code, anything
to check?
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mauro Carvalho Chehab July 22, 2011, 1:03 p.m. UTC | #9
Em 22-07-2011 09:56, Stas Sergeev escreveu:
> 22.07.2011 16:49, Mauro Carvalho Chehab wrote:
>> Let me rephase it:
>> Some applications like mplayer don't use V4L2_CID_AUDIO_MUTE to unmute a
>> video device. They assume the current behavior that starting audio on a
>> video board also unmutes audio.
> Could you please give me a command line I can use
> to verify that? Or any pointers to the code, anything
> to check?

Here, I add the following line at my .mplayer/config:

tv		= "driver=v4l2:device=/dev/video0:norm=PAL-M:chanlist=us-bcast:alsa=1:adevice=hw.1:audiorate=32000:immediatemode=0:amode=1"
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Stas Sergeev July 22, 2011, 8:40 p.m. UTC | #10
22.07.2011 17:03, Mauro Carvalho Chehab wrote:
> Here, I add the following line at my .mplayer/config:
>
> tv		= "driver=v4l2:device=/dev/video0:norm=PAL-M:chanlist=us-bcast:alsa=1:adevice=hw.1:audiorate=32000:immediatemode=0:amode=1"
Thanks for starting to answer what I was asking for over a week. :)
If this is the case (not verified yet), there may be the simple
automute logic that will fix that in an absense of an auto-unmute
in alsa.
Initially, the driver may be put in an auto-mute state.
It is mute until the tuner is tuned: after the tuner is tuned,
the audio gets immediately automatically unmuted.
If the app does not want this to happen, it may use
the V4L2_CID_AUDIO_MUTE before tuning, to put the device
in a permanent-mute state.
So, in short, I suggest to bind the auto-unmute to the
tuner tune, rather than to the capture start. And that
should be a separate, third mute state, automute. If the
app explicitly wants the mute or unmute, this automute
logic disables.
Do you know any app that will regress even with that?
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mauro Carvalho Chehab July 23, 2011, 1:28 a.m. UTC | #11
Em 22-07-2011 17:40, Stas Sergeev escreveu:
> 22.07.2011 17:03, Mauro Carvalho Chehab wrote:
>> Here, I add the following line at my .mplayer/config:
>>
>> tv        = "driver=v4l2:device=/dev/video0:norm=PAL-M:chanlist=us-bcast:alsa=1:adevice=hw.1:audiorate=32000:immediatemode=0:amode=1"
> Thanks for starting to answer what I was asking for over a week. :)
> If this is the case (not verified yet), there may be the simple
> automute logic that will fix that in an absense of an auto-unmute
> in alsa.
> Initially, the driver may be put in an auto-mute state.
> It is mute until the tuner is tuned: after the tuner is tuned,
> the audio gets immediately automatically unmuted.
> If the app does not want this to happen, it may use
> the V4L2_CID_AUDIO_MUTE before tuning, to put the device
> in a permanent-mute state.
> So, in short, I suggest to bind the auto-unmute to the
> tuner tune, rather than to the capture start. And that
> should be a separate, third mute state, automute. If the
> app explicitly wants the mute or unmute, this automute
> logic disables.
> Do you know any app that will regress even with that?

Mplayer was just one example of an application that I know
it doesn't call V4L2_CID_AUDIO_MUTE to unmute. I didn't 
check for other applications and scripts that may break
with such change.

Your approach of moving it to VIDIOC_S_FREQUENCY (if I 
understood well) won't work, as, every time someone would 
change the channel, it will be unmuted, causing troubles
on applications like "scantv" (part of xawtv).

You can't associate such logic to any ioctl, due to the
same reasons. Also, associating with V4L open also will
cause side effects, as udev opens all V4L devices when
the device is detected.

You should also remind that it is possible to use a separate
application (like v4l2-ctl) while a device is opened
by other applications, and even to not have the device
opened while streaming (radio applications allow that).

Mauro.
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Stas Sergeev July 23, 2011, 7:44 a.m. UTC | #12
23.07.2011 05:28, Mauro Carvalho Chehab wrote:
> Mplayer was just one example of an application that I know
> it doesn't call V4L2_CID_AUDIO_MUTE to unmute.
I would suggest fixing all such an apps, even if we
are not going to change that in the driver.

> Your approach of moving it to VIDIOC_S_FREQUENCY (if I
> understood well) won't work, as, every time someone would
> change the channel, it will be unmuted, causing troubles
> on applications like "scantv" (part of xawtv).
But how can scantv (or anything else) rely on the
fact that the board was muted when that app starts?
I guess it can't, and mutes it explicitly first, no?
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mauro Carvalho Chehab July 23, 2011, 1:06 p.m. UTC | #13
Em 23-07-2011 04:44, Stas Sergeev escreveu:
> 23.07.2011 05:28, Mauro Carvalho Chehab wrote:
>> Mplayer was just one example of an application that I know
>> it doesn't call V4L2_CID_AUDIO_MUTE to unmute.
> I would suggest fixing all such an apps, even if we
> are not going to change that in the driver.

If application needs to change due to a patch, this is a
regression, as it will break binary compatibility with
non-patched versions. NACK.

>> Your approach of moving it to VIDIOC_S_FREQUENCY (if I
>> understood well) won't work, as, every time someone would
>> change the channel, it will be unmuted, causing troubles
>> on applications like "scantv" (part of xawtv).
> But how can scantv (or anything else) rely on the
> fact that the board was muted when that app starts?
> I guess it can't, and mutes it explicitly first, no?

Even if it mutes, every time a channel is changed, it
will be unmuted, if you put such unmute logic at
VIDIOC_S_FREQUENCY.

Mauro.
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Stas Sergeev July 23, 2011, 1:20 p.m. UTC | #14
23.07.2011 17:06, Mauro Carvalho Chehab wrote:
>> I would suggest fixing all such an apps, even if we
>> are not going to change that in the driver.
> If application needs to change due to a patch, this is a
> regression,
I said "even if we are not going to change that in the
driver", which, imho, removes any ambiguity from my
phrase.

>> But how can scantv (or anything else) rely on the
>> fact that the board was muted when that app starts?
>> I guess it can't, and mutes it explicitly first, no?
> Even if it mutes, every time a channel is changed, it
> will be unmuted, if you put such unmute logic at
> VIDIOC_S_FREQUENCY.
As I said, I propose the automute state to be a separate,
_third_ state. mute/unmute/automute.
Automute state is only set initially, but if the app
explicitly sets any other state, it is no longer affected.
Since an app can't rely on the state before it was
started, it should set the mute state explicitly first.
In this case, it will not be autounmuted after tuning.
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mauro Carvalho Chehab July 23, 2011, 3:09 p.m. UTC | #15
Em 23-07-2011 10:20, Stas Sergeev escreveu:
> 23.07.2011 17:06, Mauro Carvalho Chehab wrote:
>>> I would suggest fixing all such an apps, even if we
>>> are not going to change that in the driver.
>> If application needs to change due to a patch, this is a
>> regression,
> I said "even if we are not going to change that in the
> driver", which, imho, removes any ambiguity from my
> phrase.
> 
>>> But how can scantv (or anything else) rely on the
>>> fact that the board was muted when that app starts?
>>> I guess it can't, and mutes it explicitly first, no?
>> Even if it mutes, every time a channel is changed, it
>> will be unmuted, if you put such unmute logic at
>> VIDIOC_S_FREQUENCY.
> As I said, I propose the automute state to be a separate,
> _third_ state. mute/unmute/automute.
> Automute state is only set initially, but if the app
> explicitly sets any other state, it is no longer affected.
> Since an app can't rely on the state before it was
> started, it should set the mute state explicitly first.
> In this case, it will not be autounmuted after tuning.

Hard to tell about your solution without seeing a patch.

Not sure if this will be consistent, especially if PA
restarts for whatever reason (X restart? manual restart?).

Anyway, we're discussing a lot for a kernel fix for PA,
while the right thing to do is to fix PA itself.

Mauro.
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Stas Sergeev July 23, 2011, 3:14 p.m. UTC | #16
23.07.2011 19:09, Mauro Carvalho Chehab wrote:
>> As I said, I propose the automute state to be a separate,
>> _third_ state. mute/unmute/automute.
>> Automute state is only set initially, but if the app
>> explicitly sets any other state, it is no longer affected.
>> Since an app can't rely on the state before it was
>> started, it should set the mute state explicitly first.
>> In this case, it will not be autounmuted after tuning.
> Hard to tell about your solution without seeing a patch.
I can try making this patch now only if we agree
on the technique first.

> Not sure if this will be consistent, especially if PA
> restarts for whatever reason (X restart? manual restart?).
I mean, this automute is set initially for every
new opening of the device node. So on every start
it will still have an automute mode.

> Anyway, we're discussing a lot for a kernel fix for PA,
> while the right thing to do is to fix PA itself.
I think both parts will better be fixed ideally, but
right now PA will probably not be fixed soon.
If we can agree on the logic, then I may take a
look into coding the patch itself.
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Stas Sergeev July 23, 2011, 3:25 p.m. UTC | #17
23.07.2011 19:09, Mauro Carvalho Chehab wrote:
> Anyway, we're discussing a lot for a kernel fix for PA,
Please note that right now we are discussing the
fix for mplayer or anything else that forgets to
just explicitly enable/disable the audio!
IMHO, that should better be fixed first.
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Stas Sergeev July 24, 2011, 5:45 p.m. UTC | #18
23.07.2011 19:09, Mauro Carvalho Chehab wrote:
> >  In this case, it will not be autounmuted after tuning.
> Hard to tell about your solution without seeing a patch.
OK, it turns out the automute code is already there,
but it doesn't work. The driver for some reasons
starts the scan on initialization, finds the carrier:
---
saa7134[0]/audio: found PAL main sound carrier @ 6.000 MHz [3969/324]
---
and, because of that, disables the automute. If the
real mute is not enabled at that point, you get the
white noise right away.

Since I have no idea why it finds some carrier, I can't
fix that in any way. Or, maybe, not to call the scan
on driver init? What will that break?

Anyway, as long as the automute code is broken,
we should either start fixing it, or fix PA, or fix mplayer...
Dunno. I wonder how come so many bugs left unfixed
for so long, resulting in a white noise to people...
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mauro Carvalho Chehab July 24, 2011, 6:36 p.m. UTC | #19
Em 24-07-2011 14:45, Stas Sergeev escreveu:
> 23.07.2011 19:09, Mauro Carvalho Chehab wrote:
>> >  In this case, it will not be autounmuted after tuning.
>> Hard to tell about your solution without seeing a patch.
> OK, it turns out the automute code is already there,
> but it doesn't work. The driver for some reasons
> starts the scan on initialization, finds the carrier:
> ---
> saa7134[0]/audio: found PAL main sound carrier @ 6.000 MHz [3969/324]
> ---
> and, because of that, disables the automute. If the
> real mute is not enabled at that point, you get the
> white noise right away.

The automute code works fine. Maybe you have a strong interference
at the default tuning frequency, leading into saa7134 miss-detection.

For saa7134 driver:
	1) There is an audio carrier;
	2) an application wants to listen audio;
	3) the device is at automute mode. So, when there's
	   an audio carrier, it will unmute the audio at
	   streaming start.

The driver is doing the _right_ thing by letting the audio to flow
to PA, when it starts the capture.

Unfortunately, on your specific device, starting audio
capture also enables audio at the audio output pin. So,
you're noticing a problem.

People with a saa7134 device without alsa stream won't notice
it (old devices). People with alsa stream without anything
connected to the LINE OUT people aren't noticing it, if PA is
not copying the saa7134 PCM IN stream to the sound card PCM out
device (the default, for PA).

So, only people that has saa7134 with alsa stream that opted
to wire the saa7134 device to the sound card, and with a strong
interference at the default tunning frequency (400 MHz) would
notice a problem.

> Since I have no idea why it finds some carrier, I can't
> fix that in any way. Or, maybe, not to call the scan
> on driver init? What will that break?

Analog tuners need to be tuned at the device init on a high frequency
according with their datasheets, otherwise the PLL may fail.

> Anyway, as long as the automute code is broken,
> we should either start fixing it, or fix PA, or fix mplayer...

As I always said, the fix should be at PA, as it makes no sense
to start capturing at saa7134 without first configuring it.
So, or PA should be converted into a V4L2-aware application, in
order to properly init the device (with seems to be the wrong
approach) or it _SHOULD_NOT_ automatically enable capture on those
devices, as this may cause undesired side effects, on the devices
that have the capture pin directly wired to the output pin, witch 
seems to be the case of your device.

PS.: it seems that you've removed Lennart/alsa people from the c/c.
I'm re-adding them, as I'm expecting a fix from their side.

> Dunno. I wonder how come so many bugs left unfixed
> for so long, resulting in a white noise to people...

You're the first one that reported it, and the code is there for _years_.
So, this is not a commonly noticed problem at all.

Mauro.
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Stas Sergeev July 24, 2011, 7 p.m. UTC | #20
24.07.2011 22:36, Mauro Carvalho Chehab wrote:
> So, only people that has saa7134 with alsa stream that opted
> to wire the saa7134 device to the sound card, and with a strong
> interference at the default tunning frequency (400 MHz) would
> notice a problem.
No, the "strong interference" thing have nothing to
do with it, I think. My card detects signal sometimes,
not always. Otherwise it says this:
---
saa7134[0]/audio: audio carrier scan failed, using 5.500 MHz [default]
---
yet the moise is still there.
If you look into a tvaudio_thread() function, you'll
notice that it disables automute _unconditionally_!
saa7134_tvaudio_do_scan() also disables automute
unconditionally.
That's why I think there are bugs. Can we start
from fixing at least this, and see what happens then?

>> Since I have no idea why it finds some carrier, I can't
>> fix that in any way. Or, maybe, not to call the scan
>> on driver init? What will that break?
> Analog tuners need to be tuned at the device init on a high frequency
> according with their datasheets, otherwise the PLL may fail.
OK.
Maybe, not disabling the automute when the scan
was started at init, rather than when it was requested
by an app?

> You're the first one that reported it, and the code is there for _years_.
> So, this is not a commonly noticed problem at all.
I am only the first one who reported it _to that list_.
I think most other reports were against pulseaudio.
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Stas Sergeev July 25, 2011, 11:15 a.m. UTC | #21
24.07.2011 22:36, Mauro Carvalho Chehab wrote:
> The automute code works fine. Maybe you have a strong interference
> at the default tuning frequency, leading into saa7134 miss-detection.
OK, so my accusation to the automute code is
that it gets disabled unconditionally, no matter
have the scan failed or succeeded. Also, since
that scan is done on driver init, the automute
state stands no chance to survive: it is getting
disabled unconditionally, on the driver init.
Do we agree that this is a bug?
Do we agree that fixing it will also fix the PA problem,
or, at the very least, will advance us a lot in getting
it fixed?
If so, can you take a look into fixing that code?
It seems the automute code is rather fragile right
now, I'd better not touch it if you have some time
to take a look.
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/media/video/saa7134/saa7134-alsa.c b/drivers/media/video/saa7134/saa7134-alsa.c
index 10460fd..cbc665a 100644
--- a/drivers/media/video/saa7134/saa7134-alsa.c
+++ b/drivers/media/video/saa7134/saa7134-alsa.c
@@ -77,7 +77,6 @@  typedef struct snd_card_saa7134 {
 
 	unsigned long iobase;
 	s16 irq;
-	u16 mute_was_on;
 
 	spinlock_t lock;
 } snd_card_saa7134_t;
@@ -718,9 +717,10 @@  static int snd_card_saa7134_capture_close(struct snd_pcm_substream * substream)
 	snd_card_saa7134_t *saa7134 = snd_pcm_substream_chip(substream);
 	struct saa7134_dev *dev = saa7134->dev;
 
-	if (saa7134->mute_was_on) {
+	if (dev->mute_was_on) {
 		dev->ctl_mute = 1;
 		saa7134_tvaudio_setmute(dev);
+		dev->mute_was_on = false;
 	}
 	return 0;
 }
@@ -775,7 +775,7 @@  static int snd_card_saa7134_capture_open(struct snd_pcm_substream * substream)
 	runtime->hw = snd_card_saa7134_capture;
 
 	if (dev->ctl_mute != 0) {
-		saa7134->mute_was_on = 1;
+		dev->mute_was_on = true;
 		dev->ctl_mute = 0;
 		saa7134_tvaudio_setmute(dev);
 	}
diff --git a/drivers/media/video/saa7134/saa7134-tvaudio.c b/drivers/media/video/saa7134/saa7134-tvaudio.c
index 57e646b..535aa75 100644
--- a/drivers/media/video/saa7134/saa7134-tvaudio.c
+++ b/drivers/media/video/saa7134/saa7134-tvaudio.c
@@ -190,6 +190,9 @@  static void mute_input_7134(struct saa7134_dev *dev)
 	struct saa7134_input *in;
 	int ausel=0, ics=0, ocs=0;
 	int mask;
+	bool change_analog_mute;
+
+	change_analog_mute = dev->mute_was_on ? false : true;
 
 	/* look what is to do ... */
 	in   = dev->input;
@@ -204,7 +207,8 @@  static void mute_input_7134(struct saa7134_dev *dev)
 			in = &card(dev).mute;
 	}
 
-	if (dev->hw_mute  == mute &&
+
+	if (dev->hw_mute  == mute && !dev->mute_was_on &&
 		dev->hw_input == in && !dev->insuspend) {
 		dprintk("mute/input: nothing to do [mute=%d,input=%s]\n",
 			mute,in->name);
@@ -216,13 +220,18 @@  static void mute_input_7134(struct saa7134_dev *dev)
 	dev->hw_mute  = mute;
 	dev->hw_input = in;
 
-	if (PCI_DEVICE_ID_PHILIPS_SAA7134 == dev->pci->device)
+	if (PCI_DEVICE_ID_PHILIPS_SAA7134 == dev->pci->device) {
+		u32 mask = ~0;
+		u32 mute_val = SAA7134_MUTE_MASK;
+
+		if (!change_analog_mute)
+			mask ^= SAA7134_MUTE_ANALOG;
+		if (mute)
+			mute_val |= SAA7134_MUTE_I2S | SAA7134_MUTE_ANALOG;
+
 		/* 7134 mute */
-		saa_writeb(SAA7134_AUDIO_MUTE_CTRL, mute ?
-						    SAA7134_MUTE_MASK |
-						    SAA7134_MUTE_ANALOG |
-						    SAA7134_MUTE_I2S :
-						    SAA7134_MUTE_MASK);
+		saa_andorb(SAA7134_AUDIO_MUTE_CTRL, mask, mute_val);
+	}
 
 	/* switch internal audio mux */
 	switch (in->amux) {
@@ -241,7 +250,7 @@  static void mute_input_7134(struct saa7134_dev *dev)
 		saa_andorb(SAA7134_SIF_SAMPLE_FREQ,   0x03, 0x01);
 
 	/* switch gpio-connected external audio mux */
-	if (0 == card(dev).gpiomask)
+	if (0 == card(dev).gpiomask || !change_analog_mute)
 		return;
 
 	mask = card(dev).gpiomask;
@@ -725,6 +734,9 @@  static int mute_input_7133(struct saa7134_dev *dev)
 	u32 xbarin, xbarout;
 	int mask;
 	struct saa7134_input *in;
+	bool change_analog_mute;
+
+	change_analog_mute = dev->mute_was_on ? false : true;
 
 	xbarin = 0x03;
 	switch (dev->input->amux) {
@@ -750,9 +762,8 @@  static int mute_input_7133(struct saa7134_dev *dev)
 
 	saa_writel(0x594 >> 2, reg);
 
-
 	/* switch gpio-connected external audio mux */
-	if (0 != card(dev).gpiomask) {
+	if (0 != card(dev).gpiomask && change_analog_mute) {
 		mask = card(dev).gpiomask;
 
 		if (card(dev).mute.name && dev->ctl_mute)
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index bc8d6bb..ae34f68 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -602,6 +602,7 @@  struct saa7134_dev {
 	int                        ctl_saturation;
 	int                        ctl_freq;
 	int                        ctl_mute;             /* audio */
+	bool			   mute_was_on;
 	int                        ctl_volume;
 	int                        ctl_invert;           /* private */
 	int                        ctl_mirror;