Class ExternalEncodedStream
java.lang.Object
net.avadeaux.klipspringer.codec.ExternalEncodedStream
- All Implemented Interfaces:
Closeable,AutoCloseable,AudioStream,Device.Player,PcmWriter
- Direct Known Subclasses:
FlacStream,LameStream,VorbisStream
Common base class for writers that use external libraries for encoding data to a channel.
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.avadeaux.klipspringer.codec.AudioStream
AudioStream.Factory -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()SeeCloseable.close().voiddrain()Forces the encoder to write any retained audio, and closes the stream.final PcmFormatformat()Gets the stream audio format.voidplayedMillis(long time) Callback by which the recipient can tell the writer how much of its received data it has finished playing.booleanChecks if the recipient appears to still be processing data.final booleanwrite(ByteBuffer data) Writes data to an external buffer, whose content is then immediately encoded, and encoded data is sent to the receiver.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.avadeaux.klipspringer.codec.AudioStream
qualityMethods inherited from interface net.avadeaux.klipspringer.codec.Device.Player
bufferedFrames, canPause, layout, pause, unpause
-
Method Details
-
format
Gets the stream audio format.- Specified by:
formatin interfaceDevice.Player
-
streaming
public boolean streaming()Checks if the recipient appears to still be processing data. If a keep-alive executor is available, this method continues checking for recipient activity even after the stream is closed. Otherwise, it returns false as soon as the stream is closed.- Specified by:
streamingin interfaceAudioStream
-
write
Writes data to an external buffer, whose content is then immediately encoded, and encoded data is sent to the receiver.- Specified by:
writein interfaceDevice.Player- Specified by:
writein interfacePcmWriter- Throws:
IOException
-
close
Description copied from interface:PcmWriterSeeCloseable.close().- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfacePcmWriter- Throws:
IOException
-
drain
Forces the encoder to write any retained audio, and closes the stream. Although all data is written to the recipient before this method returns, the recipient may not have played (or otherwise processed) the data it has received at that point, which can continue even after the stream is closed. If a keep-alive executor is available, it is used for executing a wait loop that continues for as long as callbacks toplayedMillis(long)continue. The idea is that the keep-alive executor can run a wait loop in a non-daemon thread, to keep the process alive and stop premature termination of playback.- Specified by:
drainin interfaceDevice.Player- Throws:
IOException
-
playedMillis
public void playedMillis(long time) Description copied from interface:AudioStreamCallback by which the recipient can tell the writer how much of its received data it has finished playing. The writer can use this information to refrain from flooding the recipient with data while making sure it has enough left to play without underflow. Typically not used if the recipient is a file or something else that does not place a limit on output speed.- Specified by:
playedMillisin interfaceAudioStream
-