basetextoverlay: Add new properties and alignment type for unclamped absolute positions
[platform/upstream/gstreamer.git] / ext / pango / gstbasetextoverlay.h
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  * GstBaseTextOverlay:
120  *
121  * Opaque textoverlay object structure
122  */
123 struct _GstBaseTextOverlay {
124     GstElement               element;
125
126     GstPad                  *video_sinkpad;
127     GstPad                  *text_sinkpad;
128     GstPad                  *srcpad;
129
130     GstSegment               segment;
131     GstSegment               text_segment;
132     GstBuffer               *text_buffer;
133     gboolean                 text_linked;
134     gboolean                 video_flushing;
135     gboolean                 video_eos;
136     gboolean                 text_flushing;
137     gboolean                 text_eos;
138
139     GMutex                   lock;
140     GCond                    cond;  /* to signal removal of a queued text
141                                      * buffer, arrival of a text buffer,
142                                      * a text segment update, or a change
143                                      * in status (e.g. shutdown, flushing) */
144
145     /* stream metrics */
146     GstVideoInfo             info;
147     GstVideoFormat           format;
148     gint                     width;
149     gint                     height;
150
151     /* properties */
152     gint                     xpad;
153     gint                     ypad;
154     gint                     deltax;
155     gint                     deltay;
156     gdouble                  xpos;
157     gdouble                  ypos;
158     gchar                   *default_text;
159     gboolean                 want_shading;
160     gboolean                 silent;
161     gboolean                 wait_text;
162     guint                    color, outline_color;
163     PangoLayout             *layout;
164     gboolean                 auto_adjust_size;
165     gboolean                 draw_shadow;
166     gboolean                 draw_outline;
167     gint                     shading_value;  /* for timeoverlay subclass */
168     gboolean                 use_vertical_render;
169     GstBaseTextOverlayVAlign     valign;
170     GstBaseTextOverlayHAlign     halign;
171     GstBaseTextOverlayWrapMode   wrap_mode;
172     GstBaseTextOverlayLineAlign  line_align;
173
174     /* text pad format */
175     gboolean                 have_pango_markup;
176
177     /* rendering state */
178     gboolean                 need_render;
179     GstBuffer               *text_image;
180
181     /* dimension relative to witch the render is done, this is the stream size
182      * or a portion of the window_size (adapted to aspect ratio) */
183     gint                     render_width;
184     gint                     render_height;
185     /* This is (render_width / width) uses to convert to stream scale */
186     gdouble                  render_scale;
187
188     /* dimension of text_image, the physical dimension */
189     guint                    text_width;
190     guint                    text_height;
191
192     /* position of rendering in image coordinates */
193     gint                     text_x;
194     gint                     text_y;
195
196     /* window dimension, reported in the composition meta params. This is set
197      * to stream width, height if missing */
198     gint                     window_width;
199     gint                     window_height;
200
201     gdouble                  shadow_offset;
202     gdouble                  outline_offset;
203
204     PangoRectangle           ink_rect;
205     PangoRectangle           logical_rect;
206
207     gboolean                    attach_compo_to_buffer;
208     GstVideoOverlayComposition *composition;
209     GstVideoOverlayComposition *upstream_composition;
210 };
211
212 struct _GstBaseTextOverlayClass {
213     GstElementClass parent_class;
214
215     PangoContext *pango_context;
216     GMutex       *pango_lock;
217
218     gchar *     (*get_text) (GstBaseTextOverlay *overlay, GstBuffer *video_frame);
219 };
220
221 GType gst_base_text_overlay_get_type(void) G_GNUC_CONST;
222
223 G_END_DECLS
224
225 #endif /* __GST_BASE_TEXT_OVERLAY_H */