[70533] | 1 | /* $Id: AudioDriver.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * VirtualBox audio base class for Main audio drivers.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2018-2023 Oracle and/or its affiliates.
|
---|
[70533] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[70533] | 26 | */
|
---|
| 27 |
|
---|
[76562] | 28 | #ifndef MAIN_INCLUDED_AudioDriver_h
|
---|
| 29 | #define MAIN_INCLUDED_AudioDriver_h
|
---|
[76487] | 30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 31 | # pragma once
|
---|
| 32 | #endif
|
---|
[70533] | 33 |
|
---|
| 34 | #include <VBox/com/ptr.h>
|
---|
| 35 | #include <VBox/com/string.h>
|
---|
[70579] | 36 | #include <VBox/com/AutoLock.h>
|
---|
[70533] | 37 |
|
---|
| 38 | using namespace com;
|
---|
| 39 |
|
---|
| 40 | /**
|
---|
[70544] | 41 | * Audio driver configuration for audio drivers implemented
|
---|
| 42 | * in Main.
|
---|
[70533] | 43 | */
|
---|
| 44 | struct AudioDriverCfg
|
---|
| 45 | {
|
---|
[89580] | 46 | AudioDriverCfg(Utf8Str a_strDev = "", unsigned a_uInst = 0, unsigned a_uLUN = 0, Utf8Str a_strName = "",
|
---|
| 47 | bool a_fEnabledIn = false, bool a_fEnabledOut = false)
|
---|
[70533] | 48 | : strDev(a_strDev)
|
---|
| 49 | , uInst(a_uInst)
|
---|
[70644] | 50 | , uLUN(a_uLUN)
|
---|
[89580] | 51 | , strName(a_strName)
|
---|
| 52 | , fEnabledIn(a_fEnabledIn)
|
---|
| 53 | , fEnabledOut(a_fEnabledOut)
|
---|
| 54 | { }
|
---|
[70533] | 55 |
|
---|
[81674] | 56 | /** Copy assignment operator. */
|
---|
| 57 | AudioDriverCfg& operator=(AudioDriverCfg const &a_rThat) RT_NOEXCEPT
|
---|
[70533] | 58 | {
|
---|
[89580] | 59 | this->strDev = a_rThat.strDev;
|
---|
| 60 | this->uInst = a_rThat.uInst;
|
---|
| 61 | this->uLUN = a_rThat.uLUN;
|
---|
| 62 | this->strName = a_rThat.strName;
|
---|
| 63 | this->fEnabledIn = a_rThat.fEnabledIn;
|
---|
| 64 | this->fEnabledOut = a_rThat.fEnabledOut;
|
---|
[70533] | 65 |
|
---|
| 66 | return *this;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | /** The device name. */
|
---|
[89580] | 70 | Utf8Str strDev;
|
---|
[70533] | 71 | /** The device instance. */
|
---|
[89580] | 72 | unsigned uInst;
|
---|
[70644] | 73 | /** The LUN the driver is attached to.
|
---|
| 74 | * Set the UINT8_MAX if not attached. */
|
---|
[89580] | 75 | unsigned uLUN;
|
---|
[70544] | 76 | /** The driver name. */
|
---|
[89580] | 77 | Utf8Str strName;
|
---|
| 78 | /** Whether input is enabled. */
|
---|
| 79 | bool fEnabledIn;
|
---|
| 80 | /** Whether output is enabled. */
|
---|
| 81 | bool fEnabledOut;
|
---|
[70533] | 82 | };
|
---|
| 83 |
|
---|
| 84 | class Console;
|
---|
| 85 |
|
---|
| 86 | /**
|
---|
| 87 | * Base class for all audio drivers implemented in Main.
|
---|
| 88 | */
|
---|
| 89 | class AudioDriver
|
---|
| 90 | {
|
---|
| 91 |
|
---|
| 92 | public:
|
---|
| 93 | AudioDriver(Console *pConsole);
|
---|
| 94 | virtual ~AudioDriver();
|
---|
| 95 |
|
---|
[81674] | 96 | /** Copy assignment operator. */
|
---|
| 97 | AudioDriver &operator=(AudioDriver const &a_rThat) RT_NOEXCEPT;
|
---|
| 98 |
|
---|
[70579] | 99 | Console *GetParent(void) { return mpConsole; }
|
---|
| 100 |
|
---|
[70533] | 101 | AudioDriverCfg *GetConfig(void) { return &mCfg; }
|
---|
[70579] | 102 | int InitializeConfig(AudioDriverCfg *pCfg);
|
---|
[70533] | 103 |
|
---|
[70579] | 104 | /** Checks if audio is configured or not. */
|
---|
| 105 | bool isConfigured() const { return mCfg.strName.isNotEmpty(); }
|
---|
[70533] | 106 |
|
---|
| 107 | bool IsAttached(void) { return mfAttached; }
|
---|
| 108 |
|
---|
[93444] | 109 | int doAttachDriverViaEmt(PUVM pUVM, PCVMMR3VTABLE pVMM, util::AutoWriteLock *pAutoLock);
|
---|
| 110 | int doDetachDriverViaEmt(PUVM pUVM, PCVMMR3VTABLE pVMM, util::AutoWriteLock *pAutoLock);
|
---|
[70533] | 111 |
|
---|
| 112 | protected:
|
---|
[70579] | 113 | static DECLCALLBACK(int) attachDriverOnEmt(AudioDriver *pThis);
|
---|
| 114 | static DECLCALLBACK(int) detachDriverOnEmt(AudioDriver *pThis);
|
---|
[70533] | 115 |
|
---|
[70563] | 116 | int configure(unsigned uLUN, bool fAttach);
|
---|
| 117 |
|
---|
[70533] | 118 | /**
|
---|
[93444] | 119 | * Virtual function for child specific driver configuration.
|
---|
[70544] | 120 | *
|
---|
[93444] | 121 | * This is called at the end of AudioDriver::configure().
|
---|
| 122 | *
|
---|
| 123 | * @returns VBox status code.
|
---|
| 124 | * @param pLunCfg CFGM configuration node of the driver.
|
---|
| 125 | * @param pVMM The VMM ring-3 vtable.
|
---|
[70533] | 126 | */
|
---|
[93444] | 127 | virtual int configureDriver(PCFGMNODE pLunCfg, PCVMMR3VTABLE pVMM)
|
---|
| 128 | {
|
---|
| 129 | RT_NOREF(pLunCfg, pVMM);
|
---|
| 130 | return VINF_SUCCESS;
|
---|
| 131 | }
|
---|
[70533] | 132 |
|
---|
| 133 | protected:
|
---|
| 134 |
|
---|
| 135 | /** Pointer to parent. */
|
---|
| 136 | Console *mpConsole;
|
---|
| 137 | /** The driver's configuration. */
|
---|
| 138 | AudioDriverCfg mCfg;
|
---|
| 139 | /** Whether the driver is attached or not. */
|
---|
| 140 | bool mfAttached;
|
---|
| 141 | };
|
---|
| 142 |
|
---|
[76562] | 143 | #endif /* !MAIN_INCLUDED_AudioDriver_h */
|
---|
[70533] | 144 |
|
---|