VirtualBox

source: vbox/trunk/src/VBox/Main/AudioSnifferInterface.cpp@ 20818

Last change on this file since 20818 was 14772, checked in by vboxsync, 16 years ago

Added vim modelines to aid following coding guidelines, like no tabs,
similar to what is already in the xidl file.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 KB
Line 
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 */
46typedef 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//
68AudioSniffer::AudioSniffer(Console *console) : mpDrv(NULL)
69{
70 mParent = console;
71}
72
73AudioSniffer::~AudioSniffer()
74{
75 if (mpDrv)
76 {
77 mpDrv->pAudioSniffer = NULL;
78 mpDrv = NULL;
79 }
80}
81
82PPDMIAUDIOSNIFFERPORT AudioSniffer::getAudioSnifferPort()
83{
84 Assert(mpDrv);
85 return mpDrv->pUpPort;
86}
87
88
89
90//
91// public methods
92//
93
94DECLCALLBACK(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
106DECLCALLBACK(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 */
125DECLCALLBACK(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 */
147DECLCALLBACK(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 * @returns VBox status.
162 * @param pDrvIns The driver instance data.
163 * If the registration structure is needed, pDrvIns->pDrvReg points to it.
164 * @param pCfgHandle Configuration node handle for the driver. Use this to obtain the configuration
165 * of the driver instance. It's also found in pDrvIns->pCfgHandle, but like
166 * iInstance it's expected to be used a bit in this function.
167 */
168DECLCALLBACK(int) AudioSniffer::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle)
169{
170 PDRVAUDIOSNIFFER pData = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER);
171
172 LogFlow(("AudioSniffer::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
173
174 /*
175 * Validate configuration.
176 */
177 if (!CFGMR3AreValuesValid(pCfgHandle, "Object\0"))
178 {
179 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
180 }
181
182 PPDMIBASE pBaseIgnore;
183 int rc = pDrvIns->pDrvHlp->pfnAttach(pDrvIns, &pBaseIgnore);
184 if (rc != VERR_PDM_NO_ATTACHED_DRIVER)
185 {
186 AssertMsgFailed(("Configuration error: Not possible to attach anything to this driver!\n"));
187 return VERR_PDM_DRVINS_NO_ATTACH;
188 }
189
190 /*
191 * IBase.
192 */
193 pDrvIns->IBase.pfnQueryInterface = AudioSniffer::drvQueryInterface;
194
195 /* Audio Sniffer connector. */
196 pData->Connector.pfnAudioSamplesOut = iface_AudioSamplesOut;
197 pData->Connector.pfnAudioVolumeOut = iface_AudioVolumeOut;
198
199 /*
200 * Get the Audio Sniffer Port interface of the above driver/device.
201 */
202 pData->pUpPort = (PPDMIAUDIOSNIFFERPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_AUDIO_SNIFFER_PORT);
203 if (!pData->pUpPort)
204 {
205 AssertMsgFailed(("Configuration error: No Audio Sniffer port interface above!\n"));
206 return VERR_PDM_MISSING_INTERFACE_ABOVE;
207 }
208
209 /*
210 * Get the Console object pointer and update the mpDrv member.
211 */
212 void *pv;
213 rc = CFGMR3QueryPtr(pCfgHandle, "Object", &pv);
214 if (RT_FAILURE(rc))
215 {
216 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
217 return rc;
218 }
219 pData->pAudioSniffer = (AudioSniffer *)pv; /** @todo Check this cast! */
220 pData->pAudioSniffer->mpDrv = pData;
221
222 return VINF_SUCCESS;
223}
224
225
226/**
227 * Audio Sniffer driver registration record.
228 */
229const PDMDRVREG AudioSniffer::DrvReg =
230{
231 /* u32Version */
232 PDM_DRVREG_VERSION,
233 /* szDriverName */
234 "MainAudioSniffer",
235 /* pszDescription */
236 "Main Audio Sniffer driver (Main as in the API).",
237 /* fFlags */
238 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
239 /* fClass. */
240 PDM_DRVREG_CLASS_AUDIO,
241 /* cMaxInstances */
242 ~0,
243 /* cbInstance */
244 sizeof(DRVAUDIOSNIFFER),
245 /* pfnConstruct */
246 AudioSniffer::drvConstruct,
247 /* pfnDestruct */
248 AudioSniffer::drvDestruct,
249 /* pfnIOCtl */
250 NULL,
251 /* pfnPowerOn */
252 NULL,
253 /* pfnReset */
254 NULL,
255 /* pfnSuspend */
256 NULL,
257 /* pfnResume */
258 NULL,
259 /* pfnDetach */
260 NULL
261};
262/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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