1 /*****************************************************************************
2 * video_text.c : OSD text manipulation functions
3 *****************************************************************************
4 * Copyright (C) 1999-2010 the VideoLAN team
7 * Author: Sigmund Augdal Helberg <dnumgis@videolan.org>
8 * Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
30 #include <vlc_common.h>
32 #include <vlc_vout_osd.h>
34 struct subpicture_updater_sys_t {
39 static int OSDTextValidate(subpicture_t *subpic,
40 bool has_src_changed, const video_format_t *fmt_src,
41 bool has_dst_changed, const video_format_t *fmt_dst,
44 VLC_UNUSED(subpic); VLC_UNUSED(ts); VLC_UNUSED(fmt_src);
45 VLC_UNUSED(has_dst_changed); VLC_UNUSED(fmt_dst);
47 if( !has_src_changed && !has_dst_changed)
52 static void OSDTextUpdate(subpicture_t *subpic,
53 const video_format_t *fmt_src,
54 const video_format_t *fmt_dst,
57 subpicture_updater_sys_t *sys = subpic->updater.p_sys;
58 VLC_UNUSED(fmt_dst); VLC_UNUSED(ts);
60 subpic->i_original_picture_width = fmt_src->i_width;
61 subpic->i_original_picture_height = fmt_src->i_height;
64 video_format_Init( &fmt, VLC_CODEC_TEXT);
68 subpicture_region_t *r = subpic->p_region = subpicture_region_New(&fmt);
72 r->psz_text = strdup(sys->text);
73 r->i_align = sys->position;
74 r->i_x = 30 + fmt_src->i_width
75 - fmt_src->i_visible_width
76 - fmt_src->i_x_offset;
77 r->i_y = 20 + fmt_src->i_y_offset;
80 static void OSDTextDestroy(subpicture_t *subpic)
82 subpicture_updater_sys_t *sys = subpic->updater.p_sys;
88 void vout_OSDText(vout_thread_t *vout, int channel,
89 int position, mtime_t duration, const char *text)
91 assert( (position & ~SUBPICTURE_ALIGN_MASK) == 0);
92 if (!var_InheritBool(vout, "osd") || duration <= 0)
95 subpicture_updater_sys_t *sys = malloc(sizeof(*sys));
98 sys->position = position;
99 sys->text = strdup(text);
101 subpicture_updater_t updater = {
102 .pf_validate = OSDTextValidate,
103 .pf_update = OSDTextUpdate,
104 .pf_destroy = OSDTextDestroy,
107 subpicture_t *subpic = subpicture_New(&updater);
114 subpic->i_channel = channel;
115 subpic->i_start = mdate();
116 subpic->i_stop = subpic->i_start + duration;
117 subpic->b_ephemer = true;
118 subpic->b_absolute = false;
119 subpic->b_fade = true;
121 spu_DisplaySubpicture(vout_GetSpu(vout), subpic);
124 void vout_OSDMessage(vout_thread_t *vout, int channel, const char *format, ...)
127 va_start(args, format);
130 if (vasprintf(&string, format, args) != -1) {
131 vout_OSDText(vout, channel,
132 SUBPICTURE_ALIGN_TOP|SUBPICTURE_ALIGN_RIGHT, 1000000,