如何setMicrophoneMute()的工作? [英] How does setMicrophoneMute() work?

查看:2821
本文介绍了如何setMicrophoneMute()的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图使用Android的 AudioManager.setMicrophoneMute()没有取得多大成功。也就是说,它只是拒绝麦克风静音,无论我做什么。

I have been trying to use Android's AudioManager.setMicrophoneMute() without much success. That is, it simply refuses to mute the microphone, no matter what I do.

我在网上搜索了一些线索,我发现了几个报告提到类似的经历:

I searched the web for some clues and I found several references reporting similar experience:

  • <一个href="http://groups.google.com/group/android-developers/browse_thread/thread/cf57da02446e424a">AudioManger.setMicrophoneMute功能不工作?
  • <一个href="http://stackoverflow.com/questions/5217437/setmicrophonemuteboolean-doesnt-work-on-some-devices">setMicrophoneMute(boolean)不能在某些设备
  • 无法在Android的
  • 麦克风静音
  • AudioManger.setMicrophoneMute functionality not working??
  • setMicrophoneMute(boolean) doesn't work on some devices
  • Unable to mute the microphone in Android

这引出了一个问题:是否 AudioManager.setMicrophoneMute()的工作呢?难道只是一个存根方法,等待被Android中的一些未来的版本中实现?如果不是,它是如何工作的?我需要做什么,使其工作?什么是使其工作作为它的名字所暗示的条件?

Which begs the question: Does AudioManager.setMicrophoneMute() work at all? Is it only a stub method, waiting to be implemented in some future version of Android? If not, how does it work? What do I need to make it work? What are the conditions that make it work as its name implies?

编辑:我注意到,此方法的文件说:

I noticed that the documentation for this method says:

此方法仅用于那些的应用程序替换的的   音频设置或主电话平台级管理   应用程序。

This method should only be used by applications that replace the platform-wide management of audio settings or the main telephony application.

这是什么意思?为什么我要更换平台范围的管理?我真的需要做到这一点?如果是这样,我该怎么做呢?

What does this mean? Why would I want to replace the platform-wide management? Do I really need to do that? If so, how do I do that?

编辑:下面的答案是伟大的,但我还是不明白:

The answer below is great but I still don't understand:

  1. 这是怎么回事标志(SET_MIC_MUTE数据库)所用?
  2. 在当前没有这个标记居然断开麦克风信号 手机内部的pre放大电路?
  3. 如果不这样做,谁做的?
  4. 如果没有这样做,这是怎么静音预计工作?
  1. How is that flag (SET_MIC_MUTE in database) being used?
  2. When does this flag actually disconnect the microphone signal from the pre-amplifier circuit inside the phone?
  3. If it doesn't do that, who does that?
  4. If nothing does that, how is this "mute" expected to work?

请解释一下。谢谢你。

推荐答案

要详细说明an00b:上述回答是,我们必须更深入地源$ C ​​$ C问题的编辑的版本。 IAudioflinger是接口至AudioFlinger服务并调用

To elaborate on an00b:s answer above and the edited version of the question we have to dig deeper into the source code. IAudioflinger is the interface to the AudioFlinger service and the call to

virtual status_t setMicMute(bool state)
{
    Parcel data, reply;
    data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
    data.writeInt32(state);
    remote()->transact(SET_MIC_MUTE, data, &reply);
    return reply.readInt32();
}

其实是活页夹的交易麦克风静音。活页夹电话的接收端是这样的:

