expand tabs
[platform/upstream/gstreamer.git] / 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
34 #define GST_ALSA_MIXER(obj)             ((GstAlsaMixer*)(obj))
35
36
37 typedef enum {
38   GST_ALSA_MIXER_CAPTURE = 1<<0,
39   GST_ALSA_MIXER_PLAYBACK = 1<<1,
40   GST_ALSA_MIXER_ALL = GST_ALSA_MIXER_CAPTURE | GST_ALSA_MIXER_PLAYBACK
41 } GstAlsaMixerDirection;
42   
43
44 typedef struct _GstAlsaMixer GstAlsaMixer;
45
46
47 struct _GstAlsaMixer {
48   GList *               tracklist;      /* list of available tracks */
49
50   snd_mixer_t *         handle;
51
52   gchar *               device;
53   gchar *               cardname;
54
55   GstAlsaMixerDirection dir;
56 };
57
58
59 GstAlsaMixer*   gst_alsa_mixer_new              (const gchar *device,
60                                                  GstAlsaMixerDirection dir);
61 void            gst_alsa_mixer_free             (GstAlsaMixer *mixer);
62
63 const GList*    gst_alsa_mixer_list_tracks      (GstAlsaMixer * mixer);
64 void            gst_alsa_mixer_set_volume       (GstAlsaMixer * mixer,
65                                                  GstMixerTrack * track,
66                                                  gint * volumes);
67 void            gst_alsa_mixer_get_volume       (GstAlsaMixer * mixer,
68                                                  GstMixerTrack * track,
69                                                  gint * volumes);
70 void            gst_alsa_mixer_set_record       (GstAlsaMixer * mixer,
71                                                  GstMixerTrack * track,
72                                                  gboolean record);
73 void            gst_alsa_mixer_set_mute         (GstAlsaMixer * mixer,
74                                                  GstMixerTrack * track,
75                                                  gboolean mute);
76 void            gst_alsa_mixer_set_option       (GstAlsaMixer * mixer,
77                                                  GstMixerOptions * opts,
78                                                  gchar * value);
79 const gchar*    gst_alsa_mixer_get_option       (GstAlsaMixer * mixer,
80                                                  GstMixerOptions * opts);
81
82
83 #define GST_IMPLEMENT_ALSA_MIXER_METHODS(Type, interface_as_function)           \
84 static gboolean                                                                 \
85 interface_as_function ## _supported (Type *this, GType iface_type)              \
86 {                                                                               \
87   g_assert (iface_type == GST_TYPE_MIXER);                                      \
88                                                                                 \
89   return (this->mixer != NULL);                                                 \
90 }                                                                               \
91                                                                                 \
92 static const GList*                                                             \
93 interface_as_function ## _list_tracks (GstMixer * mixer)                        \
94 {                                                                               \
95   Type *this = (Type*) mixer;                                                   \
96                                                                                 \
97   g_return_val_if_fail (this != NULL, NULL);                                    \
98   g_return_val_if_fail (this->mixer != NULL, NULL);                             \
99                                                                                 \
100   return gst_alsa_mixer_list_tracks (this->mixer);                              \
101 }                                                                               \
102                                                                                 \
103 static void                                                                     \
104 interface_as_function ## _set_volume (GstMixer * mixer, GstMixerTrack * track,  \
105     gint * volumes)                                                             \
106 {                                                                               \
107   Type *this = (Type*) mixer;                                                   \
108                                                                                 \
109   g_return_if_fail (this != NULL);                                              \
110   g_return_if_fail (this->mixer != NULL);                                       \
111                                                                                 \
112   gst_alsa_mixer_set_volume (this->mixer, track, volumes);                      \
113 }                                                                               \
114                                                                                 \
115 static void                                                                     \
116 interface_as_function ## _get_volume (GstMixer * mixer, GstMixerTrack * track,  \
117     gint * volumes)                                                             \
118 {                                                                               \
119   Type *this = (Type*) mixer;                                                   \
120                                                                                 \
121   g_return_if_fail (this != NULL);                                              \
122   g_return_if_fail (this->mixer != NULL);                                       \
123                                                                                 \
124   gst_alsa_mixer_get_volume (this->mixer, track, volumes);                      \
125 }                                                                               \
126                                                                                 \
127 static void                                                                     \
128 interface_as_function ## _set_record (GstMixer * mixer, GstMixerTrack * track,  \
129     gboolean record)                                                            \
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_record (this->mixer, track, record);                       \
137 }                                                                               \
138                                                                                 \
139 static void                                                                     \
140 interface_as_function ## _set_mute (GstMixer * mixer, GstMixerTrack * track,    \
141     gboolean mute)                                                              \
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_set_mute (this->mixer, track, mute);                           \
149 }                                                                               \
150                                                                                 \
151 static void                                                                     \
152 interface_as_function ## _set_option (GstMixer * mixer, GstMixerOptions * opts, \
153     gchar * value)                                                              \
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_option (this->mixer, opts, value);                         \
161 }                                                                               \
162                                                                                 \
163 static const gchar*                                                             \
164 interface_as_function ## _get_option (GstMixer * mixer, GstMixerOptions * opts) \
165 {                                                                               \
166   Type *this = (Type*) mixer;                                                   \
167                                                                                 \
168   g_return_val_if_fail (this != NULL, NULL);                                    \
169   g_return_val_if_fail (this->mixer != NULL, NULL);                             \
170                                                                                 \
171   return gst_alsa_mixer_get_option (this->mixer, opts);                         \
172 }                                                                               \
173                                                                                 \
174 static void                                                                     \
175 interface_as_function ## _interface_init (GstMixerClass * klass)                \
176 {                                                                               \
177   GST_MIXER_TYPE (klass) = GST_MIXER_HARDWARE;                                  \
178                                                                                 \
179   /* set up the interface hooks */                                              \
180   klass->list_tracks = interface_as_function ## _list_tracks;                   \
181   klass->set_volume = interface_as_function ## _set_volume;                     \
182   klass->get_volume = interface_as_function ## _get_volume;                     \
183   klass->set_mute = interface_as_function ## _set_mute;                         \
184   klass->set_record = interface_as_function ## _set_record;                     \
185   klass->set_option = interface_as_function ## _set_option;                     \
186   klass->get_option = interface_as_function ## _get_option;                     \
187 }
188
189
190 G_END_DECLS
191
192
193 #endif /* __GST_ALSA_MIXER_H__ */