• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * (c) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
3  * (c) 2006 Jan Schmidt <thaytan@noraisin.net>
4  *
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.
9  *
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.
14  *
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., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 /**
22  * SECTION:element-autovideosink
23  * @title: autovideosink
24  * @see_also: autoaudiosink, ximagesink, xvimagesink, sdlvideosink
25  *
26  * autovideosink is a video sink that automatically detects an appropriate
27  * video sink to use.  It does so by scanning the registry for all elements
28  * that have "Sink" and "Video" in the class field
29  * of their element information, and also have a non-zero autoplugging rank.
30  *
31  * ## Example launch line
32  * |[
33  * gst-launch-1.0 -v -m videotestsrc ! autovideosink
34  * ]|
35  *
36  */
37 
38 #ifdef HAVE_CONFIG_H
39 #include "config.h"
40 #endif
41 
42 #include "gstautodetectelements.h"
43 #include "gstautodetect.h"
44 #include "gstautovideosink.h"
45 
46 #define DEFAULT_TS_OFFSET           0
47 
48 /* Properties */
49 enum
50 {
51   PROP_0,
52   PROP_TS_OFFSET,
53 };
54 
55 static void gst_auto_video_sink_set_property (GObject * object, guint prop_id,
56     const GValue * value, GParamSpec * pspec);
57 static void gst_auto_video_sink_get_property (GObject * object, guint prop_id,
58     GValue * value, GParamSpec * pspec);
59 static void gst_auto_video_sink_configure (GstAutoDetect * autodetect,
60     GstElement * kid);
61 
62 G_DEFINE_TYPE (GstAutoVideoSink, gst_auto_video_sink, GST_TYPE_AUTO_DETECT);
63 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (autovideosink, "autovideosink",
64     GST_RANK_NONE, GST_TYPE_AUTO_VIDEO_SINK, autodetect_element_init (plugin));
65 
66 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
67     GST_PAD_SINK,
68     GST_PAD_ALWAYS,
69     GST_STATIC_CAPS_ANY);
70 
71 static void
gst_auto_video_sink_class_init(GstAutoVideoSinkClass * klass)72 gst_auto_video_sink_class_init (GstAutoVideoSinkClass * klass)
73 {
74   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
75   GstElementClass *eklass = GST_ELEMENT_CLASS (klass);
76   GstAutoDetectClass *aklass = GST_AUTO_DETECT_CLASS (klass);
77 
78   gobject_class->set_property = gst_auto_video_sink_set_property;
79   gobject_class->get_property = gst_auto_video_sink_get_property;
80 
81   aklass->configure = gst_auto_video_sink_configure;
82 
83   g_object_class_install_property (gobject_class, PROP_TS_OFFSET,
84       g_param_spec_int64 ("ts-offset", "TS Offset",
85           "Timestamp offset in nanoseconds", G_MININT64, G_MAXINT64,
86           DEFAULT_TS_OFFSET, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
87 
88   gst_element_class_add_static_pad_template (eklass, &sink_template);
89   gst_element_class_set_static_metadata (eklass, "Auto video sink",
90       "Sink/Video",
91       "Wrapper video sink for automatically detected video sink",
92       "Jan Schmidt <thaytan@noraisin.net>");
93 }
94 
95 static void
gst_auto_video_sink_init(GstAutoVideoSink * sink)96 gst_auto_video_sink_init (GstAutoVideoSink * sink)
97 {
98   GstAutoDetect *autodetect = GST_AUTO_DETECT (sink);
99 
100   autodetect->media_klass = "Video";
101   autodetect->flag = GST_ELEMENT_FLAG_SINK;
102 
103   sink->ts_offset = DEFAULT_TS_OFFSET;
104 }
105 
106 static void
gst_auto_video_sink_configure(GstAutoDetect * autodetect,GstElement * kid)107 gst_auto_video_sink_configure (GstAutoDetect * autodetect, GstElement * kid)
108 {
109   GstAutoVideoSink *self = GST_AUTO_VIDEO_SINK (autodetect);
110 
111   g_object_set (G_OBJECT (kid), "ts-offset", self->ts_offset, NULL);
112 }
113 
114 static void
gst_auto_video_sink_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)115 gst_auto_video_sink_set_property (GObject * object, guint prop_id,
116     const GValue * value, GParamSpec * pspec)
117 {
118   GstAutoVideoSink *sink = GST_AUTO_VIDEO_SINK (object);
119   GstAutoDetect *autodetect = (GstAutoDetect *) sink;
120 
121   switch (prop_id) {
122     case PROP_TS_OFFSET:
123       sink->ts_offset = g_value_get_int64 (value);
124       if (autodetect->kid)
125         g_object_set_property (G_OBJECT (autodetect->kid), pspec->name, value);
126       break;
127     default:
128       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
129       break;
130   }
131 }
132 
133 static void
gst_auto_video_sink_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)134 gst_auto_video_sink_get_property (GObject * object, guint prop_id,
135     GValue * value, GParamSpec * pspec)
136 {
137   GstAutoVideoSink *sink = GST_AUTO_VIDEO_SINK (object);
138 
139   switch (prop_id) {
140     case PROP_TS_OFFSET:
141       g_value_set_int64 (value, sink->ts_offset);
142       break;
143     default:
144       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
145       break;
146   }
147 }
148