1 /*****************************************************************************
2 * video_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_common.h>
31 #include <vlc_block.h>
32 #include <vlc_filter.h>
35 /* TODO remove access to private vout data */
36 #include "vout_internal.h"
39 * \brief Show text on the video from a given start date to a given end date
40 * \param p_vout pointer to the vout the text is to be showed on
41 * \param i_channel Subpicture channel
42 * \param psz_string The text to be shown
43 * \param p_style Pointer to a struct with text style info (it is duplicated if non NULL)
44 * \param i_flags flags for alignment and such
45 * \param i_hmargin horizontal margin in pixels
46 * \param i_vmargin vertical margin in pixels
47 * \param i_duration Amount of time the text is to be shown.
49 int vout_ShowTextRelative( vout_thread_t *p_vout, int i_channel,
50 const char *psz_string, const text_style_t *p_style,
51 int i_flags, int i_hmargin, int i_vmargin,
57 if( !psz_string ) return VLC_EGENERIC;
59 p_spu = subpicture_New( NULL );
63 p_spu->i_channel = i_channel;
64 p_spu->i_start = mdate();
65 p_spu->i_stop = p_spu->i_start + i_duration;
66 p_spu->b_ephemer = true;
67 p_spu->b_absolute = false;
71 /* Create a new subpicture region */
72 memset( &fmt, 0, sizeof(video_format_t) );
73 fmt.i_chroma = VLC_CODEC_TEXT;
74 fmt.i_width = fmt.i_height = 0;
75 fmt.i_x_offset = fmt.i_y_offset = 0;
76 p_spu->p_region = subpicture_region_New( &fmt );
77 if( !p_spu->p_region )
79 msg_Err( p_vout, "cannot allocate SPU region" );
80 subpicture_Delete( p_spu );
84 p_spu->p_region->psz_text = strdup( psz_string );
85 p_spu->p_region->i_align = i_flags & SUBPICTURE_ALIGN_MASK;
86 p_spu->p_region->i_x = i_hmargin;
87 p_spu->p_region->i_y = i_vmargin;
89 p_spu->p_region->p_style = text_style_Duplicate( p_style );
91 spu_DisplaySubpicture( vout_GetSpu( p_vout ), p_spu );
97 * \brief Write an informative message at the default location,
98 * for the default duration and only if the OSD option is enabled.
99 * \param p_caller The object that called the function.
100 * \param i_channel Subpicture channel
101 * \param psz_format printf style formatting
103 void vout_OSDMessage( vout_thread_t *p_vout, int i_channel,
104 const char *psz_format, ... )
106 if( !var_InheritBool( p_vout, "osd" ) )
110 va_start( args, psz_format );
113 if( vasprintf( &psz_string, psz_format, args ) != -1 )
115 vout_ShowTextRelative( p_vout, i_channel, psz_string, NULL,
116 SUBPICTURE_ALIGN_TOP|SUBPICTURE_ALIGN_RIGHT,
117 30 + p_vout->p->fmt_in.i_width
118 - p_vout->p->fmt_in.i_visible_width
119 - p_vout->p->fmt_in.i_x_offset,
120 20 + p_vout->p->fmt_in.i_y_offset, 1000000 );