1 /* Definition for ALSA drivers : wine multimedia system
3 * Copyright (C) 2002 Erich Pouech
4 * Copyright (C) 2002 Marco Pietrobono
5 * Copyright (C) 2003 Christian Costa
6 * Copyright (C) 2007 Maarten Lankhorst
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #ifndef __WINE_CONFIG_H
24 # error You must include config.h to use this header
27 #if defined(HAVE_ALSA) && !defined(__ALSA_H)
34 #define ALSA_PCM_NEW_HW_PARAMS_API
35 #define ALSA_PCM_NEW_SW_PARAMS_API
37 #ifdef HAVE_ALSA_ASOUNDLIB_H
38 #include <alsa/asoundlib.h>
39 #elif defined(HAVE_SYS_ASOUNDLIB_H)
40 #include <sys/asoundlib.h>
42 #ifdef HAVE_SYS_ERRNO_H
43 #include <sys/errno.h>
54 /* state diagram for waveOut writing:
56 * +---------+-------------+---------------+---------------------------------+
57 * | state | function | event | new state |
58 * +---------+-------------+---------------+---------------------------------+
59 * | | open() | | STOPPED |
60 * | PAUSED | write() | | PAUSED |
61 * | STOPPED | write() | <thrd create> | PLAYING |
62 * | PLAYING | write() | HEADER | PLAYING |
63 * | (other) | write() | <error> | |
64 * | (any) | pause() | PAUSING | PAUSED |
65 * | PAUSED | restart() | RESTARTING | PLAYING (if no thrd => STOPPED) |
66 * | (any) | reset() | RESETTING | STOPPED |
67 * | (any) | close() | CLOSING | CLOSED |
68 * +---------+-------------+---------------+---------------------------------+
71 /* states of the playing device */
72 #define WINE_WS_PLAYING 0
73 #define WINE_WS_PAUSED 1
74 #define WINE_WS_STOPPED 2
75 #define WINE_WS_CLOSED 3
77 /* events to be send to device */
79 WINE_WM_PAUSING
= WM_USER
+ 1, WINE_WM_RESTARTING
, WINE_WM_RESETTING
, WINE_WM_HEADER
,
80 WINE_WM_UPDATE
, WINE_WM_BREAKLOOP
, WINE_WM_CLOSING
, WINE_WM_STARTING
, WINE_WM_STOPPING
84 enum win_wm_message msg
; /* message identifier */
85 DWORD_PTR param
; /* parameter for this message */
86 HANDLE hEvent
; /* if message is synchronous, handle of event for synchro */
89 /* implement an in-process message ring for better performance
90 * (compared to passing thru the server)
91 * this ring will be used by the input (resp output) record (resp playback) routine
98 /* Either pipe or event is used, but that is defined in alsa.c,
99 * since this is a global header we define both here */
102 CRITICAL_SECTION msg_crst
;
106 volatile int state
; /* one of the WINE_WS_ manifest constants */
107 WAVEOPENDESC waveDesc
;
109 WAVEFORMATPCMEX format
;
111 char* pcmname
; /* string name of alsa PCM device */
112 char* ctlname
; /* string name of alsa control device */
113 char interface_name
[MAXPNAMELEN
* 2];
115 snd_pcm_t
* pcm
; /* handle to ALSA playback device */
117 snd_pcm_hw_params_t
* hw_params
;
119 DWORD dwBufferSize
; /* size of whole ALSA buffer in bytes */
120 LPWAVEHDR lpQueuePtr
; /* start of queued WAVEHDRs (waiting to be notified) */
121 LPWAVEHDR lpPlayPtr
; /* start of not yet fully played buffers */
123 LPWAVEHDR lpLoopPtr
; /* pointer of first buffer in loop, if any */
124 DWORD dwLoops
; /* private copy of loop counter */
126 DWORD dwPlayedTotal
; /* number of bytes actually played since opening */
127 DWORD dwWrittenTotal
; /* number of bytes written to ALSA buffer since opening */
129 /* synchronization stuff */
130 HANDLE hStartUpEvent
;
133 ALSA_MSG_RING msgRing
;
135 /* DirectSound stuff */
136 DSDRIVERDESC ds_desc
;
137 DSDRIVERCAPS ds_caps
;
139 /* Waveout only fields */
140 WAVEOUTCAPSW outcaps
;
142 snd_hctl_t
* hctl
; /* control handle for the playback volume */
144 snd_pcm_sframes_t (*write
)(snd_pcm_t
*, const void *, snd_pcm_uframes_t
);
146 DWORD dwPartialOffset
; /* Offset of not yet written bytes in lpPlayPtr */
148 /* Wavein only fields */
153 snd_pcm_sframes_t (*read
)(snd_pcm_t
*, void *, snd_pcm_uframes_t
);
155 DWORD dwPeriodSize
; /* size of OSS buffer period */
156 DWORD dwTotalRecorded
;
160 /*----------------------------------------------------------------------------
161 ** Global array of output and input devices, initialized via ALSA_WaveInit
163 #define WAVEDEV_ALLOC_EXTENT_SIZE 10
166 extern WINE_WAVEDEV
*WInDev
;
167 extern DWORD ALSA_WidNumMallocedDevs
;
168 extern DWORD ALSA_WidNumDevs
;
171 extern WINE_WAVEDEV
*WOutDev
;
172 extern DWORD ALSA_WodNumMallocedDevs
;
173 extern DWORD ALSA_WodNumDevs
;
176 int ALSA_InitRingMessage(ALSA_MSG_RING
* omr
);
177 int ALSA_DestroyRingMessage(ALSA_MSG_RING
* omr
);
178 void ALSA_ResetRingMessage(ALSA_MSG_RING
* omr
);
179 void ALSA_WaitRingMessage(ALSA_MSG_RING
* omr
, DWORD sleep
);
180 int ALSA_AddRingMessage(ALSA_MSG_RING
* omr
, enum win_wm_message msg
, DWORD_PTR param
, BOOL wait
);
181 int ALSA_RetrieveRingMessage(ALSA_MSG_RING
* omr
, enum win_wm_message
*msg
, DWORD_PTR
*param
, HANDLE
*hEvent
);
182 int ALSA_CheckSetVolume(snd_hctl_t
*hctl
, int *out_left
, int *out_right
, int *out_min
, int *out_max
, int *out_step
, int *new_left
, int *new_right
);
184 const char * ALSA_getCmdString(enum win_wm_message msg
);
185 const char * ALSA_getMessage(UINT msg
);
186 const char * ALSA_getFormat(WORD wFormatTag
);
187 BOOL
ALSA_NearMatch(int rate1
, int rate2
);
188 DWORD
ALSA_bytes_to_mmtime(LPMMTIME lpTime
, DWORD position
, WAVEFORMATPCMEX
* format
);
189 void ALSA_TraceParameters(snd_pcm_hw_params_t
* hw_params
, snd_pcm_sw_params_t
* sw
, int full
);
190 int wine_snd_pcm_recover(snd_pcm_t
*pcm
, int err
, int silent
);
191 void ALSA_copyFormat(LPWAVEFORMATEX wf1
, LPWAVEFORMATPCMEX wf2
);
192 BOOL
ALSA_supportedFormat(LPWAVEFORMATEX wf
);
195 DWORD
widDsCreate(UINT wDevID
, PIDSCDRIVER
* drv
);
196 DWORD
widDsDesc(UINT wDevID
, PDSDRIVERDESC desc
);
199 DWORD
wodDsCreate(UINT wDevID
, PIDSDRIVER
* drv
);
200 DWORD
wodDsDesc(UINT wDevID
, PDSDRIVERDESC desc
);
203 extern void ALSA_WaveInit(void);
205 #endif /* __ALSA_H */