4789550acba34c27533737670aaedab24c46c087
[platform/upstream/gst-plugins-good.git] / sys / sunaudio / gstsunaudiomixer.c
1 /*
2  * GStreamer - SunAudio mixer
3  * Copyright (C) 2005,2006 Sun Microsystems, Inc.,
4  *               Brian Cameron <brian.cameron@sun.com>
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., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 /**
23  * SECTION:element-sunaudiomixer
24  *
25  * <refsect2>
26  * <para>
27  * sunaudiomixer is an mixer that controls the sound input and output
28  * levels with the Sun Audio interface available in Solaris.
29  * </para>
30  * </refsect2>
31  */
32
33 #ifdef HAVE_CONFIG_H
34 #include "config.h"
35 #endif
36
37 #include "gstsunaudiomixer.h"
38
39 static const GstElementDetails gst_sunaudiomixer_details =
40 GST_ELEMENT_DETAILS ("Sun Audio Mixer",
41     "Generic/Audio",
42     "Control sound input and output levels with Sun Audio",
43     "Brian Cameron <brian.cameron@sun.com>");
44
45 GST_BOILERPLATE_WITH_INTERFACE (GstSunAudioMixer, gst_sunaudiomixer,
46     GstElement, GST_TYPE_ELEMENT, GstMixer, GST_TYPE_MIXER, gst_sunaudiomixer);
47
48 GST_IMPLEMENT_SUNAUDIO_MIXER_CTRL_METHODS (GstSunAudioMixer, gst_sunaudiomixer);
49
50 static GstStateChangeReturn gst_sunaudiomixer_change_state (GstElement *
51     element, GstStateChange transition);
52
53 static void
54 gst_sunaudiomixer_base_init (gpointer klass)
55 {
56   gst_element_class_set_details (GST_ELEMENT_CLASS (klass),
57       &gst_sunaudiomixer_details);
58 }
59
60 static void
61 gst_sunaudiomixer_class_init (GstSunAudioMixerClass * klass)
62 {
63   GstElementClass *element_class;
64
65   element_class = (GstElementClass *) klass;
66
67   element_class->change_state = gst_sunaudiomixer_change_state;
68 }
69
70 static void
71 gst_sunaudiomixer_init (GstSunAudioMixer * this,
72     GstSunAudioMixerClass * g_class)
73 {
74   this->mixer = NULL;
75 }
76
77 static GstStateChangeReturn
78 gst_sunaudiomixer_change_state (GstElement * element, GstStateChange transition)
79 {
80   GstSunAudioMixer *this = GST_SUNAUDIO_MIXER (element);
81
82   switch (transition) {
83     case GST_STATE_CHANGE_NULL_TO_READY:
84       if (!this->mixer) {
85         const char *audiodev;
86
87         audiodev = g_getenv ("AUDIODEV");
88         if (audiodev == NULL) {
89           this->mixer = gst_sunaudiomixer_ctrl_new ("/dev/audioctl");
90         } else {
91           gchar *device = g_strdup_printf ("%sctl", audiodev);
92
93           this->mixer = gst_sunaudiomixer_ctrl_new (device);
94           g_free (device);
95         }
96       }
97       break;
98     case GST_STATE_CHANGE_READY_TO_NULL:
99       if (this->mixer) {
100         gst_sunaudiomixer_ctrl_free (this->mixer);
101         this->mixer = NULL;
102       }
103       break;
104     default:
105       break;
106   }
107
108   if (GST_ELEMENT_CLASS (parent_class)->change_state)
109     return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
110
111   return GST_STATE_CHANGE_SUCCESS;
112 }