VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio/DrvAudio.h@ 59420

Last change on this file since 59420 was 59420, checked in by vboxsync, 9 years ago

Audio/DrvAudio: Use a critical section for (most) driver callbacks.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
1/* $Id: DrvAudio.h 59420 2016-01-20 14:53:24Z 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
55typedef enum
56{
57 AUD_OPT_INT,
58 AUD_OPT_FMT,
59 AUD_OPT_STR,
60 AUD_OPT_BOOL
61} audio_option_tag_e;
62
63typedef 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 */
78typedef 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 uint8_t cFreeInputStreams;
98 /** Max. number of free output streams. */
99 uint8_t cFreeOutputStreams;
100 /** Audio configuration settings retrieved from the backend. */
101 PDMAUDIOBACKENDCFG BackendCfg;
102#ifdef VBOX_WITH_AUDIO_CALLBACKS
103 /** @todo Use a map with primary key set to the callback type? */
104 RTLISTANCHOR lstCBIn;
105 RTLISTANCHOR lstCBOut;
106#endif
107} DRVAUDIO, *PDRVAUDIO;
108
109/** Makes a PDRVAUDIO out of a PPDMIAUDIOCONNECTOR. */
110#define PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface) \
111 ( (PDRVAUDIO)((uintptr_t)pInterface - RT_OFFSETOF(DRVAUDIO, IAudioConnector)) )
112
113//const char *drvAudioHlpFormatToString(PDMAUDIOFMT fmt);
114const char *drvAudioRecSourceToString(PDMAUDIORECSOURCE enmRecSource);
115PDMAUDIOFMT drvAudioHlpStringToFormat(const char *pszFormat);
116
117bool drvAudioPCMPropsAreEqual(PPDMPCMPROPS info, PPDMAUDIOSTREAMCFG pCfg);
118void drvAudioStreamCfgPrint(PPDMAUDIOSTREAMCFG pCfg);
119
120/* AUDIO IN function declarations. */
121void drvAudioHlpPcmSwFreeResourcesIn(PPDMAUDIOGSTSTRMIN pGstStrmIn);
122void drvAudioGstInFreeRes(PPDMAUDIOGSTSTRMIN pGstStrmIn);
123void drvAudioGstInRemove(PPDMAUDIOGSTSTRMIN pGstStrmIn);
124uint32_t drvAudioHstInFindMinCaptured(PPDMAUDIOHSTSTRMIN pHstStrmIn);
125void drvAudioHstInFreeRes(PPDMAUDIOHSTSTRMIN pHstStrmIn);
126uint32_t drvAudioHstInGetFree(PPDMAUDIOHSTSTRMIN pHstStrmIn);
127uint32_t drvAudioHstInGetLive(PPDMAUDIOHSTSTRMIN pHstStrmIn);
128void drvAudioGstInRemove(PPDMAUDIOGSTSTRMIN pGstStrmIn);
129int drvAudioGstInInit(PPDMAUDIOGSTSTRMIN pGstStrmIn, PPDMAUDIOHSTSTRMIN pHstStrmIn, const char *pszName, PPDMAUDIOSTREAMCFG pCfg);
130
131PPDMAUDIOHSTSTRMIN drvAudioFindNextHstIn(PDRVAUDIO pDrvAudio, PPDMAUDIOHSTSTRMIN pHstStrmIn);
132PPDMAUDIOHSTSTRMIN drvAudioFindNextEnabledHstIn(PDRVAUDIO pDrvAudio, PPDMAUDIOHSTSTRMIN pHstStrmIn);
133PPDMAUDIOHSTSTRMIN drvAudioFindNextEqHstIn(PDRVAUDIO pDrvAudio, PPDMAUDIOHSTSTRMIN pHstStrmIn, PPDMAUDIOSTREAMCFG pCfg);
134
135/* AUDIO OUT function declarations. */
136int drvAudioGstOutAlloc(PPDMAUDIOGSTSTRMOUT pGstStrmOut);
137void drvAudioGstOutFreeRes(PPDMAUDIOGSTSTRMOUT pGstStrmOut);
138void drvAudioHstOutFreeRes(PPDMAUDIOHSTSTRMOUT pHstStrmOut);
139int drvAudioDestroyGstOut(PDRVAUDIO pDrvAudio, PPDMAUDIOGSTSTRMOUT pGstStrmOut);
140void drvAudioDestroyHstOut(PDRVAUDIO pDrvAudio, PDMAUDIOHSTSTRMOUT pHstStrmOut);
141int drvAudioGstOutInit(PPDMAUDIOGSTSTRMOUT pGstStrmOut, PPDMAUDIOHSTSTRMOUT pHstStrmOut, const char *pszName, PPDMAUDIOSTREAMCFG pCfg);
142
143PPDMAUDIOHSTSTRMOUT drvAudioFindAnyHstOut(PDRVAUDIO pDrvAudio, PPDMAUDIOHSTSTRMOUT pHstStrmOut);
144PPDMAUDIOHSTSTRMOUT drvAudioHstFindAnyEnabledOut(PDRVAUDIO pDrvAudio, PPDMAUDIOHSTSTRMOUT pHstStrmOut);
145PPDMAUDIOHSTSTRMOUT drvAudioFindSpecificOut(PDRVAUDIO pDrvAudio, PPDMAUDIOHSTSTRMOUT pHstStrmOut, PPDMAUDIOSTREAMCFG pCfg);
146int drvAudioAllocHstOut(PDRVAUDIO pDrvAudio, const char *pszName, PPDMAUDIOSTREAMCFG pCfg, PPDMAUDIOHSTSTRMOUT *ppHstStrmOut);
147int drvAudioHlpPcmHwAddOut(PDRVAUDIO pDrvAudio, PPDMAUDIOSTREAMCFG pCfg, PPDMAUDIOHSTSTRMOUT *ppHstStrmOut);
148int drvAudioHlpPcmCreateVoicePairOut(PDRVAUDIO pDrvAudio, const char *pszName, PPDMAUDIOSTREAMCFG pCfg, PPDMAUDIOGSTSTRMOUT *ppGstStrmOut);
149
150/* Common functions between DrvAudio and backends (host audio drivers). */
151void DrvAudioClearBuf(PPDMPCMPROPS pPCMInfo, void *pvBuf, size_t cbBuf, uint32_t cSamples);
152int DrvAudioStreamCfgToProps(PPDMAUDIOSTREAMCFG pCfg, PPDMPCMPROPS pProps);
153
154typedef struct fixed_settings
155{
156 int enabled;
157 int cStreams;
158 int greedy;
159 PDMAUDIOSTREAMCFG settings;
160} fixed_settings;
161
162static struct {
163 struct fixed_settings fixed_out;
164 struct fixed_settings fixed_in;
165 union {
166 int hz;
167 int64_t ticks;
168 } period;
169 int plive;
170} conf = {
171
172 /* Fixed output settings. */
173 { /* DAC fixed settings */
174 1, /* enabled */
175 1, /* cStreams */
176 1, /* greedy */
177 {
178 44100, /* freq */
179 2, /* nchannels */
180 AUD_FMT_S16, /* fmt */
181 PDMAUDIOHOSTENDIANNESS
182 }
183 },
184
185 /* Fixed input settings. */
186 { /* ADC fixed settings */
187 1, /* enabled */
188 2, /* cStreams */
189 1, /* greedy */
190 {
191 44100, /* freq */
192 2, /* nchannels */
193 AUD_FMT_S16, /* fmt */
194 PDMAUDIOHOSTENDIANNESS
195 }
196 },
197
198 { 200 }, /* frequency (in Hz) */
199 0, /* plive */ /** @todo Disable pending live? */
200};
201#endif /* DRV_AUDIO_H */
202
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette