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 };
722
723 // valid video file types
724 static const ValidatorEnum<VideoPipeline::VideoFileType>::ValueStringPair s_videoFileTypes[] =
725 {
726 { VideoPipeline::VIDEO_FILE_TYPE_MP4, "mp4" },
727 { VideoPipeline::VIDEO_FILE_TYPE_3GP, "3gp" },
728 { VideoPipeline::VIDEO_FILE_TYPE_AVI, "avi" },
729 { VideoPipeline::VIDEO_FILE_TYPE_MKV, "mkv" },
730 { VideoPipeline::VIDEO_FILE_TYPE_H265, "h265" }
731 };
732
733 static const Argus::Size2D<uint32_t> s_outputSizes[] =
734 {
735 Argus::Size2D<uint32_t>(0, 0), // if size is 0,0 take the current sensor size
736 Argus::Size2D<uint32_t>(176, 144), // QCIF
737 Argus::Size2D<uint32_t>(320, 240),
738 Argus::Size2D<uint32_t>(640, 480),
739 Argus::Size2D<uint32_t>(1280, 720), // 720p HDTV
740 Argus::Size2D<uint32_t>(1920, 1080), // 1080p HDTV
741 Argus::Size2D<uint32_t>(3840, 2160), // 2160p 4K UHDTV
742 };
743
744 Dispatcher::Dispatcher()
745 : m_deviceFocusPositionRange(0)
746 , m_deviceExposureCompensationRange(0.0f)
747 , m_deviceIspDigitalGainRange(Argus::Range<float>(0.0f))
748 , m_sensorExposureTimeRange(Argus::Range<uint64_t>(0))
749 , m_sensorAnalogGainRange(Argus::Range<float>(0.0f))
750 , m_sensorFrameRateRange(0.0f)
751 , m_deviceIndex(new ValidatorStdVector<uint32_t, Argus::CameraDevice*>(&m_cameraDevices), 0)
752 , m_deviceOpen(false)
753 , m_verbose(false)
754 , m_kpi(false)
755 , m_exposureTimeRange(new ValidatorRange<Argus::Range<uint64_t> >(&m_sensorExposureTimeRange),
756 Argus::Range<uint64_t>(0))
757 , m_gainRange(new ValidatorRange<Argus::Range<float > >(&m_sensorAnalogGainRange),
758 Argus::Range<float>(0.0f))
759 , m_sensorModeIndex(new ValidatorEnum<uint32_t>(), 0)
760 , m_frameRate(new ValidatorRange<float>(&m_sensorFrameRateRange), 0.0f)
761 , m_focusPosition(new ValidatorRange<int32_t>(&m_deviceFocusPositionRange), 0)
762 , m_denoiseMode(new ValidatorEnum<Argus::DenoiseMode>(
763 s_denoiseModes, sizeof(s_denoiseModes) / sizeof(s_denoiseModes[0])),
764 Argus::DENOISE_MODE_FAST)
765 , m_denoiseStrength(new ValidatorRange<float>(-1.0f, 1.0f), -1.0f)
766 , m_edgeEnhanceMode(new ValidatorEnum<Argus::EdgeEnhanceMode>(
767 s_edgeEnhanceModes, sizeof(s_edgeEnhanceModes) / sizeof(s_edgeEnhanceModes[0])),
768 Argus::EDGE_ENHANCE_MODE_FAST)
769 , m_edgeEnhanceStrength(new ValidatorRange<float>(-1.0f, 1.0f), -1.0f)
770 , m_vstabMode(new ValidatorEnum<Argus::VideoStabilizationMode>(
771 s_vstabModes, sizeof(s_vstabModes) / sizeof(s_vstabModes[0])),
772 Argus::VIDEO_STABILIZATION_MODE_OFF)
773 , m_aeAntibandingMode(new ValidatorEnum<Argus::AeAntibandingMode>(
774 s_aeAntibandingModes, sizeof(s_aeAntibandingModes) / sizeof(s_aeAntibandingModes[0])),
775 Argus::AE_ANTIBANDING_MODE_AUTO)
776 , m_aeLock(false)
777 , m_awbLock(false)
778 , m_awbMode(new ValidatorEnum<Argus::AwbMode>(
779 s_awbModes, sizeof(s_awbModes) / sizeof(s_awbModes[0])),
780 Argus::AWB_MODE_AUTO)
781 , m_exposureCompensation(new ValidatorRange<float>(&m_deviceExposureCompensationRange), 0.0f)
782 , m_ispDigitalGainRange(new ValidatorRange<Argus::Range<float> >(&m_deviceIspDigitalGainRange),
783 Argus::Range<float>(1.0f))
784 , m_videoFormat(new ValidatorEnum<VideoPipeline::VideoFormat>(
785 s_videoFormats, sizeof(s_videoFormats) / sizeof(s_videoFormats[0])),
786 VideoPipeline::VIDEO_FORMAT_H264)
787 , m_videoFileType(new ValidatorEnum<VideoPipeline::VideoFileType>(
788 s_videoFileTypes, sizeof(s_videoFileTypes) / sizeof(s_videoFileTypes[0])),
789 VideoPipeline::VIDEO_FILE_TYPE_MP4)
790 , m_videoBitRate(new ValidatorRange<uint32_t>(0, std::numeric_limits<uint32_t>::max()), 0)
791 , m_outputSize(new ValidatorSize2D<uint32_t>(s_outputSizes,
792 sizeof(s_outputSizes) / sizeof(s_outputSizes[0]), true /*allowArbitrarySizes*/),
793 Argus::Size2D<uint32_t>(0, 0))
794 , m_outputPath(".")
795 , m_deFogEnable(false)
796 , m_deFogAmount(new ValidatorRange<float>(0.0f, 1.0f), 0.9f)
797 , m_deFogQuality(new ValidatorRange<float>(0.0f, 1.0f), 0.14285f)
798 , m_initialized(false)
799 , m_iCameraProvider(NULL)
800 {
801 PROPAGATE_ERROR_CONTINUE(initialize());
802 }
803
804 Dispatcher::~Dispatcher()
805 {
806 if (!shutdown())
807 REPORT_ERROR("Failed to shutdown");
808 }
809
810 Dispatcher &Dispatcher::getInstance()
811 {
812 static InitOnce initOnce;
813 static Dispatcher instance;
814
815 if (initOnce.begin())
816 {
817 if (instance.initialize())
818 {
819 initOnce.complete();
820 }
821 else
822 {
823 initOnce.failed();
824 REPORT_ERROR("Initalization failed");
825 }
826 }
827
828 return instance;
829 }
830
831 bool Dispatcher::initialize()
832 {
833 if (m_initialized)
834 return true;
835
836 // Create the CameraProvider object and obtain its interface.
837 m_cameraProvider = Argus::UniqueObj<Argus::CameraProvider>(Argus::CameraProvider::create());
838 m_iCameraProvider = Argus::interface_cast<Argus::ICameraProvider>(m_cameraProvider);
839 if (!m_iCameraProvider)
840 ORIGINATE_ERROR("Failed to create CameraProvider");
841 printf("Argus Version: %s\n", m_iCameraProvider->getVersion().c_str());
842
843 // Get the camera devices
844 m_iCameraProvider->getCameraDevices(&m_cameraDevices);
845 if (m_cameraDevices.size() == 0)
846 {
847 PROPAGATE_ERROR(shutdown());
848 ORIGINATE_ERROR("No cameras available");
849 }
850
851 m_initialized = true;
852
853 // register the device index observer after 'm_initialize' is set, the call back will be
854 // called immediately and assert that 'm_initialize' is set
855 PROPAGATE_ERROR_CONTINUE(m_deviceIndex.registerObserver(this,
856 static_cast<IObserver::CallbackFunction>(&Dispatcher::onDeviceIndexChanged)));
857 PROPAGATE_ERROR_CONTINUE(m_sensorModeIndex.registerObserver(this,
858 static_cast<IObserver::CallbackFunction>(&Dispatcher::onSensorModeIndexChanged)));
859
860 return true;
861 }
862
863 bool Dispatcher::shutdown()
864 {
865 if (m_initialized)
866 {
867 m_initialized = false;
868 // unregister the device index observer in reverse order
869 PROPAGATE_ERROR_CONTINUE(m_sensorModeIndex.unregisterObserver(this,
870 static_cast<IObserver::CallbackFunction>(&Dispatcher::onSensorModeIndexChanged)));
871 PROPAGATE_ERROR_CONTINUE(m_deviceIndex.unregisterObserver(this,
872 static_cast<IObserver::CallbackFunction>(&Dispatcher::onDeviceIndexChanged)));
873
874 PROPAGATE_ERROR_CONTINUE(closeSession());
875
876 m_cameraDevices.clear();
877 m_cameraProvider.reset();
878 }
879
880 return true;
881 }
882
883 bool Dispatcher::onDeviceIndexChanged(const Observed &source)
884 {
885 assert(static_cast<const Value<uint32_t>&>(source).get() == m_deviceIndex);
886 assert(m_initialized);
887
888 // close the currently open device
889 if (m_deviceOpen)
890 {
891 PROPAGATE_ERROR(m_deviceOpen.set(false));
892
893 PROPAGATE_ERROR(closeSession());
894
895 // reset the current device properties
896 }
897
898 // open the new device
899 const Argus::ICameraProperties *iCameraProperties =
900 Argus::interface_cast<Argus::ICameraProperties>(m_cameraDevices[m_deviceIndex]);
901 if (!iCameraProperties)
902 ORIGINATE_ERROR("Failed to get ICameraProperties interface");
903
904 // get the sensor modes
905 if (iCameraProperties->getAllSensorModes(&m_sensorModes) != Argus::STATUS_OK)
906 ORIGINATE_ERROR("Failed to get sensor modes");
907
908 if (m_sensorModes.size() == 0)
909 ORIGINATE_ERROR("No sensor modes found");
910
911 // get the focus position range
912 PROPAGATE_ERROR(m_deviceFocusPositionRange.set(iCameraProperties->getFocusPositionRange()));
913
914 // get new limits
915 Argus::Range<float> digitalGainRange = iCameraProperties->getIspDigitalGainRange();
916 Argus::Range<float> deviceExposureCompensationRange =
917 iCameraProperties->getExposureCompensationRange();
918
919
920 /* set ranges to unified range (to avoid errors when setting new values)
921 * Eg. Say Device 1 has range [-1,0] and Device 2 has range [1,2] .If current value is -1 and
922 * range is [-1,0] , setting the range to [1,2] would give error . Similarly, if current value
923 * is 1 , setting the range to [-1,0] would give error. Thus we set range to [-1,2] , set value
924 * to 1 and then set range to [1,2] to avoid errors.
925 */
926 Argus::Range<float> unifiedDigitalGainRange(0);
927 unifiedDigitalGainRange.min() =
928 std::min(m_deviceIspDigitalGainRange.get().min().min(), digitalGainRange.min());
929 unifiedDigitalGainRange.max() =
930 std::max(m_deviceIspDigitalGainRange.get().max().max(), digitalGainRange.max());
931
932 Argus::Range<float> unifiedExposureCompensationRange(0);
933 unifiedExposureCompensationRange.min() =
934 std::min(m_deviceExposureCompensationRange.get().min(),
935 deviceExposureCompensationRange.min());
936 unifiedExposureCompensationRange.max() =
937 std::max(m_deviceExposureCompensationRange.get().max(),
938 deviceExposureCompensationRange.max());
939
940 PROPAGATE_ERROR(m_deviceIspDigitalGainRange.set(
941 Argus::Range<Argus::Range<float> >(unifiedDigitalGainRange)));
942 PROPAGATE_ERROR(m_deviceExposureCompensationRange.set(
943 Argus::Range<float> (unifiedExposureCompensationRange)));
944
945 // update dependent values
946 PROPAGATE_ERROR(m_ispDigitalGainRange.set(digitalGainRange));
947 PROPAGATE_ERROR(m_exposureCompensation.set(0.0f));
948
949 // set to final range
950 PROPAGATE_ERROR(m_deviceIspDigitalGainRange.set(Argus::Range<Argus::Range<float> >(
951 digitalGainRange, digitalGainRange)));
952 PROPAGATE_ERROR(m_deviceExposureCompensationRange.set(Argus::Range<float> (
953 deviceExposureCompensationRange)));
954
955
956 // add value/string pairs for each sensor mode index
957 std::vector<ValidatorEnum<uint32_t>::ValueStringPair> valueStringPairs;
958 valueStringPairs.resize(m_sensorModes.size());
959 for (size_t index = 0; index < m_sensorModes.size(); ++index)
960 {
961 Argus::ISensorMode *sensorMode =
962 Argus::interface_cast<Argus::ISensorMode>(m_sensorModes[index]);
963
964 valueStringPairs[index].value = (uint32_t)index;
965
966 std::ostringstream stream;
967 stream << index << ": "
968 << sensorMode->getResolution().width() << "x" << sensorMode->getResolution().height();
969
970 Argus::Ext::IPwlWdrSensorMode* pwlMode =
971 Argus::interface_cast<Argus::Ext::IPwlWdrSensorMode>(m_sensorModes[index]);
972 if (pwlMode)
973 {
974 stream << " @" << sensorMode->getInputBitDepth() << "bpp -> " <<
975 sensorMode->getOutputBitDepth() << "bpp";
976 }
977 else
978 {
979 stream << " @" << sensorMode->getOutputBitDepth() << "bpp";
980 }
981 valueStringPairs[index].string = stream.str();
982 }
983 // update the validator with the new value/string pairs
984 ValidatorEnum<uint32_t> *validator =
985 static_cast<ValidatorEnum<uint32_t>*>(m_sensorModeIndex.getValidator());
986 PROPAGATE_ERROR(validator->setValidValues(valueStringPairs.data(), valueStringPairs.size()));
987
988 // set the sensor mode index (force notify observer because the sensor modes are different now
989 // although the sensor mode index could be the same)
990 PROPAGATE_ERROR(m_sensorModeIndex.set(0, true /*forceNotify*/));
991
992 PROPAGATE_ERROR(m_deviceOpen.set(true));
993
994 return true;
995 }
996
997 bool Dispatcher::onSensorModeIndexChanged(const Observed &source)
998 {
999 assert(static_cast<const Value<uint32_t>&>(source).get() == m_sensorModeIndex);
1000 assert(m_initialized);
1001
1002 Argus::ISensorMode *iSensorMode =
1003 Argus::interface_cast<Argus::ISensorMode>(m_sensorModes[m_sensorModeIndex.get()]);
1004 if (!iSensorMode)
1005 ORIGINATE_ERROR("Failed to get ISensorMode interface");
1006
1007 // get new limits
1008 Argus::Range<uint64_t> sensorExposureTimeRange = iSensorMode->getExposureTimeRange();
1009 Argus::Range<float> sensorAnalogGainRange = iSensorMode->getAnalogGainRange();
1010 Argus::Range<TimeValue> sensorFrameDurationRange(
1011 TimeValue::fromNSec(iSensorMode->getFrameDurationRange().min()),
1012 TimeValue::fromNSec(iSensorMode->getFrameDurationRange().max()));
1013 Argus::Range<float> sensorFrameRateRange(
1014 sensorFrameDurationRange.max().toCyclesPerSec(),
1015 sensorFrameDurationRange.min().toCyclesPerSec());
1016
1017 // set ranges to unified range (to avoid errors when setting new values)
1018 Argus::Range<uint64_t> unifiedSensorExposureTimeRange(0);
1019 unifiedSensorExposureTimeRange.min() =
1020 std::min(m_sensorExposureTimeRange.get().min().min(), sensorExposureTimeRange.min());
1021 unifiedSensorExposureTimeRange.max() =
1022 std::max(m_sensorExposureTimeRange.get().max().max(), sensorExposureTimeRange.max());
1023 Argus::Range<float> unifiedSensorAnalogGainRange(0);
1024 unifiedSensorAnalogGainRange.min() =
1025 std::min(m_sensorAnalogGainRange.get().min().min(), sensorAnalogGainRange.min());
1026 unifiedSensorAnalogGainRange.max() =
1027 std::max(m_sensorAnalogGainRange.get().max().max(), sensorAnalogGainRange.max());
1028 Argus::Range<float> unifiedSensorFrameRateRange(0.0f);
1029 unifiedSensorFrameRateRange.min() =
1030 std::min(m_sensorFrameRateRange.get().min(), sensorFrameRateRange.min());
1031 unifiedSensorFrameRateRange.max() =
1032 std::max(m_sensorFrameRateRange.get().max(), sensorFrameRateRange.max());
1033
1034 PROPAGATE_ERROR(m_sensorExposureTimeRange.set(
1035 Argus::Range<Argus::Range<uint64_t> >(unifiedSensorExposureTimeRange)));
1036 PROPAGATE_ERROR(m_sensorAnalogGainRange.set(
1037 Argus::Range<Argus::Range<float> >(unifiedSensorAnalogGainRange)));
1038 PROPAGATE_ERROR(m_sensorFrameRateRange.set(unifiedSensorFrameRateRange));
1039
1040 // update dependent values
1041 PROPAGATE_ERROR(m_exposureTimeRange.set(sensorExposureTimeRange));
1042 PROPAGATE_ERROR(m_gainRange.set(sensorAnalogGainRange));
1043 PROPAGATE_ERROR(m_frameRate.set(sensorFrameRateRange.max()));
1044
1045 // set to final ranges
1046 PROPAGATE_ERROR(m_sensorExposureTimeRange.set(Argus::Range<Argus::Range<uint64_t> >(
1047 sensorExposureTimeRange, sensorExposureTimeRange)));
1048 PROPAGATE_ERROR(m_sensorAnalogGainRange.set(Argus::Range<Argus::Range<float> >(
1049 sensorAnalogGainRange, sensorAnalogGainRange)));
1050 PROPAGATE_ERROR(m_sensorFrameRateRange.set(sensorFrameRateRange));
1051
1052 return true;
1053 }
1054
1055 bool Dispatcher::supportsExtension(const Argus::ExtensionName& extension) const
1056 {
1057 return m_iCameraProvider->supportsExtension(extension);
1058 }
1059
1060 bool Dispatcher::getInfo(std::string &info) const
1061 {
1062 std::ostringstream stream;
1063
1064 assert(m_initialized);
1065
1066 stream << "Argus extensions:" << std::endl;
1067 stream << " BayerSharpnessMap: " <<
1068 (supportsExtension(Argus::EXT_BAYER_SHARPNESS_MAP) ?
1069 "supported" : "not supported") << std::endl;
1070 stream << " DebugCaptureSession: " <<
1071 (supportsExtension(Argus::EXT_DEBUG_CAPTURE_SESSION) ?
1072 "supported" : "not supported") << std::endl;
1073 stream << " DeFog: " <<
1074 (supportsExtension(Argus::EXT_DE_FOG) ?
1075 "supported" : "not supported") << std::endl;
1076 stream << " FaceDetect: " <<
1077 (supportsExtension(Argus::EXT_FACE_DETECT) ?
1078 "supported" : "not supported") << std::endl;
1079 stream << " InternalFrameCount: " <<
1080 (supportsExtension(Argus::EXT_INTERNAL_FRAME_COUNT) ?
1081 "supported" : "not supported") << std::endl;
1082 stream << " SensorPrivateMetadata: " <<
1083 (supportsExtension(Argus::EXT_SENSOR_PRIVATE_METADATA) ?
1084 "supported" : "not supported") << std::endl;
1085
1086 stream << "Number of camera devices: " << m_cameraDevices.size() << std::endl;
1087
1088 for (uint32_t deviceIndex = 0; deviceIndex < m_cameraDevices.size(); ++deviceIndex)
1089 {
1090 stream << "Device: " << deviceIndex << std::endl;
1091
1092 const Argus::ICameraProperties *iCameraProperties =
1093 Argus::interface_cast<Argus::ICameraProperties>(m_cameraDevices[deviceIndex]);
1094 if (!iCameraProperties)
1095 ORIGINATE_ERROR("Failed to get ICameraProperties interface");
1096
1097 stream << " Max AE Regions: " <<
1098 iCameraProperties->getMaxAeRegions() << std::endl;
1099 stream << " Max AWB Regions: " <<
1100 iCameraProperties->getMaxAwbRegions() << std::endl;
1101 stream << " Focus Position Range: " <<
1102 iCameraProperties->getFocusPositionRange().min() << " - " <<
1103 iCameraProperties->getFocusPositionRange().max() << std::endl;
1104 stream << " Lens Aperture Range: " <<
1105 iCameraProperties->getLensApertureRange().min() << " - " <<
1106 iCameraProperties->getLensApertureRange().max() << std::endl;
1107 stream << " Isp Digital Gain Range: " <<
1108 iCameraProperties->getIspDigitalGainRange().min() << " - " <<
1109 iCameraProperties->getIspDigitalGainRange().max() << std::endl;
1110
1111 // print the sensor modes
1112 std::vector<Argus::SensorMode*> sensorModes;
1113 iCameraProperties->getAllSensorModes(&sensorModes);
1114 stream << " Number of sensor modes: " << sensorModes.size() << std::endl;
1115 for (uint32_t sensorModeIndex = 0; sensorModeIndex < sensorModes.size(); ++sensorModeIndex)
1116 {
1117 Argus::ISensorMode *sensorMode =
1118 Argus::interface_cast<Argus::ISensorMode>(sensorModes[sensorModeIndex]);
1119 if (!sensorMode)
1120 ORIGINATE_ERROR("Failed to get ISensorMode interface");
1121
1122 // convert ns to fps
1123 float maximum_fps = TimeValue::fromNSec(
1124 sensorMode->getFrameDurationRange().min()).toCyclesPerSec();
1125 float minimum_fps = TimeValue::fromNSec(
1126 sensorMode->getFrameDurationRange().max()).toCyclesPerSec();
1127
1128 stream << " Sensor mode: " << sensorModeIndex << std::endl;
1129 stream << " Resolution: " <<
1130 sensorMode->getResolution().width() << "x" <<
1131 sensorMode->getResolution().height() << std::endl;
1132 stream << " Exposure time range: " <<
1133 sensorMode->getExposureTimeRange().min() << " - " <<
1134 sensorMode->getExposureTimeRange().max() << " ns" << std::endl;
1135 stream << " Frame duration range: " <<
1136 sensorMode->getFrameDurationRange().min() << " - " <<
1137 sensorMode->getFrameDurationRange().max() << " ns" << std::endl;
1138 stream << " Framerate range: " <<
1139 minimum_fps << " - " <<
1140 maximum_fps << " fps" << std::endl;
1141 stream << " InputBitDepth: " <<
1142 sensorMode->getInputBitDepth() << std::endl;
1143 stream << " OutputBitDepth: " <<
1144 sensorMode->getOutputBitDepth() << std::endl;
1145 stream << " Analog gain range: " <<
1146 sensorMode->getAnalogGainRange().min() << " - " <<
1147 sensorMode->getAnalogGainRange().max() << std::endl;
1148
1149 stream << " SensorModeType: " <<
1150 sensorMode->getSensorModeType().getName() << std::endl;
1151
1152 Argus::Ext::IPwlWdrSensorMode* pwlMode =
1153 Argus::interface_cast<Argus::Ext::IPwlWdrSensorMode>(sensorModes[sensorModeIndex]);
1154 if (pwlMode)
1155 {
1156 stream << " Piecewise Linear WDR Extension supported with: " <<
1157 pwlMode->getControlPointCount() << " control points." << std::endl;
1158 std::vector< Argus::Point2D<float> > points;
1159 Argus::Status status = pwlMode->getControlPoints(&points);
1160 if (status != Argus::STATUS_OK)
1161 ORIGINATE_ERROR("Error obtaining control points");
1162 stream << " Control Points: " << std::endl;
1163 for (uint32_t j = 0; j < pwlMode->getControlPointCount(); j++)
1164 {
1165 stream << " (" << points[j].x() << ", " <<
1166 points[j].y() << ")" << std::endl;
1167 }
1168 }
1169
1170 stream << std::endl;
1171 }
1172 }
1173
1174 info = stream.str();
1175
1176 return true;
1177 }
1178
1179 bool Dispatcher::getSensorMode(uint32_t sensorModeIndex, Argus::SensorMode **sensorMode) const
1180 {
1181 assert(m_deviceOpen);
1182
1183 if (sensorModeIndex >= m_sensorModes.size())
1184 ORIGINATE_ERROR("Invalid sensor mode index");
1185
1186 *sensorMode = m_sensorModes[sensorModeIndex];
1187
1188 return true;
1189 }
1190
1191 Argus::Range<int32_t> Dispatcher::getDeviceFocusPositionRange() const
1192 {
1193 return m_deviceFocusPositionRange.get();
1194 }
1195
1196 uint32_t Dispatcher::getDeviceCount() const
1197 {
1198 assert(m_deviceOpen);
1199
1200 return m_cameraDevices.size();
1201 }
1202
1203 bool Dispatcher::createSession(TrackedUniqueObj<Argus::CaptureSession> &session,
1204 uint32_t deviceIndex)
1205 {
1206 assert(m_deviceOpen);
1207
1208 if (deviceIndex > m_cameraDevices.size())
1209 ORIGINATE_ERROR("Invalid device index");
1210
1211 // close the internal session, it might be using the device which will be used by the new
1212 // session
1213 PROPAGATE_ERROR(closeSession());
1214
1215 // create the new capture session
1216 Argus::UniqueObj<Argus::CaptureSession> newSession(
1217 m_iCameraProvider->createCaptureSession(m_cameraDevices[deviceIndex]));
1218 if (!newSession)
1219 ORIGINATE_ERROR("Failed to create CaptureSession");
1220
1221 PROPAGATE_ERROR(session.reset(newSession.release(), this));
1222
1223 return true;
1224 }
1225
1226 bool Dispatcher::dumpSessionInfo() const
1227 {
1228 for (ActiveSessionList::const_iterator it = m_activeSessions.begin(); it != m_activeSessions.end();
1229 ++it)
1230 {
1231 Argus::Ext::IDebugCaptureSession *iDebugCaptureSession =
1232 Argus::interface_cast<Argus::Ext::IDebugCaptureSession>(it->m_session);
1233 if (!iDebugCaptureSession)
1234 ORIGINATE_ERROR("DebugCaptureSession extension not supported");
1235
1236 const Argus::Status status = iDebugCaptureSession->dump(STDOUT_FILENO);
1237 if (status != Argus::STATUS_OK)
1238 ORIGINATE_ERROR("Failed to get dump runtime info");
1239 }
1240
1241 return true;
1242 }
1243
1244 /**
1245 * Create the internal session
1246 */
1247 bool Dispatcher::createSession()
1248 {
1249 if (m_captureSession)
1250 return true;
1251
1252 PROPAGATE_ERROR(createSession(m_captureSession, m_deviceIndex));
1253
1254 return true;
1255 }
1256
1257 /**
1258 * Close the internal session
1259 */
1260 bool Dispatcher::closeSession()
1261 {
1262 m_captureSession.reset();
1263 return true;
1264 }
1265
1266 bool Dispatcher::track(Argus::CaptureSession *session)
1267 {
1268 m_activeSessions.push_back(ActiveSession(session));
1269 return true;
1270 }
1271
1272 bool Dispatcher::untrack(Argus::CaptureSession *session)
1273 {
1274 for (ActiveSessionList::iterator it = m_activeSessions.begin(); it != m_activeSessions.end();
1275 ++it)
1276 {
1277 if (it->m_session == session)
1278 {
1279 m_activeSessions.erase(it);
1280 return true;
1281 }
1282 }
1283
1284 ORIGINATE_ERROR("Session not found");
1285 }
1286
1287 bool Dispatcher::waitForEvents(Argus::EventQueue *eventQueue, TimeValue timeout,
1288 Argus::CaptureSession *session)
1289 {
1290 if (!session)
1291 {
1292 // use the internal session
1293 PROPAGATE_ERROR(createSession());
1294 session = m_captureSession.get();
1295 }
1296
1297 Argus::IEventProvider *iEventProvider = Argus::interface_cast<Argus::IEventProvider>(session);
1298 if (!iEventProvider)
1299 ORIGINATE_ERROR("Failed to get iEventProvider interface");
1300
1301 // wait for the events
1302 const Argus::Status status = iEventProvider->waitForEvents(eventQueue, timeout.toNSec());
1303 if ((status != Argus::STATUS_OK) && (status != Argus::STATUS_TIMEOUT))
1304 ORIGINATE_ERROR("Failed to get events");
1305
1306 return true;
1307 }
1308
1309 bool Dispatcher::createRequest(TrackedUniqueObj<Argus::Request> &request,
1310 Argus::CaptureIntent captureIntent, Argus::CaptureSession *session)
1311 {
1312 if (!session)
1313 {
1314 // use the internal session
1315 PROPAGATE_ERROR(createSession());
1316 session = m_captureSession.get();
1317 }
1318
1319 Argus::ICaptureSession *iCaptureSession =
1320 Argus::interface_cast<Argus::ICaptureSession>(session);
1321 if (!iCaptureSession)
1322 ORIGINATE_ERROR("Failed to get ICaptureSession interface");
1323
1324 // Create request
1325 Argus::UniqueObj<Argus::Request> newRequest =
1326 Argus::UniqueObj<Argus::Request>(iCaptureSession->createRequest(captureIntent));
1327 if (!newRequest)
1328 ORIGINATE_ERROR("Failed to create request");
1329
1330 // Setup request
1331 Argus::IRequest *iRequest = Argus::interface_cast<Argus::IRequest>(newRequest);
1332 if (!iRequest)
1333 ORIGINATE_ERROR("Failed to get IRequest interface");
1334
1335 // get source settings interface
1336 Argus::ISourceSettings *iSourceSettings =
1337 Argus::interface_cast<Argus::ISourceSettings>(iRequest->getSourceSettings());
1338 if (!iSourceSettings)
1339 ORIGINATE_ERROR("Failed to get ISourceSettings interface");
1340
1341 // register the source settings observer
1342 PROPAGATE_ERROR(registerObserver(iSourceSettings));
1343
1344 // get auto control settings interface
1345 Argus::IAutoControlSettings *iAutoControlSettings =
1346 Argus::interface_cast<Argus::IAutoControlSettings>(iRequest->getAutoControlSettings());
1347 if (!iAutoControlSettings)
1348 ORIGINATE_ERROR("Failed to get IAutoControlSettings interface");
1349
1350 // register the auto control settings observer
1351 PROPAGATE_ERROR(registerObserver(iAutoControlSettings));
1352
1353 // register denoise settings interface
1354 Argus::IDenoiseSettings *iDenoiseSettings =
1355 Argus::interface_cast<Argus::IDenoiseSettings>(newRequest);
1356 if (!iDenoiseSettings)
1357 ORIGINATE_ERROR("Failed to get IDenoiseSettings interface");
1358 PROPAGATE_ERROR(registerObserver(iDenoiseSettings));
1359
1360 // register edge enhance settings interface
1361 Argus::IEdgeEnhanceSettings *iEdgeEnhanceSettings =
1362 Argus::interface_cast<Argus::IEdgeEnhanceSettings>(newRequest);
1363 if (!iEdgeEnhanceSettings)
1364 ORIGINATE_ERROR("Failed to get IEdgeEnhanceSettings interface");
1365 PROPAGATE_ERROR(registerObserver(iEdgeEnhanceSettings));
1366
1367 // register video stabilization settings interface
1368 Argus::IVideoStabilizationSettings *iVideoStabilizationSettings =
1369 Argus::interface_cast<Argus::IVideoStabilizationSettings>(newRequest);
1370 if (!iVideoStabilizationSettings)
1371 ORIGINATE_ERROR("Failed to get IVideoStabilizationSettings interface");
1372 PROPAGATE_ERROR(registerObserver(iVideoStabilizationSettings));
1373
1374 if (supportsExtension(Argus::EXT_DE_FOG))
1375 {
1376 // get DeFog settings interface
1377 Argus::Ext::IDeFogSettings *iDeFogSettings =
1378 Argus::interface_cast<Argus::Ext::IDeFogSettings>(newRequest);
1379 if (iDeFogSettings)
1380 {
1381 // register the DeFog settings observer
1382 PROPAGATE_ERROR(registerObserver(iDeFogSettings));
1383 }
1384 }
1385
1386 PROPAGATE_ERROR(request.reset(newRequest.release(), this));
1387
1388 return true;
1389 }
1390
1391 bool Dispatcher::track(Argus::Request *request)
1392 {
1393 return true;
1394 }
1395
1396 bool Dispatcher::untrack(Argus::Request *request)
1397 {
1398 Argus::IRequest *iRequest = Argus::interface_cast<Argus::IRequest>(request);
1399 if (!iRequest)
1400 ORIGINATE_ERROR("Failed to get IRequest interface");
1401
1402 // get source settings interface
1403 Argus::ISourceSettings *iSourceSettings =
1404 Argus::interface_cast<Argus::ISourceSettings>(iRequest->getSourceSettings());
1405 if (!iSourceSettings)
1406 ORIGINATE_ERROR("Failed to get ISourceSettings interface");
1407
1408 // unregister the source settings observer
1409 PROPAGATE_ERROR(unregisterObserver(iSourceSettings));
1410
1411 // get auto control settings interface
1412 Argus::IAutoControlSettings *iAutoControlSettings =
1413 Argus::interface_cast<Argus::IAutoControlSettings>(iRequest->getAutoControlSettings());
1414 if (!iAutoControlSettings)
1415 ORIGINATE_ERROR("Failed to get IAutoControlSettings interface");
1416
1417 // unregister the auto control settings observer
1418 PROPAGATE_ERROR(unregisterObserver(iAutoControlSettings));
1419
1420 // unregister denoise settings interface
1421 Argus::IDenoiseSettings *iDenoiseSettings =
1422 Argus::interface_cast<Argus::IDenoiseSettings>(request);
1423 if (!iDenoiseSettings)
1424 ORIGINATE_ERROR("Failed to get IDenoiseSettings interface");
1425 PROPAGATE_ERROR(unregisterObserver(iDenoiseSettings));
1426
1427 // unregister edge enhance settings interface
1428 Argus::IEdgeEnhanceSettings *iEdgeEnhanceSettings =
1429 Argus::interface_cast<Argus::IEdgeEnhanceSettings>(request);
1430 if (!iEdgeEnhanceSettings)
1431 ORIGINATE_ERROR("Failed to get IEdgeEnhanceSettings interface");
1432 PROPAGATE_ERROR(unregisterObserver(iEdgeEnhanceSettings));
1433
1434 // unregister video stabilization settings interface
1435 Argus::IVideoStabilizationSettings *iVideoStabilizationSettings =
1436 Argus::interface_cast<Argus::IVideoStabilizationSettings>(request);
1437 if (!iVideoStabilizationSettings)
1438 ORIGINATE_ERROR("Failed to get IVideoStabilizationSettings interface");
1439 PROPAGATE_ERROR(unregisterObserver(iVideoStabilizationSettings));
1440
1441 if (supportsExtension(Argus::EXT_DE_FOG))
1442 {
1443 // get DeFog settings interface
1444 Argus::Ext::IDeFogSettings *iDeFogSettings =
1445 Argus::interface_cast<Argus::Ext::IDeFogSettings>(request);
1446 if (iDeFogSettings)
1447 {
1448 // unregister the DeFog settings observer
1449 PROPAGATE_ERROR(unregisterObserver(iDeFogSettings));
1450 }
1451 }
1452
1453 return true;
1454 }
1455
1456 bool Dispatcher::createEventQueue(const std::vector<Argus::EventType> &eventTypes,
1457 Argus::UniqueObj<Argus::EventQueue>& eventQueue, Argus::CaptureSession *session)
1458 {
1459 if (!session)
1460 {
1461 // use the internal session
1462 PROPAGATE_ERROR(createSession());
1463 session = m_captureSession.get();
1464 }
1465
1466 Argus::IEventProvider *iEventProvider =
1467 Argus::interface_cast<Argus::IEventProvider>(session);
1468 if (!iEventProvider)
1469 ORIGINATE_ERROR("Failed to get IEventProvider interface");
1470
1471 Argus::EventQueue *newEventQueue = iEventProvider->createEventQueue(eventTypes);
1472 if (!newEventQueue)
1473 ORIGINATE_ERROR("Failed to create eventQueue");
1474
1475 eventQueue.reset(newEventQueue);
1476
1477 return true;
1478 }
1479
1480 bool Dispatcher::capture(Argus::Request *request, Argus::CaptureSession *session)
1481 {
1482 if (!session)
1483 {
1484 // use the internal session
1485 PROPAGATE_ERROR(createSession());
1486 session = m_captureSession.get();
1487 }
1488
1489 Argus::ICaptureSession *iCaptureSession =
1490 Argus::interface_cast<Argus::ICaptureSession>(session);
1491 if (!iCaptureSession)
1492 ORIGINATE_ERROR("Failed to get ICaptureSession interface");
1493
1494 if (iCaptureSession->capture(request, Argus::TIMEOUT_INFINITE) == 0)
1495 ORIGINATE_ERROR("Failed to submit the still capture request");
1496
1497 return true;
1498 }
1499
1500 bool Dispatcher::startRepeat(Argus::Request *request, Argus::CaptureSession *session)
1501 {
1502 if (!session)
1503 {
1504 // use the internal session
1505 PROPAGATE_ERROR(createSession());
1506 session = m_captureSession.get();
1507 }
1508
1509 Argus::ICaptureSession *iCaptureSession =
1510 Argus::interface_cast<Argus::ICaptureSession>(session);
1511 if (!iCaptureSession)
1512 ORIGINATE_ERROR("Failed to get ICaptureSession interface");
1513
1514 if (iCaptureSession->repeat(request) != Argus::STATUS_OK)
1515 ORIGINATE_ERROR("Failed to submit repeating capture request");
1516
1517 // add the request to the list of active requests for the session
1518 bool found = false;
1519 for (ActiveSessionList::iterator it = m_activeSessions.begin(); it != m_activeSessions.end();
1520 ++it)
1521 {
1522 if (it->m_session == session)
1523 {
1524 it->m_requests.push_back(request);
1525 found = true;
1526 break;
1527 }
1528 }
1529 if (!found)
1530 ORIGINATE_ERROR("Did not find the session in the list of active sessions");
1531
1532 return true;
1533 }
1534
1535 bool Dispatcher::startRepeatBurst(const std::vector<const Argus::Request*>& requestList,
1536 Argus::CaptureSession *session)
1537 {
1538 if (!session)
1539 {
1540 // use the internal session
1541 PROPAGATE_ERROR(createSession());
1542 session = m_captureSession.get();
1543 }
1544
1545 Argus::ICaptureSession *iCaptureSession =
1546 Argus::interface_cast<Argus::ICaptureSession>(session);
1547 if (!iCaptureSession)
1548 ORIGINATE_ERROR("Failed to get ICaptureSession interface");
1549
1550 if (iCaptureSession->repeatBurst(requestList) != Argus::STATUS_OK)
1551 ORIGINATE_ERROR("Failed to submit repeating burst request");
1552
1553 // add the requests to the list of active requests for the session
1554 bool found = false;
1555 for (ActiveSessionList::iterator it = m_activeSessions.begin(); it != m_activeSessions.end();
1556 ++it)
1557 {
1558 if (it->m_session == session)
1559 {
1560 it->m_requests.insert(it->m_requests.end(), requestList.begin(), requestList.end());
1561 found = true;
1562 break;
1563 }
1564 }
1565 if (!found)
1566 ORIGINATE_ERROR("Did not find the session in the list of active sessions");
1567
1568 return true;
1569 }
1570
1571 bool Dispatcher::stopRepeat(Argus::CaptureSession *session)
1572 {
1573 if (!session)
1574 {
1575 // use the internal session
1576 PROPAGATE_ERROR(createSession());
1577 session = m_captureSession.get();
1578 }
1579
1580 Argus::ICaptureSession *iCaptureSession =
1581 Argus::interface_cast<Argus::ICaptureSession>(session);
1582 if (!iCaptureSession)
1583 ORIGINATE_ERROR("Failed to get ICaptureSession interface");
1584
1585 iCaptureSession->stopRepeat();
1586
1587 // clear the list of active requests for the session
1588 bool found = false;
1589 for (ActiveSessionList::iterator it = m_activeSessions.begin(); it != m_activeSessions.end();
1590 ++it)
1591 {
1592 if (it->m_session == session)
1593 {
1594 it->m_requests.clear();
1595 found = true;
1596 break;
1597 }
1598 }
1599 if (!found)
1600 ORIGINATE_ERROR("Did not find the session in the list of active sessions");
1601
1602 return true;
1603 }
1604
1605 bool Dispatcher::restartActiveRequests()
1606 {
1607 for (ActiveSessionList::iterator it = m_activeSessions.begin(); it != m_activeSessions.end();
1608 ++it)
1609 {
1610 if (!it->m_requests.empty())
1611 {
1612 Argus::ICaptureSession *iCaptureSession =
1613 Argus::interface_cast<Argus::ICaptureSession>(it->m_session);
1614 if (!iCaptureSession)
1615 ORIGINATE_ERROR("Failed to get ICaptureSession interface");
1616
1617 iCaptureSession->stopRepeat();
1618
1619 if (iCaptureSession->repeatBurst(it->m_requests) != Argus::STATUS_OK)
1620 ORIGINATE_ERROR("Failed to submit repeating burst request");
1621 }
1622 }
1623
1624 return true;
1625 }
1626
1627 uint32_t Dispatcher::maxBurstRequests(Argus::CaptureSession *session)
1628 {
1629 if (!session)
1630 {
1631 // use the internal session
1632 PROPAGATE_ERROR(createSession());
1633 session = m_captureSession.get();
1634 }
1635
1636 Argus::ICaptureSession *iCaptureSession =
1637 Argus::interface_cast<Argus::ICaptureSession>(session);
1638 if (!iCaptureSession)
1639 {
1640 REPORT_ERROR("Failed to get ICaptureSession interface");
1641 return 0;
1642 }
1643
1644 return iCaptureSession->maxBurstRequests();
1645 }
1646
1647 bool Dispatcher::waitForIdle(Argus::CaptureSession *session)
1648 {
1649 if (!session)
1650 {
1651 // use the internal session
1652 PROPAGATE_ERROR(createSession());
1653 session = m_captureSession.get();
1654 }
1655
1656 Argus::ICaptureSession *iCaptureSession =
1657 Argus::interface_cast<Argus::ICaptureSession>(session);
1658 if (!iCaptureSession)
1659 ORIGINATE_ERROR("Failed to get ICaptureSession interface");
1660
1661 if (iCaptureSession->waitForIdle() != Argus::STATUS_OK)
1662 ORIGINATE_ERROR("Waiting for idle failed");
1663
1664 return true;
1665 }
1666
1667 bool Dispatcher::getOutputSize(Argus::Size2D<uint32_t> *size) const
1668 {
1669 // if width or height is 0 take the sensor size
1670 if ((m_outputSize.get().width() == 0) || (m_outputSize.get().height() == 0))
1671 {
1672 // the device needs to be open to get sensor modes
1673 assert(m_deviceOpen);
1674
1675 Argus::ISensorMode *sensorMode =
1676 Argus::interface_cast<Argus::ISensorMode>(m_sensorModes[m_sensorModeIndex.get()]);
1677 if (!sensorMode)
1678 ORIGINATE_ERROR("Failed to get ISensorMode interface");
1679 *size = sensorMode->getResolution();
1680 }
1681 else
1682 {
1683 *size = m_outputSize;
1684 }
1685
1686 return true;
1687 }
1688
1689 bool Dispatcher::createOutputStream(Argus::Request *request, bool enableMetadata,
1690 Argus::UniqueObj<Argus::OutputStream> &stream, Argus::CaptureSession *session)
1691 {
1692 if (!session)
1693 {
1694 // use the internal session
1695 PROPAGATE_ERROR(createSession());
1696 session = m_captureSession.get();
1697 }
1698
1699 Argus::IRequest *iRequest = Argus::interface_cast<Argus::IRequest>(request);
1700 if (!iRequest)
1701 ORIGINATE_ERROR("Failed to get IRequest interface");
1702
1703 Argus::Size2D<uint32_t> outputSize;
1704 PROPAGATE_ERROR(getOutputSize(&outputSize));
1705
1706 Argus::ICaptureSession *iCaptureSession =
1707 Argus::interface_cast<Argus::ICaptureSession>(session);
1708 if (!iCaptureSession)
1709 ORIGINATE_ERROR("Failed to get ICaptureSession interface");
1710
1711 Argus::UniqueObj<Argus::OutputStreamSettings> outputStreamSettings(
1712 iCaptureSession->createOutputStreamSettings());
1713 Argus::IOutputStreamSettings* iOutputStreamSettings =
1714 Argus::interface_cast<Argus::IOutputStreamSettings>(outputStreamSettings);
1715 if (!iOutputStreamSettings)
1716 ORIGINATE_ERROR("Failed to get IOutputStreamSettings interface");
1717
1718 iOutputStreamSettings->setPixelFormat(Argus::PIXEL_FMT_YCbCr_420_888);
1719 iOutputStreamSettings->setResolution(outputSize);
1720 iOutputStreamSettings->setEGLDisplay(Composer::getInstance().getEGLDisplay());
1721 iOutputStreamSettings->setMetadataEnable(enableMetadata);
1722
1723 Argus::UniqueObj<Argus::OutputStream> outputStream(
1724 iCaptureSession->createOutputStream(outputStreamSettings.get()));
1725 if (!outputStream)
1726 ORIGINATE_ERROR("Failed to create OutputStream");
1727
1728 stream.reset(outputStream.release());
1729
1730 return true;
1731 }
1732
1733 bool Dispatcher::enableOutputStream(Argus::Request *request, Argus::OutputStream *stream)
1734 {
1735 Argus::IRequest *iRequest = Argus::interface_cast<Argus::IRequest>(request);
1736 if (!iRequest)
1737 ORIGINATE_ERROR("Failed to get IRequest interface");
1738
1739 // Enable the stream
1740 if (iRequest->enableOutputStream(stream) != Argus::STATUS_OK)
1741 ORIGINATE_ERROR("Failed to enable the output stream");
1742
1743 return true;
1744 }
1745
1746 bool Dispatcher::disableOutputStream(Argus::Request *request, Argus::OutputStream *stream)
1747 {
1748 Argus::IRequest *iRequest = Argus::interface_cast<Argus::IRequest>(request);
1749 if (!iRequest)
1750 ORIGINATE_ERROR("Failed to get IRequest interface");
1751
1752 // Disable the stream
1753 if (iRequest->disableOutputStream(stream) != Argus::STATUS_OK)
1754 ORIGINATE_ERROR("Failed to disable the output stream");
1755
1756 return true;
1757 }
1758
1759 bool Dispatcher::registerObserver(Argus::IDenoiseSettings *iDenoiseSettings)
1760 {
1761 UniquePointer<DenoiseSettingsObserver> denoiseSettings;
1762
1763 denoiseSettings.reset(new DenoiseSettingsObserver(iDenoiseSettings));
1764 if (!denoiseSettings)
1765 ORIGINATE_ERROR("Out of memory");
1766
1767 m_observers.push_front(denoiseSettings.release());
1768 return true;
1769 }
1770
1771 bool Dispatcher::registerObserver(Argus::IEdgeEnhanceSettings *iEdgeEnhanceSettings)
1772 {
1773 UniquePointer<EdgeEnhanceSettingsObserver> edgeEnhanceSettings;
1774
1775 edgeEnhanceSettings.reset(new EdgeEnhanceSettingsObserver(iEdgeEnhanceSettings));
1776 if (!edgeEnhanceSettings)
1777 ORIGINATE_ERROR("Out of memory");
1778
1779 m_observers.push_front(edgeEnhanceSettings.release());
1780 return true;
1781 }
1782
1783 bool Dispatcher::registerObserver(Argus::IVideoStabilizationSettings *iVideoStabilizationSettings)
1784 {
1785 UniquePointer<VideoStabilizationSettingsObserver> vStabSettings;
1786
1787 vStabSettings.reset(new VideoStabilizationSettingsObserver(iVideoStabilizationSettings));
1788 if (!vStabSettings)
1789 ORIGINATE_ERROR("Out of memory");
1790
1791 m_observers.push_front(vStabSettings.release());
1792 return true;
1793 }
1794
1795 bool Dispatcher::registerObserver(Argus::ISourceSettings *iSourceSettings)
1796 {
1797 UniquePointer<SourceSettingsObserver> sourceSettings;
1798
1799 sourceSettings.reset(new SourceSettingsObserver(iSourceSettings));
1800 if (!sourceSettings)
1801 ORIGINATE_ERROR("Out of memory");
1802
1803 m_observers.push_front(sourceSettings.release());
1804 return true;
1805 }
1806
1807 bool Dispatcher::registerObserver(Argus::IAutoControlSettings *iAutoControlSettings)
1808 {
1809 UniquePointer<AutoControlSettingsObserver> autoControlSettings;
1810
1811 autoControlSettings.reset(new AutoControlSettingsObserver(iAutoControlSettings));
1812 if (!autoControlSettings)
1813 ORIGINATE_ERROR("Out of memory");
1814
1815 m_observers.push_front(autoControlSettings.release());
1816 return true;
1817 }
1818
1819 bool Dispatcher::registerObserver(Argus::Ext::IDeFogSettings *iDeFogSettings)
1820 {
1821 UniquePointer<DeFogSettingsObserver> deFogSettings;
1822
1823 deFogSettings.reset(new DeFogSettingsObserver(iDeFogSettings));
1824 if (!deFogSettings)
1825 ORIGINATE_ERROR("Out of memory");
1826
1827 m_observers.push_front(deFogSettings.release());
1828 return true;
1829 }
1830
1831 bool Dispatcher::unregisterObserver(Argus::Interface *interface)
1832 {
1833 for (std::list<IObserverForInterface*>::iterator it = m_observers.begin();
1834 it != m_observers.end(); ++it)
1835 {
1836 if ((*it)->isInterface(interface))
1837 {
1838 delete *it;
1839 m_observers.erase(it);
1840 return true;
1841 }
1842 }
1843
1844 ORIGINATE_ERROR("Observer not found");
1845 }
1846
1847 bool Dispatcher::message(const char *msg, ...)
1848 {
1849 if (m_verbose)
1850 {
1851 va_list list;
1852
1853 va_start(list, msg);
1854
1855 if (vprintf(msg, list) < 0)
1856 {
1857 va_end(list);
1858 ORIGINATE_ERROR("Failed to print message");
1859 }
1860
1861 va_end(list);
1862 }
1863
1864 return true;
1865 }
1866
1867 }; // namespace ArgusSamples