openDsh / dash

Join us on Slack! https://join.slack.com/t/opendsh/shared_invite/zt-la398uly-a6eMH5ttEQhbtE6asVKx4Q
GNU General Public License v3.0
281 stars 85 forks source link

Potential fix for White Screen with RtAudio enabled #179

Open ekirts-h opened 1 month ago

ekirts-h commented 1 month ago

Issue

Make sure you are running the latest version before reporting an issue.

Hardware

Device Connection Method Screen Mobile Device Android Auto Version
Raspberry Pi 4 2GB USB Cable/wireless 7" Screen pixel 7 v.1.EXAMPLE
Raspberry Pi 3 1GB USB Cable 7" Screen pixel 7 / redmi 9t v.1.EXAMPLE
x86 laptop USB Cable - pixel 7 / redmi 9t v.1.EXAMPLE

Installation Method: Install.sh

Description of problem:

White screen is displayed in place of AA when RtAudio is enabled

Expected Result:

AA is displayed

Problem-relevant steps to reproduce:

enable RtAudio in AA page settings

Additional info:

This fix seems to be working consistently for me testing on ubuntu x86 for debugging, pi4 2gb in use as dash and on a spare rpi3 with fresh raspberry pi os installation. Only pi4 was tested with wireless connection.

Changing this line in openauto/openauto/Projection/RtAudioOutput.cpp (line 36) from LINUX_PULSE to LINUX_ALSA has fixed the white screen problem for me and is working consistently.

    dac_ = std::find(apis.begin(), apis.end(), RtAudio::LINUX_PULSE) == apis.end() ? std::make_unique<RtAudio>() : std::make_unique<RtAudio>(RtAudio::LINUX_PULSE);

to

    dac_ = std::find(apis.begin(), apis.end(), RtAudio::LINUX_ALSA) == apis.end() ? std::make_unique<RtAudio>() : std::make_unique<RtAudio>(RtAudio::LINUX_ALSA);

With pulse when open() is called it seems to fail at if(dac_->getDeviceCount() > 0) for the first two calls completely skipping them then proceeds with third call with devicecount = 1 for samplerate = 16k. I also tested calling it before the if satetement and placing the value into a int variable with try catch but same thing happens. When this happens and the video output section is called it seems nothing is processed (no video stream opened) so a white screen is displayed instead, noticed this when with QTAudio is enabled h264 header replacement code is called but not with RtAudio.

bool RtAudioOutput::open()
{
    std::lock_guard<decltype(mutex_)> lock(mutex_);

    if(dac_->getDeviceCount() > 0)
    {
        RtAudio::StreamParameters parameters;
        parameters.deviceId = dac_->getDefaultOutputDevice();
        parameters.nChannels = channelCount_;
        parameters.firstChannel = 0;

        try
        {
            RtAudio::StreamOptions streamOptions;
            streamOptions.flags = RTAUDIO_MINIMIZE_LATENCY | RTAUDIO_SCHEDULE_REALTIME;
            uint32_t bufferFrames = sampleRate_ == 16000 ? 1024 : 2048; //according to the observation of audio packets
            dac_->openStream(&parameters, nullptr, RTAUDIO_SINT16, sampleRate_, &bufferFrames, &RtAudioOutput::audioBufferReadHandler, static_cast<void*>(this), &streamOptions);
            return audioBuffer_.open(QIODevice::ReadWrite);
        }
        catch(const RtAudioError& e)
        {
            OPENAUTO_LOG(error) << "[RtAudioOutput] Failed to open audio output, what: " << e.what();
        }
    }
    else
    {
        OPENAUTO_LOG(error) << "[RtAudioOutput] No output devices found.";
    }

    return false;
}
memtech3 commented 4 days ago

related to #171