instrumentation: add next-share/
[cs-p2p-next.git] / instrumentation / next-share / BaseLib / Player / Build / Mac / vlc-macosx-compile.patch
1 Index: modules/gui/macosx/voutqt.m
2 ===================================================================
3 --- modules/gui/macosx/voutqt.m (revision 20403)
4 +++ modules/gui/macosx/voutqt.m (working copy)
5 @@ -39,6 +39,7 @@
6  
7  #include "intf.h"
8  #include "vout.h"
9 +#include <vlc/libvlc_structures.h>
10  
11  #define QT_MAX_DIRECTBUFFERS 10
12  #define VL_MAX_DISPLAYS 16
13 @@ -138,13 +139,22 @@
14      p_vout->pf_display = DisplayVideo;
15      p_vout->pf_control = ControlVideo;
16  
17 -    /* Are we embedded?  If so, the drawable value will be a pointer to a
18 +    /* Are we embedded?  If so, the drawable value should be a pointer to a
19       * CGrafPtr that we're expected to use */
20      var_Get( p_vout->p_libvlc, "drawable", &value_drawable );
21 -    if( value_drawable.i_int != 0 )
22 +    if( value_drawable.i_int != 0 ) {
23 +        vlc_value_t value_drawable_type;
24 +
25 +        var_Get( p_vout->p_libvlc, "macosx-drawable-type", &value_drawable_type );
26 +        if( value_drawable_type.i_int != VLCDrawableCGrafPtr ) {
27 +            msg_Err( p_vout, "QT interface requires a CGrafPtr when embedded" );
28 +            return( 1 );
29 +        }
30 +
31          p_vout->p_sys->b_embedded = VLC_TRUE;
32 -    else
33 +    } else {
34          p_vout->p_sys->b_embedded = VLC_FALSE;
35 +    }
36  
37      p_vout->p_sys->b_cpu_has_simd =
38          vlc_CPU() & (CPU_CAPABILITY_ALTIVEC|CPU_CAPABILITY_MMXEXT);
39 Index: modules/gui/macosx/voutgl.m
40 ===================================================================
41 --- modules/gui/macosx/voutgl.m (revision 20403)
42 +++ modules/gui/macosx/voutgl.m (working copy)
43 @@ -35,6 +35,7 @@
44  #include <string.h>                                            /* strerror() */
45  
46  #include <vlc_keys.h>
47 +#include <vlc/libvlc_structures.h>
48  
49  #include "intf.h"
50  #include "vout.h"
51 @@ -43,6 +44,7 @@
52  #include <OpenGL/gl.h>
53  
54  #include <AGL/agl.h>
55 +#include <Carbon/Carbon.h>
56  
57  /*****************************************************************************
58   * VLCGLView interface
59 @@ -67,13 +69,18 @@
60      /* Mozilla plugin-related variables */
61      vlc_bool_t          b_embedded;
62      AGLContext          agl_ctx;
63 -    AGLDrawable         agl_drawable;
64      int                 i_offx, i_offy;
65      int                 i_width, i_height;
66      WindowRef           theWindow;
67      WindowGroupRef      winGroup;
68      vlc_bool_t          b_clipped_out;
69 -    Rect                clipBounds, viewBounds;             
70 +    Rect                clipBounds, viewBounds;
71 +
72 +    libvlc_macosx_drawable_type_t drawable_type;
73 +    union {
74 +        CGrafPtr        CGrafPtr;
75 +        ControlRef      ControlRef;
76 +    } drawable;
77  };
78  
79  /*****************************************************************************
80 @@ -462,17 +469,90 @@
81  static void aglReshape( vout_thread_t * p_vout );
82  static OSStatus WindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
83  
84 -static int aglInit( vout_thread_t * p_vout )
85 +/* returns the bounds of the drawable control/window */
86 +static Rect aglGetBounds( vout_thread_t * p_vout )
87  {
88 +        WindowRef win;
89 +        Rect rect;
90 +
91 +        switch( p_vout->p_sys->drawable_type ) {
92 +            case VLCDrawableCGrafPtr:
93 +                win = GetWindowFromPort( p_vout->p_sys->drawable.CGrafPtr );
94 +                GetWindowPortBounds( win, &rect );
95 +                break;
96 +
97 +            case VLCDrawableControlRef:
98 +                win = GetControlOwner( p_vout->p_sys->drawable.ControlRef );
99 +                GetControlBounds( p_vout->p_sys->drawable.ControlRef, &rect );
100 +                break;
101 +        }
102 +
103 +        return rect;
104 +}
105 +
106 +/* returns the window containing the drawable area */
107 +static WindowRef aglGetWindow( vout_thread_t * p_vout )
108 +{
109 +        WindowRef window;
110 +
111 +        switch( p_vout->p_sys->drawable_type ) {
112 +            case VLCDrawableCGrafPtr:
113 +                window = GetWindowFromPort( p_vout->p_sys->drawable.CGrafPtr );
114 +                break;
115 +
116 +            case VLCDrawableControlRef:
117 +                window = GetControlOwner( p_vout->p_sys->drawable.ControlRef );
118 +                break;
119 +        }
120 +
121 +        return window;
122 +}
123 +
124 +/* gets the graphics port associated with our drawing area */
125 +static CGrafPtr aglGetPort( vout_thread_t * p_vout )
126 +{
127 +        CGrafPtr port;
128 +
129 +        switch( p_vout->p_sys->drawable_type ) {
130 +            case VLCDrawableCGrafPtr:
131 +                port = p_vout->p_sys->drawable.CGrafPtr;
132 +                break;
133 +
134 +            case VLCDrawableControlRef:
135 +                port = GetWindowPort( GetControlOwner(
136 +                           p_vout->p_sys->drawable.ControlRef
137 +                       ) );
138 +                break;
139 +        }
140 +
141 +        return port;
142 +}
143 +
144 +/* (re)process "drawable-*" and "macosx-drawable-type" variables. `drawable' is a
145 +   parameter to allow it to be overridden (REPARENT) */
146 +static int aglProcessDrawable( vout_thread_t * p_vout, libvlc_drawable_t drawable )
147 +{
148      vlc_value_t val;
149 +    vlc_value_t val_type;
150 +    AGLDrawable agl_drawable;
151 +    Rect clipBounds,viewBounds;
152  
153 -    Rect viewBounds;    
154 -    Rect clipBounds;
155 -    
156 -    var_Get( p_vout->p_libvlc, "drawable", &val );
157 -    p_vout->p_sys->agl_drawable = (AGLDrawable)val.i_int;
158 -    aglSetDrawable(p_vout->p_sys->agl_ctx, p_vout->p_sys->agl_drawable);
159 +    var_Get( p_vout->p_libvlc, "macosx-drawable-type", &val_type );
160  
161 +    p_vout->p_sys->drawable_type = val_type.i_int;
162 +    switch( val_type.i_int ) {
163 +        case VLCDrawableCGrafPtr:
164 +            p_vout->p_sys->drawable.CGrafPtr = (CGrafPtr)drawable;
165 +            break;
166 +
167 +        case VLCDrawableControlRef:
168 +            p_vout->p_sys->drawable.ControlRef = (ControlRef)drawable;
169 +            break;
170 +    }
171 +
172 +    agl_drawable = (AGLDrawable)aglGetPort( p_vout );
173 +    aglSetDrawable(p_vout->p_sys->agl_ctx, agl_drawable);
174 +
175      var_Get( p_vout->p_libvlc, "drawable-view-top", &val );
176      viewBounds.top = val.i_int;
177      var_Get( p_vout->p_libvlc, "drawable-view-left", &val );
178 @@ -481,15 +561,21 @@
179      viewBounds.bottom = val.i_int;
180      var_Get( p_vout->p_libvlc, "drawable-view-right", &val );
181      viewBounds.right = val.i_int;
182 -    var_Get( p_vout->p_libvlc, "drawable-clip-top", &val );
183 -    clipBounds.top = val.i_int;
184 -    var_Get( p_vout->p_libvlc, "drawable-clip-left", &val );
185 -    clipBounds.left = val.i_int;
186 -    var_Get( p_vout->p_libvlc, "drawable-clip-bottom", &val );
187 -    clipBounds.bottom = val.i_int;
188 -    var_Get( p_vout->p_libvlc, "drawable-clip-right", &val );
189 -    clipBounds.right = val.i_int;
190  
191 +    if( !viewBounds.top && !viewBounds.left && !viewBounds.right && !viewBounds.bottom ) {
192 +        /* view bounds not set, use control/window bounds */
193 +        clipBounds = viewBounds = aglGetBounds( p_vout );
194 +    } else {
195 +        var_Get( p_vout->p_libvlc, "drawable-clip-top", &val );
196 +        clipBounds.top = val.i_int;
197 +        var_Get( p_vout->p_libvlc, "drawable-clip-left", &val );
198 +        clipBounds.left = val.i_int;
199 +        var_Get( p_vout->p_libvlc, "drawable-clip-bottom", &val );
200 +        clipBounds.bottom = val.i_int;
201 +        var_Get( p_vout->p_libvlc, "drawable-clip-right", &val );
202 +        clipBounds.right = val.i_int;
203 +    }
204 +
205      p_vout->p_sys->b_clipped_out = (clipBounds.top == clipBounds.bottom)
206                                   || (clipBounds.left == clipBounds.right);
207      if( ! p_vout->p_sys->b_clipped_out )
208 @@ -501,7 +587,15 @@
209      }
210      p_vout->p_sys->clipBounds = clipBounds;
211      p_vout->p_sys->viewBounds = viewBounds;
212 +}
213  
214 +static int aglInit( vout_thread_t * p_vout )
215 +{
216 +    vlc_value_t val;
217 +
218 +    var_Get( p_vout->p_libvlc, "drawable", &val );
219 +    aglProcessDrawable( p_vout, val.i_int );
220 +
221      return VLC_SUCCESS;
222  }
223  
224 @@ -564,6 +658,26 @@
225  
226  static int aglManage( vout_thread_t * p_vout )
227  {
228 +    if( p_vout->p_sys->drawable_type == VLCDrawableControlRef ) {
229 +        /* auto-detect size changes in the control by polling */
230 +        Rect clipBounds, viewBounds;
231 +
232 +        clipBounds = viewBounds = aglGetBounds( p_vout );
233 +
234 +        if( memcmp(&clipBounds, &(p_vout->p_sys->clipBounds), sizeof(clipBounds) )
235 +         && memcmp(&viewBounds, &(p_vout->p_sys->viewBounds), sizeof(viewBounds)) )
236 +        {
237 +            /* size has changed since last poll */
238 +
239 +            p_vout->p_sys->clipBounds = clipBounds;
240 +            p_vout->p_sys->viewBounds = viewBounds;
241 +            aglLock( p_vout );
242 +            aglSetViewport(p_vout, viewBounds, clipBounds);
243 +            aglReshape( p_vout );
244 +            aglUnlock( p_vout );
245 +        }
246 +    }
247 +
248      if( p_vout->i_changes & VOUT_ASPECT_CHANGE )
249      {
250          aglLock( p_vout );
251 @@ -586,42 +700,28 @@
252          {
253              /* Close the fullscreen window and resume normal drawing */
254              vlc_value_t val;
255 -            Rect viewBounds;    
256 -            Rect clipBounds;
257  
258              var_Get( p_vout->p_libvlc, "drawable", &val );
259 -            p_vout->p_sys->agl_drawable = (AGLDrawable)val.i_int;
260 -            aglSetDrawable(p_vout->p_sys->agl_ctx, p_vout->p_sys->agl_drawable);
261 +            aglProcessDrawable( p_vout, val.i_int );
262  
263 -            var_Get( p_vout->p_libvlc, "drawable-view-top", &val );
264 -            viewBounds.top = val.i_int;
265 -            var_Get( p_vout->p_libvlc, "drawable-view-left", &val );
266 -            viewBounds.left = val.i_int;
267 -            var_Get( p_vout->p_libvlc, "drawable-view-bottom", &val );
268 -            viewBounds.bottom = val.i_int;
269 -            var_Get( p_vout->p_libvlc, "drawable-view-right", &val );
270 -            viewBounds.right = val.i_int;
271 -            var_Get( p_vout->p_libvlc, "drawable-clip-top", &val );
272 -            clipBounds.top = val.i_int;
273 -            var_Get( p_vout->p_libvlc, "drawable-clip-left", &val );
274 -            clipBounds.left = val.i_int;
275 -            var_Get( p_vout->p_libvlc, "drawable-clip-bottom", &val );
276 -            clipBounds.bottom = val.i_int;
277 -            var_Get( p_vout->p_libvlc, "drawable-clip-right", &val );
278 -            clipBounds.right = val.i_int;
279 +            /*the following was here, superfluous due to the same in aglLock?
280 +              aglSetCurrentContext(p_vout->p_sys->agl_ctx);*/
281  
282 -            aglSetCurrentContext(p_vout->p_sys->agl_ctx);
283 -            aglSetViewport(p_vout, viewBounds, clipBounds);
284 -
285              /* Most Carbon APIs are not thread-safe, therefore delagate some GUI visibilty update to the main thread */
286              sendEventToMainThread(GetWindowEventTarget(p_vout->p_sys->theWindow), kEventClassVLCPlugin, kEventVLCPluginHideFullscreen);
287          }
288          else
289          {
290 +            CGDirectDisplayID displayID;
291 +            CGRect displayBounds;
292              Rect deviceRect;
293              
294 -            GDHandle deviceHdl = GetMainDevice();
295 -            deviceRect = (*deviceHdl)->gdRect;
296 +            /* the main display has its origin at (0,0) */
297 +            displayBounds = CGDisplayBounds( CGMainDisplayID() );
298 +            deviceRect.left = 0;
299 +            deviceRect.top = 0;
300 +            deviceRect.right = displayBounds.size.width;
301 +            deviceRect.bottom = displayBounds.size.height;
302              
303              if( !p_vout->p_sys->theWindow )
304              {
305 @@ -669,8 +769,9 @@
306                  SetWindowBounds(p_vout->p_sys->theWindow, kWindowContentRgn, &deviceRect);
307              }
308              glClear( GL_COLOR_BUFFER_BIT );
309 -            p_vout->p_sys->agl_drawable = (AGLDrawable)GetWindowPort(p_vout->p_sys->theWindow);
310 -            aglSetDrawable(p_vout->p_sys->agl_ctx, p_vout->p_sys->agl_drawable);
311 +            p_vout->p_sys->drawable_type = VLCDrawableCGrafPtr;
312 +            p_vout->p_sys->drawable.CGrafPtr = GetWindowPort(p_vout->p_sys->theWindow);
313 +            aglSetDrawable(p_vout->p_sys->agl_ctx, p_vout->p_sys->drawable.CGrafPtr);
314              aglSetCurrentContext(p_vout->p_sys->agl_ctx);
315              aglSetViewport(p_vout, deviceRect, deviceRect);
316              //aglSetFullScreen(p_vout->p_sys->agl_ctx, device_width, device_height, 0, 0);
317 @@ -753,11 +854,10 @@
318  
319          case VOUT_REPARENT:
320          {
321 -            AGLDrawable drawable = (AGLDrawable)va_arg( args, int);
322 -            if( !p_vout->b_fullscreen && drawable != p_vout->p_sys->agl_drawable )
323 +            libvlc_drawable_t drawable = (libvlc_drawable_t)va_arg( args, int);
324 +            if( !p_vout->b_fullscreen )
325              {
326 -                p_vout->p_sys->agl_drawable = drawable;
327 -                aglSetDrawable(p_vout->p_sys->agl_ctx, drawable);
328 +                aglProcessDrawable( p_vout, drawable );
329              }
330              return VLC_SUCCESS;
331          }
332 @@ -771,8 +871,16 @@
333  {
334      if( ! p_vout->p_sys->b_clipped_out )
335      {
336 +        WindowRef win;
337 +        Rect rect;
338 +
339          p_vout->p_sys->b_got_frame = VLC_TRUE;
340          aglSwapBuffers(p_vout->p_sys->agl_ctx);
341 +
342 +        win = aglGetWindow( p_vout );
343 +        rect = aglGetBounds( p_vout );
344 +
345 +        InvalWindowRect( win, &rect );
346      }
347      else
348      {
349 @@ -788,12 +896,14 @@
350      // however AGL coordinates are based on window structure region
351      // and are vertically flipped
352      GLint rect[4];
353 -    CGrafPtr port = (CGrafPtr)p_vout->p_sys->agl_drawable;
354 +    WindowRef window;
355      Rect winBounds, clientBounds;
356  
357 -    GetWindowBounds(GetWindowFromPort(port),
358 +    window = aglGetWindow( p_vout );
359 +
360 +    GetWindowBounds(window,
361          kWindowStructureRgn, &winBounds);
362 -    GetWindowBounds(GetWindowFromPort(port),
363 +    GetWindowBounds(window,
364          kWindowContentRgn, &clientBounds);
365  
366      /* update video clipping bounds in drawable */
367 Index: bindings/python/vlc_instance.c
368 ===================================================================
369 --- bindings/python/vlc_instance.c      (revision 20403)
370 +++ bindings/python/vlc_instance.c      (working copy)
371 @@ -349,6 +349,30 @@
372  }
373  
374  static PyObject *
375 +vlcInstance_video_set_macosx_parent_type( PyObject *self, PyObject *args )
376 +{
377 +    libvlc_exception_t ex;
378 +    int i_drawable_type;
379 +
380 +    if( !PyArg_ParseTuple( args, "i", &i_drawable_type ) )
381 +        return NULL;
382 +
383 +    if( i_drawable_type != VLCDrawableCGrafPtr
384 +     && i_drawable_type != VLCDrawableControlRef )
385 +    {
386 +        PyErr_SetString( vlcInstance_Exception, "Invalid drawable type." );
387 +        return NULL;
388 +    }
389 +
390 +    LIBVLC_TRY;
391 +    libvlc_video_set_macosx_parent_type( LIBVLC_INSTANCE->p_instance, (libvlc_macosx_drawable_type_t) i_drawable_type, &ex );
392 +    LIBVLC_EXCEPT;
393 +
394 +    Py_INCREF( Py_None );
395 +    return Py_None;
396 +}
397 +
398 +static PyObject *
399  vlcInstance_video_set_size( PyObject *self, PyObject *args )
400  {
401      libvlc_exception_t ex;
402 @@ -733,6 +757,8 @@
403        "playlist_get_input() -> object   Return the current input"},
404      { "video_set_parent", vlcInstance_video_set_parent, METH_VARARGS,
405        "video_set_parent(xid=int)       Set the parent xid or HWND"},
406 +    { "video_set_macosx_parent_type", vlcInstance_video_set_macosx_parent_type, METH_VARARGS,
407 +      "video_set_macosx_parent_type(drawabletype=int)       Set the type of parent used on Mac OS/X (see the Drawable* constants)"},
408      { "video_set_size", vlcInstance_video_set_size, METH_VARARGS,
409        "video_set_size(width=int, height=int)    Set the video width and height"},
410      { "audio_toggle_mute", vlcInstance_audio_toggle_mute, METH_VARARGS,
411 Index: bindings/python/vlc_module.c
412 ===================================================================
413 --- bindings/python/vlc_module.c        (revision 20403)
414 +++ bindings/python/vlc_module.c        (working copy)
415 @@ -147,6 +147,10 @@
416                               mediacontrol_EndStatus );
417      PyModule_AddIntConstant( p_module, "UndefinedStatus",
418                               mediacontrol_UndefinedStatus );
419 +    PyModule_AddIntConstant( p_module, "DrawableCGrafPtr",
420 +                             VLCDrawableCGrafPtr );
421 +    PyModule_AddIntConstant( p_module, "DrawableControlRef",
422 +                             VLCDrawableControlRef );
423  }
424  
425  
426 Index: src/control/video.c
427 ===================================================================
428 --- src/control/video.c (revision 20403)
429 +++ src/control/video.c (working copy)
430 @@ -277,6 +277,21 @@
431  
432  /* global video settings */
433  
434 +void libvlc_video_set_macosx_parent_type( libvlc_instance_t *p_instance, libvlc_macosx_drawable_type_t t,
435 +                              libvlc_exception_t *p_e )
436 +{
437 +    var_SetInteger(p_instance->p_libvlc_int, "macosx-drawable-type", (int)t);
438 +}
439 +
440 +libvlc_macosx_drawable_type_t libvlc_video_get_macosx_parent_type( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
441 +{
442 +    libvlc_macosx_drawable_type_t result;
443 +    
444 +    result = var_GetInteger( p_instance->p_libvlc_int, "macosx-drawable-type" );
445 +    
446 +    return result;
447 +}
448 +
449  void libvlc_video_set_parent( libvlc_instance_t *p_instance, libvlc_drawable_t d,
450                                libvlc_exception_t *p_e )
451  {
452 Index: src/libvlc-common.c
453 ===================================================================
454 --- src/libvlc-common.c (revision 20403)
455 +++ src/libvlc-common.c (working copy)
456 @@ -941,6 +941,10 @@
457      var_Create( p_libvlc, "drawable-clip-bottom", VLC_VAR_INTEGER );
458      var_Create( p_libvlc, "drawable-clip-right", VLC_VAR_INTEGER );
459  
460 +#ifdef __APPLE__
461 +    var_Create( p_libvlc, "macosx-drawable-type", VLC_VAR_INTEGER );
462 +#endif
463 +
464      /* Create volume callback system. */
465      var_Create( p_libvlc, "volume-change", VLC_VAR_BOOL );
466  
467 Index: include/vlc/libvlc.h
468 ===================================================================
469 --- include/vlc/libvlc.h        (revision 20403)
470 +++ include/vlc/libvlc.h        (working copy)
471 @@ -424,6 +424,10 @@
472   */
473  VLC_PUBLIC_API void libvlc_video_redraw_rectangle( libvlc_input_t *, const libvlc_rectangle_t *, libvlc_exception_t * );
474  
475 +VLC_PUBLIC_API void libvlc_video_set_macosx_parent_type( libvlc_instance_t *, libvlc_macosx_drawable_type_t, libvlc_exception_t * );
476 +
477 +VLC_PUBLIC_API libvlc_macosx_drawable_type_t libvlc_video_get_macosx_parent_type( libvlc_instance_t *, libvlc_exception_t * );
478 +
479  /**
480   * Set the default video output parent
481   *  this settings will be used as default for all video outputs
482 Index: include/vlc/libvlc_structures.h
483 ===================================================================
484 --- include/vlc/libvlc_structures.h     (revision 20403)
485 +++ include/vlc/libvlc_structures.h     (working copy)
486 @@ -83,12 +83,22 @@
487  /**
488  * Downcast to this general type as placeholder for a platform specific one, such as:
489  *  Drawable on X11,
490 -*  CGrafPort on MacOSX,
491 +*  (libvlc_macosx_drawable_type_t) on MacOSX,
492  *  HWND on win32
493  */
494  typedef int libvlc_drawable_t;
495  
496  /**
497 +* Type of libvlc_drawable_t on MaxOSX. Available types:
498 +* - VLCDrawableCGrafPtr
499 +* - VLCDrawableControlRef
500 +*/
501 +typedef enum {
502 +    VLCDrawableCGrafPtr = 0,
503 +    VLCDrawableControlRef,
504 +} libvlc_macosx_drawable_type_t;
505 +
506 +/**
507  * Rectangle type for video geometry
508  */
509  typedef struct