diff --git a/config.gni b/config.gni index 7e4ffdb46ad7688885720e5c58890ea39d23a2ec..1a970d58fd617ef3cba8554a8a7ae73317d91bac 100644 --- a/config.gni +++ b/config.gni @@ -128,6 +128,7 @@ if (multimedia_player_framework_support_jssoundpool) { # Config path MEDIA_PLAYER_ROOT_DIR = "//foundation/multimedia/player_framework" +MEDIA_PLAYER_AVCODEC = "//foundation/multimedia/av_codec" MEDIA_PLAYER_GRAPHIC = "//foundation/graphic/graphic_2d" # Fuzz test output path diff --git a/frameworks/native/capi/common/native_avscreen_capture_magic.h b/frameworks/native/capi/common/native_player_magic.h similarity index 81% rename from frameworks/native/capi/common/native_avscreen_capture_magic.h rename to frameworks/native/capi/common/native_player_magic.h index 60b76b6ec4edf772364fae1d64ac5a5933205817..b358b2d9daed551212628fcf55cbf63c15ac1b51 100644 --- a/frameworks/native/capi/common/native_avscreen_capture_magic.h +++ b/frameworks/native/capi/common/native_player_magic.h @@ -18,10 +18,17 @@ #include #include "screen_capture.h" +#include "player.h" struct OH_AVScreenCapture : public OHOS::RefBase { OH_AVScreenCapture() = default; virtual ~OH_AVScreenCapture() = default; }; +struct OH_AVPlayer : public OHOS::RefBase { + OH_AVPlayer() = default; + virtual ~OH_AVPlayer() = default; + OHOS::Media::PlayerStates state_ = OHOS::Media::PLAYER_IDLE; +}; + #endif // NATIVE_SCREEN_CAPTURE_MAGIC_H \ No newline at end of file diff --git a/frameworks/native/capi/player/native_avplayer.cpp b/frameworks/native/capi/player/native_avplayer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..20bbbec95eb3455b342b7b9463a1524d614fa1b8 --- /dev/null +++ b/frameworks/native/capi/player/native_avplayer.cpp @@ -0,0 +1,357 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "media_log.h" +#include "media_errors.h" +#include "native_player_magic.h" +#include "native_window.h" +#include "native_avplayer.h" + +namespace { + constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "NativeAVPlayer"}; +} + +using namespace OHOS::Media; +class NativeAVPlayerCallback; + +struct PlayerObject : public OH_AVPlayer { + explicit PlayerObject(const std::shared_ptr &player) + : player_(player) {} + ~PlayerObject() = default; + + const std::shared_ptr player_ = nullptr; + std::shared_ptr callback_ = nullptr; +}; + + +class NativeAVPlayerCallback : public PlayerCallback { +public: + NativeAVPlayerCallback(OH_AVPlayer *player, OH_AVPlayerCallback callback) + : player_(player), callback_(callback) {} + virtual ~NativeAVPlayerCallback() = default; + + void OnInfo(PlayerOnInfoType type, int32_t extra, const Format &infoBody) override + { + std::unique_lock lock(mutex_); + if (type == INFO_TYPE_STATE_CHANGE) { + PlayerStates state = static_cast(extra); + player_->state_ = state; + } + + if (player_ != nullptr && callback_.onInfo != nullptr) { + callback_.onInfo(player_, static_cast(type), extra); + } + } + + void OnError(int32_t errorCode, const std::string &errorMsg) override + { + MEDIA_LOGI("OnError() is called, errorCode %{public}d", errorCode); + std::unique_lock lock(mutex_); + + if (player_ != nullptr && callback_.onError != nullptr) { + callback_.onError(player_, errorCode, errorMsg.c_str()); + } + } + +private: + struct OH_AVPlayer *player_; + struct OH_AVPlayerCallback callback_; + std::mutex mutex_; +}; + + +OH_AVPlayer *OH_AVPlayer_Create(void) +{ + std::shared_ptr player = PlayerFactory::CreatePlayer(); + CHECK_AND_RETURN_RET_LOG(player != nullptr, nullptr, "failed to PlayerFactory::CreatePlayer"); + + PlayerObject *object = new(std::nothrow) PlayerObject(player); + CHECK_AND_RETURN_RET_LOG(object != nullptr, nullptr, "failed to new PlayerObject"); + + return object; +} + + +OH_AVErrCode OH_AVPlayer_SetUrlSource(OH_AVPlayer *player, const char *url) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + CHECK_AND_RETURN_RET_LOG(url != nullptr, AV_ERR_INVALID_VAL, "url is null"); + int32_t ret = playerObj->player_->SetSource(url); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "player setUrlSource failed"); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_SetFdSource(OH_AVPlayer *player, int32_t fd, int64_t offset, int64_t size) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + int32_t ret = playerObj->player_->SetSource(fd, offset, size); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "player setFdSource failed"); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_Play(OH_AVPlayer *player) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + int32_t ret = playerObj->player_->Play(); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "player play failed"); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_Prepare(OH_AVPlayer *player) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + int32_t ret = playerObj->player_->PrepareAsync(); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "player Prepare failed"); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_Pause(OH_AVPlayer *player) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + int32_t ret = playerObj->player_->Pause(); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "player Pause failed"); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_Stop(OH_AVPlayer *player) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + int32_t ret = playerObj->player_->Stop(); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "player Stop failed"); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_Reset(OH_AVPlayer *player) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + int32_t ret = playerObj->player_->Reset(); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "player Reset failed"); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_Release(OH_AVPlayer *player) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + int32_t ret = playerObj->player_->Release(); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "player Release failed"); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_ReleaseSync(OH_AVPlayer *player) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + int32_t ret = playerObj->player_->ReleaseSync(); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "player ReleaseSync failed"); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_SetVolume(OH_AVPlayer *player, float leftVolume, float rightVolume) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + int32_t ret = playerObj->player_->SetVolume(leftVolume, rightVolume); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "player SetVolume failed"); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_Seek(OH_AVPlayer *player, int32_t mSeconds, OH_PlayerSeekMode mode) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + int32_t ret = playerObj->player_->Seek(mSeconds, static_cast(mode)); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "player Seek failed"); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_GetCurrentTime(OH_AVPlayer *player, int32_t *currentTime) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + int32_t ret = playerObj->player_->GetCurrentTime(*currentTime); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "player GetCurrentTime failed"); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_GetVideoWidth(OH_AVPlayer *player, int32_t *videoWidth) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + *videoWidth = playerObj->player_->GetVideoWidth(); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_GetVideoHeight(OH_AVPlayer *player, int32_t *videoHeight) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + *videoHeight = playerObj->player_->GetVideoHeight(); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_SetPlaybackSpeed(OH_AVPlayer *player, OH_PlaybackRateMode mode) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + int32_t ret = playerObj->player_->SetPlaybackSpeed(static_cast(mode)); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "player SetPlaybackSpeed failed"); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_GetPlaybackSpeed(OH_AVPlayer *player, OH_PlaybackRateMode *mode) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + PlaybackRateMode md; + int32_t ret = playerObj->player_->GetPlaybackSpeed(md); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "player GetPlaybackSpeed failed"); + *mode = static_cast(md); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_SelectBitRate(OH_AVPlayer *player, uint32_t bitRate) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + int32_t ret = playerObj->player_->SelectBitRate(bitRate); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "player SelectBitRate failed"); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_GetDuration(OH_AVPlayer *player, int32_t *duration) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + int32_t ret = playerObj->player_->GetDuration(*duration); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "player GetDuration failed"); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_GetState(OH_AVPlayer *player, OH_PlayerStates *state) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + *state = static_cast(player->state_); + return AV_ERR_OK; +} + +#ifdef SUPPORT_VIDEO +OH_AVErrCode OH_AVPlayer_SetVideoSurface(OH_AVPlayer *player, OHNativeWindow *window) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + CHECK_AND_RETURN_RET_LOG(window != nullptr, AV_ERR_INVALID_VAL, "Window is nullptr!"); + CHECK_AND_RETURN_RET_LOG(window->surface != nullptr, AV_ERR_INVALID_VAL, "Input window surface is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + int32_t ret = playerObj->player_->SetVideoSurface(window->surface); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "SetVideoSurface failed!"); + return AV_ERR_OK; +} +#endif + +bool OH_AVPlayer_IsPlaying(OH_AVPlayer *player) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + return playerObj->player_->IsPlaying(); +} + +bool OH_AVPlayer_IsLooping(OH_AVPlayer *player) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + return playerObj->player_->IsLooping(); +} + +OH_AVErrCode OH_AVPlayer_SetLooping(OH_AVPlayer *player, bool loop) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + int32_t ret = playerObj->player_->SetLooping(loop); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "player SetLooping failed"); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_SetPlayerCallback(OH_AVPlayer *player, OH_AVPlayerCallback callback) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + CHECK_AND_RETURN_RET_LOG(callback.onInfo != nullptr, AV_ERR_INVALID_VAL, "onInfo is null"); + CHECK_AND_RETURN_RET_LOG(callback.onError != nullptr, AV_ERR_INVALID_VAL, "onError is null"); + playerObj->callback_ = std::make_shared(player, callback); + int32_t ret = playerObj->player_->SetPlayerCallback(playerObj->callback_); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "player SetPlayerCallback failed"); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_SelectTrack(OH_AVPlayer *player, int32_t index) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + int32_t ret = playerObj->player_->SelectTrack(index); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "player SelectTrack failed"); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_DeselectTrack(OH_AVPlayer *player, int32_t index) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + int32_t ret = playerObj->player_->DeselectTrack(index); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "player DeselectTrack failed"); + return AV_ERR_OK; +} + +OH_AVErrCode OH_AVPlayer_GetCurrentTrack(OH_AVPlayer *player, int32_t trackType, int32_t *index) +{ + CHECK_AND_RETURN_RET_LOG(player != nullptr, AV_ERR_INVALID_VAL, "input player is nullptr!"); + struct PlayerObject *playerObj = reinterpret_cast(player); + CHECK_AND_RETURN_RET_LOG(playerObj->player_ != nullptr, AV_ERR_INVALID_VAL, "player_ is null"); + int32_t ret = playerObj->player_->GetCurrentTrack(trackType, *index); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_ERR_INVALID_VAL, "player GetCurrentTrack failed"); + return AV_ERR_OK; +} \ No newline at end of file diff --git a/frameworks/native/capi/screencapture/native_avscreen_capture.cpp b/frameworks/native/capi/screencapture/native_avscreen_capture.cpp index 284390b7d9115f715b6ec105f169fb8f7c3deb5b..c5454dfb68e5b3d2067e9c81e6a9c80937c32787 100644 --- a/frameworks/native/capi/screencapture/native_avscreen_capture.cpp +++ b/frameworks/native/capi/screencapture/native_avscreen_capture.cpp @@ -16,7 +16,7 @@ #include #include "media_log.h" #include "media_errors.h" -#include "native_avscreen_capture_magic.h" +#include "native_player_magic.h" #include "surface_buffer_impl.h" #include "native_avscreen_capture.h" diff --git a/interfaces/kits/c/BUILD.gn b/interfaces/kits/c/BUILD.gn index 77a7c65d92ac072df60ada0fc9dcc88857509045..c5f18c31cbb9a45c226cf5bcdf81698005a87c15 100644 --- a/interfaces/kits/c/BUILD.gn +++ b/interfaces/kits/c/BUILD.gn @@ -17,8 +17,10 @@ import("//foundation/multimedia/player_framework/config.gni") group("capi_packages") { deps = [] if (multimedia_player_framework_support_capi) { - deps += - [ "$MEDIA_PLAYER_ROOT_DIR/interfaces/kits/c:native_avscreen_capture" ] + deps += [ + "$MEDIA_PLAYER_ROOT_DIR/interfaces/kits/c:native_avplayer", + "$MEDIA_PLAYER_ROOT_DIR/interfaces/kits/c:native_avscreen_capture", + ] } } @@ -28,6 +30,7 @@ config("media_capi_config") { "$MEDIA_PLAYER_ROOT_DIR/interfaces/kits/c", "$MEDIA_PLAYER_ROOT_DIR/frameworks/native/capi/common", "$MEDIA_PLAYER_ROOT_DIR/services/utils/include", + "$MEDIA_PLAYER_AVCODEC/interfaces/kits/c", "$MEDIA_PLAYER_GRAPHIC/frameworks/surface/include", ] @@ -83,3 +86,32 @@ ohos_shared_library("native_avscreen_capture") { subsystem_name = "multimedia" part_name = "player_framework" } + +ohos_shared_library("native_avplayer") { + install_enable = true + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + + sources = [ + "$MEDIA_PLAYER_ROOT_DIR/frameworks/native/capi/player/native_avplayer.cpp", + ] + configs = [ ":media_capi_config" ] + + public_configs = [ ":media_capi_public_config" ] + + deps = [ "$MEDIA_PLAYER_ROOT_DIR/interfaces/inner_api/native:media_client" ] + + external_deps = [ + "c_utils:utils", + "graphic_2d:surface", + "hilog:libhilog", + "window_manager:libdm", + ] + output_extension = "so" + subsystem_name = "multimedia" + part_name = "player_framework" +} diff --git a/interfaces/kits/c/avplayer/BUILD.gn b/interfaces/kits/c/avplayer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..589849a8241b783d14a344959ca1c2e929ee72ad --- /dev/null +++ b/interfaces/kits/c/avplayer/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (C) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/ohos/ndk/ndk.gni") +import("//foundation/multimedia/player_framework/config.gni") + +ohos_ndk_headers("native_avplayer_header") { + dest_dir = "$ndk_headers_out_dir/multimedia/player_framework" + sources = [ + "$MEDIA_PLAYER_ROOT_DIR/interfaces/kits/c/native_avplayer.h", + "$MEDIA_PLAYER_ROOT_DIR/interfaces/kits/c/native_avplayer_base.h", + ] +} + +ohos_ndk_library("libnative_avplayer") { + ndk_description_file = "./libnative_avplayer.ndk.json" + min_compact_version = "1" + output_name = "native_avplayer" + output_extension = "so" + + system_capability = "SystemCapability.Multimedia.Media.AVPlayer" + system_capability_headers = [ + "multimedia/player_framework/native_avplayer.h", + "multimedia/player_framework/native_avplayer_base.h", + ] +} diff --git a/interfaces/kits/c/avplayer/libnative_avplayer.ndk.json b/interfaces/kits/c/avplayer/libnative_avplayer.ndk.json new file mode 100644 index 0000000000000000000000000000000000000000..db47a60431c2603648c2c870589b5d4787207d00 --- /dev/null +++ b/interfaces/kits/c/avplayer/libnative_avplayer.ndk.json @@ -0,0 +1,30 @@ +[ + { "name": "OH_AVPlayer_Create" }, + { "name": "OH_AVPlayer_SetUrlSource" }, + { "name": "OH_AVPlayer_SetFdSource" }, + { "name": "OH_AVPlayer_Play" }, + { "name": "OH_AVPlayer_Prepare" }, + { "name": "OH_AVPlayer_Pause" }, + { "name": "OH_AVPlayer_Stop" }, + { "name": "OH_AVPlayer_Reset" }, + { "name": "OH_AVPlayer_Release" }, + { "name": "OH_AVPlayer_ReleaseSync" }, + { "name": "OH_AVPlayer_SetVolume" }, + { "name": "OH_AVPlayer_Seek" }, + { "name": "OH_AVPlayer_GetCurrentTime" }, + { "name": "OH_AVPlayer_GetVideoWidth" }, + { "name": "OH_AVPlayer_GetVideoHeight" }, + { "name": "OH_AVPlayer_SetPlaybackSpeed" }, + { "name": "OH_AVPlayer_GetPlaybackSpeed" }, + { "name": "OH_AVPlayer_SetVideoSurface" }, + { "name": "OH_AVPlayer_SelectBitRate" }, + { "name": "OH_AVPlayer_GetDuration" }, + { "name": "OH_AVPlayer_GetState" }, + { "name": "OH_AVPlayer_IsPlaying" }, + { "name": "OH_AVPlayer_IsLooping" }, + { "name": "OH_AVPlayer_SetLooping" }, + { "name": "OH_AVPlayer_SetPlayerCallback" }, + { "name": "OH_AVPlayer_SelectTrack" }, + { "name": "OH_AVPlayer_DeselectTrack" }, + { "name": "OH_AVPlayer_GetCurrentTrack" } +] \ No newline at end of file diff --git a/interfaces/kits/c/native_avplayer.h b/interfaces/kits/c/native_avplayer.h new file mode 100644 index 0000000000000000000000000000000000000000..110613744781264b10d433a2342a58ca45d8563c --- /dev/null +++ b/interfaces/kits/c/native_avplayer.h @@ -0,0 +1,410 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVPLAYER_H +#define MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVPLAYER_H + +#include +#include +#include "native_averrors.h" +#include "native_avplayer_base.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** +* @brief Create a player +* @syscap SystemCapability.Multimedia.Media.AVPlayer +* @return Returns a pointer to an OH_AVPlayer instance +* @since 10 +* @version 1.0 +*/ +OH_AVPlayer *OH_AVPlayer_Create(void); + +/** + * @brief Sets the playback source for the player. The corresponding source can be http url + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @param url Indicates the playback source. + * @return Returns {@link AV_ERR_OK} if the url is set successfully; returns an error code defined + * in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_SetUrlSource(OH_AVPlayer *player, const char *url); + +/** + * @brief Sets the playback media file descriptor source for the player. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @param fd Indicates the file descriptor of media source. + * @param offset Indicates the offset of media source in file descriptor. + * @param size Indicates the size of media source. + * @return Returns {@link AV_ERR_OK} if the fd source is set successfully; returns an error code defined + * in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_SetFdSource(OH_AVPlayer *player, int32_t fd, int64_t offset, int64_t size); + +/** + * @brief Start playback. + * + * This function must be called after {@link Prepare}. If the player state is Prepared, + * this function is called to start playback. + * + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @return Returns {@link AV_ERR_OK} if the playback is started; otherwise returns an error code defined + * in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_Play(OH_AVPlayer *player); + +/** + * @brief Prepares the playback environment and buffers media data asynchronous. + * + * This function must be called after {@link SetSource}. + * + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @return Returns {@link AV_ERR_OK} if {@link Prepare} is successfully added to the task queue; + * returns an error code defined in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_Prepare(OH_AVPlayer *player); + +/** + * @brief Pauses playback. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @return Returns {@link AV_ERR_OK} if {@link Pause} is successfully added to the task queue; + * returns an error code defined in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_Pause(OH_AVPlayer *player); + +/** + * @brief Stop playback. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @return Returns {@link AV_ERR_OK} if {@link Stop} is successfully added to the task queue; + * returns an error code defined in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_Stop(OH_AVPlayer *player); + +/** + * @brief Restores the player to the initial state. + * + * After the function is called, add a playback source by calling {@link SetSource}, + * call {@link Play} to start playback again after {@link Prepare} is called. + * + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @return Returns {@link AV_ERR_OK} if {@link Reset} is successfully added to the task queue; + * returns an error code defined in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_Reset(OH_AVPlayer *player); + +/** + * @brief Releases player resources async + * + * Asynchronous release guarantees the performance + * but cannot ensure whether the surfacebuffer is released. + * The caller needs to ensure the life cycle security of the sufrace + * + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @return Returns {@link AV_ERR_OK} if {@link Release} is successfully added to the task queue; + * returns an error code defined in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_Release(OH_AVPlayer *player); + +/** + * @brief Releases player resources sync + * + * Synchronous release ensures effective release of surfacebuffer + * but this interface will take a long time (when the engine is not idle state) + * requiring the caller to design an asynchronous mechanism by itself + * + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @return Returns {@link AV_ERR_OK} if the playback is released; returns an error code defined + * in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_ReleaseSync(OH_AVPlayer *player); + +/** + * @brief Sets the volume of the player. + * + * This function can be used during playback or pause. The value 0 indicates no sound, + * and 1 indicates the original volume. If no audio device is started or no audio + * stream exists, the value -1 is returned. + * + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @param leftVolume Indicates the target volume of the left audio channel to set, + * ranging from 0 to 1. each step is 0.01. + * @param rightVolume Indicates the target volume of the right audio channel to set, + * ranging from 0 to 1. each step is 0.01. + * @return Returns {@link AV_ERR_OK} if the volume is set; returns an error code defined + * in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_SetVolume(OH_AVPlayer *player, float leftVolume, float rightVolume); + +/** + * @brief Changes the playback position. + * + * This function can be used during play or pause. + * + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @param mSeconds Indicates the target playback position, accurate to milliseconds. + * @param mode Indicates the player seek mode. For details, see {@link PlayerSeekMode}. + * @return Returns {@link AV_ERR_OK} if the seek is done; returns an error code defined + * in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 +*/ +OH_AVErrCode OH_AVPlayer_Seek(OH_AVPlayer *player, int32_t mSeconds, OH_PlayerSeekMode mode); + +/** + * @brief Obtains the playback position, accurate to millisecond. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @param currentTime Indicates the playback position. + * @return Returns {@link AV_ERR_OK} if the current position is get; returns an error code defined + * in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_GetCurrentTime(OH_AVPlayer *player, int32_t *currentTime); + +/** + * @brief get the video width. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @return Returns width if success; else returns 0 + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_GetVideoWidth(OH_AVPlayer *player, int32_t *videoWidth); + +/** + * @brief get the video height. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @return Returns height if success; else returns 0 + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_GetVideoHeight(OH_AVPlayer *player, int32_t *videoHeight); + +/** + * @brief set the player playback rate + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @param mode the rate mode {@link PlaybackRateMode} which can set. + * @return Returns {@link AV_ERR_OK} if the playback rate is set successful; returns an error code defined + * in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_SetPlaybackSpeed(OH_AVPlayer *player, OH_PlaybackRateMode mode); + +/** + * @brief get the current player playback rate + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @param mode the rate mode {@link PlaybackRateMode} which can get. + * @return Returns {@link AV_ERR_OK} if the current player playback rate is get; returns an error code defined + * in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_GetPlaybackSpeed(OH_AVPlayer *player, OH_PlaybackRateMode *mode); + +/** + * @brief set the bit rate use for hls player + * + * the playback bitrate expressed in bits per second, expressed in bits per second, + * which is only valid for HLS protocol network flow. By default, + * the player will select the appropriate bit rate and speed according to the network connection. + * report the effective bit rate linked list by "INFO_TYPE_BITRATE_COLLECT" + * set and select the specified bit rate, and select the bit rate that is less than and closest + * to the specified bit rate for playback. When ready, read it to query the currently selected bit rate. + * + * @param player Pointer to an OH_AVPlayer instance + * @param mode the rate mode {@link PlaybackRateMode} which can get. + * @param bitRate the bit rate, The unit is bps. + * @return Returns {@link AV_ERR_OK} if the bit rate is set successfully; returns an error code defined + * in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_SelectBitRate(OH_AVPlayer *player, uint32_t bitRate); + +#ifdef SUPPORT_AUDIO_ONLY +#else +/** + * @brief Method to set the surface. + * + * @param player Pointer to an OH_AVPlayer instance + * @param window A pointer to a OHNativeWindow instance, see {@link OHNativeWindow} + * @return Returns {@link AV_ERR_OK} if the surface is set; returns an error code defined + * in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_SetVideoSurface(OH_AVPlayer *player, OHNativeWindow *window); +#endif + + +/** + * @brief Obtains the total duration of media files, accurate to milliseconds. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @param duration Indicates the total duration of media files. + * @return Returns {@link AV_ERR_OK} if the current duration is get; returns an error code defined + * in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_GetDuration(OH_AVPlayer *player, int32_t *duration); + +/** + * @brief get current paly state. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @return Returns {@link AV_ERR_OK} if the current duration is get; returns an error code defined + * in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_GetState(OH_AVPlayer *player, OH_PlayerStates *state); + +/** + * @brief Checks whether the player is playing. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @return Returns true if the playback is playing; false otherwise. + * @since 1.0 + * @version 1.0 + */ +bool OH_AVPlayer_IsPlaying(OH_AVPlayer *player); + +/** + * @brief Returns the value whether single looping is enabled or not . + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @return Returns true if the playback is single looping; false otherwise. + * @since 1.0 + * @version 1.0 + */ +bool OH_AVPlayer_IsLooping(OH_AVPlayer *player); + +/** + * @brief Enables single looping of the media playback. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @return Returns {@link AV_ERR_OK} if the single looping is set; returns an error code defined + * in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_SetLooping(OH_AVPlayer *player, bool loop); + +/** + * @brief Method to set player callback. + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @param callback object pointer. + * @return Returns {@link AV_ERR_OK} if the playercallback is set; returns an error code defined + * in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_SetPlayerCallback(OH_AVPlayer *player, OH_AVPlayerCallback callback); + +/** + * @brief Select audio or subtitle track. + * + * By default, the first audio stream with data is played, and the subtitle track is not played. + * After the settings take effect, the original track will become invalid. Please set subtitles + * in prepared/playing/paused/completed state and set audio tracks in prepared state. + * + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @param index Track index, reference {@link #GetAudioTrackInfo} and {@link #GetVideoTrackInfo}. + * @return Returns {@link AV_ERR_OK} if selected successfully; returns an error code defined + * in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 +*/ +OH_AVErrCode OH_AVPlayer_SelectTrack(OH_AVPlayer *player, int32_t index); + +/** + * @brief Deselect the current audio or subtitle track. + * + * After audio is deselected, the default track will be played, and after subtitles are deselected, + * they will not be played. Please set subtitles in prepared/playing/paused/completed state and set + * audio tracks in prepared state. + * + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @param index Track index, reference {@link #GetAudioTrackInfo} and {@link #GetVideoTrackInfo}. + * @return Returns {@link AV_ERR_OK} if selected successfully; returns an error code defined + * in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 +*/ +OH_AVErrCode OH_AVPlayer_DeselectTrack(OH_AVPlayer *player, int32_t index); + +/** + * @brief Obtain the currently effective track index. + * + * Please get it in the prepared/playing/paused/completed state. + * + * @syscap SystemCapability.Multimedia.Media.AVPlayer + * @param player Pointer to an OH_AVPlayer instance + * @param trackType Media type. + * @param index Track index, reference {@link #GetAudioTrackInfo} and {@link #GetVideoTrackInfo}. + * @return Returns {@link AV_ERR_OK} if the track index is get; returns an error code defined + * in {@link native_player_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ +OH_AVErrCode OH_AVPlayer_GetCurrentTrack(OH_AVPlayer *player, int32_t trackType, int32_t *index); + + +#ifdef __cplusplus +} +#endif + +#endif // MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVPLAYER_H diff --git a/interfaces/kits/c/native_avplayer_base.h b/interfaces/kits/c/native_avplayer_base.h new file mode 100644 index 0000000000000000000000000000000000000000..a3f1cdd9bf06eb0c4263b8736e607ef36a5325da --- /dev/null +++ b/interfaces/kits/c/native_avplayer_base.h @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVPLAYER_BASH_H +#define MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVPLAYER_BASH_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OH_AVPlayer OH_AVPlayer; +typedef struct NativeWindow OHNativeWindow; + +typedef enum OH_PlayerStates { + /* error states */ + OH_PLAYER_STATE_ERROR = 0, + /* idle states */ + OH_PLAYER_IDLE = 1, + /* initialized states(Internal states) */ + OH_PLAYER_INITIALIZED = 2, + /* preparing states(Internal states) */ + OH_PLAYER_PREPARING = 3, + /* prepared states */ + OH_PLAYER_PREPARED = 4, + /* started states */ + OH_PLAYER_STARTED = 5, + /* paused states */ + OH_PLAYER_PAUSED = 6, + /* stopped states */ + OH_PLAYER_STOPPED = 7, + /* Play to the end states */ + OH_PLAYER_PLAYBACK_COMPLETE = 8, + /* released states */ + OH_PLAYER_RELEASED = 9, +} OH_PlayerStates; + +typedef enum OH_PlayerSeekMode { + /* sync to keyframes after the time point. */ + OH_SEEK_NEXT_SYNC = 0, + /* sync to keyframes before the time point. */ + OH_SEEK_PREVIOUS_SYNC, + /* sync to closest keyframes. */ + OH_SEEK_CLOSEST_SYNC, + /* seek to frames closest the time point. */ + OH_SEEK_CLOSEST, +} OH_PlayerSeekMode; + +typedef enum OH_PlaybackRateMode { + /* Video playback at 0.75x normal speed */ + OH_SPEED_FORWARD_0_75_X, + /* Video playback at normal speed */ + OH_SPEED_FORWARD_1_00_X, + /* Video playback at 1.25x normal speed */ + OH_SPEED_FORWARD_1_25_X, + /* Video playback at 1.75x normal speed */ + OH_SPEED_FORWARD_1_75_X, + /* Video playback at 2.0x normal speed */ + OH_SPEED_FORWARD_2_00_X, +} OH_PlaybackRateMode; + +typedef enum OH_PlayerOnInfoType { + /* return the message when seeking done. */ + OH_INFO_TYPE_SEEKDONE = 1, + /* return the message when speeding done. */ + OH_INFO_TYPE_SPEEDDONE, + /* return the message when select bitrate done */ + OH_INFO_TYPE_BITRATEDONE, + /* return the message when playback is end of steam. */ + OH_INFO_TYPE_EOS, + /* return the message when PlayerStates changed. */ + OH_INFO_TYPE_STATE_CHANGE, + /* return the current posion of playback automatically. */ + OH_INFO_TYPE_POSITION_UPDATE, + /* return the playback message. */ + OH_INFO_TYPE_MESSAGE, + /* return the message when volume changed. */ + OH_INFO_TYPE_VOLUME_CHANGE, + /* return the message when video size is first known or updated. */ + OH_INFO_TYPE_RESOLUTION_CHANGE, + /* return multiqueue buffering time. */ + OH_INFO_TYPE_BUFFERING_UPDATE, + /* return hls bitrate. + Bitrate is to convert data into uint8_t array storage, + which needs to be forcibly converted to uint32_t through offset access. */ + OH_INFO_TYPE_BITRATE_COLLECT, + /* return the message when audio focus changed. */ + OH_INFO_TYPE_INTERRUPT_EVENT, + /* return the message when PlayerStates changed by audio. */ + OH_INFO_TYPE_STATE_CHANGE_BY_AUDIO, + /* return the message with extra information in format. */ + OH_INFO_TYPE_EXTRA_FORMAT, + /* return the duration of playback. */ + OH_INFO_TYPE_DURATION_UPDATE, + /* return the playback is live stream. */ + OH_INFO_TYPE_IS_LIVE_STREAM, + /* return the message when track changes. */ + OH_INFO_TYPE_TRACKCHANGE, + /* return the default audio track. */ + OH_INFO_TYPE_DEFAULTTRACK, + /* return to the end of track processing. */ + OH_INFO_TYPE_TRACK_DONE, + /* return error message to prompt the user. */ + OH_INFO_TYPE_ERROR_MSG, + /* return the message when subtitle track num updated. */ + OH_INFO_TYPE_TRACK_NUM_UPDATE, + /* return the message when subtitle track info updated. */ + OH_INFO_TYPE_TRACK_OH_INFO_UPDATE, + /* return the subtitle of playback. */ + OH_INFO_TYPE_SUBTITLE_UPDATE, + /* return to the end of adding subtitle processing. */ + OH_INFO_TYPE_ADD_SUBTITLE_DONE, +} OH_PlayerOnInfoType; + +/** + * Called when a player message or alarm is received. + * + * @param player The pointer to an OH_AVPlayer instance. + * @param type Indicates the information type. For details, see {@link PlayerOnInfoType}. + * @param extra Indicates other information, for example, the start time position of a playing file. + */ +typedef void (*OH_AVPlayerOnInfo)(OH_AVPlayer *player, OH_PlayerOnInfoType type, int32_t extra); + +/** + * Called when an error occurred for versions above api9 + * + * @param player The pointer to an OH_AVPlayer instance. + * @param errorCode Error code. + * @param errorMsg Error message. + */ +typedef void (*OH_AVPlayerOnError)(OH_AVPlayer *player, int32_t errorCode, const char *errorMsg); + + +typedef struct OH_AVPlayerCallback { + OH_AVPlayerOnInfo onInfo; + OH_AVPlayerOnError onError; +} OH_AVPlayerCallback; + + +#ifdef __cplusplus +} +#endif +#endif // MULTIMEDIA_PLAYER_FRAMEWORK_NATIVE_AVPLAYER_BASH_H