diff --git a/ChangeLog b/ChangeLog index 12aa24868c..a6ade5eaff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2008-10-08 Sebastian Dröge + + Patch by: Pavel Zeldin + + * ext/pango/gstclockoverlay.c: (gst_clock_overlay_render_time), + (gst_clock_overlay_class_init), (gst_clock_overlay_finalize), + (gst_clock_overlay_init), (gst_clock_overlay_set_property), + (gst_clock_overlay_get_property): + * ext/pango/gstclockoverlay.h: + API: Add ability to specify format for date/time display by + adding a "time-format" property. + Fixes bug #554879. + 2008-10-08 Sebastian Dröge Patch by: Jan Gerber diff --git a/ext/pango/gstclockoverlay.c b/ext/pango/gstclockoverlay.c index f558ec0487..4a1330fb97 100644 --- a/ext/pango/gstclockoverlay.c +++ b/ext/pango/gstclockoverlay.c @@ -50,6 +50,16 @@ #include #include + +#define DEFAULT_PROP_TIMEFORMAT "%H:%M:%S" + +enum +{ + PROP_0, + PROP_TIMEFORMAT, + PROP_LAST +}; + static const GstElementDetails clock_overlay_details = GST_ELEMENT_DETAILS ("Clock overlay", "Filter/Editor/Video", @@ -66,11 +76,19 @@ GST_BOILERPLATE (GstClockOverlay, gst_clock_overlay, GstTextOverlay, gst_element_class_set_details (element_class, &clock_overlay_details); } + +static void gst_clock_overlay_finalize (GObject * object); +static void gst_clock_overlay_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_clock_overlay_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); + static gchar * gst_clock_overlay_render_time (GstClockOverlay * overlay) { struct tm *t; time_t now; + gchar buf[256]; #ifdef HAVE_LOCALTIME_R struct tm dummy; @@ -88,7 +106,9 @@ gst_clock_overlay_render_time (GstClockOverlay * overlay) if (t == NULL) return g_strdup ("--:--:--"); - return g_strdup_printf ("%02u:%02u:%02u", t->tm_hour, t->tm_min, t->tm_sec); + if (strftime (buf, sizeof (buf), overlay->format, t) == 0) + return g_strdup (""); + return g_strdup (buf); } /* Called with lock held */ @@ -118,13 +138,37 @@ gst_clock_overlay_get_text (GstTextOverlay * overlay, GstBuffer * video_frame) static void gst_clock_overlay_class_init (GstClockOverlayClass * klass) { + GObjectClass *gobject_class; GstTextOverlayClass *gsttextoverlay_class; + gobject_class = (GObjectClass *) klass; gsttextoverlay_class = (GstTextOverlayClass *) klass; + gobject_class->finalize = gst_clock_overlay_finalize; + gobject_class->set_property = gst_clock_overlay_set_property; + gobject_class->get_property = gst_clock_overlay_get_property; + gsttextoverlay_class->get_text = gst_clock_overlay_get_text; + + g_object_class_install_property (gobject_class, PROP_TIMEFORMAT, + g_param_spec_string ("time-format", "Date/Time Format", + "Format to use for time and date value, as in strftime.", + DEFAULT_PROP_TIMEFORMAT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); } + +static void +gst_clock_overlay_finalize (GObject * object) +{ + GstClockOverlay *overlay = GST_CLOCK_OVERLAY (object); + + g_free (overlay->format); + overlay->format = NULL; + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + + static void gst_clock_overlay_init (GstClockOverlay * overlay, GstClockOverlayClass * klass) { @@ -151,4 +195,45 @@ gst_clock_overlay_init (GstClockOverlay * overlay, GstClockOverlayClass * klass) textoverlay->valign = GST_TEXT_OVERLAY_VALIGN_TOP; textoverlay->halign = GST_TEXT_OVERLAY_HALIGN_LEFT; + + overlay->format = g_strdup (DEFAULT_PROP_TIMEFORMAT); +} + + +static void +gst_clock_overlay_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + GstClockOverlay *overlay = GST_CLOCK_OVERLAY (object); + + GST_OBJECT_LOCK (overlay); + switch (prop_id) { + case PROP_TIMEFORMAT: + g_free (overlay->format); + overlay->format = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } + GST_OBJECT_UNLOCK (overlay); +} + + +static void +gst_clock_overlay_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) +{ + GstClockOverlay *overlay = GST_CLOCK_OVERLAY (object); + + GST_OBJECT_LOCK (overlay); + switch (prop_id) { + case PROP_TIMEFORMAT: + g_value_set_string (value, overlay->format); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } + GST_OBJECT_UNLOCK (overlay); } diff --git a/ext/pango/gstclockoverlay.h b/ext/pango/gstclockoverlay.h index 09b9bc49c1..74e32e362b 100644 --- a/ext/pango/gstclockoverlay.h +++ b/ext/pango/gstclockoverlay.h @@ -47,6 +47,7 @@ typedef struct _GstClockOverlayClass GstClockOverlayClass; */ struct _GstClockOverlay { GstTextOverlay textoverlay; + gchar *format; /* as in strftime () */ }; struct _GstClockOverlayClass {