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?
            Asked
            
        
        
            Active
            
        
            Viewed 150 times
        
    0
            
            
        - 
                    1Are you mixing C and C++? Your post talks about C, but you also have C++ tagged. I highly recommend against mixing the languages. For example, C++ has operator and function overloading which may make calling C++ from C a bit difficult. Then there's the case of inheritance, which C doesn't have. If you are expecting code, StackOverflow is not a code producing site; so update your tags. – Thomas Matthews Mar 11 '23 at 01:16
 - 
                    1Maybe you just try connecting to pipewire? – user253751 Mar 11 '23 at 01:35
 - 
                    https://docs.pipewire.org/index.html everything is there. Did you try to find it yourself? – 0___________ Mar 11 '23 at 01:45
 - 
                    @user253751 That would make more sense to me if pw_init wasn't a void function. I see no mention of detecting errors. – cecil Mar 11 '23 at 03:17
 - 
                    @ThomasMatthews PipeWire has a C API and is usable by both languages. The solution need not be different between the two. – cecil Mar 11 '23 at 03:19
 
1 Answers
0
            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
    }
}
        neon mike
        
- 57
 - 1
 - 6