]> git.sesse.net Git - vlc/blobdiff - modules/video_output/fb.c
vout_fb: cosmetics, stick to orig coding style
[vlc] / modules / video_output / fb.c
index 8a6288020835e5c8ceb09acda3e2c35b6d0f32ad..df8eba189e575607f241e81a7b17f0fd71a3cebe 100644 (file)
@@ -47,6 +47,7 @@
 #include <vlc_plugin.h>
 #include <vlc_vout_display.h>
 #include <vlc_picture_pool.h>
+#include <vlc_charset.h>
 
 /*****************************************************************************
  * Module descriptor
@@ -73,6 +74,9 @@
     "in hardware then you must disable this option. It then does double buffering " \
     "in software.")
 
+#define CHROMA_TEXT N_("Image format (default RGB).")
+#define CHROMA_LONGTEXT N_("Chroma fourcc used by the framebuffer. Default is RGB since the fb device has no way to report its chroma.")
+
 static int  Open (vlc_object_t *);
 static void Close(vlc_object_t *);
 
@@ -82,8 +86,8 @@ vlc_module_begin ()
     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)
-    add_obsolete_string("fb-chroma")
+    add_bool("fb-tty", true, NULL, TTY_TEXT, TTY_LONGTEXT, true)
+    add_string( "fb-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT, true )
     add_obsolete_string("fb-aspect-ratio")
     add_integer("fb-mode", 4, NULL, FB_MODE_TEXT, FB_MODE_LONGTEXT,
                  true)
@@ -97,10 +101,10 @@ vlc_module_end ()
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static picture_t *Get    (vout_display_t *);
-static void       Display(vout_display_t *, picture_t *);
-static int        Control(vout_display_t *, int, va_list);
-static void       Manage (vout_display_t *);
+static picture_pool_t *Pool  (vout_display_t *, unsigned);
+static void           Display(vout_display_t *, picture_t *);
+static int            Control(vout_display_t *, int, va_list);
+static void           Manage (vout_display_t *);
 
 /* */
 static int  OpenDisplay  (vout_display_t *, bool force_resolution);
@@ -136,6 +140,8 @@ struct vout_display_sys_t {
     /* Video information */
     uint32_t width;
     uint32_t height;
+    uint32_t line_length;
+    vlc_fourcc_t chroma;
     int      bytes_per_pixel;
 
     /* Video memory */
@@ -146,6 +152,23 @@ struct vout_display_sys_t {
     picture_pool_t  *pool;
 };
 
+
+static void ClearScreen(vout_display_sys_t *sys)
+{
+    switch (sys->chroma) {
+    /* XXX: add other chromas */
+    case VLC_CODEC_UYVY: {
+        unsigned int j, size = sys->video_size / 4;
+        uint32_t *ptr = (uint32_t*)((uintptr_t)(sys->video_ptr + 3) & ~3);
+        for(j=0; j < size; j++)
+            ptr[j] = 0x10801080;    /* U = V = 16, Y = 128 */
+        break;
+    }
+    default:    /* RGB */
+        memset(sys->video_ptr, 0, sys->video_size);
+    }
+}
+
 /**
  * This function allocates and initializes a FB vout method.
  */
@@ -201,6 +224,20 @@ static int Open(vlc_object_t *object)
         break;
     }
 
