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 Details

    • log

      private static final org.slf4j.Logger log
    • WAIT_THRESHOLD

      private static final long WAIT_THRESHOLD
      See Also:
    • publishedName

      protected String publishedName
      Stream published name
    • controller

      protected IPlaylistController controller
      Actual playlist controller
    • defaultController

      protected IPlaylistController defaultController
      Default playlist controller
    • isRewind

      private boolean isRewind
      Rewind flag state
    • isRandom

      private boolean isRandom
      Random flag state
    • isRepeat

      private boolean isRepeat
      Repeat flag state
    • items

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

      private int currentItemIndex
      Current item index
    • currentItem

      protected IPlayItem currentItem
      Current item
    • msgIn

      private IMessageInput msgIn
      Message input
    • msgOut

      private IMessageOutput msgOut
      Message output
    • providerService

      private IProviderService providerService
      Provider service
    • scheduler

      private ISchedulingService scheduler
      Scheduling service
    • liveJobName

      private volatile String liveJobName
      Live broadcasting scheduled job name
    • vodJobName

      private volatile String vodJobName
      VOD scheduled job name
    • vodStartTS

      private long vodStartTS
      VOD start timestamp
    • serverStartTS

      private long serverStartTS
      Server start timestamp
    • nextTS

      private long nextTS
      Next msg's timestamp
    • nextRTMPMessage

      private RTMPMessage nextRTMPMessage
      Next RTMP message
    • listeners

      Listeners to get notified about received packets.
    • recordingListener

      private WeakReference<IRecordingListener> recordingListener
      Recording listener
  • Constructor Details

    • ServerStream

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

    • 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
      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.
    • 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
    • stopRecording

      public void stopRecording()
      Stops any currently active recording.
    • 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
    • pushMessage

      private void pushMessage(IMessage message) throws IOException
      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

      protected RTMPMessage getNextRTMPMessage()
      Getter for next RTMP message.
      Returns:
      Next RTMP message
    • sendVODInitCM

      private void sendVODInitCM(IMessageInput msgIn, int start)
      Send VOD initialization control message
      Parameters:
      msgIn - Message input
      start - Start timestamp
    • sendVODSeekCM

      private void sendVODSeekCM(IMessageInput msgIn, int position)
      Send VOD seek control message
      Parameters:
      msgIn - Message input
      position - 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

      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
    • toString

      public String toString()
      Overrides:
      toString in class Object