2 * Alsa MIXER Wine Driver for Linux
3 * Very loosely based on wineoss mixer driver
5 * Copyright 2007 Maarten Lankhorst
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
35 #ifdef HAVE_SYS_IOCTL_H
36 # include <sys/ioctl.h>
39 #define NONAMELESSUNION
40 #define NONAMELESSSTRUCT
50 #include "wine/unicode.h"
51 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(mixer
);
57 #define WINE_MIXER_MANUF_ID 0xAA
58 #define WINE_MIXER_PRODUCT_ID 0x55
59 #define WINE_MIXER_VERSION 0x0100
62 * In windows it seems to be required for all controls to have a volume switch
63 * In alsa that's optional
65 * I assume for playback controls, that there is always a playback volume switch available
68 * For capture controls, it is needed that there is a capture switch and a volume switch,
69 * It doesn't matter whether it is a playback volume switch or a capture volume switch.
70 * The code will first try to get/adjust capture volume, if that fails it tries playback volume
71 * It is not pretty, but under my 3 test cards it seems that there is no other choice:
72 * Most capture controls don't have a capture volume setting
74 * MUX means that only capture source can be exclusively selected,
75 * MIXER means that multiple sources can be selected simultaneously.
78 static const char * getMessage(UINT uMsg
)
81 #define MSG_TO_STR(x) case x: return #x;
83 MSG_TO_STR(DRVM_INIT
);
84 MSG_TO_STR(DRVM_EXIT
);
85 MSG_TO_STR(DRVM_ENABLE
);
86 MSG_TO_STR(DRVM_DISABLE
);
87 MSG_TO_STR(MXDM_GETDEVCAPS
);
88 MSG_TO_STR(MXDM_GETLINEINFO
);
89 MSG_TO_STR(MXDM_GETNUMDEVS
);
90 MSG_TO_STR(MXDM_OPEN
);
91 MSG_TO_STR(MXDM_CLOSE
);
92 MSG_TO_STR(MXDM_GETLINECONTROLS
);
93 MSG_TO_STR(MXDM_GETCONTROLDETAILS
);
94 MSG_TO_STR(MXDM_SETCONTROLDETAILS
);
98 sprintf(str
, "UNKNOWN(%08x)", uMsg
);
102 static const char * getControlType(DWORD dwControlType
)
104 #define TYPE_TO_STR(x) case x: return #x;
105 switch (dwControlType
) {
106 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_CUSTOM
);
107 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_BOOLEANMETER
);
108 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_SIGNEDMETER
);
109 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_PEAKMETER
);
110 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_UNSIGNEDMETER
);
111 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_BOOLEAN
);
112 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_ONOFF
);
113 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MUTE
);
114 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MONO
);
115 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_LOUDNESS
);
116 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_STEREOENH
);
117 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_BASS_BOOST
);
118 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_BUTTON
);
119 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_DECIBELS
);
120 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_SIGNED
);
121 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_UNSIGNED
);
122 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_PERCENT
);
123 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_SLIDER
);
124 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_PAN
);
125 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_QSOUNDPAN
);
126 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_FADER
);
127 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_VOLUME
);
128 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_BASS
);
129 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_TREBLE
);
130 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_EQUALIZER
);
131 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_SINGLESELECT
);
132 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MUX
);
133 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT
);
134 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MIXER
);
135 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MICROTIME
);
136 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MILLITIME
);
139 return wine_dbg_sprintf("UNKNOWN(%08x)", dwControlType
);
142 /* A simple declaration of a line control
143 * These are each of the channels that show up
145 typedef struct line
{
146 /* Name we present to outside world */
147 WCHAR name
[MAXPNAMELEN
];
153 snd_mixer_elem_t
*elem
;
156 /* A control structure, with toggle enabled switch
157 * Control structures control volume, muted, which capture source
159 typedef struct control
{
168 WCHAR mixername
[MAXPNAMELEN
];
171 LPDRVCALLBACK callback
;
172 DWORD_PTR callbackpriv
;
179 #define MAX_MIXERS 32
180 #define CONTROLSPERLINE 3
184 static int cards
= 0;
185 static mixer mixdev
[MAX_MIXERS
];
186 static HANDLE thread
;
187 static int elem_callback(snd_mixer_elem_t
*elem
, unsigned int mask
);
188 static DWORD WINAPI
ALSA_MixerPollThread(LPVOID lParam
);
189 static CRITICAL_SECTION elem_crst
;
190 static int msg_pipe
[2];
193 /* found channel names in alsa lib, alsa api doesn't have another way for this
194 * map name -> componenttype, worst case we get a wrong componenttype which is
198 static const struct mixerlinetype
{
199 const char *name
; DWORD cmpt
;
201 { "Master", MIXERLINE_COMPONENTTYPE_DST_SPEAKERS
, },
202 { "Capture", MIXERLINE_COMPONENTTYPE_DST_WAVEIN
, },
203 { "PCM", MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT
, },
204 { "PC Speaker", MIXERLINE_COMPONENTTYPE_SRC_PCSPEAKER
, },
205 { "Synth", MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER
, },
206 { "Headphone", MIXERLINE_COMPONENTTYPE_DST_HEADPHONES
, },
207 { "Mic", MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE
, },
208 { "Aux", MIXERLINE_COMPONENTTYPE_SRC_UNDEFINED
, },
209 { "CD", MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC
, },
210 { "Line", MIXERLINE_COMPONENTTYPE_SRC_LINE
, },
211 { "Phone", MIXERLINE_COMPONENTTYPE_SRC_TELEPHONE
, },
214 /* Map name to MIXERLINE_COMPONENTTYPE_XXX */
215 static int getcomponenttype(const char *name
)
218 for (x
=0; x
< sizeof(converttable
)/sizeof(converttable
[0]); ++x
)
219 if (!strcasecmp(name
, converttable
[x
].name
))
221 TRACE("%d -> %s\n", x
, name
);
222 return converttable
[x
].cmpt
;
224 WARN("Unknown mixer name %s, probably harmless\n", name
);
225 return MIXERLINE_COMPONENTTYPE_SRC_UNDEFINED
;
228 /* Is this control suited for showing up? */
229 static int blacklisted(snd_mixer_elem_t
*elem
)
231 const char *name
= snd_mixer_selem_get_name(elem
);
234 if (!snd_mixer_selem_has_playback_volume(elem
) &&
235 (!snd_mixer_selem_has_capture_volume(elem
) ||
236 !snd_mixer_selem_has_capture_switch(elem
)))
239 TRACE("%s: %x\n", name
, blisted
);
243 static void fillcontrols(mixer
*mmixer
)
246 for (id
= 0; id
< mmixer
->chans
; ++id
)
248 line
*mline
= &mmixer
->lines
[id
];
249 int ofs
= CONTROLSPERLINE
* id
;
253 TRACE("Filling control %d\n", id
);
254 if (id
== 1 && !mline
->elem
)
257 if (mline
->capt
&& snd_mixer_selem_has_capture_volume(mline
->elem
))
258 snd_mixer_selem_get_capture_volume_range(mline
->elem
, &min
, &max
);
260 snd_mixer_selem_get_playback_volume_range(mline
->elem
, &min
, &max
);
262 /* (!snd_mixer_selem_has_playback_volume(elem) || snd_mixer_selem_has_capture_volume(elem)) */
263 /* Volume, always enabled by definition of blacklisted channels */
264 mmixer
->controls
[ofs
].enabled
= 1;
265 mmixer
->controls
[ofs
].c
.cbStruct
= sizeof(mmixer
->controls
[ofs
].c
);
266 mmixer
->controls
[ofs
].c
.dwControlType
= MIXERCONTROL_CONTROLTYPE_VOLUME
;
267 mmixer
->controls
[ofs
].c
.dwControlID
= ofs
;
268 mmixer
->controls
[ofs
].c
.Bounds
.s1
.dwMinimum
= 0;
269 mmixer
->controls
[ofs
].c
.Bounds
.s1
.dwMaximum
= 65535;
270 mmixer
->controls
[ofs
].c
.Metrics
.cSteps
= 65536/(max
-min
);
272 if ((id
== 1 && snd_mixer_selem_has_capture_switch(mline
->elem
)) ||
273 (!mline
->capt
&& snd_mixer_selem_has_playback_switch(mline
->elem
)))
274 { /* MUTE button optional, main capture channel should have one too */
275 mmixer
->controls
[ofs
+OFS_MUTE
].enabled
= 1;
276 mmixer
->controls
[ofs
+OFS_MUTE
].c
.cbStruct
= sizeof(mmixer
->controls
[ofs
].c
);
277 mmixer
->controls
[ofs
+OFS_MUTE
].c
.dwControlType
= MIXERCONTROL_CONTROLTYPE_MUTE
;
278 mmixer
->controls
[ofs
+OFS_MUTE
].c
.dwControlID
= ofs
+OFS_MUTE
;
279 mmixer
->controls
[ofs
+OFS_MUTE
].c
.Bounds
.s1
.dwMaximum
= 1;
282 if (mline
->capt
&& snd_mixer_selem_has_capture_switch_exclusive(mline
->elem
))
283 mmixer
->controls
[CONTROLSPERLINE
+OFS_MUX
].c
.dwControlType
= MIXERCONTROL_CONTROLTYPE_MUX
;
286 { /* Capture select, in case cMultipleItems is 0, it means capture is disabled anyway */
287 mmixer
->controls
[ofs
+OFS_MUX
].enabled
= 1;
288 mmixer
->controls
[ofs
+OFS_MUX
].c
.cbStruct
= sizeof(mmixer
->controls
[ofs
].c
);
289 mmixer
->controls
[ofs
+OFS_MUX
].c
.dwControlType
= MIXERCONTROL_CONTROLTYPE_MIXER
;
290 mmixer
->controls
[ofs
+OFS_MUX
].c
.dwControlID
= ofs
+OFS_MUX
;
291 mmixer
->controls
[ofs
+OFS_MUX
].c
.fdwControl
= MIXERCONTROL_CONTROLF_MULTIPLE
;
293 for (x
= 0; x
<mmixer
->chans
; ++x
)
294 if (x
!= id
&& mmixer
->lines
[x
].dst
== id
)
295 ++(mmixer
->controls
[ofs
+OFS_MUX
].c
.cMultipleItems
);
296 if (!mmixer
->controls
[ofs
+OFS_MUX
].c
.cMultipleItems
)
297 mmixer
->controls
[ofs
+OFS_MUX
].enabled
= 0;
299 mmixer
->controls
[ofs
+OFS_MUX
].c
.Bounds
.s1
.dwMaximum
= mmixer
->controls
[ofs
+OFS_MUX
].c
.cMultipleItems
- 1;
300 mmixer
->controls
[ofs
+OFS_MUX
].c
.Metrics
.cSteps
= mmixer
->controls
[ofs
+OFS_MUX
].c
.cMultipleItems
;
302 for (x
=0; x
<CONTROLSPERLINE
; ++x
)
304 lstrcpynW(mmixer
->controls
[ofs
+x
].c
.szShortName
, mline
->name
, sizeof(mmixer
->controls
[ofs
+x
].c
.szShortName
)/sizeof(WCHAR
));
305 lstrcpynW(mmixer
->controls
[ofs
+x
].c
.szName
, mline
->name
, sizeof(mmixer
->controls
[ofs
+x
].c
.szName
)/sizeof(WCHAR
));
310 /* get amount of channels for elem */
311 /* Officially we should keep capture/playback separated,
312 * but that's not going to work in the alsa api */
313 static int chans(mixer
*mmixer
, snd_mixer_elem_t
* elem
, DWORD capt
)
317 if (capt
&& snd_mixer_selem_has_capture_volume(elem
)) {
318 for (chn
= 0; chn
<= SND_MIXER_SCHN_LAST
; ++chn
)
319 if (snd_mixer_selem_has_capture_channel(elem
, chn
))
322 for (chn
= 0; chn
<= SND_MIXER_SCHN_LAST
; ++chn
)
323 if (snd_mixer_selem_has_playback_channel(elem
, chn
))
327 FIXME("Mixer channel %s was found for %s, but no channels were found? Wrong selection!\n", snd_mixer_selem_get_name(elem
), (snd_mixer_selem_has_playback_volume(elem
) ? "playback" : "capture"));
331 static void filllines(mixer
*mmixer
, snd_mixer_elem_t
*mastelem
, snd_mixer_elem_t
*captelem
, int capt
)
333 snd_mixer_elem_t
*elem
;
334 line
*mline
= mmixer
->lines
;
337 MultiByteToWideChar(CP_UNIXCP
, 0, snd_mixer_selem_get_name(mastelem
), -1, mline
->name
, sizeof(mline
->name
)/sizeof(WCHAR
));
338 mline
->component
= getcomponenttype(snd_mixer_selem_get_name(mastelem
));
341 mline
->elem
= mastelem
;
342 mline
->chans
= chans(mmixer
, mastelem
, 0);
344 snd_mixer_elem_set_callback(mastelem
, &elem_callback
);
345 snd_mixer_elem_set_callback_private(mastelem
, mmixer
);
348 * Note: since mmixer->dests = 1, it means only playback control is visible
349 * This makes sense, because if there are no capture sources capture control
350 * can't do anything and should be invisible */
352 /* Control 1 is reserved for capture even when not enabled */
356 MultiByteToWideChar(CP_UNIXCP
, 0, snd_mixer_selem_get_name(captelem
), -1, mline
->name
, sizeof(mline
->name
)/sizeof(WCHAR
));
357 mline
->component
= getcomponenttype(snd_mixer_selem_get_name(captelem
));
360 mline
->elem
= captelem
;
361 mline
->chans
= chans(mmixer
, captelem
, 1);
363 snd_mixer_elem_set_callback(captelem
, &elem_callback
);
364 snd_mixer_elem_set_callback_private(captelem
, mmixer
);
367 for (elem
= snd_mixer_first_elem(mmixer
->mix
); elem
; elem
= snd_mixer_elem_next(elem
))
368 if (elem
!= mastelem
&& elem
!= captelem
&& !blacklisted(elem
))
370 const char * name
= snd_mixer_selem_get_name(elem
);
371 DWORD comp
= getcomponenttype(name
);
373 if (snd_mixer_selem_has_playback_volume(elem
))
375 (++mline
)->component
= comp
;
376 MultiByteToWideChar(CP_UNIXCP
, 0, name
, -1, mline
->name
, MAXPNAMELEN
);
377 mline
->capt
= mline
->dst
= 0;
379 mline
->chans
= chans(mmixer
, elem
, 0);
384 if (capt
&& snd_mixer_selem_has_capture_switch(elem
))
386 (++mline
)->component
= comp
;
387 MultiByteToWideChar(CP_UNIXCP
, 0, name
, -1, mline
->name
, MAXPNAMELEN
);
388 mline
->capt
= mline
->dst
= 1;
390 mline
->chans
= chans(mmixer
, elem
, 1);
393 snd_mixer_elem_set_callback(elem
, &elem_callback
);
394 snd_mixer_elem_set_callback_private(elem
, mmixer
);
398 /* Windows api wants to have a 'master' device to which all slaves are attached
399 * There are 2 ones in this code:
400 * - 'Master', fall back to 'Headphone' if unavailable, and if that's not available 'PCM'
402 * Capture might not always be available, so should be prepared to be without if needed
405 static void ALSA_MixerInit(void)
409 for (x
= 0; x
< MAX_MIXERS
; ++x
)
411 int card
, err
, capcontrols
= 0;
412 char cardind
[6], cardname
[10];
415 snd_mixer_elem_t
*elem
, *mastelem
= NULL
, *headelem
= NULL
, *captelem
= NULL
, *pcmelem
= NULL
;
416 snd_ctl_card_info_t
*info
= NULL
;
417 snd_ctl_card_info_alloca(&info
);
419 memset(&mixdev
[mixnum
], 0, sizeof(*mixdev
));
420 snprintf(cardind
, sizeof(cardind
), "%d", x
);
421 card
= snd_card_get_index(cardind
);
425 snprintf(cardname
, sizeof(cardname
), "hw:%d", card
);
427 err
= snd_ctl_open(&ctl
, cardname
, 0);
430 WARN("Cannot open card: %s\n", snd_strerror(err
));
434 err
= snd_ctl_card_info(ctl
, info
);
437 WARN("Cannot get card info: %s\n", snd_strerror(err
));
442 MultiByteToWideChar(CP_UNIXCP
, 0, snd_ctl_card_info_get_name(info
), -1, mixdev
[mixnum
].mixername
, sizeof(mixdev
[mixnum
].mixername
)/sizeof(WCHAR
));
445 err
= snd_mixer_open(&mixdev
[mixnum
].mix
, 0);
448 WARN("Error occurred opening mixer: %s\n", snd_strerror(err
));
452 err
= snd_mixer_attach(mixdev
[mixnum
].mix
, cardname
);
456 err
= snd_mixer_selem_register(mixdev
[mixnum
].mix
, NULL
, NULL
);
460 err
= snd_mixer_load(mixdev
[mixnum
].mix
);
464 /* First, lets see what's available..
465 * If there are multiple Master or Captures, all except 1 will be added as slaves
467 for (elem
= snd_mixer_first_elem(mixdev
[mixnum
].mix
); elem
; elem
= snd_mixer_elem_next(elem
))
468 if (!strcasecmp(snd_mixer_selem_get_name(elem
), "Master") && !mastelem
)
470 else if (!strcasecmp(snd_mixer_selem_get_name(elem
), "Capture") && !captelem
)
472 else if (!blacklisted(elem
))
474 if (snd_mixer_selem_has_capture_switch(elem
))
476 if (snd_mixer_selem_has_playback_volume(elem
))
478 if (!strcasecmp(snd_mixer_selem_get_name(elem
), "Headphone") && !headelem
)
480 else if (!strcasecmp(snd_mixer_selem_get_name(elem
), "PCM") && !pcmelem
)
483 ++(mixdev
[mixnum
].chans
);
487 /* Add master channel, uncounted channels and an extra for capture */
488 mixdev
[mixnum
].chans
+= !!mastelem
+ !!headelem
+ !!pcmelem
+ 1;
490 /* If there is only 'Capture' and 'Master', this device is not worth it */
491 if (mixdev
[mixnum
].chans
== 2)
493 WARN("No channels found, skipping device!\n");
497 /* Master element can't have a capture control in this code, so
498 * if Headphone or PCM is promoted to master, unset its capture control */
499 if (headelem
&& !mastelem
)
501 /* Using 'Headphone' as master device */
503 capcontrols
-= !!snd_mixer_selem_has_capture_switch(mastelem
);
505 else if (pcmelem
&& !mastelem
)
507 /* Use 'PCM' as master device */
509 capcontrols
-= !!snd_mixer_selem_has_capture_switch(mastelem
);
513 /* If there is nothing sensible that can act as 'Master' control, something is wrong */
514 FIXME("No master control found on %s, disabling mixer\n", snd_ctl_card_info_get_name(info
));
518 if (!captelem
|| !capcontrols
)
520 /* Can't enable capture, so disabling it
521 * Note: capture control will still exist because
522 * dwLineID 0 and 1 are reserved for Master and Capture
524 WARN("No use enabling capture part of mixer, capture control found: %s, amount of capture controls: %d\n",
525 (!captelem
? "no" : "yes"), capcontrols
);
527 mixdev
[mixnum
].dests
= 1;
531 mixdev
[mixnum
].chans
+= capcontrols
;
532 mixdev
[mixnum
].dests
= 2;
535 mixdev
[mixnum
].lines
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(line
) * mixdev
[mixnum
].chans
);
536 mixdev
[mixnum
].controls
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(control
) * CONTROLSPERLINE
*mixdev
[mixnum
].chans
);
538 if (!mixdev
[mixnum
].lines
|| !mixdev
[mixnum
].controls
)
541 filllines(&mixdev
[mixnum
], mastelem
, captelem
, capcontrols
);
542 fillcontrols(&mixdev
[mixnum
]);
544 TRACE("%s: Amount of controls: %i/%i, name: %s\n", cardname
, mixdev
[mixnum
].dests
, mixdev
[mixnum
].chans
, debugstr_w(mixdev
[mixnum
].mixername
));
549 WARN("Error occurred initialising mixer: %s\n", snd_strerror(err
));
551 HeapFree(GetProcessHeap(), 0, mixdev
[mixnum
].lines
);
552 HeapFree(GetProcessHeap(), 0, mixdev
[mixnum
].controls
);
553 snd_mixer_close(mixdev
[mixnum
].mix
);
557 /* There is no trouble with already assigning callbacks without initialising critsect:
558 * Callbacks only occur when snd_mixer_handle_events is called (only happens in thread)
560 InitializeCriticalSection(&elem_crst
);
561 elem_crst
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": ALSA_MIXER.elem_crst");
565 static void ALSA_MixerExit(void)
571 WARN("Callback thread still alive, terminating uncleanly, refcnt: %d\n", refcnt
);
572 /* Least we can do is making sure we're not in 'foreign' code */
573 EnterCriticalSection(&elem_crst
);
574 TerminateThread(thread
, 1);
576 LeaveCriticalSection(&elem_crst
);
579 TRACE("Cleaning up\n");
581 elem_crst
.DebugInfo
->Spare
[0] = 0;
582 DeleteCriticalSection(&elem_crst
);
583 for (x
= 0; x
< cards
; ++x
)
585 snd_mixer_close(mixdev
[x
].mix
);
586 HeapFree(GetProcessHeap(), 0, mixdev
[x
].lines
);
587 HeapFree(GetProcessHeap(), 0, mixdev
[x
].controls
);
592 static mixer
* MIX_GetMix(UINT wDevID
)
596 if (wDevID
< 0 || wDevID
>= cards
)
598 WARN("Invalid mixer id: %d\n", wDevID
);
602 mmixer
= &mixdev
[wDevID
];
606 /* Since alsa doesn't tell what exactly changed, just assume all affected controls changed */
607 static int elem_callback(snd_mixer_elem_t
*elem
, unsigned int type
)
609 mixer
*mmixer
= snd_mixer_elem_get_callback_private(elem
);
611 BOOL captchanged
= 0;
613 if (type
!= SND_CTL_EVENT_MASK_VALUE
)
618 EnterCriticalSection(&elem_crst
);
620 if (!mmixer
->callback
)
623 for (x
=0; x
<mmixer
->chans
; ++x
)
625 const int ofs
= CONTROLSPERLINE
*x
;
626 if (elem
!= mmixer
->lines
[x
].elem
)
629 if (mmixer
->lines
[x
].capt
)
632 TRACE("Found changed control %s\n", debugstr_w(mmixer
->lines
[x
].name
));
633 mmixer
->callback(mmixer
->hmx
, MM_MIXM_LINE_CHANGE
, mmixer
->callbackpriv
, x
, 0);
634 mmixer
->callback(mmixer
->hmx
, MM_MIXM_CONTROL_CHANGE
, mmixer
->callbackpriv
, ofs
, 0);
636 if (mmixer
->controls
[ofs
+OFS_MUTE
].enabled
)
637 mmixer
->callback(mmixer
->hmx
, MM_MIXM_CONTROL_CHANGE
, mmixer
->callbackpriv
, ofs
+OFS_MUTE
, 0);
640 mmixer
->callback(mmixer
->hmx
, MM_MIXM_CONTROL_CHANGE
, mmixer
->callbackpriv
, CONTROLSPERLINE
+OFS_MUX
, 0);
643 LeaveCriticalSection(&elem_crst
);
648 static DWORD WINAPI
ALSA_MixerPollThread(LPVOID lParam
)
650 struct pollfd
*pfds
= NULL
;
651 int x
, y
, err
, mcnt
, count
= 1;
653 TRACE("%p\n", lParam
);
655 for (x
= 0; x
< cards
; ++x
)
656 count
+= snd_mixer_poll_descriptors_count(mixdev
[x
].mix
);
658 TRACE("Counted %d descriptors\n", count
);
659 pfds
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(struct pollfd
));
663 WARN("Out of memory\n");
667 pfds
[0].fd
= msg_pipe
[0];
668 pfds
[0].events
= POLLIN
;
671 for (x
= 0; x
< cards
; ++x
)
672 y
+= snd_mixer_poll_descriptors(mixdev
[x
].mix
, &pfds
[y
], count
- y
);
674 while ((err
= poll(pfds
, (unsigned int) count
, -1)) >= 0 || errno
== EINTR
|| errno
== EAGAIN
)
676 if (pfds
[0].revents
& POLLIN
)
680 for (x
= y
= 0; x
< cards
; ++x
)
682 int j
, max
= snd_mixer_poll_descriptors_count(mixdev
[x
].mix
);
683 for (j
= 0; j
< max
; ++j
)
684 if (pfds
[mcnt
+j
].revents
)
686 y
+= snd_mixer_handle_events(mixdev
[x
].mix
);
692 TRACE("Handled %d events\n", y
);
696 TRACE("Shutting down\n");
697 HeapFree(GetProcessHeap(), 0, pfds
);
699 y
= read(msg_pipe
[0], &x
, sizeof(x
));
705 static DWORD
MIX_Open(UINT wDevID
, LPMIXEROPENDESC desc
, DWORD_PTR flags
)
707 mixer
*mmixer
= MIX_GetMix(wDevID
);
709 return MMSYSERR_BADDEVICEID
;
711 flags
&= CALLBACK_TYPEMASK
;
717 case CALLBACK_FUNCTION
:
721 FIXME("Unhandled callback type: %08lx\n", flags
& CALLBACK_TYPEMASK
);
722 return MIXERR_INVALVALUE
;
725 mmixer
->callback
= (LPDRVCALLBACK
)desc
->dwCallback
;
726 mmixer
->callbackpriv
= desc
->dwInstance
;
727 mmixer
->hmx
= (HDRVR
)desc
->hmx
;
730 if (InterlockedIncrement(&refcnt
) == 1)
732 if (pipe(msg_pipe
) >= 0)
734 thread
= CreateThread(NULL
, 0, ALSA_MixerPollThread
, NULL
, 0, NULL
);
739 msg_pipe
[0] = msg_pipe
[1] = -1;
743 msg_pipe
[0] = msg_pipe
[1] = -1;
746 return MMSYSERR_NOERROR
;
749 static DWORD
MIX_Close(UINT wDevID
)
752 mixer
*mmixer
= MIX_GetMix(wDevID
);
754 return MMSYSERR_BADDEVICEID
;
756 EnterCriticalSection(&elem_crst
);
757 mmixer
->callback
= 0;
758 LeaveCriticalSection(&elem_crst
);
760 if (!InterlockedDecrement(&refcnt
))
762 if (write(msg_pipe
[1], &x
, sizeof(x
)) > 0)
764 TRACE("Shutting down thread...\n");
765 WaitForSingleObject(thread
, INFINITE
);
770 return MMSYSERR_NOERROR
;
773 static DWORD
MIX_GetDevCaps(UINT wDevID
, LPMIXERCAPS2W caps
, DWORD_PTR parm2
)
775 mixer
*mmixer
= MIX_GetMix(wDevID
);
779 return MMSYSERR_INVALPARAM
;
782 return MMSYSERR_BADDEVICEID
;
784 memset(&capsW
, 0, sizeof(MIXERCAPS2W
));
786 capsW
.wMid
= WINE_MIXER_MANUF_ID
;
787 capsW
.wPid
= WINE_MIXER_PRODUCT_ID
;
788 capsW
.vDriverVersion
= WINE_MIXER_VERSION
;
790 lstrcpynW(capsW
.szPname
, mmixer
->mixername
, sizeof(capsW
.szPname
)/sizeof(WCHAR
));
791 capsW
.cDestinations
= mmixer
->dests
;
792 memcpy(caps
, &capsW
, min(parm2
, sizeof(capsW
)));
793 return MMSYSERR_NOERROR
;
796 /* convert win32 volume to alsa volume, and vice versa */
797 static INT
normalized(INT value
, INT prevmax
, INT nextmax
)
799 int ret
= MulDiv(value
, nextmax
, prevmax
);
801 /* Have to stay in range */
802 TRACE("%d/%d -> %d/%d\n", value
, prevmax
, ret
, nextmax
);
811 /* get amount of sources for dest */
812 static int getsrccntfromchan(mixer
*mmixer
, int dad
)
816 for (i
=0; i
<mmixer
->chans
; ++i
)
817 if (i
!= dad
&& mmixer
->lines
[i
].dst
== dad
)
822 FIXME("No src found for %i (%s)?\n", dad
, debugstr_w(mmixer
->lines
[dad
].name
));
826 /* find lineid for source 'num' with dest 'dad' */
827 static int getsrclinefromchan(mixer
*mmixer
, int dad
, int num
)
830 for (i
=0; i
<mmixer
->chans
; ++i
)
831 if (i
!= dad
&& mmixer
->lines
[i
].dst
== dad
)
837 WARN("No src found for src %i from dest %i\n", num
, dad
);
841 /* get the source number belonging to line */
842 static int getsrcfromline(mixer
*mmixer
, int line
)
844 int i
, j
=0, dad
= mmixer
->lines
[line
].dst
;
846 for (i
=0; i
<mmixer
->chans
; ++i
)
847 if (i
!= dad
&& mmixer
->lines
[i
].dst
== dad
)
853 WARN("No src found for line %i with dad %i\n", line
, dad
);
857 /* Get volume/muted/capture channel */
858 static DWORD
MIX_GetControlDetails(UINT wDevID
, LPMIXERCONTROLDETAILS mctrld
, DWORD_PTR flags
)
860 mixer
*mmixer
= MIX_GetMix(wDevID
);
866 return MMSYSERR_INVALPARAM
;
868 ctrl
= mctrld
->dwControlID
;
869 line
= ctrl
/CONTROLSPERLINE
;
871 if (mctrld
->cbStruct
!= sizeof(*mctrld
))
872 return MMSYSERR_INVALPARAM
;
875 return MMSYSERR_BADDEVICEID
;
877 if (line
< 0 || line
>= mmixer
->chans
|| !mmixer
->controls
[ctrl
].enabled
)
878 return MIXERR_INVALCONTROL
;
880 ct
= &mmixer
->controls
[ctrl
];
882 flags
&= MIXER_GETCONTROLDETAILSF_QUERYMASK
;
885 case MIXER_GETCONTROLDETAILSF_VALUE
:
886 TRACE("MIXER_GETCONTROLDETAILSF_VALUE (%d/%d)\n", ctrl
, line
);
887 switch (ct
->c
.dwControlType
)
889 case MIXERCONTROL_CONTROLTYPE_VOLUME
:
891 long min
= 0, max
= 0, vol
= 0;
893 LPMIXERCONTROLDETAILS_UNSIGNED mcdu
;
894 snd_mixer_elem_t
* elem
= mmixer
->lines
[line
].elem
;
896 if (mctrld
->cbDetails
!= sizeof(MIXERCONTROLDETAILS_UNSIGNED
))
898 WARN("invalid parameter: cbDetails %d\n", mctrld
->cbDetails
);
899 return MMSYSERR_INVALPARAM
;
902 TRACE("%s MIXERCONTROLDETAILS_UNSIGNED[%u]\n", getControlType(ct
->c
.dwControlType
), mctrld
->cChannels
);
904 mcdu
= (LPMIXERCONTROLDETAILS_UNSIGNED
)mctrld
->paDetails
;
906 if (mctrld
->cChannels
!= 1 && mmixer
->lines
[line
].chans
!= mctrld
->cChannels
)
908 WARN("Unsupported cChannels (%d instead of %d)\n", mctrld
->cChannels
, mmixer
->lines
[line
].chans
);
909 return MMSYSERR_INVALPARAM
;
912 if (mmixer
->lines
[line
].capt
&& snd_mixer_selem_has_capture_volume(elem
)) {
913 snd_mixer_selem_get_capture_volume_range(elem
, &min
, &max
);
914 for (chn
= 0; chn
<= SND_MIXER_SCHN_LAST
; ++chn
)
915 if (snd_mixer_selem_has_capture_channel(elem
, chn
))
917 snd_mixer_selem_get_capture_volume(elem
, chn
, &vol
);
918 mcdu
->dwValue
= normalized(vol
- min
, max
, 65535);
919 if (mctrld
->cChannels
== 1)
924 snd_mixer_selem_get_playback_volume_range(elem
, &min
, &max
);
926 for (chn
= 0; chn
<= SND_MIXER_SCHN_LAST
; ++chn
)
927 if (snd_mixer_selem_has_playback_channel(elem
, chn
))
929 snd_mixer_selem_get_playback_volume(elem
, chn
, &vol
);
930 mcdu
->dwValue
= normalized(vol
- min
, max
, 65535);
931 if (mctrld
->cChannels
== 1)
937 return MMSYSERR_NOERROR
;
940 case MIXERCONTROL_CONTROLTYPE_ONOFF
:
941 case MIXERCONTROL_CONTROLTYPE_MUTE
:
943 LPMIXERCONTROLDETAILS_BOOLEAN mcdb
;
945 snd_mixer_elem_t
* elem
= mmixer
->lines
[line
].elem
;
947 if (mctrld
->cbDetails
!= sizeof(MIXERCONTROLDETAILS_BOOLEAN
))
949 WARN("invalid parameter: cbDetails %d\n", mctrld
->cbDetails
);
950 return MMSYSERR_INVALPARAM
;
953 TRACE("%s MIXERCONTROLDETAILS_BOOLEAN[%u]\n", getControlType(ct
->c
.dwControlType
), mctrld
->cChannels
);
955 mcdb
= (LPMIXERCONTROLDETAILS_BOOLEAN
)mctrld
->paDetails
;
958 for (chn
= 0; chn
<= SND_MIXER_SCHN_LAST
; ++chn
)
960 if (!snd_mixer_selem_has_capture_channel(elem
, chn
))
962 snd_mixer_selem_get_capture_switch(elem
, chn
, &ival
);
966 for (chn
= 0; chn
<= SND_MIXER_SCHN_LAST
; ++chn
)
968 if (!snd_mixer_selem_has_playback_channel(elem
, chn
))
970 snd_mixer_selem_get_playback_switch(elem
, chn
, &ival
);
974 mcdb
->fValue
= !ival
;
975 TRACE("=> %s\n", mcdb
->fValue
? "on" : "off");
976 return MMSYSERR_NOERROR
;
978 case MIXERCONTROL_CONTROLTYPE_MIXER
:
979 case MIXERCONTROL_CONTROLTYPE_MUX
:
981 LPMIXERCONTROLDETAILS_BOOLEAN mcdb
;
982 int x
, i
=0, ival
= 0, chn
;
984 if (mctrld
->cbDetails
!= sizeof(MIXERCONTROLDETAILS_BOOLEAN
))
986 WARN("invalid parameter: cbDetails %d\n", mctrld
->cbDetails
);
987 return MMSYSERR_INVALPARAM
;
990 TRACE("%s MIXERCONTROLDETAILS_BOOLEAN[%u]\n", getControlType(ct
->c
.dwControlType
), mctrld
->cChannels
);
992 mcdb
= (LPMIXERCONTROLDETAILS_BOOLEAN
)mctrld
->paDetails
;
994 for (x
= 0; x
<mmixer
->chans
; ++x
)
995 if (line
!= x
&& mmixer
->lines
[x
].dst
== line
)
998 for (chn
= 0; chn
<= SND_MIXER_SCHN_LAST
; ++chn
)
1000 if (!snd_mixer_selem_has_capture_channel(mmixer
->lines
[x
].elem
, chn
))
1002 snd_mixer_selem_get_capture_switch(mmixer
->lines
[x
].elem
, chn
, &ival
);
1006 if (i
>= mctrld
->u
.cMultipleItems
)
1008 TRACE("overflow\n");
1009 return MMSYSERR_INVALPARAM
;
1011 TRACE("fVal[%i] = %sselected\n", i
, (!ival
? "un" : ""));
1012 mcdb
[i
++].fValue
= ival
;
1018 FIXME("Unhandled controltype %s\n", getControlType(ct
->c
.dwControlType
));
1019 return MMSYSERR_INVALPARAM
;
1021 return MMSYSERR_NOERROR
;
1023 case MIXER_GETCONTROLDETAILSF_LISTTEXT
:
1024 TRACE("MIXER_GETCONTROLDETAILSF_LISTTEXT (%d)\n", ctrl
);
1026 if (ct
->c
.dwControlType
== MIXERCONTROL_CONTROLTYPE_MUX
|| ct
->c
.dwControlType
== MIXERCONTROL_CONTROLTYPE_MIXER
)
1028 LPMIXERCONTROLDETAILS_LISTTEXTW mcdlt
= (LPMIXERCONTROLDETAILS_LISTTEXTW
)mctrld
->paDetails
;
1031 for (i
= j
= 0; j
< mmixer
->chans
; ++j
)
1032 if (j
!= line
&& mmixer
->lines
[j
].dst
== line
)
1034 if (i
> mctrld
->u
.cMultipleItems
)
1035 return MMSYSERR_INVALPARAM
;
1036 mcdlt
->dwParam1
= j
;
1037 mcdlt
->dwParam2
= mmixer
->lines
[j
].component
;
1038 lstrcpynW(mcdlt
->szName
, mmixer
->lines
[j
].name
, sizeof(mcdlt
->szName
) / sizeof(WCHAR
));
1039 TRACE("Adding %i as %s\n", j
, debugstr_w(mcdlt
->szName
));
1042 if (i
< mctrld
->u
.cMultipleItems
)
1043 return MMSYSERR_INVALPARAM
;
1044 return MMSYSERR_NOERROR
;
1046 FIXME ("Imagine this code being horribly broken and incomplete, introducing: reality\n");
1047 return MMSYSERR_INVALPARAM
;
1050 WARN("Unknown flag (%08lx)\n", flags
);
1051 return MMSYSERR_INVALPARAM
;
1055 /* Set volume/capture channel/muted for control */
1056 static DWORD
MIX_SetControlDetails(UINT wDevID
, LPMIXERCONTROLDETAILS mctrld
, DWORD_PTR flags
)
1058 mixer
*mmixer
= MIX_GetMix(wDevID
);
1059 DWORD ctrl
, line
, i
;
1061 snd_mixer_elem_t
* elem
;
1064 return MMSYSERR_INVALPARAM
;
1066 ctrl
= mctrld
->dwControlID
;
1067 line
= ctrl
/CONTROLSPERLINE
;
1069 if (mctrld
->cbStruct
!= sizeof(*mctrld
))
1071 WARN("Invalid size of mctrld %d\n", mctrld
->cbStruct
);
1072 return MMSYSERR_INVALPARAM
;
1076 return MMSYSERR_BADDEVICEID
;
1078 if (line
< 0 || line
>= mmixer
->chans
)
1080 WARN("Invalid line id: %d not in range of 0-%d\n", line
, mmixer
->chans
-1);
1081 return MMSYSERR_INVALPARAM
;
1084 if (!mmixer
->controls
[ctrl
].enabled
)
1086 WARN("Control %d not enabled\n", ctrl
);
1087 return MIXERR_INVALCONTROL
;
1090 ct
= &mmixer
->controls
[ctrl
];
1091 elem
= mmixer
->lines
[line
].elem
;
1092 flags
&= MIXER_SETCONTROLDETAILSF_QUERYMASK
;
1095 case MIXER_SETCONTROLDETAILSF_VALUE
:
1096 TRACE("MIXER_SETCONTROLDETAILSF_VALUE (%d)\n", ctrl
);
1100 WARN("Unknown flag (%08lx)\n", flags
);
1101 return MMSYSERR_INVALPARAM
;
1104 switch (ct
->c
.dwControlType
)
1106 case MIXERCONTROL_CONTROLTYPE_VOLUME
:
1108 long min
= 0, max
= 0;
1110 LPMIXERCONTROLDETAILS_UNSIGNED mcdu
;
1111 snd_mixer_elem_t
* elem
= mmixer
->lines
[line
].elem
;
1113 if (mctrld
->cbDetails
!= sizeof(MIXERCONTROLDETAILS_UNSIGNED
))
1115 WARN("invalid parameter: cbDetails %d\n", mctrld
->cbDetails
);
1116 return MMSYSERR_INVALPARAM
;
1119 if (mctrld
->cChannels
!= 1 && mmixer
->lines
[line
].chans
!= mctrld
->cChannels
)
1121 WARN("Unsupported cChannels (%d instead of %d)\n", mctrld
->cChannels
, mmixer
->lines
[line
].chans
);
1122 return MMSYSERR_INVALPARAM
;
1125 TRACE("%s MIXERCONTROLDETAILS_UNSIGNED[%u]\n", getControlType(ct
->c
.dwControlType
), mctrld
->cChannels
);
1126 mcdu
= (LPMIXERCONTROLDETAILS_UNSIGNED
)mctrld
->paDetails
;
1128 for (chn
=0; chn
<mctrld
->cChannels
;++chn
)
1130 TRACE("Chan %d value %d\n", chn
, mcdu
[chn
].dwValue
);
1133 /* There isn't always a capture volume, so in that case change playback volume */
1134 if (mmixer
->lines
[line
].capt
&& snd_mixer_selem_has_capture_volume(elem
))
1136 snd_mixer_selem_get_capture_volume_range(elem
, &min
, &max
);
1138 for (chn
= 0; chn
<= SND_MIXER_SCHN_LAST
; ++chn
)
1139 if (snd_mixer_selem_has_capture_channel(elem
, chn
))
1141 snd_mixer_selem_set_capture_volume(elem
, chn
, min
+ normalized(mcdu
->dwValue
, 65535, max
));
1142 if (mctrld
->cChannels
!= 1)
1148 snd_mixer_selem_get_playback_volume_range(elem
, &min
, &max
);
1150 for (chn
= 0; chn
<= SND_MIXER_SCHN_LAST
; ++chn
)
1151 if (snd_mixer_selem_has_playback_channel(elem
, chn
))
1153 snd_mixer_selem_set_playback_volume(elem
, chn
, min
+ normalized(mcdu
->dwValue
, 65535, max
));
1154 if (mctrld
->cChannels
!= 1)
1161 case MIXERCONTROL_CONTROLTYPE_MUTE
:
1162 case MIXERCONTROL_CONTROLTYPE_ONOFF
:
1164 LPMIXERCONTROLDETAILS_BOOLEAN mcdb
;
1166 if (mctrld
->cbDetails
!= sizeof(MIXERCONTROLDETAILS_BOOLEAN
))
1168 WARN("invalid parameter: cbDetails %d\n", mctrld
->cbDetails
);
1169 return MMSYSERR_INVALPARAM
;
1172 TRACE("%s MIXERCONTROLDETAILS_BOOLEAN[%u]\n", getControlType(ct
->c
.dwControlType
), mctrld
->cChannels
);
1174 mcdb
= (LPMIXERCONTROLDETAILS_BOOLEAN
)mctrld
->paDetails
;
1175 if (line
== 1) /* Mute/unmute capturing */
1176 for (i
= 0; i
<= SND_MIXER_SCHN_LAST
; ++i
)
1178 if (snd_mixer_selem_has_capture_channel(elem
, i
))
1179 snd_mixer_selem_set_capture_switch(elem
, i
, !mcdb
->fValue
);
1182 for (i
= 0; i
<= SND_MIXER_SCHN_LAST
; ++i
)
1183 if (snd_mixer_selem_has_playback_channel(elem
, i
))
1184 snd_mixer_selem_set_playback_switch(elem
, i
, !mcdb
->fValue
);
1188 case MIXERCONTROL_CONTROLTYPE_MIXER
:
1189 case MIXERCONTROL_CONTROLTYPE_MUX
:
1191 LPMIXERCONTROLDETAILS_BOOLEAN mcdb
;
1193 int didone
= 0, canone
= (ct
->c
.dwControlType
== MIXERCONTROL_CONTROLTYPE_MUX
);
1195 if (mctrld
->cbDetails
!= sizeof(MIXERCONTROLDETAILS_BOOLEAN
))
1197 WARN("invalid parameter: cbDetails %d\n", mctrld
->cbDetails
);
1198 return MMSYSERR_INVALPARAM
;
1201 TRACE("%s MIXERCONTROLDETAILS_BOOLEAN[%u]\n", getControlType(ct
->c
.dwControlType
), mctrld
->cChannels
);
1202 mcdb
= (LPMIXERCONTROLDETAILS_BOOLEAN
)mctrld
->paDetails
;
1204 for (x
=i
=0; x
< mmixer
->chans
; ++x
)
1205 if (line
!= x
&& mmixer
->lines
[x
].dst
== line
)
1207 TRACE("fVal[%i] (%s) = %i\n", i
, debugstr_w(mmixer
->lines
[x
].name
), mcdb
[i
].fValue
);
1208 if (i
>= mctrld
->u
.cMultipleItems
)
1210 TRACE("Too many items to fit, overflowing\n");
1211 return MIXERR_INVALVALUE
;
1213 if (mcdb
[i
].fValue
&& canone
&& didone
)
1215 TRACE("Nice try, but it's not going to work\n");
1216 elem_callback(mmixer
->lines
[1].elem
, SND_CTL_EVENT_MASK_VALUE
);
1217 return MIXERR_INVALVALUE
;
1224 if (canone
&& !didone
)
1226 TRACE("Nice try, this is not going to work either\n");
1227 elem_callback(mmixer
->lines
[1].elem
, SND_CTL_EVENT_MASK_VALUE
);
1228 return MIXERR_INVALVALUE
;
1231 for (x
= i
= 0; x
<mmixer
->chans
; ++x
)
1232 if (line
!= x
&& mmixer
->lines
[x
].dst
== line
)
1235 for (chn
= 0; chn
<= SND_MIXER_SCHN_LAST
; ++chn
)
1237 if (!snd_mixer_selem_has_capture_channel(mmixer
->lines
[x
].elem
, chn
))
1239 snd_mixer_selem_set_capture_switch(mmixer
->lines
[x
].elem
, chn
, mcdb
[i
].fValue
);
1244 /* If it's a MUX, it means that only 1 channel can be selected
1245 * and the other channels are unselected
1247 * For MIXER multiple sources are allowed, so unselect here
1252 for (x
= i
= 0; x
<mmixer
->chans
; ++x
)
1253 if (line
!= x
&& mmixer
->lines
[x
].dst
== line
)
1255 if (!mcdb
[i
].fValue
)
1256 for (chn
= 0; chn
<= SND_MIXER_SCHN_LAST
; ++chn
)
1258 if (!snd_mixer_selem_has_capture_channel(mmixer
->lines
[x
].elem
, chn
))
1260 snd_mixer_selem_set_capture_switch(mmixer
->lines
[x
].elem
, chn
, mcdb
[i
].fValue
);
1267 FIXME("Unhandled type %s\n", getControlType(ct
->c
.dwControlType
));
1268 return MMSYSERR_INVALPARAM
;
1270 return MMSYSERR_NOERROR
;
1273 /* Here we give info over the source/dest line given by dwSource+dwDest or dwDest, respectively
1274 * It is also possible that a line is found by componenttype or target type, latter is not implemented yet
1275 * Most important values returned in struct:
1278 * line control count
1279 * amount of channels
1281 static DWORD
MIX_GetLineInfo(UINT wDevID
, LPMIXERLINEW Ml
, DWORD_PTR flags
)
1283 DWORD_PTR qf
= flags
& MIXER_GETLINEINFOF_QUERYMASK
;
1284 mixer
*mmixer
= MIX_GetMix(wDevID
);
1291 return MMSYSERR_INVALPARAM
;
1296 WARN("Device %u not found\n", wDevID
);
1297 return MMSYSERR_BADDEVICEID
;
1300 if (Ml
->cbStruct
!= sizeof(*Ml
))
1302 WARN("invalid parameter: Ml->cbStruct = %d\n", Ml
->cbStruct
);
1303 return MMSYSERR_INVALPARAM
;
1306 Ml
->fdwLine
= MIXERLINE_LINEF_ACTIVE
;
1311 case MIXER_GETLINEINFOF_COMPONENTTYPE
:
1313 Ml
->dwLineID
= 0xFFFF;
1314 for (idx
= 0; idx
< mmixer
->chans
; ++idx
)
1315 if (mmixer
->lines
[idx
].component
== Ml
->dwComponentType
)
1320 if (Ml
->dwLineID
== 0xFFFF)
1321 return MMSYSERR_KEYNOTFOUND
;
1322 /* Now that we have lineid, fallback to lineid*/
1325 case MIXER_GETLINEINFOF_LINEID
:
1326 if (Ml
->dwLineID
< 0 || Ml
->dwLineID
>= mmixer
->chans
)
1327 return MIXERR_INVALLINE
;
1329 TRACE("MIXER_GETLINEINFOF_LINEID %d\n", Ml
->dwLineID
);
1330 Ml
->dwDestination
= mmixer
->lines
[Ml
->dwLineID
].dst
;
1332 if (Ml
->dwDestination
!= Ml
->dwLineID
)
1334 Ml
->dwSource
= getsrcfromline(mmixer
, Ml
->dwLineID
);
1335 Ml
->cConnections
= 1;
1339 Ml
->cConnections
= getsrccntfromchan(mmixer
, Ml
->dwLineID
);
1340 Ml
->dwSource
= 0xFFFFFFFF;
1342 TRACE("Connections %d, source %d\n", Ml
->cConnections
, Ml
->dwSource
);
1345 case MIXER_GETLINEINFOF_DESTINATION
:
1346 if (Ml
->dwDestination
< 0 || Ml
->dwDestination
>= mmixer
->dests
)
1348 WARN("dest %d out of bounds\n", Ml
->dwDestination
);
1349 return MIXERR_INVALLINE
;
1352 Ml
->dwLineID
= Ml
->dwDestination
;
1353 Ml
->cConnections
= getsrccntfromchan(mmixer
, Ml
->dwLineID
);
1354 Ml
->dwSource
= 0xFFFFFFFF;
1357 case MIXER_GETLINEINFOF_SOURCE
:
1358 if (Ml
->dwDestination
< 0 || Ml
->dwDestination
>= mmixer
->dests
)
1360 WARN("dest %d for source out of bounds\n", Ml
->dwDestination
);
1361 return MIXERR_INVALLINE
;
1364 if (Ml
->dwSource
< 0 || Ml
->dwSource
>= getsrccntfromchan(mmixer
, Ml
->dwDestination
))
1366 WARN("src %d out of bounds\n", Ml
->dwSource
);
1367 return MIXERR_INVALLINE
;
1370 Ml
->dwLineID
= getsrclinefromchan(mmixer
, Ml
->dwDestination
, Ml
->dwSource
);
1371 Ml
->cConnections
= 1;
1374 case MIXER_GETLINEINFOF_TARGETTYPE
:
1375 FIXME("TODO: TARGETTYPE, stub\n");
1376 return MMSYSERR_INVALPARAM
;
1379 FIXME("Unknown query flag: %08lx\n", qf
);
1380 return MMSYSERR_INVALPARAM
;
1383 if (Ml
->dwLineID
>= mmixer
->dests
)
1384 Ml
->fdwLine
|= MIXERLINE_LINEF_SOURCE
;
1386 mline
= &mmixer
->lines
[Ml
->dwLineID
];
1387 Ml
->dwComponentType
= mline
->component
;
1388 Ml
->cChannels
= mmixer
->lines
[Ml
->dwLineID
].chans
;
1391 for (i
=CONTROLSPERLINE
*Ml
->dwLineID
;i
<CONTROLSPERLINE
*(Ml
->dwLineID
+1); ++i
)
1392 if (mmixer
->controls
[i
].enabled
)
1395 lstrcpynW(Ml
->szShortName
, mmixer
->lines
[Ml
->dwLineID
].name
, sizeof(Ml
->szShortName
)/sizeof(WCHAR
));
1396 lstrcpynW(Ml
->szName
, mmixer
->lines
[Ml
->dwLineID
].name
, sizeof(Ml
->szName
)/sizeof(WCHAR
));
1398 Ml
->Target
.dwType
= MIXERLINE_TARGETTYPE_WAVEIN
;
1400 Ml
->Target
.dwType
= MIXERLINE_TARGETTYPE_WAVEOUT
;
1401 Ml
->Target
.dwDeviceID
= 0xFFFFFFFF;
1402 Ml
->Target
.wMid
= WINE_MIXER_MANUF_ID
;
1403 Ml
->Target
.wPid
= WINE_MIXER_PRODUCT_ID
;
1404 Ml
->Target
.vDriverVersion
= WINE_MIXER_VERSION
;
1405 lstrcpynW(Ml
->Target
.szPname
, mmixer
->mixername
, sizeof(Ml
->Target
.szPname
)/sizeof(WCHAR
));
1406 return MMSYSERR_NOERROR
;
1409 /* Get the controls that belong to a certain line, either all or 1 */
1410 static DWORD
MIX_GetLineControls(UINT wDevID
, LPMIXERLINECONTROLSW mlc
, DWORD_PTR flags
)
1412 mixer
*mmixer
= MIX_GetMix(wDevID
);
1416 if (!mlc
|| mlc
->cbStruct
!= sizeof(*mlc
))
1418 WARN("Invalid mlc %p, cbStruct: %d\n", mlc
, (!mlc
? -1 : mlc
->cbStruct
));
1419 return MMSYSERR_INVALPARAM
;
1422 if (mlc
->cbmxctrl
!= sizeof(MIXERCONTROLW
))
1424 WARN("cbmxctrl %d\n", mlc
->cbmxctrl
);
1425 return MMSYSERR_INVALPARAM
;
1429 return MMSYSERR_BADDEVICEID
;
1431 flags
&= MIXER_GETLINECONTROLSF_QUERYMASK
;
1433 if (flags
== MIXER_GETLINECONTROLSF_ONEBYID
)
1434 mlc
->dwLineID
= mlc
->u
.dwControlID
/ CONTROLSPERLINE
;
1436 if (mlc
->dwLineID
< 0 || mlc
->dwLineID
>= mmixer
->chans
)
1438 TRACE("Invalid dwLineID %d\n", mlc
->dwLineID
);
1439 return MIXERR_INVALLINE
;
1444 case MIXER_GETLINECONTROLSF_ALL
:
1445 TRACE("line=%08x MIXER_GETLINECONTROLSF_ALL (%d)\n", mlc
->dwLineID
, mlc
->cControls
);
1446 for (i
= 0; i
< CONTROLSPERLINE
; ++i
)
1447 if (mmixer
->controls
[i
+mlc
->dwLineID
* CONTROLSPERLINE
].enabled
)
1449 memcpy(&mlc
->pamxctrl
[j
], &mmixer
->controls
[i
+mlc
->dwLineID
* CONTROLSPERLINE
].c
, sizeof(MIXERCONTROLW
));
1450 TRACE("Added %s (%s)\n", debugstr_w(mlc
->pamxctrl
[j
].szShortName
), debugstr_w(mlc
->pamxctrl
[j
].szName
));
1452 if (j
> mlc
->cControls
)
1454 WARN("invalid parameter\n");
1455 return MMSYSERR_INVALPARAM
;
1459 if (!j
|| mlc
->cControls
> j
)
1461 WARN("invalid parameter\n");
1462 return MMSYSERR_INVALPARAM
;
1465 case MIXER_GETLINECONTROLSF_ONEBYID
:
1466 TRACE("line=%08x MIXER_GETLINECONTROLSF_ONEBYID (%x)\n", mlc
->dwLineID
, mlc
->u
.dwControlID
);
1468 if (!mmixer
->controls
[mlc
->u
.dwControlID
].enabled
)
1469 return MIXERR_INVALCONTROL
;
1471 mlc
->pamxctrl
[0] = mmixer
->controls
[mlc
->u
.dwControlID
].c
;
1473 case MIXER_GETLINECONTROLSF_ONEBYTYPE
:
1474 TRACE("line=%08x MIXER_GETLINECONTROLSF_ONEBYTYPE (%s)\n", mlc
->dwLineID
, getControlType(mlc
->u
.dwControlType
));
1476 ct
= mlc
->u
.dwControlType
& MIXERCONTROL_CT_CLASS_MASK
;
1477 for (i
= 0; i
<= CONTROLSPERLINE
; ++i
)
1479 const int ofs
= i
+mlc
->dwLineID
*CONTROLSPERLINE
;
1480 if (i
== CONTROLSPERLINE
)
1482 WARN("invalid parameter: control %s not found\n", getControlType(mlc
->u
.dwControlType
));
1483 return MIXERR_INVALCONTROL
;
1485 if (mmixer
->controls
[ofs
].enabled
&& (mmixer
->controls
[ofs
].c
.dwControlType
& MIXERCONTROL_CT_CLASS_MASK
) == ct
)
1487 mlc
->pamxctrl
[0] = mmixer
->controls
[ofs
].c
;
1493 FIXME("Unknown flag %08lx\n", flags
& MIXER_GETLINECONTROLSF_QUERYMASK
);
1494 return MMSYSERR_INVALPARAM
;
1497 return MMSYSERR_NOERROR
;
1500 #endif /*HAVE_ALSA*/
1502 /**************************************************************************
1503 * mxdMessage (WINEALSA.3)
1505 DWORD WINAPI
ALSA_mxdMessage(UINT wDevID
, UINT wMsg
, DWORD_PTR dwUser
,
1506 DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
1510 TRACE("(%04X, %s, %08lX, %08lX, %08lX);\n", wDevID
, getMessage(wMsg
),
1511 dwUser
, dwParam1
, dwParam2
);
1515 case DRVM_INIT
: ALSA_MixerInit(); ret
= MMSYSERR_NOERROR
; break;
1516 case DRVM_EXIT
: ALSA_MixerExit(); ret
= MMSYSERR_NOERROR
; break;
1517 /* All taken care of by driver initialisation */
1518 /* Unimplemented, and not needed */
1521 ret
= MMSYSERR_NOERROR
; break;
1524 ret
= MIX_Open(wDevID
, (LPMIXEROPENDESC
) dwParam1
, dwParam2
); break;
1527 ret
= MIX_Close(wDevID
); break;
1529 case MXDM_GETDEVCAPS
:
1530 ret
= MIX_GetDevCaps(wDevID
, (LPMIXERCAPS2W
)dwParam1
, dwParam2
); break;
1532 case MXDM_GETLINEINFO
:
1533 ret
= MIX_GetLineInfo(wDevID
, (LPMIXERLINEW
)dwParam1
, dwParam2
); break;
1535 case MXDM_GETLINECONTROLS
:
1536 ret
= MIX_GetLineControls(wDevID
, (LPMIXERLINECONTROLSW
)dwParam1
, dwParam2
); break;
1538 case MXDM_GETCONTROLDETAILS
:
1539 ret
= MIX_GetControlDetails(wDevID
, (LPMIXERCONTROLDETAILS
)dwParam1
, dwParam2
); break;
1541 case MXDM_SETCONTROLDETAILS
:
1542 ret
= MIX_SetControlDetails(wDevID
, (LPMIXERCONTROLDETAILS
)dwParam1
, dwParam2
); break;
1544 case MXDM_GETNUMDEVS
:
1548 WARN("unknown message %s!\n", getMessage(wMsg
));
1549 return MMSYSERR_NOTSUPPORTED
;
1552 TRACE("Returning %08X\n", ret
);
1555 TRACE("(%04X, %04X, %08lX, %08lX, %08lX);\n", wDevID
, wMsg
, dwUser
, dwParam1
, dwParam2
);
1557 return MMSYSERR_NOTENABLED
;
1558 #endif /*HAVE_ALSA*/