diff --git a/services/cameraservice/cameraoperator/handler/BUILD.gn b/services/cameraservice/cameraoperator/handler/BUILD.gn index ffc0c8eb5bbd2ce224ed84c0bf1991cfc3c5ef82..1c79ba8900dd7695205e974d58ddc128aa70144b 100644 --- a/services/cameraservice/cameraoperator/handler/BUILD.gn +++ b/services/cameraservice/cameraoperator/handler/BUILD.gn @@ -42,13 +42,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 = [ "${camerastandard_path}/frameworks/native/camera:camera_framework", 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/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 06166b152851583a8a44217fdf70f96b15d3b0d9..9b55d3ee70a3bbf164ef3dfeb70d1eedfb892643 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 @@ -538,11 +538,11 @@ void DecodeDataProcess::CopyDecodedImage(const sptr& surBuf, int6 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; @@ -550,8 +550,8 @@ void DecodeDataProcess::CopyDecodedImage(const sptr& surBuf, int6 bufferOutput->SetInt64(TIME_STAMP_US, timeStampUs); bufferOutput->SetInt32("Videoformat", static_cast(processedConfig_.GetVideoformat())); - bufferOutput->SetInt32("alignedWidth", processedConfig_.GetWidth()); - bufferOutput->SetInt32("alignedHeight", processedConfig_.GetHeight()); + bufferOutput->SetInt32("alignedWidth", alignedWidth); + bufferOutput->SetInt32("alignedHeight", alignedHeight); bufferOutput->SetInt32("width", processedConfig_.GetWidth()); bufferOutput->SetInt32("height", processedConfig_.GetHeight()); @@ -566,11 +566,14 @@ bool DecodeDataProcess::IsCorrectSurfaceBuffer(const sptr& surBuf return false; } - size_t rgbImageSize = static_cast(sourceConfig_.GetWidth() * sourceConfig_.GetHeight() * - RGB32_MEMORY_COEFFICIENT); + 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); size_t surfaceBufSize = static_cast(surBuf->GetSize()); - if (rgbImageSize > surfaceBufSize) { - DHLOGE("Buffer size error, rgbImageSize %d, surBufSize %d.", rgbImageSize, surBuf->GetSize()); + 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 0080e4533cd1c096471de41f73733faae95fecea..c65d36517610b93507eb4cda99a6078d49f6e830 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 @@ -401,6 +401,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;