VirtualBox

Changeset 75251 in vbox for trunk/src/VBox/Main/xml


Ignore:
Timestamp:
Nov 5, 2018 5:55:29 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
126353
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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/xml/Settings.cpp

    r74474 r75251  
    23712371}
    23722372
     2373CaptureScreenSettings::CaptureScreenSettings(void)
     2374{
     2375    applyDefaults();
     2376}
     2377
     2378CaptureScreenSettings::~CaptureScreenSettings()
     2379{
     2380
     2381}
     2382
     2383void CaptureScreenSettings::applyDefaults(void)
     2384{
     2385    /*
     2386     * Set sensible defaults.
     2387     */
     2388
     2389    fEnabled            = true;
     2390    enmDest             = CaptureDestination_File;
     2391    ulMaxTimeS          = 0;
     2392    strOptions          = "";
     2393    File.ulMaxSizeMB    = 0;
     2394    Video.enmCodec      = CaptureVideoCodec_VP8;
     2395    Video.ulWidth       = 1024;
     2396    Video.ulHeight      = 768;
     2397    Video.ulRate        = 512;
     2398    Video.ulFPS         = 25;
     2399    Audio.enmAudioCodec = CaptureAudioCodec_Opus;
     2400    Audio.cBits         = 16;
     2401    Audio.cChannels     = 2;
     2402    Audio.uHz           = 22050;
     2403
     2404    featureMap[CaptureFeature_Video] = true;
     2405    featureMap[CaptureFeature_Audio] = false;
     2406
     2407    //i_calculateFullPath
     2408}
     2409
     2410/**
     2411 * Check if all settings have default values.
     2412 */
     2413bool CaptureScreenSettings::areDefaultSettings(void) const
     2414{
     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;
     2431}
     2432
     2433bool CaptureScreenSettings::isFeatureEnabled(CaptureFeature_T enmFeature) const
     2434{
     2435    CaptureFeatureMap::const_iterator itFeature = featureMap.find(enmFeature);
     2436    if (itFeature != featureMap.end())
     2437        return itFeature->second;
     2438
     2439    return false;
     2440}
     2441
     2442/**
     2443 * Comparison operator. This gets called from MachineConfigFile::operator==,
     2444 * which in turn gets called from Machine::saveSettings to figure out whether
     2445 * machine settings have really changed and thus need to be written out to disk.
     2446 */
     2447bool CaptureScreenSettings::operator==(const CaptureScreenSettings &d) const
     2448{
     2449    return    fEnabled            == d.fEnabled
     2450           && enmDest             == d.enmDest
     2451           && featureMap          == d.featureMap
     2452           && ulMaxTimeS          == d.ulMaxTimeS
     2453           && strOptions          == d.strOptions
     2454           && File.ulMaxSizeMB    == d.File.ulMaxSizeMB
     2455           && Video.enmCodec      == d.Video.enmCodec
     2456           && Video.ulWidth       == d.Video.ulWidth
     2457           && Video.ulHeight      == d.Video.ulHeight
     2458           && Video.ulRate        == d.Video.ulRate
     2459           && Video.ulFPS         == d.Video.ulFPS
     2460           && Audio.enmAudioCodec == d.Audio.enmAudioCodec
     2461           && Audio.cBits         == d.Audio.cBits
     2462           && Audio.cChannels     == d.Audio.cChannels
     2463           && Audio.uHz           == d.Audio.uHz;
     2464}
     2465
     2466/**
     2467 * Constructor. Needs to set sane defaults which stand the test of time.
     2468 */
     2469CaptureSettings::CaptureSettings()
     2470{
     2471    applyDefaults();
     2472}
     2473
     2474void CaptureSettings::applyDefaults(void)
     2475{
     2476    fEnabled = false;
     2477
     2478    mapScreens.clear();
     2479
     2480    CaptureScreenSettings screenSettings; /* Apply default settings. */
     2481    for (unsigned long l = 0; l < SchemaDefs::MaxGuestMonitors; l++)
     2482    {
     2483        mapScreens[l] = screenSettings;
     2484    }
     2485}
     2486
     2487/**
     2488 * Check if all settings have default values.
     2489 */
     2490bool CaptureSettings::areDefaultSettings() const
     2491{
     2492    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;
     2502}
     2503
     2504/**
     2505 * Comparison operator. This gets called from MachineConfigFile::operator==,
     2506 * which in turn gets called from Machine::saveSettings to figure out whether
     2507 * machine settings have really changed and thus need to be written out to disk.
     2508 */
     2509bool CaptureSettings::operator==(const CaptureSettings &d) const
     2510{
     2511    if (this == &d)
     2512        return true;
     2513
     2514    if (   fEnabled          != d.fEnabled
     2515        || mapScreens.size() != d.mapScreens.size())
     2516        return false;
     2517
     2518    CaptureScreenMap::const_iterator itScreen = mapScreens.begin();
     2519    size_t i = 0;
     2520    while (itScreen != mapScreens.end())
     2521    {
     2522        CaptureScreenMap::const_iterator itScreenThat = d.mapScreens.find(i);
     2523        if (itScreen->second == itScreenThat->second)
     2524        {
     2525            /* Nothing to do in here (yet). */
     2526        }
     2527        else
     2528            return false;
     2529
     2530        ++itScreen;
     2531        ++i;
     2532    }
     2533
     2534    return true;
     2535}
     2536
    23732537/**
    23742538 * Constructor. Needs to set sane defaults which stand the test of time.
     
    29013065    fAccelerate3D(false),
    29023066    fAccelerate2DVideo(false),
    2903     ulVideoCaptureHorzRes(1024),
    2904     ulVideoCaptureVertRes(768),
    2905     ulVideoCaptureRate(512),
    2906     ulVideoCaptureFPS(25),
    2907     ulVideoCaptureMaxTime(0),
    2908     ulVideoCaptureMaxSize(0),
    2909     fVideoCaptureEnabled(false),
    2910     u64VideoCaptureScreens(UINT64_C(0xffffffffffffffff)),
    2911     strVideoCaptureFile(""),
    29123067    firmwareType(FirmwareType_BIOS),
    29133068    pointingHIDType(PointingHIDType_PS2Mouse),
     
    29863141        && !fAccelerate3D
    29873142        && !fAccelerate2DVideo;
    2988 }
    2989 
    2990 /**
    2991  * Check if all Video Capture settings have default values.
    2992  */
    2993 bool Hardware::areVideoCaptureDefaultSettings() const
    2994 {
    2995     return    !fVideoCaptureEnabled
    2996            && u64VideoCaptureScreens == UINT64_C(0xffffffffffffffff)
    2997            && strVideoCaptureFile.isEmpty()
    2998            && ulVideoCaptureHorzRes == 1024
    2999            && ulVideoCaptureVertRes == 768
    3000            && ulVideoCaptureRate == 512
    3001            && ulVideoCaptureFPS == 25
    3002            && ulVideoCaptureMaxTime == 0
    3003            && ulVideoCaptureMaxSize == 0
    3004            && strVideoCaptureOptions.isEmpty();
    30053143}
    30063144
     
    30623200            && fAccelerate3D             == h.fAccelerate3D
    30633201            && fAccelerate2DVideo        == h.fAccelerate2DVideo
    3064             && fVideoCaptureEnabled      == h.fVideoCaptureEnabled
    3065             && u64VideoCaptureScreens    == h.u64VideoCaptureScreens
    3066             && strVideoCaptureFile       == h.strVideoCaptureFile
    3067             && ulVideoCaptureHorzRes     == h.ulVideoCaptureHorzRes
    3068             && ulVideoCaptureVertRes     == h.ulVideoCaptureVertRes
    3069             && ulVideoCaptureRate        == h.ulVideoCaptureRate
    3070             && ulVideoCaptureFPS         == h.ulVideoCaptureFPS
    3071             && ulVideoCaptureMaxTime     == h.ulVideoCaptureMaxTime
    3072             && ulVideoCaptureMaxSize     == h.ulVideoCaptureMaxTime
    3073             && strVideoCaptureOptions    == h.strVideoCaptureOptions
    30743202            && firmwareType              == h.firmwareType
    30753203            && pointingHIDType           == h.pointingHIDType
     
    42764404        else if (pelmHwChild->nameEquals("VideoCapture"))
    42774405        {
    4278             pelmHwChild->getAttributeValue("enabled",   hw.fVideoCaptureEnabled);
    4279             pelmHwChild->getAttributeValue("screens",   hw.u64VideoCaptureScreens);
    4280             pelmHwChild->getAttributeValuePath("file",  hw.strVideoCaptureFile);
    4281             pelmHwChild->getAttributeValue("horzRes",   hw.ulVideoCaptureHorzRes);
    4282             pelmHwChild->getAttributeValue("vertRes",   hw.ulVideoCaptureVertRes);
    4283             pelmHwChild->getAttributeValue("rate",      hw.ulVideoCaptureRate);
    4284             pelmHwChild->getAttributeValue("fps",       hw.ulVideoCaptureFPS);
    4285             pelmHwChild->getAttributeValue("maxTime",   hw.ulVideoCaptureMaxTime);
    4286             pelmHwChild->getAttributeValue("maxSize",   hw.ulVideoCaptureMaxSize);
    4287             pelmHwChild->getAttributeValue("options",   hw.strVideoCaptureOptions);
     4406            pelmHwChild->getAttributeValue("enabled",   hw.captureSettings.fEnabled);
     4407
     4408            /* Right now I don't want to bump the settings version, so just convert the enabled
     4409             * screens to the former uint6t_t bit array and vice versa. */
     4410            uint64_t u64VideoCaptureScreens;
     4411            pelmHwChild->getAttributeValue("screens",   u64VideoCaptureScreens);
     4412
     4413            /* At the moment we only support one capturing configuration, that is, all screens
     4414             * have the same configuration. So load/save to/from screen 0. */
     4415            CaptureScreenSettings &screen0Settings = hw.captureSettings.mapScreens[0];
     4416
     4417            pelmHwChild->getAttributeValue("maxTime",   screen0Settings.ulMaxTimeS);
     4418            pelmHwChild->getAttributeValue("options",   screen0Settings.strOptions);
     4419            pelmHwChild->getAttributeValuePath("file",  screen0Settings.File.strName);
     4420            pelmHwChild->getAttributeValue("maxSize",   screen0Settings.File.ulMaxSizeMB);
     4421            pelmHwChild->getAttributeValue("horzRes",   screen0Settings.Video.ulWidth);
     4422            pelmHwChild->getAttributeValue("vertRes",   screen0Settings.Video.ulHeight);
     4423            pelmHwChild->getAttributeValue("rate",      screen0Settings.Video.ulRate);
     4424            pelmHwChild->getAttributeValue("fps",       screen0Settings.Video.ulFPS);
     4425
     4426            for (unsigned i = 0; i < 64; i++)
     4427            {
     4428                if (u64VideoCaptureScreens & RT_BIT(i)) /* Screen i enabled? */
     4429                {
     4430                    hw.captureSettings.mapScreens[i] = screen0Settings;
     4431                    hw.captureSettings.mapScreens[i].fEnabled = true;
     4432                }
     4433            }
    42884434        }
    42894435        else if (pelmHwChild->nameEquals("RemoteDisplay"))
     
    56685814    }
    56695815
    5670     if (m->sv >= SettingsVersion_v1_14 && !hw.areVideoCaptureDefaultSettings())
     5816    if (m->sv >= SettingsVersion_v1_14 && !hw.captureSettings.areDefaultSettings())
    56715817    {
    56725818        xml::ElementNode *pelmVideoCapture = pelmHardware->createChild("VideoCapture");
    5673         if (hw.fVideoCaptureEnabled)
    5674             pelmVideoCapture->setAttribute("enabled",      hw.fVideoCaptureEnabled);
    5675         if (hw.u64VideoCaptureScreens != UINT64_C(0xffffffffffffffff))
    5676             pelmVideoCapture->setAttribute("screens",      hw.u64VideoCaptureScreens);
    5677         if (!hw.strVideoCaptureFile.isEmpty())
    5678             pelmVideoCapture->setAttributePath("file",     hw.strVideoCaptureFile);
    5679         if (hw.ulVideoCaptureHorzRes != 1024 || hw.ulVideoCaptureVertRes != 768)
    5680         {
    5681             pelmVideoCapture->setAttribute("horzRes",      hw.ulVideoCaptureHorzRes);
    5682             pelmVideoCapture->setAttribute("vertRes",      hw.ulVideoCaptureVertRes);
    5683         }
    5684         if (hw.ulVideoCaptureRate != 512)
    5685             pelmVideoCapture->setAttribute("rate",         hw.ulVideoCaptureRate);
    5686         if (hw.ulVideoCaptureFPS)
    5687             pelmVideoCapture->setAttribute("fps",          hw.ulVideoCaptureFPS);
    5688         if (hw.ulVideoCaptureMaxTime)
    5689             pelmVideoCapture->setAttribute("maxTime",      hw.ulVideoCaptureMaxTime);
    5690         if (hw.ulVideoCaptureMaxSize)
    5691             pelmVideoCapture->setAttribute("maxSize",      hw.ulVideoCaptureMaxSize);
    5692         if (!hw.strVideoCaptureOptions.isEmpty())
    5693             pelmVideoCapture->setAttributePath("options",  hw.strVideoCaptureOptions);
     5819
     5820        if (hw.captureSettings.fEnabled)
     5821            pelmVideoCapture->setAttribute("enabled", hw.captureSettings.fEnabled);
     5822
     5823        /* Right now I don't want to bump the settings version, so just convert the enabled
     5824         * screens to the former uint6t_t bit array and vice versa. */
     5825        uint64_t u64VideoCaptureScreens = 0;
     5826        CaptureScreenMap::const_iterator itScreen = hw.captureSettings.mapScreens.begin();
     5827        while (itScreen != hw.captureSettings.mapScreens.end())
     5828        {
     5829            if (itScreen->second.fEnabled)
     5830               u64VideoCaptureScreens |= RT_BIT(itScreen->first);
     5831            ++itScreen;
     5832        }
     5833
     5834        if (u64VideoCaptureScreens)
     5835            pelmVideoCapture->setAttribute("screens",      u64VideoCaptureScreens);
     5836
     5837        /* At the moment we only support one capturing configuration, that is, all screens
     5838         * have the same configuration. So load/save to/from screen 0. */
     5839        Assert(hw.captureSettings.mapScreens.size());
     5840        const CaptureScreenMap::const_iterator itScreen0Settings = hw.captureSettings.mapScreens.find(0);
     5841
     5842        if (itScreen0Settings->second.ulMaxTimeS)
     5843            pelmVideoCapture->setAttribute("maxTime",      itScreen0Settings->second.ulMaxTimeS);
     5844        if (itScreen0Settings->second.strOptions.isNotEmpty())
     5845            pelmVideoCapture->setAttributePath("options",  itScreen0Settings->second.strOptions);
     5846
     5847        if (!itScreen0Settings->second.File.strName.isEmpty())
     5848            pelmVideoCapture->setAttributePath("file",     itScreen0Settings->second.File.strName);
     5849        if (itScreen0Settings->second.File.ulMaxSizeMB)
     5850            pelmVideoCapture->setAttribute("maxSize",      itScreen0Settings->second.File.ulMaxSizeMB);
     5851
     5852        if (   itScreen0Settings->second.Video.ulWidth  != 1024
     5853            || itScreen0Settings->second.Video.ulHeight != 768)
     5854        {
     5855            pelmVideoCapture->setAttribute("horzRes",      itScreen0Settings->second.Video.ulWidth);
     5856            pelmVideoCapture->setAttribute("vertRes",      itScreen0Settings->second.Video.ulHeight);
     5857        }
     5858        if (itScreen0Settings->second.Video.ulRate != 512)
     5859            pelmVideoCapture->setAttribute("rate",         itScreen0Settings->second.Video.ulRate);
     5860        if (itScreen0Settings->second.Video.ulFPS)
     5861            pelmVideoCapture->setAttribute("fps",          itScreen0Settings->second.Video.ulFPS);
    56945862    }
    56955863
     
    72627430    {
    72637431        // VirtualBox 4.3 adds default frontend setting, graphics controller
    7264         // setting, explicit long mode setting, video capturing and NAT networking.
     7432        // setting, explicit long mode setting, (video) capturing and NAT networking.
    72657433        if (   !hardwareMachine.strDefaultFrontend.isEmpty()
    72667434            || hardwareMachine.graphicsControllerType != GraphicsControllerType_VBoxVGA
    72677435            || hardwareMachine.enmLongMode != Hardware::LongMode_Legacy
    72687436            || machineUserData.ovIcon.size() > 0
    7269             || hardwareMachine.fVideoCaptureEnabled)
     7437            || hardwareMachine.captureSettings.fEnabled)
    72707438        {
    72717439            m->sv = SettingsVersion_v1_14;
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