EGLStream.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. /*
  2. * Copyright (c) 2017-2022, 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. * @file
  30. * <b>Libargus API: EGLStream API</b>
  31. *
  32. * @b Description: This file defines an EGLStream-linked Output/Input Stream type.
  33. */
  34. #ifndef _ARGUS_EGL_STREAM_H
  35. #define _ARGUS_EGL_STREAM_H
  36. namespace Argus
  37. {
  38. /**
  39. * @defgroup ArgusEGLOutputStream EGLOutputStream
  40. * @ingroup ArgusOutputStream
  41. * @ref ArgusOutputStream type that generates frames as an EGLStream producer (STREAM_TYPE_EGL).
  42. *
  43. * EGLStream-linked OutputStream objects maintain a connection to an EGLStream
  44. * as the producer endpoint. The EGLStream implementation is responsible for
  45. * buffer allocation, management, and synchronization as frames are presented
  46. * to the EGLStream from libargus and then consumed using an EGLStream consumer.
  47. */
  48. /**
  49. * @defgroup ArgusEGLOutputStreamSettings EGLOutputStreamSettings
  50. * @ingroup ArgusOutputStreamSettings
  51. * Settings type used to configure/create @ref ArgusEGLOutputStream streams (STREAM_TYPE_EGL).
  52. */
  53. /**
  54. * @defgroup ArgusEGLInputStream EGLInputStream
  55. * @ingroup ArgusInputStream
  56. * @ref ArgusInputStream type that generates frames as an EGLStream consumer (STREAM_TYPE_EGL).
  57. *
  58. * EGLStream-linked InputStream objects maintain a connection to an EGLStream
  59. * as the consumer startingpoint. The EGLStream implementation is responsible for
  60. * buffer allocation, management, and synchronization as frames are produced by EGLStream
  61. * consumer and presented to EGLStream to be further consumed by InputStream consumer
  62. * in libargus.
  63. */
  64. /**
  65. * @defgroup ArgusEGLInputStreamSettings EGLInputStreamSettings
  66. * @ingroup ArgusInputStreamSettings
  67. * Settings type used to configure/create @ref ArgusEGLInputStream streams (STREAM_TYPE_EGL).
  68. */
  69. /**
  70. * @ref ArgusOutputStream type that generates frames as an EGLStream producer (STREAM_TYPE_EGL).
  71. * @ingroup ArgusOutputStreamSettings
  72. */
  73. /**
  74. * @ref ArgusInputStream type that generates frames as an EGLStream producer (STREAM_TYPE_EGL).
  75. * @ingroup ArgusInputStream ArgusInputStreamSettings
  76. */
  77. DEFINE_UUID(StreamType, STREAM_TYPE_EGL, 3a659360,5231,11e7,9598,18,00,20,0c,9a,66);
  78. /**
  79. * Defines the EGLStream queue mode of operation (see IEGLOutputStreamSettings::setMode).
  80. */
  81. DEFINE_NAMED_UUID_CLASS(EGLStreamMode);
  82. DEFINE_UUID(EGLStreamMode, EGL_STREAM_MODE_MAILBOX, 33661d40,3ee2,11e6,bdf4,08,00,20,0c,9a,66);
  83. DEFINE_UUID(EGLStreamMode, EGL_STREAM_MODE_FIFO, 33661d41,3ee2,11e6,bdf4,08,00,20,0c,9a,66);
  84. /**
  85. * @class IEGLOutputStreamSettings
  86. *
  87. * Interface that exposes the settings used for EGLStream-linked OutputStream creation.
  88. *
  89. * @ingroup ArgusEGLOutputStreamSettings
  90. */
  91. DEFINE_UUID(InterfaceID, IID_EGL_OUTPUT_STREAM_SETTINGS, 3a659361,5231,11e7,9598,18,00,20,0c,9a,66);
  92. class IEGLOutputStreamSettings : public Interface
  93. {
  94. public:
  95. static const InterfaceID& id() { return IID_EGL_OUTPUT_STREAM_SETTINGS; }
  96. /**
  97. * Set the format of the stream.
  98. * Default value: PIXEL_FMT_UNKNOWN
  99. */
  100. virtual Status setPixelFormat(const PixelFormat& format) = 0;
  101. virtual PixelFormat getPixelFormat() const = 0;
  102. /**
  103. * Set the resolution of the stream.
  104. * Default value: (0, 0)
  105. */
  106. virtual Status setResolution(const Size2D<uint32_t>& resolution) = 0;
  107. virtual Size2D<uint32_t> getResolution() const = 0;
  108. /**
  109. * Set the number of exposures per stream frame.
  110. * This number should match the number of exposures that are going to be provided
  111. * with each stream frame when capturing from multi-exposure WDR sources.
  112. * Note that the EGLStream consumer must support consuming multi-exposure/buffer
  113. * EGLStreams. In the case of the EGLStream::FrameConsumer consumer, the multiple
  114. * exposures are treated as separate buffers in the acquired Image and may be
  115. * accessed using any Image interface which supports multi-buffer/plane image access
  116. * (see EGLStream::IImage::getBufferCount()).
  117. * Default value: 1
  118. */
  119. virtual Status setExposureCount(uint32_t exposureCount) = 0;
  120. virtual uint32_t getExposureCount() const = 0;
  121. /**
  122. * Set the EGLDisplay the created stream must belong to.
  123. * Default value: EGL_NO_DISPLAY - stream is display-agnostic.
  124. */
  125. virtual Status setEGLDisplay(EGLDisplay eglDisplay) = 0;
  126. virtual EGLDisplay getEGLDisplay() const = 0;
  127. /**
  128. * Sets the mode of the OutputStream. Available options are:
  129. *
  130. * MAILBOX:
  131. * In this mode, only the newest frame is made available to the consumer. When Argus
  132. * completes a frame it empties the mailbox and inserts the new frame into the mailbox.
  133. * The consumer then retrieves the frame from the mailbox and processes it; when
  134. * finished, the frame is either placed back into the mailbox (if the mailbox is empty)
  135. * or discarded (if the mailbox is not empty). This mode implies 2 things:
  136. *
  137. * - If the consumer consumes frames slower than Argus produces frames, then some
  138. * frames may be lost (never seen by the consumer).
  139. *
  140. * - If the consumer consumes frames faster than Argus produces frames, then the
  141. * consumer may see some frames more than once.
  142. *
  143. * FIFO:
  144. * When using this mode, every producer frame is made available to the consumer through
  145. * the use of a fifo queue for the frames. When using this mode, the fifo queue length
  146. * must be specified using setFifoLength. When Argus completes a frame it inserts it to
  147. * the head of the fifo queue. If the fifo is full (already contains the number of frames
  148. * equal to the fifo queue length), Argus will stall until the fifo is no longer
  149. * full. The consumer consumes frames from the tail of the queue; however, if the
  150. * consumer releases a frame while the queue is empty, the frame is set aside and will
  151. * be returned again the next time the consumer requests a frame if another new frame
  152. * has not been inserted into the fifo queue before then. Once a new frame is inserted
  153. * into the fifo queue, any previously released frame will be permanently discarded.
  154. * This mode implies:
  155. *
  156. * - Frames are never discarded until the consumer has processed them.
  157. *
  158. * - If the consumer consumes frames slower than Argus produces them, Argus will stall.
  159. *
  160. * - If the consumer consumes frames faster than Argus produces them, then the
  161. * consumer may see some frames more than once.
  162. *
  163. * Default value: STREAM_MODE_MAILBOX
  164. */
  165. virtual Status setMode(const EGLStreamMode& mode) = 0;
  166. virtual EGLStreamMode getMode() const = 0;
  167. /**
  168. * Sets the FIFO queue length of the stream. This value is only used if the stream is using
  169. * the FIFO mode (@see OutputStreamSettings::setMode). Value must be > 0.
  170. * Default value: 1
  171. */
  172. virtual Status setFifoLength(uint32_t fifoLength) = 0;
  173. virtual uint32_t getFifoLength() const = 0;
  174. /**
  175. * Enables or disables embedding Argus CaptureMetadata within frames written to the EGLStream.
  176. * Enabling this will allow an EGLStream::MetadataContainer to be created from frames acquired
  177. * on the consumer side of the EGLStream that will expose the EGLStream::IArgusCaptureMetadata
  178. * interface, which in turn provides access to the CaptureMetadata corresponding to that frame.
  179. * This will also enable the IArgusCaptureMetadata interface directly on EGLStream::Frames
  180. * acquired by an EGLStream::FrameConsumer.
  181. * Default value: disabled.
  182. */
  183. virtual Status setMetadataEnable(bool metadataEnable) = 0;
  184. virtual bool getMetadataEnable() const = 0;
  185. /**
  186. * @returns True if the output pixel format is supported by the CaptureSession for the
  187. * queried sensor mode. Otherwise, returns false.
  188. *
  189. * @param[in] sensorMode The sensor mode being queried for the output pixel type.
  190. * @param[in] outputFormat The output pixel format being queried for support.
  191. */
  192. virtual bool supportsOutputStreamFormat(const SensorMode* sensorMode,
  193. const PixelFormat& outputFormat) const = 0;
  194. protected:
  195. ~IEGLOutputStreamSettings() {}
  196. };
  197. /**
  198. * @class IEGLOutputStream
  199. *
  200. * Interface that exposes the methods available to an EGLStream-linked OutputStream.
  201. *
  202. * @ingroup ArgusEGLOutputStream
  203. */
  204. DEFINE_UUID(InterfaceID, IID_EGL_OUTPUT_STREAM, 3a659362,5231,11e7,9598,18,00,20,0c,9a,66);
  205. class IEGLOutputStream : public Interface
  206. {
  207. public:
  208. static const InterfaceID& id() { return IID_EGL_OUTPUT_STREAM; }
  209. /**
  210. * Waits until both the producer and consumer endpoints of the stream are connected.
  211. *
  212. * @param[in] timeout The timeout in nanoseconds.
  213. *
  214. * @returns success/status of this call.
  215. */
  216. virtual Status waitUntilConnected(uint64_t timeout = TIMEOUT_INFINITE) const = 0;
  217. /**
  218. * Disconnects the stream from the underlying EGLStream.
  219. */
  220. virtual void disconnect() = 0;
  221. /**
  222. * Returns the format of the stream.
  223. */
  224. virtual PixelFormat getPixelFormat() const = 0;
  225. /**
  226. * Returns the image resolution of the stream, in pixels.
  227. */
  228. virtual Size2D<uint32_t> getResolution() const = 0;
  229. /**
  230. * Returns the EGLDisplay the stream's EGLStream belongs to.
  231. */
  232. virtual EGLDisplay getEGLDisplay() const = 0;
  233. /**
  234. * Returns the EGLStream backing the stream.
  235. */
  236. virtual EGLStreamKHR getEGLStream() const = 0;
  237. protected:
  238. ~IEGLOutputStream() {}
  239. };
  240. /**
  241. * @class IEGLInputStreamSettings
  242. *
  243. * Interface that exposes the settings used for EGLStream-linked InputStream creation.
  244. *
  245. * @ingroup ArgusEGLInputStreamSettings
  246. */
  247. DEFINE_UUID(InterfaceID, IID_EGL_INPUT_STREAM_SETTINGS, c3579170,b1ac,11ec,a893,08,00,20,0c,9a,66);
  248. class IEGLInputStreamSettings : public Interface
  249. {
  250. public:
  251. static const InterfaceID& id() { return IID_EGL_INPUT_STREAM_SETTINGS; }
  252. /**
  253. * Set the format of the stream.
  254. * Default value: PIXEL_FMT_UNKNOWN
  255. */
  256. virtual Status setPixelFormat(const PixelFormat& format) = 0;
  257. virtual PixelFormat getPixelFormat() const = 0;
  258. /**
  259. * Set the resolution of the stream.
  260. * Default value: (0, 0)
  261. */
  262. virtual Status setResolution(const Size2D<uint32_t>& resolution) = 0;
  263. virtual Size2D<uint32_t> getResolution() const = 0;
  264. /**
  265. * Set the number of exposures per stream frame.
  266. * This number should match the number of exposures that are going to be provided
  267. * with each stream frame when capturing from multi-exposure WDR sources.
  268. * Note that the EGLStream consumer must support consuming multi-exposure/buffer
  269. * EGLStreams. In the case of the EGLStream::FrameConsumer consumer, the multiple
  270. * exposures are treated as separate buffers in the acquired Image and may be
  271. * accessed using any Image interface which supports multi-buffer/plane image access
  272. * (see EGLStream::IImage::getBufferCount()).
  273. * Default value: 1
  274. */
  275. virtual Status setExposureCount(uint32_t exposureCount) = 0;
  276. virtual uint32_t getExposureCount() const = 0;
  277. /**
  278. * Set the EGLDisplay the created stream must belong to.
  279. * Default value: EGL_NO_DISPLAY - stream is display-agnostic.
  280. */
  281. virtual Status setEGLDisplay(EGLDisplay eglDisplay) = 0;
  282. virtual EGLDisplay getEGLDisplay() const = 0;
  283. /**
  284. * Sets the FIFO queue length of the stream. This value must be > 0 as currently input streams
  285. * only support FIFO mode of operation. In this mode every producer frame is made available to
  286. * the consumer through the use of a fifo queue for the frames. If the fifo is full (already
  287. * contains the number of frames equal to the fifo queue length), producer will stall until
  288. * the fifo is no longer full. The consumer consumes frames from the tail of the queue,
  289. * however, if the consumer releases a frame while the queue is empty, the frame is set aside
  290. * and will be returned again the next time the consumer requests a frame if another new frame
  291. * has not been inserted into the fifo queue before then. Once a new frame is inserted
  292. * into the fifo queue, any previously released frame will be permanently discarded.
  293. * This mode implies:
  294. * - Frames are never discarded until the consumer has processed them.
  295. *
  296. * - If the consumer consumes frames slower than producer produces them, producer will stall.
  297. *
  298. * - If the consumer consumes frames faster than producer produces them, then the
  299. * consumer may see some frames more than once.
  300. *
  301. * Default value: 1
  302. */
  303. virtual Status setFifoLength(uint32_t fifoLength) = 0;
  304. virtual uint32_t getFifoLength() const = 0;
  305. /**
  306. * @returns True if the input pixel format is supported by the CaptureSession for the
  307. * queried sensor mode. Otherwise, returns false.
  308. *
  309. * @param[in] sensorMode The sensor mode being queried for the input pixel type.
  310. * @param[in] inputFormat The input pixel format being queried for support.
  311. */
  312. virtual bool supportsInputStreamFormat(const SensorMode* sensorMode,
  313. const PixelFormat& inputFormat) const = 0;
  314. protected:
  315. ~IEGLInputStreamSettings() {}
  316. };
  317. /**
  318. * @class IEGLInputStream
  319. *
  320. * Interface that exposes the methods available to an EGLStream-linked InputStream.
  321. *
  322. * @ingroup ArgusEGLInputStream
  323. */
  324. DEFINE_UUID(InterfaceID, IID_EGL_INPUT_STREAM, c3579171,b1ac,11ec,a893,08,00,20,0c,9a,66)
  325. class IEGLInputStream : public Interface
  326. {
  327. public:
  328. static const InterfaceID& id() { return IID_EGL_INPUT_STREAM; }
  329. /**
  330. * Waits until both the consumer endpoints and producer of the stream are connected.
  331. *
  332. * @param[in] timeout The timeout in nanoseconds.
  333. *
  334. * @returns success/status of this call.
  335. */
  336. virtual Status waitUntilConnected(uint64_t timeout = TIMEOUT_INFINITE) const = 0;
  337. /**
  338. * Disconnects the stream from the underlying EGLStream.
  339. */
  340. virtual void disconnect() = 0;
  341. /**
  342. * Returns the format of the stream.
  343. */
  344. virtual PixelFormat getPixelFormat() const = 0;
  345. /**
  346. * Returns the image resolution of the stream, in pixels.
  347. */
  348. virtual Size2D<uint32_t> getResolution() const = 0;
  349. /**
  350. * Returns the EGLDisplay the stream's EGLStream belongs to.
  351. */
  352. virtual EGLDisplay getEGLDisplay() const = 0;
  353. /**
  354. * Returns the EGLStream backing the stream.
  355. */
  356. virtual EGLStreamKHR getEGLStream() const = 0;
  357. protected:
  358. ~IEGLInputStream() {}
  359. };
  360. } // namespace Argus
  361. #endif // _ARGUS_EGL_STREAM_H