2003-07-02 08:07:24 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* Copyright (C) <2003> David Schleef <ds@schleef.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* portions derived from:
|
|
|
|
* Pango
|
|
|
|
* pangoft2topgm.c: Example program to view a UTF-8 encoding file
|
|
|
|
* using Pango to render result.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 Red Hat Software
|
|
|
|
* Copyright (C) 2001 Sun Microsystems
|
|
|
|
*/
|
|
|
|
|
2003-11-10 18:42:32 +00:00
|
|
|
/*
|
|
|
|
* This file was (probably) generated from gsttimeoverlay.c,
|
|
|
|
* gsttimeoverlay.c,v 1.7 2003/11/08 02:48:59 dschleef Exp
|
|
|
|
*/
|
|
|
|
|
2003-11-07 12:47:01 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2003-07-02 08:07:24 +00:00
|
|
|
|
|
|
|
/*#define DEBUG_ENABLED */
|
|
|
|
#include <gsttimeoverlay.h>
|
2003-11-10 18:42:32 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
2003-07-02 08:07:24 +00:00
|
|
|
#include <pango/pango.h>
|
|
|
|
#include <pango/pangoft2.h>
|
|
|
|
|
|
|
|
|
|
|
|
/* GstTimeoverlay signals and args */
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2003-07-02 08:07:24 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2003-07-02 08:07:24 +00:00
|
|
|
ARG_0,
|
|
|
|
/* FILL ME */
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_timeoverlay_base_init (gpointer g_class);
|
|
|
|
static void gst_timeoverlay_class_init (gpointer g_class, gpointer class_data);
|
|
|
|
static void gst_timeoverlay_init (GTypeInstance * instance, gpointer g_class);
|
2003-07-02 08:07:24 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_timeoverlay_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_timeoverlay_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
2003-07-02 08:07:24 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_timeoverlay_planar411 (GstVideofilter * videofilter, void *dest,
|
|
|
|
void *src);
|
|
|
|
static void gst_timeoverlay_setup (GstVideofilter * videofilter);
|
2003-07-02 08:07:24 +00:00
|
|
|
|
|
|
|
GType
|
|
|
|
gst_timeoverlay_get_type (void)
|
|
|
|
{
|
|
|
|
static GType timeoverlay_type = 0;
|
|
|
|
|
|
|
|
if (!timeoverlay_type) {
|
|
|
|
static const GTypeInfo timeoverlay_info = {
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstTimeoverlayClass),
|
2003-11-02 01:21:38 +00:00
|
|
|
gst_timeoverlay_base_init,
|
2003-07-02 08:07:24 +00:00
|
|
|
NULL,
|
2003-11-10 18:42:32 +00:00
|
|
|
gst_timeoverlay_class_init,
|
2003-07-02 08:07:24 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstTimeoverlay),
|
2003-07-02 08:07:24 +00:00
|
|
|
0,
|
2003-11-10 18:42:32 +00:00
|
|
|
gst_timeoverlay_init,
|
2003-07-02 08:07:24 +00:00
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
timeoverlay_type = g_type_register_static (GST_TYPE_VIDEOFILTER,
|
2004-03-15 19:32:27 +00:00
|
|
|
"GstTimeoverlay", &timeoverlay_info, 0);
|
2003-07-02 08:07:24 +00:00
|
|
|
}
|
|
|
|
return timeoverlay_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstVideofilterFormat gst_timeoverlay_formats[] = {
|
2004-03-14 22:34:33 +00:00
|
|
|
{"I420", 12, gst_timeoverlay_planar411,},
|
2003-07-02 08:07:24 +00:00
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-11-02 01:21:38 +00:00
|
|
|
static void
|
|
|
|
gst_timeoverlay_base_init (gpointer g_class)
|
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstElementDetails timeoverlay_details =
|
|
|
|
GST_ELEMENT_DETAILS ("Time Overlay",
|
|
|
|
"Filter/Editor/Video",
|
|
|
|
"Overlays the time on a video stream",
|
|
|
|
"David Schleef <ds@schleef.org>");
|
2003-11-02 01:21:38 +00:00
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
2003-11-10 18:42:32 +00:00
|
|
|
GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
|
|
|
|
int i;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-11-02 01:21:38 +00:00
|
|
|
gst_element_class_set_details (element_class, &timeoverlay_details);
|
2003-11-09 15:44:25 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (gst_timeoverlay_formats); i++) {
|
|
|
|
gst_videofilter_class_add_format (videofilter_class,
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_timeoverlay_formats + i);
|
2003-11-10 18:42:32 +00:00
|
|
|
}
|
|
|
|
|
2003-11-09 15:44:25 +00:00
|
|
|
gst_videofilter_class_add_pad_templates (GST_VIDEOFILTER_CLASS (g_class));
|
2003-11-02 01:21:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-11-10 18:42:32 +00:00
|
|
|
gst_timeoverlay_class_init (gpointer g_class, gpointer class_data)
|
2003-11-02 01:21:38 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2003-11-10 18:42:32 +00:00
|
|
|
GstVideofilterClass *videofilter_class;
|
2003-11-02 01:21:38 +00:00
|
|
|
|
2003-11-10 18:42:32 +00:00
|
|
|
gobject_class = G_OBJECT_CLASS (g_class);
|
|
|
|
videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
|
2003-11-02 01:21:38 +00:00
|
|
|
|
|
|
|
#if 0
|
2004-03-14 22:34:33 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_METHOD,
|
|
|
|
g_param_spec_enum ("method", "method", "method",
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_TYPE_TIMEOVERLAY_METHOD, GST_TIMEOVERLAY_METHOD_1,
|
|
|
|
G_PARAM_READWRITE));
|
2003-11-02 01:21:38 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
gobject_class->set_property = gst_timeoverlay_set_property;
|
|
|
|
gobject_class->get_property = gst_timeoverlay_get_property;
|
|
|
|
|
2003-11-10 18:42:32 +00:00
|
|
|
videofilter_class->setup = gst_timeoverlay_setup;
|
2003-11-02 01:21:38 +00:00
|
|
|
}
|
|
|
|
|
2003-07-02 08:07:24 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_timeoverlay_init (GTypeInstance * instance, gpointer g_class)
|
2003-07-02 08:07:24 +00:00
|
|
|
{
|
2003-11-10 18:42:32 +00:00
|
|
|
GstTimeoverlay *timeoverlay = GST_TIMEOVERLAY (instance);
|
2003-07-02 08:07:24 +00:00
|
|
|
GstVideofilter *videofilter;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("gst_timeoverlay_init");
|
2003-07-02 08:07:24 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
videofilter = GST_VIDEOFILTER (timeoverlay);
|
2003-07-02 08:07:24 +00:00
|
|
|
|
2003-11-10 18:42:32 +00:00
|
|
|
/* do stuff */
|
2003-07-02 08:07:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_timeoverlay_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2003-07-02 08:07:24 +00:00
|
|
|
{
|
|
|
|
GstTimeoverlay *src;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2004-03-14 22:34:33 +00:00
|
|
|
g_return_if_fail (GST_IS_TIMEOVERLAY (object));
|
|
|
|
src = GST_TIMEOVERLAY (object);
|
2003-07-02 08:07:24 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("gst_timeoverlay_set_property");
|
2003-07-02 08:07:24 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
#if 0
|
|
|
|
case ARG_METHOD:
|
|
|
|
src->method = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_timeoverlay_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2003-07-02 08:07:24 +00:00
|
|
|
{
|
|
|
|
GstTimeoverlay *src;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2004-03-14 22:34:33 +00:00
|
|
|
g_return_if_fail (GST_IS_TIMEOVERLAY (object));
|
|
|
|
src = GST_TIMEOVERLAY (object);
|
2003-07-02 08:07:24 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
#if 0
|
|
|
|
case ARG_METHOD:
|
|
|
|
g_value_set_enum (value, src->method);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static gboolean
|
|
|
|
plugin_init (GstPlugin * plugin)
|
2003-07-02 08:07:24 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!gst_library_load ("gstvideofilter"))
|
2003-07-02 08:07:24 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2003-11-10 18:42:32 +00:00
|
|
|
return gst_element_register (plugin, "timeoverlay", GST_RANK_NONE,
|
|
|
|
GST_TYPE_TIMEOVERLAY);
|
2003-07-02 08:07:24 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"timeoverlay",
|
|
|
|
"Time overlay", plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN)
|
|
|
|
|
|
|
|
static void gst_timeoverlay_setup (GstVideofilter * videofilter)
|
2003-07-02 08:07:24 +00:00
|
|
|
{
|
|
|
|
GstTimeoverlay *timeoverlay;
|
|
|
|
PangoFontDescription *font_description;
|
|
|
|
PangoContext *context;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
g_return_if_fail (GST_IS_TIMEOVERLAY (videofilter));
|
|
|
|
timeoverlay = GST_TIMEOVERLAY (videofilter);
|
2003-07-02 08:07:24 +00:00
|
|
|
|
|
|
|
/* if any setup needs to be done, do it here */
|
|
|
|
|
|
|
|
/* what does this affect? */
|
|
|
|
context = pango_ft2_get_context (100, 100);
|
|
|
|
|
|
|
|
pango_context_set_language (context, pango_language_from_string ("en_US"));
|
|
|
|
pango_context_set_base_dir (context, PANGO_DIRECTION_LTR);
|
|
|
|
|
|
|
|
font_description = pango_font_description_new ();
|
|
|
|
pango_font_description_set_family (font_description, g_strdup ("Monospace"));
|
|
|
|
pango_font_description_set_style (font_description, PANGO_STYLE_NORMAL);
|
|
|
|
pango_font_description_set_variant (font_description, PANGO_VARIANT_NORMAL);
|
|
|
|
pango_font_description_set_weight (font_description, PANGO_WEIGHT_NORMAL);
|
|
|
|
pango_font_description_set_stretch (font_description, PANGO_STRETCH_NORMAL);
|
|
|
|
pango_font_description_set_size (font_description, 12 * PANGO_SCALE);
|
|
|
|
|
|
|
|
pango_context_set_font_description (context, font_description);
|
|
|
|
|
|
|
|
timeoverlay->context = context;
|
|
|
|
timeoverlay->font_description = font_description;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static char *
|
|
|
|
gst_timeoverlay_print_smpte_time (guint64 time)
|
2003-07-02 08:07:24 +00:00
|
|
|
{
|
|
|
|
int hours;
|
|
|
|
int minutes;
|
|
|
|
int seconds;
|
|
|
|
int ms;
|
|
|
|
double x;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
x = rint ((time + 500000) * 1e-6);
|
2003-07-02 08:07:24 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
hours = floor (x / (60 * 60 * 1000));
|
|
|
|
x -= hours * 60 * 60 * 1000;
|
|
|
|
minutes = floor (x / (60 * 1000));
|
|
|
|
x -= minutes * 60 * 1000;
|
|
|
|
seconds = floor (x / (1000));
|
|
|
|
x -= seconds * 1000;
|
|
|
|
ms = rint (x);
|
2003-07-02 08:07:24 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
return g_strdup_printf ("%02d:%02d:%02d.%03d", hours, minutes, seconds, ms);
|
2003-07-02 08:07:24 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
|
|
|
gst_timeoverlay_planar411 (GstVideofilter * videofilter, void *dest, void *src)
|
2003-07-02 08:07:24 +00:00
|
|
|
{
|
|
|
|
GstTimeoverlay *timeoverlay;
|
|
|
|
int width;
|
2003-11-10 18:42:32 +00:00
|
|
|
int height;
|
2003-07-02 08:07:24 +00:00
|
|
|
PangoRectangle logical_rect;
|
|
|
|
PangoLayout *layout;
|
|
|
|
int b_height, b_width;
|
|
|
|
FT_Bitmap bitmap;
|
|
|
|
char *string;
|
|
|
|
int i;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
g_return_if_fail (GST_IS_TIMEOVERLAY (videofilter));
|
|
|
|
timeoverlay = GST_TIMEOVERLAY (videofilter);
|
2003-07-02 08:07:24 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
width = gst_videofilter_get_input_width (videofilter);
|
|
|
|
height = gst_videofilter_get_input_height (videofilter);
|
2003-07-02 08:07:24 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
width = gst_videofilter_get_input_width (videofilter);
|
|
|
|
height = gst_videofilter_get_input_height (videofilter);
|
2003-11-10 18:42:32 +00:00
|
|
|
|
2003-07-02 08:07:24 +00:00
|
|
|
layout = pango_layout_new (timeoverlay->context);
|
2004-03-14 22:34:33 +00:00
|
|
|
string =
|
|
|
|
gst_timeoverlay_print_smpte_time (GST_BUFFER_TIMESTAMP (videofilter->
|
2004-03-15 19:32:27 +00:00
|
|
|
in_buf));
|
2004-03-14 22:34:33 +00:00
|
|
|
pango_layout_set_text (layout, string, strlen (string));
|
|
|
|
g_free (string);
|
2003-07-02 08:07:24 +00:00
|
|
|
|
|
|
|
pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
|
|
|
|
pango_layout_set_width (layout, -1);
|
|
|
|
|
|
|
|
pango_layout_get_extents (layout, NULL, &logical_rect);
|
|
|
|
b_height = PANGO_PIXELS (logical_rect.height);
|
|
|
|
b_width = PANGO_PIXELS (logical_rect.width);
|
|
|
|
|
|
|
|
//hheight = 20;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
memcpy (dest, src, videofilter->from_buf_size);
|
2003-07-02 08:07:24 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
for (i = 0; i < b_height; i++) {
|
|
|
|
memset (dest + i * width, 0, b_width);
|
2003-07-02 08:07:24 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
for (i = 0; i < b_height / 2; i++) {
|
|
|
|
memset (dest + width * height + i * (width / 2), 128, b_width / 2);
|
|
|
|
memset (dest + width * height + (width / 2) * (height / 2) +
|
2004-03-15 19:32:27 +00:00
|
|
|
i * (width / 2), 128, b_width / 2);
|
2003-07-02 08:07:24 +00:00
|
|
|
}
|
|
|
|
bitmap.rows = b_height;
|
|
|
|
bitmap.width = b_width;
|
|
|
|
bitmap.pitch = width;
|
|
|
|
bitmap.buffer = dest;
|
|
|
|
bitmap.num_grays = 256;
|
|
|
|
bitmap.pixel_mode = ft_pixel_mode_grays;
|
|
|
|
|
|
|
|
pango_ft2_render_layout (&bitmap, layout, 0, 0);
|
|
|
|
}
|