00001 /* 00002 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. 00003 * 00004 * NVIDIA CORPORATION and its licensors retain all intellectual property 00005 * and proprietary rights in and to this software, related documentation 00006 * and any modifications thereto. Any use, reproduction, disclosure or 00007 * distribution of this software and related documentation without an express 00008 * license agreement from NVIDIA CORPORATION is strictly prohibited. 00009 */ 00010 00011 #ifndef CAMERA_EGL_STREAM_CONSUMER_H 00012 #define CAMERA_EGL_STREAM_CONSUMER_H 00013 00014 #include <EGL/egl.h> 00015 #include <EGL/eglext.h> 00016 00017 enum CONSUMER_STATUS 00018 { 00019 /// Function succeeded. 00020 CONSUMER_STATUS_OK, 00021 00022 /// The set of parameters passed was invalid. 00023 CONSUMER_STATUS_INVALID_PARAMS, 00024 00025 /// The requested settings are invalid. 00026 CONSUMER_STATUS_INVALID_SETTINGS, 00027 00028 /// The requested device is unavailable. 00029 CONSUMER_STATUS_UNAVAILABLE, 00030 00031 /// An operation failed because of insufficient available memory. 00032 CONSUMER_STATUS_OUT_OF_MEMORY, 00033 00034 /// This method has not been implemented. 00035 CONSUMER_STATUS_UNIMPLEMENTED, 00036 00037 /// An operation timed out. 00038 CONSUMER_STATUS_TIMEOUT, 00039 00040 /// The capture was aborted. @see ICaptureSession::cancelRequests() 00041 CONSUMER_STATUS_CANCELLED, 00042 00043 /// The stream or other resource has been disconnected. 00044 CONSUMER_STATUS_DISCONNECTED, 00045 00046 // Number of elements in this enum. 00047 CONSUMER_STATUS_COUNT 00048 }; 00049 00050 /** 00051 * A Consumer object maintains a consumer connection to an EGLStream and is 00052 * used to acquire and release dmabuf Fd from the stream. 00053 * 00054 * Destroying a Consumer will implicitly disconnect the stream and release any 00055 * pending or acquired frames, invalidating any currently acquired dmabuf Fd. 00056 */ 00057 class CameraEGLStreamConsumer 00058 { 00059 public: 00060 /** 00061 * Creates a new Consumer object. The returned Consumer will have the default state 00062 * which can then be reconfigured using the various interfaces and settings methods 00063 * before it is explicitly connected to the EGLStream using connect(). 00064 * 00065 * @param[out] status An optional pointer to return an error status code. 00066 * 00067 * @returns A new Consumer object, or NULL on error. 00068 */ 00069 static CameraEGLStreamConsumer* create(CONSUMER_STATUS* status = NULL); 00070 00071 /** 00072 * Sets the maximum number of frames that can be simultaneously acquired by the 00073 * consumer at any point in time. The default is 1. 00074 * 00075 * @param[in] maxFrames The maximum number of frames that can be acquired. 00076 * 00077 * @return Success/error code of the call. 00078 */ 00079 virtual CONSUMER_STATUS setMaxAcquiredFrames(uint32_t maxFrames) = 0; 00080 00081 /** @} */ // End of PreConnect methods. 00082 00083 /** 00084 * \defgroup ConnectionState EGLStream connection state methods. 00085 * @{ 00086 */ 00087 00088 /** 00089 * Connects the Consumer to an EGLStream. 00090 * 00091 * @param[in] eglDisplay The EGLDisplay the stream belongs to. 00092 * @param[in] eglStream The EGLStream to connect the consumer to. 00093 * 00094 * @return Success/error code of the call. 00095 */ 00096 virtual CONSUMER_STATUS connect(EGLDisplay eglDisplay, EGLStreamKHR eglStream) = 0; 00097 00098 /** 00099 * Disconnects the consumer from the EGLStream. This will notify the 00100 * producer endpoint of the disconnect and will prevent new frames from 00101 * being presented to the stream by the producer. It will also prevent new 00102 * frames from being acquired, but any currently acquired frames will still 00103 * remain valid until released or until the consumer is destroyed. 00104 */ 00105 virtual void disconnect() = 0; 00106 00107 /** 00108 * Destroy the Consumer object. Destroying a Consumer will implicitly disconnect 00109 * the stream and release any pending or acquired frames, invalidating any 00110 * currently acquired dmabuf Fd. 00111 */ 00112 00113 virtual void destroy() = 0; 00114 00115 /** @} */ // End of ConnectionState methods. 00116 00117 /** 00118 * \defgroup Connected Methods available while the stream is connected. 00119 * 00120 * These methods can only be called once both the Consumer and Producer 00121 * have successfully connected to the EGLStream and it is in the 00122 * CONNECTED state. Calling any of these function when the stream is not 00123 * in the CONNECTED state will return an INVALID_STATE status. 00124 * @{ 00125 */ 00126 00127 /** 00128 * Acquires a new dmabuf Fd. If the maximum number of fds are currently acquired, 00129 * an error will be returned immediately. If -1 is returned and the status is 00130 * DISCONNECTED, the producer has disconnected from the stream and no more fds 00131 * can be acquired. 00132 * @param[in] timeout The timeout to wait for a frame if one isn't available. 00133 * @param[out] status An optional pointer to return an error status code. 00134 * 00135 * @returns dmabuf Fd of a frame acquired from the stream, or -1 on error. 00136 * This dmabuf object is owned by the Consumer, and is valid until it is 00137 * released by releaseFd() or is implicitly released by destroy(). 00138 */ 00139 virtual int acquireFd(uint64_t timeout = 0xFFFFFFFFFFFFFFFF, 00140 CONSUMER_STATUS* status = NULL) = 0; 00141 00142 /** 00143 * Releases an acquired dmabuf . 00144 * @param[in] fd The dmabuf fd to release. 00145 * 00146 * @return Success/error code of the call. 00147 */ 00148 virtual CONSUMER_STATUS releaseFd(int fd) = 0; 00149 00150 protected: 00151 ~CameraEGLStreamConsumer() {} 00152 }; 00153 00154 #endif // CAMERA_EGL_STREAM_CONSUMER_H