[Live-devel] Proper use of StreamReplicator

Ross Finlayson finlayson at live555.com
Thu Oct 16 18:34:58 PDT 2014


> I've use Live555 for some prototypes for a while now and it's working quite well so far. My use cases
> are to act as a cental video hub for a number of remote surveillance cameras as well as locally connected
> USB cameras and serve H264/MJPEG streams using unicast and multicast. Those scenarios more or
> less work ok. The code isn't too pretty but Live555 is quite hard to use.

Yes, it's hard to use, but that's mainly because it's used to build complex systems.  It's also intended for experienced systems programmers; not for the 'faint of heart' :-)  Finally, everyone should remember that Live Networks, Inc. is not a charity, and I make no money by helping people with the software 'for free' on this mailing list; it's just something that I do as a public service.


> Now I need to save the streams to disk too. There is the handy StreamReplicator class that should allow
> me to save the streams to disk as well as stream them to clients, but I've not really understood how to use
> it correctly. From what I've understood I need to create one StreamReplicator for the source stream and
> then replicator->createNewStreamReplica() for the streaming as well as the saving. Well, this does not work
> at all so I'm doing something wrong.
> 
> The class that handles a local USB camera and unicasts MJPEG is basically:
> 
> class LocalMJpegUnicastServerMediaSubsession : public OnDemandServerMediaSubsession {

First, because you're streaming from live sources (rather than prerecorded files), make sure that your "LocalMJpegUnicastServerMediaSubsession" constructor sets the "reuseFirstSource" parameter - in the "OnDemandServerMediaSubsession" constructor - to True.


> FramedSource* LocalMJpegUnicastServerMediaSubsession::createNewStreamSource (unsigned clientSessionID, unsigned& estBitRate) {
>    // create and initialize a source for the camera. This is a JPEGVideoSource subclass that captures, encodes and delivers JPEG frames
>    // it works fine as long as do not try to use StreamReplicator
>    MJpegFramedSource *source = MJpegFramedSource::createNew( envir() );
>    source->initialize( m_cameraParameters );
> 
>    m_replicator = StreamReplicator::createNew( envir(), source, False );

I would replace this line with:
	if (m_replicator == NULL) {
		m_replicator = StreamReplicator::createNew( envir(), source, False );
		startSavingStream(yourFileName);
	}
and, of course, initialize "m_replicator" to NULL in your constructor.


> 
>    return m_replicator->createStreamReplica();

This is correct.


> RTPSink* LocalMJpegUnicastServerMediaSubsession::createNewRTPSink (Groupsock* rtpGroupsock, unsigned char rtpPayloadTypeIfDynamic, FramedSource* inputSource) {
>    return JPEGVideoRTPSink::createNew( envir(), rtpGroupsock );
> }  

This is correct.


> When I use this ServerMediaSubsession and connect a client the call sequence I see is:
> 
> LocalMJpegUnicastServerMediaSubsession::createNewStreamSource() 
> LocalMJpegUnicastServerMediaSubsession::createNewRTPSink()

FYI, at this point, you should also be seeing:
	~JPEGVideoRTPSink()
	~StreamReplica()

> LocalMJpegUnicastServerMediaSubsession::createNewStreamSource() 
> LocalMJpegUnicastServerMediaSubsession::createNewRTPSink()

The reason for this is that the first "createNewStreamSource()"/"createNewRTPSink()" calls are to create 'dummy' objects that the RTSP server uses to get the stream's SDP description (for the RTSP 'DESCRIBE" command).  These two objects are then deleted (thus the "FYI" above).  Then, 'real' source and sink objects are created.


Ross Finlayson
Live Networks, Inc.
http://www.live555.com/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20141016/aa85e899/attachment-0001.html>


More information about the live-devel mailing list