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 bdd819c41827b8f50c9461945af9701dccac6a56..bcbc124a071b44c5bc35158c2f118d1202fe3ad4 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 9a43491f7c7f5c4cb92c96d2bda38299cca834dc..da00df5c5f383279c3a23408338e565caa75e4cd 100644 --- a/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp +++ b/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp @@ -90,8 +90,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; } @@ -190,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; } @@ -313,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) { diff --git a/services/cameraservice/sourceservice/BUILD.gn b/services/cameraservice/sourceservice/BUILD.gn index fcca268c6ef7e3844bb7bdeb55ab818491b01949..89c3da2ef653521c9cbf62b7ac0cb0c1fed7d8a3 100644 --- a/services/cameraservice/sourceservice/BUILD.gn +++ b/services/cameraservice/sourceservice/BUILD.gn @@ -47,6 +47,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", @@ -96,6 +97,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", ] @@ -117,8 +119,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 c0f4cb1d1361e4d8a883abccd06f6a0bc6a6b2ab..fc341c5719d9cf99e526f5a371bb5d191be95a2b 100644 --- a/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h +++ b/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h @@ -66,6 +66,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 0e31a9a0b42c22e49ec9bcab4b298d72dfaa68e5..c3eb318697b55146e8639284f36a300d1d3f8203 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: %{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); + 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) { @@ -163,17 +213,21 @@ int32_t DistributedCameraSourceService::RegisterDistributedHardware(const std::s return ret; } CamDevInsert(camIndex, camDev); + } else { + DHLOGE("RegisterDistributedHardware exist devId: %{public}s, dhId: %{public}s, sinkVersion: %{public}s", + 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 b8d991557b3b1a8fb201ed25a9c54770a386ab62..e93b6e973f5a89aa05b682be7020642d0a8b1531 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 89525c1636312e9b63bda143ea944d2821a8c431..4131d83e2ecdfc5147108faf9d0b8f60f993f4c2 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp @@ -373,7 +373,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);