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