[Live-devel] Custom memory buffer source

Ross Finlayson finlayson at live555.com
Thu Sep 15 16:08:56 PDT 2016


> What is the sane/standard way of doing this?

This is a general problem that people have: How to write a “FramedSource” subclass that implements a data source.  In particular: How to implement the “doGetNextFrame()” virtual function.

The first important thing to note is that I/O within LIVE555-based applications is asynchronous, using an event loop.  Therefore, your “doGetNextFrame()” function SHOULD NOT block, waiting for data to arrive.  If no data is immediately available to be delivered, your “doGetNextFrame()” function should instead return *immediately*.

If/when data later becomes available, then it needs to be signaled to your application via an event - handled within the event loop - which can then call your “doGetNextFrame() again, to cause the data to actually get delivered.  There are four possible ways to do this; one bad, the other three good.

1/ The bad way: Schedule a delayed task that periodically ‘polls’ for new data.  This will work, but is inefficient, and adds some delay.

2/ The good ways: Don’t execute code until new data actually becomes available:
	2a/ If your data is available via a ‘socket’ ('open file’), then you can call “turnOnBackgroundReadHandling()” on the socket, to arrange for an event handler to be called when (and only when) new data becomes available.  This is the option that you should choose, if it’s possible.
	2b/ Have a separate thread that (somehow) waits for the arrival of new data.  When new data becomes available, have this new thread call “triggerEvent()”.  (Note that “triggerEvent()” is the *only* LIVE555 function that can be called from a non-LIVE555 thread.)
	*** For a model of what your “doGetNextFrame()” function might look like in this case, see “liveMedia/DeviceSource.cpp”. ***
	2c/ Have a separate thread that (somehow) waits for the arrival of new data (as with option 2b), but use a global ‘watch variable’ to signal the event loop.  This is more complex, because it requires passing a ‘watch variable’ pointer to your “doEventLoop()” call, and putting this call inside a loop.


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




More information about the live-devel mailing list