]> git.sesse.net Git - vlc/blobdiff - plugins/beos/vout_beos.cpp
* Ported Glide and MGA plugins to the new module API. MGA never worked,
[vlc] / plugins / beos / vout_beos.cpp
index 979ea3f6d489185c1cfae8837707fd1dfce5da03..0bcb58f1f9aa8edbfc19539bc090c7999ff82f62 100644 (file)
@@ -1,10 +1,10 @@
 /*****************************************************************************
  * vout_beos.cpp: beos video output display method
  *****************************************************************************
- * Copyright (C) 2000 VideoLAN
+ * Copyright (C) 2000, 2001 VideoLAN
  *
- * Authors:
- * Jean-Marc Dressler
+ * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
+ *          Samuel Hocevar <sam@zoy.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
@@ -21,6 +21,9 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
+#define MODULE_NAME beos
+#include "modules_inner.h"
+
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
@@ -44,13 +47,14 @@ extern "C"
 #include "common.h"
 #include "threads.h"
 #include "mtime.h"
-#include "plugins.h"
+#include "tests.h"
+#include "modules.h"
 
 #include "video.h"
 #include "video_output.h"
 
-#include "intf_msg.h"
 #include "interface.h" /* XXX maybe to remove if beos_window.h is splitted */
+#include "intf_msg.h"
 
 #include "main.h"
 }
@@ -63,16 +67,16 @@ extern "C"
 #define BYTES_PER_PIXEL 2
 
 /*****************************************************************************
- * vout_sys_t: dummy video output method descriptor
+ * vout_sys_t: BeOS video output method descriptor
  *****************************************************************************
  * This structure is part of the video output thread descriptor.
- * It describes the dummy specific properties of an output thread.
+ * It describes the BeOS specific properties of an output thread.
  *****************************************************************************/
  
 typedef struct vout_sys_s
 {
     VideoWindow *         p_window;
-    
+
     byte_t *              pp_buffer[2];
     s32                   i_width;
     s32                   i_height;
@@ -296,6 +300,15 @@ void VideoWindow::DirectConnected(direct_buffer_info *info)
     locker->Unlock();
 }
 
+/*****************************************************************************
+ * VideoWindow::FrameResized
+ *****************************************************************************/
+
+void VideoWindow::FrameResized( float width, float height )
+{
+    b_resized = 1;
+}
+
 /*****************************************************************************
  * VideoWindow::MessageReceived
  *****************************************************************************/
