获取GSTREAMER中元素的类型
我正在使用DeviceMonitor,以获取GSTREAMER中的音频源。 有我无法使用的音频源(我得到了“设备由另一个应用程序使用”)
,我有一个微插入,当我打印设备时,我看到有一个gstpulsedevice
。 这是确切的输出:
[Device(ObjectRef { inner: 0x7fad8000cbf0, type: GstPulseDevice }), Device(ObjectRef { inner: 0x7fad7c00de40, type: GstAlsaDevice }), Device(ObjectRef { inner: 0x7fad7c00dd80, type: GstAlsaDevice })]
这是板条箱我正在使用,我使用的代码我是使用(直到它破裂,因为GSTREAMER不提供属性device.bus_path
再提供):
pub fn get_audio_source() -> Option<Element> {
let monitor = DeviceMonitor::new();
monitor.add_filter(Some("Audio/Source"), None);
monitor.set_show-all(false); // Removing the hidden devices
monitor.start().unwrap();
let src = monitor.devices()
.iter()
.filter(|device| {
let bus_path: Result<String, GetError> = device.properties().unwrap().get("device.bus_path");
return bus_path.is_ok() && bus_path.unwrap() == "pci-0000:00:14.0-usb-0:3:1.2"
})
.map(|device| device.create_element(None).unwrap())
.next();
if src.is_some() {
src.as_ref().unwrap().set_property("do-timestamp", true).unwrap();
}
monitor.stop();
return src
}
这是我在monitor.devices()中为x执行x的输出 {dbg!(x.properties()); } :
[src/utils/device_utils.rs:65] x.properties() = Some(
Structure(
"pulse-proplist, device.description=(string)\"Monitor\\ of\\ Built-in\\ Audio\\ Digital\\ Stereo\\ \\(HDMI\\ 2\\)\", device.class=(string)monitor, alsa.card=(string)1, alsa.card_name=(string)\"HDA\\ Intel\\ HDMI\", alsa.long_card_name=(string)\"HDA\\ Intel\\ HDMI\\ at\\ 0xf7134000\\ irq\\ 51\", alsa.driver_name=(string)snd_hda_intel, device.bus_path=(string)pci-0000:00:03.0, sysfs.path=(string)/devices/pci0000:00/0000:00:03.0/sound/card1, device.bus=(string)pci, device.vendor.id=(string)8086, device.vendor.name=(string)\"Intel\\ Corporation\", device.product.id=(string)160c, device.product.name=(string)\"Broadwell-U\\ Audio\\ Controller\", device.form_factor=(string)internal, device.string=(string)1, module-udev-detect.discovered=(string)1, device.icon_name=(string)audio-card-pci, is-default=(boolean)true;",
),
)
[src/utils/device_utils.rs:65] x.properties() = Some(
Structure(
"alsa-proplist, device.api=(string)alsa, device.class=(string)sound, alsa.card=(int)2, alsa.card_name=(string)\"HDA\\ Intel\\ PCH\", alsa.driver_name=(string)HDA-Intel, alsa.name=(string)\"HDA\\ Intel\\ PCH\", alsa.id=(string)PCH, alsa.mixername=(string)\"Realtek\\ ALC283\", alsa.components=(string)\"HDA:10ec0283\\,80862057\\,00100003\";",
),
)
[src/utils/device_utils.rs:65] x.properties() = Some(
Structure(
"alsa-proplist, device.api=(string)alsa, device.class=(string)sound, alsa.card=(int)0, alsa.card_name=(string)\"OBSBOT\\ Tiny\", alsa.driver_name=(string)USB-Audio, alsa.name=(string)\"OBSBOT\\ Tiny\", alsa.id=(string)Tiny, alsa.mixername=(string)\"USB\\ Mixer\", alsa.components=(string)USB6e30:fef0;",
),
)
如何过滤该列表以仅保留gstpulsedevice
?如何检查Rust的设备类型?
编辑:添加代码和板条箱链接 edit2:添加设备属性的调试输出
I'm using the DeviceMonitor in order to get the audio source available in GStreamer.
There are audio sources that I cannot use (I get a "Device is used by another application")
I have a micro plugged and when I print the devices I see there is a GstPulseDevice
.
Here's the exact output:
[Device(ObjectRef { inner: 0x7fad8000cbf0, type: GstPulseDevice }), Device(ObjectRef { inner: 0x7fad7c00de40, type: GstAlsaDevice }), Device(ObjectRef { inner: 0x7fad7c00dd80, type: GstAlsaDevice })]
Here's the crate I'm using and the code I was using (until it broke because gstreamer doesn't provide the property device.bus_path
anymore):
pub fn get_audio_source() -> Option<Element> {
let monitor = DeviceMonitor::new();
monitor.add_filter(Some("Audio/Source"), None);
monitor.set_show-all(false); // Removing the hidden devices
monitor.start().unwrap();
let src = monitor.devices()
.iter()
.filter(|device| {
let bus_path: Result<String, GetError> = device.properties().unwrap().get("device.bus_path");
return bus_path.is_ok() && bus_path.unwrap() == "pci-0000:00:14.0-usb-0:3:1.2"
})
.map(|device| device.create_element(None).unwrap())
.next();
if src.is_some() {
src.as_ref().unwrap().set_property("do-timestamp", true).unwrap();
}
monitor.stop();
return src
}
Here's the output when I do for x in monitor.devices() { dbg!(x.properties()); }
:
[src/utils/device_utils.rs:65] x.properties() = Some(
Structure(
"pulse-proplist, device.description=(string)\"Monitor\\ of\\ Built-in\\ Audio\\ Digital\\ Stereo\\ \\(HDMI\\ 2\\)\", device.class=(string)monitor, alsa.card=(string)1, alsa.card_name=(string)\"HDA\\ Intel\\ HDMI\", alsa.long_card_name=(string)\"HDA\\ Intel\\ HDMI\\ at\\ 0xf7134000\\ irq\\ 51\", alsa.driver_name=(string)snd_hda_intel, device.bus_path=(string)pci-0000:00:03.0, sysfs.path=(string)/devices/pci0000:00/0000:00:03.0/sound/card1, device.bus=(string)pci, device.vendor.id=(string)8086, device.vendor.name=(string)\"Intel\\ Corporation\", device.product.id=(string)160c, device.product.name=(string)\"Broadwell-U\\ Audio\\ Controller\", device.form_factor=(string)internal, device.string=(string)1, module-udev-detect.discovered=(string)1, device.icon_name=(string)audio-card-pci, is-default=(boolean)true;",
),
)
[src/utils/device_utils.rs:65] x.properties() = Some(
Structure(
"alsa-proplist, device.api=(string)alsa, device.class=(string)sound, alsa.card=(int)2, alsa.card_name=(string)\"HDA\\ Intel\\ PCH\", alsa.driver_name=(string)HDA-Intel, alsa.name=(string)\"HDA\\ Intel\\ PCH\", alsa.id=(string)PCH, alsa.mixername=(string)\"Realtek\\ ALC283\", alsa.components=(string)\"HDA:10ec0283\\,80862057\\,00100003\";",
),
)
[src/utils/device_utils.rs:65] x.properties() = Some(
Structure(
"alsa-proplist, device.api=(string)alsa, device.class=(string)sound, alsa.card=(int)0, alsa.card_name=(string)\"OBSBOT\\ Tiny\", alsa.driver_name=(string)USB-Audio, alsa.name=(string)\"OBSBOT\\ Tiny\", alsa.id=(string)Tiny, alsa.mixername=(string)\"USB\\ Mixer\", alsa.components=(string)USB6e30:fef0;",
),
)
How can I filter that list to keep only the GstPulseDevice
? How can I check the device type in Rust?
Edit: Adding code and crate link
Edit2: Adding debug output for the device properties
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于这是您的问题,您可以通过这件事来做到这一点
,但是正如其他评论所提到的那样,这可能不是您的问题,但是Pulseaudio不会检测到您的音频设备。在您的列表中,仅通过PulseAudio使用监视器设备,并且仅通过ALSA直接使用实际设备。
您的脉冲设置存在某种问题。
As this is your question, you can do that via
But as the other comment mentioned this is likely not your problem but that PulseAudio does not detect your audio device. In your list there's only the monitor device via PulseAudio, and the actual device only via ALSA directly.
There's some kind of problem with your PulseAudio setup.