is actually the Binder transaction to mute the microphone. The receiving side of the Binder call looks like:

     status_t BnAudioFlinger::onTransact(
        uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
    { 
 switch(code) {
...
 case SET_MIC_MUTE: {
            CHECK_INTERFACE(IAudioFlinger, data, reply);
            int state = data.readInt32();
            reply->writeInt32( setMicMute(state) );
            return NO_ERROR;
        } break;
...
}}

和调用setMicMute在实际执行<一个href="http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=services/audioflinger/AudioFlinger.cpp;h=c68e20d6304072d88f7a79180ffe845b5ad0eac1;hb=a8313e71fe8b483448d14e22610101c5f3672744">AudioFlinger.下一步是看这个功能:

and calls to the actual implementation of setMicMute in the AudioFlinger. Next step is to look at this function:

   status_t AudioFlinger::setMicMute(bool state)
{
    // check calling permissions
    if (!settingsAllowed()) {
        return PERMISSION_DENIED;
    }

    AutoMutex lock(mHardwareLock);
    mHardwareStatus = AUDIO_HW_SET_MIC_MUTE;
    status_t ret = mAudioHardware->setMicMute(state);
    mHardwareStatus = AUDIO_HW_IDLE;
    return ret;
}

在这里,我们可以看到两件事情。第一个是有权限检查,以便能够使麦克风静音。被检查的权限在settingsAllowed是android.permission.MODIFY_AUDIO_SETTINGS从而上文为静音麦克风首先要求的意见之一是,你的应用程序已经宣布,它需要这个权限。接下来的事情要注意的是,我们现在称之为中setMicMute使用mAudioHardware-> setMicMute(州)硬件特定版本。

Here we can note two things. The first is that there is a permissions check to be able to mute the microphone. The permission being checked for in settingsAllowed is android.permission.MODIFY_AUDIO_SETTINGS so as mentioned in one of the comments above the first requirement for muting the microphone is that your application has declared that it needs this permission. The next thing to note is that we now call in to the hardware specific version of setMicMute using mAudioHardware->setMicMute(state).

有关硬件是否插研究文件AudioHardwareInterface.cpp的方式更多信息。基本上,它结束了在与外部C调用createAudioHardware其插入在正确的AudioHardWare为平台libhardware。还有开关用于使用基于A2DP硬件,通用一个用于仿真器和捻熄音频。假设您正在实际设备上的实现则取决于非常多的硬件。为了感受一下它,我们可以使用来自克雷斯波(歌Nexus S)可用audiohardware作为一个例子。

For more info on the way the hardware is plugged study the file AudioHardwareInterface.cpp. Basically it ends up in a libhardware with an extern C call to createAudioHardware which plugs in the correct AudioHardWare for the platform. There are also switches for using an A2DP based hardware, a generic one for the emulator and stubbing the audio. Assumed that you are working on an actual device the implementation is then very much hardware depending. To get a feel for it we can use the available audiohardware from Crespo (Nexus S) as an example.

    status_t AudioHardware::setMicMute(bool state)
{
    LOGV("setMicMute(%d) mMicMute %d", state, mMicMute);
    sp<AudioStreamInALSA> spIn;
    {
        AutoMutex lock(mLock);
        if (mMicMute != state) {
            mMicMute = state;
            // in call mute is handled by RIL
            if (mMode != AudioSystem::MODE_IN_CALL) {
                spIn = getActiveInput_l();
            }
        }
    }

    if (spIn != 0) {
        spIn->standby();
    }

    return NO_ERROR;
}

根据这个例子中,我们可以换了音频路由的智能手机实施的讨论。如果你不是在通话中你可以在克雷斯波执行看到麦克风静音通话将只能得到尊重。这样做的原因是,音频通过模拟基带用于处理功率调节,放大和其他东西路由。当在一个呼叫的语音音频通常由模拟​​基带和调制解调器的CPU一起处理,并且不被路由throught应用CPU。在这种情况下,你可能需要经历通过RIL调制解调器CPU,以使麦克风静音。但由于这种行为是依赖于硬件,没有通用的解决方案。

Based on this example we may wrap up with a discussion of the implementation of audio routing in smartphones. As you can see in the Crespo implementation the mic mute call will only be respected if you are not in a call. The reason for this is that audio is routed through the analog baseband which handles power regulation, amplification and other things. When in a call the voice audio is often handled by analog baseband and modem CPU together and is not routed throught the application CPU. In that case you may need to go through the modem CPU through the RIL in order to mute the microphone. But since this behavior is hardware dependent there is no general solution.

要给予短版到你的另外4个问题:

To give the short version to your 4 additional questions:

  1. 该标志将被传递通过code几层,直到它结束了在硬件特定静音麦克风。

  1. The flag is passed on through several layers of code until it ends up in the hardware specific mute microphone.

在硬件特定code的运行,除了麦克断开时,在通话中,至少在某些设备上。

The mic is disconnected when the hardware specific code has run except when in a call at least on some devices.

在setMicrophoneMute不静音麦克风,即在通话的时候有可能做到这一点使用电话API之一:S,我建议学习的手机应用程序

When setMicrophoneMute does not mute the mic, i.e. when in a call it may be possible to do that using one of the telephony API:s, I would suggest studying the phone app.

根据当前实现静音似乎工作的时候没有处于通话状态,但有可能是我们没有在这里学习的平台硬件的具体问题。

Based on the current implementation mute seems to work when not in a call but there may be hardware specific issues on platforms we have not studied here.

编辑:

做了一些更多的挖掘装置和发送静音命令到调制解调器的CPU的方式是通过内部电话接口,它是com.android.internal.telephony包是不提供给开发者的SDK的一部分。根据该意见,你看到这个功能只能用于那些更换音频管理还是原来的电话应用程序,我猜想,AudioManager.setMicrophoneMute()应该话筒始终静音不管应用程序。但是,由于其他应用程序可能使用此,他们为了增加在硬件实现支票不要乱了电话应用程序,跟踪静音连接以及麦克风的状态。该功能可能无法正常运转的应该是,现在由于硬件实现的细节和事实,即静音是一个更复杂的操作比人们最初的想象考虑通话状态时,也是如此。

Did some more digging and the way to send a mute command to the modem CPU is via the internal Phone interface that is part of the com.android.internal.telephony package that is not available to SDK developers. Based on the comment you saw that this function should only be used by applications that replace audio management or the original telephony application I would guess that AudioManager.setMicrophoneMute() was supposed to always mute the microphone regardless. But since other applications probably use this they added a check in the hardware implementation in order not to mess up the state of the phone application which keeps track of muted connections as well as the microphone. The function is probably not working as supposed to right now due to hardware implementation details and the fact that mute is a much more complex operation than one would initially think when considering call states as well.

这篇关于如何setMicrophoneMute()的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