Changeset 70644 in vbox for trunk/src/VBox/Main/src-client/AudioDriver.cpp
- Timestamp:
- Jan 19, 2018 12:20:33 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 120374
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-client/AudioDriver.cpp
r70626 r70644 35 35 : mpConsole(pConsole) 36 36 , mfAttached(false) 37 , muLUN(UINT8_MAX)38 37 { 39 38 } … … 43 42 } 44 43 45 /**46 * Returns the next free LUN of the audio device driver47 * chain.48 *49 * @return unsigned Next free LUN in audio device driver chain.50 */51 unsigned AudioDriver::getFreeLUN(void)52 {53 Console::SafeVMPtrQuiet ptrVM(mpConsole);54 Assert(ptrVM.isOk());55 56 PUVM pUVM = ptrVM.rawUVM();57 AssertPtr(pUVM);58 59 unsigned uLUN = 0;60 61 PCFGMNODE pDevLUN;62 for (;;)63 {64 pDevLUN = CFGMR3GetChildF(CFGMR3GetRootU(pUVM), "Devices/%s/%u/LUN#%u/", mCfg.strDev.c_str(), mCfg.uInst, uLUN);65 if (!pDevLUN)66 break;67 uLUN++;68 }69 70 return uLUN;71 }72 73 44 74 45 /** 75 46 * Initializes the audio driver with a certain (device) configuration. 76 *77 * @note The driver's LUN will be determined on runtime when attaching the78 * driver to the audio driver chain.79 47 * 80 48 * @returns VBox status code. … … 84 52 { 85 53 AssertPtrReturn(pCfg, VERR_INVALID_POINTER); 54 55 /* Sanity. */ 56 AssertReturn(pCfg->strDev.isNotEmpty(), VERR_INVALID_PARAMETER); 57 AssertReturn(pCfg->uLUN != UINT8_MAX, VERR_INVALID_PARAMETER); 58 AssertReturn(pCfg->strName.isNotEmpty(), VERR_INVALID_PARAMETER); 86 59 87 60 /* Apply configuration. */ … … 142 115 Assert(ptrVM.isOk()); 143 116 144 145 117 if (pThis->mfAttached) /* Already attached? Bail out. */ 146 118 { … … 151 123 AudioDriverCfg *pCfg = &pThis->mCfg; 152 124 153 unsigned uLUN = pThis->muLUN;154 if (uLUN == UINT8_MAX) /* No LUN assigned / configured yet? Retrieve it. */155 uLUN = pThis->getFreeLUN();156 157 125 LogFunc(("strName=%s, strDevice=%s, uInst=%u, uLUN=%u\n", 158 pCfg->strName.c_str(), pCfg->strDev.c_str(), pCfg->uInst, uLUN)); 159 160 int vrc = pThis->configure(uLUN, true /* Attach */); 161 if (RT_SUCCESS(vrc)) 162 vrc = PDMR3DeviceAttach(ptrVM.rawUVM(), pCfg->strDev.c_str(), pCfg->uInst, uLUN, 0 /* fFlags */, 163 NULL /* ppBase */); 164 if (RT_SUCCESS(vrc)) 165 { 166 pThis->muLUN = uLUN; 126 pCfg->strName.c_str(), pCfg->strDev.c_str(), pCfg->uInst, pCfg->uLUN)); 127 128 int rc = pThis->configure(pCfg->uLUN, true /* Attach */); 129 if (RT_SUCCESS(rc)) 130 rc = PDMR3DriverAttach(ptrVM.rawUVM(), pCfg->strDev.c_str(), pCfg->uInst, pCfg->uLUN, 0 /* fFlags */, 131 NULL /* ppBase */); 132 if (RT_SUCCESS(rc)) 133 { 167 134 pThis->mfAttached = true; 168 169 LogRel2(("%s: Driver attached (LUN #%u)\n", pCfg->strName.c_str(), pThis->muLUN)); 135 LogRel2(("%s: Driver attached (LUN #%u)\n", pCfg->strName.c_str(), pCfg->uLUN)); 170 136 } 171 137 else 172 LogRel(("%s: Failed to attach audio driver, rc=%Rrc\n", pCfg->strName.c_str(), vrc)); 173 174 return vrc; 138 LogRel(("%s: Failed to attach audio driver, rc=%Rrc\n", pCfg->strName.c_str(), rc)); 139 140 LogFunc(("Returning %Rrc\n", rc)); 141 return rc; 175 142 } 176 143 … … 232 199 Assert(ptrVM.isOk()); 233 200 234 Assert(pThis->muLUN != UINT8_MAX);235 236 201 AudioDriverCfg *pCfg = &pThis->mCfg; 237 202 203 Assert(pCfg->uLUN != UINT8_MAX); 204 238 205 LogFunc(("strName=%s, strDevice=%s, uInst=%u, uLUN=%u\n", 239 pCfg->strName.c_str(), pCfg->strDev.c_str(), pCfg->uInst, pThis->muLUN)); 240 241 int vrc = PDMR3DriverDetach(ptrVM.rawUVM(), pCfg->strDev.c_str(), pCfg->uInst, pThis->muLUN, "AUDIO", 242 0 /* iOccurrence */, 0 /* fFlags */); 243 if (RT_SUCCESS(vrc)) 244 vrc = pThis->configure(pThis->muLUN, false /* Detach */); 245 246 if (RT_SUCCESS(vrc)) 247 { 248 pThis->muLUN = UINT8_MAX; 206 pCfg->strName.c_str(), pCfg->strDev.c_str(), pCfg->uInst, pCfg->uLUN)); 207 208 int rc = PDMR3DeviceDetach(ptrVM.rawUVM(), pCfg->strDev.c_str(), pCfg->uInst, pCfg->uLUN, 0 /* fFlags */); 209 if (RT_SUCCESS(rc)) 210 rc = pThis->configure(pCfg->uLUN, false /* Detach */); 211 212 if (RT_SUCCESS(rc)) 213 { 249 214 pThis->mfAttached = false; 250 251 215 LogRel2(("%s: Driver detached\n", pCfg->strName.c_str())); 252 216 } 253 217 else 254 LogRel(("%s: Failed to detach audio driver, rc=%Rrc\n", pCfg->strName.c_str(), vrc)); 255 256 return vrc; 218 LogRel(("%s: Failed to detach audio driver, rc=%Rrc\n", pCfg->strName.c_str(), rc)); 219 220 LogFunc(("Returning %Rrc\n", rc)); 221 return rc; 257 222 } 258 223 … … 268 233 int AudioDriver::configure(unsigned uLUN, bool fAttach) 269 234 { 270 int rc = VINF_SUCCESS;271 272 235 Console::SafeVMPtrQuiet ptrVM(mpConsole); 273 236 Assert(ptrVM.isOk()); … … 276 239 AssertPtr(pUVM); 277 240 278 PCFGMNODE pRoot 241 PCFGMNODE pRoot = CFGMR3GetRootU(pUVM); 279 242 AssertPtr(pRoot); 280 PCFGMNODE pDev0 243 PCFGMNODE pDev0 = CFGMR3GetChildF(pRoot, "Devices/%s/%u/", mCfg.strDev.c_str(), mCfg.uInst); 281 244 282 245 if (!pDev0) /* No audio device configured? Bail out. */ … … 286 249 } 287 250 251 int rc = VINF_SUCCESS; 252 288 253 PCFGMNODE pDevLun = CFGMR3GetChildF(pDev0, "LUN#%u/", uLUN); 289 254 290 255 if (fAttach) 291 256 { 292 AssertMsg(uLUN != UINT8_MAX, ("%s: LUN is undefined when it must not\n", mCfg.strName.c_str())); 293 294 if (!pDevLun) 257 do 295 258 { 296 LogRel2(("%s: Configuring audio driver (to LUN #%RU8)\n", mCfg.strName.c_str(), uLUN)); 297 298 PCFGMNODE pLunL0; 299 CFGMR3InsertNodeF(pDev0, &pLunL0, "LUN#%RU8", uLUN); 300 CFGMR3InsertString(pLunL0, "Driver", "AUDIO"); 301 302 PCFGMNODE pLunCfg; 303 CFGMR3InsertNode(pLunL0, "Config", &pLunCfg); 304 CFGMR3InsertStringF(pLunCfg, "DriverName", "%s", mCfg.strName.c_str()); 305 CFGMR3InsertInteger(pLunCfg, "InputEnabled", 0); /* Play safe by default. */ 306 CFGMR3InsertInteger(pLunCfg, "OutputEnabled", 1); 307 308 PCFGMNODE pLunL1; 309 CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); 310 CFGMR3InsertStringF(pLunL1, "Driver", "%s", mCfg.strName.c_str()); 311 312 CFGMR3InsertNode(pLunL1, "Config", &pLunCfg); 259 AssertMsgBreakStmt(pDevLun, ("%s: Device LUN #%u not found\n", mCfg.strName.c_str(), uLUN), rc = VERR_NOT_FOUND); 260 261 LogRel2(("%s: Configuring audio driver (to LUN #%u)\n", mCfg.strName.c_str(), uLUN)); 262 263 PCFGMNODE pLunCfg = CFGMR3GetChild(pDevLun, "Config"); 264 AssertBreakStmt(pLunCfg, rc = VERR_NOT_FOUND); 265 266 rc = CFGMR3InsertStringF(pLunCfg, "DriverName", "%s", mCfg.strName.c_str()); AssertRCBreak(rc); 267 268 rc = CFGMR3InsertInteger(pLunCfg, "InputEnabled", 0); /* Play safe by default. */ AssertRCBreak(rc); 269 rc = CFGMR3InsertInteger(pLunCfg, "OutputEnabled", 1); AssertRCBreak(rc); 270 271 PCFGMNODE pAttachedDriver, pAttachedDriverCfg; 272 rc = CFGMR3InsertNode(pDevLun, "AttachedDriver", &pAttachedDriver); AssertRCBreak(rc); 273 rc = CFGMR3InsertStringF(pAttachedDriver, "Driver", "%s", mCfg.strName.c_str()); AssertRCBreak(rc); 274 rc = CFGMR3InsertNode(pAttachedDriver, "Config", &pAttachedDriverCfg); AssertRCBreak(rc); 313 275 314 276 /* Call the (virtual) method for driver-specific configuration. */ 315 configureDriver(pLunCfg); 316 } 317 else 318 rc = VERR_ALREADY_EXISTS; 277 rc = configureDriver(pAttachedDriverCfg); AssertRCBreak(rc); 278 279 } while (0); 319 280 } 320 281 else /* Detach */ … … 323 284 { 324 285 LogRel2(("%s: Unconfiguring audio driver\n", mCfg.strName.c_str())); 325 CFGMR3RemoveNode(pDevLun); 286 287 PCFGMNODE pLunCfg = CFGMR3GetChild(pDevLun, "Config"); 288 if (pLunCfg) 289 CFGMR3RemoveNode(pLunCfg); 290 291 rc = CFGMR3InsertNode(pDevLun, "Config", &pLunCfg); 292 293 PCFGMNODE pLunAttachedDriver = CFGMR3GetChild(pDevLun, "AttachedDriver"); 294 if (pLunAttachedDriver) 295 CFGMR3RemoveNode(pLunAttachedDriver); 326 296 } 327 else 328 rc = VERR_NOT_FOUND; 329 } 330 331 #ifdef DEBUG_andy 332 CFGMR3Dump(pDev0); 333 #endif 297 } 334 298 335 299 if (RT_FAILURE(rc)) … … 337 301 mCfg.strName.c_str(), fAttach ? "Configuring" : "Unconfiguring", rc)); 338 302 303 LogFunc(("Returning %Rrc\n", rc)); 339 304 return rc; 340 305 }
Note:
See TracChangeset
for help on using the changeset viewer.