]> git.sesse.net Git - vlc/blobdiff - modules/gui/fbosd.c
Slovenian translation update by Matej Urbančič
[vlc] / modules / gui / fbosd.c
index 933b5231c2d2e8ca089e880ffa663d9814a55510..2a7e1b4eadda6e17cbf5bf4b5fbd0975826c66e9 100644 (file)
@@ -29,7 +29,8 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 
 #include <errno.h>
 #include <stdlib.h>                                                /* free() */
@@ -50,7 +51,8 @@
 #include <vlc_osd.h>
 #include <vlc_strings.h>
 
-// #define FBOSD_BLENDING
+#undef FBOSD_BLENDING
+#undef FBOSD_DEBUG
 
 /*****************************************************************************
  * Local prototypes
@@ -73,11 +75,6 @@ static void CloseBlending    ( intf_thread_t * );
 static int  OpenTextRenderer ( intf_thread_t * );
 static void CloseTextRenderer( intf_thread_t * );
 
-#if 0
-static int  OpenScaling      ( intf_thread_t * );
-static int  CloseScaling     ( intf_thread_t * );
-#endif
-
 /* Manipulate the overlay buffer */
 static int  OverlayCallback( vlc_object_t *, char const *,
                              vlc_value_t, vlc_value_t, void * );
@@ -162,16 +159,18 @@ static picture_t *RenderText( intf_thread_t *, const char *,
 #define DISPLAY_LONGTEXT N_( "All rendered images and text will be " \
     "displayed on the overlay framebuffer." )
 
