• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  * Copyright (C) <2003> David Schleef <ds@schleef.org>
4  * Copyright (C) <2006> Julien Moutte <julien@moutte.net>
5  * Copyright (C) <2006> Zeeshan Ali <zeeshan.ali@nokia.com>
6  * Copyright (C) <2006-2008> Tim-Philipp Müller <tim centricular net>
7  * Copyright (C) <2009> Young-Ho Cha <ganadist@gmail.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library 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 GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22  * Boston, MA 02110-1301, USA.
23  */
24 
25 #ifndef __GST_BASE_TEXT_OVERLAY_H__
26 #define __GST_BASE_TEXT_OVERLAY_H__
27 
28 #include <gst/gst.h>
29 #include <gst/video/video.h>
30 #include <gst/video/video-overlay-composition.h>
31 #include <pango/pangocairo.h>
32 
33 G_BEGIN_DECLS
34 
35 #define GST_TYPE_BASE_TEXT_OVERLAY            (gst_base_text_overlay_get_type())
36 #define GST_BASE_TEXT_OVERLAY(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),\
37                                          GST_TYPE_BASE_TEXT_OVERLAY, GstBaseTextOverlay))
38 #define GST_BASE_TEXT_OVERLAY_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),\
39                                          GST_TYPE_BASE_TEXT_OVERLAY,GstBaseTextOverlayClass))
40 #define GST_BASE_TEXT_OVERLAY_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),\
41                                          GST_TYPE_BASE_TEXT_OVERLAY, GstBaseTextOverlayClass))
42 #define GST_IS_BASE_TEXT_OVERLAY(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),\
43                                          GST_TYPE_BASE_TEXT_OVERLAY))
44 #define GST_IS_BASE_TEXT_OVERLAY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),\
45                                          GST_TYPE_BASE_TEXT_OVERLAY))
46 
47 typedef struct _GstBaseTextOverlay      GstBaseTextOverlay;
48 typedef struct _GstBaseTextOverlayClass GstBaseTextOverlayClass;
49 
50 /**
51  * GstBaseTextOverlayVAlign:
52  * @GST_BASE_TEXT_OVERLAY_VALIGN_BASELINE: draw text on the baseline
53  * @GST_BASE_TEXT_OVERLAY_VALIGN_BOTTOM: draw text on the bottom
54  * @GST_BASE_TEXT_OVERLAY_VALIGN_TOP: draw text on top
55  * @GST_BASE_TEXT_OVERLAY_VALIGN_POS: draw text according to the #GstBaseTextOverlay:ypos property
56  * @GST_BASE_TEXT_OVERLAY_VALIGN_CENTER: draw text vertically centered
57  *
58  * Vertical alignment of the text.
59  */
60 typedef enum {
61     GST_BASE_TEXT_OVERLAY_VALIGN_BASELINE,
62     GST_BASE_TEXT_OVERLAY_VALIGN_BOTTOM,
63     GST_BASE_TEXT_OVERLAY_VALIGN_TOP,
64     GST_BASE_TEXT_OVERLAY_VALIGN_POS,
65     GST_BASE_TEXT_OVERLAY_VALIGN_CENTER,
66     GST_BASE_TEXT_OVERLAY_VALIGN_ABSOLUTE
67 } GstBaseTextOverlayVAlign;
68 
69 /**
70  * GstBaseTextOverlayHAlign:
71  * @GST_BASE_TEXT_OVERLAY_HALIGN_LEFT: align text left
72  * @GST_BASE_TEXT_OVERLAY_HALIGN_CENTER: align text center
73  * @GST_BASE_TEXT_OVERLAY_HALIGN_RIGHT: align text right
74  * @GST_BASE_TEXT_OVERLAY_HALIGN_POS: position text according to the #GstBaseTextOverlay:xpos property
75  *
76  * Horizontal alignment of the text.
77  */
78 /* FIXME 0.11: remove GST_BASE_TEXT_OVERLAY_HALIGN_UNUSED */
79 typedef enum {
80     GST_BASE_TEXT_OVERLAY_HALIGN_LEFT,
81     GST_BASE_TEXT_OVERLAY_HALIGN_CENTER,
82     GST_BASE_TEXT_OVERLAY_HALIGN_RIGHT,
83     GST_BASE_TEXT_OVERLAY_HALIGN_UNUSED,
84     GST_BASE_TEXT_OVERLAY_HALIGN_POS,
85     GST_BASE_TEXT_OVERLAY_HALIGN_ABSOLUTE
86 } GstBaseTextOverlayHAlign;
87 
88 /**
89  * GstBaseTextOverlayWrapMode:
90  * @GST_BASE_TEXT_OVERLAY_WRAP_MODE_NONE: no wrapping
91  * @GST_BASE_TEXT_OVERLAY_WRAP_MODE_WORD: do word wrapping
92  * @GST_BASE_TEXT_OVERLAY_WRAP_MODE_CHAR: do char wrapping
93  * @GST_BASE_TEXT_OVERLAY_WRAP_MODE_WORD_CHAR: do word and char wrapping
94  *
95  * Whether to wrap the text and if so how.
96  */
97 typedef enum {
98     GST_BASE_TEXT_OVERLAY_WRAP_MODE_NONE = -1,
99     GST_BASE_TEXT_OVERLAY_WRAP_MODE_WORD = PANGO_WRAP_WORD,
100     GST_BASE_TEXT_OVERLAY_WRAP_MODE_CHAR = PANGO_WRAP_CHAR,
101     GST_BASE_TEXT_OVERLAY_WRAP_MODE_WORD_CHAR = PANGO_WRAP_WORD_CHAR
102 } GstBaseTextOverlayWrapMode;
103 
104 /**
105  * GstBaseTextOverlayLineAlign:
106  * @GST_BASE_TEXT_OVERLAY_LINE_ALIGN_LEFT: lines are left-aligned
107  * @GST_BASE_TEXT_OVERLAY_LINE_ALIGN_CENTER: lines are center-aligned
108  * @GST_BASE_TEXT_OVERLAY_LINE_ALIGN_RIGHT: lines are right-aligned
109  *
110  * Alignment of text lines relative to each other
111  */
112 typedef enum {
113     GST_BASE_TEXT_OVERLAY_LINE_ALIGN_LEFT = PANGO_ALIGN_LEFT,
114     GST_BASE_TEXT_OVERLAY_LINE_ALIGN_CENTER = PANGO_ALIGN_CENTER,
115     GST_BASE_TEXT_OVERLAY_LINE_ALIGN_RIGHT = PANGO_ALIGN_RIGHT
116 } GstBaseTextOverlayLineAlign;
117 
118 /**
119  * GstBaseTextOverlayScaleMode:
120  * @GST_BASE_TEXT_OVERLAY_SCALE_MODE_NONE: no compensation
121  * @GST_BASE_TEXT_OVERLAY_SCALE_MODE_PAR: compensate pixel-aspect-ratio scaling
122  * @GST_BASE_TEXT_OVERLAY_SCALE_MODE_DISPLAY: compensate for scaling to display (as determined by overlay allocation meta)
123  * @GST_BASE_TEXT_OVERLAY_SCALE_MODE_USER: compensate scaling set by #GstBaseTextOverlay:scale-pixel-aspect-ratio property
124  *
125  * Scale text to compensate for and avoid aspect distortion by subsequent
126  * scaling of video
127  */
128 typedef enum {
129     GST_BASE_TEXT_OVERLAY_SCALE_MODE_NONE,
130     GST_BASE_TEXT_OVERLAY_SCALE_MODE_PAR,
131     GST_BASE_TEXT_OVERLAY_SCALE_MODE_DISPLAY,
132     GST_BASE_TEXT_OVERLAY_SCALE_MODE_USER
133 } GstBaseTextOverlayScaleMode;
134 
135 /**
136  * GstBaseTextOverlay:
137  *
138  * Opaque textoverlay object structure
139  */
140 struct _GstBaseTextOverlay {
141     GstElement               element;
142 
143     GstPad                  *video_sinkpad;
144     GstPad                  *text_sinkpad;
145     GstPad                  *srcpad;
146 
147     PangoContext            *pango_context;
148 
149     GstSegment               segment;
150     GstSegment               text_segment;
151     GstBuffer               *text_buffer;
152     gboolean                 text_linked;
153     gboolean                 video_flushing;
154     gboolean                 video_eos;
155     gboolean                 text_flushing;
156     gboolean                 text_eos;
157 
158     GMutex                   lock;
159     GCond                    cond;  /* to signal removal of a queued text
160                                      * buffer, arrival of a text buffer,
161                                      * a text segment update, or a change
162                                      * in status (e.g. shutdown, flushing) */
163 
164     /* stream metrics */
165     GstVideoInfo             info;
166     GstVideoFormat           format;
167     gint                     width;
168     gint                     height;
169 
170     /* properties */
171     gint                     xpad;
172     gint                     ypad;
173     gint                     deltax;
174     gint                     deltay;
175     gdouble                  xpos;
176     gdouble                  ypos;
177     gchar                   *default_text;
178     gboolean                 want_shading;
179     gboolean                 silent;
180     gboolean                 wait_text;
181     guint                    color, outline_color;
182     PangoLayout             *layout;
183     gboolean                 auto_adjust_size;
184     gboolean                 draw_shadow;
185     gboolean                 draw_outline;
186     gint                     shading_value;  /* for timeoverlay subclass */
187     gboolean                 use_vertical_render;
188     GstBaseTextOverlayVAlign     valign;
189     GstBaseTextOverlayHAlign     halign;
190     GstBaseTextOverlayWrapMode   wrap_mode;
191     GstBaseTextOverlayLineAlign  line_align;
192     GstBaseTextOverlayScaleMode  scale_mode;
193     gint                     scale_par_n;
194     gint                     scale_par_d;
195 
196     /* text pad format */
197     gboolean                 have_pango_markup;
198 
199     /* rendering state */
200     gboolean                 need_render;
201     GstBuffer               *text_image;
202 
203     /* dimension relative to witch the render is done, this is the stream size
204      * or a portion of the window_size (adapted to aspect ratio) */
205     gint                     render_width;
206     gint                     render_height;
207     /* This is (render_width / width) uses to convert to stream scale */
208     gdouble                  render_scale;
209 
210     /* dimension of text_image, the physical dimension */
211     guint                    text_width;
212     guint                    text_height;
213 
214     /* position of rendering in image coordinates */
215     gint                     text_x;
216     gint                     text_y;
217 
218     /* window dimension, reported in the composition meta params. This is set
219      * to stream width, height if missing */
220     gint                     window_width;
221     gint                     window_height;
222 
223     gdouble                  shadow_offset;
224     gdouble                  outline_offset;
225 
226     PangoRectangle           ink_rect;
227     PangoRectangle           logical_rect;
228 
229     gboolean                    attach_compo_to_buffer;
230     GstVideoOverlayComposition *composition;
231     GstVideoOverlayComposition *upstream_composition;
232 };
233 
234 struct _GstBaseTextOverlayClass {
235     GstElementClass parent_class;
236 
237     gchar *     (*get_text) (GstBaseTextOverlay *overlay, GstBuffer *video_frame);
238 };
239 
240 GType gst_base_text_overlay_get_type(void) G_GNUC_CONST;
241 
242 G_END_DECLS
243 
244 #endif /* __GST_BASE_TEXT_OVERLAY_H */
245