I have been doing a little bit of research around this issue:<div><br></div><div>Turns out that Qt is still using the older Carbon windowing framework, which means that the ID I am getting from Qt is actually a HIViewRef.</div>
<div><br></div><div>The "have-ns-view" message contains a value called "nsview", which can be cast to a "NSView*", which is a Cocoa based view (the system used by almost all OSX apps).</div><div>
<br></div><div>According to Apple's dev docs, there are a handful of Carbon functions, which allow one to attach a Cocoa view to a special wrapper, which makes it look like a Carbon view. I have tried this using the following code:</div>
<div><br></div><div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco">WindowHandle </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"><span style="color: #5c2699">CocoaHelper</span>::AttachCocoaViewFromMessage(<span style="color: #5c2699">GstMessage</span>* <span style="color: #3f6e74">message</span>, <span style="color: #aa0d91">const</span> WindowHandle& handle)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> WindowHandle outputHandle;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #007400"><span style="color: #000000"> </span>// Extract the cocoa view from the message:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> <span style="color: #5c2699">NSView</span>* cocoaView = (<span style="color: #5c2699">NSView</span>*)<span style="color: #2e0d6e">g_value_get_pointer</span>(</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #2e0d6e"><span style="color: #000000"> </span>gst_structure_get_value<span style="color: #000000">(</span><span style="color: #3f6e74">message</span><span style="color: #000000">-></span><span style="color: #5c2699">structure</span><span style="color: #000000">, </span><span style="color: #c41a16">"nsview"</span><span style="color: #000000">));</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> <span style="color: #aa0d91">if</span> (cocoaView == <span style="color: #1c00cf">0</span>)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #c41a16"><span style="color: #000000"> </span><span style="color: #643820">MEDIA_LOG_ERROR</span><span style="color: #000000">(</span>"Message does not contain a value with name \"nsview\""<span style="color: #000000">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> <span style="color: #aa0d91">return</span> outputHandle;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> }</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #007400"><span style="color: #000000"> </span>// Create Cocoa wrapper view:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> <span style="color: #5c2699">HIViewRef</span> cocoaWrapperView;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> <span style="color: #5c2699">OSStatus</span> retVal;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> retVal = HICocoaViewCreate(cocoaView, <span style="color: #1c00cf">0</span>, &cocoaWrapperView);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> [cocoaView release];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> <span style="color: #aa0d91">if</span> (retVal != <span style="color: #1c00cf">0</span>)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #c41a16"><span style="color: #000000"> </span><span style="color: #643820">MEDIA_LOG_ERROR</span><span style="color: #000000">(</span>"Unable to create Cocoa wrapper view, return value: "<span style="color: #000000">, retVal);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> <span style="color: #aa0d91">return</span> outputHandle;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> }</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #007400"><span style="color: #000000"> </span>// Attach view to incoming Carbon view:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #007400"><span style="color: #000000"> </span>// From Qt sources "qwidget_mac.cpp" confirms that a WId can be</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #007400"><span style="color: #000000"> </span>// safely converted to a HIViewRef on the mac. (see qt_mac_hiview_for line 254)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> <span style="color: #5c2699">HIViewRef</span> renderView = (<span style="color: #5c2699">HIViewRef</span>)handle.<span style="color: #2e0d6e">GetHandle</span>();</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> <span style="color: #aa0d91">if</span> ((retVal = <span style="color: #2e0d6e">HIViewAddSubview</span>(renderView, cocoaWrapperView)) != <span style="color: #1c00cf">0</span>)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #c41a16"><span style="color: #000000"> </span><span style="color: #643820">MEDIA_LOG_ERROR</span><span style="color: #000000">(</span>"Unable to attach Cocoa wrapper view to render view. "</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> <span style="color: #c41a16">" return value: "</span>, retVal);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> <span style="color: #aa0d91">return</span> outputHandle;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> }</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> outputHandle = <span style="color: #2e0d6e">WindowHandle</span>((<span style="color: #5c2699">HandleType</span>)cocoaWrapperView);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #c41a16"><span style="color: #000000"> </span><span style="color: #643820">MEDIA_LOG_INFO</span><span style="color: #000000">(</span>"Successfully attached Cocoa view "<span style="color: #000000">, </span><span style="color: #aa0d91">static_cast</span><span style="color: #000000"><</span><span style="color: #aa0d91">void</span><span style="color: #000000">*>(cocoaView),</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #c41a16"><span style="color: #000000"> </span>" to Carbon view with handle "<span style="color: #000000">, handle,</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #c41a16"><span style="color: #000000"> </span>". Handle of view wrapper view is "<span style="color: #000000">, outputHandle);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco"> <span style="color: #aa0d91">return</span> outputHandle;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco">}</p><div><span class="Apple-style-span" style="font-family: Monaco; font-size: 10px;"><br></span></div></div><div>The WindowHandle object is just a simple wrapper around the window ID I am getting from Qt (GetHandle() returns the same value as QWidget::winid()).<br>
</div><div><br></div><div>I am also calling NSApplicationLoad() during startup to ensure I can use Cocoa in my Carbon based app.</div><div><br></div><div>When I run my app, I don't see any video, instead I get a lot of the following messages in my debugger:</div>
<div><br></div><div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Courier"><span class="Apple-style-span" style="font-weight: bold;"></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Courier"><b>2008-06-27 11:05:38.106 com.neokast.stream.player.ui.view_TESTCASES[92020:a80b] invalid drawable</b></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Courier"><b>2008-06-27 11:05:38.147 com.neokast.stream.player.ui.view_TESTCASES[92020:a80b] *** _NSAutoreleaseNoPool(): Object 0x1af9cb10 of class NSSurface autoreleased with no pool in place - just leaking</b></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Courier"><b>Stack: (0x90c9e12f 0x90baaec2 0x92cdef8b 0x92daa15c 0x190b3bca 0x190b2af7 0x31791f2 0x317acf0 0x317b351 0x317b970 0x31f5d86 0x31f657a 0x31890e3 0x31f5d86 0x31f657a 0x18f13fff 0x3212309 0x32f97ec 0x32f76de 0x94ef3c55 0x94ef3b12)</b></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Courier"><b>2008-06-27 11:05:38.147 com.neokast.stream.player.ui.view_TESTCASES[92020:a80b] *** _NSAutoreleaseNoPool(): Object 0x1afc2dd0 of class NSCFString autoreleased with no pool in place - just leaking</b></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Courier"><b>Stack: (0x90c9e12f 0x90baaec2 0x92ddbc92 0x92daa15c 0x190b3bca 0x190b2af7 0x31791f2 0x317acf0 0x317b351 0x317b970 0x31f5d86 0x31f657a 0x31890e3 0x31f5d86 0x31f657a 0x18f13fff 0x3212309 0x32f97ec 0x32f76de 0x94ef3c55 0x94ef3b12)</b></p>
<div><br></div><p></p></div><div><br></div><div><br></div><div>I am less concerned about the apparent leakage (I have been experimenting with the NSAutoReleasePool to fix those), I think the main problem is the "invalid drawable" message. I would guess that the frequency of those messages roughly corresponds to the framerate.</div>
<div><br></div><div><br></div><div>I would greatly appreciate any input from more experienced Mac developers. I understand that my situation is further complicated by the fact that I am using Carbon. I will keep digging and post the solution when I find it. It would be great is someone could then take this code and use it for a proper implementation of the GstXOverlay interface for the OSX video sink.</div>
<div><br></div><div>Thanks,</div><div><br></div><div>Andreas</div><div><br></div><div><br><br><div class="gmail_quote">On Thu, Jun 26, 2008 at 9:41 AM, Andreas Schuler <<a href="mailto:andreas@neokast.com">andreas@neokast.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Thanks for your detailed response. I have taken a closer look at the source code for osxvideosink and found that it supports an "embed" property (which is FALSE by default).<br>
<br>I can tell that when TRUE it will emit a message called "have-ns-view", where it passes a GstGLView object to the callback. This object is an NSView (part of the Apple Cocoa framework). I have learned that I am supposed to attach that to a NSWindow.<br>
<br>Unfortunately I am pretty new to programming on the Mac. Thus far I have been using OS abstraction libraries such as Qt to avoid dealing with different windowing systems. Qt gives me back a window handle, which turns out to be integer but I have no idea how to retrieve a NSWindow object from that.<br>
<br>So if anyone has done this before on the Mac (with or without Qt) I would greatly appreciate your input.<br><br>Thanks,<br><font color="#888888"><br>Andreas</font><div><div></div><div class="Wj3C7c"><br><br><div class="gmail_quote">
On Wed, Jun 25, 2008 at 5:26 PM, Michael Smith <<a href="mailto:msmith@xiph.org" target="_blank">msmith@xiph.org</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left:1px solid rgb(204, 204, 204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex">
<div>On Wed, Jun 25, 2008 at 3:16 PM, Andreas Schuler <<a href="mailto:andreas@neokast.com" target="_blank">andreas@neokast.com</a>> wrote:<br>
> Hi all,<br>
><br>
> I am trying to get an application to run on a Max OSX <a href="http://10.5.2." target="_blank">10.5.2.</a> I have<br>
> downloaded and built the latest tar balls and everything seems to be running<br>
> fine when I use gst-launch.<br>
><br>
> >From within my app, which also runs on Windows, I am doing the following to<br>
> set the id of the window I want the video to be rendered on:<br>
><br>
> - get_bus_set_sync_handler to setup my callback<br>
> - The callback function looks as follows:<br>
<br>
</div>That looks good for Win32 and linux. On linux the 'window handle' will<br>
need to be the XID for the window, but that's just a matter of<br>
different platform-specific types, not a big problem.<br>
<br>
On OSX, you're presumably using osxvideosink (well, you say you're<br>
using autovideosink, but that'll be selecting osxvideosink<br>
internally).<br>
<br>
osxvideosink doesn't implement GstXOverlay, so you can't do this with<br>
it. Because of this it won't ever even emit the prepare-xwindow-id<br>
signal, which is what you're seeing.<br>
<br>
osxvideosink has some other interface to set this up, but I don't know<br>
the details of how it works. You may find looking at the output of<br>
"gst-inspect-0.10 osxvideosink" to be helpful - it'll tell you what<br>
signals exist, etc.<br>
<br>
If possible, it would be best to make osxvideosink implement the<br>
GstXOverlay interface - that would let people use more common code<br>
across different platforms. Looking into whether that's possible is on<br>
my TODO list, but pretty far down right now - I probably won't get to<br>
it for a month or two. If you manage to do that sooner, that'd be<br>
great - patches would be very welcome.<br>
<br>
Mike</blockquote></div></div></div></blockquote></div></div>