]> git.sesse.net Git - vlc/blobdiff - modules/video_output/fb.c
Merge branch '1.0-bugfix'
[vlc] / modules / video_output / fb.c
index 03d94b3c6e2d824ec000a32b122a3fdb4d469bd1..cd4486e09c0fdab60cc13249c565346b7826ddec 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * fb.c : framebuffer plugin for vlc
  *****************************************************************************
- * Copyright (C) 2000, 2001 the VideoLAN team
+ * Copyright (C) 2000-2009 the VideoLAN team
  * $Id$
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <errno.h>                                                 /* ENOMEM */
 #include <signal.h>                                      /* SIGUSR1, SIGUSR2 */
 #include <fcntl.h>                                                 /* open() */
 #include <linux/vt.h>                                                /* VT_* */
 #include <linux/kd.h>                                                 /* KD* */
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_vout.h>
+#include <vlc_interface.h>
 
 /*****************************************************************************
  * Local prototypes
@@ -102,25 +104,25 @@ static void GfxMode        ( int i_tty );
     "in hardware then you must disable this option. It then does double buffering " \
     "in software." )
 
-vlc_module_begin();
-    set_shortname( "Framebuffer" );
-    set_category( CAT_VIDEO );
-    set_subcategory( SUBCAT_VIDEO_VOUT );
+vlc_module_begin ()
+    set_shortname( "Framebuffer" )
+    set_category( CAT_VIDEO )
+    set_subcategory( SUBCAT_VIDEO_VOUT )
     add_file( FB_DEV_VAR, "/dev/fb0", NULL, DEVICE_TEXT, DEVICE_LONGTEXT,
-              false );
-    add_bool( "fb-tty", 1, NULL, TTY_TEXT, TTY_LONGTEXT, true );
+              false )
+    add_bool( "fb-tty", 1, NULL, TTY_TEXT, TTY_LONGTEXT, true )
     add_string( "fb-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
-                true );
+                true )
     add_string( "fb-aspect-ratio", NULL, NULL, ASPECT_RATIO_TEXT,
-                ASPECT_RATIO_LONGTEXT, true );
+                ASPECT_RATIO_LONGTEXT, true )
     add_integer( "fb-mode", 4, NULL, FB_MODE_TEXT, FB_MODE_LONGTEXT,
-                 true );
+                 true )
     add_bool( "fb-hw-accel", true, NULL, HW_ACCEL_TEXT, HW_ACCEL_LONGTEXT,
-              true );
-    set_description( N_("GNU/Linux console framebuffer video output") );
-    set_capability( "video output", 30 );
-    set_callbacks( Create, Destroy );
-vlc_module_end();
+              true )
+    set_description( N_("GNU/Linux framebuffer video output") )
+    set_capability( "video output", 30 )
+    set_callbacks( Create, Destroy )
+vlc_module_end ()
 
 /*****************************************************************************
  * vout_sys_t: video output framebuffer method descriptor
@@ -184,10 +186,11 @@ static int Create( vlc_object_t *p_this )
     struct termios      new_termios;
 
     /* Allocate instance and initialize some members */
-    p_vout->p_sys = p_sys = malloc( sizeof( vout_sys_t ) );
+    p_vout->p_sys = p_sys = calloc( 1, sizeof( vout_sys_t ) );
     if( p_vout->p_sys == NULL )
         return VLC_ENOMEM;
-    memset( p_sys, 0, sizeof(vout_sys_t) );
+
+    p_sys->p_video = MAP_FAILED;
 
     p_vout->pf_init = Init;
     p_vout->pf_end = End;
@@ -208,6 +211,7 @@ static int Create( vlc_object_t *p_this )
     if( p_sys->b_tty && !isatty( 0 ) )
     {
         msg_Warn( p_vout, "fd 0 is not a TTY" );
+        free( p_sys );
         return VLC_EGENERIC;
     }
     else
