MacOS自定义音频驱动不覆盖默认驱动。

huangapple go评论57阅读模式
英文:

MacOS custom Audio Driver doesn't override the default Driver

问题

我们正在为USB麦克风开发自定义音频驱动程序,以便对输入音频流进行简单处理(类似于Windows的APO)。经过一些帮助,我们成功将我们的驱动程序(基于SimpleAudioDriver)分配给了正确的音频设备。但现在有两个设备显示出来:一个分配了我们的驱动程序,另一个分配了默认驱动程序。如何覆盖原来的设备,只显示一个设备?

我们已经尝试添加更多的IOKitPersonalities以获得更好的探测分数,但结果相同。我们还阅读了日志,原始驱动程序和我们的探测分数都是最大值(100000)。

以下是我们info.plist文件的当前状态:

<plist version="1.0">
<dict>
	<key>IOKitPersonalities</key>
	<dict>
		<key>SimpleAudioDriver</key>
		<dict>
			<key>idProduct</key>
			<integer>49456</integer>
			<key>idVendor</key>
			<integer>1130</integer>
			<key>CFBundleIdentifier</key>
			<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
			<key>IOClass</key>
			<string>IOUserService</string>
			<key>IOMatchCategory</key>
			<string>SimpleAudioDriver</string>
			<key>IOProviderClass</key>
			<string>IOUSBDevice</string>
			<key>IOResourceMatch</key>
			<string>IOKit</string>
			<key>IOUserAudioDriverUserClientProperties</key>
			<dict>
				<key>IOClass</key>
				<string>IOUserUserClient</string>
				<key>IOUserClass</key>
				<string>IOUserAudioDriverUserClient</string>
			</dict>
			<key>IOUserClass</key>
			<string>SimpleAudioDriver</string>
			<key>IOUserServerName</key>
			<string>com.example.apple-samplecode.SimpleAudio.Driver</string>
			<key>SimpleAudioDriverUserClientProperties</key>
			<dict>
				<key>IOClass</key>
				<string>IOUserUserClient</string>
				<key>IOUserClass</key>
				<string>SimpleAudioDriverUserClient</string>
			</dict>
		</dict>
	</dict>
</dict>
</plist>

如果您有任何提示,请与我们联系。

谢谢。

英文:

We are developing a custom audio driver for a USB microphone in order to do simple processing (EQs) on the input audio stream (comparable to an APO for Windows).
After some help, we managed to assign our Driver (based on the SimpleAudioDriver) to the right audio device. But we now have two devices showing up : one is assigned with our driver and the other one is assigned to the default driver. How can we override the original one with ours, to just have one device showing up ?

We already tried to add more IOKitPersonalities to have a better probe score but it's the same.
We also read the logs and the original driver and our probe score are both at the maximum (100000).

Here is the current state of our info.plist file :

