gdi32: Implement PaintRgn().
[wine] / dlls / winealsa.drv / alsa.h
1 /* Definition for ALSA drivers : wine multimedia system
2  *
3  * Copyright (C) 2002 Erich Pouech
4  * Copyright (C) 2002 Marco Pietrobono
5  * Copyright (C) 2003 Christian Costa
6  * Copyright (C) 2007 Maarten Lankhorst
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #ifndef __WINE_CONFIG_H
24 # error You must include config.h to use this header
25 #endif
26
27 #ifndef __ALSA_H
28 #define __ALSA_H
29
30 #ifdef interface
31 #undef interface
32 #endif
33
34 #define ALSA_PCM_NEW_HW_PARAMS_API
35 #define ALSA_PCM_NEW_SW_PARAMS_API
36
37 #ifdef HAVE_ALSA_ASOUNDLIB_H
38 #include <alsa/asoundlib.h>
39 #elif defined(HAVE_SYS_ASOUNDLIB_H)
40 #include <sys/asoundlib.h>
41 #endif
42 #ifdef HAVE_SYS_ERRNO_H
43 #include <sys/errno.h>
44 #endif
45
46 /* state diagram for waveOut writing:
47  *
48  * +---------+-------------+---------------+---------------------------------+
49  * |  state  |  function   |     event     |            new state            |
50  * +---------+-------------+---------------+---------------------------------+
51  * |         | open()      |               | STOPPED                         |
52  * | PAUSED  | write()     |               | PAUSED                          |
53  * | STOPPED | write()     | <thrd create> | PLAYING                         |
54  * | PLAYING | write()     | HEADER        | PLAYING                         |
55  * | (other) | write()     | <error>       |                                 |
56  * | (any)   | pause()     | PAUSING       | PAUSED                          |
57  * | PAUSED  | restart()   | RESTARTING    | PLAYING (if no thrd => STOPPED) |
58  * | (any)   | reset()     | RESETTING     | STOPPED                         |
59  * | (any)   | close()     | CLOSING       | CLOSED                          |
60  * +---------+-------------+---------------+---------------------------------+
61  */
62
63 /* states of the playing device */
64 #define WINE_WS_PLAYING         0
65 #define WINE_WS_PAUSED          1
66 #define WINE_WS_STOPPED         2
67 #define WINE_WS_CLOSED          3
68
69 /* events to be send to device */
70 enum win_wm_message {
71     WINE_WM_PAUSING = WM_USER + 1, WINE_WM_RESTARTING, WINE_WM_RESETTING, WINE_WM_HEADER,
72     WINE_WM_UPDATE, WINE_WM_BREAKLOOP, WINE_WM_CLOSING, WINE_WM_STARTING, WINE_WM_STOPPING
73 };
74
75 typedef struct {
76     enum win_wm_message msg; /* message identifier */
77     DWORD_PTR param;         /* parameter for this message */
78     HANDLE hEvent;           /* if message is synchronous, handle of event for synchro */
79 } ALSA_MSG;
80
81 /* implement an in-process message ring for better performance
82  * (compared to passing thru the server)
83  * this ring will be used by the input (resp output) record (resp playback) routine
84  */
85 typedef struct {
86     ALSA_MSG                    * messages;
87     int                         ring_buffer_size;
88     int                         msg_tosave;
89     int                         msg_toget;
90 /* Either pipe or event is used, but that is defined in alsa.c,
91  * since this is a global header we define both here */
92     int                         msg_pipe[2];
93     HANDLE                      msg_event;
94     CRITICAL_SECTION            msg_crst;
95 } ALSA_MSG_RING;
96
97 typedef struct {
98     volatile int                state;                  /* one of the WINE_WS_ manifest constants */
99     WAVEOPENDESC                waveDesc;
100     WORD                        wFlags;
101     WAVEFORMATPCMEX             format;
102
103     char*                       pcmname;                /* string name of alsa PCM device */
104     char*                       ctlname;                /* string name of alsa control device */
105     char                        interface_name[MAXPNAMELEN * 2];
106
107     snd_pcm_t*                  pcm;                    /* handle to ALSA playback device */
108
109     snd_pcm_hw_params_t *       hw_params;
110
111     DWORD                       dwBufferSize;           /* size of whole ALSA buffer in bytes */
112     LPWAVEHDR                   lpQueuePtr;             /* start of queued WAVEHDRs (waiting to be notified) */
113     LPWAVEHDR                   lpPlayPtr;              /* start of not yet fully played buffers */
114
115     LPWAVEHDR                   lpLoopPtr;              /* pointer of first buffer in loop, if any */
116     DWORD                       dwLoops;                /* private copy of loop counter */
117
118     DWORD                       dwPlayedTotal;          /* number of bytes actually played since opening */
119     DWORD                       dwWrittenTotal;         /* number of bytes written to ALSA buffer since opening */
120
121     /* synchronization stuff */
122     HANDLE                      hStartUpEvent;
123     HANDLE                      hThread;
124     DWORD                       dwThreadID;
125     ALSA_MSG_RING               msgRing;
126
127     /* DirectSound stuff */
128     DSDRIVERDESC                ds_desc;
129     DSDRIVERCAPS                ds_caps;
130
131     /* Waveout only fields */
132     WAVEOUTCAPSW                outcaps;
133
134     snd_hctl_t *                hctl;                    /* control handle for the playback volume */
135
136     snd_pcm_sframes_t           (*write)(snd_pcm_t *, const void *, snd_pcm_uframes_t );
137
138     DWORD                       dwPartialOffset;        /* Offset of not yet written bytes in lpPlayPtr */
139
140     /* Wavein only fields */
141
142     WAVEINCAPSW                 incaps;
143     DWORD                       dwSupport;
144
145     snd_pcm_sframes_t           (*read)(snd_pcm_t *, void *, snd_pcm_uframes_t );
146
147     DWORD                       dwPeriodSize;           /* size of OSS buffer period */
148     DWORD                       dwTotalRecorded;
149
150 }   WINE_WAVEDEV;
151
152 /*----------------------------------------------------------------------------
153 **  Global array of output and input devices, initialized via ALSA_WaveInit
154 */
155 #define WAVEDEV_ALLOC_EXTENT_SIZE       10
156
157 /* wavein.c */
158 extern WINE_WAVEDEV     *WInDev;
159 extern DWORD            ALSA_WidNumMallocedDevs;
160 extern DWORD            ALSA_WidNumDevs;
161
162 /* waveout.c */
163 extern WINE_WAVEDEV     *WOutDev;
164 extern DWORD            ALSA_WodNumMallocedDevs;
165 extern DWORD            ALSA_WodNumDevs;
166
167 /* alsa.c */
168 int     ALSA_InitRingMessage(ALSA_MSG_RING* omr);
169 int     ALSA_DestroyRingMessage(ALSA_MSG_RING* omr);
170 void    ALSA_ResetRingMessage(ALSA_MSG_RING* omr);
171 void    ALSA_WaitRingMessage(ALSA_MSG_RING* omr, DWORD sleep);
172 int     ALSA_AddRingMessage(ALSA_MSG_RING* omr, enum win_wm_message msg, DWORD_PTR param, BOOL wait);
173 int     ALSA_RetrieveRingMessage(ALSA_MSG_RING* omr, enum win_wm_message *msg, DWORD_PTR *param, HANDLE *hEvent);
174 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);
175
176 const char * ALSA_getCmdString(enum win_wm_message msg);
177 const char * ALSA_getMessage(UINT msg);
178 const char * ALSA_getFormat(WORD wFormatTag);
179 BOOL    ALSA_NearMatch(int rate1, int rate2);
180 DWORD   ALSA_bytes_to_mmtime(LPMMTIME lpTime, DWORD position, WAVEFORMATPCMEX* format);
181 void    ALSA_TraceParameters(snd_pcm_hw_params_t * hw_params, snd_pcm_sw_params_t * sw, int full);
182 int     wine_snd_pcm_recover(snd_pcm_t *pcm, int err, int silent);
183 void    ALSA_copyFormat(LPWAVEFORMATEX wf1, LPWAVEFORMATPCMEX wf2);
184 BOOL    ALSA_supportedFormat(LPWAVEFORMATEX wf);
185
186 /* dscapture.c */
187 DWORD widDsCreate(UINT wDevID, PIDSCDRIVER* drv);
188 DWORD widDsDesc(UINT wDevID, PDSDRIVERDESC desc);
189
190 /* dsoutput.c */
191 DWORD wodDsCreate(UINT wDevID, PIDSDRIVER* drv);
192 DWORD wodDsDesc(UINT wDevID, PDSDRIVERDESC desc);
193
194 /* waveinit.c */
195 extern void ALSA_WaveInit(void);
196
197 #endif /* __ALSA_H */