Yuutsuna
Yuutsuna

Reputation: 342

Get the type of an element in GStreamer

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

Upvotes: 0

Views: 549

Answers (1)

Sebastian Dr&#246;ge
Sebastian Dr&#246;ge

Reputation: 2143

How can I filter that list to keep only the GstPulseDevice? How can I check the device type in Rust?

As this is your question, you can do that via

device.type_().name() == "GstPulseDevice"

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.

Upvotes: 1

Related Questions