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