diff --git a/frameworks/js/avplayer/BUILD.gn b/frameworks/js/avplayer/BUILD.gn index a212f11c9d89f9e4b508118a0f5f49980ccd6e91..e47b9e9b7ea087a7225fd99230001bae0f8b797c 100644 --- a/frameworks/js/avplayer/BUILD.gn +++ b/frameworks/js/avplayer/BUILD.gn @@ -31,7 +31,6 @@ ohos_shared_library("media_avplayer") { "//foundation/multimedia/player_framework/interfaces/inner_api", "//foundation/multimedia/player_framework/frameworks/js/avplayer", "//foundation/multimedia/player_framework/frameworks/js/common", - "$MEDIA_ROOT_DIR/frameworks/js/utils", "$MEDIA_ROOT_DIR/frameworks/js/mediasource", "//foundation/multimedia/player_framework/services/utils/include", ] @@ -41,7 +40,6 @@ ohos_shared_library("media_avplayer") { "$MEDIA_ROOT_DIR/frameworks/js/mediasource/media_source_loader_callback.cpp", "$MEDIA_ROOT_DIR/frameworks/js/mediasource/media_source_loading_request_napi.cpp", "$MEDIA_ROOT_DIR/frameworks/js/mediasource/media_source_napi.cpp", - "$MEDIA_ROOT_DIR/frameworks/js/utils/scoped_file_descriptor.cpp", "./media_data_source_callback.cpp", "//foundation/multimedia/player_framework/frameworks/js/avplayer/avplayer_callback.cpp", "//foundation/multimedia/player_framework/frameworks/js/avplayer/avplayer_napi.cpp", diff --git a/frameworks/js/avplayer/avplayer_napi.cpp b/frameworks/js/avplayer/avplayer_napi.cpp index c6cad1ff909beaa46aee4837d7001984b2a47bd8..9839c28c4f8f8defd309f5504ce7c4352b500fb6 100644 --- a/frameworks/js/avplayer/avplayer_napi.cpp +++ b/frameworks/js/avplayer/avplayer_napi.cpp @@ -38,6 +38,8 @@ #include "ipc_skeleton.h" #include "tokenid_kit.h" #endif +#include "access_token.h" +#include "accesstoken_kit.h" using namespace OHOS::AudioStandard; @@ -93,6 +95,7 @@ napi_value AVPlayerNapi::Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("setPlaybackRange", JsSetPlaybackRange), DECLARE_NAPI_FUNCTION("setSuperResolution", JsSetSuperResolution), DECLARE_NAPI_FUNCTION("setVideoWindowSize", JsSetVideoWindowSize), + DECLARE_NAPI_FUNCTION("enableCameraPostProcess", JsEnableCameraPostProcess), DECLARE_NAPI_FUNCTION("on", JsSetOnCallback), DECLARE_NAPI_FUNCTION("off", JsClearOnCallback), DECLARE_NAPI_FUNCTION("setVolume", JsSetVolume), @@ -221,6 +224,16 @@ bool AVPlayerNapi::IsSystemApp() return isSystemApp; } +bool AVPlayerNapi::SystemPermission() +{ + auto tokenId = IPCSkeleton::GetCallingTokenID(); + auto tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId); + if (tokenType == Security::AccessToken::TOKEN_NATIVE || tokenType == Security::AccessToken::TOKEN_SHELL) { + return true; + } + return IsSystemApp(); +} + napi_value AVPlayerNapi::JsCreateAVPlayer(napi_env env, napi_callback_info info) { MediaTrace trace("AVPlayerNapi::createAVPlayer"); @@ -1742,6 +1755,68 @@ std::shared_ptr> AVPlayerNapi::SetVideoWindowSizeTask(int32 return task; } +napi_value AVPlayerNapi::JsEnableCameraPostProcess(napi_env env, napi_callback_info info) +{ + MediaTrace trace("AVPlayerNapi::enableCameraPostProcessor"); + napi_value result = nullptr; + napi_get_undefined(env, &result); + MEDIA_LOGD("JsEnableCameraPostProcess In"); + + napi_value args[PARAM_COUNT_SINGLE] = { nullptr }; + size_t argCount = PARAM_COUNT_SINGLE; // enableCameraPostProcessor(enabled: boolean) + AVPlayerNapi *jsPlayer = AVPlayerNapi::GetJsInstanceWithParameter(env, info, argCount, args); + CHECK_AND_RETURN_RET_LOG(jsPlayer != nullptr, result, "failed to GetJsInstanceWithParameter"); + + auto promiseCtx = std::make_unique(env); + promiseCtx->deferred = CommonNapi::CreatePromise(env, nullptr, result); + + if (!SystemPermission()) { + promiseCtx->SignError(MSERR_EXT_API9_PERMISSION_DENIED, "systemapi permission denied"); + } + if (!jsPlayer->CanCameraPostProcess()) { + promiseCtx->SignError(MSERR_EXT_API9_OPERATE_NOT_PERMIT, + "current state is not initialized/prepared/playing/paused/completed/stopped, " + "unsupport enable cameraPostProcessor"); + } else { + promiseCtx->asyncTask = jsPlayer->EnableCameraPostProcessTask(); + } + + napi_value resource = nullptr; + napi_create_string_utf8(env, "JsEnableCameraPostProcess", NAPI_AUTO_LENGTH, &resource); + NAPI_CALL(env, napi_create_async_work(env, nullptr, resource, + [](napi_env env, void *data) { + auto promiseCtx = reinterpret_cast(data); + CHECK_AND_RETURN_LOG(promiseCtx != nullptr, "promiseCtx is nullptr!"); + promiseCtx->CheckTaskResult(); + }, + MediaAsyncContext::CompleteCallback, static_cast(promiseCtx.get()), &promiseCtx->work)); + napi_queue_async_work_with_qos(env, promiseCtx->work, napi_qos_user_initiated); + promiseCtx.release(); + return result; +} + +std::shared_ptr> AVPlayerNapi::EnableCameraPostProcessTask() +{ + auto task = std::make_shared>([this]() { + std::unique_lock lock(taskMutex_); + auto state = GetCurrentState(); + if (CanCameraPostProcess()) { + int32_t ret = player_->EnableCameraPostProcessor(); + if (ret != MSERR_OK) { + auto errCode = MSErrorToExtErrorAPI9(static_cast(ret)); + return TaskRet(errCode, "failed to enable cameraPostProcessor"); + } + } else { + return TaskRet(MSERR_EXT_API9_OPERATE_NOT_PERMIT, + "current state is not initialized, " + "unsupport enable cameraPostProcessor"); + } + return TaskRet(MSERR_EXT_API9_OK, "Success"); + }); + (void)taskQue_->EnqueueTask(task); + return task; +} + napi_value AVPlayerNapi::JsGetUrl(napi_env env, napi_callback_info info) { MediaTrace trace("AVPlayerNapi::get url"); @@ -2600,6 +2675,15 @@ bool AVPlayerNapi::CanSetSuperResolution() return false; } +bool AVPlayerNapi::CanCameraPostProcess() +{ + auto state = GetCurrentState(); + if (state == AVPlayerState::STATE_INITIALIZED) { + return true; + } + return false; +} + std::string AVPlayerNapi::GetCurrentState() { if (isReleased_.load()) { diff --git a/frameworks/js/avplayer/avplayer_napi.h b/frameworks/js/avplayer/avplayer_napi.h index 46c708f6082a38d75a7a1a3fd8d66a5305321302..1bf2ecb243fdd6204f527103c09e22d524434d9c 100644 --- a/frameworks/js/avplayer/avplayer_napi.h +++ b/frameworks/js/avplayer/avplayer_napi.h @@ -254,6 +254,8 @@ private: static napi_value JsSetVideoWindowSize(napi_env env, napi_callback_info info); + static napi_value JsEnableCameraPostProcess(napi_env env, napi_callback_info info); + /** * getPlaybackInfo(): playbackInfo; */ @@ -305,6 +307,7 @@ private: static std::shared_ptr GetAVMediaSource(napi_env env, napi_value value, std::shared_ptr &srcTmp); static bool IsSystemApp(); + static bool SystemPermission(); AVPlayerNapi(); ~AVPlayerNapi() override; void SaveCallbackReference(const std::string &callbackName, std::shared_ptr ref); @@ -329,6 +332,7 @@ private: std::shared_ptr> SetMediaMutedTask(MediaType type, bool isMuted); std::shared_ptr> SetSuperResolutionTask(bool enabled); std::shared_ptr> SetVideoWindowSizeTask(int32_t width, int32_t height); + std::shared_ptr> EnableCameraPostProcessTask(); std::shared_ptr> EqueueSetPlayRangeTask(int32_t start, int32_t end, int32_t mode); std::shared_ptr> IsSeekContinuousSupportedTask(); @@ -337,6 +341,7 @@ private: bool CanSetPlayRange(); bool CanSetSuperResolution(); bool IsVideoWindowSizeValid(int32_t width, int32_t height); + bool CanCameraPostProcess(); bool IsLiveSource() const; void EnqueueNetworkTask(const std::string url); void EnqueueFdTask(const int32_t fd); diff --git a/frameworks/native/player/player_impl.cpp b/frameworks/native/player/player_impl.cpp index 1bed1ae18d14cc3af2679fa7d152abccc60068ab..4222567aae5591dcf9983e2c926f9069e4387189 100644 --- a/frameworks/native/player/player_impl.cpp +++ b/frameworks/native/player/player_impl.cpp @@ -22,6 +22,7 @@ #ifdef SUPPORT_AVPLAYER_DRM #include "imedia_key_session_service.h" #endif +#include "fd_utils.h" namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_PLAYER, "PlayerImpl"}; @@ -116,7 +117,23 @@ int32_t PlayerImpl::SetSource(int32_t fd, int64_t offset, int64_t size) ScopedTimer timer("SetSource fd", OVERTIME_WARNING_MS); MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " SetSource in(fd)", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); - LISTENER(return playerService_->SetSource(fd, offset, size), "SetSource fd", false, TIME_OUT_SECOND); + LISTENER(return SetSourceTask(fd, offset, size), "SetSource fd", false, TIME_OUT_SECOND); +} + +int32_t PlayerImpl::SetSourceTask(int32_t fd, int64_t offset, int64_t size) +{ + auto res = playerService_->SetSource(fd, offset, size); + int32_t dupFd = dup(fd); + if (dupFd < 0) { + MEDIA_LOGE("Dup failed with errno: %{public}s", std::strerror(errno)); + return res; + } + if (!ScopedFileDescriptor_) { + ScopedFileDescriptor_ = std::make_unique(dupFd); + } else { + ScopedFileDescriptor_->Reset(dupFd); + } + return res; } int32_t PlayerImpl::AddSubSource(const std::string &url) @@ -604,6 +621,31 @@ bool PlayerImpl::IsSeekContinuousSupported() return playerService_->IsSeekContinuousSupported(); } +int32_t PlayerImpl::SetReopenFd(int32_t fd) +{ + MEDIA_LOGI("PlayerImpl:0x%{public}06" PRIXPTR "SetReopenFd in", FAKE_POINTER(this)); + CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist."); + MEDIA_LOGI("=== set reopen fd: %{public}d", fd); + return playerService_->SetReopenFd(fd); +} + +int32_t PlayerImpl::EnableCameraPostProcess() +{ + MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " EnableCameraPostProcess in", FAKE_POINTER(this)); + ScopedTimer timer("EnableCameraPostProcess", OVERTIME_WARNING_MS); + if (ScopedFileDescriptor_ != nullptr) { + int fd = ScopedFileDescriptor_->Get(); + MEDIA_LOGD("PlayerImpl EnableCameraPostProcess reopen fd: %{public}d ", fd); + ScopedFileDescriptor reopenFd = FdUtils::ReOpenFd(fd); + if (SetReopenFd(reopenFd.Get()) != MSERR_OK) { + MEDIA_LOGW("SetReopenFd failed, fd: %{public}d", reopenFd.Get()); + } + reopenFd.Reset(); + } + CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist."); + LISTENER(return playerService_->EnableCameraPostProcess(), "EnableCameraPostProcess", false, TIME_OUT_SECOND); +} + int32_t PlayerImpl::SetSeiMessageCbStatus(bool status, const std::vector &payloadTypes) { ScopedTimer timer("SetSeiMessageCbStatus", OVERTIME_WARNING_MS); diff --git a/frameworks/native/player/player_impl.h b/frameworks/native/player/player_impl.h index 68d9d77da1502bcba6dbc259b25e7dd9ba0bcbd4..a43a2d0c78a4ed6b5f68b60fe010e060a7de0ad4 100644 --- a/frameworks/native/player/player_impl.h +++ b/frameworks/native/player/player_impl.h @@ -21,6 +21,7 @@ #include "osal/task/autolock.h" #include "i_player_service.h" #include "hitrace/tracechain.h" +#include "scoped_file_descriptor.h" namespace OHOS { namespace Media { @@ -87,9 +88,12 @@ public: bool IsSeekContinuousSupported() override; int32_t SetSeiMessageCbStatus(bool status, const std::vector &payloadTypes) override; void ReleaseClientListener() override; + int32_t SetReopenFd(int32_t fd) override; + int32_t EnableCameraPostProcess() override; private: void ResetSeekVariables(); void HandleSeekDoneInfo(PlayerOnInfoType type, int32_t extra); + int32_t SetSourceTask(int32_t fd, int64_t offset, int64_t size); std::recursive_mutex recMutex_; int32_t mCurrentPosition = INT32_MIN; PlayerSeekMode mCurrentSeekMode = PlayerSeekMode::SEEK_PREVIOUS_SYNC; @@ -98,6 +102,7 @@ private: std::atomic isSeeking_{false}; int32_t prevTrackIndex_ = INT32_MIN; std::shared_ptr callback_; + std::unique_ptr ScopedFileDescriptor_ = nullptr; std::shared_ptr playerService_ = nullptr; sptr surface_ = nullptr; diff --git a/interfaces/inner_api/native/BUILD.gn b/interfaces/inner_api/native/BUILD.gn index 41919c060e710fe83858371b5daf5c72b2cfd43d..9460358af6ab6e8b83dbc2021c0928aa3b958622 100644 --- a/interfaces/inner_api/native/BUILD.gn +++ b/interfaces/inner_api/native/BUILD.gn @@ -125,6 +125,7 @@ ohos_shared_library("media_client") { "$MEDIA_ROOT_DIR/services/services/player/client/player_client.cpp", "$MEDIA_ROOT_DIR/services/services/player/ipc/player_listener_stub.cpp", "$MEDIA_ROOT_DIR/services/services/player/ipc/player_service_proxy.cpp", + "$MEDIA_ROOT_DIR/services/utils/scoped_file_descriptor.cpp", ] } if (player_framework_support_recorder) { diff --git a/interfaces/inner_api/native/player.h b/interfaces/inner_api/native/player.h index 1095d18cc0eb3e26e3060a2737bd590d40fa9b42..66e720a3a55edb7f474a59484567d881401a34ba 100644 --- a/interfaces/inner_api/native/player.h +++ b/interfaces/inner_api/native/player.h @@ -981,6 +981,33 @@ public: (void)height; return 0; } + + /** + * @brief Set video reopen fd. + * + * @return Returns {@link MSERR_OK} if video reopen fd is set; returns an error code defined + * in {@link media_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t SetReopenFd(int32_t fd) + { + (void)fd; + return 0; + } + + /** + * @brief Enable or disable camera post processor. + * + * @return Returns {@link MSERR_OK} if enable camera post processor is set; returns an error code defined + * in {@link media_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t EnableCameraPostProcess() + { + return 0; + } }; class __attribute__((visibility("default"))) PlayerFactory { diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index 89688ac610e0fc5ef388703362b7d6d7e71d6bb6..5f3d3e5b40f1115ba76c6c14fe7a33294befcab2 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -66,7 +66,6 @@ ohos_shared_library("media") { "//foundation/multimedia/player_framework/services/utils/include", "${multimedia_player_framework_path}/frameworks/js/soundpool/include", "${multimedia_player_framework_path}/frameworks/js/metadatahelper", - "${multimedia_player_framework_path}/frameworks/js/utils", "${multimedia_player_framework_path}/interfaces/inner_api/native/soundpool/include", "//foundation/multimedia/player_framework/interfaces/inner_api/native/", ] @@ -75,7 +74,6 @@ ohos_shared_library("media") { "${multimedia_player_framework_path}/frameworks/js/mediasource/media_source_loader_callback.cpp", "${multimedia_player_framework_path}/frameworks/js/mediasource/media_source_loading_request_napi.cpp", "${multimedia_player_framework_path}/frameworks/js/mediasource/media_source_napi.cpp", - "${multimedia_player_framework_path}/frameworks/js/utils/scoped_file_descriptor.cpp", "//foundation/multimedia/player_framework/frameworks/js/common/common_napi.cpp", "//foundation/multimedia/player_framework/frameworks/js/media/media_enum_napi.cpp", "//foundation/multimedia/player_framework/frameworks/js/media/native_module_ohos_media.cpp", diff --git a/services/engine/histreamer/player/hiplayer_impl.cpp b/services/engine/histreamer/player/hiplayer_impl.cpp index f0e74caf5c73045b0659cded46c057e748fc38a1..2cb41ee1f8e14ec00aa4a34a35634d71d31e53ae 100644 --- a/services/engine/histreamer/player/hiplayer_impl.cpp +++ b/services/engine/histreamer/player/hiplayer_impl.cpp @@ -894,6 +894,9 @@ int32_t HiPlayerImpl::Pause(bool isSystemOperation) if (ret != Status::OK) { UpdateStateNoLock(PlayerStates::PLAYER_STATE_ERROR); } + if (videoDecoder_ != nullptr) { + videoDecoder_->NotifyPause(); + } callbackLooper_.StopReportMediaProgress(); StopFlvCheckLiveDelayTime(); callbackLooper_.StopCollectMaxAmplitude(); @@ -1333,6 +1336,7 @@ Status HiPlayerImpl::doSeek(int64_t seekPos, PlayerSeekMode mode) } } if (videoDecoder_ != nullptr) { + videoDecoder_->SetNormalSeekTime(seekTimeUs + mediaStartPts_); videoDecoder_->ResetSeekInfo(); } int64_t realSeekTime = seekPos; @@ -1747,6 +1751,9 @@ int32_t HiPlayerImpl::SetPlaybackSpeed(PlaybackRateMode mode) if (subtitleSink_ != nullptr) { res = subtitleSink_->SetSpeed(speed); } + if (videoDecoder_ != nullptr) { + res = videoDecoder_->SetSpeed(speed); + } if (res != Status::OK) { MEDIA_LOG_E("SetPlaybackSpeed audioSink set speed error"); return MSERR_UNKNOWN; @@ -3435,6 +3442,9 @@ int32_t HiPlayerImpl::ExitSeekContinous(bool align, int64_t seekContinousBatchNo FALSE_RETURN_V_MSG_E(Plugins::Us2HstTime(lastSeekContinousPos_, seekTimeUs), TransStatus(Status::OK), "Invalid lastSeekContinousPos_: %{public}" PRId64, lastSeekContinousPos_); syncManager_->Seek(seekTimeUs, true); + if (videoDecoder_ != nullptr) { + videoDecoder_->SetContinousSeekTime(seekTimeUs); + } FALSE_RETURN_V_MSG_E(align, TransStatus(Status::OK), "dont need align"); if (align && audioDecoder_ != nullptr && audioSink_ != nullptr) { audioDecoder_->DoFlush(); @@ -3629,6 +3639,32 @@ void HiPlayerImpl::SetPostProcessor() videoDecoder_->SetPostProcessorOn(isPostProcessorOn_); videoDecoder_->SetVideoWindowSize(postProcessorTargetWidth_, postProcessorTargetHeight_); } + videoDecoder_->SetPostProcessorFd(postProcessorFd_); + if (postProcessorFd_ > 0) { + close(postProcessorFd_); + postProcessorFd_ = -1; + } + videoDecoder_->EnableCameraPostProcess(enableCameraPostProcess_.load()); +} + +int32_t HiPlayerImpl::SetReopenFd(int32_t fd) +{ + if (postProcessorFd_ > 0) { + close(postProcessorFd_); + postProcessorFd_ = -1; + } + MEDIA_LOG_D("SetReopenFd %{public}d", fd); + if (fd > 0) { + postProcessorFd_ = dup(fd); + } + return TransStatus(Status::OK); +} + +int32_t HiPlayerImpl::EnableCameraPostProcess() +{ + MEDIA_LOG_D("EnableCameraPostProcess enter."); + enableCameraPostProcess_.store(true); + return TransStatus(Status::OK); } void HiPlayerImpl::HandleMemoryUsageEvent(const DfxEvent &event) diff --git a/services/engine/histreamer/player/hiplayer_impl.h b/services/engine/histreamer/player/hiplayer_impl.h index da31a25d706376438e64569ae57610827a6fd50f..1f50474837657089bafda522ff264c6f969ed0c6 100755 --- a/services/engine/histreamer/player/hiplayer_impl.h +++ b/services/engine/histreamer/player/hiplayer_impl.h @@ -183,6 +183,8 @@ public: int32_t IsSeekContinuousSupported(bool &isSeekContinuousSupported) override; int32_t SetSeiMessageCbStatus(bool status, const std::vector &payloadTypes) override; void SetPerfRecEnabled(bool isPerfRecEnabled) override; + int32_t SetReopenFd(int32_t fd) override; + int32_t EnableCameraPostProcess() override; private: enum HiplayerSvpMode : int32_t { @@ -453,6 +455,8 @@ private: // memory usage std::unordered_map memoryUsageInfo_ {}; std::mutex memoryReportMutex_; + int32_t postProcessorFd_ {-1}; + std::atomic enableCameraPostProcess_ {false}; }; } // namespace Media } // namespace OHOS diff --git a/services/include/i_player_service.h b/services/include/i_player_service.h index a8eb55a1692ce97452af3ce023ec51fa9ecdc60d..118bc67f494480458ff89a06413be51ca136dde4 100644 --- a/services/include/i_player_service.h +++ b/services/include/i_player_service.h @@ -634,6 +634,33 @@ public: { return 0; } + + /** + * @brief Set video reopen fd. + * + * @return Returns {@link MSERR_OK} if video reopen fd is set; returns an error code defined + * in {@link media_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t SetReopenFd(int32_t fd) + { + (void)fd; + return 0; + } + + /** + * @brief Enable or disable camera post process. + * + * @return Returns {@link MSERR_OK} if enable camera post process is set; returns an error code defined + * in {@link media_errors.h} otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t EnableCameraPostProcess() + { + return 0; + } }; } // namespace Media } // namespace OHOS diff --git a/services/services/engine_intf/i_player_engine.h b/services/services/engine_intf/i_player_engine.h index 0ef017827401621a914f3f4c3720b45b101461d1..af7880f0132755370cea4c10917adb2b393adea1 100644 --- a/services/services/engine_intf/i_player_engine.h +++ b/services/services/engine_intf/i_player_engine.h @@ -323,6 +323,17 @@ public: { return false; } + + virtual int32_t SetReopenFd(int32_t fd) + { + (void)fd; + return 0; + } + + virtual int32_t EnableCameraPostProcess() + { + return 0; + } }; } // namespace Media } // namespace OHOS diff --git a/services/services/player/client/player_client.cpp b/services/services/player/client/player_client.cpp index f7c0845996dadb190ef95b7ef4f73e5462007491..68213a2b939e474c2c365ab6c45c168f2d91a1ae 100644 --- a/services/services/player/client/player_client.cpp +++ b/services/services/player/client/player_client.cpp @@ -503,5 +503,19 @@ bool PlayerClient::IsSeekContinuousSupported() CHECK_AND_RETURN_RET_LOG(playerProxy_ != nullptr, false, "player service does not exist."); return playerProxy_->IsSeekContinuousSupported(); } + +int32_t PlayerClient::SetReopenFd(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_->SetReopenFd(fd); +} + +int32_t PlayerClient::EnableCameraPostProcess() +{ + std::lock_guard lock(mutex_); + CHECK_AND_RETURN_RET_LOG(playerProxy_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); + return playerProxy_->EnableCameraPostProcess(); +} } // namespace Media } // namespace OHOS \ No newline at end of file diff --git a/services/services/player/client/player_client.h b/services/services/player/client/player_client.h index 985ff2797e5fbb3e92d8e5c04c3a1b2a764085c1..bd7bfc918e7c3107f1d70e479a253b40b9e2eb0d 100644 --- a/services/services/player/client/player_client.h +++ b/services/services/player/client/player_client.h @@ -88,6 +88,8 @@ public: int32_t SetDeviceChangeCbStatus(bool status) override; bool IsSeekContinuousSupported() override; int32_t SetSeiMessageCbStatus(bool status, const std::vector &payloadTypes) override; + int32_t SetReopenFd(int32_t fd) override; + int32_t EnableCameraPostProcess() 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 c96729c19f606daf0ac37ccd401bea440603bd9e..0b4fbd81b819b88f84363a1d4fedf06b0c80bbac 100644 --- a/services/services/player/ipc/i_standard_player_service.h +++ b/services/services/player/ipc/i_standard_player_service.h @@ -157,6 +157,17 @@ public: return 0; } + virtual int32_t SetReopenFd(int32_t fd) + { + (void)fd; + return 0; + } + + virtual int32_t EnableCameraPostProcess() + { + return 0; + } + /** * IPC code ID */ @@ -214,6 +225,8 @@ public: GET_API_VERSION, IS_SEEK_CONTINUOUS_SUPPORTED, SET_SOURCE_LOADER, + SET_REOPEN_FD, + ENABLE_CAMERA_POST_PROCESS, MAX_IPC_ID, // all IPC codes should be added before MAX_IPC_ID }; diff --git a/services/services/player/ipc/player_service_proxy.cpp b/services/services/player/ipc/player_service_proxy.cpp index 10f2847887b12f263fefb703cbca777b2b1cdc15..182988b08363fd38726ee6067b1e0b9f0eccda84 100644 --- a/services/services/player/ipc/player_service_proxy.cpp +++ b/services/services/player/ipc/player_service_proxy.cpp @@ -109,6 +109,8 @@ void PlayerServiceProxy::InitPlayerFuncsPart2() playerFuncs_[SET_SOURCE_LOADER] = "Player::SetSourceLoader"; playerFuncs_[SET_SUPER_RESOLUTION] = "Player::SetSuperResolution"; playerFuncs_[SET_VIDEO_WINDOW_SIZE] = "Player::SetVideoWindowSize"; + playerFuncs_[SET_REOPEN_FD] = "Player::SetReopenFd"; + playerFuncs_[ENABLE_CAMERA_POST_PROCESS] = "Player::EnableCameraPostProcess"; } int32_t PlayerServiceProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) @@ -1172,5 +1174,40 @@ void PlayerServiceProxy::WritePlaybackStrategy(MessageParcel &data, const AVPlay (void)data.WriteString(strategy.preferredAudioLanguage); (void)data.WriteString(strategy.preferredSubtitleLanguage); } + +int32_t PlayerServiceProxy::SetReopenFd(int32_t fd) +{ + MediaTrace trace("PlayerServiceProxy::SetReopenFd"); + 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("SetReopenFd in fd: %{public}d", fd); + (void)data.WriteFileDescriptor(fd); + int32_t error = SendRequest(SET_REOPEN_FD, data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == MSERR_OK, MSERR_INVALID_OPERATION, + "SetReopenFd failed, error: %{public}d", error); + return reply.ReadInt32(); +} + +int32_t PlayerServiceProxy::EnableCameraPostProcess() +{ + MediaTrace trace("Proxy::EnableCameraPostProcess"); + 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!"); + + int32_t error = SendRequest(ENABLE_CAMERA_POST_PROCESS, data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == MSERR_OK, MSERR_INVALID_OPERATION, + "EnableCameraPostProcess failed, error: %{public}d", error); + + return reply.ReadInt32(); +} } // namespace Media } // namespace OHOS diff --git a/services/services/player/ipc/player_service_proxy.h b/services/services/player/ipc/player_service_proxy.h index b591a0f8996fe52131a694ce88f27e47da28b2b9..f2cf74a4fa3f997a3a5ee04013e9d3493c656614 100644 --- a/services/services/player/ipc/player_service_proxy.h +++ b/services/services/player/ipc/player_service_proxy.h @@ -82,6 +82,8 @@ public: int32_t GetApiVersion(int32_t &apiVersion) override; bool IsSeekContinuousSupported() override; int32_t SetSeiMessageCbStatus(bool status, const std::vector &payloadTypes) override; + int32_t SetReopenFd(int32_t fd) override; + int32_t EnableCameraPostProcess() 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 96ffa4f6bb547526afe386777f8eb28a080dfb89..22036ba76cb5094b5302c8db3f5067f091991b21 100644 --- a/services/services/player/ipc/player_service_stub.cpp +++ b/services/services/player/ipc/player_service_stub.cpp @@ -201,6 +201,10 @@ void PlayerServiceStub::FillPlayerFuncPart3() [this](MessageParcel &data, MessageParcel &reply) { return SetVideoWindowSize(data, reply); } }; playerFuncs_[SET_VOLUME_MODE] = { "Player::SetVolumeMode", [this](MessageParcel &data, MessageParcel &reply) { return SetVolumeMode(data, reply); } }; + playerFuncs_[SET_REOPEN_FD] = { "Player::SetReopenFd", + [this](MessageParcel &data, MessageParcel &reply) { return SetReopenFd(data, reply); } }; + playerFuncs_[ENABLE_CAMERA_POST_PROCESS] = { "Player::EnableCameraPostProcess", + [this](MessageParcel &data, MessageParcel &reply) { return EnableCameraPostProcess(data, reply); } }; } int32_t PlayerServiceStub::Init() @@ -677,6 +681,13 @@ uint32_t PlayerServiceStub::GetMemoryUsage() return playerServer_->GetMemoryUsage(); } +int32_t PlayerServiceStub::SetReopenFd(int32_t fd) +{ + MediaTrace trace("PlayerServiceStub::SetReopenFd"); + CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr"); + return playerServer_->SetReopenFd(fd); +} + int32_t PlayerServiceStub::SetListenerObject(MessageParcel &data, MessageParcel &reply) { sptr object = data.ReadRemoteObject(); @@ -1287,5 +1298,26 @@ int32_t PlayerServiceStub::SetSeiMessageCbStatus(MessageParcel &data, MessagePar reply.WriteInt32(SetSeiMessageCbStatus(status, payloadTypes)); return MSERR_OK; } + +int32_t PlayerServiceStub::SetReopenFd(MessageParcel &data, MessageParcel &reply) +{ + int32_t fd = data.ReadFileDescriptor(); + reply.WriteInt32(SetReopenFd(fd)); + (void)::close(fd); + return MSERR_OK; +} + +int32_t PlayerServiceStub::EnableCameraPostProcess(MessageParcel &data, MessageParcel &reply) +{ + reply.WriteInt32(EnableCameraPostProcess()); + return MSERR_OK; +} + +int32_t PlayerServiceStub::EnableCameraPostProcess() +{ + MediaTrace trace("Stub::EnableCameraPostProcess"); + CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr"); + return playerServer_->EnableCameraPostProcess(); +} } // namespace Media } // namespace OHOS diff --git a/services/services/player/ipc/player_service_stub.h b/services/services/player/ipc/player_service_stub.h index f64dafb46fdba6ba68865d7f3e6f77dd8f21b42f..cb3b198d89dec3237da0b0354cc847d028e10a62 100644 --- a/services/services/player/ipc/player_service_stub.h +++ b/services/services/player/ipc/player_service_stub.h @@ -99,6 +99,8 @@ public: bool IsSeekContinuousSupported() override; int32_t SetSeiMessageCbStatus(bool status, const std::vector &payloadTypes) override; uint32_t GetMemoryUsage(); + int32_t SetReopenFd(int32_t fd) override; + int32_t EnableCameraPostProcess() override; protected: PlayerServiceStub(); virtual int32_t Init(); @@ -167,6 +169,8 @@ private: int32_t SetMaxAmplitudeCbStatus(MessageParcel &data, MessageParcel &reply); int32_t IsSeekContinuousSupported(MessageParcel &data, MessageParcel &reply); int32_t SetSeiMessageCbStatus(MessageParcel &data, MessageParcel &reply); + int32_t SetReopenFd(MessageParcel &data, MessageParcel &reply); + int32_t EnableCameraPostProcess(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 b4a34163b8b25fb60daf4d141e525f27dfbfae8d..e55c8d402e49b8b55789384889c39509a52f8040 100644 --- a/services/services/player/server/player_server.cpp +++ b/services/services/player/server/player_server.cpp @@ -2155,5 +2155,23 @@ uint32_t PlayerServer::GetMemoryUsage() { return totalMemoryUage_.load(); } + +int32_t PlayerServer::SetReopenFd(int32_t fd) +{ + MEDIA_LOGD("Set reopenFd success, fd = %{public}d", fd); + CHECK_AND_RETURN_RET_NOLOG(playerEngine_ == nullptr, playerEngine_->SetReopenFd(fd)); + return MSERR_OK; +} + +int32_t PlayerServer::EnableCameraPostProcess() +{ + MediaTrace::TraceBegin("PlayerServer::EnableCameraPostProcess", FAKE_POINTER(this)); + std::lock_guard lock(mutex_); + bool isValidState = lastOpStatus_ == PLAYER_INITIALIZED; + CHECK_AND_RETURN_RET_LOG(isValidState, MSERR_INVALID_STATE, + "can not enable camera postProcessor, current state is %{public}d", static_cast(lastOpStatus_.load())); + CHECK_AND_RETURN_RET_LOG(playerEngine_ != nullptr, MSERR_NO_MEMORY, "engine is nullptr"); + return playerEngine_->EnableCameraPostProcess(); +} } // namespace Media } // namespace OHOS diff --git a/services/services/player/server/player_server.h b/services/services/player/server/player_server.h index adebfdd8a8a67922fdad99dae6105777b9593129..36593ad734425be8578e3e2727e9a5247cce4e63 100644 --- a/services/services/player/server/player_server.h +++ b/services/services/player/server/player_server.h @@ -149,6 +149,8 @@ public: int32_t SetDeviceChangeCbStatus(bool status) override; bool IsSeekContinuousSupported() override; int32_t SetSeiMessageCbStatus(bool status, const std::vector &payloadTypes) override; + int32_t SetReopenFd(int32_t fd) override; + int32_t EnableCameraPostProcess() override; protected: class BaseState; diff --git a/services/utils/BUILD.gn b/services/utils/BUILD.gn index 37c4cfd40f4a7da377b8da70b2608a8abdf926cf..7509fab8e238df64621300c26294f190e2cdcfd6 100644 --- a/services/utils/BUILD.gn +++ b/services/utils/BUILD.gn @@ -37,6 +37,7 @@ ohos_shared_library("media_service_utils") { "media_permission.cpp", "media_utils.cpp", "player_xcollie.cpp", + "scoped_file_descriptor.cpp", "task_queue.cpp", "time_format_utils.cpp", "uri_helper.cpp", diff --git a/frameworks/js/utils/fd_utils.h b/services/utils/include/fd_utils.h similarity index 91% rename from frameworks/js/utils/fd_utils.h rename to services/utils/include/fd_utils.h index fbf87c1ed8c812367b57c2d312acf7b8b4a99a5f..f0394b961f70bfab53815fc13a9580a18604cc43 100644 --- a/frameworks/js/utils/fd_utils.h +++ b/services/utils/include/fd_utils.h @@ -39,17 +39,17 @@ public: ssize_t result = readlink(fdPathStr.c_str(), realPath, sizeof(realPath)); if (result == RESULT_ERROR) { MEDIA_LOGW("invailed fd: %{public}d, error: %{public}s", fd, std::strerror(errno)); - return ScopedFileDescriptor(dup(fd)); + return ScopedFileDescriptor(); } auto newFd = open(fdPathStr.c_str(), O_RDONLY); if (newFd < 0) { MEDIA_LOGW("invailed fd: %{public}d, error: %{public}s", fd, std::strerror(errno)); - return ScopedFileDescriptor(dup(fd)); + return ScopedFileDescriptor(); } return ScopedFileDescriptor(newFd); } #endif - return ScopedFileDescriptor(dup(fd)); + return ScopedFileDescriptor(); } private: diff --git a/frameworks/js/utils/scoped_file_descriptor.h b/services/utils/include/scoped_file_descriptor.h similarity index 100% rename from frameworks/js/utils/scoped_file_descriptor.h rename to services/utils/include/scoped_file_descriptor.h diff --git a/frameworks/js/utils/scoped_file_descriptor.cpp b/services/utils/scoped_file_descriptor.cpp similarity index 100% rename from frameworks/js/utils/scoped_file_descriptor.cpp rename to services/utils/scoped_file_descriptor.cpp