@@ -221,12 +225,12 @@ static int Create( vlc_object_t *p_this )
     psz_chroma = var_CreateGetNonEmptyString( p_vout, "fb-chroma" );
     if( psz_chroma )
     {
-        if( strlen( psz_chroma ) == 4 )
+        const vlc_fourcc_t i_chroma =
+            vlc_fourcc_GetCodecFromString( VIDEO_ES, psz_chroma );
+
+        if( i_chroma )
         {
-            p_sys->i_chroma = VLC_FOURCC( psz_chroma[0],
-                                   psz_chroma[1],
-                                   psz_chroma[2],
-                                   psz_chroma[3] );
+            p_sys->i_chroma = i_chroma;
             msg_Dbg( p_vout, "forcing chroma '%s'", psz_chroma );
         }
         else
@@ -235,7 +239,6 @@ static int Create( vlc_object_t *p_this )
                       psz_chroma );
         }
         free( psz_chroma );
-        psz_chroma = NULL;
     }
 
     p_sys->i_aspect = -1;
@@ -254,7 +257,6 @@ static int Create( vlc_object_t *p_this )
                   atoi( psz_aspect ), atoi( psz_parser ) );
 
         free( psz_aspect );
-        psz_aspect = NULL;
     }
 
     p_sys->b_auto = false;
@@ -280,7 +282,6 @@ static int Create( vlc_object_t *p_this )
         case 4:
         default:
             p_sys->b_auto = true;
-            break;
      }
 
     /* tty handling */
@@ -359,15 +360,7 @@ static int Create( vlc_object_t *p_this )
 
     if( OpenDisplay( p_vout ) )
     {
-        if( p_sys->b_tty )
-        {
-            ioctl( p_sys->i_tty, VT_SETMODE, &p_vout->p_sys->vt_mode );
-            sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
-            sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
-            tcsetattr(0, 0, &p_vout->p_sys->old_termios);
-            TextMode( p_sys->i_tty );
-        }
-        free( p_vout->p_sys );
+        Destroy( VLC_OBJECT(p_vout) );
         return VLC_EGENERIC;
     }
 
@@ -422,9 +415,13 @@ static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
     }
 
     /* Fill in picture_t fields */
-    vout_InitPicture( VLC_OBJECT(p_vout), p_pic, p_vout->output.i_chroma,
-                      p_vout->output.i_width, p_vout->output.i_height,
-                      p_vout->output.i_aspect );
+    if( picture_Setup( p_pic, p_vout->output.i_chroma,
+                       p_vout->output.i_width, p_vout->output.i_height,
+                       p_vout->output.i_aspect ) )
+    {
+        free( p_pic );
+        return VLC_EGENERIC;
+    }
 
     p_pic->p_sys->p_data = malloc( p_vout->p_sys->i_page_size );
     if( !p_pic->p_sys->p_data )
