1
/* $Id: AudioSnifferInterface.cpp $ */
3
* VirtualBox Driver Interface to Audio Sniffer device
7
* Copyright (C) 2006-2010 Oracle Corporation
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.
18
#include "AudioSnifferInterface.h"
19
#include "ConsoleImpl.h"
20
#include "ConsoleVRDPServer.h"
24
#include <VBox/pdmdrv.h>
25
#include <VBox/vrdpapi.h>
26
#include <VBox/cfgm.h>
40
* Audio Sniffer driver instance data.
42
* @extends PDMIAUDIOSNIFFERCONNECTOR
44
typedef struct DRVAUDIOSNIFFER
46
/** Pointer to the Audio Sniffer object. */
47
AudioSniffer *pAudioSniffer;
49
/** Pointer to the driver instance structure. */
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;
57
} DRVAUDIOSNIFFER, *PDRVAUDIOSNIFFER;
59
/** Converts PDMIAUDIOSNIFFERCONNECTOR pointer to a DRVAUDIOSNIFFER pointer. */
60
#define PDMIAUDIOSNIFFERCONNECTOR_2_MAINAUDIOSNIFFER(pInterface) RT_FROM_MEMBER(pInterface, DRVAUDIOSNIFFER, Connector)
64
// constructor / destructor
66
AudioSniffer::AudioSniffer(Console *console)
72
AudioSniffer::~AudioSniffer()
76
mpDrv->pAudioSniffer = NULL;
81
PPDMIAUDIOSNIFFERPORT AudioSniffer::getAudioSnifferPort()
84
return mpDrv->pUpPort;
93
DECLCALLBACK(void) iface_AudioSamplesOut (PPDMIAUDIOSNIFFERCONNECTOR pInterface, void *pvSamples, uint32_t cSamples,
94
int samplesPerSec, int nChannels, int bitsPerSample, bool fUnsigned)
96
PDRVAUDIOSNIFFER pDrv = PDMIAUDIOSNIFFERCONNECTOR_2_MAINAUDIOSNIFFER(pInterface);
99
* Just call the VRDP server with the data.
101
VRDPAUDIOFORMAT format = VRDP_AUDIO_FMT_MAKE(samplesPerSec, nChannels, bitsPerSample, !fUnsigned);
102
pDrv->pAudioSniffer->getParent()->consoleVRDPServer()->SendAudioSamples(pvSamples, cSamples, format);
105
DECLCALLBACK(void) iface_AudioVolumeOut (PPDMIAUDIOSNIFFERCONNECTOR pInterface, uint16_t left, uint16_t right)
107
PDRVAUDIOSNIFFER pDrv = PDMIAUDIOSNIFFERCONNECTOR_2_MAINAUDIOSNIFFER(pInterface);
110
* Just call the VRDP server with the data.
112
pDrv->pAudioSniffer->getParent()->consoleVRDPServer()->SendAudioVolume(left, right);
117
* @interface_method_impl{PDMIBASE,pfnQueryInterface}
119
DECLCALLBACK(void *) AudioSniffer::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
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);
130
* Destruct a Audio Sniffer driver instance.
132
* @returns VBox status.
133
* @param pDrvIns The driver instance data.
135
DECLCALLBACK(void) AudioSniffer::drvDestruct(PPDMDRVINS pDrvIns)
137
PDRVAUDIOSNIFFER pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER);
138
LogFlow(("AudioSniffer::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
139
PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
141
if (pThis->pAudioSniffer)
143
pThis->pAudioSniffer->mpDrv = NULL;
149
* Construct a AudioSniffer driver instance.
151
* @copydoc FNPDMDRVCONSTRUCT
153
DECLCALLBACK(int) AudioSniffer::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
155
PDRVAUDIOSNIFFER pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER);
157
LogFlow(("AudioSniffer::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
158
PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
161
* Validate configuration.
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);
172
pDrvIns->IBase.pfnQueryInterface = AudioSniffer::drvQueryInterface;
174
/* Audio Sniffer connector. */
175
pThis->Connector.pfnAudioSamplesOut = iface_AudioSamplesOut;
176
pThis->Connector.pfnAudioVolumeOut = iface_AudioVolumeOut;
179
* Get the Audio Sniffer Port interface of the above driver/device.
181
pThis->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIAUDIOSNIFFERPORT);
184
AssertMsgFailed(("Configuration error: No Audio Sniffer port interface above!\n"));
185
return VERR_PDM_MISSING_INTERFACE_ABOVE;
189
* Get the Console object pointer and update the mpDrv member.
192
int rc = CFGMR3QueryPtr(pCfg, "Object", &pv);
195
AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
198
pThis->pAudioSniffer = (AudioSniffer *)pv; /** @todo Check this cast! */
199
pThis->pAudioSniffer->mpDrv = pThis;
206
* Audio Sniffer driver registration record.
208
const PDMDRVREG AudioSniffer::DrvReg =
219
"Main Audio Sniffer driver (Main as in the API).",
221
PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
223
PDM_DRVREG_CLASS_AUDIO,
227
sizeof(DRVAUDIOSNIFFER),
229
AudioSniffer::drvConstruct,
231
AudioSniffer::drvDestruct,
255
/* vi: set tabstop=4 shiftwidth=4 expandtab: */