1 #ifndef EMIX_H
2 #define EMIX_H
3 
4 #ifdef HAVE_CONFIG_H
5 # include "config.h"
6 #endif
7 
8 #include <Eina.h>
9 #include <Evas.h>
10 
11 #ifdef E_API
12 #undef E_API
13 #endif
14 
15 #ifdef __GNUC__
16 # if __GNUC__ >= 4
17 #  define E_API __attribute__ ((visibility("default")))
18 # else
19 #  define E_API
20 # endif
21 #else
22 # define E_API
23 #endif
24 
25 
26 #define EMIX_VOLUME_BARRIER 100
27 
28 enum Emix_Event {
29    EMIX_READY_EVENT = 0,
30    EMIX_DISCONNECTED_EVENT,
31    EMIX_SINK_ADDED_EVENT,
32    EMIX_SINK_REMOVED_EVENT,
33    EMIX_SINK_CHANGED_EVENT,
34    EMIX_SINK_INPUT_ADDED_EVENT,
35    EMIX_SINK_INPUT_REMOVED_EVENT,
36    EMIX_SINK_INPUT_CHANGED_EVENT,
37    EMIX_SOURCE_ADDED_EVENT,
38    EMIX_SOURCE_REMOVED_EVENT,
39    EMIX_SOURCE_CHANGED_EVENT,
40    EMIX_CARD_ADDED_EVENT,
41    EMIX_CARD_REMOVED_EVENT,
42    EMIX_CARD_CHANGED_EVENT
43 };
44 
45 typedef const char * Emix_Channel;
46 
47 typedef struct _Emix_Volume {
48    unsigned int channel_count;
49    // the index of the field is the id of the channel, the value the volume
50    int *volumes;
51    Emix_Channel *channel_names;
52 } Emix_Volume;
53 
54 typedef struct _Emix_Port {
55    Eina_Bool active;
56    Eina_Bool available;
57    const char *name;
58    const char *description;
59 } Emix_Port;
60 
61 typedef struct _Emix_Sink {
62    const char *name;
63    Emix_Volume volume;
64    Eina_Bool mute;
65    Eina_List *ports;
66 } Emix_Sink;
67 
68 typedef struct _Emix_Sink_Input {
69    const char *name;
70    Emix_Volume volume;
71    Eina_Bool mute;
72    Emix_Sink *sink;
73    pid_t pid;
74    const char *icon;
75 } Emix_Sink_Input;
76 
77 typedef struct _Emix_Source {
78    const char *name;
79    Emix_Volume volume;
80    Eina_Bool mute;
81 } Emix_Source;
82 
83 typedef struct _Emix_Profile {
84    const char *name;
85    const char *description;
86    Eina_Bool plugged;
87    Eina_Bool active;
88 } Emix_Profile;
89 
90 typedef struct _Emix_Card {
91    const char *name;
92    Eina_List *profiles;
93 } Emix_Card;
94 
95 typedef void (*Emix_Event_Cb)(void *data, enum Emix_Event event,
96                               void *event_info);
97 
98 typedef struct _Emix_Backend {
99    Eina_Bool             (*ebackend_init)(Emix_Event_Cb cb, const void *data);
100    void                  (*ebackend_shutdown)(void);
101 
102    int                   (*ebackend_max_volume_get)(void);
103 
104    const Eina_List*      (*ebackend_sinks_get)(void);
105    Eina_Bool             (*ebackend_sink_default_support)(void);
106    const Emix_Sink*      (*ebackend_sink_default_get)(void);
107    void                  (*ebackend_sink_default_set)(Emix_Sink *sink);
108    void                  (*ebackend_sink_mute_set)(Emix_Sink *sink,
109                                                    Eina_Bool mute);
110    void                  (*ebackend_sink_volume_set)(Emix_Sink *sink,
111                                                      Emix_Volume *volume);
112    Eina_Bool             (*ebackend_sink_port_set)(Emix_Sink *sink,
113                                                    const Emix_Port *port);
114    Eina_Bool             (*ebackend_sink_change_support)(void);
115 
116    const Eina_List*      (*ebackend_sink_inputs_get)(void);
117    void                  (*ebackend_sink_input_mute_set)(
118                                         Emix_Sink_Input *input, Eina_Bool mute);
119    void                  (*ebackend_sink_input_volume_set)(
120                                     Emix_Sink_Input *input, Emix_Volume *volume);
121    void                  (*ebackend_sink_input_sink_change)(
122                                        Emix_Sink_Input *input, Emix_Sink *sink);
123 
124    const Eina_List*      (*ebackend_sources_get)(void);
125    void                  (*ebackend_source_mute_set)(Emix_Source *source,
126                                                      Eina_Bool mute);
127    void                  (*ebackend_source_volume_set)(Emix_Source *source,
128                                                        Emix_Volume *volume);
129 
130    Evas_Object*          (*ebackend_advanced_options_add)(Evas_Object *parent);
131    const Eina_List*      (*ebackend_cards_get)(void);
132    Eina_Bool             (*ebackend_card_profile_set)(Emix_Card *card, const Emix_Profile *profile);
133 } Emix_Backend;
134 
135 //////////////////////////////////////////////////////////////////////////////
136 
137 #define VOLSET(vol, srcvol, target, func) \
138    do { \
139       int _pvol = srcvol.volumes[0]; \
140       if ((_pvol > 80) && (_pvol <= 100) && \
141           (vol > 100) && (vol < 120)) vol = 100; \
142       if (srcvol.volumes) { \
143          unsigned int _i; \
144          for (_i = 0; _i < srcvol.channel_count; _i++) srcvol.volumes[_i] = vol; \
145          func(target, &srcvol); \
146       } \
147    } while (0)
148 
149 //////////////////////////////////////////////////////////////////////////////
150 
151 
152 E_API Eina_Bool           emix_init(void);
153 E_API void                emix_shutdown(void);
154 E_API const Eina_List*    emix_backends_available(void);
155 E_API Eina_Bool           emix_backend_set(const char *backend);
156 
157 E_API Eina_Bool           emix_event_callback_add(Emix_Event_Cb cb,
158                                                  const void *data);
159 E_API Eina_Bool           emix_event_callback_del(Emix_Event_Cb cb);
160 
161 E_API int                 emix_max_volume_get(void);
162 
163 E_API const Eina_List*    emix_sinks_get(void);
164 E_API Eina_Bool           emix_sink_default_support(void);
165 E_API const Emix_Sink*    emix_sink_default_get(void);
166 E_API Eina_Bool           emix_sink_port_set(Emix_Sink *sink, Emix_Port *port);
167 E_API void                emix_sink_default_set(Emix_Sink *sink);
168 E_API void                emix_sink_mute_set(Emix_Sink *sink, Eina_Bool mute);
169 E_API void                emix_sink_volume_set(Emix_Sink *sink,
170                                               Emix_Volume *volume);
171 E_API Eina_Bool           emix_sink_change_support(void);
172 
173 E_API const Eina_List*    emix_sink_inputs_get(void);
174 E_API void                emix_sink_input_mute_set(Emix_Sink_Input *input,
175                                                   Eina_Bool mute);
176 E_API void                emix_sink_input_volume_set(Emix_Sink_Input *input,
177                                                     Emix_Volume *volume);
178 E_API void                emix_sink_input_sink_change(Emix_Sink_Input *input,
179                                                      Emix_Sink *sink);
180 
181 E_API const Eina_List*    emix_sources_get(void);
182 E_API void                emix_source_mute_set(Emix_Source *source,
183                                                   Eina_Bool mute);
184 E_API void                emix_source_volume_set(Emix_Source *source,
185                                                 Emix_Volume *volume);
186 E_API Evas_Object*        emix_advanced_options_add(Evas_Object *parent);
187 
188 E_API const Eina_List*    emix_cards_get(void);
189 E_API Eina_Bool           emix_card_profile_set(Emix_Card *card, Emix_Profile *profile);
190 
191 #endif  /* EMIX_H */
192