From 31fb5a3172f60d9c73c08f913f58b62c4ab5a199 Mon Sep 17 00:00:00 2001 From: zhuxu Date: Mon, 9 Jan 2023 10:56:59 +0800 Subject: [PATCH] fix: modify codec type Signed-off-by: zhuxu --- .../cameraoperator/client/BUILD.gn | 13 +- .../client/include/dcamera_client.h | 2 - .../listener/dcamera_video_surface_listener.h | 37 -- .../client/src/dcamera_client.cpp | 39 +- .../client/src/dcamera_client_common.cpp | 184 +++--- .../dcamera_photo_surface_listener_common.cpp | 74 --- .../dcamera_video_surface_listener.cpp | 74 --- .../dcamera_video_surface_listener_common.cpp | 71 --- .../client/test/sample/main.cpp | 6 +- .../cameraoperator/dcamera_client_test.cpp | 57 +- .../handler/src/dcamera_handler.cpp | 9 +- .../handler/src/dcamera_handler_common.cpp | 111 ++-- services/cameraservice/sinkservice/BUILD.gn | 8 +- .../dcamera_sink_data_process.cpp | 23 +- .../dcamera_sink_data_process_common.cpp | 211 ------- .../dcamera_stream_data_process.cpp | 15 +- services/data_process/BUILD.gn | 12 +- .../include/utils/image_common_type.h | 2 +- .../decoder/decode_data_process.cpp | 44 +- .../decoder/decode_data_process_common.cpp | 102 +++- .../encoder/encode_data_process.cpp | 27 +- .../encoder/encode_data_process_common.cpp | 564 ------------------ .../decode_data_process_test.cpp | 10 +- .../encode_data_process_test.cpp | 46 +- 24 files changed, 374 insertions(+), 1367 deletions(-) delete mode 100644 services/cameraservice/cameraoperator/client/include/listener/dcamera_video_surface_listener.h delete mode 100644 services/cameraservice/cameraoperator/client/src/listener/dcamera_photo_surface_listener_common.cpp delete mode 100644 services/cameraservice/cameraoperator/client/src/listener/dcamera_video_surface_listener.cpp delete mode 100644 services/cameraservice/cameraoperator/client/src/listener/dcamera_video_surface_listener_common.cpp delete mode 100644 services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process_common.cpp delete mode 100644 services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process_common.cpp diff --git a/services/cameraservice/cameraoperator/client/BUILD.gn b/services/cameraservice/cameraoperator/client/BUILD.gn index 1427646a..d209c7dc 100644 --- a/services/cameraservice/cameraoperator/client/BUILD.gn +++ b/services/cameraservice/cameraoperator/client/BUILD.gn @@ -49,20 +49,13 @@ ohos_shared_library("distributed_camera_client") { "src/callback/dcamera_preview_callback.cpp", "src/callback/dcamera_session_callback.cpp", "src/callback/dcamera_video_callback.cpp", + "src/listener/dcamera_photo_surface_listener.cpp", ] if (!distributed_camera_common) { - sources += [ - "src/dcamera_client.cpp", - "src/listener/dcamera_photo_surface_listener.cpp", - "src/listener/dcamera_video_surface_listener.cpp", - ] + sources += [ "src/dcamera_client.cpp" ] } else { - sources += [ - "src/dcamera_client_common.cpp", - "src/listener/dcamera_photo_surface_listener_common.cpp", - "src/listener/dcamera_video_surface_listener_common.cpp", - ] + sources += [ "src/dcamera_client_common.cpp" ] } deps = [ diff --git a/services/cameraservice/cameraoperator/client/include/dcamera_client.h b/services/cameraservice/cameraoperator/client/include/dcamera_client.h index 59781c41..430b8b32 100644 --- a/services/cameraservice/cameraoperator/client/include/dcamera_client.h +++ b/services/cameraservice/cameraoperator/client/include/dcamera_client.h @@ -32,7 +32,6 @@ #include "video_output.h" #include "dcamera_photo_surface_listener.h" -#include "dcamera_video_surface_listener.h" namespace OHOS { namespace DistributedHardware { @@ -87,7 +86,6 @@ private: sptr previewOutput_; sptr videoOutput_; sptr photoListener_; - sptr videoListener_; std::shared_ptr stateCallback_; std::shared_ptr resultCallback_; }; diff --git a/services/cameraservice/cameraoperator/client/include/listener/dcamera_video_surface_listener.h b/services/cameraservice/cameraoperator/client/include/listener/dcamera_video_surface_listener.h deleted file mode 100644 index cb33b642..00000000 --- a/services/cameraservice/cameraoperator/client/include/listener/dcamera_video_surface_listener.h +++ /dev/null @@ -1,37 +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. - */ - -#ifndef OHOS_DCAMERA_VIDEO_SURFACE_LISTENER_H -#define OHOS_DCAMERA_VIDEO_SURFACE_LISTENER_H - -#include "surface.h" -#include "icamera_operator.h" - -namespace OHOS { -namespace DistributedHardware { -class DCameraVideoSurfaceListener : public IBufferConsumerListener { -public: - DCameraVideoSurfaceListener(const sptr& surface, - const std::shared_ptr& callback); - void OnBufferAvailable() override; - -private: - sptr surface_; - std::shared_ptr callback_; - const int32_t SURFACE_BUFFER_MAX_SIZE = 10 * 1024 * 1024; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DCAMERA_VIDEO_SURFACE_LISTENER_H \ No newline at end of file diff --git a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp index 8dd387fa..364cec1e 100644 --- a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp +++ b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp @@ -21,6 +21,7 @@ #include "dcamera_input_callback.h" #include "dcamera_manager_callback.h" #include "dcamera_photo_callback.h" +#include "dcamera_preview_callback.h" #include "dcamera_session_callback.h" #include "dcamera_utils_tools.h" #include "dcamera_video_callback.h" @@ -247,12 +248,12 @@ int32_t DCameraClient::StopCapture() int32_t ret = cameraInput_->Close(); if (ret != DCAMERA_OK) { DHLOGE("DCameraClient::StopCapture cameraInput Close failed, cameraId: %s, ret: %d", - GetAnonyString(cameraId_).c_str(), ret); + GetAnonyString(cameraId_).c_str(), ret); } ret = cameraInput_->Release(); if (ret != DCAMERA_OK) { DHLOGE("DCameraClient::StopCapture cameraInput Release failed, cameraId: %s, ret: %d", - GetAnonyString(cameraId_).c_str(), ret); + GetAnonyString(cameraId_).c_str(), ret); } cameraInput_ = nullptr; } @@ -266,7 +267,6 @@ int32_t DCameraClient::StopCapture() DHLOGE("DCameraClient::StopCapture %s video surface unregister consumer listener failed, ret: %d", GetAnonyString(cameraId_).c_str(), ret); } - videoListener_ = nullptr; videoSurface_ = nullptr; } @@ -337,7 +337,7 @@ int32_t DCameraClient::ConfigCaptureSession(std::vector &)cameraInput_)->Open(); if (rc != DCAMERA_OK) { DHLOGE("DCameraClient::ConfigCaptureSession cameraInput_ Open failed, cameraId: %s, ret: %d", - GetAnonyString(cameraId_).c_str(), rc); + GetAnonyString(cameraId_).c_str(), rc); return DCAMERA_BAD_VALUE; } std::shared_ptr inputCallback = std::make_shared(stateCallback_); @@ -459,9 +459,9 @@ int32_t DCameraClient::CreateCaptureOutput(std::vector& info) { - DHLOGI("DCameraClient::CreatePhotoOutput camId: %s, width: %d, height: %d, format: %d, stream: %d, isCapture: %d", - GetAnonyString(cameraId_).c_str(), info->width_, info->height_, info->format_, - info->streamType_, info->isCapture_); + DHLOGI("DCameraClient::CreatePhotoOutput dhId: %s, width: %d, height: %d, format: %d, stream: %d, isCapture: %d", + GetAnonyString(cameraId_).c_str(), info->width_, info->height_, info->format_, info->streamType_, + info->isCapture_); photoSurface_ = Surface::CreateSurfaceAsConsumer(); photoListener_ = new DCameraPhotoSurfaceListener(photoSurface_, resultCallback_); photoSurface_->RegisterConsumerListener((sptr &)photoListener_); @@ -482,9 +482,9 @@ int32_t DCameraClient::CreatePhotoOutput(std::shared_ptr& in int32_t DCameraClient::CreateVideoOutput(std::shared_ptr& info) { - DHLOGI("DCameraClient::CreateVideoOutput camId: %s, width: %d, height: %d, format: %d, stream: %d, isCapture: %d", - GetAnonyString(cameraId_).c_str(), info->width_, info->height_, info->format_, - info->streamType_, info->isCapture_); + DHLOGI("DCameraClient::CreateVideoOutput dhId: %s, width: %d, height: %d, format: %d, stream: %d, isCapture: %d", + GetAnonyString(cameraId_).c_str(), info->width_, info->height_, info->format_, info->streamType_, + info->isCapture_); CameraStandard::CameraFormat videoFormat = ConvertToCameraFormat(info->format_); CameraStandard::Size videoSize = {info->width_, info->height_}; std::vector framerates = {}; @@ -506,16 +506,16 @@ CameraStandard::CameraFormat DCameraClient::ConvertToCameraFormat(int32_t format CameraStandard::CameraFormat ret = CameraStandard::CameraFormat::CAMERA_FORMAT_INVALID; DCameraFormat df = static_cast(format); switch (df) { - case OHOS_CAMERA_FORMAT_RGBA_8888: + case DCameraFormat::OHOS_CAMERA_FORMAT_RGBA_8888: ret = CameraStandard::CameraFormat::CAMERA_FORMAT_RGBA_8888; break; - case OHOS_CAMERA_FORMAT_YCBCR_420_888: + case DCameraFormat::OHOS_CAMERA_FORMAT_YCBCR_420_888: ret = CameraStandard::CameraFormat::CAMERA_FORMAT_YCBCR_420_888; break; - case OHOS_CAMERA_FORMAT_YCRCB_420_SP: + case DCameraFormat::OHOS_CAMERA_FORMAT_YCRCB_420_SP: ret = CameraStandard::CameraFormat::CAMERA_FORMAT_YUV_420_SP; break; - case OHOS_CAMERA_FORMAT_JPEG: + case DCameraFormat::OHOS_CAMERA_FORMAT_JPEG: ret = CameraStandard::CameraFormat::CAMERA_FORMAT_JPEG; break; default: @@ -562,7 +562,7 @@ int32_t DCameraClient::StartPhotoOutput(std::shared_ptr& inf int32_t ret = ((sptr &)photoOutput_)->Capture(); if (ret != DCAMERA_OK) { DHLOGE("DCameraClient::StartPhotoOutput %s photoOutput capture failed, ret: %d", - GetAnonyString(cameraId_).c_str(), ret); + GetAnonyString(cameraId_).c_str(), ret); return ret; } return DCAMERA_OK; @@ -578,7 +578,7 @@ int32_t DCameraClient::StartPhotoOutput(std::shared_ptr& inf int32_t ret = ((sptr &)photoOutput_)->Capture(photoCaptureSetting); if (ret != DCAMERA_OK) { DHLOGE("DCameraClient::StartPhotoOutput %s photoOutput capture failed, ret: %d", - GetAnonyString(cameraId_).c_str(), ret); + GetAnonyString(cameraId_).c_str(), ret); return ret; } return DCAMERA_OK; @@ -629,8 +629,9 @@ void DCameraClient::SetPhotoCaptureLocation(const std::shared_ptrlongitude = item.data.d[longitudeIndex]; location->altitude = item.data.d[altitudeIndex]; photoCaptureSetting->SetLocation(location); - DHLOGI("DCameraClient::SetPhotoCaptureLocation %s photo capture settings set %d location success", - GetAnonyString(cameraId_).c_str(), item.count); + DHLOGI("DCameraClient::SetPhotoCaptureLocation %s photo capture settings set %d location: " + + "latitude=%f, longitude=%f, altitude=%f", GetAnonyString(cameraId_).c_str(), item.count, + item.data.d[latitudeIndex], item.data.d[longitudeIndex], item.data.d[altitudeIndex]); } } @@ -644,7 +645,7 @@ int32_t DCameraClient::StartVideoOutput() int32_t ret = ((sptr &)videoOutput_)->Start(); if (ret != DCAMERA_OK) { DHLOGE("DCameraClient::StartVideoOutput %s videoOutput start failed, ret: %d", - GetAnonyString(cameraId_).c_str(), ret); + GetAnonyString(cameraId_).c_str(), ret); return ret; } return DCAMERA_OK; diff --git a/services/cameraservice/cameraoperator/client/src/dcamera_client_common.cpp b/services/cameraservice/cameraoperator/client/src/dcamera_client_common.cpp index 94656015..23bc2c1f 100644 --- a/services/cameraservice/cameraoperator/client/src/dcamera_client_common.cpp +++ b/services/cameraservice/cameraoperator/client/src/dcamera_client_common.cpp @@ -17,6 +17,7 @@ #include "anonymous_string.h" #include "camera_util.h" +#include "camera_metadata_operator.h" #include "dcamera_input_callback.h" #include "dcamera_manager_callback.h" #include "dcamera_photo_callback.h" @@ -33,7 +34,7 @@ namespace OHOS { namespace DistributedHardware { DCameraClient::DCameraClient(const std::string& dhId) { - DHLOGI("DCameraClientCommon Constructor dhId: %s", GetAnonyString(dhId).c_str()); + DHLOGI("DCameraClient Constructor dhId: %s", GetAnonyString(dhId).c_str()); cameraId_ = dhId.substr(CAMERA_ID_PREFIX.size()); isInit_ = false; } @@ -47,93 +48,91 @@ DCameraClient::~DCameraClient() int32_t DCameraClient::Init() { - DHLOGI("DCameraClientCommon::Init cameraId: %s", GetAnonyString(cameraId_).c_str()); + DHLOGI("DCameraClient::Init cameraId: %s", GetAnonyString(cameraId_).c_str()); cameraManager_ = CameraStandard::CameraManager::GetInstance(); if (cameraManager_ == nullptr) { - DHLOGE("DCameraClientCommon::Init cameraManager getInstance failed"); + DHLOGE("DCameraClient::Init cameraManager getInstance failed"); return DCAMERA_BAD_VALUE; } cameraManager_->SetCallback(std::make_shared()); std::vector> cameraList = cameraManager_->GetSupportedCameras(); if (cameraList.empty()) { - DHLOGE("DCameraClientCommon::Init no camera device"); + DHLOGE("DCameraClient::Init no camera device"); return DCAMERA_BAD_VALUE; } - DHLOGI("DCameraClientCommon::Init camera size: %d", cameraList.size()); + DHLOGI("DCameraClient::Init camera size: %d", cameraList.size()); for (auto& info : cameraList) { if (info->GetID() == cameraId_) { - DHLOGI("DCameraClientCommon::Init cameraInfo get id: %s", GetAnonyString(info->GetID()).c_str()); + DHLOGI("DCameraClient::Init cameraInfo get id: %s", GetAnonyString(info->GetID()).c_str()); cameraInfo_ = info; break; } } if (cameraInfo_ == nullptr) { - DHLOGE("DCameraClientCommon::Init cameraInfo is null"); + DHLOGE("DCameraClient::Init cameraInfo is null"); return DCAMERA_BAD_VALUE; } isInit_ = true; - DHLOGI("DCameraClientCommon::Init %s success", GetAnonyString(cameraId_).c_str()); + DHLOGI("DCameraClient::Init %s success", GetAnonyString(cameraId_).c_str()); return DCAMERA_OK; } int32_t DCameraClient::UnInit() { - DHLOGI("DCameraClientCommon::UnInit cameraId: %s", GetAnonyString(cameraId_).c_str()); + DHLOGI("DCameraClient::UnInit cameraId: %s", GetAnonyString(cameraId_).c_str()); if (cameraManager_ != nullptr) { - DHLOGI("DCameraClientCommon::UnInit unregister cameraManager callback"); + DHLOGI("DCameraClient::UnInit unregister cameraManager callback"); cameraManager_->SetCallback(nullptr); } isInit_ = false; cameraInfo_ = nullptr; cameraManager_ = nullptr; - DHLOGI("DCameraClientCommon::UnInit %s success", GetAnonyString(cameraId_).c_str()); + DHLOGI("DCameraClient::UnInit %s success", GetAnonyString(cameraId_).c_str()); return DCAMERA_OK; } int32_t DCameraClient::UpdateSettings(std::vector>& settings) { - DHLOGI("DCameraClientCommon::UpdateSettings cameraId: %s", GetAnonyString(cameraId_).c_str()); + DHLOGI("DCameraClient::UpdateSettings cameraId: %s", GetAnonyString(cameraId_).c_str()); for (auto& setting : settings) { switch (setting->type_) { case UPDATE_METADATA: { - DHLOGI("DCameraClientCommon::UpdateSettings %s update metadata settings", - GetAnonyString(cameraId_).c_str()); + DHLOGI("DCameraClient::UpdateSettings %s update metadata settings", GetAnonyString(cameraId_).c_str()); std::string dcSettingValue = setting->value_; std::string metadataStr = Base64Decode(dcSettingValue); FindCameraMetadata(metadataStr); if (cameraInput_ == nullptr) { - DHLOGE("DCameraClientCommon::UpdateSettings %s cameraInput is null", - GetAnonyString(cameraId_).c_str()); + DHLOGE("DCameraClient::UpdateSettings %s cameraInput is null", GetAnonyString(cameraId_).c_str()); UpdateSettingCache(metadataStr); return DCAMERA_OK; } int32_t ret = ((sptr &)cameraInput_)->SetCameraSettings(metadataStr); if (ret != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::UpdateSettings %s update metadata settings failed, ret: %d", + DHLOGE("DCameraClient::UpdateSettings %s update metadata settings failed, ret: %d", GetAnonyString(cameraId_).c_str(), ret); return ret; } break; } default: { - DHLOGE("DCameraClientCommon::UpdateSettings unknown setting type"); + DHLOGE("DCameraClient::UpdateSettings unknown setting type"); break; } } } - DHLOGI("DCameraClientCommon::UpdateSettings %s success", GetAnonyString(cameraId_).c_str()); + DHLOGI("DCameraClient::UpdateSettings %s success", GetAnonyString(cameraId_).c_str()); return DCAMERA_OK; } void DCameraClient::UpdateSettingCache(const std::string& metadataStr) { if (cameraMetadatas_.size() == DCAMERA_MAX_METADATA_SIZE) { - DHLOGE("DCameraClientCommon::UpdateSettingCache %s camera metadata oversize", + DHLOGE("DCameraClient::UpdateSettingCache %s camera metadata oversize", GetAnonyString(cameraId_).c_str()); cameraMetadatas_.pop(); } @@ -146,27 +145,27 @@ void DCameraClient::FindCameraMetadata(const std::string& metadataStr) camera_metadata_item_t focusItem; int32_t ret = Camera::FindCameraMetadataItem(cameraMetadata->get(), OHOS_CONTROL_FOCUS_MODE, &focusItem); if (ret == CAM_META_SUCCESS) { - DHLOGI("DCameraClientCommon::FindCameraMetadata focus mode: %d", focusItem.data.u8[0]); + DHLOGI("DCameraClient::FindCameraMetadata focus mode: %d", focusItem.data.u8[0]); } else { - DHLOGE("DCameraClientCommon::FindCameraMetadata %s find focus mode failed, ret: %d", + DHLOGE("DCameraClient::FindCameraMetadata %s find focus mode failed, ret: %d", GetAnonyString(cameraId_).c_str(), ret); } camera_metadata_item_t exposureItem; ret = Camera::FindCameraMetadataItem(cameraMetadata->get(), OHOS_CONTROL_EXPOSURE_MODE, &exposureItem); if (ret == CAM_META_SUCCESS) { - DHLOGI("DCameraClientCommon::FindCameraMetadata exposure mode: %d", exposureItem.data.u8[0]); + DHLOGI("DCameraClient::FindCameraMetadata exposure mode: %d", exposureItem.data.u8[0]); } else { - DHLOGE("DCameraClientCommon::FindCameraMetadata %s find exposure mode failed, ret: %d", + DHLOGE("DCameraClient::FindCameraMetadata %s find exposure mode failed, ret: %d", GetAnonyString(cameraId_).c_str(), ret); } camera_metadata_item_t stabilityItem; ret = Camera::FindCameraMetadataItem(cameraMetadata->get(), OHOS_CONTROL_VIDEO_STABILIZATION_MODE, &stabilityItem); if (ret == CAM_META_SUCCESS) { - DHLOGI("DCameraClientCommon::FindCameraMetadata stabilization mode: %d", stabilityItem.data.u8[0]); + DHLOGI("DCameraClient::FindCameraMetadata stabilization mode: %d", stabilityItem.data.u8[0]); } else { - DHLOGE("DCameraClientCommon::FindCameraMetadata %s find stabilization mode failed, ret: %d", + DHLOGE("DCameraClient::FindCameraMetadata %s find stabilization mode failed, ret: %d", GetAnonyString(cameraId_).c_str(), ret); } } @@ -174,9 +173,9 @@ void DCameraClient::FindCameraMetadata(const std::string& metadataStr) int32_t DCameraClient::StartCapture(std::vector>& captureInfos, sptr& surface) { - DHLOGI("DCameraClientCommon::StartCapture cameraId: %s", GetAnonyString(cameraId_).c_str()); + DHLOGI("DCameraClient::StartCapture cameraId: %s", GetAnonyString(cameraId_).c_str()); if ((photoOutput_ == nullptr) && (previewOutput_ == nullptr)) { - DHLOGI("DCameraClientCommon::StartCapture %s config capture session", GetAnonyString(cameraId_).c_str()); + DHLOGI("DCameraClient::StartCapture %s config capture session", GetAnonyString(cameraId_).c_str()); if (surface == nullptr) { DHLOGE("DCameraClient::StartCapture: input surface is nullptr."); return DCAMERA_BAD_VALUE; @@ -184,7 +183,7 @@ int32_t DCameraClient::StartCapture(std::vectorClose(); if (ret != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::StopCapture %s cameraInput_ Close failed, ret: %d", + DHLOGE("DCameraClient::StopCapture cameraInput Close failed, cameraId: %s, ret: %d", GetAnonyString(cameraId_).c_str(), ret); } ret = cameraInput_->Release(); if (ret != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::StopCapture %s cameraInput_ Release failed, ret: %d", + DHLOGE("DCameraClient::StopCapture cameraInput Release failed, cameraId: %s, ret: %d", GetAnonyString(cameraId_).c_str(), ret); } cameraInput_ = nullptr; @@ -236,23 +235,22 @@ int32_t DCameraClient::StopCapture() ReleaseCaptureSession(); if (videoSurface_ != nullptr) { - DHLOGI("DCameraClientCommon::StopCapture %s video surface unregister consumer listener", + DHLOGI("DCameraClient::StopCapture %s video surface unregister consumer listener", GetAnonyString(cameraId_).c_str()); int32_t ret = videoSurface_->UnregisterConsumerListener(); if (ret != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::StopCapture %s video surface unregister consumer listener failed, ret: %d", + DHLOGE("DCameraClient::StopCapture %s video surface unregister consumer listener failed, ret: %d", GetAnonyString(cameraId_).c_str(), ret); } - videoListener_ = nullptr; videoSurface_ = nullptr; } if (photoSurface_ != nullptr) { - DHLOGI("DCameraClientCommon::StopCapture %s photo surface unregister consumer listener", + DHLOGI("DCameraClient::StopCapture %s photo surface unregister consumer listener", GetAnonyString(cameraId_).c_str()); int32_t ret = photoSurface_->UnregisterConsumerListener(); if (ret != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::StopCapture %s photo surface unregister consumer listener failed, ret: %d", + DHLOGE("DCameraClient::StopCapture %s photo surface unregister consumer listener failed, ret: %d", GetAnonyString(cameraId_).c_str(), ret); } photoListener_ = nullptr; @@ -261,7 +259,7 @@ int32_t DCameraClient::StopCapture() photoOutput_ = nullptr; previewOutput_ = nullptr; - DHLOGI("DCameraClientCommon::StopCapture %s success", GetAnonyString(cameraId_).c_str()); + DHLOGI("DCameraClient::StopCapture %s success", GetAnonyString(cameraId_).c_str()); return DCAMERA_OK; } @@ -270,16 +268,16 @@ void DCameraClient::ReleaseCaptureSession() if (captureSession_ == nullptr) { return; } - DHLOGI("DCameraClientCommon::StopCapture %s stop captureSession", GetAnonyString(cameraId_).c_str()); + DHLOGI("DCameraClient::StopCapture %s stop captureSession", GetAnonyString(cameraId_).c_str()); int32_t ret = captureSession_->Stop(); if (ret != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::StopCapture captureSession stop failed, cameraId: %s, ret: %d", + DHLOGE("DCameraClient::StopCapture captureSession stop failed, cameraId: %s, ret: %d", GetAnonyString(cameraId_).c_str(), ret); } - DHLOGI("DCameraClientCommon::StopCapture %s release captureSession", GetAnonyString(cameraId_).c_str()); + DHLOGI("DCameraClient::StopCapture %s release captureSession", GetAnonyString(cameraId_).c_str()); ret = captureSession_->Release(); if (ret != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::StopCapture captureSession Release failed, cameraId: %s, ret: %d", + DHLOGE("DCameraClient::StopCapture captureSession Release failed, cameraId: %s, ret: %d", GetAnonyString(cameraId_).c_str(), ret); } captureSession_ = nullptr; @@ -287,10 +285,9 @@ void DCameraClient::ReleaseCaptureSession() int32_t DCameraClient::SetStateCallback(std::shared_ptr& callback) { - DHLOGI("DCameraClientCommon::SetStateCallback cameraId: %s", GetAnonyString(cameraId_).c_str()); + DHLOGI("DCameraClient::SetStateCallback cameraId: %s", GetAnonyString(cameraId_).c_str()); if (callback == nullptr) { - DHLOGE("DCameraClientCommon::SetStateCallback %s unregistering state callback", - GetAnonyString(cameraId_).c_str()); + DHLOGE("DCameraClient::SetStateCallback %s unregistering state callback", GetAnonyString(cameraId_).c_str()); } stateCallback_ = callback; return DCAMERA_OK; @@ -298,10 +295,9 @@ int32_t DCameraClient::SetStateCallback(std::shared_ptr& callback int32_t DCameraClient::SetResultCallback(std::shared_ptr& callback) { - DHLOGI("DCameraClientCommon::SetResultCallback cameraId: %s", GetAnonyString(cameraId_).c_str()); + DHLOGI("DCameraClient::SetResultCallback cameraId: %s", GetAnonyString(cameraId_).c_str()); if (callback == nullptr) { - DHLOGE("DCameraClientCommon::SetResultCallback %s unregistering result callback", - GetAnonyString(cameraId_).c_str()); + DHLOGE("DCameraClient::SetResultCallback %s unregistering result callback", GetAnonyString(cameraId_).c_str()); } resultCallback_ = callback; return DCAMERA_OK; @@ -309,16 +305,15 @@ int32_t DCameraClient::SetResultCallback(std::shared_ptr& callba int32_t DCameraClient::ConfigCaptureSession(std::vector>& captureInfos) { - DHLOGI("DCameraClientCommon::ConfigCaptureSession cameraId: %s", GetAnonyString(cameraId_).c_str()); + DHLOGI("DCameraClient::ConfigCaptureSession cameraId: %s", GetAnonyString(cameraId_).c_str()); int rv = cameraManager_->CreateCameraInput(cameraInfo_, &((sptr &)cameraInput_)); if (rv != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::ConfigCaptureSession %s create cameraInput failed", - GetAnonyString(cameraId_).c_str()); + DHLOGE("DCameraClient::ConfigCaptureSession %s create cameraInput failed", GetAnonyString(cameraId_).c_str()); return DCAMERA_BAD_VALUE; } int32_t rc = ((sptr &)cameraInput_)->Open(); if (rc != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::ConfigCaptureSession %s cameraInput_ Open failed, ret: %d", + DHLOGE("DCameraClient::ConfigCaptureSession cameraInput_ Open failed, cameraId: %s, ret: %d", GetAnonyString(cameraId_).c_str(), rc); return DCAMERA_BAD_VALUE; } @@ -330,7 +325,7 @@ int32_t DCameraClient::ConfigCaptureSession(std::vector &)cameraInput_)->SetCameraSettings(metadataStr); if (ret != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::ConfigCaptureSession %s set camera settings failed, ret: %d", + DHLOGE("DCameraClient::ConfigCaptureSession %s set camera settings failed, ret: %d", GetAnonyString(cameraId_).c_str(), ret); return ret; } @@ -339,7 +334,7 @@ int32_t DCameraClient::ConfigCaptureSession(std::vectorCreateCaptureSession(&captureSession_); if (rv != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::ConfigCaptureSession %s create captureSession failed", + DHLOGE("DCameraClient::ConfigCaptureSession %s create captureSession failed", GetAnonyString(cameraId_).c_str()); return DCAMERA_BAD_VALUE; } @@ -350,7 +345,7 @@ int32_t DCameraClient::ConfigCaptureSession(std::vectorBeginConfig(); if (ret != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::ConfigCaptureSession %s config captureSession failed, ret: %d", + DHLOGE("DCameraClient::ConfigCaptureSession %s config captureSession failed, ret: %d", GetAnonyString(cameraId_).c_str(), ret); return ret; } ret = captureSession_->AddInput(cameraInput_); if (ret != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::ConfigCaptureSession %s add cameraInput to captureSession failed, ret: %d", + DHLOGE("DCameraClient::ConfigCaptureSession %s add cameraInput to captureSession failed, ret: %d", GetAnonyString(cameraId_).c_str(), ret); return ret; } @@ -377,7 +372,7 @@ int32_t DCameraClient::ConfigCaptureSessionInner() if (photoOutput_ != nullptr) { ret = captureSession_->AddOutput(photoOutput_); if (ret != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::ConfigCaptureSession %s add photoOutput to captureSession failed, ret: %d", + DHLOGE("DCameraClient::ConfigCaptureSession %s add photoOutput to captureSession failed, ret: %d", GetAnonyString(cameraId_).c_str(), ret); return ret; } @@ -386,7 +381,7 @@ int32_t DCameraClient::ConfigCaptureSessionInner() if (previewOutput_ != nullptr) { ret = captureSession_->AddOutput(previewOutput_); if (ret != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::ConfigCaptureSession %s add previewOutput to captureSession failed, ret: %d", + DHLOGE("DCameraClient::ConfigCaptureSession %s add previewOutput to captureSession failed, ret: %d", GetAnonyString(cameraId_).c_str(), ret); return ret; } @@ -394,26 +389,25 @@ int32_t DCameraClient::ConfigCaptureSessionInner() ret = captureSession_->CommitConfig(); if (ret != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::ConfigCaptureSession %s commit captureSession failed, ret: %d", + DHLOGE("DCameraClient::ConfigCaptureSession %s commit captureSession failed, ret: %d", GetAnonyString(cameraId_).c_str(), ret); return ret; } ret = captureSession_->Start(); if (ret != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::ConfigCaptureSession %s start captureSession failed, ret: %d", + DHLOGE("DCameraClient::ConfigCaptureSession %s start captureSession failed, ret: %d", GetAnonyString(cameraId_).c_str(), ret); } - DHLOGI("DCameraClientCommon::ConfigCaptureSession %s success", GetAnonyString(cameraId_).c_str()); + DHLOGI("DCameraClient::ConfigCaptureSession %s success", GetAnonyString(cameraId_).c_str()); return DCAMERA_OK; } int32_t DCameraClient::CreateCaptureOutput(std::vector>& captureInfos) { if (captureInfos.empty()) { - DHLOGE("DCameraClientCommon::CreateCaptureOutput no capture info, cameraId: %s", - GetAnonyString(cameraId_).c_str()); + DHLOGE("DCameraClient::CreateCaptureOutput no capture info, cameraId: %s", GetAnonyString(cameraId_).c_str()); return DCAMERA_BAD_VALUE; } @@ -421,19 +415,19 @@ int32_t DCameraClient::CreateCaptureOutput(std::vectorstreamType_ == SNAPSHOT_FRAME) { int32_t ret = CreatePhotoOutput(info); if (ret != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::CreateCaptureOutput %s create photo output failed, ret: %d", + DHLOGE("DCameraClient::CreateCaptureOutput %s create photo output failed, ret: %d", GetAnonyString(cameraId_).c_str(), ret); return ret; } } else if (info->streamType_ == CONTINUOUS_FRAME) { int32_t ret = CreateVideoOutput(info); if (ret != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::CreateCaptureOutput %s create video output failed, ret: %d", + DHLOGE("DCameraClient::CreateCaptureOutput %s create video output failed, ret: %d", GetAnonyString(cameraId_).c_str(), ret); return ret; } } else { - DHLOGE("DCameraClientCommon::CreateCaptureOutput unknown stream type"); + DHLOGE("DCameraClient::CreateCaptureOutput unknown stream type"); return DCAMERA_BAD_VALUE; } } @@ -442,9 +436,9 @@ int32_t DCameraClient::CreateCaptureOutput(std::vector& info) { - DHLOGI("DCameraClientCommon::CreatePhotoOutput camId: %s, w: %d, h: %d, f: %d, stream: %d, isCapture: %d", - GetAnonyString(cameraId_).c_str(), info->width_, info->height_, - info->format_, info->streamType_, info->isCapture_); + DHLOGI("DCameraClient::CreatePhotoOutput dhId: %s, width: %d, height: %d, format: %d, stream: %d, isCapture: %d", + GetAnonyString(cameraId_).c_str(), info->width_, info->height_, info->format_, info->streamType_, + info->isCapture_); photoSurface_ = Surface::CreateSurfaceAsConsumer(); photoListener_ = new DCameraPhotoSurfaceListener(photoSurface_, resultCallback_); photoSurface_->RegisterConsumerListener((sptr &)photoListener_); @@ -454,34 +448,33 @@ int32_t DCameraClient::CreatePhotoOutput(std::shared_ptr& in int rv = cameraManager_->CreatePhotoOutput( photoProfile, photoSurface_, &((sptr &)photoOutput_)); if (rv != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::CreatePhotoOutput %s create photo output failed", - GetAnonyString(cameraId_).c_str()); + DHLOGE("DCameraClient::CreatePhotoOutput %s create photo output failed", GetAnonyString(cameraId_).c_str()); return DCAMERA_BAD_VALUE; } std::shared_ptr photoCallback = std::make_shared(stateCallback_); ((sptr &)photoOutput_)->SetCallback(photoCallback); - DHLOGI("DCameraClientCommon::CreatePhotoOutput %s success", GetAnonyString(cameraId_).c_str()); + DHLOGI("DCameraClient::CreatePhotoOutput %s success", GetAnonyString(cameraId_).c_str()); return DCAMERA_OK; } int32_t DCameraClient::CreateVideoOutput(std::shared_ptr& info) { - DHLOGI("DCameraClientCommon::CreatePreviewOutput camId: %s, w: %d, h: %d, f: %d, stream: %d, isCapture: %d", - GetAnonyString(cameraId_).c_str(), info->width_, info->height_, - info->format_, info->streamType_, info->isCapture_); + DHLOGI("DCameraClient::CreatePreviewOutput dhId: %s, width: %d, height: %d, format: %d, stream: %d, isCapture: %d", + GetAnonyString(cameraId_).c_str(), info->width_, info->height_, info->format_, info->streamType_, + info->isCapture_); CameraStandard::CameraFormat previewFormat = ConvertToCameraFormat(info->format_); CameraStandard::Size previewSize = {info->width_, info->height_}; CameraStandard::Profile previewProfile(previewFormat, previewSize); int rv = cameraManager_->CreatePreviewOutput( previewProfile, videoSurface_, &((sptr &)previewOutput_)); if (rv != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::CreatePreviewOutput %s create preview output failed", + DHLOGE("DCameraClient::CreatePreviewOutput %s create preview output failed", GetAnonyString(cameraId_).c_str()); return DCAMERA_BAD_VALUE; } std::shared_ptr previewCallback = std::make_shared(stateCallback_); ((sptr &)previewOutput_)->SetCallback(previewCallback); - DHLOGI("DCameraClientCommon::CreatePreviewOutput %s success", GetAnonyString(cameraId_).c_str()); + DHLOGI("DCameraClient::CreatePreviewOutput %s success", GetAnonyString(cameraId_).c_str()); return DCAMERA_OK; } @@ -518,7 +511,7 @@ int32_t DCameraClient::StartCaptureInner(std::shared_ptr& in return StartPhotoOutput(info); } default: { - DHLOGE("DCameraClientCommon::StartCaptureInner unknown stream type"); + DHLOGE("DCameraClient::StartCaptureInner unknown stream type"); return DCAMERA_BAD_VALUE; } } @@ -526,27 +519,26 @@ int32_t DCameraClient::StartCaptureInner(std::shared_ptr& in int32_t DCameraClient::StartPhotoOutput(std::shared_ptr& info) { - DHLOGI("DCameraClientCommon::StartPhotoOutput cameraId: %s", GetAnonyString(cameraId_).c_str()); + DHLOGI("DCameraClient::StartPhotoOutput cameraId: %s", GetAnonyString(cameraId_).c_str()); if (photoOutput_ == nullptr) { - DHLOGE("DCameraClientCommon::StartPhotoOutput photoOutput is null"); + DHLOGE("DCameraClient::StartPhotoOutput photoOutput is null"); return DCAMERA_BAD_VALUE; } std::vector> captureSettings = info->captureSettings_; std::string metadataSetting; - for (auto& setting : captureSettings) { + for (const auto& setting : captureSettings) { if (setting->type_ == UPDATE_METADATA) { - DHLOGI("DCameraClientCommon::StartPhotoOutput %s update metadata settings", - GetAnonyString(cameraId_).c_str()); + DHLOGI("DCameraClient::StartPhotoOutput %s update metadata settings", GetAnonyString(cameraId_).c_str()); metadataSetting = setting->value_; } } if (metadataSetting.empty()) { - DHLOGE("DCameraClientCommon::StartPhotoOutput no metadata settings to update"); + DHLOGE("DCameraClient::StartPhotoOutput no metadata settings to update"); int32_t ret = ((sptr &)photoOutput_)->Capture(); if (ret != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::StartPhotoOutput %s photoOutput capture failed, ret: %d", + DHLOGE("DCameraClient::StartPhotoOutput %s photoOutput capture failed, ret: %d", GetAnonyString(cameraId_).c_str(), ret); return ret; } @@ -562,7 +554,7 @@ int32_t DCameraClient::StartPhotoOutput(std::shared_ptr& inf SetPhotoCaptureLocation(cameraMetadata, photoCaptureSetting); int32_t ret = ((sptr &)photoOutput_)->Capture(photoCaptureSetting); if (ret != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::StartPhotoOutput %s photoOutput capture failed, ret: %d", + DHLOGE("DCameraClient::StartPhotoOutput %s photoOutput capture failed, ret: %d", GetAnonyString(cameraId_).c_str(), ret); return ret; } @@ -579,7 +571,7 @@ void DCameraClient::SetPhotoCaptureRotation(const std::shared_ptr(item.data.i32[0]); photoCaptureSetting->SetRotation(rotation); - DHLOGI("DCameraClientCommon::SetPhotoCaptureRotation %s photo capture settings set %d rotation: %d", + DHLOGI("DCameraClient::SetPhotoCaptureRotation %s photo capture settings set %d rotation: %d", GetAnonyString(cameraId_).c_str(), item.count, rotation); } } @@ -594,7 +586,7 @@ void DCameraClient::SetPhotoCaptureQuality(const std::shared_ptr(item.data.u8[0]); photoCaptureSetting->SetQuality(quality); - DHLOGI("DCameraClientCommon::SetPhotoCaptureQuality %s photo capture settings set %d quality: %d", + DHLOGI("DCameraClient::SetPhotoCaptureQuality %s photo capture settings set %d quality: %d", GetAnonyString(cameraId_).c_str(), item.count, quality); } } @@ -614,7 +606,7 @@ void DCameraClient::SetPhotoCaptureLocation(const std::shared_ptrlongitude = item.data.d[longitudeIndex]; location->altitude = item.data.d[altitudeIndex]; photoCaptureSetting->SetLocation(location); - DHLOGI("DCameraClientCommon::SetPhotoCaptureLocation %s photo capture settings set %d location: " + + DHLOGI("DCameraClient::SetPhotoCaptureLocation %s photo capture settings set %d location: " + "latitude=%f, longitude=%f, altitude=%f", GetAnonyString(cameraId_).c_str(), item.count, item.data.d[latitudeIndex], item.data.d[longitudeIndex], item.data.d[altitudeIndex]); } @@ -622,14 +614,14 @@ void DCameraClient::SetPhotoCaptureLocation(const std::shared_ptr &)videoOutput_)->Start(); if (ret != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::StartVideoOutput %s videoOutput start failed, ret: %d", + DHLOGE("DCameraClient::StartVideoOutput %s videoOutput start failed, ret: %d", GetAnonyString(cameraId_).c_str(), ret); return ret; } diff --git a/services/cameraservice/cameraoperator/client/src/listener/dcamera_photo_surface_listener_common.cpp b/services/cameraservice/cameraoperator/client/src/listener/dcamera_photo_surface_listener_common.cpp deleted file mode 100644 index d94e4687..00000000 --- a/services/cameraservice/cameraoperator/client/src/listener/dcamera_photo_surface_listener_common.cpp +++ /dev/null @@ -1,74 +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_photo_surface_listener.h" - -#include - -#include "data_buffer.h" -#include "distributed_camera_errno.h" -#include "distributed_hardware_log.h" - -namespace OHOS { -namespace DistributedHardware { -DCameraPhotoSurfaceListener::DCameraPhotoSurfaceListener(const sptr& surface, - const std::shared_ptr& callback) : surface_(surface), callback_(callback) -{ -} - -void DCameraPhotoSurfaceListener::OnBufferAvailable() -{ - DHLOGI("DCameraPhotoSurfaceListenerCommon::OnBufferAvailable"); - if (callback_ == nullptr || surface_ == nullptr) { - DHLOGE("DCameraPhotoSurfaceListenerCommon ResultCallback or Surface is null"); - return; - } - - int32_t flushFence = 0; - int64_t timestamp = 0; - OHOS::Rect damage; - OHOS::sptr buffer = nullptr; - surface_->AcquireBuffer(buffer, flushFence, timestamp, damage); - if (buffer == nullptr) { - DHLOGE("DCameraPhotoSurfaceListenerCommon AcquireBuffer failed"); - return; - } - - do { - int32_t size = -1; - buffer->GetExtraData()->ExtraGet("dataSize", size); - if (size <= 0) { - size = static_cast(buffer->GetSize()); - } - char *address = static_cast(buffer->GetVirAddr()); - if ((address == nullptr) || (size <= 0) || (size > SURFACE_BUFFER_MAX_SIZE)) { - DHLOGE("DCameraPhotoSurfaceListenerCommon invalid params, size: %d", size); - break; - } - - DHLOGI("DCameraPhotoSurfaceListenerCommon size: %d", size); - std::shared_ptr dataBuffer = std::make_shared(size); - int32_t ret = memcpy_s(dataBuffer->Data(), dataBuffer->Capacity(), address, size); - if (ret != EOK) { - DHLOGE("DCameraPhotoSurfaceListenerCommon Memory Copy failed, ret: %d", ret); - break; - } - - callback_->OnPhotoResult(dataBuffer); - } while (0); - surface_->ReleaseBuffer(buffer, -1); -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/cameraoperator/client/src/listener/dcamera_video_surface_listener.cpp b/services/cameraservice/cameraoperator/client/src/listener/dcamera_video_surface_listener.cpp deleted file mode 100644 index f937b343..00000000 --- a/services/cameraservice/cameraoperator/client/src/listener/dcamera_video_surface_listener.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2021-2022 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_video_surface_listener.h" - -#include - -#include "data_buffer.h" -#include "distributed_camera_errno.h" -#include "distributed_hardware_log.h" - -namespace OHOS { -namespace DistributedHardware { -DCameraVideoSurfaceListener::DCameraVideoSurfaceListener(const sptr& surface, - const std::shared_ptr& callback) : surface_(surface), callback_(callback) -{ -} - -void DCameraVideoSurfaceListener::OnBufferAvailable() -{ - if (callback_ == nullptr || surface_ == nullptr) { - DHLOGE("DCameraVideoSurfaceListener ResultCallback or Surface is null"); - return; - } - - int32_t flushFence = 0; - int64_t timestamp = 0; - OHOS::Rect damage; - OHOS::sptr buffer = nullptr; - surface_->AcquireBuffer(buffer, flushFence, timestamp, damage); - if (buffer == nullptr) { - DHLOGE("DCameraVideoSurfaceListener AcquireBuffer failed"); - return; - } - - do { - int32_t width = buffer->GetWidth(); - int32_t height = buffer->GetHeight(); - int32_t size = buffer->GetSize(); - char *address = static_cast(buffer->GetVirAddr()); - if ((address == nullptr) || (size <= 0) || (width <= 0) || (height <= 0) || (size > SURFACE_BUFFER_MAX_SIZE)) { - DHLOGE("DCameraVideoSurfaceListener invalid params, width: %d, height: %d, size: %d", width, height, size); - break; - } - - DHLOGI("DCameraVideoSurfaceListener width: %d, height: %d, size: %d", width, height, size); - int32_t y2UvRatio = 2; - int32_t bytesPerPixel = 3; - size_t validImgSize = static_cast(width * height * bytesPerPixel / y2UvRatio); - std::shared_ptr dataBuffer = std::make_shared(validImgSize); - int32_t ret = memcpy_s(dataBuffer->Data(), dataBuffer->Capacity(), address, validImgSize); - if (ret != EOK) { - DHLOGE("DCameraVideoSurfaceListener Memory Copy failed, ret: %d", ret); - break; - } - - callback_->OnVideoResult(dataBuffer); - } while (0); - surface_->ReleaseBuffer(buffer, -1); -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/cameraoperator/client/src/listener/dcamera_video_surface_listener_common.cpp b/services/cameraservice/cameraoperator/client/src/listener/dcamera_video_surface_listener_common.cpp deleted file mode 100644 index 3203298c..00000000 --- a/services/cameraservice/cameraoperator/client/src/listener/dcamera_video_surface_listener_common.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2021-2022 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_video_surface_listener.h" - -#include - -#include "data_buffer.h" -#include "distributed_camera_errno.h" -#include "distributed_hardware_log.h" - -namespace OHOS { -namespace DistributedHardware { -DCameraVideoSurfaceListener::DCameraVideoSurfaceListener(const sptr& surface, - const std::shared_ptr& callback) : surface_(surface), callback_(callback) -{ -} - -void DCameraVideoSurfaceListener::OnBufferAvailable() -{ - if (callback_ == nullptr || surface_ == nullptr) { - DHLOGE("DCameraVideoSurfaceListenerCommon ResultCallback or Surface is null"); - return; - } - - int32_t flushFence = 0; - int64_t timestamp = 0; - OHOS::Rect damage; - OHOS::sptr buffer = nullptr; - surface_->AcquireBuffer(buffer, flushFence, timestamp, damage); - if (buffer == nullptr) { - DHLOGE("DCameraVideoSurfaceListenerCommon AcquireBuffer failed"); - return; - } - - do { - int32_t width = buffer->GetWidth(); - int32_t height = buffer->GetHeight(); - int32_t size = width * height * 4; - char *address = static_cast(buffer->GetVirAddr()); - if ((address == nullptr) || (size <= 0) || (size > SURFACE_BUFFER_MAX_SIZE)) { - DHLOGE("DCameraVideoSurfaceListenerCommon invalid params, width: %d, height: %d, size: %d", - width, height, size); - break; - } - DHLOGI("DCameraVideoSurfaceListenerCommon size: %d", size); - std::shared_ptr dataBuffer = std::make_shared(size); - int32_t ret = memcpy_s(dataBuffer->Data(), dataBuffer->Capacity(), address, size); - if (ret != EOK) { - DHLOGE("DCameraVideoSurfaceListenerCommon Memory Copy failed, ret: %d", ret); - break; - } - - callback_->OnVideoResult(dataBuffer); - } while (0); - surface_->ReleaseBuffer(buffer, -1); -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/cameraoperator/client/test/sample/main.cpp b/services/cameraservice/cameraoperator/client/test/sample/main.cpp index 0d77988f..58ae32db 100644 --- a/services/cameraservice/cameraoperator/client/test/sample/main.cpp +++ b/services/cameraservice/cameraoperator/client/test/sample/main.cpp @@ -30,8 +30,8 @@ using namespace OHOS::DistributedHardware; constexpr double LATITUDE = 22.306; constexpr double LONGITUDE = 52.12; constexpr double ALTITUDE = 2.365; -constexpr int32_t PHOTO_WIDTH = 640; -constexpr int32_t PHOTO_HEIGTH = 480; +constexpr int32_t PHOTO_WIDTH = 1280; +constexpr int32_t PHOTO_HEIGTH = 960; constexpr int32_t PREVIEW_WIDTH = 640; constexpr int32_t PREVIEW_HEIGTH = 480; constexpr int32_t VIDEO_WIDTH = 640; @@ -55,7 +55,7 @@ static std::shared_ptr g_videoInfo = nullptr; constexpr int32_t PREVIEW_FORMAT = camera_format_t::OHOS_CAMERA_FORMAT_YCRCB_420_SP; constexpr int32_t VIDEO_FORMAT = camera_format_t::OHOS_CAMERA_FORMAT_YCRCB_420_SP; #else - constexpr int32_t PHOTO_FORMAT = camera_format_t::OHOS_CAMERA_FORMAT_RGBA_8888; + constexpr int32_t PHOTO_FORMAT = camera_format_t::OHOS_CAMERA_FORMAT_JPEG; constexpr int32_t PREVIEW_FORMAT = camera_format_t::OHOS_CAMERA_FORMAT_RGBA_8888; constexpr int32_t VIDEO_FORMAT = camera_format_t::OHOS_CAMERA_FORMAT_RGBA_8888; #endif diff --git a/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/dcamera_client_test.cpp b/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/dcamera_client_test.cpp index 0a867490..1a946c33 100644 --- a/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/dcamera_client_test.cpp +++ b/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/dcamera_client_test.cpp @@ -45,13 +45,13 @@ namespace OHOS { namespace DistributedHardware { class DCameraClientTestStateCallback : public StateCallback { public: - void OnStateChanged(std::shared_ptr& event) + void OnStateChanged(std::shared_ptr& event) override { DHLOGI("DCameraClientTestStateCallback::OnStateChanged type: %d, result: %d", - event->eventType_, event->eventResult_); + event->eventType_, event->eventResult_); } - void OnMetadataResult(std::vector>& settings) + void OnMetadataResult(std::vector>& settings) override { DHLOGI("DCameraClientTestStateCallback::OnMetadataResult"); } @@ -59,17 +59,25 @@ public: class DCameraClientTestResultCallback : public ResultCallback { public: - void OnPhotoResult(std::shared_ptr& buffer) + void OnPhotoResult(std::shared_ptr& buffer) override { DHLOGI("DCameraClientTestResultCallback::OnPhotoResult"); } - void OnVideoResult(std::shared_ptr& buffer) + void OnVideoResult(std::shared_ptr& buffer) override { DHLOGI("DCameraClientTestResultCallback::OnVideoResult"); } }; +class DCameraClientTestVideoSurfaceListener : public IBufferConsumerListener { +public: + void OnBufferAvailable() override + { + DHLOGD("DCameraClientTestVideoSurfaceListener::OnBufferAvailable"); + } +}; + #ifdef DCAMERA_YUV const int32_t TEST_WIDTH = 1920; const int32_t TEST_HEIGHT = 1080; @@ -96,14 +104,12 @@ public: void SetUp(); void TearDown(); void SetTokenID(); - - sptr surface_; + std::shared_ptr client_; std::shared_ptr photoInfo_false_; std::shared_ptr videoInfo_false_; std::shared_ptr photoInfo_true_; std::shared_ptr videoInfo_true_; - sptr videoListener_; }; void DCameraClientTest::SetUpTestCase(void) @@ -262,16 +268,10 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_002, TestSize.Level1) auto photoSurfaceListener = std::make_shared(nullptr, nullptr); photoSurfaceListener->OnBufferAvailable(); - auto videoSurfaceListener = std::make_shared(nullptr, nullptr); - videoSurfaceListener->OnBufferAvailable(); - std::shared_ptr resultCallback = std::make_shared(); photoSurfaceListener = std::make_shared(nullptr, resultCallback); photoSurfaceListener->OnBufferAvailable(); - videoSurfaceListener = std::make_shared(nullptr, resultCallback); - videoSurfaceListener->OnBufferAvailable(); - int32_t ret = client_->SetResultCallback(resultCallback); EXPECT_EQ(DCAMERA_OK, ret); @@ -320,9 +320,10 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_004, TestSize.Level1) std::shared_ptr resultCallback = std::make_shared(); ret = client_->SetResultCallback(resultCallback); EXPECT_EQ(DCAMERA_OK, ret); - surface_ = Surface::CreateSurfaceAsConsumer(); - videoListener_ = new DCameraVideoSurfaceListener(surface_, resultCallback); - surface_->RegisterConsumerListener((sptr &)videoListener_); + + sptr videoSurface = Surface::CreateSurfaceAsConsumer(); + sptr videoListener = new DCameraClientTestVideoSurfaceListener(); + videoSurface->RegisterConsumerListener(videoListener); ret = client_->Init(); EXPECT_EQ(DCAMERA_OK, ret); @@ -331,7 +332,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_004, TestSize.Level1) videoInfo_true_->width_, videoInfo_true_->height_, videoInfo_true_->format_, videoInfo_true_->isCapture_); std::vector> captureInfos; captureInfos.push_back(videoInfo_true_); - ret = client_->StartCapture(captureInfos, surface_); + ret = client_->StartCapture(captureInfos, videoSurface); EXPECT_EQ(DCAMERA_OK, ret); auto metaData = std::make_shared(ENTRY_CAPACITY, DATA_CAPACITY); @@ -370,9 +371,10 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_005, TestSize.Level1) std::shared_ptr resultCallback = std::make_shared(); ret = client_->SetResultCallback(resultCallback); EXPECT_EQ(DCAMERA_OK, ret); - surface_ = Surface::CreateSurfaceAsConsumer(); - videoListener_ = new DCameraVideoSurfaceListener(surface_, resultCallback); - surface_->RegisterConsumerListener((sptr &)videoListener_); + + sptr videoSurface = Surface::CreateSurfaceAsConsumer(); + sptr videoListener = new DCameraClientTestVideoSurfaceListener(); + videoSurface->RegisterConsumerListener(videoListener); ret = client_->Init(); EXPECT_EQ(DCAMERA_OK, ret); @@ -384,7 +386,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_005, TestSize.Level1) std::vector> captureInfos; captureInfos.push_back(videoInfo_true_); captureInfos.push_back(photoInfo_false_); - ret = client_->StartCapture(captureInfos, surface_); + ret = client_->StartCapture(captureInfos, videoSurface); EXPECT_EQ(DCAMERA_OK, ret); sleep(TEST_SLEEP_SEC); @@ -396,7 +398,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_005, TestSize.Level1) captureInfos.clear(); captureInfos.push_back(videoInfo_false_); captureInfos.push_back(photoInfo_true_); - ret = client_->StartCapture(captureInfos, surface_); + ret = client_->StartCapture(captureInfos, videoSurface); EXPECT_EQ(DCAMERA_OK, ret); sleep(TEST_SLEEP_SEC); @@ -572,9 +574,10 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_013, TestSize.Level1) std::shared_ptr resultCallback = std::make_shared(); ret = client_->SetResultCallback(resultCallback); EXPECT_EQ(DCAMERA_OK, ret); - surface_ = Surface::CreateSurfaceAsConsumer(); - videoListener_ = new DCameraVideoSurfaceListener(surface_, resultCallback); - surface_->RegisterConsumerListener((sptr &)videoListener_); + + sptr videoSurface = Surface::CreateSurfaceAsConsumer(); + sptr videoListener = new DCameraClientTestVideoSurfaceListener(); + videoSurface->RegisterConsumerListener(videoListener); ret = client_->Init(); EXPECT_EQ(DCAMERA_OK, ret); @@ -586,7 +589,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_013, TestSize.Level1) std::vector> captureInfos; captureInfos.push_back(videoInfo_true_); captureInfos.push_back(photoInfo_false_); - ret = client_->StartCapture(captureInfos, surface_); + ret = client_->StartCapture(captureInfos, videoSurface); EXPECT_EQ(DCAMERA_OK, ret); sleep(TEST_SLEEP_SEC); diff --git a/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp b/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp index e85b736a..7c488867 100644 --- a/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp +++ b/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp @@ -146,8 +146,9 @@ int32_t DCameraHandler::CreateDHItem(sptr& info, D for (auto& videoCaps : videoCapsList) { std::shared_ptr codecInfo = videoCaps->GetCodecInfo(); std::string name = codecInfo->GetName(); - root[CAMERA_CODEC_TYPE_KEY].append(name); - DHLOGI("DCameraHandler::CreateDHItem codec type: %s", name.c_str()); + std::string mimeType = codecInfo->GetMimeType(); + root[CAMERA_CODEC_TYPE_KEY].append(mimeType); + DHLOGI("DCameraHandler::CreateDHItem codec name: %s, mimeType: %s", name.c_str(), mimeType.c_str()); } sptr capability = cameraManager_->GetSupportedOutputCapability(info); @@ -215,13 +216,15 @@ std::string DCameraHandler::GetCameraPosition(CameraStandard::CameraPosition pos void DCameraHandler::ConfigFormatAndResolution(const DCStreamType type, Json::Value& root, std::vector& profileList) { - DHLOGI("DCameraHandler::ConfigFormatAndResolution camera Profile size: %d", profileList.size()); + DHLOGI("DCameraHandler::ConfigFormatAndResolution 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("DCameraHandler::ConfigFormatAndResolution, 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); diff --git a/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp b/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp index 61c50294..645af13d 100644 --- a/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp +++ b/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp @@ -33,20 +33,20 @@ IMPLEMENT_SINGLE_INSTANCE(DCameraHandler); DCameraHandler::~DCameraHandler() { - DHLOGI("~DCameraHandlerCommon"); + DHLOGI("~DCameraHandler"); } int32_t DCameraHandler::Initialize() { - DHLOGI("DCameraHandlerCommon::Initialize"); + DHLOGI("DCameraHandler::Initialize"); cameraManager_ = CameraStandard::CameraManager::GetInstance(); if (cameraManager_ == nullptr) { - DHLOGE("DCameraHandlerCommon::Initialize cameraManager getInstance failed"); + DHLOGE("DCameraHandler::Initialize cameraManager getInstance failed"); return DCAMERA_INIT_ERR; } std::shared_ptr cameraMgrCallback = std::make_shared(); cameraManager_->SetCallback(cameraMgrCallback); - DHLOGI("DCameraHandlerCommon::Initialize success"); + DHLOGI("DCameraHandler::Initialize success"); return DCAMERA_OK; } @@ -54,24 +54,24 @@ std::vector DCameraHandler::Query() { std::vector itemList; std::vector> cameraList = cameraManager_->GetSupportedCameras(); - DHLOGI("DCameraHandlerCommon::Query get %d cameras", cameraList.size()); + DHLOGI("DCameraHandler::Query get %d cameras", cameraList.size()); if (cameraList.empty()) { - DHLOGE("DCameraHandlerCommon::Query no camera device"); + DHLOGE("DCameraHandler::Query no camera device"); return itemList; } for (auto& info : cameraList) { if (info->GetConnectionType() != CameraStandard::ConnectionType::CAMERA_CONNECTION_BUILT_IN) { - DHLOGI("DCameraHandlerCommon::Query connection type: %d", info->GetConnectionType()); + DHLOGI("DCameraHandler::Query connection type: %d", info->GetConnectionType()); continue; } - DHLOGI("DCameraHandlerCommon::Query get %s, position: %d, cameraType: %d", + DHLOGI("DCameraHandler::Query 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("DCameraHandlerCommon::Query success, get %d items", itemList.size()); + DHLOGI("DCameraHandler::Query success, get %d items", itemList.size()); return itemList; } @@ -107,27 +107,27 @@ std::vector DCameraHandler::GetCameras() { std::vector cameras; std::vector> cameraList = cameraManager_->GetSupportedCameras(); - DHLOGI("DCameraHandlerCommon::GetCameras get %d cameras", cameraList.size()); + DHLOGI("DCameraHandler::GetCameras get %d cameras", cameraList.size()); if (cameraList.empty()) { - DHLOGE("DCameraHandlerCommon::GetCameras no camera device"); + DHLOGE("DCameraHandler::GetCameras no camera device"); return cameras; } for (auto& info : cameraList) { sptr capability = cameraManager_->GetSupportedOutputCapability(info); if (capability == nullptr) { - DHLOGI("DCameraHandlerCommon::GetCameras get supported capability is null"); + DHLOGI("DCameraHandler::GetCameras get supported capability is null"); continue; } if (info->GetConnectionType() != CameraStandard::ConnectionType::CAMERA_CONNECTION_BUILT_IN) { - DHLOGI("DCameraHandlerCommon::GetCameras connection type: %d", info->GetConnectionType()); + DHLOGI("DCameraHandler::GetCameras connection type: %d", info->GetConnectionType()); continue; } - DHLOGI("DCameraHandlerCommon::GetCameras get %s, position: %d, cameraType: %d", + DHLOGI("DCameraHandler::GetCameras 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("DCameraHandlerCommon::GetCameras success, get %d items", cameras.size()); + DHLOGI("DCameraHandler::GetCameras success, get %d items", cameras.size()); return cameras; } @@ -135,23 +135,25 @@ int32_t DCameraHandler::CreateDHItem(sptr& info, D { std::string id = info->GetID(); item.dhId = CAMERA_ID_PREFIX + id; - DHLOGI("DCameraHandlerCommon::CreateDHItem camera id: %s", GetAnonyString(id).c_str()); + DHLOGI("DCameraHandler::CreateDHItem 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("OMX_hisi_video_encoder_avc"); + root[CAMERA_CODEC_TYPE_KEY].append("video/mp4v-es"); - sptr cameraInput = nullptr; - int rv = cameraManager_->CreateCameraInput(info, &cameraInput); - if (rv != DCAMERA_OK) { - DHLOGE("DCameraHandlerCommon::CreateDHItem create cameraInput failed"); - return DCAMERA_BAD_VALUE; + 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("DCameraHandler::CreateDHItem codec name: %s, mimeType: %s", name.c_str(), mimeType.c_str()); } sptr capability = cameraManager_->GetSupportedOutputCapability(info); if (capability == nullptr) { - DHLOGI("DCameraHandlerCommon::CreateDHItem get supported capability is null"); + DHLOGI("DCameraHandler::CreateDHItem get supported capability is null"); return DCAMERA_BAD_VALUE; } std::vector photoProfiles = capability->GetPhotoProfiles(); @@ -160,20 +162,27 @@ int32_t DCameraHandler::CreateDHItem(sptr& info, D std::vector previewProfiles = capability->GetPreviewProfiles(); ConfigFormatAndResolution(CONTINUOUS_FRAME, root, previewProfiles); + sptr cameraInput = nullptr; + int rv = cameraManager_->CreateCameraInput(info, &cameraInput); + if (rv != DCAMERA_OK) { + DHLOGE("DCameraHandler::CreateDHItem create cameraInput failed"); + return DCAMERA_BAD_VALUE; + } + std::hash h; std::string abilityString = cameraInput->GetCameraSettings(); - DHLOGI("DCameraHandlerCommon::CreateDHItem abilityString hash: %zu, length: %zu", + DHLOGI("DCameraHandler::CreateDHItem abilityString hash: %zu, length: %zu", h(abilityString), abilityString.length()); std::string encodeString = Base64Encode(reinterpret_cast(abilityString.c_str()), abilityString.length()); - DHLOGI("DCameraHandlerCommon::CreateDHItem encodeString hash: %zu, length: %zu", + DHLOGI("DCameraHandler::CreateDHItem 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("DCameraHandlerCommon::CreateDHItem cameraInput Release failed"); + DHLOGE("DCameraHandler::CreateDHItem cameraInput Release failed"); } return DCAMERA_OK; } @@ -207,18 +216,34 @@ std::string DCameraHandler::GetCameraPosition(CameraStandard::CameraPosition pos void DCameraHandler::ConfigFormatAndResolution(const DCStreamType type, Json::Value& root, std::vector& profileList) { - DHLOGI("DCameraHandler::ConfigFormatAndResolution camera Profile size: %d", profileList.size()); - CameraStandard::CameraFormat format = CameraStandard::CameraFormat::CAMERA_FORMAT_RGBA_8888; - int32_t dformat = CovertToDcameraFormat(format); - std::string formatName = std::to_string(dformat); - if (type == SNAPSHOT_FRAME) { - root[CAMERA_FORMAT_PHOTO][CAMERA_RESOLUTION_KEY][formatName].append("640*480"); - root[CAMERA_FORMAT_PHOTO][CAMERA_FORMAT_KEY].append(format); - } else if (type == CONTINUOUS_FRAME) { - root[CAMERA_FORMAT_PREVIEW][CAMERA_RESOLUTION_KEY][formatName].append("640*480"); - root[CAMERA_FORMAT_VIDEO][CAMERA_RESOLUTION_KEY][formatName].append("640*480"); - root[CAMERA_FORMAT_PREVIEW][CAMERA_FORMAT_KEY].append(format); - root[CAMERA_FORMAT_VIDEO][CAMERA_FORMAT_KEY].append(format); + DHLOGI("DCameraHandler::ConfigFormatAndResolution 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("DCameraHandler::ConfigFormatAndResolution, 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); + } } } @@ -258,10 +283,12 @@ bool DCameraHandler::IsValid(const DCStreamType type, const CameraStandard::Size break; } case SNAPSHOT_FRAME: { - ret = (size.width >= RESOLUTION_MIN_WIDTH) && - (size.height >= RESOLUTION_MIN_HEIGHT) && - (size.width <= RESOLUTION_MAX_WIDTH_SNAPSHOT) && - (size.height <= RESOLUTION_MAX_HEIGHT_SNAPSHOT); + 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: { diff --git a/services/cameraservice/sinkservice/BUILD.gn b/services/cameraservice/sinkservice/BUILD.gn index 25b69bfc..48645bae 100644 --- a/services/cameraservice/sinkservice/BUILD.gn +++ b/services/cameraservice/sinkservice/BUILD.gn @@ -77,6 +77,7 @@ ohos_shared_library("distributed_camera_sink") { "src/distributedcameramgr/callback/dcamera_sink_output_result_callback.cpp", "src/distributedcameramgr/dcamera_sink_access_control.cpp", "src/distributedcameramgr/dcamera_sink_controller.cpp", + "src/distributedcameramgr/dcamera_sink_data_process.cpp", "src/distributedcameramgr/dcamera_sink_dev.cpp", "src/distributedcameramgr/dcamera_sink_output.cpp", "src/distributedcameramgr/dcamera_sink_service_ipc.cpp", @@ -89,13 +90,6 @@ ohos_shared_library("distributed_camera_sink") { "src/distributedcameramgr/listener/dcamera_sink_output_channel_listener.cpp", ] - if (!distributed_camera_common) { - sources += [ "src/distributedcameramgr/dcamera_sink_data_process.cpp" ] - } else { - sources += - [ "src/distributedcameramgr/dcamera_sink_data_process_common.cpp" ] - } - deps = [ "${camerastandard_path}/frameworks/native/camera:camera_framework", "${common_path}:distributed_camera_utils", diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process.cpp index b226c208..2b22cbc8 100644 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process.cpp +++ b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process.cpp @@ -73,7 +73,7 @@ int32_t DCameraSinkDataProcess::StartCapture(std::shared_ptr return DCAMERA_OK; } - if ((captureInfo->streamType_ == CONTINUOUS_FRAME) && (captureInfo->format_ != captureInfo->encodeType_)) { + if (captureInfo->streamType_ == CONTINUOUS_FRAME) { DHLOGI("DCameraSinkDataProcess::StartCapture %s create data process pipeline", GetAnonyString(dhId_).c_str()); pipeline_ = std::make_shared(); auto dataProcess = std::shared_ptr(shared_from_this()); @@ -166,12 +166,6 @@ void DCameraSinkDataProcess::OnError(DataProcessErrorType errorType) int32_t DCameraSinkDataProcess::FeedStreamInner(std::shared_ptr& dataBuffer) { - if (captureInfo_->format_ == captureInfo_->encodeType_) { - DHLOGI("DCameraSinkDataProcess::FeedStreamInner %s send video buffer", GetAnonyString(dhId_).c_str()); - SendDataAsync(dataBuffer); - return DCAMERA_OK; - } - std::vector> buffers; buffers.push_back(dataBuffer); int32_t ret = pipeline_->ProcessData(buffers); @@ -193,6 +187,9 @@ VideoCodecType DCameraSinkDataProcess::GetPipelineCodecType(DCEncodeType encodeT case ENCODE_TYPE_H265: codecType = VideoCodecType::CODEC_H265; break; + case ENCODE_TYPE_MPEG4_ES: + codecType = VideoCodecType::CODEC_MPEG4_ES; + break; default: codecType = VideoCodecType::NO_CODEC; break; @@ -202,8 +199,16 @@ VideoCodecType DCameraSinkDataProcess::GetPipelineCodecType(DCEncodeType encodeT Videoformat DCameraSinkDataProcess::GetPipelineFormat(int32_t format) { - (void)format; - return Videoformat::NV21; + Videoformat videoFormat; + switch (format) { + case OHOS_CAMERA_FORMAT_RGBA_8888: + videoFormat = Videoformat::RGBA_8888; + break; + default: + videoFormat = Videoformat::NV21; + break; + } + return videoFormat; } int32_t DCameraSinkDataProcess::GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process_common.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process_common.cpp deleted file mode 100644 index 5e6334f2..00000000 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process_common.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (c) 2021-2022 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_sink_data_process.h" - -#include "anonymous_string.h" -#include "dcamera_channel_sink_impl.h" -#include "dcamera_pipeline_sink.h" -#include "dcamera_sink_data_process_listener.h" -#include "distributed_camera_constants.h" -#include "distributed_camera_errno.h" -#include "distributed_hardware_log.h" - -namespace OHOS { -namespace DistributedHardware { -DCameraSinkDataProcess::DCameraSinkDataProcess(const std::string& dhId, std::shared_ptr& channel) - : dhId_(dhId), channel_(channel), eventHandler_(nullptr) -{ - DHLOGI("DCameraSinkDataProcess Constructor dhId: %s", GetAnonyString(dhId_).c_str()); -} - -DCameraSinkDataProcess::~DCameraSinkDataProcess() -{ - DHLOGI("DCameraSinkDataProcess delete dhId: %s", GetAnonyString(dhId_).c_str()); - if ((eventHandler_ != nullptr) && (eventHandler_->GetEventRunner() != nullptr)) { - eventHandler_->GetEventRunner()->Stop(); - } - eventThread_.join(); - eventHandler_ = nullptr; -} - -void DCameraSinkDataProcess::Init() -{ - DHLOGI("DCameraSinkDataProcess Init dhId: %s", GetAnonyString(dhId_).c_str()); - eventThread_ = std::thread(&DCameraSinkDataProcess::StartEventHandler, this); - std::unique_lock lock(eventMutex_); - eventCon_.wait(lock, [this] { - return eventHandler_ != nullptr; - }); -} - -void DCameraSinkDataProcess::StartEventHandler() -{ - auto runner = AppExecFwk::EventRunner::Create(false); - { - std::lock_guard lock(eventMutex_); - eventHandler_ = std::make_shared(runner); - } - eventCon_.notify_one(); - runner->Run(); -} - -int32_t DCameraSinkDataProcess::StartCapture(std::shared_ptr& captureInfo) -{ - DHLOGI("DCameraSinkDataProcess::StartCapture dhId: %s, width: %d, height: %d, format: %d, stream: %d, encode: %d", - GetAnonyString(dhId_).c_str(), captureInfo->width_, captureInfo->height_, captureInfo->format_, - captureInfo->streamType_, captureInfo->encodeType_); - captureInfo_ = captureInfo; - if (pipeline_ != nullptr) { - DHLOGI("DCameraSinkDataProcess::StartCapture %s pipeline already exits", GetAnonyString(dhId_).c_str()); - return DCAMERA_OK; - } - - if (captureInfo->streamType_ == CONTINUOUS_FRAME) { - DHLOGI("DCameraSinkDataProcess::StartCapture %s create data process pipeline", GetAnonyString(dhId_).c_str()); - pipeline_ = std::make_shared(); - auto dataProcess = std::shared_ptr(shared_from_this()); - std::shared_ptr listener = std::make_shared(dataProcess); - VideoConfigParams srcParams(VideoCodecType::NO_CODEC, - GetPipelineFormat(captureInfo->format_), - DCAMERA_PRODUCER_FPS_DEFAULT, - captureInfo->width_, - captureInfo->height_); - VideoConfigParams destParams(GetPipelineCodecType(captureInfo->encodeType_), - GetPipelineFormat(captureInfo->format_), - DCAMERA_PRODUCER_FPS_DEFAULT, - captureInfo->width_, - captureInfo->height_); - int32_t ret = pipeline_->CreateDataProcessPipeline(PipelineType::VIDEO, srcParams, destParams, listener); - if (ret != DCAMERA_OK) { - DHLOGE("DCameraSinkDataProcess::StartCapture create data process pipeline failed, dhId: %s, ret: %d", - GetAnonyString(dhId_).c_str(), ret); - return ret; - } - } - DHLOGI("DCameraSinkDataProcess::StartCapture %s success", GetAnonyString(dhId_).c_str()); - return DCAMERA_OK; -} - -int32_t DCameraSinkDataProcess::StopCapture() -{ - DHLOGI("DCameraSinkDataProcess::StopCapture dhId: %s", GetAnonyString(dhId_).c_str()); - if (pipeline_ != nullptr) { - pipeline_->DestroyDataProcessPipeline(); - pipeline_ = nullptr; - } - if (eventHandler_ != nullptr) { - DHLOGI("DCameraSinkDataProcess::StopCapture dhId: %s, remove all events", GetAnonyString(dhId_).c_str()); - eventHandler_->RemoveAllEvents(); - } - return DCAMERA_OK; -} - -int32_t DCameraSinkDataProcess::FeedStream(std::shared_ptr& dataBuffer) -{ - DCStreamType type = captureInfo_->streamType_; - DHLOGD("DCameraSinkDataProcess::FeedStream dhId: %s, stream type: %d", GetAnonyString(dhId_).c_str(), type); - switch (type) { - case CONTINUOUS_FRAME: { - int32_t ret = FeedStreamInner(dataBuffer); - if (ret != DCAMERA_OK) { - DHLOGE("DCameraSinkDataProcess::FeedStream continuous frame failed, dhId: %s, ret: %d", - GetAnonyString(dhId_).c_str(), ret); - return ret; - } - break; - } - case SNAPSHOT_FRAME: { - SendDataAsync(dataBuffer); - break; - } - default: { - DHLOGE("DCameraSinkDataProcess::FeedStream %s unknown stream type: %d", - GetAnonyString(dhId_).c_str(), type); - break; - } - } - return DCAMERA_OK; -} - -void DCameraSinkDataProcess::SendDataAsync(const std::shared_ptr& buffer) -{ - auto sendFunc = [this, buffer]() mutable { - std::shared_ptr sendBuffer = buffer; - int32_t ret = channel_->SendData(sendBuffer); - DHLOGD("SendData type: %d output data ret: %d, dhId: %s, bufferSize: %d", captureInfo_->streamType_, ret, - GetAnonyString(dhId_).c_str(), buffer->Size()); - }; - if (eventHandler_ != nullptr) { - eventHandler_->PostTask(sendFunc); - } -} - -void DCameraSinkDataProcess::OnProcessedVideoBuffer(const std::shared_ptr& videoResult) -{ - SendDataAsync(videoResult); -} - -void DCameraSinkDataProcess::OnError(DataProcessErrorType errorType) -{ - DHLOGE("DCameraSinkDataProcess::OnError %s data process pipeline error, errorType: %d", - GetAnonyString(dhId_).c_str(), errorType); -} - -int32_t DCameraSinkDataProcess::FeedStreamInner(std::shared_ptr& dataBuffer) -{ - std::vector> buffers; - buffers.push_back(dataBuffer); - int32_t ret = pipeline_->ProcessData(buffers); - if (ret != DCAMERA_OK) { - DHLOGE("DCameraSinkDataProcess::FeedStreamInner process data failed, dhId: %s, ret: %d", - GetAnonyString(dhId_).c_str(), ret); - return ret; - } - return DCAMERA_OK; -} - -VideoCodecType DCameraSinkDataProcess::GetPipelineCodecType(DCEncodeType encodeType) -{ - VideoCodecType codecType; - switch (encodeType) { - case ENCODE_TYPE_H264: - codecType = VideoCodecType::CODEC_H264; - break; - case ENCODE_TYPE_H265: - codecType = VideoCodecType::CODEC_H265; - break; - default: - codecType = VideoCodecType::NO_CODEC; - break; - } - return codecType; -} - -Videoformat DCameraSinkDataProcess::GetPipelineFormat(int32_t format) -{ - return Videoformat::NV21; -} - -int32_t DCameraSinkDataProcess::GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) -{ - if (pipeline_ == nullptr) { - DHLOGD("DCameraSinkDataProcess::GetProperty: pipeline is nullptr."); - return DCAMERA_BAD_VALUE; - } - return pipeline_->GetProperty(propertyName, propertyCarrier); -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process.cpp index f36fdd5a..9b3bf96d 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process.cpp @@ -269,6 +269,9 @@ VideoCodecType DCameraStreamDataProcess::GetPipelineCodecType(DCEncodeType encod case ENCODE_TYPE_H265: codecType = VideoCodecType::CODEC_H265; break; + case ENCODE_TYPE_MPEG4_ES: + codecType = VideoCodecType::CODEC_MPEG4_ES; + break; default: codecType = VideoCodecType::NO_CODEC; break; @@ -278,8 +281,16 @@ VideoCodecType DCameraStreamDataProcess::GetPipelineCodecType(DCEncodeType encod Videoformat DCameraStreamDataProcess::GetPipelineFormat(int32_t format) { - (void)format; - return Videoformat::NV21; + Videoformat videoFormat; + switch (format) { + case OHOS_CAMERA_FORMAT_RGBA_8888: + videoFormat = Videoformat::RGBA_8888; + break; + default: + videoFormat = Videoformat::NV21; + break; + } + return videoFormat; } } // namespace DistributedHardware } // namespace OHOS diff --git a/services/data_process/BUILD.gn b/services/data_process/BUILD.gn index 340f645c..d65da7b1 100644 --- a/services/data_process/BUILD.gn +++ b/services/data_process/BUILD.gn @@ -51,6 +51,7 @@ ohos_shared_library("distributed_camera_data_process") { "src/pipeline_node/fpscontroller/fps_controller_process.cpp", "src/pipeline_node/multimedia_codec/decoder/decode_surface_listener.cpp", "src/pipeline_node/multimedia_codec/decoder/decode_video_callback.cpp", + "src/pipeline_node/multimedia_codec/encoder/encode_data_process.cpp", "src/pipeline_node/multimedia_codec/encoder/encode_video_callback.cpp", "src/pipeline_node/scale_conversion/scale_convert_process.cpp", "src/utils/image_common_type.cpp", @@ -58,15 +59,10 @@ ohos_shared_library("distributed_camera_data_process") { ] if (!distributed_camera_common) { - sources += [ - "src/pipeline_node/multimedia_codec/decoder/decode_data_process.cpp", - "src/pipeline_node/multimedia_codec/encoder/encode_data_process.cpp", - ] + sources += + [ "src/pipeline_node/multimedia_codec/decoder/decode_data_process.cpp" ] } else { - sources += [ - "src/pipeline_node/multimedia_codec/decoder/decode_data_process_common.cpp", - "src/pipeline_node/multimedia_codec/encoder/encode_data_process_common.cpp", - ] + sources += [ "src/pipeline_node/multimedia_codec/decoder/decode_data_process_common.cpp" ] } deps = [ diff --git a/services/data_process/include/utils/image_common_type.h b/services/data_process/include/utils/image_common_type.h index 235f8607..54078f0b 100644 --- a/services/data_process/include/utils/image_common_type.h +++ b/services/data_process/include/utils/image_common_type.h @@ -30,7 +30,7 @@ enum class VideoCodecType : int32_t { NO_CODEC = 0, CODEC_H264 = 1, CODEC_H265 = 2, - CODEC_MPEG4 = 3, + CODEC_MPEG4_ES = 3, }; enum class Videoformat : int32_t { diff --git a/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process.cpp b/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process.cpp index 1eff94ef..43a60202 100644 --- a/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process.cpp +++ b/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process.cpp @@ -157,30 +157,54 @@ int32_t DecodeDataProcess::ConfigureVideoDecoder() int32_t DecodeDataProcess::InitDecoderMetadataFormat() { - DHLOGD("Init video decoder metadata format."); + DHLOGI("Init video decoder metadata format. codecType: %d", sourceConfig_.GetVideoCodecType()); + processedConfig_ = sourceConfig_; + processedConfig_.SetVideoCodecType(VideoCodecType::NO_CODEC); switch (sourceConfig_.GetVideoCodecType()) { case VideoCodecType::CODEC_H264: processType_ = "video/avc"; - metadataFormat_.PutStringValue("codec_mime", processType_); + processedConfig_.SetVideoformat(Videoformat::NV12); break; case VideoCodecType::CODEC_H265: processType_ = "video/hevc"; - metadataFormat_.PutStringValue("codec_mime", processType_); + 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."); return DCAMERA_NOT_FOUND; } - metadataFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::NV12); - metadataFormat_.PutIntValue("max_input_size", MAX_YUV420_BUFFER_SIZE); + DHLOGI("Init video decoder metadata format. videoformat: %d", processedConfig_.GetVideoformat()); + switch (processedConfig_.GetVideoformat()) { + case Videoformat::YUVI420: + metadataFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::YUVI420); + metadataFormat_.PutIntValue("max_input_size", MAX_YUV420_BUFFER_SIZE); + break; + case Videoformat::NV12: + metadataFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::NV12); + metadataFormat_.PutIntValue("max_input_size", MAX_YUV420_BUFFER_SIZE); + break; + case Videoformat::NV21: + metadataFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::NV21); + metadataFormat_.PutIntValue("max_input_size", MAX_YUV420_BUFFER_SIZE); + break; + case Videoformat::RGBA_8888: + metadataFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::RGBA); + metadataFormat_.PutIntValue("max_input_size", MAX_RGB32_BUFFER_SIZE); + break; + default: + DHLOGE("The current pixel format does not support encoding."); + return DCAMERA_NOT_FOUND; + } + + metadataFormat_.PutStringValue("codec_mime", processType_); metadataFormat_.PutIntValue("width", sourceConfig_.GetWidth()); metadataFormat_.PutIntValue("height", sourceConfig_.GetHeight()); metadataFormat_.PutIntValue("frame_rate", MAX_FRAME_RATE); - processedConfig_ = sourceConfig_; - processedConfig_.SetVideoCodecType(VideoCodecType::NO_CODEC); - processedConfig_.SetVideoformat(Videoformat::NV12); return DCAMERA_OK; } @@ -709,8 +733,8 @@ void DecodeDataProcess::OnEvent(DCameraCodecEvent& ev) return; } - std::vector> yuvDataBuffers = receivedCodecPacket->GetDataBuffers(); - DecodeDone(yuvDataBuffers); + std::vector> dataBuffers = receivedCodecPacket->GetDataBuffers(); + DecodeDone(dataBuffers); break; } case VideoCodecAction::ACTION_ONCE_AGAIN: 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 d6c48932..1df51ba4 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 @@ -40,13 +40,13 @@ DecodeDataProcess::~DecodeDataProcess() int32_t DecodeDataProcess::InitNode(const VideoConfigParams& sourceConfig, const VideoConfigParams& targetConfig, VideoConfigParams& processedConfig) { - DHLOGD("Common Init DCamera DecodeNode start."); + DHLOGD("Init DCamera DecodeNode start."); if (!(IsInDecoderRange(sourceConfig) && IsInDecoderRange(targetConfig))) { - DHLOGE("Common Source config or target config are invalid."); + DHLOGE("Source config or target config are invalid."); return DCAMERA_BAD_VALUE; } if (!IsConvertible(sourceConfig, targetConfig)) { - DHLOGE("Common The DecodeNode can't convert %d to %d.", sourceConfig_.GetVideoCodecType(), + DHLOGE("The DecodeNode can't convert %d to %d.", sourceConfig.GetVideoCodecType(), targetConfig_.GetVideoCodecType()); return DCAMERA_BAD_TYPE; } @@ -65,7 +65,7 @@ int32_t DecodeDataProcess::InitNode(const VideoConfigParams& sourceConfig, const InitCodecEvent(); int32_t err = InitDecoder(); if (err != DCAMERA_OK) { - DHLOGE("Common Init video decoder fail."); + DHLOGE("Init video decoder failed."); ReleaseProcessNode(); return err; } @@ -90,12 +90,12 @@ bool DecodeDataProcess::IsConvertible(const VideoConfigParams& sourceConfig, con void DecodeDataProcess::InitCodecEvent() { - DHLOGD("Common Init DecodeNode eventBus, and add handler for it."); + DHLOGD("Init DecodeNode eventBus, and add handler for it."); eventBusDecode_ = std::make_shared("DeDtProcHandler"); DCameraCodecEvent codecEvent(*this, std::make_shared()); eventBusRegHandleDecode_ = eventBusDecode_->AddHandler(codecEvent.GetType(), *this); - DHLOGD("Common Add handler for DCamera pipeline eventBus."); + DHLOGD("Add handler for DCamera pipeline eventBus."); eventBusRegHandlePipeline2Decode_ = eventBusPipeline_->AddHandler(codecEvent.GetType(), *this); } @@ -157,18 +157,54 @@ int32_t DecodeDataProcess::ConfigureVideoDecoder() int32_t DecodeDataProcess::InitDecoderMetadataFormat() { - DHLOGD("Common Init video decoder metadata format."); - processType_ = "video/mp4v-es"; - metadataFormat_.PutStringValue("codec_mime", processType_); + DHLOGI("Init video decoder metadata format. codecType: %d", sourceConfig_.GetVideoCodecType()); + processedConfig_ = sourceConfig_; + processedConfig_.SetVideoCodecType(VideoCodecType::NO_CODEC); + 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."); + return DCAMERA_NOT_FOUND; + } + + DHLOGI("Init video decoder metadata format. videoformat: %d", processedConfig_.GetVideoformat()); + switch (processedConfig_.GetVideoformat()) { + case Videoformat::YUVI420: + metadataFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::YUVI420); + metadataFormat_.PutIntValue("max_input_size", MAX_YUV420_BUFFER_SIZE); + break; + case Videoformat::NV12: + metadataFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::NV12); + metadataFormat_.PutIntValue("max_input_size", MAX_YUV420_BUFFER_SIZE); + break; + case Videoformat::NV21: + metadataFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::NV21); + metadataFormat_.PutIntValue("max_input_size", MAX_YUV420_BUFFER_SIZE); + break; + case Videoformat::RGBA_8888: + metadataFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::RGBA); + metadataFormat_.PutIntValue("max_input_size", MAX_RGB32_BUFFER_SIZE); + break; + default: + DHLOGE("The current pixel format does not support encoding."); + return DCAMERA_NOT_FOUND; + } - metadataFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::RGBA); - metadataFormat_.PutIntValue("max_input_size", MAX_RGB32_BUFFER_SIZE); + metadataFormat_.PutStringValue("codec_mime", processType_); metadataFormat_.PutIntValue("width", sourceConfig_.GetWidth()); metadataFormat_.PutIntValue("height", sourceConfig_.GetHeight()); metadataFormat_.PutIntValue("frame_rate", MAX_FRAME_RATE); - processedConfig_ = sourceConfig_; - processedConfig_.SetVideoCodecType(VideoCodecType::NO_CODEC); return DCAMERA_OK; } @@ -182,33 +218,33 @@ int32_t DecodeDataProcess::SetDecoderOutputSurface() decodeConsumerSurface_ = Surface::CreateSurfaceAsConsumer(); if (decodeConsumerSurface_ == nullptr) { - DHLOGE("Creat the decode consumer surface fail."); + DHLOGE("Create the decode consumer surface failed."); return DCAMERA_INIT_ERR; } decodeConsumerSurface_->SetDefaultWidthAndHeight(static_cast(sourceConfig_.GetWidth()), - (int32_t)sourceConfig_.GetHeight()); + static_cast(sourceConfig_.GetHeight())); decodeSurfaceListener_ = new DecodeSurfaceListener(decodeConsumerSurface_, shared_from_this()); if (decodeConsumerSurface_->RegisterConsumerListener(decodeSurfaceListener_) != SURFACE_ERROR_OK) { - DHLOGE("Register consumer listener fail."); + DHLOGE("Register consumer listener failed."); return DCAMERA_INIT_ERR; } sptr surfaceProducer = decodeConsumerSurface_->GetProducer(); if (surfaceProducer == nullptr) { - DHLOGE("Get the surface producer of the decode consumer surface fail."); + DHLOGE("Get the surface producer of the decode consumer surface failed."); return DCAMERA_INIT_ERR; } decodeProducerSurface_ = Surface::CreateSurfaceAsProducer(surfaceProducer); if (decodeProducerSurface_ == nullptr) { - DHLOGE("Creat the decode producer surface of the decode consumer surface fail."); + DHLOGE("Create the decode producer surface of the decode consumer surface failed."); return DCAMERA_INIT_ERR; } DHLOGD("Set the producer surface to video decoder output surface."); int32_t err = videoDecoder_->SetOutputSurface(decodeProducerSurface_); if (err != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("Set decoder output surface fail."); + DHLOGE("Set decoder output surface failed."); return DCAMERA_INIT_ERR; } return DCAMERA_OK; @@ -234,7 +270,6 @@ int32_t DecodeDataProcess::StartVideoDecoder() return DCAMERA_OK; } - int32_t DecodeDataProcess::StopVideoDecoder() { if (videoDecoder_ == nullptr) { @@ -357,7 +392,7 @@ int32_t DecodeDataProcess::ProcessData(std::vector>& return DCAMERA_INDEX_OVERFLOW; } if (inputBuffers[0]->Size() > MAX_RGB32_BUFFER_SIZE) { - DHLOGE("DecodeNode input buffer size %d error.", inputBuffers[0]->Size()); + DHLOGE("DecodeNode input buffer size %zu error.", inputBuffers[0]->Size()); return DCAMERA_MEMORY_OPT_ERROR; } if (!isDecoderProcess_.load()) { @@ -365,12 +400,12 @@ int32_t DecodeDataProcess::ProcessData(std::vector>& return DCAMERA_DISABLE_PROCESS; } inputBuffersQueue_.push(inputBuffers[0]); - DHLOGD("Push inputBuffer sucess. BufSize %d, QueueSize %d.", inputBuffers[0]->Size(), inputBuffersQueue_.size()); + DHLOGD("Push inputBuf sucess. BufSize %zu, QueueSize %zu.", inputBuffers[0]->Size(), inputBuffersQueue_.size()); int32_t err = FeedDecoderInputBuffer(); if (err != DCAMERA_OK) { int32_t sleepTimeUs = 5000; std::this_thread::sleep_for(std::chrono::microseconds(sleepTimeUs)); - DHLOGD("Feed decoder input buffer fail. Try FeedDecoderInputBuffer again."); + DHLOGD("Feed decoder input buffer failed. Try FeedDecoderInputBuffer again."); std::shared_ptr reFeedInputPacket = std::make_shared(); reFeedInputPacket->SetVideoCodecType(sourceConfig_.GetVideoCodecType()); DCameraCodecEvent dCamCodecEv(*this, reFeedInputPacket, VideoCodecAction::ACTION_ONCE_AGAIN); @@ -389,7 +424,7 @@ int32_t DecodeDataProcess::FeedDecoderInputBuffer() while ((!inputBuffersQueue_.empty()) && (isDecoderProcess_.load())) { std::shared_ptr buffer = inputBuffersQueue_.front(); if (buffer == nullptr || availableInputIndexsQueue_.empty()) { - DHLOGE("inputBuffersQueue size %d, availableInputIndexsQueue size %d.", + DHLOGE("inputBuffersQueue size %zu, availableInputIndexsQueue size %zu.", inputBuffersQueue_.size(), availableInputIndexsQueue_.size()); return DCAMERA_BAD_VALUE; } @@ -403,7 +438,7 @@ int32_t DecodeDataProcess::FeedDecoderInputBuffer() uint32_t index = availableInputIndexsQueue_.front(); std::shared_ptr sharedMemoryInput = videoDecoder_->GetInputBuffer(index); if (sharedMemoryInput == nullptr) { - DHLOGE("Failed to obtain the input shared memory corresponding to the [%d] index.", index); + DHLOGE("Failed to obtain the input shared memory corresponding to the [%u] index.", index); return DCAMERA_BAD_VALUE; } size_t inputMemoDataSize = static_cast(sharedMemoryInput->GetSize()); @@ -413,7 +448,7 @@ int32_t DecodeDataProcess::FeedDecoderInputBuffer() return DCAMERA_MEMORY_OPT_ERROR; } int64_t timeUs = GetDecoderTimeStamp(); - DHLOGD("Decoder input buffer size %d, timeStamp %lld.", buffer->Size(), (long long)timeUs); + DHLOGD("Decoder input buffer size %zu, timeStamp %lld.", buffer->Size(), (long long)timeUs); Media::AVCodecBufferInfo bufferInfo {timeUs, static_cast(buffer->Size()), 0}; int32_t ret = videoDecoder_->QueueInputBuffer(index, bufferInfo, Media::AVCODEC_BUFFER_FLAG_NONE); @@ -426,7 +461,7 @@ int32_t DecodeDataProcess::FeedDecoderInputBuffer() inputBuffersQueue_.pop(); DHLOGD("Push inputBuffer sucess. inputBuffersQueue size is %d.", inputBuffersQueue_.size()); - IncreaseWaitDecodeCnt(); + IncreaseWaitDecodeCnt(); } return DCAMERA_OK; } @@ -512,12 +547,14 @@ void DecodeDataProcess::CopyDecodedImage(const sptr& surBuf, int6 DHLOGE("memcpy_s surface buffer failed."); return; } + bufferOutput->SetInt64("timeUs", timeStampUs); bufferOutput->SetInt32("Videoformat", static_cast(processedConfig_.GetVideoformat())); bufferOutput->SetInt32("alignedWidth", processedConfig_.GetWidth()); bufferOutput->SetInt32("alignedHeight", processedConfig_.GetHeight()); bufferOutput->SetInt32("width", processedConfig_.GetWidth()); bufferOutput->SetInt32("height", processedConfig_.GetHeight()); + PostOutputDataBuffers(bufferOutput); } @@ -566,7 +603,7 @@ int32_t DecodeDataProcess::DecodeDone(std::vector>& DHLOGD("Send to the next node of the decoder for processing."); int32_t err = nextDataProcess_->ProcessData(outputBuffers); if (err != DCAMERA_OK) { - DHLOGE("Someone node after the decoder processes fail."); + DHLOGE("Someone node after the decoder processes failed."); } return err; } @@ -592,8 +629,9 @@ void DecodeDataProcess::OnEvent(DCameraCodecEvent& ev) OnError(); return; } - std::vector> rgbDataBuffers = receivedCodecPacket->GetDataBuffers(); - DecodeDone(rgbDataBuffers); + + std::vector> dataBuffers = receivedCodecPacket->GetDataBuffers(); + DecodeDone(dataBuffers); break; } case VideoCodecAction::ACTION_ONCE_AGAIN: @@ -629,7 +667,7 @@ void DecodeDataProcess::OnInputBufferAvailable(uint32_t index) DHLOGE("Video decoder available indexs queue overflow."); return; } - DHLOGD("Video decoder available indexs queue push index [%d].", index); + DHLOGD("Video decoder available indexs queue push index [%u].", index); availableInputIndexsQueue_.push(index); } @@ -660,7 +698,7 @@ void DecodeDataProcess::OnOutputBufferAvailable(uint32_t index, const Media::AVC } int32_t errRelease = videoDecoder_->ReleaseOutputBuffer(index, true); if (errRelease != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("The video decoder output decoded data to surface fail, index : [%d].", index); + DHLOGE("The video decoder output decoded data to surface failed, index : [%u].", index); } } } diff --git a/services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process.cpp b/services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process.cpp index d578c0ef..f7d14d6e 100644 --- a/services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process.cpp +++ b/services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process.cpp @@ -167,46 +167,49 @@ int32_t EncodeDataProcess::ConfigureVideoEncoder() int32_t EncodeDataProcess::InitEncoderMetadataFormat() { - DHLOGD("Init video encoder metadata format."); - processedConfig_ = sourceConfig_; - switch (targetConfig_.GetVideoCodecType()) { case VideoCodecType::CODEC_H264: processType_ = "video/avc"; - metadataFormat_.PutStringValue("codec_mime", processType_); metadataFormat_.PutIntValue("codec_profile", Media::AVCProfile::AVC_PROFILE_BASELINE); - processedConfig_.SetVideoCodecType(VideoCodecType::CODEC_H264); break; case VideoCodecType::CODEC_H265: processType_ = "video/hevc"; - metadataFormat_.PutStringValue("codec_mime", processType_); metadataFormat_.PutIntValue("codec_profile", Media::HEVCProfile::HEVC_PROFILE_MAIN); - processedConfig_.SetVideoCodecType(VideoCodecType::CODEC_H265); break; + case VideoCodecType::CODEC_MPEG4_ES: + processType_ = "video/mp4v-es"; + metadataFormat_.PutIntValue("codec_profile", Media::MPEG4Profile::MPEG4_PROFILE_ADVANCED_CODING); + processedConfig_.SetVideoCodecType(VideoCodecType::CODEC_MPEG4_ES); + break; default: DHLOGE("The current codec type does not support encoding."); return DCAMERA_NOT_FOUND; } - switch (sourceConfig_.GetVideoformat()) { case Videoformat::YUVI420: metadataFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::YUVI420); + metadataFormat_.PutLongValue("max_input_size", NORM_YUV420_BUFFER_SIZE); break; case Videoformat::NV12: metadataFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::NV12); + metadataFormat_.PutLongValue("max_input_size", NORM_YUV420_BUFFER_SIZE); break; case Videoformat::NV21: metadataFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::NV21); + metadataFormat_.PutLongValue("max_input_size", NORM_YUV420_BUFFER_SIZE); + break; + case Videoformat::RGBA_8888: + metadataFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::RGBA); + metadataFormat_.PutLongValue("max_input_size", NORM_RGB32_BUFFER_SIZE); break; default: DHLOGE("The current pixel format does not support encoding."); return DCAMERA_NOT_FOUND; } - - metadataFormat_.PutLongValue("max_input_size", NORM_YUV420_BUFFER_SIZE); + metadataFormat_.PutStringValue("codec_mime", processType_); metadataFormat_.PutIntValue("width", static_cast(sourceConfig_.GetWidth())); metadataFormat_.PutIntValue("height", static_cast(sourceConfig_.GetHeight())); metadataFormat_.PutIntValue("frame_rate", MAX_FRAME_RATE); @@ -346,7 +349,6 @@ int32_t EncodeDataProcess::ProcessData(std::vector>& sourceConfig_.GetVideoCodecType(), processedConfig_.GetVideoCodecType()); return EncodeDone(inputBuffers); } - if (videoEncoder_ == nullptr) { DHLOGE("The video encoder does not exist before encoding data."); return DCAMERA_INIT_ERR; @@ -425,6 +427,9 @@ sptr EncodeDataProcess::GetEncoderInputSurfaceBuffer() case Videoformat::NV21: requestConfig.format = PixelFormat::PIXEL_FMT_YCRCB_420_SP; break; + case Videoformat::RGBA_8888: + requestConfig.format = PixelFormat::PIXEL_FMT_RGBA_8888; + break; default: DHLOGE("The current pixel format does not support encoding."); return nullptr; diff --git a/services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process_common.cpp b/services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process_common.cpp deleted file mode 100644 index c8f53ae3..00000000 --- a/services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process_common.cpp +++ /dev/null @@ -1,564 +0,0 @@ -/* - * Copyright (c) 2022 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 "encode_data_process.h" - -#include - -#include "distributed_hardware_log.h" -#include "graphic_common_c.h" - -#include "dcamera_hisysevent_adapter.h" -#include "dcamera_utils_tools.h" -#include "encode_video_callback.h" - -#ifndef DH_LOG_TAG -#define DH_LOG_TAG "DCDP_NODE_ENCODEC" -#endif - -namespace OHOS { -namespace DistributedHardware { -const std::map EncodeDataProcess::ENCODER_BITRATE_TABLE = { - std::map::value_type(WIDTH_320_HEIGHT_240, BITRATE_500000), - std::map::value_type(WIDTH_480_HEIGHT_360, BITRATE_1110000), - std::map::value_type(WIDTH_640_HEIGHT_360, BITRATE_1500000), - std::map::value_type(WIDTH_640_HEIGHT_480, BITRATE_1800000), - std::map::value_type(WIDTH_720_HEIGHT_540, BITRATE_2100000), - std::map::value_type(WIDTH_960_HEIGHT_540, BITRATE_2300000), - std::map::value_type(WIDTH_960_HEIGHT_720, BITRATE_2800000), - std::map::value_type(WIDTH_1280_HEIGHT_720, BITRATE_3400000), - std::map::value_type(WIDTH_1440_HEIGHT_1080, BITRATE_5000000), - std::map::value_type(WIDTH_1920_HEIGHT_1080, BITRATE_6000000), -}; -const std::string ENUM_VIDEOFORMAT_STRINGS[] = { - "YUVI420", "NV12", "NV21", "RGBA_8888" -}; - -EncodeDataProcess::~EncodeDataProcess() -{ - if (isEncoderProcess_.load()) { - DHLOGD("~EncodeDataProcess : ReleaseProcessNode."); - ReleaseProcessNode(); - } -} - -int32_t EncodeDataProcess::InitNode(const VideoConfigParams& sourceConfig, const VideoConfigParams& targetConfig, - VideoConfigParams& processedConfig) -{ - DHLOGD("Common Init DCamera EncodeNode start."); - if (!(IsInEncoderRange(sourceConfig) && IsInEncoderRange(targetConfig))) { - DHLOGE("Common Source config or target config are invalid."); - return DCAMERA_BAD_VALUE; - } - if (!IsConvertible(sourceConfig, targetConfig)) { - DHLOGE("Common The EncodeNode cannot convert source VideoCodecType %d to target VideoCodecType %d.", - sourceConfig.GetVideoCodecType(), targetConfig.GetVideoCodecType()); - return DCAMERA_BAD_TYPE; - } - - sourceConfig_ = sourceConfig; - targetConfig_ = targetConfig; - if (sourceConfig_.GetVideoCodecType() == targetConfig_.GetVideoCodecType()) { - DHLOGD("Common Disable EncodeNode. The target VideoCodecType %d is the same as the source VideoCodecType %d.", - sourceConfig_.GetVideoCodecType(), targetConfig_.GetVideoCodecType()); - processedConfig_ = sourceConfig; - processedConfig = processedConfig_; - isEncoderProcess_.store(true); - return DCAMERA_OK; - } - - int32_t err = InitEncoder(); - if (err != DCAMERA_OK) { - DHLOGE("Common Init video encoder failed."); - ReleaseProcessNode(); - return err; - } - processedConfig = processedConfig_; - isEncoderProcess_.store(true); - return DCAMERA_OK; -} - -bool EncodeDataProcess::IsInEncoderRange(const VideoConfigParams& curConfig) -{ - return (curConfig.GetWidth() >= MIN_VIDEO_WIDTH || curConfig.GetWidth() <= MAX_VIDEO_WIDTH || - curConfig.GetHeight() >= MIN_VIDEO_HEIGHT || curConfig.GetHeight() <= MAX_VIDEO_HEIGHT || - curConfig.GetFrameRate() >= MIN_FRAME_RATE || curConfig.GetFrameRate() <= MAX_FRAME_RATE); -} - -bool EncodeDataProcess::IsConvertible(const VideoConfigParams& sourceConfig, const VideoConfigParams& targetConfig) -{ - return (sourceConfig.GetVideoCodecType() == targetConfig.GetVideoCodecType() || - sourceConfig.GetVideoCodecType() == VideoCodecType::NO_CODEC); -} - -int32_t EncodeDataProcess::InitEncoder() -{ - DHLOGD("Common Init video encoder."); - int32_t ret = ConfigureVideoEncoder(); - if (ret != DCAMERA_OK) { - DHLOGE("Init video encoder metadata format failed. Error code %d.", ret); - return ret; - } - - ret = StartVideoEncoder(); - if (ret != DCAMERA_OK) { - DHLOGE("Start Video encoder failed."); - ReportDcamerOptFail(DCAMERA_OPT_FAIL, DCAMERA_ENCODE_ERROR, - CreateMsg("start video encoder failed, width: %d, height: %d, format: %s", sourceConfig_.GetWidth(), - sourceConfig_.GetHeight(), - ENUM_VIDEOFORMAT_STRINGS[static_cast(sourceConfig_.GetVideoformat())].c_str())); - return ret; - } - - return DCAMERA_OK; -} - -int32_t EncodeDataProcess::ConfigureVideoEncoder() -{ - int32_t ret = InitEncoderMetadataFormat(); - if (ret != DCAMERA_OK) { - DHLOGE("Init video encoder metadata format failed. Error code %d.", ret); - return ret; - } - ret = InitEncoderBitrateFormat(); - if (ret != DCAMERA_OK) { - DHLOGE("Init video encoder bitrate format failed. Error code %d.", ret); - return ret; - } - - videoEncoder_ = Media::VideoEncoderFactory::CreateByMime(processType_); - if (videoEncoder_ == nullptr) { - DHLOGE("Create video encoder failed."); - return DCAMERA_INIT_ERR; - } - encodeVideoCallback_ = std::make_shared(shared_from_this()); - ret = videoEncoder_->SetCallback(encodeVideoCallback_); - if (ret != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("Set video encoder callback failed. Error code %d.", ret); - return DCAMERA_INIT_ERR; - } - - ret = videoEncoder_->Configure(metadataFormat_); - if (ret != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("Set video encoder metadata format failed. Error code %d.", ret); - return DCAMERA_INIT_ERR; - } - - encodeProducerSurface_ = videoEncoder_->CreateInputSurface(); - if (encodeProducerSurface_ == nullptr) { - DHLOGE("Get video encoder producer surface failed."); - return DCAMERA_INIT_ERR; - } - - return DCAMERA_OK; -} - -int32_t EncodeDataProcess::InitEncoderMetadataFormat() -{ - DHLOGD("Common Init video encoder metadata format."); - - processedConfig_ = sourceConfig_; - - processType_ = "video/mp4v-es"; - metadataFormat_.PutStringValue("codec_mime", processType_); - metadataFormat_.PutIntValue("codec_profile", Media::MPEG4Profile::MPEG4_PROFILE_ADVANCED_CODING); - - processedConfig_.SetVideoCodecType(VideoCodecType::CODEC_MPEG4); - - metadataFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::RGBA); - metadataFormat_.PutLongValue("max_input_size", NORM_RGB32_BUFFER_SIZE); - metadataFormat_.PutIntValue("width", sourceConfig_.GetWidth()); - metadataFormat_.PutIntValue("height", sourceConfig_.GetHeight()); - metadataFormat_.PutIntValue("frame_rate", MAX_FRAME_RATE); - return DCAMERA_OK; -} - -int32_t EncodeDataProcess::InitEncoderBitrateFormat() -{ - DHLOGD("Init video encoder bitrate format."); - if (!(IsInEncoderRange(sourceConfig_) && IsInEncoderRange(targetConfig_))) { - DHLOGE("Source config or target config are invalid."); - return DCAMERA_BAD_VALUE; - } - metadataFormat_.PutIntValue("i_frame_interval", IDR_FRAME_INTERVAL_MS); - metadataFormat_.PutIntValue("video_encode_bitrate_mode", Media::VideoEncodeBitrateMode::VBR); - - if (ENCODER_BITRATE_TABLE.empty()) { - DHLOGD("ENCODER_BITRATE_TABLE is null, use the default bitrate of the encoder."); - return DCAMERA_OK; - } - int64_t pixelformat = static_cast(sourceConfig_.GetWidth() * sourceConfig_.GetHeight()); - int32_t matchedBitrate = BITRATE_6000000; - int64_t minPixelformatDiff = WIDTH_1920_HEIGHT_1080 - pixelformat; - for (auto it = ENCODER_BITRATE_TABLE.begin(); it != ENCODER_BITRATE_TABLE.end(); it++) { - int64_t pixelformatDiff = abs(pixelformat - it->first); - if (pixelformatDiff == 0) { - matchedBitrate = it->second; - break; - } - if (minPixelformatDiff >= pixelformatDiff) { - minPixelformatDiff = pixelformatDiff; - matchedBitrate = it->second; - } - } - DHLOGD("Source config: width : %d, height : %d, matched bitrate %d.", sourceConfig_.GetWidth(), - sourceConfig_.GetHeight(), matchedBitrate); - metadataFormat_.PutIntValue("bitrate", matchedBitrate); - return DCAMERA_OK; -} - -int32_t EncodeDataProcess::StartVideoEncoder() -{ - if (videoEncoder_ == nullptr) { - DHLOGE("The video encoder does not exist before StopVideoEncoder."); - return DCAMERA_BAD_VALUE; - } - - int32_t ret = videoEncoder_->Prepare(); - if (ret != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("Video encoder prepare failed. Error code %d.", ret); - return DCAMERA_INIT_ERR; - } - ret = videoEncoder_->Start(); - if (ret != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("Video encoder start failed. Error code %d.", ret); - return DCAMERA_INIT_ERR; - } - return DCAMERA_OK; -} - -int32_t EncodeDataProcess::StopVideoEncoder() -{ - if (videoEncoder_ == nullptr) { - DHLOGE("The video encoder does not exist before StopVideoEncoder."); - return DCAMERA_BAD_VALUE; - } - - bool isSuccess = true; - int32_t ret = videoEncoder_->Flush(); - if (ret != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("VideoEncoder flush failed. Error type: %d.", ret); - isSuccess = isSuccess && false; - } - ret = videoEncoder_->Stop(); - if (ret != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("VideoEncoder stop failed. Error type: %d.", ret); - isSuccess = isSuccess && false; - } - - if (!isSuccess) { - return DCAMERA_BAD_OPERATE; - } - return DCAMERA_OK; -} - -void EncodeDataProcess::ReleaseVideoEncoder() -{ - std::lock_guard lck(mtxEncoderState_); - DHLOGD("Start release videoEncoder."); - if (videoEncoder_ == nullptr) { - DHLOGE("The video encoder does not exist before ReleaseVideoEncoder."); - encodeProducerSurface_ = nullptr; - encodeVideoCallback_ = nullptr; - return; - } - int32_t ret = StopVideoEncoder(); - if (ret != DCAMERA_OK) { - DHLOGE("StopVideoEncoder failed."); - } - ret = videoEncoder_->Release(); - if (ret != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("VideoEncoder release failed. Error type: %d.", ret); - } - encodeProducerSurface_ = nullptr; - videoEncoder_ = nullptr; - encodeVideoCallback_ = nullptr; - DHLOGD("Start release videoEncoder success."); -} - -void EncodeDataProcess::ReleaseProcessNode() -{ - DHLOGD("Start release [%d] node : EncodeNode.", nodeRank_); - isEncoderProcess_.store(false); - ReleaseVideoEncoder(); - - waitEncoderOutputCount_ = 0; - lastFeedEncoderInputBufferTimeUs_ = 0; - inputTimeStampUs_ = 0; - processType_ = ""; - - if (nextDataProcess_ != nullptr) { - nextDataProcess_->ReleaseProcessNode(); - nextDataProcess_ = nullptr; - } - DHLOGD("Release [%d] node : EncodeNode end.", nodeRank_); -} - -int32_t EncodeDataProcess::ProcessData(std::vector>& inputBuffers) -{ - DHLOGD("Process data in EncodeDataProcess."); - if (inputBuffers.empty()) { - DHLOGE("The input data buffers is empty."); - return DCAMERA_BAD_VALUE; - } - if (sourceConfig_.GetVideoCodecType() == processedConfig_.GetVideoCodecType()) { - DHLOGD("The target VideoCodecType : %d is the same as the source VideoCodecType : %d.", - sourceConfig_.GetVideoCodecType(), processedConfig_.GetVideoCodecType()); - return EncodeDone(inputBuffers); - } - - if (videoEncoder_ == nullptr) { - DHLOGE("The video encoder does not exist before encoding data."); - return DCAMERA_INIT_ERR; - } - - if (inputBuffers[0]->Size() > NORM_RGB32_BUFFER_SIZE) { - DHLOGE("EncodeNode input buffer size %d error.", inputBuffers[0]->Size()); - return DCAMERA_MEMORY_OPT_ERROR; - } - if (!isEncoderProcess_.load()) { - DHLOGE("EncodeNode occurred error or start release."); - return DCAMERA_DISABLE_PROCESS; - } - int32_t err = FeedEncoderInputBuffer(inputBuffers[0]); - if (err != DCAMERA_OK) { - DHLOGE("Feed encoder input Buffer fail."); - return err; - } - return DCAMERA_OK; -} - -int32_t EncodeDataProcess::FeedEncoderInputBuffer(std::shared_ptr& inputBuffer) -{ - std::lock_guard lck(mtxEncoderState_); - DHLOGD("Feed encoder input buffer, buffer size %d.", inputBuffer->Size()); - if (encodeProducerSurface_ == nullptr) { - DHLOGE("Get encoder input producer surface failed."); - return DCAMERA_INIT_ERR; - } - - sptr surfacebuffer = GetEncoderInputSurfaceBuffer(); - if (surfacebuffer == nullptr) { - DHLOGE("Get encoder input producer surface buffer failed."); - return DCAMERA_BAD_OPERATE; - } - uint8_t *addr = static_cast(surfacebuffer->GetVirAddr()); - if (addr == nullptr) { - DHLOGE("SurfaceBuffer address is nullptr"); - encodeProducerSurface_->CancelBuffer(surfacebuffer); - return DCAMERA_BAD_OPERATE; - } - size_t size = static_cast(surfacebuffer->GetSize()); - errno_t err = memcpy_s(addr, size, inputBuffer->Data(), inputBuffer->Size()); - if (err != EOK) { - DHLOGE("memcpy_s encoder input producer surface buffer failed, surBufSize %z.", size); - return DCAMERA_MEMORY_OPT_ERROR; - } - - inputTimeStampUs_ = GetEncoderTimeStamp(); - DHLOGD("Encoder input buffer size %d, timeStamp %lld.", inputBuffer->Size(), (long long)inputTimeStampUs_); - surfacebuffer->GetExtraData()->ExtraSet("timeStamp", inputTimeStampUs_); - - BufferFlushConfig flushConfig = { {0, 0, sourceConfig_.GetWidth(), sourceConfig_.GetHeight()}, 0}; - SurfaceError ret = encodeProducerSurface_->FlushBuffer(surfacebuffer, -1, flushConfig); - if (ret != SURFACE_ERROR_OK) { - DHLOGE("Flush encoder input producer surface buffer failed."); - return DCAMERA_BAD_OPERATE; - } - return DCAMERA_OK; -} - -sptr EncodeDataProcess::GetEncoderInputSurfaceBuffer() -{ - BufferRequestConfig requestConfig; - requestConfig.width = sourceConfig_.GetWidth(); - requestConfig.height = sourceConfig_.GetHeight(); - requestConfig.usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA; - requestConfig.timeout = 0; - requestConfig.strideAlignment = ENCODER_STRIDE_ALIGNMENT; - requestConfig.format = PixelFormat::PIXEL_FMT_RGBA_8888; - sptr surfacebuffer = nullptr; - int32_t flushFence = -1; - GSError err = encodeProducerSurface_->RequestBuffer(surfacebuffer, flushFence, requestConfig); - if (err != GSERROR_OK || surfacebuffer == nullptr) { - DHLOGE("Request encoder input producer surface buffer failed, error code: %d.", err); - } - return surfacebuffer; -} - -int64_t EncodeDataProcess::GetEncoderTimeStamp() -{ - const int64_t nsPerUs = 1000L; - int64_t nowTimeUs = GetNowTimeStampUs() * nsPerUs; - return nowTimeUs; -} - -void EncodeDataProcess::IncreaseWaitEncodeCnt() -{ - std::lock_guard lck(mtxHoldCount_); - if (inputTimeStampUs_ == 0) { - waitEncoderOutputCount_ += FIRST_FRAME_OUTPUT_NUM; - } else { - waitEncoderOutputCount_++; - } - DHLOGD("Wait encoder output frames number is %d.", waitEncoderOutputCount_); -} - -void EncodeDataProcess::ReduceWaitEncodeCnt() -{ - std::lock_guard lck(mtxHoldCount_); - if (waitEncoderOutputCount_ <= 0) { - DHLOGE("The waitEncoderOutputCount_ = %d.", waitEncoderOutputCount_); - } - waitEncoderOutputCount_--; - DHLOGD("Wait encoder output frames number is %d.", waitEncoderOutputCount_); -} - -int32_t EncodeDataProcess::GetEncoderOutputBuffer(uint32_t index, Media::AVCodecBufferInfo info) -{ - DHLOGD("Get encoder output buffer."); - if (videoEncoder_ == nullptr) { - DHLOGE("The video encoder does not exist before output encoded data."); - return DCAMERA_BAD_VALUE; - } - std::shared_ptr sharedMemoryOutput = videoEncoder_->GetOutputBuffer(index); - if (sharedMemoryOutput == nullptr) { - DHLOGE("Failed to get the output shared memory, index : %d", index); - return DCAMERA_BAD_OPERATE; - } - - if (info.size <= 0 || info.size > DATABUFF_MAX_SIZE) { - DHLOGE("AVCodecBufferInfo error, buffer size : %d", info.size); - return DCAMERA_BAD_VALUE; - } - - size_t outputMemoDataSize = static_cast(info.size); - DHLOGD("Encoder output buffer size : %d", outputMemoDataSize); - std::shared_ptr bufferOutput = std::make_shared(outputMemoDataSize); - errno_t err = memcpy_s(bufferOutput->Data(), bufferOutput->Size(), - sharedMemoryOutput->GetBase(), outputMemoDataSize); - if (err != EOK) { - DHLOGE("memcpy_s buffer failed."); - return DCAMERA_MEMORY_OPT_ERROR; - } - bufferOutput->SetInt64("timeUs", info.presentationTimeUs); - - std::vector> nextInputBuffers; - nextInputBuffers.push_back(bufferOutput); - return EncodeDone(nextInputBuffers); -} - -int32_t EncodeDataProcess::EncodeDone(std::vector>& outputBuffers) -{ - DHLOGD("Encoder done."); - if (outputBuffers.empty()) { - DHLOGE("The received data buffers is empty."); - return DCAMERA_BAD_VALUE; - } - - if (nextDataProcess_ != nullptr) { - DHLOGD("Send to the next node of the encoder for processing."); - int32_t err = nextDataProcess_->ProcessData(outputBuffers); - if (err != DCAMERA_OK) { - DHLOGE("Someone node after the encoder processes fail."); - } - return err; - } - DHLOGD("The current node is the last node, and Output the processed video buffer"); - std::shared_ptr targetPipelineSink = callbackPipelineSink_.lock(); - if (targetPipelineSink == nullptr) { - DHLOGE("callbackPipelineSink_ is nullptr."); - return DCAMERA_BAD_VALUE; - } - targetPipelineSink->OnProcessedVideoBuffer(outputBuffers[0]); - return DCAMERA_OK; -} - -void EncodeDataProcess::OnError() -{ - DHLOGD("EncodeDataProcess : OnError."); - isEncoderProcess_.store(false); - if (videoEncoder_ != nullptr) { - videoEncoder_->Flush(); - videoEncoder_->Stop(); - } - std::shared_ptr targetPipelineSink = callbackPipelineSink_.lock(); - if (targetPipelineSink == nullptr) { - DHLOGE("callbackPipelineSink_ is nullptr."); - return; - } - targetPipelineSink->OnError(DataProcessErrorType::ERROR_PIPELINE_ENCODER); -} - -void EncodeDataProcess::OnInputBufferAvailable(uint32_t index) -{ - DHLOGD("The available input buffer index : %d. No operation when using surface input.", index); -} - -void EncodeDataProcess::OnOutputFormatChanged(const Media::Format &format) -{ - if (encodeOutputFormat_.GetFormatMap().empty()) { - DHLOGE("The first changed video encoder output format is null."); - return; - } - encodeOutputFormat_ = format; -} - -void EncodeDataProcess::OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info, - Media::AVCodecBufferFlag flag) -{ - if (!isEncoderProcess_.load()) { - DHLOGE("EncodeNode occurred error or start release."); - return; - } - DHLOGD("Video encode buffer info: presentation TimeUs %lld, size %d, offset %d, flag %d", - info.presentationTimeUs, info.size, info.offset, flag); - int32_t err = GetEncoderOutputBuffer(index, info); - if (err != DCAMERA_OK) { - DHLOGE("Get encode output Buffer fail."); - return; - } - if (videoEncoder_ == nullptr) { - DHLOGE("The video encoder does not exist before release output buffer index."); - return; - } - int32_t errRelease = videoEncoder_->ReleaseOutputBuffer(index); - if (errRelease != Media::MediaServiceErrCode::MSERR_OK) { - DHLOGE("The video encoder release output buffer fail, index : [%d].", index); - } -} -VideoConfigParams EncodeDataProcess::GetSourceConfig() const -{ - return sourceConfig_; -} - -VideoConfigParams EncodeDataProcess::GetTargetConfig() const -{ - return targetConfig_; -} - -int32_t EncodeDataProcess::GetProperty(const std::string& propertyName, PropertyCarrier& propertyCarrier) -{ - if (propertyName != surfaceStr_) { - return DCAMERA_OK; - } - if (encodeProducerSurface_ == nullptr) { - DHLOGD("EncodeDataProcess::GetProperty: encode dataProcess get property fail, encode surface is nullptr."); - return DCAMERA_BAD_VALUE; - } - return propertyCarrier.CarrySurfaceProperty(encodeProducerSurface_); -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/data_process/test/unittest/common/pipeline_node/decode_data_process_test.cpp b/services/data_process/test/unittest/common/pipeline_node/decode_data_process_test.cpp index 0c42bb4b..59a2840a 100644 --- a/services/data_process/test/unittest/common/pipeline_node/decode_data_process_test.cpp +++ b/services/data_process/test/unittest/common/pipeline_node/decode_data_process_test.cpp @@ -271,7 +271,7 @@ HWTEST_F(DecodeDataProcessTest, decode_data_process_test_008, TestSize.Level1) DHLOGI("DecodeDataProcessTest::decode_data_process_test_008."); EXPECT_EQ(false, testDecodeDataProcess_ == nullptr); - VideoConfigParams srcParams(VideoCodecType::CODEC_MPEG4, + VideoConfigParams srcParams(VideoCodecType::CODEC_MPEG4_ES, Videoformat::NV12, DCAMERA_PRODUCER_FPS_DEFAULT, TEST_WIDTH, @@ -282,19 +282,11 @@ HWTEST_F(DecodeDataProcessTest, decode_data_process_test_008, TestSize.Level1) TEST_WIDTH, TEST_HEIGTH); VideoConfigParams procConfig; -#ifdef DCAMERA_COMMON int32_t rc = testDecodeDataProcess_->InitNode(srcParams, destParams, procConfig); EXPECT_EQ(rc, DCAMERA_OK); rc = testDecodeDataProcess_->InitDecoderMetadataFormat(); EXPECT_EQ(rc, DCAMERA_OK); -#else - int32_t rc = testDecodeDataProcess_->InitNode(srcParams, destParams, procConfig); - EXPECT_EQ(rc, DCAMERA_NOT_FOUND); - - rc = testDecodeDataProcess_->InitDecoderMetadataFormat(); - EXPECT_EQ(rc, DCAMERA_NOT_FOUND); -#endif } /** diff --git a/services/data_process/test/unittest/common/pipeline_node/encode_data_process_test.cpp b/services/data_process/test/unittest/common/pipeline_node/encode_data_process_test.cpp index 51b610dc..9d7d1014 100644 --- a/services/data_process/test/unittest/common/pipeline_node/encode_data_process_test.cpp +++ b/services/data_process/test/unittest/common/pipeline_node/encode_data_process_test.cpp @@ -152,25 +152,17 @@ HWTEST_F(EncodeDataProcessTest, encode_data_process_test_004, TestSize.Level1) DCAMERA_PRODUCER_FPS_DEFAULT, TEST_WIDTH, TEST_HEIGTH); - VideoConfigParams destParams(VideoCodecType::CODEC_MPEG4, + VideoConfigParams destParams(VideoCodecType::CODEC_MPEG4_ES, Videoformat::NV21, DCAMERA_PRODUCER_FPS_DEFAULT, TEST_WIDTH2, TEST_HEIGTH2); VideoConfigParams procConfig; -#ifdef DCAMERA_COMMON int32_t rc = testEncodeDataProcess_->InitNode(srcParams, destParams, procConfig); EXPECT_EQ(rc, DCAMERA_OK); rc = testEncodeDataProcess_->InitEncoderMetadataFormat(); EXPECT_EQ(rc, DCAMERA_OK); -#else - int32_t rc = testEncodeDataProcess_->InitNode(srcParams, destParams, procConfig); - EXPECT_EQ(rc, DCAMERA_NOT_FOUND); - - rc = testEncodeDataProcess_->InitEncoderMetadataFormat(); - EXPECT_EQ(rc, DCAMERA_NOT_FOUND); -#endif } /** @@ -287,19 +279,11 @@ HWTEST_F(EncodeDataProcessTest, encode_data_process_test_008, TestSize.Level1) TEST_WIDTH2, TEST_HEIGTH2); VideoConfigParams procConfig; -#ifdef DCAMERA_COMMON int32_t rc = testEncodeDataProcess_->InitNode(srcParams, destParams, procConfig); EXPECT_EQ(rc, DCAMERA_OK); rc = testEncodeDataProcess_->InitEncoderMetadataFormat(); EXPECT_EQ(rc, DCAMERA_OK); -#else - int32_t rc = testEncodeDataProcess_->InitNode(srcParams, destParams, procConfig); - EXPECT_EQ(rc, DCAMERA_NOT_FOUND); - - rc = testEncodeDataProcess_->InitEncoderMetadataFormat(); - EXPECT_EQ(rc, DCAMERA_NOT_FOUND); -#endif } /** @@ -326,18 +310,6 @@ HWTEST_F(EncodeDataProcessTest, encode_data_process_test_009, TestSize.Level1) int32_t rc = testEncodeDataProcess_->InitNode(srcParams, destParams, procConfig); EXPECT_EQ(rc, DCAMERA_OK); -#ifdef DCAMERA_COMMON - constexpr int32_t NORM_RGB32_BUFFER_SIZE = 1920 * 1080 * 4; - size_t capacity = NORM_RGB32_BUFFER_SIZE + 5; - std::vector> inputBuffers; - std::shared_ptr db = std::make_shared(capacity); - size_t offset = 1; - size_t size = NORM_RGB32_BUFFER_SIZE + 1; - db->SetRange(offset, size); - inputBuffers.push_back(db); - rc = testEncodeDataProcess_->ProcessData(inputBuffers); - EXPECT_EQ(rc, DCAMERA_MEMORY_OPT_ERROR); -#else constexpr int64_t NORM_YUV420_BUFFER_SIZE = 1920 * 1080 * 3 / 2; size_t capacity = NORM_YUV420_BUFFER_SIZE + 5; std::vector> inputBuffers; @@ -348,7 +320,6 @@ HWTEST_F(EncodeDataProcessTest, encode_data_process_test_009, TestSize.Level1) inputBuffers.push_back(db); rc = testEncodeDataProcess_->ProcessData(inputBuffers); EXPECT_EQ(rc, DCAMERA_MEMORY_OPT_ERROR); -#endif } /** @@ -372,7 +343,6 @@ HWTEST_F(EncodeDataProcessTest, encode_data_process_test_010, TestSize.Level1) TEST_WIDTH, TEST_HEIGTH); VideoConfigParams procConfig; -#ifdef DCAMERA_COMMON int32_t rc = testEncodeDataProcess_->InitNode(srcParams, destParams, procConfig); EXPECT_EQ(rc, DCAMERA_OK); @@ -385,20 +355,6 @@ HWTEST_F(EncodeDataProcessTest, encode_data_process_test_010, TestSize.Level1) rc = testEncodeDataProcess_->FeedEncoderInputBuffer(db); EXPECT_EQ(rc, DCAMERA_OK); -#else - int32_t rc = testEncodeDataProcess_->InitNode(srcParams, destParams, procConfig); - EXPECT_EQ(rc, DCAMERA_NOT_FOUND); - - size_t capacity = 100; - std::vector> inputBuffers; - std::shared_ptr db = std::make_shared(capacity); - inputBuffers.push_back(db); - rc = testEncodeDataProcess_->ProcessData(inputBuffers); - EXPECT_EQ(rc, DCAMERA_INIT_ERR); - - rc = testEncodeDataProcess_->FeedEncoderInputBuffer(db); - EXPECT_EQ(rc, DCAMERA_INIT_ERR); -#endif } /** -- Gitee