VirtualBox

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

Last change on this file since 25966 was 25966, checked in by vboxsync, 15 years ago

PDMIBASE refactoring; use UUID as interface IDs.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1/* $Id: AudioSnifferInterface.cpp 25966 2010-01-22 11:15:43Z 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.215389.xyz. 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 */
48typedef 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//
70AudioSniffer::AudioSniffer(Console *console) : mpDrv(NULL)
71{
72 mParent = console;
73}
74
75AudioSniffer::~AudioSniffer()
76{
77 if (mpDrv)
78 {
79 mpDrv->pAudioSniffer = NULL;
80 mpDrv = NULL;
81 }
82}
83
84PPDMIAUDIOSNIFFERPORT AudioSniffer::getAudioSnifferPort()
85{
86 Assert(mpDrv);
87 return mpDrv->pUpPort;
88}
89
90
91
92//
93// public methods
94//
95
96DECLCALLBACK(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
108DECLCALLBACK(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 */
122DECLCALLBACK(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 if (RTUuidCompare2Strs(pszIID, PDMIBASE_IID) == 0)
127 return &pDrvIns->IBase;
128 if (RTUuidCompare2Strs(pszIID, PDMINTERFACE_AUDIO_SNIFFER_CONNECTOR) == 0)
129 return &pDrv->Connector;
130 return NULL;
131}
132
133
134/**
135 * Destruct a Audio Sniffer driver instance.
136 *
137 * @returns VBox status.
138 * @param pDrvIns The driver instance data.
139 */
140DECLCALLBACK(void) AudioSniffer::drvDestruct(PPDMDRVINS pDrvIns)
141{
142 PDRVAUDIOSNIFFER pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER);
143 LogFlow(("AudioSniffer::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
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 */
156DECLCALLBACK(int) AudioSniffer::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
157{
158 PDRVAUDIOSNIFFER pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER);
159
160 LogFlow(("AudioSniffer::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
161
162 /*
163 * Validate configuration.
164 */
165 if (!CFGMR3AreValuesValid(pCfgHandle, "Object\0"))
166 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
167 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
168 ("Configuration error: Not possible to attach anything to this driver!\n"),
169 VERR_PDM_DRVINS_NO_ATTACH);
170
171 /*
172 * IBase.
173 */
174 pDrvIns->IBase.pfnQueryInterface = AudioSniffer::drvQueryInterface;
175
176 /* Audio Sniffer connector. */
177 pThis->Connector.pfnAudioSamplesOut = iface_AudioSamplesOut;
178 pThis->Connector.pfnAudioVolumeOut = iface_AudioVolumeOut;
179
180 /*
181 * Get the Audio Sniffer Port interface of the above driver/device.
182 */
183 pThis->pUpPort = (PPDMIAUDIOSNIFFERPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_AUDIO_SNIFFER_PORT);
184 if (!pThis->pUpPort)
185 {
186 AssertMsgFailed(("Configuration error: No Audio Sniffer port interface above!\n"));
187 return VERR_PDM_MISSING_INTERFACE_ABOVE;
188 }
189
190 /*
191 * Get the Console object pointer and update the mpDrv member.
192 */
193 void *pv;
194 int rc = CFGMR3QueryPtr(pCfgHandle, "Object", &pv);
195 if (RT_FAILURE(rc))
196 {
197 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
198 return rc;
199 }
200 pThis->pAudioSniffer = (AudioSniffer *)pv; /** @todo Check this cast! */
201 pThis->pAudioSniffer->mpDrv = pThis;
202
203 return VINF_SUCCESS;
204}
205
206
207/**
208 * Audio Sniffer driver registration record.
209 */
210const PDMDRVREG AudioSniffer::DrvReg =
211{
212 /* u32Version */
213 PDM_DRVREG_VERSION,
214 /* szDriverName */
215 "MainAudioSniffer",
216 /* szRCMod */
217 "",
218 /* szR0Mod */
219 "",
220 /* pszDescription */
221 "Main Audio Sniffer driver (Main as in the API).",
222 /* fFlags */
223 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
224 /* fClass. */
225 PDM_DRVREG_CLASS_AUDIO,
226 /* cMaxInstances */
227 ~0,
228 /* cbInstance */
229 sizeof(DRVAUDIOSNIFFER),
230 /* pfnConstruct */
231 AudioSniffer::drvConstruct,
232 /* pfnDestruct */
233 AudioSniffer::drvDestruct,
234 /* pfnRelocate */
235 NULL,
236 /* pfnIOCtl */
237 NULL,
238 /* pfnPowerOn */
239 NULL,
240 /* pfnReset */
241 NULL,
242 /* pfnSuspend */
243 NULL,
244 /* pfnResume */
245 NULL,
246 /* pfnAttach */
247 NULL,
248 /* pfnDetach */
249 NULL,
250 /* pfnPowerOff */
251 NULL,
252 /* pfnSoftReset */
253 NULL,
254 /* u32EndVersion */
255 PDM_DRVREG_VERSION
256};
257/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette