1 | /* $Id: DrvAudio.h 59470 2016-01-26 11:32:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Intermediate audio driver header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2016 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | * --------------------------------------------------------------------
|
---|
17 | *
|
---|
18 | * This code is based on: audio.h
|
---|
19 | *
|
---|
20 | * QEMU Audio subsystem header
|
---|
21 | *
|
---|
22 | * Copyright (c) 2003-2005 Vassili Karpov (malc)
|
---|
23 | *
|
---|
24 | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
---|
25 | * of this software and associated documentation files (the "Software"), to deal
|
---|
26 | * in the Software without restriction, including without limitation the rights
|
---|
27 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
28 | * copies of the Software, and to permit persons to whom the Software is
|
---|
29 | * furnished to do so, subject to the following conditions:
|
---|
30 | *
|
---|
31 | * The above copyright notice and this permission notice shall be included in
|
---|
32 | * all copies or substantial portions of the Software.
|
---|
33 | *
|
---|
34 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
35 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
36 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
---|
37 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
---|
38 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
---|
39 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
---|
40 | * THE SOFTWARE.
|
---|
41 | */
|
---|
42 |
|
---|
43 | #ifndef DRV_AUDIO_H
|
---|
44 | #define DRV_AUDIO_H
|
---|
45 |
|
---|
46 | #include <limits.h>
|
---|
47 |
|
---|
48 | #include <iprt/circbuf.h>
|
---|
49 | #include <iprt/critsect.h>
|
---|
50 |
|
---|
51 | #include <VBox/vmm/pdmdev.h>
|
---|
52 | #include <VBox/vmm/pdm.h>
|
---|
53 | #include <VBox/vmm/pdmaudioifs.h>
|
---|
54 |
|
---|
55 | typedef enum
|
---|
56 | {
|
---|
57 | AUD_OPT_INT,
|
---|
58 | AUD_OPT_FMT,
|
---|
59 | AUD_OPT_STR,
|
---|
60 | AUD_OPT_BOOL
|
---|
61 | } audio_option_tag_e;
|
---|
62 |
|
---|
63 | typedef struct audio_option
|
---|
64 | {
|
---|
65 | const char *name;
|
---|
66 | audio_option_tag_e tag;
|
---|
67 | void *valp;
|
---|
68 | const char *descr;
|
---|
69 | int *overridenp;
|
---|
70 | int overriden;
|
---|
71 | } audio_option;
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * Audio driver instance data.
|
---|
75 | *
|
---|
76 | * @implements PDMIAUDIOCONNECTOR
|
---|
77 | */
|
---|
78 | typedef struct DRVAUDIO
|
---|
79 | {
|
---|
80 | /** Input/output processing thread. */
|
---|
81 | RTTHREAD hThread;
|
---|
82 | /** Critical section for serializing access. */
|
---|
83 | RTCRITSECT CritSect;
|
---|
84 | /** Shutdown indicator. */
|
---|
85 | bool fTerminate;
|
---|
86 | /** Our audio connector interface. */
|
---|
87 | PDMIAUDIOCONNECTOR IAudioConnector;
|
---|
88 | /** Pointer to the driver instance. */
|
---|
89 | PPDMDRVINS pDrvIns;
|
---|
90 | /** Pointer to audio driver below us. */
|
---|
91 | PPDMIHOSTAUDIO pHostDrvAudio;
|
---|
92 | /** List of host input streams. */
|
---|
93 | RTLISTANCHOR lstHstStrmIn;
|
---|
94 | /** List of host output streams. */
|
---|
95 | RTLISTANCHOR lstHstStrmOut;
|
---|
96 | /** Max. number of free input streams.
|
---|
97 | * UINT32_MAX for unlimited streams. */
|
---|
98 | uint32_t cFreeInputStreams;
|
---|
99 | /** Max. number of free output streams.
|
---|
100 | * UINT32_MAX for unlimited streams. */
|
---|
101 | uint32_t cFreeOutputStreams;
|
---|
102 | /** Audio configuration settings retrieved from the backend. */
|
---|
103 | PDMAUDIOBACKENDCFG BackendCfg;
|
---|
104 | #ifdef VBOX_WITH_AUDIO_CALLBACKS
|
---|
105 | /** @todo Use a map with primary key set to the callback type? */
|
---|
106 | RTLISTANCHOR lstCBIn;
|
---|
107 | RTLISTANCHOR lstCBOut;
|
---|
108 | #endif
|
---|
109 | } DRVAUDIO, *PDRVAUDIO;
|
---|
110 |
|
---|
111 | /** Makes a PDRVAUDIO out of a PPDMIAUDIOCONNECTOR. */
|
---|
112 | #define PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface) \
|
---|
113 | ( (PDRVAUDIO)((uintptr_t)pInterface - RT_OFFSETOF(DRVAUDIO, IAudioConnector)) )
|
---|
114 |
|
---|
115 | //const char *drvAudioHlpFormatToString(PDMAUDIOFMT fmt);
|
---|
116 | const char *drvAudioRecSourceToString(PDMAUDIORECSOURCE enmRecSource);
|
---|
117 | PDMAUDIOFMT drvAudioHlpStringToFormat(const char *pszFormat);
|
---|
118 |
|
---|
119 | bool drvAudioPCMPropsAreEqual(PPDMPCMPROPS info, PPDMAUDIOSTREAMCFG pCfg);
|
---|
120 | void drvAudioStreamCfgPrint(PPDMAUDIOSTREAMCFG pCfg);
|
---|
121 |
|
---|
122 | /* AUDIO IN function declarations. */
|
---|
123 | void drvAudioHlpPcmSwFreeResourcesIn(PPDMAUDIOGSTSTRMIN pGstStrmIn);
|
---|
124 | void drvAudioGstInFreeRes(PPDMAUDIOGSTSTRMIN pGstStrmIn);
|
---|
125 | void drvAudioGstInRemove(PPDMAUDIOGSTSTRMIN pGstStrmIn);
|
---|
126 | uint32_t drvAudioHstInFindMinCaptured(PPDMAUDIOHSTSTRMIN pHstStrmIn);
|
---|
127 | void drvAudioHstInFreeRes(PPDMAUDIOHSTSTRMIN pHstStrmIn);
|
---|
128 | uint32_t drvAudioHstInGetFree(PPDMAUDIOHSTSTRMIN pHstStrmIn);
|
---|
129 | uint32_t drvAudioHstInGetLive(PPDMAUDIOHSTSTRMIN pHstStrmIn);
|
---|
130 | void drvAudioGstInRemove(PPDMAUDIOGSTSTRMIN pGstStrmIn);
|
---|
131 | int drvAudioGstInInit(PPDMAUDIOGSTSTRMIN pGstStrmIn, PPDMAUDIOHSTSTRMIN pHstStrmIn, const char *pszName, PPDMAUDIOSTREAMCFG pCfg);
|
---|
132 |
|
---|
133 | PPDMAUDIOHSTSTRMIN drvAudioFindNextHstIn(PDRVAUDIO pDrvAudio, PPDMAUDIOHSTSTRMIN pHstStrmIn);
|
---|
134 | PPDMAUDIOHSTSTRMIN drvAudioFindNextEnabledHstIn(PDRVAUDIO pDrvAudio, PPDMAUDIOHSTSTRMIN pHstStrmIn);
|
---|
135 | PPDMAUDIOHSTSTRMIN drvAudioFindNextEqHstIn(PDRVAUDIO pDrvAudio, PPDMAUDIOHSTSTRMIN pHstStrmIn, PPDMAUDIOSTREAMCFG pCfg);
|
---|
136 |
|
---|
137 | /* AUDIO OUT function declarations. */
|
---|
138 | int drvAudioGstOutAlloc(PPDMAUDIOGSTSTRMOUT pGstStrmOut);
|
---|
139 | void drvAudioGstOutFreeRes(PPDMAUDIOGSTSTRMOUT pGstStrmOut);
|
---|
140 | void drvAudioHstOutFreeRes(PPDMAUDIOHSTSTRMOUT pHstStrmOut);
|
---|
141 | int drvAudioDestroyGstOut(PDRVAUDIO pDrvAudio, PPDMAUDIOGSTSTRMOUT pGstStrmOut);
|
---|
142 | void drvAudioDestroyHstOut(PDRVAUDIO pDrvAudio, PDMAUDIOHSTSTRMOUT pHstStrmOut);
|
---|
143 | int drvAudioGstOutInit(PPDMAUDIOGSTSTRMOUT pGstStrmOut, PPDMAUDIOHSTSTRMOUT pHstStrmOut, const char *pszName, PPDMAUDIOSTREAMCFG pCfg);
|
---|
144 |
|
---|
145 | PPDMAUDIOHSTSTRMOUT drvAudioFindAnyHstOut(PDRVAUDIO pDrvAudio, PPDMAUDIOHSTSTRMOUT pHstStrmOut);
|
---|
146 | PPDMAUDIOHSTSTRMOUT drvAudioHstFindAnyEnabledOut(PDRVAUDIO pDrvAudio, PPDMAUDIOHSTSTRMOUT pHstStrmOut);
|
---|
147 | PPDMAUDIOHSTSTRMOUT drvAudioFindSpecificOut(PDRVAUDIO pDrvAudio, PPDMAUDIOHSTSTRMOUT pHstStrmOut, PPDMAUDIOSTREAMCFG pCfg);
|
---|
148 | int drvAudioAllocHstOut(PDRVAUDIO pDrvAudio, const char *pszName, PPDMAUDIOSTREAMCFG pCfg, PPDMAUDIOHSTSTRMOUT *ppHstStrmOut);
|
---|
149 | int drvAudioHlpPcmHwAddOut(PDRVAUDIO pDrvAudio, PPDMAUDIOSTREAMCFG pCfg, PPDMAUDIOHSTSTRMOUT *ppHstStrmOut);
|
---|
150 | int drvAudioHlpPcmCreateVoicePairOut(PDRVAUDIO pDrvAudio, const char *pszName, PPDMAUDIOSTREAMCFG pCfg, PPDMAUDIOGSTSTRMOUT *ppGstStrmOut);
|
---|
151 |
|
---|
152 | /* Common functions between DrvAudio and backends (host audio drivers). */
|
---|
153 | void DrvAudioClearBuf(PPDMPCMPROPS pPCMInfo, void *pvBuf, size_t cbBuf, uint32_t cSamples);
|
---|
154 | int DrvAudioStreamCfgToProps(PPDMAUDIOSTREAMCFG pCfg, PPDMPCMPROPS pProps);
|
---|
155 |
|
---|
156 | typedef struct fixed_settings
|
---|
157 | {
|
---|
158 | int enabled;
|
---|
159 | int cStreams;
|
---|
160 | int greedy;
|
---|
161 | PDMAUDIOSTREAMCFG settings;
|
---|
162 | } fixed_settings;
|
---|
163 |
|
---|
164 | static struct {
|
---|
165 | struct fixed_settings fixed_out;
|
---|
166 | struct fixed_settings fixed_in;
|
---|
167 | union {
|
---|
168 | int hz;
|
---|
169 | int64_t ticks;
|
---|
170 | } period;
|
---|
171 | int plive;
|
---|
172 | } conf = {
|
---|
173 |
|
---|
174 | /* Fixed output settings. */
|
---|
175 | { /* DAC fixed settings */
|
---|
176 | 1, /* enabled */
|
---|
177 | 1, /* cStreams */
|
---|
178 | 1, /* greedy */
|
---|
179 | {
|
---|
180 | 44100, /* freq */
|
---|
181 | 2, /* nchannels */
|
---|
182 | AUD_FMT_S16, /* fmt */
|
---|
183 | PDMAUDIOHOSTENDIANNESS
|
---|
184 | }
|
---|
185 | },
|
---|
186 |
|
---|
187 | /* Fixed input settings. */
|
---|
188 | { /* ADC fixed settings */
|
---|
189 | 1, /* enabled */
|
---|
190 | 2, /* cStreams */
|
---|
191 | 1, /* greedy */
|
---|
192 | {
|
---|
193 | 44100, /* freq */
|
---|
194 | 2, /* nchannels */
|
---|
195 | AUD_FMT_S16, /* fmt */
|
---|
196 | PDMAUDIOHOSTENDIANNESS
|
---|
197 | }
|
---|
198 | },
|
---|
199 |
|
---|
200 | { 200 }, /* frequency (in Hz) */
|
---|
201 | 0, /* plive */ /** @todo Disable pending live? */
|
---|
202 | };
|
---|
203 | #endif /* DRV_AUDIO_H */
|
---|
204 |
|
---|