Commit 892f3b5a authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

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

parent 1609af14
...@@ -193,8 +193,10 @@ VLC_PUBLIC_API void libvlc_media_player_stop ( libvlc_media_player_t *p_mi ); ...@@ -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. * Set the NSView handler where the media player should render its video output.
* *
* The object minimal_macosx expects is of kind NSObject and should * Use the vout called "macosx".
* respect the protocol: *
* The drawable is an NSObject that follow the VLCOpenGLVideoViewEmbedding
* protocol:
* *
* @begincode * @begincode
* \@protocol VLCOpenGLVideoViewEmbedding <NSObject> * \@protocol VLCOpenGLVideoViewEmbedding <NSObject>
...@@ -203,10 +205,24 @@ VLC_PUBLIC_API void libvlc_media_player_stop ( libvlc_media_player_t *p_mi ); ...@@ -203,10 +205,24 @@ VLC_PUBLIC_API void libvlc_media_player_stop ( libvlc_media_player_t *p_mi );
* \@end * \@end
* @endcode * @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. * You can find a live example in VLCVideoView in VLCKit.framework.
* *
* \param p_mi the Media Player * \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 ); VLC_PUBLIC_API void libvlc_media_player_set_nsobject ( libvlc_media_player_t *p_mi, void * drawable );
......
...@@ -144,7 +144,21 @@ static int Open(vlc_object_t *this) ...@@ -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 /* We don't wait, that means that we'll have to be careful about releasing
* container. * container.
* That's why we'll release on main thread in Close(). */ * 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 release];
nsPool = nil; nsPool = nil;
...@@ -192,8 +206,11 @@ void Close(vlc_object_t *this) ...@@ -192,8 +206,11 @@ void Close(vlc_object_t *this)
[sys->glView setVoutDisplay:nil]; [sys->glView setVoutDisplay:nil];
var_Destroy(vd, "drawable-nsobject"); var_Destroy(vd, "drawable-nsobject");
/* This will retain sys->glView */ if ([(id)sys->container respondsToSelector:@selector(removeVoutSubview:)])
[(id)sys->container performSelectorOnMainThread:@selector(removeVoutSubview:) withObject:sys->glView waitUntilDone:NO]; {
/* This will retain sys->glView */
[(id)sys->container performSelectorOnMainThread:@selector(removeVoutSubview:) withObject:sys->glView waitUntilDone:NO];
}
/* release on main thread as explained in Open() */ /* release on main thread as explained in Open() */
[(id)sys->container performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO]; [(id)sys->container performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];
[sys->glView performSelectorOnMainThread:@selector(removeFromSuperview) withObject:nil waitUntilDone:NO]; [sys->glView performSelectorOnMainThread:@selector(removeFromSuperview) withObject:nil waitUntilDone:NO];
...@@ -353,6 +370,7 @@ static void OpenglSwap(vout_opengl_t *gl) ...@@ -353,6 +370,7 @@ static void OpenglSwap(vout_opengl_t *gl)
GLint params[] = { 1 }; GLint params[] = { 1 };
CGLSetParameter([[self openGLContext] CGLContextObj], kCGLCPSwapInterval, params); CGLSetParameter([[self openGLContext] CGLContextObj], kCGLCPSwapInterval, params);
[self setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
return self; return self;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment