]> git.sesse.net Git - vlc/blob - src/osd/osd_text.c
update module LIST file.
[vlc] / src / osd / osd_text.c
1 /*****************************************************************************
2  * osd_text.c : text manipulation functions
3  *****************************************************************************
4  * Copyright (C) 1999-2007 the VideoLAN team
5  * $Id$
6  *
7  * Author: Sigmund Augdal Helberg <dnumgis@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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
26
27 #include <vlc/vlc.h>
28 #include <vlc_vout.h>
29 #include <vlc_block.h>
30 #include <vlc_filter.h>
31 #include <vlc_osd.h>
32
33 /**
34  * \brief Show text on the video for some time
35  * \param p_spu pointer to the subpicture queue the text is to be showed on
36  * \param i_channel Subpicture channel
37  * \param psz_string The text to be shown
38  * \param p_style Pointer to a struct with text style info
39  * \param i_flags flags for alignment and such
40  * \param i_hmargin horizontal margin in pixels
41  * \param i_vmargin vertical margin in pixels
42  * \param i_duration Amount of time the text is to be shown.
43  */
44 int osd_ShowTextRelative( spu_t *p_spu, int i_channel,
45                            char *psz_string, text_style_t *p_style,
46                            int i_flags, int i_hmargin, int i_vmargin,
47                            mtime_t i_duration )
48 {
49     mtime_t i_now = mdate();
50
51     return osd_ShowTextAbsolute( p_spu, i_channel, psz_string,
52                                   p_style, i_flags, i_hmargin, i_vmargin,
53                                   i_now, i_now + i_duration );
54 }
55
56 /**
57  * \brief Show text on the video from a given start date to a given end date
58  * \param p_spu pointer to the subpicture queue the text is to be showed on
59  * \param i_channel Subpicture channel
60  * \param psz_string The text to be shown
61  * \param p_style Pointer to a struct with text style info
62  * \param i_flags flags for alignment and such
63  * \param i_hmargin horizontal margin in pixels
64  * \param i_vmargin vertical margin in pixels
65  * \param i_start the time when this string is to appear on the video
66  * \param i_stop the time when this string should stop to be displayed
67  *               if this is 0 the string will be shown untill the next string
68  *               is about to be shown
69  */
70 int osd_ShowTextAbsolute( spu_t *p_spu_channel, int i_channel,
71                            char *psz_string, text_style_t *p_style,
72                            int i_flags, int i_hmargin, int i_vmargin,
73                            mtime_t i_start, mtime_t i_stop )
74 {
75     subpicture_t *p_spu;
76     video_format_t fmt;
77     (void)p_style;
78
79     if( !psz_string ) return VLC_EGENERIC;
80
81     p_spu = spu_CreateSubpicture( p_spu_channel );
82     if( !p_spu ) return VLC_EGENERIC;
83
84     /* Create a new subpicture region */
85     memset( &fmt, 0, sizeof(video_format_t) );
86     fmt.i_chroma = VLC_FOURCC('T','E','X','T');
87     fmt.i_aspect = 0;
88     fmt.i_width = fmt.i_height = 0;
89     fmt.i_x_offset = fmt.i_y_offset = 0;
90     p_spu->p_region = p_spu->pf_create_region( VLC_OBJECT(p_spu_channel), &fmt );
91     if( !p_spu->p_region )
92     {
93         msg_Err( p_spu_channel, "cannot allocate SPU region" );
94         spu_DestroySubpicture( p_spu_channel, p_spu );
95         return VLC_EGENERIC;
96     }
97
98     p_spu->p_region->psz_text = strdup( psz_string );
99     p_spu->p_region->i_align = i_flags & SUBPICTURE_ALIGN_MASK;
100     p_spu->i_start = i_start;
101     p_spu->i_stop = i_stop;
102     p_spu->b_ephemer = VLC_TRUE;
103     p_spu->b_absolute = VLC_FALSE;
104
105     p_spu->i_x = i_hmargin;
106     p_spu->i_y = i_vmargin;
107     p_spu->i_flags = i_flags & ~SUBPICTURE_ALIGN_MASK;
108     p_spu->i_channel = i_channel;
109
110     spu_DisplaySubpicture( p_spu_channel, p_spu );
111
112     return VLC_SUCCESS;
113 }
114
115
116 /**
117  * \brief Write an informative message at the default location,
118  *        for the default duration and only if the OSD option is enabled.
119  * \param p_caller The object that called the function.
120  * \param i_channel Subpicture channel
121  * \param psz_format printf style formatting
122  **/
123 void osd_Message( spu_t *p_spu, int i_channel,
124                         char *psz_format, ... )
125 {
126     char *psz_string;
127     va_list args;
128
129     if( p_spu )
130     {
131         va_start( args, psz_format );
132         vasprintf( &psz_string, psz_format, args );
133
134         osd_ShowTextRelative( p_spu, i_channel, psz_string, NULL,
135                                OSD_ALIGN_TOP|OSD_ALIGN_RIGHT, 30,20,1000000 );
136
137         free( psz_string );
138         va_end( args );
139     }
140 }