d3d9/tests: Add a test for 0 width / height surface creation.
[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 #if defined(HAVE_ALSA) && !defined(__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 #include "mmreg.h"
47 #include "dsound.h"
48 #include "dsdriver.h"
49
50 #include "ks.h"
51 #include "ksmedia.h"
52 #include "ksguid.h"
53
54 /* state diagram for waveOut writing:
55  *
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  * +---------+-------------+---------------+---------------------------------+
69  */
70
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
76
77 /* events to be send to device */
78 enum win_wm_message {
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
81 };
82
83 typedef struct {
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 */
87 } ALSA_MSG;
88
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
92  */
93 typedef struct {
94     ALSA_MSG                    * messages;
95     int                         ring_buffer_size;
96     int                         msg_tosave;
97     int                         msg_toget;
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 */
100     int                         msg_pipe[2];
101     HANDLE                      msg_event;
102     CRITICAL_SECTION            msg_crst;
103 } ALSA_MSG_RING;
104
105 typedef struct {
106     volatile int                state;                  /* one of the WINE_WS_ manifest constants */
107     WAVEOPENDESC                waveDesc;
108     WORD                        wFlags;
109     WAVEFORMATPCMEX             format;
110
111     char*                       pcmname;                /* string name of alsa PCM device */
112     char*                       ctlname;                /* string name of alsa control device */
113     char                        interface_name[MAXPNAMELEN * 2];
114
115     snd_pcm_t*                  pcm;                    /* handle to ALSA playback device */
116
117     snd_pcm_hw_params_t *       hw_params;
118
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 */
122
123     LPWAVEHDR                   lpLoopPtr;              /* pointer of first buffer in loop, if any */
124     DWORD                       dwLoops;                /* private copy of loop counter */
125
126     DWORD                       dwPlayedTotal;          /* number of bytes actually played since opening */
127     DWORD                       dwWrittenTotal;         /* number of bytes written to ALSA buffer since opening */
128
129     /* synchronization stuff */
130     HANDLE                      hStartUpEvent;
131     HANDLE                      hThread;
132     DWORD                       dwThreadID;
133     ALSA_MSG_RING               msgRing;
134
135     /* DirectSound stuff */
136     DSDRIVERDESC                ds_desc;
137     DSDRIVERCAPS                ds_caps;
138
139     /* Waveout only fields */
140     WAVEOUTCAPSW                outcaps;
141
142     snd_hctl_t *                hctl;                    /* control handle for the playback volume */
143
144     snd_pcm_sframes_t           (*write)(snd_pcm_t *, const void *, snd_pcm_uframes_t );
145
146     DWORD                       dwPartialOffset;        /* Offset of not yet written bytes in lpPlayPtr */
147
148     /* Wavein only fields */
149
150     WAVEINCAPSW                 incaps;
151     DWORD                       dwSupport;
152
153     snd_pcm_sframes_t           (*read)(snd_pcm_t *, void *, snd_pcm_uframes_t );
154
155     DWORD                       dwPeriodSize;           /* size of OSS buffer period */
156     DWORD                       dwTotalRecorded;
157
158 }   WINE_WAVEDEV;
159
160 /*----------------------------------------------------------------------------
161 **  Global array of output and input devices, initialized via ALSA_WaveInit
162 */
163 #define WAVEDEV_ALLOC_EXTENT_SIZE       10
164
165 /* wavein.c */
166 extern WINE_WAVEDEV     *WInDev;
167 extern DWORD            ALSA_WidNumMallocedDevs;
168 extern DWORD            ALSA_WidNumDevs;
169
170 /* waveout.c */
171 extern WINE_WAVEDEV     *WOutDev;
172 extern DWORD            ALSA_WodNumMallocedDevs;
173 extern DWORD            ALSA_WodNumDevs;
174
175 /* alsa.c */
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);
183
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);
193
194 /* dscapture.c */
195 DWORD widDsCreate(UINT wDevID, PIDSCDRIVER* drv);
196 DWORD widDsDesc(UINT wDevID, PDSDRIVERDESC desc);
197
198 /* dsoutput.c */
199 DWORD wodDsCreate(UINT wDevID, PIDSDRIVER* drv);
200 DWORD wodDsDesc(UINT wDevID, PDSDRIVERDESC desc);
201
202 /* waveinit.c */
203 extern void ALSA_WaveInit(void);
204
205 #endif /* __ALSA_H */