org.red5.server.stream
Class ServerStream

java.lang.Object
  extended by org.red5.server.stream.AbstractStream
      extended by 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 ([email protected]), Steven Gong ([email protected]), Paul Gregoire ([email protected])

Field Summary
protected  IPlaylistController controller
          Actual playlist controller
protected  IPlayItem currentItem
          Current item
protected  IPlaylistController defaultController
          Default playlist controller
protected  CopyOnWriteArrayList<IPlayItem> items
          List of items in this playlist
protected  String publishedName
          Stream published name
protected  String recordingFilename
          The filename we are recording to.
 
Fields inherited from class org.red5.server.stream.AbstractStream
creationTime, lock, metaData, state
 
Fields inherited from interface org.red5.server.messaging.IPushableConsumer
KEY
 
Constructor Summary
ServerStream()
          Constructs a new ServerStream.
 
Method Summary
 void addItem(IPlayItem item)
          Add an item to the list.
 void addItem(IPlayItem item, int index)
          Add an item to specific index.
 void addStreamListener(IStreamListener listener)
          Add a listener to be notified about received packets.
 void close()
          Close this stream.
 IPlayItem getCurrentItem()
          Get currently playing item
 int getCurrentItemIndex()
          Get currently playing item index.
 IPlayItem getItem(int index)
          Get the item according to the index.
 CopyOnWriteArrayList<IPlayItem> getItems()
           
 int getItemSize()
          Return number of items in list
protected  RTMPMessage getNextRTMPMessage()
          Getter for next RTMP message.
 IProvider getProvider()
          Get the provider corresponding to this stream.
 String getPublishedName()
          Get stream publish name.
 String getSaveFilename()
          Get the filename the stream is being saved as.
 Collection<IStreamListener> getStreamListeners()
          Return registered stream listeners.
 boolean hasMoreItems()
          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 moveToNext()
          Move to the next item updating the currentItemIndex.
protected  void moveToPrevious()
          Move to the previous item updating the currentItemIndex.
 void nextItem()
          Go for next item decided by controller logic.
protected  void notifyBroadcastClose()
          Notifies handler on stream broadcast stop
protected  void notifyBroadcastStart()
          Notifies handler on stream broadcast start
protected  void onItemEnd()
          Play next item on item end
 void onOOBControlMessage(IMessageComponent source, IPipe pipe, OOBControlMessage oobCtrlMsg)
          
 void onPipeConnectionEvent(PipeConnectionEvent event)
          Pipe connection event handler.
 void pause()
          Toggles the paused state.
protected  void play(IPlayItem item)
          Play a specific IPlayItem.
 void previousItem()
          Go for the previous played item.
 void pushMessage(IPipe pipe, IMessage message)
          Pushes message through pipe
 void removeAllItems()
          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 saveAs(String name, boolean isAppend)
          Save the broadcast stream as a file.
protected  void scheduleNextMessage()
          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.
 void 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 stream
protected  void startBroadcastVOD()
          Begin VOD broadcasting
 void stop()
          Stop this server-side stream
 
Methods inherited from class org.red5.server.stream.AbstractStream
getCodecInfo, getCreationTime, getMetaData, getName, getScope, getState, getStreamAwareHandler, setCodecInfo, 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.IBroadcastStream
getMetaData
 
Methods inherited from interface org.red5.server.api.stream.IStream
getCodecInfo, getCreationTime, getName, getScope
 

Field Detail

publishedName

protected String publishedName
Stream published name


controller

protected IPlaylistController controller
Actual playlist controller


defaultController

protected IPlaylistController defaultController
Default playlist controller


items

protected CopyOnWriteArrayList<IPlayItem> items
List of items in this playlist


currentItem

protected IPlayItem currentItem
Current item


recordingFilename

protected String recordingFilename
The filename we are recording to.

Constructor Detail

ServerStream

public ServerStream()
Constructs a new ServerStream.

Method Detail

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

getItemSize

