diff --git a/services/cameraservice/cameraoperator/handler/BUILD.gn b/services/cameraservice/cameraoperator/handler/BUILD.gn index 607632975b5c7f128b097d932f42b00c217e12c8..203cd8dd4778e4cb982470848a7edbbeb14ffad1 100644 --- a/services/cameraservice/cameraoperator/handler/BUILD.gn +++ b/services/cameraservice/cameraoperator/handler/BUILD.gn @@ -47,13 +47,10 @@ ohos_shared_library("distributed_camera_handler") { "${services_path}/cameraservice/cameraoperator/client/include/callback", ] - sources = [ "${services_path}/cameraservice/cameraoperator/client/src/callback/dcamera_manager_callback.cpp" ] - - if (!distributed_camera_common) { - sources += [ "src/dcamera_handler.cpp" ] - } else { - sources += [ "src/dcamera_handler_common.cpp" ] - } + sources = [ + "${services_path}/cameraservice/cameraoperator/client/src/callback/dcamera_manager_callback.cpp", + "src/dcamera_handler.cpp", + ] deps = [ "${common_path}:distributed_camera_utils", diff --git a/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp b/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp deleted file mode 100644 index 9758d03510b55ddb13a3e76df3feed3dcf16fca1..0000000000000000000000000000000000000000 --- a/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp +++ /dev/null @@ -1,305 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "dcamera_handler.h" - -#include - -#include "anonymous_string.h" -#include "avcodec_info.h" -#include "avcodec_list.h" -#include "dcamera_manager_callback.h" -#include "dcamera_utils_tools.h" -#include "distributed_camera_constants.h" -#include "distributed_camera_errno.h" -#include "distributed_hardware_log.h" -#include "metadata_utils.h" - -namespace OHOS { -namespace DistributedHardware { -IMPLEMENT_SINGLE_INSTANCE(DCameraHandler); - -DCameraHandler::~DCameraHandler() -{ - DHLOGI("~DCameraHandler"); -} - -int32_t DCameraHandler::Initialize() -{ - DHLOGI("start"); - cameraManager_ = CameraStandard::CameraManager::GetInstance(); - if (cameraManager_ == nullptr) { - DHLOGE("cameraManager getInstance failed"); - return DCAMERA_INIT_ERR; - } - std::shared_ptr cameraMgrCallback = std::make_shared(); - cameraManager_->SetCallback(cameraMgrCallback); - DHLOGI("success"); - return DCAMERA_OK; -} - -std::vector DCameraHandler::Query() -{ - std::vector itemList; - std::vector> cameraList = cameraManager_->GetSupportedCameras(); - DHLOGI("get %d cameras", cameraList.size()); - if (cameraList.empty()) { - DHLOGE("no camera device"); - return itemList; - } - for (auto& info : cameraList) { - if (info->GetConnectionType() != CameraStandard::ConnectionType::CAMERA_CONNECTION_BUILT_IN) { - DHLOGI("connection type: %d", info->GetConnectionType()); - continue; - } - DHLOGI("get %s, position: %d, cameraType: %d", - GetAnonyString(info->GetID()).c_str(), info->GetPosition(), info->GetCameraType()); - DHItem item; - if (CreateDHItem(info, item) == DCAMERA_OK) { - itemList.emplace_back(item); - } - } - DHLOGI("success, get %d items", itemList.size()); - return itemList; -} - -std::map DCameraHandler::QueryExtraInfo() -{ - DHLOGI("enter"); - std::map extraInfo; - return extraInfo; -} - -bool DCameraHandler::IsSupportPlugin() -{ - DHLOGI("enter"); - return false; -} - -void DCameraHandler::RegisterPluginListener(std::shared_ptr listener) -{ - DHLOGI("enter"); - if (listener == nullptr) { - DHLOGE("DCameraHandler unregistering plugin listener"); - } - pluginListener_ = listener; -} - -void DCameraHandler::UnRegisterPluginListener() -{ - DHLOGI("enter"); - pluginListener_ = nullptr; -} - -std::vector DCameraHandler::GetCameras() -{ - std::vector cameras; - std::vector> cameraList = cameraManager_->GetSupportedCameras(); - DHLOGI("get %d cameras", cameraList.size()); - if (cameraList.empty()) { - DHLOGE("no camera device"); - return cameras; - } - for (auto& info : cameraList) { - sptr capability = cameraManager_->GetSupportedOutputCapability(info); - if (capability == nullptr) { - DHLOGI("get supported capability is null"); - continue; - } - if (info->GetConnectionType() != CameraStandard::ConnectionType::CAMERA_CONNECTION_BUILT_IN) { - DHLOGI("connection type: %d", info->GetConnectionType()); - continue; - } - DHLOGI("get %s, position: %d, cameraType: %d", - GetAnonyString(info->GetID()).c_str(), info->GetPosition(), info->GetCameraType()); - std::string dhId = CAMERA_ID_PREFIX + info->GetID(); - cameras.emplace_back(dhId); - } - DHLOGI("success, get %d items", cameras.size()); - return cameras; -} - -int32_t DCameraHandler::CreateDHItem(sptr& info, DHItem& item) -{ - std::string id = info->GetID(); - item.dhId = CAMERA_ID_PREFIX + id; - DHLOGI("camera id: %s", GetAnonyString(id).c_str()); - - Json::Value root; - root[CAMERA_PROTOCOL_VERSION_KEY] = Json::Value(CAMERA_PROTOCOL_VERSION_VALUE); - root[CAMERA_POSITION_KEY] = Json::Value(GetCameraPosition(info->GetPosition())); - root[CAMERA_CODEC_TYPE_KEY].append("video/mp4v-es"); - - std::shared_ptr avCodecList = Media::AVCodecListFactory::CreateAVCodecList(); - std::vector> videoCapsList = avCodecList->GetVideoEncoderCaps(); - for (auto& videoCaps : videoCapsList) { - std::shared_ptr codecInfo = videoCaps->GetCodecInfo(); - std::string name = codecInfo->GetName(); - std::string mimeType = codecInfo->GetMimeType(); - DHLOGI("codec name: %s, mimeType: %s", name.c_str(), mimeType.c_str()); - } - - sptr capability = cameraManager_->GetSupportedOutputCapability(info); - if (capability == nullptr) { - DHLOGI("get supported capability is null"); - return DCAMERA_BAD_VALUE; - } - std::vector photoProfiles = capability->GetPhotoProfiles(); - ConfigFormatAndResolution(SNAPSHOT_FRAME, root, photoProfiles); - - std::vector previewProfiles = capability->GetPreviewProfiles(); - ConfigFormatAndResolution(CONTINUOUS_FRAME, root, previewProfiles); - - sptr cameraInput = nullptr; - int rv = cameraManager_->CreateCameraInput(info, &cameraInput); - if (rv != DCAMERA_OK) { - DHLOGE("create cameraInput failed"); - return DCAMERA_BAD_VALUE; - } - - std::hash h; - std::string abilityString = cameraInput->GetCameraSettings(); - DHLOGI("abilityString hash: %zu, length: %zu", h(abilityString), abilityString.length()); - - std::string encodeString = Base64Encode(reinterpret_cast(abilityString.c_str()), - abilityString.length()); - DHLOGI("encodeString hash: %zu, length: %zu", h(encodeString), encodeString.length()); - root[CAMERA_METADATA_KEY] = Json::Value(encodeString); - - item.attrs = root.toStyledString(); - if (cameraInput->Release() != DCAMERA_OK) { - DHLOGE("cameraInput Release failed"); - } - return DCAMERA_OK; -} - -std::string DCameraHandler::GetCameraPosition(CameraStandard::CameraPosition position) -{ - DHLOGI("position: %d", position); - std::string ret = ""; - switch (position) { - case CameraStandard::CameraPosition::CAMERA_POSITION_BACK: { - ret = CAMERA_POSITION_BACK; - break; - } - case CameraStandard::CameraPosition::CAMERA_POSITION_FRONT: { - ret = CAMERA_POSITION_FRONT; - break; - } - case CameraStandard::CameraPosition::CAMERA_POSITION_UNSPECIFIED: { - ret = CAMERA_POSITION_UNSPECIFIED; - break; - } - default: { - DHLOGE("unknown camera position"); - break; - } - } - DHLOGI("success ret: %s", ret.c_str()); - return ret; -} - -void DCameraHandler::ConfigFormatAndResolution(const DCStreamType type, Json::Value& root, - std::vector& profileList) -{ - DHLOGI("type: %d, size: %d", type, profileList.size()); - std::set formatSet; - for (auto& profile : profileList) { - CameraStandard::CameraFormat format = profile.GetCameraFormat(); - CameraStandard::Size picSize = profile.GetSize(); - int32_t dformat = CovertToDcameraFormat(format); - formatSet.insert(dformat); - DHLOGI("width: %d, height: %d, format: %d", picSize.width, picSize.height, dformat); - std::string formatName = std::to_string(dformat); - if (IsValid(type, picSize)) { - std::string resolutionValue = std::to_string(picSize.width) + "*" + std::to_string(picSize.height); - if (type == SNAPSHOT_FRAME) { - root[CAMERA_FORMAT_PHOTO][CAMERA_RESOLUTION_KEY][formatName].append(resolutionValue); - } else if (type == CONTINUOUS_FRAME) { - root[CAMERA_FORMAT_PREVIEW][CAMERA_RESOLUTION_KEY][formatName].append(resolutionValue); - root[CAMERA_FORMAT_VIDEO][CAMERA_RESOLUTION_KEY][formatName].append(resolutionValue); - } - } - } - - for (auto format : formatSet) { - if (type == SNAPSHOT_FRAME) { - root[CAMERA_FORMAT_PHOTO][CAMERA_FORMAT_KEY].append(format); - } else if (type == CONTINUOUS_FRAME) { - root[CAMERA_FORMAT_PREVIEW][CAMERA_FORMAT_KEY].append(format); - root[CAMERA_FORMAT_VIDEO][CAMERA_FORMAT_KEY].append(format); - } - } -} - -int32_t DCameraHandler::CovertToDcameraFormat(CameraStandard::CameraFormat format) -{ - DHLOGI("format: %d", format); - int32_t ret = -1; - switch (format) { - case CameraStandard::CameraFormat::CAMERA_FORMAT_RGBA_8888: - ret = camera_format_t::OHOS_CAMERA_FORMAT_RGBA_8888; - break; - case CameraStandard::CameraFormat::CAMERA_FORMAT_YCBCR_420_888: - ret = camera_format_t::OHOS_CAMERA_FORMAT_YCBCR_420_888; - break; - case CameraStandard::CameraFormat::CAMERA_FORMAT_YUV_420_SP: - ret = camera_format_t::OHOS_CAMERA_FORMAT_YCRCB_420_SP; - break; - case CameraStandard::CameraFormat::CAMERA_FORMAT_JPEG: - ret = camera_format_t::OHOS_CAMERA_FORMAT_JPEG; - break; - default: - DHLOGE("invalid camera format"); - break; - } - return ret; -} - -bool DCameraHandler::IsValid(const DCStreamType type, const CameraStandard::Size& size) -{ - bool ret = false; - switch (type) { - case CONTINUOUS_FRAME: { - ret = (size.width >= RESOLUTION_MIN_WIDTH) && - (size.height >= RESOLUTION_MIN_HEIGHT) && - (size.width <= RESOLUTION_MAX_WIDTH_CONTINUOUS) && - (size.height <= RESOLUTION_MAX_HEIGHT_CONTINUOUS); - break; - } - case SNAPSHOT_FRAME: { - uint64_t dcResolution = static_cast(size.width * size.width); - uint64_t dcMaxResolution = static_cast(RESOLUTION_MAX_WIDTH_SNAPSHOT * - RESOLUTION_MAX_HEIGHT_SNAPSHOT); - uint64_t dcMinResolution = static_cast(RESOLUTION_MIN_WIDTH * - RESOLUTION_MIN_HEIGHT); - ret = (dcResolution >= dcMinResolution) && (dcResolution <= dcMaxResolution); - break; - } - default: { - DHLOGE("unknown stream type"); - break; - } - } - return ret; -} - -IHardwareHandler* GetHardwareHandler() -{ - DHLOGI("DCameraHandler::GetHardwareHandler"); - return &DCameraHandler::GetInstance(); -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_dev.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_dev.h index fce546f046f19da3ad401f49926467eb0acc4587..0b07bc8b924655d8e1c689f7af219e5c1b53a18d 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_dev.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_dev.h @@ -78,6 +78,7 @@ private: void NotifyRegisterResult(DCAMERA_EVENT eventType, DCameraSourceEvent& event, int32_t result); void NotifyHalResult(DCAMERA_EVENT eventType, DCameraSourceEvent& event, int32_t result); void HitraceAndHisyseventImpl(std::vector>& captureInfos); + int32_t ParseEnableParam(std::shared_ptr& param, std::string& ability); private: std::string devId_; diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp index ba11a523a96ff308fa45df536ebe7a8fb25c9eb4..e9f6f74f98d86872ccaee1945f4fe642ac015b69 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp @@ -251,7 +251,12 @@ int32_t DCameraSourceDev::Register(std::shared_ptr& param) DHBase dhBase; dhBase.deviceId_ = param->devId_; dhBase.dhId_ = param->dhId_; - int32_t retHdi = camHdiProvider->EnableDCameraDevice(dhBase, param->sinkParam_, hdiCallback_); + std::string ability; + ret = ParseEnableParam(param, ability); + if (ret != DCAMERA_OK) { + DHLOGE("Parsing param failed."); + } + int32_t retHdi = camHdiProvider->EnableDCameraDevice(dhBase, ability, hdiCallback_); DHLOGI("DCameraSourceDev Execute Register register hal, ret: %d, devId: %s dhId: %s", retHdi, GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); if (retHdi != SUCCESS) { @@ -262,6 +267,32 @@ int32_t DCameraSourceDev::Register(std::shared_ptr& param) return DCAMERA_OK; } +int32_t DCameraSourceDev::ParseEnableParam(std::shared_ptr& param, std::string& ability) +{ + JSONCPP_STRING errs; + Json::CharReaderBuilder readerBuilder; + Json::Value sinkRootValue; + + std::unique_ptr const jsonReader(readerBuilder.newCharReader()); + if (!jsonReader->parse(param->sinkParam_.c_str(), param->sinkParam_.c_str() + param->sinkParam_.length(), + &sinkRootValue, &errs) || !sinkRootValue.isObject()) { + DHLOGE("Input sink ablity info is not json object."); + return DCAMERA_INIT_ERR; + } + + Json::Value srcRootValue; + if (!jsonReader->parse(param->srcParam_.c_str(), param->srcParam_.c_str() + param->srcParam_.length(), + &srcRootValue, &errs) || !srcRootValue.isObject()) { + DHLOGE("Input source ablity info is not json object."); + return DCAMERA_INIT_ERR; + } + Json::Value abilityRootValue; + abilityRootValue["SinkAbility"] = sinkRootValue; + abilityRootValue["SourceAbility"] = srcRootValue; + ability = abilityRootValue.toStyledString(); + return DCAMERA_OK; +} + int32_t DCameraSourceDev::UnRegister(std::shared_ptr& param) { DCAMERA_SYNC_TRACE(DCAMERA_UNREGISTER_CAMERA); diff --git a/services/data_process/include/pipeline_node/multimedia_codec/decoder/decode_data_process.h b/services/data_process/include/pipeline_node/multimedia_codec/decoder/decode_data_process.h index ee914fbadd46f5b862ea80cb554ab6f52980733c..cdfc0dee9249c5071e36c30acd7d8b0b3caf7610 100644 --- a/services/data_process/include/pipeline_node/multimedia_codec/decoder/decode_data_process.h +++ b/services/data_process/include/pipeline_node/multimedia_codec/decoder/decode_data_process.h @@ -103,6 +103,7 @@ private: constexpr static int32_t VIDEO_DECODER_QUEUE_MAX = 1000; constexpr static int32_t MAX_YUV420_BUFFER_SIZE = 1920 * 1080 * 3 / 2 * 2; constexpr static int32_t MAX_RGB32_BUFFER_SIZE = 1920 * 1080 * 4 * 2; + constexpr static int32_t MAX_BUFFER_SIZE = 1920 * 1080 * 4 * 2; constexpr static int32_t MIN_FRAME_RATE = 0; constexpr static int32_t MAX_FRAME_RATE = 30; constexpr static int32_t MIN_VIDEO_WIDTH = 320; diff --git a/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process_common.cpp b/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process_common.cpp index 2cd79817e0ebd2dd782fa9311a0888e86b481ccf..3522e58925a46aa18253df0f0a0af507b15b7cdc 100644 --- a/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process_common.cpp +++ b/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process_common.cpp @@ -160,17 +160,13 @@ int32_t DecodeDataProcess::InitDecoderMetadataFormat() DHLOGI("Init video decoder metadata format. codecType: %d", sourceConfig_.GetVideoCodecType()); processedConfig_ = sourceConfig_; processedConfig_.SetVideoCodecType(VideoCodecType::NO_CODEC); + processedConfig_.SetVideoformat(Videoformat::NV12); switch (sourceConfig_.GetVideoCodecType()) { case VideoCodecType::CODEC_H264: processType_ = "video/avc"; - processedConfig_.SetVideoformat(Videoformat::NV12); break; case VideoCodecType::CODEC_H265: processType_ = "video/hevc"; - processedConfig_.SetVideoformat(Videoformat::NV12); - break; - case VideoCodecType::CODEC_MPEG4_ES: - processType_ = "video/mp4v-es"; break; default: DHLOGE("The current codec type does not support decoding."); @@ -392,7 +388,7 @@ int32_t DecodeDataProcess::ProcessData(std::vector>& DHLOGE("video decoder input buffers queue over flow."); return DCAMERA_INDEX_OVERFLOW; } - if (inputBuffers[0]->Size() > MAX_RGB32_BUFFER_SIZE) { + if (inputBuffers[0]->Size() > MAX_BUFFER_SIZE) { DHLOGE("DecodeNode input buffer size %zu error.", inputBuffers[0]->Size()); return DCAMERA_MEMORY_OPT_ERROR; } @@ -550,12 +546,11 @@ void DecodeDataProcess::CopyDecodedImage(const sptr& surBuf, int3 DHLOGE("Surface output buffer error."); return; } - - size_t rgbImageSize = static_cast(sourceConfig_.GetWidth() * sourceConfig_.GetHeight() * - RGB32_MEMORY_COEFFICIENT); - std::shared_ptr bufferOutput = std::make_shared(rgbImageSize); + size_t yuvImageSize = static_cast( + sourceConfig_.GetWidth() * sourceConfig_.GetHeight() * YUV_BYTES_PER_PIXEL / Y2UV_RATIO); + std::shared_ptr bufferOutput = std::make_shared(yuvImageSize); uint8_t *addr = static_cast(surBuf->GetVirAddr()); - errno_t err = memcpy_s(bufferOutput->Data(), bufferOutput->Size(), addr, rgbImageSize); + errno_t err = memcpy_s(bufferOutput->Data(), bufferOutput->Size(), addr, yuvImageSize); if (err != EOK) { DHLOGE("memcpy_s surface buffer failed."); return; @@ -582,11 +577,14 @@ bool DecodeDataProcess::IsCorrectSurfaceBuffer(const sptr& surBuf return false; } - size_t rgbImageSize = static_cast(sourceConfig_.GetWidth() * sourceConfig_.GetHeight() * - RGB32_MEMORY_COEFFICIENT); size_t surfaceBufSize = static_cast(surBuf->GetSize()); - if (rgbImageSize > surfaceBufSize) { - DHLOGE("Buffer size error, rgbImageSize %d, surBufSize %d.", rgbImageSize, surBuf->GetSize()); + size_t yuvImageAlignedSize = static_cast( + alignedWidth * alignedHeight * YUV_BYTES_PER_PIXEL / Y2UV_RATIO); + size_t yuvImageSize = static_cast( + sourceConfig_.GetWidth() * sourceConfig_.GetHeight() * YUV_BYTES_PER_PIXEL / Y2UV_RATIO); + if (yuvImageAlignedSize > surfaceBufSize || yuvImageAlignedSize < yuvImageSize) { + DHLOGE("Buffer size error, yuvImageSize %zu, yuvImageAlignedSize %zu, surBufSize %zu.", + yuvImageSize, yuvImageAlignedSize, surBuf->GetSize()); return false; } return true; diff --git a/services/data_process/src/pipeline_node/scale_conversion/scale_convert_process_common.cpp b/services/data_process/src/pipeline_node/scale_conversion/scale_convert_process_common.cpp index f8a1e0fb618ecc7adcdd2e701702c5b7032e5bb3..0d9cb2f5bffb68c2bfeb8545ff4cc00d82cfd073 100644 --- a/services/data_process/src/pipeline_node/scale_conversion/scale_convert_process_common.cpp +++ b/services/data_process/src/pipeline_node/scale_conversion/scale_convert_process_common.cpp @@ -400,6 +400,9 @@ AVPixelFormat ScaleConvertProcess::GetAVPixelFormat(Videoformat colorFormat) case Videoformat::NV21: format = AVPixelFormat::AV_PIX_FMT_NV21; break; + case Videoformat::RGBA_8888: + format = AVPixelFormat::AV_PIX_FMT_RGBA; + break; default: format = AVPixelFormat::AV_PIX_FMT_YUV420P; break;