Class ChannelStreamLine
java.lang.Object
net.avadeaux.klipspringer.encoder.PlayerState
net.avadeaux.klipspringer.encoder.ChannelStreamLine
- All Implemented Interfaces:
AutoCloseable,DataLine,Line,SourceDataLine
- Direct Known Subclasses:
AuChannelStreamLine,EncoderChannelStreamLine
Line for streaming audio to a channel. Data should be written in sequence from a single
thread. Extends the
SourceDataLine contract with the
finish mehod, which should be called to make sure that no data is retained in
an internal encoder buffer before at the end of playback.-
Nested Class Summary
Nested classes/interfaces inherited from interface javax.sound.sampled.DataLine
DataLine.Info -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionChannelStreamLine(WritableByteChannel bc, AudioFormat format, long writeAheadMillis, long timeoutMillis) Creates a line for streaming to a channel. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLineListener(LineListener listener) protected abstract intNumber of bytes received by the line but not yet sent to the channel.voidclose()Closes the line and the destination channel, without writing anything.voiddrain()Emits data buffered on the line to the channel before returning.voidfinish()Emits buffered data and any data buffered in encoder.getControl(Control.Type control) Control[]intfloatgetLevel()longlongbooleanisActive()booleanisControlSupported(Control.Type control) booleanvoidopen()voidopen(AudioFormat fmt) voidopen(AudioFormat fmt, int bufferSize) protected longNumber of samples known to have been sent to the client endpoint for playing.voidremoveLineListener(LineListener listener) voidstart()voidstop()protected abstract voidWrites data buffered on the line to the channel.Methods inherited from class net.avadeaux.klipspringer.encoder.PlayerState
isOpen, onClose, playedMillis, playedMillis, waitForPlayedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface javax.sound.sampled.DataLine
available, flush, getBufferSizeMethods inherited from interface javax.sound.sampled.SourceDataLine
write
-
Field Details
-
bc
-
fs
protected final int fs -
bips
protected final int bips -
byps
protected final int byps -
bsam
protected final int bsam -
esam
protected final int esam -
dsam
protected final int dsam
-
-
Constructor Details
-
ChannelStreamLine
public ChannelStreamLine(WritableByteChannel bc, AudioFormat format, long writeAheadMillis, long timeoutMillis) throws UnsupportedAudioFileException Creates a line for streaming to a channel.- Parameters:
bc- the channel to stream to, which must be non-blockingformat- audio format of the PCM data written to this linewriteAheadMillis- limit for how much to write ahead of what receiver hasplayed, Long.MAX_VALUE for unlimitedtimeoutMillis- time to wait when when write-ahead limit is reached- Throws:
UnsupportedAudioFileException
-
-
Method Details
-
getLineInfo
- Specified by:
getLineInfoin interfaceLine
-
open
- Specified by:
openin interfaceLine- Throws:
LineUnavailableException
-
finish
public void finish()Emits buffered data and any data buffered in encoder. Default implementation just callsdrain. -
close
public void close()Closes the line and the destination channel, without writing anything. In order for all data to be emitted,finishshould be called before close.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceLine- Overrides:
closein classPlayerState
-
getControls
- Specified by:
getControlsin interfaceLine
-
isControlSupported
- Specified by:
isControlSupportedin interfaceLine
-
getControl
- Specified by:
getControlin interfaceLine
-
addLineListener
- Specified by:
addLineListenerin interfaceLine
-
removeLineListener
- Specified by:
removeLineListenerin interfaceLine
-
drain
public void drain()Emits data buffered on the line to the channel before returning. -
start
public void start() -
stop
public void stop() -
isRunning
public boolean isRunning() -
isActive
public boolean isActive() -
getFormat
-
getFramePosition
public int getFramePosition()- Specified by:
getFramePositionin interfaceDataLine
-
getLongFramePosition
public long getLongFramePosition()- Specified by:
getLongFramePositionin interfaceDataLine
-
getMicrosecondPosition
public long getMicrosecondPosition()- Specified by:
getMicrosecondPositionin interfaceDataLine
-
getLevel
public float getLevel() -
open
- Specified by:
openin interfaceSourceDataLine- Throws:
LineUnavailableException
-
open
- Specified by:
openin interfaceSourceDataLine- Throws:
LineUnavailableException
-
outputSamples
protected long outputSamples()Number of samples known to have been sent to the client endpoint for playing. The default implementation returns the number of samples sent to the channel. Needs to be overridden if there is buffering/compression from this point that may cause a delay in the client playing. The number returned by this method may be slightly lower than the actual number output to the endpoint but must never be higher. -
bufferedSamples
protected abstract int bufferedSamples()Number of bytes received by the line but not yet sent to the channel. -
writeBuffer
Writes data buffered on the line to the channel.- Throws:
IOException
-