Package 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
Modifier and TypeClassDescriptionclass
Handles notifications in a separate thread. -
Field Summary
Modifier and TypeFieldDescriptionprotected int
Interval in ms to check for buffer underruns in VOD streams.protected long
Number of bytes sent.private IPlaylistController
Playlist controllerprotected long
Timestamp this stream was created.private int
Current item indexprivate IPlaylistController
Default playlist controllerprotected PlayEngine
Plays items backprivate final LinkedList<IPlayItem>
Playlist itemsprotected CopyOnWriteArraySet<String>
Scheduled job namesprivate static final org.slf4j.Logger
protected boolean
Random mode stateprivate final Lock
private final ReentrantReadWriteLock
protected boolean
Repeat mode stateprotected boolean
Rewind mode stateprotected ISchedulingService
Service used to provide notifications, keep client buffer filled, clean up, etc...protected int
Number of pending messages at which aprivate final Lock
Fields inherited from class org.red5.server.stream.AbstractStream
lock, state
Fields inherited from interface org.red5.server.api.stream.IClientStream
MODE_APPEND, MODE_LIVE, MODE_PUBLISH, MODE_READ, MODE_RECORD
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add an item to the list.void
Add an item to specific index.void
Cancels a scheduled job by name.void
close()
Close this stream.(package private) PlayEngine
createEngine
(ISchedulingService schedulingService, IConsumerService consumerService, IProviderService providerService) Creates a play engine based on current services (scheduling service, consumer service, and provider service).long
Return total number of bytes sent to the client from this stream.long
Returns timestamp at which the stream was created.Get currently playing itemint
Get currently playing item index.int
Return the currently active timestamp inside the stream.double
Return estimated fill ratio of the client buffer.getItem
(int index) Get the item according to the index.int
Return number of items in listReturn statistics about this stream.boolean
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.private void
Move the current item to the next in list.private void
Move the current item to the previous in 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
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
Remove all items.void
removeItem
(int index) Remove an item from list.boolean
Replaces an item in the list with another item.void
resume
(int position) Resume from a position for current playing item.Schedule a job to be executed only once after a 10ms delay.scheduleWithFixedDelay
(IScheduledJob job, int interval) Schedule a job to be executed regularly at the given interval.void
seek
(int position) Seek into a position for current playing item.private void
Seek to current position to restart playback with audio and/or video.void
setBufferCheckInterval
(int bufferCheckInterval) Set interval to check for buffer underruns.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 avoid
start()
Start this stream.void
stop()
Stop playing.Methods inherited from class org.red5.server.stream.AbstractClientStream
getBroadcastStreamPublishName, getClientBufferDuration, getConnection, getStreamId, setBroadcastStreamPublishName, setClientBufferDuration, setConnection, setStreamId
Methods inherited from class org.red5.server.stream.AbstractStream
getAbsoluteStartTimeMs, getCodecInfo, getMetaData, getName, getScope, getState, getStreamAwareHandler, setCodecInfo, setMetaData, setName, setScope, setState
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.IClientStream
getBroadcastStreamPublishName, getClientBufferDuration, getConnection, getStreamId, setBroadcastStreamPublishName, setClientBufferDuration
Methods inherited from interface org.red5.server.api.statistics.IPlaylistSubscriberStreamStatistics
getClientBufferDuration
Methods inherited from interface org.red5.server.api.stream.IStream
getCodecInfo, getName, getScope
Methods inherited from interface org.red5.server.api.stream.ISubscriberStream
getState, setState
-
Field Details
-
log
private static final org.slf4j.Logger log -
readWriteLock
-
read
-
write
-
controller
Playlist controller -
defaultController
Default playlist controller -
items
Playlist items -
currentItemIndex
private int currentItemIndexCurrent item index -
engine
Plays items back -
rewind
protected boolean rewindRewind mode state -
random
protected boolean randomRandom mode state -
repeat
protected boolean repeatRepeat mode state -
schedulingService
Service used to provide notifications, keep client buffer filled, clean up, etc... -
jobs
Scheduled job names -
bufferCheckInterval
protected int bufferCheckIntervalInterval in ms to check for buffer underruns in VOD streams. -
underrunTrigger
protected int underrunTriggerNumber of pending messages at which aNetStream.Play.InsufficientBW
message is generated for VOD streams. -
creationTime
protected long creationTimeTimestamp this stream was created. -
bytesSent
protected long bytesSentNumber 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 aNetStream.Play.InsufficientBW
message will be generated for VOD streams- Parameters:
underrunTrigger
- the maximum number of pending messages
-
start
public void start()Start this stream. -
play
Start playing.- Specified by:
play
in interfaceISubscriberStream
- 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 interfaceISubscriberStream
- 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 interfaceISubscriberStream
- Parameters:
position
- Position for resume in millisecond.
-
stop
public void stop()Stop playing.- Specified by:
stop
in interfaceIStream
- Specified by:
stop
in interfaceISubscriberStream
-
seek
Seek into a position for current playing item.- Specified by:
seek
in interfaceISubscriberStream
- Parameters:
position
- Position for seek in millisecond.- Throws:
OperationNotSupportedException
- if the stream doesn't support seeking.
-
close
public void close()Close this stream. -
isPaused
public boolean isPaused()Check if the stream is currently paused.- Specified by:
isPaused
in interfaceISubscriberStream
- Returns:
- stream is paused
-
addItem
Add an item to the list. -
addItem
Add an item to specific index. -
removeItem
public void removeItem(int index) Remove an item from list.- Specified by:
removeItem
in interfaceIPlaylist
- Parameters:
index
- Index in list
-
removeAllItems
public void removeAllItems()Remove all items.- Specified by:
removeAllItems
in interfaceIPlaylist
-
previousItem
public void previousItem()Go for the previous played item.- Specified by:
previousItem
in interfaceIPlaylist
-
hasMoreItems
public boolean hasMoreItems()Check if the playlist has more items after the currently playing one.- Specified by:
hasMoreItems
in interfaceIPlaylist
- Returns:
true
if more items are available,false
otherwise
-
nextItem
public void nextItem()Go for next item decided by controller logic. -
setItem
public void setItem(int index) Set the current item for playing. -
isRandom
public boolean isRandom()Whether items are randomly played. -
setRandom
public void setRandom(boolean random) Set whether items should be randomly played. -
isRewind
public boolean isRewind()Whether rewind the list. -
setRewind
public void setRewind(boolean rewind) Set whether rewind the list. -
isRepeat
public boolean isRepeat()Whether repeat playing an item. -
setRepeat
public void setRepeat(boolean repeat) Set whether repeat playing an item. -
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 interfaceISubscriberStream
- Parameters:
receive
- toggle
-
receiveAudio
public void receiveAudio(boolean receive) Should the stream send audio to the client?- Specified by:
receiveAudio
in interfaceISubscriberStream
- Parameters:
receive
- toggle
-
setPlaylistController
Set list controller.- Specified by:
setPlaylistController
in interfaceIPlaylist
- Parameters:
controller
- Playlist controller
-
getItemSize
public int getItemSize()Return number of items in list- Specified by:
getItemSize
in interfaceIPlaylist
- Returns:
- Number of items in list
-
getCurrentItemIndex
public int getCurrentItemIndex()Get currently playing item index.- Specified by:
getCurrentItemIndex
in interfaceIPlaylist
- Returns:
- Currently playing item index.
-
getCurrentItem
Get currently playing item- Specified by:
getCurrentItem
in interfaceIPlaylist
- Returns:
- Item
-
getItem
Get the item according to the index. -
replace
Replaces an item in the list with another item.- Specified by:
replace
in interfaceIPlaylistSubscriberStream
- Parameters:
oldItem
- old play itemnewItem
- 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
Handles a change occurring on the stream.- Specified by:
onChange
in interfaceIPlaylistSubscriberStream
- Specified by:
onChange
in interfaceISubscriberStream
- Parameters:
state
- stream state that we are changing to or notifying ofchanged
- changed items
-
getStatistics
Return statistics about this stream.- Specified by:
getStatistics
in interfaceIPlaylistSubscriberStream
- Returns:
- statistics
-
getCreationTime
public long getCreationTime()Returns timestamp at which the stream was created.- Specified by:
getCreationTime
in interfaceIStatisticsBase
- Specified by:
getCreationTime
in interfaceIStream
- Overrides:
getCreationTime
in classAbstractStream
- Returns:
- creation timestamp
-
getCurrentTimestamp
public int getCurrentTimestamp()Return the currently active timestamp inside the stream.- Specified by:
getCurrentTimestamp
in interfaceIStreamStatistics
- 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 interfaceIPlaylistSubscriberStreamStatistics
- Returns:
- number of bytes
-
getEstimatedBufferFill
public double getEstimatedBufferFill()Return estimated fill ratio of the client buffer.- Specified by:
getEstimatedBufferFill
in interfaceIPlaylistSubscriberStreamStatistics
- Returns:
- fill ratio in percent
-
scheduleOnceJob
Schedule a job to be executed only once after a 10ms delay.- Specified by:
scheduleOnceJob
in interfaceISubscriberStream
- Parameters:
job
- scheduled job- Returns:
- jobName
-
scheduleWithFixedDelay
Schedule a job to be executed regularly at the given interval.- Specified by:
scheduleWithFixedDelay
in interfaceISubscriberStream
- Parameters:
job
- scheduled jobinterval
- interval- Returns:
- jobName
-
cancelJob
Cancels a scheduled job by name.- Specified by:
cancelJob
in interfaceISubscriberStream
- Parameters:
jobName
- job name
-