mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-21 07:46:38 +00:00
e972defd3e
Original commit message from CVS: * ext/alsa/gstalsamixerelement.c: * ext/alsa/gstalsasrc.c: * ext/cdparanoia/gstcdparanoiasrc.c: * ext/gnomevfs/gstgnomevfssink.c: * ext/gnomevfs/gstgnomevfssrc.c: * ext/ogg/gstoggdemux.c: * ext/ogg/gstoggmux.c: * ext/ogg/gstoggparse.c: * ext/ogg/gstogmparse.c: * ext/pango/gstclockoverlay.c: * ext/pango/gsttextoverlay.c: * ext/pango/gsttextrender.c: * ext/pango/gsttimeoverlay.c: * ext/theora/theoradec.c: * ext/theora/theoraenc.c: * ext/vorbis/vorbisdec.c: * ext/vorbis/vorbisenc.c: * gst-libs/gst/audio/gstaudiofilter.c: * gst-libs/gst/audio/gstaudiofiltertemplate.c: * gst/audioconvert/gstaudioconvert.c: * gst/audiorate/gstaudiorate.c: * gst/audioresample/gstaudioresample.c: * gst/audiotestsrc/gstaudiotestsrc.c: * gst/ffmpegcolorspace/gstffmpegcolorspace.c: * gst/playback/gstdecodebin.c: * gst/playback/gstplaybin.c: * gst/playback/gststreamselector.c: * gst/subparse/gstsubparse.c: * gst/tcp/gstmultifdsink.c: * gst/tcp/gsttcpclientsink.c: * gst/tcp/gsttcpclientsrc.c: * gst/tcp/gsttcpserversink.c: * gst/tcp/gsttcpserversrc.c: * gst/typefind/gsttypefindfunctions.c: (plugin_init): * gst/videorate/gstvideorate.c: * gst/videoscale/gstvideoscale.c: * gst/videotestsrc/gstvideotestsrc.c: * gst/volume/gstvolume.c: * sys/v4l/gstv4ljpegsrc.c: * sys/v4l/gstv4lmjpegsink.c: * sys/v4l/gstv4lmjpegsrc.c: * sys/v4l/gstv4lsrc.c: * sys/ximage/ximagesink.c: * sys/xvimage/xvimagesink.c: * tests/check/libs/cddabasesrc.c: make GstElementDetails const
160 lines
5.2 KiB
C
160 lines
5.2 KiB
C
/* GStreamer
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
* Copyright (C) <2005> Tim-Philipp Müller <tim@centricular.net>
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
/**
|
|
* SECTION:element-timeoverlay
|
|
* @see_also: #GstTextOverlay, #GstClockOverlay
|
|
*
|
|
* <refsect2>
|
|
* <para>
|
|
* This element overlays the buffer time stamps of a video stream on
|
|
* top of itself. You can position the text and configure the font details
|
|
* using the properties of the #GstTextOverlay class. By default, the
|
|
* time stamp is displayed in the top left corner of the picture, with some
|
|
* padding to the left and to the top.
|
|
* </para>
|
|
* <para>
|
|
* Here is a simple pipeline that displays the time stamps in the top left
|
|
* corner of the video picture:
|
|
* <programlisting>
|
|
* gst-launch -v videotestsrc ! timeoverlay ! xvimagesink
|
|
* </programlisting>
|
|
* </para>
|
|
* <para>
|
|
* Here is another pipeline that displays the time stamps with some leading
|
|
* text in the bottom right corner of the video picture, with the background
|
|
* of the text being shaded in order to make it more legible on top of a
|
|
* bright video background:
|
|
* <programlisting>
|
|
* gst-launch -v videotestsrc ! timeoverlay halign=right valign=bottom text="Stream time:" shaded-background=true ! xvimagesink
|
|
* </programlisting>
|
|
* </para>
|
|
* </refsect2>
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
|
|
#include <gst/video/video.h>
|
|
|
|
#include <gsttimeoverlay.h>
|
|
|
|
static const GstElementDetails time_overlay_details =
|
|
GST_ELEMENT_DETAILS ("Time overlay",
|
|
"Filter/Editor/Video",
|
|
"Overlays buffer time stamps on a video stream",
|
|
"Tim-Philipp Müller <tim@centricular.net>");
|
|
|
|
GST_BOILERPLATE (GstTimeOverlay, gst_time_overlay, GstTextOverlay,
|
|
GST_TYPE_TEXT_OVERLAY)
|
|
|
|
static void gst_time_overlay_base_init (gpointer g_class)
|
|
{
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
gst_element_class_set_details (element_class, &time_overlay_details);
|
|
}
|
|
|
|
static gchar *
|
|
gst_time_overlay_render_time (GstTimeOverlay * overlay, GstClockTime time)
|
|
{
|
|
guint hours, mins, secs, msecs;
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (time))
|
|
return g_strdup ("");
|
|
|
|
hours = (guint) (time / (GST_SECOND * 60 * 60));
|
|
mins = (guint) ((time / (GST_SECOND * 60)) % 60);
|
|
secs = (guint) ((time / GST_SECOND) % 60);
|
|
msecs = (guint) ((time % GST_SECOND) / (1000 * 1000));
|
|
|
|
return g_strdup_printf ("%u:%02u:%02u.%03u", hours, mins, secs, msecs);
|
|
}
|
|
|
|
/* Called with lock held */
|
|
static gchar *
|
|
gst_time_overlay_get_text (GstTextOverlay * overlay, GstBuffer * video_frame)
|
|
{
|
|
GstClockTime time = GST_BUFFER_TIMESTAMP (video_frame);
|
|
gchar *time_str, *txt, *ret;
|
|
|
|
overlay->need_render = TRUE;
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (time)) {
|
|
GST_DEBUG ("buffer without valid timestamp");
|
|
return g_strdup ("");
|
|
}
|
|
|
|
GST_DEBUG ("buffer with timestamp %" GST_TIME_FORMAT, GST_TIME_ARGS (time));
|
|
|
|
txt = g_strdup (overlay->default_text);
|
|
|
|
time_str = gst_time_overlay_render_time (GST_TIME_OVERLAY (overlay), time);
|
|
if (txt != NULL && *txt != '\0') {
|
|
ret = g_strdup_printf ("%s %s", txt, time_str);
|
|
} else {
|
|
ret = time_str;
|
|
time_str = NULL;
|
|
}
|
|
|
|
g_free (txt);
|
|
g_free (time_str);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static void
|
|
gst_time_overlay_class_init (GstTimeOverlayClass * klass)
|
|
{
|
|
GstTextOverlayClass *gsttextoverlay_class;
|
|
|
|
gsttextoverlay_class = (GstTextOverlayClass *) klass;
|
|
|
|
gsttextoverlay_class->get_text = gst_time_overlay_get_text;
|
|
}
|
|
|
|
static void
|
|
gst_time_overlay_init (GstTimeOverlay * overlay, GstTimeOverlayClass * klass)
|
|
{
|
|
PangoFontDescription *font_description;
|
|
GstTextOverlay *textoverlay;
|
|
PangoContext *context;
|
|
|
|
textoverlay = GST_TEXT_OVERLAY (overlay);
|
|
|
|
context = GST_TEXT_OVERLAY_CLASS (klass)->pango_context;
|
|
|
|
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, 18 * PANGO_SCALE);
|
|
pango_context_set_font_description (context, font_description);
|
|
pango_font_description_free (font_description);
|
|
|
|
textoverlay->valign = GST_TEXT_OVERLAY_VALIGN_TOP;
|
|
textoverlay->halign = GST_TEXT_OVERLAY_HALIGN_LEFT;
|
|
}
|