VirtualBox

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

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

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 KB
Line 
1/* $Id: AudioSnifferInterface.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * VirtualBox Driver Interface to Audio Sniffer device
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
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
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 *
42 * @extends PDMIAUDIOSNIFFERCONNECTOR
43 */
44typedef struct DRVAUDIOSNIFFER
45{
46 /** Pointer to the Audio Sniffer object. */
47 AudioSniffer *pAudioSniffer;
48
49 /** Pointer to the driver instance structure. */
50 PPDMDRVINS pDrvIns;
51
52 /** Pointer to the AudioSniffer port interface of the driver/device above us. */
53 PPDMIAUDIOSNIFFERPORT pUpPort;
54 /** Our VMM device connector interface. */
55 PDMIAUDIOSNIFFERCONNECTOR Connector;
56
57} DRVAUDIOSNIFFER, *PDRVAUDIOSNIFFER;
58
59/** Converts PDMIAUDIOSNIFFERCONNECTOR pointer to a DRVAUDIOSNIFFER pointer. */
60#define PDMIAUDIOSNIFFERCONNECTOR_2_MAINAUDIOSNIFFER(pInterface) RT_FROM_MEMBER(pInterface, DRVAUDIOSNIFFER, Connector)
61
62
63//
64// constructor / destructor
65//
66AudioSniffer::AudioSniffer(Console *console)
67 : mpDrv(NULL),
68 mParent(console)
69{
70}
71
72AudioSniffer::~AudioSniffer()
73{
74 if (mpDrv)
75 {
76 mpDrv->pAudioSniffer = NULL;
77 mpDrv = NULL;
78 }
79}
80
81PPDMIAUDIOSNIFFERPORT AudioSniffer::getAudioSnifferPort()
82{
83 Assert(mpDrv);
84 return mpDrv->pUpPort;
85}
86
87
88
89//
90// public methods
91//
92
93DECLCALLBACK(void) iface_AudioSamplesOut (PPDMIAUDIOSNIFFERCONNECTOR pInterface, void *pvSamples, uint32_t cSamples,
94 int samplesPerSec, int nChannels, int bitsPerSample, bool fUnsigned)
95{
96 PDRVAUDIOSNIFFER pDrv = PDMIAUDIOSNIFFERCONNECTOR_2_MAINAUDIOSNIFFER(pInterface);
97
98 /*
99 * Just call the VRDP server with the data.
100 */
101 VRDPAUDIOFORMAT format = VRDP_AUDIO_FMT_MAKE(samplesPerSec, nChannels, bitsPerSample, !fUnsigned);
102 pDrv->pAudioSniffer->getParent()->consoleVRDPServer()->SendAudioSamples(pvSamples, cSamples, format);
103}
104
105DECLCALLBACK(void) iface_AudioVolumeOut (PPDMIAUDIOSNIFFERCONNECTOR pInterface, uint16_t left, uint16_t right)
106{
107 PDRVAUDIOSNIFFER pDrv = PDMIAUDIOSNIFFERCONNECTOR_2_MAINAUDIOSNIFFER(pInterface);
108
109 /*
110 * Just call the VRDP server with the data.
111 */
112 pDrv->pAudioSniffer->getParent()->consoleVRDPServer()->SendAudioVolume(left, right);
113}
114
115
116/**
117 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
118 */
119DECLCALLBACK(void *) AudioSniffer::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
120{
121 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
122 PDRVAUDIOSNIFFER pDrv = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER);
123 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
124 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIAUDIOSNIFFERCONNECTOR, &pDrv->Connector);
125 return NULL;
126}
127
128
129/**
130 * Destruct a Audio Sniffer driver instance.
131 *
132 * @returns VBox status.
133 * @param pDrvIns The driver instance data.
134 */
135DECLCALLBACK(void) AudioSniffer::drvDestruct(PPDMDRVINS pDrvIns)
136{
137 PDRVAUDIOSNIFFER pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER);
138 LogFlow(("AudioSniffer::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
139 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
140
141 if (pThis->pAudioSniffer)
142 {
143 pThis->pAudioSniffer->mpDrv = NULL;
144 }
145}
146
147
148/**
149 * Construct a AudioSniffer driver instance.
150 *
151 * @copydoc FNPDMDRVCONSTRUCT
152 */
153DECLCALLBACK(int) AudioSniffer::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
154{
155 PDRVAUDIOSNIFFER pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER);
156
157 LogFlow(("AudioSniffer::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
158 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
159
160 /*
161 * Validate configuration.
162 */
163 if (!CFGMR3AreValuesValid(pCfg, "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(pCfg, "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 /* szName */
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.

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