0

I have a raspberry pi 4, and pulseaudio 9 running on it. I am writing a custom pulseaudio module which will load the 3 available sound cards - hdmi1, hdmi2 and headphones. the command i am using is

    static void load_lineout_alsa_sink(struct userdata *u, int soundcardNo, int  deviceNo, int status, int  islineout)
        {
            pa_assert(u);
            int sink = 0;
            char *args = NULL;
            /* Request for lineout loading
            * Load Alsa Sink Module
            * Send Error To AudioD in case Alsa sink Load fails
            */
            pa_log("[alsa sink loading begins for lineout] [AudioD sent] cardno = %d playback device number = %d de

viceName = %s",\
            soundcardNo, deviceNo, u->deviceName);
        if (islineout)
        {
            if (u->alsa_sink == NULL)
            {
                char *args = NULL;
                args = pa_sprintf_malloc("device=hw:%d,%d mmap=0 sink_name=%s fragment_size=4096 tsched=0", soundcardNo, 0, u->deviceName);
                u->alsa_sink = pa_module_load(u->core, "module-alsa-sink", args);
                if (args)
                    pa_xfree(args);
                if (!u->alsa_sink)
                {
                    pa_log("Error loading in module-alsa-sink for pcm_output");
                    return;
                }
            }
            else if (u->alsa_sink1 == NULL)
            {
                char *args = NULL;
                args = pa_sprintf_malloc("device=hw:%d,%d mmap=0 sink_name=%s fragment_size=4096 tsched=0", soundcardNo, 0, u->deviceName);
                u->alsa_sink1 = pa_module_load(u->core, "module-alsa-sink", args);
                if (args)
                    pa_xfree(args);
                if (!u->alsa_sink1)
                {
                    pa_log("Error loading in module-alsa-sink for pcm_output");
                    return;
                }
                pa_log_info("module-alsa-sink loaded for pcm_output");
            }
        }
        else
        {
            if (u->headphone_sink == NULL)
            {
                char *args = NULL;
                args = pa_sprintf_malloc("device=hw:%d,%d mmap=0 sink_name=%s fragment_size=4096 tsched=0", soundcardNo, 0, u->deviceName);
                u->headphone_sink = pa_module_load(u->core, "module-alsa-sink", args);
                if (args)
                    pa_xfree(args);
                if (!u->headphone_sink)
                {
                    pa_log("Error loading in module-alsa-sink for pcm_headphone");
                    return;
                }
                pa_log_info("module-alsa-sink loaded for pcm_headphone");
            }
        }
        if (args)
            pa_xfree(args);
        pa_log_info("module-alsa-sink loaded");
    }


void load_alsa_sinks()
{
    u->deviceName = pcm_output
    load_lineout_alsa_sink(u, 0, 0, 1, 1);
    u->deviceName = pcm_output1
    load_lineout_alsa_sink(u, 0, 1, 1, 1);
    u->deviceName = pcm_headphone
    load_lineout_alsa_sink(u, 0, 2, 1, 0);
}

Issue is that once I load the second sound card, pulseaudio hangs. I have to reboot the raspberry pi to get it running again. what could be the mistake here?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.