1 | /* $Id: AudioSnifferInterface.cpp 26173 2010-02-02 21:11:09Z 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) : mpDrv(NULL)
|
---|
71 | {
|
---|
72 | mParent = console;
|
---|
73 | }
|
---|
74 |
|
---|
75 | AudioSniffer::~AudioSniffer()
|
---|
76 | {
|
---|
77 | if (mpDrv)
|
---|
78 | {
|
---|
79 | mpDrv->pAudioSniffer = NULL;
|
---|
80 | mpDrv = NULL;
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | PPDMIAUDIOSNIFFERPORT AudioSniffer::getAudioSnifferPort()
|
---|
85 | {
|
---|
86 | Assert(mpDrv);
|
---|
87 | return mpDrv->pUpPort;
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 |
|
---|
92 | //
|
---|
93 | // public methods
|
---|
94 | //
|
---|
95 |
|
---|
96 | DECLCALLBACK(void) iface_AudioSamplesOut (PPDMIAUDIOSNIFFERCONNECTOR pInterface, void *pvSamples, uint32_t cSamples,
|
---|
97 | int samplesPerSec, int nChannels, int bitsPerSample, bool fUnsigned)
|
---|
98 | {
|
---|
99 | PDRVAUDIOSNIFFER pDrv = PDMIAUDIOSNIFFERCONNECTOR_2_MAINAUDIOSNIFFER(pInterface);
|
---|
100 |
|
---|
101 | /*
|
---|
102 | * Just call the VRDP server with the data.
|
---|
103 | */
|
---|
104 | VRDPAUDIOFORMAT format = VRDP_AUDIO_FMT_MAKE(samplesPerSec, nChannels, bitsPerSample, !fUnsigned);
|
---|
105 | pDrv->pAudioSniffer->getParent()->consoleVRDPServer()->SendAudioSamples(pvSamples, cSamples, format);
|
---|
106 | }
|
---|
107 |
|
---|
108 | DECLCALLBACK(void) iface_AudioVolumeOut (PPDMIAUDIOSNIFFERCONNECTOR pInterface, uint16_t left, uint16_t right)
|
---|
109 | {
|
---|
110 | PDRVAUDIOSNIFFER pDrv = PDMIAUDIOSNIFFERCONNECTOR_2_MAINAUDIOSNIFFER(pInterface);
|
---|
111 |
|
---|
112 | /*
|
---|
113 | * Just call the VRDP server with the data.
|
---|
114 | */
|
---|
115 | pDrv->pAudioSniffer->getParent()->consoleVRDPServer()->SendAudioVolume(left, right);
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * @interface_method_impl{PDMIBASE,pfnQueryInterface}
|
---|
121 | */
|
---|
122 | DECLCALLBACK(void *) AudioSniffer::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
|
---|
123 | {
|
---|
124 | PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
|
---|
125 | PDRVAUDIOSNIFFER pDrv = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER);
|
---|
126 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
|
---|
127 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIAUDIOSNIFFERCONNECTOR, &pDrv->Connector);
|
---|
128 | return NULL;
|
---|
129 | }
|
---|
130 |
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Destruct a Audio Sniffer driver instance.
|
---|
134 | *
|
---|
135 | * @returns VBox status.
|
---|
136 | * @param pDrvIns The driver instance data.
|
---|
137 | */
|
---|
138 | DECLCALLBACK(void) AudioSniffer::drvDestruct(PPDMDRVINS pDrvIns)
|
---|
139 | {
|
---|
140 | PDRVAUDIOSNIFFER pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER);
|
---|
141 | LogFlow(("AudioSniffer::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
|
---|
142 | PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
|
---|
143 |
|
---|
144 | if (pThis->pAudioSniffer)
|
---|
145 | {
|
---|
146 | pThis->pAudioSniffer->mpDrv = NULL;
|
---|
147 | }
|
---|
148 | }
|
---|
149 |
|
---|
150 |
|
---|
151 | /**
|
---|
152 | * Construct a AudioSniffer driver instance.
|
---|
153 | *
|
---|
154 | * @copydoc FNPDMDRVCONSTRUCT
|
---|
155 | */
|
---|
156 | DECLCALLBACK(int) AudioSniffer::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
|
---|
157 | {
|
---|
158 | PDRVAUDIOSNIFFER pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER);
|
---|
159 |
|
---|
160 | LogFlow(("AudioSniffer::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
|
---|
161 | PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
|
---|
162 |
|
---|
163 | /*
|
---|
164 | * Validate configuration.
|
---|
165 | */
|
---|
166 | if (!CFGMR3AreValuesValid(pCfg, "Object\0"))
|
---|
167 | return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
|
---|
168 | AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
|
---|
169 | ("Configuration error: Not possible to attach anything to this driver!\n"),
|
---|
170 | VERR_PDM_DRVINS_NO_ATTACH);
|
---|
171 |
|
---|
172 | /*
|
---|
173 | * IBase.
|
---|
174 | */
|
---|
175 | pDrvIns->IBase.pfnQueryInterface = AudioSniffer::drvQueryInterface;
|
---|
176 |
|
---|
177 | /* Audio Sniffer connector. */
|
---|
178 | pThis->Connector.pfnAudioSamplesOut = iface_AudioSamplesOut;
|
---|
179 | pThis->Connector.pfnAudioVolumeOut = iface_AudioVolumeOut;
|
---|
180 |
|
---|
181 | /*
|
---|
182 | * Get the Audio Sniffer Port interface of the above driver/device.
|
---|
183 | */
|
---|
184 | pThis->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIAUDIOSNIFFERPORT);
|
---|
185 | if (!pThis->pUpPort)
|
---|
186 | {
|
---|
187 | AssertMsgFailed(("Configuration error: No Audio Sniffer port interface above!\n"));
|
---|
188 | return VERR_PDM_MISSING_INTERFACE_ABOVE;
|
---|
189 | }
|
---|
190 |
|
---|
191 | /*
|
---|
192 | * Get the Console object pointer and update the mpDrv member.
|
---|
193 | */
|
---|
194 | void *pv;
|
---|
195 | int rc = CFGMR3QueryPtr(pCfg, "Object", &pv);
|
---|
196 | if (RT_FAILURE(rc))
|
---|
197 | {
|
---|
198 | AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
|
---|
199 | return rc;
|
---|
200 | }
|
---|
201 | pThis->pAudioSniffer = (AudioSniffer *)pv; /** @todo Check this cast! */
|
---|
202 | pThis->pAudioSniffer->mpDrv = pThis;
|
---|
203 |
|
---|
204 | return VINF_SUCCESS;
|
---|
205 | }
|
---|
206 |
|
---|
207 |
|
---|
208 | /**
|
---|
209 | * Audio Sniffer driver registration record.
|
---|
210 | */
|
---|
211 | const PDMDRVREG AudioSniffer::DrvReg =
|
---|
212 | {
|
---|
213 | /* u32Version */
|
---|
214 | PDM_DRVREG_VERSION,
|
---|
215 | /* szName */
|
---|
216 | "MainAudioSniffer",
|
---|
217 | /* szRCMod */
|
---|
218 | "",
|
---|
219 | /* szR0Mod */
|
---|
220 | "",
|
---|
221 | /* pszDescription */
|
---|
222 | "Main Audio Sniffer driver (Main as in the API).",
|
---|
223 | /* fFlags */
|
---|
224 | PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
|
---|
225 | /* fClass. */
|
---|
226 | PDM_DRVREG_CLASS_AUDIO,
|
---|
227 | /* cMaxInstances */
|
---|
228 | ~0,
|
---|
229 | /* cbInstance */
|
---|
230 | sizeof(DRVAUDIOSNIFFER),
|
---|
231 | /* pfnConstruct */
|
---|
232 | AudioSniffer::drvConstruct,
|
---|
233 | /* pfnDestruct */
|
---|
234 | AudioSniffer::drvDestruct,
|
---|
235 | /* pfnRelocate */
|
---|
236 | NULL,
|
---|
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: */
|
---|