One step closer to getting hardware accelerated capture working.
[wine] / dlls / winmm / wineoss / audio.h
1 /*
2  * Sample Wine Driver for Open Sound System (featured in Linux and FreeBSD)
3  *
4  * Copyright 1994 Martin Ayotte
5  *           1999 Eric Pouech (async playing in waveOut/waveIn)
6  *           2000 Eric Pouech (loops in waveOut)
7  *           2002 Eric Pouech (full duplex)
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #ifdef HAVE_OSS
25
26 /* unless someone makes a wineserver kernel module, Unix pipes are faster than win32 events */
27 #define USE_PIPE_SYNC
28
29 #define MAX_WAVEDRV     (6)
30
31 /* states of the playing device */
32 #define WINE_WS_PLAYING         0
33 #define WINE_WS_PAUSED          1
34 #define WINE_WS_STOPPED         2
35 #define WINE_WS_CLOSED          3
36
37 /* events to be send to device */
38 enum win_wm_message {
39     WINE_WM_PAUSING = WM_USER + 1, WINE_WM_RESTARTING, WINE_WM_RESETTING, WINE_WM_HEADER,
40     WINE_WM_UPDATE, WINE_WM_BREAKLOOP, WINE_WM_CLOSING, WINE_WM_STARTING, WINE_WM_STOPPING
41 };
42
43 #ifdef USE_PIPE_SYNC
44 #define SIGNAL_OMR(omr) do { int x = 0; write((omr)->msg_pipe[1], &x, sizeof(x)); } while (0)
45 #define CLEAR_OMR(omr) do { int x = 0; read((omr)->msg_pipe[0], &x, sizeof(x)); } while (0)
46 #define RESET_OMR(omr) do { } while (0)
47 #define WAIT_OMR(omr, sleep) \
48   do { struct pollfd pfd; pfd.fd = (omr)->msg_pipe[0]; \
49        pfd.events = POLLIN; poll(&pfd, 1, sleep); } while (0)
50 #else
51 #define SIGNAL_OMR(omr) do { SetEvent((omr)->msg_event); } while (0)
52 #define CLEAR_OMR(omr) do { } while (0)
53 #define RESET_OMR(omr) do { ResetEvent((omr)->msg_event); } while (0)
54 #define WAIT_OMR(omr, sleep) \
55   do { WaitForSingleObject((omr)->msg_event, sleep); } while (0)
56 #endif
57
58 typedef struct {
59     enum win_wm_message         msg;    /* message identifier */
60     DWORD                       param;  /* parameter for this message */
61     HANDLE                      hEvent; /* if message is synchronous, handle of event for synchro */
62 } OSS_MSG;
63
64 /* implement an in-process message ring for better performance
65  * (compared to passing thru the server)
66  * this ring will be used by the input (resp output) record (resp playback) routine
67  */
68 #define OSS_RING_BUFFER_INCREMENT       64
69 typedef struct {
70     int                         ring_buffer_size;
71     OSS_MSG                     * messages;
72     int                         msg_tosave;
73     int                         msg_toget;
74 #ifdef USE_PIPE_SYNC
75     int                         msg_pipe[2];
76 #else
77     HANDLE                      msg_event;
78 #endif
79     CRITICAL_SECTION            msg_crst;
80 } OSS_MSG_RING;
81
82 typedef struct tagOSS_DEVICE {
83     char*                       dev_name;
84     char*                       mixer_name;
85     char*                       interface_name;
86     unsigned                    open_count;
87     WAVEOUTCAPSA                out_caps;
88     WAVEOUTCAPSA                duplex_out_caps;
89     WAVEINCAPSA                 in_caps;
90     DWORD                       in_caps_support;
91     unsigned                    open_access;
92     int                         fd;
93     DWORD                       owner_tid;
94     int                         sample_rate;
95     int                         stereo;
96     int                         format;
97     unsigned                    audio_fragment;
98     BOOL                        full_duplex;
99     BOOL                        bTriggerSupport;
100     BOOL                        bOutputEnabled;
101     BOOL                        bInputEnabled;
102     DSDRIVERDESC                ds_desc;
103     DSDRIVERCAPS                ds_caps;
104     DSCDRIVERCAPS               dsc_caps;
105 } OSS_DEVICE;
106
107 typedef struct {
108     OSS_DEVICE*                 ossdev;
109     volatile int                state;                  /* one of the WINE_WS_ manifest constants */
110     WAVEOPENDESC                waveDesc;
111     WORD                        wFlags;
112     WAVEFORMATPCMEX             waveFormat;
113     DWORD                       volume;
114
115     /* OSS information */
116     DWORD                       dwFragmentSize;         /* size of OSS buffer fragment */
117     DWORD                       dwBufferSize;           /* size of whole OSS buffer in bytes */
118     LPWAVEHDR                   lpQueuePtr;             /* start of queued WAVEHDRs (waiting to be notified) */
119     LPWAVEHDR                   lpPlayPtr;              /* start of not yet fully played buffers */
120     DWORD                       dwPartialOffset;        /* Offset of not yet written bytes in lpPlayPtr */
121
122     LPWAVEHDR                   lpLoopPtr;              /* pointer of first buffer in loop, if any */
123     DWORD                       dwLoops;                /* private copy of loop counter */
124
125     DWORD                       dwPlayedTotal;          /* number of bytes actually played since opening */
126     DWORD                       dwWrittenTotal;         /* number of bytes written to OSS buffer since opening */
127     BOOL                        bNeedPost;              /* whether audio still needs to be physically started */
128
129     /* synchronization stuff */
130     HANDLE                      hStartUpEvent;
131     HANDLE                      hThread;
132     DWORD                       dwThreadID;
133     OSS_MSG_RING                msgRing;
134 } WINE_WAVEOUT;
135
136 typedef struct {
137     OSS_DEVICE*                 ossdev;
138     volatile int                state;
139     DWORD                       dwFragmentSize;         /* OpenSound '/dev/dsp' give us that size */
140     WAVEOPENDESC                waveDesc;
141     WORD                        wFlags;
142     WAVEFORMATPCMEX             waveFormat;
143     LPWAVEHDR                   lpQueuePtr;
144     DWORD                       dwTotalRecorded;
145     DWORD                       dwTotalRead;
146
147     /* synchronization stuff */
148     HANDLE                      hThread;
149     DWORD                       dwThreadID;
150     HANDLE                      hStartUpEvent;
151     OSS_MSG_RING                msgRing;
152 } WINE_WAVEIN;
153
154 extern OSS_DEVICE       OSS_Devices[MAX_WAVEDRV];
155 extern WINE_WAVEOUT     WOutDev[MAX_WAVEDRV];
156 extern WINE_WAVEIN      WInDev[MAX_WAVEDRV];
157 extern unsigned         numOutDev;
158 extern unsigned         numInDev;
159
160 extern int getEnables(OSS_DEVICE *ossdev);
161 extern void copy_format(LPWAVEFORMATEX wf1, LPWAVEFORMATPCMEX wf2);
162
163 extern DWORD OSS_OpenDevice(OSS_DEVICE* ossdev, unsigned req_access,
164                             int* frag, int strict_format,
165                             int sample_rate, int stereo, int fmt);
166
167 extern void OSS_CloseDevice(OSS_DEVICE* ossdev);
168
169 extern DWORD wodOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags);
170 extern DWORD wodSetVolume(WORD wDevID, DWORD dwParam);
171 extern DWORD widOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags);
172
173 /* dscapture.c */
174 extern DWORD widDsCreate(UINT wDevID, PIDSCDRIVER* drv);
175 extern DWORD widDsDesc(UINT wDevID, PDSDRIVERDESC desc);
176
177 /* dsrender.c */
178 extern DWORD wodDsCreate(UINT wDevID, PIDSDRIVER* drv);
179 extern DWORD wodDsDesc(UINT wDevID, PDSDRIVERDESC desc);
180
181 #endif /* HAVE_OSS */