Tizen 2.0 Release
[framework/multimedia/gst-plugins-good0.10.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  * sunaudiomixer is an mixer that controls the sound input and output
26  * levels with the Sun Audio interface available in Solaris.
27  */
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include "gstsunaudiomixer.h"
34
35 GST_BOILERPLATE_WITH_INTERFACE (GstSunAudioMixer, gst_sunaudiomixer,
36     GstElement, GST_TYPE_ELEMENT, GstMixer, GST_TYPE_MIXER, gst_sunaudiomixer);
37
38 GST_IMPLEMENT_SUNAUDIO_MIXER_CTRL_METHODS (GstSunAudioMixer, gst_sunaudiomixer);
39
40 static GstStateChangeReturn gst_sunaudiomixer_change_state (GstElement *
41     element, GstStateChange transition);
42
43 static void
44 gst_sunaudiomixer_base_init (gpointer klass)
45 {
46   gst_element_class_set_details_simple (GST_ELEMENT_CLASS (klass),
47       "Sun Audio Mixer", "Generic/Audio",
48       "Control sound input and output levels with Sun Audio",
49       "Brian Cameron <brian.cameron@sun.com>");
50 }
51
52 static void
53 gst_sunaudiomixer_class_init (GstSunAudioMixerClass * klass)
54 {
55   GstElementClass *element_class;
56
57   element_class = (GstElementClass *) klass;
58
59   element_class->change_state = gst_sunaudiomixer_change_state;
60 }
61
62 static void
63 gst_sunaudiomixer_init (GstSunAudioMixer * this,
64     GstSunAudioMixerClass * g_class)
65 {
66   this->mixer = NULL;
67 }
68
69 static GstStateChangeReturn
70 gst_sunaudiomixer_change_state (GstElement * element, GstStateChange transition)
71 {
72   GstSunAudioMixer *this = GST_SUNAUDIO_MIXER (element);
73
74   switch (transition) {
75     case GST_STATE_CHANGE_NULL_TO_READY:
76       if (!this->mixer) {
77         const char *audiodev;
78
79         audiodev = g_getenv ("AUDIODEV");
80         if (audiodev == NULL) {
81           this->mixer = gst_sunaudiomixer_ctrl_new ("/dev/audioctl");
82         } else {
83           gchar *device = g_strdup_printf ("%sctl", audiodev);
84
85           this->mixer = gst_sunaudiomixer_ctrl_new (device);
86           g_free (device);
87         }
88       }
89       break;
90     case GST_STATE_CHANGE_READY_TO_NULL:
91       if (this->mixer) {
92         gst_sunaudiomixer_ctrl_free (this->mixer);
93         this->mixer = NULL;
94       }
95       break;
96     default:
97       break;
98   }
99
100   if (GST_ELEMENT_CLASS (parent_class)->change_state)
101     return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
102
103   return GST_STATE_CHANGE_SUCCESS;
104 }