diff --git a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp index 5f08742544daf0d6aaa5d0880c4d1404c9bc00e0..93f858a332bc663d0f56a9a1c3bcc23420b33cf2 100644 --- a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp +++ b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp @@ -214,19 +214,36 @@ int32_t DCameraClient::StopCapture() GetAnonyString(cameraId_).c_str(), ret); } DHLOGI("DCameraClient::StopCapture %s release videoOutput", GetAnonyString(cameraId_).c_str()); - videoOutput_->Release(); + ret = videoOutput_->Release(); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraClient::StopCapture videoOutput Release failed, cameraId: %s, ret: %d", + GetAnonyString(cameraId_).c_str(), ret); + } videoOutput_ = nullptr; } if (photoOutput_ != nullptr) { DHLOGI("DCameraClient::StopCapture %s release photoOutput", GetAnonyString(cameraId_).c_str()); - photoOutput_->Release(); + int32_t ret = photoOutput_->Release(); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraClient::StopCapture photoOutput Release failed, cameraId: %s, ret: %d", + GetAnonyString(cameraId_).c_str(), ret); + } photoOutput_ = nullptr; } ReleaseCaptureSession(); if (cameraInput_ != nullptr) { DHLOGI("DCameraClient::StopCapture %s release cameraInput", GetAnonyString(cameraId_).c_str()); - cameraInput_->Release(); + int32_t ret = cameraInput_->Close(); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraClient::StopCapture cameraInput Close failed, cameraId: %s, ret: %d", + 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); + } cameraInput_ = nullptr; } @@ -271,7 +288,11 @@ void DCameraClient::ReleaseCaptureSession() } cameraInput_->Close(); DHLOGI("DCameraClient::StopCapture %s release captureSession", GetAnonyString(cameraId_).c_str()); - captureSession_->Release(); + ret = captureSession_->Release(); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraClient::StopCapture captureSession Release failed, cameraId: %s, ret: %d", + GetAnonyString(cameraId_).c_str(), ret); + } captureSession_ = nullptr; } @@ -298,12 +319,17 @@ int32_t DCameraClient::SetResultCallback(std::shared_ptr& callba int32_t DCameraClient::ConfigCaptureSession(std::vector>& captureInfos) { DHLOGI("DCameraClient::ConfigCaptureSession cameraId: %s", GetAnonyString(cameraId_).c_str()); - cameraInput_ = cameraManager_->CreateCameraInput(cameraInfo_); - if (cameraInput_ == nullptr) { + int rv = cameraManager_->CreateCameraInput(cameraInfo_, &((sptr &)cameraInput_)); + if (rv != DCAMERA_OK) { DHLOGE("DCameraClient::ConfigCaptureSession %s create cameraInput failed", GetAnonyString(cameraId_).c_str()); return DCAMERA_BAD_VALUE; } - ((sptr &)cameraInput_)->Open(); + int32_t rc = ((sptr &)cameraInput_)->Open(); + if (rc != DCAMERA_OK) { + DHLOGE("DCameraClient::ConfigCaptureSession cameraInput_ Open failed, cameraId: %s, ret: %d", + GetAnonyString(cameraId_).c_str(), rc); + return DCAMERA_BAD_VALUE; + } std::shared_ptr inputCallback = std::make_shared(stateCallback_); ((sptr &)cameraInput_)->SetErrorCallback(inputCallback); @@ -319,8 +345,8 @@ int32_t DCameraClient::ConfigCaptureSession(std::vectorCreateCaptureSession(); - if (captureSession_ == nullptr) { + rv = cameraManager_->CreateCaptureSession(&captureSession_); + if (rv != DCAMERA_OK) { DHLOGE("DCameraClient::ConfigCaptureSession %s create captureSession failed", GetAnonyString(cameraId_).c_str()); return DCAMERA_BAD_VALUE; @@ -434,8 +460,9 @@ int32_t DCameraClient::CreatePhotoOutput(std::shared_ptr& in CameraStandard::CameraFormat photoFormat = ConvertToCameraFormat(info->format_); CameraStandard::Size photoSize = {info->width_, info->height_}; CameraStandard::Profile photoProfile(photoFormat, photoSize); - photoOutput_ = cameraManager_->CreatePhotoOutput(photoProfile, photoSurface_); - if (photoOutput_ == nullptr) { + int rv = cameraManager_->CreatePhotoOutput( + photoProfile, photoSurface_, &((sptr &)photoOutput_)); + if (rv != DCAMERA_OK) { DHLOGE("DCameraClient::CreatePhotoOutput %s create photo output failed", GetAnonyString(cameraId_).c_str()); return DCAMERA_BAD_VALUE; } @@ -458,9 +485,10 @@ int32_t DCameraClient::CreateVideoOutput(std::shared_ptr& in CameraStandard::CameraFormat videoFormat = ConvertToCameraFormat(info->format_); CameraStandard::Size videoSize = {info->width_, info->height_}; std::vector framerates = {}; - CameraStandard::VideoProfile videoProfile(videoFormat, videoSize, framerates); - videoOutput_ = cameraManager_->CreateVideoOutput(videoProfile, videoSurface_); - if (videoOutput_ == nullptr) { + CameraStandard::VideoProfile videoSettings(videoFormat, videoSize, framerates); + int rv = cameraManager_->CreateVideoOutput( + videoSettings, videoSurface_, &((sptr &)videoOutput_)); + if (rv != DCAMERA_OK) { DHLOGE("DCameraClient::CreateVideoOutput %s create video output failed", GetAnonyString(cameraId_).c_str()); return DCAMERA_BAD_VALUE; } diff --git a/services/cameraservice/cameraoperator/client/src/dcamera_client_common.cpp b/services/cameraservice/cameraoperator/client/src/dcamera_client_common.cpp index e8819cfbaa7f182654c3dcb2133c70e6cdd66803..0730ca2d8fd817a8db4f7633055f673a18a7ae3c 100644 --- a/services/cameraservice/cameraoperator/client/src/dcamera_client_common.cpp +++ b/services/cameraservice/cameraoperator/client/src/dcamera_client_common.cpp @@ -212,7 +212,16 @@ int32_t DCameraClient::StopCapture() if (cameraInput_ != nullptr) { DHLOGI("DCameraClientCommon::StopCapture %s release cameraInput", GetAnonyString(cameraId_).c_str()); - cameraInput_->Release(); + int32_t ret = cameraInput_->Close(); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraClientCommon::StopCapture %s cameraInput_ Close failed, ret: %d", + GetAnonyString(cameraId_).c_str(), ret); + } + ret = cameraInput_->Release(); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraClientCommon::StopCapture %s cameraInput_ Release failed, ret: %d", + GetAnonyString(cameraId_).c_str(), ret); + } cameraInput_ = nullptr; } @@ -259,7 +268,11 @@ void DCameraClient::ReleaseCaptureSession() } cameraInput_->Close(); DHLOGI("DCameraClientCommon::StopCapture %s release captureSession", GetAnonyString(cameraId_).c_str()); - captureSession_->Release(); + ret = captureSession_->Release(); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraClientCommon::StopCapture captureSession Release failed, cameraId: %s, ret: %d", + GetAnonyString(cameraId_).c_str(), ret); + } captureSession_ = nullptr; } @@ -288,13 +301,18 @@ int32_t DCameraClient::SetResultCallback(std::shared_ptr& callba int32_t DCameraClient::ConfigCaptureSession(std::vector>& captureInfos) { DHLOGI("DCameraClientCommon::ConfigCaptureSession cameraId: %s", GetAnonyString(cameraId_).c_str()); - cameraInput_ = cameraManager_->CreateCameraInput(cameraInfo_); - if (cameraInput_ == nullptr) { + int rv = cameraManager_->CreateCameraInput(cameraInfo_, &((sptr &)cameraInput_)); + if (rv != DCAMERA_OK) { DHLOGE("DCameraClientCommon::ConfigCaptureSession %s create cameraInput failed", GetAnonyString(cameraId_).c_str()); return DCAMERA_BAD_VALUE; } - ((sptr &)cameraInput_)->Open(); + int32_t rc = ((sptr &)cameraInput_)->Open(); + if (rc != DCAMERA_OK) { + DHLOGE("DCameraClientCommon::ConfigCaptureSession %s cameraInput_ Open failed, ret: %d", + GetAnonyString(cameraId_).c_str(), rc); + return DCAMERA_BAD_VALUE; + } std::shared_ptr inputCallback = std::make_shared(stateCallback_); ((sptr &)cameraInput_)->SetErrorCallback(inputCallback); @@ -310,8 +328,8 @@ int32_t DCameraClient::ConfigCaptureSession(std::vectorCreateCaptureSession(); - if (captureSession_ == nullptr) { + rv = cameraManager_->CreateCaptureSession(&captureSession_); + if (rv != DCAMERA_OK) { DHLOGE("DCameraClientCommon::ConfigCaptureSession %s create captureSession failed", GetAnonyString(cameraId_).c_str()); return DCAMERA_BAD_VALUE; @@ -426,8 +444,9 @@ int32_t DCameraClient::CreatePhotoOutput(std::shared_ptr& in CameraStandard::CameraFormat photoFormat = ConvertToCameraFormat(info->format_); CameraStandard::Size photoSize = {info->width_, info->height_}; CameraStandard::Profile photoProfile(photoFormat, photoSize); - photoOutput_ = cameraManager_->CreatePhotoOutput(photoProfile, photoSurface_); - if (photoOutput_ == nullptr) { + int rv = cameraManager_->CreatePhotoOutput( + photoProfile, photoSurface_, &((sptr &)photoOutput_)); + if (rv != DCAMERA_OK) { DHLOGE("DCameraClientCommon::CreatePhotoOutput %s create photo output failed", GetAnonyString(cameraId_).c_str()); return DCAMERA_BAD_VALUE; @@ -451,8 +470,9 @@ int32_t DCameraClient::CreateVideoOutput(std::shared_ptr& in CameraStandard::CameraFormat previewFormat = ConvertToCameraFormat(info->format_); CameraStandard::Size previewSize = {info->width_, info->height_}; CameraStandard::Profile previewProfile(previewFormat, previewSize); - previewOutput_ = cameraManager_->CreatePreviewOutput(previewProfile, videoSurface_); - if (previewOutput_ == nullptr) { + int rv = cameraManager_->CreatePreviewOutput( + previewProfile, videoSurface_, &((sptr &)previewOutput_)); + if (rv != DCAMERA_OK) { DHLOGE("DCameraClientCommon::CreatePreviewOutput %s create preview output failed", GetAnonyString(cameraId_).c_str()); return DCAMERA_BAD_VALUE; diff --git a/services/cameraservice/cameraoperator/client/test/sample/main.cpp b/services/cameraservice/cameraoperator/client/test/sample/main.cpp index ffc5918738fba8497915a58137d07c8f57e478c1..455a6b7e565f332b79cb1d5c9578c2f3d2cc5970 100644 --- a/services/cameraservice/cameraoperator/client/test/sample/main.cpp +++ b/services/cameraservice/cameraoperator/client/test/sample/main.cpp @@ -64,8 +64,14 @@ static int32_t InitCameraStandard() g_cameraManager = CameraManager::GetInstance(); g_cameraManager->SetCallback(std::make_shared()); - g_captureSession = g_cameraManager->CreateCaptureSession(); - g_captureSession->SetCallback(std::make_shared()); + int rv = g_cameraManager->CreateCaptureSession(&g_captureSession); + if (rv != DCAMERA_OK) { + DHLOGE("InitCameraStandard create captureSession failed, rv: %d", rv); + return rv; + } + std::shared_ptr sessionCallback = std::make_shared(); + g_captureSession->SetCallback(sessionCallback); + g_captureSession->SetFocusCallback(sessionCallback); std::vector> cameraObjList = g_cameraManager->GetSupportedCameras(); for (auto info : cameraObjList) { @@ -84,8 +90,16 @@ static int32_t InitCameraStandard() return DCAMERA_BAD_VALUE; } - g_cameraInput = g_cameraManager->CreateCameraInput(g_cameraInfo); - ((sptr &)g_cameraInput)->Open(); + rv = g_cameraManager->CreateCameraInput(g_cameraInfo, &((sptr &)g_cameraInput)); + if (rv != DCAMERA_OK) { + DHLOGE("InitCameraStandard create cameraInput failed, rv: %d", rv); + return rv; + } + int32_t ret = ((sptr &)g_cameraInput)->Open(); + if (ret != DCAMERA_OK) { + DHLOGE("InitCameraStandard g_cameraInput Open failed, ret: %d", ret); + return ret; + } std::shared_ptr inputCallback = std::make_shared(); ((sptr &)g_cameraInput)->SetErrorCallback(inputCallback); g_captureSession->SetFocusCallback(std::make_shared()); @@ -145,7 +159,11 @@ static void InitPhotoOutput() CameraFormat photoFormat = ConvertToCameraFormat(g_photoInfo->format_); Size photoSize = {g_photoInfo->width_, g_photoInfo->height_}; Profile photoProfile(photoFormat, photoSize); - g_photoOutput = g_cameraManager->CreatePhotoOutput(photoProfile, photoSurface); + int rv = g_cameraManager->CreatePhotoOutput(photoProfile, photoSurface, &((sptr &)g_photoOutput)); + if (rv != DCAMERA_OK) { + DHLOGE("InitPhotoOutput create photoOutput failed, rv: %d", rv); + return; + } ((sptr &)g_photoOutput)->SetCallback(std::make_shared()); } @@ -161,7 +179,12 @@ static void InitPreviewOutput() CameraFormat previewFormat = ConvertToCameraFormat(g_previewInfo->format_); Size previewSize = {g_previewInfo->width_, g_previewInfo->height_}; Profile previewProfile(previewFormat, previewSize); - g_previewOutput = g_cameraManager->CreatePreviewOutput(previewProfile, previewSurface); + int rv = g_cameraManager->CreatePreviewOutput( + previewProfile, previewSurface, &((sptr &)g_previewOutput)); + if (rv != DCAMERA_OK) { + DHLOGE("InitPhotoOutput create previewOutput failed, rv: %d", rv); + return; + } ((sptr &)g_previewOutput)->SetCallback(std::make_shared()); } @@ -177,8 +200,12 @@ static void InitVideoOutput() CameraFormat videoFormat = ConvertToCameraFormat(g_videoInfo->format_); Size videoSize = {g_videoInfo->width_, g_videoInfo->height_}; std::vector framerates = {}; - VideoProfile videoProfile(videoFormat, videoSize, framerates); - g_videoOutput = g_cameraManager->CreateVideoOutput(videoProfile, videoSurface); + VideoProfile videoSettings(videoFormat, videoSize, framerates); + int rv = g_cameraManager->CreateVideoOutput(videoSettings, videoSurface, &((sptr &)g_videoOutput)); + if (rv != DCAMERA_OK) { + DHLOGE("InitPhotoOutput create videoOutput failed, rv: %d", rv); + return; + } ((sptr &)g_videoOutput)->SetCallback(std::make_shared()); } @@ -191,9 +218,17 @@ static void ConfigCaptureSession() g_captureSession->AddOutput(g_photoOutput); g_captureSession->CommitConfig(); - std::vector stabilizationModes = g_captureSession->GetSupportedStabilizationMode(); - for (auto mode : stabilizationModes) { - DHLOGI("Distributed Camera Demo: video stabilization mode %d", mode); + std::vector stabilizationModes; + int32_t rv = g_captureSession->GetSupportedStabilizationMode(stabilizationModes); + if (rv != DCAMERA_OK) { + DHLOGE("ConfigCaptureSession get supported stabilization mode failed, rv: %d", rv); + return; + } + if (!stabilizationModes.empty()) { + for (auto mode : stabilizationModes) { + DHLOGI("Distributed Camera Demo: video stabilization mode %d", mode); + } + g_captureSession->SetVideoStabilizationMode(stabilizationModes.back()); } g_captureSession->SetVideoStabilizationMode(stabilizationModes.back()); } @@ -204,7 +239,12 @@ static void ConfigFocusAndExposure() FocusMode focusMode = FOCUS_MODE_CONTINUOUS_AUTO; ExposureMode exposureMode = EXPOSURE_MODE_AUTO; int32_t exposureValue = 0; - std::vector biasRange = g_captureSession->GetExposureBiasRange(); + std::vector biasRange; + int32_t rv = g_captureSession->GetExposureBiasRange(biasRange); + if (rv != DCAMERA_OK) { + DHLOGE("ConfigFocusAndExposure get exposure bias range failed, rv: %d", rv); + return; + } if (!biasRange.empty()) { DHLOGI("Distributed Camera Demo: get %d exposure compensation range", biasRange.size()); exposureValue = biasRange[0]; @@ -330,7 +370,9 @@ int main() g_captureSession->Start(); sleep(SLEEP_FIVE_SECOND); - ((sptr &)g_videoOutput)->Start(); + if (((sptr &)g_videoOutput)->Start() != DCAMERA_OK) { + DHLOGE("main g_videoOutput Start failed"); + } sleep(SLEEP_FIVE_SECOND); ConfigFocusAndExposure(); @@ -339,13 +381,19 @@ int main() ((sptr &)g_photoOutput)->Capture(ConfigPhotoCaptureSetting()); sleep(SLEEP_TWENTY_SECOND); - ((sptr &)g_videoOutput)->Stop(); + if (((sptr &)g_videoOutput)->Stop() != DCAMERA_OK) { + DHLOGE("main g_videoOutput Stop failed"); + } sleep(SLEEP_FIVE_SECOND); g_captureSession->Stop(); - g_cameraInput->Close(); + if (g_cameraInput->Close() != DCAMERA_OK) { + DHLOGE("main g_cameraInput Close failed"); + } g_captureSession->Release(); - g_cameraInput->Release(); + if (g_cameraInput->Release() != DCAMERA_OK) { + DHLOGE("main g_cameraInput Close failed"); + } DHLOGI("========== Distributed Camera Demo End =========="); return 0; } \ No newline at end of file diff --git a/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp b/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp index ae04982b02536244cd9bcf155f14b70707f61d7c..e85b736a413ae1dd91754325ea4e01c64675aad1 100644 --- a/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp +++ b/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp @@ -161,8 +161,9 @@ int32_t DCameraHandler::CreateDHItem(sptr& info, D std::vector previewProfiles = capability->GetPreviewProfiles(); ConfigFormatAndResolution(CONTINUOUS_FRAME, root, previewProfiles); - sptr cameraInput = cameraManager_->CreateCameraInput(info); - if (cameraInput == nullptr) { + sptr cameraInput = nullptr; + int rv = cameraManager_->CreateCameraInput(info, &cameraInput); + if (rv != DCAMERA_OK) { DHLOGE("DCameraHandler::CreateDHItem create cameraInput failed"); return DCAMERA_BAD_VALUE; } @@ -179,7 +180,9 @@ int32_t DCameraHandler::CreateDHItem(sptr& info, D root[CAMERA_METADATA_KEY] = Json::Value(encodeString); item.attrs = root.toStyledString(); - cameraInput->Release(); + if (cameraInput->Release() != DCAMERA_OK) { + DHLOGE("DCameraHandler::CreateDHItem cameraInput Release failed"); + } return DCAMERA_OK; } diff --git a/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp b/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp index 84a118deb3c77a134a2d1430fd5a928d70994fe1..61c50294a4332003212a3376426f2606ef9ab1fa 100644 --- a/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp +++ b/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp @@ -142,8 +142,9 @@ int32_t DCameraHandler::CreateDHItem(sptr& info, D root[CAMERA_POSITION_KEY] = Json::Value(GetCameraPosition(info->GetPosition())); root[CAMERA_CODEC_TYPE_KEY].append("OMX_hisi_video_encoder_avc"); - sptr cameraInput = cameraManager_->CreateCameraInput(info); - if (cameraInput == nullptr) { + sptr cameraInput = nullptr; + int rv = cameraManager_->CreateCameraInput(info, &cameraInput); + if (rv != DCAMERA_OK) { DHLOGE("DCameraHandlerCommon::CreateDHItem create cameraInput failed"); return DCAMERA_BAD_VALUE; } @@ -171,7 +172,9 @@ int32_t DCameraHandler::CreateDHItem(sptr& info, D root[CAMERA_METADATA_KEY] = Json::Value(encodeString); item.attrs = root.toStyledString(); - cameraInput->Release(); + if (cameraInput->Release() != DCAMERA_OK) { + DHLOGE("DCameraHandlerCommon::CreateDHItem cameraInput Release failed"); + } return DCAMERA_OK; }