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 AVPlayer 18 * @{ 19 * 20 * @brief Provides APIs of Playback capability for Media Source. 21 * 22 * @Syscap SystemCapability.Multimedia.Media.AVPlayer 23 * @since 11 24 * @version 1.0 25 */ 26 27 /** 28 * @file avplayer_base.h 29 * 30 * @brief Defines the structure and enumeration for Media AVPlayer. 31 * 32 * @kit MediaKit 33 * @library libavplayer.so 34 * @since 11 35 * @version 1.0 36 */ 37 38 #ifndef MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVPLAYER_BASH_H 39 #define MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVPLAYER_BASH_H 40 41 #include <stdint.h> 42 43 #include "native_avformat.h" 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 typedef struct OH_AVPlayer OH_AVPlayer; 50 51 /** 52 * @brief Player States 53 * @syscap SystemCapability.Multimedia.Media.AVPlayer 54 * @since 11 55 * @version 1.0 56 */ 57 typedef enum AVPlayerState { 58 /* idle states */ 59 AV_IDLE = 0, 60 /* initialized states */ 61 AV_INITIALIZED = 1, 62 /* prepared states */ 63 AV_PREPARED = 2, 64 /* playing states */ 65 AV_PLAYING = 3, 66 /* paused states */ 67 AV_PAUSED = 4, 68 /* stopped states */ 69 AV_STOPPED = 5, 70 /* Play to the end states */ 71 AV_COMPLETED = 6, 72 /* released states */ 73 AV_RELEASED = 7, 74 /* error states */ 75 AV_ERROR = 8, 76 } AVPlayerState; 77 78 /** 79 * @brief Player Seek Mode 80 * @syscap SystemCapability.Multimedia.Media.AVPlayer 81 * @since 11 82 * @version 1.0 83 */ 84 typedef enum AVPlayerSeekMode { 85 /* sync to keyframes after the time point. */ 86 AV_SEEK_NEXT_SYNC = 0, 87 /* sync to keyframes before the time point. */ 88 AV_SEEK_PREVIOUS_SYNC, 89 /** 90 * @brief Sync to frames closest to the time point. 91 * @syscap SystemCapability.Multimedia.Media.AVPlayer 92 * @since 12 93 */ 94 AV_SEEK_CLOSEST = 2, 95 } AVPlayerSeekMode; 96 97 /** 98 * @brief Playback Speed 99 * @syscap SystemCapability.Multimedia.Media.AVPlayer 100 * @since 11 101 * @version 1.0 102 */ 103 typedef enum AVPlaybackSpeed { 104 /* Video playback at 0.75x normal speed */ 105 AV_SPEED_FORWARD_0_75_X, 106 /* Video playback at normal speed */ 107 AV_SPEED_FORWARD_1_00_X, 108 /* Video playback at 1.25x normal speed */ 109 AV_SPEED_FORWARD_1_25_X, 110 /* Video playback at 1.75x normal speed */ 111 AV_SPEED_FORWARD_1_75_X, 112 /* Video playback at 2.0x normal speed */ 113 AV_SPEED_FORWARD_2_00_X, 114 /** 115 * @brief Video playback at 0.5x normal speed. 116 * @syscap SystemCapability.Multimedia.Media.AVPlayer 117 * @since 12 118 */ 119 AV_SPEED_FORWARD_0_50_X, 120 /** 121 * @brief Video playback at 1.5x normal speed. 122 * @syscap SystemCapability.Multimedia.Media.AVPlayer 123 * @since 12 124 */ 125 AV_SPEED_FORWARD_1_50_X, 126 /** 127 * @brief Video playback at 3.0x normal speed. 128 * @syscap SystemCapability.Multimedia.Media.AVPlayer 129 * @since 13 130 */ 131 AV_SPEED_FORWARD_3_00_X, 132 /** 133 * @brief Video playback at 0.25x normal speed. 134 * @syscap SystemCapability.Multimedia.Media.AVPlayer 135 * @since 13 136 */ 137 AV_SPEED_FORWARD_0_25_X, 138 /** 139 * @brief Video playback at 0.125x normal speed. 140 * @syscap SystemCapability.Multimedia.Media.AVPlayer 141 * @since 13 142 */ 143 AV_SPEED_FORWARD_0_125_X, 144 } AVPlaybackSpeed; 145 146 /** 147 * @brief Player OnInfo Type 148 * @syscap SystemCapability.Multimedia.Media.AVPlayer 149 * @since 11 150 * @version 1.0 151 */ 152 typedef enum AVPlayerOnInfoType { 153 /* return the message when seeking done. */ 154 AV_INFO_TYPE_SEEKDONE = 0, 155 /* return the message when speeding done. */ 156 AV_INFO_TYPE_SPEEDDONE = 1, 157 /* return the message when select bitrate done */ 158 AV_INFO_TYPE_BITRATEDONE = 2, 159 /* return the message when playback is end of steam. */ 160 AV_INFO_TYPE_EOS = 3, 161 /* return the message when PlayerStates changed. */ 162 AV_INFO_TYPE_STATE_CHANGE = 4, 163 /* return the current posion of playback automatically. */ 164 AV_INFO_TYPE_POSITION_UPDATE = 5, 165 /* return the playback message. */ 166 AV_INFO_TYPE_MESSAGE = 6, 167 /* return the message when volume changed. */ 168 AV_INFO_TYPE_VOLUME_CHANGE = 7, 169 /* return the message when video size is first known or updated. */ 170 AV_INFO_TYPE_RESOLUTION_CHANGE = 8, 171 /* return multiqueue buffering time. */ 172 AV_INFO_TYPE_BUFFERING_UPDATE = 9, 173 /* return hls bitrate. 174 Bitrate is to convert data into uint8_t array storage, 175 which needs to be forcibly converted to uint32_t through offset access. */ 176 AV_INFO_TYPE_BITRATE_COLLECT = 10, 177 /* return the message when audio focus changed. */ 178 AV_INFO_TYPE_INTERRUPT_EVENT = 11, 179 /* return the duration of playback. */ 180 AV_INFO_TYPE_DURATION_UPDATE = 12, 181 /* return the playback is live stream. */ 182 AV_INFO_TYPE_IS_LIVE_STREAM = 13, 183 /* return the message when track changes. */ 184 AV_INFO_TYPE_TRACKCHANGE = 14, 185 /* return the message when subtitle track info updated. */ 186 AV_INFO_TYPE_TRACK_INFO_UPDATE = 15, 187 /* return the subtitle of playback. */ 188 AV_INFO_TYPE_SUBTITLE_UPDATE = 16, 189 /** Return the reason when the audio output device changes. When this info is reported, the extra param of 190 * {@link OH_AVPlayerOnInfo} is the same as {@OH_AudioStream_DeviceChangeReason} in audio framework. 191 */ 192 AV_INFO_TYPE_AUDIO_OUTPUT_DEVICE_CHANGE = 17, 193 } AVPlayerOnInfoType; 194 195 /** 196 * @brief Player Buffering Type 197 * @syscap SystemCapability.Multimedia.Media.AVPlayer 198 * @since 12 199 * @version 1.0 200 */ 201 typedef enum AVPlayerBufferingType { 202 /** Indicates the buffer to start buffering. */ 203 AVPLAYER_BUFFERING_START = 1, 204 205 /** Indicates the buffer to end buffering and start playback. */ 206 AVPLAYER_BUFFERING_END, 207 208 /** Indicates the current buffering percentage of the buffer. */ 209 AVPLAYER_BUFFERING_PERCENT, 210 211 /** Indicates how long the buffer cache data can be played. */ 212 AVPLAYER_BUFFERING_CACHED_DURATION, 213 } AVPlayerBufferingType; 214 215 /** 216 * @brief Key to get state, value type is int32_t. 217 * @syscap SystemCapability.Multimedia.Media.AVPlayer 218 * @since 12 219 * @version 1.0 220 */ 221 extern const char* OH_PLAYER_STATE; 222 223 /** 224 * @brief Key to get state change reason, value type is int32_t. 225 * @syscap SystemCapability.Multimedia.Media.AVPlayer 226 * @since 12 227 * @version 1.0 228 */ 229 extern const char* OH_PLAYER_STATE_CHANGE_REASON; 230 231 /** 232 * @brief Key to get volume, value type is float. 233 * @syscap SystemCapability.Multimedia.Media.AVPlayer 234 * @since 12 235 * @version 1.0 236 */ 237 extern const char* OH_PLAYER_VOLUME; 238 239 /** 240 * @brief Key to get bitrate count, value type is uint32_t array. 241 * @syscap SystemCapability.Multimedia.Media.AVPlayer 242 * @since 12 243 * @version 1.0 244 */ 245 extern const char* OH_PLAYER_BITRATE_ARRAY; 246 247 /** 248 * @brief Key to get audio interrupt type, value type is int32_t. 249 * @syscap SystemCapability.Multimedia.Media.AVPlayer 250 * @since 12 251 * @version 1.0 252 */ 253 extern const char* OH_PLAYER_AUDIO_INTERRUPT_TYPE; 254 255 /** 256 * @brief Key to get audio interrupt force, value type is int32_t. 257 * @syscap SystemCapability.Multimedia.Media.AVPlayer 258 * @since 12 259 * @version 1.0 260 */ 261 extern const char* OH_PLAYER_AUDIO_INTERRUPT_FORCE; 262 263 /** 264 * @brief Key to get audio interrupt hint, value type is int32_t. 265 * @syscap SystemCapability.Multimedia.Media.AVPlayer 266 * @since 12 267 * @version 1.0 268 */ 269 extern const char* OH_PLAYER_AUDIO_INTERRUPT_HINT; 270 271 /** 272 * @brief Key to get audio device change reason, value type is int32_t. 273 * @syscap SystemCapability.Multimedia.Media.AVPlayer 274 * @since 12 275 * @version 1.0 276 */ 277 extern const char* OH_PLAYER_AUDIO_DEVICE_CHANGE_REASON; 278 279 /** 280 * @brief Key to get buffering type, value type is AVPlayerBufferingType. 281 * @syscap SystemCapability.Multimedia.Media.AVPlayer 282 * @since 12 283 * @version 1.0 284 */ 285 extern const char* OH_PLAYER_BUFFERING_TYPE; 286 287 /** 288 * @brief Key to get buffering value, value type is int32_t. 289 * @syscap SystemCapability.Multimedia.Media.AVPlayer 290 * @since 12 291 * @version 1.0 292 */ 293 extern const char* OH_PLAYER_BUFFERING_VALUE; 294 295 /** 296 * @brief Key to get seek position, value type is int32_t. 297 * @syscap SystemCapability.Multimedia.Media.AVPlayer 298 * @since 12 299 */ 300 extern const char* OH_PLAYER_SEEK_POSITION; 301 302 /** 303 * @brief Key to get playback speed, value type is AVPlaybackSpeed. 304 * @syscap SystemCapability.Multimedia.Media.AVPlayer 305 * @since 12 306 */ 307 extern const char* OH_PLAYER_PLAYBACK_SPEED; 308 309 /** 310 * @brief Key to get bitrate, value type is uint32_t. 311 * @syscap SystemCapability.Multimedia.Media.AVPlayer 312 * @since 12 313 */ 314 extern const char* OH_PLAYER_BITRATE; 315 316 /** 317 * @brief Key to get current position, value type is int32_t. 318 * @syscap SystemCapability.Multimedia.Media.AVPlayer 319 * @since 12 320 */ 321 extern const char* OH_PLAYER_CURRENT_POSITION; 322 323 /** 324 * @brief Key to get duration, value type is int64_t. 325 * @syscap SystemCapability.Multimedia.Media.AVPlayer 326 * @since 12 327 */ 328 extern const char* OH_PLAYER_DURATION; 329 330 /** 331 * @brief Key to get video width, value type is int32_t. 332 * @syscap SystemCapability.Multimedia.Media.AVPlayer 333 * @since 12 334 */ 335 extern const char* OH_PLAYER_VIDEO_WIDTH; 336 337 /** 338 * @brief Key to get video height, value type is int32_t. 339 * @syscap SystemCapability.Multimedia.Media.AVPlayer 340 * @since 12 341 */ 342 extern const char* OH_PLAYER_VIDEO_HEIGHT; 343 344 /** 345 * @brief Key to get message type, value type is int32_t. 346 * @syscap SystemCapability.Multimedia.Media.AVPlayer 347 * @since 12 348 */ 349 extern const char* OH_PLAYER_MESSAGE_TYPE; 350 351 /** 352 * @brief Key to get is live stream, value type is int32_t. 353 * @syscap SystemCapability.Multimedia.Media.AVPlayer 354 * @since 12 355 */ 356 extern const char* OH_PLAYER_IS_LIVE_STREAM; 357 358 /** 359 * @brief Called when a player message or alarm is received. 360 * @syscap SystemCapability.Multimedia.Media.AVPlayer 361 * @param player The pointer to an OH_AVPlayer instance. 362 * @param type Indicates the information type. For details, see {@link AVPlayerOnInfoType}. 363 * @param extra Indicates other information, for example, the start time position of a playing file. 364 * @since 11 365 * @deprecated since 12 366 * @useinstead {@link OH_AVPlayerOnInfoCallback} 367 * @version 1.0 368 */ 369 typedef void (*OH_AVPlayerOnInfo)(OH_AVPlayer *player, AVPlayerOnInfoType type, int32_t extra); 370 371 /** 372 * @brief Called when a player info event is received. 373 * @syscap SystemCapability.Multimedia.Media.AVPlayer 374 * @param player The pointer to an OH_AVPlayer instance. 375 * @param type Indicates the information type. For details, see {@link AVPlayerOnInfoType}. 376 * @param infoBody Indicates the information parameters, only valid in callback function. 377 * @param userData Pointer to user specific data. 378 * @since 12 379 */ 380 typedef void (*OH_AVPlayerOnInfoCallback)(OH_AVPlayer *player, AVPlayerOnInfoType type, OH_AVFormat* infoBody, 381 void *userData); 382 383 /** 384 * @brief Called when an error occurred for versions above api9 385 * @syscap SystemCapability.Multimedia.Media.AVPlayer 386 * @param player The pointer to an OH_AVPlayer instance. 387 * @param errorCode Error code. 388 * @param errorMsg Error message. 389 * @since 11 390 * @deprecated since 12 391 * @useinstead {@link OH_AVPlayerOnInfoCallback} {@link OH_AVPlayerOnError} 392 * @version 1.0 393 */ 394 typedef void (*OH_AVPlayerOnError)(OH_AVPlayer *player, int32_t errorCode, const char *errorMsg); 395 396 /** 397 * @brief Called when an error occurred. 398 * @syscap SystemCapability.Multimedia.Media.AVPlayer 399 * @param player The pointer to an OH_AVPlayer instance. 400 * @param errorCode Error code. 401 * @param errorMsg Error message, only valid in callback function. 402 * @param userData Pointer to user specific data. 403 * @since 12 404 */ 405 typedef void (*OH_AVPlayerOnErrorCallback)(OH_AVPlayer *player, int32_t errorCode, const char *errorMsg, 406 void *userData); 407 408 /** 409 * @brief A collection of all callback function pointers in OH_AVPlayer. Register an instance of this 410 * structure to the OH_AVPlayer instance, and process the information reported through the callback to ensure the 411 * normal operation of OH_AVPlayer. 412 * @syscap SystemCapability.Multimedia.Media.AVPlayer 413 * @param onInfo Monitor OH_AVPlayer operation information, refer to {@link OH_AVPlayerOnInfo} 414 * @param onError Monitor OH_AVPlayer operation errors, refer to {@link OH_AVPlayerOnError} 415 * @since 11 416 * @deprecated since 12 417 * @useinstead {@link OH_AVPlayerOnInfoCallback} {@link OH_AVPlayerOnErrorCallback} 418 * @version 1.0 419 */ 420 typedef struct AVPlayerCallback { 421 OH_AVPlayerOnInfo onInfo; 422 OH_AVPlayerOnError onError; 423 } AVPlayerCallback; 424 425 #ifdef __cplusplus 426 } 427 #endif 428 #endif // MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVPLAYER_BASH_H 429