[pulseaudio] fix null pointer exception and ensure source bg task stops (#12414)
* [pulseaudio] fix null pointer exception and ensure source bg task stops Signed-off-by: Miguel Álvarez Díez <miguelwork92@gmail.com>
This commit is contained in:
@@ -138,7 +138,7 @@ public class PulseAudioAudioSource extends PulseaudioSimpleProtocolStream implem
|
|||||||
this.pipeWriteTask = executor.submit(() -> {
|
this.pipeWriteTask = executor.submit(() -> {
|
||||||
int lengthRead;
|
int lengthRead;
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
while (true) {
|
while (!pipeOutputs.isEmpty()) {
|
||||||
var stream = getSourceInputStream();
|
var stream = getSourceInputStream();
|
||||||
if (stream != null) {
|
if (stream != null) {
|
||||||
try {
|
try {
|
||||||
@@ -156,6 +156,7 @@ public class PulseAudioAudioSource extends PulseaudioSimpleProtocolStream implem
|
|||||||
logger.warn("Unable to get source input stream");
|
logger.warn("Unable to get source input stream");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.pipeWriteTask = null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.pulseaudio.internal.PulseAudioBindingConfiguration;
|
import org.openhab.binding.pulseaudio.internal.PulseAudioBindingConfiguration;
|
||||||
import org.openhab.binding.pulseaudio.internal.PulseAudioBindingConfigurationListener;
|
import org.openhab.binding.pulseaudio.internal.PulseAudioBindingConfigurationListener;
|
||||||
import org.openhab.binding.pulseaudio.internal.PulseaudioBindingConstants;
|
import org.openhab.binding.pulseaudio.internal.PulseaudioBindingConstants;
|
||||||
@@ -115,7 +116,7 @@ public class PulseaudioBridgeHandler extends BaseBridgeHandler implements PulseA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractAudioDeviceConfig getDevice(String name) {
|
public @Nullable AbstractAudioDeviceConfig getDevice(String name) {
|
||||||
return client.getGenericAudioItem(name);
|
return client.getGenericAudioItem(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -281,6 +281,10 @@ public class PulseaudioHandler extends BaseThingHandler implements DeviceStatusL
|
|||||||
// refresh to get the current volume level
|
// refresh to get the current volume level
|
||||||
bridge.getClient().update();
|
bridge.getClient().update();
|
||||||
device = bridge.getDevice(name);
|
device = bridge.getDevice(name);
|
||||||
|
if (device == null) {
|
||||||
|
logger.warn("missing device info, aborting");
|
||||||
|
return;
|
||||||
|
}
|
||||||
int oldVolume = device.getVolume();
|
int oldVolume = device.getVolume();
|
||||||
int newVolume = oldVolume;
|
int newVolume = oldVolume;
|
||||||
if (command.equals(IncreaseDecreaseType.INCREASE)) {
|
if (command.equals(IncreaseDecreaseType.INCREASE)) {
|
||||||
@@ -358,11 +362,12 @@ public class PulseaudioHandler extends BaseThingHandler implements DeviceStatusL
|
|||||||
public int getLastVolume() {
|
public int getLastVolume() {
|
||||||
if (savedVolume == null) {
|
if (savedVolume == null) {
|
||||||
PulseaudioBridgeHandler bridge = getPulseaudioBridgeHandler();
|
PulseaudioBridgeHandler bridge = getPulseaudioBridgeHandler();
|
||||||
AbstractAudioDeviceConfig device = bridge.getDevice(name);
|
|
||||||
// refresh to get the current volume level
|
// refresh to get the current volume level
|
||||||
bridge.getClient().update();
|
bridge.getClient().update();
|
||||||
device = bridge.getDevice(name);
|
AbstractAudioDeviceConfig device = bridge.getDevice(name);
|
||||||
savedVolume = device.getVolume();
|
if (device != null) {
|
||||||
|
savedVolume = device.getVolume();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return savedVolume == null ? 50 : savedVolume;
|
return savedVolume == null ? 50 : savedVolume;
|
||||||
}
|
}
|
||||||
@@ -370,6 +375,10 @@ public class PulseaudioHandler extends BaseThingHandler implements DeviceStatusL
|
|||||||
public void setVolume(int volume) {
|
public void setVolume(int volume) {
|
||||||
PulseaudioBridgeHandler bridge = getPulseaudioBridgeHandler();
|
PulseaudioBridgeHandler bridge = getPulseaudioBridgeHandler();
|
||||||
AbstractAudioDeviceConfig device = bridge.getDevice(name);
|
AbstractAudioDeviceConfig device = bridge.getDevice(name);
|
||||||
|
if (device == null) {
|
||||||
|
logger.warn("missing device info, aborting");
|
||||||
|
return;
|
||||||
|
}
|
||||||
bridge.getClient().setVolumePercent(device, volume);
|
bridge.getClient().setVolumePercent(device, volume);
|
||||||
updateState(VOLUME_CHANNEL, new PercentType(volume));
|
updateState(VOLUME_CHANNEL, new PercentType(volume));
|
||||||
savedVolume = volume;
|
savedVolume = volume;
|
||||||
@@ -412,11 +421,15 @@ public class PulseaudioHandler extends BaseThingHandler implements DeviceStatusL
|
|||||||
* If no module is listening, then it will command the module to load on the pulse audio server,
|
* If no module is listening, then it will command the module to load on the pulse audio server,
|
||||||
*
|
*
|
||||||
* @return the port on which the pulseaudio server is listening for this sink
|
* @return the port on which the pulseaudio server is listening for this sink
|
||||||
|
* @throws IOException when device info is not available
|
||||||
* @throws InterruptedException when interrupted during the loading module wait
|
* @throws InterruptedException when interrupted during the loading module wait
|
||||||
*/
|
*/
|
||||||
public int getSimpleTcpPort() throws InterruptedException {
|
public int getSimpleTcpPort() throws IOException, InterruptedException {
|
||||||
var bridgeHandler = getPulseaudioBridgeHandler();
|
var bridgeHandler = getPulseaudioBridgeHandler();
|
||||||
AbstractAudioDeviceConfig device = bridgeHandler.getDevice(name);
|
AbstractAudioDeviceConfig device = bridgeHandler.getDevice(name);
|
||||||
|
if (device == null) {
|
||||||
|
throw new IOException("missing device info, device appears to be offline");
|
||||||
|
}
|
||||||
String simpleTcpPortPrefName = (device instanceof Source) ? DEVICE_PARAMETER_AUDIO_SOURCE_PORT
|
String simpleTcpPortPrefName = (device instanceof Source) ? DEVICE_PARAMETER_AUDIO_SOURCE_PORT
|
||||||
: DEVICE_PARAMETER_AUDIO_SINK_PORT;
|
: DEVICE_PARAMETER_AUDIO_SINK_PORT;
|
||||||
BigDecimal simpleTcpPortPref = ((BigDecimal) getThing().getConfiguration().get(simpleTcpPortPrefName));
|
BigDecimal simpleTcpPortPref = ((BigDecimal) getThing().getConfiguration().get(simpleTcpPortPrefName));
|
||||||
|
|||||||
Reference in New Issue
Block a user