osxvideosink: fix setting window handle after transition
[platform/upstream/gstreamer.git] / sys / osxvideo / osxvideosink.h
1 /* GStreamer
2  * Copyright (C) 2004-6 Zaheer Abbas Merali <zaheerabbas at merali dot org>
3  * Copyright (C) 2007 Pioneers of the Inevitable <songbird@songbirdnest.com>
4  *
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  *
22  * The development of this code was made possible due to the involvement of Pioneers 
23  * of the Inevitable, the creators of the Songbird Music player
24  * 
25  */
26  
27 #ifndef __GST_OSX_VIDEO_SINK_H__
28 #define __GST_OSX_VIDEO_SINK_H__
29
30 #include <gst/video/gstvideosink.h>
31
32 #include <string.h>
33 #include <math.h>
34 #include <objc/runtime.h>
35 #include <Cocoa/Cocoa.h>
36
37 #include <QuickTime/QuickTime.h>
38 #import "cocoawindow.h"
39
40 GST_DEBUG_CATEGORY_EXTERN (gst_debug_osx_video_sink);
41 #define GST_CAT_DEFAULT gst_debug_osx_video_sink
42
43 /* The hack doesn't work on leopard, the _CFMainPThread symbol
44  * is doesn't exist in the CoreFoundation library */
45 #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_5
46 #ifdef RUN_NS_APP_THREAD
47 #undef RUN_NS_APP_THREAD
48 #endif
49 #endif
50
51 G_BEGIN_DECLS
52
53 #define GST_TYPE_OSX_VIDEO_SINK \
54   (gst_osx_video_sink_get_type())
55 #define GST_OSX_VIDEO_SINK(obj) \
56   (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_OSX_VIDEO_SINK, GstOSXVideoSink))
57 #define GST_OSX_VIDEO_SINK_CLASS(klass) \
58   (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_OSX_VIDEO_SINK, GstOSXVideoSinkClass))
59 #define GST_IS_OSX_VIDEO_SINK(obj) \
60   (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_OSX_VIDEO_SINK))
61 #define GST_IS_OSX_VIDEO_SINK_CLASS(klass) \
62   (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_OSX_VIDEO_SINK))
63
64 typedef struct _GstOSXWindow GstOSXWindow;
65
66 typedef struct _GstOSXVideoSink GstOSXVideoSink;
67 typedef struct _GstOSXVideoSinkClass GstOSXVideoSinkClass;
68
69 #define GST_TYPE_OSXVIDEOBUFFER (gst_osxvideobuffer_get_type())
70
71 /* OSXWindow stuff */
72 struct _GstOSXWindow {
73   gint width, height;
74   gboolean closed;
75   gboolean internal;
76   GstGLView* gstview;
77   GstOSXVideoSinkWindow* win;
78 };
79
80 struct _GstOSXVideoSink {
81   /* Our element stuff */
82   GstVideoSink videosink;
83   GstOSXWindow *osxwindow;
84   void *osxvideosinkobject;
85   NSView *superview;
86   NSThread *ns_app_thread;
87 #ifdef RUN_NS_APP_THREAD
88   GMutex loop_thread_lock;
89   GCond loop_thread_cond;
90 #else
91   guint cocoa_timeout;
92 #endif
93   GMutex mrl_check_lock;
94   GCond mrl_check_cond;
95   gboolean mrl_check_done;
96   gboolean main_run_loop_running;
97   gboolean app_started;
98   gboolean keep_par;
99   gboolean embed;
100 };
101
102 struct _GstOSXVideoSinkClass {
103   GstVideoSinkClass parent_class;
104 };
105
106 GType gst_osx_video_sink_get_type(void);
107
108 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
109 @interface NSApplication(AppleMenu)
110 - (void)setAppleMenu:(NSMenu *)menu;
111 @end
112 #endif
113
114 @interface GstBufferObject : NSObject
115 {
116   @public
117   GstBuffer *buf;
118 }
119
120 -(id) initWithBuffer: (GstBuffer *) buf;
121 @end
122
123
124 #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_5
125 @interface GstWindowDelegate : NSObject
126 #else
127 @interface GstWindowDelegate : NSObject <NSWindowDelegate>
128 #endif
129 {
130   @public
131   GstOSXVideoSink *osxvideosink;
132 }
133 -(id) initWithSink: (GstOSXVideoSink *) sink;
134 @end
135
136 @interface GstOSXVideoSinkObject : NSObject
137 {
138   @public
139   GstOSXVideoSink *osxvideosink;
140 }
141
142 -(id) initWithSink: (GstOSXVideoSink *) sink;
143 -(void) createInternalWindow;
144 -(void) resize;
145 -(void) destroy;
146 -(void) showFrame: (GstBufferObject*) buf;
147 #ifdef RUN_NS_APP_THREAD
148 + (BOOL) isMainThread;
149 -(void) nsAppThread;
150 -(void) checkMainRunLoop;
151 #endif
152 @end
153
154 G_END_DECLS
155
156 #endif /* __GST_OSX_VIDEO_SINK_H__ */
157