VirtualBox

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

Last change on this file since 63848 was 63743, checked in by vboxsync, 8 years ago

Audio: More code for device enumeration and dynamic device handling / switching.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 KB
Line 
1/* $Id: DrvAudio.h 63743 2016-09-07 09:26:22Z 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#include <iprt/file.h>
51#include <iprt/path.h>
52
53#include <VBox/vmm/pdmdev.h>
54#include <VBox/vmm/pdm.h>
55#include <VBox/vmm/pdmaudioifs.h>
56
57typedef enum
58{
59 AUD_OPT_INT,
60 AUD_OPT_FMT,
61 AUD_OPT_STR,
62 AUD_OPT_BOOL
63} audio_option_tag_e;
64
65typedef struct audio_option
66{
67 const char *name;
68 audio_option_tag_e tag;
69 void *valp;
70 const char *descr;
71 int *overridenp;
72 int overriden;
73} audio_option;
74
75#ifdef VBOX_WITH_STATISTICS
76/**
77 * Structure for keeping stream statistics for the
78 * statistic manager (STAM).
79 */
80typedef struct DRVAUDIOSTATS
81{
82 STAMCOUNTER TotalStreamsActive;
83 STAMCOUNTER TotalStreamsCreated;
84 STAMCOUNTER TotalSamplesPlayed;
85 STAMCOUNTER TotalSamplesCaptured;
86 STAMCOUNTER TotalBytesRead;
87 STAMCOUNTER TotalBytesWritten;
88} DRVAUDIOSTATS, *PDRVAUDIOSTATS;
89#endif
90
91/**
92 * Audio driver instance data.
93 *
94 * @implements PDMIAUDIOCONNECTOR
95 */
96typedef struct DRVAUDIO
97{
98 /** Input/output processing thread. */
99 RTTHREAD hThread;
100 /** Critical section for serializing access. */
101 RTCRITSECT CritSect;
102 /** Shutdown indicator. */
103 bool fTerminate;
104 /** Our audio connector interface. */
105 PDMIAUDIOCONNECTOR IAudioConnector;
106 /** Pointer to the driver instance. */
107 PPDMDRVINS pDrvIns;
108 /** Pointer to audio driver below us. */
109 PPDMIHOSTAUDIO pHostDrvAudio;
110 /** List of host input/output audio streams. */
111 RTLISTANCHOR lstHstStreams;
112 /** List of guest input/output audio streams. */
113 RTLISTANCHOR lstGstStreams;
114 /** Max. number of free input streams.
115 * UINT32_MAX for unlimited streams. */
116 uint32_t cStreamsFreeIn;
117 /** Max. number of free output streams.
118 * UINT32_MAX for unlimited streams. */
119 uint32_t cStreamsFreeOut;
120 /** Flag indicating to perform an (re-)enumeration of the host audio devices. */
121 bool fEnumerateDevices;
122 /** Audio configuration settings retrieved from the backend. */
123 PDMAUDIOBACKENDCFG BackendCfg;
124#ifdef VBOX_WITH_AUDIO_DEVICE_CALLBACKS
125 /** @todo Use a map with primary key set to the callback type? */
126 RTLISTANCHOR lstCBIn;
127 RTLISTANCHOR lstCBOut;
128#endif
129#ifdef VBOX_WITH_STATISTICS
130 /** Statistics for the statistics manager (STAM). */
131 DRVAUDIOSTATS Stats;
132#endif
133} DRVAUDIO, *PDRVAUDIO;
134
135/** Makes a PDRVAUDIO out of a PPDMIAUDIOCONNECTOR. */
136#define PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface) \
137 ( (PDRVAUDIO)((uintptr_t)pInterface - RT_OFFSETOF(DRVAUDIO, IAudioConnector)) )
138
139
140bool DrvAudioHlpAudFmtIsSigned(PDMAUDIOFMT enmFmt);
141uint8_t DrvAudioHlpAudFmtToBits(PDMAUDIOFMT enmFmt);
142const char *DrvAudioHlpAudFmtToStr(PDMAUDIOFMT enmFmt);
143void DrvAudioHlpClearBuf(PPDMAUDIOPCMPROPS pPCMInfo, void *pvBuf, size_t cbBuf, uint32_t cSamples);
144uint32_t DrvAudioHlpCalcBitrate(uint8_t cBits, uint32_t uHz, uint8_t cChannels);
145uint32_t DrvAudioHlpCalcBitrate(PPDMAUDIOSTREAMCFG pCfg);
146bool DrvAudioHlpPCMPropsAreEqual(PPDMAUDIOPCMPROPS pPCMProps1, PPDMAUDIOPCMPROPS pPCMProps2);
147bool DrvAudioHlpPCMPropsAreEqual(PPDMAUDIOPCMPROPS pPCMProps, PPDMAUDIOSTREAMCFG pCfg);
148int DrvAudioHlpPCMPropsToStreamCfg(PPDMAUDIOPCMPROPS pPCMProps, PPDMAUDIOSTREAMCFG pCfg);
149const char *DrvAudioHlpRecSrcToStr(PDMAUDIORECSOURCE enmRecSource);
150void DrvAudioHlpStreamCfgPrint(PPDMAUDIOSTREAMCFG pCfg);
151bool DrvAudioHlpStreamCfgIsValid(PPDMAUDIOSTREAMCFG pCfg);
152int DrvAudioHlpStreamCfgToProps(PPDMAUDIOSTREAMCFG pCfg, PPDMAUDIOPCMPROPS pProps);
153PDMAUDIOFMT DrvAudioHlpStrToAudFmt(const char *pszFmt);
154
155int DrvAudioHlpSanitizeFileName(char *pszPath, size_t cbPath);
156int DrvAudioHlpGetFileName(char *pszFile, size_t cchFile, const char *pszPath, const char *pszName, PDMAUDIOFILETYPE enmType);
157
158PPDMAUDIODEVICE DrvAudioHlpDeviceAlloc(size_t cbData);
159void DrvAudioHlpDeviceFree(PPDMAUDIODEVICE pDev);
160PPDMAUDIODEVICE DrvAudioHlpDeviceDup(PPDMAUDIODEVICE pDev, bool fCopyUserData);
161
162int DrvAudioHlpDeviceEnumInit(PPDMAUDIODEVICEENUM pDevEnm);
163void DrvAudioHlpDeviceEnumFree(PPDMAUDIODEVICEENUM pDevEnm);
164int DrvAudioHlpDeviceEnumAdd(PPDMAUDIODEVICEENUM pDevEnm, PPDMAUDIODEVICE pDev);
165int DrvAudioHlpDeviceEnumCopyEx(PPDMAUDIODEVICEENUM pDstDevEnm, PPDMAUDIODEVICEENUM pSrcDevEnm, PDMAUDIODIR enmUsage);
166int DrvAudioHlpDeviceEnumCopy(PPDMAUDIODEVICEENUM pDstDevEnm, PPDMAUDIODEVICEENUM pSrcDevEnm);
167PPDMAUDIODEVICEENUM DrvAudioHlpDeviceEnumDup(PPDMAUDIODEVICEENUM pDevEnm);
168int DrvAudioHlpDeviceEnumCopy(PPDMAUDIODEVICEENUM pDstDevEnm, PPDMAUDIODEVICEENUM pSrcDevEnm);
169PPDMAUDIODEVICE DrvAudioHlpDeviceEnumGetDefaultDevice(PPDMAUDIODEVICEENUM pDevEnm, PDMAUDIODIR enmDir);
170void DrvAudioHlpDeviceEnumPrint(const char *pszDesc, PPDMAUDIODEVICEENUM pDevEnm);
171
172const char *DrvAudioHlpAudDirToStr(PDMAUDIODIR enmDir);
173char *DrvAudioHlpAudDevFlagsToStrA(PDMAUDIODEVFLAG fFlags);
174
175int DrvAudioHlpWAVFileOpen(PPDMAUDIOFILE pFile, const char *pszFile, uint32_t fOpen, PPDMAUDIOPCMPROPS pProps, PDMAUDIOFILEFLAGS fFlags);
176int DrvAudioHlpWAVFileClose(PPDMAUDIOFILE pFile);
177size_t DrvAudioHlpWAVFileGetDataSize(PPDMAUDIOFILE pFile);
178int DrvAudioHlpWAVFileWrite(PPDMAUDIOFILE pFile, const void *pvBuf, size_t cbBuf, uint32_t fFlags);
179
180#define AUDIO_MAKE_FOURCC(c0, c1, c2, c3) RT_H2LE_U32_C(RT_MAKE_U32_FROM_U8(c0, c1, c2, c3))
181
182#endif /* DRV_AUDIO_H */
183
Note: See TracBrowser for help on using the repository browser.

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