Libargus API
Libargus Camera API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Stream.h
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 /**
30  * @file
31  * <b>Libargus API: Stream API</b>
32  *
33  * @b Description: Defines stream related objects and interfaces.
34  */
35 
36 #ifndef _ARGUS_STREAM_H
37 #define _ARGUS_STREAM_H
38 
39 namespace Argus
40 {
41 
42 DEFINE_NAMED_UUID_CLASS(StreamMode);
43 DEFINE_UUID(StreamMode, STREAM_MODE_MAILBOX, 33661d40,3ee2,11e6,bdf4,08,00,20,0c,9a,66);
44 DEFINE_UUID(StreamMode, STREAM_MODE_FIFO, 33661d41,3ee2,11e6,bdf4,08,00,20,0c,9a,66);
45 
46 /**
47  * Object representing an output stream capable of receiving image frames from a capture.
48  *
49  * Output streams are created and owned by CaptureSessions, and they maintain
50  * a connection with an EGLStream in order to present frames as an EGLStream producer.
51  *
52  * @defgroup ArgusOutputStream OutputStream
53  * @ingroup ArgusObjects
54  */
56 {
57 protected:
59 };
60 
61 /**
62  * Container for settings used to configure/create an OutputStream.
63  *
64  * These are created by CaptureSessions and used for calls to ICaptureSession::createOutputStream.
65  *
66  * @defgroup ArgusOutputStreamSettings OutputStreamSettings
67  * @ingroup ArgusObjects
68  */
70 {
71 protected:
73 };
74 
75 /**
76  * @class IStream
77  *
78  * Interface that exposes common Stream properties.
79  *
80  * @ingroup ArgusOutputStream
81  */
82 DEFINE_UUID(InterfaceID, IID_STREAM, 8f50dade,cc26,4ec6,9d2e,d9,d0,19,2a,ef,06);
83 class IStream : public Interface
84 {
85 public:
86  static const InterfaceID& id() { return IID_STREAM; }
87 
88  /**
89  * Waits until both the producer and consumer endpoints of the stream are connected.
90  *
91  * @param[in] timeout The timeout in nanoseconds.
92  *
93  * @returns success/status of this call.
94  */
95  virtual Status waitUntilConnected(uint64_t timeout = TIMEOUT_INFINITE) const = 0;
96 
97  /**
98  * Disconnects the stream from the underlying EGLStream.
99  */
100  virtual void disconnect() = 0;
101 
102  /**
103  * Returns the format of the stream.
104  */
105  virtual PixelFormat getPixelFormat() const = 0;
106 
107  /**
108  * Returns the image resolution of the stream, in pixels.
109  */
110  virtual Size2D<uint32_t> getResolution() const = 0;
111 
112  /**
113  * Returns the EGLDisplay the stream's EGLStream belongs to.
114  */
115  virtual EGLDisplay getEGLDisplay() const = 0;
116 
117  /**
118  * Returns the EGLStream backing the stream.
119  */
120  virtual EGLStreamKHR getEGLStream() const = 0;
121 
122 protected:
123  ~IStream() {}
124 };
125 
126 /**
127  * @class IOutputStreamSettings
128  *
129  * Interface that exposes the settings used for OutputStream creation.
130  *
131  * @ingroup ArgusOutputStreamSettings
132  */
133 DEFINE_UUID(InterfaceID, IID_OUTPUT_STREAM_SETTINGS, 52f2b830,3d52,11e6,bdf4,08,00,20,0c,9a,66);
135 {
136 public:
137  static const InterfaceID& id() { return IID_OUTPUT_STREAM_SETTINGS; }
138 
139  /**
140  * Set the format of the stream.
141  * Default value: PIXEL_FMT_UNKNOWN
142  */
143  virtual Status setPixelFormat(const PixelFormat& format) = 0;
144  virtual PixelFormat getPixelFormat() const = 0;
145 
146  /**
147  * Set the resolution of the stream.
148  * Default value: (0, 0)
149  */
150  virtual Status setResolution(const Size2D<uint32_t>& resolution) = 0;
151  virtual Size2D<uint32_t> getResolution() const = 0;
152 
153  /**
154  * Set the camera device to use as the source for this stream.
155  * Default value: First available device in the session.
156  */
157  virtual Status setCameraDevice(CameraDevice* device) = 0;
158  virtual CameraDevice* getCameraDevice() const = 0;
159 
160  /**
161  * Set the EGLDisplay the created stream must belong to.
162  * Default value: EGL_NO_DISPLAY - stream is display-agnostic.
163  */
164  virtual Status setEGLDisplay(EGLDisplay eglDisplay) = 0;
165  virtual EGLDisplay getEGLDisplay() const = 0;
166 
167  /**
168  * Sets the mode of the OutputStream. Available options are:
169  *
170  * MAILBOX:
171  * In this mode, only the newest frame is made available to the consumer. When libargus
172  * completes a frame it empties the mailbox and inserts the new frame into the mailbox.
173  * The consumer then retrieves the frame from the mailbox and processes it; when
174  * finished, the frame is either placed back into the mailbox (if the mailbox is empty)
175  * or discarded (if the mailbox is not empty). This mode implies 2 things:
176  *
177  * - If the consumer consumes frames slower than libargus produces frames, then some
178  * frames may be lost (never seen by the consumer).
179  *
180  * - If the consumer consumes frames faster than libargus produces frames, then the
181  * consumer may see some frames more than once.
182  *
183  * FIFO:
184  * When using this mode, every producer frame is made available to the consumer through
185  * the use of a fifo queue for the frames. When using this mode, the fifo queue length
186  * must be specified using setFifoLength. When libargus completes a frame it inserts it to
187  * the head of the fifo queue. If the fifo is full (already contains the number of frames
188  * equal to the fifo queue length), libargus will stall until the fifo is no longer
189  * full. The consumer consumes frames from the tail of the queue; however, if the
190  * consumer releases a frame while the queue is empty, the frame is set aside and will
191  * be returned again the next time the consumer requests a frame if another new frame
192  * has not been inserted into the fifo queue before then. Once a new frame is inserted
193  * into the fifo queue, any previously released frame will be permanently discarded.
194  * This mode implies:
195  *
196  * - Frames are never discarded until the consumer has processed them.
197  *
198  * - If the consumer consumes frames slower than libargus produces them,
199  * libargus will stall.
200  *
201  * - If the consumer consumes frames faster than libargus produces them, then the
202  * consumer may see some frames more than once.
203  *
204  * Default value: STREAM_MODE_MAILBOX
205  */
206  virtual Status setMode(const StreamMode& mode) = 0;
207  virtual StreamMode getMode() const = 0;
208 
209  /**
210  * Sets the FIFO queue length of the stream. This value is only used if the stream is using
211  * the FIFO mode (@see OutputStreamSettings::setMode). Value must be > 0.
212  * Default value: 1
213  */
214  virtual Status setFifoLength(uint32_t fifoLength) = 0;
215  virtual uint32_t getFifoLength() const = 0;
216 
217  /**
218  * Enable or disable embedding libargus CaptureMetadata within frames written to the EGLStream.
219  * Enabling this will allow an EGLStream::MetadataContainer to be created from frames acquired
220  * on the consumer side of the EGLStream that will expose the EGLStream::IArgusCaptureMetadata
221  * interface, which in turn provides access to the CaptureMetadata corresponding to that frame.
222  * This will also enable the IArgusCaptureMetadata interface directly on EGLStream::Frames
223  * acquired by an EGLStream::FrameConsumer.
224  * Default value: disabled.
225  */
226  virtual Status setMetadataEnable(bool metadataEnable) = 0;
227  virtual bool getMetadataEnable() const = 0;
228 
229  /**
230  * @returns True if the output pixel format is supported by the CaptureSession for the
231  * queried sensor mode. Otherwise, returns false.
232  *
233  * @param[in] sensorMode The sensor mode being queried for the output pixel type.
234  * @param[in] outputFormat The output pixel format being queried for support.
235  */
236  virtual bool supportsOutputStreamFormat(const SensorMode* sensorMode,
237  const PixelFormat& outputFormat) const = 0;
238 
239 protected:
241 };
242 
243 } // namespace Argus
244 
245 #endif // _ARGUS_STREAM_H