Package org.red5.server.stream
Class ClientBroadcastStream
- java.lang.Object
-
- org.red5.server.stream.AbstractStream
-
- org.red5.server.stream.AbstractClientStream
-
- org.red5.server.stream.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 ([email protected]), Vladimir Hmelyoff ([email protected])
-
-
Field Summary
Fields Modifier and Type Field Description protected CopyOnWriteArraySet<String>
aliases
Subscribe aliases for this instance.protected boolean
automaticRecording
Whether or not to automatically record the associated stream.protected long
bytesReceived
Total number of bytes received.protected boolean
checkAudioCodec
Is there need to check audio codec?protected boolean
checkVideoCodec
Is there need to check video codec?protected int
chunkSize
Data is sent by chunks, each of them has sizeprotected AtomicBoolean
closed
Is this stream still active?protected IMessageOutput
connMsgOut
Output endpoint that providers useprotected long
firstPacketTime
Stores timestamp of first packetprotected long
latestTimeStamp
protected Set<IStreamListener>
listeners
Listeners to get notified about received packets.protected IPipe
livePipe
Pipe for live streamingprotected static CopyOnWriteArraySet<String>
localAliases
Stream name aliases for the entire server instance.protected String
nameAlias
Publish alias for the stream name.protected Map<String,String>
parameters
Streaming parametersprotected String
publishedName
Stream published nameprotected WeakReference<IRecordingListener>
recordingListener
Recording listenerprotected boolean
registerJMX
Whether or not to register with JMX.protected boolean
sendStartNotification
Is there need to send start notification?-
Fields inherited from class org.red5.server.stream.AbstractStream
codecInfo, creationTime, metaData, startTime, state, stateListeners
-
Fields inherited from interface org.red5.server.api.stream.IClientStream
MODE_APPEND, MODE_LIVE, MODE_PUBLISH, MODE_READ, MODE_RECORD
-
Fields inherited from interface org.red5.server.messaging.IPushableConsumer
KEY
-
-
Constructor Summary
Constructors Constructor Description ClientBroadcastStream()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addAlias(String alias)
Adds a stream name subscribe-side alias.void
addStreamListener(IStreamListener listener)
Add a listener to be notified about received packets.boolean
aliasRegistered(String alias)
Returns whether or not an alias is in-use / registered already; this includes both publish and subscribe aliases within a server instance.protected void
checkSendNotifications(IEvent event)
Check and send notification if necessaryvoid
close()
Closes stream, unsubscribes provides, sends stoppage notifications and broadcast close notification.boolean
containsAlias(String alias)
Returns whether or not a given subscribe-side alias exists.void
dispatchEvent(IEvent event)
Dispatches eventint
getActiveSubscribers()
Return current number of subscribers.String
getAlias()
Returns an subscribe-side alias.Set<String>
getAliases()
Returns all the subscribe-side aliases.long
getBytesReceived()
Return total number of bytes received from client for this stream.int
getCurrentTimestamp()
Return the currently active timestamp inside the stream.int
getMaxSubscribers()
Return maximum number of concurrent subscribers.String
getNameAlias()
Returns the publish-side alias, if configured.Map<String,String>
getParameters()
Returns streaming parameters.IProvider
getProvider()
Getter for providerString
getPublishedName()
Getter for published nameprotected File
getRecordFile(IScope scope, String name)
Get the file we'd be recording to based on scope and given name.String
getSaveFilename()
Get the filename the stream is being saved as.IClientBroadcastStreamStatistics
getStatistics()
Return statistics about the stream.Collection<IStreamListener>
getStreamListeners()
Return registered stream listeners.int
getTotalSubscribers()
Return total number of subscribers.boolean
hasAlias()
Returns whether or not an subscribe-side alias for this stream exists.boolean
isAutomaticRecording()
boolean
isRecording()
protected void
notifyBroadcastClose()
Notifies handler on stream broadcast closeprotected void
notifyBroadcastStart()
Notifies handler on stream broadcast startprotected void
notifyChunkSize()
Send OOB control message with chunk sizeprotected void
notifyRecordingStop()
Notifies handler on stream recording stopvoid
onOOBControlMessage(IMessageComponent source, IPipe pipe, OOBControlMessage oobCtrlMsg)
Out-of-band control message handlervoid
onPipeConnectionEvent(PipeConnectionEvent event)
Pipe connection event handlervoid
pushMessage(IPipe pipe, IMessage message)
Currently not implementedprotected void
pushMessage(StatusMessage msg)
Pushes a message out to a consumer.protected void
registerJMX()
void
removeStreamListener(IStreamListener listener)
Remove a listener from being notified about received packets.void
saveAs(String name, boolean isAppend)
Save broadcasted stream.protected void
sendPublishStartNotify()
Sends publish start notificationsprotected void
sendPublishStopNotify()
Sends publish stop notificationsprotected void
sendRecordFailedNotify(String reason)
Sends record failed notificationsprotected void
sendRecordStartNotify()
Sends record start notificationsprotected void
sendRecordStopNotify()
Sends record stop notificationsprotected void
sendStartNotifications(IEventListener source)
void
setAutomaticRecording(boolean automaticRecording)
void
setNameAlias(String nameAlias)
Sets the publish-side alias for the streams name.void
setParameters(Map<String,String> params)
Sets streaming parameters as supplied by the publishing application.void
setPublishedName(String name)
Setter for stream published namevoid
setRegisterJMX(boolean registerJMX)
void
start()
Starts stream, creates pipes, connectsvoid
startPublishing()
Notify client that stream is ready for publishing.void
stop()
Stop this stream.void
stopRecording()
Stops any currently active recording.protected void
unregisterJMX()
-
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
addStateChangeListener, fireStateChange, getCodecInfo, getCreationTime, getMetaData, getName, getScope, getStartTime, getState, getStreamAwareHandler, removeStateChangeListener, 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.IBroadcastStream
getMetaData
-
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.IStatisticsBase
getCreationTime
-
Methods inherited from interface org.red5.server.api.stream.IStream
getCodecInfo, getCreationTime, getName, getScope, getStartTime
-
-
-
-
Field Detail
-
automaticRecording
protected boolean automaticRecording
Whether or not to automatically record the associated stream.
-
bytesReceived
protected volatile long bytesReceived
Total number of bytes received.
-
checkVideoCodec
protected volatile boolean checkVideoCodec
Is there need to check video codec?
-
checkAudioCodec
protected volatile 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 AtomicBoolean 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
-
sendStartNotification
protected boolean sendStartNotification
Is there need to send start notification?
-
listeners
protected transient Set<IStreamListener> listeners
Listeners to get notified about received packets.
-
recordingListener
protected transient WeakReference<IRecordingListener> recordingListener
Recording listener
-
latestTimeStamp
protected volatile long latestTimeStamp
-
registerJMX
protected boolean registerJMX
Whether or not to register with JMX.
-
localAliases
protected static CopyOnWriteArraySet<String> localAliases
Stream name aliases for the entire server instance.
-
nameAlias
protected String nameAlias
Publish alias for the stream name.
-
aliases
protected CopyOnWriteArraySet<String> aliases
Subscribe aliases for this instance.
-
-
Method Detail
-
checkSendNotifications
protected 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 interfaceClientBroadcastStreamMXBean
- Specified by:
close
in interfaceIStream
-
dispatchEvent
public void dispatchEvent(IEvent event)
Dispatches event- Specified by:
dispatchEvent
in interfaceIEventDispatcher
- Parameters:
event
- Event to dispatch
-
getActiveSubscribers
public int getActiveSubscribers()
Return current number of subscribers.- Specified by:
getActiveSubscribers
in interfaceIClientBroadcastStreamStatistics
- Returns:
- number of subscribers
-
getBytesReceived
public long getBytesReceived()
Return total number of bytes received from client for this stream.- Specified by:
getBytesReceived
in interfaceIClientBroadcastStreamStatistics
- Returns:
- number of bytes
-
getCurrentTimestamp
public int getCurrentTimestamp()
Return the currently active timestamp inside the stream.- Specified by:
getCurrentTimestamp
in interfaceIStreamStatistics
- Returns:
- the timestamp in milliseconds
-
getMaxSubscribers
public int getMaxSubscribers()
Return maximum number of concurrent subscribers.- Specified by:
getMaxSubscribers
in interfaceIClientBroadcastStreamStatistics
- Returns:
- number of subscribers
-
getProvider
public IProvider getProvider()
Getter for provider- Specified by:
getProvider
in interfaceIBroadcastStream
- Returns:
- Provider
-
setPublishedName
public void setPublishedName(String name)
Setter for stream published name- Specified by:
setPublishedName
in interfaceClientBroadcastStreamMXBean
- Specified by:
setPublishedName
in interfaceIBroadcastStream
- 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 interfaceClientBroadcastStreamMXBean
- Specified by:
getPublishedName
in interfaceIBroadcastStream
- Specified by:
getPublishedName
in interfaceIClientBroadcastStreamStatistics
- 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 interfaceIClientBroadcastStream
- Parameters:
params
- parameter map
-
getParameters
public Map<String,String> getParameters()
Returns streaming parameters.- Specified by:
getParameters
in interfaceIClientBroadcastStream
- Returns:
- parameters
-
getSaveFilename
public String getSaveFilename()
Get the filename the stream is being saved as.- Specified by:
getSaveFilename
in interfaceClientBroadcastStreamMXBean
- Specified by:
getSaveFilename
in interfaceIBroadcastStream
- Specified by:
getSaveFilename
in interfaceIClientBroadcastStreamStatistics
- 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 interfaceIClientBroadcastStream
- Returns:
- statistics
-
getTotalSubscribers
public int getTotalSubscribers()
Return total number of subscribers.- Specified by:
getTotalSubscribers
in interfaceIClientBroadcastStreamStatistics
- 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
protected void notifyBroadcastClose()
Notifies handler on stream broadcast close
-
notifyRecordingStop
protected void notifyRecordingStop()
Notifies handler on stream recording stop
-
notifyBroadcastStart
protected void notifyBroadcastStart()
Notifies handler on stream broadcast start
-
notifyChunkSize
protected 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 interfaceIMessageComponent
- Parameters:
source
- OOB message sourcepipe
- Pipe that used to send OOB messageoobCtrlMsg
- Out-of-band control message
-
onPipeConnectionEvent
public void onPipeConnectionEvent(PipeConnectionEvent event)
Pipe connection event handler- Specified by:
onPipeConnectionEvent
in interfaceIPipeConnectionListener
- Parameters:
event
- Pipe connection event
-
pushMessage
public void pushMessage(IPipe pipe, IMessage message)
Currently not implemented- Specified by:
pushMessage
in interfaceIPushableConsumer
- Parameters:
pipe
- Pipemessage
- Message
-
saveAs
public void saveAs(String name, boolean isAppend) throws IOException
Save broadcasted stream.- Specified by:
saveAs
in interfaceClientBroadcastStreamMXBean
- Specified by:
saveAs
in interfaceIBroadcastStream
- Parameters:
name
- Stream nameisAppend
- Append mode- Throws:
IOException
- File could not be created/written to
-
sendPublishStartNotify
protected void sendPublishStartNotify()
Sends publish start notifications
-
sendPublishStopNotify
protected void sendPublishStopNotify()
Sends publish stop notifications
-
sendRecordFailedNotify
protected void sendRecordFailedNotify(String reason)
Sends record failed notifications
-
sendRecordStartNotify
protected void sendRecordStartNotify()
Sends record start notifications
-
sendRecordStopNotify
protected void sendRecordStopNotify()
Sends record stop notifications
-
pushMessage
protected void pushMessage(StatusMessage msg)
Pushes a message out to a consumer.- Parameters:
msg
- StatusMessage
-
sendStartNotifications
protected void sendStartNotifications(IEventListener source)
-
start
public void start()
Starts stream, creates pipes, connects- Specified by:
start
in interfaceClientBroadcastStreamMXBean
- Specified by:
start
in interfaceIStream
-
startPublishing
public void startPublishing()
Notify client that stream is ready for publishing.- Specified by:
startPublishing
in interfaceClientBroadcastStreamMXBean
- Specified by:
startPublishing
in interfaceIClientBroadcastStream
-
stop
public void stop()
Stop this stream.- Specified by:
stop
in interfaceClientBroadcastStreamMXBean
- Specified by:
stop
in interfaceIStream
-
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 interfaceIBroadcastStream
- Parameters:
listener
- the listener to add
-
getStreamListeners
public Collection<IStreamListener> getStreamListeners()
Return registered stream listeners.- Specified by:
getStreamListeners
in interfaceIBroadcastStream
- Returns:
- the registered listeners
-
removeStreamListener
public void removeStreamListener(IStreamListener listener)
Remove a listener from being notified about received packets.- Specified by:
removeStreamListener
in interfaceIBroadcastStream
- 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
- scopename
- record name- Returns:
- file
-
registerJMX
protected void registerJMX()
-
unregisterJMX
protected void unregisterJMX()
-
addAlias
public boolean addAlias(String alias)
Description copied from interface:IClientBroadcastStream
Adds a stream name subscribe-side alias.- Specified by:
addAlias
in interfaceIClientBroadcastStream
- Returns:
- true if added to the aliases, false otherwise
-
hasAlias
public boolean hasAlias()
Description copied from interface:IClientBroadcastStream
Returns whether or not an subscribe-side alias for this stream exists.- Specified by:
hasAlias
in interfaceIClientBroadcastStream
- Returns:
- true if an alias has been added and false otherwise
-
getAlias
public String getAlias()
Description copied from interface:IClientBroadcastStream
Returns an subscribe-side alias.- Specified by:
getAlias
in interfaceIClientBroadcastStream
- Returns:
- alias if at least one exists or null when there are none
-
containsAlias
public boolean containsAlias(String alias)
Description copied from interface:IClientBroadcastStream
Returns whether or not a given subscribe-side alias exists.- Specified by:
containsAlias
in interfaceIClientBroadcastStream
- Returns:
- true if found and false otherwise
-
getAliases
public Set<String> getAliases()
Description copied from interface:IClientBroadcastStream
Returns all the subscribe-side aliases.- Specified by:
getAliases
in interfaceIClientBroadcastStream
- Returns:
- all aliases for this instance or an empty set
-
setNameAlias
public void setNameAlias(String nameAlias)
Description copied from interface:IClientBroadcastStream
Sets the publish-side alias for the streams name. Subsequent calls will replace an existing alias if already set.- Specified by:
setNameAlias
in interfaceIClientBroadcastStream
- Parameters:
nameAlias
- alias to set for the streams name or null to clear it
-
getNameAlias
public String getNameAlias()
Description copied from interface:IClientBroadcastStream
Returns the publish-side alias, if configured.- Specified by:
getNameAlias
in interfaceIClientBroadcastStream
- Returns:
- alias for the streams name or null if not set
-
aliasRegistered
public boolean aliasRegistered(String alias)
Description copied from interface:IClientBroadcastStream
Returns whether or not an alias is in-use / registered already; this includes both publish and subscribe aliases within a server instance.- Specified by:
aliasRegistered
in interfaceIClientBroadcastStream
- Parameters:
alias
- the name to check against publish and subscribe aliases- Returns:
- true if registered and false otherwise
-
-