-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[pulseaudio] Apply real disconnection when needed #13338
[pulseaudio] Apply real disconnection when needed #13338
Conversation
The isIdle boolean was not properly handled. When disconnection is called, isIdle is not relevant : we should always honnor the disconnection request. In fact, isIdle prevented disconnection when it is necessary (example : when a IOException occurs when sending audio to sink) +Little bug fix on volume parsing: some volume request doesn't respond with a space after the comma separating left/right channel. Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
The "isidle" logic attempts to prevent closing the connection for a while to speed up the response time when you are using it frequently (for example when using it with the dialog processor implementation), it was not implemented by me but doesn't seems like something we want to remove. |
Have reviewed the code and I was wrong, the disconnect method just closes the socket, do not instruct the pulseaudio server to close the "Simple TCP Stream" protocol port, but still the next usage will require to check if this port is available plus reopening the connection so I don't think is a bad idea to keep the "isidle" logic if we can fix the issue in another way. |
Thank you for checking this PR ! So, if I want to sum up, as far as I understand it, the isIdle boolean is :
So it prevents the socket from being disconnect, when we are playing or recording a sound. The situations, when we want to disconnect, are : I think we should implement it this way: canceling the scheduledDisconnection when the socket is opened/used, instead of not closing it at the scheduledDisconnection timeout expiration if the socket is in use. I will add a commit to this PR to take the third point in consideration. |
So, PR is not yet ready for review & merge ? |
Using a counter to count client instead of a isIdle variable, which was not thread safe. The PulseaudioSimpleProtocolStream parent class is now the sole responsible for closing source or sink stream. Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
Avoid a costly synchronized operation for a method called very often. Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
This PR is now ready for a second review. After the judicious comment from @GiviMAD , I complete my initial proposal with a rewrited system for the idle -> disconnection functionnality. Instead of simply deleting the isIdle variable (which as I said in the OP was faulty and prevented in some case a needed healing disconnection) I now propose using a count of the clients using the connection, and giving it the responsibility of scheduling optional disconnection.
Alternatively, the connectIfNeeded method can also schedule a disconnection. Indeed, using solely the end of an operation to schedule a disconnection is not sufficient because the handler also initiate a dumb connection at startup, without operation, with the goal to check connectivity. I tested this solution with a sink (with a TTS) and with a source (using rustpotter KS and volk STT) and it works. Additionnaly, I made a little enhancement to avoid using a synchronized method for a method called very often. |
....pulseaudio/src/main/java/org/openhab/binding/pulseaudio/internal/PulseAudioAudioSource.java
Show resolved
Hide resolved
....pulseaudio/src/main/java/org/openhab/binding/pulseaudio/internal/PulseAudioAudioSource.java
Show resolved
Hide resolved
Hey @dalgwen, I let you a couple of comments, but it seems like a great improvement, thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks for the changes. I'm using this binding on a daily basis to connect to a speaker at my living room for using the voice assistant capabilities and I think I have faced the issue couple of times, so really appreciated!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM, I have not tried to understand the detailed stuff with "idle" but as @GiviMAD already approved the changes, that is fine for me.
* [pulseaudio] Removing isIdle test The isIdle boolean was not properly handled. When disconnection is called, isIdle is not relevant : we should always honnor the disconnection request. In fact, isIdle prevented disconnection when it is necessary (example : when a IOException occurs when sending audio to sink) +Little bug fix on volume parsing: some volume request doesn't respond with a space after the comma separating left/right channel. * [pulseaudio] Enhancement to the idle detection for disconnection Using a counter to count client instead of a isIdle variable, which was not thread safe. The PulseaudioSimpleProtocolStream parent class is now the sole responsible for closing source or sink stream. * [pulseaudio] Small performance enhancement Avoid a costly synchronized operation for a method called very often. Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
* [pulseaudio] Removing isIdle test The isIdle boolean was not properly handled. When disconnection is called, isIdle is not relevant : we should always honnor the disconnection request. In fact, isIdle prevented disconnection when it is necessary (example : when a IOException occurs when sending audio to sink) +Little bug fix on volume parsing: some volume request doesn't respond with a space after the comma separating left/right channel. * [pulseaudio] Enhancement to the idle detection for disconnection Using a counter to count client instead of a isIdle variable, which was not thread safe. The PulseaudioSimpleProtocolStream parent class is now the sole responsible for closing source or sink stream. * [pulseaudio] Small performance enhancement Avoid a costly synchronized operation for a method called very often. Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
* [pulseaudio] Removing isIdle test The isIdle boolean was not properly handled. When disconnection is called, isIdle is not relevant : we should always honnor the disconnection request. In fact, isIdle prevented disconnection when it is necessary (example : when a IOException occurs when sending audio to sink) +Little bug fix on volume parsing: some volume request doesn't respond with a space after the comma separating left/right channel. * [pulseaudio] Enhancement to the idle detection for disconnection Using a counter to count client instead of a isIdle variable, which was not thread safe. The PulseaudioSimpleProtocolStream parent class is now the sole responsible for closing source or sink stream. * [pulseaudio] Small performance enhancement Avoid a costly synchronized operation for a method called very often. Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
* [pulseaudio] Removing isIdle test The isIdle boolean was not properly handled. When disconnection is called, isIdle is not relevant : we should always honnor the disconnection request. In fact, isIdle prevented disconnection when it is necessary (example : when a IOException occurs when sending audio to sink) +Little bug fix on volume parsing: some volume request doesn't respond with a space after the comma separating left/right channel. * [pulseaudio] Enhancement to the idle detection for disconnection Using a counter to count client instead of a isIdle variable, which was not thread safe. The PulseaudioSimpleProtocolStream parent class is now the sole responsible for closing source or sink stream. * [pulseaudio] Small performance enhancement Avoid a costly synchronized operation for a method called very often. Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com> Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
* [pulseaudio] Removing isIdle test The isIdle boolean was not properly handled. When disconnection is called, isIdle is not relevant : we should always honnor the disconnection request. In fact, isIdle prevented disconnection when it is necessary (example : when a IOException occurs when sending audio to sink) +Little bug fix on volume parsing: some volume request doesn't respond with a space after the comma separating left/right channel. * [pulseaudio] Enhancement to the idle detection for disconnection Using a counter to count client instead of a isIdle variable, which was not thread safe. The PulseaudioSimpleProtocolStream parent class is now the sole responsible for closing source or sink stream. * [pulseaudio] Small performance enhancement Avoid a costly synchronized operation for a method called very often. Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
* [pulseaudio] Removing isIdle test The isIdle boolean was not properly handled. When disconnection is called, isIdle is not relevant : we should always honnor the disconnection request. In fact, isIdle prevented disconnection when it is necessary (example : when a IOException occurs when sending audio to sink) +Little bug fix on volume parsing: some volume request doesn't respond with a space after the comma separating left/right channel. * [pulseaudio] Enhancement to the idle detection for disconnection Using a counter to count client instead of a isIdle variable, which was not thread safe. The PulseaudioSimpleProtocolStream parent class is now the sole responsible for closing source or sink stream. * [pulseaudio] Small performance enhancement Avoid a costly synchronized operation for a method called very often. Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
* [pulseaudio] Removing isIdle test The isIdle boolean was not properly handled. When disconnection is called, isIdle is not relevant : we should always honnor the disconnection request. In fact, isIdle prevented disconnection when it is necessary (example : when a IOException occurs when sending audio to sink) +Little bug fix on volume parsing: some volume request doesn't respond with a space after the comma separating left/right channel. * [pulseaudio] Enhancement to the idle detection for disconnection Using a counter to count client instead of a isIdle variable, which was not thread safe. The PulseaudioSimpleProtocolStream parent class is now the sole responsible for closing source or sink stream. * [pulseaudio] Small performance enhancement Avoid a costly synchronized operation for a method called very often. Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
Bug description:
When the pulseaudio server is shutdown and relaunched, the socket is dead. But the audiosink connection doesn't properly reset the next time it is needed. The isIdle boolean prevents this disconnection/reconnection by checking if it's in use before effectively disconnecting (and of course it's in use, because we are trying to use it when we see that the connection is broken...)
Additionnally, isIdle is not in a try catch block for the pulseaudio sink : so exception within an operation doesn't free the boolean.
Actually, isIdle seems not even relevant : we should always honnor the disconnection request, even if an operation is running (disconnection requests occur when we get I/O exception, or when shutting down the bridge/thing).
This PR remove the isIdle boolean.
+Little bug fix on volume parsing: in some case (audio source), a volume request doesn't respond with a space after the comma separating left/right channel, so I change the volume pattern.