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

public abstract class ExternalEncodedStream extends Object implements AudioStream
Common base class for writers that use external libraries for encoding data to a channel.
  • Method Details

    • format

      public final PcmFormat format()
      Gets the stream audio format.
      Specified by:
      format in interface Device.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:
      streaming in interface AudioStream
    • write

      public final boolean write(ByteBuffer data) throws IOException
      Writes data to an external buffer, whose content is then immediately encoded, and encoded data is sent to the receiver.
      Specified by:
      write in interface Device.Player
      Specified by:
      write in interface PcmWriter
      Throws:
      IOException
    • close

      public void close() throws IOException
      Description copied from interface: PcmWriter
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface PcmWriter
      Throws:
      IOException
    • drain

      public void drain() throws IOException
      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 to playedMillis(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:
      drain in interface Device.Player
      Throws:
      IOException
    • playedMillis

      public void playedMillis(long time)
      Description copied from interface: AudioStream
      Callback 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:
      playedMillis in interface AudioStream