@@ -465,6 +462,7 @@ static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
  *****************************************************************************/
 static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic )
 {
+    VLC_UNUSED(p_vout);
     free( p_pic->p_sys->p_data );
     free( p_pic->p_sys );
     p_pic->p_sys = NULL;
@@ -493,15 +491,15 @@ static int Init( vout_thread_t *p_vout )
         switch( p_sys->var_info.bits_per_pixel )
         {
         case 8: /* FIXME: set the palette */
-            p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2'); break;
+            p_vout->output.i_chroma = VLC_CODEC_RGB8; break;
         case 15:
-            p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5'); break;
+            p_vout->output.i_chroma = VLC_CODEC_RGB15; break;
         case 16:
-            p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6'); break;
+            p_vout->output.i_chroma = VLC_CODEC_RGB16; break;
         case 24:
-            p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4'); break;
+            p_vout->output.i_chroma = VLC_CODEC_RGB24; break;
         case 32:
-            p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2'); break;
+            p_vout->output.i_chroma = VLC_CODEC_RGB32; break;
         default:
             msg_Err( p_vout, "unknown screen depth %i",
                      p_vout->p_sys->var_info.bits_per_pixel );
@@ -524,13 +522,12 @@ static int Init( vout_thread_t *p_vout )
     }
     p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;
 
-    if( !p_sys->b_auto )
-    {
-        p_vout->render.i_width = p_sys->i_width;
-        p_vout->render.i_height = p_sys->i_height;
-    }
-    p_vout->output.i_width  = p_vout->fmt_out.i_width = p_sys->i_width;
-    p_vout->output.i_height = p_vout->fmt_out.i_height = p_sys->i_height;
+    p_vout->output.i_width =
+    p_vout->fmt_out.i_width =
+    p_vout->fmt_out.i_visible_width = p_sys->i_width;
+    p_vout->output.i_height =
+    p_vout->fmt_out.i_height =
+    p_vout->fmt_out.i_visible_height = p_sys->i_height;
 
     /* Assume we have square pixels */
     if( p_sys->i_aspect < 0 )
@@ -557,7 +554,7 @@ static int Init( vout_thread_t *p_vout )
             /* Find an empty picture slot */
             for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
             {
-            if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
+                if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
                 {
                     p_pic = p_vout->p_picture + i_index;
                     break;
@@ -657,11 +654,8 @@ static void End( vout_thread_t *p_vout )
  *****************************************************************************/
 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
 {
-    switch( i_query )
-    {
-       default:
-            return vout_vaControlDefault( p_vout, i_query, args );
-    }
+    (void) p_vout; (void) i_query; (void) args;
+    return VLC_EGENERIC;
 }
 
 /*****************************************************************************
@@ -680,7 +674,7 @@ static int Manage( vout_thread_t *p_vout )
         switch( buf )
         {
         case 'q':
-            vlc_object_kill( p_vout->p_libvlc );
+            libvlc_Quit( p_vout->p_libvlc );
             break;
 
         default:
@@ -790,7 +784,6 @@ static int OpenDisplay( vout_thread_t *p_vout )
         return VLC_EGENERIC;
     }
     free( psz_device );
-    psz_device = NULL;
 
     /* Get framebuffer device information */
     if( ioctl( p_sys->i_fd, FBIOGET_VSCREENINFO, &p_sys->var_info ) )
@@ -918,11 +911,11 @@ static int OpenDisplay( vout_thread_t *p_vout )
                          p_sys->i_bytes_per_pixel;
 
     /* Map a framebuffer at the beginning */
-    p_sys->p_video = mmap( 0, p_sys->i_page_size,
+    p_sys->p_video = mmap( NULL, p_sys->i_page_size,
                               PROT_READ | PROT_WRITE, MAP_SHARED,
                               p_sys->i_fd, 0 );
 
-    if( p_sys->p_video == ((void*)-1) )
+    if( p_sys->p_video == MAP_FAILED )
     {
         msg_Err( p_vout, "cannot map video memory (%m)" );
 
@@ -950,24 +943,31 @@ static int OpenDisplay( vout_thread_t *p_vout )
  *****************************************************************************/
 static void CloseDisplay( vout_thread_t *p_vout )
 {
-    /* Clear display */
-    memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
-
-    /* Restore palette */
-    if( p_vout->p_sys->var_info.bits_per_pixel == 8 )
+    if( p_vout->p_sys->p_video != MAP_FAILED )
     {
-        ioctl( p_vout->p_sys->i_fd,
-               FBIOPUTCMAP, &p_vout->p_sys->fb_cmap );
-        free( p_vout->p_sys->p_palette );
-        p_vout->p_sys->p_palette = NULL;
+        /* Clear display */
+        memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
+        munmap( p_vout->p_sys->p_video, p_vout->p_sys->i_page_size );
     }
 
-    /* Restore fb config */
-    ioctl( p_vout->p_sys->i_fd,
-           FBIOPUT_VSCREENINFO, &p_vout->p_sys->old_info );
+    if( p_vout->p_sys->i_fd >= 0 )
+    {
+        /* Restore palette */
+        if( p_vout->p_sys->var_info.bits_per_pixel == 8 )
+        {
+            ioctl( p_vout->p_sys->i_fd,
+                   FBIOPUTCMAP, &p_vout->p_sys->fb_cmap );
+            free( p_vout->p_sys->p_palette );
+            p_vout->p_sys->p_palette = NULL;
+        }
 
-    /* Close fb */
-    close( p_vout->p_sys->i_fd );
+        /* Restore fb config */
+        ioctl( p_vout->p_sys->i_fd,
+               FBIOPUT_VSCREENINFO, &p_vout->p_sys->old_info );
+
+        /* Close fb */
+        close( p_vout->p_sys->i_fd );
+    }
 }
 
 /*****************************************************************************
@@ -978,6 +978,7 @@ static void CloseDisplay( vout_thread_t *p_vout )
  *****************************************************************************/
 static void SwitchDisplay( int i_signal )
 {
+    VLC_UNUSED( i_signal );
 #if 0
     vout_thread_t *p_vout;