<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:st1="urn:schemas-microsoft-com:office:smarttags" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<title>Re: [Live-devel] Live 555 multi-thread support</title>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
name="country-region"/>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
name="place"/>
<!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:blue;
        text-decoration:underline;}
pre
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.EmailStyle18
        {mso-style-type:personal;
        font-family:Arial;
        color:navy;}
span.EmailStyle21
        {mso-style-type:personal-reply;
        font-family:Arial;
        color:navy;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink=blue>
<div class=Section1>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>I forgot to add, but if you want to have
multiple threads interact with LiveMedia, use pipes and shared fifo memory as
your main base of data transfer/communication.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Pipes allow you to expose file handles
that can then be ‘listened’ on by LiveMedia’s task scheduler
using the select() call – it will just add this file handle to its list
of schedulable sleeping tasks, and once data gets transferred on that pipe,
your function handler should awake. That combined with some sort of shared
memory makes it a complete cinch to implement various packetizers.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>I usually have a base class that
implements inter-thread data transfer, sub-classing DeviceSource – then I
just latch on my packetizer classes on-top of this so that it becomes quite
seamless. This way, you can have multiple streams, multiple codecs all
implemented seamlessly as long as your base class does its job well of relaying
data between threads. Key thing to note is not to use mutexes/conditional
variables in the thread running LiveMedia, as then you might potentially be
blocking the thread outside of the select() call – this incurs ‘double’
scheduling, and would prevent LiveMedia from servicing network events on time.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Thanks,<o:p></o:p></span></font></p>
<div>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><strong><b><font
size=2 color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial;
color:navy'>Jerry Johns</span></font></b></strong><b><font size=2 color=navy
face=Arial><span style='font-size:10.0pt;font-family:Arial;color:navy;
font-weight:bold'><br>
</span></font></b><em><i><font size=1 color=navy face=Arial><span
style='font-size:7.5pt;font-family:Arial;color:navy'>Design Engineer</span></font></i></em><i><font
size=1 color=blue face=Arial><span style='font-size:7.5pt;font-family:Arial;
color:blue;font-style:italic'><br>
</span></font></i><em><i><font size=1 color=navy face=Arial><span
style='font-size:7.5pt;font-family:Arial;color:navy'>Nuvation Research Corp - <u1:country-region u2:st="on"><u1:place u2:st="on"><st1:place
w:st="on"><st1:country-region w:st="on">Canada</st1:country-region></st1:place></span></font></i></em><i><font
size=1 color=blue face=Arial><span style='font-size:7.5pt;font-family:Arial;
color:blue;font-style:italic'><br>
</span></font></i><em><i><font size=1 color=navy face=Arial><span
style='font-size:7.5pt;font-family:Arial;color:navy'></u1:place></u1:country-region>Tel:
(519) 746-2304 ext. 221</span></font></i></em><i><font size=1 color=blue
face=Arial><span style='font-size:7.5pt;font-family:Arial;color:blue;
font-style:italic'><br>
</span></font></i><font size=1 color=navy face=Arial><span style='font-size:
7.5pt;font-family:Arial;color:navy'><a href="http://www.nuvation.com/"
title="http://www.nuvation.com"><em><i><font color=navy face=Arial
title="http://www.nuvation.com"><span title="http://www.nuvation.com"><span
style='font-family:Arial;color:navy;text-decoration:none'>www.nuvation.com</span></span></font></i></em></a></span></font><o:p></o:p></p>
</div>
<div>
<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>
<hr size=2 width="100%" align=center tabindex=-1>
</span></font></div>
<p class=MsoNormal><b><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'>
live-devel-bounces@ns.live555.com [mailto:live-devel-bounces@ns.live555.com] <b><span
style='font-weight:bold'>On Behalf Of </span></b>Jerry Johns<br>
<b><span style='font-weight:bold'>Sent:</span></b> Wednesday, July 08, 2009
2:14 PM<br>
<b><span style='font-weight:bold'>To:</span></b> LIVE555 Streaming Media -
development & use<br>
<b><span style='font-weight:bold'>Subject:</span></b> Re: [Live-devel] Live 555
multi-thread support</span></font><o:p></o:p></p>
</div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>You don’t really have to run it
under multiple processes, especially since it works fine under its own thread
(pthread in Linux)<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>The heart of its implementation revolves
around the select() call involving multiple sockets, so really, it is
‘safe’ as long as no one else uses those sockets/ports, and you
don’t try to run multiple instances of LiveMedia on multiple threads.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>I’ve successfully used LiveMedia in
designs using this above concept and as long as you lower its thread priority
relative to the other threads in your system, it chugs along just fine </span></font><font
size=2 color=navy face=Wingdings><span style='font-size:10.0pt;font-family:
Wingdings;color:navy'>J</span></font><font size=2 color=navy face=Arial><span
style='font-size:10.0pt;font-family:Arial;color:navy'><o:p></o:p></span></font></p>
<div>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><strong><b><font
size=2 color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial;
color:navy'>Jerry Johns</span></font></b></strong><b><font size=2 color=navy
face=Arial><span style='font-size:10.0pt;font-family:Arial;color:navy;
font-weight:bold'><br>
</span></font></b><em><i><font size=1 color=navy face=Arial><span
style='font-size:7.5pt;font-family:Arial;color:navy'>Design Engineer</span></font></i></em><i><font
size=1 color=blue face=Arial><span style='font-size:7.5pt;font-family:Arial;
color:blue;font-style:italic'><br>
</span></font></i><em><i><font size=1 color=navy face=Arial><span
style='font-size:7.5pt;font-family:Arial;color:navy'>Nuvation Research Corp - <u1:country-region u2:st="on"><u1:place u2:st="on"><st1:place
w:st="on"><st1:country-region w:st="on">Canada</st1:country-region></st1:place></span></font></i></em><i><font
size=1 color=blue face=Arial><span style='font-size:7.5pt;font-family:Arial;
color:blue;font-style:italic'><br>
</span></font></i><em><i><font size=1 color=navy face=Arial><span
style='font-size:7.5pt;font-family:Arial;color:navy'></u1:place></u1:country-region>Tel:
(519) 746-2304 ext. 221</span></font></i></em><i><font size=1 color=blue
face=Arial><span style='font-size:7.5pt;font-family:Arial;color:blue;
font-style:italic'><br>
</span></font></i><font size=1 color=navy face=Arial><span style='font-size:
7.5pt;font-family:Arial;color:navy'><a href="http://www.nuvation.com/"
title="http://www.nuvation.com"><em><i><font color=navy face=Arial
title="http://www.nuvation.com"><span title="http://www.nuvation.com"><span
style='font-family:Arial;color:navy;text-decoration:none'>www.nuvation.com</span></span></font></i></em></a></span></font><o:p></o:p></p>
</div>
<div>
<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>
<hr size=2 width="100%" align=center tabindex=-1>
</span></font></div>
<p class=MsoNormal><b><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'>
live-devel-bounces@ns.live555.com [mailto:live-devel-bounces@ns.live555.com] <b><span
style='font-weight:bold'>On Behalf Of </span></b>Ross Finlayson<br>
<b><span style='font-weight:bold'>Sent:</span></b> Sunday, July 05, 2009 5:58
AM<br>
<b><span style='font-weight:bold'>To:</span></b> LIVE555 Streaming Media -
development & use<br>
<b><span style='font-weight:bold'>Subject:</span></b> Re: [Live-devel] Live 555
multi-thread support</span></font><o:p></o:p></p>
</div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>
<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>Hi.<br>
<br>
I read the FAQ but I still not 100% sure about this:<br>
<br>
"<o:p></o:p></span></font></p>
</blockquote>
<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt' type=cite cite>
<p class=MsoNormal><i><font size=3 face="Times New Roman"><span
style='font-size:12.0pt;font-style:italic'>Longer answer:</span></font></i>
More than one thread can still use this code, if only one thread runs the
library code proper, and the other thread(s) communicate with the library only
by setting global 'flag' variables. (For one possible use of this technique,
see the answer to <a
href="http://www.live555.com/liveMedia/faq.html#exiting-event-loop">this
question</a>.)<o:p></o:p></p>
</blockquote>
<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt' type=cite cite>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>Another possible way to access the code from multiple threads is to
have each thread use its own "UsageEnvironment" and
"TaskScheduler" objects, and thus its own event loop. The objects
created by each thread (i.e., using its own "UsageEnvironment") must
not interact (except via global variables).<o:p></o:p></span></font></p>
</blockquote>
<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt' type=cite cite>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>"<br>
<br>
Is there any good guide-lines to run the Live555 (or OpenRTSP example) in
multi-threaded fashion?<o:p></o:p></span></font></p>
</blockquote>
<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt' type=cite cite>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>Or my best bet would be to run separate processes?<o:p></o:p></span></font></p>
</blockquote>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>Yes, that's the best way - use multiple processes if you can.<o:p></o:p></span></font></p>
</div>
<pre><font size=2 face="Courier New"><span style='font-size:10.0pt'><x-sigsep>-- <o:p></o:p></span></font></pre>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><br>
</x-sigsep>Ross Finlayson<br>
Live Networks, Inc.<br>
http://www.live555.com/<o:p></o:p></span></font></p>
</div>
</div>
</body>
</html>