VirtualBox

Changeset 75324 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Nov 8, 2018 3:39:50 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
126445
Message:

Recording: More settings bugfixes for Main and FE/Qt.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/CaptureScreenSettingsImpl.cpp

    r75313 r75324  
    1717 */
    1818
     19#define LOG_GROUP LOG_GROUP_MAIN_CAPTURESCREENSETTINGS
     20#include "LoggingNew.h"
     21
    1922#include "CaptureScreenSettingsImpl.h"
     23#include "CaptureSettingsImpl.h"
    2024#include "MachineImpl.h"
    2125
     
    2731#include "AutoCaller.h"
    2832#include "Global.h"
    29 #include "Logging.h"
    3033
    3134////////////////////////////////////////////////////////////////////////////////
     
    3841{
    3942    Data()
    40         : pMachine(NULL)
     43        : pParent(NULL)
    4144    { }
    4245
    43     Machine * const                  pMachine;
     46    CaptureSettings * const          pParent;
    4447    ComObjPtr<CaptureScreenSettings> pPeer;
    4548    uint32_t                         uScreenId;
     
    7376 * @returns COM result indicator
    7477 */
    75 HRESULT CaptureScreenSettings::init(Machine *aParent, uint32_t uScreenId, const settings::CaptureScreenSettings& data)
     78HRESULT CaptureScreenSettings::init(CaptureSettings *aParent, uint32_t uScreenId, const settings::CaptureScreenSettings& data)
    7679{
    7780    LogFlowThisFuncEnter();
     
    8689    m = new Data();
    8790
    88     /* Share the parent weakly. */
    89     unconst(m->pMachine) = aParent;
     91    /* Share the parent & machine weakly. */
     92    unconst(m->pParent) = aParent;
    9093    /* mPeer is left null. */
    9194
     
    120123 *  it shares data with is destroyed.
    121124 */
    122 HRESULT CaptureScreenSettings::init(Machine *aParent, CaptureScreenSettings *that)
     125HRESULT CaptureScreenSettings::init(CaptureSettings *aParent, CaptureScreenSettings *that)
    123126{
    124127    LogFlowThisFuncEnter();
     
    133136    m = new Data();
    134137
    135     unconst(m->pMachine) = aParent;
     138    unconst(m->pParent) = aParent;
    136139    m->pPeer = that;
    137140
     
    163166 *  of the original object passed as an argument.
    164167 */
    165 HRESULT CaptureScreenSettings::initCopy(Machine *aParent, CaptureScreenSettings *that)
     168HRESULT CaptureScreenSettings::initCopy(CaptureSettings *aParent, CaptureScreenSettings *that)
    166169{
    167170    LogFlowThisFuncEnter();
     
    176179    m = new Data();
    177180
    178     unconst(m->pMachine) = aParent;
     181    unconst(m->pParent) = aParent;
    179182    /* mPeer is left null. */
    180183
     
    217220
    218221    unconst(m->pPeer) = NULL;
    219     unconst(m->pMachine) = NULL;
     222    unconst(m->pParent) = NULL;
    220223
    221224    delete m;
     
    227230HRESULT CaptureScreenSettings::isFeatureEnabled(CaptureFeature_T aFeature, BOOL *aEnabled)
    228231{
     232    AutoCaller autoCaller(this);
     233    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     234
     235    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     236
    229237    settings::CaptureFeatureMap::const_iterator itFeature = m->bd->featureMap.find(aFeature);
    230238
     
    237245HRESULT CaptureScreenSettings::getEnabled(BOOL *enabled)
    238246{
     247    AutoCaller autoCaller(this);
     248    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     249
    239250    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    240251
     
    246257HRESULT CaptureScreenSettings::setEnabled(BOOL enabled)
    247258{
     259    AutoCaller autoCaller(this);
     260    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     261
     262    LogFlowThisFunc(("Screen %RU32\n", m->uScreenId));
     263
     264    if (!m->pParent->i_canChangeSettings())
     265        return setError(E_INVALIDARG, tr("Cannot change enabled state of screen while capturing is enabled"));
     266
    248267    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    249268
     
    254273        alock.release();
    255274
    256         AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
    257         m->pMachine->i_setModified(Machine::IsModified_Capture);
    258         mlock.release();
    259 
    260         HRESULT rc = m->pMachine->i_onCaptureChange();
    261         if (FAILED(rc)) return rc;
    262 
    263         /** Save settings if online - @todo why is this required? -- @bugref{6818} */
    264         AutoAnyStateDependency adep(m->pMachine);
    265         AssertComRCReturn(adep.rc(), E_UNEXPECTED);
    266 
    267         if (Global::IsOnline(adep.machineState()))
    268             m->pMachine->i_saveSettings(NULL);
     275        m->pParent->i_onSettingsChanged();
    269276    }
    270277
     278    LogFlowThisFunc(("Screen %RU32\n", m->uScreenId));
    271279    return S_OK;
    272280}
     
    274282HRESULT CaptureScreenSettings::getFeatures(ULONG *aFeatures)
    275283{
     284    AutoCaller autoCaller(this);
     285    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     286
    276287    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    277288
     
    292303HRESULT CaptureScreenSettings::setFeatures(ULONG aFeatures)
    293304{
    294     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    295 
    296     if (m->bd->fEnabled)
     305    AutoCaller autoCaller(this);
     306    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     307
     308    if (!m->pParent->i_canChangeSettings())
    297309        return setError(E_INVALIDARG, tr("Cannot change features while capturing is enabled"));
     310
     311    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    298312
    299313    m->bd.backup();
     
    307321    alock.release();
    308322
    309     AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
    310     m->pMachine->i_setModified(Machine::IsModified_Capture);
    311     mlock.release();
    312 
    313323    return S_OK;
    314324}
     
    316326HRESULT CaptureScreenSettings::getDestination(CaptureDestination_T *aDestination)
    317327{
     328    AutoCaller autoCaller(this);
     329    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     330
    318331    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    319332
     
    325338HRESULT CaptureScreenSettings::setDestination(CaptureDestination_T aDestination)
    326339{
    327     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    328 
    329     if (m->bd->fEnabled)
     340    AutoCaller autoCaller(this);
     341    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     342
     343    if (!m->pParent->i_canChangeSettings())
    330344        return setError(E_INVALIDARG, tr("Cannot change destination type while capturing is enabled"));
    331345
     346    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     347
    332348    m->bd.backup();
    333349    m->bd->enmDest = aDestination;
    334350
    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 
    341351    return S_OK;
    342352}
     
    344354HRESULT CaptureScreenSettings::getFileName(com::Utf8Str &aFileName)
    345355{
     356    AutoCaller autoCaller(this);
     357    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     358
    346359    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    347360
     
    353366HRESULT CaptureScreenSettings::setFileName(const com::Utf8Str &aFileName)
    354367{
    355     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    356 
    357     if (m->bd->fEnabled)
     368    AutoCaller autoCaller(this);
     369    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     370
     371    if (!m->pParent->i_canChangeSettings())
    358372        return setError(E_INVALIDARG, tr("Cannot change file name while capturing is enabled"));
     373
     374    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    359375
    360376    Utf8Str strFile(aFileName);
     
    366382    m->bd->File.strName = strFile;
    367383
    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 
    374384    return S_OK;
    375385}
     
    377387HRESULT CaptureScreenSettings::getMaxTime(ULONG *aMaxTimeS)
    378388{
     389    AutoCaller autoCaller(this);
     390    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     391
    379392    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    380393
     
    386399HRESULT CaptureScreenSettings::setMaxTime(ULONG aMaxTimeS)
    387400{
    388     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    389 
    390     if (m->bd->fEnabled)
     401    AutoCaller autoCaller(this);
     402    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     403
     404    if (!m->pParent->i_canChangeSettings())
    391405        return setError(E_INVALIDARG, tr("Cannot change maximum time while capturing is enabled"));
    392406
     407    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     408
    393409    m->bd.backup();
    394410    m->bd->ulMaxTimeS = aMaxTimeS;
    395411
    396     AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
    397     m->pMachine->i_setModified(Machine::IsModified_Capture);
    398     mlock.release();
    399 
    400412    return S_OK;
    401413}
     
    403415HRESULT CaptureScreenSettings::getMaxFileSize(ULONG *aMaxFileSizeMB)
    404416{
     417    AutoCaller autoCaller(this);
     418    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     419
    405420    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    406421
     
    412427HRESULT CaptureScreenSettings::setMaxFileSize(ULONG aMaxFileSize)
    413428{
    414     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    415 
    416     if (m->bd->fEnabled)
     429    AutoCaller autoCaller(this);
     430    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     431
     432    if (!m->pParent->i_canChangeSettings())
    417433        return setError(E_INVALIDARG, tr("Cannot change maximum file size while capturing is enabled"));
    418434
     435    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     436
    419437    m->bd.backup();
    420438    m->bd->File.ulMaxSizeMB = aMaxFileSize;
    421439
    422     AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
    423     m->pMachine->i_setModified(Machine::IsModified_Capture);
    424     mlock.release();
    425 
    426440    return S_OK;
    427441}
     
    429443HRESULT CaptureScreenSettings::getOptions(com::Utf8Str &aOptions)
    430444{
     445    AutoCaller autoCaller(this);
     446    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     447
    431448    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    432449
     
    438455HRESULT CaptureScreenSettings::setOptions(const com::Utf8Str &aOptions)
    439456{
    440     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    441 
    442     if (m->bd->fEnabled)
     457    AutoCaller autoCaller(this);
     458    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     459
     460    if (!m->pParent->i_canChangeSettings())
    443461        return setError(E_INVALIDARG, tr("Cannot change options while capturing is enabled"));
    444462
     463    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     464
    445465    m->bd.backup();
    446466    m->bd->strOptions = aOptions;
    447467
    448     alock.release();
    449     AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
    450     m->pMachine->i_setModified(Machine::IsModified_Capture);
    451 
    452468    return S_OK;
    453469}
     
    455471HRESULT CaptureScreenSettings::getAudioCodec(CaptureAudioCodec_T *aCodec)
    456472{
     473    AutoCaller autoCaller(this);
     474    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     475
    457476    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    458477
     
    464483HRESULT CaptureScreenSettings::setAudioCodec(CaptureAudioCodec_T aCodec)
    465484{
    466     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    467 
    468     if (m->bd->fEnabled)
     485    AutoCaller autoCaller(this);
     486    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     487
     488    if (!m->pParent->i_canChangeSettings())
    469489        return setError(E_INVALIDARG, tr("Cannot change audio codec while capturing is enabled"));
    470490
     491    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     492
    471493    m->bd.backup();
    472494    m->bd->Audio.enmAudioCodec = aCodec;
    473495
    474     AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
    475     m->pMachine->i_setModified(Machine::IsModified_Capture);
    476     mlock.release();
    477 
    478496    return S_OK;
    479497}
     
    481499HRESULT CaptureScreenSettings::getAudioHz(ULONG *aHz)
    482500{
     501    AutoCaller autoCaller(this);
     502    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     503
    483504    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    484505
     
    490511HRESULT CaptureScreenSettings::setAudioHz(ULONG aHz)
    491512{
    492     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    493 
    494     if (m->bd->fEnabled)
     513    AutoCaller autoCaller(this);
     514    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     515
     516    if (!m->pParent->i_canChangeSettings())
    495517        return setError(E_INVALIDARG, tr("Cannot change audio Hertz rate while capturing is enabled"));
    496518
     519    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     520
    497521    m->bd.backup();
    498522    m->bd->Audio.uHz = (uint16_t)aHz;
    499523
    500     AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
    501     m->pMachine->i_setModified(Machine::IsModified_Capture);
    502     mlock.release();
    503 
    504524    return S_OK;
    505525}
     
    507527HRESULT CaptureScreenSettings::getAudioBits(ULONG *aBits)
    508528{
     529    AutoCaller autoCaller(this);
     530    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     531
    509532    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    510533
     
    516539HRESULT CaptureScreenSettings::setAudioBits(ULONG aBits)
    517540{
    518     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    519 
    520     if (m->bd->fEnabled)
     541    AutoCaller autoCaller(this);
     542    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     543
     544    if (!m->pParent->i_canChangeSettings())
    521545        return setError(E_INVALIDARG, tr("Cannot change audio bits while capturing is enabled"));
    522546
     547    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     548
    523549    m->bd.backup();
    524550    m->bd->Audio.cBits = (uint8_t)aBits;
    525551
    526     AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
    527     m->pMachine->i_setModified(Machine::IsModified_Capture);
    528     mlock.release();
    529 
    530552    return S_OK;
    531553}
     
    533555HRESULT CaptureScreenSettings::getAudioChannels(ULONG *aChannels)
    534556{
     557    AutoCaller autoCaller(this);
     558    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     559
    535560    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    536561
     
    542567HRESULT CaptureScreenSettings::setAudioChannels(ULONG aChannels)
    543568{
    544     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    545 
    546     if (m->bd->fEnabled)
     569    AutoCaller autoCaller(this);
     570    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     571
     572    if (!m->pParent->i_canChangeSettings())
    547573        return setError(E_INVALIDARG, tr("Cannot change audio channels while capturing is enabled"));
    548574
     575    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     576
    549577    m->bd.backup();
    550578    m->bd->Audio.cChannels = (uint8_t)aChannels;
    551579
    552     AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
    553     m->pMachine->i_setModified(Machine::IsModified_Capture);
    554     mlock.release();
    555 
    556580    return S_OK;
    557581}
     
    559583HRESULT CaptureScreenSettings::getVideoCodec(CaptureVideoCodec_T *aCodec)
    560584{
     585    AutoCaller autoCaller(this);
     586    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     587
    561588    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    562589
     
    568595HRESULT CaptureScreenSettings::setVideoCodec(CaptureVideoCodec_T aCodec)
    569596{
    570     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    571 
    572     if (m->bd->fEnabled)
     597    AutoCaller autoCaller(this);
     598    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     599
     600    if (!m->pParent->i_canChangeSettings())
    573601        return setError(E_INVALIDARG, tr("Cannot change video codec while capturing is enabled"));
    574602
     603    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     604
    575605    m->bd.backup();
    576606    m->bd->Video.enmCodec = aCodec;
    577607
    578     AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
    579     m->pMachine->i_setModified(Machine::IsModified_Capture);
    580     mlock.release();
    581 
    582608    return S_OK;
    583609}
     
    585611HRESULT CaptureScreenSettings::getVideoWidth(ULONG *aVideoWidth)
    586612{
     613    AutoCaller autoCaller(this);
     614    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     615
    587616    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    588617
     
    594623HRESULT CaptureScreenSettings::setVideoWidth(ULONG aVideoWidth)
    595624{
    596     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    597 
    598     if (m->bd->fEnabled)
     625    AutoCaller autoCaller(this);
     626    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     627
     628    if (!m->pParent->i_canChangeSettings())
    599629        return setError(E_INVALIDARG, tr("Cannot change video width while capturing is enabled"));
    600630
     631    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     632
    601633    m->bd.backup();
    602634    m->bd->Video.ulWidth = aVideoWidth;
    603635
    604     AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
    605     m->pMachine->i_setModified(Machine::IsModified_Capture);
    606     mlock.release();
    607 
    608636    return S_OK;
    609637}
     
    611639HRESULT CaptureScreenSettings::getVideoHeight(ULONG *aVideoHeight)
    612640{
     641    AutoCaller autoCaller(this);
     642    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     643
    613644    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    614645
     
    620651HRESULT CaptureScreenSettings::setVideoHeight(ULONG aVideoHeight)
    621652{
    622     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    623 
    624     if (m->bd->fEnabled)
     653    AutoCaller autoCaller(this);
     654    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     655
     656    if (!m->pParent->i_canChangeSettings())
    625657        return setError(E_INVALIDARG, tr("Cannot change video height while capturing is enabled"));
    626658
     659    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     660
    627661    m->bd.backup();
    628662    m->bd->Video.ulHeight = aVideoHeight;
    629663
    630     AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
    631     m->pMachine->i_setModified(Machine::IsModified_Capture);
    632     mlock.release();
    633 
    634664    return S_OK;
    635665}
     
    637667HRESULT CaptureScreenSettings::getVideoRate(ULONG *aVideoRate)
    638668{
     669    AutoCaller autoCaller(this);
     670    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     671
    639672    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    640673
     
    646679HRESULT CaptureScreenSettings::setVideoRate(ULONG aVideoRate)
    647680{
    648     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    649 
    650     if (m->bd->fEnabled)
     681    AutoCaller autoCaller(this);
     682    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     683
     684    if (!m->pParent->i_canChangeSettings())
    651685        return setError(E_INVALIDARG, tr("Cannot change video rate while capturing is enabled"));
    652686
     687    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     688
    653689    m->bd.backup();
    654690    m->bd->Video.ulRate = aVideoRate;
    655691
    656     AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
    657     m->pMachine->i_setModified(Machine::IsModified_Capture);
    658     mlock.release();
    659 
    660692    return S_OK;
    661693}
     
    663695HRESULT CaptureScreenSettings::getVideoRateControlMode(CaptureVideoRateControlMode_T *aMode)
    664696{
     697    AutoCaller autoCaller(this);
     698    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     699
    665700    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    666701
     
    672707HRESULT CaptureScreenSettings::setVideoRateControlMode(CaptureVideoRateControlMode_T aMode)
    673708{
    674     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    675 
    676     if (m->bd->fEnabled)
     709    AutoCaller autoCaller(this);
     710    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     711
     712    if (!m->pParent->i_canChangeSettings())
    677713        return setError(E_INVALIDARG, tr("Cannot change video rate control mode while capturing is enabled"));
     714
     715    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    678716
    679717    /** @todo Implement this. */
     
    685723HRESULT CaptureScreenSettings::getVideoFPS(ULONG *aVideoFPS)
    686724{
     725    AutoCaller autoCaller(this);
     726    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     727
    687728    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    688729
     
    694735HRESULT CaptureScreenSettings::setVideoFPS(ULONG aVideoFPS)
    695736{
    696     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    697 
    698     if (m->bd->fEnabled)
     737    AutoCaller autoCaller(this);
     738    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     739
     740    if (!m->pParent->i_canChangeSettings())
    699741        return setError(E_INVALIDARG, tr("Cannot change video FPS while capturing is enabled"));
    700742
     743    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     744
    701745    m->bd.backup();
    702746    m->bd->Video.ulFPS = aVideoFPS;
    703747
    704     AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
    705     m->pMachine->i_setModified(Machine::IsModified_Capture);
    706     mlock.release();
    707 
    708748    return S_OK;
    709749}
     
    711751HRESULT CaptureScreenSettings::getVideoScalingMethod(CaptureVideoScalingMethod_T *aMode)
    712752{
     753    AutoCaller autoCaller(this);
     754    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     755
    713756    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    714757
     
    720763HRESULT CaptureScreenSettings::setVideoScalingMethod(CaptureVideoScalingMethod_T aMode)
    721764{
    722     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    723 
    724     if (m->bd->fEnabled)
     765    AutoCaller autoCaller(this);
     766    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     767
     768    if (!m->pParent->i_canChangeSettings())
    725769        return setError(E_INVALIDARG, tr("Cannot change video rate scaling method while capturing is enabled"));
     770
     771    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    726772
    727773    /** @todo Implement this. */
     
    729775
    730776    return E_NOTIMPL;
    731 }
    732 
    733 /**
    734  * Returns the full path to the default video capture file.
    735  */
    736 int CaptureScreenSettings::i_getDefaultFileName(Utf8Str &strFile)
    737 {
    738     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    739 
    740     strFile = m->pMachine->i_getSettingsFileFull(); // path/to/machinesfolder/vmname/vmname.vbox
    741     strFile.stripSuffix();                          // path/to/machinesfolder/vmname/vmname
    742     strFile.append(".webm");                        // path/to/machinesfolder/vmname/vmname.webm
    743 
    744     return VINF_SUCCESS;
    745777}
    746778
     
    753785{
    754786    Assert(m);
    755     return i_getDefaultFileName(m->bd->File.strName);
    756 }
    757 
     787
     788    int rc = VINF_SUCCESS;
     789
     790    switch (m->bd->enmDest)
     791    {
     792        case CaptureDestination_File:
     793        {
     794            if (m->bd->File.strName.isEmpty())
     795                rc = m->pParent->i_getDefaultFileName(m->bd->File.strName);
     796            break;
     797        }
     798
     799        default:
     800            break;
     801    }
     802
     803    return rc;
     804}
     805
  • trunk/src/VBox/Main/src-server/CaptureSettingsImpl.cpp

    r75308 r75324  
    1717 */
    1818
     19#define LOG_GROUP LOG_GROUP_MAIN_CAPTURESETTINGS
     20#include "LoggingNew.h"
     21
    1922#include "CaptureSettingsImpl.h"
    2023#include "CaptureScreenSettingsImpl.h"
     
    2730#include "AutoCaller.h"
    2831#include "Global.h"
    29 #include "Logging.h"
    3032
    3133////////////////////////////////////////////////////////////////////////////////
     
    4345    Machine * const             pMachine;
    4446    ComObjPtr<CaptureSettings>  pPeer;
    45     CaptureScreenSettingsMap    mapScreenSettings;
     47    CaptureScreenSettingsMap    mapScreenObj;
    4648    bool                        fHasMachineLock;
    4749
     
    120122
    121123    m->bd.share(that->m->bd);
    122     m->mapScreenSettings = that->m->mapScreenSettings;
     124    m->mapScreenObj = that->m->mapScreenObj;
    123125    m->fHasMachineLock = false;
    124126
     
    153155
    154156    m->bd.attachCopy(that->m->bd);
    155     m->mapScreenSettings = that->m->mapScreenSettings;
     157    m->mapScreenObj = that->m->mapScreenObj;
    156158    m->fHasMachineLock = false;
    157159
     
    175177        return;
    176178
     179    /* Note: Do *not* call i_reset() here, as the shared recording configuration
     180     *       otherwise gets destructed when this object goes out of scope or is destroyed. */
     181
    177182    m->bd.free();
    178183
     
    200205HRESULT CaptureSettings::setEnabled(BOOL enable)
    201206{
     207    LogFlowThisFuncEnter();
     208
    202209    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    203210
     
    223230            alock.acquire();
    224231            m->bd->fEnabled = m->bd.backedUpData()->fEnabled;
    225             return rc;
    226232        }
    227233        else
     
    247253HRESULT CaptureSettings::getScreens(std::vector<ComPtr<ICaptureScreenSettings> > &aCaptureScreenSettings)
    248254{
     255    LogFlowThisFuncEnter();
     256
     257    i_syncToMachineDisplays();
     258
    249259    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    250260
    251261    aCaptureScreenSettings.clear();
    252     aCaptureScreenSettings.resize(m->mapScreenSettings.size());
    253 
    254     CaptureScreenSettingsMap::const_iterator itScreenSettings = m->mapScreenSettings.begin();
     262    aCaptureScreenSettings.resize(m->mapScreenObj.size());
     263
     264    CaptureScreenSettingsMap::const_iterator itScreenSettings = m->mapScreenObj.begin();
    255265    size_t i = 0;
    256     while (itScreenSettings != m->mapScreenSettings.end())
     266    while (itScreenSettings != m->mapScreenObj.end())
    257267    {
    258268        itScreenSettings->second.queryInterfaceTo(aCaptureScreenSettings[i].asOutParam());
     
    262272    }
    263273
    264     Assert(aCaptureScreenSettings.size() == m->mapScreenSettings.size());
     274    Assert(aCaptureScreenSettings.size() == m->mapScreenObj.size());
    265275
    266276    return S_OK;
     
    269279HRESULT CaptureSettings::getScreenSettings(ULONG uScreenId, ComPtr<ICaptureScreenSettings> &aCaptureScreenSettings)
    270280{
    271     if (uScreenId + 1 > m->mapScreenSettings.size())
     281    LogFlowThisFuncEnter();
     282
     283    i_syncToMachineDisplays();
     284
     285    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     286
     287    if (uScreenId + 1 > m->mapScreenObj.size())
    272288        return setError(E_INVALIDARG, tr("Invalid screen ID specified"));
    273289
    274     CaptureScreenSettingsMap::const_iterator itScreenSettings = m->mapScreenSettings.find(uScreenId);
    275     if (itScreenSettings != m->mapScreenSettings.end())
     290    CaptureScreenSettingsMap::const_iterator itScreenSettings = m->mapScreenObj.find(uScreenId);
     291    if (itScreenSettings != m->mapScreenObj.end())
    276292    {
    277293        itScreenSettings->second.queryInterfaceTo(aCaptureScreenSettings.asOutParam());
     
    289305
    290306/**
    291  * Adds a screen settings object to the recording settings.
     307 * Adds a screen settings object to a particular map.
    292308 *
    293309 * @returns IPRT status code. VERR_ALREADY_EXISTS if the object in question already exists.
     310 * @param   screenSettingsMap   Map to add screen settings to.
    294311 * @param   uScreenId           Screen ID to add settings for.
    295312 * @param   data                Recording screen settings to use for that screen.
    296313 */
    297 int CaptureSettings::i_addScreen(uint32_t uScreenId, const settings::CaptureScreenSettings &data)
    298 {
    299     if (m->mapScreenSettings.find(uScreenId) != m->mapScreenSettings.end())
     314int CaptureSettings::i_createScreenObj(CaptureScreenSettingsMap &screenSettingsMap,
     315                                       uint32_t uScreenId, const settings::CaptureScreenSettings &data)
     316{
     317    LogFlowThisFunc(("Screen %RU32\n", uScreenId));
     318
     319    if (screenSettingsMap.find(uScreenId) != screenSettingsMap.end())
    300320    {
    301321        AssertFailed();
     
    309329    if (SUCCEEDED(rc))
    310330    {
    311         rc = captureScreenSettings->init(m->pMachine, uScreenId, data);
     331        rc = captureScreenSettings->init(this, uScreenId, data);
    312332        if (SUCCEEDED(rc))
    313333        {
    314334            try
    315335            {
    316                 m->mapScreenSettings[uScreenId] = captureScreenSettings;
     336                screenSettingsMap[uScreenId] = captureScreenSettings;
    317337            }
    318338            catch (std::bad_alloc &)
     
    327347
    328348/**
     349 * Removes a screen settings object from a particular map.
     350 *
     351 * @returns IPRT status code. VERR_NOT_FOUND if specified screen was not found.
     352 * @param   screenSettingsMap   Map to remove screen settings from.
     353 * @param   uScreenId           ID of screen to remove.
     354 */
     355int CaptureSettings::i_destroyScreenObj(CaptureScreenSettingsMap &screenSettingsMap, uint32_t uScreenId)
     356{
     357    LogFlowThisFunc(("Screen %RU32\n", uScreenId));
     358
     359    AssertReturn(uScreenId > 0, VERR_INVALID_PARAMETER); /* Removing screen 0 isn't a good idea. */
     360
     361    CaptureScreenSettingsMap::iterator itScreen = screenSettingsMap.find(uScreenId);
     362    if (itScreen == screenSettingsMap.end())
     363    {
     364        AssertFailed();
     365        return VERR_NOT_FOUND;
     366    }
     367
     368    /* Make sure to consume the pointer before the one of the
     369     * iterator gets released. */
     370    ComObjPtr<CaptureScreenSettings> pScreenSettings = itScreen->second;
     371
     372    screenSettingsMap.erase(itScreen);
     373
     374    pScreenSettings.setNull();
     375
     376    return VINF_SUCCESS;
     377}
     378
     379/**
     380 * Destroys all screen settings objects of a particular map.
     381 *
     382 * @returns IPRT status code.
     383 * @param   screenSettingsMap   Map to destroy screen settings objects for.
     384 */
     385int CaptureSettings::i_destroyAllScreenObj(CaptureScreenSettingsMap &screenSettingsMap)
     386{
     387    LogFlowThisFuncEnter();
     388
     389    CaptureScreenSettingsMap::const_iterator itScreen = screenSettingsMap.begin();
     390    if (itScreen != screenSettingsMap.end())
     391    {
     392        /* Make sure to consume the pointer before the one of the
     393         * iterator gets released. */
     394        ComObjPtr<CaptureScreenSettings> pScreenSettings = itScreen->second;
     395
     396        screenSettingsMap.erase(itScreen);
     397
     398        pScreenSettings.setNull();
     399
     400        itScreen = screenSettingsMap.begin();
     401    }
     402
     403    return VINF_SUCCESS;
     404}
     405
     406/**
    329407 * Loads settings from the given settings.
    330408 * May be called once right after this object creation.
     
    336414HRESULT CaptureSettings::i_loadSettings(const settings::CaptureSettings &data)
    337415{
     416    LogFlowThisFuncEnter();
     417
    338418    AutoCaller autoCaller(this);
    339419    AssertComRCReturnRC(autoCaller.rc());
     
    343423    HRESULT rc = S_OK;
    344424
    345     m->mapScreenSettings.clear();
     425    i_reset();
     426
     427    LogFlowThisFunc(("Data has %zu screens\n", data.mapScreens.size()));
    346428
    347429    settings::CaptureScreenMap::const_iterator itScreen = data.mapScreens.begin();
    348430    while (itScreen != data.mapScreens.end())
    349431    {
    350         int vrc = i_addScreen(itScreen->first /* uScreenId */, itScreen->second /* Settings */);
     432        int vrc = i_createScreenObj(m->mapScreenObj,
     433                                    itScreen->first /* uScreenId */, itScreen->second /* Settings */);
    351434        if (RT_FAILURE(vrc))
    352435        {
     
    362445
    363446    ComAssertComRC(rc);
    364     Assert(m->mapScreenSettings.size() == data.mapScreens.size());
     447    Assert(m->mapScreenObj.size() == data.mapScreens.size());
    365448
    366449    // simply copy
    367450    m->bd.assignCopy(&data);
    368451
     452    LogFlowThisFunc(("Returning %Rhrc\n", rc));
    369453    return rc;
    370454}
    371455
    372456/**
     457 * Resets the internal object state by destroying all screen settings objects.
     458 */
     459void CaptureSettings::i_reset(void)
     460{
     461    LogFlowThisFuncEnter();
     462
     463    i_destroyAllScreenObj(m->mapScreenObj);
     464    m->bd->mapScreens.clear();
     465}
     466
     467/**
    373468 * Saves settings to the given settings.
    374469 *
     
    379474HRESULT CaptureSettings::i_saveSettings(settings::CaptureSettings &data)
    380475{
     476    LogFlowThisFuncEnter();
     477
    381478    AutoCaller autoCaller(this);
    382479    AssertComRCReturnRC(autoCaller.rc());
     480
     481    int rc2 = i_syncToMachineDisplays();
     482    AssertRC(rc2);
    383483
    384484    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    395495    }
    396496
     497    LogFlowThisFuncLeave();
    397498    return S_OK;
    398499}
     
    462563}
    463564
     565/**
     566 * Returns the full path to the default video capture file.
     567 */
     568int CaptureSettings::i_getDefaultFileName(Utf8Str &strFile)
     569{
     570    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     571
     572    strFile = m->pMachine->i_getSettingsFileFull(); // path/to/machinesfolder/vmname/vmname.vbox
     573    strFile.stripSuffix();                          // path/to/machinesfolder/vmname/vmname
     574    strFile.append(".webm");                        // path/to/machinesfolder/vmname/vmname.webm
     575
     576    return VINF_SUCCESS;
     577}
     578
     579/**
     580 * Determines whether the recording settings currently can be changed or not.
     581 *
     582 * @returns \c true if the settings can be changed, \c false if not.
     583 */
     584bool CaptureSettings::i_canChangeSettings(void)
     585{
     586    AutoAnyStateDependency adep(m->pMachine);
     587    if (FAILED(adep.rc()))
     588        return false;
     589
     590    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     591
     592    /* Only allow settings to be changed when recording is disabled. */
     593    return m->bd->fEnabled == false;
     594}
     595
     596/**
     597 * Gets called when the machine object needs to know that the recording settings
     598 * have been changed.
     599 */
     600void CaptureSettings::i_onSettingsChanged(void)
     601{
     602    LogFlowThisFuncEnter();
     603
     604    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     605    m->pMachine->i_setModified(Machine::IsModified_Capture);
     606    mlock.release();
     607
     608    LogFlowThisFuncLeave();
     609}
     610
     611/**
     612 * Synchronizes the screen settings (COM) objects and configuration data
     613 * to the number of the machine's configured displays.
     614 */
     615int CaptureSettings::i_syncToMachineDisplays(void)
     616{
     617    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     618
     619    AssertPtr(m->pMachine);
     620    const ULONG cMonitors = m->pMachine->i_getMonitorCount();
     621
     622    LogFlowThisFunc(("cMonitors=%RU32\n", cMonitors));
     623    LogFlowThisFunc(("Data screen count = %zu, COM object count = %zu\n", m->bd->mapScreens.size(), m->mapScreenObj.size()));
     624
     625    /* If counts match, take a shortcut. */
     626    if (cMonitors == m->mapScreenObj.size())
     627        return VINF_SUCCESS;
     628
     629    /* Create all new screen settings objects which are not there yet. */
     630    for (ULONG i = 0; i < cMonitors; i++)
     631    {
     632        if (m->mapScreenObj.find(i) == m->mapScreenObj.end())
     633        {
     634            settings::CaptureScreenMap::const_iterator itScreen = m->bd->mapScreens.find(i);
     635            if (itScreen == m->bd->mapScreens.end())
     636            {
     637                settings::CaptureScreenSettings defaultScreenSettings; /* Apply default settings. */
     638                m->bd->mapScreens[i] = defaultScreenSettings;
     639            }
     640
     641            int vrc2 = i_createScreenObj(m->mapScreenObj, i /* Screen ID */, m->bd->mapScreens[i]);
     642            AssertRC(vrc2);
     643        }
     644    }
     645
     646    /* Remove all left over screen settings objects which are not needed anymore. */
     647    const ULONG cSettings = (ULONG)m->mapScreenObj.size();
     648    for (ULONG i = cMonitors; i < cSettings; i++)
     649    {
     650        m->bd->mapScreens.erase(i);
     651        int vrc2 = i_destroyScreenObj(m->mapScreenObj, i /* Screen ID */);
     652        AssertRC(vrc2);
     653    }
     654
     655    Assert(m->mapScreenObj.size() == cMonitors);
     656    Assert(m->bd->mapScreens.size() == cMonitors);
     657
     658    LogFlowThisFuncLeave();
     659    return VINF_SUCCESS;
     660}
     661
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