VirtualBox

Changeset 74765 in vbox


Ignore:
Timestamp:
Oct 11, 2018 11:42:31 AM (6 years ago)
Author:
vboxsync
Message:

VideoRec/Main: Condensed code for enabling / disabling video (audio) recording at VM startup and onVideoCaptureChange handler.

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

Legend:

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

    r73258 r74765  
    200200#ifdef VBOX_WITH_USB_CARDREADER
    201201    UsbCardReader *i_getUsbCardReader() { return mUsbCardReader; }
     202#endif
     203
     204#ifdef VBOX_WITH_VIDEOREC
     205    int i_videoCaptureEnable(BOOL fEnable, util::AutoWriteLock *pAutoLock);
    202206#endif
    203207
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r73005 r74765  
    56025602}
    56035603
    5604 HRESULT Console::i_onVideoCaptureChange()
    5605 {
    5606     AutoCaller autoCaller(this);
    5607     AssertComRCReturnRC(autoCaller.rc());
    5608 
    5609     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    5610 
    5611     HRESULT rc = S_OK;
    5612 
    56135604#ifdef VBOX_WITH_VIDEOREC
    5614     /* Don't trigger video capture changes if the VM isn't running. */
    5615     SafeVMPtrQuiet ptrVM(this);
    5616     if (ptrVM.isOk())
    5617     {
    5618         if (mDisplay)
    5619         {
    5620             Display *pDisplay = mDisplay;
    5621             AssertPtr(pDisplay);
     5605/**
     5606 * Enables or disables video (audio) capturing of a VM.
     5607 *
     5608 * @returns IPRT status code. Will return VERR_NO_CHANGE if the capturing state has not been changed.
     5609 * @param   fEnable             Whether to enable or disable the capturing.
     5610 * @param   pAutoLock           Pointer to auto write lock to use for attaching/detaching required driver(s) at runtime.
     5611 */
     5612int Console::i_videoCaptureEnable(BOOL fEnable, util::AutoWriteLock *pAutoLock)
     5613{
     5614    AssertPtrReturn(pAutoLock, VERR_INVALID_POINTER);
     5615
     5616    int vrc = VINF_SUCCESS;
     5617
     5618    Display *pDisplay = i_getDisplay();
     5619    if (pDisplay)
     5620    {
     5621        if (RT_BOOL(fEnable) != pDisplay->i_videoRecStarted())
     5622        {
     5623            LogRel(("VideoRec: %s\n", fEnable ? "Enabling" : "Disabling"));
    56225624
    56235625            pDisplay->i_videoRecInvalidate();
    56245626
    5625             BOOL fEnabled;
    5626             rc = mMachine->COMGETTER(VideoCaptureEnabled)(&fEnabled);
    5627             AssertComRCReturnRC(rc);
    5628 
    5629             int vrc;
    5630 
    5631             if (fEnabled)
     5627            if (fEnable)
    56325628            {
    56335629# ifdef VBOX_WITH_AUDIO_VIDEOREC
    56345630                /* Attach the video recording audio driver if required. */
    5635                 if (mDisplay->i_videoRecGetFeatures() & VIDEORECFEATURE_AUDIO)
    5636                     mAudioVideoRec->doAttachDriverViaEmt(mpUVM, &alock);
     5631                if (   pDisplay->i_videoRecGetFeatures() & VIDEORECFEATURE_AUDIO
     5632                    && mAudioVideoRec)
     5633                    vrc = mAudioVideoRec->doAttachDriverViaEmt(mpUVM, pAutoLock);
    56375634# endif
    5638                 vrc = mDisplay->i_videoRecStart();
    5639                 if (RT_FAILURE(vrc))
    5640                     rc = setErrorBoth(E_FAIL, vrc, tr("Unable to start video capturing (%Rrc)"), vrc);
     5635                if (   RT_SUCCESS(vrc)
     5636                    && pDisplay->i_videoRecGetFeatures()) /* Any video recording (audio and/or video) feature enabled? */
     5637                {
     5638                    vrc = pDisplay->i_videoRecStart();
     5639                }
    56415640            }
    56425641            else
     
    56445643                mDisplay->i_videoRecStop();
    56455644# ifdef VBOX_WITH_AUDIO_VIDEOREC
    5646                 mAudioVideoRec->doDetachDriverViaEmt(mpUVM, &alock);
     5645                mAudioVideoRec->doDetachDriverViaEmt(mpUVM, pAutoLock);
    56475646# endif
    56485647            }
     5648
     5649            if (RT_FAILURE(vrc))
     5650                LogRel(("VideoRec: %s failed with %Rrc\n", fEnable ? "Enabling" : "Disabling", vrc));
     5651        }
     5652        else /* Should not happen. */
     5653            vrc = VERR_NO_CHANGE;
     5654    }
     5655
     5656    return vrc;
     5657}
     5658#endif /* VBOX_WITH_VIDEOREC */
     5659
     5660HRESULT Console::i_onVideoCaptureChange()
     5661{
     5662    AutoCaller autoCaller(this);
     5663    AssertComRCReturnRC(autoCaller.rc());
     5664
     5665    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     5666
     5667    HRESULT rc = S_OK;
     5668#ifdef VBOX_WITH_VIDEOREC
     5669    /* Don't trigger video capture changes if the VM isn't running. */
     5670    SafeVMPtrQuiet ptrVM(this);
     5671    if (ptrVM.isOk())
     5672    {
     5673        BOOL fEnabled;
     5674        rc = mMachine->COMGETTER(VideoCaptureEnabled)(&fEnabled);
     5675        AssertComRCReturnRC(rc);
     5676
     5677        int vrc = i_videoCaptureEnable(fEnabled, &alock);
     5678        if (RT_SUCCESS(vrc))
     5679        {
     5680            alock.release();
     5681            fireVideoCaptureChangedEvent(mEventSource);
    56495682        }
    56505683
     
    56525685    }
    56535686#endif /* VBOX_WITH_VIDEOREC */
    5654 
    5655     /* Notify console callbacks on success. */
    5656     if (SUCCEEDED(rc))
    5657     {
    5658         alock.release();
    5659         fireVideoCaptureChangedEvent(mEventSource);
    5660     }
    56615687
    56625688    return rc;
     
    99259951
    99269952#ifdef VBOX_WITH_VIDEOREC
    9927         Display *pDisplay = pConsole->i_getDisplay();
    9928         AssertPtr(pDisplay);
    9929         if (pDisplay)
    9930         {
    9931             BOOL fVideoRecEnabled = FALSE;
    9932             rc = pConsole->mMachine->COMGETTER(VideoCaptureEnabled)(&fVideoRecEnabled);
    9933             AssertComRCReturnVoid(rc);
    9934 
    9935             if (fVideoRecEnabled)
     9953        BOOL fVideoRecEnabled = FALSE;
     9954        rc = pConsole->mMachine->COMGETTER(VideoCaptureEnabled)(&fVideoRecEnabled);
     9955        AssertComRCReturnVoid(rc);
     9956
     9957        if (fVideoRecEnabled)
     9958        {
     9959            int vrc2 = pConsole->i_videoCaptureEnable(fVideoRecEnabled, &alock);
     9960            if (RT_SUCCESS(vrc2))
    99369961            {
    9937                 pDisplay->i_videoRecInvalidate();
    9938 
    9939                 /* If video recording fails for whatever reason here, this is
    9940                  * non-critical and should not be returned at this point -- otherwise
    9941                  * the display driver construction fails completely. */
    9942                 int vrc2 = VINF_SUCCESS;
    9943 
    9944 #ifdef VBOX_WITH_AUDIO_VIDEOREC
    9945                 /* Attach the video recording audio driver if required. */
    9946                 if (   pDisplay->i_videoRecGetFeatures() & VIDEORECFEATURE_AUDIO
    9947                     && pConsole->mAudioVideoRec)
    9948                     vrc2 = pConsole->mAudioVideoRec->doAttachDriverViaEmt(pConsole->mpUVM, &alock);
    9949 #endif
    9950                 if (   RT_SUCCESS(vrc2)
    9951                     && pDisplay->i_videoRecGetFeatures()) /* Any video recording (audio and/or video) feature enabled? */
    9952                 {
    9953                     vrc2 = pDisplay->i_videoRecStart();
    9954                     if (RT_SUCCESS(vrc2))
    9955                         fireVideoCaptureChangedEvent(pConsole->i_getEventSource());
    9956                 }
     9962                fireVideoCaptureChangedEvent(pConsole->mEventSource);
    99579963            }
     9964            else
     9965               LogRel(("VideoRec: Failed with %Rrc on VM power up\n", vrc2));
     9966
     9967            /** Note: Do not use vrc here, as starting the video recording isn't critical to
     9968             *        powering up the VM. */
    99589969        }
    99599970#endif
Note: See TracChangeset for help on using the changeset viewer.

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