VirtualBox

Changeset 75307 in vbox


Ignore:
Timestamp:
Nov 7, 2018 1:56:14 PM (6 years ago)
Author:
vboxsync
Message:

Recording: Bugfixes for Main and FE/Qt.

Location:
trunk/src/VBox
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIIndicatorsPool.cpp

    r75291 r75307  
    957957        /* For now all screens have the same config: */
    958958        CCaptureScreenSettings recordingScreen0Settings = recordingSettings.GetScreenSettings(0);
    959 
    960         QStringList strOptionsPairList = recordingScreen0Settings.GetOptions().split(",", QString::SkipEmptyParts);
    961 
    962         for (int i = 0; i < strOptionsPairList.size(); ++i)
    963         {
    964             if (strOptionsPairList.at(i).contains("vc_enabled", Qt::CaseInsensitive) &&
    965                 strOptionsPairList.at(i).contains("true", Qt::CaseInsensitive))
    966                 m_eRecordingMode = (UIIndicatorStateRecordingMode)((int)m_eRecordingMode | (int)UIIndicatorStateRecordingMode_Video);
    967 
    968             if (strOptionsPairList.at(i).contains("ac_enabled", Qt::CaseInsensitive) &&
    969                 strOptionsPairList.at(i).contains("true", Qt::CaseInsensitive))
    970                 m_eRecordingMode = (UIIndicatorStateRecordingMode)((int)m_eRecordingMode | (int)UIIndicatorStateRecordingMode_Audio);
    971         }
     959        if (recordingScreen0Settings.IsFeatureEnabled(KCaptureFeature_Video))
     960            m_eRecordingMode = (UIIndicatorStateRecordingMode)((int)m_eRecordingMode | (int)UIIndicatorStateRecordingMode_Video);
     961
     962        if (recordingScreen0Settings.IsFeatureEnabled(KCaptureFeature_Audio))
     963            m_eRecordingMode = (UIIndicatorStateRecordingMode)((int)m_eRecordingMode | (int)UIIndicatorStateRecordingMode_Audio);
    972964    }
    973965
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsDisplay.cpp

    r75296 r75307  
    370370
    371371    /* Check whether remote display server is valid: */
    372     const CVRDEServer &comServer = m_machine.GetVRDEServer();
    373     oldDisplayData.m_fRemoteDisplayServerSupported = !comServer.isNull();
    374     if (!comServer.isNull())
     372    const CVRDEServer &vrdeServer = m_machine.GetVRDEServer();
     373    oldDisplayData.m_fRemoteDisplayServerSupported = !vrdeServer.isNull();
     374    if (!vrdeServer.isNull())
    375375    {
    376376        /* Gather old 'Remote Display' data: */
    377         oldDisplayData.m_fRemoteDisplayServerEnabled = comServer.GetEnabled();
    378         oldDisplayData.m_strRemoteDisplayPort = comServer.GetVRDEProperty("TCP/Ports");
    379         oldDisplayData.m_remoteDisplayAuthType = comServer.GetAuthType();
    380         oldDisplayData.m_uRemoteDisplayTimeout = comServer.GetAuthTimeout();
    381         oldDisplayData.m_fRemoteDisplayMultiConnAllowed = comServer.GetAllowMultiConnection();
     377        oldDisplayData.m_fRemoteDisplayServerEnabled = vrdeServer.GetEnabled();
     378        oldDisplayData.m_strRemoteDisplayPort = vrdeServer.GetVRDEProperty("TCP/Ports");
     379        oldDisplayData.m_remoteDisplayAuthType = vrdeServer.GetAuthType();
     380        oldDisplayData.m_uRemoteDisplayTimeout = vrdeServer.GetAuthTimeout();
     381        oldDisplayData.m_fRemoteDisplayMultiConnAllowed = vrdeServer.GetAllowMultiConnection();
    382382    }
    383383
    384384    /* Gather old 'Recording' data: */
    385385    CCaptureSettings recordingSettings = m_machine.GetCaptureSettings();
     386    Assert(recordingSettings.isNotNull());
    386387    oldDisplayData.m_fRecordingEnabled = recordingSettings.GetEnabled();
    387388
     
    403404    for (int iScreenIndex = 0; iScreenIndex < recordingScreenSettingsVector.size(); ++iScreenIndex)
    404405    {
    405         CCaptureScreenSettings captureScreenSettings = recordingScreenSettingsVector.at(iScreenIndex);
    406         oldDisplayData.m_vecRecordingScreens[iScreenIndex] = captureScreenSettings.GetEnabled();
     406        CCaptureScreenSettings recordingScreenSettings = recordingScreenSettingsVector.at(iScreenIndex);
     407        if (!recordingScreenSettings.isNull())
     408            oldDisplayData.m_vecRecordingScreens[iScreenIndex] = recordingScreenSettings.GetEnabled();
    407409    }
    408410
     
    15101512
    15111513        CCaptureSettings recordingSettings = m_machine.GetCaptureSettings();
     1514        Assert(recordingSettings.isNotNull());
    15121515
    15131516        /* Save new 'Recording' data for online case: */
  • trunk/src/VBox/Main/include/CaptureScreenSettingsImpl.h

    r75279 r75307  
    103103    // internal methods
    104104    bool i_canChangeSettings();
    105     int  i_getDefaultCaptureFile(Utf8Str &strFile);
     105    int  i_getDefaultFileName(Utf8Str &strFile);
     106    int  i_initInternal();
    106107
    107108private:
  • trunk/src/VBox/Main/include/CaptureSettingsImpl.h

    r75286 r75307  
    2626{
    2727    struct CaptureSettings;
     28    struct CaptureScreenSettings;
    2829}
    2930
     
    5758private:
    5859
     60    int i_addScreen(uint32_t uScreenId, const settings::CaptureScreenSettings &data);
     61
     62private:
     63
    5964    // wrapped ICaptureSettings properties
    6065    HRESULT getEnabled(BOOL *enabled);
  • trunk/src/VBox/Main/include/MachineImpl.h

    r75251 r75307  
    494494    void i_setModified(uint32_t fl, bool fAllowStateModification = true);
    495495    void i_setModifiedLock(uint32_t fl, bool fAllowStateModification = true);
     496
     497    MachineState_T i_getMachineState() const { return mData->mMachineState; }
    496498
    497499    bool i_isStateModificationAllowed() const { return mData->m_fAllowStateModification; }
  • trunk/src/VBox/Main/include/VideoRec.h

    r75251 r75307  
    180180    int Destroy(void);
    181181
     182    int Start(void);
     183    int Stop(void);
     184
    182185    int SendAudioFrame(const void *pvData, size_t cbData, uint64_t uTimestampMs);
    183186    int SendVideoFrame(uint32_t uScreen,
     
    196199
    197200    int createInternal(const settings::CaptureSettings &a_Settings);
     201    int startInternal(void);
     202    int stopInternal(void);
    198203
    199204    int destroyInternal(void);
  • trunk/src/VBox/Main/include/VideoRecStream.h

    r75254 r75307  
    130130protected:
    131131
    132     int open(void);
     132    int open(const settings::CaptureScreenSettings &Settings);
    133133    int close(void);
    134134
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r75287 r75307  
    56165616    if (pDisplay)
    56175617    {
    5618         const bool fEnabled =    Capture.mpVideoRecCtx
    5619                               && Capture.mpVideoRecCtx->IsStarted();
    5620 
    5621         if (RT_BOOL(fEnable) != fEnabled)
     5618        const bool fIsEnabled =    Capture.mpVideoRecCtx
     5619                                && Capture.mpVideoRecCtx->IsStarted();
     5620
     5621        if (RT_BOOL(fEnable) != fIsEnabled)
    56225622        {
    56235623            LogRel(("VideoRec: %s\n", fEnable ? "Enabling" : "Disabling"));
     
    56285628            {
    56295629                vrc = i_videoRecCreate();
     5630                if (RT_SUCCESS(vrc))
     5631                    vrc = i_videoRecStart();
     5632
    56305633                if (RT_SUCCESS(vrc))
    56315634                {
     
    69046907    AssertComRCReturn(hrc, VERR_INVALID_PARAMETER);
    69056908
    6906     Settings.mapScreens.clear();
     6909    Settings.applyDefaults();
    69076910
    69086911    for (unsigned long i = 0; i < (unsigned long)paCaptureScreens.size(); ++i)
     
    69346937    }
    69356938
     6939    Assert(Settings.mapScreens.size() == paCaptureScreens.size());
     6940
    69366941    return VINF_SUCCESS;
    69376942}
     
    69616966    }
    69626967
     6968    settings::CaptureSettings Settings;
     6969    rc = i_videoRecGetSettings(Settings);
     6970    if (RT_SUCCESS(rc))
     6971    {
     6972        AssertPtr(Capture.mpVideoRecCtx);
     6973        rc = Capture.mpVideoRecCtx->Create(Settings);
     6974    }
     6975
     6976    LogFlowFuncLeaveRC(rc);
    69636977    return rc;
    69646978}
     
    69706984{
    69716985    if (Capture.mpVideoRecCtx)
     6986    {
    69726987        delete Capture.mpVideoRecCtx;
     6988        Capture.mpVideoRecCtx = NULL;
     6989    }
     6990
     6991    LogFlowThisFuncLeave();
    69736992}
    69746993
     
    69877006    LogRel(("VideoRec: Starting ...\n"));
    69887007
    6989     settings::CaptureSettings Settings;
    6990     int rc = i_videoRecGetSettings(Settings);
    6991     if (RT_SUCCESS(rc))
    6992     {
    6993         rc = Capture.mpVideoRecCtx->Create(Settings);
    6994         if (RT_SUCCESS(rc))
    6995         {
    6996             for (unsigned uScreen = 0; uScreen < Capture.mpVideoRecCtx->GetStreamCount(); uScreen++)
    6997                 mDisplay->i_videoRecScreenChanged(uScreen);
    6998         }
    6999     }
     7008    int rc = VINF_SUCCESS;
     7009
     7010    for (unsigned uScreen = 0; uScreen < Capture.mpVideoRecCtx->GetStreamCount(); uScreen++)
     7011        mDisplay->i_videoRecScreenChanged(uScreen);
    70007012
    70017013    if (RT_FAILURE(rc))
    70027014        LogRel(("VideoRec: Failed to start video recording (%Rrc)\n", rc));
    70037015
     7016    LogFlowFuncLeaveRC(rc);
    70047017    return rc;
    70057018}
     
    70107023int Console::i_videoRecStop(void)
    70117024{
    7012     AssertPtrReturn(Capture.mpVideoRecCtx, VERR_WRONG_ORDER);
    7013 
    7014     if (!Capture.mpVideoRecCtx->IsStarted())
     7025    if (   !Capture.mpVideoRecCtx
     7026        || !Capture.mpVideoRecCtx->IsStarted())
    70157027        return VINF_SUCCESS;
    70167028
     
    70207032    for (unsigned uScreen = 0; uScreen < cStreams; ++uScreen)
    70217033        mDisplay->i_videoRecScreenChanged(uScreen);
    7022 
    7023     delete Capture.mpVideoRecCtx;
    7024     Capture.mpVideoRecCtx = NULL;
    70257034
    70267035    ComPtr<ICaptureSettings> pCaptureSettings;
     
    70327041    LogRel(("VideoRec: Stopped\n"));
    70337042
     7043    LogFlowFuncLeaveRC(VINF_SUCCESS);
    70347044    return VINF_SUCCESS;
    70357045}
  • trunk/src/VBox/Main/src-client/VideoRec.cpp

    r75254 r75307  
    5858
    5959/**
    60  * Enumeration for a video recording state.
     60 * Enumeration for a recording state.
    6161 */
    6262enum VIDEORECSTS
     
    6464    /** Not initialized. */
    6565    VIDEORECSTS_UNINITIALIZED = 0,
    66     /** Initialized. */
    67     VIDEORECSTS_INITIALIZED   = 1,
     66    /** Created. */
     67    VIDEORECSTS_CREATED       = 1,
     68    /** Started. */
     69    VIDEORECSTS_STARTED       = 2,
    6870    /** The usual 32-bit hack. */
    6971    VIDEORECSTS_32BIT_HACK    = 0x7fffffff
     
    105107
    106108CaptureContext::CaptureContext(Console *a_pConsole)
    107     : pConsole(a_pConsole) { }
     109    : pConsole(a_pConsole)
     110    , enmState(VIDEORECSTS_UNINITIALIZED) { }
    108111
    109112CaptureContext::CaptureContext(Console *a_pConsole, const settings::CaptureSettings &a_Settings)
    110113    : pConsole(a_pConsole)
     114    , enmState(VIDEORECSTS_UNINITIALIZED)
    111115{
    112116    int rc = CaptureContext::createInternal(a_Settings);
     
    214218    {
    215219        this->tsStartMs = RTTimeMilliTS();
    216         this->enmState  = VIDEORECSTS_UNINITIALIZED;
     220        this->enmState  = VIDEORECSTS_CREATED;
    217221        this->fStarted  = false;
    218222        this->fShutdown = false;
     
    223227        rc = RTSemEventCreate(&this->WaitEvent);
    224228        AssertRCReturn(rc, rc);
    225 
    226         rc = RTThreadCreate(&this->Thread, CaptureContext::threadMain, (void *)this, 0,
    227                             RTTHREADTYPE_MAIN_WORKER, RTTHREADFLAGS_WAITABLE, "VideoRec");
    228 
    229         if (RT_SUCCESS(rc)) /* Wait for the thread to start. */
    230             rc = RTThreadUserWait(this->Thread, 30 * RT_MS_1SEC /* 30s timeout */);
    231 
    232         if (RT_SUCCESS(rc))
    233         {
    234             this->enmState = VIDEORECSTS_INITIALIZED;
    235             this->fStarted = true;
    236         }
    237229    }
    238230
     
    246238}
    247239
     240int CaptureContext::startInternal(void)
     241{
     242    if (this->enmState == VIDEORECSTS_STARTED)
     243        return VINF_SUCCESS;
     244
     245    Assert(this->enmState == VIDEORECSTS_CREATED);
     246
     247    int rc = RTThreadCreate(&this->Thread, CaptureContext::threadMain, (void *)this, 0,
     248                            RTTHREADTYPE_MAIN_WORKER, RTTHREADFLAGS_WAITABLE, "VideoRec");
     249
     250    if (RT_SUCCESS(rc)) /* Wait for the thread to start. */
     251        rc = RTThreadUserWait(this->Thread, 30 * RT_MS_1SEC /* 30s timeout */);
     252
     253    if (RT_SUCCESS(rc))
     254    {
     255        this->enmState = VIDEORECSTS_STARTED;
     256        this->fStarted = true;
     257    }
     258
     259    return rc;
     260}
     261
     262int CaptureContext::stopInternal(void)
     263{
     264    if (this->enmState != VIDEORECSTS_STARTED)
     265        return VINF_SUCCESS;
     266
     267    LogFunc(("Shutting down thread ...\n"));
     268
     269    /* Set shutdown indicator. */
     270    ASMAtomicWriteBool(&this->fShutdown, true);
     271
     272    /* Signal the thread and wait for it to shut down. */
     273    int rc = threadNotify();
     274    if (RT_SUCCESS(rc))
     275        rc = RTThreadWait(this->Thread, 30 * 1000 /* 10s timeout */, NULL);
     276
     277    return rc;
     278}
     279
    248280/**
    249281 * Destroys a video recording context.
     
    253285    int rc = VINF_SUCCESS;
    254286
    255     if (this->enmState == VIDEORECSTS_INITIALIZED)
    256     {
    257         LogFunc(("Shutting down thread ...\n"));
    258 
    259         /* Set shutdown indicator. */
    260         ASMAtomicWriteBool(&this->fShutdown, true);
    261 
    262         /* Signal the thread and wait for it to shut down. */
    263         rc = threadNotify();
    264         if (RT_SUCCESS(rc))
    265             rc = RTThreadWait(this->Thread, 30 * 1000 /* 10s timeout */, NULL);
    266 
     287    if (this->enmState == VIDEORECSTS_STARTED)
     288    {
     289        rc = stopInternal();
    267290        if (RT_SUCCESS(rc))
    268291        {
     
    365388}
    366389
     390int CaptureContext::Start(void)
     391{
     392    return startInternal();
     393}
     394
     395int CaptureContext::Stop(void)
     396{
     397    return stopInternal();
     398}
     399
    367400bool CaptureContext::IsFeatureEnabled(CaptureFeature_T enmFeature) const
    368401{
     
    394427    RT_NOREF(uTimeStampMs);
    395428
    396     if (this->enmState != VIDEORECSTS_INITIALIZED)
     429    if (this->enmState != VIDEORECSTS_STARTED)
    397430        return false;
    398431
  • trunk/src/VBox/Main/src-client/VideoRecStream.cpp

    r75256 r75307  
    4545    : tsStartMs(0)
    4646{
     47    File.pWEBM = NULL;
     48    File.hFile = NIL_RTFILE;
    4749}
    4850
     
    5052    : tsStartMs(0)
    5153{
     54    File.pWEBM = NULL;
     55    File.hFile = NIL_RTFILE;
     56
    5257    int rc2 = initInternal(uScreen, Settings);
    5358    if (RT_FAILURE(rc2))
     
    6671 * @returns IPRT status code.
    6772 */
    68 int CaptureStream::open(void)
    69 {
    70     Assert(ScreenSettings.enmDest == CaptureDestination_None);
     73int CaptureStream::open(const settings::CaptureScreenSettings &Settings)
     74{
     75    /* Sanity. */
     76    Assert(Settings.enmDest != CaptureDestination_None);
    7177
    7278    int rc;
    7379
    74     switch (ScreenSettings.enmDest)
     80    switch (Settings.enmDest)
    7581    {
    7682        case CaptureDestination_File:
    7783        {
    78             Assert(ScreenSettings.File.strName.isNotEmpty());
    79 
    80             char *pszAbsPath = RTPathAbsDup(ScreenSettings.File.strName.c_str());
     84            Assert(Settings.File.strName.isNotEmpty());
     85
     86            char *pszAbsPath = RTPathAbsDup(Settings.File.strName.c_str());
    8187            AssertPtrReturn(pszAbsPath, VERR_NO_MEMORY);
    8288
     
    132138                    if (RT_SUCCESS(rc))
    133139                        rc = RTFileOpen(&hFile, pszFile, fOpen);
     140                }
     141
     142                try
     143                {
     144                    Assert(File.pWEBM == NULL);
     145                    File.pWEBM = new WebMWriter();
     146                }
     147                catch (std::bad_alloc &)
     148               {
     149                    rc = VERR_NO_MEMORY;
    134150                }
    135151
     
    656672        return rc;
    657673
    658     rc = open();
     674    rc = open(Settings);
    659675    if (RT_FAILURE(rc))
    660676        return rc;
     
    675691            const char *pszFile = this->ScreenSettings.File.strName.c_str();
    676692
     693            AssertPtr(File.pWEBM);
    677694            rc = File.pWEBM->OpenEx(pszFile, &this->File.hFile,
    678695#ifdef VBOX_WITH_AUDIO_VIDEOREC
  • trunk/src/VBox/Main/src-server/CaptureScreenSettingsImpl.cpp

    r75279 r75307  
    8686    m = new Data();
    8787
    88     /* share the parent weakly */
     88    /* Share the parent weakly. */
    8989    unconst(m->pMachine) = aParent;
     90    /* mPeer is left null. */
    9091
    9192    /* Simply copy the settings data. */
     
    9495    m->bd->operator=(data);
    9596
    96     autoInitSpan.setSucceeded();
     97    HRESULT rc = S_OK;
     98
     99    int vrc = i_initInternal();
     100    if (RT_SUCCESS(vrc))
     101    {
     102        autoInitSpan.setSucceeded();
     103    }
     104    else
     105    {
     106        autoInitSpan.setFailed();
     107        rc = E_UNEXPECTED;
     108    }
    97109
    98110    LogFlowThisFuncLeave();
    99     return S_OK;
     111    return rc;
    100112}
    101113
     
    129141    m->bd.share(that->m->bd);
    130142
    131     autoInitSpan.setSucceeded();
     143    HRESULT rc = S_OK;
     144
     145    int vrc = i_initInternal();
     146    if (RT_SUCCESS(vrc))
     147    {
     148        autoInitSpan.setSucceeded();
     149    }
     150    else
     151    {
     152        autoInitSpan.setFailed();
     153        rc = E_UNEXPECTED;
     154    }
    132155
    133156    LogFlowThisFuncLeave();
    134     return S_OK;
     157    return rc;
    135158}
    136159
     
    154177
    155178    unconst(m->pMachine) = aParent;
    156     // mPeer is left null
     179    /* mPeer is left null. */
    157180
    158181    AutoWriteLock thatlock(that COMMA_LOCKVAL_SRC_POS);
     
    161184    m->bd.attachCopy(that->m->bd);
    162185
    163     autoInitSpan.setSucceeded();
     186    HRESULT rc = S_OK;
     187
     188    int vrc = i_initInternal();
     189    if (RT_SUCCESS(vrc))
     190    {
     191        autoInitSpan.setSucceeded();
     192    }
     193    else
     194    {
     195        autoInitSpan.setFailed();
     196        rc = E_UNEXPECTED;
     197    }
    164198
    165199    LogFlowThisFuncLeave();
    166     return S_OK;
     200    return rc;
    167201}
    168202
     
    216250    if (m->bd->fEnabled != RT_BOOL(enabled))
    217251    {
     252        m->bd.backup();
     253        m->bd->fEnabled = RT_BOOL(enabled);
    218254        alock.release();
     255
     256        AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     257        m->pMachine->i_setModified(Machine::IsModified_Capture);
     258        mlock.release();
    219259
    220260        HRESULT rc = m->pMachine->i_onCaptureChange();
    221261        if (FAILED(rc)) return rc;
    222 
    223         m->pMachine->i_setModified(Machine::IsModified_Capture);
    224 
    225         alock.acquire();
    226         m->bd->fEnabled = RT_BOOL(enabled);
    227         alock.release();
    228262
    229263        /** Save settings if online - @todo why is this required? -- @bugref{6818} */
     
    263297    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    264298
    265     m->pMachine->i_setModified(Machine::IsModified_Capture);
    266     m->bd.backup();
    267 
     299    m->bd.backup();
    268300    m->bd->featureMap.clear();
    269301
     
    273305        m->bd->featureMap[CaptureFeature_Video] = true;
    274306
     307    alock.release();
     308
     309    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     310    m->pMachine->i_setModified(Machine::IsModified_Capture);
     311    mlock.release();
     312
    275313    return S_OK;
    276314}
     
    292330    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    293331
    294     m->pMachine->i_setModified(Machine::IsModified_Capture);
    295332    m->bd.backup();
    296333    m->bd->enmDest = aDestination;
    297334
     335    alock.release();
     336
     337    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     338    m->pMachine->i_setModified(Machine::IsModified_Capture);
     339    mlock.release();
     340
    298341    return S_OK;
    299342}
     
    303346    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    304347
    305     if (m->bd->File.strName.isEmpty())
    306         i_getDefaultCaptureFile(aFileName);
    307     else
    308         aFileName = m->bd->File.strName;
     348    aFileName = m->bd->File.strName;
    309349
    310350    return S_OK;
     
    323363        return setError(E_INVALIDARG, tr("Capture file name '%s' is not absolute"), strFile.c_str());
    324364
    325     if (!strFile.isEmpty())
    326     {
    327         Utf8Str defaultFile;
    328         i_getDefaultCaptureFile(defaultFile);
    329         if (!RTPathCompare(strFile.c_str(), defaultFile.c_str()))
    330             strFile.setNull();
    331     }
    332 
    333     m->pMachine->i_setModified(Machine::IsModified_Capture);
    334365    m->bd.backup();
    335366    m->bd->File.strName = strFile;
    336367
     368    alock.release();
     369
     370    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     371    m->pMachine->i_setModified(Machine::IsModified_Capture);
     372    mlock.release();
     373
    337374    return S_OK;
    338375}
     
    354391        return setError(E_INVALIDARG, tr("Cannot change maximum time while capturing is enabled"));
    355392
    356     m->pMachine->i_setModified(Machine::IsModified_Capture);
    357     m->bd.backup();
    358 
     393    m->bd.backup();
    359394    m->bd->ulMaxTimeS = aMaxTimeS;
    360395
     396    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     397    m->pMachine->i_setModified(Machine::IsModified_Capture);
     398    mlock.release();
     399
    361400    return S_OK;
    362401}
     
    378417        return setError(E_INVALIDARG, tr("Cannot change maximum file size while capturing is enabled"));
    379418
    380     m->pMachine->i_setModified(Machine::IsModified_Capture);
    381     m->bd.backup();
    382 
     419    m->bd.backup();
    383420    m->bd->File.ulMaxSizeMB = aMaxFileSize;
    384421
     422    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     423    m->pMachine->i_setModified(Machine::IsModified_Capture);
     424    mlock.release();
     425
    385426    return S_OK;
    386427}
     
    402443        return setError(E_INVALIDARG, tr("Cannot change options string while capturing is enabled"));
    403444
    404     m->pMachine->i_setModified(Machine::IsModified_Capture);
    405     m->bd.backup();
    406 
     445    m->bd.backup();
    407446    m->bd->strOptions = aOptions;
    408447
     448    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     449    m->pMachine->i_setModified(Machine::IsModified_Capture);
     450    mlock.release();
     451
    409452    return S_OK;
    410453}
     
    426469        return setError(E_INVALIDARG, tr("Cannot change audio codec while capturing is enabled"));
    427470
    428     m->pMachine->i_setModified(Machine::IsModified_Capture);
    429     m->bd.backup();
    430 
     471    m->bd.backup();
    431472    m->bd->Audio.enmAudioCodec = aCodec;
    432473
     474    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     475    m->pMachine->i_setModified(Machine::IsModified_Capture);
     476    mlock.release();
     477
    433478    return S_OK;
    434479}
     
    450495        return setError(E_INVALIDARG, tr("Cannot change audio Hertz rate while capturing is enabled"));
    451496
    452     m->pMachine->i_setModified(Machine::IsModified_Capture);
    453     m->bd.backup();
    454 
     497    m->bd.backup();
    455498    m->bd->Audio.uHz = (uint16_t)aHz;
    456499
     500    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     501    m->pMachine->i_setModified(Machine::IsModified_Capture);
     502    mlock.release();
     503
    457504    return S_OK;
    458505}
     
    474521        return setError(E_INVALIDARG, tr("Cannot change audio bits while capturing is enabled"));
    475522
    476     m->pMachine->i_setModified(Machine::IsModified_Capture);
    477     m->bd.backup();
    478 
     523    m->bd.backup();
    479524    m->bd->Audio.cBits = (uint8_t)aBits;
    480525
     526    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     527    m->pMachine->i_setModified(Machine::IsModified_Capture);
     528    mlock.release();
     529
    481530    return S_OK;
    482531}
     
    498547        return setError(E_INVALIDARG, tr("Cannot change audio channels while capturing is enabled"));
    499548
    500     m->pMachine->i_setModified(Machine::IsModified_Capture);
    501     m->bd.backup();
    502 
     549    m->bd.backup();
    503550    m->bd->Audio.cChannels = (uint8_t)aChannels;
    504551
     552    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     553    m->pMachine->i_setModified(Machine::IsModified_Capture);
     554    mlock.release();
     555
    505556    return S_OK;
    506557}
     
    522573        return setError(E_INVALIDARG, tr("Cannot change video codec while capturing is enabled"));
    523574
    524     m->pMachine->i_setModified(Machine::IsModified_Capture);
    525     m->bd.backup();
    526 
     575    m->bd.backup();
    527576    m->bd->Video.enmCodec = aCodec;
    528577
     578    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     579    m->pMachine->i_setModified(Machine::IsModified_Capture);
     580    mlock.release();
     581
    529582    return S_OK;
    530583}
     
    546599        return setError(E_INVALIDARG, tr("Cannot change video width while capturing is enabled"));
    547600
    548     m->pMachine->i_setModified(Machine::IsModified_Capture);
    549     m->bd.backup();
    550 
     601    m->bd.backup();
    551602    m->bd->Video.ulWidth = aVideoWidth;
    552603
     604    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     605    m->pMachine->i_setModified(Machine::IsModified_Capture);
     606    mlock.release();
     607
    553608    return S_OK;
    554609}
     
    570625        return setError(E_INVALIDARG, tr("Cannot change video height while capturing is enabled"));
    571626
    572     m->pMachine->i_setModified(Machine::IsModified_Capture);
    573     m->bd.backup();
    574 
     627    m->bd.backup();
    575628    m->bd->Video.ulHeight = aVideoHeight;
    576629
     630    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     631    m->pMachine->i_setModified(Machine::IsModified_Capture);
     632    mlock.release();
     633
    577634    return S_OK;
    578635}
     
    594651        return setError(E_INVALIDARG, tr("Cannot change video rate while capturing is enabled"));
    595652
    596     m->pMachine->i_setModified(Machine::IsModified_Capture);
    597     m->bd.backup();
    598 
     653    m->bd.backup();
    599654    m->bd->Video.ulRate = aVideoRate;
     655
     656    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     657    m->pMachine->i_setModified(Machine::IsModified_Capture);
     658    mlock.release();
    600659
    601660    return S_OK;
     
    640699        return setError(E_INVALIDARG, tr("Cannot change video FPS while capturing is enabled"));
    641700
    642     m->pMachine->i_setModified(Machine::IsModified_Capture);
    643     m->bd.backup();
    644 
     701    m->bd.backup();
    645702    m->bd->Video.ulFPS = aVideoFPS;
     703
     704    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     705    m->pMachine->i_setModified(Machine::IsModified_Capture);
     706    mlock.release();
    646707
    647708    return S_OK;
     
    685746 * Returns the full path to the default video capture file.
    686747 */
    687 int CaptureScreenSettings::i_getDefaultCaptureFile(Utf8Str &strFile)
     748int CaptureScreenSettings::i_getDefaultFileName(Utf8Str &strFile)
    688749{
    689750    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    696757}
    697758
     759/**
     760 * Initializes data, internal version.
     761 *
     762 * @returns IPRT status code.
     763 */
     764int CaptureScreenSettings::i_initInternal(void)
     765{
     766    Assert(m);
     767    return i_getDefaultFileName(m->bd->File.strName);
     768}
     769
  • trunk/src/VBox/Main/src-server/CaptureSettingsImpl.cpp

    r75287 r75307  
    4444    ComObjPtr<CaptureSettings>  pPeer;
    4545    CaptureScreenSettingsMap    mapScreenSettings;
     46    bool                        fHasMachineLock;
    4647
    4748    // use the XML settings structure in the members for simplicity
     
    8485
    8586    m->bd.allocate();
     87    m->fHasMachineLock = false;
    8688
    8789    autoInitSpan.setSucceeded();
     
    119121    m->bd.share(that->m->bd);
    120122    m->mapScreenSettings = that->m->mapScreenSettings;
     123    m->fHasMachineLock = false;
    121124
    122125    autoInitSpan.setSucceeded();
     
    151154    m->bd.attachCopy(that->m->bd);
    152155    m->mapScreenSettings = that->m->mapScreenSettings;
     156    m->fHasMachineLock = false;
    153157
    154158    autoInitSpan.setSucceeded();
     
    196200HRESULT CaptureSettings::setEnabled(BOOL enable)
    197201{
    198     /* the machine needs to be mutable */
    199     AutoMutableStateDependency adep(m->pMachine);
    200     if (FAILED(adep.rc())) return adep.rc();
    201 
    202202    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    203203
     
    216216        {
    217217            /*
    218              * Normally we would do the actual change _after_ i_onVideoCaptureChange() succeeded.
    219              * We cannot do this because that function uses Machine::GetVideoCaptureEnabled to
     218             * Normally we would do the actual change _after_ i_onCaptureChange() succeeded.
     219             * We cannot do this because that function uses CaptureSettings::GetEnabled to
    220220             * determine if it should start or stop capturing. Therefore we need to manually
    221221             * undo change.
     
    230230            m->pMachine->i_setModified(Machine::IsModified_Capture);
    231231
     232            /* We need to indicate here that we just took the machine lock, as Machine::i_saveSettings() will
     233             * call i_commit(), which in turn also wants to lock the machine for writing. */
     234            m->fHasMachineLock = true;
     235
    232236            /** Save settings if online - @todo why is this required? -- @bugref{6818} */
    233             if (Global::IsOnline(adep.machineState()))
    234                 m->pMachine->i_saveSettings(NULL);
     237            if (Global::IsOnline(m->pMachine->i_getMachineState()))
     238                rc = m->pMachine->i_saveSettings(NULL);
     239
     240            m->fHasMachineLock = false;
    235241        }
    236242    }
     
    251257    {
    252258        itScreenSettings->second.queryInterfaceTo(aCaptureScreenSettings[i].asOutParam());
     259        Assert(aCaptureScreenSettings[i].isNotNull());
    253260        ++i;
    254261        ++itScreenSettings;
    255262    }
    256263
     264    Assert(aCaptureScreenSettings.size() == m->mapScreenSettings.size());
     265
    257266    return S_OK;
    258267}
     
    280289
    281290/**
     291 * Adds a screen settings object to the recording settings.
     292 *
     293 * @returns IPRT status code. VERR_ALREADY_EXISTS if the object in question already exists.
     294 * @param   uScreenId           Screen ID to add settings for.
     295 * @param   data                Recording screen settings to use for that screen.
     296 */
     297int CaptureSettings::i_addScreen(uint32_t uScreenId, const settings::CaptureScreenSettings &data)
     298{
     299    if (m->mapScreenSettings.find(uScreenId) != m->mapScreenSettings.end())
     300    {
     301        AssertFailed();
     302        return VERR_ALREADY_EXISTS;
     303    }
     304
     305    int vrc = VINF_SUCCESS;
     306
     307    ComObjPtr<CaptureScreenSettings> captureScreenSettings;
     308    HRESULT rc = captureScreenSettings.createObject();
     309    if (SUCCEEDED(rc))
     310    {
     311        rc = captureScreenSettings->init(m->pMachine, uScreenId, data);
     312        if (SUCCEEDED(rc))
     313        {
     314            try
     315            {
     316                m->mapScreenSettings[uScreenId] = captureScreenSettings;
     317            }
     318            catch (std::bad_alloc &)
     319            {
     320                vrc = VERR_NO_MEMORY;
     321            }
     322        }
     323    }
     324
     325    return vrc;
     326}
     327
     328/**
    282329 * Loads settings from the given settings.
    283330 * May be called once right after this object creation.
     
    301348    while (itScreen != data.mapScreens.end())
    302349    {
    303         ComObjPtr<CaptureScreenSettings> captureScreenSettings;
    304         rc = captureScreenSettings.createObject();
    305         if (FAILED(rc))
     350        int vrc = i_addScreen(itScreen->first /* uScreenId */, itScreen->second /* Settings */);
     351        if (RT_FAILURE(vrc))
     352        {
     353            rc = E_OUTOFMEMORY;
    306354            break;
    307 
    308         rc = captureScreenSettings->init(m->pMachine, itScreen->first /* uScreenId */, itScreen->second /* Settings */);
    309         if (FAILED(rc))
    310             break;
    311 
    312         m->mapScreenSettings[itScreen->first] = captureScreenSettings;
     355        }
    313356
    314357        ++itScreen;
    315358    }
     359
     360    if (FAILED(rc))
     361        return rc;
    316362
    317363    ComAssertComRC(rc);
     
    378424        {
    379425            /* attach new data to the peer and reshare it */
    380             AutoWriteLock peerlock(m->pPeer COMMA_LOCKVAL_SRC_POS);
     426            AutoWriteLock peerlock(RT_SRC_POS);
     427            if (!m->fHasMachineLock)
     428                peerlock.attach(m->pPeer);
    381429            m->pPeer->m->bd.attach(m->bd);
    382430        }
  • trunk/src/VBox/Main/xml/Settings.cpp

    r75283 r75307  
    23872387     */
    23882388
    2389     fEnabled            = true;
     2389    fEnabled            = false;
    23902390    enmDest             = CaptureDestination_File;
    23912391    ulMaxTimeS          = 0;
    23922392    strOptions          = "";
    23932393    File.ulMaxSizeMB    = 0;
     2394    File.strName        = "";
    23942395    Video.enmCodec      = CaptureVideoCodec_VP8;
    23952396    Video.ulWidth       = 1024;
     
    24042405    featureMap[CaptureFeature_Video] = true;
    24052406    featureMap[CaptureFeature_Audio] = false;
    2406 
    2407     //i_calculateFullPath
    24082407}
    24092408
     
    24132412bool CaptureScreenSettings::areDefaultSettings(void) const
    24142413{
    2415     const bool fDefault =    fEnabled            == true
    2416                           && enmDest             == CaptureDestination_File
    2417                           && ulMaxTimeS          == 0
    2418                           && strOptions          == ""
    2419                           && File.ulMaxSizeMB    == 0
    2420                           && Video.enmCodec      == CaptureVideoCodec_VP8
    2421                           && Video.ulWidth       == 1024
    2422                           && Video.ulHeight      == 768
    2423                           && Video.ulRate        == 512
    2424                           && Video.ulFPS         == 25
    2425                           && Audio.enmAudioCodec == CaptureAudioCodec_Opus
    2426                           && Audio.cBits         == 16
    2427                           && Audio.cChannels     == 2
    2428                           && Audio.uHz           == 22050;
    2429 
    2430     return fDefault;
     2414    return    fEnabled            == false
     2415           && enmDest             == CaptureDestination_File
     2416           && ulMaxTimeS          == 0
     2417           && strOptions          == ""
     2418           && File.ulMaxSizeMB    == 0
     2419           && File.strName        == ""
     2420           && Video.enmCodec      == CaptureVideoCodec_VP8
     2421           && Video.ulWidth       == 1024
     2422           && Video.ulHeight      == 768
     2423           && Video.ulRate        == 512
     2424           && Video.ulFPS         == 25
     2425           && Audio.enmAudioCodec == CaptureAudioCodec_Opus
     2426           && Audio.cBits         == 16
     2427           && Audio.cChannels     == 2
     2428           && Audio.uHz           == 22050;
    24312429}
    24322430
     
    24722470}
    24732471
     2472/**
     2473 * Applies the default settings.
     2474 */
    24742475void CaptureSettings::applyDefaults(void)
    24752476{
     
    24782479    mapScreens.clear();
    24792480
    2480     CaptureScreenSettings screenSettings; /* Apply default settings. */
    2481     for (uint32_t l = 0; l < SchemaDefs::MaxGuestMonitors; l++)
    2482     {
    2483         mapScreens[l] = screenSettings;
     2481    try
     2482    {
     2483        /* Always add screen 0 to the default configuration. */
     2484        CaptureScreenSettings screenSettings; /* Apply default settings for screen 0. */
     2485        mapScreens[0] = screenSettings;
     2486    }
     2487    catch (std::bad_alloc &)
     2488    {
     2489        AssertFailed();
    24842490    }
    24852491}
     
    24902496bool CaptureSettings::areDefaultSettings() const
    24912497{
     2498    const bool fDefault =    fEnabled          == false
     2499                          && mapScreens.size() == 1;
     2500    if (!fDefault)
     2501        return false;
     2502
    24922503    CaptureScreenMap::const_iterator itScreen = mapScreens.begin();
    2493     while (itScreen != mapScreens.end())
    2494     {
    2495         if (!itScreen->second.areDefaultSettings())
    2496             return false;
    2497 
    2498         ++itScreen;
    2499     }
    2500 
    2501     return true;
     2504    return    itScreen->first == 0
     2505           && itScreen->second.areDefaultSettings();
    25022506}
    25032507
     
    44134417            /* At the moment we only support one capturing configuration, that is, all screens
    44144418             * have the same configuration. So load/save to/from screen 0. */
     4419            Assert(hw.captureSettings.mapScreens.size()); /* At least screen must be present. */
    44154420            CaptureScreenSettings &screen0Settings = hw.captureSettings.mapScreens[0];
    44164421
     
    44244429            pelmHwChild->getAttributeValue("fps",       screen0Settings.Video.ulFPS);
    44254430
    4426             for (unsigned i = 0; i < 64; i++)
     4431            for (unsigned i = 0; i < hw.cMonitors; i++) /* Don't add more settings than we have monitors configured. */
    44274432            {
    44284433                if (u64VideoCaptureScreens & RT_BIT_64(i)) /* Screen i enabled? */
     
    58395844        Assert(hw.captureSettings.mapScreens.size());
    58405845        const CaptureScreenMap::const_iterator itScreen0Settings = hw.captureSettings.mapScreens.find(0);
     5846        Assert(itScreen0Settings != hw.captureSettings.mapScreens.end());
    58415847
    58425848        if (itScreen0Settings->second.ulMaxTimeS)
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