VirtualBox

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

Last change on this file since 4753 was 4071, checked in by vboxsync, 17 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

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