+    char *chroma = var_CreateGetNonEmptyString(vd, "fb-chroma");
+    if (chroma) {
+        sys->chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, chroma);
+
+        if (sys->chroma)
+            msg_Dbg(vd, "forcing chroma '%s'", chroma);
+        else
+            msg_Warn(vd, "chroma %s invalid, using default", chroma);
+
+        free(chroma);
+    }
+    else
+        sys->chroma = 0;
+
     /* tty handling */
     if (sys->is_tty && TtyInit(vd)) {
         free(sys);
@@ -220,37 +257,44 @@ static int Open(vlc_object_t *object)
     /* */
     video_format_t fmt = vd->fmt;
 
-    msg_Err(vd, "var_info.bits_per_pixel = %d", sys->var_info.bits_per_pixel);
-    switch (sys->var_info.bits_per_pixel) {
-    case 8: /* FIXME: set the palette */
-        fmt.i_chroma = VLC_CODEC_RGB8;
-        break;
-    case 15:
-        fmt.i_chroma = VLC_CODEC_RGB15;
-        break;
-    case 16:
-        fmt.i_chroma = VLC_CODEC_RGB16;
-        break;
-    case 24:
-        fmt.i_chroma = VLC_CODEC_RGB24;
-        break;
-    case 32:
-        fmt.i_chroma = VLC_CODEC_RGB32;
-        break;
-    default:
-        msg_Err(vd, "unknown screen depth %i",
-                sys->var_info.bits_per_pixel);
-        Close(VLC_OBJECT(vd));
-        return VLC_EGENERIC;
+    if (sys->chroma) {
+        fmt.i_chroma = sys->chroma;
     }
-    if (sys->var_info.bits_per_pixel != 8) {
-        fmt.i_rmask = ((1 << sys->var_info.red.length) - 1)
-                             << sys->var_info.red.offset;
-        fmt.i_gmask = ((1 << sys->var_info.green.length) - 1)
-                             << sys->var_info.green.offset;
-        fmt.i_bmask = ((1 << sys->var_info.blue.length) - 1)
-                             << sys->var_info.blue.offset;
+    else {
+        /* Assume RGB */
+
+        msg_Dbg(vd, "%d bppd", sys->var_info.bits_per_pixel);
+        switch (sys->var_info.bits_per_pixel) {
+        case 8: /* FIXME: set the palette */
+            fmt.i_chroma = VLC_CODEC_RGB8;
+            break;
+        case 15:
+            fmt.i_chroma = VLC_CODEC_RGB15;
+            break;
+        case 16:
+            fmt.i_chroma = VLC_CODEC_RGB16;
+            break;
+        case 24:
+            fmt.i_chroma = VLC_CODEC_RGB24;
+            break;
+        case 32:
+            fmt.i_chroma = VLC_CODEC_RGB32;
+            break;
+        default:
+            msg_Err(vd, "unknown screendepth %i", sys->var_info.bits_per_pixel);
+            Close(VLC_OBJECT(vd));
+            return VLC_EGENERIC;
+        }
+        if (sys->var_info.bits_per_pixel != 8) {
+            fmt.i_rmask = ((1 << sys->var_info.red.length) - 1)
+                                 << sys->var_info.red.offset;
+            fmt.i_gmask = ((1 << sys->var_info.green.length) - 1)
+                                 << sys->var_info.green.offset;
+            fmt.i_bmask = ((1 << sys->var_info.blue.length) - 1)
+                                 << sys->var_info.blue.offset;
+        }
     }
+
     fmt.i_width  = sys->width;
     fmt.i_height = sys->height;
 
@@ -261,7 +305,7 @@ static int Open(vlc_object_t *object)
     /* */
     vd->fmt     = fmt;
     vd->info    = info;
-    vd->get     = Get;
+    vd->pool    = Pool;
     vd->prepare = NULL;
     vd->display = Display;
     vd->control = Control;
@@ -269,7 +313,7 @@ static int Open(vlc_object_t *object)
 
     /* */
     vout_display_SendEventFullscreen(vd, true);
-    vout_display_SendEventDisplaySize(vd, fmt.i_width, fmt.i_height);
+    vout_display_SendEventDisplaySize(vd, fmt.i_width, fmt.i_height, true);
     return VLC_SUCCESS;
 }
 
@@ -295,7 +339,7 @@ static void Close(vlc_object_t *object)
 }
 
 /* */
-static picture_t *Get(vout_display_t *vd)
+static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
 {
     vout_display_sys_t *sys = vd->sys;
 
@@ -306,12 +350,7 @@ static picture_t *Get(vout_display_t *vd)
             memset(&rsc, 0, sizeof(rsc));
             rsc.p[0].p_pixels = sys->video_ptr;
             rsc.p[0].i_lines  = sys->var_info.yres;
-            if (sys->var_info.xres_virtual)
-                rsc.p[0].i_pitch = sys->var_info.xres_virtual *
-                                   sys->bytes_per_pixel;
-            else
-                rsc.p[0].i_pitch = sys->var_info.xres *
-                                   sys->bytes_per_pixel;
+            rsc.p[0].i_pitch = sys->line_length;
 
             sys->picture = picture_NewFromResource(&vd->fmt, &rsc);
             if (!sys->picture)
@@ -321,11 +360,9 @@ static picture_t *Get(vout_display_t *vd)
         if (sys->is_hw_accel)
             sys->pool = picture_pool_New(1, &sys->picture);
         else
-            sys->pool = picture_pool_NewFromFormat(&vd->fmt, 1);
-        if (!sys->pool)
-            return NULL;
+            sys->pool = picture_pool_NewFromFormat(&vd->fmt, count);
     }
-    return picture_pool_Get(sys->pool);
+    return sys->pool;
 }
 static void Display(vout_display_t *vd, picture_t *picture)
 {
@@ -384,9 +421,7 @@ static void Manage (vout_display_t *vd)
 
         vout_display_SendEventDisplaySize();
 
-        /* Clear screen */
-        memset(vd->sys->video_ptr, 0, vd->sys->video_size);
-
+        ClearScreen(vd->sys);
     }
 #endif
 }
