1 /* GStreamer Editing Services
2 * Copyright (C) 2010 Brandon Lewis <brandon.lewis@collabora.co.uk>
3 * 2010 Nokia Corporation
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * SECTION:ges-track-text-overlay
23 * @short_description: render text onto another video stream in a
28 #include "ges-internal.h"
29 #include "ges-track-object.h"
30 #include "ges-track-title-source.h"
31 #include "ges-track-text-overlay.h"
33 G_DEFINE_TYPE (GESTrackTextOverlay, ges_track_text_overlay,
34 GES_TYPE_TRACK_OPERATION);
36 struct _GESTrackTextOverlayPrivate
53 static void ges_track_text_overlay_dispose (GObject * object);
55 static void ges_track_text_overlay_finalize (GObject * object);
57 static void ges_track_text_overlay_get_property (GObject * object, guint
58 property_id, GValue * value, GParamSpec * pspec);
60 static void ges_track_text_overlay_set_property (GObject * object, guint
61 property_id, const GValue * value, GParamSpec * pspec);
63 static GstElement *ges_track_text_overlay_create_element (GESTrackObject
67 ges_track_text_overlay_class_init (GESTrackTextOverlayClass * klass)
69 GObjectClass *object_class = G_OBJECT_CLASS (klass);
70 GESTrackObjectClass *bg_class = GES_TRACK_OBJECT_CLASS (klass);
72 g_type_class_add_private (klass, sizeof (GESTrackTextOverlayPrivate));
74 object_class->get_property = ges_track_text_overlay_get_property;
75 object_class->set_property = ges_track_text_overlay_set_property;
76 object_class->dispose = ges_track_text_overlay_dispose;
77 object_class->finalize = ges_track_text_overlay_finalize;
79 bg_class->create_element = ges_track_text_overlay_create_element;
83 ges_track_text_overlay_init (GESTrackTextOverlay * self)
85 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
86 GES_TYPE_TRACK_TEXT_OVERLAY, GESTrackTextOverlayPrivate);
88 self->priv->text = NULL;
89 self->priv->font_desc = NULL;
90 self->priv->text_el = NULL;
91 self->priv->halign = DEFAULT_HALIGNMENT;
92 self->priv->valign = DEFAULT_VALIGNMENT;
93 self->priv->color = G_MAXUINT32;
94 self->priv->xpos = 0.5;
95 self->priv->ypos = 0.5;
99 ges_track_text_overlay_dispose (GObject * object)
101 GESTrackTextOverlay *self = GES_TRACK_TEXT_OVERLAY (object);
102 if (self->priv->text) {
103 g_free (self->priv->text);
106 if (self->priv->font_desc) {
107 g_free (self->priv->font_desc);
110 if (self->priv->text_el) {
111 g_object_unref (self->priv->text_el);
112 self->priv->text_el = NULL;
115 G_OBJECT_CLASS (ges_track_text_overlay_parent_class)->dispose (object);
119 ges_track_text_overlay_finalize (GObject * object)
121 G_OBJECT_CLASS (ges_track_text_overlay_parent_class)->finalize (object);
125 ges_track_text_overlay_get_property (GObject * object,
126 guint property_id, GValue * value, GParamSpec * pspec)
128 switch (property_id) {
130 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
135 ges_track_text_overlay_set_property (GObject * object,
136 guint property_id, const GValue * value, GParamSpec * pspec)
138 switch (property_id) {
140 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
145 ges_track_text_overlay_create_element (GESTrackObject * object)
147 GstElement *ret, *text, *iconv, *oconv;
148 GstPad *src_target, *sink_target;
150 GESTrackTextOverlay *self = GES_TRACK_TEXT_OVERLAY (object);
152 text = gst_element_factory_make ("textoverlay", NULL);
153 iconv = gst_element_factory_make ("ffmpegcolorspace", NULL);
154 oconv = gst_element_factory_make ("ffmpegcolorspace", NULL);
155 self->priv->text_el = text;
158 if (self->priv->text)
159 g_object_set (text, "text", (gchar *) self->priv->text, NULL);
160 if (self->priv->font_desc)
161 g_object_set (text, "font-desc", (gchar *) self->priv->font_desc, NULL);
163 g_object_set (text, "halignment", (gint) self->priv->halign, "valignment",
164 (gint) self->priv->valign, NULL);
165 g_object_set (text, "color", (guint32) self->priv->color, NULL);
166 g_object_set (text, "xpos", (gdouble) self->priv->xpos, NULL);
167 g_object_set (text, "ypos", (gdouble) self->priv->ypos, NULL);
169 ret = gst_bin_new ("overlay-bin");
170 gst_bin_add_many (GST_BIN (ret), text, iconv, oconv, NULL);
171 gst_element_link_many (iconv, text, oconv, NULL);
173 src_target = gst_element_get_static_pad (oconv, "src");
174 sink_target = gst_element_get_static_pad (iconv, "sink");
176 src = gst_ghost_pad_new ("src", src_target);
177 sink = gst_ghost_pad_new ("video_sink", sink_target);
178 g_object_unref (src_target);
179 g_object_unref (sink_target);
181 gst_element_add_pad (ret, src);
182 gst_element_add_pad (ret, sink);
188 * ges_track_text_overlay_set_text:
189 * @self: the #GESTrackTextOverlay* to set text on
190 * @text: the text to render. an internal copy of this text will be
193 * Sets the text this track object will render.
197 ges_track_text_overlay_set_text (GESTrackTextOverlay * self, const gchar * text)
199 GST_DEBUG ("self:%p, text:%s", self, text);
201 if (self->priv->text)
202 g_free (self->priv->text);
204 self->priv->text = g_strdup (text);
205 if (self->priv->text_el)
206 g_object_set (self->priv->text_el, "text", text, NULL);
210 * ges_track_text_overlay_set_font_desc:
211 * @self: the #GESTrackTextOverlay
212 * @font_desc: the pango font description
214 * Sets the pango font description of the text this track object
219 ges_track_text_overlay_set_font_desc (GESTrackTextOverlay * self,
220 const gchar * font_desc)
222 GST_DEBUG ("self:%p, font_desc:%s", self, font_desc);
224 if (self->priv->font_desc)
225 g_free (self->priv->font_desc);
227 self->priv->font_desc = g_strdup (font_desc);
228 GST_LOG ("setting font-desc to '%s'", font_desc);
229 if (self->priv->text_el)
230 g_object_set (self->priv->text_el, "font-desc", font_desc, NULL);
234 * ges_track_text_overlay_set_valignment:
235 * @self: the #GESTrackTextOverlay* to set text on
236 * @valign: The #GESTextVAlign defining the vertical alignment
237 * of the text render by @self.
239 * Sets the vertical aligment of the text.
243 ges_track_text_overlay_set_valignment (GESTrackTextOverlay * self,
244 GESTextVAlign valign)
246 GST_DEBUG ("self:%p, halign:%d", self, valign);
248 self->priv->valign = valign;
249 if (self->priv->text_el)
250 g_object_set (self->priv->text_el, "valignment", valign, NULL);
254 * ges_track_text_overlay_set_halignment:
255 * @self: the #GESTrackTextOverlay* to set text on
256 * @halign: The #GESTextHAlign defining the horizontal alignment
257 * of the text render by @self.
259 * Sets the horizontal aligment of the text.
263 ges_track_text_overlay_set_halignment (GESTrackTextOverlay * self,
264 GESTextHAlign halign)
266 GST_DEBUG ("self:%p, halign:%d", self, halign);
268 self->priv->halign = halign;
269 if (self->priv->text_el)
270 g_object_set (self->priv->text_el, "halignment", halign, NULL);
274 * ges_track_text_overlay_set_color:
275 * @self: the #GESTrackTextOverlay* to set
276 * @color: The color @self is being set to
278 * Sets the color of the text.
283 ges_track_text_overlay_set_color (GESTrackTextOverlay * self, guint32 color)
285 GST_DEBUG ("self:%p, color:%d", self, color);
287 self->priv->color = color;
288 if (self->priv->text_el)
289 g_object_set (self->priv->text_el, "color", color, NULL);
293 * ges_track_text_overlay_set_xpos:
294 * @self: the #GESTrackTextOverlay* to set
295 * @position: The horizontal position @self is being set to
297 * Sets the horizontal position of the text.
302 ges_track_text_overlay_set_xpos (GESTrackTextOverlay * self, gdouble position)
304 GST_DEBUG ("self:%p, xpos:%f", self, position);
306 self->priv->xpos = position;
307 if (self->priv->text_el)
308 g_object_set (self->priv->text_el, "xpos", position, NULL);
312 * ges_track_text_overlay_set_ypos:
313 * @self: the #GESTrackTextOverlay* to set
314 * @position: The vertical position @self is being set to
316 * Sets the vertical position of the text.
321 ges_track_text_overlay_set_ypos (GESTrackTextOverlay * self, gdouble position)
323 GST_DEBUG ("self:%p, ypos:%f", self, position);
325 self->priv->ypos = position;
326 if (self->priv->text_el)
327 g_object_set (self->priv->text_el, "ypos", position, NULL);
331 * ges_track_text_overlay_get_text:
332 * @self: a GESTrackTextOverlay
334 * Get the text currently set on @source.
336 * Returns: The text currently set on @source.
339 ges_track_text_overlay_get_text (GESTrackTextOverlay * self)
341 return self->priv->text;
345 * ges_track_text_overlay_get_font_desc:
346 * @self: a GESTrackTextOverlay
348 * Get the pango font description currently set on @source.
350 * Returns: The pango font description currently set on @source.
353 ges_track_text_overlay_get_font_desc (GESTrackTextOverlay * self)
355 return self->priv->font_desc;
359 * ges_track_text_overlay_get_halignment:
360 * @self: a GESTrackTextOverlay
362 * Get the horizontal aligment used by @source.
364 * Returns: The horizontal aligment used by @source.
367 ges_track_text_overlay_get_halignment (GESTrackTextOverlay * self)
369 return self->priv->halign;
373 * ges_track_text_overlay_get_valignment:
374 * @self: a GESTrackTextOverlay
376 * Get the vertical aligment used by @source.
378 * Returns: The vertical aligment used by @source.
381 ges_track_text_overlay_get_valignment (GESTrackTextOverlay * self)
383 return self->priv->valign;
387 * ges_track_text_overlay_get_color:
388 * @self: a GESTrackTextOverlay
390 * Get the color used by @source.
392 * Returns: The color used by @source.
397 ges_track_text_overlay_get_color (GESTrackTextOverlay * self)
399 return self->priv->color;
403 * ges_track_text_overlay_get_xpos:
404 * @self: a GESTrackTextOverlay
406 * Get the horizontal position used by @source.
408 * Returns: The horizontal position used by @source.
413 ges_track_text_overlay_get_xpos (GESTrackTextOverlay * self)
415 return self->priv->xpos;
419 * ges_track_text_overlay_get_ypos:
420 * @self: a GESTrackTextOverlay
422 * Get the vertical position used by @source.
424 * Returns: The vertical position used by @source.
429 ges_track_text_overlay_get_ypos (GESTrackTextOverlay * self)
431 return self->priv->ypos;
435 * ges_track_text_overlay_new:
437 * Creates a new #GESTrackTextOverlay.
439 * Returns: The newly created #GESTrackTextOverlay or %NULL if something went
442 GESTrackTextOverlay *
443 ges_track_text_overlay_new (void)
445 return g_object_new (GES_TYPE_TRACK_TEXT_OVERLAY, NULL);