-static int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
-static const char *ppsz_pos_descriptions[] =
+static const int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
+static const char *const ppsz_pos_descriptions[] =
 { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
   N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
 
-static int pi_color_values[] = { 0xf0000000, 0x00000000, 0x00808080, 0x00C0C0C0,
+static const int pi_color_values[] = {
+               0xf0000000, 0x00000000, 0x00808080, 0x00C0C0C0,
                0x00FFFFFF, 0x00800000, 0x00FF0000, 0x00FF00FF, 0x00FFFF00,
                0x00808000, 0x00008000, 0x00008080, 0x0000FF00, 0x00800080,
                0x00000080, 0x000000FF, 0x0000FFFF};
-static const char *ppsz_color_descriptions[] = { N_("Default"), N_("Black"),
+static const char *const ppsz_color_descriptions[] = {
+               N_("Default"), N_("Black"),
                N_("Gray"), N_("Silver"), N_("White"), N_("Maroon"), N_("Red"),
                N_("Fuchsia"), N_("Yellow"), N_("Olive"), N_("Green"),
                N_("Teal"), N_("Lime"), N_("Purple"), N_("Navy"), N_("Blue"),
@@ -192,12 +191,9 @@ vlc_module_begin();
     add_string( "fbosd-text", NULL, NULL, FBOSD_TEXT,
                 FBOSD_LONGTEXT, true );
 
-#if defined(FBOSD_BLENDING)
     add_integer_with_range( "fbosd-alpha", 255, 0, 255, NULL, ALPHA_TEXT,
                             ALPHA_LONGTEXT, true );
 
-#endif
-
     set_section( N_("Position"), NULL );
     add_integer( "fbosd-x", 0, NULL, POSX_TEXT,
                  POSX_LONGTEXT, false );
@@ -220,7 +216,7 @@ vlc_module_begin();
     add_bool( "fbosd-render", false, NULL, RENDER_TEXT, RENDER_LONGTEXT, true );
     add_bool( "fbosd-display", false, NULL, DISPLAY_TEXT, DISPLAY_LONGTEXT, true );
 
-    set_description( _("GNU/Linux osd/overlay framebuffer interface") );
+    set_description( N_("GNU/Linux osd/overlay framebuffer interface") );
     set_capability( "interface", 10 );
     set_callbacks( Create, Destroy );
 vlc_module_end();
@@ -244,7 +240,7 @@ struct fbosd_render_t
     char            *psz_string;
 
     /* Position */
-    bool      b_absolute;
+    bool            b_absolute;
     int             i_x;
     int             i_y;
     int             i_pos;
@@ -279,9 +275,6 @@ struct intf_sys_t
     filter_t *p_blend;                              /* alpha blending module */
 #endif
     filter_t *p_text;                                /* text renderer module */
-#if 0
-    filter_t *p_scale;                                     /* scaling module */
-#endif
 
     /* Render */
     struct fbosd_render_t render[FBOSD_RENDER_MAX];
@@ -291,11 +284,11 @@ struct intf_sys_t
 
     /* Position */
     bool      b_absolute;
-    int             i_x;
-    int             i_y;
-    int             i_pos;
+    int       i_x;
+    int       i_y;
+    int       i_pos;
 
-    int             i_alpha;                      /* transparency for images */
+    int       i_alpha;                      /* transparency for images */
 
     /* commands control */
     bool      b_need_update;    /* update display with \overlay buffer */
@@ -314,21 +307,16 @@ static int Create( vlc_object_t *p_this )
     char          *psz_tmp;
     int i;
 
-
     /* Allocate instance and initialize some members */
     p_intf->p_sys = p_sys = malloc( sizeof( intf_sys_t ) );
     if( !p_intf->p_sys )
-    {
-        msg_Err( p_intf, "out of memory" );
         return VLC_ENOMEM;
-    };
     memset( p_sys, 0, sizeof(intf_sys_t) );
 
     p_sys->p_style = malloc( sizeof( text_style_t ) );
     if( !p_sys->p_style )
     {
         free( p_intf->p_sys );
-        msg_Err( p_intf, "out of memory" );
         return VLC_ENOMEM;
     }
     vlc_memcpy( p_sys->p_style, &default_text_style, sizeof( text_style_t ) );
@@ -340,16 +328,12 @@ static int Create( vlc_object_t *p_this )
     {
         free( p_intf->p_sys->p_style );
         free( p_intf->p_sys );
-        msg_Err( p_intf, "out of memory" );
         return VLC_ENOMEM;
     }
 
-#if defined(FBOSD_BLENDING)
     p_sys->i_alpha = var_CreateGetIntegerCommand( p_intf, "fbosd-alpha" );
     var_AddCallback( p_intf, "fbosd-alpha", OverlayCallback, NULL );
-#else
-    p_sys->i_alpha = 255;
-#endif
+
     p_sys->i_aspect = -1;
     psz_aspect =
             var_CreateGetNonEmptyString( p_intf, "fbosd-aspect-ratio" );
@@ -470,15 +454,7 @@ static int Create( vlc_object_t *p_this )
         Destroy( VLC_OBJECT(p_intf) );
         return VLC_EGENERIC;
     }
-#if 0
-    /* Load scaling module */
-    if( OpenScaling( p_intf ) )
-    {
-        msg_Err( p_intf, "Unable to load image scaling module" );
-        Destroy( VLC_OBJECT(p_intf) );
-        return VLC_EGENERIC;
-    }
-#endif
+
     p_sys->b_render = true;
     p_sys->b_need_update = true;
 
@@ -500,10 +476,8 @@ static void Destroy( vlc_object_t *p_this )
     p_sys->b_render = false;
     p_sys->b_clear = false;
 
-#if defined(FBOSD_BLENDING)
     var_DelCallback( p_intf, "fbosd-alpha", OverlayCallback, NULL );
     var_Destroy( p_intf, "fbosd-alpha" );
-#endif
 
     var_DelCallback( p_intf, "fbosd-x", OverlayCallback, NULL );
     var_DelCallback( p_intf, "fbosd-y", OverlayCallback, NULL );
@@ -543,13 +517,11 @@ static void Destroy( vlc_object_t *p_this )
     if( p_sys->p_blend ) CloseBlending( p_intf );
 #endif
     if( p_sys->p_text )  CloseTextRenderer( p_intf );
-#if 0
-    if( p_sys->p_scale ) CloseScaling( p_intf );
-#endif
+
     if( p_sys->p_image )
         image_HandlerDelete( p_sys->p_image );
     if( p_sys->p_overlay )
-        p_sys->p_overlay->pf_release( p_sys->p_overlay );
+        picture_Release( p_sys->p_overlay );
 
     free( p_sys->p_style );
     free( p_sys );
@@ -561,7 +533,7 @@ static int OpenBlending( intf_thread_t *p_intf )
     if( p_intf->p_sys->p_blend ) return VLC_EGENERIC;
 
     p_intf->p_sys->p_blend =
-            vlc_object_create( p_intf, VLC_OBJECT_FILTER );
+            vlc_object_create( p_intf, sizeof(filter_t) );
     vlc_object_attach( p_intf->p_sys->p_blend, p_intf );
     p_intf->p_sys->p_blend->fmt_out.video.i_x_offset =
         p_intf->p_sys->p_blend->fmt_out.video.i_y_offset = 0;
@@ -606,7 +578,7 @@ static int OpenTextRenderer( intf_thread_t *p_intf )
     if( p_intf->p_sys->p_text ) return VLC_EGENERIC;
 
     p_intf->p_sys->p_text =
-            vlc_object_create( p_intf, VLC_OBJECT_FILTER );
+            vlc_object_create( p_intf, sizeof(filter_t) );
     vlc_object_attach( p_intf->p_sys->p_text, p_intf );
 
     p_intf->p_sys->p_text->fmt_out.video.i_width =
@@ -648,46 +620,6 @@ static void CloseTextRenderer( intf_thread_t *p_intf )
         vlc_object_release( p_intf->p_sys->p_text );
     }
 }
-#if 0
-static int OpenScaling( intf_thread_t *p_intf )
-{
-    if( p_intf->p_sys->p_scale ) return VLC_EGENERIC;
-
-    p_intf->p_sys->p_scale =
-            vlc_object_create( p_intf, VLC_OBJECT_FILTER );
-    vlc_object_attach( p_intf->p_sys->p_scale, p_intf );
-    p_intf->p_sys->p_scale->fmt_out.video.i_chroma =
-        p_intf->p_sys->p_scale->fmt_in.video.i_chroma =
-            p_intf->p_sys->fmt_out.i_chroma;
-
-    /* XXX: We'll also be using it for YUVA and RGBA blending ... */
-    p_intf->p_sys->p_scale->fmt_in.video.i_width =
-        p_intf->p_sys->p_scale->fmt_in.video.i_height = 32;
-    p_intf->p_sys->p_scale->fmt_out.video.i_width =
-        p_intf->p_sys->p_scale->fmt_out.video.i_height = 16;
-
-    p_intf->p_sys->p_scale->p_module =
-        module_Need( p_intf->p_sys->p_scale, "video filter2", 0, 0 );
-
-    if( !p_intf->p_sys->p_scale->p_module )
-        return VLC_EGENERIC;
-
-    return VLC_SUCCESS;
-}
-
-static int CloseScaling( intf_thread_t *p_intf )
-{
-    if( p_intf->p_sys->p_scale )
-    {
-        if( p_intf->p_sys->p_scale->p_module )
-            module_Unneed( p_intf->p_sys->p_scale,
-                           p_intf->p_sys->p_scale->p_module );
-
-        vlc_object_detach( p_intf->p_sys->p_scale );
-        vlc_object_release( p_intf->p_sys->p_scale );
-    }
-}
-#endif
 
 /*****************************************************************************
  * AllocatePicture:
@@ -696,8 +628,11 @@ static int CloseScaling( intf_thread_t *p_intf )
 static picture_t *AllocatePicture( vlc_object_t *p_this,
                                    video_format_t *p_fmt )
 {
-    picture_t *p_pic = malloc( sizeof( picture_t ) );
-    if( !p_pic ) return NULL;
+    picture_t *p_picture = picture_New( p_fmt->i_chroma,
+                                        p_fmt->i_width, p_fmt->i_height,
+                                        p_fmt->i_aspect );
+    if( !p_picture )
+        return NULL;
 
     if( !p_fmt->p_palette &&
         ( p_fmt->i_chroma == VLC_FOURCC('Y','U','V','P') ) )
@@ -705,24 +640,16 @@ static picture_t *AllocatePicture( vlc_object_t *p_this,
         p_fmt->p_palette = malloc( sizeof(video_palette_t) );
         if( !p_fmt->p_palette )
         {
-            free( p_pic );
+            picture_Release( p_picture );
             return NULL;
         }
     }
-    else p_fmt->p_palette = NULL;
-
-    p_pic->p_data_orig = NULL;
-
-    vout_AllocatePicture( p_this, p_pic, p_fmt->i_chroma,
-                          p_fmt->i_width, p_fmt->i_height, p_fmt->i_aspect );
-
-    if( !p_pic->i_planes )
+    else
     {
-        free( p_pic );
-        free( p_fmt->p_palette );
-        return NULL;
+        p_fmt->p_palette = NULL;
     }
-    return p_pic;
+
+    return p_picture;
 }
 
 /*****************************************************************************
@@ -733,17 +660,15 @@ static void DeAllocatePicture( vlc_object_t *p_this, picture_t *p_pic,
                                video_format_t *p_fmt )
 {
     VLC_UNUSED(p_this);
-    if( p_pic )
-    {
-        free( p_pic->p_data_orig );
-        if( p_pic->pf_release ) p_pic->pf_release( p_pic );
-    }
+
     if( p_fmt )
     {
         free( p_fmt->p_palette );
         p_fmt->p_palette = NULL;
     }
-    p_pic = NULL;
+
+    if( p_pic )
+        picture_Release( p_pic );
 }
 
 /*****************************************************************************
@@ -764,9 +689,10 @@ static void SetOverlayTransparency( intf_thread_t *p_intf,
     {
         msg_Dbg( p_intf, "Make overlay %s",
                  b_transparent ? "transparent" : "opaque" );
-        memset( p_sys->p_overlay->p[0].p_pixels, 0x00, i_page_size );
         if( b_transparent )
             memset( p_sys->p_overlay->p[0].p_pixels, 0xFF, i_page_size );
+        else
+            memset( p_sys->p_overlay->p[0].p_pixels, 0x00, i_page_size );
     }
 }
 
@@ -785,22 +711,7 @@ static int BlendPicture( intf_thread_t *p_intf, video_format_t *p_fmt_src,
         int i_y_offset = p_sys->i_y;
 
         memcpy( &p_sys->p_blend->fmt_in.video, p_fmt_src, sizeof( video_format_t ) );
-#if 0
-        msg_Dbg( p_intf, "Blending pictures %p %4.4s (%dx%d) %d bits %d planes: 0=%p 1=%p 2=%p 3=%p",
-                 p_pic_src, (char*)&p_fmt_src->i_chroma,
-                 p_sys->p_blend->fmt_in.video.i_width, p_sys->p_blend->fmt_in.video.i_height,
-                 p_fmt_src->i_bits_per_pixel,
-                 p_pic_src->i_planes,
-                 p_pic_src->p[0].p_pixels, p_pic_src->p[1].p_pixels,
-                 p_pic_src->p[2].p_pixels, p_pic_src->p[3].p_pixels );
-        msg_Dbg( p_intf, "Blending pictures %p %4.4s (%dx%d) %d bits %d planes: 0=%p 1=%p 2=%p 3=%p",
-                 p_pic_dst, (char*)&p_fmt_dst->i_chroma,
-                 p_fmt_dst->i_width, p_fmt_dst->i_height,
-                 p_fmt_dst->i_bits_per_pixel,
-                 p_pic_dst->i_planes,
-                 p_pic_dst->p[0].p_pixels, p_pic_dst->p[1].p_pixels,
-                 p_pic_dst->p[2].p_pixels, p_pic_dst->p[3].p_pixels );
-#endif
+
         /* Update the output picture size */
         p_sys->p_blend->fmt_out.video.i_width =
             p_sys->p_blend->fmt_out.video.i_visible_width =
@@ -820,7 +731,6 @@ static int BlendPicture( intf_thread_t *p_intf, video_format_t *p_fmt_src,
     }
     return VLC_EGENERIC;
 }
