From b2ac8e249bddb014991d9e19d8b4895e71ee7aa6 Mon Sep 17 00:00:00 2001 From: Viva La Vida Date: Wed, 27 Aug 2025 21:43:08 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=BE=B9=E6=92=AD=E7=89=B9=E6=80=A7?= =?UTF-8?q?=E4=BB=8E=E7=9B=B8=E6=9C=BA=E5=B7=A6=E4=B8=8B=E8=A7=92=E8=BF=9B?= =?UTF-8?q?=E5=85=A5=E5=90=8E=E5=A4=84=E7=90=86=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Viva La Vida --- frameworks/native/player/player_impl.cpp | 11 ++++- frameworks/native/player/player_impl.h | 1 + services/include/i_player_service.h | 6 +++ .../services/player/client/player_client.cpp | 7 +++ .../services/player/client/player_client.h | 1 + .../player/ipc/i_standard_player_service.h | 7 +++ .../player/ipc/player_service_proxy.cpp | 19 ++++++++ .../player/ipc/player_service_proxy.h | 1 + .../player/ipc/player_service_stub.cpp | 17 ++++++++ .../services/player/ipc/player_service_stub.h | 2 + .../services/player/server/player_server.cpp | 11 +++++ .../services/player/server/player_server.h | 1 + services/utils/include/fd_utils.h | 43 ++++++++++++++++++- 13 files changed, 124 insertions(+), 3 deletions(-) diff --git a/frameworks/native/player/player_impl.cpp b/frameworks/native/player/player_impl.cpp index a83e0a8a8..10869af43 100644 --- a/frameworks/native/player/player_impl.cpp +++ b/frameworks/native/player/player_impl.cpp @@ -914,7 +914,8 @@ int32_t PlayerImpl::EnableCameraPostprocessing() CHECK_AND_RETURN_RET_LOG(fdsanFd_ != nullptr, MSERR_OK, "source fd does not exist."); int fd = fdsanFd_->Get(); MEDIA_LOGD("PlayerImpl EnableCameraPostprocessing reopen fd: %{public}d ", fd); - FdsanFd reopenFd = FdUtils::ReOpenFd(fd); + bool isLocalFd = IsLocalFd(fd); + FdsanFd reopenFd = FdUtils::ReOpenFdOld(fd, isLocalFd); CHECK_AND_RETURN_RET_LOG(reopenFd.Get() >= 0, MSERR_UNKNOWN, "EnableCameraPostprocessing: reopen failed"); auto ret = SetReopenFd(reopenFd.Get()); reopenFd.Reset(); @@ -923,6 +924,14 @@ int32_t PlayerImpl::EnableCameraPostprocessing() LISTENER(return playerService_->EnableCameraPostprocessing(), "EnableCameraPostprocessing", false, TIME_OUT_SECOND); } +bool PlayerImpl::IsLocalFd(int32_t fd) +{ + MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR "IsLocalFd in", FAKE_POINTER(this)); + ScopedTimer timer("IsLocalFd", OVERTIME_WARNING_MS); + CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist."); + LISTENER(return playerService_->IsLocalFd(fd), "IsLocalFd", false, TIME_OUT_SECOND); +} + int32_t PlayerImpl::SetCameraPostprocessing(bool isOpen) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR "SetCameraPostprocessing in", FAKE_POINTER(this)); diff --git a/frameworks/native/player/player_impl.h b/frameworks/native/player/player_impl.h index bd36c2171..6817fe742 100644 --- a/frameworks/native/player/player_impl.h +++ b/frameworks/native/player/player_impl.h @@ -106,6 +106,7 @@ private: void ResetSeekVariables(); void HandleSeekDoneInfo(PlayerOnInfoType type, int32_t extra); int32_t SetSourceTask(int32_t fd, int64_t offset, int64_t size); + bool IsLocalFd(int32_t fd); std::recursive_mutex recMutex_; int32_t mCurrentPosition = INT32_MIN; PlayerSeekMode mCurrentSeekMode = PlayerSeekMode::SEEK_PREVIOUS_SYNC; diff --git a/services/include/i_player_service.h b/services/include/i_player_service.h index 3398e2270..10dfe88c4 100644 --- a/services/include/i_player_service.h +++ b/services/include/i_player_service.h @@ -701,6 +701,12 @@ public: return 0; } + virtual bool IsLocalFd(int32_t fd) + { + (void)fd; + return false; + } + virtual int32_t SetCameraPostprocessing(bool isOpen) { (void)isOpen; diff --git a/services/services/player/client/player_client.cpp b/services/services/player/client/player_client.cpp index 7b30af2ce..d102e519c 100644 --- a/services/services/player/client/player_client.cpp +++ b/services/services/player/client/player_client.cpp @@ -532,6 +532,13 @@ int32_t PlayerClient::SetReopenFd(int32_t fd) CHECK_AND_RETURN_RET_LOG(playerProxy_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist."); return playerProxy_->SetReopenFd(fd); } + +bool PlayerClient::IsLocalFd(int32_t fd) +{ + std::lock_guard lock(mutex_); + CHECK_AND_RETURN_RET_LOG(playerProxy_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist."); + return playerProxy_->IsLocalFd(fd); +} int32_t PlayerClient::EnableCameraPostprocessing() { diff --git a/services/services/player/client/player_client.h b/services/services/player/client/player_client.h index 798cc4c11..6f1832c5b 100644 --- a/services/services/player/client/player_client.h +++ b/services/services/player/client/player_client.h @@ -99,6 +99,7 @@ public: int32_t ForceLoadVideo(bool status) override; int32_t SetLoudnessGain(float loudnessGain) override; int32_t GetGlobalInfo(std::shared_ptr &globalInfo) override; + bool IsLocalFd(int32_t fd) override; private: int32_t CreateListenerObject(); diff --git a/services/services/player/ipc/i_standard_player_service.h b/services/services/player/ipc/i_standard_player_service.h index 10a524835..280e6a06d 100644 --- a/services/services/player/ipc/i_standard_player_service.h +++ b/services/services/player/ipc/i_standard_player_service.h @@ -176,6 +176,12 @@ public: return 0; } + virtual bool IsLocalFd(int32_t fd) + { + (void)fd; + return false; + } + virtual int32_t SetCameraPostprocessing(bool isOpen) { (void)isOpen; @@ -278,6 +284,7 @@ public: FORCE_LOAD_VIDEO, SET_LOUDNESSGAIN, SET_CAMERA_POST_POSTPROCESSING, + IS_LOCAL_FD, MAX_IPC_ID, // all IPC codes should be added before MAX_IPC_ID GET_GLOBAL_INFO, }; diff --git a/services/services/player/ipc/player_service_proxy.cpp b/services/services/player/ipc/player_service_proxy.cpp index cb05e8cf4..6c3b05b60 100644 --- a/services/services/player/ipc/player_service_proxy.cpp +++ b/services/services/player/ipc/player_service_proxy.cpp @@ -117,6 +117,7 @@ void PlayerServiceProxy::InitPlayerFuncsPart2() playerFuncs_[ENABLE_REPORT_MEDIA_PROGRESS] = "Player::EnableReportMediaProgress"; playerFuncs_[ENABLE_REPORT_AUDIO_INTERRUPT] = "Player::EnableReportAudioInterrupt"; playerFuncs_[SET_CAMERA_POST_POSTPROCESSING] = "Player::SetCameraPostprocessing"; + playerFuncs_[IS_LOCAL_FD] = "Player::IsLocalFd"; playerFuncs_[GET_GLOBAL_INFO] = "Player::GetGlobalInfo"; } @@ -1255,6 +1256,24 @@ int32_t PlayerServiceProxy::SetReopenFd(int32_t fd) "SetReopenFd failed, error: %{public}d", error); return reply.ReadInt32(); } + +bool PlayerServiceProxy::IsLocalFd(int32_t fd) +{ + MediaTrace trace("PlayerServiceProxy::IsLocalFd"); + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool token = data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor()); + CHECK_AND_RETURN_RET_LOG(token, MSERR_INVALID_OPERATION, "Failed to write descriptor!"); + + MEDIA_LOGI("IsLocalFd in fd: %{public}d", fd); + (void)data.WriteFileDescriptor(fd); + int32_t error = SendRequest(IS_LOCAL_FD, data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == MSERR_OK, MSERR_INVALID_OPERATION, + "IsLocalFd failed, error: %{public}d", error); + return reply.ReadBool(); +} int32_t PlayerServiceProxy::EnableCameraPostprocessing() { diff --git a/services/services/player/ipc/player_service_proxy.h b/services/services/player/ipc/player_service_proxy.h index 8d8f1d798..ec6015104 100644 --- a/services/services/player/ipc/player_service_proxy.h +++ b/services/services/player/ipc/player_service_proxy.h @@ -93,6 +93,7 @@ public: int32_t ForceLoadVideo(bool status) override; int32_t SetLoudnessGain(float loudnessGain) override; int32_t GetGlobalInfo(std::shared_ptr &globalInfo) override; + bool IsLocalFd(int32_t fd) override; private: int32_t SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); void InitPlayerFuncsPart1(); diff --git a/services/services/player/ipc/player_service_stub.cpp b/services/services/player/ipc/player_service_stub.cpp index 6b5a56dff..97ab9112d 100644 --- a/services/services/player/ipc/player_service_stub.cpp +++ b/services/services/player/ipc/player_service_stub.cpp @@ -262,6 +262,8 @@ void PlayerServiceStub::FillPlayerFuncPart3() [this](MessageParcel &data, MessageParcel &reply) { return SetLoudnessGain(data, reply); } }; playerFuncs_[SET_CAMERA_POST_POSTPROCESSING] = { "Player::SetCameraPostprocessing", [this](MessageParcel &data, MessageParcel &reply) { return SetCameraPostprocessing(data, reply); } }; + playerFuncs_[IS_LOCAL_FD] = { "Player::IsLocalFd", + [this](MessageParcel &data, MessageParcel &reply) { return IsLocalFd(data, reply); } }; playerFuncs_[GET_GLOBAL_INFO] = { "Player::GetGlobalInfo", [this](MessageParcel &data, MessageParcel &reply) { return GetGlobalInfo(data, reply); } }; } @@ -784,6 +786,21 @@ int32_t PlayerServiceStub::SetReopenFd(int32_t fd) return playerServer_->SetReopenFd(fd); } +bool PlayerServiceStub::IsLocalFd(MessageParcel &data, MessageParcel &reply) +{ + int32_t fd = data.ReadFileDescriptor(); + reply.WriteBool(IsLocalFd(fd)); + (void)::close(fd); + return MSERR_OK; +} + +bool PlayerServiceStub::IsLocalFd(int32_t fd) +{ + MediaTrace trace("PlayerServiceStub::IsLocalFd"); + CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr"); + return playerServer_->IsLocalFd(fd); +} + int32_t PlayerServiceStub::SetListenerObject(MessageParcel &data, MessageParcel &reply) { sptr object = data.ReadRemoteObject(); diff --git a/services/services/player/ipc/player_service_stub.h b/services/services/player/ipc/player_service_stub.h index ebe836a24..c2c778900 100644 --- a/services/services/player/ipc/player_service_stub.h +++ b/services/services/player/ipc/player_service_stub.h @@ -113,6 +113,7 @@ public: int32_t ForceLoadVideo(bool status) override; int32_t SetLoudnessGain(float loudnessGain) override; int32_t GetGlobalInfo(std::shared_ptr &globalInfo) override; + bool IsLocalFd(int32_t fd) override; protected: PlayerServiceStub(); virtual int32_t Init(); @@ -192,6 +193,7 @@ private: int32_t ForceLoadVideo(MessageParcel &data, MessageParcel &reply); int32_t SetLoudnessGain(MessageParcel &data, MessageParcel &reply); int32_t GetGlobalInfo(MessageParcel &data, MessageParcel &reply); + bool IsLocalFd(MessageParcel &data, MessageParcel &reply); int32_t ReadMediaStreamListFromMessageParcel( MessageParcel &data, const std::shared_ptr &mediaSource); diff --git a/services/services/player/server/player_server.cpp b/services/services/player/server/player_server.cpp index 7fc1256fe..0d8aeacfb 100644 --- a/services/services/player/server/player_server.cpp +++ b/services/services/player/server/player_server.cpp @@ -36,6 +36,7 @@ #include "audio_info.h" #include "osal/utils/steady_clock.h" #include "common/event.h" +#include "fd_utils.h" using namespace OHOS::QOS; @@ -2384,6 +2385,16 @@ int32_t PlayerServer::SetReopenFd(int32_t fd) CHECK_AND_RETURN_RET_NOLOG(playerEngine_ == nullptr, playerEngine_->SetReopenFd(fd)); return MSERR_OK; } + +bool PlayerServer::IsLocalFd(int32_t fd) +{ + MEDIA_LOGD("IsLocalFd success, fd = %{public}d", fd); + bool isLocalFd = false; +#if __linux__ + isLocalFd = FdUtils::LocalFdOld(fd); +#endif + return isLocalFd; +} int32_t PlayerServer::EnableCameraPostprocessing() { diff --git a/services/services/player/server/player_server.h b/services/services/player/server/player_server.h index 24c79425e..621cce580 100644 --- a/services/services/player/server/player_server.h +++ b/services/services/player/server/player_server.h @@ -162,6 +162,7 @@ public: int32_t ForceLoadVideo(bool status) override; int32_t SetLoudnessGain(float loudnessGain) override; int32_t GetGlobalInfo(std::shared_ptr &globalInfo) override; + bool IsLocalFd(int32_t fd) override; protected: class BaseState; diff --git a/services/utils/include/fd_utils.h b/services/utils/include/fd_utils.h index eef106b29..ac36988ed 100644 --- a/services/utils/include/fd_utils.h +++ b/services/utils/include/fd_utils.h @@ -30,7 +30,7 @@ namespace Media { namespace { constexpr size_t MAX_ATTR_NAME = 64; const std::string CLOUD_LOCATION_ATTR = "user.cloud.location"; -static const std::string LOCAL = "1"; +static const std::string LOCAL_FD = "1"; } #endif @@ -63,6 +63,45 @@ public: return FdsanFd(); } + static FdsanFd ReOpenFdOld(int32_t fd, bool isLocalFd) + { +#ifdef __linux__ + if (fd > 0 && isLocalFd) { + MEDIA_LOGI("ReOpenFdOld In"); + std::stringstream ss; + ss << "/proc/self/fd/" << fd; + std::string fdPathStr = ss.str(); + char realPath[PATH_MAX_REAL]; + ssize_t result = readlink(fdPathStr.c_str(), realPath, sizeof(realPath)); + if (result == RESULT_ERROR) { + MEDIA_LOGW("ReOpenFdOld readlink invalid fd: %{public}d, error: %{public}s", fd, std::strerror(errno)); + return FdsanFd(); + } + int32_t newFd = dup(fd); + if (newFd < 0) { + MEDIA_LOGW("ReOpenFdOld invalid fd: %{public}d, error: %{public}s", fd, std::strerror(errno)); + return FdsanFd(); + } + return FdsanFd(newFd); + } +#endif + MEDIA_LOGW("=== fd is cloud"); + return FdsanFd(); + } + + static bool LocalFdOld(int32_t fd) + { +#ifdef __linux__ + int loc; + int ioResult = ioctl(fd, HMDFS_IOC_GET_LOCATION, &loc); + if (ioResult == 0 && loc != IOCTL_CLOUD) { + return true; + } +#endif + MEDIA_LOGW("fd is cloud"); + return false; + } + private: #if __linux__ static bool LocalFd(int32_t fd) @@ -76,7 +115,7 @@ private: std::string local(value, static_cast(size)); MEDIA_LOGD("Getxattr value, local is %{public}s", local.c_str()); - return local == LOCAL; + return local == LOCAL_FD; } #endif -- Gitee From f7942f275fc74c05fb1309632fb64f343739349e Mon Sep 17 00:00:00 2001 From: Viva La Vida Date: Tue, 9 Sep 2025 11:05:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?handleEos=E4=B8=AD=E6=9C=AA=E5=AF=B9playerE?= =?UTF-8?q?ngine=E5=88=A4=E7=A9=BA=EF=BC=8C=E5=AF=BC=E8=87=B4=E5=A4=9A?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E8=AE=BF=E9=97=AE=E5=87=BA=E7=8E=B0=E4=BA=86?= =?UTF-8?q?crash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Viva La Vida --- services/services/player/server/player_server.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/services/services/player/server/player_server.cpp b/services/services/player/server/player_server.cpp index 0d8aeacfb..3e17ba6c8 100644 --- a/services/services/player/server/player_server.cpp +++ b/services/services/player/server/player_server.cpp @@ -1394,9 +1394,11 @@ void PlayerServer::HandleEos() auto cancelTask = std::make_shared>([this]() { MEDIA_LOGI("Interrupted seek action"); - playerEngine_->SetEosInLoopForFrozen(false); - taskMgr_.MarkTaskDone("interrupted seek done"); - disableNextSeekDone_ = false; + if (playerEngine_ != nullptr) { + playerEngine_->SetEosInLoopForFrozen(false); + taskMgr_.MarkTaskDone("interrupted seek done"); + disableNextSeekDone_ = false; + } }); int32_t ret = taskMgr_.SeekTask(seekTask, cancelTask, "eos seek", SEEK_PREVIOUS_SYNC, 0); -- Gitee