• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* mixer.h
2 **
3 ** Copyright 2011, The Android Open Source Project
4 **
5 ** Redistribution and use in source and binary forms, with or without
6 ** modification, are permitted provided that the following conditions are met:
7 **     * Redistributions of source code must retain the above copyright
8 **       notice, this list of conditions and the following disclaimer.
9 **     * Redistributions in binary form must reproduce the above copyright
10 **       notice, this list of conditions and the following disclaimer in the
11 **       documentation and/or other materials provided with the distribution.
12 **     * Neither the name of The Android Open Source Project nor the names of
13 **       its contributors may be used to endorse or promote products derived
14 **       from this software without specific prior written permission.
15 **
16 ** THIS SOFTWARE IS PROVIDED BY The Android Open Source Project ``AS IS'' AND
17 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 ** ARE DISCLAIMED. IN NO EVENT SHALL The Android Open Source Project BE LIABLE
20 ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26 ** DAMAGE.
27 */
28 
29 /** @file */
30 
31 /** @defgroup libtinyalsa-mixer Mixer Interface
32  * @brief All macros, structures and functions that make up the mixer interface.
33  */
34 
35 #ifndef TINYALSA_MIXER_H
36 #define TINYALSA_MIXER_H
37 
38 #include <sys/time.h>
39 #include <stddef.h>
40 
41 #if defined(__cplusplus)
42 extern "C" {
43 #endif
44 
45 struct mixer;
46 
47 struct mixer_ctl;
48 
49 // mixer_ctl_event is a mirroring structure of snd_ctl_event
50 struct mixer_ctl_event {
51     int type;
52     union {
53         struct {
54             unsigned int mask;
55             struct {
56                 unsigned int numid;
57                 int iface;
58                 unsigned int device;
59                 unsigned int subdevice;
60                 unsigned char name[44];
61                 unsigned int index;
62             } id;
63         } element;
64         unsigned char data[60];
65     } data;
66 };
67 
68 /** Mixer control type.
69  * @ingroup libtinyalsa-mixer
70  */
71 enum mixer_ctl_type {
72     /** boolean control type */
73     MIXER_CTL_TYPE_BOOL,
74     /** integer control type */
75     MIXER_CTL_TYPE_INT,
76     /** an enumerated control type */
77     MIXER_CTL_TYPE_ENUM,
78     MIXER_CTL_TYPE_BYTE,
79     MIXER_CTL_TYPE_IEC958,
80     /** a 64 bit integer control type */
81     MIXER_CTL_TYPE_INT64,
82     /** unknown control type */
83     MIXER_CTL_TYPE_UNKNOWN,
84     /** end of the enumeration (not a control type) */
85     MIXER_CTL_TYPE_MAX,
86 };
87 
88 struct mixer *mixer_open(unsigned int card);
89 
90 void mixer_close(struct mixer *mixer);
91 
92 int mixer_add_new_ctls(struct mixer *mixer);
93 
94 const char *mixer_get_name(const struct mixer *mixer);
95 
96 unsigned int mixer_get_num_ctls(const struct mixer *mixer);
97 
98 unsigned int mixer_get_num_ctls_by_name(const struct mixer *mixer, const char *name);
99 
100 const struct mixer_ctl *mixer_get_ctl_const(const struct mixer *mixer, unsigned int id);
101 
102 struct mixer_ctl *mixer_get_ctl(struct mixer *mixer, unsigned int id);
103 
104 struct mixer_ctl *mixer_get_ctl_by_name(struct mixer *mixer, const char *name);
105 
106 struct mixer_ctl *mixer_get_ctl_by_name_and_index(struct mixer *mixer,
107                                                   const char *name,
108                                                   unsigned int index);
109 
110 int mixer_subscribe_events(struct mixer *mixer, int subscribe);
111 
112 int mixer_wait_event(struct mixer *mixer, int timeout);
113 
114 unsigned int mixer_ctl_get_id(const struct mixer_ctl *ctl);
115 
116 const char *mixer_ctl_get_name(const struct mixer_ctl *ctl);
117 
118 enum mixer_ctl_type mixer_ctl_get_type(const struct mixer_ctl *ctl);
119 
120 const char *mixer_ctl_get_type_string(const struct mixer_ctl *ctl);
121 
122 unsigned int mixer_ctl_get_num_values(const struct mixer_ctl *ctl);
123 
124 unsigned int mixer_ctl_get_num_enums(const struct mixer_ctl *ctl);
125 
126 const char *mixer_ctl_get_enum_string(struct mixer_ctl *ctl, unsigned int enum_id);
127 
128 /* Some sound cards update their controls due to external events,
129  * such as HDMI EDID byte data changing when an HDMI cable is
130  * connected. This API allows the count of elements to be updated.
131  */
132 void mixer_ctl_update(struct mixer_ctl *ctl);
133 
134 int mixer_ctl_is_access_tlv_rw(const struct mixer_ctl *ctl);
135 
136 /* Set and get mixer controls */
137 int mixer_ctl_get_percent(const struct mixer_ctl *ctl, unsigned int id);
138 
139 int mixer_ctl_set_percent(struct mixer_ctl *ctl, unsigned int id, int percent);
140 
141 int mixer_ctl_get_value(const struct mixer_ctl *ctl, unsigned int id);
142 
143 int mixer_ctl_get_array(const struct mixer_ctl *ctl, void *array, size_t count);
144 
145 int mixer_ctl_set_value(struct mixer_ctl *ctl, unsigned int id, int value);
146 
147 int mixer_ctl_set_array(struct mixer_ctl *ctl, const void *array, size_t count);
148 
149 int mixer_ctl_set_enum_by_string(struct mixer_ctl *ctl, const char *string);
150 
151 /* Determine range of integer mixer controls */
152 int mixer_ctl_get_range_min(const struct mixer_ctl *ctl);
153 
154 int mixer_ctl_get_range_max(const struct mixer_ctl *ctl);
155 
156 int mixer_read_event(struct mixer *mixer, struct mixer_ctl_event *event);
157 
158 int mixer_consume_event(struct mixer *mixer);
159 #if defined(__cplusplus)
160 }  /* extern "C" */
161 #endif
162 
163 #endif
164 
165