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 (mondain@gmail.com), Vladimir Hmelyoff (vlhm@splitmedialabs.com)
-
Field Summary
Modifier and TypeFieldDescriptionprivate boolean
Whether or not automatically record incoming stream as mp4private boolean
Whether or not automatically record incoming stream as mp4protected boolean
Whether or not to automatically record the associated stream.protected long
Total number of bytes received.protected boolean
Is there need to check audio codec?protected boolean
Is there need to check video codec?protected int
Data is sent by chunks, each of them has sizeprotected boolean
Is this stream still active?private IClusterNotifier
protected IMessageOutput
Output endpoint that providers useprotected long
Stores timestamp of first packetprotected long
protected Set<IStreamListener>
Listeners to get notified about received packets.protected IPipe
Pipe for live streamingprivate static final org.slf4j.Logger
private WeakReference<MuxAdaptor>
Streaming parametersprotected String
Stream published nameprivate WeakReference<IRecordingListener>
Recording listenerprivate boolean
Whether or not to register with JMX.protected boolean
Is there need to send start notification?private StatisticsCounter
Stores statistics about subscribers.Fields inherited from class org.red5.server.stream.AbstractStream
creationTime, lock, state
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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addStreamListener
(IStreamListener listener) Add a listener to be notified about received packets.private void
checkSendNotifications
(IEvent event) Check and send notification if necessaryvoid
close()
Closes stream, unsubscribes provides, sends stoppage notifications and broadcast close notification.void
dispatchEvent
(IEvent event) Dispatches eventint
Return current number of subscribers.long
Return total number of bytes received from client for this stream.int
Return the currently active timestamp inside the stream.getDatastore
(ApplicationContext appCtx) int
Return maximum number of concurrent subscribers.Returns streaming parameters.Getter for providerGetter for published nameprotected File
getRecordFile
(IScope scope, String name) Get the file we'd be recording to based on scope and given name.Get the filename the stream is being saved as.Return statistics about the stream.Return registered stream listeners.int
Return total number of subscribers.boolean
boolean
private void
Notifies handler on stream broadcast closeprivate void
Notifies handler on stream broadcast startprivate void
Send OOB control message with chunk sizeprivate void
Notifies handler on stream recording stopvoid
onOOBControlMessage
(IMessageComponent source, IPipe pipe, OOBControlMessage oobCtrlMsg) Out-of-band control message handlervoid
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
void
removeStreamListener
(IStreamListener listener) Remove a listener from being notified about received packets.void
Save broadcasted stream.private void
Sends publish start notificationsprivate void
Sends publish stop notificationsprivate void
sendRecordFailedNotify
(String reason) Sends record failed notificationsprivate void
Sends record start notificationsprivate void
Sends record stop notificationsprivate void
sendStartNotifications
(IEventListener source) void
setAutomaticHlsRecording
(boolean automaticHlsRecording) void
setAutomaticMp4Recording
(boolean automaticMp4Recording) void
setAutomaticRecording
(boolean automaticRecording) void
setMuxAdaptor
(WeakReference<MuxAdaptor> muxAdaptor) 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) private void
setUpEndPoints
(ApplicationContext appCtx, Broadcast broadcast, MuxAdaptor muxAdaptor) void
start()
Starts stream, creates pipes, connectsvoid
Notify client that stream is ready for publishing.void
stop()
Stop this stream.void
Stops any currently active recording.protected void
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
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, 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
-
Field Details
-
log
private static final org.slf4j.Logger log -
automaticRecording
protected boolean automaticRecordingWhether or not to automatically record the associated stream. -
bytesReceived
protected long bytesReceivedTotal number of bytes received. -
checkVideoCodec
protected boolean checkVideoCodecIs there need to check video codec? -
checkAudioCodec
protected boolean checkAudioCodecIs there need to check audio codec? -
chunkSize
protected int chunkSizeData is sent by chunks, each of them has size -
closed
protected volatile boolean closedIs this stream still active? -
connMsgOut
Output endpoint that providers use -
firstPacketTime
protected long firstPacketTimeStores timestamp of first packet -
livePipe
Pipe for live streaming -
publishedName
Stream published name -
parameters
Streaming parameters -
sendStartNotification
protected boolean sendStartNotificationIs there need to send start notification? -
subscriberStats
Stores statistics about subscribers. -
listeners
Listeners to get notified about received packets. -
recordingListener
Recording listener -
latestTimeStamp
protected long latestTimeStamp -
registerJMX
private boolean registerJMXWhether or not to register with JMX. -
automaticMp4Recording
private boolean automaticMp4RecordingWhether or not automatically record incoming stream as mp4 -
automaticHlsRecording
private boolean automaticHlsRecordingWhether or not automatically record incoming stream as mp4 -
muxAdaptor
-
clusterNotifier
-
-
Constructor Details
-
ClientBroadcastStream
public ClientBroadcastStream()
-
-
Method Details
-
checkSendNotifications
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
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
Getter for provider- Specified by:
getProvider
in interfaceIBroadcastStream
- Returns:
- Provider
-
setPublishedName
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
Getter for published name- Specified by:
getPublishedName
in interfaceClientBroadcastStreamMXBean
- Specified by:
getPublishedName
in interfaceIBroadcastStream
- Specified by:
getPublishedName
in interfaceIClientBroadcastStreamStatistics
- Returns:
- Stream published name
-
setParameters
Sets streaming parameters as supplied by the publishing application.- Specified by:
setParameters
in interfaceIClientBroadcastStream
- Parameters:
params
- parameter map
-
getParameters
Returns streaming parameters.- Specified by:
getParameters
in interfaceIClientBroadcastStream
- Returns:
- parameters
-
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
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
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
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
Pipe connection event handler- Specified by:
onPipeConnectionEvent
in interfaceIPipeConnectionListener
- Parameters:
event
- Pipe connection event
-
pushMessage
Currently not implemented- Specified by:
pushMessage
in interfaceIPushableConsumer
- Parameters:
pipe
- Pipemessage
- Message
-
saveAs
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
private void sendPublishStartNotify()Sends publish start notifications -
sendPublishStopNotify
private void sendPublishStopNotify()Sends publish stop notifications -
sendRecordFailedNotify
Sends record failed notifications -
sendRecordStartNotify
private void sendRecordStartNotify()Sends record start notifications -
sendRecordStopNotify
private void sendRecordStopNotify()Sends record stop notifications -
pushMessage
Pushes a message out to a consumer.- Parameters:
msg
- StatusMessage
-
sendStartNotifications
-
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
-
getDatastore
-
setUpEndPoints
-
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
Add a listener to be notified about received packets.- Specified by:
addStreamListener
in interfaceIBroadcastStream
- Parameters:
listener
- the listener to add
-
getStreamListeners
Return registered stream listeners.- Specified by:
getStreamListeners
in interfaceIBroadcastStream
- Returns:
- the registered listeners
-
removeStreamListener
Remove a listener from being notified about received packets.- Specified by:
removeStreamListener
in interfaceIBroadcastStream
- Parameters:
listener
- the listener to remove
-
getRecordFile
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() -
setAutomaticMp4Recording
public void setAutomaticMp4Recording(boolean automaticMp4Recording) -
setAutomaticHlsRecording
public void setAutomaticHlsRecording(boolean automaticHlsRecording) -
setMuxAdaptor
-
getMuxAdaptor
-