-#endif
 
 static int InvertAlpha( intf_thread_t *p_intf, picture_t **p_pic, video_format_t fmt )
 {
@@ -857,15 +767,16 @@ static int InvertAlpha( intf_thread_t *p_intf, picture_t **p_pic, video_format_t
 
     for( ; p_begin < p_end; p_begin += i_skip )
     {
-        uint8_t i_opacity;
+        uint8_t i_opacity = 0;
 
-        if( i_opacity != 0xFF )
+        if( *p_begin != 0xFF )
             i_opacity = 255 - *p_begin;
         *p_begin = i_opacity;
     }
     /* end of kludge */
     return VLC_SUCCESS;
 }
+#endif
 
 /*****************************************************************************
  * RenderPicture: Render the picture into the p_dest buffer.
@@ -876,6 +787,7 @@ static int RenderPicture( intf_thread_t *p_intf, int i_x_offset, int i_y_offset,
                           picture_t *p_src, picture_t *p_dest )
 {
     int i;
+    VLC_UNUSED( p_intf );
 
     if( !p_dest && !p_src ) return VLC_EGENERIC;
 
@@ -902,7 +814,7 @@ static int RenderPicture( intf_thread_t *p_intf, int i_x_offset, int i_y_offset,
 
             i_y_clip = ( i_y_offset + p_src->p[i].i_visible_lines ) - p_dest->p[i].i_visible_lines;
             i_y_clip = ( i_y_clip > 0 ) ? i_y_clip : 0;
-#if 0
+#if defined(FBOSD_DEBUG)
             msg_Dbg( p_intf, "i_pitch (%d,%d), (%d,%d)/(%d,%d)",
                      p_dest->p[i].i_visible_pitch, p_src->p[i].i_visible_pitch,
                      i_x_offset, i_y_offset, i_x, i_x_clip );
@@ -947,6 +859,11 @@ static picture_t *RenderText( intf_thread_t *p_intf, const char *psz_string,
         memset( p_region, 0, sizeof(subpicture_region_t) );
 
         p_region->psz_text = strdup( psz_string );
+        if( !p_region->psz_text )
+        {
+            free( p_region );
+            return NULL;
+        }
         p_region->p_style = p_style;
 
         p_region->fmt.i_chroma = VLC_FOURCC('T','E','X','T');
@@ -1132,7 +1049,8 @@ static void End( intf_thread_t *p_intf )
     if( p_sys->p_overlay )
     {
         int ret;
-        ret = write( p_sys->i_fd, p_sys->p_overlay->p[0].p_pixels, p_sys->i_page_size );
+        ret = write( p_sys->i_fd, p_sys->p_overlay->p[0].p_pixels,
+                     p_sys->i_page_size );
         if( ret < 0 )
             msg_Err( p_intf, "unable to clear overlay" );
     }
@@ -1201,7 +1119,6 @@ static int OpenDisplay( intf_thread_t *p_intf )
         p_sys->p_palette = malloc( 8 * 256 * sizeof( uint16_t ) );
         if( !p_sys->p_palette )
         {
-            msg_Err( p_intf, "out of memory" );
             close( p_sys->i_fd );
             return VLC_ENOMEM;
         }
@@ -1282,7 +1199,7 @@ static void Render( intf_thread_t *p_intf, struct fbosd_render_t *render )
         {
             RenderPicture( p_intf, render->i_x, render->i_y,
                            p_pic, p_sys->p_overlay );
-            p_pic->pf_release( p_pic );
+            picture_Release( p_pic );
         }
     }
     else if( render->i_type == FBOSD_RENDER_TEXT )
@@ -1307,7 +1224,7 @@ static void Render( intf_thread_t *p_intf, struct fbosd_render_t *render )
         {
             RenderPicture( p_intf, render->i_x, render->i_y,
                            p_text, p_sys->p_overlay );
-            p_text->pf_release( p_text );
+            picture_Release( p_text );
         }
 #endif
     }
@@ -1345,7 +1262,7 @@ static bool isRendererReady( intf_thread_t *p_intf )
 }
 
 /*****************************************************************************
- * Run: rc thread
+ * Run: thread
  *****************************************************************************
  * This part of the interface is in a separate thread so that we can call
  * exec() from within it without annoying the rest of the program.
@@ -1365,8 +1282,8 @@ static void Run( intf_thread_t *p_intf )
             {
                 Render( p_intf, &p_sys->render[i] );
                 RenderClear( p_intf, &p_sys->render[i] );
-             }
-         }
+            }
+        }
 
         if( p_sys->b_clear )
         {
@@ -1507,12 +1424,10 @@ static int OverlayCallback( vlc_object_t *p_this, char const *psz_cmd,
         {
             p_sys->render[i].text_style.i_font_alpha = 255 - newval.i_int;
         }
-#if defined(FBOSD_BLENDING)
         else if( !strncmp( psz_cmd, "fbosd-alpha", 11 ) )
         {
             p_sys->render[i].i_alpha = newval.i_int;
         }
-#endif
     }
     return VLC_SUCCESS;
 }