]> git.basschouten.com Git - openhab-addons.git/commitdiff
[pulseaudio] For source, default timeout should be disconnection ASAP (#15314)
authorGwendal Roulleau <dalgwen@users.noreply.github.com>
Thu, 3 Aug 2023 09:01:48 +0000 (11:01 +0200)
committerGitHub <noreply@github.com>
Thu, 3 Aug 2023 09:01:48 +0000 (11:01 +0200)
* [pulseaudio] For source,  default timeout should be disconnection ASAP

To avoid weird behaviour, such as pulseaudio server storing audio data between inputstream get/read and then sending the backlog all at once when finally reading, we must disconnect immediately thereafter.

---------

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
Co-authored-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
bundles/org.openhab.binding.pulseaudio/src/main/java/org/openhab/binding/pulseaudio/internal/PulseAudioAudioSource.java
bundles/org.openhab.binding.pulseaudio/src/main/java/org/openhab/binding/pulseaudio/internal/PulseaudioClient.java
bundles/org.openhab.binding.pulseaudio/src/main/java/org/openhab/binding/pulseaudio/internal/PulseaudioSimpleProtocolStream.java
bundles/org.openhab.binding.pulseaudio/src/main/resources/OH-INF/i18n/pulseaudio.properties
bundles/org.openhab.binding.pulseaudio/src/main/resources/OH-INF/thing/sink.xml
bundles/org.openhab.binding.pulseaudio/src/main/resources/OH-INF/thing/source.xml

index bb2731e482aadc9b7911a4801057ffe7a9c26323..887e06c81416666123e1a6a69f10d000b0cca448 100644 (file)
@@ -162,13 +162,13 @@ public class PulseAudioAudioSource extends PulseaudioSimpleProtocolStream implem
                                         // task has been ended while writing
                                         return;
                                     }
