VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/CaptureScreenSettingsImpl.cpp@ 75267

Last change on this file since 75267 was 75264, checked in by vboxsync, 6 years ago

Capturing: SCM fixes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.4 KB
Line 
1/* $Id: CaptureScreenSettingsImpl.cpp 75264 2018-11-05 22:54:41Z vboxsync $ */
2/** @file
3 *
4 * VirtualBox COM class implementation - Capture settings of one virtual screen.
5 */
6
7/*
8 * Copyright (C) 2018 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#include "CaptureScreenSettingsImpl.h"
20#include "MachineImpl.h"
21
22#include <iprt/path.h>
23#include <iprt/cpp/utils.h>
24#include <VBox/settings.h>
25
26#include "AutoStateDep.h"
27#include "AutoCaller.h"
28#include "Global.h"
29#include "Logging.h"
30
31////////////////////////////////////////////////////////////////////////////////
32//
33// CaptureScreenSettings private data definition
34//
35////////////////////////////////////////////////////////////////////////////////
36
37struct CaptureScreenSettings::Data
38{
39 Data()
40 : pMachine(NULL)
41 { }
42
43 Machine * const pMachine;
44 ComObjPtr<CaptureScreenSettings> pPeer;
45 unsigned long uScreenId;
46
47 // use the XML settings structure in the members for simplicity
48 Backupable<settings::CaptureScreenSettings> bd;
49};
50
51// constructor / destructor
52/////////////////////////////////////////////////////////////////////////////
53
54DEFINE_EMPTY_CTOR_DTOR(CaptureScreenSettings)
55
56HRESULT CaptureScreenSettings::FinalConstruct()
57{
58 return BaseFinalConstruct();
59}
60
61void CaptureScreenSettings::FinalRelease()
62{
63 uninit();
64 BaseFinalRelease();
65}
66
67// public initializer/uninitializer for internal purposes only
68/////////////////////////////////////////////////////////////////////////////
69
70/**
71 * Initializes the audio adapter object.
72 *
73 * @returns COM result indicator
74 */
75HRESULT CaptureScreenSettings::init(Machine *aParent, unsigned long uScreenId, const settings::CaptureScreenSettings& data)
76{
77 LogFlowThisFuncEnter();
78 LogFlowThisFunc(("aParent: %p\n", aParent));
79
80 ComAssertRet(aParent, E_INVALIDARG);
81
82 /* Enclose the state transition NotReady->InInit->Ready */
83 AutoInitSpan autoInitSpan(this);
84 AssertReturn(autoInitSpan.isOk(), E_FAIL);
85
86 m = new Data();
87
88 /* share the parent weakly */
89 unconst(m->pMachine) = aParent;
90
91 // simply copy
92 m->uScreenId = uScreenId;
93 m->bd.assignCopy(&data);
94
95 autoInitSpan.setSucceeded();
96
97 LogFlowThisFuncLeave();
98 return S_OK;
99}
100
101/**
102 * Initializes the capture settings object given another capture settings object
103 * (a kind of copy constructor). This object shares data with
104 * the object passed as an argument.
105 *
106 * @note This object must be destroyed before the original object
107 * it shares data with is destroyed.
108 */
109HRESULT CaptureScreenSettings::init(Machine *aParent, CaptureScreenSettings *that)
110{
111 LogFlowThisFuncEnter();
112 LogFlowThisFunc(("aParent: %p, that: %p\n", aParent, that));
113
114 ComAssertRet(aParent && that, E_INVALIDARG);
115
116 /* Enclose the state transition NotReady->InInit->Ready */
117 AutoInitSpan autoInitSpan(this);
118 AssertReturn(autoInitSpan.isOk(), E_FAIL);
119
120 m = new Data();
121
122 unconst(m->pMachine) = aParent;
123 m->pPeer = that;
124
125 AutoWriteLock thatlock(that COMMA_LOCKVAL_SRC_POS);
126
127 m->uScreenId = that->m->uScreenId;
128 m->bd.share(that->m->bd);
129
130 autoInitSpan.setSucceeded();
131
132 LogFlowThisFuncLeave();
133 return S_OK;
134}
135
136/**
137 * Initializes the guest object given another guest object
138 * (a kind of copy constructor). This object makes a private copy of data
139 * of the original object passed as an argument.
140 */
141HRESULT CaptureScreenSettings::initCopy(Machine *aParent, CaptureScreenSettings *that)
142{
143 LogFlowThisFuncEnter();
144 LogFlowThisFunc(("aParent: %p, that: %p\n", aParent, that));
145
146 ComAssertRet(aParent && that, E_INVALIDARG);
147
148 /* Enclose the state transition NotReady->InInit->Ready */
149 AutoInitSpan autoInitSpan(this);
150 AssertReturn(autoInitSpan.isOk(), E_FAIL);
151
152 m = new Data();
153
154 unconst(m->pMachine) = aParent;
155 // mPeer is left null
156
157 AutoWriteLock thatlock(that COMMA_LOCKVAL_SRC_POS);
158
159 m->uScreenId = that->m->uScreenId;
160 m->bd.attachCopy(that->m->bd);
161
162 autoInitSpan.setSucceeded();
163
164 LogFlowThisFuncLeave();
165 return S_OK;
166}
167
168/**
169 * Uninitializes the instance and sets the ready flag to FALSE.
170 * Called either from FinalRelease() or by the parent when it gets destroyed.
171 */
172void CaptureScreenSettings::uninit()
173{
174 LogFlowThisFuncEnter();
175
176 /* Enclose the state transition Ready->InUninit->NotReady */
177 AutoUninitSpan autoUninitSpan(this);
178 if (autoUninitSpan.uninitDone())
179 return;
180
181 m->bd.free();
182
183 unconst(m->pPeer) = NULL;
184 unconst(m->pMachine) = NULL;
185
186 delete m;
187 m = NULL;
188
189 LogFlowThisFuncLeave();
190}
191
192HRESULT CaptureScreenSettings::isFeatureEnabled(CaptureFeature_T aFeature, BOOL *aEnabled)
193{
194 settings::CaptureFeatureMap::const_iterator itFeature = m->bd->featureMap.find(aFeature);
195
196 *aEnabled = ( itFeature != m->bd->featureMap.end()
197 && itFeature->second == true);
198
199 return S_OK;
200}
201
202HRESULT CaptureScreenSettings::getEnabled(BOOL *enabled)
203{
204 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
205
206 *enabled = m->bd->fEnabled ? TRUE : FALSE;
207
208 return S_OK;
209}
210
211HRESULT CaptureScreenSettings::setEnabled(BOOL enabled)
212{
213 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
214
215 if (m->bd->fEnabled != RT_BOOL(enabled))
216 {
217 alock.release();
218
219 HRESULT rc = m->pMachine->i_onCaptureChange();
220 if (FAILED(rc)) return rc;
221
222 m->pMachine->i_setModified(Machine::IsModified_Capture);
223
224 alock.acquire();
225 m->bd->fEnabled = RT_BOOL(enabled);
226 alock.release();
227
228 /** Save settings if online - @todo why is this required? -- @bugref{6818} */
229 AutoAnyStateDependency adep(m->pMachine);
230 AssertComRCReturn(adep.rc(), E_UNEXPECTED);
231
232 if (Global::IsOnline(adep.machineState()))
233 m->pMachine->i_saveSettings(NULL);
234 }
235
236 return S_OK;
237}
238
239HRESULT CaptureScreenSettings::getFeatures(ULONG *aFeatures)
240{
241 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
242
243 *aFeatures = 0;
244
245 settings::CaptureFeatureMap::const_iterator itFeature = m->bd->featureMap.begin();
246 while (itFeature != m->bd->featureMap.end())
247 {
248 if (itFeature->second) /* Is feature enable? */
249 *aFeatures |= (ULONG)itFeature->first;
250
251 ++itFeature;
252 }
253
254 return S_OK;
255}
256
257HRESULT CaptureScreenSettings::setFeatures(ULONG aFeatures)
258{
259 if (!i_canChangeSettings())
260 return setError(E_INVALIDARG, tr("Cannot change features while capturing is enabled"));
261
262 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
263
264 m->pMachine->i_setModified(Machine::IsModified_Capture);
265 m->bd.backup();
266
267 m->bd->featureMap.clear();
268
269 if (aFeatures & CaptureFeature_Audio)
270 m->bd->featureMap[CaptureFeature_Audio] = true;
271 if (aFeatures & CaptureFeature_Video)
272 m->bd->featureMap[CaptureFeature_Video] = true;
273
274 return S_OK;
275}
276
277HRESULT CaptureScreenSettings::getDestination(CaptureDestination_T *aDestination)
278{
279 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
280
281 *aDestination = m->bd->enmDest;
282
283 return S_OK;
284}
285
286HRESULT CaptureScreenSettings::setDestination(CaptureDestination_T aDestination)
287{
288 if (!i_canChangeSettings())
289 return setError(E_INVALIDARG, tr("Cannot change destination type while capturing is enabled"));
290
291 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
292
293 m->pMachine->i_setModified(Machine::IsModified_Capture);
294 m->bd.backup();
295 m->bd->enmDest = aDestination;
296
297 return S_OK;
298}
299
300HRESULT CaptureScreenSettings::getFileName(com::Utf8Str &aFileName)
301{
302 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
303
304 if (m->bd->File.strName.isEmpty())
305 i_getDefaultCaptureFile(aFileName);
306 else
307 aFileName = m->bd->File.strName;
308
309 return S_OK;
310}
311
312HRESULT CaptureScreenSettings::setFileName(const com::Utf8Str &aFileName)
313{
314 if (!i_canChangeSettings())
315 return setError(E_INVALIDARG, tr("Cannot change file name while capturing is enabled"));
316
317 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
318
319 Utf8Str strFile(aFileName);
320
321 if (!RTPathStartsWithRoot(strFile.c_str()))
322 return setError(E_INVALIDARG, tr("Capture file name '%s' is not absolute"), strFile.c_str());
323
324 if (!strFile.isEmpty())
325 {
326 Utf8Str defaultFile;
327 i_getDefaultCaptureFile(defaultFile);
328 if (!RTPathCompare(strFile.c_str(), defaultFile.c_str()))
329 strFile.setNull();
330 }
331
332 m->pMachine->i_setModified(Machine::IsModified_Capture);
333 m->bd.backup();
334 m->bd->File.strName = strFile;
335
336 return S_OK;
337}
338
339HRESULT CaptureScreenSettings::getMaxTime(ULONG *aMaxTimeS)
340{
341 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
342
343 *aMaxTimeS = m->bd->ulMaxTimeS;
344
345 return S_OK;
346}
347
348HRESULT CaptureScreenSettings::setMaxTime(ULONG aMaxTimeS)
349{
350 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
351
352 if (!i_canChangeSettings())
353 return setError(E_INVALIDARG, tr("Cannot change maximum time while capturing is enabled"));
354
355 m->pMachine->i_setModified(Machine::IsModified_Capture);
356 m->bd.backup();
357
358 m->bd->ulMaxTimeS = aMaxTimeS;
359
360 return S_OK;
361}
362
363HRESULT CaptureScreenSettings::getMaxFileSize(ULONG *aMaxFileSizeMB)
364{
365 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
366
367 *aMaxFileSizeMB = m->bd->File.ulMaxSizeMB;
368
369 return S_OK;
370}
371
372HRESULT CaptureScreenSettings::setMaxFileSize(ULONG aMaxFileSize)
373{
374 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
375
376 if (!i_canChangeSettings())
377 return setError(E_INVALIDARG, tr("Cannot change maximum file size while capturing is enabled"));
378
379 m->pMachine->i_setModified(Machine::IsModified_Capture);
380 m->bd.backup();
381
382 m->bd->File.ulMaxSizeMB = aMaxFileSize;
383
384 return S_OK;
385}
386
387HRESULT CaptureScreenSettings::getOptions(com::Utf8Str &aOptions)
388{
389 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
390
391 aOptions = m->bd->strOptions;
392
393 return S_OK;
394}
395
396HRESULT CaptureScreenSettings::setOptions(const com::Utf8Str &aOptions)
397{
398 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
399
400 if (!i_canChangeSettings())
401 return setError(E_INVALIDARG, tr("Cannot change options string while capturing is enabled"));
402
403 m->pMachine->i_setModified(Machine::IsModified_Capture);
404 m->bd.backup();
405
406 m->bd->strOptions = aOptions;
407
408 return S_OK;
409}
410
411HRESULT CaptureScreenSettings::getVideoWidth(ULONG *aVideoWidth)
412{
413 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
414
415 *aVideoWidth = m->bd->Video.ulWidth;
416
417 return S_OK;
418}
419
420HRESULT CaptureScreenSettings::setVideoWidth(ULONG aVideoWidth)
421{
422 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
423
424 if (!i_canChangeSettings())
425 return setError(E_INVALIDARG, tr("Cannot change video width while capturing is enabled"));
426
427 m->pMachine->i_setModified(Machine::IsModified_Capture);
428 m->bd.backup();
429
430 m->bd->Video.ulWidth = aVideoWidth;
431
432 return S_OK;
433}
434
435HRESULT CaptureScreenSettings::getVideoHeight(ULONG *aVideoHeight)
436{
437 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
438
439 *aVideoHeight = m->bd->Video.ulHeight;
440
441 return S_OK;
442}
443
444HRESULT CaptureScreenSettings::setVideoHeight(ULONG aVideoHeight)
445{
446 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
447
448 if (!i_canChangeSettings())
449 return setError(E_INVALIDARG, tr("Cannot change video height while capturing is enabled"));
450
451 m->pMachine->i_setModified(Machine::IsModified_Capture);
452 m->bd.backup();
453
454 m->bd->Video.ulHeight = aVideoHeight;
455
456 return S_OK;
457}
458
459HRESULT CaptureScreenSettings::getVideoRate(ULONG *aVideoRate)
460{
461 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
462
463 *aVideoRate = m->bd->Video.ulRate;
464
465 return S_OK;
466}
467
468HRESULT CaptureScreenSettings::setVideoRate(ULONG aVideoRate)
469{
470 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
471
472 if (!i_canChangeSettings())
473 return setError(E_INVALIDARG, tr("Cannot change video rate while capturing is enabled"));
474
475 m->pMachine->i_setModified(Machine::IsModified_Capture);
476 m->bd.backup();
477
478 m->bd->Video.ulRate = aVideoRate;
479
480 return S_OK;
481}
482
483HRESULT CaptureScreenSettings::getVideoFPS(ULONG *aVideoFPS)
484{
485 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
486
487 *aVideoFPS = m->bd->Video.ulFPS;
488
489 return S_OK;
490}
491
492HRESULT CaptureScreenSettings::setVideoFPS(ULONG aVideoFPS)
493{
494 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
495
496 if (!i_canChangeSettings())
497 return setError(E_INVALIDARG, tr("Cannot change parameters while capturing is enabled"));
498
499 m->pMachine->i_setModified(Machine::IsModified_Capture);
500 m->bd.backup();
501
502 m->bd->Video.ulFPS = aVideoFPS;
503
504 return S_OK;
505}
506
507bool CaptureScreenSettings::i_canChangeSettings(void)
508{
509 AutoAnyStateDependency adep(m->pMachine);
510 AssertComRCReturn(adep.rc(), false);
511
512 if ( Global::IsOnline(adep.machineState())
513 && m->bd->fEnabled)
514 return false;
515
516 return true;
517}
518
519/**
520 * Returns the full path to the default video capture file.
521 */
522int CaptureScreenSettings::i_getDefaultCaptureFile(Utf8Str &strFile)
523{
524 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
525
526 strFile = m->pMachine->i_getSettingsFileFull(); // path/to/machinesfolder/vmname/vmname.vbox
527 strFile.stripSuffix(); // path/to/machinesfolder/vmname/vmname
528 strFile.append(".webm"); // path/to/machinesfolder/vmname/vmname.webm
529
530 return VINF_SUCCESS;
531}
532
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette