1 /* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup image 18 * @{ 19 * 20 * @brief Provides APIs for obtaining image data from the native layer. 21 * 22 * @Syscap SystemCapability.Multimedia.Image 23 * @since 10 24 * @version 2.0 25 */ 26 27 /** 28 * @file image_receiver_mdk.h 29 * 30 * @brief Declares the APIs for obtaining image data from the native layer. 31 * Need link <b>libimagendk.z.so</b> and <b>libimage_receiverndk.z.so</b> 32 * @since 10 33 * @version 2.0 34 */ 35 36 #ifndef INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_RECEIVER_MDK_H 37 #define INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_RECEIVER_MDK_H 38 #include "napi/native_api.h" 39 #include "image_mdk_common.h" 40 #include "image_mdk.h" 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 /** 47 * @brief Defines an <b>ImageReceiver</b> object at the native layer. 48 * 49 * @since 10 50 * @version 2.0 51 */ 52 struct ImageReceiverNative_; 53 54 /** 55 * @brief Defines the data type name of a native image receiver. 56 * 57 * @since 10 58 * @version 2.0 59 */ 60 typedef struct ImageReceiverNative_ ImageReceiverNative; 61 62 /** 63 * @brief Defines the callbacks for images at the native layer. 64 * 65 * @since 10 66 * @version 2.0 67 */ 68 typedef void (*OH_Image_Receiver_On_Callback)(void); 69 70 /** 71 * @brief Defines the information about an image receiver. 72 * 73 * @since 10 74 * @version 2.0 75 */ 76 struct OhosImageReceiverInfo { 77 /* Default width of the image received by the consumer, in pixels. */ 78 int32_t width; 79 /* Default height of the image received by the consumer, in pixels. */ 80 int32_t height; 81 /* Image format {@link OHOS_IMAGE_FORMAT_JPEG} created by using the receiver. */ 82 int32_t format; 83 /* Maximum number of images that can be cached. */ 84 int32_t capicity; 85 }; 86 87 /** 88 * @brief Creates an <b>ImageReceiver</b> object at the application layer. 89 * 90 * @param env Indicates the NAPI environment pointer. 91 * @param info Indicates the options for setting the <b>ImageReceiver</b> object. 92 * @param res Indicates the pointer to the <b>ImageReceiver</b> object obtained. 93 * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. 94 * returns {@link IRNdkErrCode} IMAGE_RESULT_BAD_PARAMETER - if bad parameter. 95 * returns {@link IRNdkErrCode} IMAGE_RESULT_JNI_ENV_ABNORMAL - if Abnormal JNI environment. 96 * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter. 97 * returns {@link IRNdkErrCode} IMAGE_RESULT_SURFACE_GET_PARAMETER_FAILED - if Failed to obtain parameters for surface. 98 * returns {@link IRNdkErrCode} IMAGE_RESULT_CREATE_SURFACE_FAILED - if create surface failed. 99 * returns {@link IRNdkErrCode} IMAGE_RESULT_SURFACE_GRALLOC_BUFFER_FAILED - if surface gralloc buffer failed. 100 * returns {@link IRNdkErrCode} IMAGE_RESULT_GET_SURFACE_FAILED - if get sufrace failed. 101 * returns {@link IRNdkErrCode} IMAGE_RESULT_MEDIA_RTSP_SURFACE_UNSUPPORT - if media rtsp surface not support. 102 * returns {@link IRNdkErrCode} IMAGE_RESULT_DATA_UNSUPPORT - if image type unsupported. 103 * returns {@link IRNdkErrCode} IMAGE_RESULT_MEDIA_DATA_UNSUPPORT - if media type unsupported. 104 * @see OhosImageReceiverInfo 105 * @since 10 106 * @version 2.0 107 */ 108 int32_t OH_Image_Receiver_CreateImageReceiver(napi_env env, struct OhosImageReceiverInfo info, napi_value* res); 109 110 /** 111 * @brief Initializes an {@link ImageReceiverNative} object at the native layer 112 * through an <b>ImageReceiver</b> object at the application layer. 113 * 114 * @param env Indicates the NAPI environment pointer. 115 * @param source Indicates an <b>ImageReceiver</b> object. 116 * @return Returns the pointer to the {@link ImageReceiverNative} object obtained if the operation is successful; 117 * returns a null pointer otherwise. 118 * @see ImageReceiverNative, OH_Image_Receiver_Release 119 * @since 10 120 * @version 2.0 121 */ 122 ImageReceiverNative* OH_Image_Receiver_InitImageReceiverNative(napi_env env, napi_value source); 123 124 /** 125 * @brief Obtains the receiver ID through an {@link ImageReceiverNative} object. 126 * 127 * @param native Indicates the pointer to an {@link ImageReceiverNative} object at the native layer. 128 * @param id Indicates the pointer to the buffer that stores the ID string obtained. 129 * @param len Indicates the size of the buffer. 130 * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. 131 * returns {@link IRNdkErrCode} IMAGE_RESULT_BAD_PARAMETER - if bad parameter. 132 * returns {@link IRNdkErrCode} IMAGE_RESULT_JNI_ENV_ABNORMAL - if Abnormal JNI environment. 133 * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter. 134 * returns {@link IRNdkErrCode} IMAGE_RESULT_SURFACE_GET_PARAMETER_FAILED - if Failed to obtain parameters for surface. 135 * returns {@link IRNdkErrCode} IMAGE_RESULT_GET_SURFACE_FAILED - if get sufrace failed. 136 * returns {@link IRNdkErrCode} IMAGE_RESULT_DATA_UNSUPPORT - if image type unsupported. 137 * returns {@link IRNdkErrCode} IMAGE_RESULT_MEDIA_DATA_UNSUPPORT - if media type unsupported. 138 * @see ImageReceiverNative 139 * @since 10 140 * @version 2.0 141 */ 142 int32_t OH_Image_Receiver_GetReceivingSurfaceId(const ImageReceiverNative* native, char* id, size_t len); 143 144 /** 145 * @brief Obtains the latest image through an {@link ImageReceiverNative} object. 146 * 147 * @param native Indicates the pointer to an {@link ImageReceiverNative} object at the native layer. 148 * @param image Indicates the pointer to an <b>Image</b> object at the application layer. 149 * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. 150 * returns {@link IRNdkErrCode} IMAGE_RESULT_BAD_PARAMETER - if bad parameter. 151 * returns {@link IRNdkErrCode} IMAGE_RESULT_JNI_ENV_ABNORMAL - if Abnormal JNI environment. 152 * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter. 153 * returns {@link IRNdkErrCode} IMAGE_RESULT_SURFACE_GET_PARAMETER_FAILED - if Failed to obtain parameters for surface. 154 * returns {@link IRNdkErrCode} IMAGE_RESULT_CREATE_SURFACE_FAILED - if create surface failed. 155 * returns {@link IRNdkErrCode} IMAGE_RESULT_SURFACE_GRALLOC_BUFFER_FAILED - if surface gralloc buffer failed. 156 * returns {@link IRNdkErrCode} IMAGE_RESULT_GET_SURFACE_FAILED - if get sufrace failed. 157 * returns {@link IRNdkErrCode} IMAGE_RESULT_MEDIA_RTSP_SURFACE_UNSUPPORT - if media rtsp surface not support. 158 * returns {@link IRNdkErrCode} IMAGE_RESULT_DATA_UNSUPPORT - if image type unsupported. 159 * returns {@link IRNdkErrCode} IMAGE_RESULT_SURFACE_REQUEST_BUFFER_FAILED - if request Buffer failed. 160 * @see ImageReceiverNative 161 * @since 10 162 * @version 2.0 163 */ 164 int32_t OH_Image_Receiver_ReadLatestImage(const ImageReceiverNative* native, napi_value* image); 165 166 /** 167 * @brief Obtains the next image through an {@link ImageReceiverNative} object. 168 * 169 * @param native Indicates the pointer to an {@link ImageReceiverNative} object at the native layer. 170 * @param image Indicates the pointer to an <b>Image</b> object at the application layer. 171 * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. 172 * returns {@link IRNdkErrCode} IMAGE_RESULT_BAD_PARAMETER - if bad parameter. 173 * returns {@link IRNdkErrCode} IMAGE_RESULT_JNI_ENV_ABNORMAL - if Abnormal JNI environment. 174 * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter. 175 * returns {@link IRNdkErrCode} IMAGE_RESULT_SURFACE_GET_PARAMETER_FAILED - if Failed to obtain parameters for surface. 176 * returns {@link IRNdkErrCode} IMAGE_RESULT_CREATE_SURFACE_FAILED - if create surface failed. 177 * returns {@link IRNdkErrCode} IMAGE_RESULT_SURFACE_GRALLOC_BUFFER_FAILED - if surface gralloc buffer failed. 178 * returns {@link IRNdkErrCode} IMAGE_RESULT_GET_SURFACE_FAILED - if get sufrace failed. 179 * returns {@link IRNdkErrCode} IMAGE_RESULT_MEDIA_RTSP_SURFACE_UNSUPPORT - if media rtsp surface not support. 180 * returns {@link IRNdkErrCode} IMAGE_RESULT_DATA_UNSUPPORT - if image type unsupported. 181 * returns {@link IRNdkErrCode} IMAGE_RESULT_SURFACE_REQUEST_BUFFER_FAILED - if request Buffer failed. 182 * @see ImageReceiverNative 183 * @since 10 184 * @version 2.0 185 */ 186 int32_t OH_Image_Receiver_ReadNextImage(const ImageReceiverNative* native, napi_value* image); 187 188 /** 189 * @brief Registers an {@link OH_Image_Receiver_On_Callback} callback event. 190 * 191 * This callback event is triggered whenever a new image is received. 192 * 193 * @param native Indicates the pointer to an {@link ImageReceiverNative} object at the native layer. 194 * @param callback Indicates the {@link OH_Image_Receiver_On_Callback} callback event to register. 195 * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. 196 * returns {@link IRNdkErrCode} IMAGE_RESULT_BAD_PARAMETER - if bad parameter. 197 * returns {@link IRNdkErrCode} IMAGE_RESULT_JNI_ENV_ABNORMAL - if Abnormal JNI environment. 198 * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter. 199 * returns {@link IRNdkErrCode} IMAGE_RESULT_GET_SURFACE_FAILED - if get sufrace failed. 200 * returns {@link IRNdkErrCode} IMAGE_RESULT_DATA_UNSUPPORT - if image type unsupported. 201 * returns {@link IRNdkErrCode} IMAGE_RESULT_REGISTER_LISTENER_FAILED - if Failed to register listener. 202 * returns {@link IRNdkErrCode} IMAGE_RESULT_REGISTER_BUFFER_FAILED - if Failed to register buffer. 203 * @see ImageReceiverNative 204 * @since 10 205 * @version 2.0 206 */ 207 int32_t OH_Image_Receiver_On(const ImageReceiverNative* native, OH_Image_Receiver_On_Callback callback); 208 209 /** 210 * @brief Obtains the size of the image receiver through an {@link ImageReceiverNative} object. 211 * 212 * @param native Indicates the pointer to an {@link ImageReceiverNative} object at the native layer. 213 * @param size Indicates the pointer to the {@link OhosImageSize} object obtained. 214 * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. 215 * returns {@link IRNdkErrCode} IMAGE_RESULT_BAD_PARAMETER - if bad parameter. 216 * returns {@link IRNdkErrCode} IMAGE_RESULT_JNI_ENV_ABNORMAL - if Abnormal JNI environment. 217 * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter. 218 * returns {@link IRNdkErrCode} IMAGE_RESULT_DATA_UNSUPPORT - if image type unsupported. 219 * @see ImageReceiverNative, OH_Image_Receiver_On_Callback 220 * @since 10 221 * @version 2.0 222 */ 223 int32_t OH_Image_Receiver_GetSize(const ImageReceiverNative* native, struct OhosImageSize* size); 224 225 /** 226 * @brief Obtains the capacity of the image receiver through an {@link ImageReceiverNative} object. 227 * 228 * @param native Indicates the pointer to an {@link ImageReceiverNative} object at the native layer. 229 * @param capacity Indicates the pointer to the capacity obtained. 230 * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. 231 * returns {@link IRNdkErrCode} IMAGE_RESULT_BAD_PARAMETER - if bad parameter. 232 * returns {@link IRNdkErrCode} IMAGE_RESULT_JNI_ENV_ABNORMAL - if Abnormal JNI environment. 233 * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter. 234 * returns {@link IRNdkErrCode} IMAGE_RESULT_DATA_UNSUPPORT - if image type unsupported. 235 * @see ImageReceiverNative, OhosImageSize 236 * @since 10 237 * @version 2.0 238 */ 239 int32_t OH_Image_Receiver_GetCapacity(const ImageReceiverNative* native, int32_t* capacity); 240 241 /** 242 * @brief Obtains the format of the image receiver through an {@link ImageReceiverNative} object. 243 * 244 * @param native Indicates the pointer to an {@link ImageReceiverNative} object at the native layer. 245 * @param format Indicates the pointer to the format obtained. 246 * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. 247 * returns {@link IRNdkErrCode} IMAGE_RESULT_BAD_PARAMETER - if bad parameter. 248 * returns {@link IRNdkErrCode} IMAGE_RESULT_JNI_ENV_ABNORMAL - if Abnormal JNI environment. 249 * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter. 250 * returns {@link IRNdkErrCode} IMAGE_RESULT_DATA_UNSUPPORT - if image type unsupported. 251 * @see ImageReceiverNative 252 253 * @since 10 254 * @version 2.0 255 */ 256 int32_t OH_Image_Receiver_GetFormat(const ImageReceiverNative* native, int32_t* format); 257 258 /** 259 * @brief Releases an {@link ImageReceiverNative} object at the native layer. 260 * 261 * This API is not used to release an <b>ImageReceiver</b> object at the application layer. 262 * 263 * @param native Indicates the pointer to an {@link ImageReceiverNative} object at the native layer. 264 * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. 265 * returns {@link IRNdkErrCode} IMAGE_RESULT_BAD_PARAMETER - if bad parameter. 266 * returns {@link IRNdkErrCode} IMAGE_RESULT_JNI_ENV_ABNORMAL - if Abnormal JNI environment. 267 * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter. 268 * @see ImageReceiverNative 269 * @since 10 270 * @version 2.0 271 */ 272 int32_t OH_Image_Receiver_Release(ImageReceiverNative* native); 273 #ifdef __cplusplus 274 }; 275 #endif 276 /** @} */ 277 278 #endif // INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_RECEIVER_MDK_H 279