VirtualBox

Changeset 95645 in vbox


Ignore:
Timestamp:
Jul 14, 2022 10:33:14 AM (2 years ago)
Author:
vboxsync
Message:

Recording/Main: Simplified and got rid of some destruction races by not dynamically (re-)allocating the recording context. Added docs, a bit of renaming. bugref:9286

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

Legend:

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

    r95639 r95645  
    174174    AudioVideoRec *i_recordingGetAudioDrv(void) const { return mRecording.mAudioRec; }
    175175# endif
    176     RecordingContext *i_recordingGetContext(void) const { return mRecording.mpCtx; }
     176    RecordingContext *i_recordingGetContext(void) { return &mRecording.mCtx; }
    177177# ifdef VBOX_WITH_AUDIO_RECORDING
    178178    HRESULT i_recordingSendAudio(const void *pvData, size_t cbData, uint64_t uDurationMs);
     
    11561156    {
    11571157        Recording()
    1158             : mpCtx(NULL)
    11591158# ifdef VBOX_WITH_AUDIO_RECORDING
    1160             , mAudioRec(NULL)
     1159            : mAudioRec(NULL)
    11611160# endif
    11621161        { }
    11631162
    11641163        /** The recording context. */
    1165         RecordingContext     *mpCtx;
     1164        RecordingContext      mCtx;
    11661165# ifdef VBOX_WITH_AUDIO_RECORDING
    11671166        /** Pointer to capturing audio backend. */
  • trunk/src/VBox/Main/include/Recording.h

    r93115 r95645  
    3636public:
    3737
    38     RecordingContext(Console *pConsole, const settings::RecordingSettings &a_Settings);
     38    RecordingContext();
     39
     40    RecordingContext(Console *ptrConsole, const settings::RecordingSettings &settings);
    3941
    4042    virtual ~RecordingContext(void);
     
    4648    size_t GetStreamCount(void) const;
    4749
    48     int Create(const settings::RecordingSettings &a_Settings);
     50    int Create(Console *pConsole, const settings::RecordingSettings &settings);
    4951    void Destroy(void);
    5052
     
    7072protected:
    7173
    72     int createInternal(const settings::RecordingSettings &a_Settings);
     74    int createInternal(Console *ptrConsole, const settings::RecordingSettings &settings);
    7375    int startInternal(void);
    7476    int stopInternal(void);
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r95639 r95645  
    58875887    if (pDisplay)
    58885888    {
    5889         const bool fIsEnabled =    mRecording.mpCtx
    5890                                 && mRecording.mpCtx->IsStarted();
     5889        bool const fIsEnabled = mRecording.mCtx.IsStarted();
    58915890
    58925891        if (RT_BOOL(fEnable) != fIsEnabled)
     
    59045903# ifdef VBOX_WITH_AUDIO_RECORDING
    59055904                        /* Attach the video recording audio driver if required. */
    5906                         if (   mRecording.mpCtx->IsFeatureEnabled(RecordingFeature_Audio)
     5905                        if (   mRecording.mCtx.IsFeatureEnabled(RecordingFeature_Audio)
    59075906                            && mRecording.mAudioRec)
    59085907                        {
    5909                             vrc = mRecording.mAudioRec->applyConfiguration(mRecording.mpCtx->GetConfig());
     5908                            vrc = mRecording.mAudioRec->applyConfiguration(mRecording.mCtx.GetConfig());
    59105909                            if (RT_SUCCESS(vrc))
    59115910                                vrc = mRecording.mAudioRec->doAttachDriverViaEmt(ptrVM.rawUVM(), ptrVM.vtable(), pAutoLock);
     
    59135912# endif
    59145913                        if (   RT_SUCCESS(vrc)
    5915                             && mRecording.mpCtx->IsReady()) /* Any video recording (audio and/or video) feature enabled? */
     5914                            && mRecording.mCtx.IsReady()) /* Any video recording (audio and/or video) feature enabled? */
    59165915                        {
    59175916                            vrc = pDisplay->i_recordingInvalidate();
     
    72357234HRESULT Console::i_recordingSendAudio(const void *pvData, size_t cbData, uint64_t uTimestampMs)
    72367235{
    7237     if (!mRecording.mpCtx)
    7238         return S_OK;
    7239 
    7240     if (   mRecording.mpCtx->IsStarted()
    7241         && mRecording.mpCtx->IsFeatureEnabled(RecordingFeature_Audio))
    7242         return mRecording.mpCtx->SendAudioFrame(pvData, cbData, uTimestampMs);
     7236    if (   mRecording.mCtx.IsStarted()
     7237        && mRecording.mCtx.IsFeatureEnabled(RecordingFeature_Audio))
     7238        return mRecording.mCtx.SendAudioFrame(pvData, cbData, uTimestampMs);
    72437239
    72447240    return S_OK;
     
    73107306int Console::i_recordingCreate(void)
    73117307{
    7312     AssertReturn(mRecording.mpCtx == NULL, VERR_WRONG_ORDER);
    7313 
    73147308    settings::RecordingSettings recordingSettings;
    7315     int rc = i_recordingGetSettings(recordingSettings);
    7316     if (RT_SUCCESS(rc))
    7317     {
    7318         try
    7319         {
    7320             mRecording.mpCtx = new RecordingContext(this /* pConsole */, recordingSettings);
    7321         }
    7322         catch (std::bad_alloc &)
    7323         {
    7324             return VERR_NO_MEMORY;
    7325         }
    7326         catch (int &rc2)
    7327         {
    7328             return rc2;
    7329         }
    7330     }
    7331 
    7332     LogFlowFuncLeaveRC(rc);
    7333     return rc;
     7309    int vrc = i_recordingGetSettings(recordingSettings);
     7310    if (RT_SUCCESS(vrc))
     7311        vrc = mRecording.mCtx.Create(this, recordingSettings);
     7312
     7313    LogFlowFuncLeaveRC(vrc);
     7314    return vrc;
    73347315}
    73357316
     
    73397320void Console::i_recordingDestroy(void)
    73407321{
    7341     if (mRecording.mpCtx)
    7342     {
    7343         delete mRecording.mpCtx;
    7344         mRecording.mpCtx = NULL;
    7345     }
    7346 
    7347     LogFlowThisFuncLeave();
     7322    mRecording.mCtx.Destroy();
    73487323}
    73497324
     
    73567331{
    73577332    RT_NOREF(pAutoLock);
    7358     AssertPtrReturn(mRecording.mpCtx, VERR_WRONG_ORDER);
    7359 
    7360     if (mRecording.mpCtx->IsStarted())
     7333
     7334    if (mRecording.mCtx.IsStarted())
    73617335        return VINF_SUCCESS;
    73627336
    73637337    LogRel(("Recording: Starting ...\n"));
    73647338
    7365     int rc = mRecording.mpCtx->Start();
    7366     if (RT_SUCCESS(rc))
    7367     {
    7368         for (unsigned uScreen = 0; uScreen < mRecording.mpCtx->GetStreamCount(); uScreen++)
     7339    int vrc = mRecording.mCtx.Start();
     7340    if (RT_SUCCESS(vrc))
     7341    {
     7342        for (unsigned uScreen = 0; uScreen < mRecording.mCtx.GetStreamCount(); uScreen++)
    73697343            mDisplay->i_recordingScreenChanged(uScreen);
    73707344    }
    73717345
    7372     LogFlowFuncLeaveRC(rc);
    7373     return rc;
     7346    LogFlowFuncLeaveRC(vrc);
     7347    return vrc;
    73747348}
    73757349
     
    73797353int Console::i_recordingStop(util::AutoWriteLock *pAutoLock /* = NULL */)
    73807354{
    7381     if (   !mRecording.mpCtx
    7382         || !mRecording.mpCtx->IsStarted())
     7355    if (!mRecording.mCtx.IsStarted())
    73837356        return VINF_SUCCESS;
    73847357
    73857358    LogRel(("Recording: Stopping ...\n"));
    73867359
    7387     int rc = mRecording.mpCtx->Stop();
    7388     if (RT_SUCCESS(rc))
    7389     {
    7390         const size_t cStreams = mRecording.mpCtx->GetStreamCount();
     7360    int vrc = mRecording.mCtx.Stop();
     7361    if (RT_SUCCESS(vrc))
     7362    {
     7363        const size_t cStreams = mRecording.mCtx.GetStreamCount();
    73917364        for (unsigned uScreen = 0; uScreen < cStreams; ++uScreen)
    73927365            mDisplay->i_recordingScreenChanged(uScreen);
     
    74057378    }
    74067379
    7407     LogFlowFuncLeaveRC(rc);
    7408     return rc;
     7380    LogFlowFuncLeaveRC(vrc);
     7381    return vrc;
    74097382}
    74107383
  • trunk/src/VBox/Main/src-client/Recording.cpp

    r95639 r95645  
    5858
    5959
    60 RecordingContext::RecordingContext(Console *a_pConsole, const settings::RecordingSettings &a_Settings)
    61     : pConsole(a_pConsole)
     60/**
     61 * Recording context constructor.
     62 *
     63 * @note    Will throw when unable to create.
     64 */
     65RecordingContext::RecordingContext(void)
     66    : pConsole(NULL)
    6267    , enmState(RECORDINGSTS_UNINITIALIZED)
    6368    , cStreamsEnabled(0)
    6469{
    65     int vrc = RecordingContext::createInternal(a_Settings);
     70    int vrc = RTCritSectInit(&this->CritSect);
    6671    if (RT_FAILURE(vrc))
    6772        throw vrc;
    6873}
    6974
     75/**
     76 * Recording context constructor.
     77 *
     78 * @param   ptrConsole          Pointer to console object this context is bound to (weak pointer).
     79 * @param   settings            Reference to recording settings to use for creation.
     80 *
     81 * @note    Will throw when unable to create.
     82 */
     83RecordingContext::RecordingContext(Console *ptrConsole, const settings::RecordingSettings &settings)
     84    : pConsole(NULL)
     85    , enmState(RECORDINGSTS_UNINITIALIZED)
     86    , cStreamsEnabled(0)
     87{
     88    int vrc = RTCritSectInit(&this->CritSect);
     89    if (RT_FAILURE(vrc))
     90        throw vrc;
     91
     92    vrc = RecordingContext::createInternal(ptrConsole, settings);
     93    if (RT_FAILURE(vrc))
     94        throw vrc;
     95}
     96
    7097RecordingContext::~RecordingContext(void)
    7198{
    7299    destroyInternal();
     100
     101    if (RTCritSectIsInitialized(&this->CritSect))
     102        RTCritSectDelete(&this->CritSect);
    73103}
    74104
     
    143173 *
    144174 * @returns IPRT status code.
    145  * @param   a_Settings          Recording settings to use for context creation.
    146  */
    147 int RecordingContext::createInternal(const settings::RecordingSettings &a_Settings)
    148 {
    149     int vrc = RTCritSectInit(&this->CritSect);
    150     if (RT_FAILURE(vrc))
    151         return vrc;
    152 
    153     settings::RecordingScreenSettingsMap::const_iterator itScreen = a_Settings.mapScreens.begin();
    154     while (itScreen != a_Settings.mapScreens.end())
     175 * @param   ptrConsole          Pointer to console object this context is bound to (weak pointer).
     176 * @param   settings            Reference to recording settings to use for creation.
     177 */
     178int RecordingContext::createInternal(Console *ptrConsole, const settings::RecordingSettings &settings)
     179{
     180    int vrc = VINF_SUCCESS;
     181
     182    this->pConsole = ptrConsole;
     183
     184    settings::RecordingScreenSettingsMap::const_iterator itScreen = settings.mapScreens.begin();
     185    while (itScreen != settings.mapScreens.end())
    155186    {
    156187        RecordingStream *pStream = NULL;
     
    178209
    179210        /* Copy the settings to our context. */
    180         this->Settings  = a_Settings;
     211        this->Settings  = settings;
    181212
    182213        vrc = RTSemEventCreate(&this->WaitEvent);
     
    260291void RecordingContext::destroyInternal(void)
    261292{
     293    lock();
     294
    262295    if (this->enmState == RECORDINGSTS_UNINITIALIZED)
     296    {
     297        unlock();
    263298        return;
     299    }
    264300
    265301    int vrc = stopInternal();
    266302    AssertRCReturnVoid(vrc);
    267 
    268     lock();
    269303
    270304    vrc = RTSemEventDestroy(this->WaitEvent);
     
    292326    Assert(this->mapBlocksCommon.size() == 0);
    293327
    294     unlock();
    295 
    296     if (RTCritSectIsInitialized(&this->CritSect))
    297         RTCritSectDelete(&this->CritSect);
    298 
    299328    this->enmState = RECORDINGSTS_UNINITIALIZED;
     329
     330    unlock();
    300331}
    301332
     
    371402 *
    372403 * @returns IPRT status code.
    373  * @param   a_Settings          Recording settings to use for creation.
    374  *
    375  */
    376 int RecordingContext::Create(const settings::RecordingSettings &a_Settings)
    377 {
    378     return createInternal(a_Settings);
     404 * @param   ptrConsole          Pointer to console object this context is bound to (weak pointer).
     405 * @param   settings            Reference to recording settings to use for creation.
     406 */
     407int RecordingContext::Create(Console *ptrConsole, const settings::RecordingSettings &settings)
     408{
     409    return createInternal(ptrConsole, settings);
    379410}
    380411
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