From 5778ab5db0afd2a1618ed8b8bf855d06cea39553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A6=E5=9B=BD=E5=BA=86?= Date: Sun, 28 Apr 2024 10:43:15 +0800 Subject: [PATCH 1/3] =?UTF-8?q?param=E4=B8=8A=E6=8A=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韦国庆 --- .../src/distributed_camera_source_proxy.cpp | 7 +-- .../handler/src/dcamera_handler.cpp | 3 +- services/cameraservice/sourceservice/BUILD.gn | 4 ++ .../distributed_camera_source_service.h | 1 + .../distributed_camera_source_service.cpp | 60 +++++++++++++++++-- .../distributed_camera_source_stub.cpp | 6 +- .../dcamera_source_dev.cpp | 2 +- 7 files changed, 65 insertions(+), 18 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/camera_source/src/distributed_camera_source_proxy.cpp b/interfaces/inner_kits/native_cpp/camera_source/src/distributed_camera_source_proxy.cpp index bdd819c4..bcbc124a 100644 --- a/interfaces/inner_kits/native_cpp/camera_source/src/distributed_camera_source_proxy.cpp +++ b/interfaces/inner_kits/native_cpp/camera_source/src/distributed_camera_source_proxy.cpp @@ -103,8 +103,7 @@ int32_t DistributedCameraSourceProxy::RegisterDistributedHardware(const std::str } if (!data.WriteString(devId) || !data.WriteString(dhId) || !data.WriteString(reqId) || - !data.WriteString(param.sinkVersion) || !data.WriteString(param.sinkAttrs) || - !data.WriteString(param.sourceVersion) || !data.WriteString(param.sourceAttrs)) { + !data.WriteString(param.sinkVersion) || !data.WriteString(param.sinkAttrs)) { DHLOGE("write params failed"); return DCAMERA_BAD_VALUE; } @@ -128,9 +127,7 @@ bool DistributedCameraSourceProxy::CheckRegParams(const std::string& devId, cons } if (param.sinkVersion.empty() || param.sinkVersion.size() > PARAM_MAX_SIZE || - param.sinkAttrs.empty() || param.sinkAttrs.size() > PARAM_MAX_SIZE || - param.sourceVersion.empty() || param.sourceVersion.size() > PARAM_MAX_SIZE || - param.sourceAttrs.empty() || param.sourceAttrs.size() > PARAM_MAX_SIZE) { + param.sinkAttrs.empty() || param.sinkAttrs.size() > PARAM_MAX_SIZE) { DHLOGE("param is invalid"); return false; } diff --git a/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp b/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp index aec4b6b6..0d8c13f4 100644 --- a/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp +++ b/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp @@ -68,8 +68,7 @@ std::vector DCameraHandler::Query() return itemList; } for (auto& info : cameraList) { - if ((info->GetConnectionType() != CameraStandard::ConnectionType::CAMERA_CONNECTION_BUILT_IN) && - (info->GetConnectionType() != CameraStandard::ConnectionType::CAMERA_CONNECTION_USB_PLUGIN)) { + if ((info->GetConnectionType() != CameraStandard::ConnectionType::CAMERA_CONNECTION_BUILT_IN)) { DHLOGI("connection type: %{public}d", info->GetConnectionType()); continue; } diff --git a/services/cameraservice/sourceservice/BUILD.gn b/services/cameraservice/sourceservice/BUILD.gn index a0444f33..e1103bac 100644 --- a/services/cameraservice/sourceservice/BUILD.gn +++ b/services/cameraservice/sourceservice/BUILD.gn @@ -48,6 +48,7 @@ ohos_shared_library("distributed_camera_source") { "${innerkits_path}/native_cpp/camera_source/include/callback", "${services_path}/cameraservice/base/include", "${services_path}/channel/include", + "${services_path}/cameraservice/cameraoperator/handler/include", "${services_path}/data_process/include/eventbus", "${services_path}/data_process/include/interfaces", "${services_path}/data_process/include/pipeline", @@ -97,6 +98,7 @@ ohos_shared_library("distributed_camera_source") { deps = [ "${common_path}:distributed_camera_utils", "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", + "${services_path}/cameraservice/cameraoperator/handler:distributed_camera_handler", "${services_path}/channel:distributed_camera_channel", "${services_path}/data_process:distributed_camera_data_process", ] @@ -118,8 +120,10 @@ ohos_shared_library("distributed_camera_source") { external_deps = [ "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", + "av_codec:av_codec_client", "cJSON:cjson", "c_utils:utils", + "camera_framework:camera_framework", "distributed_hardware_fwk:distributed_av_receiver", "distributed_hardware_fwk:distributedhardwareutils", "distributed_hardware_fwk:libdhfwk_sdk", diff --git a/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h b/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h index fc175368..4953c36c 100644 --- a/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h +++ b/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h @@ -65,6 +65,7 @@ private: bool Init(); int32_t LoadDCameraHDF(); int32_t UnLoadCameraHDF(); + std::string GetCodecInfo(); bool registerToService_ = false; DCameraServiceState state_ = DCameraServiceState::DCAMERA_SRV_STATE_NOT_START; diff --git a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp index 36b94f6b..18305e5c 100644 --- a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp +++ b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp @@ -24,6 +24,8 @@ #include "xcollie/watchdog.h" #include "anonymous_string.h" +#include "avcodec_info.h" +#include "avcodec_list.h" #include "dcamera_hdf_operate.h" #include "dcamera_hisysevent_adapter.h" #include "dcamera_hitrace_adapter.h" @@ -32,6 +34,7 @@ #include "dcamera_utils_tools.h" #include "distributed_camera_errno.h" #include "distributed_hardware_log.h" +#include "dcamera_handler.h" namespace OHOS { namespace DistributedHardware { @@ -140,6 +143,50 @@ int32_t DistributedCameraSourceService::ReleaseSource() return DCAMERA_OK; } +std::string DistributedCameraSourceService::GetCodecInfo() +{ + DHLOGI("Create avCodecList start"); + std::string sourceAttrs = ""; + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + return sourceAttrs; + } + std::shared_ptr avCodecList = MediaAVCodec::AVCodecListFactory::CreateAVCodecList(); + if (avCodecList == nullptr) { + DHLOGI("Create avCodecList failed"); + cJSON_Delete(root); + return sourceAttrs; + } + const std::vector encoderName = {std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC), + std::string(MediaAVCodec::CodecMimeType::VIDEO_HEVC)}; + cJSON *array = cJSON_CreateArray(); + if (array == nullptr) { + DHLOGI("Create arrray failed"); + cJSON_Delete(root); + return sourceAttrs; + } + for (auto &coder : encoderName) { + MediaAVCodec::CapabilityData *capData = avCodecList->GetCapability(coder, true, + MediaAVCodec::AVCodecCategory::AVCODEC_HARDWARE); + if (capData == nullptr) { + continue; + } + std::string mimeType = capData->mimeType; + cJSON_AddItemToArray(array, cJSON_CreateString(mimeType.c_str())); + DHLOGI("codec name: %s, mimeType: %s", coder.c_str(), mimeType.c_str()); + } + cJSON_AddItemToObject(root, CAMERA_CODEC_TYPE_KEY.c_str(), array); + char *jsonstr = cJSON_Print(root); + if (jsonstr == nullptr) { + cJSON_Delete(root); + return sourceAttrs; + } + sourceAttrs = jsonstr; + cJSON_free(jsonstr); + cJSON_Delete(root); + return sourceAttrs; +} + int32_t DistributedCameraSourceService::RegisterDistributedHardware(const std::string& devId, const std::string& dhId, const std::string& reqId, const EnableParam& param) { @@ -149,12 +196,15 @@ int32_t DistributedCameraSourceService::RegisterDistributedHardware(const std::s DHLOGE("cameras exceed the upper limit"); return DCAMERA_BAD_VALUE; } + EnableParam params = const_cast(param); + params.sourceAttrs = GetCodecInfo(); + DHLOGI("RegisterDistributedHardware sourceAttrs: %{public}s.", params.sourceAttrs.c_str()); DCameraIndex camIndex(devId, dhId); int32_t ret = DCAMERA_OK; std::shared_ptr camDev = GetCamDevByIndex(camIndex); if (camDev == nullptr) { DHLOGI("new dev devId: %{public}s, dhId: %{public}s, sinkVersion: %{public}s", - GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), param.sinkVersion.c_str()); + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), params.sinkVersion.c_str()); camDev = std::make_shared(devId, dhId, listener_); ret = camDev->InitDCameraSourceDev(); if (ret != DCAMERA_OK) { @@ -165,19 +215,19 @@ int32_t DistributedCameraSourceService::RegisterDistributedHardware(const std::s CamDevInsert(camIndex, camDev); } else { DHLOGE("RegisterDistributedHardware exist devId: %{public}s, dhId: %{public}s, sinkVersion: %{public}s", - GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), param.sinkVersion.c_str()); + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), params.sinkVersion.c_str()); return DCAMERA_ALREADY_EXISTS; } - ret = camDev->RegisterDistributedHardware(devId, dhId, reqId, param); + ret = camDev->RegisterDistributedHardware(devId, dhId, reqId, params); if (ret != DCAMERA_OK) { DHLOGE("RegisterDistributedHardware failed, ret: %{public}d", ret); - ReportRegisterCameraFail(DCAMERA_REGISTER_FAIL, GetAnonyString(devId), dhId, param.sinkVersion, + ReportRegisterCameraFail(DCAMERA_REGISTER_FAIL, GetAnonyString(devId), dhId, params.sinkVersion, "dcamera source RegisterDistributedHardware fail."); CamDevErase(camIndex); } DHLOGI("RegisterDistributedHardware end devId: %{public}s, dhId: %{public}s, sinkVersion: %{public}s", - GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), param.sinkVersion.c_str()); + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), params.sinkVersion.c_str()); return ret; } diff --git a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_stub.cpp b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_stub.cpp index b8d99155..e93b6e97 100644 --- a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_stub.cpp +++ b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_stub.cpp @@ -138,8 +138,6 @@ int32_t DistributedCameraSourceStub::RegisterDistributedHardwareInner(MessagePar EnableParam params; params.sinkVersion = data.ReadString(); params.sinkAttrs = data.ReadString(); - params.sourceVersion = data.ReadString(); - params.sourceAttrs = data.ReadString(); if (!CheckRegParams(devId, dhId, reqId, params)) { DHLOGE("input is invalid"); ret = DCAMERA_BAD_VALUE; @@ -166,9 +164,7 @@ bool DistributedCameraSourceStub::CheckRegParams(const std::string& devId, const } if (param.sinkVersion.empty() || param.sinkVersion.size() > PARAM_MAX_SIZE || - param.sinkAttrs.empty() || param.sinkAttrs.size() > PARAM_MAX_SIZE || - param.sourceVersion.empty() || param.sourceVersion.size() > PARAM_MAX_SIZE || - param.sourceAttrs.empty() || param.sourceAttrs.size() > PARAM_MAX_SIZE) { + param.sinkAttrs.empty() || param.sinkAttrs.size() > PARAM_MAX_SIZE) { DHLOGE("param is invalid"); return false; } diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp index 812d258e..fe344ab2 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp @@ -293,7 +293,7 @@ int32_t DCameraSourceDev::ParseEnableParam(std::shared_ptr& return DCAMERA_BAD_VALUE; } cJSON_AddItemToObject(abilityRootValue, "SinkAbility", sinkRootValue); - cJSON_AddItemToObject(abilityRootValue, "SourceAbility", srcRootValue); + cJSON_AddItemToObject(abilityRootValue, "SourceCodec", srcRootValue); char *jsonstr = cJSON_Print(abilityRootValue); if (jsonstr == nullptr) { cJSON_Delete(abilityRootValue); -- Gitee From 8cbc5dcc6e8e6e11f20ef5f967214960aa14d7e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A6=E5=9B=BD=E5=BA=86?= Date: Wed, 8 May 2024 01:20:17 +0000 Subject: [PATCH 2/3] update log MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韦国庆 --- .../src/distributedcamera/distributed_camera_source_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp index 18305e5c..c3eb3186 100644 --- a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp +++ b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp @@ -173,7 +173,7 @@ std::string DistributedCameraSourceService::GetCodecInfo() } std::string mimeType = capData->mimeType; cJSON_AddItemToArray(array, cJSON_CreateString(mimeType.c_str())); - DHLOGI("codec name: %s, mimeType: %s", coder.c_str(), mimeType.c_str()); + DHLOGI("codec name: %{public}s, mimeType: %{public}s", coder.c_str(), mimeType.c_str()); } cJSON_AddItemToObject(root, CAMERA_CODEC_TYPE_KEY.c_str(), array); char *jsonstr = cJSON_Print(root); -- Gitee From ec72ea730b0e41d4a8ab6a5406f52f5181179a89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A6=E5=9B=BD=E5=BA=86?= Date: Wed, 8 May 2024 01:21:41 +0000 Subject: [PATCH 3/3] update log MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韦国庆 --- .../cameraoperator/handler/src/dcamera_handler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp b/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp index f8b1f418..da00df5c 100644 --- a/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp +++ b/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp @@ -189,7 +189,7 @@ int32_t DCameraHandler::CreateAVCodecList(cJSON *root) } std::string mimeType = capData->mimeType; cJSON_AddItemToArray(array, cJSON_CreateString(mimeType.c_str())); - DHLOGI("codec name: %s, mimeType: %s", coder.c_str(), mimeType.c_str()); + DHLOGI("codec name: %{public}s, mimeType: %{public}s", coder.c_str(), mimeType.c_str()); } return DCAMERA_OK; } @@ -312,7 +312,7 @@ void DCameraHandler::ProcessProfile(const DCStreamType type, std::map& profileList) { - DHLOGI("type: %d, size: %{public}zu", type, profileList.size()); + DHLOGI("type: %{public}d, size: %{public}zu", type, profileList.size()); std::set formatSet; cJSON* formatphotoObj = cJSON_CreateObject(); if (formatphotoObj == nullptr) { -- Gitee