1 | /* $Id: CaptureScreenSettingsImpl.cpp 75307 2018-11-07 13:56:14Z 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 |
|
---|
37 | struct CaptureScreenSettings::Data
|
---|
38 | {
|
---|
39 | Data()
|
---|
40 | : pMachine(NULL)
|
---|
41 | { }
|
---|
42 |
|
---|
43 | Machine * const pMachine;
|
---|
44 | ComObjPtr<CaptureScreenSettings> pPeer;
|
---|
45 | uint32_t 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 |
|
---|
54 | DEFINE_EMPTY_CTOR_DTOR(CaptureScreenSettings)
|
---|
55 |
|
---|
56 | HRESULT CaptureScreenSettings::FinalConstruct()
|
---|
57 | {
|
---|
58 | return BaseFinalConstruct();
|
---|
59 | }
|
---|
60 |
|
---|
61 | void 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 | */
|
---|
75 | HRESULT CaptureScreenSettings::init(Machine *aParent, uint32_t 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 | /* mPeer is left null. */
|
---|
91 |
|
---|
92 | /* Simply copy the settings data. */
|
---|
93 | m->uScreenId = uScreenId;
|
---|
94 | m->bd.allocate();
|
---|
95 | m->bd->operator=(data);
|
---|
96 |
|
---|
97 | HRESULT rc = S_OK;
|
---|
98 |
|
---|
99 | int vrc = i_initInternal();
|
---|
100 | if (RT_SUCCESS(vrc))
|
---|
101 | {
|
---|
102 | autoInitSpan.setSucceeded();
|
---|
103 | }
|
---|
104 | else
|
---|
105 | {
|
---|
106 | autoInitSpan.setFailed();
|
---|
107 | rc = E_UNEXPECTED;
|
---|
108 | }
|
---|
109 |
|
---|
110 | LogFlowThisFuncLeave();
|
---|
111 | return rc;
|
---|
112 | }
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * Initializes the capture settings object given another capture settings object
|
---|
116 | * (a kind of copy constructor). This object shares data with
|
---|
117 | * the object passed as an argument.
|
---|
118 | *
|
---|
119 | * @note This object must be destroyed before the original object
|
---|
120 | * it shares data with is destroyed.
|
---|
121 | */
|
---|
122 | HRESULT CaptureScreenSettings::init(Machine *aParent, CaptureScreenSettings *that)
|
---|
123 | {
|
---|
124 | LogFlowThisFuncEnter();
|
---|
125 | LogFlowThisFunc(("aParent: %p, that: %p\n", aParent, that));
|
---|
126 |
|
---|
127 | ComAssertRet(aParent && that, E_INVALIDARG);
|
---|
128 |
|
---|
129 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
130 | AutoInitSpan autoInitSpan(this);
|
---|
131 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
132 |
|
---|
133 | m = new Data();
|
---|
134 |
|
---|
135 | unconst(m->pMachine) = aParent;
|
---|
136 | m->pPeer = that;
|
---|
137 |
|
---|
138 | AutoWriteLock thatlock(that COMMA_LOCKVAL_SRC_POS);
|
---|
139 |
|
---|
140 | m->uScreenId = that->m->uScreenId;
|
---|
141 | m->bd.share(that->m->bd);
|
---|
142 |
|
---|
143 | HRESULT rc = S_OK;
|
---|
144 |
|
---|
145 | int vrc = i_initInternal();
|
---|
146 | if (RT_SUCCESS(vrc))
|
---|
147 | {
|
---|
148 | autoInitSpan.setSucceeded();
|
---|
149 | }
|
---|
150 | else
|
---|
151 | {
|
---|
152 | autoInitSpan.setFailed();
|
---|
153 | rc = E_UNEXPECTED;
|
---|
154 | }
|
---|
155 |
|
---|
156 | LogFlowThisFuncLeave();
|
---|
157 | return rc;
|
---|
158 | }
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Initializes the guest object given another guest object
|
---|
162 | * (a kind of copy constructor). This object makes a private copy of data
|
---|
163 | * of the original object passed as an argument.
|
---|
164 | */
|
---|
165 | HRESULT CaptureScreenSettings::initCopy(Machine *aParent, CaptureScreenSettings *that)
|
---|
166 | {
|
---|
167 | LogFlowThisFuncEnter();
|
---|
168 | LogFlowThisFunc(("aParent: %p, that: %p\n", aParent, that));
|
---|
169 |
|
---|
170 | ComAssertRet(aParent && that, E_INVALIDARG);
|
---|
171 |
|
---|
172 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
173 | AutoInitSpan autoInitSpan(this);
|
---|
174 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
175 |
|
---|
176 | m = new Data();
|
---|
177 |
|
---|
178 | unconst(m->pMachine) = aParent;
|
---|
179 | /* mPeer is left null. */
|
---|
180 |
|
---|
181 | AutoWriteLock thatlock(that COMMA_LOCKVAL_SRC_POS);
|
---|
182 |
|
---|
183 | m->uScreenId = that->m->uScreenId;
|
---|
184 | m->bd.attachCopy(that->m->bd);
|
---|
185 |
|
---|
186 | HRESULT rc = S_OK;
|
---|
187 |
|
---|
188 | int vrc = i_initInternal();
|
---|
189 | if (RT_SUCCESS(vrc))
|
---|
190 | {
|
---|
191 | autoInitSpan.setSucceeded();
|
---|
192 | }
|
---|
193 | else
|
---|
194 | {
|
---|
195 | autoInitSpan.setFailed();
|
---|
196 | rc = E_UNEXPECTED;
|
---|
197 | }
|
---|
198 |
|
---|
199 | LogFlowThisFuncLeave();
|
---|
200 | return rc;
|
---|
201 | }
|
---|
202 |
|
---|
203 | /**
|
---|
204 | * Uninitializes the instance and sets the ready flag to FALSE.
|
---|
205 | * Called either from FinalRelease() or by the parent when it gets destroyed.
|
---|
206 | */
|
---|
207 | void CaptureScreenSettings::uninit()
|
---|
208 | {
|
---|
209 | LogFlowThisFuncEnter();
|
---|
210 |
|
---|
211 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
212 | AutoUninitSpan autoUninitSpan(this);
|
---|
213 | if (autoUninitSpan.uninitDone())
|
---|
214 | return;
|
---|
215 |
|
---|
216 | m->bd.free();
|
---|
217 |
|
---|
218 | unconst(m->pPeer) = NULL;
|
---|
219 | unconst(m->pMachine) = NULL;
|
---|
220 |
|
---|
221 | delete m;
|
---|
222 | m = NULL;
|
---|
223 |
|
---|
224 | LogFlowThisFuncLeave();
|
---|
225 | }
|
---|
226 |
|
---|
227 | HRESULT CaptureScreenSettings::isFeatureEnabled(CaptureFeature_T aFeature, BOOL *aEnabled)
|
---|
228 | {
|
---|
229 | settings::CaptureFeatureMap::const_iterator itFeature = m->bd->featureMap.find(aFeature);
|
---|
230 |
|
---|
231 | *aEnabled = ( itFeature != m->bd->featureMap.end()
|
---|
232 | && itFeature->second == true);
|
---|
233 |
|
---|
234 | return S_OK;
|
---|
235 | }
|
---|
236 |
|
---|
237 | HRESULT CaptureScreenSettings::getEnabled(BOOL *enabled)
|
---|
238 | {
|
---|
239 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
240 |
|
---|
241 | *enabled = m->bd->fEnabled ? TRUE : FALSE;
|
---|
242 |
|
---|
243 | return S_OK;
|
---|
244 | }
|
---|
245 |
|
---|
246 | HRESULT CaptureScreenSettings::setEnabled(BOOL enabled)
|
---|
247 | {
|
---|
248 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
249 |
|
---|
250 | if (m->bd->fEnabled != RT_BOOL(enabled))
|
---|
251 | {
|
---|
252 | m->bd.backup();
|
---|
253 | m->bd->fEnabled = RT_BOOL(enabled);
|
---|
254 | alock.release();
|
---|
255 |
|
---|
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);
|
---|
269 | }
|
---|
270 |
|
---|
271 | return S_OK;
|
---|
272 | }
|
---|
273 |
|
---|
274 | HRESULT CaptureScreenSettings::getFeatures(ULONG *aFeatures)
|
---|
275 | {
|
---|
276 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
277 |
|
---|
278 | *aFeatures = 0;
|
---|
279 |
|
---|
280 | settings::CaptureFeatureMap::const_iterator itFeature = m->bd->featureMap.begin();
|
---|
281 | while (itFeature != m->bd->featureMap.end())
|
---|
282 | {
|
---|
283 | if (itFeature->second) /* Is feature enable? */
|
---|
284 | *aFeatures |= (ULONG)itFeature->first;
|
---|
285 |
|
---|
286 | ++itFeature;
|
---|
287 | }
|
---|
288 |
|
---|
289 | return S_OK;
|
---|
290 | }
|
---|
291 |
|
---|
292 | HRESULT CaptureScreenSettings::setFeatures(ULONG aFeatures)
|
---|
293 | {
|
---|
294 | if (!i_canChangeSettings())
|
---|
295 | return setError(E_INVALIDARG, tr("Cannot change features while capturing is enabled"));
|
---|
296 |
|
---|
297 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
298 |
|
---|
299 | m->bd.backup();
|
---|
300 | m->bd->featureMap.clear();
|
---|
301 |
|
---|
302 | if (aFeatures & CaptureFeature_Audio)
|
---|
303 | m->bd->featureMap[CaptureFeature_Audio] = true;
|
---|
304 | if (aFeatures & CaptureFeature_Video)
|
---|
305 | m->bd->featureMap[CaptureFeature_Video] = true;
|
---|
306 |
|
---|
307 | alock.release();
|
---|
308 |
|
---|
309 | AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
|
---|
310 | m->pMachine->i_setModified(Machine::IsModified_Capture);
|
---|
311 | mlock.release();
|
---|
312 |
|
---|
313 | return S_OK;
|
---|
314 | }
|
---|
315 |
|
---|
316 | HRESULT CaptureScreenSettings::getDestination(CaptureDestination_T *aDestination)
|
---|
317 | {
|
---|
318 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
319 |
|
---|
320 | *aDestination = m->bd->enmDest;
|
---|
321 |
|
---|
322 | return S_OK;
|
---|
323 | }
|
---|
324 |
|
---|
325 | HRESULT CaptureScreenSettings::setDestination(CaptureDestination_T aDestination)
|
---|
326 | {
|
---|
327 | if (!i_canChangeSettings())
|
---|
328 | return setError(E_INVALIDARG, tr("Cannot change destination type while capturing is enabled"));
|
---|
329 |
|
---|
330 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
331 |
|
---|
332 | m->bd.backup();
|
---|
333 | m->bd->enmDest = aDestination;
|
---|
334 |
|
---|
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 |
|
---|
341 | return S_OK;
|
---|
342 | }
|
---|
343 |
|
---|
344 | HRESULT CaptureScreenSettings::getFileName(com::Utf8Str &aFileName)
|
---|
345 | {
|
---|
346 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
347 |
|
---|
348 | aFileName = m->bd->File.strName;
|
---|
349 |
|
---|
350 | return S_OK;
|
---|
351 | }
|
---|
352 |
|
---|
353 | HRESULT CaptureScreenSettings::setFileName(const com::Utf8Str &aFileName)
|
---|
354 | {
|
---|
355 | if (!i_canChangeSettings())
|
---|
356 | return setError(E_INVALIDARG, tr("Cannot change file name while capturing is enabled"));
|
---|
357 |
|
---|
358 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
359 |
|
---|
360 | Utf8Str strFile(aFileName);
|
---|
361 |
|
---|
362 | if (!RTPathStartsWithRoot(strFile.c_str()))
|
---|
363 | return setError(E_INVALIDARG, tr("Capture file name '%s' is not absolute"), strFile.c_str());
|
---|
364 |
|
---|
365 | m->bd.backup();
|
---|
366 | m->bd->File.strName = strFile;
|
---|
367 |
|
---|
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 |
|
---|
374 | return S_OK;
|
---|
375 | }
|
---|
376 |
|
---|
377 | HRESULT CaptureScreenSettings::getMaxTime(ULONG *aMaxTimeS)
|
---|
378 | {
|
---|
379 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
380 |
|
---|
381 | *aMaxTimeS = m->bd->ulMaxTimeS;
|
---|
382 |
|
---|
383 | return S_OK;
|
---|
384 | }
|
---|
385 |
|
---|
386 | HRESULT CaptureScreenSettings::setMaxTime(ULONG aMaxTimeS)
|
---|
387 | {
|
---|
388 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
389 |
|
---|
390 | if (!i_canChangeSettings())
|
---|
391 | return setError(E_INVALIDARG, tr("Cannot change maximum time while capturing is enabled"));
|
---|
392 |
|
---|
393 | m->bd.backup();
|
---|
394 | m->bd->ulMaxTimeS = aMaxTimeS;
|
---|
395 |
|
---|
396 | AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
|
---|
397 | m->pMachine->i_setModified(Machine::IsModified_Capture);
|
---|
398 | mlock.release();
|
---|
399 |
|
---|
400 | return S_OK;
|
---|
401 | }
|
---|
402 |
|
---|
403 | HRESULT CaptureScreenSettings::getMaxFileSize(ULONG *aMaxFileSizeMB)
|
---|
404 | {
|
---|
405 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
406 |
|
---|
407 | *aMaxFileSizeMB = m->bd->File.ulMaxSizeMB;
|
---|
408 |
|
---|
409 | return S_OK;
|
---|
410 | }
|
---|
411 |
|
---|
412 | HRESULT CaptureScreenSettings::setMaxFileSize(ULONG aMaxFileSize)
|
---|
413 | {
|
---|
414 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
415 |
|
---|
416 | if (!i_canChangeSettings())
|
---|
417 | return setError(E_INVALIDARG, tr("Cannot change maximum file size while capturing is enabled"));
|
---|
418 |
|
---|
419 | m->bd.backup();
|
---|
420 | m->bd->File.ulMaxSizeMB = aMaxFileSize;
|
---|
421 |
|
---|
422 | AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
|
---|
423 | m->pMachine->i_setModified(Machine::IsModified_Capture);
|
---|
424 | mlock.release();
|
---|
425 |
|
---|
426 | return S_OK;
|
---|
427 | }
|
---|
428 |
|
---|
429 | HRESULT CaptureScreenSettings::getOptions(com::Utf8Str &aOptions)
|
---|
430 | {
|
---|
431 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
432 |
|
---|
433 | aOptions = m->bd->strOptions;
|
---|
434 |
|
---|
435 | return S_OK;
|
---|
436 | }
|
---|
437 |
|
---|
438 | HRESULT CaptureScreenSettings::setOptions(const com::Utf8Str &aOptions)
|
---|
439 | {
|
---|
440 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
441 |
|
---|
442 | if (!i_canChangeSettings())
|
---|
443 | return setError(E_INVALIDARG, tr("Cannot change options string while capturing is enabled"));
|
---|
444 |
|
---|
445 | m->bd.backup();
|
---|
446 | m->bd->strOptions = aOptions;
|
---|
447 |
|
---|
448 | AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
|
---|
449 | m->pMachine->i_setModified(Machine::IsModified_Capture);
|
---|
450 | mlock.release();
|
---|
451 |
|
---|
452 | return S_OK;
|
---|
453 | }
|
---|
454 |
|
---|
455 | HRESULT CaptureScreenSettings::getAudioCodec(CaptureAudioCodec_T *aCodec)
|
---|
456 | {
|
---|
457 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
458 |
|
---|
459 | *aCodec = m->bd->Audio.enmAudioCodec;
|
---|
460 |
|
---|
461 | return S_OK;
|
---|
462 | }
|
---|
463 |
|
---|
464 | HRESULT CaptureScreenSettings::setAudioCodec(CaptureAudioCodec_T aCodec)
|
---|
465 | {
|
---|
466 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
467 |
|
---|
468 | if (!i_canChangeSettings())
|
---|
469 | return setError(E_INVALIDARG, tr("Cannot change audio codec while capturing is enabled"));
|
---|
470 |
|
---|
471 | m->bd.backup();
|
---|
472 | m->bd->Audio.enmAudioCodec = aCodec;
|
---|
473 |
|
---|
474 | AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
|
---|
475 | m->pMachine->i_setModified(Machine::IsModified_Capture);
|
---|
476 | mlock.release();
|
---|
477 |
|
---|
478 | return S_OK;
|
---|
479 | }
|
---|
480 |
|
---|
481 | HRESULT CaptureScreenSettings::getAudioHz(ULONG *aHz)
|
---|
482 | {
|
---|
483 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
484 |
|
---|
485 | *aHz = m->bd->Audio.uHz;
|
---|
486 |
|
---|
487 | return S_OK;
|
---|
488 | }
|
---|
489 |
|
---|
490 | HRESULT CaptureScreenSettings::setAudioHz(ULONG aHz)
|
---|
491 | {
|
---|
492 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
493 |
|
---|
494 | if (!i_canChangeSettings())
|
---|
495 | return setError(E_INVALIDARG, tr("Cannot change audio Hertz rate while capturing is enabled"));
|
---|
496 |
|
---|
497 | m->bd.backup();
|
---|
498 | m->bd->Audio.uHz = (uint16_t)aHz;
|
---|
499 |
|
---|
500 | AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
|
---|
501 | m->pMachine->i_setModified(Machine::IsModified_Capture);
|
---|
502 | mlock.release();
|
---|
503 |
|
---|
504 | return S_OK;
|
---|
505 | }
|
---|
506 |
|
---|
507 | HRESULT CaptureScreenSettings::getAudioBits(ULONG *aBits)
|
---|
508 | {
|
---|
509 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
510 |
|
---|
511 | *aBits = m->bd->Audio.cBits;
|
---|
512 |
|
---|
513 | return S_OK;
|
---|
514 | }
|
---|
515 |
|
---|
516 | HRESULT CaptureScreenSettings::setAudioBits(ULONG aBits)
|
---|
517 | {
|
---|
518 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
519 |
|
---|
520 | if (!i_canChangeSettings())
|
---|
521 | return setError(E_INVALIDARG, tr("Cannot change audio bits while capturing is enabled"));
|
---|
522 |
|
---|
523 | m->bd.backup();
|
---|
524 | m->bd->Audio.cBits = (uint8_t)aBits;
|
---|
525 |
|
---|
526 | AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
|
---|
527 | m->pMachine->i_setModified(Machine::IsModified_Capture);
|
---|
528 | mlock.release();
|
---|
529 |
|
---|
530 | return S_OK;
|
---|
531 | }
|
---|
532 |
|
---|
533 | HRESULT CaptureScreenSettings::getAudioChannels(ULONG *aChannels)
|
---|
534 | {
|
---|
535 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
536 |
|
---|
537 | *aChannels = m->bd->Audio.cChannels;
|
---|
538 |
|
---|
539 | return S_OK;
|
---|
540 | }
|
---|
541 |
|
---|
542 | HRESULT CaptureScreenSettings::setAudioChannels(ULONG aChannels)
|
---|
543 | {
|
---|
544 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
545 |
|
---|
546 | if (!i_canChangeSettings())
|
---|
547 | return setError(E_INVALIDARG, tr("Cannot change audio channels while capturing is enabled"));
|
---|
548 |
|
---|
549 | m->bd.backup();
|
---|
550 | m->bd->Audio.cChannels = (uint8_t)aChannels;
|
---|
551 |
|
---|
552 | AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
|
---|
553 | m->pMachine->i_setModified(Machine::IsModified_Capture);
|
---|
554 | mlock.release();
|
---|
555 |
|
---|
556 | return S_OK;
|
---|
557 | }
|
---|
558 |
|
---|
559 | HRESULT CaptureScreenSettings::getVideoCodec(CaptureVideoCodec_T *aCodec)
|
---|
560 | {
|
---|
561 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
562 |
|
---|
563 | *aCodec = m->bd->Video.enmCodec;
|
---|
564 |
|
---|
565 | return S_OK;
|
---|
566 | }
|
---|
567 |
|
---|
568 | HRESULT CaptureScreenSettings::setVideoCodec(CaptureVideoCodec_T aCodec)
|
---|
569 | {
|
---|
570 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
571 |
|
---|
572 | if (!i_canChangeSettings())
|
---|
573 | return setError(E_INVALIDARG, tr("Cannot change video codec while capturing is enabled"));
|
---|
574 |
|
---|
575 | m->bd.backup();
|
---|
576 | m->bd->Video.enmCodec = aCodec;
|
---|
577 |
|
---|
578 | AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
|
---|
579 | m->pMachine->i_setModified(Machine::IsModified_Capture);
|
---|
580 | mlock.release();
|
---|
581 |
|
---|
582 | return S_OK;
|
---|
583 | }
|
---|
584 |
|
---|
585 | HRESULT CaptureScreenSettings::getVideoWidth(ULONG *aVideoWidth)
|
---|
586 | {
|
---|
587 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
588 |
|
---|
589 | *aVideoWidth = m->bd->Video.ulWidth;
|
---|
590 |
|
---|
591 | return S_OK;
|
---|
592 | }
|
---|
593 |
|
---|
594 | HRESULT CaptureScreenSettings::setVideoWidth(ULONG aVideoWidth)
|
---|
595 | {
|
---|
596 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
597 |
|
---|
598 | if (!i_canChangeSettings())
|
---|
599 | return setError(E_INVALIDARG, tr("Cannot change video width while capturing is enabled"));
|
---|
600 |
|
---|
601 | m->bd.backup();
|
---|
602 | m->bd->Video.ulWidth = aVideoWidth;
|
---|
603 |
|
---|
604 | AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
|
---|
605 | m->pMachine->i_setModified(Machine::IsModified_Capture);
|
---|
606 | mlock.release();
|
---|
607 |
|
---|
608 | return S_OK;
|
---|
609 | }
|
---|
610 |
|
---|
611 | HRESULT CaptureScreenSettings::getVideoHeight(ULONG *aVideoHeight)
|
---|
612 | {
|
---|
613 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
614 |
|
---|
615 | *aVideoHeight = m->bd->Video.ulHeight;
|
---|
616 |
|
---|
617 | return S_OK;
|
---|
618 | }
|
---|
619 |
|
---|
620 | HRESULT CaptureScreenSettings::setVideoHeight(ULONG aVideoHeight)
|
---|
621 | {
|
---|
622 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
623 |
|
---|
624 | if (!i_canChangeSettings())
|
---|
625 | return setError(E_INVALIDARG, tr("Cannot change video height while capturing is enabled"));
|
---|
626 |
|
---|
627 | m->bd.backup();
|
---|
628 | m->bd->Video.ulHeight = aVideoHeight;
|
---|
629 |
|
---|
630 | AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
|
---|
631 | m->pMachine->i_setModified(Machine::IsModified_Capture);
|
---|
632 | mlock.release();
|
---|
633 |
|
---|
634 | return S_OK;
|
---|
635 | }
|
---|
636 |
|
---|
637 | HRESULT CaptureScreenSettings::getVideoRate(ULONG *aVideoRate)
|
---|
638 | {
|
---|
639 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
640 |
|
---|
641 | *aVideoRate = m->bd->Video.ulRate;
|
---|
642 |
|
---|
643 | return S_OK;
|
---|
644 | }
|
---|
645 |
|
---|
646 | HRESULT CaptureScreenSettings::setVideoRate(ULONG aVideoRate)
|
---|
647 | {
|
---|
648 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
649 |
|
---|
650 | if (!i_canChangeSettings())
|
---|
651 | return setError(E_INVALIDARG, tr("Cannot change video rate while capturing is enabled"));
|
---|
652 |
|
---|
653 | m->bd.backup();
|
---|
654 | m->bd->Video.ulRate = aVideoRate;
|
---|
655 |
|
---|
656 | AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
|
---|
657 | m->pMachine->i_setModified(Machine::IsModified_Capture);
|
---|
658 | mlock.release();
|
---|
659 |
|
---|
660 | return S_OK;
|
---|
661 | }
|
---|
662 |
|
---|
663 | HRESULT CaptureScreenSettings::getVideoRateControlMode(CaptureVideoRateControlMode_T *aMode)
|
---|
664 | {
|
---|
665 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
666 |
|
---|
667 | *aMode = CaptureVideoRateControlMode_CBR; /** @todo Implement VBR. */
|
---|
668 |
|
---|
669 | return S_OK;
|
---|
670 | }
|
---|
671 |
|
---|
672 | HRESULT CaptureScreenSettings::setVideoRateControlMode(CaptureVideoRateControlMode_T aMode)
|
---|
673 | {
|
---|
674 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
675 |
|
---|
676 | if (!i_canChangeSettings())
|
---|
677 | return setError(E_INVALIDARG, tr("Cannot change video rate control mode while capturing is enabled"));
|
---|
678 |
|
---|
679 | /** @todo Implement this. */
|
---|
680 | RT_NOREF(aMode);
|
---|
681 |
|
---|
682 | return E_NOTIMPL;
|
---|
683 | }
|
---|
684 |
|
---|
685 | HRESULT CaptureScreenSettings::getVideoFPS(ULONG *aVideoFPS)
|
---|
686 | {
|
---|
687 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
688 |
|
---|
689 | *aVideoFPS = m->bd->Video.ulFPS;
|
---|
690 |
|
---|
691 | return S_OK;
|
---|
692 | }
|
---|
693 |
|
---|
694 | HRESULT CaptureScreenSettings::setVideoFPS(ULONG aVideoFPS)
|
---|
695 | {
|
---|
696 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
697 |
|
---|
698 | if (!i_canChangeSettings())
|
---|
699 | return setError(E_INVALIDARG, tr("Cannot change video FPS while capturing is enabled"));
|
---|
700 |
|
---|
701 | m->bd.backup();
|
---|
702 | m->bd->Video.ulFPS = aVideoFPS;
|
---|
703 |
|
---|
704 | AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
|
---|
705 | m->pMachine->i_setModified(Machine::IsModified_Capture);
|
---|
706 | mlock.release();
|
---|
707 |
|
---|
708 | return S_OK;
|
---|
709 | }
|
---|
710 |
|
---|
711 | HRESULT CaptureScreenSettings::getVideoScalingMethod(CaptureVideoScalingMethod_T *aMode)
|
---|
712 | {
|
---|
713 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
714 |
|
---|
715 | *aMode = CaptureVideoScalingMethod_None; /** @todo Implement this. */
|
---|
716 |
|
---|
717 | return S_OK;
|
---|
718 | }
|
---|
719 |
|
---|
720 | HRESULT CaptureScreenSettings::setVideoScalingMethod(CaptureVideoScalingMethod_T aMode)
|
---|
721 | {
|
---|
722 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
723 |
|
---|
724 | if (!i_canChangeSettings())
|
---|
725 | return setError(E_INVALIDARG, tr("Cannot change video rate scaling method while capturing is enabled"));
|
---|
726 |
|
---|
727 | /** @todo Implement this. */
|
---|
728 | RT_NOREF(aMode);
|
---|
729 |
|
---|
730 | return E_NOTIMPL;
|
---|
731 | }
|
---|
732 |
|
---|
733 | bool CaptureScreenSettings::i_canChangeSettings(void)
|
---|
734 | {
|
---|
735 | AutoAnyStateDependency adep(m->pMachine);
|
---|
736 | AssertComRCReturn(adep.rc(), false);
|
---|
737 |
|
---|
738 | if ( Global::IsOnline(adep.machineState())
|
---|
739 | && m->bd->fEnabled)
|
---|
740 | return false;
|
---|
741 |
|
---|
742 | return true;
|
---|
743 | }
|
---|
744 |
|
---|
745 | /**
|
---|
746 | * Returns the full path to the default video capture file.
|
---|
747 | */
|
---|
748 | int CaptureScreenSettings::i_getDefaultFileName(Utf8Str &strFile)
|
---|
749 | {
|
---|
750 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
751 |
|
---|
752 | strFile = m->pMachine->i_getSettingsFileFull(); // path/to/machinesfolder/vmname/vmname.vbox
|
---|
753 | strFile.stripSuffix(); // path/to/machinesfolder/vmname/vmname
|
---|
754 | strFile.append(".webm"); // path/to/machinesfolder/vmname/vmname.webm
|
---|
755 |
|
---|
756 | return VINF_SUCCESS;
|
---|
757 | }
|
---|
758 |
|
---|
759 | /**
|
---|
760 | * Initializes data, internal version.
|
---|
761 | *
|
---|
762 | * @returns IPRT status code.
|
---|
763 | */
|
---|
764 | int CaptureScreenSettings::i_initInternal(void)
|
---|
765 | {
|
---|
766 | Assert(m);
|
---|
767 | return i_getDefaultFileName(m->bd->File.strName);
|
---|
768 | }
|
---|
769 |
|
---|