<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div><blockquote type="cite">Given that, why doesn't the sink take full ownership of the source object once you pass it to startPlaying()?</blockquote><div><br></div>Because it doesn't :-) That design decision was made (I think; it's been well over a decade now) because 'sources' and 'sinks' are different kinds of object. In principle, many different objects - not just a 'sink' - may want to perform some operation (other than 'playing') on a 'source'. And because the 'source' and 'sink' were each created by a third party (the "testMPEG2TransportStreamer" application code, in this case), it makes sense for the same third party to take responsibility for reclaiming the 'source' and 'sink' objects, when it wants to do so.</div><div><br></div><div>(OTOH, "FramedFilter" objects (a subclass of "FramedSource") *do* take ownership of their upstream input source object; that's why you can delete an entire filter chain by deleting just the tail "FramedFilter" object ("videoSource" in this case).)</div><div><br></div><div>Anyway, the way to avoid global variables in (your modified) "testMPEG2TransportStreamer" application is to use the 'clientData' parameter in the 'afterPlaying' callback. E.g., you can do something like:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>struct streamParameters {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>FramedSource* source;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>MediaSink* sink;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// any other stream-specific parameters that you want</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>};</div><div><br></div><div>and then:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>streamParameters* myStream = new streamParameters;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>myStream->source = videoSource;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>myStream->sink = videoSink;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>videoSink<-startPlaying(*videoSource, afterPlaying, myStream); // note: The last parameter to "startPlaying()" is different than before</div><div><br></div><div>and then, in "afterPlaying()":</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>void afterPlaying(void* clientData) {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>streamParameters* myStream = (streamParameters*)clientData;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>myStream->sink->stopPlaying();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Medium::close(myStream->source);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>play();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div>Voila! No global variables.</div><br><div apple-content-edited="true">
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; ">Ross Finlayson<br>Live Networks, Inc.<br><a href="http://www.live555.com/">http://www.live555.com/</a></span></span>
</div>
<br></body></html>