From 9f360a48bc545e189b42eb14fa238c5d9c4c63b2 Mon Sep 17 00:00:00 2001 From: yuanjinghua Date: Thu, 15 Aug 2024 15:46:11 +0800 Subject: [PATCH] =?UTF-8?q?Add=20interfaces=20for=20NDK=20AVPlayer=20to=20?= =?UTF-8?q?implement=20OnError=20and=20OnInfo=20=EF=BC=88cherry=20picked?= =?UTF-8?q?=20commit=20from=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- multimedia/player_framework/avplayer.h | 28 +++ .../avplayer/libavplayer.ndk.json | 84 ++++++++ multimedia/player_framework/avplayer_base.h | 200 +++++++++++++++++- 3 files changed, 309 insertions(+), 3 deletions(-) diff --git a/multimedia/player_framework/avplayer.h b/multimedia/player_framework/avplayer.h index d2d7aa7e8..2b3b7e76f 100644 --- a/multimedia/player_framework/avplayer.h +++ b/multimedia/player_framework/avplayer.h @@ -461,6 +461,8 @@ OH_AVErrCode OH_AVPlayer_SetLooping(OH_AVPlayer *player, bool loop); * {@link AV_ERR_INVALID_VAL} if input player is nullptr, callback.onInfo or callback.onError is null, * or player SetPlayerCallback failed. * @since 11 + * @deprecated since 12 + * @useinstead {@link OH_AVPlayer_SetPlayerOnInfoCallback} {@link OH_AVPlayer_SetPlayerOnErrorCallback} * @version 1.0 */ OH_AVErrCode OH_AVPlayer_SetPlayerCallback(OH_AVPlayer *player, AVPlayerCallback callback); @@ -562,6 +564,32 @@ OH_AVErrCode OH_AVPlayer_GetMediaKeySystemInfo(OH_AVPlayer *player, DRM_MediaKey OH_AVErrCode OH_AVPlayer_SetDecryptionConfig(OH_AVPlayer *player, MediaKeySession *mediaKeySession, bool secureVideoPath); +/** + * @brief Method to set player information notify callback. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance. + * @param callback Pointer to callback function, nullptr indicates unregister callback. + * @param userData Pointer to user specific data. + * @return Function result code. + * {@link AV_ERR_OK} if the execution is successful. + * {@link AV_ERR_INVALID_VAL} if input player is null or player SetOnInfoCallback failed. + * @since 12 + */ +OH_AVErrCode OH_AVPlayer_SetOnInfoCallback(OH_AVPlayer *player, OH_AVPlayerOnInfoCallback callback, void *userData); + +/** + * @brief Method to set player error callback. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance. + * @param callback Pointer to callback function, nullptr indicates unregister callback. + * @param userData Pointer to user specific data. + * @return Function result code. + * {@link AV_ERR_OK} if the execution is successful. + * {@link AV_ERR_INVALID_VAL} if input player is null or player SetOnErrorCallback failed. + * @since 12 + */ +OH_AVErrCode OH_AVPlayer_SetOnErrorCallback(OH_AVPlayer *player, OH_AVPlayerOnErrorCallback callback, void *userData); + #ifdef __cplusplus } #endif diff --git a/multimedia/player_framework/avplayer/libavplayer.ndk.json b/multimedia/player_framework/avplayer/libavplayer.ndk.json index dbfa420ed..d7151471e 100644 --- a/multimedia/player_framework/avplayer/libavplayer.ndk.json +++ b/multimedia/player_framework/avplayer/libavplayer.ndk.json @@ -27,6 +27,90 @@ { "name": "OH_AVPlayer_SelectTrack" }, { "name": "OH_AVPlayer_DeselectTrack" }, { "name": "OH_AVPlayer_GetCurrentTrack" }, + { + "first_introduced": "12", + "name": "OH_PLAYER_STATE" + }, + { + "first_introduced": "12", + "name": "OH_PLAYER_STATE_CHANGE_REASON" + }, + { + "first_introduced": "12", + "name": "OH_PLAYER_VOLUME" + }, + { + "first_introduced": "12", + "name": "OH_PLAYER_BITRATE_ARRAY" + }, + { + "first_introduced": "12", + "name": "OH_PLAYER_AUDIO_INTERRUPT_TYPE" + }, + { + "first_introduced": "12", + "name": "OH_PLAYER_AUDIO_INTERRUPT_FORCE" + }, + { + "first_introduced": "12", + "name": "OH_PLAYER_AUDIO_INTERRUPT_HINT" + }, + { + "first_introduced": "12", + "name": "OH_PLAYER_AUDIO_DEVICE_CHANGE_REASON" + }, + { + "first_introduced": "12", + "name": "OH_PLAYER_BUFFERING_TYPE" + }, + { + "first_introduced": "12", + "name": "OH_PLAYER_BUFFERING_VALUE" + }, + { + "first_introduced": "12", + "name": "OH_PLAYER_SEEK_POSITION" + }, + { + "first_introduced": "12", + "name": "OH_PLAYER_PLAYBACK_SPEED" + }, + { + "first_introduced": "12", + "name": "OH_PLAYER_BITRATE" + }, + { + "first_introduced": "12", + "name": "OH_PLAYER_CURRENT_POSITION" + }, + { + "first_introduced": "12", + "name": "OH_PLAYER_DURATION" + }, + { + "first_introduced": "12", + "name": "OH_PLAYER_VIDEO_WIDTH" + }, + { + "first_introduced": "12", + "name": "OH_PLAYER_VIDEO_HEIGHT" + }, + { + "first_introduced": "12", + "name": "OH_PLAYER_MESSAGE_TYPE" + }, + { + "first_introduced": "12", + "name": "OH_PLAYER_IS_LIVE_STREAM" + }, + { + "first_introduced": "12", + "name": "OH_AVPlayer_SetOnInfoCallback" + }, + { + "first_introduced": "12", + "name": "OH_AVPlayer_SetOnErrorCallback" + }, { "first_introduced": "12", "name": "OH_AVPlayer_SetMediaKeySystemInfoCallback" diff --git a/multimedia/player_framework/avplayer_base.h b/multimedia/player_framework/avplayer_base.h index 903a52f72..50a8ffa49 100644 --- a/multimedia/player_framework/avplayer_base.h +++ b/multimedia/player_framework/avplayer_base.h @@ -40,6 +40,8 @@ #include +#include "native_avformat.h" + #ifdef __cplusplus extern "C" { #endif @@ -113,13 +115,13 @@ typedef enum AVPlaybackSpeed { * @brief Video playback at 0.5x normal speed. * @syscap SystemCapability.Multimedia.Media.AVPlayer * @since 12 - */ + */ AV_SPEED_FORWARD_0_50_X, /** * @brief Video playback at 1.5x normal speed. * @syscap SystemCapability.Multimedia.Media.AVPlayer * @since 12 - */ + */ AV_SPEED_FORWARD_1_50_X, } AVPlaybackSpeed; @@ -172,6 +174,169 @@ typedef enum AVPlayerOnInfoType { AV_INFO_TYPE_AUDIO_OUTPUT_DEVICE_CHANGE = 17, } AVPlayerOnInfoType; +/** + * @brief Player Buffering Type + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @since 12 + * @version 1.0 + */ +typedef enum AVPlayerBufferingType { + /** Indicates the buffer to start buffering. */ + AVPLAYER_BUFFERING_START = 1, + + /** Indicates the buffer to end buffering and start playback. */ + AVPLAYER_BUFFERING_END, + + /** Indicates the current buffering percentage of the buffer. */ + AVPLAYER_BUFFERING_PERCENT, + + /** Indicates how long the buffer cache data can be played. */ + AVPLAYER_BUFFERING_CACHED_DURATION, +} AVPlayerBufferingType; + +/** + * @brief Key to get state, value type is int32_t. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @since 12 + * @version 1.0 + */ +extern const char* OH_PLAYER_STATE; + +/** + * @brief Key to get state change reason, value type is int32_t. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @since 12 + * @version 1.0 + */ +extern const char* OH_PLAYER_STATE_CHANGE_REASON; + +/** + * @brief Key to get volume, value type is float. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @since 12 + * @version 1.0 + */ +extern const char* OH_PLAYER_VOLUME; + +/** + * @brief Key to get bitrate count, value type is uint32_t array. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @since 12 + * @version 1.0 + */ +extern const char* OH_PLAYER_BITRATE_ARRAY; + +/** + * @brief Key to get audio interrupt type, value type is int32_t. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @since 12 + * @version 1.0 + */ +extern const char* OH_PLAYER_AUDIO_INTERRUPT_TYPE; + +/** + * @brief Key to get audio interrupt force, value type is int32_t. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @since 12 + * @version 1.0 + */ +extern const char* OH_PLAYER_AUDIO_INTERRUPT_FORCE; + +/** + * @brief Key to get audio interrupt hint, value type is int32_t. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @since 12 + * @version 1.0 + */ +extern const char* OH_PLAYER_AUDIO_INTERRUPT_HINT; + +/** + * @brief Key to get audio device change reason, value type is int32_t. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @since 12 + * @version 1.0 + */ +extern const char* OH_PLAYER_AUDIO_DEVICE_CHANGE_REASON; + +/** + * @brief Key to get buffering type, value type is AVPlayerBufferingType. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @since 12 + * @version 1.0 + */ +extern const char* OH_PLAYER_BUFFERING_TYPE; + +/** + * @brief Key to get buffering value, value type is int32_t. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @since 12 + * @version 1.0 + */ +extern const char* OH_PLAYER_BUFFERING_VALUE; + +/** + * @brief Key to get seek position, value type is int32_t. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @since 12 + */ +extern const char* OH_PLAYER_SEEK_POSITION; + +/** + * @brief Key to get playback speed, value type is AVPlaybackSpeed. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @since 12 + */ +extern const char* OH_PLAYER_PLAYBACK_SPEED; + +/** + * @brief Key to get bitrate, value type is uint32_t. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @since 12 + */ +extern const char* OH_PLAYER_BITRATE; + +/** + * @brief Key to get current position, value type is int32_t. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @since 12 + */ +extern const char* OH_PLAYER_CURRENT_POSITION; + +/** + * @brief Key to get duration, value type is int64_t. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @since 12 + */ +extern const char* OH_PLAYER_DURATION; + +/** + * @brief Key to get video width, value type is int32_t. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @since 12 + */ +extern const char* OH_PLAYER_VIDEO_WIDTH; + +/** + * @brief Key to get video height, value type is int32_t. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @since 12 + */ +extern const char* OH_PLAYER_VIDEO_HEIGHT; + +/** + * @brief Key to get message type, value type is int32_t. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @since 12 + */ +extern const char* OH_PLAYER_MESSAGE_TYPE; + +/** + * @brief Key to get is live stream, value type is int32_t. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @since 12 + */ +extern const char* OH_PLAYER_IS_LIVE_STREAM; + /** * @brief Called when a player message or alarm is received. * @syscap SystemCapability.Multimedia.Media.AVPlayer @@ -179,10 +344,24 @@ typedef enum AVPlayerOnInfoType { * @param type Indicates the information type. For details, see {@link AVPlayerOnInfoType}. * @param extra Indicates other information, for example, the start time position of a playing file. * @since 11 + * @deprecated since 12 + * @useinstead {@link OH_AVPlayerOnInfoCallback} * @version 1.0 */ typedef void (*OH_AVPlayerOnInfo)(OH_AVPlayer *player, AVPlayerOnInfoType type, int32_t extra); +/** + * @brief Called when a player info event is received. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player The pointer to an OH_AVPlayer instance. + * @param type Indicates the information type. For details, see {@link AVPlayerOnInfoType}. + * @param infoBody Indicates the information parameters, only valid in callback function. + * @param userData Pointer to user specific data. + * @since 12 + */ +typedef void (*OH_AVPlayerOnInfoCallback)(OH_AVPlayer *player, AVPlayerOnInfoType type, OH_AVFormat* infoBody, + void *userData); + /** * @brief Called when an error occurred for versions above api9 * @syscap SystemCapability.Multimedia.Media.AVPlayer @@ -190,10 +369,24 @@ typedef void (*OH_AVPlayerOnInfo)(OH_AVPlayer *player, AVPlayerOnInfoType type, * @param errorCode Error code. * @param errorMsg Error message. * @since 11 + * @deprecated since 12 + * @useinstead {@link OH_AVPlayerOnInfoCallback} {@link OH_AVPlayerOnError} * @version 1.0 */ typedef void (*OH_AVPlayerOnError)(OH_AVPlayer *player, int32_t errorCode, const char *errorMsg); +/** + * @brief Called when an error occurred. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player The pointer to an OH_AVPlayer instance. + * @param errorCode Error code. + * @param errorMsg Error message, only valid in callback function. + * @param userData Pointer to user specific data. + * @since 12 + */ +typedef void (*OH_AVPlayerOnErrorCallback)(OH_AVPlayer *player, int32_t errorCode, const char *errorMsg, + void *userData); + /** * @brief A collection of all callback function pointers in OH_AVPlayer. Register an instance of this * structure to the OH_AVPlayer instance, and process the information reported through the callback to ensure the @@ -202,6 +395,8 @@ typedef void (*OH_AVPlayerOnError)(OH_AVPlayer *player, int32_t errorCode, const * @param onInfo Monitor OH_AVPlayer operation information, refer to {@link OH_AVPlayerOnInfo} * @param onError Monitor OH_AVPlayer operation errors, refer to {@link OH_AVPlayerOnError} * @since 11 + * @deprecated since 12 + * @useinstead {@link OH_AVPlayerOnInfoCallback} {@link OH_AVPlayerOnErrorCallback} * @version 1.0 */ typedef struct AVPlayerCallback { @@ -209,7 +404,6 @@ typedef struct AVPlayerCallback { OH_AVPlayerOnError onError; } AVPlayerCallback; - #ifdef __cplusplus } #endif -- Gitee