VirtualBox

Changeset 70644 in vbox


Ignore:
Timestamp:
Jan 19, 2018 12:20:33 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
120374
Message:

Audio/Main: More code needed for attaching / detaching host backends at runtime.

Location:
trunk/src/VBox/Main
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/AudioDriver.h

    r70579 r70644  
    3131struct AudioDriverCfg
    3232{
    33     AudioDriverCfg(Utf8Str a_strDev = "", unsigned a_uInst = 0, Utf8Str a_strName = "")
     33    AudioDriverCfg(Utf8Str a_strDev = "", unsigned a_uInst = 0, unsigned a_uLUN = 0, Utf8Str a_strName = "")
    3434        : strDev(a_strDev)
    3535        , uInst(a_uInst)
     36        , uLUN(a_uLUN)
    3637        , strName(a_strName) { }
    3738
     
    4041        this->strDev  = that.strDev;
    4142        this->uInst   = that.uInst;
     43        this->uLUN    = that.uLUN;
    4244        this->strName = that.strName;
    4345
     
    4951    /** The device instance. */
    5052    unsigned             uInst;
     53    /** The LUN the driver is attached to.
     54     *  Set the UINT8_MAX if not attached. */
     55    unsigned             uLUN;
    5156    /** The driver name. */
    5257    Utf8Str              strName;
     
    8691    /**
    8792     * Optional (virtual) function to give the derived audio driver
    88      * class the ability to add more driver configuration entries when
    89      * setting up.
     93     * class the ability to add (or change) the driver configuration
     94     * entries when setting up.
    9095     *
    91      * @param pLunCfg           CFGM configuration node of the driver.
     96     * @return VBox status code.
     97     * @param  pLunCfg          CFGM configuration node of the driver.
    9298     */
    93     virtual void configureDriver(PCFGMNODE pLunCfg) { RT_NOREF(pLunCfg); }
    94 
    95     unsigned getFreeLUN(void);
     99    virtual int configureDriver(PCFGMNODE pLunCfg) { RT_NOREF(pLunCfg); return VINF_SUCCESS; }
    96100
    97101protected:
     
    103107    /** Whether the driver is attached or not. */
    104108    bool                 mfAttached;
    105     /** The LUN the driver is attached to.
    106      *  Set the UINT8_MAX if not attached. */
    107     unsigned             muLUN;
    108109};
    109110
  • trunk/src/VBox/Main/include/DrvAudioVRDE.h

    r70553 r70644  
    6262private:
    6363
    64     void configureDriver(PCFGMNODE pLunCfg);
     64    int configureDriver(PCFGMNODE pLunCfg);
    6565
    6666    /** Pointer to the associated VRDE audio driver. */
  • trunk/src/VBox/Main/include/DrvAudioVideoRec.h

    r70563 r70644  
    5050private:
    5151
    52     void configureDriver(PCFGMNODE pLunCfg);
     52    int configureDriver(PCFGMNODE pLunCfg);
    5353
    5454    /** Pointer to the associated video recording audio driver. */
  • trunk/src/VBox/Main/src-client/AudioDriver.cpp

    r70626 r70644  
    3535    : mpConsole(pConsole)
    3636    , mfAttached(false)
    37     , muLUN(UINT8_MAX)
    3837{
    3938}
     
    4342}
    4443
    45 /**
    46  * Returns the next free LUN of the audio device driver
    47  * 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 
    7344
    7445/**
    7546 * Initializes the audio driver with a certain (device) configuration.
    76  *
    77  * @note The driver's LUN will be determined on runtime when attaching the
    78  *       driver to the audio driver chain.
    7947 *
    8048 * @returns VBox status code.
     
    8452{
    8553    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);
    8659
    8760    /* Apply configuration. */
     
    142115    Assert(ptrVM.isOk());
    143116
    144 
    145117    if (pThis->mfAttached) /* Already attached? Bail out. */
    146118    {
     
    151123    AudioDriverCfg *pCfg = &pThis->mCfg;
    152124
    153     unsigned uLUN = pThis->muLUN;
    154     if (uLUN == UINT8_MAX) /* No LUN assigned / configured yet? Retrieve it. */
    155         uLUN = pThis->getFreeLUN();
    156 
    157125    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    {
    167134        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));
    170136    }
    171137    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;
    175142}
    176143
     
    232199    Assert(ptrVM.isOk());
    233200
    234     Assert(pThis->muLUN != UINT8_MAX);
    235 
    236201    AudioDriverCfg *pCfg = &pThis->mCfg;
    237202
     203    Assert(pCfg->uLUN != UINT8_MAX);
     204
    238205    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    {
    249214        pThis->mfAttached = false;
    250 
    251215        LogRel2(("%s: Driver detached\n", pCfg->strName.c_str()));
    252216    }
    253217    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;
    257222}
    258223
     
    268233int AudioDriver::configure(unsigned uLUN, bool fAttach)
    269234{
    270     int rc = VINF_SUCCESS;
    271 
    272235    Console::SafeVMPtrQuiet ptrVM(mpConsole);
    273236    Assert(ptrVM.isOk());
     
    276239    AssertPtr(pUVM);
    277240
    278     PCFGMNODE pRoot   = CFGMR3GetRootU(pUVM);
     241    PCFGMNODE pRoot = CFGMR3GetRootU(pUVM);
    279242    AssertPtr(pRoot);
    280     PCFGMNODE pDev0   = CFGMR3GetChildF(pRoot, "Devices/%s/%u/", mCfg.strDev.c_str(), mCfg.uInst);
     243    PCFGMNODE pDev0 = CFGMR3GetChildF(pRoot, "Devices/%s/%u/", mCfg.strDev.c_str(), mCfg.uInst);
    281244
    282245    if (!pDev0) /* No audio device configured? Bail out. */
     
    286249    }
    287250
     251    int rc = VINF_SUCCESS;
     252
    288253    PCFGMNODE pDevLun = CFGMR3GetChildF(pDev0, "LUN#%u/", uLUN);
    289254
    290255    if (fAttach)
    291256    {
    292         AssertMsg(uLUN != UINT8_MAX, ("%s: LUN is undefined when it must not\n", mCfg.strName.c_str()));
    293 
    294         if (!pDevLun)
     257        do
    295258        {
    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);
    313275
    314276                /* 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);
    319280    }
    320281    else /* Detach */
     
    323284        {
    324285            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);
    326296        }
    327         else
    328             rc = VERR_NOT_FOUND;
    329     }
    330 
    331 #ifdef DEBUG_andy
    332     CFGMR3Dump(pDev0);
    333 #endif
     297    }
    334298
    335299    if (RT_FAILURE(rc))
     
    337301                mCfg.strName.c_str(), fAttach ? "Configuring" : "Unconfiguring", rc));
    338302
     303    LogFunc(("Returning %Rrc\n", rc));
    339304    return rc;
    340305}
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r70579 r70644  
    98409840            AssertComRCReturnVoid(rc);
    98419841
    9842             if (fVRDEEnabled)
     9842            if (   fVRDEEnabled
     9843                && pConsole->mAudioVRDE)
    98439844                pConsole->mAudioVRDE->doAttachDriverViaEmt(pConsole->mpUVM, &alock);
    98449845        }
     
    98489849        pConsole->i_consoleVRDPServer()->EnableConnections();
    98499850
    9850 #ifdef VBOX_WITH_AUDIO_VIDEOREC
    98519851        Display *pDisplay = pConsole->i_getDisplay();
    98529852        AssertPtr(pDisplay);
     
    98559855            pDisplay->i_videoRecInvalidate();
    98569856
     9857            /* If video recording fails for whatever reason here, this is
     9858             * non-critical and should not be returned at this point -- otherwise
     9859             * the display driver construction fails completely. */
     9860            int vrc2 = VINF_SUCCESS;
     9861
     9862#ifdef VBOX_WITH_AUDIO_VIDEOREC
    98579863            /* Attach the video recording audio driver if required. */
    9858             if (pDisplay->i_videoRecGetEnabled() & VIDEORECFEATURE_AUDIO)
    9859                 pConsole->mAudioVideoRec->doAttachDriverViaEmt(pConsole->mpUVM, &alock);
    9860         }
     9864            if (   pDisplay->i_videoRecGetEnabled() & VIDEORECFEATURE_AUDIO
     9865                && pConsole->mAudioVideoRec)
     9866                vrc2 = pConsole->mAudioVideoRec->doAttachDriverViaEmt(pConsole->mpUVM, &alock);
    98619867#endif
     9868            if (   RT_SUCCESS(vrc2)
     9869                && pDisplay->i_videoRecGetEnabled()) /* Any video recording (audio and/or video) feature enabled? */
     9870            {
     9871                vrc2 = pDisplay->i_videoRecStart();
     9872                if (RT_SUCCESS(vrc2))
     9873                    fireVideoCaptureChangedEvent(pConsole->i_getEventSource());
     9874            }
     9875        }
     9876
    98629877        if (RT_SUCCESS(vrc))
    98639878        {
  • trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp

    r70628 r70644  
    29792979
    29802980#ifdef VBOX_WITH_AUDIO_VRDE
    2981             AudioDriverCfg DrvCfgVRDE(strAudioDevice, 0 /* Instance */, "AudioVRDE");
     2981            /* Insert dummy audio driver to have the LUN configured. */
     2982            CFGMR3InsertNodeF(pInst, &pLunL0, "LUN#%RU8", uAudioLUN);
     2983                InsertConfigString(pLunL0, "Driver", "AUDIO");
     2984            AudioDriverCfg DrvCfgVRDE(strAudioDevice, 0 /* Instance */, uAudioLUN, "AudioVRDE");
    29822985            rc = mAudioVRDE->InitializeConfig(&DrvCfgVRDE);
    2983             AssertRC(rc);
     2986            if (RT_SUCCESS(rc))
     2987                uAudioLUN++;
    29842988#endif /* VBOX_WITH_AUDIO_VRDE */
    29852989
    29862990#ifdef VBOX_WITH_AUDIO_VIDEOREC
    2987             AudioDriverCfg DrvCfgVideoRec(strAudioDevice, 0 /* Instance */, "AudioVideoRec");
     2991            /* Insert dummy audio driver to have the LUN configured. */
     2992            CFGMR3InsertNodeF(pInst, &pLunL0, "LUN#%RU8", uAudioLUN);
     2993                InsertConfigString(pLunL0, "Driver", "AUDIO");
     2994            AudioDriverCfg DrvCfgVideoRec(strAudioDevice, 0 /* Instance */, uAudioLUN, "AudioVideoRec");
    29882995            rc = mAudioVideoRec->InitializeConfig(&DrvCfgVideoRec);
    2989             AssertRC(rc);
     2996            if (RT_SUCCESS(rc))
     2997                uAudioLUN++;
    29902998#endif /* VBOX_WITH_AUDIO_VIDEOREC */
    29912999
  • trunk/src/VBox/Main/src-client/DisplayImpl.cpp

    r70596 r70644  
    45694569#endif
    45704570
    4571 #ifdef VBOX_WITH_VIDEOREC
    4572     if (pDisplay->i_videoRecGetEnabled())
    4573     {
    4574         int rc2 = pDisplay->i_videoRecStart();
    4575         if (RT_SUCCESS(rc2))
    4576             fireVideoCaptureChangedEvent(pDisplay->mParent->i_getEventSource());
    4577 
    4578         /* If video recording fails for whatever reason here, this is
    4579          * non-critical and should not be returned at this point -- otherwise
    4580          * the display driver construction fails completely. */
    4581     }
    4582 #endif
    4583 
    45844571    return rc;
    45854572}
  • trunk/src/VBox/Main/src-client/DrvAudioVRDE.cpp

    r70553 r70644  
    586586
    587587
    588 void AudioVRDE::configureDriver(PCFGMNODE pLunCfg)
     588/**
     589 * @copydoc AudioDriver::configureDriver
     590 */
     591int AudioVRDE::configureDriver(PCFGMNODE pLunCfg)
    589592{
    590593    CFGMR3InsertInteger(pLunCfg, "Object", (uintptr_t)this);
    591594    CFGMR3InsertInteger(pLunCfg, "ObjectVRDPServer", (uintptr_t)mpConsole->i_consoleVRDPServer());
    592 }
     595
     596    return VINF_SUCCESS;
     597}
     598
    593599
    594600int AudioVRDE::onVRDEControl(bool fEnable, uint32_t uFlags)
  • trunk/src/VBox/Main/src-client/DrvAudioVideoRec.cpp

    r70563 r70644  
    10321032
    10331033
    1034 void AudioVideoRec::configureDriver(PCFGMNODE pLunCfg)
     1034/**
     1035 * @copydoc AudioDriver::configureDriver
     1036 */
     1037int AudioVideoRec::configureDriver(PCFGMNODE pLunCfg)
    10351038{
    10361039    CFGMR3InsertInteger(pLunCfg, "Object",        (uintptr_t)mpConsole->i_getAudioVideoRec());
    10371040    CFGMR3InsertInteger(pLunCfg, "ObjectConsole", (uintptr_t)mpConsole);
     1041
     1042    return VINF_SUCCESS;
    10381043}
    10391044
Note: See TracChangeset for help on using the changeset viewer.

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