]> git.sesse.net Git - vlc/blob - plugins/xosd/xosd.c
ee8242fac9de28cfe43881fd323a9c3a0bfced5e
[vlc] / plugins / xosd / xosd.c
1 /*****************************************************************************
2  * xosd.c : X On Screen Display interface
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: xosd.c,v 1.4 2002/07/20 18:01:43 sam Exp $
6  *
7  * Authors: Loïc Minier <lool@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <string.h>
29
30 #include <xosd.h>
31
32 #include <vlc/intf.h>
33
34 #ifdef HAVE_UNISTD_H
35 #    include <unistd.h>
36 #endif
37
38 /*****************************************************************************
39  * intf_sys_t: description and status of rc interface
40  *****************************************************************************/
41 struct intf_sys_t
42 {
43     input_thread_t * p_input;   /* associated input thread */
44     xosd * p_osd;               /* libxosd handle */
45     char * psz_source;          /* current file || NULL */
46 };
47
48 #define MAX_LINE_LENGTH 256
49
50 /*****************************************************************************
51  * Local prototypes.
52  *****************************************************************************/
53 static void intf_getfunctions ( function_list_t * p_function_list );
54 static int  intf_Open         ( intf_thread_t *p_intf );
55 static void intf_Close        ( intf_thread_t *p_intf );
56 static void intf_Run          ( intf_thread_t *p_intf );
57
58 /*****************************************************************************
59  * Build configuration tree.
60  *****************************************************************************/
61 #define POSITION_TEXT N_("flip vertical position")
62 #define POSITION_LONGTEXT N_("Display xosd output on the bottom of the " \
63                              "screen instead of the top")
64
65 #define TXT_OFS_TEXT N_("vertical offset")
66 #define TXT_OFS_LONGTEXT N_("Vertical offset in pixels of the displayed text")
67
68 #define SHD_OFS_TEXT N_("shadow offset")
69 #define SHD_OFS_LONGTEXT N_("Offset in pixels of the shadow")
70
71 #define FONT_TEXT N_("font")
72 #define FONT_LONGTEXT N_("Font used to display text in the xosd output")
73
74 MODULE_CONFIG_START
75 ADD_CATEGORY_HINT( N_("Miscellaneous"), NULL )
76 ADD_BOOL( "xosd-position", 1, NULL, POSITION_TEXT, POSITION_LONGTEXT )
77 ADD_INTEGER( "xosd-text-offset", 0, NULL, TXT_OFS_TEXT, TXT_OFS_LONGTEXT )
78 ADD_INTEGER( "xosd-shadow-offset", 1, NULL, SHD_OFS_TEXT, SHD_OFS_LONGTEXT )
79 ADD_STRING( "xosd-font", "-misc-fixed-medium-r-*-*-*-300-*-*-*-*-*-*", NULL, FONT_TEXT, FONT_LONGTEXT )
80 MODULE_CONFIG_STOP
81 // -misc-fixed-medium-r-normal-*-*-160-*-*-c-*-iso8859-15
82
83 MODULE_INIT_START
84     SET_DESCRIPTION( _("xosd interface module") )
85     ADD_CAPABILITY( INTF, 40 )
86 MODULE_INIT_STOP
87
88 MODULE_ACTIVATE_START
89     intf_getfunctions( &p_module->p_functions->intf );
90 MODULE_ACTIVATE_STOP
91
92 MODULE_DEACTIVATE_START
93 MODULE_DEACTIVATE_STOP
94
95 /*****************************************************************************
96  * Functions exported as capabilities. They are declared as static so that
97  * we don't pollute the namespace too much.
98  *****************************************************************************/
99 static void intf_getfunctions( function_list_t * p_function_list )
100 {
101     p_function_list->functions.intf.pf_open  = intf_Open;
102     p_function_list->functions.intf.pf_close = intf_Close;
103     p_function_list->functions.intf.pf_run   = intf_Run;
104 }
105
106 /*****************************************************************************
107  * intf_Open: initialize and create stuff
108  *****************************************************************************/
109 static int intf_Open( intf_thread_t * p_intf )
110 {
111     /* Allocate instance and initialize some members */
112     p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
113     if( p_intf->p_sys == NULL )
114     {
115         msg_Err( p_intf, "out of memory" );
116         return( 1 );
117     }
118
119     /* Initialize library */
120     p_intf->p_sys->p_osd =
121         xosd_init( "fixed", "LawnGreen", 3, XOSD_top, 0, 1 );
122
123     /* Initialize to NULL */
124     p_intf->p_sys->psz_source = NULL;
125
126     xosd_display( p_intf->p_sys->p_osd,
127                   0,
128                   XOSD_string,
129                   "xosd interface initialized" );
130     return( 0 );
131 }
132
133 /*****************************************************************************
134  * intf_Close: destroy interface stuff
135  *****************************************************************************/
136 static void intf_Close( intf_thread_t *p_intf )
137 {
138     if( p_intf->p_sys->psz_source ) free( p_intf->p_sys->psz_source );
139
140     /* Uninitialize library */
141     xosd_uninit( p_intf->p_sys->p_osd );
142
143     /* Destroy structure */
144     free( p_intf->p_sys );
145 }
146
147 /*****************************************************************************
148  * intf_Run: xosd thread
149  *****************************************************************************
150  * This part of the interface runs in a separate thread
151  *****************************************************************************/
152 static void intf_Run( intf_thread_t *p_intf )
153 {
154     p_intf->p_sys->p_input = NULL;
155
156     while( !p_intf->b_die )
157     {
158         /* Manage the input part */
159         if( p_intf->p_sys->p_input == NULL )
160         {
161             p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
162                                                               FIND_ANYWHERE );
163         }
164         else if( p_intf->p_sys->p_input->b_dead )
165         {
166             vlc_object_release( p_intf->p_sys->p_input );
167             p_intf->p_sys->p_input = NULL;
168         }
169         else /* We have a valid input */
170         {
171             /* Did source change? */
172             if ( (p_intf->p_sys->psz_source == NULL)
173                  || (strcmp( p_intf->p_sys->psz_source,
174                              p_intf->p_sys->p_input->psz_source ) != 0)
175                )
176             {
177                 if( p_intf->p_sys->psz_source )
178                     free( p_intf->p_sys->psz_source );
179
180                 p_intf->p_sys->psz_source =
181                     strdup( p_intf->p_sys->p_input->psz_source );
182
183                 /* Set user preferences */
184                 xosd_set_font( p_intf->p_sys->p_osd,
185                                config_GetPsz( p_intf, "xosd-font" ) );
186                 xosd_set_offset( p_intf->p_sys->p_osd,
187                     config_GetInt( p_intf, "xosd-text-offset" ) );
188                 xosd_set_shadow_offset( p_intf->p_sys->p_osd,
189                     config_GetInt( p_intf, "xosd-shadow-offset" ));
190                 xosd_set_pos( p_intf->p_sys->p_osd,
191                     config_GetInt( p_intf, "xosd-position" ) ? XOSD_bottom
192                                                              : XOSD_top );
193
194                 /* Display */
195                 xosd_display( p_intf->p_sys->p_osd,
196                               0,                               /* first line */
197                               XOSD_string,
198                               p_intf->p_sys->psz_source );
199             }
200         }
201
202         msleep( INTF_IDLE_SLEEP );
203     }
204
205     if( p_intf->p_sys->p_input )
206     {
207         vlc_object_release( p_intf->p_sys->p_input );
208         p_intf->p_sys->p_input = NULL;
209     }
210
211 }
212