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