2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2003> David Schleef <ds@schleef.org>
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 * This file was (probably) generated from gsttimeoverlay.c,
23 * gsttimeoverlay.c,v 1.7 2003/11/08 02:48:59 dschleef Exp
30 /*#define DEBUG_ENABLED */
31 #include <gsttimeoverlay.h>
38 /* GstTimeoverlay signals and args */
51 static void gst_timeoverlay_base_init (gpointer g_class);
52 static void gst_timeoverlay_class_init (gpointer g_class, gpointer class_data);
53 static void gst_timeoverlay_init (GTypeInstance * instance, gpointer g_class);
55 static void gst_timeoverlay_set_property (GObject * object, guint prop_id,
56 const GValue * value, GParamSpec * pspec);
57 static void gst_timeoverlay_get_property (GObject * object, guint prop_id,
58 GValue * value, GParamSpec * pspec);
60 static void gst_timeoverlay_planar411 (GstVideofilter * videofilter, void *dest,
62 static void gst_timeoverlay_setup (GstVideofilter * videofilter);
65 gst_timeoverlay_get_type (void)
67 static GType timeoverlay_type = 0;
69 if (!timeoverlay_type) {
70 static const GTypeInfo timeoverlay_info = {
71 sizeof (GstTimeoverlayClass),
72 gst_timeoverlay_base_init,
74 gst_timeoverlay_class_init,
77 sizeof (GstTimeoverlay),
82 timeoverlay_type = g_type_register_static (GST_TYPE_VIDEOFILTER,
83 "GstTimeoverlay", &timeoverlay_info, 0);
85 return timeoverlay_type;
88 static GstVideofilterFormat gst_timeoverlay_formats[] = {
89 {"I420", 12, gst_timeoverlay_planar411,},
94 gst_timeoverlay_base_init (gpointer g_class)
96 static GstElementDetails timeoverlay_details =
97 GST_ELEMENT_DETAILS ("Time Overlay",
98 "Filter/Editor/Video",
99 "Overlays the time on a video stream",
100 "David Schleef <ds@schleef.org>");
101 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
102 GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
105 gst_element_class_set_details (element_class, &timeoverlay_details);
107 for (i = 0; i < G_N_ELEMENTS (gst_timeoverlay_formats); i++) {
108 gst_videofilter_class_add_format (videofilter_class,
109 gst_timeoverlay_formats + i);
112 gst_videofilter_class_add_pad_templates (GST_VIDEOFILTER_CLASS (g_class));
116 gst_timeoverlay_class_init (gpointer g_class, gpointer class_data)
118 GObjectClass *gobject_class;
119 GstVideofilterClass *videofilter_class;
121 gobject_class = G_OBJECT_CLASS (g_class);
122 videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
125 g_object_class_install_property (gobject_class, ARG_METHOD,
126 g_param_spec_enum ("method", "method", "method",
127 GST_TYPE_TIMEOVERLAY_METHOD, GST_TIMEOVERLAY_METHOD_1,
131 gobject_class->set_property = gst_timeoverlay_set_property;
132 gobject_class->get_property = gst_timeoverlay_get_property;
134 videofilter_class->setup = gst_timeoverlay_setup;
138 gst_timeoverlay_init (GTypeInstance * instance, gpointer g_class)
140 GstTimeoverlay *timeoverlay = GST_TIMEOVERLAY (instance);
141 GstVideofilter *videofilter;
143 GST_DEBUG ("gst_timeoverlay_init");
145 videofilter = GST_VIDEOFILTER (timeoverlay);
151 gst_timeoverlay_set_property (GObject * object, guint prop_id,
152 const GValue * value, GParamSpec * pspec)
156 g_return_if_fail (GST_IS_TIMEOVERLAY (object));
157 src = GST_TIMEOVERLAY (object);
159 GST_DEBUG ("gst_timeoverlay_set_property");
163 src->method = g_value_get_enum (value);
172 gst_timeoverlay_get_property (GObject * object, guint prop_id, GValue * value,
177 g_return_if_fail (GST_IS_TIMEOVERLAY (object));
178 src = GST_TIMEOVERLAY (object);
183 g_value_set_enum (value, src->method);
187 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
193 gst_timeoverlay_setup (GstVideofilter * videofilter)
195 GstTimeoverlay *timeoverlay;
196 cairo_font_extents_t font_extents;
198 g_return_if_fail (GST_IS_TIMEOVERLAY (videofilter));
199 timeoverlay = GST_TIMEOVERLAY (videofilter);
201 /* if any setup needs to be done, do it here */
203 timeoverlay->cr = cairo_create ();
205 cairo_set_rgb_color (timeoverlay->cr, 0, 0, 0);
207 cairo_select_font (timeoverlay->cr, "monospace", 0, 0);
208 cairo_scale_font (timeoverlay->cr, 20);
210 cairo_current_font_extents (timeoverlay->cr, &font_extents);
211 timeoverlay->text_height = font_extents.height;
216 gst_timeoverlay_print_smpte_time (guint64 time)
224 x = rint ((time + 500000) * 1e-6);
226 hours = floor (x / (60 * 60 * 1000));
227 x -= hours * 60 * 60 * 1000;
228 minutes = floor (x / (60 * 1000));
229 x -= minutes * 60 * 1000;
230 seconds = floor (x / (1000));
234 return g_strdup_printf ("%02d:%02d:%02d.%03d", hours, minutes, seconds, ms);
238 gst_timeoverlay_planar411 (GstVideofilter * videofilter, void *dest, void *src)
240 GstTimeoverlay *timeoverlay;
247 cairo_text_extents_t extents;
249 g_return_if_fail (GST_IS_TIMEOVERLAY (videofilter));
250 timeoverlay = GST_TIMEOVERLAY (videofilter);
252 width = gst_videofilter_get_input_width (videofilter);
253 height = gst_videofilter_get_input_height (videofilter);
256 gst_timeoverlay_print_smpte_time (GST_BUFFER_TIMESTAMP (videofilter->
259 image = g_malloc (4 * width * timeoverlay->text_height);
261 cairo_set_target_image (timeoverlay->cr, image, CAIRO_FORMAT_ARGB32,
262 width, timeoverlay->text_height, width * 4);
264 cairo_save (timeoverlay->cr);
265 cairo_rectangle (timeoverlay->cr, 0, 0, width, timeoverlay->text_height);
266 cairo_set_alpha (timeoverlay->cr, 0);
267 cairo_set_operator (timeoverlay->cr, CAIRO_OPERATOR_SRC);
268 cairo_fill (timeoverlay->cr);
269 cairo_restore (timeoverlay->cr);
271 cairo_save (timeoverlay->cr);
272 cairo_text_extents (timeoverlay->cr, string, &extents);
274 cairo_set_rgb_color (timeoverlay->cr, 1, 1, 1);
275 cairo_move_to (timeoverlay->cr, 0, timeoverlay->text_height - 2);
276 cairo_show_text (timeoverlay->cr, string);
279 cairo_text_path (timeoverlay->cr, string);
280 cairo_set_rgb_color (timeoverlay->cr, 1, 1, 1);
281 cairo_set_line_width (timeoverlay->cr, 1.0);
282 cairo_stroke (timeoverlay->cr);
285 cairo_restore (timeoverlay->cr);
287 b_width = extents.width;
291 memcpy (dest, src, videofilter->from_buf_size);
292 for (i = 0; i < timeoverlay->text_height; i++) {
293 for (j = 0; j < b_width; j++) {
294 ((uint8_t *) dest)[i * width + j] = image[(i * width + j) * 4 + 0];
297 for (i = 0; i < timeoverlay->text_height / 2; i++) {
298 memset (dest + width * height + i * (width / 2), 128, b_width / 2);
299 memset (dest + width * height + (width / 2) * (height / 2) +
300 i * (width / 2), 128, b_width / 2);