Package org.openhab.core.audio
Class PipedAudioStream
java.lang.Object
java.io.InputStream
org.openhab.core.audio.AudioStream
org.openhab.core.audio.PipedAudioStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
This is an implementation of an
AudioStream
used to transmit raw audio data to a sink.
It just pipes the audio through it, the default pipe size is equal to 0.5 seconds of audio,
the implementation locks if you set a pipe size lower to the byte length used to write.
In order to support audio multiplex out of the box you should create a PipedAudioStream.Group
instance
which can be used to create the PipedAudioStream
connected to it and then write to all of them though the
group.- Author:
- Miguel Álvarez Díez - Initial contribution
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
ThePipedAudioStream.Group
is anOutputStream
implementation that can be use to create one or morePipedAudioStream
instances and write to them at once. -
Constructor Summary
ModifierConstructorDescriptionprotected
PipedAudioStream
(AudioFormat format, int pipeSize, PipedOutputStream outputStream) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Gets the supported audio formatprotected PipedOutputStream
static PipedAudioStream.Group
newGroup
(AudioFormat format) Creates a new piped stream group used to open new streams and write data to them.static PipedAudioStream.Group
newGroup
(AudioFormat format, int pipeSize) Creates a new piped stream group used to open new streams and write data to them.void
Add a new handler that will be executed on stream close.int
read()
int
read
(byte @Nullable [] b) int
read
(byte @Nullable [] b, int off, int len) Methods inherited from class org.openhab.core.audio.AudioStream
getId
Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Constructor Details
-
PipedAudioStream
protected PipedAudioStream(AudioFormat format, int pipeSize, PipedOutputStream outputStream) throws IOException - Throws:
IOException
-
-
Method Details
-
getFormat
Description copied from class:AudioStream
Gets the supported audio format- Specified by:
getFormat
in classAudioStream
- Returns:
- The supported audio format
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
onClose
Add a new handler that will be executed on stream close. It will be chained to the previous handler if any, and executed in order.- Parameters:
onClose
- block to run on stream close
-
getOutputStream
-
newGroup
Creates a new piped stream group used to open new streams and write data to them. Internal pipe size is 0.5s.- Parameters:
format
- the audio format of the group audio streams- Returns:
- a group instance
-
newGroup
Creates a new piped stream group used to open new streams and write data to them.- Parameters:
format
- the audio format of the group audio streamspipeSize
- the pipe size of the created streams- Returns:
- a piped stream group instance
-