@@ -307,6 +320,7 @@ void VideoWindow::MessageReceived( BMessage * p_message )
     switch( p_message->what )
     {
     case B_KEY_DOWN:
+    case B_SIMPLE_DATA:
         // post the message to the interface window which will handle it
         p_win = beos_GetAppWindow( "interface" );
         if( p_win != NULL )
@@ -327,7 +341,10 @@ void VideoWindow::MessageReceived( BMessage * p_message )
 
 bool VideoWindow::QuitRequested()
 {
-    return( true );
+    /* FIXME: send a message ! */
+    p_main->p_intf->b_die = 1;
+
+    return( false );
 }
 
 extern "C"
@@ -336,33 +353,74 @@ extern "C"
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static int     BeosOpenDisplay   ( vout_thread_t *p_vout );
-static void    BeosCloseDisplay  ( vout_thread_t *p_vout );
+static int  vout_Probe      ( probedata_t *p_data );
+static int  vout_Create     ( struct vout_thread_s * );
+static int  vout_Init       ( struct vout_thread_s * );
+static void vout_End        ( struct vout_thread_s * );
+static void vout_Destroy    ( struct vout_thread_s * );
+static int  vout_Manage     ( struct vout_thread_s * );
+static void vout_Display    ( struct vout_thread_s * );
+
+static int  BeosOpenDisplay ( vout_thread_t *p_vout );
+static void BeosCloseDisplay( vout_thread_t *p_vout );
 
 /*****************************************************************************
- * vout_SysCreate: allocates dummy video thread output method
+ * Functions exported as capabilities. They are declared as static so that
+ * we don't pollute the namespace too much.
+ *****************************************************************************/
+void _M( vout_getfunctions )( function_list_t * p_function_list )
+{
+    p_function_list->pf_probe = vout_Probe;
+    p_function_list->functions.vout.pf_create     = vout_Create;
+    p_function_list->functions.vout.pf_init       = vout_Init;
+    p_function_list->functions.vout.pf_end        = vout_End;
+    p_function_list->functions.vout.pf_destroy    = vout_Destroy;
+    p_function_list->functions.vout.pf_manage     = vout_Manage;
+    p_function_list->functions.vout.pf_display    = vout_Display;
+    p_function_list->functions.vout.pf_setpalette = NULL;
+}
+
+/*****************************************************************************
+ * vout_Probe: probe the video driver and return a score
  *****************************************************************************
- * This function allocates and initializes a dummy vout method.
+ * This function tries to initialize SDL and returns a score to the
+ * plugin manager so that it can select the best plugin.
  *****************************************************************************/
-int vout_SysCreate( vout_thread_t *p_vout, char *psz_display,
-                    int i_root_window, void *p_data )
+static int vout_Probe( probedata_t *p_data )
+{
+    if( TestMethod( VOUT_METHOD_VAR, "beos" ) )
+    {
+        return( 999 );
+    }
+
+    return( 100 );
+}
+
+/*****************************************************************************
+ * vout_Create: allocates BeOS video thread output method
+ *****************************************************************************
+ * This function allocates and initializes a BeOS vout method.
+ *****************************************************************************/
+int vout_Create( vout_thread_t *p_vout )
 {
     /* Allocate structure */
     p_vout->p_sys = (vout_sys_t*) malloc( sizeof( vout_sys_t ) );
     if( p_vout->p_sys == NULL )
     {
-        intf_ErrMsg( "error: %s\n", strerror(ENOMEM) );
+        intf_ErrMsg( "error: %s", strerror(ENOMEM) );
         return( 1 );
     }
     
     /* Set video window's size */
-    p_vout->i_width =  main_GetIntVariable( VOUT_WIDTH_VAR, VOUT_WIDTH_DEFAULT );
-    p_vout->i_height = main_GetIntVariable( VOUT_HEIGHT_VAR, VOUT_HEIGHT_DEFAULT );
+    p_vout->i_width =  main_GetIntVariable( VOUT_WIDTH_VAR,
+                                            VOUT_WIDTH_DEFAULT );
+    p_vout->i_height = main_GetIntVariable( VOUT_HEIGHT_VAR,
+                                            VOUT_HEIGHT_DEFAULT );
 
     /* Open and initialize device */
     if( BeosOpenDisplay( p_vout ) )
     {
-        intf_ErrMsg("vout error: can't open display\n");
+        intf_ErrMsg("vout error: can't open display");
         free( p_vout->p_sys );
         return( 1 );
     }
@@ -371,9 +429,9 @@ int vout_SysCreate( vout_thread_t *p_vout, char *psz_display,
 }
 
 /*****************************************************************************
- * vout_SysInit: initialize dummy video thread output method
+ * vout_Init: initialize BeOS video thread output method
  *****************************************************************************/
-int vout_SysInit( vout_thread_t *p_vout )
+int vout_Init( vout_thread_t *p_vout )
 {
     VideoWindow * p_win = p_vout->p_sys->p_window;
     u32 i_page_size;
@@ -390,7 +448,7 @@ int vout_SysInit( vout_thread_t *p_vout )
     p_vout->p_sys->pp_buffer[1] = (byte_t*) malloc( i_page_size );
     if( p_vout->p_sys->pp_buffer[0] == NULL  || p_vout->p_sys->pp_buffer[0] == NULL )
     {
-        intf_ErrMsg("vout error: can't allocate video memory (%s)\n", strerror(errno) );
+        intf_ErrMsg("vout error: can't allocate video memory (%s)", strerror(errno) );
         if( p_vout->p_sys->pp_buffer[0] != NULL ) free( p_vout->p_sys->pp_buffer[0] );
         if( p_vout->p_sys->pp_buffer[1] != NULL ) free( p_vout->p_sys->pp_buffer[1] );
         p_win->locker->Unlock();
@@ -406,9 +464,9 @@ int vout_SysInit( vout_thread_t *p_vout )
 }
 
 /*****************************************************************************
- * vout_SysEnd: terminate dummy video thread output method
+ * vout_End: terminate BeOS video thread output method
  *****************************************************************************/
-void vout_SysEnd( vout_thread_t *p_vout )
+void vout_End( vout_thread_t *p_vout )
 {
    VideoWindow * p_win = p_vout->p_sys->p_window;
    
@@ -422,11 +480,11 @@ void vout_SysEnd( vout_thread_t *p_vout )
 }
 
 /*****************************************************************************
- * vout_SysDestroy: destroy dummy video thread output method
+ * vout_Destroy: destroy BeOS video thread output method
  *****************************************************************************
  * Terminate an output method created by DummyCreateOutputMethod
  *****************************************************************************/
-void vout_SysDestroy( vout_thread_t *p_vout )
+void vout_Destroy( vout_thread_t *p_vout )
 {
     BeosCloseDisplay( p_vout );
     
@@ -434,46 +492,55 @@ void vout_SysDestroy( vout_thread_t *p_vout )
 }
 
 /*****************************************************************************
- * vout_SysManage: handle dummy events
+ * vout_Manage: handle BeOS events
  *****************************************************************************
  * This function should be called regularly by video output thread. It manages
  * console events. It returns a non null value on error.
  *****************************************************************************/
-int vout_SysManage( vout_thread_t *p_vout )
+int vout_Manage( vout_thread_t *p_vout )
 {
+    if( p_vout->p_sys->p_window->b_resized )
+    {
+        p_vout->p_sys->p_window->b_resized = 0;
+        p_vout->i_changes |= VOUT_SIZE_CHANGE;
+    }
+
     if( p_vout->i_changes & VOUT_SIZE_CHANGE )
     {
-        intf_DbgMsg("resizing window\n");
+        intf_WarnMsg( 1, "resizing window" );
         p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
 
         /* Resize window */
         p_vout->p_sys->p_window->ResizeTo( p_vout->i_width, p_vout->i_height );
 
         /* Destroy XImages to change their size */
-        vout_SysEnd( p_vout );
+        vout_End( p_vout );
 
         /* Recreate XImages. If SysInit failed, the thread can't go on. */
-        if( vout_SysInit( p_vout ) )
+        if( vout_Init( p_vout ) )
         {
-            intf_ErrMsg("error: can't resize display\n");
+            intf_ErrMsg( "error: can't resize display" );
             return( 1 );
         }
 
         /* Tell the video output thread that it will need to rebuild YUV
-         * tables. This is needed since convertion buffer size may have changed */
+         * tables. This is needed since convertion buffer size may have
+         * changed */
         p_vout->i_changes |= VOUT_YUV_CHANGE;
-        intf_Msg("Video display resized (%dx%d)\n", p_vout->i_width, p_vout->i_height);
+        intf_Msg( "vout: video display resized (%dx%d)",
+                  p_vout->i_width, p_vout->i_height );
     }
+
     return( 0 );
 }
 
 /*****************************************************************************
- * vout_SysDisplay: displays previously rendered output
+ * vout_Display: displays previously rendered output
  *****************************************************************************
- * This function send the currently rendered image to dummy image, waits until
+ * This function send the currently rendered image to BeOS image, waits until
  * it is displayed and switch the two rendering buffers, preparing next frame.
  *****************************************************************************/
-void vout_SysDisplay( vout_thread_t *p_vout )
+void vout_Display( vout_thread_t *p_vout )
 {
     VideoWindow * p_win = p_vout->p_sys->p_window;
     
@@ -487,7 +554,7 @@ void vout_SysDisplay( vout_thread_t *p_vout )
 /* following functions are local */
 
 /*****************************************************************************
- * BeosOpenDisplay: open and initialize dummy device
+ * BeosOpenDisplay: open and initialize BeOS device
  *****************************************************************************
  * XXX?? The framebuffer mode is only provided as a fast and efficient way to
  * display video, providing the card is configured and the mode ok. It is
@@ -499,11 +566,11 @@ static int BeosOpenDisplay( vout_thread_t *p_vout )
 { 
     /* Create the DirectDraw video window */
     p_vout->p_sys->p_window =
-        new VideoWindow(  BRect( 100, 100, 100+p_vout->i_width, 100+p_vout->i_height ), "VideoLAN", p_vout );
+        new VideoWindow(  BRect( 50, 150, 50+p_vout->i_width-1, 150+p_vout->i_height-1 ), VOUT_TITLE " (BeOS output) - drop a file here to play it !", p_vout );
     if( p_vout->p_sys->p_window == 0 )
     {
         free( p_vout->p_sys );
-        intf_ErrMsg( "error: cannot allocate memory for VideoWindow\n" );
+        intf_ErrMsg( "error: cannot allocate memory for VideoWindow" );
         return( 1 );
     }   
     VideoWindow * p_win = p_vout->p_sys->p_window;
@@ -519,7 +586,7 @@ static int BeosOpenDisplay( vout_thread_t *p_vout )
     switch( p_vout->i_screen_depth )
     {
     case 8:
-        intf_ErrMsg( "vout error: 8 bit mode not fully supported\n" );
+        intf_ErrMsg( "vout error: 8 bit mode not fully supported" );
         break;
     case 15:
         p_vout->i_red_mask =        0x7c00;
@@ -544,7 +611,7 @@ static int BeosOpenDisplay( vout_thread_t *p_vout )
 }
 
 /*****************************************************************************
- * BeosDisplay: close and reset dummy device
+ * BeosDisplay: close and reset BeOS device
  *****************************************************************************
  * Returns all resources allocated by BeosOpenDisplay and restore the original
  * state of the device.