CameraEGLStreamConsumer.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * NVIDIA CORPORATION and its licensors retain all intellectual property
  5. * and proprietary rights in and to this software, related documentation
  6. * and any modifications thereto. Any use, reproduction, disclosure or
  7. * distribution of this software and related documentation without an express
  8. * license agreement from NVIDIA CORPORATION is strictly prohibited.
  9. */
  10. #ifndef CAMERA_EGL_STREAM_CONSUMER_H
  11. #define CAMERA_EGL_STREAM_CONSUMER_H
  12. #include <EGL/egl.h>
  13. #include <EGL/eglext.h>
  14. enum CONSUMER_STATUS
  15. {
  16. /// Function succeeded.
  17. CONSUMER_STATUS_OK,
  18. /// The set of parameters passed was invalid.
  19. CONSUMER_STATUS_INVALID_PARAMS,
  20. /// The requested settings are invalid.
  21. CONSUMER_STATUS_INVALID_SETTINGS,
  22. /// The requested device is unavailable.
  23. CONSUMER_STATUS_UNAVAILABLE,
  24. /// An operation failed because of insufficient available memory.
  25. CONSUMER_STATUS_OUT_OF_MEMORY,
  26. /// This method has not been implemented.
  27. CONSUMER_STATUS_UNIMPLEMENTED,
  28. /// An operation timed out.
  29. CONSUMER_STATUS_TIMEOUT,
  30. /// The capture was aborted. @see ICaptureSession::cancelRequests()
  31. CONSUMER_STATUS_CANCELLED,
  32. /// The stream or other resource has been disconnected.
  33. CONSUMER_STATUS_DISCONNECTED,
  34. // Number of elements in this enum.
  35. CONSUMER_STATUS_COUNT
  36. };
  37. /**
  38. * A Consumer object maintains a consumer connection to an EGLStream and is
  39. * used to acquire and release dmabuf Fd from the stream.
  40. *
  41. * Destroying a Consumer will implicitly disconnect the stream and release any
  42. * pending or acquired frames, invalidating any currently acquired dmabuf Fd.
  43. */
  44. class CameraEGLStreamConsumer
  45. {
  46. public:
  47. /**
  48. * Creates a new Consumer object. The returned Consumer will have the default state
  49. * which can then be reconfigured using the various interfaces and settings methods
  50. * before it is explicitly connected to the EGLStream using connect().
  51. *
  52. * @param[out] status An optional pointer to return an error status code.
  53. *
  54. * @returns A new Consumer object, or NULL on error.
  55. */
  56. static CameraEGLStreamConsumer* create(CONSUMER_STATUS* status = NULL);
  57. /**
  58. * Sets the maximum number of frames that can be simultaneously acquired by the
  59. * consumer at any point in time. The default is 1.
  60. *
  61. * @param[in] maxFrames The maximum number of frames that can be acquired.
  62. *
  63. * @return Success/error code of the call.
  64. */
  65. virtual CONSUMER_STATUS setMaxAcquiredFrames(uint32_t maxFrames) = 0;
  66. /** @} */ // End of PreConnect methods.
  67. /**
  68. * \defgroup ConnectionState EGLStream connection state methods.
  69. * @{
  70. */
  71. /**
  72. * Connects the Consumer to an EGLStream.
  73. *
  74. * @param[in] eglDisplay The EGLDisplay the stream belongs to.
  75. * @param[in] eglStream The EGLStream to connect the consumer to.
  76. *
  77. * @return Success/error code of the call.
  78. */
  79. virtual CONSUMER_STATUS connect(EGLDisplay eglDisplay, EGLStreamKHR eglStream) = 0;
  80. /**
  81. * Disconnects the consumer from the EGLStream. This will notify the
  82. * producer endpoint of the disconnect and will prevent new frames from
  83. * being presented to the stream by the producer. It will also prevent new
  84. * frames from being acquired, but any currently acquired frames will still
  85. * remain valid until released or until the consumer is destroyed.
  86. */
  87. virtual void disconnect() = 0;
  88. /**
  89. * Destroy the Consumer object. Destroying a Consumer will implicitly disconnect
  90. * the stream and release any pending or acquired frames, invalidating any
  91. * currently acquired dmabuf Fd.
  92. */
  93. virtual void destroy() = 0;
  94. /** @} */ // End of ConnectionState methods.
  95. /**
  96. * \defgroup Connected Methods available while the stream is connected.
  97. *
  98. * These methods can only be called once both the Consumer and Producer
  99. * have successfully connected to the EGLStream and it is in the
  100. * CONNECTED state. Calling any of these function when the stream is not
  101. * in the CONNECTED state will return an INVALID_STATE status.
  102. * @{
  103. */
  104. /**
  105. * Acquires a new dmabuf Fd. If the maximum number of fds are currently acquired,
  106. * an error will be returned immediately. If -1 is returned and the status is
  107. * DISCONNECTED, the producer has disconnected from the stream and no more fds
  108. * can be acquired.
  109. * @param[in] timeout The timeout to wait for a frame if one isn't available.
  110. * @param[out] status An optional pointer to return an error status code.
  111. *
  112. * @returns dmabuf Fd of a frame acquired from the stream, or -1 on error.
  113. * This dmabuf object is owned by the Consumer, and is valid until it is
  114. * released by releaseFd() or is implicitly released by destroy().
  115. */
  116. virtual int acquireFd(uint64_t timeout = 0xFFFFFFFFFFFFFFFF,
  117. CONSUMER_STATUS* status = NULL) = 0;
  118. /**
  119. * Releases an acquired dmabuf .
  120. * @param[in] fd The dmabuf fd to release.
  121. *
  122. * @return Success/error code of the call.
  123. */
  124. virtual CONSUMER_STATUS releaseFd(int fd) = 0;
  125. protected:
  126. ~CameraEGLStreamConsumer() {}
  127. };
  128. #endif // CAMERA_EGL_STREAM_CONSUMER_H