How to test if PipeWire is running in C?

341 Views Asked by At

I would like to write a C program to test if PipeWire is running. If it's not I will fallback to using ALSA. What's a good way to accomplish this?

1

There are 1 best solutions below

0
Robinson yuan On BEST ANSWER

test if PipeWire is running in C is to use the PipeWire API to check the availability of its core object.


gcc -o test test.c -lpipewire-0.3

#include <pipewire/pipewire.h>
int main() {
    pw_init(NULL, NULL); // initialize the PipeWire library
    struct pw_core *core = pw_context_connect(pw_context_new(NULL, NULL), NULL, 0); // connect to the PipeWire core
    if (core != NULL) { // check if the connection was successful
        pw_core_disconnect(core); // disconnect from the PipeWire core
        return 0; // PipeWire is running, exit with success code
    } else {
        return 1; // PipeWire is not running, exit with error code
    }
}