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 #ifndef NATIVE_AVSCREEN_CAPTURE_BASE_H 17 #define NATIVE_AVSCREEN_CAPTURE_BASE_H 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 /** 24 * @brief Nativebuffer of avscreeencapture that from graphics. 25 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 26 * 27 * @since 10 28 * @version 1.0 29 */ 30 typedef struct OH_NativeBuffer OH_NativeBuffer; 31 32 /** 33 * @brief Initialization of avscreeencapture 34 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 35 * 36 * @since 10 37 * @version 1.0 38 */ 39 typedef struct OH_AVScreenCapture OH_AVScreenCapture; 40 41 /** 42 * @brief Enumerates screen capture mode. 43 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 44 * 45 * @since 10 46 * @version 1.0 47 */ 48 typedef enum OH_CaptureMode { 49 /* capture home screen */ 50 OH_CAPTURE_HOME_SCREEN = 0, 51 /* capture a specified screen */ 52 OH_CAPTURE_SPECIFIED_SCREEN = 1, 53 /* capture a specified window */ 54 OH_CAPTURE_SPECIFIED_WINDOW = 2, 55 OH_CAPTURE_INVAILD = -1 56 } OH_CaptureMode; 57 58 /** 59 * @brief Enumerates audio cap source type. 60 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 61 * 62 * @since 10 63 * @version 1.0 64 */ 65 typedef enum OH_AudioCaptureSourceType { 66 /* Invalid audio source */ 67 OH_SOURCE_INVALID = -1, 68 /* Default audio source */ 69 OH_SOURCE_DEFAULT = 0, 70 /* Microphone */ 71 OH_MIC = 1, 72 /* inner all PlayBack */ 73 OH_ALL_PLAYBACK = 2, 74 /* inner app PlayBack */ 75 OH_APP_PLAYBACK = 3, 76 } OH_AudioCaptureSourceType; 77 78 /** 79 * @brief Enumerates audio codec formats. 80 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 81 * 82 * @since 10 83 * @version 1.0 84 */ 85 typedef enum OH_AudioCodecFormat { 86 /* Default format */ 87 OH_AUDIO_DEFAULT = 0, 88 /* Advanced Audio Coding Low Complexity (AAC-LC) */ 89 OH_AAC_LC = 3, 90 /* Invalid value */ 91 OH_AUDIO_CODEC_FORMAT_BUTT, 92 } OH_AudioCodecFormat; 93 94 /** 95 * @brief Enumerates video codec formats. 96 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 97 * 98 * @since 10 99 * @version 1.0 100 */ 101 typedef enum OH_VideoCodecFormat { 102 /* Default format */ 103 OH_VIDEO_DEFAULT = 0, 104 /* H.264 */ 105 OH_H264 = 2, 106 /* H.265/HEVC */ 107 OH_H265 = 4, 108 /* MPEG4 */ 109 OH_MPEG4 = 6, 110 /* VP8 */ 111 OH_VP8 = 8, 112 /* VP9 */ 113 OH_VP9 = 10, 114 /* Invalid format */ 115 OH_VIDEO_CODEC_FORMAT_BUTT, 116 } OH_VideoCodecFormat; 117 118 /** 119 * @brief Enumerates screen capture data type. 120 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 121 * 122 * @since 10 123 * @version 1.0 124 */ 125 typedef enum OH_DataType { 126 /* YUV/RGBA/PCM, etc. original stream */ 127 OH_ORIGINAL_STREAM = 0, 128 /* h264/AAC, etc. encoded stream */ 129 OH_ENCODED_STREAM = 1, 130 /* mp4 file */ 131 OH_CAPTURE_FILE = 2, 132 OH_INVAILD = -1 133 } OH_DataType; 134 135 /** 136 * @brief Enumerates video source types. 137 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 138 * 139 * @since 10 140 * @version 1.0 141 */ 142 typedef enum OH_VideoSourceType { 143 /* Unsupported App Usage. */ 144 /* YUV video data provided through graphic */ 145 OH_VIDEO_SOURCE_SURFACE_YUV = 0, 146 /* Raw encoded data provided through graphic */ 147 OH_VIDEO_SOURCE_SURFACE_ES, 148 /* RGBA video data provided through graphic */ 149 OH_VIDEO_SOURCE_SURFACE_RGBA, 150 /* Invalid value */ 151 OH_VIDEO_SOURCE_BUTT 152 } OH_VideoSourceType; 153 154 /** 155 * @brief Enumerates the container format types. 156 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 157 * 158 * @since 10 159 * @version 1.0 160 */ 161 typedef enum OH_ContainerFormatType { 162 /* Audio format type -- m4a */ 163 CFT_MPEG_4A = 0, 164 /* Video format type -- mp4 */ 165 CFT_MPEG_4 = 1 166 } OH_ContainerFormatType; 167 168 /** 169 * @brief Audio capture info struct 170 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 171 * 172 * @since 10 173 * @version 1.0 174 */ 175 typedef struct OH_AudioCaptureInfo { 176 /* Audio capture sample rate info */ 177 int32_t audioSampleRate; 178 /* Audio capture channel info */ 179 int32_t audioChannels; 180 /* Audio capture source type */ 181 OH_AudioCaptureSourceType audioSource; 182 } OH_AudioCaptureInfo; 183 184 /** 185 * @brief Audio encoder info 186 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 187 * 188 * @since 10 189 * @version 1.0 190 */ 191 typedef struct OH_AudioEncInfo { 192 /* Audio encoder bitrate */ 193 int32_t audioBitrate; 194 /* Audio codec format */ 195 OH_AudioCodecFormat audioCodecformat; 196 } OH_AudioEncInfo; 197 198 /** 199 * @brief The audio info of avscreeencapture 200 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 201 * 202 * @since 10 203 * @version 1.0 204 */ 205 typedef struct OH_AudioInfo { 206 /* Audio capture info of microphone */ 207 OH_AudioCaptureInfo micCapInfo; 208 /* Audio capture info of inner */ 209 OH_AudioCaptureInfo innerCapInfo; 210 /* Audio encoder info, no need to set, while dataType = OH_ORIGINAL_STREAM */ 211 OH_AudioEncInfo audioEncInfo; 212 } OH_AudioInfo; 213 214 /** 215 * @brief Video capture info 216 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 217 * 218 * @since 10 219 * @version 1.0 220 */ 221 typedef struct OH_VideoCaptureInfo { 222 /* Display id, should be set while captureMode = CAPTURE_SPECIFIED_SCREEN */ 223 uint64_t displayId; 224 /* The ids of mission, should be set while captureMode = CAPTURE_SPECIFIED_WINDOW */ 225 int32_t *missionIDs; 226 /* Mission ids length, should be set while captureMode = CAPTURE_SPECIFIED_WINDOW */ 227 int32_t missionIDsLen; 228 /* Video frame width of avscreeencapture */ 229 int32_t videoFrameWidth; 230 /* Video frame height of avscreeencapture */ 231 int32_t videoFrameHeight; 232 /* Video source type of avscreeencapture */ 233 OH_VideoSourceType videoSource; 234 } OH_VideoCaptureInfo; 235 236 /** 237 * @brief Videoc encoder info 238 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 239 * 240 * @since 10 241 * @version 1.0 242 */ 243 typedef struct OH_VideoEncInfo { 244 /* Video encoder format */ 245 OH_VideoCodecFormat videoCodec; 246 /* Video encoder bitrate */ 247 int32_t videoBitrate; 248 /* Video encoder frame rate */ 249 int32_t videoFrameRate; 250 } OH_VideoEncInfo; 251 252 /** 253 * @brief Video info 254 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 255 * 256 * @since 10 257 * @version 1.0 258 */ 259 typedef struct OH_VideoInfo { 260 /* Video capture info */ 261 OH_VideoCaptureInfo videoCapInfo; 262 /* Video encoder info */ 263 OH_VideoEncInfo videoEncInfo; 264 } OH_VideoInfo; 265 266 /** 267 * @brief Recorder file info 268 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 269 * 270 * @since 10 271 * @version 1.0 272 */ 273 typedef struct OH_RecorderInfo { 274 /* Recorder file url */ 275 char *url; 276 /* Recorder file url length */ 277 uint32_t urlLen; 278 /* Recorder file format */ 279 OH_ContainerFormatType fileFormat; 280 } OH_RecorderInfo; 281 282 /** 283 * @brief AV screeen capture config info 284 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 285 * 286 * @since 10 287 * @version 1.0 288 */ 289 typedef struct OH_AVScreenCaptureConfig { 290 OH_CaptureMode captureMode; 291 OH_DataType dataType; 292 OH_AudioInfo audioInfo; 293 OH_VideoInfo videoInfo; 294 /* should be set, while dataType = OH_CAPTURE_FILE */ 295 OH_RecorderInfo recorderInfo; 296 } OH_AVScreenCaptureConfig; 297 298 /** 299 * @brief When an error occurs in the running of the OH_AVScreenCapture instance, the function pointer will be called 300 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 301 * @param capture Pointer to an OH_AVScreenCapture instance 302 * @param errorCode specific error code 303 * 304 * @since 10 305 * @version 1.0 306 */ 307 typedef void (*OH_AVScreenCaptureOnError)(OH_AVScreenCapture *capture, int32_t errorCode); 308 309 /** 310 * @brief When audio buffer is available during the operation of OH_AVScreenCapture, the function pointer will 311 * be called. 312 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 313 * @param capture Pointer to an OH_AVScreenCapture instance 314 * @param isReady Information describing whether audio buffer is available 315 * @param type Information describing the audio source type 316 * 317 * @since 10 318 * @version 1.0 319 */ 320 typedef void (*OH_AVScreenCaptureOnAudioBufferAvailable)(OH_AVScreenCapture *capture, bool isReady, 321 OH_AudioCaptureSourceType type); 322 323 /** 324 * @brief When video buffer is available during the operation of OH_AVScreenCapture, the function pointer will 325 * be called. 326 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 327 * @param capture Pointer to an OH_AVScreenCapture instance 328 * @param isReady Information describing whether video buffer is available 329 * 330 * @since 10 331 * @version 1.0 332 */ 333 typedef void (*OH_AVScreenCaptureOnVideoBufferAvailable)(OH_AVScreenCapture *capture, bool isReady); 334 335 /** 336 * @brief A collection of all callback function pointers in OH_AVScreenCapture. Register an instance of this 337 * structure to the OH_AVScreenCapture instance, and process the information reported through the callback to ensure the 338 * normal operation of OH_AVScreenCapture. 339 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 340 * @param onError Monitor OH_AVScreenCapture operation errors, refer to {@link OH_AVScreenCaptureOnError} 341 * @param onAudioBufferAvailable Monitor audio buffer, refer to {@link OH_AVScreenCaptureOnAudioBufferAvailable} 342 * @param onVideoBufferAvailable Monitor video buffer, refer to {@link OH_AVScreenCaptureOnVideoBufferAvailable} 343 * 344 * @since 10 345 * @version 1.0 346 */ 347 typedef struct OH_AVScreenCaptureCallback { 348 OH_AVScreenCaptureOnError onError; 349 OH_AVScreenCaptureOnAudioBufferAvailable onAudioBufferAvailable; 350 OH_AVScreenCaptureOnVideoBufferAvailable onVideoBufferAvailable; 351 } OH_AVScreenCaptureCallback; 352 353 /** 354 * @brief avscreeencapture rect info 355 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 356 * 357 * @since 10 358 * @version 1.0 359 */ 360 typedef struct OH_Rect { 361 /* X-coordinate of screen recording */ 362 int32_t x; 363 /* y-coordinate of screen recording */ 364 int32_t y; 365 /* Width of screen recording */ 366 int32_t width; 367 /* Height of screen recording */ 368 int32_t height; 369 } OH_Rect; 370 371 372 /** 373 * @brief Audiobuffer struct info 374 * @syscap SystemCapability.Multimedia.Media.AVScreenCapture 375 * 376 * @since 10 377 * @version 1.0 378 */ 379 typedef struct OH_AudioBuffer { 380 /* Audio buffer memory block */ 381 uint8_t *buf; 382 /* Audio buffer memory block size */ 383 int32_t size; 384 /* Audio buffer timestamp info */ 385 int64_t timestamp; 386 /* Audio capture source type */ 387 OH_AudioCaptureSourceType type; 388 } OH_AudioBuffer; 389 390 #ifdef __cplusplus 391 } 392 #endif 393 394 #endif // NATIVE_AVSCREEN_CAPTURE_BASE_H