-                                    logger.warn("InterruptedIOException while writing to from pulse source pipe: {}",
+                                    logger.warn("InterruptedIOException while writing from pulse source to pipe: {}",
                                             getExceptionMessage(e));
                                 } catch (IOException e) {
-                                    logger.warn("IOException while writing to from pulse source pipe: {}",
+                                    logger.warn("IOException while writing from pulse source to pipe: {}",
                                             getExceptionMessage(e));
                                 } catch (RuntimeException e) {
-                                    logger.warn("RuntimeException while writing to pulse source pipe: {}",
+                                    logger.warn("RuntimeException while writing from pulse source to pipe: {}",
                                             getExceptionMessage(e));
                                 }
                             }
index a30491f9d5d6d95ee94e2c8d773126aa8b5d8e5f..eeab4962b6077f269c80d1e8c5efc15926ba34ee 100644 (file)
@@ -637,7 +637,6 @@ public class PulseaudioClient {
                         lc++;
                         if (retRead > 0) {
                             String line = new String(buff, 0, retRead);
-                            // System.out.println("'"+line+"'");
                             if (line.endsWith(">>> ") && lc > 1) {
                                 result += line.substring(0, line.length() - 4);
                                 break;
index 897517cc008dc9ef3acd3d2e6311ecfbd8240abe..b5b09c94924f3ba586253ad4966937afcdfff417 100644 (file)
@@ -101,8 +101,13 @@ public abstract class PulseaudioSimpleProtocolStream {
                 }
                 int idleTimeout = pulseaudioHandler.getIdleTimeout();
                 if (idleTimeout > -1) {
-                    logger.debug("Scheduling next disconnect");
-                    scheduledDisconnection = scheduler.schedule(this::disconnect, idleTimeout, TimeUnit.MILLISECONDS);
+                    if (idleTimeout == 0) {
+                        this.disconnect();
+                    } else {
+                        logger.debug("Scheduling next disconnect");
+                        scheduledDisconnection = scheduler.schedule(this::disconnect, idleTimeout,
+                                TimeUnit.MILLISECONDS);
+                    }
                 }
             }
         } finally {
index 16281ba959f3e8812cbdcd8cbda5ca071cbf9dcb..e92a40913b1dd0bfb13bda7144dfec2dbf16231a 100644 (file)
@@ -48,7 +48,7 @@ thing-type.config.pulseaudio.sink.name.description = The name of one specific de
 thing-type.config.pulseaudio.sink.simpleProtocolSOTimeout.label = Simple Protocol SO Timeout
 thing-type.config.pulseaudio.sink.simpleProtocolSOTimeout.description = Socket SO timeout when connecting to pulseaudio server though module-simple-protocol-tcp. You can tune this option if the socket disconnect frequently.
 thing-type.config.pulseaudio.sink.simpleProtocolSinkIdleTimeout.label = Idle Timeout
-thing-type.config.pulseaudio.sink.simpleProtocolSinkIdleTimeout.description = Timeout in ms after which the connection will be closed when no stream is running. This ensures that your speaker is not on all the time and the pulseaudio sink can go to idle mode. -1 for no disconnection.
+thing-type.config.pulseaudio.sink.simpleProtocolSinkIdleTimeout.description = Timeout in ms after which the connection will be closed when no stream is running. This ensures that your speaker is not on all the time and the pulseaudio sink can go to idle mode. -1 for no disconnection (improve latency). 0 for immediate disconnection.
 thing-type.config.pulseaudio.sink.simpleProtocolSinkPort.label = Simple Protocol Port
 thing-type.config.pulseaudio.sink.simpleProtocolSinkPort.description = Default Port to allocate for use by module-simple-protocol-tcp on the pulseaudio server
 thing-type.config.pulseaudio.sinkInput.additionalFilters.label = Additional Filters
@@ -75,7 +75,7 @@ thing-type.config.pulseaudio.source.simpleProtocolSourceFormat.option.s24be = PC
 thing-type.config.pulseaudio.source.simpleProtocolSourceFormat.option.s32le = PCM signed 32-bit little-endian
 thing-type.config.pulseaudio.source.simpleProtocolSourceFormat.option.s32be = PCM signed 32-bit big-endian
 thing-type.config.pulseaudio.source.simpleProtocolSourceIdleTimeout.label = Idle Timeout
-thing-type.config.pulseaudio.source.simpleProtocolSourceIdleTimeout.description = Timeout in ms after which the connection will be closed when no stream is running. This ensures that your speaker is not on all the time and the pulseaudio source can go to idle mode. -1 for no disconnection.
+thing-type.config.pulseaudio.source.simpleProtocolSourceIdleTimeout.description = Timeout in ms after which the connection will be closed when no stream is running. This ensures that your mic is not on all the time and the pulseaudio source can go to idle mode. -1 for no disconnection. 0 for immediate disconnection (recommended value to avoid capturing unwanted buffered audio).
 thing-type.config.pulseaudio.source.simpleProtocolSourcePort.label = Simple Protocol Port
 thing-type.config.pulseaudio.source.simpleProtocolSourcePort.description = Default Port to allocate to be used by module-simple-protocol-tcp on the pulseaudio server
 thing-type.config.pulseaudio.source.simpleProtocolSourceRate.label = Simple Protocol Rate
index 9348fa3427fa1f355bc982ca9d6980d86622ba18..e81f4a353d66fd4ed38019f4d05852bf8cea961e 100644 (file)
@@ -45,7 +45,8 @@
                        <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
-                                       your speaker is not on all the time and the pulseaudio sink can go to idle mode. -1 for no disconnection.
+                                       your speaker is not on all the time and the pulseaudio sink can go to idle mode. -1 for no disconnection (improve
+                                       latency). 0 for immediate disconnection.
                                </description>
                                <default>30000</default>
                        </parameter>
index 385c5d266a4a3ed03b1f6579dd16557291b7c689..cb8fceb134af1cbd70b0e45b05229b7e6398795e 100644 (file)
                                <default>4710</default>
                        </parameter>
                        <parameter name="simpleProtocolSourceIdleTimeout" type="integer" required="false">
+                               <advanced>true</advanced>
                                <label>Idle Timeout</label>
                                <description>Timeout in ms after which the connection will be closed when no stream is running. This ensures that
-                                       your speaker is not on all the time and the pulseaudio source can go to idle mode. -1 for no disconnection.
+                                       your mic is not on all the time and the pulseaudio source can go to idle mode. -1 for no disconnection. 0 for
+                                       immediate disconnection (recommended value to avoid capturing unwanted buffered audio)
                                </description>
-                               <default>30000</default>
+                               <default>0</default>
                        </parameter>
                        <parameter name="simpleProtocolSourceFormat" type="text">
                                <label>Simple Protocol Format</label>