Libargus API
Libargus Camera API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
EGLStream.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2017-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of NVIDIA CORPORATION nor the names of its
14  * contributors may be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 /**
31  * @file
32  * <b>Libargus API: EGLStream API</b>
33  *
34  * @b Description: This file defines an EGLStream-linked Output/Input Stream type.
35  */
36 
37 #ifndef _ARGUS_EGL_STREAM_H
38 #define _ARGUS_EGL_STREAM_H
39 
40 namespace Argus
41 {
42 
43 /**
44  * @defgroup ArgusEGLOutputStream EGLOutputStream
45  * @ingroup ArgusOutputStream
46  * @ref ArgusOutputStream type that generates frames as an EGLStream producer (STREAM_TYPE_EGL).
47  *
48  * EGLStream-linked OutputStream objects maintain a connection to an EGLStream
49  * as the producer endpoint. The EGLStream implementation is responsible for
50  * buffer allocation, management, and synchronization as frames are presented
51  * to the EGLStream from libargus and then consumed using an EGLStream consumer.
52  */
53 /**
54  * @defgroup ArgusEGLOutputStreamSettings EGLOutputStreamSettings
55  * @ingroup ArgusOutputStreamSettings
56  * Settings type used to configure/create @ref ArgusEGLOutputStream streams (STREAM_TYPE_EGL).
57  */
58 
59 /**
60  * @defgroup ArgusEGLInputStream EGLInputStream
61  * @ingroup ArgusInputStream
62  * @ref ArgusInputStream type that generates frames as an EGLStream consumer (STREAM_TYPE_EGL).
63  *
64  * EGLStream-linked InputStream objects maintain a connection to an EGLStream
65  * as the consumer startingpoint. The EGLStream implementation is responsible for
66  * buffer allocation, management, and synchronization as frames are produced by EGLStream
67  * consumer and presented to EGLStream to be further consumed by InputStream consumer
68  * in libargus.
69  */
70 /**
71  * @defgroup ArgusEGLInputStreamSettings EGLInputStreamSettings
72  * @ingroup ArgusInputStreamSettings
73  * Settings type used to configure/create @ref ArgusEGLInputStream streams (STREAM_TYPE_EGL).
74  */
75 
76 /**
77  * @ref ArgusOutputStream type that generates frames as an EGLStream producer (STREAM_TYPE_EGL).
78  * @ingroup ArgusOutputStreamSettings
79  */
80 /**
81  * @ref ArgusInputStream type that generates frames as an EGLStream producer (STREAM_TYPE_EGL).
82  * @ingroup ArgusInputStream ArgusInputStreamSettings
83  */
84 DEFINE_UUID(StreamType, STREAM_TYPE_EGL, 3a659360,5231,11e7,9598,18,00,20,0c,9a,66);
85 
86 /**
87  * Defines the EGLStream queue mode of operation (see IEGLOutputStreamSettings::setMode).
88  */
89 DEFINE_NAMED_UUID_CLASS(EGLStreamMode);
90 DEFINE_UUID(EGLStreamMode, EGL_STREAM_MODE_MAILBOX, 33661d40,3ee2,11e6,bdf4,08,00,20,0c,9a,66);
91 DEFINE_UUID(EGLStreamMode, EGL_STREAM_MODE_FIFO, 33661d41,3ee2,11e6,bdf4,08,00,20,0c,9a,66);
92 
93 /**
94  * @class IEGLOutputStreamSettings
95  *
96  * Interface that exposes the settings used for EGLStream-linked OutputStream creation.
97  *
98  * @ingroup ArgusEGLOutputStreamSettings
99  */
100 DEFINE_UUID(InterfaceID, IID_EGL_OUTPUT_STREAM_SETTINGS, 3a659361,5231,11e7,9598,18,00,20,0c,9a,66);
102 {
103 public:
104  static const InterfaceID& id() { return IID_EGL_OUTPUT_STREAM_SETTINGS; }
105 
106  /**
107  * Set the format of the stream.
108  * Default value: PIXEL_FMT_UNKNOWN
109  */
110  virtual Status setPixelFormat(const PixelFormat& format) = 0;
111  virtual PixelFormat getPixelFormat() const = 0;
112 
113  /**
114  * Set the resolution of the stream.
115  * Default value: (0, 0)
116  */
117  virtual Status setResolution(const Size2D<uint32_t>& resolution) = 0;
118  virtual Size2D<uint32_t> getResolution() const = 0;
119 
120  /**
121  * Set the number of exposures per stream frame.
122  * This number should match the number of exposures that are going to be provided
123  * with each stream frame when capturing from multi-exposure WDR sources.
124  * Note that the EGLStream consumer must support consuming multi-exposure/buffer
125  * EGLStreams. In the case of the EGLStream::FrameConsumer consumer, the multiple
126  * exposures are treated as separate buffers in the acquired Image and may be
127  * accessed using any Image interface which supports multi-buffer/plane image access
128  * (see EGLStream::IImage::getBufferCount()).
129  * Default value: 1
130  */
131  virtual Status setExposureCount(uint32_t exposureCount) = 0;
132  virtual uint32_t getExposureCount() const = 0;
133 
134  /**
135  * Set the EGLDisplay the created stream must belong to.
136  * Default value: EGL_NO_DISPLAY - stream is display-agnostic.
137  */
138  virtual Status setEGLDisplay(EGLDisplay eglDisplay) = 0;
139  virtual EGLDisplay getEGLDisplay() const = 0;
140 
141  /**
142  * Sets the mode of the OutputStream. Available options are:
143  *
144  * MAILBOX:
145  * In this mode, only the newest frame is made available to the consumer. When Argus
146  * completes a frame it empties the mailbox and inserts the new frame into the mailbox.
147  * The consumer then retrieves the frame from the mailbox and processes it; when
148  * finished, the frame is either placed back into the mailbox (if the mailbox is empty)
149  * or discarded (if the mailbox is not empty). This mode implies 2 things:
150  *
151  * - If the consumer consumes frames slower than Argus produces frames, then some
152  * frames may be lost (never seen by the consumer).
153  *
154  * - If the consumer consumes frames faster than Argus produces frames, then the
155  * consumer may see some frames more than once.
156  *
157  * FIFO:
158  * When using this mode, every producer frame is made available to the consumer through
159  * the use of a fifo queue for the frames. When using this mode, the fifo queue length
160  * must be specified using setFifoLength. When Argus completes a frame it inserts it to
161  * the head of the fifo queue. If the fifo is full (already contains the number of frames
162  * equal to the fifo queue length), Argus will stall until the fifo is no longer
163  * full. The consumer consumes frames from the tail of the queue; however, if the
164  * consumer releases a frame while the queue is empty, the frame is set aside and will
165  * be returned again the next time the consumer requests a frame if another new frame
166  * has not been inserted into the fifo queue before then. Once a new frame is inserted
167  * into the fifo queue, any previously released frame will be permanently discarded.
168  * This mode implies:
169  *
170  * - Frames are never discarded until the consumer has processed them.
171  *
172  * - If the consumer consumes frames slower than Argus produces them, Argus will stall.
173  *
174  * - If the consumer consumes frames faster than Argus produces them, then the
175  * consumer may see some frames more than once.
176  *
177  * Default value: STREAM_MODE_MAILBOX
178  */
179  virtual Status setMode(const EGLStreamMode& mode) = 0;
180  virtual EGLStreamMode getMode() const = 0;
181 
182  /**
183  * Sets the FIFO queue length of the stream. This value is only used if the stream is using
184  * the FIFO mode (@see OutputStreamSettings::setMode). Value must be > 0.
185  * Default value: 1
186  */
187  virtual Status setFifoLength(uint32_t fifoLength) = 0;
188  virtual uint32_t getFifoLength() const = 0;
189 
190  /**
191  * Enables or disables embedding Argus CaptureMetadata within frames written to the EGLStream.
192  * Enabling this will allow an EGLStream::MetadataContainer to be created from frames acquired
193  * on the consumer side of the EGLStream that will expose the EGLStream::IArgusCaptureMetadata
194  * interface, which in turn provides access to the CaptureMetadata corresponding to that frame.
195  * This will also enable the IArgusCaptureMetadata interface directly on EGLStream::Frames
196  * acquired by an EGLStream::FrameConsumer.
197  * Default value: disabled.
198  */
199  virtual Status setMetadataEnable(bool metadataEnable) = 0;
200  virtual bool getMetadataEnable() const = 0;
201 
202  /**
203  * @returns True if the output pixel format is supported by the CaptureSession for the
204  * queried sensor mode. Otherwise, returns false.
205  *
206  * @param[in] sensorMode The sensor mode being queried for the output pixel type.
207  * @param[in] outputFormat The output pixel format being queried for support.
208  */
209  virtual bool supportsOutputStreamFormat(const SensorMode* sensorMode,
210  const PixelFormat& outputFormat) const = 0;
211 
212  /**
213  * Set the output buffer layout of the stream. Available options are
214  *
215  * BufferLayout_PitchLinear:
216  *
217  * Indicates pitch-linear layout, using pitch-linear mapping,
218  * in which pixels are assigned incrementing addresses across each successive row
219  * of the image.
220  *
221  * BufferLayout_BlockLinear:
222  *
223  * Indicates block-linear layout. This layout is similar to pitch-linear layout,
224  * but maps blocks of pixels using pitch-linear addressing, rather than
225  * individual pixels. This layout provides spatial locality for addressing
226  * and improves memory access performance. NVIDIA recommends using block-linear
227  * layout whenever possible.
228  *
229  * Default value: BufferLayout_BlockLinear
230  */
231  virtual Status setBufferLayout(const BufferLayout& layout) = 0;
232  virtual BufferLayout getBufferLayout() const = 0;
233 
234 protected:
236 };
237 
238 /**
239  * @class IEGLOutputStream
240  *
241  * Interface that exposes the methods available to an EGLStream-linked OutputStream.
242  *
243  * @ingroup ArgusEGLOutputStream
244  */
245 DEFINE_UUID(InterfaceID, IID_EGL_OUTPUT_STREAM, 3a659362,5231,11e7,9598,18,00,20,0c,9a,66);
247 {
248 public:
249  static const InterfaceID& id() { return IID_EGL_OUTPUT_STREAM; }
250 
251  /**
252  * Waits until both the producer and consumer endpoints of the stream are connected.
253  *
254  * @param[in] timeout The timeout in nanoseconds.
255  *
256  * @returns success/status of this call.
257  */
258  virtual Status waitUntilConnected(uint64_t timeout = TIMEOUT_INFINITE) const = 0;
259 
260  /**
261  * Disconnects the stream from the underlying EGLStream.
262  */
263  virtual void disconnect() = 0;
264 
265  /**
266  * Returns the format of the stream.
267  */
268  virtual PixelFormat getPixelFormat() const = 0;
269 
270  /**
271  * Returns the image resolution of the stream, in pixels.
272  */
273  virtual Size2D<uint32_t> getResolution() const = 0;
274 
275  /**
276  * Returns the EGLDisplay the stream's EGLStream belongs to.
277  */
278  virtual EGLDisplay getEGLDisplay() const = 0;
279 
280  /**
281  * Returns the EGLStream backing the stream.
282  */
283  virtual EGLStreamKHR getEGLStream() const = 0;
284 
285 protected:
287 };
288 
289 /**
290  * @class IEGLInputStreamSettings
291  *
292  * Interface that exposes the settings used for EGLStream-linked InputStream creation.
293  *
294  * @ingroup ArgusEGLInputStreamSettings
295  */
296 DEFINE_UUID(InterfaceID, IID_EGL_INPUT_STREAM_SETTINGS, c3579170,b1ac,11ec,a893,08,00,20,0c,9a,66);
298 {
299 public:
300  static const InterfaceID& id() { return IID_EGL_INPUT_STREAM_SETTINGS; }
301 
302  /**
303  * Set the format of the stream.
304  * Default value: PIXEL_FMT_UNKNOWN
305  */
306  virtual Status setPixelFormat(const PixelFormat& format) = 0;
307  virtual PixelFormat getPixelFormat() const = 0;
308 
309  /**
310  * Set the resolution of the stream.
311  * Default value: (0, 0)
312  */
313  virtual Status setResolution(const Size2D<uint32_t>& resolution) = 0;
314  virtual Size2D<uint32_t> getResolution() const = 0;
315 
316  /**
317  * Set the number of exposures per stream frame.
318  * This number should match the number of exposures that are going to be provided
319  * with each stream frame when capturing from multi-exposure WDR sources.
320  * Note that the EGLStream consumer must support consuming multi-exposure/buffer
321  * EGLStreams. In the case of the EGLStream::FrameConsumer consumer, the multiple
322  * exposures are treated as separate buffers in the acquired Image and may be
323  * accessed using any Image interface which supports multi-buffer/plane image access
324  * (see EGLStream::IImage::getBufferCount()).
325  * Default value: 1
326  */
327  virtual Status setExposureCount(uint32_t exposureCount) = 0;
328  virtual uint32_t getExposureCount() const = 0;
329 
330 
331  /**
332  * Set the EGLDisplay the created stream must belong to.
333  * Default value: EGL_NO_DISPLAY - stream is display-agnostic.
334  */
335  virtual Status setEGLDisplay(EGLDisplay eglDisplay) = 0;
336  virtual EGLDisplay getEGLDisplay() const = 0;
337 
338  /**
339  * Sets the FIFO queue length of the stream. This value must be > 0 as currently input streams
340  * only support FIFO mode of operation. In this mode every producer frame is made available to
341  * the consumer through the use of a fifo queue for the frames. If the fifo is full (already
342  * contains the number of frames equal to the fifo queue length), producer will stall until
343  * the fifo is no longer full. The consumer consumes frames from the tail of the queue,
344  * however, if the consumer releases a frame while the queue is empty, the frame is set aside
345  * and will be returned again the next time the consumer requests a frame if another new frame
346  * has not been inserted into the fifo queue before then. Once a new frame is inserted
347  * into the fifo queue, any previously released frame will be permanently discarded.
348  * This mode implies:
349  * - Frames are never discarded until the consumer has processed them.
350  *
351  * - If the consumer consumes frames slower than producer produces them, producer will stall.
352  *
353  * - If the consumer consumes frames faster than producer produces them, then the
354  * consumer may see some frames more than once.
355  *
356  * Default value: 1
357  */
358  virtual Status setFifoLength(uint32_t fifoLength) = 0;
359  virtual uint32_t getFifoLength() const = 0;
360 
361  /**
362  * @returns True if the input pixel format is supported by the CaptureSession for the
363  * queried sensor mode. Otherwise, returns false.
364  *
365  * @param[in] sensorMode The sensor mode being queried for the input pixel type.
366  * @param[in] inputFormat The input pixel format being queried for support.
367  */
368  virtual bool supportsInputStreamFormat(const SensorMode* sensorMode,
369  const PixelFormat& inputFormat) const = 0;
370 
371 protected:
373 };
374 
375 /**
376  * @class IEGLInputStream
377  *
378  * Interface that exposes the methods available to an EGLStream-linked InputStream.
379  *
380  * @ingroup ArgusEGLInputStream
381  */
382 DEFINE_UUID(InterfaceID, IID_EGL_INPUT_STREAM, c3579171,b1ac,11ec,a893,08,00,20,0c,9a,66)
384 {
385 public:
386  static const InterfaceID& id() { return IID_EGL_INPUT_STREAM; }
387 
388  /**
389  * Waits until both the consumer endpoints and producer of the stream are connected.
390  *
391  * @param[in] timeout The timeout in nanoseconds.
392  *
393  * @returns success/status of this call.
394  */
395  virtual Status waitUntilConnected(uint64_t timeout = TIMEOUT_INFINITE) const = 0;
396 
397  /**
398  * Disconnects the stream from the underlying EGLStream.
399  */
400  virtual void disconnect() = 0;
401 
402  /**
403  * Returns the format of the stream.
404  */
405  virtual PixelFormat getPixelFormat() const = 0;
406 
407  /**
408  * Returns the image resolution of the stream, in pixels.
409  */
410  virtual Size2D<uint32_t> getResolution() const = 0;
411 
412  /**
413  * Returns the EGLDisplay the stream's EGLStream belongs to.
414  */
415  virtual EGLDisplay getEGLDisplay() const = 0;
416 
417  /**
418  * Returns the EGLStream backing the stream.
419  */
420  virtual EGLStreamKHR getEGLStream() const = 0;
421 
422 protected:
424 };
425 
426 } // namespace Argus
427 
428 #endif // _ARGUS_EGL_STREAM_H