thestr4ng3r / chiaki

Moved to https://git.sr.ht/~thestr4ng3r/chiaki - Free and Open Source PS4 Remote Play Client
https://git.sr.ht/~thestr4ng3r/chiaki
2.17k stars 373 forks source link

Suggestion for fixing the Audio on Raspbian! #376

Closed Fredrum closed 3 years ago

Fredrum commented 3 years ago

Environment

Describe the bug Qt is not able to find the correct Audio output device on its own. Also Qt is not able to pick the right Audio plugin when both Alsa and PulseAudio are present. This results in no sound on Raspbian. My previous Qt5.12 fix was a red herring, the reason it worked was that it didn't have the Pulse Qt plugin, only the Alsa plugin, so qt had to default to Alsa.

To Reproduce Steps to reproduce the behavior:

  1. Build Chiaki as usual on Raspbian without Qt5.12
  2. Start a game session.
  3. No sound will be heard.

Expected behavior Alsa should be available without special Qt hacks. Audio should work by default.

Additional context @tomblind discovered that if he removed the /usr/lib/arm-linux-gnueabihf/qt5/plugins/audio/libqtmedia_pulse.so file then Qt defaulted to Alsa and he could hear the sound even with the regular Qt5.

Based on that I went back to the code and now have it working with the regular Qt5 install. No 5.12 version needed.

In streamsession.cpp: (just to show what does work)

       //Commented out as it returns null or nothing on Raspbian.
       //QAudioDeviceInfo audio_device_info(QAudioDeviceInfo::defaultOutputDevice());

    // try pick Alsa if available ("default" on my Raspbian)
    QAudioDeviceInfo audio_device_info;
    QString user_device_name = "default";
    for (QAudioDeviceInfo di : QAudioDeviceInfo::availableDevices(QAudio::AudioOutput))
    {
        //printf("DEVICE:  %s\n", di.deviceName().toLocal8Bit().constData());
        if(di.deviceName() == user_device_name)
        {
            //printf("Will Use Audio Device:  %s\n", di.deviceName().toLocal8Bit().constData());
            audio_device_info = di;
        }
    }

then further down we need to add this device info,

audio_output = new QAudioOutput(audio_device_info, audio_format, this);

I suggest that we add a popup menu in the settings gui where we cross match a premade list of audiodevices maybe even just "default" and "pulse", with what comes up when doing availableDevices(). The intersection would populate the popup menu.

"default" should be chosen as default if present.

That would enable Alsa sound straight away without user having to do anything and people who want to set up with PulseAudio can still do that.

And I could remove Qt5.12 from the install process for Raspian!

Cheers Fred

Fredrum commented 3 years ago

I'll start doing something for this. Does anyone know what other computers' defaults are? I could just expose the full availableDevices() but there's a lot of non intuitive entries there.

tomblind commented 3 years ago

I would recommend exposing them all. Someone who needs a particular device would be frustrated if it was left intentionally unlisted.

Fredrum commented 3 years ago

Added a pull request Adding audio device selection #377, @thestr4ng3r