1 /*****************************************************************************
2 * osd_text.c : text manipulation functions
3 *****************************************************************************
4 * Copyright (C) 1999-2007 the VideoLAN team
7 * Author: Sigmund Augdal Helberg <dnumgis@videolan.org>
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.
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.
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 *****************************************************************************/
29 #include <vlc_block.h>
30 #include <vlc_filter.h>
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.
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,
49 mtime_t i_now = mdate();
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 );
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
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 )
79 if( !psz_string ) return VLC_EGENERIC;
81 p_spu = spu_CreateSubpicture( p_spu_channel );
82 if( !p_spu ) return VLC_EGENERIC;
84 /* Create a new subpicture region */
85 memset( &fmt, 0, sizeof(video_format_t) );
86 fmt.i_chroma = VLC_FOURCC('T','E','X','T');
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 )
93 msg_Err( p_spu_channel, "cannot allocate SPU region" );
94 spu_DestroySubpicture( p_spu_channel, p_spu );
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;
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;
110 spu_DisplaySubpicture( p_spu_channel, p_spu );
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
123 void osd_Message( spu_t *p_spu, int i_channel,
124 char *psz_format, ... )
131 va_start( args, psz_format );
132 vasprintf( &psz_string, psz_format, args );
134 osd_ShowTextRelative( p_spu, i_channel, psz_string, NULL,
135 OSD_ALIGN_TOP|OSD_ALIGN_RIGHT, 30,20,1000000 );