1 /*****************************************************************************
2 * video_text.c : OSD text manipulation functions
3 *****************************************************************************
4 * Copyright (C) 1999-2010 VLC authors and VideoLAN
6 * Author: Sigmund Augdal Helberg <dnumgis@videolan.org>
7 * Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
29 #include <vlc_common.h>
31 #include <vlc_vout_osd.h>
36 } osd_spu_updater_sys_t
;
38 static int OSDTextValidate(subpicture_t
*subpic
,
39 bool has_src_changed
, const video_format_t
*fmt_src
,
40 bool has_dst_changed
, const video_format_t
*fmt_dst
,
43 VLC_UNUSED(subpic
); VLC_UNUSED(ts
);
44 VLC_UNUSED(fmt_src
); VLC_UNUSED(has_src_changed
);
47 if( !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 osd_spu_updater_sys_t
*sys
= subpic
->updater
.p_sys
;
58 VLC_UNUSED(fmt_src
); VLC_UNUSED(ts
);
60 if( fmt_dst
->i_sar_num
<= 0 || fmt_dst
->i_sar_den
<= 0 )
63 subpic
->b_absolute
= false;
64 subpic
->i_original_picture_width
= fmt_dst
->i_visible_width
* fmt_dst
->i_sar_num
/ fmt_dst
->i_sar_den
;
65 subpic
->i_original_picture_height
= fmt_dst
->i_visible_height
;
68 video_format_Init( &fmt
, VLC_CODEC_TEXT
);
72 subpicture_region_t
*r
= subpic
->p_region
= subpicture_region_New(&fmt
);
76 r
->p_text
= text_segment_New( sys
->text
);
78 const float margin_ratio
= 0.04;
79 const int margin_h
= margin_ratio
* fmt_dst
->i_visible_width
;
80 const int margin_v
= margin_ratio
* fmt_dst
->i_visible_height
;
82 r
->i_text_align
= sys
->position
;
83 r
->i_align
= sys
->position
;
85 if (r
->i_align
& SUBPICTURE_ALIGN_LEFT
)
86 r
->i_x
+= margin_h
+ fmt_dst
->i_x_offset
;
87 else if (r
->i_align
& SUBPICTURE_ALIGN_RIGHT
)
88 r
->i_x
+= margin_h
- fmt_dst
->i_x_offset
;
91 if (r
->i_align
& SUBPICTURE_ALIGN_TOP
)
92 r
->i_y
+= margin_v
+ fmt_dst
->i_y_offset
;
93 else if (r
->i_align
& SUBPICTURE_ALIGN_BOTTOM
)
94 r
->i_y
+= margin_v
- fmt_dst
->i_y_offset
;
97 static void OSDTextDestroy(subpicture_t
*subpic
)
99 osd_spu_updater_sys_t
*sys
= subpic
->updater
.p_sys
;
105 void vout_OSDText(vout_thread_t
*vout
, int channel
,
106 int position
, vlc_tick_t duration
, const char *text
)
108 assert( (position
& ~SUBPICTURE_ALIGN_MASK
) == 0);
109 if (!var_InheritBool(vout
, "osd") || duration
<= 0)
112 osd_spu_updater_sys_t
*sys
= malloc(sizeof(*sys
));
115 sys
->position
= position
;
116 sys
->text
= strdup(text
);
118 subpicture_updater_t updater
= {
119 .pf_validate
= OSDTextValidate
,
120 .pf_update
= OSDTextUpdate
,
121 .pf_destroy
= OSDTextDestroy
,
124 subpicture_t
*subpic
= subpicture_New(&updater
);
131 subpic
->i_channel
= channel
;
132 subpic
->i_start
= vlc_tick_now();
133 subpic
->i_stop
= subpic
->i_start
+ duration
;
134 subpic
->b_ephemer
= true;
135 subpic
->b_absolute
= false;
136 subpic
->b_fade
= true;
138 vout_PutSubpicture(vout
, subpic
);
141 void vout_OSDMessageVa(vout_thread_t
*vout
, int channel
,
142 const char *format
, va_list args
)
145 if (vasprintf(&string
, format
, args
) != -1) {
146 vout_OSDText(vout
, channel
,
147 SUBPICTURE_ALIGN_TOP
|SUBPICTURE_ALIGN_RIGHT
, VLC_TICK_FROM_SEC(1),