org.red5.server.stream

## Class PlaylistSubscriberStream

- java.lang.Object
- - org.red5.server.stream.AbstractStream
  - - org.red5.server.stream.AbstractClientStream
    - - org.red5.server.stream.PlaylistSubscriberStream

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

    public class PlaylistSubscriberStream
    extends AbstractClientStream
    implements IPlaylistSubscriberStream, IPlaylistSubscriberStreamStatistics

Stream of playlist subscriber

### Nested Class Summary

Nested Classes
`class` `PlaylistSubscriberStream.Notifier` Handles notifications in a separate thread.

### Field Summary

Fields
`protected int` `bufferCheckInterval` Interval in ms to check for buffer underruns in VOD streams.
`protected long` `bytesSent` Number of bytes sent.
`protected long` `creationTime` Timestamp this stream was created.
`protected PlayEngine` `engine` Plays items back
`protected static ScheduledThreadPoolExecutor` `executor` Executor that will be used to schedule stream playback to keep the client buffer filled.
`protected boolean` `random` Random mode state
`protected boolean` `repeat` Repeat mode state
`protected boolean` `rewind` Rewind mode state
`protected int` `underrunTrigger` Number of pending messages at which a `NetStream.Play.InsufficientBW` message is generated for VOD streams.

### Fields inherited from class org.red5.server.stream.AbstractStream

`metaData, state`

### Fields inherited from interface org.red5.server.api.stream.IClientStream

`MODE_APPEND, MODE_LIVE, MODE_PUBLISH, MODE_READ, MODE_RECORD`

### Constructor Summary

Constructors
Constructor and Description
`PlaylistSubscriberStream()` Constructs a new PlaylistSubscriberStream.

### Method Summary

Methods
`void` `addItem(IPlayItem item)` Add an item to the list.
`void` `addItem(IPlayItem item, int index)` Add an item to specific index.
`void` `close()` Close this stream.
`long` `getBytesSent()` Return total number of bytes sent to the client from this stream.
`long` `getCreationTime()` Returns timestamp at which the stream was created.
`IPlayItem` `getCurrentItem()` Get currently playing item
`int` `getCurrentItemIndex()` Get currently playing item index.
`int` `getCurrentTimestamp()` Return the currently active timestamp inside the stream.
`double` `getEstimatedBufferFill()` Return estimated fill ratio of the client buffer.
`ScheduledThreadPoolExecutor` `getExecutor()` Return the executor to use.
`IPlayItem` `getItem(int index)` Get the item according to the index.
`int` `getItemSize()` Return number of items in list
`IPlaylistSubscriberStreamStatistics` `getStatistics()` Return statistics about this stream.
`boolean` `hasMoreItems()` Check if the playlist has more items after the currently playing one.
`boolean` `isPaused()` Check if the stream is currently paused.
`boolean` `isRandom()` Whether items are randomly played.
`boolean` `isRepeat()` Whether repeat playing an item.
`boolean` `isRewind()` Whether rewind the list.
`void` `nextItem()` Go for next item decided by controller logic.
`void` `onChange(StreamState state, Object... changed)` Handles a change occurring on the stream.
`void` `pause(int position)` Pause at a position for current playing item.
`void` `play()` Start playing.
`void` `previousItem()` Go for the previous played item.
`void` `receiveAudio(boolean receive)` Should the stream send audio to the client?
`void` `receiveVideo(boolean receive)` Should the stream send video to the client?
`void` `removeAllItems()` Remove all items.
`void` `removeItem(int index)` Remove an item from list.
`boolean` `replace(IPlayItem oldItem, IPlayItem newItem)` Replaces an item in the list with another item.
`void` `resume(int position)` Resume from a position for current playing item.
`void` `seek(int position)` Seek into a position for current playing item.
`void` `setBufferCheckInterval(int bufferCheckInterval)` Set interval to check for buffer underruns.
`void` `setExecutor(ScheduledThreadPoolExecutor executor)` Set the executor to use.
`void` `setItem(int index)` Set the current item for playing.
`void` `setPlaylistController(IPlaylistController controller)` Set list controller.
`void` `setRandom(boolean random)` Set whether items should be randomly played.
`void` `setRepeat(boolean repeat)` Set whether repeat playing an item.
`void` `setRewind(boolean rewind)` Set whether rewind the list.
`void` `setUnderrunTrigger(int underrunTrigger)` Set maximum number of pending messages at which a `NetStream.Play.InsufficientBW` message will be generated for VOD streams
`void` `start()` Start this stream.
`void` `stop()` Stop playing.

### Methods inherited from class org.red5.server.stream.AbstractClientStream

`getBroadcastStreamPublishName, getClientBufferDuration, getConnection, getState, getStreamId, setBroadcastStreamPublishName, setClientBufferDuration, setConnection, setState, setStreamId`

### Methods inherited from class org.red5.server.stream.AbstractStream

`getCodecInfo, getMetaData, getName, getScope, getStreamAwareHandler, setCodecInfo, setName, setScope`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.red5.server.api.stream.ISubscriberStream

`getState, setState`

### Methods inherited from interface org.red5.server.api.stream.IClientStream

`getBroadcastStreamPublishName, getClientBufferDuration, getConnection, getStreamId, setClientBufferDuration`

### Methods inherited from interface org.red5.server.api.stream.IStream

`getCodecInfo, getName, getScope`

### Methods inherited from interface org.red5.server.api.statistics.IPlaylistSubscriberStreamStatistics

`getClientBufferDuration`

### Field Detail

#### 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

#### executor

    protected static ScheduledThreadPoolExecutor executor

Executor that will be used to schedule stream playback to keep the client buffer filled.

#### 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 Detail

#### PlaylistSubscriberStream

    public PlaylistSubscriberStream()

Constructs a new PlaylistSubscriberStream.

### Method Detail

#### setExecutor

    public void setExecutor(ScheduledThreadPoolExecutor executor)

Set the executor to use.

Parameters:
  `executor` - the executor

#### getExecutor

    public ScheduledThreadPoolExecutor getExecutor()

Return the executor to use.

Specified by:
  `getExecutor` in interface `IPlaylistSubscriberStream`
Specified by:
  `getExecutor` in interface `ISubscriberStream`
Returns:
  the executor

#### 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

#### receiveVideo

    public void receiveVideo(boolean receive)

Should the stream send video to the client?

Specified by:
  `receiveVideo` in interface `ISubscriberStream`

#### receiveAudio

    public void receiveAudio(boolean receive)

Should the stream send audio to the client?

Specified by:
  `receiveAudio` in interface `ISubscriberStream`

#### 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`
Returns:
  true if successful and false otherwise

#### 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