Initialize Tizen 2.3
[framework/multimedia/gst-plugins-base0.10.git] / mobile / ext / alsa / gstalsamixer.h
1 /* ALSA mixer interface implementation.
2  * Copyright (C) 2003 Leif Johnson <leif@ambient.2y.net>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19
20 #ifndef __GST_ALSA_MIXER_H__
21 #define __GST_ALSA_MIXER_H__
22
23
24 #include "gstalsa.h"
25
26 #include <gst/interfaces/mixer.h>
27 #include "gstalsamixeroptions.h"
28 #include "gstalsamixertrack.h"
29
30
31 G_BEGIN_DECLS
32
33 /* This does not get you what you think it does, use obj->mixer   */
34 /* #define GST_ALSA_MIXER(obj)             ((GstAlsaMixer*)(obj)) */
35
36 typedef struct _GstAlsaMixer GstAlsaMixer;
37
38 typedef enum {
39   GST_ALSA_MIXER_CAPTURE = 1<<0,
40   GST_ALSA_MIXER_PLAYBACK = 1<<1,
41   GST_ALSA_MIXER_ALL = GST_ALSA_MIXER_CAPTURE | GST_ALSA_MIXER_PLAYBACK
42 } GstAlsaMixerDirection;
43
44 /**
45  * GstAlsaMixer:
46  *
47  * Opaque data structure
48  */
49 struct _GstAlsaMixer
50 {
51   GList *               tracklist;      /* list of available tracks */
52
53   snd_mixer_t *         handle;
54
55   GstTask *             task;
56   GStaticRecMutex       task_mutex;
57
58 #if !GLIB_CHECK_VERSION (2, 31, 0)
59   GStaticRecMutex       rec_mutex;
60 #else
61   GRecMutex             rec_mutex;
62 #endif
63
64   int                   pfd[2];
65
66   GstMixer *            interface;
67   gchar *               device;
68   gchar *               cardname;
69
70   GstAlsaMixerDirection dir;
71 };
72
73 #if !GLIB_CHECK_VERSION (2, 31, 0)
74 #define GST_ALSA_MIXER_LOCK(mixer)   g_static_rec_mutex_lock (&mixer->rec_mutex)
75 #define GST_ALSA_MIXER_UNLOCK(mixer) g_static_rec_mutex_unlock (&mixer->rec_mutex)
76 #else
77 #define GST_ALSA_MIXER_LOCK(mixer)   g_rec_mutex_lock (&mixer->rec_mutex)
78 #define GST_ALSA_MIXER_UNLOCK(mixer) g_rec_mutex_unlock (&mixer->rec_mutex)
79 #endif
80
81 GstAlsaMixer*   gst_alsa_mixer_new              (const gchar *device,
82                                                  GstAlsaMixerDirection dir);
83 void            gst_alsa_mixer_free             (GstAlsaMixer *mixer);
84
85 const GList*    gst_alsa_mixer_list_tracks      (GstAlsaMixer * mixer);
86 void            gst_alsa_mixer_set_volume       (GstAlsaMixer * mixer,
87                                                  GstMixerTrack * track,
88                                                  gint * volumes);
89 void            gst_alsa_mixer_get_volume       (GstAlsaMixer * mixer,
90                                                  GstMixerTrack * track,
91                                                  gint * volumes);
92 void            gst_alsa_mixer_set_record       (GstAlsaMixer * mixer,
93                                                  GstMixerTrack * track,
94                                                  gboolean record);
95 void            gst_alsa_mixer_set_mute         (GstAlsaMixer * mixer,
96                                                  GstMixerTrack * track,
97                                                  gboolean mute);
98 void            gst_alsa_mixer_set_option       (GstAlsaMixer * mixer,
99                                                  GstMixerOptions * opts,
100                                                  gchar * value);
101 const gchar*    gst_alsa_mixer_get_option       (GstAlsaMixer * mixer,
102                                                  GstMixerOptions * opts);
103 void            _gst_alsa_mixer_set_interface   (GstAlsaMixer * mixer,
104                                                  GstMixer * interface);
105 GstMixerFlags   gst_alsa_mixer_get_mixer_flags  (GstAlsaMixer *mixer);
106
107 #define GST_IMPLEMENT_ALSA_MIXER_METHODS(Type, interface_as_function)           \
108 static gboolean                                                                 \
109 interface_as_function ## _supported (Type *this, GType iface_type)              \
110 {                                                                               \
111   g_assert (iface_type == GST_TYPE_MIXER);                                      \
112                                                                                 \
113   return (this->mixer != NULL);                                                 \
114 }                                                                               \
115                                                                                 \
116 static const GList*                                                             \
117 interface_as_function ## _list_tracks (GstMixer * mixer)                        \
118 {                                                                               \
119   Type *this = (Type*) mixer;                                                   \
120                                                                                 \
121   g_return_val_if_fail (this != NULL, NULL);                                    \
122   g_return_val_if_fail (this->mixer != NULL, NULL);                             \
123                                                                                 \
124   return gst_alsa_mixer_list_tracks (this->mixer);                              \
125 }                                                                               \
126                                                                                 \
127 static void                                                                     \
128 interface_as_function ## _set_volume (GstMixer * mixer, GstMixerTrack * track,  \
129     gint * volumes)                                                             \
130 {                                                                               \
131   Type *this = (Type*) mixer;                                                   \
132                                                                                 \
133   g_return_if_fail (this != NULL);                                              \
134   g_return_if_fail (this->mixer != NULL);                                       \
135                                                                                 \
136   gst_alsa_mixer_set_volume (this->mixer, track, volumes);                      \
137 }                                                                               \
138                                                                                 \
139 static void                                                                     \
140 interface_as_function ## _get_volume (GstMixer * mixer, GstMixerTrack * track,  \
141     gint * volumes)                                                             \
142 {                                                                               \
143   Type *this = (Type*) mixer;                                                   \
144                                                                                 \
145   g_return_if_fail (this != NULL);                                              \
146   g_return_if_fail (this->mixer != NULL);                                       \
147                                                                                 \
148   gst_alsa_mixer_get_volume (this->mixer, track, volumes);                      \
149 }                                                                               \
150                                                                                 \
151 static void                                                                     \
152 interface_as_function ## _set_record (GstMixer * mixer, GstMixerTrack * track,  \
153     gboolean record)                                                            \
154 {                                                                               \
155   Type *this = (Type*) mixer;                                                   \
156                                                                                 \
157   g_return_if_fail (this != NULL);                                              \
158   g_return_if_fail (this->mixer != NULL);                                       \
159                                                                                 \
160   gst_alsa_mixer_set_record (this->mixer, track, record);                       \
161 }                                                                               \
162                                                                                 \
163 static void                                                                     \
164 interface_as_function ## _set_mute (GstMixer * mixer, GstMixerTrack * track,    \
165     gboolean mute)                                                              \
166 {                                                                               \
167   Type *this = (Type*) mixer;                                                   \
168                                                                                 \
169   g_return_if_fail (this != NULL);                                              \
170   g_return_if_fail (this->mixer != NULL);                                       \
171                                                                                 \
172   gst_alsa_mixer_set_mute (this->mixer, track, mute);                           \
173 }                                                                               \
174                                                                                 \
175 static void                                                                     \
176 interface_as_function ## _set_option (GstMixer * mixer, GstMixerOptions * opts, \
177     gchar * value)                                                              \
178 {                                                                               \
179   Type *this = (Type*) mixer;                                                   \
180                                                                                 \
181   g_return_if_fail (this != NULL);                                              \
182   g_return_if_fail (this->mixer != NULL);                                       \
183                                                                                 \
184   gst_alsa_mixer_set_option (this->mixer, opts, value);                         \
185 }                                                                               \
186                                                                                 \
187 static const gchar*                                                             \
188 interface_as_function ## _get_option (GstMixer * mixer, GstMixerOptions * opts) \
189 {                                                                               \
190   Type *this = (Type*) mixer;                                                   \
191                                                                                 \
192   g_return_val_if_fail (this != NULL, NULL);                                    \
193   g_return_val_if_fail (this->mixer != NULL, NULL);                             \
194                                                                                 \
195   return gst_alsa_mixer_get_option (this->mixer, opts);                         \
196 }                                                                               \
197                                                                                 \
198 static GstMixerFlags                                                            \
199 interface_as_function ## _get_mixer_flags (GstMixer * mixer)                    \
200 {                                                                               \
201   Type *this = (Type*) mixer;                                                   \
202                                                                                 \
203   g_return_val_if_fail (this != NULL, GST_MIXER_FLAG_NONE);                     \
204   g_return_val_if_fail (this->mixer != NULL, GST_MIXER_FLAG_NONE);              \
205                                                                                 \
206   return gst_alsa_mixer_get_mixer_flags (this->mixer);                          \
207 }                                                                               \
208                                                                                 \
209 static void                                                                     \
210 interface_as_function ## _interface_init (GstMixerClass * klass)                \
211 {                                                                               \
212   GST_MIXER_TYPE (klass) = GST_MIXER_HARDWARE;                                  \
213                                                                                 \
214   /* set up the interface hooks */                                              \
215   klass->list_tracks = interface_as_function ## _list_tracks;                   \
216   klass->set_volume = interface_as_function ## _set_volume;                     \
217   klass->get_volume = interface_as_function ## _get_volume;                     \
218   klass->set_mute = interface_as_function ## _set_mute;                         \
219   klass->set_record = interface_as_function ## _set_record;                     \
220   klass->set_option = interface_as_function ## _set_option;                     \
221   klass->get_option = interface_as_function ## _get_option;                     \
222   klass->get_mixer_flags = interface_as_function ## _get_mixer_flags;           \
223 }
224
225
226 G_END_DECLS
227
228
229 #endif /* __GST_ALSA_MIXER_H__ */