Argus Camera Sample Argus Camera Sample

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Dispatcher.cpp
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of NVIDIA CORPORATION nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <stdio.h>
30 #include <unistd.h>
31 #include <stdarg.h>
32 #include <assert.h>
33
34 #include <sstream>
35 #include <limits>
36
37 #include "Dispatcher.h"
38 #include "InitOnce.h"
39 #include "UniquePointer.h"
40 #include "Error.h"
41 #include "Util.h"
42 #include "Composer.h"
43 #include "Validator.h"
44 #include <Argus/Ext/BayerSharpnessMap.h>
45 #include <Argus/Ext/DebugCaptureSession.h>
46 #include <Argus/Ext/DeFog.h>
47 #include <Argus/Ext/FaceDetect.h>
48 #include <Argus/Ext/InternalFrameCount.h>
49 #include <Argus/Ext/SensorPrivateMetadata.h>
50 #include <Argus/Ext/DebugCaptureSession.h>
51 #include <Argus/Ext/PwlWdrSensorMode.h>
52
53 namespace ArgusSamples
54 {
55
56 /**
57 * An observer for an Argus interface.
58 */
59 class IObserverForInterface : public IObserver
60 {
61 public:
62 virtual ~IObserverForInterface() { };
63
64 /**
65 * Check if this is the observer for the given interface.
66 *
67 * @param interface [in]
68 */
69 virtual bool isInterface(Argus::Interface *interface) const = 0;
70 };
71
72 /**
73 * Denoise settings observer. Update Argus denoise settings when values change.
74 */
75 class DenoiseSettingsObserver : public IObserverForInterface
76 {
77 public:
78 DenoiseSettingsObserver(Argus::IDenoiseSettings *iDenoiseSettings)
79 : m_iDenoiseSettings(iDenoiseSettings)
80 {
81 Dispatcher &dispatcher = Dispatcher::getInstance();
82
83 PROPAGATE_ERROR_CONTINUE(dispatcher.m_denoiseMode.registerObserver(this,
84 static_cast<IObserver::CallbackFunction>(
85 &DenoiseSettingsObserver::onDenoiseModeChanged)));
86 PROPAGATE_ERROR_CONTINUE(dispatcher.m_denoiseStrength.registerObserver(this,
87 static_cast<IObserver::CallbackFunction>(
88 &DenoiseSettingsObserver::onDenoiseStrengthChanged)));
89 }
90
91 virtual ~DenoiseSettingsObserver()
92 {
93 Dispatcher &dispatcher = Dispatcher::getInstance();
94
95 PROPAGATE_ERROR_CONTINUE(dispatcher.m_denoiseStrength.unregisterObserver(this,
96 static_cast<IObserver::CallbackFunction>(
97 &DenoiseSettingsObserver::onDenoiseStrengthChanged)));
98 PROPAGATE_ERROR_CONTINUE(dispatcher.m_denoiseMode.unregisterObserver(this,
99 static_cast<IObserver::CallbackFunction>(
100 &DenoiseSettingsObserver::onDenoiseModeChanged)));
101 }
102
103 virtual bool isInterface(Argus::Interface *interface) const
104 {
105 return (interface == m_iDenoiseSettings);
106 }
107
108 private:
109 bool onDenoiseModeChanged(const Observed &source)
110 {
111 Dispatcher &dispatcher = Dispatcher::getInstance();
112
113 assert(&source == &dispatcher.m_denoiseMode);
114
115 if (m_iDenoiseSettings->setDenoiseMode(dispatcher.m_denoiseMode.get()) != Argus::STATUS_OK)
116 ORIGINATE_ERROR("Failed to set the denoising mode");
117
118 PROPAGATE_ERROR(Dispatcher::getInstance().restartActiveRequests());
119
120 return true;
121 }
122
123 bool onDenoiseStrengthChanged(const Observed &source)
124 {
125 Dispatcher &dispatcher = Dispatcher::getInstance();
126
127 assert(&source == &dispatcher.m_denoiseStrength);
128
129 if (m_iDenoiseSettings->setDenoiseStrength(dispatcher.m_denoiseStrength.get()) !=
130 Argus::STATUS_OK)
131 {
132 ORIGINATE_ERROR("Failed to set the denoise strength");
133 }
134
135 PROPAGATE_ERROR(Dispatcher::getInstance().restartActiveRequests());
136
137 return true;
138 }
139
140 Argus::IDenoiseSettings *m_iDenoiseSettings;
141 };
142
143 /**
144 * Edge enhancement settings observer. Update Argus edge enhance settings when values change.
145 */
146 class EdgeEnhanceSettingsObserver : public IObserverForInterface
147 {
148 public:
149 EdgeEnhanceSettingsObserver(Argus::IEdgeEnhanceSettings *iEdgeEnhanceSettings)
150 : m_iEdgeEnhanceSettings(iEdgeEnhanceSettings)
151 {
152 Dispatcher &dispatcher = Dispatcher::getInstance();
153
154 PROPAGATE_ERROR_CONTINUE(dispatcher.m_edgeEnhanceMode.registerObserver(this,
155 static_cast<IObserver::CallbackFunction>(
156 &EdgeEnhanceSettingsObserver::onEdgeEnhanceModeChanged)));
157 PROPAGATE_ERROR_CONTINUE(dispatcher.m_edgeEnhanceStrength.registerObserver(this,
158 static_cast<IObserver::CallbackFunction>(
159 &EdgeEnhanceSettingsObserver::onEdgeEnhanceStrengthChanged)));
160 }
161
162 virtual ~EdgeEnhanceSettingsObserver()
163 {
164 Dispatcher &dispatcher = Dispatcher::getInstance();
165
166 PROPAGATE_ERROR_CONTINUE(dispatcher.m_edgeEnhanceStrength.unregisterObserver(this,
167 static_cast<IObserver::CallbackFunction>(
168 &EdgeEnhanceSettingsObserver::onEdgeEnhanceStrengthChanged)));
169 PROPAGATE_ERROR_CONTINUE(dispatcher.m_edgeEnhanceMode.unregisterObserver(this,
170 static_cast<IObserver::CallbackFunction>(
171 &EdgeEnhanceSettingsObserver::onEdgeEnhanceModeChanged)));
172 }
173
174 virtual bool isInterface(Argus::Interface *interface) const
175 {
176 return (interface == m_iEdgeEnhanceSettings);
177 }
178
179 private:
180 bool onEdgeEnhanceModeChanged(const Observed &source)
181 {
182 Dispatcher &dispatcher = Dispatcher::getInstance();
183
184 assert(&source == &dispatcher.m_edgeEnhanceMode);
185
186 if (m_iEdgeEnhanceSettings->setEdgeEnhanceMode(dispatcher.m_edgeEnhanceMode.get())
187 != Argus::STATUS_OK)
188 {
189 ORIGINATE_ERROR("Failed to set the edge enhancement mode");
190 }
191
192 PROPAGATE_ERROR(Dispatcher::getInstance().restartActiveRequests());
193
194 return true;
195 }
196
197 bool onEdgeEnhanceStrengthChanged(const Observed &source)
198 {
199 Dispatcher &dispatcher = Dispatcher::getInstance();
200
201 assert(&source == &dispatcher.m_edgeEnhanceStrength);
202
203 if (m_iEdgeEnhanceSettings->setEdgeEnhanceStrength(dispatcher.m_edgeEnhanceStrength.get())
204 != Argus::STATUS_OK)
205 {
206 ORIGINATE_ERROR("Failed to set the edge enhancement strength");
207 }
208
209 PROPAGATE_ERROR(Dispatcher::getInstance().restartActiveRequests());
210
211 return true;
212 }
213
214 Argus::IEdgeEnhanceSettings *m_iEdgeEnhanceSettings;
215 };
216
217 /**
218 * Video stabilization settings observer. Update Argus video stabilization settings when changed.
219 */
220 class VideoStabilizationSettingsObserver : public IObserverForInterface
221 {
222 public:
223 VideoStabilizationSettingsObserver(Argus::IVideoStabilizationSettings *iVStabSettings)
224 : m_iVideoStabilizationSettings(iVStabSettings)
225 {
226 Dispatcher &dispatcher = Dispatcher::getInstance();
227
228 PROPAGATE_ERROR_CONTINUE(dispatcher.m_vstabMode.registerObserver(this,
229 static_cast<IObserver::CallbackFunction>(
230 &VideoStabilizationSettingsObserver::onVideoStabilizationModeChanged)));
231 }
232
233 virtual ~VideoStabilizationSettingsObserver()
234 {
235 Dispatcher &dispatcher = Dispatcher::getInstance();
236
237 PROPAGATE_ERROR_CONTINUE(dispatcher.m_vstabMode.unregisterObserver(this,
238 static_cast<IObserver::CallbackFunction>(
239 &VideoStabilizationSettingsObserver::onVideoStabilizationModeChanged)));
240 }
241
242 virtual bool isInterface(Argus::Interface *interface) const
243 {
244 return (interface == m_iVideoStabilizationSettings);
245 }
246
247 private:
248 bool onVideoStabilizationModeChanged(const Observed &source)
249 {
250 Dispatcher &dispatcher = Dispatcher::getInstance();
251
252 assert(&source == &dispatcher.m_vstabMode);
253
254 if (m_iVideoStabilizationSettings->setVideoStabilizationMode(dispatcher.m_vstabMode.get())
255 != Argus::STATUS_OK)
256 {
257 ORIGINATE_ERROR("Failed to set the video stabilization mode");
258 }
259
260 PROPAGATE_ERROR(Dispatcher::getInstance().restartActiveRequests());
261
262 return true;
263 }
264
265 Argus::IVideoStabilizationSettings *m_iVideoStabilizationSettings;
266 };
267
268 /**
269 * Source settings observer. Update Argus source settings if values which are set through the
270 * source settings change.
271 */
272 class SourceSettingsObserver : public IObserverForInterface
273 {
274 public:
275 SourceSettingsObserver(Argus::ISourceSettings *iSourceSettings)
276 : m_iSourceSettings(iSourceSettings)
277 {
278 Dispatcher &dispatcher = Dispatcher::getInstance();
279
280 PROPAGATE_ERROR_CONTINUE(dispatcher.m_exposureTimeRange.registerObserver(this,
281 static_cast<IObserver::CallbackFunction>(
282 &SourceSettingsObserver::onExposureTimeRangeChanged)));
283 PROPAGATE_ERROR_CONTINUE(dispatcher.m_gainRange.registerObserver(this,
284 static_cast<IObserver::CallbackFunction>(
285 &SourceSettingsObserver::onGainRangeChanged)));
286 PROPAGATE_ERROR_CONTINUE(dispatcher.m_sensorModeIndex.registerObserver(this,
287 static_cast<IObserver::CallbackFunction>(
288 &SourceSettingsObserver::onSensorModeChanged)));
289 PROPAGATE_ERROR_CONTINUE(dispatcher.m_frameRate.registerObserver(this,
290 static_cast<IObserver::CallbackFunction>(
291 &SourceSettingsObserver::onFrameRateChanged)));
292 PROPAGATE_ERROR_CONTINUE(dispatcher.m_focusPosition.registerObserver(this,
293 static_cast<IObserver::CallbackFunction>(
294 &SourceSettingsObserver::onFocusPositionChanged)));
295 }
296
297 virtual ~SourceSettingsObserver()
298 {
299 Dispatcher &dispatcher = Dispatcher::getInstance();
300
301 PROPAGATE_ERROR_CONTINUE(dispatcher.m_focusPosition.unregisterObserver(this,
302 static_cast<IObserver::CallbackFunction>(
303 &SourceSettingsObserver::onFocusPositionChanged)));
304 PROPAGATE_ERROR_CONTINUE(dispatcher.m_frameRate.unregisterObserver(this,
305 static_cast<IObserver::CallbackFunction>(
306 &SourceSettingsObserver::onFrameRateChanged)));
307 PROPAGATE_ERROR_CONTINUE(dispatcher.m_sensorModeIndex.unregisterObserver(this,
308 static_cast<IObserver::CallbackFunction>(
309 &SourceSettingsObserver::onSensorModeChanged)));
310 PROPAGATE_ERROR_CONTINUE(dispatcher.m_gainRange.unregisterObserver(this,
311 static_cast<IObserver::CallbackFunction>(
312 &SourceSettingsObserver::onGainRangeChanged)));
313 PROPAGATE_ERROR_CONTINUE(dispatcher.m_exposureTimeRange.unregisterObserver(this,
314 static_cast<IObserver::CallbackFunction>(
315 &SourceSettingsObserver::onExposureTimeRangeChanged)));
316 }
317
318 virtual bool isInterface(Argus::Interface *interface) const
319 {
320 return (interface == m_iSourceSettings);
321 }
322
323 private:
324 bool onExposureTimeRangeChanged(const Observed &source)
325 {
326 Dispatcher &dispatcher = Dispatcher::getInstance();
327
328 assert(&source == &dispatcher.m_exposureTimeRange);
329
330 if (m_iSourceSettings->setExposureTimeRange(dispatcher.m_exposureTimeRange.get()) !=
331 Argus::STATUS_OK)
332 {
333 ORIGINATE_ERROR("Failed to set exposure time range");
334 }
335
336 PROPAGATE_ERROR(Dispatcher::getInstance().restartActiveRequests());
337
338 return true;
339 }
340
341 bool onGainRangeChanged(const Observed &source)
342 {
343 Dispatcher &dispatcher = Dispatcher::getInstance();
344
345 assert(&source == &dispatcher.m_gainRange);
346
347 if (m_iSourceSettings->setGainRange(dispatcher.m_gainRange.get()) != Argus::STATUS_OK)
348 ORIGINATE_ERROR("Failed to set gain range");
349
350 PROPAGATE_ERROR(Dispatcher::getInstance().restartActiveRequests());
351
352 return true;
353 }
354
355 bool onSensorModeChanged(const Observed &source)
356 {
357 Dispatcher &dispatcher = Dispatcher::getInstance();
358
359 assert(&source == &dispatcher.m_sensorModeIndex);
360
361 Argus::SensorMode *sensorMode = NULL;
362 PROPAGATE_ERROR(dispatcher.getSensorMode(dispatcher.m_sensorModeIndex.get(), &sensorMode));
363
364 if (m_iSourceSettings->setSensorMode(sensorMode) != Argus::STATUS_OK)
365 ORIGINATE_ERROR("Failed to set sensor mode");
366
367 PROPAGATE_ERROR(dispatcher.restartActiveRequests());
368
369 return true;
370 }
371
372 bool onFocusPositionChanged(const Observed &source)
373 {
374 Dispatcher &dispatcher = Dispatcher::getInstance();
375
376 assert(&source == &dispatcher.m_focusPosition);
377
378 if (m_iSourceSettings->setFocusPosition(dispatcher.m_focusPosition.get()) !=
379 Argus::STATUS_OK)
380 {
381 ORIGINATE_ERROR("Failed to set focus position");
382 }
383
384 PROPAGATE_ERROR(Dispatcher::getInstance().restartActiveRequests());
385
386 return true;
387 }
388
389 bool onFrameRateChanged(const Observed &source)
390 {
391 Dispatcher &dispatcher = Dispatcher::getInstance();
392
393 assert(&source == &dispatcher.m_frameRate);
394
395 Argus::Range<uint64_t> frameDurationRangeNs(0);
396
397 if (dispatcher.m_frameRate.get() == 0.0f)
398 {
399 // a frame rate of zero means VFR, get the sensor frame duration and apply it to
400 // the source
401 Argus::SensorMode *sensorMode = NULL;
402 PROPAGATE_ERROR(dispatcher.getSensorMode(dispatcher.m_sensorModeIndex.get(),
403 &sensorMode));
404
405 Argus::ISensorMode *iSensorMode =
406 Argus::interface_cast<Argus::ISensorMode>(sensorMode);
407
408 frameDurationRangeNs = iSensorMode->getFrameDurationRange();
409 }
410 else
411 {
412 // frame rate is frames per second, frameduration is in nanoseconds
413 frameDurationRangeNs =
414 TimeValue::fromCycelsPerSec(dispatcher.m_frameRate.get()).toNSec();
415 }
416
417 if (m_iSourceSettings->setFrameDurationRange(frameDurationRangeNs) != Argus::STATUS_OK)
418 ORIGINATE_ERROR("Failed to set frame duration range");
419
420 PROPAGATE_ERROR(Dispatcher::getInstance().restartActiveRequests());
421
422 return true;
423 }
424
425 Argus::ISourceSettings *m_iSourceSettings;
426 };
427
428 /**
429 * Auto control settings observer. Update Argus auto control settings if values which are set
430 * through the auto control settings change.
431 */
432 class AutoControlSettingsObserver : public IObserverForInterface
433 {
434 public:
435 AutoControlSettingsObserver(Argus::IAutoControlSettings *iAutoControlSettings)
436 : m_iAutoControlSettings(iAutoControlSettings)
437 {
438 Dispatcher &dispatcher = Dispatcher::getInstance();
439
440 PROPAGATE_ERROR_CONTINUE(dispatcher.m_aeAntibandingMode.registerObserver(this,
441 static_cast<IObserver::CallbackFunction>(
442 &AutoControlSettingsObserver::onAeAntibandingModeChanged)));
443 PROPAGATE_ERROR_CONTINUE(dispatcher.m_aeLock.registerObserver(this,
444 static_cast<IObserver::CallbackFunction>(
445 &AutoControlSettingsObserver::onAeLockChanged)));
446 PROPAGATE_ERROR_CONTINUE(dispatcher.m_awbLock.registerObserver(this,
447 static_cast<IObserver::CallbackFunction>(
448 &AutoControlSettingsObserver::onAwbLockChanged)));
449 PROPAGATE_ERROR_CONTINUE(dispatcher.m_awbMode.registerObserver(this,
450 static_cast<IObserver::CallbackFunction>(
451 &AutoControlSettingsObserver::onAwbModeChanged)));
452 PROPAGATE_ERROR_CONTINUE(dispatcher.m_exposureCompensation.registerObserver(this,
453 static_cast<IObserver::CallbackFunction>(
454 &AutoControlSettingsObserver::onExposureCompensationChanged)));
455 PROPAGATE_ERROR_CONTINUE(dispatcher.m_ispDigitalGainRange.registerObserver(this,
456 static_cast<IObserver::CallbackFunction>(
457 &AutoControlSettingsObserver::onIspDigitalGainRangeChanged)));
458
459 }
460
461 virtual ~AutoControlSettingsObserver()
462 {
463 Dispatcher &dispatcher = Dispatcher::getInstance();
464
465 PROPAGATE_ERROR_CONTINUE(dispatcher.m_ispDigitalGainRange.unregisterObserver(this,
466 static_cast<IObserver::CallbackFunction>(
467 &AutoControlSettingsObserver::onIspDigitalGainRangeChanged)));
468 PROPAGATE_ERROR_CONTINUE(dispatcher.m_exposureCompensation.unregisterObserver(this,
469 static_cast<IObserver::CallbackFunction>(
470 &AutoControlSettingsObserver::onExposureCompensationChanged)));
471 PROPAGATE_ERROR_CONTINUE(dispatcher.m_awbMode.unregisterObserver(this,
472 static_cast<IObserver::CallbackFunction>(
473 &AutoControlSettingsObserver::onAwbModeChanged)));
474 PROPAGATE_ERROR_CONTINUE(dispatcher.m_awbLock.unregisterObserver(this,
475 static_cast<IObserver::CallbackFunction>(
476 &AutoControlSettingsObserver::onAwbLockChanged)));
477 PROPAGATE_ERROR_CONTINUE(dispatcher.m_aeLock.unregisterObserver(this,
478 static_cast<IObserver::CallbackFunction>(
479 &AutoControlSettingsObserver::onAeLockChanged)));
480 PROPAGATE_ERROR_CONTINUE(dispatcher.m_aeAntibandingMode.unregisterObserver(this,
481 static_cast<IObserver::CallbackFunction>(
482 &AutoControlSettingsObserver::onAeAntibandingModeChanged)));
483 }
484
485 virtual bool isInterface(Argus::Interface *interface) const
486 {
487 return (interface == m_iAutoControlSettings);
488 }
489
490 private:
491 bool onAeAntibandingModeChanged(const Observed &source)
492 {
493 Dispatcher &dispatcher = Dispatcher::getInstance();
494
495 assert(&source == &dispatcher.m_aeAntibandingMode);
496
497 if (m_iAutoControlSettings->setAeAntibandingMode(dispatcher.m_aeAntibandingMode.get()) !=
498 Argus::STATUS_OK)
499 {
500 ORIGINATE_ERROR("Failed to set the AE antibanding mode");
501 }
502
503 PROPAGATE_ERROR(Dispatcher::getInstance().restartActiveRequests());
504
505 return true;
506 }
507
508 bool onAeLockChanged(const Observed &source)
509 {
510 Dispatcher &dispatcher = Dispatcher::getInstance();
511
512 assert(&source == &dispatcher.m_aeLock);
513
514 if (m_iAutoControlSettings->setAeLock(dispatcher.m_aeLock.get()) != Argus::STATUS_OK)
515 ORIGINATE_ERROR("Failed to set the AE lock");
516
517 PROPAGATE_ERROR(Dispatcher::getInstance().restartActiveRequests());
518
519 return true;
520 }
521
522 bool onAwbLockChanged(const Observed &source)
523 {
524 Dispatcher &dispatcher = Dispatcher::getInstance();
525
526 assert(&source == &dispatcher.m_awbLock);
527
528 if (m_iAutoControlSettings->setAwbLock(dispatcher.m_awbLock.get()) != Argus::STATUS_OK)
529 ORIGINATE_ERROR("Failed to set the AWB lock");
530
531 PROPAGATE_ERROR(Dispatcher::getInstance().restartActiveRequests());
532
533 return true;
534 }
535
536 bool onAwbModeChanged(const Observed &source)
537 {
538 Dispatcher &dispatcher = Dispatcher::getInstance();
539
540 assert(&source == &dispatcher.m_awbMode);
541
542 if (m_iAutoControlSettings->setAwbMode(dispatcher.m_awbMode.get()) != Argus::STATUS_OK)
543 ORIGINATE_ERROR("Failed to set the AWB mode");
544
545 PROPAGATE_ERROR(Dispatcher::getInstance().restartActiveRequests());
546
547 return true;
548 }
549
550 bool onExposureCompensationChanged(const Observed &source)
551 {
552 Dispatcher &dispatcher = Dispatcher::getInstance();
553
554 assert(&source == &dispatcher.m_exposureCompensation);
555
556 if (m_iAutoControlSettings->setExposureCompensation(
557 dispatcher.m_exposureCompensation.get()) != Argus::STATUS_OK)
558 {
559 ORIGINATE_ERROR("Failed to set the exposure compensation");
560 }
561
562 PROPAGATE_ERROR(Dispatcher::getInstance().restartActiveRequests());
563
564 return true;
565 }
566
567 bool onIspDigitalGainRangeChanged(const Observed &source)
568 {
569 Dispatcher &dispatcher = Dispatcher::getInstance();
570
571 assert(&source == &dispatcher.m_ispDigitalGainRange);
572
573 if (m_iAutoControlSettings->setIspDigitalGainRange(
574 dispatcher.m_ispDigitalGainRange.get()) != Argus::STATUS_OK)
575 {
576 ORIGINATE_ERROR("Failed to set the Isp Digital Gain Range");
577 }
578 PROPAGATE_ERROR(Dispatcher::getInstance().restartActiveRequests());
579
580 return true;
581 }
582
583 Argus::IAutoControlSettings *m_iAutoControlSettings;
584 };
585
586 /**
587 * DeFog settings observer. Update Argus DeFog settings if values which are set through the
588 * DeFog settings change.
589 */
590 class DeFogSettingsObserver : public IObserverForInterface
591 {
592 public:
593 DeFogSettingsObserver(Argus::Ext::IDeFogSettings *iDeFogSettings)
594 : m_iDeFogSettings(iDeFogSettings)
595 {
596 Dispatcher &dispatcher = Dispatcher::getInstance();
597
598 PROPAGATE_ERROR_CONTINUE(dispatcher.m_deFogEnable.registerObserver(this,
599 static_cast<IObserver::CallbackFunction>(&DeFogSettingsObserver::onDeFogEnableChanged)));
600 PROPAGATE_ERROR_CONTINUE(dispatcher.m_deFogAmount.registerObserver(this,
601 static_cast<IObserver::CallbackFunction>(&DeFogSettingsObserver::onDeFogAmountChanged)));
602 PROPAGATE_ERROR_CONTINUE(dispatcher.m_deFogQuality.registerObserver(this,
603 static_cast<IObserver::CallbackFunction>(&DeFogSettingsObserver::onDeFogQualityChanged)));
604 }
605
606 virtual ~DeFogSettingsObserver()
607 {
608 Dispatcher &dispatcher = Dispatcher::getInstance();
609
610 PROPAGATE_ERROR_CONTINUE(dispatcher.m_deFogQuality.unregisterObserver(this,
611 static_cast<IObserver::CallbackFunction>(&DeFogSettingsObserver::onDeFogQualityChanged)));
612 PROPAGATE_ERROR_CONTINUE(dispatcher.m_deFogAmount.unregisterObserver(this,
613 static_cast<IObserver::CallbackFunction>(&DeFogSettingsObserver::onDeFogAmountChanged)));
614 PROPAGATE_ERROR_CONTINUE(dispatcher.m_deFogEnable.unregisterObserver(this,
615 static_cast<IObserver::CallbackFunction>(&DeFogSettingsObserver::onDeFogEnableChanged)));
616 }
617
618 virtual bool isInterface(Argus::Interface *interface) const
619 {
620 return (interface == m_iDeFogSettings);
621 }
622
623 private:
624 bool onDeFogEnableChanged(const Observed &source)
625 {
626 Dispatcher &dispatcher = Dispatcher::getInstance();
627
628 assert(&source == &dispatcher.m_deFogEnable);
629
630 m_iDeFogSettings->setDeFogEnable(dispatcher.m_deFogEnable.get());
631
632 PROPAGATE_ERROR(Dispatcher::getInstance().restartActiveRequests());
633
634 return true;
635 }
636
637 bool onDeFogAmountChanged(const Observed &source)
638 {
639 Dispatcher &dispatcher = Dispatcher::getInstance();
640
641 assert(&source == &dispatcher.m_deFogAmount);
642
643 if (m_iDeFogSettings->setDeFogAmount(dispatcher.m_deFogAmount.get()) != Argus::STATUS_OK)
644 ORIGINATE_ERROR("Failed to set the DeFog amount");
645
646 PROPAGATE_ERROR(Dispatcher::getInstance().restartActiveRequests());
647
648 return true;
649 }
650
651 bool onDeFogQualityChanged(const Observed &source)
652 {
653 Dispatcher &dispatcher = Dispatcher::getInstance();
654
655 assert(&source == &dispatcher.m_deFogQuality);
656
657 if (m_iDeFogSettings->setDeFogQuality(dispatcher.m_deFogQuality.get()) != Argus::STATUS_OK)
658 ORIGINATE_ERROR("Failed to set the DeFog quality");
659
660 PROPAGATE_ERROR(Dispatcher::getInstance().restartActiveRequests());
661
662 return true;
663 }
664
665 Argus::Ext::IDeFogSettings *m_iDeFogSettings;
666 };
667
668 // valid denoise modes
669 static const ValidatorEnum<Argus::DenoiseMode>::ValueStringPair s_denoiseModes[] =
670 {
671 { Argus::DENOISE_MODE_OFF, "off" },
672 { Argus::DENOISE_MODE_FAST, "fast" },
673 { Argus::DENOISE_MODE_HIGH_QUALITY, "highquality" }
674 };
675
676 // valid edge enhance modes
677 static const ValidatorEnum<Argus::EdgeEnhanceMode>::ValueStringPair s_edgeEnhanceModes[] =
678 {
679 { Argus::EDGE_ENHANCE_MODE_OFF, "off" },
680 { Argus::EDGE_ENHANCE_MODE_FAST, "fast" },
681 { Argus::EDGE_ENHANCE_MODE_HIGH_QUALITY, "highquality" }
682 };
683
684 // valid vstab modes
685 static const ValidatorEnum<Argus::VideoStabilizationMode>::ValueStringPair s_vstabModes[] =
686 {
687 { Argus::VIDEO_STABILIZATION_MODE_OFF, "off" },
688 { Argus::VIDEO_STABILIZATION_MODE_ON, "on" }
689 };
690
691 // valid AE antibanding modes
692 static const ValidatorEnum<Argus::AeAntibandingMode>::ValueStringPair s_aeAntibandingModes[] =
693 {
694 { Argus::AE_ANTIBANDING_MODE_OFF, "off" },
695 { Argus::AE_ANTIBANDING_MODE_AUTO, "auto" },
696 { Argus::AE_ANTIBANDING_MODE_50HZ, "50hz" },
697 { Argus::AE_ANTIBANDING_MODE_60HZ, "60hz" }
698 };
699
700 // valid AWB modes
701 static const ValidatorEnum<Argus::AwbMode>::ValueStringPair s_awbModes[] =
702 {
703 { Argus::AWB_MODE_OFF, "off" },
704 { Argus::AWB_MODE_AUTO, "auto" },
705 { Argus::AWB_MODE_INCANDESCENT, "incandescent" },
706 { Argus::AWB_MODE_FLUORESCENT, "fluorescent" },
707 { Argus::AWB_MODE_WARM_FLUORESCENT, "warmfluorescent" },
708 { Argus::AWB_MODE_DAYLIGHT, "daylight" },
709 { Argus::AWB_MODE_CLOUDY_DAYLIGHT, "cloudydaylight" },
710 { Argus::AWB_MODE_TWILIGHT, "twilight" },
711 { Argus::AWB_MODE_SHADE, "shade" },
712 { Argus::AWB_MODE_MANUAL, "manual" }
713 };
714
715 // valid video formats
716 static const ValidatorEnum<VideoPipeline::VideoFormat>::ValueStringPair s_videoFormats[] =
717 {
718 { VideoPipeline::VIDEO_FORMAT_H264, "h264" },
719 { VideoPipeline::VIDEO_FORMAT_H265, "h265" },
720 { VideoPipeline::VIDEO_FORMAT_VP8, "vp8" },
721 { VideoPipeline::VIDEO_FORMAT_VP9, "vp9" }
722 };
723
724 // valid video file types
725 static const ValidatorEnum<VideoPipeline::VideoFileType>::ValueStringPair s_videoFileTypes[] =
726 {
727 { VideoPipeline::VIDEO_FILE_TYPE_MP4, "mp4" },
728 { VideoPipeline::VIDEO_FILE_TYPE_3GP, "3gp" },
729 { VideoPipeline::VIDEO_FILE_TYPE_AVI, "avi" },
730 { VideoPipeline::VIDEO_FILE_TYPE_MKV, "mkv" },
731 { VideoPipeline::VIDEO_FILE_TYPE_H265, "h265" }
732 };
733
734 static const Argus::Size2D<uint32_t> s_outputSizes[] =
735 {
736 Argus::Size2D<uint32_t>(0, 0), // if size is 0,0 take the current sensor size
737 Argus::Size2D<uint32_t>(176, 144), // QCIF
738 Argus::Size2D<uint32_t>(320, 240),
739 Argus::Size2D<uint32_t>(640, 480),
740 Argus::Size2D<uint32_t>(1280, 720), // 720p HDTV
741 Argus::Size2D<uint32_t>(1920, 1080), // 1080p HDTV
742 Argus::Size2D<uint32_t>(3840, 2160), // 2160p 4K UHDTV
743 };
744
745 Dispatcher::Dispatcher()
746 : m_deviceFocusPositionRange(0)
747 , m_deviceExposureCompensationRange(0.0f)
748 , m_deviceIspDigitalGainRange(Argus::Range<float>(0.0f))
749 , m_sensorExposureTimeRange(Argus::Range<uint64_t>(0))
750 , m_sensorAnalogGainRange(Argus::Range<float>(0.0f))
751 , m_sensorFrameRateRange(0.0f)
752 , m_deviceIndex(new ValidatorStdVector<uint32_t, Argus::CameraDevice*>(&m_cameraDevices), 0)
753 , m_deviceOpen(false)
754 , m_sensorModeValid(false)
755 , m_verbose(false)
756 , m_kpi(false)
757 , m_exposureTimeRange(new ValidatorRange<Argus::Range<uint64_t> >(&m_sensorExposureTimeRange),
758 Argus::Range<uint64_t>(0))
759 , m_gainRange(new ValidatorRange<Argus::Range<float > >(&m_sensorAnalogGainRange),
760 Argus::Range<float>(0.0f))
761 , m_sensorModeIndex(new ValidatorEnum<uint32_t>(), 0)
762 , m_frameRate(new ValidatorRange<float>(&m_sensorFrameRateRange), 0.0f)
763 , m_focusPosition(new ValidatorRange<int32_t>(&m_deviceFocusPositionRange), 0)
764 , m_denoiseMode(new ValidatorEnum<Argus::DenoiseMode>(
765 s_denoiseModes, sizeof(s_denoiseModes) / sizeof(s_denoiseModes[0])),
766 Argus::DENOISE_MODE_FAST)
767 , m_denoiseStrength(new ValidatorRange<float>(-1.0f, 1.0f), -1.0f)
768 , m_edgeEnhanceMode(new ValidatorEnum<Argus::EdgeEnhanceMode>(
769 s_edgeEnhanceModes, sizeof(s_edgeEnhanceModes) / sizeof(s_edgeEnhanceModes[0])),
770 Argus::EDGE_ENHANCE_MODE_FAST)
771 , m_edgeEnhanceStrength(new ValidatorRange<float>(-1.0f, 1.0f), -1.0f)
772 , m_vstabMode(new ValidatorEnum<Argus::VideoStabilizationMode>(
773 s_vstabModes, sizeof(s_vstabModes) / sizeof(s_vstabModes[0])),
774 Argus::VIDEO_STABILIZATION_MODE_OFF)
775 , m_aeAntibandingMode(new ValidatorEnum<Argus::AeAntibandingMode>(
776 s_aeAntibandingModes, sizeof(s_aeAntibandingModes) / sizeof(s_aeAntibandingModes[0])),
777 Argus::AE_ANTIBANDING_MODE_AUTO)
778 , m_aeLock(false)
779 , m_awbLock(false)
780 , m_awbMode(new ValidatorEnum<Argus::AwbMode>(
781 s_awbModes, sizeof(s_awbModes) / sizeof(s_awbModes[0])),
782 Argus::AWB_MODE_AUTO)
783 , m_exposureCompensation(new ValidatorRange<float>(&m_deviceExposureCompensationRange), 0.0f)
784 , m_ispDigitalGainRange(new ValidatorRange<Argus::Range<float> >(&m_deviceIspDigitalGainRange),
785 Argus::Range<float>(1.0f))
786 , m_videoFormat(new ValidatorEnum<VideoPipeline::VideoFormat>(
787 s_videoFormats, sizeof(s_videoFormats) / sizeof(s_videoFormats[0])),
788 VideoPipeline::VIDEO_FORMAT_H264)
789 , m_videoFileType(new ValidatorEnum<VideoPipeline::VideoFileType>(
790 s_videoFileTypes, sizeof(s_videoFileTypes) / sizeof(s_videoFileTypes[0])),
791 VideoPipeline::VIDEO_FILE_TYPE_MP4)
792 , m_videoBitRate(new ValidatorRange<uint32_t>(0, VideoPipeline::VIDEO_BITRATE_MAX),0)
793 , m_outputSize(new ValidatorSize2D<uint32_t>(s_outputSizes,
794 sizeof(s_outputSizes) / sizeof(s_outputSizes[0]), true /*allowArbitrarySizes*/),
795 Argus::Size2D<uint32_t>(0, 0))
796 , m_outputPath(".")
797 , m_deFogEnable(false)
798 , m_deFogAmount(new ValidatorRange<float>(0.0f, 1.0f), 0.9f)
799 , m_deFogQuality(new ValidatorRange<float>(0.0f, 1.0f), 0.14285f)
800 , m_initialized(false)
801 , m_iCameraProvider(NULL)
802 {
803 PROPAGATE_ERROR_CONTINUE(initialize());
804 }
805
806 Dispatcher::~Dispatcher()
807 {
808 if (!shutdown())
809 REPORT_ERROR("Failed to shutdown");
810 }
811
812 Dispatcher &Dispatcher::getInstance()
813 {
814 static InitOnce initOnce;
815 static Dispatcher instance;
816
817 if (initOnce.begin())
818 {
819 if (instance.initialize())
820 {
821 initOnce.complete();
822 }
823 else
824 {
825 initOnce.failed();
826 REPORT_ERROR("Initalization failed");
827 }
828 }
829
830 return instance;
831 }
832
833 bool Dispatcher::initialize()
834 {
835 if (m_initialized)
836 return true;
837
838 // Create the CameraProvider object and obtain its interface.
839 m_cameraProvider = Argus::UniqueObj<Argus::CameraProvider>(Argus::CameraProvider::create());
840 m_iCameraProvider = Argus::interface_cast<Argus::ICameraProvider>(m_cameraProvider);
841 if (!m_iCameraProvider)
842 ORIGINATE_ERROR("Failed to create CameraProvider");
843 printf("Argus Version: %s\n", m_iCameraProvider->getVersion().c_str());
844
845 // Get the camera devices
846 m_iCameraProvider->getCameraDevices(&m_cameraDevices);
847 if (m_cameraDevices.size() == 0)
848 {
849 PROPAGATE_ERROR(shutdown());
850 ORIGINATE_ERROR("No cameras available");
851 }
852
853 m_initialized = true;
854
855 // register the device index observer after 'm_initialize' is set, the call back will be
856 // called immediately and assert that 'm_initialize' is set
857 PROPAGATE_ERROR_CONTINUE(m_deviceIndex.registerObserver(this,
858 static_cast<IObserver::CallbackFunction>(&Dispatcher::onDeviceIndexChanged)));
859 PROPAGATE_ERROR_CONTINUE(m_sensorModeIndex.registerObserver(this,
860 static_cast<IObserver::CallbackFunction>(&Dispatcher::onSensorModeIndexChanged)));
861
862 return true;
863 }
864
865 bool Dispatcher::shutdown()
866 {
867 if (m_initialized)
868 {
869 m_initialized = false;
870 // unregister the device index observer in reverse order
871 PROPAGATE_ERROR_CONTINUE(m_sensorModeIndex.unregisterObserver(this,
872 static_cast<IObserver::CallbackFunction>(&Dispatcher::onSensorModeIndexChanged)));
873 PROPAGATE_ERROR_CONTINUE(m_deviceIndex.unregisterObserver(this,
874 static_cast<IObserver::CallbackFunction>(&Dispatcher::onDeviceIndexChanged)));
875
876 PROPAGATE_ERROR_CONTINUE(closeSession());
877
878 m_cameraDevices.clear();
879 m_cameraProvider.reset();
880 }
881
882 return true;
883 }
884
885 bool Dispatcher::onDeviceIndexChanged(const Observed &source)
886 {
887 assert(static_cast<const Value<uint32_t>&>(source).get() == m_deviceIndex);
888 assert(m_initialized);
889
890 // close the currently open device
891 if (m_deviceOpen)
892 {
893 PROPAGATE_ERROR(m_deviceOpen.set(false));
894
895 PROPAGATE_ERROR(closeSession());
896
897 // reset the current device properties
898 }
899
900 // open the new device
901 const Argus::ICameraProperties *iCameraProperties =
902 Argus::interface_cast<Argus::ICameraProperties>(m_cameraDevices[m_deviceIndex]);
903 if (!iCameraProperties)
904 ORIGINATE_ERROR("Failed to get ICameraProperties interface");
905
906 // get the sensor modes
907 if (iCameraProperties->getAllSensorModes(&m_sensorModes) != Argus::STATUS_OK)
908 ORIGINATE_ERROR("Failed to get sensor modes");
909
910 if (m_sensorModes.size() == 0)
911 ORIGINATE_ERROR("No sensor modes found");
912
913 // get the focus position range
914 PROPAGATE_ERROR(m_deviceFocusPositionRange.set(iCameraProperties->getFocusPositionRange()));
915
916 // get new limits
917 Argus::Range<float> digitalGainRange = iCameraProperties->getIspDigitalGainRange();
918 Argus::Range<float> deviceExposureCompensationRange =
919 iCameraProperties->getExposureCompensationRange();
920
921
922 /* set ranges to unified range (to avoid errors when setting new values)
923 * Eg. Say Device 1 has range [-1,0] and Device 2 has range [1,2] .If current value is -1 and
924 * range is [-1,0] , setting the range to [1,2] would give error . Similarly, if current value
925 * is 1 , setting the range to [-1,0] would give error. Thus we set range to [-1,2] , set value
926 * to 1 and then set range to [1,2] to avoid errors.
927 */
928 Argus::Range<float> unifiedDigitalGainRange(0);
929 unifiedDigitalGainRange.min() =
930 std::min(m_deviceIspDigitalGainRange.get().min().min(), digitalGainRange.min());
931 unifiedDigitalGainRange.max() =
932 std::max(m_deviceIspDigitalGainRange.get().max().max(), digitalGainRange.max());
933
934 Argus::Range<float> unifiedExposureCompensationRange(0);
935 unifiedExposureCompensationRange.min() =
936 std::min(m_deviceExposureCompensationRange.get().min(),
937 deviceExposureCompensationRange.min());
938 unifiedExposureCompensationRange.max() =
939 std::max(m_deviceExposureCompensationRange.get().max(),
940 deviceExposureCompensationRange.max());
941
942 PROPAGATE_ERROR(m_deviceIspDigitalGainRange.set(
943 Argus::Range<Argus::Range<float> >(unifiedDigitalGainRange)));
944 PROPAGATE_ERROR(m_deviceExposureCompensationRange.set(
945 Argus::Range<float> (unifiedExposureCompensationRange)));
946
947 // update dependent values
948 PROPAGATE_ERROR(m_ispDigitalGainRange.set(digitalGainRange));
949 PROPAGATE_ERROR(m_exposureCompensation.set(0.0f));
950
951 // set to final range
952 PROPAGATE_ERROR(m_deviceIspDigitalGainRange.set(Argus::Range<Argus::Range<float> >(
953 digitalGainRange, digitalGainRange)));
954 PROPAGATE_ERROR(m_deviceExposureCompensationRange.set(Argus::Range<float> (
955 deviceExposureCompensationRange)));
956
957
958 // add value/string pairs for each sensor mode index
959 std::vector<ValidatorEnum<uint32_t>::ValueStringPair> valueStringPairs;
960 valueStringPairs.resize(m_sensorModes.size());
961 for (size_t index = 0; index < m_sensorModes.size(); ++index)
962 {
963 Argus::ISensorMode *sensorMode =
964 Argus::interface_cast<Argus::ISensorMode>(m_sensorModes[index]);
965
966 valueStringPairs[index].value = (uint32_t)index;
967
968 std::ostringstream stream;
969 stream << index << ": "
970 << sensorMode->getResolution().width() << "x" << sensorMode->getResolution().height();
971
972 Argus::Ext::IPwlWdrSensorMode* pwlMode =
973 Argus::interface_cast<Argus::Ext::IPwlWdrSensorMode>(m_sensorModes[index]);
974 if (pwlMode)
975 {
976 stream << " @" << sensorMode->getInputBitDepth() << "bpp -> " <<
977 sensorMode->getOutputBitDepth() << "bpp";
978 }
979 else
980 {
981 stream << " @" << sensorMode->getOutputBitDepth() << "bpp";
982 }
983 valueStringPairs[index].string = stream.str();
984 }
985 // update the validator with the new value/string pairs
986 ValidatorEnum<uint32_t> *validator =
987 static_cast<ValidatorEnum<uint32_t>*>(m_sensorModeIndex.getValidator());
988 PROPAGATE_ERROR(validator->setValidValues(valueStringPairs.data(), valueStringPairs.size()));
989
990 // set the sensor mode index (force notify observer because the sensor modes are different now
991 // although the sensor mode index could be the same)
992 PROPAGATE_ERROR(m_sensorModeIndex.set(0, true /*forceNotify*/));
993
994 PROPAGATE_ERROR(m_deviceOpen.set(true));
995
996 return true;
997 }
998
999 bool Dispatcher::onSensorModeIndexChanged(const Observed &source)
1000 {
1001 m_sensorModeValid.set(false);
1002 assert(static_cast<const Value<uint32_t>&>(source).get() == m_sensorModeIndex);
1003 assert(m_initialized);
1004
1005 Argus::ISensorMode *iSensorMode =
1006 Argus::interface_cast<Argus::ISensorMode>(m_sensorModes[m_sensorModeIndex.get()]);
1007 if (!iSensorMode)
1008 ORIGINATE_ERROR("Failed to get ISensorMode interface");
1009
1010 // get new limits
1011 Argus::Range<uint64_t> sensorExposureTimeRange = iSensorMode->getExposureTimeRange();
1012 Argus::Range<float> sensorAnalogGainRange = iSensorMode->getAnalogGainRange();
1013 Argus::Range<TimeValue> sensorFrameDurationRange(
1014 TimeValue::fromNSec(iSensorMode->getFrameDurationRange().min()),
1015 TimeValue::fromNSec(iSensorMode->getFrameDurationRange().max()));
1016 Argus::Range<float> sensorFrameRateRange(
1017 sensorFrameDurationRange.max().toCyclesPerSec(),
1018 sensorFrameDurationRange.min().toCyclesPerSec());
1019
1020 // set ranges to unified range (to avoid errors when setting new values)
1021 Argus::Range<uint64_t> unifiedSensorExposureTimeRange(0);
1022 unifiedSensorExposureTimeRange.min() =
1023 std::min(m_sensorExposureTimeRange.get().min().min(), sensorExposureTimeRange.min());
1024 unifiedSensorExposureTimeRange.max() =
1025 std::max(m_sensorExposureTimeRange.get().max().max(), sensorExposureTimeRange.max());
1026 Argus::Range<float> unifiedSensorAnalogGainRange(0);
1027 unifiedSensorAnalogGainRange.min() =
1028 std::min(m_sensorAnalogGainRange.get().min().min(), sensorAnalogGainRange.min());
1029 unifiedSensorAnalogGainRange.max() =
1030 std::max(m_sensorAnalogGainRange.get().max().max(), sensorAnalogGainRange.max());
1031 Argus::Range<float> unifiedSensorFrameRateRange(0.0f);
1032 unifiedSensorFrameRateRange.min() =
1033 std::min(m_sensorFrameRateRange.get().min(), sensorFrameRateRange.min());
1034 unifiedSensorFrameRateRange.max() =
1035 std::max(m_sensorFrameRateRange.get().max(), sensorFrameRateRange.max());
1036
1037 PROPAGATE_ERROR(m_sensorExposureTimeRange.set(
1038 Argus::Range<Argus::Range<uint64_t> >(unifiedSensorExposureTimeRange)));
1039 PROPAGATE_ERROR(m_sensorAnalogGainRange.set(
1040 Argus::Range<Argus::Range<float> >(unifiedSensorAnalogGainRange)));
1041 PROPAGATE_ERROR(m_sensorFrameRateRange.set(unifiedSensorFrameRateRange));
1042
1043 // update dependent values
1044 PROPAGATE_ERROR(m_exposureTimeRange.set(sensorExposureTimeRange));
1045 PROPAGATE_ERROR(m_gainRange.set(sensorAnalogGainRange));
1046 PROPAGATE_ERROR(m_frameRate.set(sensorFrameRateRange.max()));
1047
1048 // set to final ranges
1049 PROPAGATE_ERROR(m_sensorExposureTimeRange.set(Argus::Range<Argus::Range<uint64_t> >(
1050 sensorExposureTimeRange, sensorExposureTimeRange)));
1051 PROPAGATE_ERROR(m_sensorAnalogGainRange.set(Argus::Range<Argus::Range<float> >(
1052 sensorAnalogGainRange, sensorAnalogGainRange)));
1053 PROPAGATE_ERROR(m_sensorFrameRateRange.set(sensorFrameRateRange));
1054 m_sensorModeValid.set(true);
1055
1056 return true;
1057 }
1058
1059 bool Dispatcher::supportsExtension(const Argus::ExtensionName& extension) const
1060 {
1061 return m_iCameraProvider->supportsExtension(extension);
1062 }
1063
1064 bool Dispatcher::getInfo(std::string &info) const
1065 {
1066 std::ostringstream stream;
1067
1068 assert(m_initialized);
1069
1070 stream << "Argus extensions:" << std::endl;
1071 stream << " BayerSharpnessMap: " <<
1072 (supportsExtension(Argus::EXT_BAYER_SHARPNESS_MAP) ?
1073 "supported" : "not supported") << std::endl;
1074 stream << " DebugCaptureSession: " <<
1075 (supportsExtension(Argus::EXT_DEBUG_CAPTURE_SESSION) ?
1076 "supported" : "not supported") << std::endl;
1077 stream << " DeFog: " <<
1078 (supportsExtension(Argus::EXT_DE_FOG) ?
1079 "supported" : "not supported") << std::endl;
1080 stream << " FaceDetect: " <<
1081 (supportsExtension(Argus::EXT_FACE_DETECT) ?
1082 "supported" : "not supported") << std::endl;
1083 stream << " InternalFrameCount: " <<
1084 (supportsExtension(Argus::EXT_INTERNAL_FRAME_COUNT) ?
1085 "supported" : "not supported") << std::endl;
1086 stream << " SensorPrivateMetadata: " <<
1087 (supportsExtension(Argus::EXT_SENSOR_PRIVATE_METADATA) ?
1088 "supported" : "not supported") << std::endl;
1089
1090 stream << "Number of camera devices: " << m_cameraDevices.size() << std::endl;
1091
1092 for (uint32_t deviceIndex = 0; deviceIndex < m_cameraDevices.size(); ++deviceIndex)
1093 {
1094 stream << "Device: " << deviceIndex << std::endl;
1095
1096 const Argus::ICameraProperties *iCameraProperties =
1097 Argus::interface_cast<Argus::ICameraProperties>(m_cameraDevices[deviceIndex]);
1098 if (!iCameraProperties)
1099 ORIGINATE_ERROR("Failed to get ICameraProperties interface");
1100
1101 stream << " Max AE Regions: " <<
1102 iCameraProperties->getMaxAeRegions() << std::endl;
1103 stream << " Max AWB Regions: " <<
1104 iCameraProperties->getMaxAwbRegions() << std::endl;
1105 stream << " Focus Position Range: " <<
1106 iCameraProperties->getFocusPositionRange().min() << " - " <<
1107 iCameraProperties->getFocusPositionRange().max() << std::endl;
1108 stream << " Lens Aperture Range: " <<
1109 iCameraProperties->getLensApertureRange().min() << " - " <<
1110 iCameraProperties->getLensApertureRange().max() << std::endl;
1111 stream << " Isp Digital Gain Range: " <<
1112 iCameraProperties->getIspDigitalGainRange().min() << " - " <<
1113 iCameraProperties->getIspDigitalGainRange().max() << std::endl;
1114
1115 // print the sensor modes
1116 std::vector<Argus::SensorMode*> sensorModes;
1117 iCameraProperties->getAllSensorModes(&sensorModes);
1118 stream << " Number of sensor modes: " << sensorModes.size() << std::endl;
1119 for (uint32_t sensorModeIndex = 0; sensorModeIndex < sensorModes.size(); ++sensorModeIndex)
1120 {
1121 Argus::ISensorMode *sensorMode =
1122 Argus::interface_cast<Argus::ISensorMode>(sensorModes[sensorModeIndex]);
1123 if (!sensorMode)
1124 ORIGINATE_ERROR("Failed to get ISensorMode interface");
1125
1126 // convert ns to fps
1127 float maximum_fps = TimeValue::fromNSec(
1128 sensorMode->getFrameDurationRange().min()).toCyclesPerSec();
1129 float minimum_fps = TimeValue::fromNSec(
1130 sensorMode->getFrameDurationRange().max()).toCyclesPerSec();
1131
1132 stream << " Sensor mode: " << sensorModeIndex << std::endl;
1133 stream << " Resolution: " <<
1134 sensorMode->getResolution().width() << "x" <<
1135 sensorMode->getResolution().height() << std::endl;
1136 stream << " Exposure time range: " <<
1137 sensorMode->getExposureTimeRange().min() << " - " <<
1138 sensorMode->getExposureTimeRange().max() << " ns" << std::endl;
1139 stream << " Frame duration range: " <<
1140 sensorMode->getFrameDurationRange().min() << " - " <<
1141 sensorMode->getFrameDurationRange().max() << " ns" << std::endl;
1142 stream << " Framerate range: " <<
1143 minimum_fps << " - " <<
1144 maximum_fps << " fps" << std::endl;
1145 stream << " InputBitDepth: " <<
1146 sensorMode->getInputBitDepth() << std::endl;
1147 stream << " OutputBitDepth: " <<
1148 sensorMode->getOutputBitDepth() << std::endl;
1149 stream << " Analog gain range: " <<
1150 sensorMode->getAnalogGainRange().min() << " - " <<
1151 sensorMode->getAnalogGainRange().max() << std::endl;
1152
1153 stream << " SensorModeType: " <<
1154 sensorMode->getSensorModeType().getName() << std::endl;
1155
1156 Argus::Ext::IPwlWdrSensorMode* pwlMode =
1157 Argus::interface_cast<Argus::Ext::IPwlWdrSensorMode>(sensorModes[sensorModeIndex]);
1158 if (pwlMode)
1159 {
1160 stream << " Piecewise Linear WDR Extension supported with: " <<
1161 pwlMode->getControlPointCount() << " control points." << std::endl;
1162 std::vector< Argus::Point2D<float> > points;
1163 Argus::Status status = pwlMode->getControlPoints(&points);
1164 if (status != Argus::STATUS_OK)
1165 ORIGINATE_ERROR("Error obtaining control points");
1166 stream << " Control Points: " << std::endl;
1167 for (uint32_t j = 0; j < pwlMode->getControlPointCount(); j++)
1168 {
1169 stream << " (" << points[j].x() << ", " <<
1170 points[j].y() << ")" << std::endl;
1171 }
1172 }
1173
1174 stream << std::endl;
1175 }
1176 }
1177
1178 info = stream.str();
1179
1180 return true;
1181 }
1182
1183 bool Dispatcher::getSensorMode(uint32_t sensorModeIndex, Argus::SensorMode **sensorMode) const
1184 {
1185 assert(m_deviceOpen);
1186
1187 if (sensorModeIndex >= m_sensorModes.size())
1188 ORIGINATE_ERROR("Invalid sensor mode index");
1189
1190 *sensorMode = m_sensorModes[sensorModeIndex];
1191
1192 return true;
1193 }
1194
1195 Argus::Range<int32_t> Dispatcher::getDeviceFocusPositionRange() const
1196 {
1197 return m_deviceFocusPositionRange.get();
1198 }
1199
1200 uint32_t Dispatcher::getDeviceCount() const
1201 {
1202 assert(m_deviceOpen);
1203
1204 return m_cameraDevices.size();
1205 }
1206
1207 bool Dispatcher::createSession(TrackedUniqueObj<Argus::CaptureSession> &session,
1208 uint32_t deviceIndex)
1209 {
1210 assert(m_deviceOpen);
1211
1212 if (deviceIndex > m_cameraDevices.size())
1213 ORIGINATE_ERROR("Invalid device index");
1214
1215 // close the internal session, it might be using the device which will be used by the new
1216 // session
1217 PROPAGATE_ERROR(closeSession());
1218
1219 // create the new capture session
1220 Argus::UniqueObj<Argus::CaptureSession> newSession(
1221 m_iCameraProvider->createCaptureSession(m_cameraDevices[deviceIndex]));
1222 if (!newSession)
1223 ORIGINATE_ERROR("Failed to create CaptureSession");
1224
1225 PROPAGATE_ERROR(session.reset(newSession.release(), this));
1226
1227 return true;
1228 }
1229
1230 bool Dispatcher::dumpSessionInfo() const
1231 {
1232 for (ActiveSessionList::const_iterator it = m_activeSessions.begin(); it != m_activeSessions.end();
1233 ++it)
1234 {
1235 Argus::Ext::IDebugCaptureSession *iDebugCaptureSession =
1236 Argus::interface_cast<Argus::Ext::IDebugCaptureSession>(it->m_session);
1237 if (!iDebugCaptureSession)
1238 ORIGINATE_ERROR("DebugCaptureSession extension not supported");
1239
1240 const Argus::Status status = iDebugCaptureSession->dump(STDOUT_FILENO);
1241 if (status != Argus::STATUS_OK)
1242 ORIGINATE_ERROR("Failed to get dump runtime info");
1243 }
1244
1245 return true;
1246 }
1247
1248 /**
1249 * Create the internal session
1250 */
1251 bool Dispatcher::createSession()
1252 {
1253 if (m_captureSession)
1254 return true;
1255
1256 PROPAGATE_ERROR(createSession(m_captureSession, m_deviceIndex));
1257
1258 return true;
1259 }
1260
1261 /**
1262 * Close the internal session
1263 */
1264 bool Dispatcher::closeSession()
1265 {
1266 m_captureSession.reset();
1267 return true;
1268 }
1269
1270 bool Dispatcher::track(Argus::CaptureSession *session)
1271 {
1272 m_activeSessions.push_back(ActiveSession(session));
1273 return true;
1274 }
1275
1276 bool Dispatcher::untrack(Argus::CaptureSession *session)
1277 {
1278 for (ActiveSessionList::iterator it = m_activeSessions.begin(); it != m_activeSessions.end();
1279 ++it)
1280 {
1281 if (it->m_session == session)
1282 {
1283 m_activeSessions.erase(it);
1284 return true;
1285 }
1286 }
1287
1288 ORIGINATE_ERROR("Session not found");
1289 }
1290
1291 bool Dispatcher::waitForEvents(Argus::EventQueue *eventQueue, TimeValue timeout,
1292 Argus::CaptureSession *session)
1293 {
1294 if (!session)
1295 {
1296 // use the internal session
1297 PROPAGATE_ERROR(createSession());
1298 session = m_captureSession.get();
1299 }
1300
1301 Argus::IEventProvider *iEventProvider = Argus::interface_cast<Argus::IEventProvider>(session);
1302 if (!iEventProvider)
1303 ORIGINATE_ERROR("Failed to get iEventProvider interface");
1304
1305 // wait for the events
1306 const Argus::Status status = iEventProvider->waitForEvents(eventQueue, timeout.toNSec());
1307 if ((status != Argus::STATUS_OK) && (status != Argus::STATUS_TIMEOUT))
1308 ORIGINATE_ERROR("Failed to get events");
1309
1310 return true;
1311 }
1312
1313 bool Dispatcher::createRequest(TrackedUniqueObj<Argus::Request> &request,
1314 Argus::CaptureIntent captureIntent, Argus::CaptureSession *session)
1315 {
1316 if (!session)
1317 {
1318 // use the internal session
1319 PROPAGATE_ERROR(createSession());
1320 session = m_captureSession.get();
1321 }
1322
1323 Argus::ICaptureSession *iCaptureSession =
1324 Argus::interface_cast<Argus::ICaptureSession>(session);
1325 if (!iCaptureSession)
1326 ORIGINATE_ERROR("Failed to get ICaptureSession interface");
1327
1328 // Create request
1329 Argus::UniqueObj<Argus::Request> newRequest =
1330 Argus::UniqueObj<Argus::Request>(iCaptureSession->createRequest(captureIntent));
1331 if (!newRequest)
1332 ORIGINATE_ERROR("Failed to create request");
1333
1334 // Setup request
1335 Argus::IRequest *iRequest = Argus::interface_cast<Argus::IRequest>(newRequest);
1336 if (!iRequest)
1337 ORIGINATE_ERROR("Failed to get IRequest interface");
1338
1339 // get source settings interface
1340 Argus::ISourceSettings *iSourceSettings =
1341 Argus::interface_cast<Argus::ISourceSettings>(iRequest->getSourceSettings());
1342 if (!iSourceSettings)
1343 ORIGINATE_ERROR("Failed to get ISourceSettings interface");
1344
1345 // register the source settings observer
1346 PROPAGATE_ERROR(registerObserver(iSourceSettings));
1347
1348 // get auto control settings interface
1349 Argus::IAutoControlSettings *iAutoControlSettings =
1350 Argus::interface_cast<Argus::IAutoControlSettings>(iRequest->getAutoControlSettings());
1351 if (!iAutoControlSettings)
1352 ORIGINATE_ERROR("Failed to get IAutoControlSettings interface");
1353
1354 // register the auto control settings observer
1355 PROPAGATE_ERROR(registerObserver(iAutoControlSettings));
1356
1357 // register denoise settings interface
1358 Argus::IDenoiseSettings *iDenoiseSettings =
1359 Argus::interface_cast<Argus::IDenoiseSettings>(newRequest);
1360 if (!iDenoiseSettings)
1361 ORIGINATE_ERROR("Failed to get IDenoiseSettings interface");
1362 PROPAGATE_ERROR(registerObserver(iDenoiseSettings));
1363
1364 // register edge enhance settings interface
1365 Argus::IEdgeEnhanceSettings *iEdgeEnhanceSettings =
1366 Argus::interface_cast<Argus::IEdgeEnhanceSettings>(newRequest);
1367 if (!iEdgeEnhanceSettings)
1368 ORIGINATE_ERROR("Failed to get IEdgeEnhanceSettings interface");
1369 PROPAGATE_ERROR(registerObserver(iEdgeEnhanceSettings));
1370
1371 // register video stabilization settings interface
1372 Argus::IVideoStabilizationSettings *iVideoStabilizationSettings =
1373 Argus::interface_cast<Argus::IVideoStabilizationSettings>(newRequest);
1374 if (!iVideoStabilizationSettings)
1375 ORIGINATE_ERROR("Failed to get IVideoStabilizationSettings interface");
1376 PROPAGATE_ERROR(registerObserver(iVideoStabilizationSettings));
1377
1378 if (supportsExtension(Argus::EXT_DE_FOG))
1379 {
1380 // get DeFog settings interface
1381 Argus::Ext::IDeFogSettings *iDeFogSettings =
1382 Argus::interface_cast<Argus::Ext::IDeFogSettings>(newRequest);
1383 if (iDeFogSettings)
1384 {
1385 // register the DeFog settings observer
1386 PROPAGATE_ERROR(registerObserver(iDeFogSettings));
1387 }
1388 }
1389
1390 PROPAGATE_ERROR(request.reset(newRequest.release(), this));
1391
1392 return true;
1393 }
1394
1395 bool Dispatcher::track(Argus::Request *request)
1396 {
1397 return true;
1398 }
1399
1400 bool Dispatcher::untrack(Argus::Request *request)
1401 {
1402 Argus::IRequest *iRequest = Argus::interface_cast<Argus::IRequest>(request);
1403 if (!iRequest)
1404 ORIGINATE_ERROR("Failed to get IRequest interface");
1405
1406 // get source settings interface
1407 Argus::ISourceSettings *iSourceSettings =
1408 Argus::interface_cast<Argus::ISourceSettings>(iRequest->getSourceSettings());
1409 if (!iSourceSettings)
1410 ORIGINATE_ERROR("Failed to get ISourceSettings interface");
1411
1412 // unregister the source settings observer
1413 PROPAGATE_ERROR(unregisterObserver(iSourceSettings));
1414
1415 // get auto control settings interface
1416 Argus::IAutoControlSettings *iAutoControlSettings =
1417 Argus::interface_cast<Argus::IAutoControlSettings>(iRequest->getAutoControlSettings());
1418 if (!iAutoControlSettings)
1419 ORIGINATE_ERROR("Failed to get IAutoControlSettings interface");
1420
1421 // unregister the auto control settings observer
1422 PROPAGATE_ERROR(unregisterObserver(iAutoControlSettings));
1423
1424 // unregister denoise settings interface
1425 Argus::IDenoiseSettings *iDenoiseSettings =
1426 Argus::interface_cast<Argus::IDenoiseSettings>(request);
1427 if (!iDenoiseSettings)
1428 ORIGINATE_ERROR("Failed to get IDenoiseSettings interface");
1429 PROPAGATE_ERROR(unregisterObserver(iDenoiseSettings));
1430
1431 // unregister edge enhance settings interface
1432 Argus::IEdgeEnhanceSettings *iEdgeEnhanceSettings =
1433 Argus::interface_cast<Argus::IEdgeEnhanceSettings>(request);
1434 if (!iEdgeEnhanceSettings)
1435 ORIGINATE_ERROR("Failed to get IEdgeEnhanceSettings interface");
1436 PROPAGATE_ERROR(unregisterObserver(iEdgeEnhanceSettings));
1437
1438 // unregister video stabilization settings interface
1439 Argus::IVideoStabilizationSettings *iVideoStabilizationSettings =
1440 Argus::interface_cast<Argus::IVideoStabilizationSettings>(request);
1441 if (!iVideoStabilizationSettings)
1442 ORIGINATE_ERROR("Failed to get IVideoStabilizationSettings interface");
1443 PROPAGATE_ERROR(unregisterObserver(iVideoStabilizationSettings));
1444
1445 if (supportsExtension(Argus::EXT_DE_FOG))
1446 {
1447 // get DeFog settings interface
1448 Argus::Ext::IDeFogSettings *iDeFogSettings =
1449 Argus::interface_cast<Argus::Ext::IDeFogSettings>(request);
1450 if (iDeFogSettings)
1451 {
1452 // unregister the DeFog settings observer
1453 PROPAGATE_ERROR(unregisterObserver(iDeFogSettings));
1454 }
1455 }
1456
1457 return true;
1458 }
1459
1460 bool Dispatcher::createEventQueue(const std::vector<Argus::EventType> &eventTypes,
1461 Argus::UniqueObj<Argus::EventQueue>& eventQueue, Argus::CaptureSession *session)
1462 {
1463 if (!session)
1464 {
1465 // use the internal session
1466 PROPAGATE_ERROR(createSession());
1467 session = m_captureSession.get();
1468 }
1469
1470 Argus::IEventProvider *iEventProvider =
1471 Argus::interface_cast<Argus::IEventProvider>(session);
1472 if (!iEventProvider)
1473 ORIGINATE_ERROR("Failed to get IEventProvider interface");
1474
1475 Argus::EventQueue *newEventQueue = iEventProvider->createEventQueue(eventTypes);
1476 if (!newEventQueue)
1477 ORIGINATE_ERROR("Failed to create eventQueue");
1478
1479 eventQueue.reset(newEventQueue);
1480
1481 return true;
1482 }
1483
1484 bool Dispatcher::capture(Argus::Request *request, Argus::CaptureSession *session)
1485 {
1486 if (!session)
1487 {
1488 // use the internal session
1489 PROPAGATE_ERROR(createSession());
1490 session = m_captureSession.get();
1491 }
1492
1493 Argus::ICaptureSession *iCaptureSession =
1494 Argus::interface_cast<Argus::ICaptureSession>(session);
1495 if (!iCaptureSession)
1496 ORIGINATE_ERROR("Failed to get ICaptureSession interface");
1497
1498 if (iCaptureSession->capture(request, Argus::TIMEOUT_INFINITE) == 0)
1499 ORIGINATE_ERROR("Failed to submit the still capture request");
1500
1501 return true;
1502 }
1503
1504 bool Dispatcher::startRepeat(Argus::Request *request, Argus::CaptureSession *session)
1505 {
1506 if (!session)
1507 {
1508 // use the internal session
1509 PROPAGATE_ERROR(createSession());
1510 session = m_captureSession.get();
1511 }
1512
1513 Argus::ICaptureSession *iCaptureSession =
1514 Argus::interface_cast<Argus::ICaptureSession>(session);
1515 if (!iCaptureSession)
1516 ORIGINATE_ERROR("Failed to get ICaptureSession interface");
1517
1518 if (iCaptureSession->repeat(request) != Argus::STATUS_OK)
1519 ORIGINATE_ERROR("Failed to submit repeating capture request");
1520
1521 // add the request to the list of active requests for the session
1522 bool found = false;
1523 for (ActiveSessionList::iterator it = m_activeSessions.begin(); it != m_activeSessions.end();
1524 ++it)
1525 {
1526 if (it->m_session == session)
1527 {
1528 it->m_requests.push_back(request);
1529 found = true;
1530 break;
1531 }
1532 }
1533 if (!found)
1534 ORIGINATE_ERROR("Did not find the session in the list of active sessions");
1535
1536 return true;
1537 }
1538
1539 bool Dispatcher::startRepeatBurst(const std::vector<const Argus::Request*>& requestList,
1540 Argus::CaptureSession *session)
1541 {
1542 if (!session)
1543 {
1544 // use the internal session
1545 PROPAGATE_ERROR(createSession());
1546 session = m_captureSession.get();
1547 }
1548
1549 Argus::ICaptureSession *iCaptureSession =
1550 Argus::interface_cast<Argus::ICaptureSession>(session);
1551 if (!iCaptureSession)
1552 ORIGINATE_ERROR("Failed to get ICaptureSession interface");
1553
1554 if (iCaptureSession->repeatBurst(requestList) != Argus::STATUS_OK)
1555 ORIGINATE_ERROR("Failed to submit repeating burst request");
1556
1557 // add the requests to the list of active requests for the session
1558 bool found = false;
1559 for (ActiveSessionList::iterator it = m_activeSessions.begin(); it != m_activeSessions.end();
1560 ++it)
1561 {
1562 if (it->m_session == session)
1563 {
1564 it->m_requests.insert(it->m_requests.end(), requestList.begin(), requestList.end());
1565 found = true;
1566 break;
1567 }
1568 }
1569 if (!found)
1570 ORIGINATE_ERROR("Did not find the session in the list of active sessions");
1571
1572 return true;
1573 }
1574
1575 bool Dispatcher::stopRepeat(Argus::CaptureSession *session)
1576 {
1577 if (!session)
1578 {
1579 // use the internal session
1580 PROPAGATE_ERROR(createSession());
1581 session = m_captureSession.get();
1582 }
1583
1584 Argus::ICaptureSession *iCaptureSession =
1585 Argus::interface_cast<Argus::ICaptureSession>(session);
1586 if (!iCaptureSession)
1587 ORIGINATE_ERROR("Failed to get ICaptureSession interface");
1588
1589 iCaptureSession->stopRepeat();
1590
1591 // clear the list of active requests for the session
1592 bool found = false;
1593 for (ActiveSessionList::iterator it = m_activeSessions.begin(); it != m_activeSessions.end();
1594 ++it)
1595 {
1596 if (it->m_session == session)
1597 {
1598 it->m_requests.clear();
1599 found = true;
1600 break;
1601 }
1602 }
1603 if (!found)
1604 ORIGINATE_ERROR("Did not find the session in the list of active sessions");
1605
1606 return true;
1607 }
1608
1609 bool Dispatcher::restartActiveRequests()
1610 {
1611 for (ActiveSessionList::iterator it = m_activeSessions.begin(); it != m_activeSessions.end();
1612 ++it)
1613 {
1614 if (!it->m_requests.empty())
1615 {
1616 Argus::ICaptureSession *iCaptureSession =
1617 Argus::interface_cast<Argus::ICaptureSession>(it->m_session);
1618 if (!iCaptureSession)
1619 ORIGINATE_ERROR("Failed to get ICaptureSession interface");
1620
1621 iCaptureSession->stopRepeat();
1622
1623 if (iCaptureSession->repeatBurst(it->m_requests) != Argus::STATUS_OK)
1624 ORIGINATE_ERROR("Failed to submit repeating burst request");
1625 }
1626 }
1627
1628 return true;
1629 }
1630
1631 uint32_t Dispatcher::maxBurstRequests(Argus::CaptureSession *session)
1632 {
1633 if (!session)
1634 {
1635 // use the internal session
1636 PROPAGATE_ERROR(createSession());
1637 session = m_captureSession.get();
1638 }
1639
1640 Argus::ICaptureSession *iCaptureSession =
1641 Argus::interface_cast<Argus::ICaptureSession>(session);
1642 if (!iCaptureSession)
1643 {
1644 REPORT_ERROR("Failed to get ICaptureSession interface");
1645 return 0;
1646 }
1647
1648 return iCaptureSession->maxBurstRequests();
1649 }
1650
1651 bool Dispatcher::waitForIdle(Argus::CaptureSession *session)
1652 {
1653 if (!session)
1654 {
1655 // use the internal session
1656 PROPAGATE_ERROR(createSession());
1657 session = m_captureSession.get();
1658 }
1659
1660 Argus::ICaptureSession *iCaptureSession =
1661 Argus::interface_cast<Argus::ICaptureSession>(session);
1662 if (!iCaptureSession)
1663 ORIGINATE_ERROR("Failed to get ICaptureSession interface");
1664
1665 if (iCaptureSession->waitForIdle() != Argus::STATUS_OK)
1666 ORIGINATE_ERROR("Waiting for idle failed");
1667
1668 return true;
1669 }
1670
1671 bool Dispatcher::getOutputSize(Argus::Size2D<uint32_t> *size) const
1672 {
1673 // if width or height is 0 take the sensor size
1674 if ((m_outputSize.get().width() == 0) || (m_outputSize.get().height() == 0))
1675 {
1676 // the device needs to be open to get sensor modes
1677 assert(m_deviceOpen);
1678
1679 Argus::ISensorMode *sensorMode =
1680 Argus::interface_cast<Argus::ISensorMode>(m_sensorModes[m_sensorModeIndex.get()]);
1681 if (!sensorMode)
1682 ORIGINATE_ERROR("Failed to get ISensorMode interface");
1683 *size = sensorMode->getResolution();
1684 }
1685 else
1686 {
1687 *size = m_outputSize;
1688 }
1689
1690 return true;
1691 }
1692
1693 bool Dispatcher::createOutputStream(Argus::Request *request, bool enableMetadata,
1694 Argus::UniqueObj<Argus::OutputStream> &stream, Argus::CaptureSession *session)
1695 {
1696 if (!session)
1697 {
1698 // use the internal session
1699 PROPAGATE_ERROR(createSession());
1700 session = m_captureSession.get();
1701 }
1702
1703 Argus::IRequest *iRequest = Argus::interface_cast<Argus::IRequest>(request);
1704 if (!iRequest)
1705 ORIGINATE_ERROR("Failed to get IRequest interface");
1706
1707 Argus::Size2D<uint32_t> outputSize;
1708 PROPAGATE_ERROR(getOutputSize(&outputSize));
1709
1710 Argus::ICaptureSession *iCaptureSession =
1711 Argus::interface_cast<Argus::ICaptureSession>(session);
1712 if (!iCaptureSession)
1713 ORIGINATE_ERROR("Failed to get ICaptureSession interface");
1714
1715 Argus::UniqueObj<Argus::OutputStreamSettings> outputStreamSettings(
1716 iCaptureSession->createOutputStreamSettings());
1717 Argus::IOutputStreamSettings* iOutputStreamSettings =
1718 Argus::interface_cast<Argus::IOutputStreamSettings>(outputStreamSettings);
1719 if (!iOutputStreamSettings)
1720 ORIGINATE_ERROR("Failed to get IOutputStreamSettings interface");
1721
1722 iOutputStreamSettings->setPixelFormat(Argus::PIXEL_FMT_YCbCr_420_888);
1723 iOutputStreamSettings->setResolution(outputSize);
1724 iOutputStreamSettings->setEGLDisplay(Composer::getInstance().getEGLDisplay());
1725 iOutputStreamSettings->setMetadataEnable(enableMetadata);
1726
1727 Argus::UniqueObj<Argus::OutputStream> outputStream(
1728 iCaptureSession->createOutputStream(outputStreamSettings.get()));
1729 if (!outputStream)
1730 ORIGINATE_ERROR("Failed to create OutputStream");
1731
1732 stream.reset(outputStream.release());
1733
1734 return true;
1735 }
1736
1737 bool Dispatcher::enableOutputStream(Argus::Request *request, Argus::OutputStream *stream)
1738 {
1739 Argus::IRequest *iRequest = Argus::interface_cast<Argus::IRequest>(request);
1740 if (!iRequest)
1741 ORIGINATE_ERROR("Failed to get IRequest interface");
1742
1743 // Enable the stream
1744 if (iRequest->enableOutputStream(stream) != Argus::STATUS_OK)
1745 ORIGINATE_ERROR("Failed to enable the output stream");
1746
1747 return true;
1748 }
1749
1750 bool Dispatcher::disableOutputStream(Argus::Request *request, Argus::OutputStream *stream)
1751 {
1752 Argus::IRequest *iRequest = Argus::interface_cast<Argus::IRequest>(request);
1753 if (!iRequest)
1754 ORIGINATE_ERROR("Failed to get IRequest interface");
1755
1756 // Disable the stream
1757 if (iRequest->disableOutputStream(stream) != Argus::STATUS_OK)
1758 ORIGINATE_ERROR("Failed to disable the output stream");
1759
1760 return true;
1761 }
1762
1763 bool Dispatcher::registerObserver(Argus::IDenoiseSettings *iDenoiseSettings)
1764 {
1765 UniquePointer<DenoiseSettingsObserver> denoiseSettings;
1766
1767 denoiseSettings.reset(new DenoiseSettingsObserver(iDenoiseSettings));
1768 if (!denoiseSettings)
1769 ORIGINATE_ERROR("Out of memory");
1770
1771 m_observers.push_front(denoiseSettings.release());
1772 return true;
1773 }
1774
1775 bool Dispatcher::registerObserver(Argus::IEdgeEnhanceSettings *iEdgeEnhanceSettings)
1776 {
1777 UniquePointer<EdgeEnhanceSettingsObserver> edgeEnhanceSettings;
1778
1779 edgeEnhanceSettings.reset(new EdgeEnhanceSettingsObserver(iEdgeEnhanceSettings));
1780 if (!edgeEnhanceSettings)
1781 ORIGINATE_ERROR("Out of memory");
1782
1783 m_observers.push_front(edgeEnhanceSettings.release());
1784 return true;
1785 }
1786
1787 bool Dispatcher::registerObserver(Argus::IVideoStabilizationSettings *iVideoStabilizationSettings)
1788 {
1789 UniquePointer<VideoStabilizationSettingsObserver> vStabSettings;
1790
1791 vStabSettings.reset(new VideoStabilizationSettingsObserver(iVideoStabilizationSettings));
1792 if (!vStabSettings)
1793 ORIGINATE_ERROR("Out of memory");
1794
1795 m_observers.push_front(vStabSettings.release());
1796 return true;
1797 }
1798
1799 bool Dispatcher::registerObserver(Argus::ISourceSettings *iSourceSettings)
1800 {
1801 UniquePointer<SourceSettingsObserver> sourceSettings;
1802
1803 sourceSettings.reset(new SourceSettingsObserver(iSourceSettings));
1804 if (!sourceSettings)
1805 ORIGINATE_ERROR("Out of memory");
1806
1807 m_observers.push_front(sourceSettings.release());
1808 return true;
1809 }
1810
1811 bool Dispatcher::registerObserver(Argus::IAutoControlSettings *iAutoControlSettings)
1812 {
1813 UniquePointer<AutoControlSettingsObserver> autoControlSettings;
1814
1815 autoControlSettings.reset(new AutoControlSettingsObserver(iAutoControlSettings));
1816 if (!autoControlSettings)
1817 ORIGINATE_ERROR("Out of memory");
1818
1819 m_observers.push_front(autoControlSettings.release());
1820 return true;
1821 }
1822
1823 bool Dispatcher::registerObserver(Argus::Ext::IDeFogSettings *iDeFogSettings)
1824 {
1825 UniquePointer<DeFogSettingsObserver> deFogSettings;
1826
1827 deFogSettings.reset(new DeFogSettingsObserver(iDeFogSettings));
1828 if (!deFogSettings)
1829 ORIGINATE_ERROR("Out of memory");
1830
1831 m_observers.push_front(deFogSettings.release());
1832 return true;
1833 }
1834
1835 bool Dispatcher::unregisterObserver(Argus::Interface *interface)
1836 {
1837 for (std::list<IObserverForInterface*>::iterator it = m_observers.begin();
1838 it != m_observers.end(); ++it)
1839 {
1840 if ((*it)->isInterface(interface))
1841 {
1842 delete *it;
1843 m_observers.erase(it);
1844 return true;
1845 }
1846 }
1847
1848 ORIGINATE_ERROR("Observer not found");
1849 }
1850
1851 bool Dispatcher::message(const char *msg, ...)
1852 {
1853 if (m_verbose)
1854 {
1855 va_list list;
1856
1857 va_start(list, msg);
1858
1859 if (vprintf(msg, list) < 0)
1860 {
1861 va_end(list);
1862 ORIGINATE_ERROR("Failed to print message");
1863 }
1864
1865 va_end(list);
1866 }
1867
1868 return true;
1869 }
1870
1871 }; // namespace ArgusSamples