&lt;plist version=&quot;1.0&quot;&gt;
&lt;dict&gt;
	&lt;key&gt;IOKitPersonalities&lt;/key&gt;
	&lt;dict&gt;
		&lt;key&gt;SimpleAudioDriver&lt;/key&gt;
		&lt;dict&gt;
			&lt;key&gt;idProduct&lt;/key&gt;
			&lt;integer&gt;49456&lt;/integer&gt;
			&lt;key&gt;idVendor&lt;/key&gt;
			&lt;integer&gt;1130&lt;/integer&gt;
			&lt;key&gt;CFBundleIdentifier&lt;/key&gt;
			&lt;string&gt;$(PRODUCT_BUNDLE_IDENTIFIER)&lt;/string&gt;
			&lt;key&gt;IOClass&lt;/key&gt;
			&lt;string&gt;IOUserService&lt;/string&gt;
			&lt;key&gt;IOMatchCategory&lt;/key&gt;
			&lt;string&gt;SimpleAudioDriver&lt;/string&gt;
			&lt;key&gt;IOProviderClass&lt;/key&gt;
			&lt;string&gt;IOUSBDevice&lt;/string&gt;
			&lt;key&gt;IOResourceMatch&lt;/key&gt;
			&lt;string&gt;IOKit&lt;/string&gt;
			&lt;key&gt;IOUserAudioDriverUserClientProperties&lt;/key&gt;
			&lt;dict&gt;
				&lt;key&gt;IOClass&lt;/key&gt;
				&lt;string&gt;IOUserUserClient&lt;/string&gt;
				&lt;key&gt;IOUserClass&lt;/key&gt;
				&lt;string&gt;IOUserAudioDriverUserClient&lt;/string&gt;
			&lt;/dict&gt;
			&lt;key&gt;IOUserClass&lt;/key&gt;
			&lt;string&gt;SimpleAudioDriver&lt;/string&gt;
			&lt;key&gt;IOUserServerName&lt;/key&gt;
			&lt;string&gt;com.example.apple-samplecode.SimpleAudio.Driver&lt;/string&gt;
			&lt;key&gt;SimpleAudioDriverUserClientProperties&lt;/key&gt;
			&lt;dict&gt;
				&lt;key&gt;IOClass&lt;/key&gt;
				&lt;string&gt;IOUserUserClient&lt;/string&gt;
				&lt;key&gt;IOUserClass&lt;/key&gt;
				&lt;string&gt;SimpleAudioDriverUserClient&lt;/string&gt;
			&lt;/dict&gt;
		&lt;/dict&gt;
	&lt;/dict&gt;
&lt;/dict&gt;
&lt;/plist&gt;

If you have any hints, please get back to us.

Thanks.

答案1

得分: 5

这是一个示例驱动程序,不匹配任何真实硬件,而是连接到虚拟的“resources”模块:

<key>IOProviderClass</key>
<string>IOUserResources</string>

这是一个通用的对象,除了存在以供虚拟驱动程序附加之外,不执行任何操作。默认情况下,对象只能成功匹配一个客户端(即驱动程序),因此虚拟驱动程序将争夺对此虚拟对象的访问权。因此,在仅匹配此对象时,您需要使用匹配类别:

<key>IOMatchCategory</key>
<string>SimpleAudioDriver</string>

但是,在匹配真实硬件时,绝对不要使用此键,除非您有非常充分的理由。如果保留此键,您的驱动程序的匹配类别将与Apple的默认驱动程序不同,因此两者都将匹配设备,导致混乱。

为了避免多个驱动程序尝试声明相同的设备,只需删除整个IOMatchCategory键/值对,以使用默认类别,这也是标准的macOS USB音频驱动程序使用的类别,因此只有一个驱动程序将成功匹配。哪个驱动程序成功匹配可以通过不同USB匹配模式的不同探测得分级别或在不寻常情况下,使用显式的探测得分来控制。

英文:

The sample driver doesn't match any real hardware, but instead attaches itself to the dummy "resources" nub:

			&lt;key&gt;IOProviderClass&lt;/key&gt;
			&lt;string&gt;IOUserResources&lt;/string&gt;

This is a generic object that does nothing other than exist so that virtual drivers can attach. By default, objects can only be successfully be matched by one client (i.e. driver), so virtual drivers would fight over access to this dummy object. So when matching this object only, you need to use match categories:

            &lt;key&gt;IOMatchCategory&lt;/key&gt;
            &lt;string&gt;SimpleAudioDriver&lt;/string&gt;

However, you must absolutely not use this key when matching real hardware, unless you have a very good reason. If you keep this in, your driver's match category will be different from Apple's default driver, so both will match the device, leading to chaos.

To avoid multiple drivers trying to claim the same device, simply remove the entire IOMatchCategory key/value pair to use the default category, which is also what the standard macOS USB audio driver uses, and therefore only one driver will succeed at matching. Which one wins can be controlled via the different probe score levels for different USB matching patterns or, in unusual cases, using an explicit probe score.

huangapple
  • 本文由 发表于 2023年2月16日 17:44:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75470423.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定