From 75688dc296d0122af65d9c6c76b5c4a0a2f4dc12 Mon Sep 17 00:00:00 2001 From: Kishore Date: Thu, 2 Sep 2021 19:32:46 +0530 Subject: [PATCH] Dynamic size support is added in camera service Signed-off-by: Kishore --- .../camera/src/input/camera_manager.cpp | 19 ++ .../camera/src/output/photo_output.cpp | 5 +- .../camera/test/src/camera_framework_test.cpp | 62 +++-- .../kitsimpl/camera_napi/src/camera_napi.cpp | 214 +++++++++--------- .../camera/include/input/camera_manager.h | 5 +- .../innerkits/native/test/camera_capture.cpp | 84 +++++-- .../innerkits/native/test/camera_video.cpp | 109 ++++++--- .../kits/js/camera_napi/include/camera_napi.h | 6 +- .../binder/base/include/icamera_service.h | 3 + .../binder/base/include/remote_request_code.h | 1 + .../client/include/hcamera_service_proxy.h | 3 + .../client/src/hcamera_service_proxy.cpp | 41 +++- .../server/include/hcamera_service_stub.h | 1 + .../server/src/hcamera_service_stub.cpp | 28 +++ services/camera_service/include/camera_util.h | 35 ++- .../camera_service/include/hcamera_service.h | 2 + .../camera_service/include/hstream_capture.h | 1 + .../camera_service/include/hstream_repeat.h | 5 + services/camera_service/src/camera_util.cpp | 13 +- .../camera_service/src/hcamera_service.cpp | 21 +- .../camera_service/src/hcapture_session.cpp | 23 +- .../camera_service/src/hstream_capture.cpp | 7 +- .../camera_service/src/hstream_repeat.cpp | 39 +++- 23 files changed, 507 insertions(+), 220 deletions(-) diff --git a/frameworks/innerkitsimpl/camera/src/input/camera_manager.cpp b/frameworks/innerkitsimpl/camera/src/input/camera_manager.cpp index 3cffec2c8..fdb97d16e 100644 --- a/frameworks/innerkitsimpl/camera/src/input/camera_manager.cpp +++ b/frameworks/innerkitsimpl/camera/src/input/camera_manager.cpp @@ -157,6 +157,25 @@ sptr CameraManager::CreatePreviewOutput(sptr surface) return result; } +sptr CameraManager::CreateCustomPreviewOutput(sptr surface, int32_t width, int32_t height) +{ + sptr streamRepeat = nullptr; + sptr result = nullptr; + int32_t retCode = CAMERA_OK; + + if (serviceProxy_ == nullptr || surface == nullptr || width == 0 || height == 0) { + MEDIA_ERR_LOG("CameraManager::CreatePreviewOutput serviceProxy_ is null or surface is null or invalid size"); + return nullptr; + } + retCode = serviceProxy_->CreateCustomPreviewOutput(surface->GetProducer(), width, height, streamRepeat); + if (retCode == CAMERA_OK) { + result = new PreviewOutput(streamRepeat); + } else { + MEDIA_ERR_LOG("PreviewOutput: Failed to get stream repeat object from hcamera service!, %{public}d", retCode); + } + return result; +} + sptr CameraManager::CreateVideoOutput(sptr &surface) { sptr streamRepeat = nullptr; diff --git a/frameworks/innerkitsimpl/camera/src/output/photo_output.cpp b/frameworks/innerkitsimpl/camera/src/output/photo_output.cpp index fcf45e353..651fc2414 100644 --- a/frameworks/innerkitsimpl/camera/src/output/photo_output.cpp +++ b/frameworks/innerkitsimpl/camera/src/output/photo_output.cpp @@ -102,11 +102,12 @@ public: } }; -void PhotoCaptureSetting::SetMirror(bool enable){ +void PhotoCaptureSetting::SetMirror(bool enable) +{ return; } -PhotoOutput::PhotoOutput (sptr &streamCapture) +PhotoOutput::PhotoOutput(sptr &streamCapture) : CaptureOutput(CAPTURE_OUTPUT_TYPE::PHOTO_OUTPUT), streamCapture_(streamCapture) { } diff --git a/frameworks/innerkitsimpl/camera/test/src/camera_framework_test.cpp b/frameworks/innerkitsimpl/camera/test/src/camera_framework_test.cpp index e4612bd47..2f47fe302 100644 --- a/frameworks/innerkitsimpl/camera/test/src/camera_framework_test.cpp +++ b/frameworks/innerkitsimpl/camera/test/src/camera_framework_test.cpp @@ -14,6 +14,7 @@ */ #include "camera_framework_test.h" +#include #include #include #include @@ -38,6 +39,12 @@ enum mode_ { MODE_PHOTO }; +enum SaveVideoMode { + CREATE = 0, + APPEND, + CLOSE +}; + enum CAM_PHOTO_EVENTS { CAM_PHOTO_CAPTURE_START = 0, CAM_PHOTO_CAPTURE_END, @@ -60,17 +67,24 @@ enum CAM_VIDEO_EVENTS { CAM_VIDEO_MAX_EVENT }; - -static std::bitset g_photoEvents; -static std::bitset g_previewEvents; -static std::bitset g_videoEvents; -static std::unordered_map g_camStatusMap; -static std::unordered_map g_camFlashMap; -static bool g_camInputOnError = false; -static int32_t g_videoFd = -1; -static const int WAIT_TIME_AFTER_START = 5; -static const int WAIT_TIME_BEFORE_STOP = 2; - +namespace { + static std::bitset g_photoEvents; + static std::bitset g_previewEvents; + static std::bitset g_videoEvents; + static std::unordered_map g_camStatusMap; + static std::unordered_map g_camFlashMap; + static bool g_camInputOnError = false; + static int32_t g_videoFd = -1; + static const int WAIT_TIME_AFTER_START = 5; + static const int WAIT_TIME_BEFORE_STOP = 2; + static const std::int32_t PHOTO_DEFAULT_WIDTH = 1280; + static const std::int32_t PHOTO_DEFAULT_HEIGHT = 960; + static const std::int32_t PREVIEW_DEFAULT_WIDTH = 640; + static const std::int32_t PREVIEW_DEFAULT_HEIGHT = 480; + static const std::int32_t VIDEO_DEFAULT_WIDTH = 1280; + static const std::int32_t VIDEO_DEFAULT_HEIGHT = 720; + static const std::int32_t FILE_PERMISSION_FLAG = 00766; +} void CameraFrameworkTest::SetUpTestCase(void) {} void CameraFrameworkTest::TearDownTestCase(void) {} @@ -114,7 +128,7 @@ static int32_t SaveYUV(int32_t mode, const char *buffer, int32_t size) } MEDIA_DEBUG_LOG("%s, saving file to %{public}s", __FUNCTION__, path); - int imgFd = open(path, O_RDWR | O_CREAT, 00766); + int imgFd = open(path, O_RDWR | O_CREAT, FILE_PERMISSION_FLAG); if (imgFd == -1) { MEDIA_DEBUG_LOG("%s, open file failed, errno = %{public}s.", __FUNCTION__, strerror(errno)); return -1; @@ -131,7 +145,7 @@ static int32_t SaveYUV(int32_t mode, const char *buffer, int32_t size) static int32_t SaveVideoFile(const char *buffer, int32_t size, int32_t operationMode) { - if (operationMode == 0) { + if (operationMode == CREATE) { char path[255] = {0}; system("mkdir -p /mnt/video"); int32_t retlen = sprintf_s(path, sizeof(path) / sizeof(path[0]), "/mnt/video/%s_%lld.h264", @@ -141,12 +155,12 @@ static int32_t SaveVideoFile(const char *buffer, int32_t size, int32_t operation return -1; } MEDIA_DEBUG_LOG("%s, save video to file %s", __FUNCTION__, path); - g_videoFd = open(path, O_RDWR | O_CREAT, 00766); + g_videoFd = open(path, O_RDWR | O_CREAT, FILE_PERMISSION_FLAG); if (g_videoFd == -1) { std::cout << "open file failed, errno = " << strerror(errno) << std::endl; return -1; } - } else if (operationMode == 1 && g_videoFd != -1) { + } else if (operationMode == APPEND && g_videoFd != -1) { int32_t ret = write(g_videoFd, buffer, size); if (ret == -1) { std::cout << "write file failed, error = " << strerror(errno) << std::endl; @@ -164,7 +178,7 @@ static int32_t SaveVideoFile(const char *buffer, int32_t size, int32_t operation class AppCallback : public CameraManagerCallback, public ErrorCallback, public PhotoCallback, public PreviewCallback { public: - void OnCameraStatusChanged(const std::string cameraID, const CameraDeviceStatus cameraStatus) const override + void OnCameraStatusChanged(const std::string &cameraID, const CameraDeviceStatus cameraStatus) const override { switch (cameraStatus) { case CAMERA_DEVICE_STATUS_UNAVAILABLE: { @@ -187,7 +201,7 @@ public: return; } - void OnFlashlightStatusChanged(const std::string cameraID, const FlashlightStatus flashStatus) const override + void OnFlashlightStatusChanged(const std::string &cameraID, const FlashlightStatus flashStatus) const override { switch (flashStatus) { case FLASHLIGHT_STATUS_OFF: { @@ -239,7 +253,8 @@ public: void OnFrameShutter(const int32_t captureId, const uint64_t timestamp) const override { - MEDIA_DEBUG_LOG("AppCallback::OnFrameShutter captureId: %{public}d", captureId); + MEDIA_DEBUG_LOG("AppCallback::OnFrameShutter captureId: %{public}d, timestamp: %{public}" + PRIu64, captureId, timestamp); g_photoEvents[CAM_PHOTO_FRAME_SHUTTER] = 1; return; } @@ -326,7 +341,7 @@ public: { if (g_videoFd == -1) { // Create video file - SaveVideoFile(nullptr, 0, 0); + SaveVideoFile(nullptr, 0, CREATE); } int32_t flushFence = 0; int64_t timestamp = 0; @@ -338,7 +353,7 @@ public: char *addr = static_cast(buffer->GetVirAddr()); int32_t size = buffer->GetSize(); MEDIA_DEBUG_LOG("Saving to video file"); - SaveVideoFile(addr, size, 1); + SaveVideoFile(addr, size, APPEND); surface_->ReleaseBuffer(buffer, -1); } else { MEDIA_DEBUG_LOG("AcquireBuffer failed!"); @@ -373,6 +388,7 @@ public: static sptr CreatePhotoOutput(sptr &camManagerObj) { sptr photoSurface = Surface::CreateSurfaceAsConsumer(); + photoSurface->SetDefaultWidthAndHeight(PHOTO_DEFAULT_WIDTH, PHOTO_DEFAULT_HEIGHT); sptr capturelistener = new CaptureSurfaceListener(); capturelistener->mode_ = MODE_PHOTO; capturelistener->surface_ = photoSurface; @@ -384,6 +400,7 @@ static sptr CreatePhotoOutput(sptr &camManagerObj) static sptr CreatePreviewOutput(sptr &camManagerObj) { sptr previewSurface = Surface::CreateSurfaceAsConsumer(); + previewSurface->SetDefaultWidthAndHeight(PREVIEW_DEFAULT_WIDTH, PREVIEW_DEFAULT_HEIGHT); sptr listener = new SurfaceListener(); listener->mode_ = MODE_PREVIEW; listener->surface_ = previewSurface; @@ -395,6 +412,7 @@ static sptr CreatePreviewOutput(sptr &camManagerOb static sptr CreateVideoOutput(sptr &camManagerObj) { sptr videoSurface = Surface::CreateSurfaceAsConsumer(); + videoSurface->SetDefaultWidthAndHeight(VIDEO_DEFAULT_WIDTH, VIDEO_DEFAULT_HEIGHT); sptr videoListener = new VideoSurfaceListener(); videoListener->surface_ = videoSurface; videoSurface->RegisterConsumerListener((sptr &)videoListener); @@ -550,7 +568,7 @@ HWTEST_F(CameraFrameworkTest, media_camera_framework_test_003, TestSize.Level1) captureSession->Stop(); captureSession->Release(); - SaveVideoFile(nullptr, 0, 2); + SaveVideoFile(nullptr, 0, CLOSE); } void TestCallbacks(bool video) @@ -668,7 +686,7 @@ void TestCallbacks(bool video) } if (videoOutput != nullptr) { - SaveVideoFile(nullptr, 0, 2); + SaveVideoFile(nullptr, 0, CLOSE); EXPECT_TRUE(g_videoEvents[CAM_VIDEO_FRAME_START] == 1); diff --git a/frameworks/kitsimpl/camera_napi/src/camera_napi.cpp b/frameworks/kitsimpl/camera_napi/src/camera_napi.cpp index a6fa66a59..fc1b79288 100644 --- a/frameworks/kitsimpl/camera_napi/src/camera_napi.cpp +++ b/frameworks/kitsimpl/camera_napi/src/camera_napi.cpp @@ -37,6 +37,8 @@ napi_ref CameraNapi::parameterResultRef_ = nullptr; namespace { constexpr HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "CameraNapi"}; + const int ARGS_TWO = 2; + const int ARGS_THREE = 3; } struct CameraNapiAsyncContext { @@ -422,7 +424,7 @@ static std::string GetStringArgument(napi_env env, napi_value value) status = napi_get_value_string_utf8(env, value, nullptr, 0, &bufLength); if (status == napi_ok && bufLength > 0) { // Create a buffer and create std::string later from it - buffer = (char *) malloc((bufLength + 1) * sizeof(char)); + buffer = (char *)malloc((bufLength + 1) * sizeof(char)); if (buffer != nullptr) { status = napi_get_value_string_utf8(env, value, buffer, bufLength + 1, &bufLength); if (status == napi_ok) { @@ -470,7 +472,6 @@ void CameraNapi::SaveCallbackReference(napi_env env, CameraNapi* camWrapper, if (status != napi_ok) { HiLog::Error(LABEL, "Unknown error while creating reference for callback!"); } - } napi_ref CameraNapi::GetErrorCallbackRef() @@ -482,10 +483,10 @@ napi_ref CameraNapi::GetErrorCallbackRef() napi_value CameraNapi::On(napi_env env, napi_callback_info info) { napi_status status; - size_t argCount = 2; + size_t argCount = ARGS_TWO; napi_value jsThis = nullptr; napi_value undefinedResult = nullptr; - napi_value args[2] = {0}; + napi_value args[ARGS_TWO] = {0}; CameraNapi* cameraWrapper = nullptr; napi_valuetype valueType0 = napi_undefined; napi_valuetype valueType1 = napi_undefined; @@ -493,7 +494,7 @@ napi_value CameraNapi::On(napi_env env, napi_callback_info info) napi_get_undefined(env, &undefinedResult); status = napi_get_cb_info(env, info, &argCount, args, &jsThis, nullptr); - if (status != napi_ok || argCount < 2) { + if (status != napi_ok || argCount < ARGS_TWO) { HiLog::Error(LABEL, "Invalid arguments!"); return nullptr; } @@ -813,8 +814,8 @@ sptr CameraNapi::CreateSubWindowSurface() { if (!subWindow_) { WindowConfig config = { - .width = 480, - .height = 480, + .width = SURFACE_DEFAULT_WIDTH, + .height = SURFACE_DEFAULT_HEIGHT, .pos_x = 0, .pos_y = 0, .format = PIXEL_FMT_RGBA_8888 @@ -882,6 +883,7 @@ int32_t CameraNapi::PreparePhoto(sptr camManagerObj) HiLog::Error(LABEL, "CreateSurface failed"); return -1; } + captureConsumerSurface_->SetDefaultWidthAndHeight(PHOTO_DEFAULT_WIDTH, PHOTO_DEFAULT_HEIGHT); listener = new SurfaceListener(); if (listener == nullptr) { HiLog::Error(LABEL, "Create Listener failed"); @@ -959,14 +961,14 @@ napi_value CameraNapi::Prepare(napi_env env, napi_callback_info info) int32_t intResult = -1; napi_value jsCallback, result; - GET_PARAMS(env, info, 3); + GET_PARAMS(env, info, ARGS_THREE); napi_get_undefined(env, &undefinedResult); - if (argc > 3) { + if (argc > ARGS_THREE) { HiLog::Error(LABEL, "CameraNapi::Prepare() Invalid arguments!"); return undefinedResult; } - status = napi_unwrap(env, thisVar, (void**) &CameraWrapper); + status = napi_unwrap(env, thisVar, (void**)&CameraWrapper); if (status == napi_ok && CameraWrapper != nullptr) { for (size_t i = 0; i < argc; i++) { napi_valuetype valueType = napi_undefined; @@ -997,7 +999,7 @@ napi_value CameraNapi::Prepare(napi_env env, napi_callback_info info) static void GetCameraIdsAsyncCallbackComplete(napi_env env, napi_status status, void* data) { auto asyncContext = static_cast(data); - napi_value result[2] = {0}; + napi_value result[ARGS_TWO] = {0}; napi_value retVal; napi_get_undefined(env, &result[0]); size_t size = asyncContext->cameraObjList.size(); @@ -1019,7 +1021,7 @@ static void GetCameraIdsAsyncCallbackComplete(napi_env env, napi_status status, } else { napi_value callback = nullptr; napi_get_reference_value(env, asyncContext->callbackRef, &callback); - napi_call_function(env, nullptr, callback, 2, result, &retVal); + napi_call_function(env, nullptr, callback, ARGS_TWO, result, &retVal); napi_delete_reference(env, asyncContext->callbackRef); } napi_delete_async_work(env, asyncContext->work); @@ -1033,10 +1035,10 @@ napi_value CameraNapi::GetCameraIDs(napi_env env, napi_callback_info info) std::unique_ptr asyncContext = std::make_unique(); napi_value result = nullptr; napi_value undefinedResult = nullptr; - GET_PARAMS(env, info, 2); + GET_PARAMS(env, info, ARGS_TWO); napi_get_undefined(env, &undefinedResult); - if (argc > 2) { + if (argc > ARGS_TWO) { HiLog::Error(LABEL, "Invalid arguments!"); return undefinedResult; } @@ -1064,7 +1066,7 @@ napi_value CameraNapi::GetCameraIDs(napi_env env, napi_callback_info info) status = napi_create_async_work( env, nullptr, resource, [](napi_env env, void* data) { - CameraNapiAsyncContext* context = (CameraNapiAsyncContext*) data; + CameraNapiAsyncContext* context = (CameraNapiAsyncContext*)data; sptr camManagerObj = CameraManager::GetInstance(); context->cameraObjList = camManagerObj->GetCameras(); context->status = 0; @@ -1121,7 +1123,7 @@ napi_value CameraNapi::StartVideoRecording(napi_env env, napi_callback_info info return undefinedResult; } - status = napi_unwrap(env, jsThis, (void**) &camWrapper); + status = napi_unwrap(env, jsThis, (void**)&camWrapper); if (status == napi_ok) { if (camWrapper->recordState_ == State::STATE_RUNNING) { HiLog::Error(LABEL, "Camera is already recording."); @@ -1174,7 +1176,7 @@ napi_value CameraNapi::StopVideoRecording(napi_env env, napi_callback_info info) return undefinedResult; } - status = napi_unwrap(env, jsThis, (void**) &camWrapper); + status = napi_unwrap(env, jsThis, (void**)&camWrapper); if (status == napi_ok) { if (camWrapper->recordState_ != State::STATE_RUNNING) { HiLog::Error(LABEL, "Failed to Stop Recording"); @@ -1223,7 +1225,7 @@ napi_value CameraNapi::ResetVideoRecording(napi_env env, napi_callback_info info return undefinedResult; } - status = napi_unwrap(env, jsThis, (void**) &camWrapper); + status = napi_unwrap(env, jsThis, (void**)&camWrapper); if (status == napi_ok) { if (camWrapper->recorder_->Reset() != 0) { HiLog::Error(LABEL, "Failed to Reset Recording"); @@ -1264,7 +1266,7 @@ napi_value CameraNapi::PauseVideoRecording(napi_env env, napi_callback_info info return undefinedResult; } - status = napi_unwrap(env, jsThis, (void**) &camWrapper); + status = napi_unwrap(env, jsThis, (void**)&camWrapper); if (status == napi_ok) { if (camWrapper->recorder_->Pause() != 0) { HiLog::Error(LABEL, "Failed to Pause Recording"); @@ -1275,7 +1277,7 @@ napi_value CameraNapi::PauseVideoRecording(napi_env env, napi_callback_info info return undefinedResult; } - status = napi_get_reference_value(env, camWrapper->pauseCallback_ ,&jsCallback); + status = napi_get_reference_value(env, camWrapper->pauseCallback_, &jsCallback); if (status == napi_ok && jsCallback != nullptr) { if (napi_call_function(env, nullptr, jsCallback, 0, nullptr, &result) == napi_ok) { return undefinedResult; @@ -1303,7 +1305,7 @@ napi_value CameraNapi::ResumeVideoRecording(napi_env env, napi_callback_info inf return undefinedResult; } - status = napi_unwrap(env, jsThis, (void**) &camWrapper); + status = napi_unwrap(env, jsThis, (void**)&camWrapper); if (status == napi_ok) { if (camWrapper->recorder_->Resume() != 0) { HiLog::Error(LABEL, "Failed to Resume Recording"); @@ -1343,7 +1345,7 @@ napi_value CameraNapi::StartPreview(napi_env env, napi_callback_info info) return undefinedResult; } - status = napi_unwrap(env, jsThis, (void**) &cameraWrapper); + status = napi_unwrap(env, jsThis, (void**)&cameraWrapper); if (status == napi_ok) { if (!(cameraWrapper->isReady_) || (cameraWrapper->capSession_ == nullptr)) { HiLog::Error(LABEL, "Not ready for StartPreview."); @@ -1395,7 +1397,7 @@ napi_value CameraNapi::StopPreview(napi_env env, napi_callback_info info) HiLog::Error(LABEL, "Invalid arguments!"); return undefinedResult; } - status = napi_unwrap(env, jsThis, (void**) &cameraWrapper); + status = napi_unwrap(env, jsThis, (void**)&cameraWrapper); if (status == napi_ok) { if (cameraWrapper->capSession_ != nullptr) { cameraWrapper->capSession_->Stop(); @@ -1427,7 +1429,6 @@ napi_value CameraNapi::StopPreview(napi_env env, napi_callback_info info) int32_t CameraNapi::GetPhotoConfig(napi_env env, napi_value arg) { - char buffer[SIZE]; size_t res = 0; napi_value temp, mirtemp; bool bIsMirror = false; @@ -1458,7 +1459,6 @@ int32_t CameraNapi::GetPhotoConfig(napi_env env, napi_value arg) if (listener != nullptr) { listener->SetPhotoPath(photoConfig_->strPhotoPath); } - memset_s(buffer, SIZE, 0, sizeof(buffer)); napi_has_named_property(env, arg, "mirror", &bIsPresent); if (!bIsPresent) { HiLog::Error(LABEL, "No mirror flag Exists"); @@ -1478,7 +1478,7 @@ int32_t CameraNapi::GetPhotoConfig(napi_env env, napi_value arg) static void TakePhotoAsyncCallbackComplete(napi_env env, napi_status status, void* data) { auto asyncContext = static_cast(data); - napi_value result[2] = {0}; + napi_value result[ARGS_TWO] = {0}; napi_value retVal; napi_get_undefined(env, &result[0]); napi_get_undefined(env, &result[1]); @@ -1488,7 +1488,7 @@ static void TakePhotoAsyncCallbackComplete(napi_env env, napi_status status, voi } else { napi_value callback = nullptr; napi_get_reference_value(env, asyncContext->callbackRef, &callback); - napi_call_function(env, nullptr, callback, 2, result, &retVal); + napi_call_function(env, nullptr, callback, ARGS_TWO, result, &retVal); napi_delete_reference(env, asyncContext->callbackRef); } napi_delete_async_work(env, asyncContext->work); @@ -1502,9 +1502,9 @@ napi_value CameraNapi::TakePhoto(napi_env env, napi_callback_info info) napi_value result = nullptr; std::unique_ptr asyncContext = std::make_unique(); - GET_PARAMS(env, info, 2); + GET_PARAMS(env, info, ARGS_TWO); napi_get_undefined(env, &result); - if (argc > 2) { + if (argc > ARGS_TWO) { HiLog::Error(LABEL, "Invalid arguments!"); return result; } @@ -1989,8 +1989,8 @@ napi_value CameraNapi::CreateParameterResultObject(napi_env env) static void GetSupportedPropertiesAsyncCallbackComplete(napi_env env, napi_status status, void* data) { - auto asyncContext = (CameraNapiAsyncContext*) data; - napi_value result[2] = {0}; + auto asyncContext = (CameraNapiAsyncContext*)data; + napi_value result[ARGS_TWO] = {0}; napi_value retVal; napi_get_undefined(env, &result[0]); @@ -2012,7 +2012,7 @@ static void GetSupportedPropertiesAsyncCallbackComplete(napi_env env, napi_statu } else { napi_value callback = nullptr; napi_get_reference_value(env, asyncContext->callbackRef, &callback); - napi_call_function(env, nullptr, callback, 2, result, &retVal); + napi_call_function(env, nullptr, callback, ARGS_TWO, result, &retVal); napi_delete_reference(env, asyncContext->callbackRef); } napi_delete_async_work(env, asyncContext->work); @@ -2028,9 +2028,9 @@ napi_value CameraNapi::GetSupportedProperties(napi_env env, napi_callback_info i napi_value result = nullptr; napi_value undefinedResult = nullptr; - GET_PARAMS(env, info, 2); + GET_PARAMS(env, info, ARGS_TWO); napi_get_undefined(env, &undefinedResult); - if (argc > 2) { + if (argc > ARGS_TWO) { HiLog::Error(LABEL, "Invalid arguments!"); return undefinedResult; } @@ -2060,7 +2060,7 @@ napi_value CameraNapi::GetSupportedProperties(napi_env env, napi_callback_info i env, nullptr, resource, [](napi_env env, void* data) { CameraNapiAsyncContext* context = static_cast (data); - //Need to add logic for calling native to get supported Exposure Mode + // Need to add logic for calling native to get supported Exposure Mode context->status = 0; }, GetSupportedPropertiesAsyncCallbackComplete, static_cast(asyncContext.get()), &asyncContext->work); @@ -2077,8 +2077,8 @@ napi_value CameraNapi::GetSupportedProperties(napi_env env, napi_callback_info i static void GetPropertyValueAsyncCallbackComplete(napi_env env, napi_status status, void* data) { - CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*) data; - napi_value result[2] = {0}; + CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*)data; + napi_value result[ARGS_TWO] = {0}; napi_value retVal; napi_get_undefined(env, &result[0]); napi_get_undefined(env, &result[1]); @@ -2088,7 +2088,7 @@ static void GetPropertyValueAsyncCallbackComplete(napi_env env, napi_status stat } else { napi_value callback = nullptr; napi_get_reference_value(env, asyncContext->callbackRef, &callback); - napi_call_function(env, nullptr, callback, 2, result, &retVal); + napi_call_function(env, nullptr, callback, ARGS_TWO, result, &retVal); napi_delete_reference(env, asyncContext->callbackRef); } napi_delete_async_work(env, asyncContext->work); @@ -2103,15 +2103,15 @@ napi_value CameraNapi::GetPropertyValue(napi_env env, napi_callback_info info) const int32_t refCount = 1; napi_value result = nullptr; napi_value undefinedResult = nullptr; - GET_PARAMS(env, info, 2); + GET_PARAMS(env, info, ARGS_TWO); napi_get_undefined(env, &undefinedResult); - if (argc > 2) { + if (argc > ARGS_TWO) { HiLog::Error(LABEL, "Invalid arguments!"); return undefinedResult; } - status = napi_unwrap(env, thisVar, reinterpret_cast(&asyncContext->objectInfo)); + status = napi_unwrap(env, thisVar, reinterpret_cast(&asyncContext->objectInfo)); if (status == napi_ok && asyncContext->objectInfo != nullptr) { for (size_t i = 0; i < argc; i++) { napi_valuetype valueType = napi_undefined; @@ -2137,7 +2137,7 @@ napi_value CameraNapi::GetPropertyValue(napi_env env, napi_callback_info info) env, nullptr, resource, [](napi_env env, void* data) { CameraNapiAsyncContext* context = static_cast (data); - //Need to add logic for calling native to get supported Exposure Mode + // Need to add logic for calling native to get supported Exposure Mode context->status = 0; }, GetPropertyValueAsyncCallbackComplete, static_cast(asyncContext.get()), &asyncContext->work); @@ -2154,8 +2154,8 @@ napi_value CameraNapi::GetPropertyValue(napi_env env, napi_callback_info info) static void GetSupportedResolutionScalesAsyncCallbackComplete(napi_env env, napi_status status, void* data) { - CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*) data; - napi_value result[2] = {0}; + CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*)data; + napi_value result[ARGS_TWO] = {0}; napi_value retVal; napi_get_undefined(env, &result[0]); size_t size = asyncContext->vecSupportedResolutionScalesList.size(); @@ -2176,7 +2176,7 @@ static void GetSupportedResolutionScalesAsyncCallbackComplete(napi_env env, napi } else { napi_value callback = nullptr; napi_get_reference_value(env, asyncContext->callbackRef, &callback); - napi_call_function(env, nullptr, callback, 2, result, &retVal); + napi_call_function(env, nullptr, callback, ARGS_TWO, result, &retVal); napi_delete_reference(env, asyncContext->callbackRef); } napi_delete_async_work(env, asyncContext->work); @@ -2191,10 +2191,10 @@ napi_value CameraNapi::GetSupportedResolutionScales(napi_env env, napi_callback_ const int32_t refCount = 1; napi_value result = nullptr; napi_value undefinedResult = nullptr; - GET_PARAMS(env, info, 2); + GET_PARAMS(env, info, ARGS_TWO); napi_get_undefined(env, &undefinedResult); - if (argc > 2) { + if (argc > ARGS_TWO) { HiLog::Error(LABEL, "Invalid arguments!"); return undefinedResult; } @@ -2242,8 +2242,8 @@ napi_value CameraNapi::GetSupportedResolutionScales(napi_env env, napi_callback_ static void SetPreviewResolutionScaleAsyncCallbackComplete(napi_env env, napi_status status, void* data) { - CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*) data; - napi_value result[2] = {0}; + CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*)data; + napi_value result[ARGS_TWO] = {0}; napi_value retVal; napi_get_undefined(env, &result[0]); napi_get_undefined(env, &result[1]); @@ -2253,7 +2253,7 @@ static void SetPreviewResolutionScaleAsyncCallbackComplete(napi_env env, napi_st } else { napi_value callback = nullptr; napi_get_reference_value(env, asyncContext->callbackRef, &callback); - napi_call_function(env, nullptr, callback, 2, result, &retVal); + napi_call_function(env, nullptr, callback, ARGS_TWO, result, &retVal); napi_delete_reference(env, asyncContext->callbackRef); } napi_delete_async_work(env, asyncContext->work); @@ -2268,9 +2268,9 @@ napi_value CameraNapi::SetPreviewResolutionScale(napi_env env, napi_callback_inf const int32_t refCount = 1; napi_value result = nullptr; napi_value undefinedResult = nullptr; - GET_PARAMS(env, info, 2); + GET_PARAMS(env, info, ARGS_TWO); napi_get_undefined(env, &undefinedResult); - if (argc > 2) { + if (argc > ARGS_TWO) { HiLog::Error(LABEL, "Invalid arguments!"); return undefinedResult; } @@ -2302,7 +2302,7 @@ napi_value CameraNapi::SetPreviewResolutionScale(napi_env env, napi_callback_inf env, nullptr, resource, [](napi_env env, void* data) { CameraNapiAsyncContext* context = static_cast (data); - //Need to add logic for calling native to set Preview Resolution Scale + // Need to add logic for calling native to set Preview Resolution Scale context->status = 0; }, SetPreviewResolutionScaleAsyncCallbackComplete, @@ -2320,8 +2320,8 @@ napi_value CameraNapi::SetPreviewResolutionScale(napi_env env, napi_callback_inf static void SetPreviewQualityAsyncCallbackComplete(napi_env env, napi_status status, void* data) { - CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*) data; - napi_value result[2] = {0}; + CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*)data; + napi_value result[ARGS_TWO] = {0}; napi_value retVal; napi_get_undefined(env, &result[0]); napi_get_undefined(env, &result[1]); @@ -2331,7 +2331,7 @@ static void SetPreviewQualityAsyncCallbackComplete(napi_env env, napi_status sta } else { napi_value callback = nullptr; napi_get_reference_value(env, asyncContext->callbackRef, &callback); - napi_call_function(env, nullptr, callback, 2, result, &retVal); + napi_call_function(env, nullptr, callback, ARGS_TWO, result, &retVal); napi_delete_reference(env, asyncContext->callbackRef); } napi_delete_async_work(env, asyncContext->work); @@ -2346,9 +2346,9 @@ napi_value CameraNapi::SetPreviewQuality(napi_env env, napi_callback_info info) const int32_t refCount = 1; napi_value result = nullptr; napi_value undefinedResult = nullptr; - GET_PARAMS(env, info, 2); + GET_PARAMS(env, info, ARGS_TWO); napi_get_undefined(env, &undefinedResult); - if (argc > 2) { + if (argc > ARGS_TWO) { HiLog::Error(LABEL, "Invalid arguments!"); return undefinedResult; } @@ -2381,7 +2381,7 @@ napi_value CameraNapi::SetPreviewQuality(napi_env env, napi_callback_info info) env, nullptr, resource, [](napi_env env, void* data) { CameraNapiAsyncContext* context = static_cast (data); - //Need to add logic for calling native to get supported Exposure Mode + // Need to add logic for calling native to get supported Exposure Mode context->status = 0; }, SetPreviewQualityAsyncCallbackComplete, static_cast(asyncContext.get()), &asyncContext->work); @@ -2398,8 +2398,8 @@ napi_value CameraNapi::SetPreviewQuality(napi_env env, napi_callback_info info) static void GetSupportedExposureModeAsyncCallbackComplete(napi_env env, napi_status status, void* data) { - CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*) data; - napi_value result[2] = {0}; + CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*)data; + napi_value result[ARGS_TWO] = {0}; napi_value retVal; napi_get_undefined(env, &result[0]); size_t size = asyncContext->vecSupportedExposureModeList.size(); @@ -2419,7 +2419,7 @@ static void GetSupportedExposureModeAsyncCallbackComplete(napi_env env, napi_sta } else { napi_value callback = nullptr; napi_get_reference_value(env, asyncContext->callbackRef, &callback); - napi_call_function(env, nullptr, callback, 2, result, &retVal); + napi_call_function(env, nullptr, callback, ARGS_TWO, result, &retVal); napi_delete_reference(env, asyncContext->callbackRef); } napi_delete_async_work(env, asyncContext->work); @@ -2434,9 +2434,9 @@ napi_value CameraNapi::GetSupportedExposureMode(napi_env env, napi_callback_info const int32_t refCount = 1; napi_value result = nullptr; napi_value undefinedResult = nullptr; - GET_PARAMS(env, info, 2); + GET_PARAMS(env, info, ARGS_TWO); napi_get_undefined(env, &undefinedResult); - if (argc > 2) { + if (argc > ARGS_TWO) { HiLog::Error(LABEL, "Invalid arguments!"); return undefinedResult; } @@ -2483,8 +2483,8 @@ napi_value CameraNapi::GetSupportedExposureMode(napi_env env, napi_callback_info static void SetExposureModeAsyncCallbackComplete(napi_env env, napi_status status, void* data) { - CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*) data; - napi_value result[2] = {0}; + CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*)data; + napi_value result[ARGS_TWO] = {0}; napi_value retVal; napi_get_undefined(env, &result[0]); napi_get_undefined(env, &result[1]); @@ -2494,7 +2494,7 @@ static void SetExposureModeAsyncCallbackComplete(napi_env env, napi_status statu } else { napi_value callback = nullptr; napi_get_reference_value(env, asyncContext->callbackRef, &callback); - napi_call_function(env, nullptr, callback, 2, result, &retVal); + napi_call_function(env, nullptr, callback, ARGS_TWO, result, &retVal); napi_delete_reference(env, asyncContext->callbackRef); } napi_delete_async_work(env, asyncContext->work); @@ -2509,9 +2509,9 @@ napi_value CameraNapi::SetExposureMode(napi_env env, napi_callback_info info) const int32_t refCount = 1; napi_value result = nullptr; napi_value undefinedResult = nullptr; - GET_PARAMS(env, info, 2); + GET_PARAMS(env, info, ARGS_TWO); napi_get_undefined(env, &undefinedResult); - if (argc > 2) { + if (argc > ARGS_TWO) { HiLog::Error(LABEL, "Invalid arguments!"); return undefinedResult; } @@ -2563,8 +2563,8 @@ napi_value CameraNapi::SetExposureMode(napi_env env, napi_callback_info info) static void GetSupportedFocusModeAsyncCallbackComplete(napi_env env, napi_status status, void* data) { - CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*) data; - napi_value result[2] = {0}; + CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*)data; + napi_value result[ARGS_TWO] = {0}; napi_value retVal; napi_get_undefined(env, &result[0]); size_t size = asyncContext->vecSupportedFocusModeList.size(); @@ -2584,7 +2584,7 @@ static void GetSupportedFocusModeAsyncCallbackComplete(napi_env env, napi_status } else { napi_value callback = nullptr; napi_get_reference_value(env, asyncContext->callbackRef, &callback); - napi_call_function(env, nullptr, callback, 2, result, &retVal); + napi_call_function(env, nullptr, callback, ARGS_TWO, result, &retVal); napi_delete_reference(env, asyncContext->callbackRef); } napi_delete_async_work(env, asyncContext->work); @@ -2600,9 +2600,9 @@ napi_value CameraNapi::GetSupportedFocusMode(napi_env env, napi_callback_info in napi_value result = nullptr; napi_value undefinedResult = nullptr; - GET_PARAMS(env, info, 2); + GET_PARAMS(env, info, ARGS_TWO); napi_get_undefined(env, &undefinedResult); - if (argc > 2) { + if (argc > ARGS_TWO) { HiLog::Error(LABEL, "Invalid arguments!"); return undefinedResult; } @@ -2650,8 +2650,8 @@ napi_value CameraNapi::GetSupportedFocusMode(napi_env env, napi_callback_info in static void SetFocusModeAsyncCallbackComplete(napi_env env, napi_status status, void* data) { - CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*) data; - napi_value result[2] = {0}; + CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*)data; + napi_value result[ARGS_TWO] = {0}; napi_value retVal; napi_get_undefined(env, &result[0]); napi_get_undefined(env, &result[1]); @@ -2661,7 +2661,7 @@ static void SetFocusModeAsyncCallbackComplete(napi_env env, napi_status status, } else { napi_value callback = nullptr; napi_get_reference_value(env, asyncContext->callbackRef, &callback); - napi_call_function(env, nullptr, callback, 2, result, &retVal); + napi_call_function(env, nullptr, callback, ARGS_TWO, result, &retVal); napi_delete_reference(env, asyncContext->callbackRef); } napi_delete_async_work(env, asyncContext->work); @@ -2676,10 +2676,10 @@ napi_value CameraNapi::SetFocusMode(napi_env env, napi_callback_info info) const int32_t refCount = 1; napi_value result = nullptr; napi_value undefinedResult = nullptr; - GET_PARAMS(env, info, 2); + GET_PARAMS(env, info, ARGS_TWO); napi_get_undefined(env, &undefinedResult); - if (argc > 2) { + if (argc > ARGS_TWO) { HiLog::Error(LABEL, "Invalid arguments!"); return undefinedResult; } @@ -2730,8 +2730,8 @@ napi_value CameraNapi::SetFocusMode(napi_env env, napi_callback_info info) static void GetSupportedFlashModeAsyncCallbackComplete(napi_env env, napi_status status, void* data) { - CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*) data; - napi_value result[2] = {0}; + CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*)data; + napi_value result[ARGS_TWO] = {0}; napi_value retVal; napi_get_undefined(env, &result[0]); @@ -2752,7 +2752,7 @@ static void GetSupportedFlashModeAsyncCallbackComplete(napi_env env, napi_status } else { napi_value callback = nullptr; napi_get_reference_value(env, asyncContext->callbackRef, &callback); - napi_call_function(env, nullptr, callback, 2, result, &retVal); + napi_call_function(env, nullptr, callback, ARGS_TWO, result, &retVal); napi_delete_reference(env, asyncContext->callbackRef); } napi_delete_async_work(env, asyncContext->work); @@ -2767,10 +2767,10 @@ napi_value CameraNapi::GetSupportedFlashMode(napi_env env, napi_callback_info in const int32_t refCount = 1; napi_value result = nullptr; napi_value undefinedResult = nullptr; - GET_PARAMS(env, info, 2); + GET_PARAMS(env, info, ARGS_TWO); napi_get_undefined(env, &undefinedResult); - if (argc > 2) { + if (argc > ARGS_TWO) { HiLog::Error(LABEL, "Invalid arguments!"); return undefinedResult; } @@ -2800,7 +2800,7 @@ napi_value CameraNapi::GetSupportedFlashMode(napi_env env, napi_callback_info in env, nullptr, resource, [](napi_env env, void* data) { CameraNapiAsyncContext* context = static_cast (data); - //Need to add logic for calling native to get supported Exposure Mode + // Need to add logic for calling native to get supported Exposure Mode context->vecSupportedFlashModeList = ((sptr &) (context->objectInfo->camInput_))->GetSupportedFlashModes(); context->status = 0; @@ -2819,8 +2819,8 @@ napi_value CameraNapi::GetSupportedFlashMode(napi_env env, napi_callback_info in static void SetFlashModeAsyncCallbackComplete(napi_env env, napi_status status, void* data) { - CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*) data; - napi_value result[2] = {0}; + CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*)data; + napi_value result[ARGS_TWO] = {0}; napi_value retVal; napi_get_undefined(env, &result[0]); napi_get_undefined(env, &result[1]); @@ -2830,7 +2830,7 @@ static void SetFlashModeAsyncCallbackComplete(napi_env env, napi_status status, } else { napi_value callback = nullptr; napi_get_reference_value(env, asyncContext->callbackRef, &callback); - napi_call_function(env, nullptr, callback, 2, result, &retVal); + napi_call_function(env, nullptr, callback, ARGS_TWO, result, &retVal); napi_delete_reference(env, asyncContext->callbackRef); } napi_delete_async_work(env, asyncContext->work); @@ -2846,9 +2846,9 @@ napi_value CameraNapi::SetFlashMode(napi_env env, napi_callback_info info) napi_value result = nullptr; napi_value undefinedResult = nullptr; - GET_PARAMS(env, info, 2); + GET_PARAMS(env, info, ARGS_TWO); napi_get_undefined(env, &undefinedResult); - if (argc > 2) { + if (argc > ARGS_TWO) { HiLog::Error(LABEL, "Invalid arguments!"); return undefinedResult; } @@ -2899,8 +2899,8 @@ napi_value CameraNapi::SetFlashMode(napi_env env, napi_callback_info info) static void GetSupportedZoomRangeAsyncCallbackComplete(napi_env env, napi_status status, void* data) { - CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*) data; - napi_value result[2] = {0}; + CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*)data; + napi_value result[ARGS_TWO] = {0}; napi_value retVal; napi_get_undefined(env, &result[0]); size_t size = asyncContext->vecSupportedZoomRangeList.size(); @@ -2921,7 +2921,7 @@ static void GetSupportedZoomRangeAsyncCallbackComplete(napi_env env, napi_status } else { napi_value callback = nullptr; napi_get_reference_value(env, asyncContext->callbackRef, &callback); - napi_call_function(env, nullptr, callback, 2, result, &retVal); + napi_call_function(env, nullptr, callback, ARGS_TWO, result, &retVal); napi_delete_reference(env, asyncContext->callbackRef); } napi_delete_async_work(env, asyncContext->work); @@ -2936,10 +2936,10 @@ napi_value CameraNapi::GetSupportedZoomRange(napi_env env, napi_callback_info in const int32_t refCount = 1; napi_value result = nullptr; napi_value undefinedResult = nullptr; - GET_PARAMS(env, info, 2); + GET_PARAMS(env, info, ARGS_TWO); napi_get_undefined(env, &undefinedResult); - if (argc > 2) { + if (argc > ARGS_TWO) { HiLog::Error(LABEL, "Invalid arguments!"); return undefinedResult; } @@ -2969,7 +2969,7 @@ napi_value CameraNapi::GetSupportedZoomRange(napi_env env, napi_callback_info in env, nullptr, resource, [](napi_env env, void* data) { CameraNapiAsyncContext* context = static_cast (data); - //Need to add logic for calling native to get supported Exposure Mode + // Need to add logic for calling native to get supported Exposure Mode context->vecSupportedZoomRangeList = ((sptr &) (context->objectInfo->camInput_))->GetSupportedZoomRatioRange(); context->status = 0; @@ -2988,8 +2988,8 @@ napi_value CameraNapi::GetSupportedZoomRange(napi_env env, napi_callback_info in static void SetZoomAsyncCallbackComplete(napi_env env, napi_status status, void* data) { - CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*) data; - napi_value result[2] = {0}; + CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*)data; + napi_value result[ARGS_TWO] = {0}; napi_value retVal; napi_get_undefined(env, &result[0]); napi_get_undefined(env, &result[1]); @@ -2999,7 +2999,7 @@ static void SetZoomAsyncCallbackComplete(napi_env env, napi_status status, void* } else { napi_value callback = nullptr; napi_get_reference_value(env, asyncContext->callbackRef, &callback); - napi_call_function(env, nullptr, callback, 2, result, &retVal); + napi_call_function(env, nullptr, callback, ARGS_TWO, result, &retVal); napi_delete_reference(env, asyncContext->callbackRef); } napi_delete_async_work(env, asyncContext->work); @@ -3015,7 +3015,7 @@ napi_value CameraNapi::SetZoom(napi_env env, napi_callback_info info) napi_value result = nullptr; napi_value undefinedResult = nullptr; - GET_PARAMS(env, info, 2); + GET_PARAMS(env, info, ARGS_TWO); napi_get_undefined(env, &undefinedResult); if (argc > ARGS_MAX_TWO_COUNT) { HiLog::Error(LABEL, "Invalid arguments!"); @@ -3066,8 +3066,8 @@ napi_value CameraNapi::SetZoom(napi_env env, napi_callback_info info) static void SetParameterAsyncCallbackComplete(napi_env env, napi_status status, void* data) { - CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*) data; - napi_value result[2] = {0}; + CameraNapiAsyncContext* asyncContext = (CameraNapiAsyncContext*)data; + napi_value result[ARGS_TWO] = {0}; napi_value retVal; napi_get_undefined(env, &result[0]); napi_get_undefined(env, &result[1]); @@ -3077,7 +3077,7 @@ static void SetParameterAsyncCallbackComplete(napi_env env, napi_status status, } else { napi_value callback = nullptr; napi_get_reference_value(env, asyncContext->callbackRef, &callback); - napi_call_function(env, nullptr, callback, 2, result, &retVal); + napi_call_function(env, nullptr, callback, ARGS_TWO, result, &retVal); napi_delete_reference(env, asyncContext->callbackRef); } napi_delete_async_work(env, asyncContext->work); @@ -3091,9 +3091,9 @@ napi_value CameraNapi::SetParameter(napi_env env, napi_callback_info info) const int32_t refCount = 1; napi_value result = nullptr; napi_value undefinedResult = nullptr; - GET_PARAMS(env, info, 2); + GET_PARAMS(env, info, ARGS_TWO); napi_get_undefined(env, &undefinedResult); - if (argc > 2) { + if (argc > ARGS_TWO) { HiLog::Error(LABEL, "Invalid arguments!"); return undefinedResult; } @@ -3106,7 +3106,7 @@ napi_value CameraNapi::SetParameter(napi_env env, napi_callback_info info) continue; } else if (i == 1) { continue; - } else if (i == 2 && valueType == napi_function) { + } else if (i == ARGS_TWO && valueType == napi_function) { napi_create_reference(env, argv[i], refCount, &asyncContext->callbackRef); break; } else { @@ -3127,7 +3127,7 @@ napi_value CameraNapi::SetParameter(napi_env env, napi_callback_info info) env, nullptr, resource, [](napi_env env, void* data) { CameraNapiAsyncContext* context = static_cast (data); - //Need to add logic for calling native to set Parameters + // Need to add logic for calling native to set Parameters context->status = 0; }, SetParameterAsyncCallbackComplete, static_cast(asyncContext.get()), &asyncContext->work); diff --git a/interfaces/innerkits/native/camera/include/input/camera_manager.h b/interfaces/innerkits/native/camera/include/input/camera_manager.h index cfa56e120..d79a09e2a 100644 --- a/interfaces/innerkits/native/camera/include/input/camera_manager.h +++ b/interfaces/innerkits/native/camera/include/input/camera_manager.h @@ -46,8 +46,8 @@ class CameraManagerCallback { public: CameraManagerCallback() = default; virtual ~CameraManagerCallback() = default; - virtual void OnCameraStatusChanged(const std::string cameraID, const CameraDeviceStatus cameraStatus) const = 0; - virtual void OnFlashlightStatusChanged(const std::string cameraID, const FlashlightStatus flashStatus) const = 0; + virtual void OnCameraStatusChanged(const std::string &cameraID, const CameraDeviceStatus cameraStatus) const = 0; + virtual void OnFlashlightStatusChanged(const std::string &cameraID, const FlashlightStatus flashStatus) const = 0; }; class CameraManager : public RefBase { @@ -59,6 +59,7 @@ public: sptr CreatePhotoOutput(sptr &surface); sptr CreateVideoOutput(sptr &surface); sptr CreatePreviewOutput(sptr surface); + sptr CreateCustomPreviewOutput(sptr surface, int32_t width, int32_t height); void SetCallback(std::shared_ptr callback); std::shared_ptr GetApplicationCallback(); diff --git a/interfaces/innerkits/native/test/camera_capture.cpp b/interfaces/innerkits/native/test/camera_capture.cpp index 6b980c7e2..dc56a5c3b 100644 --- a/interfaces/innerkits/native/test/camera_capture.cpp +++ b/interfaces/innerkits/native/test/camera_capture.cpp @@ -43,14 +43,14 @@ enum mode_ { class MyCallback : public CameraManagerCallback { public: - void OnCameraStatusChanged(const std::string cameraID, const CameraDeviceStatus cameraStatus) const override + void OnCameraStatusChanged(const std::string &cameraID, const CameraDeviceStatus cameraStatus) const override { MEDIA_DEBUG_LOG("OnCameraStatusChanged() is called, cameraID: %{public}s, cameraStatus: %{public}d", cameraID.c_str(), cameraStatus); return; } - void OnFlashlightStatusChanged(const std::string cameraID, const FlashlightStatus flashStatus) const override + void OnFlashlightStatusChanged(const std::string &cameraID, const FlashlightStatus flashStatus) const override { MEDIA_DEBUG_LOG("OnFlashlightStatusChanged() is called cameraID: %{public}s, flashStatus: %{public}d", cameraID.c_str(), flashStatus); @@ -92,7 +92,6 @@ class PhotoOutputCallback : public PhotoCallback { }; class PreviewOutputCallback : public PreviewCallback { - void OnFrameStarted() const override { MEDIA_INFO_LOG("PreviewOutputCallback:OnFrameStarted() is called!"); @@ -117,8 +116,10 @@ static uint64_t GetCurrentLocalTimeStamp() static int32_t SaveYUV(int32_t mode, const char *buffer, int32_t size) { + static const std::int32_t FILE_PERMISSION_FLAG = 00766; char path[PATH_MAX] = {0}; int32_t retVal; + if (mode == MODE_PREVIEW) { system("mkdir -p /mnt/preview"); retVal = sprintf_s(path, sizeof(path) / sizeof(path[0]), "/mnt/preview/%s_%lld.yuv", "preview", @@ -133,7 +134,7 @@ static int32_t SaveYUV(int32_t mode, const char *buffer, int32_t size) return -1; } MEDIA_DEBUG_LOG("%s, saving file to %{public}s", __FUNCTION__, path); - int imgFd = open(path, O_RDWR | O_CREAT, 00766); + int imgFd = open(path, O_RDWR | O_CREAT, FILE_PERMISSION_FLAG); if (imgFd == -1) { MEDIA_DEBUG_LOG("%s, open file failed, errno = %{public}s.", __FUNCTION__, strerror(errno)); return -1; @@ -198,11 +199,54 @@ public: } }; -int main() +static bool IsNumber(char number[]) +{ + for (int i = 0; number[i] != 0; i++) { + if (!std::isdigit(number[i])) { + return false; + } + } + return true; +} + +int main(int argc, char **argv) { + const std::int32_t PHOTO_DEFAULT_WIDTH = 1280; + const std::int32_t PHOTO_DEFAULT_HEIGHT = 960; + const std::int32_t PREVIEW_DEFAULT_WIDTH = 640; + const std::int32_t PREVIEW_DEFAULT_HEIGHT = 480; + const std::int32_t PREVIEW_WIDTH_INDEX = 1; + const std::int32_t PREVIEW_HEIGHT_INDEX = 2; + const std::int32_t PHOTO_WIDTH_INDEX = 3; + const std::int32_t PHOTO_HEIGHT_INDEX = 4; + const std::int32_t VALID_ARG_COUNT = 5; + const std::int32_t GAP_AFTER_CAPTURE = 2; // 2 seconds + const std::int32_t PREVIEW_CAPTURE_GAP = 5; // 5 seconds int32_t intResult = -1; - MEDIA_DEBUG_LOG("Camera new sample begin."); + // Default sizes for Preview Output and PhotoOutput + int32_t previewWidth = PREVIEW_DEFAULT_WIDTH; + int32_t previewHeight = PREVIEW_DEFAULT_HEIGHT; + int32_t photoWidth = PHOTO_DEFAULT_WIDTH; + int32_t photoHeight = PHOTO_DEFAULT_HEIGHT; + MEDIA_DEBUG_LOG("Camera new sample begin."); + // Update sizes if enough number of valid arguments are passed + if (argc == VALID_ARG_COUNT) { + // Validate arguments + for (int counter = 1; counter < argc; counter++) { + if (!IsNumber(argv[counter])) { + cout << "Invalid argument: " << argv[counter] << endl; + cout << "Retry by giving proper sizes" << endl; + return 0; + } + } + previewWidth = atoi(argv[PREVIEW_WIDTH_INDEX]); + previewHeight = atoi(argv[PREVIEW_HEIGHT_INDEX]); + photoWidth = atoi(argv[PHOTO_WIDTH_INDEX]); + photoHeight = atoi(argv[PHOTO_HEIGHT_INDEX]); + } + MEDIA_DEBUG_LOG("previewWidth: %{public}d, previewHeight: %{public}d", previewWidth, previewHeight); + MEDIA_DEBUG_LOG("photoWidth: %{public}d, photoHeight: %{public}d", photoWidth, photoHeight); sptr camManagerObj = CameraManager::GetInstance(); std::shared_ptr cameraMngrCallback = make_shared(); MEDIA_DEBUG_LOG("Setting callback to listen camera status and flash status"); @@ -221,10 +265,11 @@ int main() sptr cameraInput = camManagerObj->CreateCameraInput(cameraObjList[0]); if (cameraInput != nullptr) { std::shared_ptr deviceCallback = make_shared(); - ((sptr &) cameraInput)->SetErrorCallback(deviceCallback); + ((sptr &)cameraInput)->SetErrorCallback(deviceCallback); intResult = captureSession->AddInput(cameraInput); - if (0 == intResult) { + if (intResult == 0) { photoSurface = Surface::CreateSurfaceAsConsumer(); + photoSurface->SetDefaultWidthAndHeight(photoWidth, photoHeight); sptr capturelistener = new CaptureSurfaceListener(); capturelistener->mode_ = MODE_PHOTO; capturelistener->surface_ = photoSurface; @@ -238,16 +283,19 @@ int main() std::shared_ptr photoCallback = std::make_shared(); ((sptr &)photoOutput)->SetCallback(photoCallback); intResult = captureSession->AddOutput(photoOutput); - if (intResult != 0){ + if (intResult != 0) { MEDIA_DEBUG_LOG("Failed to Add output to session, intResult: %{public}d", intResult); return 0; } previewSurface = Surface::CreateSurfaceAsConsumer(); + previewSurface->SetDefaultWidthAndHeight(previewHeight, previewWidth); sptr listener = new SurfaceListener(); listener->mode_ = MODE_PREVIEW; listener->surface_ = previewSurface; previewSurface->RegisterConsumerListener((sptr &)listener); - sptr previewOutput = camManagerObj->CreatePreviewOutput(previewSurface); + sptr previewOutput = camManagerObj->CreateCustomPreviewOutput(previewSurface, + previewWidth, + previewHeight); if (previewOutput == nullptr) { MEDIA_DEBUG_LOG("Failed to create previewOutput"); return 0; @@ -256,33 +304,29 @@ int main() std::shared_ptr previewCallback = std::make_shared(); ((sptr &)previewOutput)->SetCallback(previewCallback); intResult = captureSession->AddOutput(previewOutput); - if (intResult != 0){ + if (intResult != 0) { MEDIA_DEBUG_LOG("Failed to Add output to session, intResult: %{public}d", intResult); return 0; } intResult = captureSession->CommitConfig(); - if (intResult != 0){ + if (intResult != 0) { MEDIA_DEBUG_LOG("Failed to Commit config, intResult: %{public}d", intResult); return 0; } intResult = captureSession->Start(); - if (intResult != 0){ + if (intResult != 0) { MEDIA_DEBUG_LOG("Failed to start, intResult: %{public}d", intResult); return 0; } MEDIA_DEBUG_LOG("Preview started"); - MEDIA_DEBUG_LOG("Waiting for 5 seconds begin"); - sleep(5); - MEDIA_DEBUG_LOG("Waiting for 5 seconds end"); + sleep(PREVIEW_CAPTURE_GAP); MEDIA_DEBUG_LOG("Photo capture started"); intResult = ((sptr &)photoOutput)->Capture(); - if (intResult != 0){ + if (intResult != 0) { MEDIA_DEBUG_LOG("Failed to capture, intResult: %{public}d", intResult); return 0; } - MEDIA_DEBUG_LOG("Waiting for 2 seconds begin"); - sleep(2); - MEDIA_DEBUG_LOG("Waiting for 2 seconds end"); + sleep(GAP_AFTER_CAPTURE); MEDIA_DEBUG_LOG("Closing the session"); captureSession->Stop(); captureSession->Release(); diff --git a/interfaces/innerkits/native/test/camera_video.cpp b/interfaces/innerkits/native/test/camera_video.cpp index 2a8d0bf87..72bf45f22 100644 --- a/interfaces/innerkits/native/test/camera_video.cpp +++ b/interfaces/innerkits/native/test/camera_video.cpp @@ -41,16 +41,26 @@ enum mode_ { MODE_PHOTO }; +enum SaveVideoMode { + CREATE = 0, + APPEND, + CLOSE +}; + +namespace { + static const std::int32_t FILE_PERMISSION_FLAG = 00766; +} + class MyCallback : public CameraManagerCallback { public: - void OnCameraStatusChanged(const std::string cameraID, const CameraDeviceStatus cameraStatus) const override + void OnCameraStatusChanged(const std::string &cameraID, const CameraDeviceStatus cameraStatus) const override { MEDIA_DEBUG_LOG("OnCameraStatusChanged() is called, cameraID: %{public}s, cameraStatus: %{public}d", cameraID.c_str(), cameraStatus); return; } - void OnFlashlightStatusChanged(const std::string cameraID, const FlashlightStatus flashStatus) const override + void OnFlashlightStatusChanged(const std::string &cameraID, const FlashlightStatus flashStatus) const override { MEDIA_DEBUG_LOG("OnFlashlightStatusChanged() is called cameraID: %{public}s, flashStatus: %{public}d", cameraID.c_str(), flashStatus); @@ -97,7 +107,7 @@ class VideoOutputCallback : public VideoCallback { } }; -uint64_t GetCurrentLocalTimeStamp() +static uint64_t GetCurrentLocalTimeStamp() { std::chrono::time_point tp = std::chrono::time_point_cast(std::chrono::system_clock::now()); @@ -105,20 +115,20 @@ uint64_t GetCurrentLocalTimeStamp() return tmp.count(); } -int32_t SaveYUV(int32_t mode, void* buffer, int32_t size) +static int32_t SaveYUV(int32_t mode, char *buffer, int32_t size) { char path[PATH_MAX] = {0}; if (mode == MODE_PREVIEW) { system("mkdir -p /mnt/preview"); - (void) sprintf_s(path, sizeof(path) / sizeof(path[0]), - "/mnt/preview/%s_%lld.yuv", "preview", GetCurrentLocalTimeStamp()); + (void)sprintf_s(path, sizeof(path) / sizeof(path[0]), + "/mnt/preview/%s_%lld.yuv", "preview", GetCurrentLocalTimeStamp()); } else { system("mkdir -p /mnt/capture"); - (void) sprintf_s(path, sizeof(path) / sizeof(path[0]), - "/mnt/capture/%s_%lld.jpg", "photo", GetCurrentLocalTimeStamp()); + (void)sprintf_s(path, sizeof(path) / sizeof(path[0]), + "/mnt/capture/%s_%lld.jpg", "photo", GetCurrentLocalTimeStamp()); } MEDIA_DEBUG_LOG("%s, saving file to %{public}s", __FUNCTION__, path); - int imgFd = open(path, O_RDWR | O_CREAT, 00766); + int imgFd = open(path, O_RDWR | O_CREAT, FILE_PERMISSION_FLAG); if (imgFd == -1) { MEDIA_DEBUG_LOG("%s, open file failed, errno = %{public}s.", __FUNCTION__, strerror(errno)); return -1; @@ -133,20 +143,20 @@ int32_t SaveYUV(int32_t mode, void* buffer, int32_t size) return 0; } -int32_t SaveVideoFile(const void* buffer, int32_t size, int32_t operationMode) +static int32_t SaveVideoFile(const char *buffer, int32_t size, int32_t operationMode) { - if (operationMode == 0) { + if (operationMode == CREATE) { char path[255] = {0}; system("mkdir -p /mnt/video"); - (void) sprintf_s(path, sizeof(path) / sizeof(path[0]), - "/mnt/video/%s_%lld.h264", "video", GetCurrentLocalTimeStamp()); + (void)sprintf_s(path, sizeof(path) / sizeof(path[0]), + "/mnt/video/%s_%lld.h264", "video", GetCurrentLocalTimeStamp()); MEDIA_DEBUG_LOG("%s, save video to file %s", __FUNCTION__, path); - sVideoFd = open(path, O_RDWR | O_CREAT, 00766); + sVideoFd = open(path, O_RDWR | O_CREAT, FILE_PERMISSION_FLAG); if (sVideoFd == -1) { std::cout << "open file failed, errno = " << strerror(errno) << std::endl; return -1; } - } else if (operationMode == 1 && sVideoFd != -1) { + } else if (operationMode == APPEND && sVideoFd != -1) { int32_t ret = write(sVideoFd, buffer, size); if (ret == -1) { std::cout << "write file failed, error = " << strerror(errno) << std::endl; @@ -170,7 +180,7 @@ public: { if (sVideoFd == -1) { // Create video file - SaveVideoFile(nullptr, 0, 0); + SaveVideoFile(nullptr, 0, CREATE); } int32_t flushFence = 0; int64_t timestamp = 0; @@ -179,10 +189,10 @@ public: OHOS::sptr buffer = nullptr; surface_->AcquireBuffer(buffer, flushFence, timestamp, damage); if (buffer != nullptr) { - void *addr = buffer->GetVirAddr(); + char *addr = static_cast(buffer->GetVirAddr()); int32_t size = buffer->GetSize(); MEDIA_DEBUG_LOG("Saving to video file"); - SaveVideoFile(addr, size, 1); + SaveVideoFile(addr, size, APPEND); surface_->ReleaseBuffer(buffer, -1); } else { MEDIA_DEBUG_LOG("AcquireBuffer failed!"); @@ -204,7 +214,7 @@ public: OHOS::sptr buffer = nullptr; surface_->AcquireBuffer(buffer, flushFence, timestamp, damage); if (buffer != nullptr) { - void *addr = buffer->GetVirAddr(); + char *addr = static_cast(buffer->GetVirAddr()); int32_t size = buffer->GetSize(); MEDIA_DEBUG_LOG("Calling SaveYUV"); SaveYUV(mode_, addr, size); @@ -215,11 +225,54 @@ public: } }; -int main() +static bool IsNumber(char number[]) +{ + for (int i = 0; number[i] != 0; i++) { + if (!std::isdigit(number[i])) { + return false; + } + } + return true; +} + +int main(int argc, char **argv) { + const std::int32_t PREVIEW_DEFAULT_WIDTH = 640; + const std::int32_t PREVIEW_DEFAULT_HEIGHT = 480; + const std::int32_t VIDEO_DEFAULT_WIDTH = 1280; + const std::int32_t VIDEO_DEFAULT_HEIGHT = 720; + const std::int32_t PREVIEW_WIDTH_INDEX = 1; + const std::int32_t PREVIEW_HEIGHT_INDEX = 2; + const std::int32_t VIDEO_WIDTH_INDEX = 3; + const std::int32_t VIDEO_HEIGHT_INDEX = 4; + const std::int32_t VALID_ARG_COUNT = 5; + const std::int32_t VIDEO_CAPTURE_DURATION = 10; // Sleep for 10 sec + const std::int32_t PREVIEW_VIDEO_GAP = 2; // Sleep for 2 sec int32_t intResult = -1; - MEDIA_DEBUG_LOG("Camera new sample begin."); + // Default sizes for PreviewOutput and VideoOutput + int32_t previewWidth = PREVIEW_DEFAULT_WIDTH; + int32_t previewHeight = PREVIEW_DEFAULT_HEIGHT; + int32_t videoWidth = VIDEO_DEFAULT_WIDTH; + int32_t videoHeight = VIDEO_DEFAULT_HEIGHT; + MEDIA_DEBUG_LOG("Camera new sample begin."); + // Update sizes if enough number of valid arguments are passed + if (argc == VALID_ARG_COUNT) { + // Validate arguments and consider if valid + for (int counter = 1; counter < argc; counter++) { + if (!IsNumber(argv[counter])) { + cout << "Invalid argument: " << argv[counter] << endl; + cout << "Retry by giving proper sizes" << endl; + return 0; + } + } + previewWidth = atoi(argv[PREVIEW_WIDTH_INDEX]); + previewHeight = atoi(argv[PREVIEW_HEIGHT_INDEX]); + videoWidth = atoi(argv[VIDEO_WIDTH_INDEX]); + videoHeight = atoi(argv[VIDEO_HEIGHT_INDEX]); + } + MEDIA_DEBUG_LOG("previewWidth: %{public}d, previewHeight: %{public}d", previewWidth, previewHeight); + MEDIA_DEBUG_LOG("videoWidth: %{public}d, videoHeight: %{public}d", videoWidth, videoHeight); sptr camManagerObj = CameraManager::GetInstance(); std::shared_ptr cameraMngrCallback = make_shared(); MEDIA_DEBUG_LOG("Setting callback to listen camera status and flash status"); @@ -238,10 +291,11 @@ int main() sptr cameraInput = camManagerObj->CreateCameraInput(cameraObjList[0]); if (cameraInput != nullptr) { std::shared_ptr deviceCallback = make_shared(); - ((sptr &) cameraInput)->SetErrorCallback(deviceCallback); + ((sptr &)cameraInput)->SetErrorCallback(deviceCallback); intResult = captureSession->AddInput(cameraInput); if (intResult == 0) { previewSurface = Surface::CreateSurfaceAsConsumer(); + previewSurface->SetDefaultWidthAndHeight(previewWidth, previewHeight); sptr listener = new SurfaceListener(); listener->mode_ = MODE_PREVIEW; listener->surface_ = previewSurface; @@ -260,6 +314,7 @@ int main() return 0; } videoSurface = Surface::CreateSurfaceAsConsumer(); + videoSurface->SetDefaultWidthAndHeight(videoWidth, videoHeight); sptr videoListener = new VideoSurfaceListener(); videoListener->surface_ = videoSurface; videoSurface->RegisterConsumerListener((sptr &)videoListener); @@ -287,21 +342,17 @@ int main() return 0; } MEDIA_DEBUG_LOG("Preview started"); - MEDIA_DEBUG_LOG("Waiting for 2 seconds begin"); - sleep(2); - MEDIA_DEBUG_LOG("Waiting for 2 seconds end"); + sleep(PREVIEW_VIDEO_GAP); MEDIA_DEBUG_LOG("Start video recording"); ((sptr &)videoOutput)->Start(); - MEDIA_DEBUG_LOG("Waiting for 10 seconds begin"); - sleep(10); - MEDIA_DEBUG_LOG("Waiting for 10 seconds end"); + sleep(VIDEO_CAPTURE_DURATION); MEDIA_DEBUG_LOG("Stop video recording"); ((sptr &)videoOutput)->Stop(); MEDIA_DEBUG_LOG("Closing the session"); captureSession->Stop(); captureSession->Release(); // Close video file - SaveVideoFile(nullptr, 0, 2); + SaveVideoFile(nullptr, 0, CLOSE); camManagerObj->SetCallback(nullptr); } else { MEDIA_DEBUG_LOG("Add input to session is failed, intResult: %{public}d", intResult); diff --git a/interfaces/kits/js/camera_napi/include/camera_napi.h b/interfaces/kits/js/camera_napi/include/camera_napi.h index c751b988e..9c73146af 100644 --- a/interfaces/kits/js/camera_napi/include/camera_napi.h +++ b/interfaces/kits/js/camera_napi/include/camera_napi.h @@ -60,6 +60,10 @@ struct MediaLocation { }; static const std::int32_t SIZE = 100; +static const std::int32_t PHOTO_DEFAULT_WIDTH = 1280; +static const std::int32_t PHOTO_DEFAULT_HEIGHT = 960; +static const std::int32_t SURFACE_DEFAULT_WIDTH = 480; +static const std::int32_t SURFACE_DEFAULT_HEIGHT = 480; static const std::string CAMERA_MNGR_NAPI_CLASS_NAME = "Camera"; static const std::int32_t REFERENCE_CREATION_COUNT = 1; static const std::int32_t ARGS_MAX_TWO_COUNT = 2; @@ -112,7 +116,7 @@ static const std::vector vecQualityLevel { static const std::vector vecFileFormat { "FORMAT_DEFAULT", "MP4", "FORMAT_M4A", "FORMAT_BUTT" }; static const std::vector vecVideoEncoder { "H264" }; static const std::vector vecAudioEncoder { "AAC_LC" }; -static const std::vector vecParameterResult { "ERROR_UNKNOWN", "PARAMETERS_RESULT"}; +static const std::vector vecParameterResult { "ERROR_UNKNOWN", "PARAMETERS_RESULT" }; #define GET_PARAMS(env, info, num) \ size_t argc = num; \ diff --git a/services/camera_service/binder/base/include/icamera_service.h b/services/camera_service/binder/base/include/icamera_service.h index b991d2bc8..3b446db5e 100644 --- a/services/camera_service/binder/base/include/icamera_service.h +++ b/services/camera_service/binder/base/include/icamera_service.h @@ -44,6 +44,9 @@ public: virtual int32_t CreatePreviewOutput(const sptr &producer, sptr &previewOutput) = 0; + virtual int32_t CreateCustomPreviewOutput(const sptr &producer, int32_t width, + int32_t height, sptr &previewOutput) = 0; + virtual int32_t CreateVideoOutput(const sptr &producer, sptr &videoOutput) = 0; diff --git a/services/camera_service/binder/base/include/remote_request_code.h b/services/camera_service/binder/base/include/remote_request_code.h index 4faf5281c..d4675f373 100644 --- a/services/camera_service/binder/base/include/remote_request_code.h +++ b/services/camera_service/binder/base/include/remote_request_code.h @@ -59,6 +59,7 @@ enum CameraServiceRequestCode { CAMERA_SERVICE_CREATE_CAPTURE_SESSION, CAMERA_SERVICE_CREATE_PHOTO_OUTPUT, CAMERA_SERVICE_CREATE_PREVIEW_OUTPUT, + CAMERA_SERVICE_CREATE_PREVIEW_OUTPUT_CUSTOM_SIZE, CAMERA_SERVICE_CREATE_VIDEO_OUTPUT }; diff --git a/services/camera_service/binder/client/include/hcamera_service_proxy.h b/services/camera_service/binder/client/include/hcamera_service_proxy.h index 040e4b389..50ca8379e 100644 --- a/services/camera_service/binder/client/include/hcamera_service_proxy.h +++ b/services/camera_service/binder/client/include/hcamera_service_proxy.h @@ -42,6 +42,9 @@ public: int32_t CreatePreviewOutput(const sptr &producer, sptr& previewOutput) override; + int32_t CreateCustomPreviewOutput(const sptr &producer, int32_t width, int32_t height, + sptr& previewOutput) override; + int32_t CreateVideoOutput(const sptr &producer, sptr& videoOutput) override; private: diff --git a/services/camera_service/binder/client/src/hcamera_service_proxy.cpp b/services/camera_service/binder/client/src/hcamera_service_proxy.cpp index 1a79aea6c..9bf6b649c 100644 --- a/services/camera_service/binder/client/src/hcamera_service_proxy.cpp +++ b/services/camera_service/binder/client/src/hcamera_service_proxy.cpp @@ -194,7 +194,46 @@ int32_t HCameraServiceProxy::CreatePreviewOutput(const sptr &producer, sptr& videoOutput) +int32_t HCameraServiceProxy::CreateCustomPreviewOutput(const sptr &producer, int32_t width, + int32_t height, sptr& previewOutput) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (producer == nullptr || width == 0 || height == 0) { + MEDIA_ERR_LOG("HCameraServiceProxy CreateCustomPreviewOutput producer is null or invalid size is set"); + return IPC_PROXY_ERR; + } + if (!data.WriteRemoteObject(producer->AsObject())) { + MEDIA_ERR_LOG("HCameraServiceProxy CreateCustomPreviewOutput write producer obj failed"); + return IPC_PROXY_ERR; + } + if (!data.WriteInt32(width)) { + MEDIA_ERR_LOG("HCameraDeviceCallbackProxy Write width failed"); + return IPC_PROXY_ERR; + } + if (!data.WriteInt32(height)) { + MEDIA_ERR_LOG("HCameraDeviceCallbackProxy Write height failed"); + return IPC_PROXY_ERR; + } + int error = Remote()->SendRequest(CAMERA_SERVICE_CREATE_PREVIEW_OUTPUT_CUSTOM_SIZE, data, reply, option); + if (error != ERR_NONE) { + MEDIA_ERR_LOG("HCameraServiceProxy CreateCustomPreviewOutput failed, error: %{public}d", error); + return error; + } + auto remoteObject = reply.ReadRemoteObject(); + if (remoteObject != nullptr) { + previewOutput = iface_cast(remoteObject); + } else { + MEDIA_ERR_LOG("HCameraServiceProxy CreateCustomPreviewOutput previewOutput is null"); + error = IPC_PROXY_ERR; + } + return error; +} + +int32_t HCameraServiceProxy::CreateVideoOutput(const sptr &producer, + sptr& videoOutput) { MessageParcel data; MessageParcel reply; diff --git a/services/camera_service/binder/server/include/hcamera_service_stub.h b/services/camera_service/binder/server/include/hcamera_service_stub.h index ab8ccc375..cedce8e6e 100644 --- a/services/camera_service/binder/server/include/hcamera_service_stub.h +++ b/services/camera_service/binder/server/include/hcamera_service_stub.h @@ -33,6 +33,7 @@ private: int HandleCreateCaptureSession(MessageParcel &reply); int HandleCreatePhotoOutput(MessageParcel &data, MessageParcel &reply); int HandleCreatePreviewOutput(MessageParcel &data, MessageParcel &reply); + int HandleCreatePreviewOutputCustomSize(MessageParcel &data, MessageParcel &reply); int HandleCreateVideoOutput(MessageParcel &data, MessageParcel &reply); }; } // namespace CameraStandard diff --git a/services/camera_service/binder/server/src/hcamera_service_stub.cpp b/services/camera_service/binder/server/src/hcamera_service_stub.cpp index c7cbbd817..752b48d39 100644 --- a/services/camera_service/binder/server/src/hcamera_service_stub.cpp +++ b/services/camera_service/binder/server/src/hcamera_service_stub.cpp @@ -44,6 +44,9 @@ int HCameraServiceStub::OnRemoteRequest( case CAMERA_SERVICE_CREATE_PREVIEW_OUTPUT: errCode = HCameraServiceStub::HandleCreatePreviewOutput(data, reply); break; + case CAMERA_SERVICE_CREATE_PREVIEW_OUTPUT_CUSTOM_SIZE: + errCode = HCameraServiceStub::HandleCreatePreviewOutputCustomSize(data, reply); + break; case CAMERA_SERVICE_CREATE_VIDEO_OUTPUT: errCode = HCameraServiceStub::HandleCreateVideoOutput(data, reply); break; @@ -184,6 +187,31 @@ int HCameraServiceStub::HandleCreatePreviewOutput(MessageParcel &data, MessagePa return errCode; } +int HCameraServiceStub::HandleCreatePreviewOutputCustomSize(MessageParcel &data, MessageParcel &reply) +{ + sptr previewOutput = nullptr; + + sptr remoteObj = data.ReadRemoteObject(); + if (remoteObj == nullptr) { + MEDIA_ERR_LOG("HCameraServiceStub HandleCreatePreviewOutput BufferProducer is null"); + return IPC_STUB_INVALID_DATA_ERR; + } + int32_t width = data.ReadInt32(); + int32_t height = data.ReadInt32(); + MEDIA_INFO_LOG("CreatePreviewOutput with custom sizes, width: %{public}d, height: %{public}d", width, height); + sptr producer = iface_cast(remoteObj); + int errCode = CreateCustomPreviewOutput(producer, width, height, previewOutput); + if (errCode != ERR_NONE) { + MEDIA_ERR_LOG("HandleCreatePreviewOutput CreatePreviewOutput failed : %{public}d", errCode); + return errCode; + } + if (!reply.WriteRemoteObject(previewOutput->AsObject())) { + MEDIA_ERR_LOG("HCameraServiceStub HandleCreatePreviewOutput Write previewOutput obj failed"); + return IPC_STUB_WRITE_PARCEL_ERR; + } + return errCode; +} + int HCameraServiceStub::HandleCreateVideoOutput(MessageParcel &data, MessageParcel &reply) { sptr videoOutput = nullptr; diff --git a/services/camera_service/include/camera_util.h b/services/camera_service/include/camera_util.h index e74fe0206..9ba5f9ba3 100644 --- a/services/camera_service/include/camera_util.h +++ b/services/camera_service/include/camera_util.h @@ -20,38 +20,33 @@ namespace OHOS { namespace CameraStandard { -enum { - CAMERA_PREVIEW_WIDTH = 640, - CAMERA_PREVIEW_HEIGHT = 480, - CAMERA_PREVIEW_COLOR_SPACE = 8, - CAMERA_PREVIEW_CAPTURE_ID = 101, - CAMERA_PREVIEW_STREAM_ID = 1001, - - CAMERA_PHOTO_WIDTH = 1280, - CAMERA_PHOTO_HEIGHT = 960, - CAMERA_PHOTO_COLOR_SPACE = 8, - CAMERA_PHOTO_CAPTURE_ID = 102, - CAMERA_PHOTO_STREAM_ID = 1002, - - CAMERA_VIDEO_WIDTH = 1280, - CAMERA_VIDEO_HEIGHT = 720, - CAMERA_VIDEO_COLOR_SPACE = 8, - CAMERA_VIDEO_CAPTURE_ID = 103, - CAMERA_VIDEO_STREAM_ID = 1003 -}; +static const std::int32_t CAMERA_PREVIEW_COLOR_SPACE = 8; +static const std::int32_t CAMERA_PREVIEW_CAPTURE_ID = 101; +static const std::int32_t CAMERA_PREVIEW_STREAM_ID = 1001; + +static const std::int32_t CAMERA_PHOTO_COLOR_SPACE = 8; +static const std::int32_t CAMERA_PHOTO_CAPTURE_ID = 102; +static const std::int32_t CAMERA_PHOTO_STREAM_ID = 1002; + +static const std::int32_t CAMERA_VIDEO_COLOR_SPACE = 8; +static const std::int32_t CAMERA_VIDEO_CAPTURE_ID = 103; +static const std::int32_t CAMERA_VIDEO_STREAM_ID = 1003; enum CamServiceError { - CAMERA_OK, + CAMERA_OK = 0, CAMERA_ALLOC_ERROR, CAMERA_INVALID_ARG, CAMERA_DEVICE_BUSY, CAMERA_DEVICE_CLOSED, CAMERA_DEVICE_REQUEST_TIMEOUT, CAMERA_STREAM_BUFFER_LOST, + CAMERA_INVALID_OUTPUT_CFG, CAMERA_UNKNOWN_ERROR }; int HdiToServiceError(Camera::CamRetCode ret); + +bool IsValidSize(int32_t width, int32_t height, std::vector> validSizes); } // namespace CameraStandard } // namespace OHOS #endif // OHOS_CAMERA_UTIL_H diff --git a/services/camera_service/include/hcamera_service.h b/services/camera_service/include/hcamera_service.h index 11f7f2dbe..8feae1616 100644 --- a/services/camera_service/include/hcamera_service.h +++ b/services/camera_service/include/hcamera_service.h @@ -47,6 +47,8 @@ public: int32_t CreatePhotoOutput(const sptr &producer, sptr &photoOutput) override; int32_t CreatePreviewOutput(const sptr &producer, sptr &previewOutput) override; + int32_t CreateCustomPreviewOutput(const sptr &producer, int32_t width, int32_t height, + sptr &previewOutput) override; int32_t CreateVideoOutput(const sptr &producer, sptr &videoOutput) override; int32_t SetCallback(sptr &callback) override; void OnDump() override; diff --git a/services/camera_service/include/hstream_capture.h b/services/camera_service/include/hstream_capture.h index df90e8e78..e6218bd1d 100644 --- a/services/camera_service/include/hstream_capture.h +++ b/services/camera_service/include/hstream_capture.h @@ -48,6 +48,7 @@ private: sptr producer_; sptr streamCaptureCallback_; std::shared_ptr cameraAbility_; + std::vector> validSizes_ = {{1280, 960}}; }; } // namespace CameraStandard } // namespace OHOS diff --git a/services/camera_service/include/hstream_repeat.h b/services/camera_service/include/hstream_repeat.h index 1eea94ff0..6926eb412 100644 --- a/services/camera_service/include/hstream_repeat.h +++ b/services/camera_service/include/hstream_repeat.h @@ -29,6 +29,7 @@ namespace CameraStandard { class HStreamRepeat : public HStreamRepeatStub { public: HStreamRepeat(sptr producer); + HStreamRepeat(sptr producer, int32_t width, int32_t height); HStreamRepeat(sptr producer, bool isVideo); ~HStreamRepeat(); @@ -55,12 +56,16 @@ private: int32_t StopPreview(); int32_t StopVideo(); bool isVideo_; + int32_t customPreviewWidth_; + int32_t customPreviewHeight_; sptr streamOperator_; int32_t previewStreamId_, previewCaptureId_; int32_t videoStreamId_, videoCaptureId_; sptr producer_; sptr streamRepeatCallback_; std::shared_ptr cameraAbility_; + std::vector> validPreviewSizes_ = {{640, 480}, {832, 480}}; + std::vector> validVideoSizes_ = {{1280, 720}}; }; } // namespace CameraStandard } // namespace OHOS diff --git a/services/camera_service/src/camera_util.cpp b/services/camera_service/src/camera_util.cpp index 0f1b7aca0..f87569a61 100644 --- a/services/camera_service/src/camera_util.cpp +++ b/services/camera_service/src/camera_util.cpp @@ -41,5 +41,16 @@ int HdiToServiceError(Camera::CamRetCode ret) } return err; } + +bool IsValidSize(int32_t width, int32_t height, std::vector> validSizes) +{ + auto curPair = std::make_pair(width, height); + if (std::find(validSizes.begin(), validSizes.end(), curPair) != validSizes.end()) { + return true; + } else { + MEDIA_ERR_LOG("Width %{public}d and height %{public}d not found in suported sizes", width, height); + } + return false; } -} +} // namespace CameraStandard +} // namespace OHOS diff --git a/services/camera_service/src/hcamera_service.cpp b/services/camera_service/src/hcamera_service.cpp index 3ebbd1673..8ad754334 100644 --- a/services/camera_service/src/hcamera_service.cpp +++ b/services/camera_service/src/hcamera_service.cpp @@ -125,7 +125,8 @@ int32_t HCameraService::CreatePhotoOutput(const sptr &pro return CAMERA_OK; } -int32_t HCameraService::CreatePreviewOutput(const sptr &producer, sptr &previewOutput) +int32_t HCameraService::CreatePreviewOutput(const sptr &producer, + sptr &previewOutput) { sptr streamRepeatPreview; @@ -142,6 +143,24 @@ int32_t HCameraService::CreatePreviewOutput(const sptr &p return CAMERA_OK; } +int32_t HCameraService::CreateCustomPreviewOutput(const sptr &producer, int32_t width, + int32_t height, sptr &previewOutput) +{ + sptr streamRepeatPreview; + + if (producer == nullptr || width == 0 || height == 0) { + MEDIA_ERR_LOG("HCameraService::CreateCustomPreviewOutput producer is null or invalid custom size is set"); + return CAMERA_INVALID_ARG; + } + streamRepeatPreview = new HStreamRepeat(producer, width, height); + if (streamRepeatPreview == nullptr) { + MEDIA_ERR_LOG("HCameraService::CreateCustomPreviewOutput HStreamRepeat allocation failed"); + return CAMERA_ALLOC_ERROR; + } + previewOutput = streamRepeatPreview; + return CAMERA_OK; +} + int32_t HCameraService::CreateVideoOutput(const sptr &producer, sptr &videoOutput) { sptr streamRepeatVideo; diff --git a/services/camera_service/src/hcapture_session.cpp b/services/camera_service/src/hcapture_session.cpp index 5bea102f5..1e6513649 100644 --- a/services/camera_service/src/hcapture_session.cpp +++ b/services/camera_service/src/hcapture_session.cpp @@ -132,21 +132,33 @@ int32_t HCaptureSession::CommitConfig() streamIds_.clear(); cameraAbility_ = cameraDevice_->GetSettings(); if (streamRepeatPreview_ != nullptr) { - streamRepeatPreview_->LinkInput(streamOperator_, cameraAbility_, previewStreamID_); + rc = streamRepeatPreview_->LinkInput(streamOperator_, cameraAbility_, previewStreamID_); + if (rc != CAMERA_OK) { + MEDIA_ERR_LOG("HCaptureSession::CommitConfig(), Failed to link input to PreviewOutput, %{public}d", rc); + return rc; + } streamInfo = std::make_shared(); streamRepeatPreview_->SetStreamInfo(streamInfo); streamInfos.push_back(streamInfo); streamIds_.push_back(previewStreamID_); } if (streamCapture_ != nullptr) { - streamCapture_->LinkInput(streamOperator_, cameraAbility_, photoStreamID_); + rc = streamCapture_->LinkInput(streamOperator_, cameraAbility_, photoStreamID_); + if (rc != CAMERA_OK) { + MEDIA_ERR_LOG("HCaptureSession::CommitConfig(), Failed to link input to PhotoOutput, %{public}d", rc); + return rc; + } streamInfo = std::make_shared(); streamCapture_->SetStreamInfo(streamInfo); streamInfos.push_back(streamInfo); streamIds_.push_back(photoStreamID_); } if (streamRepeatVideo_ != nullptr) { - streamRepeatVideo_->LinkInput(streamOperator_, cameraAbility_, videoStreamID_); + rc = streamRepeatVideo_->LinkInput(streamOperator_, cameraAbility_, videoStreamID_); + if (rc != CAMERA_OK) { + MEDIA_ERR_LOG("HCaptureSession::CommitConfig(), Failed to link input to VideoOutput, %{public}d", rc); + return rc; + } streamInfo = std::make_shared(); streamRepeatVideo_->SetStreamInfo(streamInfo); streamInfos.push_back(streamInfo); @@ -305,14 +317,15 @@ void StreamOperatorCallback::OnFrameShutter(int32_t captureId, const std::vector &streamId, uint64_t timestamp) { if (captureId == CAMERA_PHOTO_CAPTURE_ID && captureSession_ != nullptr - && captureSession_->streamCapture_ != nullptr) { + && captureSession_->streamCapture_ != nullptr) { captureSession_->streamCapture_->OnFrameShutter(captureId, timestamp); } else { MEDIA_INFO_LOG("HCaptureSession::OnFrameShutter(), called for other streams too"); } } -void StreamOperatorCallback::SetCaptureSession(sptr captureSession) { +void StreamOperatorCallback::SetCaptureSession(sptr captureSession) +{ captureSession_ = captureSession; } } // namespace CameraStandard diff --git a/services/camera_service/src/hstream_capture.cpp b/services/camera_service/src/hstream_capture.cpp index bdfe138da..6e5076d6b 100644 --- a/services/camera_service/src/hstream_capture.cpp +++ b/services/camera_service/src/hstream_capture.cpp @@ -38,6 +38,9 @@ int32_t HStreamCapture::LinkInput(sptr &streamOperator, MEDIA_ERR_LOG("HStreamCapture::LinkInput streamOperator is null"); return CAMERA_INVALID_ARG; } + if (!IsValidSize(producer_->GetDefaultWidth(), producer_->GetDefaultHeight(), validSizes_)) { + return CAMERA_INVALID_OUTPUT_CFG; + } streamOperator_ = streamOperator; photoStreamId_ = streamId; cameraAbility_ = cameraAbility; @@ -47,8 +50,8 @@ int32_t HStreamCapture::LinkInput(sptr &streamOperator, void HStreamCapture::SetStreamInfo(std::shared_ptr streamInfoPhoto) { streamInfoPhoto->streamId_ = photoStreamId_; - streamInfoPhoto->width_ = CAMERA_PHOTO_WIDTH; - streamInfoPhoto->height_ = CAMERA_PHOTO_HEIGHT; + streamInfoPhoto->width_ = producer_->GetDefaultWidth(); + streamInfoPhoto->height_ = producer_->GetDefaultHeight(); streamInfoPhoto->format_ = PIXEL_FMT_YCRCB_420_SP; streamInfoPhoto->datasapce_ = CAMERA_PHOTO_COLOR_SPACE; streamInfoPhoto->intent_ = Camera::STILL_CAPTURE; diff --git a/services/camera_service/src/hstream_repeat.cpp b/services/camera_service/src/hstream_repeat.cpp index 4df96d78a..b085ca89c 100644 --- a/services/camera_service/src/hstream_repeat.cpp +++ b/services/camera_service/src/hstream_repeat.cpp @@ -29,6 +29,20 @@ HStreamRepeat::HStreamRepeat(sptr producer) videoCaptureId_ = 0; previewStreamId_ = 0; previewCaptureId_ = 0; + customPreviewWidth_ = 0; + customPreviewHeight_ = 0; +} + +HStreamRepeat::HStreamRepeat(sptr producer, int32_t width, int32_t height) +{ + producer_ = producer; + isVideo_ = false; + videoStreamId_ = 0; + videoCaptureId_ = 0; + previewStreamId_ = 0; + previewCaptureId_ = 0; + customPreviewWidth_ = width; + customPreviewHeight_ = height; } HStreamRepeat::HStreamRepeat(sptr producer, bool isVideo) @@ -39,24 +53,37 @@ HStreamRepeat::HStreamRepeat(sptr producer, bool isVideo) videoCaptureId_ = 0; previewStreamId_ = 0; previewCaptureId_ = 0; + customPreviewWidth_ = 0; + customPreviewHeight_ = 0; } HStreamRepeat::~HStreamRepeat() {} int32_t HStreamRepeat::LinkInput(sptr &streamOperator, - std::shared_ptr cameraAbility, int32_t streamId) + std::shared_ptr cameraAbility, int32_t streamId) { + int32_t previewWidth = 0; + int32_t previewHeight = 0; + if (streamOperator == nullptr || cameraAbility == nullptr) { MEDIA_ERR_LOG("HStreamRepeat::LinkInput streamOperator is null"); return CAMERA_INVALID_ARG; } - streamOperator_ = streamOperator; if (isVideo_) { + if (!IsValidSize(producer_->GetDefaultWidth(), producer_->GetDefaultHeight(), validVideoSizes_)) { + return CAMERA_INVALID_OUTPUT_CFG; + } videoStreamId_ = streamId; } else { + previewWidth = (customPreviewWidth_ == 0) ? producer_->GetDefaultWidth() : customPreviewWidth_; + previewHeight = (customPreviewHeight_ == 0) ? producer_->GetDefaultHeight() : customPreviewHeight_; + if (!IsValidSize(previewWidth, previewHeight, validPreviewSizes_)) { + return CAMERA_INVALID_OUTPUT_CFG; + } previewStreamId_ = streamId; } + streamOperator_ = streamOperator; cameraAbility_ = cameraAbility; return CAMERA_OK; } @@ -67,16 +94,14 @@ void HStreamRepeat::SetStreamInfo(std::shared_ptr streamInfo streamInfo->tunneledMode_ = true; streamInfo->datasapce_ = CAMERA_PREVIEW_COLOR_SPACE; streamInfo->bufferQueue_ = producer_; + streamInfo->width_ = (customPreviewWidth_ == 0) ? producer_->GetDefaultWidth() : customPreviewWidth_; + streamInfo->height_ = (customPreviewHeight_ == 0) ? producer_->GetDefaultHeight() : customPreviewHeight_; if (isVideo_) { streamInfo->streamId_ = videoStreamId_; - streamInfo->width_ = CAMERA_VIDEO_WIDTH; - streamInfo->height_ = CAMERA_VIDEO_HEIGHT; streamInfo->intent_ = Camera::VIDEO; streamInfo->encodeType_ = Camera::ENCODE_TYPE_H264; } else { streamInfo->streamId_ = previewStreamId_; - streamInfo->width_ = CAMERA_PREVIEW_WIDTH; - streamInfo->height_ = CAMERA_PREVIEW_HEIGHT; streamInfo->intent_ = Camera::PREVIEW; } } @@ -240,7 +265,7 @@ int32_t HStreamRepeat::OnFrameError(int32_t errorType) { if (streamRepeatCallback_ != nullptr) { if (errorType == Camera::BUFFER_LOST) { - streamRepeatCallback_->OnFrameError(CAMERA_STREAM_BUFFER_LOST); + streamRepeatCallback_->OnFrameError(CAMERA_STREAM_BUFFER_LOST); } else { streamRepeatCallback_->OnFrameError(CAMERA_UNKNOWN_ERROR); } -- Gitee