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.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2016-2018, 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 #ifndef DISPATCHER_H
30 #define DISPATCHER_H
31
32 #include <stdint.h>
33 #include <string>
34 #include <list>
35
36 #include <Argus/Argus.h>
37
38 #include "Value.h"
39 #include "Error.h"
40 #include "VideoPipeline.h"
41 #include "IObserver.h"
42 #include "Util.h"
43 #include "TrackedUniqueObject.h"
44 #include "UniquePointer.h"
45
46 namespace Argus { namespace Ext { class IDeFogSettings; } }
47
48 namespace ArgusSamples
49 {
50
51 class IObserverForInterface;
52
53 /**
54 * The dispatcher is called by clients like the command line interface.
55 * It provides functions to set properties like the camera device index or the sensor mode. It
56 * also implements services to open devices, sessions and create requests.
57 * It also maintains an internal capture session which is used when only a single session is
58 * required.
59 */
60 class Dispatcher
61 : public IObserver
62 , public Tracker<Argus::CaptureSession>
63 , public Tracker<Argus::Request>
64 {
65 public:
66 /**
67 * Get the dispatcher instance.
68 */
69 static Dispatcher &getInstance();
70
71 /**
72 * Shutdown, free all resources
73 */
74 bool shutdown();
75
76 /**
77 * Returns whether or not an extension is supported.
78 */
79 bool supportsExtension(const Argus::ExtensionName& extension) const;
80
81 /**
82 * Get an information string
83 */
84 bool getInfo(std::string &info) const;
85
86 /**
87 * Get the sensor mode for a given index
88 *
89 * @param sensorModeIndex [in]
90 * @param sensorMode [out]
91 */
92 bool getSensorMode(uint32_t sensorModeIndex, Argus::SensorMode **sensorMode) const;
93
94 /**
95 * Returns the range of focuser positions of the current device.
96 * The units are focuser steps.
97 */
98 Argus::Range<int32_t> getDeviceFocusPositionRange() const;
99
100 /**
101 * Get the output size
102 */
103 bool getOutputSize(Argus::Size2D<uint32_t> *size) const;
104
105 /**
106 * Get the amount of available camera devices
107 */
108 uint32_t getDeviceCount() const;
109
110 /**
111 * Create a capture session using the device index
112 */
113 bool createSession(TrackedUniqueObj<Argus::CaptureSession> &session, uint32_t deviceIndex);
114
115 /**
116 * Wait for events from the specific session.
117 *
118 * @param eventQueue [in] event queue to transfer events to
119 * @param timeout [in] maximum time (in nanoseconds) to wait for new events.
120 * @param session [in] capture session (optional, if NULL the internal session is used)
121 */
122 bool waitForEvents(Argus::EventQueue *eventQueue, TimeValue timeout = TimeValue::infinite(),
123 Argus::CaptureSession *session = NULL);
124
125 /**
126 * Dump runtime information for a session.
127 */
128 bool dumpSessionInfo() const;
129
130 /**
131 * Create a request for a session
132 *
133 * @param request [out] created request
134 * @param captureIntent [in] capture intent
135 * @param session [in] capture session (optional, if NULL the internal session is used)
136 */
137 bool createRequest(TrackedUniqueObj<Argus::Request> &request,
138 Argus::CaptureIntent captureIntent, Argus::CaptureSession *session = NULL);
139
140 /**
141 * create a event queue
142 *
143 * @param eventTypes [in]
144 * @param eventQueue [out] created event queue
145 * @param session [in] capture session (optional, if NULL the internal session is used)
146 */
147 bool createEventQueue(const std::vector<Argus::EventType> &eventTypes,
148 Argus::UniqueObj<Argus::EventQueue> &eventQueue, Argus::CaptureSession *session = NULL);
149
150
151 /**
152 * Submits a single capture request for a session
153 *
154 * @param request [in] capture request
155 * @param session [in] capture session (optional, if NULL the internal session is used)
156 */
157 bool capture(Argus::Request *request, Argus::CaptureSession *session = NULL);
158
159 /**
160 * Start a repeating request for a session
161 *
162 * @param request [in] request
163 * @param session [in] capture session (optional, if NULL the internal session is used)
164 */
165 bool startRepeat(Argus::Request *request, Argus::CaptureSession *session = NULL);
166
167 /**
168 * Start a repeating burst request for a session
169 *
170 * @param requestList [in] burst request
171 * @param session [in] capture session (optional, if NULL the internal session is used)
172 */
173 bool startRepeatBurst(const std::vector<const Argus::Request*>& requestList,
174 Argus::CaptureSession *session = NULL);
175
176 /**
177 * Clears the repeating request for a session
178 *
179 * @param session [in] capture session (optional, if NULL the internal session is used)
180 */
181 bool stopRepeat(Argus::CaptureSession *session = NULL);
182
183 /**
184 * Restart the currently active requests to pick up changed settings.
185 */
186 bool restartActiveRequests();
187
188 /**
189 * Returns the maximum number of capture requests for a session that can be included in a
190 * burst capture.
191 *
192 * @param session [in] capture session (optional, if NULL the internal session is used)
193 */
194 uint32_t maxBurstRequests(Argus::CaptureSession *session = NULL);
195
196 /**
197 * Wait until all pending captures for a session are complete
198 *
199 * @param session [in] capture session (optional, if NULL the internal session is used)
200 */
201 bool waitForIdle(Argus::CaptureSession *session = NULL);
202
203 /**
204 * Create an output stream of an request of a session.
205 *
206 * @param request [in] request
207 * @param enableMetadata [in] whether or not to enable meatdata for the stream
208 * @param stream [out] the created Argus output stream
209 * @param session [in] capture session (optional, if NULL the internal session is used)
210 */
211 bool createOutputStream(Argus::Request *request, bool enableMetadata,
212 Argus::UniqueObj<Argus::OutputStream> &stream,
213 Argus::CaptureSession *session = NULL);
214
215 /**
216 * Enable an output stream of an request
217 */
218 bool enableOutputStream(Argus::Request *request, Argus::OutputStream *stream);
219
220 /**
221 * Disable an output stream of an request
222 */
223 bool disableOutputStream(Argus::Request *request, Argus::OutputStream *stream);
224
225 /**
226 * Output a message if verbose mode is enabled
227 */
228 bool message(const char *msg, ...);
229
230 private:
231 // the current properties need to be initialized first, some Value<> members below use them
232 // for the validator
233
234 // current device properties
235 std::vector<Argus::SensorMode*> m_sensorModes; ///< sensor modes
236 Value<Argus::Range<int32_t> > m_deviceFocusPositionRange; ///< device focus position range
237 Value<Argus::Range<float> > m_deviceExposureCompensationRange; ///< exposure compensation range
238 Value<Argus::Range<Argus::Range<float> > >
239 m_deviceIspDigitalGainRange; ///< device isp digital gain range
240
241 // current sensor mode properties
242 Value<Argus::Range<Argus::Range<uint64_t> > >
243 m_sensorExposureTimeRange; ///< exposure time range
244 Value<Argus::Range<Argus::Range<float> > >
245 m_sensorAnalogGainRange; ///< analog gain range
246 Value<Argus::Range<float> > m_sensorFrameRateRange; ///< frame rate range
247
248 public:
249 Value<uint32_t> m_deviceIndex; ///< the device index
250 Value<bool> m_deviceOpen; ///< if set then the device is open
251 Value<bool> m_sensorModeValid;
252
253
254 Value<bool> m_verbose; ///< if set verbose mode is enabled and messages are printed
255
256 Value<bool> m_kpi; ///< if set kpi mode is enabled and kpi number are printed
257
258 // source settings
259 Value<Argus::Range<uint64_t> > m_exposureTimeRange; ///< exposure time range
260 Value<Argus::Range<float> > m_gainRange; ///< gain range
261 Value<uint32_t> m_sensorModeIndex; ///< the sensor mode index
262 Value<float> m_frameRate; ///< in frames per second
263 Value<int32_t> m_focusPosition; ///< focus position
264 Value<Argus::PixelFormat> m_captureYuvFormat; ///< NV12 vs. P016 YUV color depth
265
266 // denoise settings
267 Value<Argus::DenoiseMode> m_denoiseMode; ///< denoise mode
268 Value<float> m_denoiseStrength; ///< denoise strength
269
270 // edge enhance settings
271 Value<Argus::EdgeEnhanceMode> m_edgeEnhanceMode; ///< edge enhancement mode
272 Value<float> m_edgeEnhanceStrength; ///< edge enhancement strength
273
274 // auto control settings
275 Value<Argus::AeAntibandingMode> m_aeAntibandingMode; ///< auto exposure antibanding mode
276 Value<bool> m_aeLock; ///< auto exposure lock
277 Value<bool> m_awbLock; ///< auto white balance lock
278 Value<Argus::AwbMode> m_awbMode; ///< auto white balance mode
279 Value<float> m_exposureCompensation;///< exposure compensation
280 Value<Argus::Range<float> > m_ispDigitalGainRange;///< ISP digital Gain Range
281
282 // still settings
283 Value<StillFileType> m_stillFileType; ///< the still image file format
284
285 // video settings
286 Value<VideoPipeline::VideoFormat> m_videoFormat; ///< the video format
287 Value<VideoPipeline::VideoFileType> m_videoFileType; ///< the video file type
288 Value<uint32_t> m_videoBitRate; ///< the video bit rate
289
290 // output settings
291 Value<Argus::Size2D<uint32_t> > m_outputSize; ///< output size
292 Value<std::string> m_outputPath; ///< output path
293
294 // DeFog extension
295 Value<bool> m_deFogEnable; ///< enable
296 Value<float> m_deFogAmount; ///< amount of fog to be removed. Range 0.0 - 1.0 (none - all)
297 Value<float> m_deFogQuality; ///< quality of the effect. Range 0.0 - 1.0 (low - high)
298
299 private:
300 Dispatcher();
301 ~Dispatcher();
302
303 // this is a singleton, hide copy constructor etc.
304 Dispatcher(const Dispatcher&);
305 Dispatcher& operator=(const Dispatcher&);
306
307 /**
308 * Initialize the dispatcher
309 */
310 bool initialize();
311
312 /**
313 * Create the internal session
314 */
315 bool createSession();
316
317 /**
318 * Close the internal session
319 */
320 bool closeSession();
321
322 /**
323 * Start tracking a session
324 */
325 bool track(Argus::CaptureSession *session);
326
327 /**
328 * No longer track a session
329 */
330 bool untrack(Argus::CaptureSession *session);
331
332 /**
333 * Start tracking a request
334 */
335 bool track(Argus::Request *request);
336
337 /**
338 * No longer track a request
339 */
340 bool untrack(Argus::Request *request);
341
342 /**
343 * Register an IDenoiseSettings observer
344 */
345 bool registerObserver(Argus::IDenoiseSettings *iDenoiseSettings);
346
347 /**
348 * Register an IEdgeEnhanceSettings observer
349 */
350 bool registerObserver(Argus::IEdgeEnhanceSettings *iEdgeEnhanceSettings);
351
352 /**
353 * Register an ISourceSettings observer
354 */
355 bool registerObserver(Argus::ISourceSettings *iSourceSettings);
356
357 /**
358 * Register an IAutoControlSettings observer
359 */
360 bool registerObserver(Argus::IAutoControlSettings *iAutoControlSettings);
361
362 /**
363 * Register an IDeFogSettings observer
364 */
365 bool registerObserver(Argus::Ext::IDeFogSettings *iDeFogSettings);
366
367 /**
368 * Unregister an interface which had been registered as an observer.
369 */
370 bool unregisterObserver(Argus::Interface *interface);
371
372 /**
373 * Callback when the device index changes.
374 */
375 bool onDeviceIndexChanged(const Observed &source);
376
377 /**
378 * Callback when the sensor mode index changes.
379 */
380 bool onSensorModeIndexChanged(const Observed &source);
381
382 bool m_initialized; ///< if set the dispatcher is initialized
383
384 std::list<IObserverForInterface*> m_observers;
385
386 Argus::UniqueObj<Argus::CameraProvider> m_cameraProvider; ///< camera provider
387 Argus::ICameraProvider *m_iCameraProvider; ///< camera provider interface
388
389 std::vector<Argus::CameraDevice*> m_cameraDevices; ///< a list of available devices
390
391 TrackedUniqueObj<Argus::CaptureSession> m_captureSession; ///< internal capture session
392
393 class ActiveSession
394 {
395 public:
396 ActiveSession(Argus::CaptureSession *session)
397 : m_session(session)
398 {
399 }
400
401 Argus::CaptureSession *m_session;
402 std::vector<const Argus::Request*> m_requests;
403 };
404 typedef std::list<ActiveSession> ActiveSessionList;
405 ActiveSessionList m_activeSessions;
406 };
407
408 }; // namespace ArgusSamples
409
410 #endif // DISPATCHER_H