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 );
/**
* 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 );
......
......@@ -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(). */
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");
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;
}
......
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