Package org.red5.server.stream
Class ServerStream
java.lang.Object
org.red5.server.stream.AbstractStream
org.red5.server.stream.ServerStream
- All Implemented Interfaces:
IBroadcastStream
,IPlaylist
,IServerStream
,IStream
,IConsumer
,IFilter
,IMessageComponent
,IPipeConnectionListener
,IProvider
,IPushableConsumer
public class ServerStream
extends AbstractStream
implements IServerStream, IFilter, IPushableConsumer, IPipeConnectionListener
An implementation for server side stream.
- Author:
- The Red5 Project, Steven Gong (steven.gong@gmail.com), Paul Gregoire (mondain@gmail.com)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected IPlaylistController
Actual playlist controllerprotected IPlayItem
Current itemprivate int
Current item indexprotected IPlaylistController
Default playlist controllerprivate boolean
Random flag stateprivate boolean
Repeat flag stateprivate boolean
Rewind flag stateprotected CopyOnWriteArrayList<IPlayItem>
List of items in this playlistprivate CopyOnWriteArraySet<IStreamListener>
Listeners to get notified about received packets.private String
Live broadcasting scheduled job nameprivate static final org.slf4j.Logger
private IMessageInput
Message inputprivate IMessageOutput
Message outputprivate RTMPMessage
Next RTMP messageprivate long
Next msg's timestampprivate IProviderService
Provider serviceprotected String
Stream published nameprivate WeakReference<IRecordingListener>
Recording listenerprivate ISchedulingService
Scheduling serviceprivate long
Server start timestampprivate String
VOD scheduled job nameprivate long
VOD start timestampprivate static final long
Fields inherited from class org.red5.server.stream.AbstractStream
creationTime, lock, state
Fields inherited from interface org.red5.server.messaging.IPushableConsumer
KEY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add an item to the list.void
Add an item to specific index.void
addStreamListener
(IStreamListener listener) Add a listener to be notified about received packets.void
close()
Close this stream.private boolean
Get currently playing itemint
Get currently playing item index.getItem
(int index) Get the item according to the index.getItems()
int
Return number of items in listprotected RTMPMessage
Getter for next RTMP message.Get the provider corresponding to this stream.Get stream publish name.Get the filename the stream is being saved as.Return registered stream listeners.boolean
Check if the playlist has more items after the currently playing one.boolean
isRandom()
Whether items are randomly played.boolean
isRepeat()
Whether repeat playing an item.boolean
isRewind()
Whether rewind the list.protected void
Move to the next item updating the currentItemIndex.protected void
Move to the previous item updating the currentItemIndex.void
nextItem()
Go for next item decided by controller logic.protected void
Notifies handler on stream broadcast stopprotected void
Notifies handler on stream broadcast startprivate void
Notifies handler on stream recording stopprotected void
Play next item on item endvoid
onOOBControlMessage
(IMessageComponent source, IPipe pipe, OOBControlMessage oobCtrlMsg) void
Pipe connection event handler.void
pause()
Toggles the paused state.protected void
Play a specific IPlayItem.void
Go for the previous played item.private void
pushMessage
(IMessage message) Push messagevoid
pushMessage
(IPipe pipe, IMessage message) Pushes message through pipevoid
Remove all items.void
removeItem
(int index) Remove an item from list.void
removeStreamListener
(IStreamListener listener) Remove a listener from being notified about received packets.void
Save the broadcast stream as a file.protected void
Pull the next message from IMessageInput and schedule it for push according to the timestamp.void
seek
(int position) Seek to a given position in the stream.private void
Send reset messageprivate void
sendVODInitCM
(IMessageInput msgIn, int start) Send VOD initialization control messageprivate void
sendVODSeekCM
(IMessageInput msgIn, int position) Send VOD seek control messagevoid
setItem
(int index) Set the current item for playing.void
setPlaylistController
(IPlaylistController controller) Set list controller.void
setPublishedName
(String name) 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
start()
Start this server-side streamprotected void
Begin VOD broadcastingvoid
stop()
Stop this server-side streamvoid
Stops any currently active recording.toString()
Methods inherited from class org.red5.server.stream.AbstractStream
getAbsoluteStartTimeMs, getCodecInfo, getCreationTime, getMetaData, getName, getScope, getState, getStreamAwareHandler, setCodecInfo, setMetaData, setName, setScope, setState
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.red5.server.api.stream.IBroadcastStream
getMetaData
Methods inherited from interface org.red5.server.api.stream.IStream
getCodecInfo, getCreationTime, getName, getScope
-
Field Details
-
log
private static final org.slf4j.Logger log -
WAIT_THRESHOLD
private static final long WAIT_THRESHOLD- See Also:
-
publishedName
Stream published name -
controller
Actual playlist controller -
defaultController
Default playlist controller -
isRewind
private boolean isRewindRewind flag state -
isRandom
private boolean isRandomRandom flag state -
isRepeat
private boolean isRepeatRepeat flag state -
items
List of items in this playlist -
currentItemIndex
private int currentItemIndexCurrent item index -
currentItem
Current item -
msgIn
Message input -
msgOut
Message output -
providerService
Provider service -
scheduler
Scheduling service -
liveJobName
Live broadcasting scheduled job name -
vodJobName
VOD scheduled job name -
vodStartTS
private long vodStartTSVOD start timestamp -
serverStartTS
private long serverStartTSServer start timestamp -
nextTS
private long nextTSNext msg's timestamp -
nextRTMPMessage
Next RTMP message -
listeners
Listeners to get notified about received packets. -
recordingListener
Recording listener
-
-
Constructor Details
-
ServerStream
public ServerStream()Constructs a new ServerStream.
-
-
Method Details
-
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
-
getItemSize
public int getItemSize()Return number of items in list- Specified by:
getItemSize
in interfaceIPlaylist
- Returns:
- Number of items in list
-
getItems
-
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. -
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. -
setPlaylistController
Set list controller.- Specified by:
setPlaylistController
in interfaceIPlaylist
- Parameters:
controller
- Playlist controller
-
saveAs
Save the broadcast stream as a file.- Specified by:
saveAs
in interfaceIBroadcastStream
- Parameters:
name
- The path of the file relative to the scope.isAppend
- Whether to append to the end of file.- Throws:
IOException
- File could not be created/written to.
-
getSaveFilename
Get the filename the stream is being saved as.- Specified by:
getSaveFilename
in interfaceIBroadcastStream
- Returns:
- The filename relative to the scope or
null
if the stream is not being saved.
-
getProvider
Get the provider corresponding to this stream. Provider objects are object that- Specified by:
getProvider
in interfaceIBroadcastStream
- Returns:
- the provider
-
getPublishedName
Get stream publish name. Publish name is the value of the first parameter had been passed toNetStream.publish
on client side in SWF.- Specified by:
getPublishedName
in interfaceIBroadcastStream
- Returns:
- Stream publish name
-
setPublishedName
- Specified by:
setPublishedName
in interfaceIBroadcastStream
- Parameters:
name
- Set stream publish name
-
start
public void start()Start this server-side stream -
stop
public void stop()Stop this server-side stream -
stopRecording
public void stopRecording()Stops any currently active recording. -
pause
public void pause()Toggles the paused state.- Specified by:
pause
in interfaceIServerStream
-
seek
public void seek(int position) Seek to a given position in the stream.- Specified by:
seek
in interfaceIServerStream
- Parameters:
position
- new playback position in milliseconds
-
close
public void close()Close this stream. -
onOOBControlMessage
- Specified by:
onOOBControlMessage
in interfaceIMessageComponent
- Parameters:
source
- Message component sourcepipe
- Connection pipeoobCtrlMsg
- Out-of-band control message
-
pushMessage
Pushes message through pipe- Specified by:
pushMessage
in interfaceIPushableConsumer
- Parameters:
pipe
- Pipemessage
- Message- Throws:
IOException
- if message could not be written
-
onPipeConnectionEvent
Pipe connection event handler. There are two types of pipe connection events so far, provider push connection event and provider disconnection event. Pipe events handling is the most common way of working with pipes.- Specified by:
onPipeConnectionEvent
in interfaceIPipeConnectionListener
- Parameters:
event
- Pipe connection event context
-
play
Play a specific IPlayItem. The strategy for now is VOD first, Live second.- Parameters:
item
- Item to play
-
onItemEnd
protected void onItemEnd()Play next item on item end -
pushMessage
Push message- Parameters:
message
- Message- Throws:
IOException
-
sendResetMessage
private void sendResetMessage()Send reset message -
startBroadcastVOD
protected void startBroadcastVOD()Begin VOD broadcasting -
notifyBroadcastClose
protected void notifyBroadcastClose()Notifies handler on stream broadcast stop -
notifyRecordingStop
private void notifyRecordingStop()Notifies handler on stream recording stop -
notifyBroadcastStart
protected void notifyBroadcastStart()Notifies handler on stream broadcast start -
scheduleNextMessage
protected void scheduleNextMessage()Pull the next message from IMessageInput and schedule it for push according to the timestamp. -
doPushMessage
private boolean doPushMessage() -
getNextRTMPMessage
Getter for next RTMP message.- Returns:
- Next RTMP message
-
sendVODInitCM
Send VOD initialization control message- Parameters:
msgIn
- Message inputstart
- Start timestamp
-
sendVODSeekCM
Send VOD seek control message- Parameters:
msgIn
- Message inputposition
- New timestamp to play from
-
moveToNext
protected void moveToNext()Move to the next item updating the currentItemIndex. -
moveToPrevious
protected void moveToPrevious()Move to the previous item updating the currentItemIndex. -
addStreamListener
Description copied from interface:IBroadcastStream
Add a listener to be notified about received packets.- Specified by:
addStreamListener
in interfaceIBroadcastStream
- Parameters:
listener
- the listener to add
-
getStreamListeners
Description copied from interface:IBroadcastStream
Return registered stream listeners.- Specified by:
getStreamListeners
in interfaceIBroadcastStream
- Returns:
- the registered listeners
-
removeStreamListener
Description copied from interface:IBroadcastStream
Remove a listener from being notified about received packets.- Specified by:
removeStreamListener
in interfaceIBroadcastStream
- Parameters:
listener
- the listener to remove
-
toString
-