[Live-devel] LiveMedia for multiply thread streaming server

Ross Finlayson finlayson at live.com
Tue Sep 7 11:12:27 PDT 2004


>What I had to do was schedule a live media timer that fires every 100 ms or
>so.  This timer checks a queue which contains commands such as adding,
>removing, or changing streams.  The calling thread that queues the command
>blocks on a condition variable waiting for the queued command to be processed.
>  Once the command has been processed, the error code is put into the 
> structure
>that was used to queue the command.  The live media timer then signals the
>condition variable and the calling thread resumes and picks up the error code.
>
>It's actually a little more work than the above, but you get the idea.  It's a
>little disgusting, but it works okay for my application.  100 ms is quick
>enough response time for adding/deleting streams and 100 ms timer is nothing
>compared to all the timers going off for all the streams the application is
>handling.

Greg,

Note that the issue you faced was not so much 'threads', but was really 
"How to signal new kinds of events to be handled within the LIVE.COM event 
loop".  Other than developing your own event loop implementatation (a 
subclass of "TaskScheduler"), the simplest way to do this is to use the 
"watchVariable" feature of "TaskScheduler::doEventLoop()" (see 
<http://www.live.com/liveMedia/faq.html#exiting-event-loop>).

For example, in your LIVE.COM thread, you could wrap your call to 
"doEventLoop()" within an external loop:

         char watchVariable;
         while (1) {
                 watchVariable = 0;
                 doEventLoop(&watchVariable);
                 //[1] handle the special event(s)
         }

and then, in your extra thread (that generates special events):

         //[2] set appropriate variables to indicate the special event(s) 
to be handled
         watchVariable = ~0;

Of course, you will need to take measures to ensure that [1] and [2] don't 
get done concurrently.

This will give you much better response than 100ms.


	Ross Finlayson
	LIVE.COM
	<http://www.live.com/>



More information about the live-devel mailing list