y4mencode: fix gst-launch version in documentation
[platform/upstream/gst-plugins-good.git] / gst / autodetect / gstautoaudiosink.c
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-autoaudiosink
23  * @see_also: autovideosink, alsasink, osssink
24  *
25  * autoaudiosink is an audio sink that automatically detects an appropriate
26  * audio sink to use.  It does so by scanning the registry for all elements
27  * that have <quote>Sink</quote> and <quote>Audio</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 audiotestsrc ! audioconvert ! audioresample ! autoaudiosink
34  * ]|
35  * </refsect2>
36  */
37
38 #ifdef HAVE_CONFIG_H
39 #include "config.h"
40 #endif
41
42 #include "gstautoaudiosink.h"
43
44 #define DEFAULT_TS_OFFSET           0
45
46 /* Properties */
47 enum
48 {
49   PROP_0,
50   PROP_TS_OFFSET,
51 };
52
53 static void gst_auto_audio_sink_set_property (GObject * object, guint prop_id,
54     const GValue * value, GParamSpec * pspec);
55 static void gst_auto_audio_sink_get_property (GObject * object, guint prop_id,
56     GValue * value, GParamSpec * pspec);
57 static void gst_auto_audio_sink_configure (GstAutoDetect * autodetect,
58     GstElement * kid);
59
60 G_DEFINE_TYPE (GstAutoAudioSink, gst_auto_audio_sink, GST_TYPE_AUTO_DETECT);
61
62 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
63     GST_PAD_SINK,
64     GST_PAD_ALWAYS,
65     GST_STATIC_CAPS_ANY);
66
67 static void
68 gst_auto_audio_sink_class_init (GstAutoAudioSinkClass * klass)
69 {
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   gobject_class->set_property = gst_auto_audio_sink_set_property;
75   gobject_class->get_property = gst_auto_audio_sink_get_property;
76
77   aklass->configure = gst_auto_audio_sink_configure;
78
79   g_object_class_install_property (gobject_class, PROP_TS_OFFSET,
80       g_param_spec_int64 ("ts-offset", "TS Offset",
81           "Timestamp offset in nanoseconds", G_MININT64, G_MAXINT64,
82           DEFAULT_TS_OFFSET, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
83
84   gst_element_class_add_pad_template (eklass,
85       gst_static_pad_template_get (&sink_template));
86   gst_element_class_set_static_metadata (eklass, "Auto audio sink",
87       "Sink/Audio",
88       "Wrapper audio sink for automatically detected audio sink",
89       "Jan Schmidt <thaytan@noraisin.net>");
90 }
91
92 static void
93 gst_auto_audio_sink_init (GstAutoAudioSink * sink)
94 {
95   GstAutoDetect *autodetect = GST_AUTO_DETECT (sink);
96
97   autodetect->media_klass = "Audio";
98   autodetect->flag = GST_ELEMENT_FLAG_SINK;
99
100   sink->ts_offset = DEFAULT_TS_OFFSET;
101 }
102
103 static void
104 gst_auto_audio_sink_configure (GstAutoDetect * autodetect, GstElement * kid)
105 {
106   GstAutoAudioSink *self = GST_AUTO_AUDIO_SINK (autodetect);
107
108   g_object_set (G_OBJECT (kid), "ts-offset", self->ts_offset, NULL);
109 }
110
111 static void
112 gst_auto_audio_sink_set_property (GObject * object, guint prop_id,
113     const GValue * value, GParamSpec * pspec)
114 {
115   GstAutoAudioSink *sink = GST_AUTO_AUDIO_SINK (object);
116   GstAutoDetect *autodetect = (GstAutoDetect *) sink;
117
118   switch (prop_id) {
119     case PROP_TS_OFFSET:
120       sink->ts_offset = g_value_get_int64 (value);
121       if (autodetect->kid)
122         g_object_set_property (G_OBJECT (autodetect->kid), pspec->name, value);
123       break;
124     default:
125       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
126       break;
127   }
128 }
129
130 static void
131 gst_auto_audio_sink_get_property (GObject * object, guint prop_id,
132     GValue * value, GParamSpec * pspec)
133 {
134   GstAutoAudioSink *sink = GST_AUTO_AUDIO_SINK (object);
135
136   switch (prop_id) {
137     case PROP_TS_OFFSET:
138       g_value_set_int64 (value, sink->ts_offset);
139       break;
140     default:
141       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
142       break;
143   }
144 }