gstautovideosink.c 4.46 KB
Newer Older
1 2
/* GStreamer
 * (c) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
3
 * (c) 2006 Jan Schmidt <thaytan@noraisin.net>
4 5 6 7 8 9 10 11 12 13 14 15 16
 *
 * 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
Tim-Philipp Müller's avatar
Tim-Philipp Müller committed
17 18
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
19 20
 */

21 22 23 24 25 26
/**
 * SECTION:element-autovideosink
 * @see_also: autoaudiosink, ximagesink, xvimagesink, sdlvideosink
 *
 * autovideosink is a video sink that automatically detects an appropriate
 * video sink to use.  It does so by scanning the registry for all elements
27
 * that have <quote>Sink</quote> and <quote>Video</quote> in the class field
28
 * of their element information, and also have a non-zero autoplugging rank.
29 30
 *
 * <refsect2>
31
 * <title>Example launch line</title>
32
 * |[
33
 * gst-launch-1.0 -v -m videotestsrc ! autovideosink
34
 * ]|
35 36 37
 * </refsect2>
 */

38 39 40 41 42 43
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "gstautovideosink.h"

44 45
#define DEFAULT_TS_OFFSET           0

46 47 48 49
/* Properties */
enum
{
  PROP_0,
50
  PROP_TS_OFFSET,
51 52 53 54 55 56
};

static void gst_auto_video_sink_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec);
static void gst_auto_video_sink_get_property (GObject * object, guint prop_id,
    GValue * value, GParamSpec * pspec);
57 58
static void gst_auto_video_sink_configure (GstAutoDetect * autodetect,
    GstElement * kid);
59

60
G_DEFINE_TYPE (GstAutoVideoSink, gst_auto_video_sink, GST_TYPE_AUTO_DETECT);
61

62 63 64 65 66
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
    GST_PAD_SINK,
    GST_PAD_ALWAYS,
    GST_STATIC_CAPS_ANY);

67 68 69
static void
gst_auto_video_sink_class_init (GstAutoVideoSinkClass * klass)
{
70
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
71
  GstElementClass *eklass = GST_ELEMENT_CLASS (klass);
72
  GstAutoDetectClass *aklass = GST_AUTO_DETECT_CLASS (klass);
73

74 75
  gobject_class->set_property = gst_auto_video_sink_set_property;
  gobject_class->get_property = gst_auto_video_sink_get_property;
76

77
  aklass->configure = gst_auto_video_sink_configure;
Wim Taymans's avatar
Wim Taymans committed
78

79 80 81 82 83
  g_object_class_install_property (gobject_class, PROP_TS_OFFSET,
      g_param_spec_int64 ("ts-offset", "TS Offset",
          "Timestamp offset in nanoseconds", G_MININT64, G_MAXINT64,
          DEFAULT_TS_OFFSET, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

Wim Taymans's avatar
Wim Taymans committed
84 85
  gst_element_class_add_pad_template (eklass,
      gst_static_pad_template_get (&sink_template));
86
  gst_element_class_set_static_metadata (eklass, "Auto video sink",
Wim Taymans's avatar
Wim Taymans committed
87 88 89
      "Sink/Video",
      "Wrapper video sink for automatically detected video sink",
      "Jan Schmidt <thaytan@noraisin.net>");
90 91 92
}

static void
Wim Taymans's avatar
Wim Taymans committed
93
gst_auto_video_sink_init (GstAutoVideoSink * sink)
94
{
95
  GstAutoDetect *autodetect = GST_AUTO_DETECT (sink);
96

97 98
  autodetect->media_klass = "Video";
  autodetect->flag = GST_ELEMENT_FLAG_SINK;
99

100
  sink->ts_offset = DEFAULT_TS_OFFSET;
101 102
}

103 104
static void
gst_auto_video_sink_configure (GstAutoDetect * autodetect, GstElement * kid)
105
{
106
  GstAutoVideoSink *self = GST_AUTO_VIDEO_SINK (autodetect);
107

108
  g_object_set (G_OBJECT (kid), "ts-offset", self->ts_offset, NULL);
109
}
110 111 112 113 114 115

static void
gst_auto_video_sink_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec)
{
  GstAutoVideoSink *sink = GST_AUTO_VIDEO_SINK (object);
116
  GstAutoDetect *autodetect = (GstAutoDetect *) sink;
117 118

  switch (prop_id) {
119 120
    case PROP_TS_OFFSET:
      sink->ts_offset = g_value_get_int64 (value);
121 122
      if (autodetect->kid)
        g_object_set_property (G_OBJECT (autodetect->kid), pspec->name, value);
123
      break;
124 125 126 127 128 129 130 131 132 133 134 135 136
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

static void
gst_auto_video_sink_get_property (GObject * object, guint prop_id,
    GValue * value, GParamSpec * pspec)
{
  GstAutoVideoSink *sink = GST_AUTO_VIDEO_SINK (object);

  switch (prop_id) {
137 138 139
    case PROP_TS_OFFSET:
      g_value_set_int64 (value, sink->ts_offset);
      break;
140 141 142 143 144
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}