]> git.sesse.net Git - vlc/blobdiff - modules/gui/minimal_macosx/intf.m
Revert "MKV: Always set an i_pts in a lace otherwise it disturbs seeking performance"
[vlc] / modules / gui / minimal_macosx / intf.m
index b9a13ef93ccefab45efd5fff53ff9eb345826c01..d6c73b3848b8f92ef436cbcfc03f12dd0c6531f5 100644 (file)
@@ -1,70 +1,63 @@
 /*****************************************************************************
  * intf.m: MacOS X interface module
  *****************************************************************************
- * Copyright (C) 2002-2007 the VideoLAN team
+ * Copyright (C) 2002-2012 VLC authors and VideoLAN
  * $Id$
  *
- * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
- *          Christophe Massiot <massiot@via.ecp.fr>
- *          Derk-Jan Hartman <hartman at videolan.org>
- *          Felix Kühne <fkuehne at videolan dot org>
+ * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
+ *          Felix Paul Kühne <fkuehne at videolan dot org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
-#include <sys/param.h>                                    /* for MAXPATHLEN */
-#include <string.h>
+#import <stdlib.h>                                      /* malloc(), free() */
+#import <sys/param.h>                                    /* for MAXPATHLEN */
+#import <string.h>
 #ifdef HAVE_CONFIG_H
-# include "config.h"
+# import "config.h"
 #endif
+#include <unistd.h>
 
-#include <vlc_common.h>
+#import <vlc_playlist.h>
+#import <vlc_vout_window.h>
 
-#include <vlc_keys.h>
-
-#include <vlc_input.h>
-#import <vlc_interface.h>
-
-#import <intf.h>
+#import "intf.h"
+#import "VLCMinimalVoutWindow.h"
 
 /*****************************************************************************
  * Local prototypes.
  *****************************************************************************/
-static void Run ( intf_thread_t *p_intf );
+static void Run (intf_thread_t *p_intf);
 
 /*****************************************************************************
  * OpenIntf: initialize interface
  *****************************************************************************/
-int OpenIntf ( vlc_object_t *p_this )
+int OpenIntf (vlc_object_t *p_this)
 {
     intf_thread_t *p_intf = (intf_thread_t*) p_this;
 
-    p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
-    if( p_intf->p_sys == NULL )
-    {
+    p_intf->p_sys = malloc(sizeof(intf_sys_t));
+    if (p_intf->p_sys == NULL)
         return VLC_ENOMEM;
-    }
 
-    memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
+    memset(p_intf->p_sys, 0, sizeof(*p_intf->p_sys));
 
-    p_intf->pf_run = Run;
-    p_intf->b_should_run_on_first_thread = true;
+    Run(p_intf);
 
     return VLC_SUCCESS;
 }
@@ -72,11 +65,11 @@ int OpenIntf ( vlc_object_t *p_this )
 /*****************************************************************************
  * CloseIntf: destroy interface
  *****************************************************************************/
-void CloseIntf ( vlc_object_t *p_this )
+void CloseIntf (vlc_object_t *p_this)
 {
     intf_thread_t *p_intf = (intf_thread_t*) p_this;
 
-    free( p_intf->p_sys );
+    free(p_intf->p_sys);
 }
 
 /* Dock Connection */
@@ -86,31 +79,21 @@ typedef struct CPSProcessSerNum
         UInt32                hi;
 } CPSProcessSerNum;
 
