VirtualBox

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

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

pdmifs.h: the final batch of refactored interface ID code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1/* $Id: AudioSnifferInterface.cpp 25985 2010-01-23 00:51:04Z 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 */
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 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 */
138DECLCALLBACK(void) AudioSniffer::drvDestruct(PPDMDRVINS pDrvIns)
139{
140 PDRVAUDIOSNIFFER pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER);
141 LogFlow(("AudioSniffer::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
142 if (pThis->pAudioSniffer)
143 {
144 pThis->pAudioSniffer->mpDrv = NULL;
145 }
146}
147
148
149/**
150 * Construct a AudioSniffer driver instance.
151 *
152 * @copydoc FNPDMDRVCONSTRUCT
153 */
154DECLCALLBACK(int) AudioSniffer::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
155{
156 PDRVAUDIOSNIFFER pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER);
157
158 LogFlow(("AudioSniffer::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
159
160 /*
161 * Validate configuration.
162 */
163 if (!CFGMR3AreValuesValid(pCfgHandle, "Object\0"))
164 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
165 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
166 ("Configuration error: Not possible to attach anything to this driver!\n"),
167 VERR_PDM_DRVINS_NO_ATTACH);
168
169 /*
170 * IBase.
171 */
172 pDrvIns->IBase.pfnQueryInterface = AudioSniffer::drvQueryInterface;
173
174 /* Audio Sniffer connector. */
175 pThis->Connector.pfnAudioSamplesOut = iface_AudioSamplesOut;
176 pThis->Connector.pfnAudioVolumeOut = iface_AudioVolumeOut;
177
178 /*
179 * Get the Audio Sniffer Port interface of the above driver/device.
180 */
181 pThis->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIAUDIOSNIFFERPORT);
182 if (!pThis->pUpPort)
183 {
184 AssertMsgFailed(("Configuration error: No Audio Sniffer port interface above!\n"));
185 return VERR_PDM_MISSING_INTERFACE_ABOVE;
186 }
187
188 /*
189 * Get the Console object pointer and update the mpDrv member.
190 */
191 void *pv;
192 int rc = CFGMR3QueryPtr(pCfgHandle, "Object", &pv);
193 if (RT_FAILURE(rc))
194 {
195 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
196 return rc;
197 }
198 pThis->pAudioSniffer = (AudioSniffer *)pv; /** @todo Check this cast! */
199 pThis->pAudioSniffer->mpDrv = pThis;
200
201 return VINF_SUCCESS;
202}
203
204
205/**
206 * Audio Sniffer driver registration record.
207 */
208const PDMDRVREG AudioSniffer::DrvReg =
209{
210 /* u32Version */
211 PDM_DRVREG_VERSION,
212 /* szDriverName */
213 "MainAudioSniffer",
214 /* szRCMod */
215 "",
216 /* szR0Mod */
217 "",
218 /* pszDescription */
219 "Main Audio Sniffer driver (Main as in the API).",
220 /* fFlags */
221 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
222 /* fClass. */
223 PDM_DRVREG_CLASS_AUDIO,
224 /* cMaxInstances */
225 ~0,
226 /* cbInstance */
227 sizeof(DRVAUDIOSNIFFER),
228 /* pfnConstruct */
229 AudioSniffer::drvConstruct,
230 /* pfnDestruct */
231 AudioSniffer::drvDestruct,
232 /* pfnRelocate */
233 NULL,
234 /* pfnIOCtl */
235 NULL,
236 /* pfnPowerOn */
237 NULL,
238 /* pfnReset */
239 NULL,
240 /* pfnSuspend */
241 NULL,
242 /* pfnResume */
243 NULL,
244 /* pfnAttach */
245 NULL,
246 /* pfnDetach */
247 NULL,
248 /* pfnPowerOff */
249 NULL,
250 /* pfnSoftReset */
251 NULL,
252 /* u32EndVersion */
253 PDM_DRVREG_VERSION
254};
255/* 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