1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox Driver Interface to Audio Sniffer device
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #include "AudioSnifferInterface.h"
|
---|
23 | #include "ConsoleImpl.h"
|
---|
24 | #include "ConsoleVRDPServer.h"
|
---|
25 |
|
---|
26 | #include "Logging.h"
|
---|
27 |
|
---|
28 | #include <VBox/pdmdrv.h>
|
---|
29 | #include <VBox/vrdpapi.h>
|
---|
30 | #include <VBox/cfgm.h>
|
---|
31 | #include <VBox/err.h>
|
---|
32 |
|
---|
33 | //
|
---|
34 | // defines
|
---|
35 | //
|
---|
36 |
|
---|
37 |
|
---|
38 | //
|
---|
39 | // globals
|
---|
40 | //
|
---|
41 |
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Audio Sniffer driver instance data.
|
---|
45 | */
|
---|
46 | typedef struct DRVAUDIOSNIFFER
|
---|
47 | {
|
---|
48 | /** Pointer to the Audio Sniffer object. */
|
---|
49 | AudioSniffer *pAudioSniffer;
|
---|
50 |
|
---|
51 | /** Pointer to the driver instance structure. */
|
---|
52 | PPDMDRVINS pDrvIns;
|
---|
53 |
|
---|
54 | /** Pointer to the AudioSniffer port interface of the driver/device above us. */
|
---|
55 | PPDMIAUDIOSNIFFERPORT pUpPort;
|
---|
56 | /** Our VMM device connector interface. */
|
---|
57 | PDMIAUDIOSNIFFERCONNECTOR Connector;
|
---|
58 |
|
---|
59 | } DRVAUDIOSNIFFER, *PDRVAUDIOSNIFFER;
|
---|
60 |
|
---|
61 | /** Converts PDMIAUDIOSNIFFERCONNECTOR pointer to a DRVAUDIOSNIFFER pointer. */
|
---|
62 | #define PDMIAUDIOSNIFFERCONNECTOR_2_MAINAUDIOSNIFFER(pInterface) ( (PDRVAUDIOSNIFFER) ((uintptr_t)pInterface - RT_OFFSETOF(DRVAUDIOSNIFFER, Connector)) )
|
---|
63 |
|
---|
64 |
|
---|
65 | //
|
---|
66 | // constructor / destructor
|
---|
67 | //
|
---|
68 | AudioSniffer::AudioSniffer(Console *console) : mpDrv(NULL)
|
---|
69 | {
|
---|
70 | mParent = console;
|
---|
71 | }
|
---|
72 |
|
---|
73 | AudioSniffer::~AudioSniffer()
|
---|
74 | {
|
---|
75 | if (mpDrv)
|
---|
76 | {
|
---|
77 | mpDrv->pAudioSniffer = NULL;
|
---|
78 | mpDrv = NULL;
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | PPDMIAUDIOSNIFFERPORT AudioSniffer::getAudioSnifferPort()
|
---|
83 | {
|
---|
84 | Assert(mpDrv);
|
---|
85 | return mpDrv->pUpPort;
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 |
|
---|
90 | //
|
---|
91 | // public methods
|
---|
92 | //
|
---|
93 |
|
---|
94 | DECLCALLBACK(void) iface_AudioSamplesOut (PPDMIAUDIOSNIFFERCONNECTOR pInterface, void *pvSamples, uint32_t cSamples,
|
---|
95 | int samplesPerSec, int nChannels, int bitsPerSample, bool fUnsigned)
|
---|
96 | {
|
---|
97 | PDRVAUDIOSNIFFER pDrv = PDMIAUDIOSNIFFERCONNECTOR_2_MAINAUDIOSNIFFER(pInterface);
|
---|
98 |
|
---|
99 | /*
|
---|
100 | * Just call the VRDP server with the data.
|
---|
101 | */
|
---|
102 | VRDPAUDIOFORMAT format = VRDP_AUDIO_FMT_MAKE(samplesPerSec, nChannels, bitsPerSample, !fUnsigned);
|
---|
103 | pDrv->pAudioSniffer->getParent()->consoleVRDPServer()->SendAudioSamples(pvSamples, cSamples, format);
|
---|
104 | }
|
---|
105 |
|
---|
106 | DECLCALLBACK(void) iface_AudioVolumeOut (PPDMIAUDIOSNIFFERCONNECTOR pInterface, uint16_t left, uint16_t right)
|
---|
107 | {
|
---|
108 | PDRVAUDIOSNIFFER pDrv = PDMIAUDIOSNIFFERCONNECTOR_2_MAINAUDIOSNIFFER(pInterface);
|
---|
109 |
|
---|
110 | /*
|
---|
111 | * Just call the VRDP server with the data.
|
---|
112 | */
|
---|
113 | pDrv->pAudioSniffer->getParent()->consoleVRDPServer()->SendAudioVolume(left, right);
|
---|
114 | }
|
---|
115 |
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * Queries an interface to the driver.
|
---|
119 | *
|
---|
120 | * @returns Pointer to interface.
|
---|
121 | * @returns NULL if the interface was not supported by the driver.
|
---|
122 | * @param pInterface Pointer to this interface structure.
|
---|
123 | * @param enmInterface The requested interface identification.
|
---|
124 | */
|
---|
125 | DECLCALLBACK(void *) AudioSniffer::drvQueryInterface(PPDMIBASE pInterface, PDMINTERFACE enmInterface)
|
---|
126 | {
|
---|
127 | PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
|
---|
128 | PDRVAUDIOSNIFFER pDrv = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER);
|
---|
129 | switch (enmInterface)
|
---|
130 | {
|
---|
131 | case PDMINTERFACE_BASE:
|
---|
132 | return &pDrvIns->IBase;
|
---|
133 | case PDMINTERFACE_AUDIO_SNIFFER_CONNECTOR:
|
---|
134 | return &pDrv->Connector;
|
---|
135 | default:
|
---|
136 | return NULL;
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * Destruct a Audio Sniffer driver instance.
|
---|
143 | *
|
---|
144 | * @returns VBox status.
|
---|
145 | * @param pDrvIns The driver instance data.
|
---|
146 | */
|
---|
147 | DECLCALLBACK(void) AudioSniffer::drvDestruct(PPDMDRVINS pDrvIns)
|
---|
148 | {
|
---|
149 | PDRVAUDIOSNIFFER pData = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER);
|
---|
150 | LogFlow(("AudioSniffer::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
|
---|
151 | if (pData->pAudioSniffer)
|
---|
152 | {
|
---|
153 | pData->pAudioSniffer->mpDrv = NULL;
|
---|
154 | }
|
---|
155 | }
|
---|
156 |
|
---|
157 |
|
---|
158 | /**
|
---|
159 | * Construct a AudioSniffer driver instance.
|
---|
160 | *
|
---|
161 | * @copydoc FNPDMDRVCONSTRUCT
|
---|
162 | */
|
---|
163 | DECLCALLBACK(int) AudioSniffer::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
|
---|
164 | {
|
---|
165 | PDRVAUDIOSNIFFER pData = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER);
|
---|
166 |
|
---|
167 | LogFlow(("AudioSniffer::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
|
---|
168 |
|
---|
169 | /*
|
---|
170 | * Validate configuration.
|
---|
171 | */
|
---|
172 | if (!CFGMR3AreValuesValid(pCfgHandle, "Object\0"))
|
---|
173 | return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
|
---|
174 | AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
|
---|
175 | ("Configuration error: Not possible to attach anything to this driver!\n"),
|
---|
176 | VERR_PDM_DRVINS_NO_ATTACH);
|
---|
177 |
|
---|
178 | /*
|
---|
179 | * IBase.
|
---|
180 | */
|
---|
181 | pDrvIns->IBase.pfnQueryInterface = AudioSniffer::drvQueryInterface;
|
---|
182 |
|
---|
183 | /* Audio Sniffer connector. */
|
---|
184 | pData->Connector.pfnAudioSamplesOut = iface_AudioSamplesOut;
|
---|
185 | pData->Connector.pfnAudioVolumeOut = iface_AudioVolumeOut;
|
---|
186 |
|
---|
187 | /*
|
---|
188 | * Get the Audio Sniffer Port interface of the above driver/device.
|
---|
189 | */
|
---|
190 | pData->pUpPort = (PPDMIAUDIOSNIFFERPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_AUDIO_SNIFFER_PORT);
|
---|
191 | if (!pData->pUpPort)
|
---|
192 | {
|
---|
193 | AssertMsgFailed(("Configuration error: No Audio Sniffer port interface above!\n"));
|
---|
194 | return VERR_PDM_MISSING_INTERFACE_ABOVE;
|
---|
195 | }
|
---|
196 |
|
---|
197 | /*
|
---|
198 | * Get the Console object pointer and update the mpDrv member.
|
---|
199 | */
|
---|
200 | void *pv;
|
---|
201 | int rc = CFGMR3QueryPtr(pCfgHandle, "Object", &pv);
|
---|
202 | if (RT_FAILURE(rc))
|
---|
203 | {
|
---|
204 | AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
|
---|
205 | return rc;
|
---|
206 | }
|
---|
207 | pData->pAudioSniffer = (AudioSniffer *)pv; /** @todo Check this cast! */
|
---|
208 | pData->pAudioSniffer->mpDrv = pData;
|
---|
209 |
|
---|
210 | return VINF_SUCCESS;
|
---|
211 | }
|
---|
212 |
|
---|
213 |
|
---|
214 | /**
|
---|
215 | * Audio Sniffer driver registration record.
|
---|
216 | */
|
---|
217 | const PDMDRVREG AudioSniffer::DrvReg =
|
---|
218 | {
|
---|
219 | /* u32Version */
|
---|
220 | PDM_DRVREG_VERSION,
|
---|
221 | /* szDriverName */
|
---|
222 | "MainAudioSniffer",
|
---|
223 | /* pszDescription */
|
---|
224 | "Main Audio Sniffer driver (Main as in the API).",
|
---|
225 | /* fFlags */
|
---|
226 | PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
|
---|
227 | /* fClass. */
|
---|
228 | PDM_DRVREG_CLASS_AUDIO,
|
---|
229 | /* cMaxInstances */
|
---|
230 | ~0,
|
---|
231 | /* cbInstance */
|
---|
232 | sizeof(DRVAUDIOSNIFFER),
|
---|
233 | /* pfnConstruct */
|
---|
234 | AudioSniffer::drvConstruct,
|
---|
235 | /* pfnDestruct */
|
---|
236 | AudioSniffer::drvDestruct,
|
---|
237 | /* pfnIOCtl */
|
---|
238 | NULL,
|
---|
239 | /* pfnPowerOn */
|
---|
240 | NULL,
|
---|
241 | /* pfnReset */
|
---|
242 | NULL,
|
---|
243 | /* pfnSuspend */
|
---|
244 | NULL,
|
---|
245 | /* pfnResume */
|
---|
246 | NULL,
|
---|
247 | /* pfnAttach */
|
---|
248 | NULL,
|
---|
249 | /* pfnDetach */
|
---|
250 | NULL,
|
---|
251 | /* pfnPowerOff */
|
---|
252 | NULL,
|
---|
253 | /* pfnSoftReset */
|
---|
254 | NULL,
|
---|
255 | /* u32EndVersion */
|
---|
256 | PDM_DRVREG_VERSION
|
---|
257 | };
|
---|
258 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|