-extern OSErr    CPSGetCurrentProcess( CPSProcessSerNum *psn);
-extern OSErr    CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
-extern OSErr    CPSSetFrontProcess( CPSProcessSerNum *psn);
+extern OSErr    CPSGetCurrentProcess(CPSProcessSerNum *psn);
+extern OSErr    CPSEnableForegroundOperation(CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
+extern OSErr    CPSSetFrontProcess(CPSProcessSerNum *psn);
 
 /*****************************************************************************
  * KillerThread: Thread that kill the application
  *****************************************************************************/
-static void * KillerThread( void *user_data )
+static void * KillerThread(void *user_data)
 {
     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
 
     intf_thread_t *p_intf = user_data;
 
-    vlc_mutex_init( &p_intf->p_sys->lock );
-    vlc_cond_init( &p_intf->p_sys->wait );
-
-    vlc_mutex_lock ( &p_intf->p_sys->lock );
-    while( vlc_object_alive( p_intf ) )
-        vlc_cond_wait( &p_intf->p_sys->wait, &p_intf->p_sys->lock );
-    vlc_mutex_unlock( &p_intf->p_sys->lock );
-
-    vlc_mutex_destroy( &p_intf->p_sys->lock );
-    vlc_cond_destroy( &p_intf->p_sys->wait );
-
-    msg_Dbg( p_intf, "Killing the Minimal Mac OS X module" );
+    for(;;)
+        pause();
 
     /* We are dead, terminate */
     [NSApp terminate: nil];
@@ -121,7 +104,7 @@ static void * KillerThread( void *user_data )
 /*****************************************************************************
  * Run: main loop
  *****************************************************************************/
-static void Run( intf_thread_t *p_intf )
+static void Run(intf_thread_t *p_intf)
 {
     sigset_t set;
 
@@ -129,13 +112,13 @@ static void Run( intf_thread_t *p_intf )
      * VLC overrides SIGTERM which is sent by the "force quit"
      * menu item to make sure deamon mode quits gracefully, so
      * we un-override SIGTERM here. */
-    sigemptyset( &set );
-    sigaddset( &set, SIGTERM );
-    pthread_sigmask( SIG_UNBLOCK, &set, NULL );
+    sigemptyset(&set);
+    sigaddset(&set, SIGTERM);
+    pthread_sigmask(SIG_UNBLOCK, &set, NULL);
 
     /* Setup a thread that will monitor the module killing */
     pthread_t killer_thread;
-    pthread_create( &killer_thread, NULL, KillerThread, p_intf );
+    pthread_create(&killer_thread, NULL, KillerThread, p_intf);
 
     CPSProcessSerNum PSN;
     NSAutoreleasePool   *pool = [[NSAutoreleasePool alloc] init];
@@ -146,8 +129,107 @@ static void Run( intf_thread_t *p_intf )
                 [NSApplication sharedApplication];
     [NSApp run];
 
-    pthread_join( killer_thread, NULL );
+    pthread_join(killer_thread, NULL);
 
     [pool release];
 }
 
+/*****************************************************************************
+ * Vout window management
+ *****************************************************************************/
+static int WindowControl(vout_window_t *, int i_query, va_list);
+
+int WindowOpen(vout_window_t *p_wnd, const vout_window_cfg_t *cfg)
+{
+    if (cfg->type != VOUT_WINDOW_TYPE_INVALID
+     && cfg->type != VOUT_WINDOW_TYPE_NSOBJECT)
+        return VLC_EGENERIC;
+
+    NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
+
+    NSRect proposedVideoViewPosition = NSMakeRect(cfg->x, cfg->y, cfg->width, cfg->height);
+
+    VLCMinimalVoutWindow *o_window = [[VLCMinimalVoutWindow alloc] initWithContentRect:proposedVideoViewPosition];
+    [o_window makeKeyAndOrderFront:nil];
+
+    if (!o_window) {
+        msg_Err(p_wnd, "window creation failed");
+        [o_pool release];
+        return VLC_EGENERIC;
+    }
+
+    msg_Dbg(p_wnd, "returning video window with proposed position x=%i, y=%i, width=%i, height=%i", cfg->x, cfg->y, cfg->width, cfg->height);
+    p_wnd->handle.nsobject = [o_window contentView];
+
+    // TODO: find a cleaner way for "start in fullscreen"
+    if (var_GetBool(pl_Get(p_wnd), "fullscreen"))
+        [o_window performSelectorOnMainThread:@selector(enterFullscreen) withObject:nil waitUntilDone:NO];
+
+    p_wnd->type = VOUT_WINDOW_TYPE_NSOBJECT;
+    p_wnd->control = WindowControl;
+
+    [o_pool release];
+    return VLC_SUCCESS;
+}
+
+static int WindowControl(vout_window_t *p_wnd, int i_query, va_list args)
+{
+    NSWindow * o_window = [(id)p_wnd->handle.nsobject window];
+    if (!o_window) {
+        msg_Err(p_wnd, "failed to recover cocoa window");
+        return VLC_EGENERIC;
+    }
+
+    switch (i_query) {
+        case VOUT_WINDOW_SET_STATE:
+        {
+            unsigned i_state = va_arg(args, unsigned);
+
+            [o_window setLevel: i_state];
+
+            return VLC_SUCCESS;
+        }
+        case VOUT_WINDOW_SET_SIZE:
+        {
+            NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
+
+            NSRect theFrame = [o_window frame];
+            unsigned int i_width  = va_arg(args, unsigned int);
+            unsigned int i_height = va_arg(args, unsigned int);
+            theFrame.size.width = i_width;
+            theFrame.size.height = i_height;
+            [o_window setFrame: theFrame display: YES animate: YES];
+
+            [o_pool release];
+            return VLC_SUCCESS;
+        }
+        case VOUT_WINDOW_SET_FULLSCREEN:
+        {
+            NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
+            int i_full = va_arg(args, int);
+
+            if (i_full)
+                [o_window performSelectorOnMainThread:@selector(enterFullscreen) withObject:nil waitUntilDone:NO];
+            else
+                [o_window performSelectorOnMainThread:@selector(leaveFullscreen) withObject:nil waitUntilDone:NO];
+
+            [o_pool release];
+            return VLC_SUCCESS;
+        }
+        default:
+            msg_Warn(p_wnd, "unsupported control query");
+            return VLC_EGENERIC;
+    }
+}
+
+void WindowClose(vout_window_t *p_wnd)
+{
+    NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
+
+    NSWindow * o_window = [(id)p_wnd->handle.nsobject window];
+    if (o_window)
+        [o_window release];
+
+    [o_pool release];
+}
+