1 | /* $Id: AudioSnifferInterface.cpp 27607 2010-03-22 18:13:07Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Driver Interface to Audio Sniffer device
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2010 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 | * @extends PDMIAUDIOSNIFFERCONNECTOR
|
---|
47 | */
|
---|
48 | typedef struct DRVAUDIOSNIFFER
|
---|
49 | {
|
---|
50 | /** Pointer to the Audio Sniffer object. */
|
---|
51 | AudioSniffer *pAudioSniffer;
|
---|
52 |
|
---|
53 | /** Pointer to the driver instance structure. */
|
---|
54 | PPDMDRVINS pDrvIns;
|
---|
55 |
|
---|
56 | /** Pointer to the AudioSniffer port interface of the driver/device above us. */
|
---|
57 | PPDMIAUDIOSNIFFERPORT pUpPort;
|
---|
58 | /** Our VMM device connector interface. */
|
---|
59 | PDMIAUDIOSNIFFERCONNECTOR Connector;
|
---|
60 |
|
---|
61 | } DRVAUDIOSNIFFER, *PDRVAUDIOSNIFFER;
|
---|
62 |
|
---|
63 | /** Converts PDMIAUDIOSNIFFERCONNECTOR pointer to a DRVAUDIOSNIFFER pointer. */
|
---|
64 | #define PDMIAUDIOSNIFFERCONNECTOR_2_MAINAUDIOSNIFFER(pInterface) RT_FROM_MEMBER(pInterface, DRVAUDIOSNIFFER, Connector)
|
---|
65 |
|
---|
66 |
|
---|
67 | //
|
---|
68 | // constructor / destructor
|
---|
69 | //
|
---|
70 | AudioSniffer::AudioSniffer(Console *console)
|
---|
71 | : mpDrv(NULL),
|
---|
72 | mParent(console)
|
---|
73 | {
|
---|
74 | }
|
---|
75 |
|
---|
76 | AudioSniffer::~AudioSniffer()
|
---|
77 | {
|
---|
78 | if (mpDrv)
|
---|
79 | {
|
---|
80 | mpDrv->pAudioSniffer = NULL;
|
---|
81 | mpDrv = NULL;
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | PPDMIAUDIOSNIFFERPORT AudioSniffer::getAudioSnifferPort()
|
---|
86 | {
|
---|
87 | Assert(mpDrv);
|
---|
88 | return mpDrv->pUpPort;
|
---|
89 | }
|
---|
90 |
|
---|
91 |
|
---|
92 |
|
---|
93 | //
|
---|
94 | // public methods
|
---|
95 | //
|
---|
96 |
|
---|
97 | DECLCALLBACK(void) iface_AudioSamplesOut (PPDMIAUDIOSNIFFERCONNECTOR pInterface, void *pvSamples, uint32_t cSamples,
|
---|
98 | int samplesPerSec, int nChannels, int bitsPerSample, bool fUnsigned)
|
---|
99 | {
|
---|
100 | PDRVAUDIOSNIFFER pDrv = PDMIAUDIOSNIFFERCONNECTOR_2_MAINAUDIOSNIFFER(pInterface);
|
---|
101 |
|
---|
102 | /*
|
---|
103 | * Just call the VRDP server with the data.
|
---|
104 | */
|
---|
105 | VRDPAUDIOFORMAT format = VRDP_AUDIO_FMT_MAKE(samplesPerSec, nChannels, bitsPerSample, !fUnsigned);
|
---|
106 | pDrv->pAudioSniffer->getParent()->consoleVRDPServer()->SendAudioSamples(pvSamples, cSamples, format);
|
---|
107 | }
|
---|
108 |
|
---|
109 | DECLCALLBACK(void) iface_AudioVolumeOut (PPDMIAUDIOSNIFFERCONNECTOR pInterface, uint16_t left, uint16_t right)
|
---|
110 | {
|
---|
111 | PDRVAUDIOSNIFFER pDrv = PDMIAUDIOSNIFFERCONNECTOR_2_MAINAUDIOSNIFFER(pInterface);
|
---|
112 |
|
---|
113 | /*
|
---|
114 | * Just call the VRDP server with the data.
|
---|
115 | */
|
---|
116 | pDrv->pAudioSniffer->getParent()->consoleVRDPServer()->SendAudioVolume(left, right);
|
---|
117 | }
|
---|
118 |
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * @interface_method_impl{PDMIBASE,pfnQueryInterface}
|
---|
122 | */
|
---|
123 | DECLCALLBACK(void *) AudioSniffer::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
|
---|
124 | {
|
---|
125 | PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
|
---|
126 | PDRVAUDIOSNIFFER pDrv = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER);
|
---|
127 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
|
---|
128 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIAUDIOSNIFFERCONNECTOR, &pDrv->Connector);
|
---|
129 | return NULL;
|
---|
130 | }
|
---|
131 |
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * Destruct a Audio Sniffer driver instance.
|
---|
135 | *
|
---|
136 | * @returns VBox status.
|
---|
137 | * @param pDrvIns The driver instance data.
|
---|
138 | */
|
---|
139 | DECLCALLBACK(void) AudioSniffer::drvDestruct(PPDMDRVINS pDrvIns)
|
---|
140 | {
|
---|
141 | PDRVAUDIOSNIFFER pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER);
|
---|
142 | LogFlow(("AudioSniffer::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
|
---|
143 | PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
|
---|
144 |
|
---|
145 | if (pThis->pAudioSniffer)
|
---|
146 | {
|
---|
147 | pThis->pAudioSniffer->mpDrv = NULL;
|
---|
148 | }
|
---|
149 | }
|
---|
150 |
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Construct a AudioSniffer driver instance.
|
---|
154 | *
|
---|
155 | * @copydoc FNPDMDRVCONSTRUCT
|
---|
156 | */
|
---|
157 | DECLCALLBACK(int) AudioSniffer::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
|
---|
158 | {
|
---|
159 | PDRVAUDIOSNIFFER pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER);
|
---|
160 |
|
---|
161 | LogFlow(("AudioSniffer::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
|
---|
162 | PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
|
---|
163 |
|
---|
164 | /*
|
---|
165 | * Validate configuration.
|
---|
166 | */
|
---|
167 | if (!CFGMR3AreValuesValid(pCfg, "Object\0"))
|
---|
168 | return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
|
---|
169 | AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
|
---|
170 | ("Configuration error: Not possible to attach anything to this driver!\n"),
|
---|
171 | VERR_PDM_DRVINS_NO_ATTACH);
|
---|
172 |
|
---|
173 | /*
|
---|
174 | * IBase.
|
---|
175 | */
|
---|
176 | pDrvIns->IBase.pfnQueryInterface = AudioSniffer::drvQueryInterface;
|
---|
177 |
|
---|
178 | /* Audio Sniffer connector. */
|
---|
179 | pThis->Connector.pfnAudioSamplesOut = iface_AudioSamplesOut;
|
---|
180 | pThis->Connector.pfnAudioVolumeOut = iface_AudioVolumeOut;
|
---|
181 |
|
---|
182 | /*
|
---|
183 | * Get the Audio Sniffer Port interface of the above driver/device.
|
---|
184 | */
|
---|
185 | pThis->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIAUDIOSNIFFERPORT);
|
---|
186 | if (!pThis->pUpPort)
|
---|
187 | {
|
---|
188 | AssertMsgFailed(("Configuration error: No Audio Sniffer port interface above!\n"));
|
---|
189 | return VERR_PDM_MISSING_INTERFACE_ABOVE;
|
---|
190 | }
|
---|
191 |
|
---|
192 | /*
|
---|
193 | * Get the Console object pointer and update the mpDrv member.
|
---|
194 | */
|
---|
195 | void *pv;
|
---|
196 | int rc = CFGMR3QueryPtr(pCfg, "Object", &pv);
|
---|
197 | if (RT_FAILURE(rc))
|
---|
198 | {
|
---|
199 | AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
|
---|
200 | return rc;
|
---|
201 | }
|
---|
202 | pThis->pAudioSniffer = (AudioSniffer *)pv; /** @todo Check this cast! */
|
---|
203 | pThis->pAudioSniffer->mpDrv = pThis;
|
---|
204 |
|
---|
205 | return VINF_SUCCESS;
|
---|
206 | }
|
---|
207 |
|
---|
208 |
|
---|
209 | /**
|
---|
210 | * Audio Sniffer driver registration record.
|
---|
211 | */
|
---|
212 | const PDMDRVREG AudioSniffer::DrvReg =
|
---|
213 | {
|
---|
214 | /* u32Version */
|
---|
215 | PDM_DRVREG_VERSION,
|
---|
216 | /* szName */
|
---|
217 | "MainAudioSniffer",
|
---|
218 | /* szRCMod */
|
---|
219 | "",
|
---|
220 | /* szR0Mod */
|
---|
221 | "",
|
---|
222 | /* pszDescription */
|
---|
223 | "Main Audio Sniffer driver (Main as in the API).",
|
---|
224 | /* fFlags */
|
---|
225 | PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
|
---|
226 | /* fClass. */
|
---|
227 | PDM_DRVREG_CLASS_AUDIO,
|
---|
228 | /* cMaxInstances */
|
---|
229 | ~0,
|
---|
230 | /* cbInstance */
|
---|
231 | sizeof(DRVAUDIOSNIFFER),
|
---|
232 | /* pfnConstruct */
|
---|
233 | AudioSniffer::drvConstruct,
|
---|
234 | /* pfnDestruct */
|
---|
235 | AudioSniffer::drvDestruct,
|
---|
236 | /* pfnRelocate */
|
---|
237 | NULL,
|
---|
238 | /* pfnIOCtl */
|
---|
239 | NULL,
|
---|
240 | /* pfnPowerOn */
|
---|
241 | NULL,
|
---|
242 | /* pfnReset */
|
---|
243 | NULL,
|
---|
244 | /* pfnSuspend */
|
---|
245 | NULL,
|
---|
246 | /* pfnResume */
|
---|
247 | NULL,
|
---|
248 | /* pfnAttach */
|
---|
249 | NULL,
|
---|
250 | /* pfnDetach */
|
---|
251 | NULL,
|
---|
252 | /* pfnPowerOff */
|
---|
253 | NULL,
|
---|
254 | /* pfnSoftReset */
|
---|
255 | NULL,
|
---|
256 | /* u32EndVersion */
|
---|
257 | PDM_DRVREG_VERSION
|
---|
258 | };
|
---|
259 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|