[vlc-devel] commit: libvlc: Attempt to fix set_nsobject() with QMacCocoaViewContainer and improve documentation. (Pierre d' Herbemont )

git version control git at videolan.org
Sun Feb 28 23:53:48 CET 2010


vlc | branch: master | Pierre d'Herbemont <pdherbemont at free.fr> | Sun Feb 28 23:53:00 2010 +0100| [892f3b5aa68e57dd35c0a95f13c6ac7112ec2d32] | committer: Pierre d'Herbemont 

libvlc: Attempt to fix set_nsobject() with QMacCocoaViewContainer and improve documentation.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=892f3b5aa68e57dd35c0a95f13c6ac7112ec2d32
---

 include/vlc/libvlc_media_player.h |   22 +++++++++++++++++++---
 modules/video_output/macosx.m     |   24 +++++++++++++++++++++---
 2 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index b8763ca..fb7b05b 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -193,8 +193,10 @@ VLC_PUBLIC_API void libvlc_media_player_stop ( libvlc_media_player_t *p_mi );
 /**
  * Set the NSView handler where the media player should render its video output.
  *
- * The object minimal_macosx expects is of kind NSObject and should
- * respect the protocol:
+ * Use the vout called "macosx".
+ *
+ * The drawable is an NSObject that follow the VLCOpenGLVideoViewEmbedding
+ * protocol:
  *
  * @begincode
  * \@protocol VLCOpenGLVideoViewEmbedding <NSObject>
@@ -203,10 +205,24 @@ VLC_PUBLIC_API void libvlc_media_player_stop ( libvlc_media_player_t *p_mi );
  * \@end
  * @endcode
  *
+ * Or it can be an NSView object.
+ *
+ * If you want to use it along with Qt4 see the QMacCocoaViewContainer. Then
+ * the following code should work:
+ * @begincode
+ * {
+ *     NSView *video = [[NSView alloc] init];
+ *     QMacCocoaViewContainer *container = new QMacCocoaViewContainer(video, parent);
+ *     libvlc_media_player_set_nsobject(mp, video);
+ *     [video release];
+ * }
+ * @endcode
+ *
  * You can find a live example in VLCVideoView in VLCKit.framework.
  *
  * \param p_mi the Media Player
- * \param drawable the NSView handler
+ * \param drawable the drawable that is either an NSView or an object following
+ * the VLCOpenGLVideoViewEmbedding protocol.
  */
 VLC_PUBLIC_API void libvlc_media_player_set_nsobject ( libvlc_media_player_t *p_mi, void * drawable );
 
diff --git a/modules/video_output/macosx.m b/modules/video_output/macosx.m
index fe508fe..ff965fd 100644
--- a/modules/video_output/macosx.m
+++ b/modules/video_output/macosx.m
@@ -144,7 +144,21 @@ static int Open(vlc_object_t *this)
     /* We don't wait, that means that we'll have to be careful about releasing
      * container.
      * That's why we'll release on main thread in Close(). */
-    [(id)container performSelectorOnMainThread:@selector(addVoutSubview:) withObject:sys->glView waitUntilDone:NO];
+    if ([(id)container respondsToSelector:@selector(addVoutSubview:)])
+        [(id)container performSelectorOnMainThread:@selector(addVoutSubview:) withObject:sys->glView waitUntilDone:NO];
+    else if ([container isKindOfClass:[NSView class]])
+    {
+        NSView *parentView = container;
+        [parentView performSelectorOnMainThread:@selector(addSubview:) withObject:sys->glView waitUntilDone:NO];
+        [sys->glView performSelectorOnMainThread:@selector(setFrame:) withObject:[NSValue valueWithRect:[parentView bounds]] waitUntilDone:NO];
+    }
+    else
+    {
+        msg_Err(vd, "Invalid drawable-nsobject object. drawable-nsobject must either be an NSView or comply to the @protocol VLCOpenGLVideoViewEmbedding.");
+        goto error;
+    }
+
+
     [nsPool release];
     nsPool = nil;
 
@@ -192,8 +206,11 @@ void Close(vlc_object_t *this)
     [sys->glView setVoutDisplay:nil];
 
     var_Destroy(vd, "drawable-nsobject");
-    /* This will retain sys->glView */
-    [(id)sys->container performSelectorOnMainThread:@selector(removeVoutSubview:) withObject:sys->glView waitUntilDone:NO];
+    if ([(id)sys->container respondsToSelector:@selector(removeVoutSubview:)])
+    {
+        /* This will retain sys->glView */
+        [(id)sys->container performSelectorOnMainThread:@selector(removeVoutSubview:) withObject:sys->glView waitUntilDone:NO];
+    }
     /* release on main thread as explained in Open() */
     [(id)sys->container performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];
     [sys->glView performSelectorOnMainThread:@selector(removeFromSuperview) withObject:nil waitUntilDone:NO];
@@ -353,6 +370,7 @@ static void OpenglSwap(vout_opengl_t *gl)
     GLint params[] = { 1 };
     CGLSetParameter([[self openGLContext] CGLContextObj], kCGLCPSwapInterval, params);
 
+    [self setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
     return self;
 }
 




More information about the vlc-devel mailing list