textoverlay: Expose rendering dimensions as properties.
[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 } GstBaseTextOverlayVAlign;
67
68 /**
69  * GstBaseTextOverlayHAlign:
70  * @GST_BASE_TEXT_OVERLAY_HALIGN_LEFT: align text left
71  * @GST_BASE_TEXT_OVERLAY_HALIGN_CENTER: align text center
72  * @GST_BASE_TEXT_OVERLAY_HALIGN_RIGHT: align text right
73  * @GST_BASE_TEXT_OVERLAY_HALIGN_POS: position text according to the #GstBaseTextOverlay:xpos property
74  *
75  * Horizontal alignment of the text.
76  */
77 /* FIXME 0.11: remove GST_BASE_TEXT_OVERLAY_HALIGN_UNUSED */
78 typedef enum {
79     GST_BASE_TEXT_OVERLAY_HALIGN_LEFT,
80     GST_BASE_TEXT_OVERLAY_HALIGN_CENTER,
81     GST_BASE_TEXT_OVERLAY_HALIGN_RIGHT,
82     GST_BASE_TEXT_OVERLAY_HALIGN_UNUSED,
83     GST_BASE_TEXT_OVERLAY_HALIGN_POS
84 } GstBaseTextOverlayHAlign;
85
86 /**
87  * GstBaseTextOverlayWrapMode:
88  * @GST_BASE_TEXT_OVERLAY_WRAP_MODE_NONE: no wrapping
89  * @GST_BASE_TEXT_OVERLAY_WRAP_MODE_WORD: do word wrapping
90  * @GST_BASE_TEXT_OVERLAY_WRAP_MODE_CHAR: do char wrapping
91  * @GST_BASE_TEXT_OVERLAY_WRAP_MODE_WORD_CHAR: do word and char wrapping
92  *
93  * Whether to wrap the text and if so how.
94  */
95 typedef enum {
96     GST_BASE_TEXT_OVERLAY_WRAP_MODE_NONE = -1,
97     GST_BASE_TEXT_OVERLAY_WRAP_MODE_WORD = PANGO_WRAP_WORD,
98     GST_BASE_TEXT_OVERLAY_WRAP_MODE_CHAR = PANGO_WRAP_CHAR,
99     GST_BASE_TEXT_OVERLAY_WRAP_MODE_WORD_CHAR = PANGO_WRAP_WORD_CHAR
100 } GstBaseTextOverlayWrapMode;
101
102 /**
103  * GstBaseTextOverlayLineAlign:
104  * @GST_BASE_TEXT_OVERLAY_LINE_ALIGN_LEFT: lines are left-aligned
105  * @GST_BASE_TEXT_OVERLAY_LINE_ALIGN_CENTER: lines are center-aligned
106  * @GST_BASE_TEXT_OVERLAY_LINE_ALIGN_RIGHT: lines are right-aligned
107  *
108  * Alignment of text lines relative to each other
109  */
110 typedef enum {
111     GST_BASE_TEXT_OVERLAY_LINE_ALIGN_LEFT = PANGO_ALIGN_LEFT,
112     GST_BASE_TEXT_OVERLAY_LINE_ALIGN_CENTER = PANGO_ALIGN_CENTER,
113     GST_BASE_TEXT_OVERLAY_LINE_ALIGN_RIGHT = PANGO_ALIGN_RIGHT
114 } GstBaseTextOverlayLineAlign;
115
116 /**
117  * GstBaseTextOverlay:
118  *
119  * Opaque textoverlay object structure
120  */
121 struct _GstBaseTextOverlay {
122     GstElement               element;
123
124     GstPad                  *video_sinkpad;
125     GstPad                  *text_sinkpad;
126     GstPad                  *srcpad;
127
128     GstSegment               segment;
129     GstSegment               text_segment;
130     GstBuffer               *text_buffer;
131     gboolean                 text_linked;
132     gboolean                 video_flushing;
133     gboolean                 video_eos;
134     gboolean                 text_flushing;
135     gboolean                 text_eos;
136
137     GMutex                   lock;
138     GCond                    cond;  /* to signal removal of a queued text
139                                      * buffer, arrival of a text buffer,
140                                      * a text segment update, or a change
141                                      * in status (e.g. shutdown, flushing) */
142
143     /* stream metrics */
144     GstVideoInfo             info;
145     GstVideoFormat           format;
146     gint                     width;
147     gint                     height;
148
149     /* properties */
150     gint                     xpad;
151     gint                     ypad;
152     gint                     deltax;
153     gint                     deltay;
154     gdouble                  xpos;
155     gdouble                  ypos;
156     gchar                   *default_text;
157     gboolean                 want_shading;
158     gboolean                 silent;
159     gboolean                 wait_text;
160     guint                    color, outline_color;
161     PangoLayout             *layout;
162     gboolean                 auto_adjust_size;
163     gboolean                 draw_shadow;
164     gboolean                 draw_outline;
165     gint                     shading_value;  /* for timeoverlay subclass */
166     gboolean                 use_vertical_render;
167     GstBaseTextOverlayVAlign     valign;
168     GstBaseTextOverlayHAlign     halign;
169     GstBaseTextOverlayWrapMode   wrap_mode;
170     GstBaseTextOverlayLineAlign  line_align;
171
172     /* text pad format */
173     gboolean                 have_pango_markup;
174
175     /* rendering state */
176     gboolean                 need_render;
177     GstBuffer               *text_image;
178
179     /* dimension relative to witch the render is done, this is the stream size
180      * or a portion of the window_size (adapted to aspect ratio) */
181     gint                     render_width;
182     gint                     render_height;
183     /* This is (render_width / width) uses to convert to stream scale */
184     gdouble                  render_scale;
185
186     /* dimension of text_image, the physical dimension */
187     guint                    text_width;
188     guint                    text_height;
189
190     /* position of rendering in image coordinates */
191     gint                     text_x;
192     gint                     text_y;
193
194     /* window dimension, reported in the composition meta params. This is set
195      * to stream width, height if missing */
196     gint                     window_width;
197     gint                     window_height;
198
199     gdouble                  shadow_offset;
200     gdouble                  outline_offset;
201
202     PangoRectangle           ink_rect;
203     PangoRectangle           logical_rect;
204
205     gboolean                    attach_compo_to_buffer;
206     GstVideoOverlayComposition *composition;
207     GstVideoOverlayComposition *upstream_composition;
208 };
209
210 struct _GstBaseTextOverlayClass {
211     GstElementClass parent_class;
212
213     PangoContext *pango_context;
214     GMutex       *pango_lock;
215
216     gchar *     (*get_text) (GstBaseTextOverlay *overlay, GstBuffer *video_frame);
217 };
218
219 GType gst_base_text_overlay_get_type(void) G_GNUC_CONST;
220
221 G_END_DECLS
222
223 #endif /* __GST_BASE_TEXT_OVERLAY_H */