Class ClientBroadcastStream

All Implemented Interfaces:
IEventDispatcher, IClientBroadcastStreamStatistics, IStatisticsBase, IStreamStatistics, IBroadcastStream, IClientBroadcastStream, IClientStream, IStream, ClientBroadcastStreamMXBean, IConsumer, IFilter, IMessageComponent, IPipeConnectionListener, IProvider, IPushableConsumer

@ManagedResource(objectName="org.red5.server:type=ClientBroadcastStream", description="ClientBroadcastStream") public class ClientBroadcastStream extends AbstractClientStream implements IClientBroadcastStream, IFilter, IPushableConsumer, IPipeConnectionListener, IEventDispatcher, IClientBroadcastStreamStatistics, ClientBroadcastStreamMXBean
Represents live stream broadcasted from client. As Flash Media Server, Red5 supports recording mode for live streams, that is, broadcasted stream has broadcast mode. It can be either "live" or "record" and latter causes server-side application to record broadcasted stream. Note that recorded streams are recorded as FLV files. This type of stream uses two different pipes for live streaming and recording.
Author:
The Red5 Project, Steven Gong, Paul Gregoire (mondain@gmail.com), Vladimir Hmelyoff (vlhm@splitmedialabs.com)
  • Field Details

    • log

      private static final org.slf4j.Logger log
    • automaticRecording

      protected boolean automaticRecording
      Whether or not to automatically record the associated stream.
    • bytesReceived

      protected long bytesReceived
      Total number of bytes received.
    • checkVideoCodec

      protected boolean checkVideoCodec
      Is there need to check video codec?
    • checkAudioCodec

      protected boolean checkAudioCodec
      Is there need to check audio codec?
    • chunkSize

      protected int chunkSize
      Data is sent by chunks, each of them has size
    • closed

      protected volatile boolean closed
      Is this stream still active?
    • connMsgOut

      protected transient IMessageOutput connMsgOut
      Output endpoint that providers use
    • firstPacketTime

      protected long firstPacketTime
      Stores timestamp of first packet
    • livePipe

      protected transient IPipe livePipe
      Pipe for live streaming
    • publishedName

      protected String publishedName
      Stream published name
    • parameters

      protected Map<String,String> parameters
      Streaming parameters
    • sendStartNotification

      protected boolean sendStartNotification
      Is there need to send start notification?
    • subscriberStats

      private transient StatisticsCounter subscriberStats
      Stores statistics about subscribers.
    • listeners

      protected transient Set<IStreamListener> listeners
      Listeners to get notified about received packets.
    • recordingListener

      private transient WeakReference<IRecordingListener> recordingListener
      Recording listener
    • latestTimeStamp

      protected long latestTimeStamp
    • registerJMX

      private boolean registerJMX
      Whether or not to register with JMX.
    • automaticMp4Recording

      private boolean automaticMp4Recording
      Whether or not automatically record incoming stream as mp4
    • automaticHlsRecording

      private boolean automaticHlsRecording
      Whether or not automatically record incoming stream as mp4
    • muxAdaptor

      private WeakReference<MuxAdaptor> muxAdaptor
    • clusterNotifier

      private IClusterNotifier clusterNotifier
  • Constructor Details

    • ClientBroadcastStream

      public ClientBroadcastStream()
  • Method Details

    • checkSendNotifications

      private void checkSendNotifications(IEvent event)
      Check and send notification if necessary
      Parameters:
      event - Event
    • close

      public void close()
      Closes stream, unsubscribes provides, sends stoppage notifications and broadcast close notification.
      Specified by:
      close in interface ClientBroadcastStreamMXBean
      Specified by:
      close in interface IStream
    • dispatchEvent

      public void dispatchEvent(IEvent event)
      Dispatches event
      Specified by:
      dispatchEvent in interface IEventDispatcher
      Parameters:
      event - Event to dispatch
    • getActiveSubscribers

      public int getActiveSubscribers()
      Return current number of subscribers.
      Specified by:
      getActiveSubscribers in interface IClientBroadcastStreamStatistics
      Returns:
      number of subscribers
    • getBytesReceived

      public long getBytesReceived()
      Return total number of bytes received from client for this stream.
      Specified by:
      getBytesReceived in interface IClientBroadcastStreamStatistics
      Returns:
      number of bytes
    • getCurrentTimestamp

      public int getCurrentTimestamp()
      Return the currently active timestamp inside the stream.
      Specified by:
      getCurrentTimestamp in interface IStreamStatistics
      Returns:
      the timestamp in milliseconds
    • getMaxSubscribers

      public int getMaxSubscribers()
      Return maximum number of concurrent subscribers.
      Specified by:
      getMaxSubscribers in interface IClientBroadcastStreamStatistics
      Returns:
      number of subscribers
    • getProvider

      public IProvider getProvider()
      Getter for provider
      Specified by:
      getProvider in interface IBroadcastStream
      Returns:
      Provider
    • setPublishedName

      public void setPublishedName(String name)
      Setter for stream published name
      Specified by:
      setPublishedName in interface ClientBroadcastStreamMXBean
      Specified by:
      setPublishedName in interface IBroadcastStream
      Parameters:
      name - Name that used for publishing. Set at client side when begin to broadcast with NetStream#publish.
    • getPublishedName

      public String getPublishedName()
      Getter for published name
      Specified by:
      getPublishedName in interface ClientBroadcastStreamMXBean
      Specified by:
      getPublishedName in interface IBroadcastStream
      Specified by:
      getPublishedName in interface IClientBroadcastStreamStatistics
      Returns:
      Stream published name
    • setParameters

      public void setParameters(Map<String,String> params)
      Sets streaming parameters as supplied by the publishing application.
      Specified by:
      setParameters in interface IClientBroadcastStream
      Parameters:
      params - parameter map
    • getParameters

      public Map<String,String> getParameters()
      Returns streaming parameters.
      Specified by:
      getParameters in interface IClientBroadcastStream
      Returns:
      parameters
    • getSaveFilename

      public String getSaveFilename()
      Get the filename the stream is being saved as.
      Specified by:
      getSaveFilename in interface ClientBroadcastStreamMXBean
      Specified by:
      getSaveFilename in interface IBroadcastStream
      Specified by:
      getSaveFilename in interface IClientBroadcastStreamStatistics
      Returns:
      The filename relative to the scope or
       null
       
      if the stream is not being saved.
    • getStatistics

      public IClientBroadcastStreamStatistics getStatistics()
      Return statistics about the stream.
      Specified by:
      getStatistics in interface IClientBroadcastStream
      Returns:
      statistics
    • getTotalSubscribers

      public int getTotalSubscribers()
      Return total number of subscribers.
      Specified by:
      getTotalSubscribers in interface IClientBroadcastStreamStatistics
      Returns:
      number of subscribers
    • isAutomaticRecording

      public boolean isAutomaticRecording()
      Returns:
      the automaticRecording
    • setAutomaticRecording

      public void setAutomaticRecording(boolean automaticRecording)
      Parameters:
      automaticRecording - the automaticRecording to set
    • setRegisterJMX

      public void setRegisterJMX(boolean registerJMX)
      Parameters:
      registerJMX - the registerJMX to set
    • notifyBroadcastClose

      private void notifyBroadcastClose()
      Notifies handler on stream broadcast close
    • notifyRecordingStop

      private void notifyRecordingStop()
      Notifies handler on stream recording stop
    • notifyBroadcastStart

      private void notifyBroadcastStart()
      Notifies handler on stream broadcast start
    • notifyChunkSize

      private void notifyChunkSize()
      Send OOB control message with chunk size
    • onOOBControlMessage

      public void onOOBControlMessage(IMessageComponent source, IPipe pipe, OOBControlMessage oobCtrlMsg)
      Out-of-band control message handler
      Specified by:
      onOOBControlMessage in interface IMessageComponent
      Parameters:
      source - OOB message source
      pipe - Pipe that used to send OOB message
      oobCtrlMsg - Out-of-band control message
    • onPipeConnectionEvent

      public void onPipeConnectionEvent(PipeConnectionEvent event)
      Pipe connection event handler
      Specified by:
      onPipeConnectionEvent in interface IPipeConnectionListener
      Parameters:
      event - Pipe connection event
    • pushMessage

      public void pushMessage(IPipe pipe, IMessage message)
      Currently not implemented
      Specified by:
      pushMessage in interface IPushableConsumer
      Parameters:
      pipe - Pipe
      message - Message
    • saveAs

      public void saveAs(String name, boolean isAppend) throws IOException
      Save broadcasted stream.
      Specified by:
      saveAs in interface ClientBroadcastStreamMXBean
      Specified by:
      saveAs in interface IBroadcastStream
      Parameters:
      name - Stream name
      isAppend - Append mode
      Throws:
      IOException - File could not be created/written to
    • sendPublishStartNotify

      private void sendPublishStartNotify()
      Sends publish start notifications
    • sendPublishStopNotify

      private void sendPublishStopNotify()
      Sends publish stop notifications
    • sendRecordFailedNotify

      private void sendRecordFailedNotify(String reason)
      Sends record failed notifications
    • sendRecordStartNotify

      private void sendRecordStartNotify()
      Sends record start notifications
    • sendRecordStopNotify

      private void sendRecordStopNotify()
      Sends record stop notifications
    • pushMessage

      protected void pushMessage(StatusMessage msg)
      Pushes a message out to a consumer.
      Parameters:
      msg - StatusMessage
    • sendStartNotifications

      private void sendStartNotifications(IEventListener source)
    • start

      public void start()
      Starts stream, creates pipes, connects
      Specified by:
      start in interface ClientBroadcastStreamMXBean
      Specified by:
      start in interface IStream
    • startPublishing

      public void startPublishing()
      Notify client that stream is ready for publishing.
      Specified by:
      startPublishing in interface ClientBroadcastStreamMXBean
      Specified by:
      startPublishing in interface IClientBroadcastStream
    • getDatastore

      public DataStore getDatastore(ApplicationContext appCtx)
    • setUpEndPoints

      private void setUpEndPoints(ApplicationContext appCtx, Broadcast broadcast, MuxAdaptor muxAdaptor)
    • stop

      public void stop()
      Stop this stream.
      Specified by:
      stop in interface ClientBroadcastStreamMXBean
      Specified by:
      stop in interface IStream
    • stopRecording

      public void stopRecording()
      Stops any currently active recording.
    • isRecording

      public boolean isRecording()
    • addStreamListener

      public void addStreamListener(IStreamListener listener)
      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()
      Return registered stream listeners.
      Specified by:
      getStreamListeners in interface IBroadcastStream
      Returns:
      the registered listeners
    • removeStreamListener

      public void removeStreamListener(IStreamListener listener)
      Remove a listener from being notified about received packets.
      Specified by:
      removeStreamListener in interface IBroadcastStream
      Parameters:
      listener - the listener to remove
    • getRecordFile

      protected File getRecordFile(IScope scope, String name)
      Get the file we'd be recording to based on scope and given name.
      Parameters:
      scope - scope
      name - record name
      Returns:
      file
    • registerJMX

      protected void registerJMX()
    • unregisterJMX

      protected void unregisterJMX()
    • setAutomaticMp4Recording

      public void setAutomaticMp4Recording(boolean automaticMp4Recording)
    • setAutomaticHlsRecording

      public void setAutomaticHlsRecording(boolean automaticHlsRecording)
    • setMuxAdaptor

      public void setMuxAdaptor(WeakReference<MuxAdaptor> muxAdaptor)
    • getMuxAdaptor

      public WeakReference<MuxAdaptor> getMuxAdaptor()