Class PlaylistSubscriberStream

All Implemented Interfaces:
IPlaylistSubscriberStreamStatistics, IStatisticsBase, IStreamStatistics, IClientStream, IPlaylist, IPlaylistSubscriberStream, IStream, ISubscriberStream

public class PlaylistSubscriberStream extends AbstractClientStream implements IPlaylistSubscriberStream, IPlaylistSubscriberStreamStatistics
Stream of playlist subscriber
  • Field Details

    • log

      private static final org.slf4j.Logger log
    • readWriteLock

      private final ReentrantReadWriteLock readWriteLock
    • read

      private final Lock read
    • write

      private final Lock write
    • controller

      private IPlaylistController controller
      Playlist controller
    • defaultController

      private IPlaylistController defaultController
      Default playlist controller
    • items

      private final LinkedList<IPlayItem> items
      Playlist items
    • currentItemIndex

      private int currentItemIndex
      Current item index
    • engine

      protected PlayEngine engine
      Plays items back
    • rewind

      protected boolean rewind
      Rewind mode state
    • random

      protected boolean random
      Random mode state
    • repeat

      protected boolean repeat
      Repeat mode state
    • schedulingService

      protected ISchedulingService schedulingService
      Service used to provide notifications, keep client buffer filled, clean up, etc...
    • jobs

      protected CopyOnWriteArraySet<String> jobs
      Scheduled job names
    • bufferCheckInterval

      protected int bufferCheckInterval
      Interval in ms to check for buffer underruns in VOD streams.
    • underrunTrigger

      protected int underrunTrigger
      Number of pending messages at which a
       NetStream.Play.InsufficientBW
       
      message is generated for VOD streams.
    • creationTime

      protected long creationTime
      Timestamp this stream was created.
    • bytesSent

      protected long bytesSent
      Number of bytes sent.
  • Constructor Details

    • PlaylistSubscriberStream

      public PlaylistSubscriberStream()
      Constructs a new PlaylistSubscriberStream.
  • Method Details

    • createEngine

      PlayEngine createEngine(ISchedulingService schedulingService, IConsumerService consumerService, IProviderService providerService)
      Creates a play engine based on current services (scheduling service, consumer service, and provider service). This method is useful during unit testing.
    • setBufferCheckInterval

      public void setBufferCheckInterval(int bufferCheckInterval)
      Set interval to check for buffer underruns. Set to 0 to disable.
      Parameters:
      bufferCheckInterval - interval in ms
    • setUnderrunTrigger

      public void setUnderrunTrigger(int underrunTrigger)
      Set maximum number of pending messages at which a
       NetStream.Play.InsufficientBW
       
      message will be generated for VOD streams
      Parameters:
      underrunTrigger - the maximum number of pending messages
    • start

      public void start()
      Start this stream.
      Specified by:
      start in interface IStream
    • play

      public void play() throws IOException
      Start playing.
      Specified by:
      play in interface ISubscriberStream
      Throws:
      IOException - if an IO error occurred while starting to play the stream
    • pause

      public void pause(int position)
      Pause at a position for current playing item.
      Specified by:
      pause in interface ISubscriberStream
      Parameters:
      position - Position for pause in millisecond.
    • resume

      public void resume(int position)
      Resume from a position for current playing item.
      Specified by:
      resume in interface ISubscriberStream
      Parameters:
      position - Position for resume in millisecond.
    • stop

      public void stop()
      Stop playing.
      Specified by:
      stop in interface IStream
      Specified by:
      stop in interface ISubscriberStream
    • seek

      public void seek(int position) throws OperationNotSupportedException
      Seek into a position for current playing item.
      Specified by:
      seek in interface ISubscriberStream
      Parameters:
      position - Position for seek in millisecond.
      Throws:
      OperationNotSupportedException - if the stream doesn't support seeking.
    • close

      public void close()
      Close this stream.
      Specified by:
      close in interface IStream
    • isPaused

      public boolean isPaused()
      Check if the stream is currently paused.
      Specified by:
      isPaused in interface ISubscriberStream
      Returns:
      stream is paused
    • addItem

      public void addItem(IPlayItem item)
      Add an item to the list.
      Specified by:
      addItem in interface IPlaylist
      Parameters:
      item - Playlist item
    • addItem

      public void addItem(IPlayItem item, int index)
      Add an item to specific index.
      Specified by:
      addItem in interface IPlaylist
      Parameters:
      item - Playlist item
      index - Index in list
    • removeItem

      public void removeItem(int index)
      Remove an item from list.
      Specified by:
      removeItem in interface IPlaylist
      Parameters:
      index - Index in list
    • removeAllItems

      public void removeAllItems()
      Remove all items.
      Specified by:
      removeAllItems in interface IPlaylist
    • previousItem

      public void previousItem()
      Go for the previous played item.
      Specified by:
      previousItem in interface IPlaylist
    • hasMoreItems

      public boolean hasMoreItems()
      Check if the playlist has more items after the currently playing one.
      Specified by:
      hasMoreItems in interface IPlaylist
      Returns:
       true
       
      if more items are available,
       false
       
      otherwise
    • nextItem

      public void nextItem()
      Go for next item decided by controller logic.
      Specified by:
      nextItem in interface IPlaylist
    • setItem

      public void setItem(int index)
      Set the current item for playing.
      Specified by:
      setItem in interface IPlaylist
      Parameters:
      index - Position in list
    • isRandom

      public boolean isRandom()
      Whether items are randomly played.
      Specified by:
      isRandom in interface IPlaylist
      Returns:
       true
       
      if shuffle is on for this list,
       false
       
      otherwise
    • setRandom

      public void setRandom(boolean random)
      Set whether items should be randomly played.
      Specified by:
      setRandom in interface IPlaylist
      Parameters:
      random - Shuffle flag
    • isRewind

      public boolean isRewind()
      Whether rewind the list.
      Specified by:
      isRewind in interface IPlaylist
      Returns:
       true
       
      if playlist is rewind on end,
       false
       
      otherwise
    • setRewind

      public void setRewind(boolean rewind)
      Set whether rewind the list.
      Specified by:
      setRewind in interface IPlaylist
      Parameters:
      rewind - New vallue for rewind flag
    • isRepeat

      public boolean isRepeat()
      Whether repeat playing an item.
      Specified by:
      isRepeat in interface IPlaylist
      Returns:
       true
       
      if repeat mode is on for this playlist,
       false
       
      otherwise
    • setRepeat

      public void setRepeat(boolean repeat)
      Set whether repeat playing an item.
      Specified by:
      setRepeat in interface IPlaylist
      Parameters:
      repeat - New value for item playback repeat flag
    • seekToCurrentPlayback

      private void seekToCurrentPlayback()
      Seek to current position to restart playback with audio and/or video.
    • receiveVideo

      public void receiveVideo(boolean receive)
      Should the stream send video to the client?
      Specified by:
      receiveVideo in interface ISubscriberStream
      Parameters:
      receive - toggle
    • receiveAudio

      public void receiveAudio(boolean receive)
      Should the stream send audio to the client?
      Specified by:
      receiveAudio in interface ISubscriberStream
      Parameters:
      receive - toggle
    • setPlaylistController

      public void setPlaylistController(IPlaylistController controller)
      Set list controller.
      Specified by:
      setPlaylistController in interface IPlaylist
      Parameters:
      controller - Playlist controller
    • getItemSize

      public int getItemSize()
      Return number of items in list
      Specified by:
      getItemSize in interface IPlaylist
      Returns:
      Number of items in list
    • getCurrentItemIndex

      public int getCurrentItemIndex()
      Get currently playing item index.
      Specified by:
      getCurrentItemIndex in interface IPlaylist
      Returns:
      Currently playing item index.
    • getCurrentItem

      public IPlayItem getCurrentItem()
      Get currently playing item
      Specified by:
      getCurrentItem in interface IPlaylist
      Returns:
      Item
    • getItem

      public IPlayItem getItem(int index)
      Get the item according to the index.
      Specified by:
      getItem in interface IPlaylist
      Parameters:
      index - Item index
      Returns:
      Item at that index in list
    • replace

      public boolean replace(IPlayItem oldItem, IPlayItem newItem)
      Replaces an item in the list with another item.
      Specified by:
      replace in interface IPlaylistSubscriberStream
      Parameters:
      oldItem - old play item
      newItem - new play item
      Returns:
      true if successful and false otherwise
    • moveToNext

      private void moveToNext()
      Move the current item to the next in list.
    • moveToPrevious

      private void moveToPrevious()
      Move the current item to the previous in list.
    • onChange

      public void onChange(StreamState state, Object... changed)
      Handles a change occurring on the stream.
      Specified by:
      onChange in interface IPlaylistSubscriberStream
      Specified by:
      onChange in interface ISubscriberStream
      Parameters:
      state - stream state that we are changing to or notifying of
      changed - changed items
    • getStatistics

      public IPlaylistSubscriberStreamStatistics getStatistics()
      Return statistics about this stream.
      Specified by:
      getStatistics in interface IPlaylistSubscriberStream
      Returns:
      statistics
    • getCreationTime

      public long getCreationTime()
      Returns timestamp at which the stream was created.
      Specified by:
      getCreationTime in interface IStatisticsBase
      Specified by:
      getCreationTime in interface IStream
      Overrides:
      getCreationTime in class AbstractStream
      Returns:
      creation timestamp
    • getCurrentTimestamp

      public int getCurrentTimestamp()
      Return the currently active timestamp inside the stream.
      Specified by:
      getCurrentTimestamp in interface IStreamStatistics
      Returns:
      the timestamp in milliseconds
    • getBytesSent

      public long getBytesSent()
      Return total number of bytes sent to the client from this stream.
      Specified by:
      getBytesSent in interface IPlaylistSubscriberStreamStatistics
      Returns:
      number of bytes
    • getEstimatedBufferFill

      public double getEstimatedBufferFill()
      Return estimated fill ratio of the client buffer.
      Specified by:
      getEstimatedBufferFill in interface IPlaylistSubscriberStreamStatistics
      Returns:
      fill ratio in percent
    • scheduleOnceJob

      public String scheduleOnceJob(IScheduledJob job)
      Schedule a job to be executed only once after a 10ms delay.
      Specified by:
      scheduleOnceJob in interface ISubscriberStream
      Parameters:
      job - scheduled job
      Returns:
      jobName
    • scheduleWithFixedDelay

      public String scheduleWithFixedDelay(IScheduledJob job, int interval)
      Schedule a job to be executed regularly at the given interval.
      Specified by:
      scheduleWithFixedDelay in interface ISubscriberStream
      Parameters:
      job - scheduled job
      interval - interval
      Returns:
      jobName
    • cancelJob

      public void cancelJob(String jobName)
      Cancels a scheduled job by name.
      Specified by:
      cancelJob in interface ISubscriberStream
      Parameters:
      jobName - job name