y4mencode: fix gst-launch version in documentation
[platform/upstream/gst-plugins-good.git] / gst / autodetect / gstautoaudiosrc.c
1 /* GStreamer
2  * (c) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
3  * (c) 2006 Jan Schmidt <thaytan@noraisin.net>
4  * (c) 2008 Stefan Kost <ensonic@users.sf.net>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 /**
23  * SECTION:element-autoaudiosrc
24  * @see_also: autovideosrc, alsasrc, osssrc
25  *
26  * autoaudiosrc is an audio source that automatically detects an appropriate
27  * audio source to use.  It does so by scanning the registry for all elements
28  * that have <quote>Source</quote> and <quote>Audio</quote> in the class field
29  * of their element information, and also have a non-zero autoplugging rank.
30  *
31  * <refsect2>
32  * <title>Example launch line</title>
33  * |[
34  * gst-launch-1.0 -v -m autoaudiosrc ! audioconvert ! audioresample ! autoaudiosink
35  * ]|
36  * </refsect2>
37  */
38
39 #ifdef HAVE_CONFIG_H
40 #include "config.h"
41 #endif
42
43 #include "gstautoaudiosrc.h"
44
45 G_DEFINE_TYPE (GstAutoAudioSrc, gst_auto_audio_src, GST_TYPE_AUTO_DETECT);
46
47 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
48     GST_PAD_SRC,
49     GST_PAD_ALWAYS,
50     GST_STATIC_CAPS_ANY);
51
52 static GstElement *
53 gst_auto_audio_src_create_fake_element (GstAutoDetect * autodetect)
54 {
55   GstElement *fake;
56
57   fake = gst_element_factory_make ("audiotestsrc", "fake-auto-audio-src");
58   if (fake != NULL) {
59     g_object_set (fake, "is-live", TRUE, NULL);
60     gst_util_set_object_arg (G_OBJECT (fake), "wave", "silence");
61   } else {
62     GST_ELEMENT_ERROR (autodetect, RESOURCE, NOT_FOUND,
63         ("Failed to find usable audio source element."),
64         ("Failed to find a usable audio source and couldn't create an audio"
65             "testsrc as fallback either, check your GStreamer installation."));
66     /* This will error out with not-negotiated.. */
67     fake = gst_element_factory_make ("fakesrc", "fake-auto-audio-src");
68   }
69   return fake;
70 }
71
72 static void
73 gst_auto_audio_src_class_init (GstAutoAudioSrcClass * klass)
74 {
75   GstAutoDetectClass *autoclass = GST_AUTO_DETECT_CLASS (klass);
76   GstElementClass *eklass = GST_ELEMENT_CLASS (klass);
77
78   gst_element_class_add_pad_template (eklass,
79       gst_static_pad_template_get (&src_template));
80   gst_element_class_set_static_metadata (eklass, "Auto audio source",
81       "Source/Audio",
82       "Wrapper audio source for automatically detected audio source",
83       "Jan Schmidt <thaytan@noraisin.net>, "
84       "Stefan Kost <ensonic@users.sf.net>");
85
86   autoclass->create_fake_element = gst_auto_audio_src_create_fake_element;
87 }
88
89 static void
90 gst_auto_audio_src_init (GstAutoAudioSrc * src)
91 {
92   GstAutoDetect *autodetect = GST_AUTO_DETECT (src);
93
94   autodetect->media_klass = "Audio";
95   autodetect->flag = GST_ELEMENT_FLAG_SOURCE;
96 }