1 | /* $Id: AudioDriver.h 93444 2022-01-26 18:01:15Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox audio base class for Main audio drivers.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2018-2022 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 | #ifndef MAIN_INCLUDED_AudioDriver_h
|
---|
19 | #define MAIN_INCLUDED_AudioDriver_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include <VBox/com/ptr.h>
|
---|
25 | #include <VBox/com/string.h>
|
---|
26 | #include <VBox/com/AutoLock.h>
|
---|
27 |
|
---|
28 | using namespace com;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Audio driver configuration for audio drivers implemented
|
---|
32 | * in Main.
|
---|
33 | */
|
---|
34 | struct AudioDriverCfg
|
---|
35 | {
|
---|
36 | AudioDriverCfg(Utf8Str a_strDev = "", unsigned a_uInst = 0, unsigned a_uLUN = 0, Utf8Str a_strName = "",
|
---|
37 | bool a_fEnabledIn = false, bool a_fEnabledOut = false)
|
---|
38 | : strDev(a_strDev)
|
---|
39 | , uInst(a_uInst)
|
---|
40 | , uLUN(a_uLUN)
|
---|
41 | , strName(a_strName)
|
---|
42 | , fEnabledIn(a_fEnabledIn)
|
---|
43 | , fEnabledOut(a_fEnabledOut)
|
---|
44 | { }
|
---|
45 |
|
---|
46 | /** Copy assignment operator. */
|
---|
47 | AudioDriverCfg& operator=(AudioDriverCfg const &a_rThat) RT_NOEXCEPT
|
---|
48 | {
|
---|
49 | this->strDev = a_rThat.strDev;
|
---|
50 | this->uInst = a_rThat.uInst;
|
---|
51 | this->uLUN = a_rThat.uLUN;
|
---|
52 | this->strName = a_rThat.strName;
|
---|
53 | this->fEnabledIn = a_rThat.fEnabledIn;
|
---|
54 | this->fEnabledOut = a_rThat.fEnabledOut;
|
---|
55 |
|
---|
56 | return *this;
|
---|
57 | }
|
---|
58 |
|
---|
59 | /** The device name. */
|
---|
60 | Utf8Str strDev;
|
---|
61 | /** The device instance. */
|
---|
62 | unsigned uInst;
|
---|
63 | /** The LUN the driver is attached to.
|
---|
64 | * Set the UINT8_MAX if not attached. */
|
---|
65 | unsigned uLUN;
|
---|
66 | /** The driver name. */
|
---|
67 | Utf8Str strName;
|
---|
68 | /** Whether input is enabled. */
|
---|
69 | bool fEnabledIn;
|
---|
70 | /** Whether output is enabled. */
|
---|
71 | bool fEnabledOut;
|
---|
72 | };
|
---|
73 |
|
---|
74 | class Console;
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Base class for all audio drivers implemented in Main.
|
---|
78 | */
|
---|
79 | class AudioDriver
|
---|
80 | {
|
---|
81 |
|
---|
82 | public:
|
---|
83 | AudioDriver(Console *pConsole);
|
---|
84 | virtual ~AudioDriver();
|
---|
85 |
|
---|
86 | /** Copy assignment operator. */
|
---|
87 | AudioDriver &operator=(AudioDriver const &a_rThat) RT_NOEXCEPT;
|
---|
88 |
|
---|
89 | Console *GetParent(void) { return mpConsole; }
|
---|
90 |
|
---|
91 | AudioDriverCfg *GetConfig(void) { return &mCfg; }
|
---|
92 | int InitializeConfig(AudioDriverCfg *pCfg);
|
---|
93 |
|
---|
94 | /** Checks if audio is configured or not. */
|
---|
95 | bool isConfigured() const { return mCfg.strName.isNotEmpty(); }
|
---|
96 |
|
---|
97 | bool IsAttached(void) { return mfAttached; }
|
---|
98 |
|
---|
99 | int doAttachDriverViaEmt(PUVM pUVM, PCVMMR3VTABLE pVMM, util::AutoWriteLock *pAutoLock);
|
---|
100 | int doDetachDriverViaEmt(PUVM pUVM, PCVMMR3VTABLE pVMM, util::AutoWriteLock *pAutoLock);
|
---|
101 |
|
---|
102 | protected:
|
---|
103 | static DECLCALLBACK(int) attachDriverOnEmt(AudioDriver *pThis);
|
---|
104 | static DECLCALLBACK(int) detachDriverOnEmt(AudioDriver *pThis);
|
---|
105 |
|
---|
106 | int configure(unsigned uLUN, bool fAttach);
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * Virtual function for child specific driver configuration.
|
---|
110 | *
|
---|
111 | * This is called at the end of AudioDriver::configure().
|
---|
112 | *
|
---|
113 | * @returns VBox status code.
|
---|
114 | * @param pLunCfg CFGM configuration node of the driver.
|
---|
115 | * @param pVMM The VMM ring-3 vtable.
|
---|
116 | */
|
---|
117 | virtual int configureDriver(PCFGMNODE pLunCfg, PCVMMR3VTABLE pVMM)
|
---|
118 | {
|
---|
119 | RT_NOREF(pLunCfg, pVMM);
|
---|
120 | return VINF_SUCCESS;
|
---|
121 | }
|
---|
122 |
|
---|
123 | protected:
|
---|
124 |
|
---|
125 | /** Pointer to parent. */
|
---|
126 | Console *mpConsole;
|
---|
127 | /** The driver's configuration. */
|
---|
128 | AudioDriverCfg mCfg;
|
---|
129 | /** Whether the driver is attached or not. */
|
---|
130 | bool mfAttached;
|
---|
131 | };
|
---|
132 |
|
---|
133 | #endif /* !MAIN_INCLUDED_AudioDriver_h */
|
---|
134 |
|
---|