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, 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
265 // denoise settings
266 Value<Argus::DenoiseMode> m_denoiseMode; ///< denoise mode
267 Value<float> m_denoiseStrength; ///< denoise strength
268
269 // edge enhance settings
270 Value<Argus::EdgeEnhanceMode> m_edgeEnhanceMode; ///< edge enhancement mode
271 Value<float> m_edgeEnhanceStrength; ///< edge enhancement strength
272
273 // video stabilization settings
274 Value<Argus::VideoStabilizationMode> m_vstabMode; ///< video stabilization mode
275
276 // auto control settings
277 Value<Argus::AeAntibandingMode> m_aeAntibandingMode; ///< auto exposure antibanding mode
278 Value<bool> m_aeLock; ///< auto exposure lock
279 Value<bool> m_awbLock; ///< auto white balance lock
280 Value<Argus::AwbMode> m_awbMode; ///< auto white balance mode
281 Value<float> m_exposureCompensation;///< exposure compensation
282 Value<Argus::Range<float> > m_ispDigitalGainRange;///< ISP digital Gain Range
283
284 // video settings
285 Value<VideoPipeline::VideoFormat> m_videoFormat; ///< the video format
286 Value<VideoPipeline::VideoFileType> m_videoFileType; ///< the video file type
287 Value<uint32_t> m_videoBitRate; ///< the video bit rate
288
289 // output settings
290 Value<Argus::Size2D<uint32_t> > m_outputSize; ///< output size
291 Value<std::string> m_outputPath; ///< output path
292
293 // DeFog extension
294 Value<bool> m_deFogEnable; ///< enable
295 Value<float> m_deFogAmount; ///< amount of fog to be removed. Range 0.0 - 1.0 (none - all)
296 Value<float> m_deFogQuality; ///< quality of the effect. Range 0.0 - 1.0 (low - high)
297
298 private:
299 Dispatcher();
300 ~Dispatcher();
301
302 // this is a singleton, hide copy constructor etc.
303 Dispatcher(const Dispatcher&);
304 Dispatcher& operator=(const Dispatcher&);
305
306 /**
307 * Initialize the dispatcher
308 */
309 bool initialize();
310
311 /**
312 * Create the internal session
313 */
314 bool createSession();
315
316 /**
317 * Close the internal session
318 */
319 bool closeSession();
320
321 /**
322 * Start tracking a session
323 */
324 bool track(Argus::CaptureSession *session);
325
326 /**
327 * No longer track a session
328 */
329 bool untrack(Argus::CaptureSession *session);
330
331 /**
332 * Start tracking a request
333 */
334 bool track(Argus::Request *request);
335
336 /**
337 * No longer track a request
338 */
339 bool untrack(Argus::Request *request);
340
341 /**
342 * Register an IDenoiseSettings observer
343 */
344 bool registerObserver(Argus::IDenoiseSettings *iDenoiseSettings);
345
346 /**
347 * Register an IEdgeEnhanceSettings observer
348 */
349 bool registerObserver(Argus::IEdgeEnhanceSettings *iEdgeEnhanceSettings);
350
351 /**
352 * Register an IVideoStabilizationSettings observer
353 */
354 bool registerObserver(Argus::IVideoStabilizationSettings *iVideoStabilizationSettings);
355
356 /**
357 * Register an ISourceSettings observer
358 */
359 bool registerObserver(Argus::ISourceSettings *iSourceSettings);
360
361 /**
362 * Register an IAutoControlSettings observer
363 */
364 bool registerObserver(Argus::IAutoControlSettings *iAutoControlSettings);
365
366 /**
367 * Register an IDeFogSettings observer
368 */
369 bool registerObserver(Argus::Ext::IDeFogSettings *iDeFogSettings);
370
371 /**
372 * Unregister an interface which had been registered as an observer.
373 */
374 bool unregisterObserver(Argus::Interface *interface);
375
376 /**
377 * Callback when the device index changes.
378 */
379 bool onDeviceIndexChanged(const Observed &source);
380
381 /**
382 * Callback when the sensor mode index changes.
383 */
384 bool onSensorModeIndexChanged(const Observed &source);
385
386 bool m_initialized; ///< if set the dispatcher is initialized
387
388 std::list<IObserverForInterface*> m_observers;
389
390 Argus::UniqueObj<Argus::CameraProvider> m_cameraProvider; ///< camera provider
391 Argus::ICameraProvider *m_iCameraProvider; ///< camera provider interface
392
393 std::vector<Argus::CameraDevice*> m_cameraDevices; ///< a list of available devices
394
395 TrackedUniqueObj<Argus::CaptureSession> m_captureSession; ///< internal capture session
396
397 class ActiveSession
398 {
399 public:
400 ActiveSession(Argus::CaptureSession *session)
401 : m_session(session)
402 {
403 }
404
405 Argus::CaptureSession *m_session;
406 std::vector<const Argus::Request*> m_requests;
407 };
408 typedef std::list<ActiveSession> ActiveSessionList;
409 ActiveSessionList m_activeSessions;
410 };
411
412 }; // namespace ArgusSamples
413
414 #endif // DISPATCHER_H