From 4c6393690f881c7f65c686650ec4881af354fe08 Mon Sep 17 00:00:00 2001 From: liujie129 Date: Mon, 15 Jan 2024 20:52:53 +0800 Subject: [PATCH] use appuid to create histreamer engine Signed-off-by: liujie129 --- .../gstreamer/factory/engine_factory.cpp | 5 +- .../histreamer/factory/hst_engine_factory.cpp | 14 ++++- services/etc/media_service.cfg | 1 + .../avcodec/server/avcodec_server.cpp | 4 +- .../avcodeclist/server/avcodeclist_server.cpp | 5 +- .../server/avmetadatahelper_server.cpp | 8 ++- .../server/avmetadatahelper_server.h | 1 + .../services/engine_intf/i_engine_factory.h | 3 +- .../services/factory/engine_factory_repo.cpp | 22 ++++--- .../services/factory/engine_factory_repo.h | 5 +- .../ipc/i_standard_media_data_source.h | 3 +- .../ipc/media_data_source_proxy.cpp | 14 ++--- .../ipc/media_data_source_proxy.h | 3 +- .../ipc/media_data_source_stub.cpp | 5 +- .../ipc/media_data_source_stub.h | 3 +- .../services/player/server/player_server.cpp | 3 +- .../recorder/server/recorder_server.cpp | 3 +- services/utils/BUILD.gn | 4 ++ services/utils/include/media_utils.h | 2 + services/utils/media_utils.cpp | 57 +++++++++++++++++++ 20 files changed, 128 insertions(+), 37 deletions(-) diff --git a/services/engine/gstreamer/factory/engine_factory.cpp b/services/engine/gstreamer/factory/engine_factory.cpp index 0f720f36f..d10fbe8d6 100644 --- a/services/engine/gstreamer/factory/engine_factory.cpp +++ b/services/engine/gstreamer/factory/engine_factory.cpp @@ -35,7 +35,7 @@ public: GstEngineFactory() = default; ~GstEngineFactory() = default; - int32_t Score(Scene scene, const std::string &uri) override; + int32_t Score(Scene scene, const int32_t& appUid, const std::string &uri) override; #ifdef SUPPORT_PLAYER std::unique_ptr CreatePlayerEngine(int32_t uid = 0, int32_t pid = 0, uint32_t tokenId = 0) override; #endif @@ -52,9 +52,10 @@ public: #endif }; -int32_t GstEngineFactory::Score(Scene scene, const std::string &uri) +int32_t GstEngineFactory::Score(Scene scene, const int32_t& appUid, const std::string &uri) { (void)uri; + (void)appUid; (void)scene; return MIN_SCORE + 1; } diff --git a/services/engine/histreamer/factory/hst_engine_factory.cpp b/services/engine/histreamer/factory/hst_engine_factory.cpp index 7a9617e1d..902e84278 100644 --- a/services/engine/histreamer/factory/hst_engine_factory.cpp +++ b/services/engine/histreamer/factory/hst_engine_factory.cpp @@ -15,6 +15,7 @@ #include "i_engine_factory.h" #include "media_errors.h" +#include "media_utils.h" #include "common/log.h" #include "avmetadatahelper_impl.h" #ifdef SUPPORT_RECORDER @@ -31,7 +32,7 @@ public: HstEngineFactory() = default; ~HstEngineFactory() override = default; - int32_t Score(Scene scene, const std::string& uri) override; + int32_t Score(Scene scene, const int32_t& appUid, const std::string& uri) override; #ifdef SUPPORT_PLAYER std::unique_ptr CreatePlayerEngine(int32_t uid = 0, int32_t pid = 0, uint32_t tokenId = 0) override; #endif @@ -48,11 +49,18 @@ public: #endif }; -int32_t HstEngineFactory::Score(Scene scene, const std::string& uri) +int32_t HstEngineFactory::Score(Scene scene, const int32_t& appUid, const std::string& uri) { MEDIA_LOG_E("Score in"); + (void)scene; (void)uri; - return MAX_SCORE; + + std::string bundleName = GetClientBundleName(appUid); + bool isEnableHst = IsEnableHiStreamer(bundleName); + MEDIA_LOG_I("Score histreamer engine factory, appUid = %{public}d, bundleName = %{public}s," + "isEnableHiStreamer = %{public}d", appUid, bundleName.c_str(), isEnableHst); + + return isEnableHst ? MAX_SCORE : MIN_SCORE; } #ifdef SUPPORT_RECORDER diff --git a/services/etc/media_service.cfg b/services/etc/media_service.cfg index 2c6edb1d3..76e9b0a27 100644 --- a/services/etc/media_service.cfg +++ b/services/etc/media_service.cfg @@ -5,6 +5,7 @@ "uid" : "media", "gid" : ["media_rw", "system", "netsys_socket"], "permission" : [ + "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", "ohos.permission.MICROPHONE", "ohos.permission.CAPTURE_SCREEN" ], diff --git a/services/services/avcodec/server/avcodec_server.cpp b/services/services/avcodec/server/avcodec_server.cpp index bca5184f7..ac713f989 100644 --- a/services/services/avcodec/server/avcodec_server.cpp +++ b/services/services/avcodec/server/avcodec_server.cpp @@ -19,6 +19,7 @@ #include "media_errors.h" #include "engine_factory_repo.h" #include "media_dfx.h" +#include "ipc_skeleton.h" namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AVCodecServer"}; @@ -68,7 +69,8 @@ void AVCodecServer::ExitProcessor() int32_t AVCodecServer::Init() { - auto engineFactory = EngineFactoryRepo::Instance().GetEngineFactory(IEngineFactory::Scene::SCENE_AVCODEC); + int32_t appUid = IPCSkeleton::GetCallingUid(); + auto engineFactory = EngineFactoryRepo::Instance().GetEngineFactory(IEngineFactory::Scene::SCENE_AVCODEC, appUid); CHECK_AND_RETURN_RET_LOG(engineFactory != nullptr, MSERR_CREATE_AVCODEC_ENGINE_FAILED, "failed to get factory"); codecEngine_ = engineFactory->CreateAVCodecEngine(); CHECK_AND_RETURN_RET_LOG(codecEngine_ != nullptr, MSERR_CREATE_AVCODEC_ENGINE_FAILED, diff --git a/services/services/avcodeclist/server/avcodeclist_server.cpp b/services/services/avcodeclist/server/avcodeclist_server.cpp index cd851e4dc..767ff8f88 100644 --- a/services/services/avcodeclist/server/avcodeclist_server.cpp +++ b/services/services/avcodeclist/server/avcodeclist_server.cpp @@ -17,6 +17,7 @@ #include "media_log.h" #include "media_errors.h" #include "engine_factory_repo.h" +#include "ipc_skeleton.h" namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AVCodecListServer"}; @@ -47,7 +48,9 @@ AVCodecListServer::~AVCodecListServer() int32_t AVCodecListServer::Init() { - auto engineFactory = EngineFactoryRepo::Instance().GetEngineFactory(IEngineFactory::Scene::SCENE_AVCODECLIST); + int32_t appUid = IPCSkeleton::GetCallingUid(); + auto engineFactory = EngineFactoryRepo::Instance().GetEngineFactory( + IEngineFactory::Scene::SCENE_AVCODECLIST, appUid); CHECK_AND_RETURN_RET_LOG(engineFactory != nullptr, MSERR_CREATE_REC_ENGINE_FAILED, "failed to get factory"); codecListEngine_ = engineFactory->CreateAVCodecListEngine(); CHECK_AND_RETURN_RET_LOG(codecListEngine_ != nullptr, MSERR_CREATE_REC_ENGINE_FAILED, diff --git a/services/services/avmetadatahelper/server/avmetadatahelper_server.cpp b/services/services/avmetadatahelper/server/avmetadatahelper_server.cpp index f56775ad3..1e04b6a57 100644 --- a/services/services/avmetadatahelper/server/avmetadatahelper_server.cpp +++ b/services/services/avmetadatahelper/server/avmetadatahelper_server.cpp @@ -19,6 +19,7 @@ #include "engine_factory_repo.h" #include "uri_helper.h" #include "media_dfx.h" +#include "ipc_skeleton.h" namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AVMetadataHelperServer"}; @@ -44,6 +45,7 @@ std::shared_ptr AVMetadataHelperServer::Create() AVMetadataHelperServer::AVMetadataHelperServer() : taskQue_("AVMetadata") { + appUid_ = IPCSkeleton::GetCallingUid(); (void)taskQue_.Start(); MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this)); } @@ -78,7 +80,7 @@ int32_t AVMetadataHelperServer::SetSource(const std::string &uri, int32_t usage) } auto task = std::make_shared>([&, this] { auto metaEngineFactory = EngineFactoryRepo::Instance().GetEngineFactory( - IEngineFactory::Scene::SCENE_AVMETADATA, uriHelper_->FormattedUri()); + IEngineFactory::Scene::SCENE_AVMETADATA, appUid_, uriHelper_->FormattedUri()); CHECK_AND_RETURN_RET_LOG(metaEngineFactory != nullptr, (int32_t)MSERR_CREATE_AVMETADATAHELPER_ENGINE_FAILED, "Failed to get engine factory."); avMetadataHelperEngine_ = metaEngineFactory->CreateAVMetadataHelperEngine(); @@ -111,7 +113,7 @@ int32_t AVMetadataHelperServer::SetSource(int32_t fd, int64_t offset, int64_t si auto task = std::make_shared>([&, this] { auto engineFactory = EngineFactoryRepo::Instance().GetEngineFactory( - IEngineFactory::Scene::SCENE_AVMETADATA, uriHelper_->FormattedUri()); + IEngineFactory::Scene::SCENE_AVMETADATA, appUid_, uriHelper_->FormattedUri()); CHECK_AND_RETURN_RET_LOG(engineFactory != nullptr, (int32_t)MSERR_CREATE_AVMETADATAHELPER_ENGINE_FAILED, "Failed to get engine factory"); avMetadataHelperEngine_ = engineFactory->CreateAVMetadataHelperEngine(); @@ -142,7 +144,7 @@ int32_t AVMetadataHelperServer::SetSource(const std::shared_ptr>([&, this] { auto engineFactory = EngineFactoryRepo::Instance().GetEngineFactory( - IEngineFactory::Scene::SCENE_AVMETADATA, config_.url); + IEngineFactory::Scene::SCENE_AVMETADATA, appUid_, config_.url); CHECK_AND_RETURN_RET_LOG(engineFactory != nullptr, (int32_t)MSERR_CREATE_AVMETADATAHELPER_ENGINE_FAILED, "Failed to get engine factory"); avMetadataHelperEngine_ = engineFactory->CreateAVMetadataHelperEngine(); diff --git a/services/services/avmetadatahelper/server/avmetadatahelper_server.h b/services/services/avmetadatahelper/server/avmetadatahelper_server.h index cb7f282de..5bc9ce463 100644 --- a/services/services/avmetadatahelper/server/avmetadatahelper_server.h +++ b/services/services/avmetadatahelper/server/avmetadatahelper_server.h @@ -48,6 +48,7 @@ private: void NotifyErrorCallback(int32_t code, const std::string msg); void NotifyInfoCallback(HelperOnInfoType type, int32_t extra); + int32_t appUid_; std::shared_ptr avMetadataHelperEngine_ = nullptr; std::mutex mutex_; std::unique_ptr uriHelper_; diff --git a/services/services/engine_intf/i_engine_factory.h b/services/services/engine_intf/i_engine_factory.h index ee9e77c38..d6077e1f5 100644 --- a/services/services/engine_intf/i_engine_factory.h +++ b/services/services/engine_intf/i_engine_factory.h @@ -45,9 +45,10 @@ public: }; virtual ~IEngineFactory() = default; - virtual int32_t Score(Scene scene, const std::string &uri = "") + virtual int32_t Score(Scene scene, const int32_t& appUid, const std::string &uri = "") { (void)scene; + (void)appUid; (void)uri; return 0; } diff --git a/services/services/factory/engine_factory_repo.cpp b/services/services/factory/engine_factory_repo.cpp index bd7009a3c..8cf9c3454 100644 --- a/services/services/factory/engine_factory_repo.cpp +++ b/services/services/factory/engine_factory_repo.cpp @@ -20,7 +20,7 @@ #include "directory_ex.h" #include "media_errors.h" #include "media_log.h" -#include "parameter.h" +#include "media_utils.h" namespace { static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "EngineFactoryRepo"}; @@ -112,7 +112,7 @@ int32_t EngineFactoryRepo::LoadGstreamerEngine() return MSERR_OK; } -int32_t EngineFactoryRepo::LoadHistreamerEngine() +int32_t EngineFactoryRepo::LoadHistreamerEngine(const int32_t& appUid) { std::unique_lock lock(mutex_); if (isLoadHistreamer_) { @@ -120,9 +120,12 @@ int32_t EngineFactoryRepo::LoadHistreamerEngine() return MSERR_OK; } - char useHistreamer[10] = {0}; // 10 for system parameter usage - auto res = GetParameter("debug.media_service.histreamer", "0", useHistreamer, sizeof(useHistreamer)); - if (res == 1 && useHistreamer[0] == '1') { + std::string bundleName = GetClientBundleName(appUid); + bool isEnableHistreamer = IsEnableHiStreamer(bundleName); + MEDIA_LOGI("try to LoadHistreamerEngine, appUid = %{public}d, bundleName = %{public}s," + "isEnableHistreamer = %{public}d", appUid, bundleName.c_str(), isEnableHistreamer); + if (isEnableHistreamer) { + MEDIA_LOGI("LoadHistreamerEngine succeed!"); std::vector allFiles; GetDirFiles(MEDIA_ENGINE_LIB_PATH, allFiles); for (auto &file : allFiles) { @@ -141,10 +144,10 @@ int32_t EngineFactoryRepo::LoadHistreamerEngine() } std::shared_ptr EngineFactoryRepo::GetEngineFactory( - IEngineFactory::Scene scene, const std::string &uri) + IEngineFactory::Scene scene, const int32_t& appUid, const std::string &uri) { (void)LoadGstreamerEngine(); - (void)LoadHistreamerEngine(); + (void)LoadHistreamerEngine(appUid); if (factorys_.empty()) { isLoadGstreamer_ = false; @@ -156,7 +159,7 @@ std::shared_ptr EngineFactoryRepo::GetEngineFactory( int32_t maxScore = std::numeric_limits::min(); std::shared_ptr target = nullptr; for (auto &factory : factorys_) { - int32_t score = factory->Score(scene, uri); + int32_t score = factory->Score(scene, appUid, uri); if (maxScore < score) { maxScore = score; target = factory; @@ -166,7 +169,8 @@ std::shared_ptr EngineFactoryRepo::GetEngineFactory( target = factorys_.front(); } - MEDIA_LOGI("Selected factory: 0x%{public}06" PRIXPTR ", score: %{public}d", FAKE_POINTER(target.get()), maxScore); + MEDIA_LOGI("Selected factory: 0x%{public}06" PRIXPTR ", score: %{public}d," + "appUid: %{public}d", FAKE_POINTER(target.get()), maxScore, appUid); return target; } } // namespace Media diff --git a/services/services/factory/engine_factory_repo.h b/services/services/factory/engine_factory_repo.h index 53791276c..82a4ff432 100644 --- a/services/services/factory/engine_factory_repo.h +++ b/services/services/factory/engine_factory_repo.h @@ -26,13 +26,14 @@ namespace Media { class EngineFactoryRepo { public: static EngineFactoryRepo &Instance(); - std::shared_ptr GetEngineFactory(IEngineFactory::Scene scene, const std::string &uri = ""); + std::shared_ptr GetEngineFactory(IEngineFactory::Scene scene, const int32_t& appUid, + const std::string &uri = ""); private: EngineFactoryRepo() = default; ~EngineFactoryRepo(); int32_t LoadGstreamerEngine(); - int32_t LoadHistreamerEngine(); + int32_t LoadHistreamerEngine(const int32_t& appUid); __attribute__((no_sanitize("cfi"))) int32_t LoadLib(const std::string &libPath); __attribute__((no_sanitize("cfi"))) void UnloadLib(); diff --git a/services/services/media_data_source/ipc/i_standard_media_data_source.h b/services/services/media_data_source/ipc/i_standard_media_data_source.h index 61aecd83a..ca5ef6015 100644 --- a/services/services/media_data_source/ipc/i_standard_media_data_source.h +++ b/services/services/media_data_source/ipc/i_standard_media_data_source.h @@ -28,7 +28,8 @@ namespace Media { class IStandardMediaDataSource : public IRemoteBroker { public: virtual ~IStandardMediaDataSource() = default; - virtual int32_t ReadAt(const std::shared_ptr &mem, uint32_t length, int64_t pos = -1) = 0; + virtual int32_t ReadAt(const std::shared_ptr &mem, uint32_t length, int64_t pos = -1, + bool isHistreamer = false) = 0; virtual int32_t GetSize(int64_t &size) = 0; enum class ListenerMsg : uint8_t { diff --git a/services/services/media_data_source/ipc/media_data_source_proxy.cpp b/services/services/media_data_source/ipc/media_data_source_proxy.cpp index 9a629c36d..dcb607304 100644 --- a/services/services/media_data_source/ipc/media_data_source_proxy.cpp +++ b/services/services/media_data_source/ipc/media_data_source_proxy.cpp @@ -20,7 +20,6 @@ #include "avdatasrcmemory.h" #include "avsharedmemory_ipc.h" #include "meta/any.h" -#include "parameter.h" namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "MediaDataSourceProxy"}; @@ -78,7 +77,7 @@ int32_t MediaDataCallback::ReadAt(const std::shared_ptr &mem, ui MEDIA_LOGD("ReadAt in"); CHECK_AND_RETURN_RET_LOG(callbackProxy_ != nullptr, SOURCE_ERROR_IO, "callbackProxy_ is nullptr"); CHECK_AND_RETURN_RET_LOG(mem != nullptr, MSERR_NO_MEMORY, "memory is nullptr"); - return callbackProxy_->ReadAt(mem, length, pos); + return callbackProxy_->ReadAt(mem, length, pos, false); } int32_t MediaDataCallback::ReadAt(int64_t pos, uint32_t length, const std::shared_ptr &mem) @@ -86,7 +85,7 @@ int32_t MediaDataCallback::ReadAt(int64_t pos, uint32_t length, const std::share MEDIA_LOGD("ReadAt in"); CHECK_AND_RETURN_RET_LOG(callbackProxy_ != nullptr, SOURCE_ERROR_IO, "callbackProxy_ is nullptr"); CHECK_AND_RETURN_RET_LOG(mem != nullptr, MSERR_NO_MEMORY, "memory is nullptr"); - return callbackProxy_->ReadAt(mem, length, pos); + return callbackProxy_->ReadAt(mem, length, pos, true); } int32_t MediaDataCallback::ReadAt(uint32_t length, const std::shared_ptr &mem) @@ -94,7 +93,7 @@ int32_t MediaDataCallback::ReadAt(uint32_t length, const std::shared_ptrReadAt(mem, length, 0); + return callbackProxy_->ReadAt(mem, length, 0, true); } int32_t MediaDataCallback::GetSize(int64_t &size) @@ -114,7 +113,8 @@ MediaDataSourceProxy::~MediaDataSourceProxy() MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this)); } -int32_t MediaDataSourceProxy::ReadAt(const std::shared_ptr &mem, uint32_t length, int64_t pos) +int32_t MediaDataSourceProxy::ReadAt(const std::shared_ptr &mem, uint32_t length, int64_t pos, + bool isHistreamer) { MEDIA_LOGD("ReadAt in"); CHECK_AND_RETURN_RET_LOG(mem != nullptr, MSERR_NO_MEMORY, "mem is nullptr"); @@ -132,9 +132,7 @@ int32_t MediaDataSourceProxy::ReadAt(const std::shared_ptr &mem, CHECK_AND_RETURN_RET_LOG(BufferCache_ != nullptr, MSERR_NO_MEMORY, "Failed to create BufferCache_!"); uint32_t offset = 0; - char useHistreamer[10] = {0}; // 10 for system parameter usage - auto res = GetParameter("debug.media_service.histreamer", "0", useHistreamer, sizeof(useHistreamer)); - if (res != 1 || useHistreamer[0] != '1') { + if (!isHistreamer) { offset = std::static_pointer_cast(mem)->GetOffset(); } MEDIA_LOGD("offset is %{public}u", offset); diff --git a/services/services/media_data_source/ipc/media_data_source_proxy.h b/services/services/media_data_source/ipc/media_data_source_proxy.h index 1b6fd39a5..f3aa5936e 100644 --- a/services/services/media_data_source/ipc/media_data_source_proxy.h +++ b/services/services/media_data_source/ipc/media_data_source_proxy.h @@ -43,7 +43,8 @@ public: explicit MediaDataSourceProxy(const sptr &impl); virtual ~MediaDataSourceProxy(); - int32_t ReadAt(const std::shared_ptr &mem, uint32_t length, int64_t pos = -1) override; + int32_t ReadAt(const std::shared_ptr &mem, uint32_t length, int64_t pos = -1, + bool isHistreamer = false) override; int32_t GetSize(int64_t &size) override; private: diff --git a/services/services/media_data_source/ipc/media_data_source_stub.cpp b/services/services/media_data_source/ipc/media_data_source_stub.cpp index 52793fb0c..82c9e1475 100644 --- a/services/services/media_data_source/ipc/media_data_source_stub.cpp +++ b/services/services/media_data_source/ipc/media_data_source_stub.cpp @@ -105,9 +105,10 @@ int MediaDataSourceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Mes } } -int32_t MediaDataSourceStub::ReadAt(const std::shared_ptr &mem, uint32_t length, int64_t pos) +int32_t MediaDataSourceStub::ReadAt(const std::shared_ptr &mem, uint32_t length, int64_t pos, + bool isHiStreamer) { - MEDIA_LOGD("ReadAt in"); + MEDIA_LOGD("ReadAt in isHiStreamer = %{public}d", isHiStreamer); CHECK_AND_RETURN_RET_LOG(dataSrc_ != nullptr, SOURCE_ERROR_IO, "dataSrc_ is nullptr"); CHECK_AND_RETURN_RET_LOG(mem != nullptr, MSERR_NO_MEMORY, "mem is nullptr"); return dataSrc_->ReadAt(mem, length, pos); diff --git a/services/services/media_data_source/ipc/media_data_source_stub.h b/services/services/media_data_source/ipc/media_data_source_stub.h index d68da1f45..1118dc882 100644 --- a/services/services/media_data_source/ipc/media_data_source_stub.h +++ b/services/services/media_data_source/ipc/media_data_source_stub.h @@ -28,7 +28,8 @@ public: virtual ~MediaDataSourceStub(); int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - int32_t ReadAt(const std::shared_ptr &mem, uint32_t length, int64_t pos = -1) override; + int32_t ReadAt(const std::shared_ptr &mem, uint32_t length, int64_t pos = -1, + bool isHistreamer = false) override; int32_t GetSize(int64_t &size) override; private: diff --git a/services/services/player/server/player_server.cpp b/services/services/player/server/player_server.cpp index 60e0e329c..62bfe91df 100755 --- a/services/services/player/server/player_server.cpp +++ b/services/services/player/server/player_server.cpp @@ -207,7 +207,8 @@ int32_t PlayerServer::InitPlayEngine(const std::string &url) int32_t ret = taskMgr_.Init(); CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "task mgr init failed"); MEDIA_LOGI("current url is : %{public}s", url.c_str()); - auto engineFactory = EngineFactoryRepo::Instance().GetEngineFactory(IEngineFactory::Scene::SCENE_PLAYBACK, url); + auto engineFactory = EngineFactoryRepo::Instance().GetEngineFactory( + IEngineFactory::Scene::SCENE_PLAYBACK, appUid_, url); CHECK_AND_RETURN_RET_LOG(engineFactory != nullptr, MSERR_CREATE_PLAYER_ENGINE_FAILED, "failed to get engine factory"); playerEngine_ = engineFactory->CreatePlayerEngine(appUid_, appPid_, appTokenId_); diff --git a/services/services/recorder/server/recorder_server.cpp b/services/services/recorder/server/recorder_server.cpp index 6b971856b..d013931d3 100644 --- a/services/services/recorder/server/recorder_server.cpp +++ b/services/services/recorder/server/recorder_server.cpp @@ -85,7 +85,8 @@ int32_t RecorderServer::Init() int32_t appPid = IPCSkeleton::GetCallingPid(); auto task = std::make_shared>([&, this] { - auto engineFactory = EngineFactoryRepo::Instance().GetEngineFactory(IEngineFactory::Scene::SCENE_RECORDER); + auto engineFactory = EngineFactoryRepo::Instance().GetEngineFactory( + IEngineFactory::Scene::SCENE_RECORDER, appUid); CHECK_AND_RETURN_RET_LOG(engineFactory != nullptr, MSERR_CREATE_REC_ENGINE_FAILED, "failed to get factory"); recorderEngine_ = engineFactory->CreateRecorderEngine(appUid, appPid, tokenId, fullTokenId); diff --git a/services/utils/BUILD.gn b/services/utils/BUILD.gn index 2e668a41f..0383dc06d 100644 --- a/services/utils/BUILD.gn +++ b/services/utils/BUILD.gn @@ -78,6 +78,9 @@ ohos_shared_library("media_service_utils") { external_deps = [ "access_token:libaccesstoken_sdk", + "access_token:libprivacy_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "c_utils:utils", "graphic_surface:surface", "hicollie:libhicollie", @@ -88,6 +91,7 @@ ohos_shared_library("media_service_utils") { "ipc:ipc_single", "media_foundation:media_foundation", "qos_manager:qos", + "samgr:samgr_proxy", ] subsystem_name = "multimedia" diff --git a/services/utils/include/media_utils.h b/services/utils/include/media_utils.h index 27755a164..978cbadb5 100644 --- a/services/utils/include/media_utils.h +++ b/services/utils/include/media_utils.h @@ -33,6 +33,8 @@ enum class PlayerStateId { namespace OHOS { namespace Media { + bool __attribute__((visibility("default"))) IsEnableHiStreamer(const std::string& clientBundleName); + std::string __attribute__((visibility("default"))) GetClientBundleName(int32_t uid); int __attribute__((visibility("default"))) TransStatus(Status status); PlayerStates __attribute__((visibility("default"))) TransStateId2PlayerState(PlayerStateId state); Plugins::SeekMode __attribute__((visibility("default"))) Transform2SeekMode(PlayerSeekMode mode); diff --git a/services/utils/media_utils.cpp b/services/utils/media_utils.cpp index 0bfbe7243..f2f39dfa2 100644 --- a/services/utils/media_utils.cpp +++ b/services/utils/media_utils.cpp @@ -17,6 +17,11 @@ #include #include "common/log.h" #include "media_utils.h" +#include "iservice_registry.h" +#include "bundle_mgr_interface.h" +#include "system_ability_definition.h" +#include +#include "parameter.h" namespace OHOS { namespace Media { @@ -41,8 +46,60 @@ const std::array, 5> PLAY_RATE_REFS = { std::make_pair(PlaybackRateMode::SPEED_FORWARD_1_75_X, 1.75), std::make_pair(PlaybackRateMode::SPEED_FORWARD_2_00_X, 2.00), }; + +const std::unordered_set HST_ENABLE_BUNDLE_LIST = { + "com.huawei.hmsapp.music", + "com.huawei.hmsapp.himovie", + "com.huawei.hmos.photos", + "com.ohos.medialibrary.medialibrarydata", +}; } // namespace +bool __attribute__((visibility("default"))) IsEnableHiStreamer(const std::string& clientBundleName) +{ + char useHistreamer[10] = {0}; // 10 for system parameter usage + auto res = GetParameter("debug.media_service.histreamer", "0", useHistreamer, sizeof(useHistreamer)); + bool enableHiStreamerBySwitch = (res == 1 && useHistreamer[0] == '1'); + bool enableHiStreamerByBundleList = (HST_ENABLE_BUNDLE_LIST.count(clientBundleName) > 0); + + MEDIA_LOG_I("IsEnableHiStreamer enableHiStreamerBySwitch = %{public}d, enableHiStreamerByBundleList = %{public}d", + enableHiStreamerBySwitch, enableHiStreamerByBundleList); + + return enableHiStreamerByBundleList || enableHiStreamerBySwitch; +} + +std::string __attribute__((visibility("default"))) GetClientBundleName(int32_t uid) +{ + std::string bundleName = ""; + auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + MEDIA_LOG_E("Get ability manager failed"); + return bundleName; + } + + sptr object = samgr->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + if (object == nullptr) { + MEDIA_LOG_E("object is NULL."); + return bundleName; + } + + sptr bms = iface_cast(object); + if (bms == nullptr) { + MEDIA_LOG_E("bundle manager service is NULL."); + return bundleName; + } + + auto result = bms->GetNameForUid(uid, bundleName); + if (result != ERR_OK) { + MEDIA_LOG_E("GetBundleNameForUid fail"); + return ""; + } + MEDIA_LOG_I("bundle name is %{public}s ", bundleName.c_str()); + + return bundleName; +} + + int __attribute__((visibility("default"))) TransStatus(Status status) { for (const auto& errPair : g_statusPair) { -- Gitee