FDH2 / UxPlay

AirPlay Unix mirroring server
GNU General Public License v3.0
1.35k stars 72 forks source link

release audio device after connection destroyed #201

Closed lisbethw1130 closed 1 year ago

lisbethw1130 commented 1 year ago

Hi, I have to give a big thanks for you guys developing such a great software.

I am using UxPlayer with audio mode only uxplay -vs 0 -nh and just found out that UxPlayer don't release audio device after connection closed, if there's other program that want to use same audio device, the later one will fail and have to terminate UxPlayer first

I check whether process is taking control to device using sudo lsof /dev/snd/*

I am not a linux developer so it's hard for me to give any PR but any discussion is appreciated

fduncanh commented 1 year ago

@lisbethw1130,

  1. A better way to listen to audio is with the other method (ALAC audio-only mode) at least from iOS devices (not sure about from macOS). Use the other airplay icon on the iPad or iPhone, etc.

  2. can you give an explicit way to test your issue (what other sound app get blocked) It might be easy to fix with an "audio_renderer_stop" when a connection is dropped.

fduncanh commented 1 year ago

@lisbethw1130

I added an "audio-renderer_stop()" when a connection is terminated. The modified code is in the "testing" branch on github which you should test. Or just edit uxplay.cpp at line 1057

current code

extern "C" void conn_destroy (void *cls) {
    //video_renderer_update_background(-1);
    open_connections--;
    //LOGD("Open connections: %i", open_connections);
    if (open_connections == 0) {
        remote_clock_offset = 0;
    }
}

modified code


extern "C" void conn_destroy (void *cls) {
    //video_renderer_update_background(-1);
    open_connections--;
    //LOGD("Open connections: %i", open_connections);
    if (open_connections == 0) {
        remote_clock_offset = 0;
    if (use_audio) {
      audio_renderer_stop();
      LOGI("stopping audio");
    }
    }
}

Does this fix your issue?

If it does, I'll need to test that it doesn't cause any other problems before updating the "master" branch

lisbethw1130 commented 1 year ago

@fduncanh thank you so much for fast reply! I just tested and it works, it can be test by checking sudo lsof /dev/snd/* and see whether uxplay is still on the list when connection between device closed, if it's not on the list, means the device is released

Another app I use is roon , but it's paid app, it may hard to test

BTW, I also tried to fix by my own lol, I added audio_renderer_stop(); when connection teardown https://github.com/lisbethw1130/UxPlay/commit/eef96b2871581ff7da5bb084053477e46501fd17

but I also see some error message on both solution sometimes, it said


(uxplay:232816): GStreamer-CRITICAL **: 20:34:11.466: _gst_util_uint64_scale: assertion 'denom != 0' failed

(uxplay:232816): GStreamer-CRITICAL **: 20:34:11.466: gst_segment_to_running_time: assertion 'segment->format == format' failed

(uxplay:232816): GStreamer-CRITICAL **: 20:34:11.466: gst_segment_to_stream_time: assertion 'segment->format == format' failed
stopping audio

but except the error message, everything seems fine

fduncanh commented 1 year ago

@lisbethw1130 I dont think those GStreamer messages are related to the fix.

Just to be clear, the fix I posted works for you, right ?

lisbethw1130 commented 1 year ago

yes, this fix works for me

fduncanh commented 1 year ago

@lisbethw1130 thanks for your help in improving uxplay The fix is now in the github master branch