Skip to content
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] Add "idle timeout" to Pulseaudio audio sink #10731

Merged
merged 2 commits into from
Jun 5, 2021

Conversation

Dbzman
Copy link
Contributor

@Dbzman Dbzman commented May 21, 2021

What?

This PR allows the Pulseaudio audio sink to disconnect after a configured period of being idle.

Why?

I use Pulseaudio with a Raspberry and a speaker to announce events via TTS and noticed that the speaker never goes to sleep and constantly produces high pitch noise.

Solution

After digging through the code the most obvious and simplest option was to disconnect immediately after a stream has finished. This worked initially but had a big drawback when issuing multiple "say" (TTS) commands in a row. There a new connection has been made for every "say" command which resulted in an overlap of the streams. This was not a problem previously because the same socket connection was used and the Pulseaudio server played this consecutively.
The solution I came up with is simple enough and works quite well. After each "thing save" and/or stream command a disconnect is scheduled with a configured delay (30s is the default). So for 30s a connection is reused and after that it will disconnect if no other stream started in the meantime.

If you have suggestions or notes, don't hesitate to approach me.
Cheers and thanks!

@Dbzman Dbzman requested a review from peuter as a code owner May 21, 2021 18:08
@Dbzman Dbzman force-pushed the pulseaudio-audio-sink-disconnect branch 2 times, most recently from 9c7e34b to 9ca3c9b Compare June 1, 2021 07:12
…onnect after being idle

Signed-off-by: Timo Litzius <dev@dbzman-online.eu>
@Dbzman Dbzman force-pushed the pulseaudio-audio-sink-disconnect branch from e3755d5 to b3840f9 Compare June 2, 2021 09:05
@Dbzman
Copy link
Contributor Author

Dbzman commented Jun 3, 2021

I managed to get the build green. Some unrelated test (from the homematic binding) has been failing for quite some time.
@peuter Could you please check if these changes make sense? If you don't have time, maybe you know someone else who can review this PR.
@kaikreuzer Would it be possible to have it in 3.1? The audio sink itself came in 3.1 M4 and I think this PR is a nice addition to it. I have it running on my instance for 2 weeks now and it works pretty well.

Copy link
Member

@kaikreuzer kaikreuzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Dbzman,
Code looks good to me and the feature makes imho sense as you nicely explain.

I have only a very very small review comment and we should be good to merge.

<parameter name="simpleProtocolSinkIdleTimeout" type="integer" required="false">
<label>Idle Timeout</label>
<description>Timeout in ms after which the connection will be closed when no stream is running.
This ensures that
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These line breaks look a bit weird here. Could you clean this up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. The linter complained about it and I ran mvn spotless:apply which resulted in this weirdly formatted code. I tried to make it a bit nicer without the linter going nuts.

Signed-off-by: Timo Litzius <dev@dbzman-online.eu>
Copy link
Member

@kaikreuzer kaikreuzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks!

@kaikreuzer kaikreuzer merged commit 7109475 into openhab:main Jun 5, 2021
@kaikreuzer kaikreuzer added this to the 3.1 milestone Jun 5, 2021
@kaikreuzer kaikreuzer added the enhancement An enhancement or new feature for an existing add-on label Jun 5, 2021
@Dbzman
Copy link
Contributor Author

Dbzman commented Jun 5, 2021

@kaikreuzer Thanks for the review and merge! :)

computergeek1507 pushed a commit to computergeek1507/openhab-addons that referenced this pull request Jul 13, 2021
* Add "idle timeout" to pulseaudio audio sink to allow the sink to disconnect after being idle

Signed-off-by: Timo Litzius <dev@dbzman-online.eu>
lucacalcaterra pushed a commit to lucacalcaterra/openhab-addons that referenced this pull request Jul 26, 2021
* Add "idle timeout" to pulseaudio audio sink to allow the sink to disconnect after being idle

Signed-off-by: Timo Litzius <dev@dbzman-online.eu>
Signed-off-by: Luca Calcaterra <calcaterra.luca@gmail.com>
lucacalcaterra pushed a commit to lucacalcaterra/openhab-addons that referenced this pull request Jul 26, 2021
* Add "idle timeout" to pulseaudio audio sink to allow the sink to disconnect after being idle

Signed-off-by: Timo Litzius <dev@dbzman-online.eu>
Signed-off-by: Luca Calcaterra <calcaterra.luca@gmail.com>
lucacalcaterra pushed a commit to lucacalcaterra/openhab-addons that referenced this pull request Aug 3, 2021
* Add "idle timeout" to pulseaudio audio sink to allow the sink to disconnect after being idle

Signed-off-by: Timo Litzius <dev@dbzman-online.eu>
Signed-off-by: Luca Calcaterra <calcaterra.luca@gmail.com>
frederictobiasc pushed a commit to frederictobiasc/openhab-addons that referenced this pull request Oct 26, 2021
* Add "idle timeout" to pulseaudio audio sink to allow the sink to disconnect after being idle

Signed-off-by: Timo Litzius <dev@dbzman-online.eu>
thinkingstone pushed a commit to thinkingstone/openhab-addons that referenced this pull request Nov 7, 2021
* Add "idle timeout" to pulseaudio audio sink to allow the sink to disconnect after being idle

Signed-off-by: Timo Litzius <dev@dbzman-online.eu>
marcfischerboschio pushed a commit to bosch-io/openhab-addons that referenced this pull request May 5, 2022
* Add "idle timeout" to pulseaudio audio sink to allow the sink to disconnect after being idle

Signed-off-by: Timo Litzius <dev@dbzman-online.eu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature for an existing add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants