VirtualBox

Changeset 70563 in vbox for trunk/src/VBox/Main/src-client


Ignore:
Timestamp:
Jan 12, 2018 5:52:10 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
120250
Message:

Audio/Main: Also made the video recording driver use the new AudioDriver base class, more bugfixing and clearer abstraction for the AudioDriver API.

Location:
trunk/src/VBox/Main/src-client
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/AudioDriver.cpp

    r70547 r70563  
    3535    : mpConsole(pConsole)
    3636    , mfAttached(false)
     37    , muLUN(UINT8_MAX)
    3738{
    3839}
     
    5859    unsigned uLUN = 0;
    5960
    60     /* First check if the LUN already exists. */
    6161    PCFGMNODE pDevLUN;
    6262    for (;;)
     
    7171}
    7272
     73int AudioDriver::Initialize(AudioDriverCfg *pCfg)
     74{
     75    AssertPtrReturn(pCfg, VERR_INVALID_POINTER);
     76
     77    /* Apply configuration. */
     78    mCfg = *pCfg;
     79
     80    return VINF_SUCCESS;
     81}
     82
    7383/**
    7484 * Configures the audio driver (to CFGM) and attaches it to the audio chain.
     
    7787 * @returns IPRT status code.
    7888 * @param   pThis               Audio driver to detach.
    79  * @param   pCfg                Audio driver configuration to use for the audio driver to attach.
    8089 */
    8190/* static */
    82 DECLCALLBACK(int) AudioDriver::Attach(AudioDriver *pThis, AudioDriverCfg *pCfg)
     91DECLCALLBACK(int) AudioDriver::Attach(AudioDriver *pThis)
    8392{
    8493    AssertPtrReturn(pThis, VERR_INVALID_POINTER);
     
    9099
    91100    if (pThis->mfAttached) /* Already attached? Bail out. */
     101    {
     102        LogFunc(("%s: Already attached\n", pThis->mCfg.strName.c_str()));
    92103        return VINF_SUCCESS;
    93 
    94     if (pCfg->uLUN == UINT8_MAX) /* No LUN assigned / configured yet? Retrieve it. */
    95         pCfg->uLUN = pThis->getFreeLUN();
     104    }
     105
     106    AudioDriverCfg *pCfg = &pThis->mCfg;
     107
     108    unsigned uLUN = pThis->muLUN;
     109    if (uLUN == UINT8_MAX) /* No LUN assigned / configured yet? Retrieve it. */
     110        uLUN = pThis->getFreeLUN();
    96111
    97112    LogFunc(("strName=%s, strDevice=%s, uInst=%u, uLUN=%u\n",
    98              pCfg->strName.c_str(), pCfg->strDev.c_str(), pCfg->uInst, pCfg->uLUN));
    99 
    100     vrc = pThis->Configure(pCfg, true /* Attach */);
    101     if (RT_SUCCESS(vrc))
    102         vrc = PDMR3DriverAttach(ptrVM.rawUVM(), pCfg->strDev.c_str(), pCfg->uInst, pCfg->uLUN, 0 /* fFlags */, NULL /* ppBase */);
    103 
    104     if (RT_SUCCESS(vrc))
    105     {
     113             pCfg->strName.c_str(), pCfg->strDev.c_str(), pCfg->uInst, uLUN));
     114
     115    vrc = pThis->configure(uLUN, true /* Attach */);
     116    if (RT_SUCCESS(vrc))
     117        vrc = PDMR3DeviceAttach(ptrVM.rawUVM(), pCfg->strDev.c_str(), pCfg->uInst, uLUN, 0 /* fFlags */,
     118                                NULL /* ppBase */);
     119    if (RT_SUCCESS(vrc))
     120    {
     121        pThis->muLUN      = uLUN;
    106122        pThis->mfAttached = true;
     123
     124        LogRel2(("%s: Driver attached (LUN #%u)\n", pCfg->strName.c_str(), pThis->muLUN));
    107125    }
    108126    else
     
    124142    AssertPtrReturn(pThis, VERR_INVALID_POINTER);
    125143
     144    if (!pThis->mfAttached) /* Not attached? Bail out. */
     145    {
     146        LogFunc(("%s: Not attached\n", pThis->mCfg.strName.c_str()));
     147        return VINF_SUCCESS;
     148    }
     149
    126150    Console::SafeVMPtrQuiet ptrVM(pThis->mpConsole);
    127151    Assert(ptrVM.isOk());
    128152
    129     if (!pThis->mfAttached) /* Not attached? Bail out. */
    130         return VINF_SUCCESS;
     153    Assert(pThis->muLUN != UINT8_MAX);
    131154
    132155    int vrc = VINF_SUCCESS;
     
    135158
    136159    LogFunc(("strName=%s, strDevice=%s, uInst=%u, uLUN=%u\n",
    137              pCfg->strName.c_str(), pCfg->strDev.c_str(), pCfg->uInst, pCfg->uLUN));
    138 
    139     vrc = PDMR3DriverDetach(ptrVM.rawUVM(), pCfg->strDev.c_str(), pCfg->uInst, pCfg->uLUN, "AUDIO",
     160             pCfg->strName.c_str(), pCfg->strDev.c_str(), pCfg->uInst, pThis->muLUN));
     161
     162    vrc = PDMR3DriverDetach(ptrVM.rawUVM(), pCfg->strDev.c_str(), pCfg->uInst, pThis->muLUN, "AUDIO",
    140163                            0 /* iOccurrence */, 0 /* fFlags */);
    141164    if (RT_SUCCESS(vrc))
    142         vrc = pThis->Configure(pCfg, false /* Detach */);
    143 
    144     if (RT_SUCCESS(vrc))
    145     {
    146         pCfg->uLUN = UINT8_MAX;
    147 
     165        vrc = pThis->configure(pThis->muLUN, false /* Detach */);
     166
     167    if (RT_SUCCESS(vrc))
     168    {
     169        pThis->muLUN      = UINT8_MAX;
    148170        pThis->mfAttached = false;
     171
     172        LogRel2(("%s: Driver detached\n", pCfg->strName.c_str()));
    149173    }
    150174    else
     
    158182 *
    159183 * @returns VBox status code.
    160  * @param   pCfg                Audio driver configuration to use.
     184 * @param   uLUN                LUN to attach driver to.
    161185 * @param   fAttach             Whether to attach or detach the driver configuration to CFGM.
    162186 *
    163187 * @thread EMT
    164188 */
    165 int AudioDriver::Configure(AudioDriverCfg *pCfg, bool fAttach)
    166 {
    167     if (pCfg->strDev.isEmpty()) /* No audio device configured. Bail out. */
    168         return VINF_SUCCESS;
    169 
     189int AudioDriver::configure(unsigned uLUN, bool fAttach)
     190{
    170191    int rc = VINF_SUCCESS;
    171192
    172193    Console::SafeVMPtrQuiet ptrVM(mpConsole);
    173194    Assert(ptrVM.isOk());
    174 
    175     /* Apply configuration. */
    176     mCfg = *pCfg;
    177195
    178196    PUVM pUVM = ptrVM.rawUVM();
     
    184202    AssertPtr(pDev0);
    185203
    186     PCFGMNODE pDevLun = CFGMR3GetChildF(pDev0, "LUN#%u/", mCfg.uLUN);
     204    PCFGMNODE pDevLun = CFGMR3GetChildF(pDev0, "LUN#%u/", uLUN);
    187205
    188206    if (fAttach)
    189207    {
     208        AssertMsg(uLUN != UINT8_MAX, ("%s: LUN is undefined when it must not\n", mCfg.strName.c_str()));
     209
    190210        if (!pDevLun)
    191211        {
    192             LogRel2(("%s: Configuring audio driver\n", mCfg.strName.c_str()));
     212            LogRel2(("%s: Configuring audio driver (to LUN #%RU8)\n", mCfg.strName.c_str(), uLUN));
    193213
    194214            PCFGMNODE pLunL0;
    195             CFGMR3InsertNodeF(pDev0, &pLunL0, "LUN#%RU8", mCfg.uLUN);
     215            CFGMR3InsertNodeF(pDev0, &pLunL0, "LUN#%RU8", uLUN);
    196216            CFGMR3InsertString(pLunL0, "Driver", "AUDIO");
    197217
     
    211231                configureDriver(pLunCfg);
    212232        }
     233        else
     234            rc = VERR_ALREADY_EXISTS;
    213235    }
    214236    else /* Detach */
     
    219241            CFGMR3RemoveNode(pDevLun);
    220242        }
    221     }
    222 
    223     AssertRC(rc);
     243        else
     244            rc = VERR_NOT_FOUND;
     245    }
     246
     247#ifdef DEBUG_andy
     248    CFGMR3Dump(pDev0);
     249#endif
     250
     251    if (RT_FAILURE(rc))
     252        LogRel(("%s: %s audio driver failed with rc=%Rrc\n",
     253                mCfg.strName.c_str(), fAttach ? "Configuring" : "Unconfiguring", rc));
     254
    224255    return rc;
    225256}
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r70535 r70563  
    54055405                            mConsoleVRDPServer->Stop();
    54065406
    5407                             int vrc;
    5408 #ifdef VBOX_WITH_AUDIO_VRDE
    5409                             if (!mAudioVRDE->IsAttached())
    5410                             {
    5411                                 vrc = VMR3ReqCallWaitU(ptrVM.rawUVM(), VMCPUID_ANY /*idDstCpu*/,
    5412                                                        (PFNRT)AudioVRDE::Attach, 2,
    5413                                                        mAudioVRDE, mAudioVRDE->GetConfig());
    5414                                 AssertRC(vrc);
    5415                             }
    5416 #endif
    5417                             vrc = mConsoleVRDPServer->Launch();
     5407                            int vrc = mConsoleVRDPServer->Launch();
    54185408                            if (vrc != VINF_SUCCESS)
    54195409                            {
     
    54225412                            }
    54235413                            else
     5414                            {
     5415#ifdef VBOX_WITH_AUDIO_VRDE
     5416                                alock.acquire();
     5417
     5418                                PVMREQ pReq;
     5419                                int vrc2 = VMR3ReqCallU(mpUVM, VMCPUID_ANY, &pReq, 0 /* no wait! */, VMREQFLAGS_VBOX_STATUS,
     5420                                                        (PFNRT)AudioVRDE::Attach, 1,
     5421                                                        mAudioVRDE);
     5422
     5423                                /* Release the lock before a VMR3* call (EMT might wait for it, @bugref{7648})! */
     5424                                alock.release();
     5425
     5426                                if (vrc2 == VERR_TIMEOUT)
     5427                                    vrc2 = VMR3ReqWait(pReq, RT_INDEFINITE_WAIT);
     5428                                AssertRC(vrc2);
     5429                                VMR3ReqFree(pReq);
     5430#endif
    54245431                                mConsoleVRDPServer->EnableConnections();
     5432                            }
    54255433                        }
    54265434                        else
     
    54285436                            mConsoleVRDPServer->Stop();
    54295437#ifdef VBOX_WITH_AUDIO_VRDE
    5430                             if (mAudioVRDE->IsAttached())
    5431                             {
    5432                                 int vrc2 = VMR3ReqCallWaitU(ptrVM.rawUVM(), VMCPUID_ANY /*idDstCpu*/,
    5433                                                             (PFNRT)AudioVRDE::Detach, 1,
    5434                                                             mAudioVRDE);
    5435                                 AssertRC(vrc2);
    5436                             }
     5438                            alock.acquire();
     5439
     5440                            PVMREQ pReq;
     5441                            int vrc2 = VMR3ReqCallU(mpUVM, VMCPUID_ANY, &pReq, 0 /* no wait! */, VMREQFLAGS_VBOX_STATUS,
     5442                                                    (PFNRT)AudioVRDE::Detach, 1,
     5443                                                    mAudioVRDE);
     5444
     5445                            /* Release the lock before a VMR3* call (EMT might wait for it, @bugref{7648})! */
     5446                            alock.release();
     5447
     5448                            if (vrc2 == VERR_TIMEOUT)
     5449                                vrc2 = VMR3ReqWait(pReq, RT_INDEFINITE_WAIT);
     5450                            AssertRC(vrc2);
     5451                            VMR3ReqFree(pReq);
    54375452#endif
    54385453                        }
     
    55295544            AssertPtr(pDisplay);
    55305545
    5531             /* Release lock because the call scheduled on EMT may also try to take it. */
    5532             alock.release();
    5533 
    5534             const PVIDEORECCFG pCfg = pDisplay->i_videoRecGetConfig();
     5546            pDisplay->i_videoRecInvalidate();
     5547
     5548            int vrc;
     5549
     5550            if (!mDisplay->i_videoRecStarted())
     5551            {
    55355552# ifdef VBOX_WITH_AUDIO_VIDEOREC
    5536             const unsigned     uLUN = pCfg->Audio.uLUN; /* Get the currently configured LUN. */
    5537 # else
    5538             const unsigned     uLUN = 0;
     5553                /* Attach the video recording audio driver if required. */
     5554                if (mDisplay->i_videoRecGetEnabled() & VIDEORECFEATURE_AUDIO)
     5555                {
     5556                    PVMREQ pReq;
     5557                    int vrc2 = VMR3ReqCallU(mpUVM, VMCPUID_ANY, &pReq, 0 /* no wait! */, VMREQFLAGS_VBOX_STATUS,
     5558                                            (PFNRT)AudioVideoRec::Attach, 1,
     5559                                            mAudioVideoRec);
     5560
     5561                    /* Release the lock before a VMR3* call (EMT might wait for it, @bugref{7648})! */
     5562                    alock.release();
     5563
     5564                    if (vrc2 == VERR_TIMEOUT)
     5565                        vrc2 = VMR3ReqWait(pReq, RT_INDEFINITE_WAIT);
     5566                    AssertRC(vrc2);
     5567                    VMR3ReqFree(pReq);
     5568
     5569                    alock.acquire();
     5570                }
    55395571# endif
    5540             int vrc = VMR3ReqCallWaitU(ptrVM.rawUVM(), VMCPUID_ANY /*idDstCpu*/,
    5541                                        (PFNRT)Display::i_videoRecConfigure, 4,
    5542                                        pDisplay, pCfg, true /* fAttachDetach */, &uLUN);
    5543             if (RT_SUCCESS(vrc))
    5544             {
    5545                 /* Make sure to acquire the lock again after we're done running in EMT. */
    5546                 alock.acquire();
    5547 
    5548                 if (!mDisplay->i_videoRecStarted())
    5549                 {
    5550                     vrc = mDisplay->i_videoRecStart();
    5551                     if (RT_FAILURE(vrc))
    5552                         rc = setError(E_FAIL, tr("Unable to start video capturing (%Rrc)"), vrc);
    5553                 }
    5554                 else
    5555                     mDisplay->i_videoRecStop();
     5572                vrc = mDisplay->i_videoRecStart();
     5573                if (RT_FAILURE(vrc))
     5574                    rc = setError(E_FAIL, tr("Unable to start video capturing (%Rrc)"), vrc);
    55565575            }
    55575576            else
    5558                 rc = setError(E_FAIL, tr("Unable to set screens for capturing (%Rrc)"), vrc);
     5577            {
     5578                mDisplay->i_videoRecStop();
     5579# ifdef VBOX_WITH_AUDIO_VIDEOREC
     5580                PVMREQ pReq;
     5581                int vrc2 = VMR3ReqCallU(mpUVM, VMCPUID_ANY, &pReq, 0 /* no wait! */, VMREQFLAGS_VBOX_STATUS,
     5582                                        (PFNRT)AudioVideoRec::Detach, 1,
     5583                                        mAudioVideoRec);
     5584
     5585                /* Release the lock before a VMR3* call (EMT might wait for it, @bugref{7648})! */
     5586                alock.release();
     5587
     5588                if (vrc2 == VERR_TIMEOUT)
     5589                    vrc2 = VMR3ReqWait(pReq, RT_INDEFINITE_WAIT);
     5590                AssertRC(vrc2);
     5591                VMR3ReqFree(pReq);
     5592
     5593                alock.acquire();
     5594# endif
     5595            }
    55595596        }
    55605597
     
    98469883                         static_cast<Console *>(pConsole),
    98479884                         &pVM, NULL);
    9848 
    98499885        alock.acquire();
    98509886
    9851         /* Enable client connections to the server. */
     9887#ifdef VBOX_WITH_AUDIO_VRDE
     9888        /* Attach the VRDE audio driver. */
     9889        IVRDEServer *pVRDEServer = pConsole->i_getVRDEServer();
     9890        if (pVRDEServer)
     9891        {
     9892            BOOL fVRDEEnabled = FALSE;
     9893            rc = pVRDEServer->COMGETTER(Enabled)(&fVRDEEnabled);
     9894            AssertComRCReturnVoid(rc);
     9895
     9896            if (fVRDEEnabled)
     9897            {
     9898                PVMREQ pReq;
     9899                int vrc2 = VMR3ReqCallU(pConsole->mpUVM, VMCPUID_ANY, &pReq, 0 /* no wait! */, VMREQFLAGS_VBOX_STATUS,
     9900                                        (PFNRT)AudioVRDE::Attach, 1,
     9901                                        pConsole->mAudioVRDE);
     9902
     9903                /* Release the lock before a VMR3* call (EMT might wait for it, @bugref{7648})! */
     9904                alock.release();
     9905
     9906                if (vrc2 == VERR_TIMEOUT)
     9907                    vrc2 = VMR3ReqWait(pReq, RT_INDEFINITE_WAIT);
     9908                AssertRC(vrc2);
     9909                VMR3ReqFree(pReq);
     9910
     9911                alock.acquire();
     9912            }
     9913        }
     9914#endif
     9915
     9916        /* Enable client connections to the VRDP server. */
    98529917        pConsole->i_consoleVRDPServer()->EnableConnections();
    98539918
     9919#ifdef VBOX_WITH_AUDIO_VIDEOREC
     9920        Display *pDisplay = pConsole->i_getDisplay();
     9921        AssertPtr(pDisplay);
     9922        if (pDisplay)
     9923        {
     9924            pDisplay->i_videoRecInvalidate();
     9925
     9926            /* Attach the video recording audio driver if required. */
     9927            if (pDisplay->i_videoRecGetEnabled() & VIDEORECFEATURE_AUDIO)
     9928            {
     9929                PVMREQ pReq;
     9930                int vrc2 = VMR3ReqCallU(pConsole->mpUVM, VMCPUID_ANY, &pReq, 0 /* no wait! */, VMREQFLAGS_VBOX_STATUS,
     9931                                        (PFNRT)AudioVideoRec::Attach, 1,
     9932                                        pConsole->mAudioVideoRec);
     9933
     9934                /* Release the lock before a VMR3* call (EMT might wait for it, @bugref{7648})! */
     9935                alock.release();
     9936
     9937                if (vrc2 == VERR_TIMEOUT)
     9938                    vrc2 = VMR3ReqWait(pReq, RT_INDEFINITE_WAIT);
     9939                AssertRC(vrc2);
     9940                VMR3ReqFree(pReq);
     9941
     9942                alock.acquire();
     9943            }
     9944        }
     9945#endif
    98549946        if (RT_SUCCESS(vrc))
    98559947        {
  • trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp

    r70544 r70563  
    124124#ifdef VBOX_WITH_AUDIO_VRDE
    125125# include "DrvAudioVRDE.h"
     126#endif
     127#ifdef VBOX_WITH_AUDIO_VIDEOREC
     128# include "DrvAudioVideoRec.h"
    126129#endif
    127130#include "NetworkServiceRunner.h"
     
    29672970
    29682971#ifdef VBOX_WITH_AUDIO_VRDE
    2969             BOOL fVRDEEnabled = FALSE;
    2970 
    2971             if (mVRDEServer)
    2972             {
    2973                 hrc = mVRDEServer->COMGETTER(Enabled)(&fVRDEEnabled);
    2974                 ComAssertComRC(hrc);
    2975             }
    2976 
    2977             AudioDriverCfg Cfg(strAudioDevice, 0 /* Instance */, uAudioLUN, "AudioVRDE");
    2978             rc = mAudioVRDE->Configure(&Cfg, RT_BOOL(fVRDEEnabled) /* Attach */);
    2979             if (   RT_SUCCESS(rc)
    2980                 && fVRDEEnabled) /* Successfully configured, use next LUN for drivers below. */
    2981             {
    2982                 uAudioLUN++;
    2983             }
     2972            AudioDriverCfg DrvCfgVRDE(strAudioDevice, 0 /* Instance */, "AudioVRDE");
     2973            rc = mAudioVRDE->Initialize(&DrvCfgVRDE);
     2974            AssertRC(rc);
    29842975#endif /* VBOX_WITH_AUDIO_VRDE */
    29852976
    29862977#ifdef VBOX_WITH_AUDIO_VIDEOREC
    2987             Display *pDisplay = i_getDisplay();
    2988             if (pDisplay)
    2989             {
    2990                 /* Note: Don't do any driver attaching (fAttachDetach) here, as this will
    2991                  *       be done automatically as part of the VM startup process. */
    2992                 rc = pDisplay->i_videoRecConfigure(pDisplay, pDisplay->i_videoRecGetConfig(), false /* fAttachDetach */,
    2993                                                    &uAudioLUN);
    2994                 if (RT_SUCCESS(rc)) /* Successfully configured, use next LUN for drivers below. */
    2995                     uAudioLUN++;
    2996             }
     2978            AudioDriverCfg DrvCfgVideoRec(strAudioDevice, 0 /* Instance */, "AudioVideoRec");
     2979            rc = mAudioVideoRec->Initialize(&DrvCfgVideoRec);
     2980            AssertRC(rc);
    29972981#endif /* VBOX_WITH_AUDIO_VIDEOREC */
    29982982
  • trunk/src/VBox/Main/src-client/DisplayImpl.cpp

    r70075 r70563  
    24172417}
    24182418
    2419 #ifdef VBOX_WITH_AUDIO_VIDEOREC
    24202419/**
    2421  * Configures the video recording audio driver in CFGM.
    2422  *
    2423  * @returns VBox status code.
    2424  * @param   strDevice           The PDM device name.
    2425  * @param   uInstance           The PDM device instance.
    2426  * @param   uLUN                The PDM LUN number of the driver.
    2427  * @param   fAttach             Whether to attach or detach the driver configuration to CFGM.
    2428  *
    2429  * @thread EMT
     2420 * Invalidates the video recording configuration.
    24302421 */
    2431 int Display::i_videoRecConfigureAudioDriver(const Utf8Str& strDevice,
    2432                                             unsigned       uInstance,
    2433                                             unsigned       uLUN,
    2434                                             bool           fAttach)
    2435 {
    2436     if (strDevice.isEmpty()) /* No audio device configured. Bail out. */
    2437         return VINF_SUCCESS;
    2438 
     2422void Display::i_videoRecInvalidate(void)
     2423{
    24392424    AssertPtr(mParent);
    2440 
    24412425    ComPtr<IMachine> pMachine = mParent->i_machine();
    24422426    Assert(pMachine.isNotNull());
    24432427
    2444     Console::SafeVMPtr ptrVM(mParent);
    2445     Assert(ptrVM.isOk());
    2446 
    2447     PUVM pUVM = ptrVM.rawUVM();
    2448     AssertPtr(pUVM);
    2449 
    2450     PCFGMNODE pRoot   = CFGMR3GetRootU(pUVM);
    2451     AssertPtr(pRoot);
    2452     PCFGMNODE pDev0   = CFGMR3GetChildF(pRoot, "Devices/%s/%u/", strDevice.c_str(), uInstance);
    2453     AssertPtr(pDev0);
    2454 
    2455     PCFGMNODE pDevLun = CFGMR3GetChildF(pDev0, "LUN#%u/", uLUN);
    2456 
    2457     if (fAttach)
    2458     {
    2459         if (!pDevLun)
    2460         {
    2461             LogRel2(("VideoRec: Attaching audio driver\n"));
    2462 
    2463             PCFGMNODE pLunL0;
    2464             CFGMR3InsertNodeF(pDev0, &pLunL0, "LUN#%RU8", uLUN);
    2465             CFGMR3InsertString(pLunL0, "Driver", "AUDIO");
    2466 
    2467             PCFGMNODE pCfg;
    2468             CFGMR3InsertNode(pLunL0,   "Config", &pCfg);
    2469                 CFGMR3InsertString (pCfg, "DriverName",    "AudioVideoRec");
    2470                 CFGMR3InsertInteger(pCfg, "InputEnabled",  0);
    2471                 CFGMR3InsertInteger(pCfg, "OutputEnabled", 1);
    2472 
    2473             PCFGMNODE pLunL1;
    2474             CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1);
    2475                 CFGMR3InsertString(pLunL1, "Driver", "AudioVideoRec");
    2476 
    2477                 CFGMR3InsertNode(pLunL1, "Config", &pCfg);
    2478                     CFGMR3InsertInteger(pCfg, "Object",        (uintptr_t)mParent->i_getAudioVideoRec());
    2479                     CFGMR3InsertInteger(pCfg, "ObjectConsole", (uintptr_t)mParent /* Console */);
    2480         }
    2481     }
    2482     else /* Detach */
    2483     {
    2484         if (pDevLun)
    2485         {
    2486             LogRel2(("VideoRec: Detaching audio driver\n"));
    2487             CFGMR3RemoveNode(pDevLun);
    2488         }
    2489     }
    2490 
    2491     return VINF_SUCCESS;
    2492 }
    2493 #endif
    2494 
    2495 /**
    2496  * Configures video capturing (via CFGM) and attaches / detaches the associated driver.
    2497  * Currently this only is the audio driver (if available).
    2498  *
    2499  * @returns IPRT status code.
    2500  * @param   pThis               Display instance to configure video capturing for.
    2501  * @param   pCfg                Where to store the configuration into.
    2502  * @param   fAttachDetach       Whether to attach/detach associated drivers or not.
    2503  * @param   puLUN               On input, this defines the LUN to which the audio driver shall be assigned to.
    2504  *                              On output, this returns the LUN the audio driver was assigned to.
    2505  */
    2506 /* static */
    2507 DECLCALLBACK(int) Display::i_videoRecConfigure(Display *pThis, PVIDEORECCFG pCfg, bool fAttachDetach, unsigned *puLUN)
    2508 {
    2509     AssertPtrReturn(pThis, VERR_INVALID_POINTER);
    2510     AssertPtrReturn(pCfg,  VERR_INVALID_POINTER);
    2511     AssertPtrReturn(puLUN, VERR_INVALID_POINTER);
    2512 
    2513     AssertPtr(pThis->mParent);
    2514     ComPtr<IMachine> pMachine = pThis->mParent->i_machine();
    2515     Assert(pMachine.isNotNull());
    2516 
    2517     pCfg->enmDst = VIDEORECDEST_FILE; /** @todo Make this configurable once we have more variations. */
     2428    mVideoRecCfg.enmDst = VIDEORECDEST_FILE; /** @todo Make this configurable once we have more variations. */
    25182429
    25192430    /*
     
    25212432     */
    25222433    BOOL fEnabled;
    2523     HRESULT rc = pMachine->COMGETTER(VideoCaptureEnabled)(&fEnabled);
    2524     AssertComRCReturn(rc, VERR_COM_UNEXPECTED);
    2525     pCfg->fEnabled = RT_BOOL(fEnabled);
     2434    HRESULT hrc = pMachine->COMGETTER(VideoCaptureEnabled)(&fEnabled);
     2435    AssertComRCReturnVoid(hrc);
     2436    mVideoRecCfg.fEnabled = RT_BOOL(fEnabled);
    25262437
    25272438    com::SafeArray<BOOL> aScreens;
    2528     rc = pMachine->COMGETTER(VideoCaptureScreens)(ComSafeArrayAsOutParam(aScreens));
    2529     AssertComRCReturn(rc, VERR_COM_UNEXPECTED);
    2530 
    2531     pCfg->aScreens.resize(aScreens.size());
     2439    hrc = pMachine->COMGETTER(VideoCaptureScreens)(ComSafeArrayAsOutParam(aScreens));
     2440    AssertComRCReturnVoid(hrc);
     2441
     2442    mVideoRecCfg.aScreens.resize(aScreens.size());
    25322443    for (size_t i = 0; i < aScreens.size(); ++i)
    2533         pCfg->aScreens[i] = aScreens[i];
    2534 
    2535     rc = pMachine->COMGETTER(VideoCaptureWidth)((ULONG *)&pCfg->Video.uWidth);
    2536     AssertComRCReturn(rc, VERR_COM_UNEXPECTED);
    2537     rc = pMachine->COMGETTER(VideoCaptureHeight)((ULONG *)&pCfg->Video.uHeight);
    2538     AssertComRCReturn(rc, VERR_COM_UNEXPECTED);
    2539     rc = pMachine->COMGETTER(VideoCaptureRate)((ULONG *)&pCfg->Video.uRate);
    2540     AssertComRCReturn(rc, VERR_COM_UNEXPECTED);
    2541     rc = pMachine->COMGETTER(VideoCaptureFPS)((ULONG *)&pCfg->Video.uFPS);
    2542     AssertComRCReturn(rc, VERR_COM_UNEXPECTED);
    2543     rc = pMachine->COMGETTER(VideoCaptureFile)(pCfg->File.strName.asOutParam());
    2544     AssertComRCReturn(rc, VERR_COM_UNEXPECTED);
    2545     rc = pMachine->COMGETTER(VideoCaptureMaxFileSize)((ULONG *)&pCfg->File.uMaxSizeMB);
    2546     AssertComRCReturn(rc, VERR_COM_UNEXPECTED);
    2547     rc = pMachine->COMGETTER(VideoCaptureMaxTime)((ULONG *)&pCfg->uMaxTimeS);
    2548     AssertComRCReturn(rc, VERR_COM_UNEXPECTED);
     2444        mVideoRecCfg.aScreens[i] = aScreens[i];
     2445
     2446    hrc = pMachine->COMGETTER(VideoCaptureWidth)((ULONG *)&mVideoRecCfg.Video.uWidth);
     2447    AssertComRCReturnVoid(hrc);
     2448    hrc = pMachine->COMGETTER(VideoCaptureHeight)((ULONG *)&mVideoRecCfg.Video.uHeight);
     2449    AssertComRCReturnVoid(hrc);
     2450    hrc = pMachine->COMGETTER(VideoCaptureRate)((ULONG *)&mVideoRecCfg.Video.uRate);
     2451    AssertComRCReturnVoid(hrc);
     2452    hrc = pMachine->COMGETTER(VideoCaptureFPS)((ULONG *)&mVideoRecCfg.Video.uFPS);
     2453    AssertComRCReturnVoid(hrc);
     2454    hrc = pMachine->COMGETTER(VideoCaptureFile)(mVideoRecCfg.File.strName.asOutParam());
     2455    AssertComRCReturnVoid(hrc);
     2456    hrc = pMachine->COMGETTER(VideoCaptureMaxFileSize)((ULONG *)&mVideoRecCfg.File.uMaxSizeMB);
     2457    AssertComRCReturnVoid(hrc);
     2458    hrc = pMachine->COMGETTER(VideoCaptureMaxTime)((ULONG *)&mVideoRecCfg.uMaxTimeS);
     2459    AssertComRCReturnVoid(hrc);
    25492460    BSTR bstrOptions;
    2550     rc = pMachine->COMGETTER(VideoCaptureOptions)(&bstrOptions);
    2551     AssertComRCReturn(rc, VERR_COM_UNEXPECTED);
     2461    hrc = pMachine->COMGETTER(VideoCaptureOptions)(&bstrOptions);
     2462    AssertComRCReturnVoid(hrc);
    25522463
    25532464    /*
    25542465     * Set sensible defaults.
    25552466     */
    2556     pCfg->Video.fEnabled = pCfg->fEnabled;
    2557 
    2558     if (!pCfg->Video.uFPS) /* Prevent division by zero. */
    2559         pCfg->Video.uFPS = 15;
     2467    mVideoRecCfg.Video.fEnabled = mVideoRecCfg.fEnabled;
     2468
     2469    if (!mVideoRecCfg.Video.uFPS) /* Prevent division by zero. */
     2470        mVideoRecCfg.Video.uFPS = 15;
    25602471
    25612472#ifdef VBOX_WITH_LIBVPX
    2562     pCfg->Video.Codec.VPX.uEncoderDeadline = 1000000 / pCfg->Video.uFPS;
     2473    mVideoRecCfg.Video.Codec.VPX.uEncoderDeadline = 1000000 / mVideoRecCfg.Video.uFPS;
    25632474#endif
    25642475
     
    25662477     * There be dragons! */
    25672478#ifdef VBOX_WITH_AUDIO_VIDEOREC
    2568     pCfg->Audio.fEnabled  = false;
     2479    mVideoRecCfg.Audio.fEnabled  = false;
    25692480    /* By default we use 48kHz, 16-bit, stereo for the audio track. */
    2570     pCfg->Audio.uHz       = 48000;
    2571     pCfg->Audio.cBits     = 16;
    2572     pCfg->Audio.cChannels = 2;
     2481    mVideoRecCfg.Audio.uHz       = 48000;
     2482    mVideoRecCfg.Audio.cBits     = 16;
     2483    mVideoRecCfg.Audio.cChannels = 2;
    25732484#endif
    25742485
     
    25852496#ifdef VBOX_WITH_LIBVPX
    25862497            if (value.compare("realtime", Utf8Str::CaseInsensitive) == 0)
    2587                 pCfg->Video.Codec.VPX.uEncoderDeadline = VPX_DL_REALTIME;
     2498                mVideoRecCfg.Video.Codec.VPX.uEncoderDeadline = VPX_DL_REALTIME;
    25882499            else if (value.compare("good", Utf8Str::CaseInsensitive) == 0)
    2589                 pCfg->Video.Codec.VPX.uEncoderDeadline = 1000000 / pCfg->Video.uFPS;
     2500                mVideoRecCfg.Video.Codec.VPX.uEncoderDeadline = 1000000 / mVideoRecCfg.Video.uFPS;
    25902501            else if (value.compare("best", Utf8Str::CaseInsensitive) == 0)
    2591                 pCfg->Video.Codec.VPX.uEncoderDeadline = VPX_DL_BEST_QUALITY;
     2502                mVideoRecCfg.Video.Codec.VPX.uEncoderDeadline = VPX_DL_BEST_QUALITY;
    25922503            else
    25932504            {
    25942505                LogRel(("VideoRec: Setting quality deadline to '%s'\n", value.c_str()));
    2595                 pCfg->Video.Codec.VPX.uEncoderDeadline = value.toUInt32();
     2506                mVideoRecCfg.Video.Codec.VPX.uEncoderDeadline = value.toUInt32();
    25962507#endif
    25972508            }
     
    26012512            if (value.compare("false", Utf8Str::CaseInsensitive) == 0)
    26022513            {
    2603                 pCfg->Video.fEnabled = false;
     2514                mVideoRecCfg.Video.fEnabled = false;
    26042515#ifdef VBOX_WITH_AUDIO_VIDEOREC
    26052516                LogRel(("VideoRec: Only audio will be recorded\n"));
     
    26122523            if (value.compare("true", Utf8Str::CaseInsensitive) == 0)
    26132524            {
    2614                 pCfg->Audio.fEnabled = true;
     2525                mVideoRecCfg.Audio.fEnabled = true;
    26152526
    26162527            }
     
    26242535            if (value.compare("low", Utf8Str::CaseInsensitive) == 0)
    26252536            {
    2626                 pCfg->Audio.uHz       = 8000;
    2627                 pCfg->Audio.cBits     = 16;
    2628                 pCfg->Audio.cChannels = 1;
     2537                mVideoRecCfg.Audio.uHz       = 8000;
     2538                mVideoRecCfg.Audio.cBits     = 16;
     2539                mVideoRecCfg.Audio.cChannels = 1;
    26292540            }
    26302541            else if (value.startsWith("med" /* "med[ium]" */, Utf8Str::CaseInsensitive) == 0)
    26312542            {
    2632                 pCfg->Audio.uHz       = 22050;
    2633                 pCfg->Audio.cBits     = 16;
    2634                 pCfg->Audio.cChannels = 2;
     2543                mVideoRecCfg.Audio.uHz       = 22050;
     2544                mVideoRecCfg.Audio.cBits     = 16;
     2545                mVideoRecCfg.Audio.cChannels = 2;
    26352546            }
    26362547            else if (value.compare("high", Utf8Str::CaseInsensitive) == 0)
     
    26452556    } /* while */
    26462557
    2647     unsigned uLUN = *puLUN;
    2648 
    2649 #ifdef VBOX_WITH_AUDIO_VIDEOREC
    2650     ComPtr<IAudioAdapter> audioAdapter;
    2651     rc = pMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
    2652     AssertComRC(rc);
    2653 
    2654     unsigned uInstance = 0;
    2655 
    2656     Utf8Str strAudioDev = pThis->mParent->i_getAudioAdapterDeviceName(audioAdapter);
    2657     if (!strAudioDev.isEmpty())
    2658     {
    2659         Console::SafeVMPtr ptrVM(pThis->mParent);
    2660         Assert(ptrVM.isOk());
    2661 
    2662         /*
    2663          * Configure + attach audio driver.
    2664          */
    2665         int vrc2 = VINF_SUCCESS;
    2666 
    2667         LogFunc(("Audio fAttachDetach=%RTbool, fEnabled=%RTbool\n", fAttachDetach, pCfg->Audio.fEnabled));
    2668 
    2669         if (pCfg->Audio.fEnabled) /* Enable */
    2670         {
    2671             vrc2 = pThis->i_videoRecConfigureAudioDriver(strAudioDev, uInstance, uLUN, true /* fAttach */);
    2672             if (   RT_SUCCESS(vrc2)
    2673                 && fAttachDetach)
    2674             {
    2675                 vrc2 = PDMR3DriverAttach(ptrVM.rawUVM(), strAudioDev.c_str(), uInstance, uLUN, 0 /* fFlags */, NULL /* ppBase */);
    2676             }
    2677 
    2678             if (RT_FAILURE(vrc2))
    2679                 LogRel(("VideoRec: Failed to attach audio driver, rc=%Rrc\n", vrc2));
    2680         }
    2681         else /* Disable */
    2682         {
    2683             if (fAttachDetach)
    2684                 vrc2 = PDMR3DriverDetach(ptrVM.rawUVM(), strAudioDev.c_str(), uInstance, uLUN, "AUDIO",
    2685                                          0 /* iOccurrence */, 0 /* fFlags */);
    2686 
    2687             if (RT_SUCCESS(vrc2))
    2688             {
    2689                 vrc2 = pThis->i_videoRecConfigureAudioDriver(strAudioDev, uInstance, uLUN, false /* fAttach */);
    2690             }
    2691 
    2692             if (RT_FAILURE(vrc2))
    2693                 LogRel(("VideoRec: Failed to detach audio driver, rc=%Rrc\n", vrc2));
    2694         }
    2695 
    2696         AssertRC(vrc2);
    2697     }
    2698     else
    2699         LogRel2(("VideoRec: No audio hardware configured, skipping to record audio\n"));
    2700 #else
    2701     RT_NOREF(fAttachDetach);
    2702 #endif
    2703 
    27042558    /*
    27052559     * Invalidate screens.
    27062560     */
    2707     for (unsigned i = 0; i < pCfg->aScreens.size(); i++)
    2708     {
    2709         bool fChanged = pThis->maVideoRecEnabled[i] != RT_BOOL(pCfg->aScreens[i]);
    2710 
    2711         pThis->maVideoRecEnabled[i] = RT_BOOL(pCfg->aScreens[i]);
    2712 
    2713         if (fChanged && i < pThis->mcMonitors)
    2714             pThis->i_videoRecScreenChanged(i);
    2715 
    2716     }
    2717 
    2718     if (puLUN)
    2719         *puLUN = uLUN;
    2720 
    2721     return S_OK;
     2561    for (unsigned i = 0; i < mVideoRecCfg.aScreens.size(); i++)
     2562    {
     2563        bool fChanged = maVideoRecEnabled[i] != RT_BOOL(mVideoRecCfg.aScreens[i]);
     2564
     2565        maVideoRecEnabled[i] = RT_BOOL(mVideoRecCfg.aScreens[i]);
     2566
     2567        if (fChanged && i < mcMonitors)
     2568            i_videoRecScreenChanged(i);
     2569
     2570    }
    27222571}
    27232572
  • trunk/src/VBox/Main/src-client/DrvAudioVideoRec.cpp

    r70038 r70563  
    10161016
    10171017AudioVideoRec::AudioVideoRec(Console *pConsole)
    1018     : mpDrv(NULL)
    1019     , mpConsole(pConsole)
     1018    : AudioDriver(pConsole)
     1019    , mpDrv(NULL)
    10201020{
    10211021}
     
    10291029        mpDrv = NULL;
    10301030    }
     1031}
     1032
     1033
     1034void AudioVideoRec::configureDriver(PCFGMNODE pLunCfg)
     1035{
     1036    CFGMR3InsertInteger(pLunCfg, "Object",        (uintptr_t)mpConsole->i_getAudioVideoRec());
     1037    CFGMR3InsertInteger(pLunCfg, "ObjectConsole", (uintptr_t)mpConsole);
    10311038}
    10321039
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