VirtualBox

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


Ignore:
Timestamp:
Nov 5, 2018 5:55:29 PM (6 years ago)
Author:
vboxsync
Message:

Capturing: Separated capturing settings into new interfaces ICaptureSettings and ICaptureScreenSettings to unload stuff from IMachine; a lot of internal interface / code cleanups. Also see #9286. Work in progress.

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

Legend:

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

    r74804 r75251  
    55
    66/*
    7  * Copyright (C) 2004-2017 Oracle Corporation
     7 * Copyright (C) 2004-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    168168    mAccelerate2DVideoEnabled = false;
    169169    mMonitorCount = 1;
    170     mVideoCaptureWidth = 1024;
    171     mVideoCaptureHeight = 768;
    172     mVideoCaptureRate = 512;
    173     mVideoCaptureFPS = 25;
    174     mVideoCaptureMaxTime = 0;
    175     mVideoCaptureMaxFileSize = 0;
    176     mVideoCaptureEnabled = false;
    177     for (unsigned i = 0; i < RT_ELEMENTS(maVideoCaptureScreens); ++i)
    178         maVideoCaptureScreens[i] = true;
    179 
    180170    mHWVirtExEnabled = true;
    181171    mHWVirtExNestedPagingEnabled = true;
     
    365355        }
    366356
    367         /* Apply BIOS defaults */
     357        /* Apply BIOS defaults. */
    368358        mBIOSSettings->i_applyDefaults(aOsType);
     359
     360        /* Apply capture defaults. */
     361        mCaptureSettings->i_applyDefaults();
    369362
    370363        /* Apply network adapters defaults */
     
    17321725}
    17331726
    1734 HRESULT Machine::getVideoCaptureEnabled(BOOL *aVideoCaptureEnabled)
    1735 {
    1736     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    1737 
    1738     *aVideoCaptureEnabled = mHWData->mVideoCaptureEnabled;
    1739     return S_OK;
    1740 }
    1741 
    1742 HRESULT Machine::setVideoCaptureEnabled(BOOL aVideoCaptureEnabled)
    1743 {
    1744     HRESULT rc = S_OK;
    1745 
    1746     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    1747 
    1748     i_setModified(IsModified_MachineData);
    1749     mHWData.backup();
    1750     mHWData->mVideoCaptureEnabled = aVideoCaptureEnabled;
    1751 
    1752     alock.release();
    1753     rc = i_onVideoCaptureChange();
    1754     alock.acquire();
    1755     if (FAILED(rc))
    1756     {
    1757         /*
    1758          * Normally we would do the actual change _after_ i_onVideoCaptureChange() succeeded.
    1759          * We cannot do this because that function uses Machine::GetVideoCaptureEnabled to
    1760          * determine if it should start or stop capturing. Therefore we need to manually
    1761          * undo change.
    1762          */
    1763         mHWData->mVideoCaptureEnabled = mHWData.backedUpData()->mVideoCaptureEnabled;
    1764         return rc;
    1765     }
    1766 
    1767     /** Save settings if online - @todo why is this required? -- @bugref{6818} */
    1768     if (Global::IsOnline(mData->mMachineState))
    1769         i_saveSettings(NULL);
    1770 
    1771     return rc;
    1772 }
    1773 
    1774 HRESULT Machine::getVideoCaptureScreens(std::vector<BOOL> &aVideoCaptureScreens)
    1775 {
    1776     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    1777     aVideoCaptureScreens.resize(mHWData->mMonitorCount);
    1778     for (unsigned i = 0; i < mHWData->mMonitorCount; ++i)
    1779         aVideoCaptureScreens[i] = mHWData->maVideoCaptureScreens[i];
    1780     return S_OK;
    1781 }
    1782 
    1783 HRESULT Machine::setVideoCaptureScreens(const std::vector<BOOL> &aVideoCaptureScreens)
    1784 {
    1785     AssertReturn(aVideoCaptureScreens.size() <= RT_ELEMENTS(mHWData->maVideoCaptureScreens), E_INVALIDARG);
    1786     bool fChanged = false;
    1787 
    1788     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    1789 
    1790     for (unsigned i = 0; i < aVideoCaptureScreens.size(); ++i)
    1791     {
    1792         if (mHWData->maVideoCaptureScreens[i] != RT_BOOL(aVideoCaptureScreens[i]))
    1793         {
    1794             mHWData->maVideoCaptureScreens[i] = RT_BOOL(aVideoCaptureScreens[i]);
    1795             fChanged = true;
    1796         }
    1797     }
    1798     if (fChanged)
    1799     {
    1800         alock.release();
    1801         HRESULT rc = i_onVideoCaptureChange();
    1802         alock.acquire();
    1803         if (FAILED(rc)) return rc;
    1804         i_setModified(IsModified_MachineData);
    1805 
    1806         /** Save settings if online - @todo why is this required? -- @bugref{6818} */
    1807         if (Global::IsOnline(mData->mMachineState))
    1808             i_saveSettings(NULL);
    1809     }
    1810 
    1811     return S_OK;
    1812 }
    1813 
    1814 HRESULT Machine::getVideoCaptureFile(com::Utf8Str &aVideoCaptureFile)
    1815 {
    1816     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    1817     if (mHWData->mVideoCaptureFile.isEmpty())
    1818         i_getDefaultVideoCaptureFile(aVideoCaptureFile);
    1819     else
    1820         aVideoCaptureFile = mHWData->mVideoCaptureFile;
    1821     return S_OK;
    1822 }
    1823 
    1824 HRESULT Machine::setVideoCaptureFile(const com::Utf8Str &aVideoCaptureFile)
    1825 {
    1826     Utf8Str strFile(aVideoCaptureFile);
    1827     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    1828 
    1829     if (   Global::IsOnline(mData->mMachineState)
    1830         && mHWData->mVideoCaptureEnabled)
    1831         return setError(E_INVALIDARG, tr("Cannot change parameters while capturing is enabled"));
    1832 
    1833     if (!RTPathStartsWithRoot(strFile.c_str()))
    1834         return setError(E_INVALIDARG, tr("Video capture file name '%s' is not absolute"), strFile.c_str());
    1835 
    1836     if (!strFile.isEmpty())
    1837     {
    1838         Utf8Str defaultFile;
    1839         i_getDefaultVideoCaptureFile(defaultFile);
    1840         if (!RTPathCompare(strFile.c_str(), defaultFile.c_str()))
    1841             strFile.setNull();
    1842     }
    1843 
    1844     i_setModified(IsModified_MachineData);
    1845     mHWData.backup();
    1846     mHWData->mVideoCaptureFile = strFile;
    1847 
    1848     return S_OK;
    1849 }
    1850 
    1851 HRESULT Machine::getVideoCaptureWidth(ULONG *aVideoCaptureWidth)
    1852 {
    1853     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    1854     *aVideoCaptureWidth = mHWData->mVideoCaptureWidth;
    1855     return S_OK;
    1856 }
    1857 
    1858 HRESULT Machine::setVideoCaptureWidth(ULONG aVideoCaptureWidth)
    1859 {
    1860     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    1861 
    1862     if (   Global::IsOnline(mData->mMachineState)
    1863         && mHWData->mVideoCaptureEnabled)
    1864         return setError(E_INVALIDARG, tr("Cannot change parameters while capturing is enabled"));
    1865 
    1866     i_setModified(IsModified_MachineData);
    1867     mHWData.backup();
    1868     mHWData->mVideoCaptureWidth = aVideoCaptureWidth;
    1869 
    1870     return S_OK;
    1871 }
    1872 
    1873 HRESULT Machine::getVideoCaptureHeight(ULONG *aVideoCaptureHeight)
    1874 {
    1875     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    1876     *aVideoCaptureHeight = mHWData->mVideoCaptureHeight;
    1877     return S_OK;
    1878 }
    1879 
    1880 HRESULT Machine::setVideoCaptureHeight(ULONG aVideoCaptureHeight)
    1881 {
    1882     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    1883 
    1884     if (   Global::IsOnline(mData->mMachineState)
    1885         && mHWData->mVideoCaptureEnabled)
    1886         return setError(E_INVALIDARG, tr("Cannot change parameters while capturing is enabled"));
    1887 
    1888     i_setModified(IsModified_MachineData);
    1889     mHWData.backup();
    1890     mHWData->mVideoCaptureHeight = aVideoCaptureHeight;
    1891 
    1892     return S_OK;
    1893 }
    1894 
    1895 HRESULT Machine::getVideoCaptureRate(ULONG *aVideoCaptureRate)
    1896 {
    1897     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    1898     *aVideoCaptureRate = mHWData->mVideoCaptureRate;
    1899     return S_OK;
    1900 }
    1901 
    1902 HRESULT Machine::setVideoCaptureRate(ULONG aVideoCaptureRate)
    1903 {
    1904     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    1905 
    1906     if (   Global::IsOnline(mData->mMachineState)
    1907         && mHWData->mVideoCaptureEnabled)
    1908         return setError(E_INVALIDARG, tr("Cannot change parameters while capturing is enabled"));
    1909 
    1910     i_setModified(IsModified_MachineData);
    1911     mHWData.backup();
    1912     mHWData->mVideoCaptureRate = aVideoCaptureRate;
    1913 
    1914     return S_OK;
    1915 }
    1916 
    1917 HRESULT Machine::getVideoCaptureFPS(ULONG *aVideoCaptureFPS)
    1918 {
    1919     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    1920     *aVideoCaptureFPS = mHWData->mVideoCaptureFPS;
    1921     return S_OK;
    1922 }
    1923 
    1924 HRESULT Machine::setVideoCaptureFPS(ULONG aVideoCaptureFPS)
    1925 {
    1926     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    1927 
    1928     if (   Global::IsOnline(mData->mMachineState)
    1929         && mHWData->mVideoCaptureEnabled)
    1930         return setError(E_INVALIDARG, tr("Cannot change parameters while capturing is enabled"));
    1931 
    1932     i_setModified(IsModified_MachineData);
    1933     mHWData.backup();
    1934     mHWData->mVideoCaptureFPS = aVideoCaptureFPS;
    1935 
    1936     return S_OK;
    1937 }
    1938 
    1939 HRESULT Machine::getVideoCaptureMaxTime(ULONG *aVideoCaptureMaxTime)
    1940 {
    1941     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    1942     *aVideoCaptureMaxTime = mHWData->mVideoCaptureMaxTime;
    1943     return S_OK;
    1944 }
    1945 
    1946 HRESULT Machine::setVideoCaptureMaxTime(ULONG aVideoCaptureMaxTime)
    1947 {
    1948     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    1949 
    1950     if (   Global::IsOnline(mData->mMachineState)
    1951         && mHWData->mVideoCaptureEnabled)
    1952         return setError(E_INVALIDARG, tr("Cannot change parameters while capturing is enabled"));
    1953 
    1954     i_setModified(IsModified_MachineData);
    1955     mHWData.backup();
    1956     mHWData->mVideoCaptureMaxTime = aVideoCaptureMaxTime;
    1957 
    1958     return S_OK;
    1959 }
    1960 
    1961 HRESULT Machine::getVideoCaptureMaxFileSize(ULONG *aVideoCaptureMaxFileSize)
    1962 {
    1963     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    1964     *aVideoCaptureMaxFileSize = mHWData->mVideoCaptureMaxFileSize;
    1965     return S_OK;
    1966 }
    1967 
    1968 HRESULT Machine::setVideoCaptureMaxFileSize(ULONG aVideoCaptureMaxFileSize)
    1969 {
    1970     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    1971 
    1972     if (   Global::IsOnline(mData->mMachineState)
    1973         && mHWData->mVideoCaptureEnabled)
    1974         return setError(E_INVALIDARG, tr("Cannot change parameters while capturing is enabled"));
    1975 
    1976     i_setModified(IsModified_MachineData);
    1977     mHWData.backup();
    1978     mHWData->mVideoCaptureMaxFileSize = aVideoCaptureMaxFileSize;
    1979 
    1980     return S_OK;
    1981 }
    1982 
    1983 HRESULT Machine::getVideoCaptureOptions(com::Utf8Str &aVideoCaptureOptions)
    1984 {
    1985     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    1986 
    1987     aVideoCaptureOptions = mHWData->mVideoCaptureOptions;
    1988     return S_OK;
    1989 }
    1990 
    1991 HRESULT Machine::setVideoCaptureOptions(const com::Utf8Str &aVideoCaptureOptions)
    1992 {
    1993     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    1994 
    1995     if (   Global::IsOnline(mData->mMachineState)
    1996         && mHWData->mVideoCaptureEnabled)
    1997         return setError(E_INVALIDARG, tr("Cannot change parameters while capturing is enabled"));
    1998 
    1999     i_setModified(IsModified_MachineData);
    2000     mHWData.backup();
    2001     mHWData->mVideoCaptureOptions = aVideoCaptureOptions;
    2002 
    2003     return S_OK;
    2004 }
    2005 
    20061727HRESULT Machine::getGraphicsControllerType(GraphicsControllerType_T *aGraphicsControllerType)
    20071728{
     
    22151936    /* mBIOSSettings is constant during life time, no need to lock */
    22161937    aBIOSSettings = mBIOSSettings;
     1938
     1939    return S_OK;
     1940}
     1941
     1942HRESULT Machine::getCaptureSettings(ComPtr<ICaptureSettings> &aCaptureSettings)
     1943{
     1944    /* mCaptureSettings is constant during life time, no need to lock */
     1945    aCaptureSettings = mCaptureSettings;
    22171946
    22181947    return S_OK;
     
    76547383
    76557384/**
    7656  *  Returns the full path to the default video capture file.
    7657  */
    7658 void Machine::i_getDefaultVideoCaptureFile(Utf8Str &strFile)
    7659 {
    7660     AutoCaller autoCaller(this);
    7661     AssertComRCReturnVoid(autoCaller.rc());
    7662 
    7663     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    7664 
    7665     strFile = mData->m_strConfigFileFull;       // path/to/machinesfolder/vmname/vmname.vbox
    7666     strFile.stripSuffix();                      // path/to/machinesfolder/vmname/vmname
    7667     strFile.append(".webm");                    // path/to/machinesfolder/vmname/vmname.webm
    7668 }
    7669 
    7670 /**
    76717385 * Returns whether at least one USB controller is present for the VM.
    76727386 */
     
    85458259    mBIOSSettings->init(this);
    85468260
     8261    /* create associated capture settings object */
     8262    unconst(mCaptureSettings).createObject();
     8263    mCaptureSettings->init(this);
     8264
    85478265    /* create an associated VRDE object (default is disabled) */
    85488266    unconst(mVRDEServer).createObject();
     
    86588376        mBIOSSettings->uninit();
    86598377        unconst(mBIOSSettings).setNull();
     8378    }
     8379
     8380    if (mCaptureSettings)
     8381    {
     8382        mCaptureSettings->uninit();
     8383        unconst(mCaptureSettings).setNull();
    86608384    }
    86618385
     
    91578881        mHWData->mAccelerate3DEnabled = data.fAccelerate3D;
    91588882        mHWData->mAccelerate2DVideoEnabled = data.fAccelerate2DVideo;
    9159         mHWData->mVideoCaptureWidth = data.ulVideoCaptureHorzRes;
    9160         mHWData->mVideoCaptureHeight = data.ulVideoCaptureVertRes;
    9161         mHWData->mVideoCaptureEnabled = data.fVideoCaptureEnabled;
    9162         for (unsigned i = 0; i < RT_ELEMENTS(mHWData->maVideoCaptureScreens); ++i)
    9163             mHWData->maVideoCaptureScreens[i] = ASMBitTest(&data.u64VideoCaptureScreens, i);
    9164         AssertCompile(RT_ELEMENTS(mHWData->maVideoCaptureScreens) == sizeof(data.u64VideoCaptureScreens) * 8);
    9165         mHWData->mVideoCaptureRate = data.ulVideoCaptureRate;
    9166         mHWData->mVideoCaptureFPS = data.ulVideoCaptureFPS;
    9167         if (!data.strVideoCaptureFile.isEmpty())
    9168             i_calculateFullPath(data.strVideoCaptureFile, mHWData->mVideoCaptureFile);
    9169         else
    9170             mHWData->mVideoCaptureFile.setNull();
    9171         mHWData->mVideoCaptureOptions = data.strVideoCaptureOptions;
    91728883        mHWData->mFirmwareType = data.firmwareType;
    91738884        mHWData->mPointingHIDType = data.pointingHIDType;
     
    91878898        if (FAILED(rc)) return rc;
    91888899
     8900        /* Capture settings */
     8901        rc = mCaptureSettings->i_loadSettings(data.captureSettings);
     8902        if (FAILED(rc)) return rc;
     8903
    91898904        // Bandwidth control (must come before network adapters)
    91908905        rc = mBandwidthControl->i_loadSettings(data.ioSettings);
    91918906        if (FAILED(rc)) return rc;
    91928907
    9193         /* Shared folders */
     8908        /* USB controllers */
    91948909        for (settings::USBControllerList::const_iterator
    91958910             it = data.usbSettings.llUSBControllers.begin();
     
    1049310208        data.fAccelerate3D = !!mHWData->mAccelerate3DEnabled;
    1049410209        data.fAccelerate2DVideo = !!mHWData->mAccelerate2DVideoEnabled;
    10495         data.ulVideoCaptureHorzRes = mHWData->mVideoCaptureWidth;
    10496         data.ulVideoCaptureVertRes = mHWData->mVideoCaptureHeight;
    10497         data.ulVideoCaptureRate = mHWData->mVideoCaptureRate;
    10498         data.ulVideoCaptureFPS = mHWData->mVideoCaptureFPS;
    10499         data.fVideoCaptureEnabled  = !!mHWData->mVideoCaptureEnabled;
    10500         for (unsigned i = 0; i < sizeof(data.u64VideoCaptureScreens) * 8; ++i)
    10501         {
    10502             if (mHWData->maVideoCaptureScreens[i])
    10503                 ASMBitSet(&data.u64VideoCaptureScreens, i);
    10504             else
    10505                 ASMBitClear(&data.u64VideoCaptureScreens, i);
    10506         }
    10507         /* store relative video capture file if possible */
    10508         i_copyPathRelativeToMachine(mHWData->mVideoCaptureFile, data.strVideoCaptureFile);
    10509         data.strVideoCaptureOptions = mHWData->mVideoCaptureOptions;
    1051010210
    1051110211        /* VRDEServer settings (optional) */
     
    1051310213        if (FAILED(rc)) throw rc;
    1051410214
    10515         /* BIOS (required) */
     10215        /* BIOS settings (required) */
    1051610216        rc = mBIOSSettings->i_saveSettings(data.biosSettings);
     10217        if (FAILED(rc)) throw rc;
     10218
     10219        /* Capture settings (required) */
     10220        rc = mCaptureSettings->i_saveSettings(data.captureSettings);
    1051710221        if (FAILED(rc)) throw rc;
    1051810222
     
    1201911723        mBIOSSettings->i_rollback();
    1202011724
     11725    if (mCaptureSettings && (mData->flModifications & IsModified_Capture))
     11726        mCaptureSettings->i_rollback();
     11727
    1202111728    if (mVRDEServer && (mData->flModifications & IsModified_VRDEServer))
    1202211729        mVRDEServer->i_rollback();
     
    1212911836
    1213011837    mBIOSSettings->i_commit();
     11838    mCaptureSettings->i_commit();
    1213111839    mVRDEServer->i_commit();
    1213211840    mAudioAdapter->i_commit();
     
    1238112089
    1238212090    mBIOSSettings->i_copyFrom(aThat->mBIOSSettings);
     12091    mCaptureSettings->i_copyFrom(aThat->mCaptureSettings);
    1238312092    mVRDEServer->i_copyFrom(aThat->mVRDEServer);
    1238412093    mAudioAdapter->i_copyFrom(aThat->mAudioAdapter);
     
    1275412463    unconst(mBIOSSettings).createObject();
    1275512464    mBIOSSettings->init(this, aMachine->mBIOSSettings);
     12465    unconst(mCaptureSettings).createObject();
     12466    mCaptureSettings->init(this, aMachine->mCaptureSettings);
    1275612467    /* create another VRDEServer object that will be mutable */
    1275712468    unconst(mVRDEServer).createObject();
     
    1438714098 * @note Locks this object for reading.
    1438814099 */
    14389 HRESULT SessionMachine::i_onVideoCaptureChange()
     14100HRESULT SessionMachine::i_onCaptureChange()
    1439014101{
    1439114102    LogFlowThisFunc(("\n"));
     
    1440514116        return S_OK;
    1440614117
    14407     return directControl->OnVideoCaptureChange();
     14118    return directControl->OnCaptureChange();
    1440814119}
    1440914120
     
    1533915050    mBIOSSettings->i_applyDefaults(osType);
    1534015051
     15052    /* Initialize default capture settings. */
     15053    mCaptureSettings->i_applyDefaults();
     15054
    1534115055    /* Initialize default BIOS settings here */
    1534215056    mHWData->mAPIC = osType->i_recommendedIOAPIC();
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