EGLStream.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * Copyright (c) 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. * @file
  30. * <b>Libargus API: EGLStream API</b>
  31. *
  32. * @b Description: This file defines an EGLStream-linked OutputStream 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. * @ref ArgusOutputStream type that generates frames as an EGLStream producer (STREAM_TYPE_EGL).
  55. * @ingroup ArgusOutputStreamSettings
  56. */
  57. DEFINE_UUID(StreamType, STREAM_TYPE_EGL, 3a659360,5231,11e7,9598,18,00,20,0c,9a,66);
  58. /**
  59. * Defines the EGLStream queue mode of operation (see IEGLOutputStreamSettings::setMode).
  60. */
  61. DEFINE_NAMED_UUID_CLASS(EGLStreamMode);
  62. DEFINE_UUID(EGLStreamMode, EGL_STREAM_MODE_MAILBOX, 33661d40,3ee2,11e6,bdf4,08,00,20,0c,9a,66);
  63. DEFINE_UUID(EGLStreamMode, EGL_STREAM_MODE_FIFO, 33661d41,3ee2,11e6,bdf4,08,00,20,0c,9a,66);
  64. /**
  65. * @class IEGLOutputStreamSettings
  66. *
  67. * Interface that exposes the settings used for EGLStream-linked OutputStream creation.
  68. *
  69. * @ingroup ArgusEGLOutputStreamSettings
  70. */
  71. DEFINE_UUID(InterfaceID, IID_EGL_OUTPUT_STREAM_SETTINGS, 3a659361,5231,11e7,9598,18,00,20,0c,9a,66);
  72. class IEGLOutputStreamSettings : public Interface
  73. {
  74. public:
  75. static const InterfaceID& id() { return IID_EGL_OUTPUT_STREAM_SETTINGS; }
  76. /**
  77. * Set the format of the stream.
  78. * Default value: PIXEL_FMT_UNKNOWN
  79. */
  80. virtual Status setPixelFormat(const PixelFormat& format) = 0;
  81. virtual PixelFormat getPixelFormat() const = 0;
  82. /**
  83. * Set the resolution of the stream.
  84. * Default value: (0, 0)
  85. */
  86. virtual Status setResolution(const Size2D<uint32_t>& resolution) = 0;
  87. virtual Size2D<uint32_t> getResolution() const = 0;
  88. /**
  89. * Set the number of exposures per stream frame.
  90. * This number should match the number of exposures that are going to be provided
  91. * with each stream frame when capturing from multi-exposure WDR sources.
  92. * Note that the EGLStream consumer must support consuming multi-exposure/buffer
  93. * EGLStreams. In the case of the EGLStream::FrameConsumer consumer, the multiple
  94. * exposures are treated as separate buffers in the acquired Image and may be
  95. * accessed using any Image interface which supports multi-buffer/plane image access
  96. * (see EGLStream::IImage::getBufferCount()).
  97. * Default value: 1
  98. */
  99. virtual Status setExposureCount(uint32_t exposureCount) = 0;
  100. virtual uint32_t getExposureCount() const = 0;
  101. /**
  102. * Set the EGLDisplay the created stream must belong to.
  103. * Default value: EGL_NO_DISPLAY - stream is display-agnostic.
  104. */
  105. virtual Status setEGLDisplay(EGLDisplay eglDisplay) = 0;
  106. virtual EGLDisplay getEGLDisplay() const = 0;
  107. /**
  108. * Sets the mode of the OutputStream. Available options are:
  109. *
  110. * MAILBOX:
  111. * In this mode, only the newest frame is made available to the consumer. When Argus
  112. * completes a frame it empties the mailbox and inserts the new frame into the mailbox.
  113. * The consumer then retrieves the frame from the mailbox and processes it; when
  114. * finished, the frame is either placed back into the mailbox (if the mailbox is empty)
  115. * or discarded (if the mailbox is not empty). This mode implies 2 things:
  116. *
  117. * - If the consumer consumes frames slower than Argus produces frames, then some
  118. * frames may be lost (never seen by the consumer).
  119. *
  120. * - If the consumer consumes frames faster than Argus produces frames, then the
  121. * consumer may see some frames more than once.
  122. *
  123. * FIFO:
  124. * When using this mode, every producer frame is made available to the consumer through
  125. * the use of a fifo queue for the frames. When using this mode, the fifo queue length
  126. * must be specified using setFifoLength. When Argus completes a frame it inserts it to
  127. * the head of the fifo queue. If the fifo is full (already contains the number of frames
  128. * equal to the fifo queue length), Argus will stall until the fifo is no longer
  129. * full. The consumer consumes frames from the tail of the queue; however, if the
  130. * consumer releases a frame while the queue is empty, the frame is set aside and will
  131. * be returned again the next time the consumer requests a frame if another new frame
  132. * has not been inserted into the fifo queue before then. Once a new frame is inserted
  133. * into the fifo queue, any previously released frame will be permanently discarded.
  134. * This mode implies:
  135. *
  136. * - Frames are never discarded until the consumer has processed them.
  137. *
  138. * - If the consumer consumes frames slower than Argus produces them, Argus will stall.
  139. *
  140. * - If the consumer consumes frames faster than Argus produces them, then the
  141. * consumer may see some frames more than once.
  142. *
  143. * Default value: STREAM_MODE_MAILBOX
  144. */
  145. virtual Status setMode(const EGLStreamMode& mode) = 0;
  146. virtual EGLStreamMode getMode() const = 0;
  147. /**
  148. * Sets the FIFO queue length of the stream. This value is only used if the stream is using
  149. * the FIFO mode (@see OutputStreamSettings::setMode). Value must be > 0.
  150. * Default value: 1
  151. */
  152. virtual Status setFifoLength(uint32_t fifoLength) = 0;
  153. virtual uint32_t getFifoLength() const = 0;
  154. /**
  155. * Enables or disables embedding Argus CaptureMetadata within frames written to the EGLStream.
  156. * Enabling this will allow an EGLStream::MetadataContainer to be created from frames acquired
  157. * on the consumer side of the EGLStream that will expose the EGLStream::IArgusCaptureMetadata
  158. * interface, which in turn provides access to the CaptureMetadata corresponding to that frame.
  159. * This will also enable the IArgusCaptureMetadata interface directly on EGLStream::Frames
  160. * acquired by an EGLStream::FrameConsumer.
  161. * Default value: disabled.
  162. */
  163. virtual Status setMetadataEnable(bool metadataEnable) = 0;
  164. virtual bool getMetadataEnable() const = 0;
  165. /**
  166. * @returns True if the output pixel format is supported by the CaptureSession for the
  167. * queried sensor mode. Otherwise, returns false.
  168. *
  169. * @param[in] sensorMode The sensor mode being queried for the output pixel type.
  170. * @param[in] outputFormat The output pixel format being queried for support.
  171. */
  172. virtual bool supportsOutputStreamFormat(const SensorMode* sensorMode,
  173. const PixelFormat& outputFormat) const = 0;
  174. protected:
  175. ~IEGLOutputStreamSettings() {}
  176. };
  177. /**
  178. * @class IEGLOutputStream
  179. *
  180. * Interface that exposes the methods available to an EGLStream-linked OutputStream.
  181. *
  182. * @ingroup ArgusEGLOutputStream
  183. */
  184. DEFINE_UUID(InterfaceID, IID_EGL_OUTPUT_STREAM, 3a659362,5231,11e7,9598,18,00,20,0c,9a,66);
  185. class IEGLOutputStream : public Interface
  186. {
  187. public:
  188. static const InterfaceID& id() { return IID_EGL_OUTPUT_STREAM; }
  189. /**
  190. * Waits until both the producer and consumer endpoints of the stream are connected.
  191. *
  192. * @param[in] timeout The timeout in nanoseconds.
  193. *
  194. * @returns success/status of this call.
  195. */
  196. virtual Status waitUntilConnected(uint64_t timeout = TIMEOUT_INFINITE) const = 0;
  197. /**
  198. * Disconnects the stream from the underlying EGLStream.
  199. */
  200. virtual void disconnect() = 0;
  201. /**
  202. * Returns the format of the stream.
  203. */
  204. virtual PixelFormat getPixelFormat() const = 0;
  205. /**
  206. * Returns the image resolution of the stream, in pixels.
  207. */
  208. virtual Size2D<uint32_t> getResolution() const = 0;
  209. /**
  210. * Returns the EGLDisplay the stream's EGLStream belongs to.
  211. */
  212. virtual EGLDisplay getEGLDisplay() const = 0;
  213. /**
  214. * Returns the EGLStream backing the stream.
  215. */
  216. virtual EGLStreamKHR getEGLStream() const = 0;
  217. protected:
  218. ~IEGLOutputStream() {}
  219. };
  220. } // namespace Argus
  221. #endif // _ARGUS_EGL_STREAM_H