@@ -485,7 +520,6 @@ static int OpenDisplay(vout_display_t *vd, bool force_resolution)
 {
     vout_display_sys_t *sys = vd->sys;
     char *psz_device;                             /* framebuffer device path */
-    struct fb_fix_screeninfo    fix_info;     /* framebuffer fix information */
 
     /* Open framebuffer device */
     if (!(psz_device = config_GetPsz(vd, FB_DEV_VAR))) {
@@ -493,7 +527,7 @@ static int OpenDisplay(vout_display_t *vd, bool force_resolution)
         return VLC_EGENERIC;
     }
 
-    sys->fd = open(psz_device, O_RDWR);
+    sys->fd = utf8_open(psz_device, O_RDWR);
     if (sys->fd == -1) {
         msg_Err(vd, "cannot open %s (%m)", psz_device);
         free(psz_device);
@@ -527,6 +561,7 @@ static int OpenDisplay(vout_display_t *vd, bool force_resolution)
         return VLC_EGENERIC;
     }
 
+    struct fb_fix_screeninfo fix_info;
     /* Get some information again, in the definitive configuration */
     if (ioctl(sys->fd, FBIOGET_FSCREENINFO, &fix_info) ||
         ioctl(sys->fd, FBIOGET_VSCREENINFO, &sys->var_info)) {
@@ -550,6 +585,7 @@ static int OpenDisplay(vout_display_t *vd, bool force_resolution)
     sys->height = sys->var_info.yres;
     sys->width  = sys->var_info.xres_virtual ? sys->var_info.xres_virtual :
                                                sys->var_info.xres;
+    sys->line_length = fix_info.line_length;
 
     /* FIXME: if the image is full-size, it gets cropped on the left
      * because of the xres / xres_virtual slight difference */
@@ -609,7 +645,7 @@ static int OpenDisplay(vout_display_t *vd, bool force_resolution)
         return VLC_EGENERIC;
     }
 
-    sys->video_size = sys->width * sys->height * sys->bytes_per_pixel;
+    sys->video_size = sys->line_length * sys->var_info.yres_virtual;
 
     /* Map a framebuffer at the beginning */
     sys->video_ptr = mmap(NULL, sys->video_size,
@@ -629,8 +665,8 @@ static int OpenDisplay(vout_display_t *vd, bool force_resolution)
         close(sys->fd);
         return VLC_EGENERIC;
     }
-    /* Clear the screen */
-    memset(sys->video_ptr, 0, sys->video_size);
+
+    ClearScreen(sys);
 
     msg_Dbg(vd,
             "framebuffer type=%d, visual=%d, ypanstep=%d, ywrap=%d, accel=%d",
@@ -647,8 +683,7 @@ static void CloseDisplay(vout_display_t *vd)
     vout_display_sys_t *sys = vd->sys;
 
     if (sys->video_ptr != MAP_FAILED) {
-        /* Clear display */
-        memset(sys->video_ptr, 0, sys->video_size);
+        ClearScreen(sys);
         munmap(sys->video_ptr, sys->video_size);
     }