public int getItemSize()
Return number of items in list

Specified by:
getItemSize in interface IPlaylist
Returns:
Number of items in list

getItems

public CopyOnWriteArrayList<IPlayItem> getItems()

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

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

setPlaylistController

public void setPlaylistController(IPlaylistController controller)
Set list controller.

Specified by:
setPlaylistController in interface IPlaylist
Parameters:
controller - Playlist controller

saveAs

public void saveAs(String name,
                   boolean isAppend)
            throws IOException,
                   ResourceNotFoundException,
                   ResourceExistException
Save the broadcast stream as a file.

Specified by:
saveAs in interface IBroadcastStream
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.
ResourceNotFoundException - Resource not exist when trying to append.
ResourceExistException - Resource exist when trying to create.

getSaveFilename

public String getSaveFilename()
Get the filename the stream is being saved as.

Specified by:
getSaveFilename in interface IBroadcastStream
Returns:
The filename relative to the scope or null if the stream is not being saved.

getProvider

public IProvider getProvider()
Get the provider corresponding to this stream. Provider objects are object that

Specified by:
getProvider in interface IBroadcastStream
Returns:
the provider

getPublishedName

public String getPublishedName()
Get stream publish name. Publish name is the value of the first parameter had been passed to NetStream.publish on client side in SWF.

Specified by:
getPublishedName in interface IBroadcastStream
Returns:
Stream publish name

setPublishedName

public void setPublishedName(String name)

Specified by:
setPublishedName in interface IBroadcastStream
Parameters:
name - Set stream publish name

start

public void start()
Start this server-side stream

Specified by:
start in interface IStream

stop

public void stop()
Stop this server-side stream

Specified by:
stop in interface IStream

pause

public void pause()
Toggles the paused state.

Specified by:
pause in interface IServerStream

seek

public void seek(int position)
Seek to a given position in the stream.

Specified by:
seek in interface IServerStream
Parameters:
position - new playback position in milliseconds

close

public void close()
Close this stream.

Specified by:
close in interface IStream

onOOBControlMessage

public void onOOBControlMessage(IMessageComponent source,
                                IPipe pipe,
                                OOBControlMessage oobCtrlMsg)

Specified by:
onOOBControlMessage in interface IMessageComponent
Parameters:
source - Message component source
pipe - Connection pipe
oobCtrlMsg - Out-of-band control message

pushMessage

public void pushMessage(IPipe pipe,
                        IMessage message)
                 throws IOException
Pushes message through pipe

Specified by:
pushMessage in interface IPushableConsumer
Parameters:
pipe - Pipe
message - Message
Throws:
IOException - if message could not be written

onPipeConnectionEvent

public void onPipeConnectionEvent(PipeConnectionEvent event)
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 interface IPipeConnectionListener
Parameters:
event - Pipe connection event context

play

protected void play(IPlayItem item)
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


startBroadcastVOD

protected void startBroadcastVOD()
Begin VOD broadcasting


notifyBroadcastClose

protected void notifyBroadcastClose()
Notifies handler on stream broadcast 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.


getNextRTMPMessage

protected RTMPMessage getNextRTMPMessage()
Getter for next RTMP message.

Returns:
Next RTMP message

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

public void addStreamListener(IStreamListener listener)
Description copied from interface: IBroadcastStream
Add a listener to be notified about received packets.

Specified by:
addStreamListener in interface IBroadcastStream
Parameters:
listener - the listener to add

getStreamListeners

public Collection<IStreamListener> getStreamListeners()
Description copied from interface: IBroadcastStream
Return registered stream listeners.

Specified by:
getStreamListeners in interface IBroadcastStream
Returns:
the registered listeners

removeStreamListener

public void removeStreamListener(IStreamListener listener)
Description copied from interface: IBroadcastStream
Remove a listener from being notified about received packets.

Specified by:
removeStreamListener in interface IBroadcastStream
Parameters:
listener - the listener to remove


Copyright © 2006-2012 The Red5 Project