After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 578811 - crash with cocoa backend
crash with cocoa backend
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-gl
git master
Other Mac OS
: Normal normal
: 0.10.2
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2009-04-13 06:39 UTC by David Schleef
Modified: 2009-08-10 23:42 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
register objc thread (2.98 KB, application/octet-stream)
2009-05-09 01:02 UTC, Julien Isorce
Details

Description David Schleef 2009-04-13 06:39:11 UTC
I recently fixed some compile difficulties with the cocoa backend on mac os.  Running 'gst-launch videotestsrc ! glimagesink', I get:

  • #0 -[NSView setFrameSize:]
  • #1 -[NSView setFrame:]
  • #2 -[NSWindow setContentView:]
  • #3 -[GstGLNSWindow initWithContentRect:styleMask:backing:defer:screen:gstWin:]
    at gstglwindow_cocoa.m line 401
  • #4 gst_gl_window_new
    at gstglwindow_cocoa.m line 183
  • #5 gst_gl_display_thread_create_context
    at gstgldisplay.c line 529
  • #6 g_thread_create_proxy
    at gthread.c line 635
  • #7 _pthread_start
  • #8 thread_start

Comment 1 David Schleef 2009-04-13 06:43:24 UTC
Same result with gtkxoverlay test.
Comment 2 Tristan Matthews 2009-04-14 17:39:47 UTC
the latest changes to gst-plugins-gl are probably responsible for this bug:
http://bugzilla.gnome.org/show_bug.cgi?id=578939
Comment 3 Julien Isorce 2009-05-09 01:02:06 UTC
Created attachment 134292 [details]
register objc thread
Comment 4 Julien Isorce 2009-05-09 01:03:25 UTC
Hi,

On Mac OSX there is no GSRegisterCurrentThread (which is GNUstep specific).
The crash you got comes shows that we finally cannot avoid it as it's currently done.
For now in gst-plugins-gl/gst-libs/gst/gl/gstglwindow_cocoa.m we have:

#ifndef GNUSTEP
static BOOL GSRegisterCurrentThread(void) { return TRUE; };
static void GSUnregisterCurrentThread(void) {};
#endif

I attached a possible implementation that comes from GNUstep code (gnustep-base-1.18.0/Source/NSThread.m) with some modifications I made to adapt it to our case. 
(it's not a patch, you have to put the attachment code into gstglwindow_cocoa.m)

I have no Mac machine so I let you try it.

Julien
Comment 5 Julien Isorce 2009-07-27 08:48:24 UTC
G.P. : 

"
Neither objc_mutex_t nor objc/thr.h exists on Mac OS X.

There are two Objective-C runtime implementations: the one originally written by NeXT, and the one originally written for GNU. They both implement the same language (more or less), but their internal structure, file formats, and introspection API are incompatible. Mac OS X uses the NeXT runtime, and gcc includes the GNU runtime to be used on platforms other than Mac OS X.

GSRegisterCurrentThread() tells the GNU runtime about a non-NSThread. There's no need to do that on Mac OS X unless you're using the garbage collector.

As far as I know there is no way to reassign the main thread. The main thread must always be the one started by the kernel at process launch.
"


My approach was to reassign the main thread and so make the gl thread the main thread. Then I could run the nsapp loop in the gk thread. But it's only possible with GNUstep. Moreover it causes problems when using several glimagesink, because it was attempting to have several main threads and this is not possible.

So I changed my approach a little bit.
We have two cases : non-embedded (gst-launch), and embedded (cocoa application)

The nsapp is initialized at gstglwindow class initialization to make sure the nsapp is initialized only one time (for multiple sink).
In non-embedded mode the nsapp is initialized in the main thread through the g_main_loop (which is runnning in the main thread when using gst-launch).
In embedded mode the nsapp is initialized by the user in his client code (see gst-plugins-gl/tests/exampples/cocoa/videoxoverlay/main.m)


In the gl thread I am now running a NSRunLoop associated with the NSThread (which is associated to the gl thread)
This loop performs all OpenGL calls and hanldes the events of the non-embedded window.
In embedded mode, this loop only handles OpenGL calls.(the gl context is made current only one time).
Also in embedded mode, the user can run the nsapp as normal. (see gst-plugins-gl/tests/exampples/cocoa/videoxoverlay/main.m)

commit 6f80b865d5fb7e7cf70541324abb985ce48ba0ef    
Author: Julien Isorce <julien.isorce@gmail.com>    
Date:   Mon Jul 27 09:58:20 2009 +0200             

    Cocoa backend: make sure that nsapp is initialized
                                                      
    gst-launch-0.10 videotestsrc ! tee name=t ! queue ! glimagesink t. ! queue ! glimagesink
    now works properly on MacOSX                                                              

commit db69e930c5ef485f6ba16dd79af8e2da71a617ce
Author: Julien Isorce <julien.isorce@gmail.com>
Date:   Fri Jul 24 10:12:07 2009 +0200         

    Cocoa backend: fix crash when closing
                                         
    - All gstglwindow members are now modified only in the gl thread
    to avoid thread concurrency
    - OpenGL context is now properly clean
    - fix a couple of things in implementation of xoverlay interface

commit f13d38b8e76974792905b2beb9aa01cf0a6af261
Author: Julien Isorce <julien.isorce@gmail.com>
Date:   Fri Jul 17 16:47:41 2009 +0200

    make cocoa backend work on MacOSX

    It works with both gst-launch and a cocoa app (non-embedded and embedded)
    But there is still some problems:
      - sometimes crash when closing
      - flickering when resizing
      - embedded mode not perfect

    I will first make the CMake build work with cocoa backend
    in order to generate a XCode project.
    Then it should be easier to fix those issues.