code review fixes

Signed-off-by: Veeresh Kadasani <veeresh.kadasani@huawei.com>
This commit is contained in:
Veeresh Kadasani
2022-03-21 14:32:23 +05:30
parent 2f2ae22b19
commit 5c6a35b9e3
92 changed files with 1003 additions and 694 deletions
Executable → Regular
View File
-1
View File
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Executable → Regular
View File
Executable → Regular
View File
View File

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

Before

Width:  |  Height:  |  Size: 83 KiB

After

Width:  |  Height:  |  Size: 83 KiB

View File

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

@@ -56,14 +56,14 @@ napi_value CameraInfoNapi::Init(napi_env env, napi_value exports)
DECLARE_NAPI_GETTER("connectionType", GetConnectionType)
};
status = napi_define_class(env, CAMERA_OBJECT_NAPI_CLASS_NAME.c_str(), NAPI_AUTO_LENGTH,
status = napi_define_class(env, CAMERA_OBJECT_NAPI_CLASS_NAME, NAPI_AUTO_LENGTH,
CameraInfoNapiConstructor, nullptr,
sizeof(camera_object_props) / sizeof(camera_object_props[PARAM0]),
camera_object_props, &ctorObj);
if (status == napi_ok) {
status = napi_create_reference(env, ctorObj, refCount, &sConstructor_);
if (status == napi_ok) {
status = napi_set_named_property(env, exports, CAMERA_OBJECT_NAPI_CLASS_NAME.c_str(), ctorObj);
status = napi_set_named_property(env, exports, CAMERA_OBJECT_NAPI_CLASS_NAME, ctorObj);
if (status == napi_ok) {
return exports;
}
@@ -135,14 +135,14 @@ napi_value CameraInputNapi::Init(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("on", On)
};
status = napi_define_class(env, CAMERA_INPUT_NAPI_CLASS_NAME.c_str(), NAPI_AUTO_LENGTH,
status = napi_define_class(env, CAMERA_INPUT_NAPI_CLASS_NAME, NAPI_AUTO_LENGTH,
CameraInputNapiConstructor, nullptr,
sizeof(camera_input_props) / sizeof(camera_input_props[PARAM0]),
camera_input_props, &ctorObj);
if (status == napi_ok) {
status = napi_create_reference(env, ctorObj, refCount, &sConstructor_);
if (status == napi_ok) {
status = napi_set_named_property(env, exports, CAMERA_INPUT_NAPI_CLASS_NAME.c_str(), ctorObj);
status = napi_set_named_property(env, exports, CAMERA_INPUT_NAPI_CLASS_NAME, ctorObj);
if (status == napi_ok) {
return exports;
}
@@ -355,8 +355,10 @@ napi_value CameraInputNapi::GetCameraId(napi_env env, napi_callback_info info)
status = napi_create_async_work(
env, nullptr, resource, [](napi_env env, void* data) {
auto context = static_cast<CameraInputAsyncContext*>(data);
context->cameraId = context->objectInfo->cameraId_;
context->status = true;
if (context->objectInfo != nullptr) {
context->cameraId = context->objectInfo->cameraId_;
context->status = true;
}
},
GetCameraIdAsyncCallbackComplete, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -409,9 +411,11 @@ napi_value CameraInputNapi::HasFlash(napi_env env, napi_callback_info info)
status = napi_create_async_work(
env, nullptr, resource, [](napi_env env, void* data) {
auto context = static_cast<CameraInputAsyncContext*>(data);
std::vector<camera_flash_mode_enum_t> list;
list = context->objectInfo->cameraInput_->GetSupportedFlashModes();
context->status = !(list.empty());
if (context->objectInfo != nullptr) {
std::vector<camera_flash_mode_enum_t> list;
list = context->objectInfo->cameraInput_->GetSupportedFlashModes();
context->status = !(list.empty());
}
},
CommonCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -450,7 +454,9 @@ napi_value CameraInputNapi::IsFlashModeSupported(napi_env env, napi_callback_inf
env, nullptr, resource,
[](napi_env env, void* data) {
auto context = static_cast<CameraInputAsyncContext*>(data);
context->status = IsFlashSupported(context->objectInfo->cameraInput_, context->flashMode);
if (context->objectInfo != nullptr) {
context->status = IsFlashSupported(context->objectInfo->cameraInput_, context->flashMode);
}
},
CommonCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -515,16 +521,18 @@ napi_value CameraInputNapi::SetFlashMode(napi_env env, napi_callback_info info)
env, nullptr, resource,
[](napi_env env, void* data) {
auto context = static_cast<CameraInputAsyncContext*>(data);
sptr<CameraInput> cameraInput = context->objectInfo->cameraInput_;
if (IsFlashSupported(cameraInput, context->flashMode)) {
cameraInput->LockForControl();
cameraInput->SetFlashMode(static_cast<camera_flash_mode_enum_t>(context->flashMode));
cameraInput->SetExposureMode(OHOS_CAMERA_AE_MODE_ON_ALWAYS_FLASH);
cameraInput->UnlockForControl();
context->status = true;
} else {
MEDIA_ERR_LOG("Flash mode is not supported");
context->status = false;
if (context->objectInfo != nullptr) {
sptr<CameraInput> cameraInput = context->objectInfo->cameraInput_;
if (IsFlashSupported(cameraInput, context->flashMode)) {
cameraInput->LockForControl();
cameraInput->SetFlashMode(static_cast<camera_flash_mode_enum_t>(context->flashMode));
cameraInput->SetExposureMode(OHOS_CAMERA_AE_MODE_ON_ALWAYS_FLASH);
cameraInput->UnlockForControl();
context->status = true;
} else {
MEDIA_ERR_LOG("Flash mode is not supported");
context->status = false;
}
}
},
ReturnVoidInCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
@@ -584,8 +592,10 @@ napi_value CameraInputNapi::GetFlashMode(napi_env env, napi_callback_info info)
status = napi_create_async_work(
env, nullptr, resource, [](napi_env env, void* data) {
auto context = static_cast<CameraInputAsyncContext*>(data);
context->flashMode = context->objectInfo->cameraInput_->GetFlashMode();
context->status = true;
if (context->objectInfo != nullptr) {
context->flashMode = context->objectInfo->cameraInput_->GetFlashMode();
context->status = true;
}
},
GetFlashModeAsyncCallbackComplete, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -688,8 +698,10 @@ napi_value CameraInputNapi::GetExposureMode(napi_env env, napi_callback_info inf
status = napi_create_async_work(
env, nullptr, resource, [](napi_env env, void* data) {
auto context = static_cast<CameraInputAsyncContext*>(data);
context->exposureMode = context->objectInfo->cameraInput_->GetExposureMode();
context->status = true;
if (context->objectInfo != nullptr) {
context->exposureMode = context->objectInfo->cameraInput_->GetExposureMode();
context->status = true;
}
},
GetExposureModeAsyncCallbackComplete, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -728,9 +740,11 @@ napi_value CameraInputNapi::SetExposureMode(napi_env env, napi_callback_info inf
env, nullptr, resource,
[](napi_env env, void* data) {
auto context = static_cast<CameraInputAsyncContext*>(data);
context->objectInfo->cameraInput_->
SetExposureMode(static_cast<camera_ae_mode_t>(context->exposureMode));
context->status = true;
if (context->objectInfo != nullptr) {
context->objectInfo->cameraInput_->
SetExposureMode(static_cast<camera_ae_mode_t>(context->exposureMode));
context->status = true;
}
},
ReturnVoidInCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -769,19 +783,21 @@ napi_value CameraInputNapi::IsFocusModeSupported(napi_env env, napi_callback_inf
status = napi_create_async_work(
env, nullptr, resource, [](napi_env env, void* data) {
auto context = static_cast<CameraInputAsyncContext*>(data);
if (context->focusModeLocked) {
MEDIA_INFO_LOG("FOCUS_MODE_LOCKED is supported");
context->status = true;
return;
}
if (context->objectInfo != nullptr) {
if (context->focusModeLocked) {
MEDIA_INFO_LOG("FOCUS_MODE_LOCKED is supported");
context->status = true;
return;
}
vector<camera_af_mode_t> vecSupportedFocusModeList;
vecSupportedFocusModeList = context->objectInfo->cameraInput_->GetSupportedFocusModes();
if (find(vecSupportedFocusModeList.begin(), vecSupportedFocusModeList.end(),
context->focusMode) != vecSupportedFocusModeList.end()) {
context->status = true;
} else {
context->status = false;
vector<camera_af_mode_t> vecSupportedFocusModeList;
vecSupportedFocusModeList = context->objectInfo->cameraInput_->GetSupportedFocusModes();
if (find(vecSupportedFocusModeList.begin(), vecSupportedFocusModeList.end(),
context->focusMode) != vecSupportedFocusModeList.end()) {
context->status = true;
} else {
context->status = false;
}
}
},
CommonCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
@@ -861,8 +877,11 @@ napi_value CameraInputNapi::GetSupportedPhotoFormats(napi_env env, napi_callback
status = napi_create_async_work(
env, nullptr, resource, [](napi_env env, void* data) {
auto context = static_cast<CameraInputAsyncContext*>(data);
context->vecSupportedPhotoFormatList = context->objectInfo->cameraInput_->GetSupportedPhotoFormats();
context->status = true;
if (context->objectInfo != nullptr) {
context->vecSupportedPhotoFormatList =
context->objectInfo->cameraInput_->GetSupportedPhotoFormats();
context->status = true;
}
},
GetSupportedPhotoFormatsAsyncCallbackComplete, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -940,8 +959,11 @@ napi_value CameraInputNapi::GetSupportedVideoFormats(napi_env env, napi_callback
status = napi_create_async_work(
env, nullptr, resource, [](napi_env env, void* data) {
auto context = static_cast<CameraInputAsyncContext*>(data);
context->vecSupportedVideoFormatList = context->objectInfo->cameraInput_->GetSupportedVideoFormats();
context->status = true;
if (context->objectInfo != nullptr) {
context->vecSupportedVideoFormatList =
context->objectInfo->cameraInput_->GetSupportedVideoFormats();
context->status = true;
}
},
GetSupportedVideoFormatsAsyncCallbackComplete, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -1019,9 +1041,11 @@ napi_value CameraInputNapi::GetSupportedPreviewFormats(napi_env env, napi_callba
status = napi_create_async_work(
env, nullptr, resource, [](napi_env env, void* data) {
auto context = static_cast<CameraInputAsyncContext*>(data);
context->vecSupportedPreviewFormatList =
context->objectInfo->cameraInput_->GetSupportedPreviewFormats();
context->status = true;
if (context->objectInfo != nullptr) {
context->vecSupportedPreviewFormatList =
context->objectInfo->cameraInput_->GetSupportedPreviewFormats();
context->status = true;
}
},
GetSupportedPreviewFormatsAsyncCallbackComplete,
static_cast<void*>(asyncContext.get()), &asyncContext->work);
@@ -1088,8 +1112,10 @@ napi_value CameraInputNapi::GetFocusMode(napi_env env, napi_callback_info info)
status = napi_create_async_work(
env, nullptr, resource, [](napi_env env, void* data) {
auto context = static_cast<CameraInputAsyncContext*>(data);
context->focusMode = context->objectInfo->cameraInput_->GetFocusMode();
context->status = true;
if (context->objectInfo != nullptr) {
context->focusMode = context->objectInfo->cameraInput_->GetFocusMode();
context->status = true;
}
},
GetFocusModeAsyncCallbackComplete, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -1129,23 +1155,25 @@ napi_value CameraInputNapi::SetFocusMode(napi_env env, napi_callback_info info)
env, nullptr, resource,
[](napi_env env, void* data) {
auto context = static_cast<CameraInputAsyncContext*>(data);
sptr<CameraInput> cameraInput = context->objectInfo->cameraInput_;
context->status = true;
if (context->focusModeLocked) {
MEDIA_INFO_LOG("Focus mode set is FOCUS_MODE_LOCKED");
return;
}
if (context->objectInfo != nullptr) {
sptr<CameraInput> cameraInput = context->objectInfo->cameraInput_;
context->status = true;
if (context->focusModeLocked) {
MEDIA_INFO_LOG("Focus mode set is FOCUS_MODE_LOCKED");
return;
}
vector<camera_af_mode_t> vecSupportedFocusModeList;
vecSupportedFocusModeList = context->objectInfo->cameraInput_->GetSupportedFocusModes();
if (find(vecSupportedFocusModeList.begin(), vecSupportedFocusModeList.end(),
context->focusMode) != vecSupportedFocusModeList.end()) {
cameraInput->LockForControl();
context->objectInfo->cameraInput_->SetFocusMode(context->focusMode);
cameraInput->UnlockForControl();
} else {
MEDIA_ERR_LOG("Focus mode is not supported");
context->status = false;
vector<camera_af_mode_t> vecSupportedFocusModeList;
vecSupportedFocusModeList = context->objectInfo->cameraInput_->GetSupportedFocusModes();
if (find(vecSupportedFocusModeList.begin(), vecSupportedFocusModeList.end(),
context->focusMode) != vecSupportedFocusModeList.end()) {
cameraInput->LockForControl();
context->objectInfo->cameraInput_->SetFocusMode(context->focusMode);
cameraInput->UnlockForControl();
} else {
MEDIA_ERR_LOG("Focus mode is not supported");
context->status = false;
}
}
},
ReturnVoidInCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
@@ -1225,9 +1253,11 @@ napi_value CameraInputNapi::GetSupportedSizes(napi_env env, napi_callback_info i
env, nullptr, resource,
[](napi_env env, void* data) {
auto context = static_cast<CameraInputAsyncContext*>(data);
context->vecSupportedSizeList =
context->objectInfo->cameraInput_->getSupportedSizes(context->cameraFormat);
context->status = true;
if (context->objectInfo != nullptr) {
context->vecSupportedSizeList =
context->objectInfo->cameraInput_->getSupportedSizes(context->cameraFormat);
context->status = true;
}
},
GetSupportedSizesAsyncCallbackComplete, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -1301,8 +1331,10 @@ napi_value CameraInputNapi::GetZoomRatioRange(napi_env env, napi_callback_info i
status = napi_create_async_work(
env, nullptr, resource, [](napi_env env, void* data) {
auto context = static_cast<CameraInputAsyncContext*>(data);
context->vecZoomRatioList = context->objectInfo->cameraInput_->GetSupportedZoomRatioRange();
context->status = true;
if (context->objectInfo != nullptr) {
context->vecZoomRatioList = context->objectInfo->cameraInput_->GetSupportedZoomRatioRange();
context->status = true;
}
},
GetZoomRatioRangeAsyncCallbackComplete, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -1366,8 +1398,10 @@ napi_value CameraInputNapi::GetZoomRatio(napi_env env, napi_callback_info info)
status = napi_create_async_work(
env, nullptr, resource, [](napi_env env, void* data) {
auto context = static_cast<CameraInputAsyncContext*>(data);
context->zoomRatio = context->objectInfo->cameraInput_->GetZoomRatio();
context->status = true;
if (context->objectInfo != nullptr) {
context->zoomRatio = context->objectInfo->cameraInput_->GetZoomRatio();
context->status = true;
}
},
GetZoomRatioAsyncCallbackComplete, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -1407,11 +1441,13 @@ napi_value CameraInputNapi::SetZoomRatio(napi_env env, napi_callback_info info)
env, nullptr, resource,
[](napi_env env, void* data) {
auto context = static_cast<CameraInputAsyncContext*>(data);
sptr<CameraInput> cameraInput = context->objectInfo->cameraInput_;
cameraInput->LockForControl();
cameraInput->SetZoomRatio(context->zoomRatio);
cameraInput->UnlockForControl();
context->status = true;
if (context->objectInfo != nullptr) {
sptr<CameraInput> cameraInput = context->objectInfo->cameraInput_;
cameraInput->LockForControl();
cameraInput->SetZoomRatio(context->zoomRatio);
cameraInput->UnlockForControl();
context->status = true;
}
},
ReturnVoidInCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -1453,8 +1489,10 @@ napi_value CameraInputNapi::Release(napi_env env, napi_callback_info info)
status = napi_create_async_work(
env, nullptr, resource, [](napi_env env, void* data) {
auto context = static_cast<CameraInputAsyncContext*>(data);
context->objectInfo->cameraInput_->Release();
context->status = true;
if (context->objectInfo != nullptr) {
context->objectInfo->cameraInput_->Release();
context->status = true;
}
},
ReturnVoidInCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -1478,19 +1516,19 @@ void CameraInputNapi::RegisterCallback(napi_env env, const string &eventType, na
if (eventType.compare("exposureStateChange") == 0) {
// Set callback for exposureStateChange
shared_ptr<ExposureCallbackListener> callback = make_shared<ExposureCallbackListener>(env, callbackRef);
cameraInput_->SetExposureCallback(callback);
exposureCallback_ = callback;
shared_ptr<ExposureCallbackListener> exposureCallback = make_shared<ExposureCallbackListener>(env, callbackRef);
cameraInput_->SetExposureCallback(exposureCallback);
exposureCallback_ = exposureCallback;
} else if (eventType.compare("focusStateChange") == 0) {
// Set callback for focusStateChange
shared_ptr<FocusCallbackListener> callback = make_shared<FocusCallbackListener>(env, callbackRef);
cameraInput_->SetFocusCallback(callback);
focusCallback_ = callback;
shared_ptr<FocusCallbackListener> focusCallback = make_shared<FocusCallbackListener>(env, callbackRef);
cameraInput_->SetFocusCallback(focusCallback);
focusCallback_ = focusCallback;
} else if (eventType.compare("error") == 0) {
// Set callback for error
shared_ptr<ErrorCallbackListener> callback = make_shared<ErrorCallbackListener>(env, callbackRef);
cameraInput_->SetErrorCallback(callback);
errorCallback_ = callback;
shared_ptr<ErrorCallbackListener> errorCallback = make_shared<ErrorCallbackListener>(env, callbackRef);
cameraInput_->SetErrorCallback(errorCallback);
errorCallback_ = errorCallback;
} else {
MEDIA_ERR_LOG("Incorrect callback event type provided for camera input!");
}
@@ -54,6 +54,10 @@ napi_value CameraManagerNapi::CameraManagerNapiConstructor(napi_env env, napi_ca
if (obj != nullptr) {
obj->env_ = env;
obj->cameraManager_ = CameraManager::GetInstance();
if (obj->cameraManager_ == nullptr) {
MEDIA_ERR_LOG("Failure wrapping js to native napi, obj->cameraManager_ null");
return result;
}
status = napi_wrap(env, thisVar, reinterpret_cast<void*>(obj.get()),
CameraManagerNapi::CameraManagerNapiDestructor, nullptr, &(obj->wrapper_));
if (status == napi_ok) {
@@ -89,13 +93,13 @@ napi_value CameraManagerNapi::Init(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("on", On)
};
status = napi_define_class(env, CAMERA_MANAGER_NAPI_CLASS_NAME.c_str(), NAPI_AUTO_LENGTH,
status = napi_define_class(env, CAMERA_MANAGER_NAPI_CLASS_NAME, NAPI_AUTO_LENGTH,
CameraManagerNapiConstructor, nullptr,
sizeof(camera_mgr_properties) / sizeof(camera_mgr_properties[PARAM0]),
camera_mgr_properties, &ctorObj);
if (status == napi_ok) {
if (napi_create_reference(env, ctorObj, refCount, &sConstructor_) == napi_ok) {
status = napi_set_named_property(env, exports, CAMERA_MANAGER_NAPI_CLASS_NAME.c_str(), ctorObj);
status = napi_set_named_property(env, exports, CAMERA_MANAGER_NAPI_CLASS_NAME, ctorObj);
if (status == napi_ok) {
return exports;
}
@@ -147,12 +147,12 @@ napi_value CameraNapi::Init(napi_env env, napi_value exports)
DECLARE_NAPI_PROPERTY("VideoOutputErrorCode", CreateErrorUnknownEnum(env))
};
status = napi_define_class(env, CAMERA_LIB_NAPI_CLASS_NAME.c_str(), NAPI_AUTO_LENGTH, CameraNapiConstructor,
status = napi_define_class(env, CAMERA_LIB_NAPI_CLASS_NAME, NAPI_AUTO_LENGTH, CameraNapiConstructor,
nullptr, sizeof(camera_properties) / sizeof(camera_properties[PARAM0]),
camera_properties, &ctorObj);
if (status == napi_ok) {
if (napi_create_reference(env, ctorObj, refCount, &sConstructor_) == napi_ok) {
status = napi_set_named_property(env, exports, CAMERA_LIB_NAPI_CLASS_NAME.c_str(), ctorObj);
status = napi_set_named_property(env, exports, CAMERA_LIB_NAPI_CLASS_NAME, ctorObj);
if (status == napi_ok && napi_define_properties(env, exports,
sizeof(camera_static_prop) / sizeof(camera_static_prop[PARAM0]), camera_static_prop) == napi_ok) {
return exports;
@@ -56,14 +56,14 @@ napi_value CameraSizeNapi::Init(napi_env env, napi_value exports)
DECLARE_NAPI_GETTER("height", GetCameraSizeHeight)
};
status = napi_define_class(env, CAMERA_SIZE_NAPI_CLASS_NAME.c_str(), NAPI_AUTO_LENGTH,
status = napi_define_class(env, CAMERA_SIZE_NAPI_CLASS_NAME, NAPI_AUTO_LENGTH,
CameraSizeNapiConstructor, nullptr,
sizeof(camera_size_props) / sizeof(camera_size_props[PARAM0]),
camera_size_props, &ctorObj);
if (status == napi_ok) {
status = napi_create_reference(env, ctorObj, refCount, &sConstructor_);
if (status == napi_ok) {
status = napi_set_named_property(env, exports, CAMERA_SIZE_NAPI_CLASS_NAME.c_str(), ctorObj);
status = napi_set_named_property(env, exports, CAMERA_SIZE_NAPI_CLASS_NAME, ctorObj);
if (status == napi_ok) {
return exports;
}
@@ -141,7 +141,7 @@ napi_value CameraSizeNapi::GetCameraSizeWidth(napi_env env, napi_callback_info i
}
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status == napi_ok && obj != nullptr) {
if ((status == napi_ok) && (obj != nullptr) && (obj->cameraPicSize_)) {
cameraSizeWidth = obj->cameraPicSize_->width;
status = napi_create_uint32(env, cameraSizeWidth, &jsResult);
if (status == napi_ok) {
@@ -172,7 +172,7 @@ napi_value CameraSizeNapi::GetCameraSizeHeight(napi_env env, napi_callback_info
}
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status == napi_ok && obj != nullptr) {
if ((status == napi_ok) && (obj != nullptr) && (obj->cameraPicSize_)) {
cameraSizeHeight = obj->cameraPicSize_->height;
status = napi_create_uint32(env, cameraSizeHeight, &jsResult);
if (status == napi_ok) {
@@ -45,7 +45,7 @@ static napi_module g_module = {
.nm_filename = nullptr,
.nm_register_func = Export,
.nm_modname = "multimedia.camera",
.nm_priv = ((void*)0),
.nm_priv = (reinterpret_cast<void*>(0)),
.reserved = {0}
};
@@ -160,14 +160,14 @@ napi_value PhotoOutputNapi::Init(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("on", On)
};
status = napi_define_class(env, CAMERA_PHOTO_OUTPUT_NAPI_CLASS_NAME.c_str(), NAPI_AUTO_LENGTH,
status = napi_define_class(env, CAMERA_PHOTO_OUTPUT_NAPI_CLASS_NAME, NAPI_AUTO_LENGTH,
PhotoOutputNapiConstructor, nullptr,
sizeof(photo_output_props) / sizeof(photo_output_props[PARAM0]),
photo_output_props, &ctorObj);
if (status == napi_ok) {
status = napi_create_reference(env, ctorObj, refCount, &sConstructor_);
if (status == napi_ok) {
status = napi_set_named_property(env, exports, CAMERA_PHOTO_OUTPUT_NAPI_CLASS_NAME.c_str(), ctorObj);
status = napi_set_named_property(env, exports, CAMERA_PHOTO_OUTPUT_NAPI_CLASS_NAME, ctorObj);
if (status == napi_ok) {
return exports;
}
@@ -506,8 +506,10 @@ napi_value PhotoOutputNapi::Release(napi_env env, napi_callback_info info)
status = napi_create_async_work(
env, nullptr, resource, [](napi_env env, void* data) {
auto context = static_cast<PhotoOutputAsyncContext*>(data);
((sptr<PhotoOutput> &)(context->objectInfo->photoOutput_))->Release();
context->status = 0;
if (context->objectInfo != nullptr) {
((sptr<PhotoOutput> &)(context->objectInfo->photoOutput_))->Release();
context->status = 0;
}
},
CommonCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -126,14 +126,14 @@ napi_value PreviewOutputNapi::Init(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("on", JSonFunc)
};
status = napi_define_class(env, CAMERA_PREVIEW_OUTPUT_NAPI_CLASS_NAME.c_str(), NAPI_AUTO_LENGTH,
status = napi_define_class(env, CAMERA_PREVIEW_OUTPUT_NAPI_CLASS_NAME, NAPI_AUTO_LENGTH,
PreviewOutputNapiConstructor, nullptr,
sizeof(preview_output_props) / sizeof(preview_output_props[PARAM0]),
preview_output_props, &ctorObj);
if (status == napi_ok) {
status = napi_create_reference(env, ctorObj, refCount, &sConstructor_);
if (status == napi_ok) {
status = napi_set_named_property(env, exports, CAMERA_PREVIEW_OUTPUT_NAPI_CLASS_NAME.c_str(), ctorObj);
status = napi_set_named_property(env, exports, CAMERA_PREVIEW_OUTPUT_NAPI_CLASS_NAME, ctorObj);
if (status == napi_ok) {
return exports;
}
@@ -302,8 +302,10 @@ napi_value PreviewOutputNapi::Release(napi_env env, napi_callback_info info)
status = napi_create_async_work(
env, nullptr, resource, [](napi_env env, void* data) {
auto context = static_cast<PreviewOutputAsyncContext*>(data);
((sptr<PreviewOutput> &)(context->objectInfo->previewOutput_))->Release();
context->status = true;
if (context->objectInfo != nullptr) {
((sptr<PreviewOutput> &)(context->objectInfo->previewOutput_))->Release();
context->status = true;
}
},
CommonCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -105,6 +105,9 @@ void SurfaceListener::OnBufferAvailable()
int64_t timestamp = 0;
OHOS::Rect damage;
OHOS::sptr<OHOS::SurfaceBuffer> buffer = nullptr;
if (captureSurface_ == nullptr) {
return;
}
captureSurface_->AcquireBuffer(buffer, flushFence, timestamp, damage);
if (buffer != nullptr) {
const char *addr = static_cast<char *>(buffer->GetVirAddr());
@@ -182,14 +185,14 @@ napi_value VideoOutputNapi::Init(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("on", On)
};
status = napi_define_class(env, CAMERA_VIDEO_OUTPUT_NAPI_CLASS_NAME.c_str(), NAPI_AUTO_LENGTH,
status = napi_define_class(env, CAMERA_VIDEO_OUTPUT_NAPI_CLASS_NAME, NAPI_AUTO_LENGTH,
VideoOutputNapiConstructor, nullptr,
sizeof(video_output_props) / sizeof(video_output_props[PARAM0]),
video_output_props, &ctorObj);
if (status == napi_ok) {
status = napi_create_reference(env, ctorObj, refCount, &sConstructor_);
if (status == napi_ok) {
status = napi_set_named_property(env, exports, CAMERA_VIDEO_OUTPUT_NAPI_CLASS_NAME.c_str(), ctorObj);
status = napi_set_named_property(env, exports, CAMERA_VIDEO_OUTPUT_NAPI_CLASS_NAME, ctorObj);
if (status == napi_ok) {
return exports;
}
@@ -87,14 +87,14 @@ napi_value CameraSessionNapi::Init(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("on", On)
};
status = napi_define_class(env, CAMERA_SESSION_NAPI_CLASS_NAME.c_str(), NAPI_AUTO_LENGTH,
status = napi_define_class(env, CAMERA_SESSION_NAPI_CLASS_NAME, NAPI_AUTO_LENGTH,
CameraSessionNapiConstructor, nullptr,
sizeof(camera_session_props) / sizeof(camera_session_props[PARAM0]),
camera_session_props, &ctorObj);
if (status == napi_ok) {
status = napi_create_reference(env, ctorObj, refCount, &sConstructor_);
if (status == napi_ok) {
status = napi_set_named_property(env, exports, CAMERA_SESSION_NAPI_CLASS_NAME.c_str(), ctorObj);
status = napi_set_named_property(env, exports, CAMERA_SESSION_NAPI_CLASS_NAME, ctorObj);
if (status == napi_ok) {
return exports;
}
@@ -120,6 +120,7 @@ napi_value CameraSessionNapi::CameraSessionNapiConstructor(napi_env env, napi_ca
obj->env_ = env;
if (sCameraSession_ == nullptr) {
MEDIA_ERR_LOG("sCameraSession_ is null");
return result;
}
obj->cameraSession_ = sCameraSession_;
status = napi_wrap(env, thisVar, reinterpret_cast<void*>(obj.get()),
@@ -215,8 +216,10 @@ napi_value CameraSessionNapi::BeginConfig(napi_env env, napi_callback_info info)
status = napi_create_async_work(
env, nullptr, resource, [](napi_env env, void* data) {
auto context = static_cast<CameraSessionAsyncContext*>(data);
context->status = context->objectInfo->cameraSession_->BeginConfig();
MEDIA_INFO_LOG("BeginConfig status : %{public}d", context->status);
if (context->objectInfo != nullptr) {
context->status = context->objectInfo->cameraSession_->BeginConfig();
MEDIA_INFO_LOG("BeginConfig status : %{public}d", context->status);
}
},
CommonCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -258,8 +261,10 @@ napi_value CameraSessionNapi::CommitConfig(napi_env env, napi_callback_info info
status = napi_create_async_work(
env, nullptr, resource, [](napi_env env, void* data) {
auto context = static_cast<CameraSessionAsyncContext*>(data);
context->status = context->objectInfo->cameraSession_->CommitConfig();
MEDIA_INFO_LOG("CommitConfig status : %{public}d", context->status);
if (context->objectInfo != nullptr) {
context->status = context->objectInfo->cameraSession_->CommitConfig();
MEDIA_INFO_LOG("CommitConfig status : %{public}d", context->status);
}
},
CommonCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -332,8 +337,10 @@ napi_value CameraSessionNapi::AddInput(napi_env env, napi_callback_info info)
env, nullptr, resource,
[](napi_env env, void* data) {
auto context = static_cast<CameraSessionAsyncContext*>(data);
context->status = context->objectInfo->cameraSession_->AddInput(context->cameraInput);
MEDIA_INFO_LOG("AddInput status : %{public}d", context->status);
if (context->objectInfo != nullptr) {
context->status = context->objectInfo->cameraSession_->AddInput(context->cameraInput);
MEDIA_INFO_LOG("AddInput status : %{public}d", context->status);
}
},
CommonCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -371,9 +378,11 @@ napi_value CameraSessionNapi::RemoveInput(napi_env env, napi_callback_info info)
env, nullptr, resource,
[](napi_env env, void* data) {
auto context = static_cast<CameraSessionAsyncContext*>(data);
int status = context->objectInfo->cameraSession_->RemoveInput(context->cameraInput);
context->status = (status == 0) ? true : false;
MEDIA_INFO_LOG("RemoveInput status : %{public}d", status);
if (context->objectInfo != nullptr) {
int status_ = context->objectInfo->cameraSession_->RemoveInput(context->cameraInput);
context->status = (status_ == 0) ? true : false;
MEDIA_INFO_LOG("RemoveInput status : %{public}d", status_);
}
},
CommonCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -458,8 +467,10 @@ napi_value CameraSessionNapi::AddOutput(napi_env env, napi_callback_info info)
env, nullptr, resource,
[](napi_env env, void* data) {
auto context = static_cast<CameraSessionAsyncContext*>(data);
context->status = context->objectInfo->cameraSession_->AddOutput(context->cameraOutput);
MEDIA_INFO_LOG("AddOutput status : %{public}d", context->status);
if (context->objectInfo != nullptr) {
context->status = context->objectInfo->cameraSession_->AddOutput(context->cameraOutput);
MEDIA_INFO_LOG("AddOutput status : %{public}d", context->status);
}
},
CommonCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -498,9 +509,11 @@ napi_value CameraSessionNapi::RemoveOutput(napi_env env, napi_callback_info info
env, nullptr, resource,
[](napi_env env, void* data) {
auto context = static_cast<CameraSessionAsyncContext*>(data);
int status = context->objectInfo->cameraSession_->RemoveOutput(context->cameraOutput);
context->status = (status == 0) ? true : false;
MEDIA_INFO_LOG("RemoveOutput status : %{public}d", status);
if (context->objectInfo != nullptr) {
int status_ = context->objectInfo->cameraSession_->RemoveOutput(context->cameraOutput);
context->status = (status_ == 0) ? true : false;
MEDIA_INFO_LOG("RemoveOutput status : %{public}d", status_);
}
},
CommonCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -542,9 +555,11 @@ napi_value CameraSessionNapi::Start(napi_env env, napi_callback_info info)
status = napi_create_async_work(
env, nullptr, resource, [](napi_env env, void* data) {
auto context = static_cast<CameraSessionAsyncContext*>(data);
int status = context->objectInfo->cameraSession_->Start();
context->status = (status == 0) ? true : false;
MEDIA_INFO_LOG("Start status : %{public}d", status);
if (context->objectInfo != nullptr) {
int status_ = context->objectInfo->cameraSession_->Start();
context->status = (status_ == 0) ? true : false;
MEDIA_INFO_LOG("Start status : %{public}d", status_);
}
},
CommonCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -586,8 +601,10 @@ napi_value CameraSessionNapi::Stop(napi_env env, napi_callback_info info)
status = napi_create_async_work(
env, nullptr, resource, [](napi_env env, void* data) {
auto context = static_cast<CameraSessionAsyncContext*>(data);
context->status = context->objectInfo->cameraSession_->Stop();
MEDIA_INFO_LOG("Stop status : %{public}d", context->status);
if (context->objectInfo != nullptr) {
context->status = context->objectInfo->cameraSession_->Stop();
MEDIA_INFO_LOG("Stop status : %{public}d", context->status);
}
},
CommonCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
@@ -628,8 +645,10 @@ napi_value CameraSessionNapi::Release(napi_env env, napi_callback_info info)
status = napi_create_async_work(
env, nullptr, resource, [](napi_env env, void* data) {
auto context = static_cast<CameraSessionAsyncContext*>(data);
context->objectInfo->cameraSession_->Release();
context->status = true;
if (context->objectInfo != nullptr) {
context->objectInfo->cameraSession_->Release();
context->status = true;
}
},
CommonCompleteCallback, static_cast<void*>(asyncContext.get()), &asyncContext->work);
if (status != napi_ok) {
+2 -2
View File
@@ -67,8 +67,8 @@ ohos_shared_library("camera_framework") {
"samgr_standard:samgr_proxy",
]
if (device_name == "baltimore") {
cflags += [ "-DBALTIMORE_CAMERA" ]
if ("${product_name}" == "m40") {
cflags += [ "-DPRODUCT_M40" ]
include_dirs += [ "//drivers/peripheral/adapter/camera/interfaces/include" ]
} else {
if (device_name == "rk3566" || device_name == "rk3568") {
@@ -13,6 +13,7 @@
* limitations under the License.
*/
#include "input/camera_info.h"
#include <securec.h>
#include "camera_metadata_info.h"
#include "media_log.h"
@@ -153,7 +154,7 @@ std::vector<float> CameraInfo::GetZoomRatioRange()
return zoomRatioRange_;
}
#ifndef BALTIMORE_CAMERA
#ifndef PRODUCT_M40
int ret;
uint32_t zoomRangeCount = 2;
camera_metadata_item_t item;
@@ -16,6 +16,7 @@
#include "input/camera_input.h"
#include <cinttypes>
#include <securec.h>
#include <set>
#include "camera_device_ability_items.h"
#include "camera_util.h"
@@ -88,6 +89,10 @@ CameraInput::CameraInput(sptr<ICameraDeviceService> &deviceObj,
sptr<CameraInfo> &cameraObj) : cameraObj_(cameraObj), deviceObj_(deviceObj)
{
CameraDeviceSvcCallback_ = new CameraDeviceServiceCallback(this);
if (!CameraDeviceSvcCallback_) {
MEDIA_ERR_LOG("CameraInput::CameraInput CameraDeviceServiceCallback alloc failed");
return;
}
deviceObj_->SetCallback(CameraDeviceSvcCallback_);
}
@@ -97,7 +102,6 @@ void CameraInput::Release()
if (retCode != CAMERA_OK) {
MEDIA_ERR_LOG("Failed to release Camera Input, retCode: %{public}d", retCode);
}
return;
}
void CameraInput::LockForControl()
@@ -106,7 +110,6 @@ void CameraInput::LockForControl()
int32_t items = 10;
int32_t dataLength = 100;
changedMetadata_ = std::make_shared<CameraMetadata>(items, dataLength);
return;
}
int32_t CameraInput::UpdateSetting(std::shared_ptr<CameraMetadata> changedMetadata)
@@ -262,8 +265,8 @@ std::vector<CameraPicSize> CameraInput::getSupportedSizes(camera_format_t format
return {};
}
int32_t count = 0;
for (uint32_t index = 0; index < item.count; index += unitLen) {
if (item.data.i32[index] == format) {
for (uint32_t index_ = 0; index_ < item.count; index_ += unitLen) {
if (item.data.i32[index_] == format) {
count++;
}
}
@@ -337,7 +340,6 @@ camera_ae_mode_t CameraInput::GetExposureMode()
void CameraInput::SetExposureCallback(std::shared_ptr<ExposureCallback> exposureCallback)
{
exposurecallback_ = exposureCallback;
return;
}
std::vector<camera_af_mode_t> CameraInput::GetSupportedFocusModes()
@@ -416,7 +418,7 @@ void CameraInput::SetFocusMode(camera_af_mode_t focusMode)
MEDIA_DEBUG_LOG("CameraInput::SetFocusMode Focus mode: %{public}d", focusMode);
#ifdef BALTIMORE_CAMERA
#ifdef PRODUCT_M40
ret = StartFocus(focusMode);
if (ret != CAM_META_SUCCESS) {
return;
@@ -561,7 +563,7 @@ void CameraInput::SetZoomRatio(float zoomRatio)
return;
}
#ifdef BALTIMORE_CAMERA
#ifdef PRODUCT_M40
ret = SetCropRegion(zoomRatio);
if (ret != CAM_META_SUCCESS) {
return;
@@ -13,13 +13,15 @@
* limitations under the License.
*/
#include "input/camera_manager.h"
#include <cstring>
#include "camera_util.h"
#include "ipc_skeleton.h"
#include "iservice_registry.h"
#include "media_log.h"
#include "system_ability_definition.h"
#include "ipc_skeleton.h"
#include "input/camera_manager.h"
using namespace std;
namespace OHOS {
@@ -138,6 +140,9 @@ sptr<CaptureSession> CameraManager::CreateCaptureSession()
retCode = serviceProxy_->CreateCaptureSession(captureSession);
if (retCode == CAMERA_OK && captureSession != nullptr) {
result = new CaptureSession(captureSession);
if (!result) {
MEDIA_ERR_LOG("Failed to new CaptureSession");
}
} else {
MEDIA_ERR_LOG("Failed to get capture session object from hcamera service!, %{public}d", retCode);
}
@@ -158,6 +163,9 @@ sptr<PhotoOutput> CameraManager::CreatePhotoOutput(sptr<Surface> &surface)
retCode = serviceProxy_->CreatePhotoOutput(surface->GetProducer(), std::stoi(format), streamCapture);
if (retCode == CAMERA_OK) {
result = new PhotoOutput(streamCapture);
if (!result) {
MEDIA_ERR_LOG("Failed to new PhotoOutput ");
}
} else {
MEDIA_ERR_LOG("Failed to get stream capture object from hcamera service!, %{public}d", retCode);
}
@@ -177,6 +185,9 @@ sptr<PhotoOutput> CameraManager::CreatePhotoOutput(const sptr<OHOS::IBufferProdu
retCode = serviceProxy_->CreatePhotoOutput(producer, format, streamCapture);
if (retCode == CAMERA_OK) {
result = new PhotoOutput(streamCapture);
if (!result) {
MEDIA_ERR_LOG("Failed to new PhotoOutput");
}
} else {
MEDIA_ERR_LOG("Failed to get stream capture object from hcamera service!, %{public}d", retCode);
}
@@ -197,6 +208,9 @@ sptr<PreviewOutput> CameraManager::CreatePreviewOutput(sptr<Surface> surface)
retCode = serviceProxy_->CreatePreviewOutput(surface->GetProducer(), std::stoi(format), streamRepeat);
if (retCode == CAMERA_OK) {
result = new PreviewOutput(streamRepeat);
if (!result) {
MEDIA_ERR_LOG("Failed to new PreviewOutput");
}
} else {
MEDIA_ERR_LOG("PreviewOutput: Failed to get stream repeat object from hcamera service!, %{public}d", retCode);
}
@@ -216,6 +230,9 @@ sptr<PreviewOutput> CameraManager::CreatePreviewOutput(const sptr<OHOS::IBufferP
retCode = serviceProxy_->CreatePreviewOutput(producer, format, streamRepeat);
if (retCode == CAMERA_OK) {
result = new PreviewOutput(streamRepeat);
if (!result) {
MEDIA_ERR_LOG("Failed to new PreviewOutput");
}
} else {
MEDIA_ERR_LOG("PreviewOutput: Failed to get stream repeat object from hcamera service!, %{public}d", retCode);
}
@@ -237,6 +254,9 @@ sptr<PreviewOutput> CameraManager::CreateCustomPreviewOutput(sptr<Surface> surfa
streamRepeat);
if (retCode == CAMERA_OK) {
result = new PreviewOutput(streamRepeat);
if (!result) {
MEDIA_ERR_LOG("Failed to new PreviewOutput");
}
} else {
MEDIA_ERR_LOG("PreviewOutput: Failed to get stream repeat object from hcamera service!, %{public}d", retCode);
}
@@ -257,6 +277,9 @@ sptr<PreviewOutput> CameraManager::CreateCustomPreviewOutput(const sptr<OHOS::IB
retCode = serviceProxy_->CreateCustomPreviewOutput(producer, format, width, height, streamRepeat);
if (retCode == CAMERA_OK) {
result = new PreviewOutput(streamRepeat);
if (!result) {
MEDIA_ERR_LOG("Failed to new PreviewOutput");
}
} else {
MEDIA_ERR_LOG("PreviewOutput: Failed to get stream repeat object from hcamera service!, %{public}d", retCode);
}
@@ -277,6 +300,9 @@ sptr<VideoOutput> CameraManager::CreateVideoOutput(sptr<Surface> &surface)
retCode = serviceProxy_->CreateVideoOutput(surface->GetProducer(), std::stoi(format), streamRepeat);
if (retCode == CAMERA_OK) {
result = new VideoOutput(streamRepeat);
if (!result) {
MEDIA_ERR_LOG("Failed to new VideoOutput");
}
} else {
MEDIA_ERR_LOG("VideoOutpout: Failed to get stream repeat object from hcamera service! %{public}d", retCode);
}
@@ -296,6 +322,9 @@ sptr<VideoOutput> CameraManager::CreateVideoOutput(const sptr<OHOS::IBufferProdu
retCode = serviceProxy_->CreateVideoOutput(producer, format, streamRepeat);
if (retCode == CAMERA_OK) {
result = new VideoOutput(streamRepeat);
if (!result) {
MEDIA_ERR_LOG("Failed to new VideoOutput");
}
} else {
MEDIA_ERR_LOG("VideoOutpout: Failed to get stream repeat object from hcamera service! %{public}d", retCode);
}
@@ -322,9 +351,12 @@ void CameraManager::Init()
MEDIA_ERR_LOG("CameraManager::init serviceProxy_ is null.");
return;
} else {
sptr<CameraManager> helper = this;
cameraSvcCallback_ = new CameraStatusServiceCallback(helper);
SetCameraServiceCallback(cameraSvcCallback_);
cameraSvcCallback_ = new CameraStatusServiceCallback(this);
if (cameraSvcCallback_) {
SetCameraServiceCallback(cameraSvcCallback_);
} else {
MEDIA_ERR_LOG("CameraManager::init Failed to new CameraStatusServiceCallback.");
}
}
pid_t pid = 0;
deathRecipient_ = new(std::nothrow) CameraDeathRecipient(pid);
@@ -400,6 +432,9 @@ sptr<CameraManager> &CameraManager::GetInstance()
if (CameraManager::cameraManager_ == nullptr) {
MEDIA_INFO_LOG("Initializing camera manager for first time!");
CameraManager::cameraManager_ = new CameraManager();
if (CameraManager::cameraManager_ == nullptr) {
MEDIA_ERR_LOG("CameraManager::GetInstance failed to new CameraManager");
}
}
return CameraManager::cameraManager_;
}
@@ -416,13 +451,17 @@ std::vector<sptr<CameraInfo>> CameraManager::GetCameras()
cameraObjList.clear();
}
if (serviceProxy_ == nullptr) {
MEDIA_ERR_LOG("CameraManager::SetCallback serviceProxy_ is null, returning empty list!");
MEDIA_ERR_LOG("CameraManager::GetCameras serviceProxy_ is null, returning empty list!");
return cameraObjList;
}
retCode = serviceProxy_->GetCameras(cameraIds, cameraAbilityList);
if (retCode == CAMERA_OK) {
for (auto& it : cameraIds) {
cameraObj = new CameraInfo(it, cameraAbilityList[index++]);
if (cameraObj == nullptr) {
MEDIA_ERR_LOG("CameraManager::GetCameras new CameraInfo failed for id={public}%s", it.c_str());
continue;
}
cameraObjList.emplace_back(cameraObj);
}
} else {
@@ -440,6 +479,10 @@ sptr<CameraInput> CameraManager::CreateCameraInput(sptr<CameraInfo> &camera)
deviceObj = CreateCameraDevice(camera->GetID());
if (deviceObj != nullptr) {
cameraInput = new CameraInput(deviceObj, camera);
if (cameraInput == nullptr) {
MEDIA_ERR_LOG("failed to new CameraInput Returning null in CreateCameraInput");
return cameraInput;
}
} else {
MEDIA_ERR_LOG("Returning null in CreateCameraInput");
}
@@ -26,3 +26,4 @@ CAPTURE_OUTPUT_TYPE CaptureOutput::GetType()
}
} // CameraStandard
} // OHOS
@@ -14,6 +14,7 @@
*/
#include "output/photo_output.h"
#include <securec.h>
#include "camera_util.h"
#include "hstream_capture_callback_stub.h"
#include "media_log.h"
@@ -70,7 +71,6 @@ void PhotoCaptureSetting::SetQuality(PhotoCaptureSetting::QualityLevel qualityLe
if (!status) {
MEDIA_ERR_LOG("PhotoCaptureSetting::SetQuality Failed to set Quality");
}
return;
}
PhotoCaptureSetting::RotationConfig PhotoCaptureSetting::GetRotation()
@@ -230,6 +230,11 @@ void PhotoOutput::SetCallback(std::shared_ptr<PhotoCallback> callback)
if (appCallback_ != nullptr) {
if (cameraSvcCallback_ == nullptr) {
cameraSvcCallback_ = new HStreamCaptureCallbackImpl(this);
if (!cameraSvcCallback_) {
MEDIA_ERR_LOG("PhotoOutput::SetCallback new HStreamCaptureCallbackImpl Failed to register callback");
appCallback_ = nullptr;
return;
}
}
errorCode = streamCapture_->SetCallback(cameraSvcCallback_);
if (errorCode != CAMERA_OK) {
@@ -238,7 +243,6 @@ void PhotoOutput::SetCallback(std::shared_ptr<PhotoCallback> callback)
appCallback_ = nullptr;
}
}
return;
}
std::shared_ptr<PhotoCallback> PhotoOutput::GetApplicationCallback()
@@ -86,6 +86,11 @@ void PreviewOutput::SetCallback(std::shared_ptr<PreviewCallback> callback)
if (appCallback_ != nullptr) {
if (svcCallback_ == nullptr) {
svcCallback_ = new HStreamRepeatCallbackImpl(this);
if (!svcCallback_) {
MEDIA_ERR_LOG("PreviewOutput::SetCallback: new HStreamRepeatCallbackImpl Failed to register callback");
appCallback_ = nullptr;
return;
}
}
errorCode = streamRepeat_->SetCallback(svcCallback_);
if (errorCode != CAMERA_OK) {
@@ -107,4 +112,5 @@ std::shared_ptr<PreviewCallback> PreviewOutput::GetApplicationCallback()
return appCallback_;
}
} // CameraStandard
} // OHOS
} // OHOS
@@ -77,6 +77,11 @@ void VideoOutput::SetCallback(std::shared_ptr<VideoCallback> callback)
if (appCallback_ != nullptr) {
if (svcCallback_ == nullptr) {
svcCallback_ = new HStreamRepeatCallbackImpl(this);
if (!svcCallback_) {
MEDIA_ERR_LOG("VideoOutput::SetCallback: new HStreamRepeatCallbackImpl Failed to register callback");
appCallback_ = nullptr;
return;
}
}
errorCode = streamRepeat_->SetCallback(svcCallback_);
if (errorCode != CAMERA_OK) {
@@ -85,7 +90,6 @@ void VideoOutput::SetCallback(std::shared_ptr<VideoCallback> callback)
appCallback_ = nullptr;
}
}
return;
}
std::vector<float> VideoOutput::GetSupportedFps()
@@ -53,8 +53,8 @@ ohos_moduletest("camera_framework_moduletest") {
]
cflags = [ "-fPIC" ]
if (device_name == "baltimore") {
cflags += [ "-DBALTIMORE_CAMERA" ]
if ("${product_name}" == "m40") {
cflags += [ "-DPRODUCT_M40" ]
include_dirs += [ "//drivers/peripheral/adapter/camera/interfaces/include" ]
} else {
if (device_name == "rk3566" || device_name == "rk3568") {
File diff suppressed because it is too large Load Diff
@@ -56,8 +56,8 @@ ohos_unittest("camera_framework_unittest") {
]
cflags = [ "-fPIC" ]
if (device_name == "baltimore") {
cflags += [ "-DBALTIMORE_CAMERA" ]
if ("${product_name}" == "m40") {
cflags += [ "-DPRODUCT_M40" ]
include_dirs += [
"//drivers/peripheral/adapter/camera/interfaces/include",
"//drivers/peripheral/adapter/camera/interfaces/include/callback/device",
@@ -168,6 +168,9 @@ public:
sptr<CaptureOutput> CameraFrameworkUnitTest::CreatePhotoOutput(int32_t width, int32_t height)
{
sptr<Surface> surface = Surface::CreateSurfaceAsConsumer();
if (!surface) {
return nullptr;
}
surface->SetDefaultWidthAndHeight(width, height);
surface->SetUserData(CameraManager::surfaceFormat, std::to_string(OHOS_CAMERA_FORMAT_JPEG));
return cameraManager->CreatePhotoOutput(surface);
@@ -176,6 +179,9 @@ sptr<CaptureOutput> CameraFrameworkUnitTest::CreatePhotoOutput(int32_t width, in
sptr<CaptureOutput> CameraFrameworkUnitTest::CreatePreviewOutput(int32_t width, int32_t height)
{
sptr<Surface> surface = Surface::CreateSurfaceAsConsumer();
if (!surface) {
return nullptr;
}
surface->SetDefaultWidthAndHeight(width, height);
surface->SetUserData(CameraManager::surfaceFormat, std::to_string(OHOS_CAMERA_FORMAT_YCRCB_420_SP));
return cameraManager->CreatePreviewOutput(surface);
@@ -184,6 +190,9 @@ sptr<CaptureOutput> CameraFrameworkUnitTest::CreatePreviewOutput(int32_t width,
sptr<CaptureOutput> CameraFrameworkUnitTest::CreateVideoOutput(int32_t width, int32_t height)
{
sptr<Surface> surface = Surface::CreateSurfaceAsConsumer();
if (!surface) {
return nullptr;
}
surface->SetDefaultWidthAndHeight(width, height);
surface->SetUserData(CameraManager::surfaceFormat, std::to_string(OHOS_CAMERA_FORMAT_YCRCB_420_SP));
return cameraManager->CreateVideoOutput(surface);
@@ -644,11 +653,11 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_020, TestSize.Level0
input->UnlockForControl();
if (!zoomRatioRange.empty()) {
EXPECT_TRUE(input->GetZoomRatio() == zoomRatioRange[0]);
EXPECT_EQ(input->GetZoomRatio(), zoomRatioRange[0]);
}
EXPECT_TRUE(input->GetFlashMode() == flash);
EXPECT_TRUE(input->GetFocusMode() == focus);
EXPECT_TRUE(input->GetExposureMode() == exposure);
EXPECT_EQ(input->GetFlashMode(), flash);
EXPECT_EQ(input->GetFocusMode(), focus);
EXPECT_EQ(input->GetExposureMode(), exposure);
}
/*
@@ -746,11 +755,11 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_025, TestSize.Level0
ASSERT_NE(session, nullptr);
int32_t ret = session->BeginConfig();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
sptr<CaptureInput> input = nullptr;
ret = session->AddInput(input);
EXPECT_TRUE(ret != 0);
EXPECT_NE(ret, 0);
}
/*
@@ -767,11 +776,11 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_026, TestSize.Level0
ASSERT_NE(session, nullptr);
int32_t ret = session->BeginConfig();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
sptr<CaptureOutput> preview = nullptr;
ret = session->AddOutput(preview);
EXPECT_TRUE(ret != 0);
EXPECT_NE(ret, 0);
}
/*
@@ -788,16 +797,16 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_027, TestSize.Level0
ASSERT_NE(session, nullptr);
int32_t ret = session->BeginConfig();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
sptr<CaptureOutput> preview = CreatePreviewOutput();
ASSERT_NE(preview, nullptr);
ret = session->AddOutput(preview);
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
ret = session->CommitConfig();
EXPECT_TRUE(ret != 0);
EXPECT_NE(ret, 0);
}
/*
@@ -822,13 +831,13 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_028, TestSize.Level0
ASSERT_NE(session, nullptr);
int32_t ret = session->BeginConfig();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
ret = session->AddInput(input);
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
ret = session->CommitConfig();
EXPECT_TRUE(ret != 0);
EXPECT_NE(ret, 0);
}
/*
@@ -859,25 +868,25 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_029, TestSize.Level0
ASSERT_NE(session, nullptr);
int32_t ret = session->AddInput(input);
EXPECT_TRUE(ret != 0);
EXPECT_NE(ret, 0);
ret = session->AddOutput(preview);
EXPECT_TRUE(ret != 0);
EXPECT_NE(ret, 0);
ret = session->AddOutput(photo);
EXPECT_TRUE(ret != 0);
EXPECT_NE(ret, 0);
ret = session->CommitConfig();
EXPECT_TRUE(ret != 0);
EXPECT_NE(ret, 0);
ret = session->Start();
EXPECT_TRUE(ret != 0);
EXPECT_NE(ret, 0);
ret = ((sptr<PhotoOutput> &)photo)->Capture();
EXPECT_TRUE(ret != 0);
EXPECT_NE(ret, 0);
ret = session->Stop();
EXPECT_TRUE(ret != 0);
EXPECT_NE(ret, 0);
}
/*
@@ -905,34 +914,34 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_030, TestSize.Level0
ASSERT_NE(session, nullptr);
int32_t ret = session->BeginConfig();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
ret = session->AddInput(input);
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
ret = session->AddOutput(photo);
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
EXPECT_CALL(*mockCameraHostManager, OpenCameraDevice(_, _, _));
EXPECT_CALL(*mockCameraDevice, SetResultMode(Camera::ON_CHANGED));
EXPECT_CALL(*mockCameraDevice, GetStreamOperator(_, _));
EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
#ifndef BALTIMORE_CAMERA
#ifndef PRODUCT_M40
EXPECT_CALL(*mockStreamOperator, IsStreamsSupported(_, _,
A<const std::vector<std::shared_ptr<Camera::StreamInfo>> &>(), _));
#endif
EXPECT_CALL(*mockStreamOperator, CreateStreams(_));
EXPECT_CALL(*mockStreamOperator, CommitStreams(_, _));
ret = session->CommitConfig();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
EXPECT_CALL(*mockStreamOperator, Capture(PREVIEW_CAPTURE_ID_START, _, true)).Times(0);
ret = session->Start();
EXPECT_TRUE(ret != 0);
EXPECT_NE(ret, 0);
EXPECT_CALL(*mockStreamOperator, CancelCapture(PREVIEW_CAPTURE_ID_START)).Times(0);
ret = session->Stop();
EXPECT_TRUE(ret != 0);
EXPECT_NE(ret, 0);
EXPECT_CALL(*mockStreamOperator, ReleaseStreams(_));
EXPECT_CALL(*mockCameraDevice, Close());
@@ -967,41 +976,41 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_031, TestSize.Level0
ASSERT_NE(session, nullptr);
int32_t ret = session->BeginConfig();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
ret = session->AddInput(input);
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
ret = session->AddOutput(preview);
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
ret = session->AddOutput(photo);
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
EXPECT_CALL(*mockCameraHostManager, OpenCameraDevice(_, _, _));
EXPECT_CALL(*mockCameraDevice, SetResultMode(Camera::ON_CHANGED));
EXPECT_CALL(*mockCameraDevice, GetStreamOperator(_, _));
EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
#ifndef BALTIMORE_CAMERA
#ifndef PRODUCT_M40
EXPECT_CALL(*mockStreamOperator, IsStreamsSupported(_, _,
A<const std::vector<std::shared_ptr<Camera::StreamInfo>> &>(), _));
#endif
EXPECT_CALL(*mockStreamOperator, CreateStreams(_));
EXPECT_CALL(*mockStreamOperator, CommitStreams(_, _));
ret = session->CommitConfig();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
EXPECT_CALL(*mockStreamOperator, Capture(PREVIEW_CAPTURE_ID_START, _, true));
ret = session->Start();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
EXPECT_CALL(*mockStreamOperator, Capture(PHOTO_CAPTURE_ID_START, _, false));
ret = ((sptr<PhotoOutput> &)photo)->Capture();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
EXPECT_CALL(*mockStreamOperator, CancelCapture(PREVIEW_CAPTURE_ID_START));
ret = session->Stop();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
EXPECT_CALL(*mockStreamOperator, ReleaseStreams(_));
EXPECT_CALL(*mockCameraDevice, Close());
@@ -1045,16 +1054,16 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_032, TestSize.Level0
ASSERT_NE(session, nullptr);
int32_t ret = session->BeginConfig();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
ret = session->AddInput(input);
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
ret = session->AddOutput(preview);
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
ret = session->AddOutput(photo);
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
EXPECT_CALL(*mockCameraHostManager, OpenCameraDevice(_, _, _));
if (!zoomRatioRange.empty()) {
@@ -1063,14 +1072,14 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_032, TestSize.Level0
EXPECT_CALL(*mockCameraDevice, SetResultMode(Camera::ON_CHANGED));
EXPECT_CALL(*mockCameraDevice, GetStreamOperator(_, _));
EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
#ifndef BALTIMORE_CAMERA
#ifndef PRODUCT_M40
EXPECT_CALL(*mockStreamOperator, IsStreamsSupported(_, _,
A<const std::vector<std::shared_ptr<Camera::StreamInfo>> &>(), _));
#endif
EXPECT_CALL(*mockStreamOperator, CreateStreams(_));
EXPECT_CALL(*mockStreamOperator, CommitStreams(_, _));
ret = session->CommitConfig();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
EXPECT_CALL(*mockStreamOperator, ReleaseStreams(_));
EXPECT_CALL(*mockCameraDevice, Close());
@@ -1105,45 +1114,45 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_033, TestSize.Level0
ASSERT_NE(session, nullptr);
int32_t ret = session->BeginConfig();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
ret = session->AddInput(input);
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
ret = session->AddOutput(preview);
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
ret = session->AddOutput(video);
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
EXPECT_CALL(*mockCameraHostManager, OpenCameraDevice(_, _, _));
EXPECT_CALL(*mockCameraDevice, SetResultMode(Camera::ON_CHANGED));
EXPECT_CALL(*mockCameraDevice, GetStreamOperator(_, _));
EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
#ifndef BALTIMORE_CAMERA
#ifndef PRODUCT_M40
EXPECT_CALL(*mockStreamOperator, IsStreamsSupported(_, _,
A<const std::vector<std::shared_ptr<Camera::StreamInfo>> &>(), _));
#endif
EXPECT_CALL(*mockStreamOperator, CreateStreams(_));
EXPECT_CALL(*mockStreamOperator, CommitStreams(_, _));
ret = session->CommitConfig();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
EXPECT_CALL(*mockStreamOperator, Capture(PREVIEW_CAPTURE_ID_START, _, true));
ret = session->Start();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
EXPECT_CALL(*mockStreamOperator, Capture(VIDEO_CAPTURE_ID_START, _, true));
ret = ((sptr<VideoOutput> &)video)->Start();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
EXPECT_CALL(*mockStreamOperator, CancelCapture(VIDEO_CAPTURE_ID_START));
ret = ((sptr<VideoOutput> &)video)->Stop();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
EXPECT_CALL(*mockStreamOperator, CancelCapture(PREVIEW_CAPTURE_ID_START));
ret = session->Stop();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
EXPECT_CALL(*mockStreamOperator, ReleaseStreams(_));
EXPECT_CALL(*mockCameraDevice, Close());
@@ -1164,11 +1173,11 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_034, TestSize.Level0
ASSERT_NE(session, nullptr);
int32_t ret = session->BeginConfig();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
sptr<CaptureOutput> output = nullptr;
ret = session->RemoveOutput(output);
EXPECT_TRUE(ret != 0);
EXPECT_NE(ret, 0);
}
/*
@@ -1188,13 +1197,13 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_035, TestSize.Level0
ASSERT_NE(video, nullptr);
int32_t ret = session->BeginConfig();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
ret = session->AddOutput(video);
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
ret = session->RemoveOutput(video);
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
}
/*
@@ -1211,11 +1220,11 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_036, TestSize.Level0
ASSERT_NE(session, nullptr);
int32_t ret = session->BeginConfig();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
sptr<CaptureInput> input = nullptr;
ret = session->RemoveInput(input);
EXPECT_TRUE(ret != 0);
EXPECT_NE(ret, 0);
}
/*
@@ -1240,13 +1249,13 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_037, TestSize.Level0
ASSERT_NE(session, nullptr);
int32_t ret = session->BeginConfig();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
ret = session->AddInput(input);
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
ret = session->RemoveInput(input);
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
}
/*
@@ -1274,37 +1283,37 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_038, TestSize.Level0
ASSERT_NE(session, nullptr);
int32_t ret = session->BeginConfig();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
ret = session->AddInput(input);
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
ret = session->AddOutput(photo);
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
EXPECT_CALL(*mockCameraHostManager, OpenCameraDevice(_, _, _));
EXPECT_CALL(*mockCameraDevice, SetResultMode(Camera::ON_CHANGED));
EXPECT_CALL(*mockCameraDevice, GetStreamOperator(_, _));
EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
#ifndef BALTIMORE_CAMERA
#ifndef PRODUCT_M40
EXPECT_CALL(*mockStreamOperator, IsStreamsSupported(_, _,
A<const std::vector<std::shared_ptr<Camera::StreamInfo>> &>(), _));
#endif
EXPECT_CALL(*mockStreamOperator, CreateStreams(_));
EXPECT_CALL(*mockStreamOperator, CommitStreams(_, _));
ret = session->CommitConfig();
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
std::shared_ptr<PhotoCaptureSetting> photoSetting = std::make_shared<PhotoCaptureSetting>();
photoSetting->SetRotation(PhotoCaptureSetting::Rotation_90);
photoSetting->SetQuality(PhotoCaptureSetting::NORMAL_QUALITY);
EXPECT_TRUE(photoSetting->GetRotation() == PhotoCaptureSetting::Rotation_90);
EXPECT_TRUE(photoSetting->GetQuality() == PhotoCaptureSetting::NORMAL_QUALITY);
EXPECT_EQ(photoSetting->GetRotation(), PhotoCaptureSetting::Rotation_90);
EXPECT_EQ(photoSetting->GetQuality(), PhotoCaptureSetting::NORMAL_QUALITY);
EXPECT_CALL(*mockStreamOperator, Capture(PHOTO_CAPTURE_ID_START,
matchCaptureSetting(photoSetting->GetCaptureMetadataSetting()), false));
ret = ((sptr<PhotoOutput> &)photo)->Capture(photoSetting);
EXPECT_TRUE(ret == 0);
EXPECT_EQ(ret, 0);
EXPECT_CALL(*mockStreamOperator, ReleaseStreams(_));
EXPECT_CALL(*mockCameraDevice, Close());
@@ -1312,3 +1321,4 @@ HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_038, TestSize.Level0
}
} // CameraStandard
} // OHOS
@@ -178,4 +178,4 @@ size_t CalculateCameraMetadataItemDataSize(uint32_t type, size_t data_count);
int32_t GetCameraMetadataItemType(uint32_t item, uint32_t *data_type);
} // CameraStandard
} // OHOS
#endif
#endif // CAMERA_METADATA_OPERATOR_H
@@ -14,6 +14,7 @@
*/
#include "camera_metadata_info.h"
#include <securec.h>
#include "metadata_log.h"
namespace OHOS {
@@ -126,9 +127,9 @@ bool CameraMetadata::updateEntry(uint32_t tag, const void *data, size_t dataCoun
"dataCount: %{public}zu", metadata_, tag, name ? name : "<unknown>", dataCount);
ret = UpdateCameraMetadataItemByIndex(metadata_, item.index, data, dataCount, nullptr);
if (ret) {
const char *name = GetCameraMetadataItemName(tag);
(void)name;
METADATA_ERR_LOG("Failed to update tag tagname = %{public}s", (name ? name : "<unknown>"));
const char *name_ = GetCameraMetadataItemName(tag);
(void)name_;
METADATA_ERR_LOG("Failed to update tag tagname = %{public}s", (name_ ? name_ : "<unknown>"));
return false;
}
@@ -35,13 +35,17 @@ uint32_t MaxAlignment(uint32_t dataAlignment, uint32_t metadataAlignment)
uint8_t *GetMetadataData(const common_metadata_header_t *metadataHeader)
{
if (!metadataHeader) {
METADATA_ERR_LOG("GetMetadataData metadataHeader is null");
return nullptr;
}
return (uint8_t *)metadataHeader + metadataHeader->data_start;
}
camera_metadata_item_entry_t *GetMetadataItems(const common_metadata_header_t *metadataHeader)
{
return (camera_metadata_item_entry_t *)
((uint8_t *)metadataHeader + metadataHeader->items_start);
return reinterpret_cast<camera_metadata_item_entry_t *>(
((uint8_t *)(metadataHeader) + metadataHeader->items_start));
}
common_metadata_header_t *FillCameraMetadata(common_metadata_header_t *buffer, size_t memoryRequired,
@@ -62,7 +66,7 @@ common_metadata_header_t *FillCameraMetadata(common_metadata_header_t *buffer, s
metadataHeader->data_count = 0;
metadataHeader->data_capacity = dataCapacity;
size_t dataUnaligned = (uint8_t *)(GetMetadataItems(metadataHeader) +
metadataHeader->item_capacity) - (uint8_t *)metadataHeader;
metadataHeader->item_capacity) - (uint8_t *)metadataHeader;
metadataHeader->data_start = AlignTo(dataUnaligned, DATA_ALIGNMENT);
METADATA_DEBUG_LOG("FillCameraMetadata end");
@@ -95,10 +99,11 @@ common_metadata_header_t *AllocateCameraMetadataBuffer(uint32_t item_capacity, u
void *buffer = calloc(1, memoryRequired);
if (buffer == nullptr) {
METADATA_ERR_LOG("AllocateCameraMetadataBuffer memory allocation failed");
return (common_metadata_header_t *) buffer;
return reinterpret_cast<common_metadata_header_t *>(buffer);
}
common_metadata_header_t *metadataHeader = FillCameraMetadata((common_metadata_header_t *)buffer, memoryRequired,
common_metadata_header_t *metadataHeader = FillCameraMetadata(reinterpret_cast<common_metadata_header_t *>(buffer),
memoryRequired,
item_capacity, data_capacity);
if (metadataHeader == nullptr) {
METADATA_ERR_LOG("AllocateCameraMetadataBuffer metadataHeader is null");
@@ -271,14 +276,18 @@ int AddCameraMetadataItem(common_metadata_header_t *dst, uint32_t item, const vo
size_t dataPayloadBytes =
dataCount * OHOS_CAMERA_METADATA_TYPE_SIZE[dataType];
camera_metadata_item_entry_t *metadataItem = GetMetadataItems(dst) + dst->item_count;
(void)memset_s(metadataItem, sizeof(camera_metadata_item_entry_t), 0, sizeof(camera_metadata_item_entry_t));
ret = memset_s(metadataItem, sizeof(camera_metadata_item_entry_t), 0, sizeof(camera_metadata_item_entry_t));
if (ret != EOK) {
METADATA_ERR_LOG("AddCameraMetadataItem: memset_s failed");
return CAM_META_FAILURE;
}
metadataItem->item = item;
metadataItem->data_type = dataType;
metadataItem->count = dataCount;
if (dataBytes == 0) {
ret = memcpy_s(metadataItem->data.value, dataPayloadBytes, data, dataPayloadBytes);
if (ret != CAM_META_SUCCESS) {
if (ret != EOK) {
METADATA_ERR_LOG("AddCameraMetadataItem memory copy failed");
return CAM_META_FAILURE;
}
@@ -286,7 +295,7 @@ int AddCameraMetadataItem(common_metadata_header_t *dst, uint32_t item, const vo
metadataItem->data.offset = dst->data_count;
ret = memcpy_s(GetMetadataData(dst) + metadataItem->data.offset, dataPayloadBytes, data,
dataPayloadBytes);
if (ret != CAM_META_SUCCESS) {
if (ret != EOK) {
METADATA_ERR_LOG("AddCameraMetadataItem memory copy failed");
return CAM_META_FAILURE;
}
@@ -306,8 +315,11 @@ int GetCameraMetadataItem(const common_metadata_header_t *src, uint32_t index, c
return CAM_META_INVALID_PARAM;
}
(void)memset_s(item, sizeof(camera_metadata_item_t), 0, sizeof(camera_metadata_item_t));
int32_t ret = memset_s(item, sizeof(camera_metadata_item_t), 0, sizeof(camera_metadata_item_t));
if (ret != EOK) {
METADATA_ERR_LOG("GetCameraMetadataItem: memset_s failed");
return CAM_META_FAILURE;
}
if (index >= src->item_count) {
METADATA_ERR_LOG("GetCameraMetadataItem index is greater than item count");
return CAM_META_INVALID_PARAM;
@@ -354,7 +366,7 @@ int FindCameraMetadataItemIndex(const common_metadata_header_t *src, uint32_t it
}
*idx = index;
METADATA_DEBUG_LOG("FindCameraMetadataItemIndex index: %{public}d", index);
METADATA_DEBUG_LOG("FindCameraMetadataItemIndex index: %{public}u", index);
METADATA_DEBUG_LOG("FindCameraMetadataItemIndex end");
return CAM_META_SUCCESS;
}
@@ -394,7 +406,7 @@ int MetadataExpandItemMem(common_metadata_header_t *dst, camera_metadata_item_en
size_t length = dst->data_count - item->data.offset - oldItemSize;
if (length != 0) {
ret = memmove_s(start, length, end, length);
if (ret != CAM_META_SUCCESS) {
if (ret != EOK) {
METADATA_ERR_LOG("MetadataExpandItemMem memory move failed");
return CAM_META_FAILURE;
}
@@ -437,13 +449,16 @@ int UpdateCameraMetadataItemByIndex(common_metadata_header_t *dst, uint32_t inde
}
if (oldItemSize != 0) {
MetadataExpandItemMem(dst, item, oldItemSize);
ret = MetadataExpandItemMem(dst, item, oldItemSize);
if (ret != CAM_META_SUCCESS) {
return ret;
}
}
if (dataSize != 0) {
item->data.offset = dst->data_count;
ret = memcpy_s(GetMetadataData(dst) + item->data.offset, dataPayloadSize, data, dataPayloadSize);
if (ret != CAM_META_SUCCESS) {
if (ret != EOK) {
METADATA_ERR_LOG("UpdateCameraMetadataItemByIndex memory copy failed");
return CAM_META_FAILURE;
}
@@ -451,7 +466,7 @@ int UpdateCameraMetadataItemByIndex(common_metadata_header_t *dst, uint32_t inde
}
} else if (dataSize != 0) {
ret = memcpy_s(GetMetadataData(dst) + item->data.offset, dataPayloadSize, data, dataPayloadSize);
if (ret != CAM_META_SUCCESS) {
if (ret != EOK) {
METADATA_ERR_LOG("UpdateCameraMetadataItemByIndex memory copy failed");
return CAM_META_FAILURE;
}
@@ -459,7 +474,7 @@ int UpdateCameraMetadataItemByIndex(common_metadata_header_t *dst, uint32_t inde
if (dataSize == 0) {
ret = memcpy_s(item->data.value, dataPayloadSize, data, dataPayloadSize);
if (ret != CAM_META_SUCCESS) {
if (ret != EOK) {
METADATA_ERR_LOG("UpdateCameraMetadataItemByIndex memory copy failed");
return CAM_META_FAILURE;
}
@@ -467,7 +482,10 @@ int UpdateCameraMetadataItemByIndex(common_metadata_header_t *dst, uint32_t inde
item->count = dataCount;
if (updatedItem != nullptr) {
GetCameraMetadataItem(dst, index, updatedItem);
ret = GetCameraMetadataItem(dst, index, updatedItem);
if (ret != CAM_META_SUCCESS) {
return ret;
}
}
METADATA_DEBUG_LOG("UpdateCameraMetadataItemByIndex end");
@@ -518,7 +536,7 @@ int DeleteCameraMetadataItemByIndex(common_metadata_header_t *dst, uint32_t inde
size_t length = dst->data_count - itemToDelete->data.offset - dataBytes;
if (length != 0) {
ret = memmove_s(start, length, end, length);
if (ret != CAM_META_SUCCESS) {
if (ret != EOK) {
METADATA_ERR_LOG("DeleteCameraMetadataItemByIndex memory move failed");
return CAM_META_FAILURE;
}
@@ -538,7 +556,7 @@ int DeleteCameraMetadataItemByIndex(common_metadata_header_t *dst, uint32_t inde
uint64_t length = sizeof(camera_metadata_item_entry_t) * (dst->item_count - index - 1);
if (length != 0) {
ret = memmove_s(itemToDelete, length, itemToDelete + 1, length);
if (ret != CAM_META_SUCCESS) {
if (ret != EOK) {
METADATA_ERR_LOG("DeleteCameraMetadataItemByIndex memory move failed");
return CAM_META_FAILURE;
}
@@ -569,11 +587,19 @@ void FreeCameraMetadataBuffer(common_metadata_header_t *dst)
uint32_t GetCameraMetadataItemCount(const common_metadata_header_t *metadataHeader)
{
if (!metadataHeader) {
METADATA_ERR_LOG("GetCameraMetadataItemCount::metadataHeader is null");
return 0;
}
return metadataHeader->item_count;
}
uint32_t GetCameraMetadataItemCapacity(const common_metadata_header_t *metadataHeader)
{
if (!metadataHeader) {
METADATA_ERR_LOG("GetCameraMetadataItemCapacity::metadataHeader is null");
return 0;
}
return metadataHeader->item_capacity;
}
@@ -592,7 +618,7 @@ int32_t CopyCameraMetadataItems(common_metadata_header_t *newMetadata, const com
if (oldMetadata->item_count != 0) {
ret = memcpy_s(GetMetadataItems(newMetadata), sizeof(camera_metadata_item_entry_t[oldMetadata->item_count]),
GetMetadataItems(oldMetadata), sizeof(camera_metadata_item_entry_t[oldMetadata->item_count]));
if (ret != CAM_META_SUCCESS) {
if (ret != EOK) {
METADATA_ERR_LOG("CopyCameraMetadataItems memory copy failed");
return CAM_META_FAILURE;
}
@@ -601,7 +627,7 @@ int32_t CopyCameraMetadataItems(common_metadata_header_t *newMetadata, const com
if (oldMetadata->data_count != 0) {
ret = memcpy_s(GetMetadataData(newMetadata), sizeof(uint8_t[oldMetadata->data_count]),
GetMetadataData(oldMetadata), sizeof(uint8_t[oldMetadata->data_count]));
if (ret != CAM_META_SUCCESS) {
if (ret != EOK) {
METADATA_ERR_LOG("CopyCameraMetadataItems memory copy failed");
return CAM_META_FAILURE;
}
@@ -614,3 +640,4 @@ int32_t CopyCameraMetadataItems(common_metadata_header_t *newMetadata, const com
}
} // CameraStandard
} // OHOS
@@ -95,59 +95,60 @@ void MetadataUtils::DecodeCameraMetadata(MessageParcel &data, std::shared_ptr<Ca
metadata = std::make_shared<CameraMetadata>(itemCapacity, dataCapacity);
common_metadata_header_t *meta = metadata->get();
for (auto &item : items) {
for (auto &item_ : items) {
void *buffer = nullptr;
MetadataUtils::ItemDataToBuffer(item, &buffer);
(void)AddCameraMetadataItem(meta, item.item, buffer, item.count);
MetadataUtils::ItemDataToBuffer(item_, &buffer);
(void)AddCameraMetadataItem(meta, item_.item, buffer, item_.count);
}
}
bool MetadataUtils::WriteMetadata(const camera_metadata_item_t &item, MessageParcel &data)
{
bool bRet = false;
size_t i;
if (item.data_type == META_TYPE_BYTE) {
std::vector<uint8_t> buffers;
for (size_t i = 0; i < item.count; i++) {
buffers.push_back(*(item.data.u8 + i));
std::vector<uint8_t> byteBuffers;
for (i = 0; i < item.count; i++) {
byteBuffers.push_back(*(item.data.u8 + i));
}
bRet = data.WriteUInt8Vector(buffers);
bRet = data.WriteUInt8Vector(byteBuffers);
} else if (item.data_type == META_TYPE_INT32) {
std::vector<int32_t> buffers;
for (size_t i = 0; i < item.count; i++) {
buffers.push_back(*(item.data.i32 + i));
std::vector<int32_t> int32Buffers;
for (i = 0; i < item.count; i++) {
int32Buffers.push_back(*(item.data.i32 + i));
}
bRet = data.WriteInt32Vector(buffers);
bRet = data.WriteInt32Vector(int32Buffers);
} else if (item.data_type == META_TYPE_FLOAT) {
std::vector<float> buffers;
for (size_t i = 0; i < item.count; i++) {
buffers.push_back(*(item.data.f + i));
std::vector<float> floatBuffers;
for (i = 0; i < item.count; i++) {
floatBuffers.push_back(*(item.data.f + i));
}
bRet = data.WriteFloatVector(buffers);
bRet = data.WriteFloatVector(floatBuffers);
} else if (item.data_type == META_TYPE_UINT32) {
std::vector<uint32_t> buffers;
for (size_t i = 0; i < item.count; i++) {
buffers.push_back(*(item.data.ui32 + i));
std::vector<uint32_t> uInt32Buffers;
for (i = 0; i < item.count; i++) {
uInt32Buffers.push_back(*(item.data.ui32 + i));
}
bRet = data.WriteUInt32Vector(buffers);
bRet = data.WriteUInt32Vector(uInt32Buffers);
} else if (item.data_type == META_TYPE_INT64) {
std::vector<int64_t> buffers;
for (size_t i = 0; i < item.count; i++) {
buffers.push_back(*(item.data.i64 + i));
std::vector<int64_t> int64Buffers;
for (i = 0; i < item.count; i++) {
int64Buffers.push_back(*(item.data.i64 + i));
}
bRet = data.WriteInt64Vector(buffers);
bRet = data.WriteInt64Vector(int64Buffers);
} else if (item.data_type == META_TYPE_DOUBLE) {
std::vector<double> buffers;
for (size_t i = 0; i < item.count; i++) {
buffers.push_back(*(item.data.d + i));
std::vector<double> doubleBuffers;
for (i = 0; i < item.count; i++) {
doubleBuffers.push_back(*(item.data.d + i));
}
bRet = data.WriteDoubleVector(buffers);
bRet = data.WriteDoubleVector(doubleBuffers);
} else if (item.data_type == META_TYPE_RATIONAL) {
std::vector<int32_t> buffers;
for (size_t i = 0; i < item.count; i++) {
buffers.push_back((*(item.data.r + i)).numerator);
buffers.push_back((*(item.data.r + i)).denominator);
std::vector<int32_t> rationalBuffers;
for (i = 0; i < item.count; i++) {
rationalBuffers.push_back((*(item.data.r + i)).numerator);
rationalBuffers.push_back((*(item.data.r + i)).denominator);
}
bRet = data.WriteInt32Vector(buffers);
bRet = data.WriteInt32Vector(rationalBuffers);
}
return bRet;
@@ -166,38 +167,43 @@ std::string MetadataUtils::EncodeToString(std::shared_ptr<CameraStandard::Camera
}
common_metadata_header_t *meta = metadata->get();
std::string s(headerLength + (itemLen * meta->item_count) + meta->data_count, '\0');
int32_t encodeDataLen = headerLength + (itemLen * meta->item_count) + meta->data_count;
std::string s(encodeDataLen, '\0');
char *encodeData = &s[0];
ret = memcpy_s(encodeData, headerLength, meta, headerLength);
if (ret != CAM_META_SUCCESS) {
ret = memcpy_s(encodeData, encodeDataLen, meta, headerLength);
if (ret != EOK) {
METADATA_ERR_LOG("MetadataUtils::EncodeToString Failed to copy memory for metadata header");
return {};
}
encodeData += headerLength;
encodeDataLen -= headerLength;
camera_metadata_item_entry_t *item = GetMetadataItems(meta);
for (uint32_t index = 0; index < meta->item_count; index++, item++) {
ret = memcpy_s(encodeData, itemFixedLen, item, itemFixedLen);
if (ret != CAM_META_SUCCESS) {
ret = memcpy_s(encodeData, encodeDataLen, item, itemFixedLen);
if (ret != EOK) {
METADATA_ERR_LOG("MetadataUtils::EncodeToString Failed to copy memory for item fixed fields");
return {};
}
encodeData += itemFixedLen;
encodeDataLen -= itemFixedLen;
dataLen = itemLen - itemFixedLen;
ret = memcpy_s(encodeData, dataLen, &(item->data), dataLen);
if (ret != CAM_META_SUCCESS) {
ret = memcpy_s(encodeData, encodeDataLen, &(item->data), dataLen);
if (ret != EOK) {
METADATA_ERR_LOG("MetadataUtils::EncodeToString Failed to copy memory for item data field");
return {};
}
encodeData += dataLen;
encodeDataLen -= dataLen;
}
if (meta->data_count != 0) {
ret = memcpy_s(encodeData, meta->data_count, GetMetadataData(meta), meta->data_count);
if (ret != CAM_META_SUCCESS) {
ret = memcpy_s(encodeData, encodeDataLen, GetMetadataData(meta), meta->data_count);
if (ret != EOK) {
METADATA_ERR_LOG("MetadataUtils::EncodeToString Failed to copy memory for data");
return {};
}
encodeData += meta->data_count;
encodeDataLen -= meta->data_count;
}
METADATA_DEBUG_LOG("MetadataUtils::EncodeToString Calculated length: %{public}d, encoded length: %{public}d",
s.capacity(), (encodeData - &s[0]));
@@ -221,7 +227,7 @@ std::shared_ptr<CameraStandard::CameraMetadata> MetadataUtils::DecodeFromString(
char *decodeData = &setting[0];
common_metadata_header_t header;
ret = memcpy_s(&header, headerLength, decodeData, headerLength);
if (ret != CAM_META_SUCCESS) {
if (ret != EOK) {
METADATA_ERR_LOG("MetadataUtils::DecodeFromString Failed to copy memory for metadata header");
return {};
}
@@ -230,8 +236,12 @@ std::shared_ptr<CameraStandard::CameraMetadata> MetadataUtils::DecodeFromString(
std::shared_ptr<CameraStandard::CameraMetadata> metadata
= std::make_shared<CameraMetadata>(header.item_capacity, header.data_capacity);
common_metadata_header_t *meta = metadata->get();
if (!meta) {
METADATA_ERR_LOG("MetadataUtils::DecodeFromString Failed to get metadata header");
return {};
}
ret = memcpy_s(meta, headerLength, &header, headerLength);
if (ret != CAM_META_SUCCESS) {
if (ret != EOK) {
METADATA_ERR_LOG("MetadataUtils::DecodeFromString Failed to copy memory for metadata header");
return {};
}
@@ -243,14 +253,14 @@ std::shared_ptr<CameraStandard::CameraMetadata> MetadataUtils::DecodeFromString(
return {};
}
ret = memcpy_s(item, itemFixedLen, decodeData, itemFixedLen);
if (ret != CAM_META_SUCCESS) {
if (ret != EOK) {
METADATA_ERR_LOG("MetadataUtils::DecodeFromString Failed to copy memory for item fixed fields");
return {};
}
decodeData += itemFixedLen;
dataLen = itemLen - itemFixedLen;
ret = memcpy_s(&(item->data), dataLen, decodeData, dataLen);
if (ret != CAM_META_SUCCESS) {
if (ret != EOK) {
METADATA_ERR_LOG("MetadataUtils::DecodeFromString Failed to copy memory for item data field");
return {};
}
@@ -263,7 +273,7 @@ std::shared_ptr<CameraStandard::CameraMetadata> MetadataUtils::DecodeFromString(
return {};
}
ret = memcpy_s(GetMetadataData(meta), meta->data_count, decodeData, meta->data_count);
if (ret != CAM_META_SUCCESS) {
if (ret != EOK) {
METADATA_ERR_LOG("MetadataUtils::DecodeFromString Failed to copy memory for data");
return {};
}
@@ -277,70 +287,71 @@ std::shared_ptr<CameraStandard::CameraMetadata> MetadataUtils::DecodeFromString(
bool MetadataUtils::ReadMetadata(camera_metadata_item_t &item, MessageParcel &data)
{
size_t i, j;
if (item.data_type == META_TYPE_BYTE) {
std::vector<uint8_t> buffers;
data.ReadUInt8Vector(&buffers);
std::vector<uint8_t> byteBuffers;
data.ReadUInt8Vector(&byteBuffers);
item.data.u8 = new(std::nothrow) uint8_t[item.count];
if (item.data.u8 != nullptr) {
for (size_t i = 0; i < item.count; i++) {
item.data.u8[i] = buffers.at(i);
for (i = 0; i < item.count; i++) {
item.data.u8[i] = byteBuffers.at(i);
}
}
} else if (item.data_type == META_TYPE_INT32) {
std::vector<int32_t> buffers;
data.ReadInt32Vector(&buffers);
std::vector<int32_t> int32Buffers;
data.ReadInt32Vector(&int32Buffers);
item.data.i32 = new(std::nothrow) int32_t[item.count];
if (item.data.i32 != nullptr) {
for (size_t i = 0; i < item.count; i++) {
item.data.i32[i] = buffers.at(i);
for (i = 0; i < item.count; i++) {
item.data.i32[i] = int32Buffers.at(i);
}
}
} else if (item.data_type == META_TYPE_FLOAT) {
std::vector<float> buffers;
data.ReadFloatVector(&buffers);
std::vector<float> floatBuffers;
data.ReadFloatVector(&floatBuffers);
item.data.f = new(std::nothrow) float[item.count];
if (item.data.f != nullptr) {
for (size_t i = 0; i < item.count; i++) {
item.data.f[i] = buffers.at(i);
for (i = 0; i < item.count; i++) {
item.data.f[i] = floatBuffers.at(i);
}
}
} else if (item.data_type == META_TYPE_UINT32) {
std::vector<uint32_t> buffers;
data.ReadUInt32Vector(&buffers);
std::vector<uint32_t> uInt32Buffers;
data.ReadUInt32Vector(&uInt32Buffers);
item.data.ui32 = new(std::nothrow) uint32_t[item.count];
if (item.data.ui32 != nullptr) {
for (size_t i = 0; i < item.count; i++) {
item.data.ui32[i] = buffers.at(i);
for (i = 0; i < item.count; i++) {
item.data.ui32[i] = uInt32Buffers.at(i);
}
}
} else if (item.data_type == META_TYPE_INT64) {
std::vector<int64_t> buffers;
data.ReadInt64Vector(&buffers);
std::vector<int64_t> int64uBffers;
data.ReadInt64Vector(&int64uBffers);
item.data.i64 = new(std::nothrow) int64_t[item.count];
if (item.data.i64 != nullptr) {
for (size_t i = 0; i < item.count; i++) {
item.data.i64[i] = buffers.at(i);
for (i = 0; i < item.count; i++) {
item.data.i64[i] = int64uBffers.at(i);
}
}
} else if (item.data_type == META_TYPE_DOUBLE) {
std::vector<double> buffers;
data.ReadDoubleVector(&buffers);
std::vector<double> doubleBuffers;
data.ReadDoubleVector(&doubleBuffers);
item.data.d = new(std::nothrow) double[item.count];
if (item.data.d != nullptr) {
for (size_t i = 0; i < item.count; i++) {
item.data.d[i] = buffers.at(i);
for (i = 0; i < item.count; i++) {
item.data.d[i] = doubleBuffers.at(i);
}
}
} else if (item.data_type == META_TYPE_RATIONAL) {
std::vector<int32_t> buffers;
data.ReadInt32Vector(&buffers);
std::vector<int32_t> rationalBuffers;
data.ReadInt32Vector(&rationalBuffers);
item.data.r = new(std::nothrow) camera_rational_t[item.count];
if (item.data.r != nullptr) {
for (size_t i = 0, j = 0;
i < item.count && j < static_cast<size_t>(buffers.size());
for (i = 0, j = 0;
i < item.count && j < static_cast<size_t>(rationalBuffers.size());
i++, j += INDEX_COUNTER) {
item.data.r[i].numerator = buffers.at(j);
item.data.r[i].denominator = buffers.at(j + 1);
item.data.r[i].numerator = rationalBuffers.at(j);
item.data.r[i].denominator = rationalBuffers.at(j + 1);
}
}
}
@@ -354,19 +365,19 @@ void MetadataUtils::ItemDataToBuffer(const camera_metadata_item_t &item, void **
return;
}
if (item.data_type == META_TYPE_BYTE) {
*buffer = (void*)item.data.u8;
*buffer = reinterpret_cast<void *>(item.data.u8);
} else if (item.data_type == META_TYPE_INT32) {
*buffer = (void*)item.data.i32;
*buffer = reinterpret_cast<void *>(item.data.i32);
} else if (item.data_type == META_TYPE_FLOAT) {
*buffer = (void*)item.data.f;
*buffer = reinterpret_cast<void *>(item.data.f);
} else if (item.data_type == META_TYPE_UINT32) {
*buffer = (void*)item.data.ui32;
*buffer = reinterpret_cast<void *>(item.data.ui32);
} else if (item.data_type == META_TYPE_INT64) {
*buffer = (void*)item.data.i64;
*buffer = reinterpret_cast<void *>(item.data.i64);
} else if (item.data_type == META_TYPE_DOUBLE) {
*buffer = (void*)item.data.d;
*buffer = reinterpret_cast<void *>(item.data.d);
} else if (item.data_type == META_TYPE_RATIONAL) {
*buffer = (void*)item.data.r;
*buffer = reinterpret_cast<void *>(item.data.r);
}
}
} // CameraStandard
@@ -14,6 +14,7 @@
*/
#include "camera_metadata_unittest.h"
#include <securec.h>
#include "metadata_utils.h"
using namespace testing::ext;
@@ -64,7 +64,7 @@ public:
class CameraInput : public CaptureInput {
public:
CameraInput(sptr<ICameraDeviceService> &deviceObj, sptr<CameraInfo> &camera);
~CameraInput() {};
~CameraInput() {}
void LockForControl();
int32_t UnlockForControl();
std::vector<camera_format_t> GetSupportedPhotoFormats();
@@ -113,3 +113,4 @@ private:
} // namespace CameraStandard
} // namespace OHOS
#endif // OHOS_CAMERA_CAMERA_INPUT_H
@@ -79,7 +79,7 @@ public:
static const std::string surfaceFormat;
protected:
CameraManager(sptr<ICameraService> serviceProxy) : serviceProxy_(serviceProxy) {}
explicit CameraManager(sptr<ICameraService> serviceProxy) : serviceProxy_(serviceProxy) {}
private:
CameraManager();
@@ -27,7 +27,7 @@ enum CAPTURE_OUTPUT_TYPE {
};
class CaptureOutput : public RefBase {
public:
CaptureOutput(CAPTURE_OUTPUT_TYPE type);
explicit CaptureOutput(CAPTURE_OUTPUT_TYPE type);
virtual ~CaptureOutput() {}
virtual void Release() = 0;
CAPTURE_OUTPUT_TYPE GetType();
@@ -62,7 +62,7 @@ private:
class PhotoOutput : public CaptureOutput {
public:
PhotoOutput(sptr<IStreamCapture> &streamCapture);
explicit PhotoOutput(sptr<IStreamCapture> &streamCapture);
sptr<IStreamCapture> GetStreamCapture();
void SetCallback(std::shared_ptr<PhotoCallback> callback);
int32_t Capture(std::shared_ptr<PhotoCaptureSetting> photoCaptureSettings);
@@ -33,7 +33,7 @@ public:
class PreviewOutput : public CaptureOutput {
public:
PreviewOutput(sptr<IStreamRepeat> &streamRepeat);
explicit PreviewOutput(sptr<IStreamRepeat> &streamRepeat);
void SetCallback(std::shared_ptr<PreviewCallback> callback);
void Release() override;
sptr<IStreamRepeat> GetStreamRepeat();
@@ -46,4 +46,5 @@ private:
};
} // namespace CameraStandard
} // namespace OHOS
#endif // OHOS_CAMERA_PREVIEW_OUTPUT_H
#endif // OHOS_CAMERA_PREVIEW_OUTPUT_H
@@ -35,7 +35,7 @@ public:
class VideoOutput : public CaptureOutput {
public:
VideoOutput(sptr<IStreamRepeat> &streamRepeat);
explicit VideoOutput(sptr<IStreamRepeat> &streamRepeat);
void Release() override;
sptr<IStreamRepeat> GetStreamRepeat();
void SetCallback(std::shared_ptr<VideoCallback> callback);
@@ -34,8 +34,8 @@ public:
class CaptureSession : public RefBase {
public:
CaptureSession(sptr<ICaptureSession> &captureSession);
~CaptureSession() {};
explicit CaptureSession(sptr<ICaptureSession> &captureSession);
~CaptureSession() {}
int32_t BeginConfig();
int32_t CommitConfig();
int32_t AddInput(sptr<CaptureInput> &input);
+1 -1
View File
@@ -32,7 +32,7 @@ config("camera_config") {
"//base/security/access_token/interfaces/innerkits/token_setproc/include",
]
if (device_name == "baltimore") {
if ("${product_name}" == "m40") {
include_dirs += [
"//drivers/peripheral/adapter/camera/interfaces/include",
"//drivers/peripheral/adapter/camera/interfaces/include/server",
@@ -171,8 +171,8 @@ int main(int argc, char **argv)
if (!isResolutionConfigured) {
std::vector<camera_format_t> previewFormats = cameraInput->GetSupportedPreviewFormats();
MEDIA_DEBUG_LOG("Supported preview formats:");
for (auto &format : previewFormats) {
MEDIA_DEBUG_LOG("format : %{public}d", format);
for (auto &formatPreview : previewFormats) {
MEDIA_DEBUG_LOG("format : %{public}d", formatPreview);
}
if (std::find(previewFormats.begin(), previewFormats.end(), OHOS_CAMERA_FORMAT_YCRCB_420_SP)
!= previewFormats.end()) {
@@ -184,8 +184,8 @@ int main(int argc, char **argv)
}
std::vector<camera_format_t> photoFormats = cameraInput->GetSupportedPhotoFormats();
MEDIA_DEBUG_LOG("Supported photo formats:");
for (auto &format : photoFormats) {
MEDIA_DEBUG_LOG("format : %{public}d", format);
for (auto &formatPhoto : photoFormats) {
MEDIA_DEBUG_LOG("format : %{public}d", formatPhoto);
}
if (!photoFormats.empty()) {
photoFormat = photoFormats[0];
@@ -226,6 +226,10 @@ int main(int argc, char **argv)
}
sptr<Surface> photoSurface = Surface::CreateSurfaceAsConsumer();
if (photoSurface == nullptr) {
MEDIA_DEBUG_LOG("Failed to create photoSurface");
return 0;
}
photoSurface->SetDefaultWidthAndHeight(photoWidth, photoHeight);
photoSurface->SetUserData(CameraManager::surfaceFormat, std::to_string(photoFormat));
sptr<SurfaceListener> captureListener = new SurfaceListener("Photo", SurfaceType::PHOTO, photoFd, photoSurface);
@@ -245,12 +249,16 @@ int main(int argc, char **argv)
}
sptr<Surface> previewSurface = Surface::CreateSurfaceAsConsumer();
if (previewSurface == nullptr) {
MEDIA_DEBUG_LOG("Failed to create previewSurface");
return 0;
}
previewSurface->SetDefaultWidthAndHeight(previewWidth, previewHeight);
previewSurface->SetUserData(CameraManager::surfaceFormat, std::to_string(previewFormat));
sptr<SurfaceListener> listener = new SurfaceListener("Preview", SurfaceType::PREVIEW, previewFd, previewSurface);
previewSurface->RegisterConsumerListener((sptr<IBufferConsumerListener> &)listener);
sptr<CaptureOutput> previewOutput = camManagerObj->CreateCustomPreviewOutput(previewSurface, previewWidth,
previewHeight);
sptr<CaptureOutput> previewOutput = camManagerObj->CreateCustomPreviewOutput(previewSurface,
previewWidth, previewHeight);
if (previewOutput == nullptr) {
MEDIA_DEBUG_LOG("Failed to create previewOutput");
return 0;
@@ -254,6 +254,11 @@ int32_t CameraCaptureVideo::TakePhoto()
{
int32_t result = -1;
if (!photoOutput_) {
MEDIA_ERR_LOG("photoOutput_ is null");
return result;
}
result = ((sptr<PhotoOutput> &)photoOutput_)->Capture();
if (result != CAMERA_OK) {
MEDIA_ERR_LOG("Failed to capture, result: %{public}d", result);
@@ -267,6 +272,11 @@ int32_t CameraCaptureVideo::RecordVideo()
{
int32_t result = -1;
if (!videoOutput_) {
MEDIA_ERR_LOG("videoOutput_ is null");
return result;
}
result = ((sptr<VideoOutput> &)videoOutput_)->Start();
if (result != CAMERA_OK) {
MEDIA_ERR_LOG("Failed to start recording, result: %{public}d", result);
@@ -357,8 +367,8 @@ int32_t CameraCaptureVideo::InitCameraFormatAndResolution(sptr<CameraInput> &cam
{
std::vector<camera_format_t> previewFormats = cameraInput->GetSupportedPreviewFormats();
MEDIA_DEBUG_LOG("Supported preview formats:");
for (auto &format : previewFormats) {
MEDIA_DEBUG_LOG("format : %{public}d", format);
for (auto &formatPreview : previewFormats) {
MEDIA_DEBUG_LOG("format : %{public}d", formatPreview);
}
if (std::find(previewFormats.begin(), previewFormats.end(), OHOS_CAMERA_FORMAT_YCRCB_420_SP)
!= previewFormats.end()) {
@@ -370,16 +380,16 @@ int32_t CameraCaptureVideo::InitCameraFormatAndResolution(sptr<CameraInput> &cam
}
std::vector<camera_format_t> photoFormats = cameraInput->GetSupportedPhotoFormats();
MEDIA_DEBUG_LOG("Supported photo formats:");
for (auto &format : photoFormats) {
MEDIA_DEBUG_LOG("format : %{public}d", format);
for (auto &formatPhoto : photoFormats) {
MEDIA_DEBUG_LOG("format : %{public}d", formatPhoto);
}
if (!photoFormats.empty()) {
photoFormat_ = photoFormats[0];
}
std::vector<camera_format_t> videoFormats = cameraInput->GetSupportedVideoFormats();
MEDIA_DEBUG_LOG("Supported video formats:");
for (auto &format : videoFormats) {
MEDIA_DEBUG_LOG("format : %{public}d", format);
for (auto &formatVideo : videoFormats) {
MEDIA_DEBUG_LOG("format : %{public}d", formatVideo);
}
if (std::find(videoFormats.begin(), videoFormats.end(), OHOS_CAMERA_FORMAT_YCRCB_420_SP) != videoFormats.end()) {
videoFormat_ = OHOS_CAMERA_FORMAT_YCRCB_420_SP;
@@ -391,18 +401,18 @@ int32_t CameraCaptureVideo::InitCameraFormatAndResolution(sptr<CameraInput> &cam
std::vector<CameraPicSize> previewSizes
= cameraInput->getSupportedSizes(static_cast<camera_format_t>(previewFormat_));
MEDIA_DEBUG_LOG("Supported sizes for preview:");
for (auto &size : previewSizes) {
MEDIA_DEBUG_LOG("width: %{public}d, height: %{public}d", size.width, size.height);
for (auto &sizePreview : previewSizes) {
MEDIA_DEBUG_LOG("width: %{public}d, height: %{public}d", sizePreview.width, sizePreview.height);
}
std::vector<CameraPicSize> photoSizes = cameraInput->getSupportedSizes(static_cast<camera_format_t>(photoFormat_));
MEDIA_DEBUG_LOG("Supported sizes for photo:");
for (auto &size : photoSizes) {
MEDIA_DEBUG_LOG("width: %{public}d, height: %{public}d", size.width, size.height);
for (auto &sizePhoto : photoSizes) {
MEDIA_DEBUG_LOG("width: %{public}d, height: %{public}d", sizePhoto.width, sizePhoto.height);
}
std::vector<CameraPicSize> videoSizes = cameraInput->getSupportedSizes(static_cast<camera_format_t>(videoFormat_));
MEDIA_DEBUG_LOG("Supported sizes for video:");
for (auto &size : videoSizes) {
MEDIA_DEBUG_LOG("width: %{public}d, height: %{public}d", size.width, size.height);
for (auto &sizeVideo : videoSizes) {
MEDIA_DEBUG_LOG("width: %{public}d, height: %{public}d", sizeVideo.width, sizeVideo.height);
}
if (!photoSizes.empty()) {
@@ -437,6 +447,11 @@ int32_t CameraCaptureVideo::InitCameraInput()
{
int32_t result = -1;
if (!cameraManager_) {
MEDIA_ERR_LOG("cameraManager_ is null");
return result;
}
if (cameraInput_ == nullptr) {
std::vector<sptr<CameraInfo>> cameraObjList = cameraManager_->GetCameras();
if (cameraObjList.size() <= 0) {
@@ -464,8 +479,17 @@ int32_t CameraCaptureVideo::InitPreviewOutput()
{
int32_t result = -1;
if (!cameraManager_) {
MEDIA_ERR_LOG("cameraManager_ is null");
return result;
}
if (previewOutput_ == nullptr) {
previewSurface_ = Surface::CreateSurfaceAsConsumer();
if (!previewSurface_) {
MEDIA_ERR_LOG("previewSurface_ is null");
return result;
}
previewSurface_->SetDefaultWidthAndHeight(previewWidth_, previewHeight_);
previewSurface_->SetUserData(CameraManager::surfaceFormat, std::to_string(previewFormat_));
previewSurfaceListener_ = new SurfaceListener(testName_, SurfaceType::PREVIEW, fd_, previewSurface_);
@@ -486,12 +510,25 @@ int32_t CameraCaptureVideo::InitSecondPreviewOutput()
{
int32_t result = -1;
if (!cameraManager_) {
MEDIA_ERR_LOG("cameraManager_ is null");
return result;
}
if (secondPreviewOutput_ == nullptr) {
secondPreviewSurface_ = Surface::CreateSurfaceAsConsumer();
if (!secondPreviewSurface_) {
MEDIA_ERR_LOG("secondPreviewSurface_ is null");
return result;
}
secondPreviewSurface_->SetDefaultWidthAndHeight(previewWidth_, previewHeight_);
secondPreviewSurface_->SetUserData(CameraManager::surfaceFormat, std::to_string(previewFormat_));
secondPreviewSurfaceListener_ = new SurfaceListener(testName_,
SurfaceType::SECOND_PREVIEW, fd_, secondPreviewSurface_);
if (!secondPreviewSurfaceListener_) {
MEDIA_ERR_LOG("Failed to create new SurfaceListener");
return result;
}
secondPreviewSurface_->RegisterConsumerListener((sptr<IBufferConsumerListener> &)secondPreviewSurfaceListener_);
secondPreviewOutput_ = cameraManager_->CreateCustomPreviewOutput(secondPreviewSurface_->GetProducer(),
previewFormat_, previewWidth2_,
@@ -511,11 +548,24 @@ int32_t CameraCaptureVideo::InitPhotoOutput()
{
int32_t result = -1;
if (!cameraManager_) {
MEDIA_ERR_LOG("cameraManager_ is null");
return result;
}
if (photoOutput_ == nullptr) {
photoSurface_ = Surface::CreateSurfaceAsConsumer();
if (!photoSurface_) {
MEDIA_ERR_LOG("photoSurface_ is null");
return result;
}
photoSurface_->SetDefaultWidthAndHeight(photoWidth_, photoHeight_);
photoSurface_->SetUserData(CameraManager::surfaceFormat, std::to_string(photoFormat_));
photoSurfaceListener_ = new SurfaceListener(testName_, SurfaceType::PHOTO, fd_, photoSurface_);
if (!photoSurfaceListener_) {
MEDIA_ERR_LOG("Failed to create new SurfaceListener");
return result;
}
photoSurface_->RegisterConsumerListener((sptr<IBufferConsumerListener> &)photoSurfaceListener_);
photoOutput_ = cameraManager_->CreatePhotoOutput(photoSurface_);
if (photoOutput_ == nullptr) {
@@ -533,11 +583,24 @@ int32_t CameraCaptureVideo::InitVideoOutput()
{
int32_t result = -1;
if (!cameraManager_) {
MEDIA_ERR_LOG("cameraManager_ is null");
return result;
}
if (videoOutput_ == nullptr) {
videoSurface_ = Surface::CreateSurfaceAsConsumer();
if (!videoSurface_) {
MEDIA_ERR_LOG("videoSurface_ is null");
return result;
}
videoSurface_->SetDefaultWidthAndHeight(videoWidth_, videoHeight_);
videoSurface_->SetUserData(CameraManager::surfaceFormat, std::to_string(videoFormat_));
videoSurfaceListener_ = new SurfaceListener(testName_, SurfaceType::VIDEO, fd_, videoSurface_);
if (!videoSurfaceListener_) {
MEDIA_ERR_LOG("Failed to create new SurfaceListener");
return result;
}
videoSurface_->RegisterConsumerListener((sptr<IBufferConsumerListener> &)videoSurfaceListener_);
videoOutput_ = cameraManager_->CreateVideoOutput(videoSurface_);
if (videoOutput_ == nullptr) {
@@ -555,6 +618,10 @@ int32_t CameraCaptureVideo::AddOutputbyState()
{
int32_t result = -1;
if (!captureSession_) {
MEDIA_ERR_LOG("captureSession_ is null");
return result;
}
switch (currentState_) {
case State::PHOTO_CAPTURE:
result = InitPhotoOutput();
@@ -632,3 +699,4 @@ int32_t main(int32_t argc, char **argv)
DisplayMenu(testObj);
return 0;
}
@@ -52,6 +52,7 @@ public:
int32_t TakePhoto();
int32_t RecordVideo();
void Release();
private:
int32_t AddOutputbyState();
int32_t InitCameraFormatAndResolution(sptr<CameraInput> &cameraInput);
@@ -335,8 +335,8 @@ int main(int argc, char **argv)
std::vector<CameraPicSize> videoSizes
= cameraInput->getSupportedSizes(static_cast<camera_format_t>(videoFormat));
MEDIA_DEBUG_LOG("Supported sizes for video:");
for (auto &size : videoSizes) {
MEDIA_DEBUG_LOG("width: %{public}d, height: %{public}d", size.width, size.height);
for (auto &sizeVideo : videoSizes) {
MEDIA_DEBUG_LOG("width: %{public}d, height: %{public}d", sizeVideo.width, sizeVideo.height);
}
if (!previewSizes.empty()) {
previewWidth = previewSizes[0].width;
@@ -72,7 +72,7 @@ int32_t TestUtils::SaveYUV(const char *buffer, int32_t size, SurfaceType type)
return -1;
}
MEDIA_DEBUG_LOG("%s, saving file to %{public}s", __FUNCTION__, path);
MEDIA_DEBUG_LOG("%s, saving file to %{private}s", __FUNCTION__, path);
int imgFd = open(path, O_RDWR | O_CREAT, FILE_PERMISSIONS_FLAG);
if (imgFd == -1) {
MEDIA_ERR_LOG("%s, open file failed, errno = %{public}s.", __FUNCTION__, strerror(errno));
@@ -112,7 +112,7 @@ int32_t TestUtils::SaveVideoFile(const char *buffer, int32_t size, VideoSaveMode
MEDIA_ERR_LOG("Failed to create video file name");
return -1;
}
MEDIA_DEBUG_LOG("%{public}s, save video to file %{public}s", __FUNCTION__, path);
MEDIA_DEBUG_LOG("%{public}s, save video to file %{private}s", __FUNCTION__, path);
fd = open(path, O_RDWR | O_CREAT, FILE_PERMISSIONS_FLAG);
if (fd == -1) {
std::cout << "open file failed, errno = " << strerror(errno) << std::endl;
@@ -123,7 +123,8 @@ int32_t TestUtils::SaveVideoFile(const char *buffer, int32_t size, VideoSaveMode
if (ret == -1) {
std::cout << "write file failed, error = " << strerror(errno) << std::endl;
close(fd);
return -1;
fd = -1;
return fd;
}
} else { // VideoSaveMode::CLOSE
if (fd != -1) {
@@ -237,6 +238,10 @@ void SurfaceListener::OnBufferAvailable()
MEDIA_DEBUG_LOG("SurfaceListener::OnBufferAvailable(), testName_: %{public}s, surfaceType_: %{public}d",
testName_, surfaceType_);
OHOS::sptr<OHOS::SurfaceBuffer> buffer = nullptr;
if (!surface_) {
MEDIA_ERR_LOG("OnBufferAvailable:surface_ is null");
return;
}
surface_->AcquireBuffer(buffer, flushFence, timestamp, damage);
if (buffer != nullptr) {
char *addr = static_cast<char *>(buffer->GetVirAddr());
@@ -287,3 +292,4 @@ void SurfaceListener::OnBufferAvailable()
}
} // namespace CameraStandard
} // namespace OHOS
+17 -16
View File
@@ -49,9 +49,9 @@ class TestCameraMngerCallback : public CameraManagerCallback {
public:
explicit TestCameraMngerCallback(const char *testName);
virtual ~TestCameraMngerCallback() = default;
virtual void OnCameraStatusChanged(const CameraStatusInfo &cameraStatusInfo) const override;
virtual void OnFlashlightStatusChanged(const std::string &cameraID,
const FlashlightStatus flashStatus) const override;
void OnCameraStatusChanged(const CameraStatusInfo &cameraStatusInfo) const override;
void OnFlashlightStatusChanged(const std::string &cameraID,
const FlashlightStatus flashStatus) const override;
private:
const char *testName_;
@@ -61,7 +61,7 @@ class TestDeviceCallback : public ErrorCallback {
public:
explicit TestDeviceCallback(const char *testName);
virtual ~TestDeviceCallback() = default;
virtual void OnError(const int32_t errorType, const int32_t errorMsg) const override;
void OnError(const int32_t errorType, const int32_t errorMsg) const override;
private:
const char *testName_;
@@ -71,10 +71,10 @@ class TestPhotoOutputCallback : public PhotoCallback {
public:
explicit TestPhotoOutputCallback(const char *testName);
virtual ~TestPhotoOutputCallback() = default;
virtual void OnCaptureStarted(const int32_t captureID) const override;
virtual void OnCaptureEnded(const int32_t captureID, const int32_t frameCount) const override;
virtual void OnFrameShutter(const int32_t captureId, const uint64_t timestamp) const override;
virtual void OnCaptureError(const int32_t captureId, const int32_t errorCode) const override;
void OnCaptureStarted(const int32_t captureID) const override;
void OnCaptureEnded(const int32_t captureID, const int32_t frameCount) const override;
void OnFrameShutter(const int32_t captureId, const uint64_t timestamp) const override;
void OnCaptureError(const int32_t captureId, const int32_t errorCode) const override;
private:
const char *testName_;
@@ -84,9 +84,9 @@ class TestPreviewOutputCallback : public PreviewCallback {
public:
explicit TestPreviewOutputCallback(const char *testName);
virtual ~TestPreviewOutputCallback() = default;
virtual void OnFrameStarted() const override;
virtual void OnFrameEnded(const int32_t frameCount) const override;
virtual void OnError(const int32_t errorCode) const override;
void OnFrameStarted() const override;
void OnFrameEnded(const int32_t frameCount) const override;
void OnError(const int32_t errorCode) const override;
private:
const char *testName_;
@@ -96,9 +96,9 @@ class TestVideoOutputCallback : public VideoCallback {
public:
explicit TestVideoOutputCallback(const char *testName);
virtual ~TestVideoOutputCallback() = default;
virtual void OnFrameStarted() const override;
virtual void OnFrameEnded(const int32_t frameCount) const override;
virtual void OnError(const int32_t errorCode) const override;
void OnFrameStarted() const override;
void OnFrameEnded(const int32_t frameCount) const override;
void OnError(const int32_t errorCode) const override;
private:
const char *testName_;
@@ -108,7 +108,7 @@ class SurfaceListener : public IBufferConsumerListener {
public:
SurfaceListener(const char *testName, SurfaceType surfaceType, int32_t &fd, sptr<Surface> surface);
virtual ~SurfaceListener() = default;
virtual void OnBufferAvailable() override;
void OnBufferAvailable() override;
private:
const char *testName_;
@@ -120,4 +120,5 @@ private:
};
} // namespace CameraStandard
} // namespace OHOS
#endif // CAMERA_TEST_COMMON_H
#endif // CAMERA_TEST_COMMON_H
+2 -2
View File
@@ -59,8 +59,8 @@ ohos_shared_library("camera_napi") {
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
cflags = [ "-fPIC" ]
if (device_name == "baltimore") {
cflags += [ "-DBALTIMORE_CAMERA" ]
if ("${product_name}" == "m40") {
cflags += [ "-DPRODUCT_M40" ]
} else {
if (device_name == "rk3566" || device_name == "rk3568") {
cflags += [ "-DRK_CAMERA" ]
@@ -36,7 +36,7 @@
namespace OHOS {
namespace CameraStandard {
static const std::string CAMERA_OBJECT_NAPI_CLASS_NAME = "Camera";
static const char CAMERA_OBJECT_NAPI_CLASS_NAME[] = "Camera";
class CameraInfoNapi {
public:
@@ -42,7 +42,7 @@
namespace OHOS {
namespace CameraStandard {
static const std::string CAMERA_INPUT_NAPI_CLASS_NAME = "CameraInput";
static const char CAMERA_INPUT_NAPI_CLASS_NAME[] = "CameraInput";
class ExposureCallbackListener : public ExposureCallback {
public:
@@ -48,7 +48,7 @@
namespace OHOS {
namespace CameraStandard {
static const std::string CAMERA_MANAGER_NAPI_CLASS_NAME = "CameraManager";
static const char CAMERA_MANAGER_NAPI_CLASS_NAME[] = "CameraManager";
class CameraManagerNapi {
public:
@@ -49,7 +49,7 @@ namespace OHOS {
namespace CameraStandard {
struct CamRecorderCallback;
static const std::string CAMERA_LIB_NAPI_CLASS_NAME = "camera";
static const char CAMERA_LIB_NAPI_CLASS_NAME[] = "camera";
// Photo default size
static const std::int32_t PHOTO_DEFAULT_WIDTH = 1280;
static const std::int32_t PHOTO_DEFAULT_HEIGHT = 960;
@@ -36,7 +36,7 @@
namespace OHOS {
namespace CameraStandard {
static const std::string CAMERA_SIZE_NAPI_CLASS_NAME = "Size";
static const char CAMERA_SIZE_NAPI_CLASS_NAME[] = "Size";
class CameraSizeNapi {
public:
@@ -43,7 +43,7 @@
namespace OHOS {
namespace CameraStandard {
static const std::string CAMERA_PHOTO_OUTPUT_NAPI_CLASS_NAME = "PhotoOutput";
static const char CAMERA_PHOTO_OUTPUT_NAPI_CLASS_NAME[] = "PhotoOutput";
struct CallbackInfo {
int32_t captureID;
@@ -42,7 +42,7 @@
namespace OHOS {
namespace CameraStandard {
static const std::string CAMERA_PREVIEW_OUTPUT_NAPI_CLASS_NAME = "PreviewOutput";
static const char CAMERA_PREVIEW_OUTPUT_NAPI_CLASS_NAME[] = "PreviewOutput";
class PreviewOutputCallback : public PreviewCallback {
public:
@@ -40,7 +40,7 @@
namespace OHOS {
namespace CameraStandard {
static const std::string CAMERA_VIDEO_OUTPUT_NAPI_CLASS_NAME = "VideoOutput";
static const char CAMERA_VIDEO_OUTPUT_NAPI_CLASS_NAME[] = "VideoOutput";
class SurfaceListener : public IBufferConsumerListener {
public:
@@ -44,7 +44,7 @@
namespace OHOS {
namespace CameraStandard {
static const std::string CAMERA_SESSION_NAPI_CLASS_NAME = "CaptureSession";
static const char CAMERA_SESSION_NAPI_CLASS_NAME[] = "CaptureSession";
class SessionCallbackListener : public SessionCallback {
public:
+2 -2
View File
@@ -80,8 +80,8 @@ ohos_shared_library("camera_service") {
"samgr_standard:samgr_proxy",
]
if (device_name == "baltimore") {
cflags += [ "-DBALTIMORE_CAMERA" ]
if ("${product_name}" == "m40") {
cflags += [ "-DPRODUCT_M40" ]
include_dirs += [
"//drivers/peripheral/adapter/camera/interfaces/include",
"//drivers/peripheral/adapter/camera/interfaces/include/server",
@@ -41,3 +41,4 @@ public:
} // namespace CameraStandard
} // namespace OHOS
#endif // OHOS_CAMERA_ICAMERA_SERVICE_CALLBACK_H
@@ -34,4 +34,5 @@ public:
};
} // namespace CameraStandard
} // namespace OHOS
#endif // OHOS_CAMERA_ISTREAM_CAPTURE_CALLBACK_H
#endif // OHOS_CAMERA_ISTREAM_CAPTURE_CALLBACK_H
@@ -35,3 +35,4 @@ private:
} // namespace CameraStandard
} // namespace OHOS
#endif // OHOS_CAMERA_HCAMERA_SERVICE_CALLBACK_PROXY_H
@@ -40,4 +40,5 @@ private:
};
} // namespace CameraStandard
} // namespace OHOS
#endif // OHOS_CAMERA_HSTREAM_CAPTURE_CALLBACK_PROXY_H
#endif // OHOS_CAMERA_HSTREAM_CAPTURE_CALLBACK_PROXY_H
@@ -54,7 +54,6 @@ int32_t HCameraDeviceCallbackProxy::OnResult(const uint64_t timestamp,
MessageParcel data;
MessageParcel reply;
MessageOption option;
bool bRet = false;
if (!data.WriteInterfaceToken(GetDescriptor())) {
MEDIA_ERR_LOG("HCameraDeviceCallbackProxy OnResult Write interface token failed");
@@ -64,8 +63,7 @@ int32_t HCameraDeviceCallbackProxy::OnResult(const uint64_t timestamp,
MEDIA_ERR_LOG("HCameraDeviceCallbackProxy OnResult Write timestamp failed");
return IPC_PROXY_ERR;
}
bRet = MetadataUtils::EncodeCameraMetadata(result, data);
if (!bRet) {
if (!(MetadataUtils::EncodeCameraMetadata(result, data))) {
MEDIA_ERR_LOG("HCameraDeviceCallbackProxy OnResult EncodeCameraMetadata failed");
return IPC_PROXY_ERR;
}
@@ -115,8 +115,7 @@ int32_t HCameraDeviceProxy::UpdateSetting(const std::shared_ptr<CameraMetadata>
MEDIA_ERR_LOG("HCameraDeviceProxy UpdateSetting Write interface token failed");
return IPC_PROXY_ERR;
}
bool bRet = MetadataUtils::EncodeCameraMetadata(settings, data);
if (!bRet) {
if (!(MetadataUtils::EncodeCameraMetadata(settings, data))) {
MEDIA_ERR_LOG("HCameraDeviceProxy UpdateSetting EncodeCameraMetadata failed");
return IPC_PROXY_ERR;
}
@@ -12,11 +12,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "hcamera_listener_proxy.h"
#include <cinttypes>
#include "media_log.h"
#include "camera_util.h"
#include "hcamera_listener_proxy.h"
namespace OHOS {
namespace CameraStandard {
@@ -74,3 +74,4 @@ int32_t HCameraServiceCallbackProxy::OnFlashlightStatusChanged(const std::string
}
} // namespace CameraStandard
} // namespace OHOS
@@ -45,3 +45,4 @@ int32_t HCaptureSessionCallbackProxy::OnError(int32_t errorCode)
}
} // namespace CameraStandard
} // namespace OHOS
@@ -33,8 +33,7 @@ int32_t HStreamCaptureProxy::Capture(const std::shared_ptr<CameraMetadata> &capt
MEDIA_ERR_LOG("HStreamCaptureProxy Capture Write interface token failed");
return IPC_PROXY_ERR;
}
bool bRet = MetadataUtils::EncodeCameraMetadata(captureSettings, data);
if (!bRet) {
if (!(MetadataUtils::EncodeCameraMetadata(captureSettings, data))) {
MEDIA_ERR_LOG("HStreamCaptureProxy Capture EncodeCameraMetadata failed");
return IPC_PROXY_ERR;
}
@@ -23,7 +23,7 @@ namespace OHOS {
namespace CameraStandard {
class HCameraDeviceCallbackStub : public IRemoteStub<ICameraDeviceServiceCallback> {
public:
virtual int OnRemoteRequest(uint32_t code, MessageParcel &data,
int OnRemoteRequest(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option) override;
private:
@@ -23,7 +23,7 @@ namespace OHOS {
namespace CameraStandard {
class HCameraDeviceStub : public IRemoteStub<ICameraDeviceService> {
public:
virtual int OnRemoteRequest(uint32_t code, MessageParcel &data,
int OnRemoteRequest(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option) override;
private:
@@ -23,8 +23,8 @@ namespace OHOS {
namespace CameraStandard {
class HCameraServiceCallbackStub : public IRemoteStub<ICameraServiceCallback> {
public:
virtual int OnRemoteRequest(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option) override;
int OnRemoteRequest(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option) override;
private:
int HandleOnCameraStatusChanged(MessageParcel& data);
@@ -32,4 +32,4 @@ private:
};
} // namespace CameraStandard
} // namespace OHOS
#endif // OHOS_CAMERA_HCAMERA_SERVICE_CALLBACK_STUB_H
#endif // OHOS_CAMERA_HCAMERA_SERVICE_CALLBACK_STUB_H
@@ -27,8 +27,8 @@ class HCameraServiceStub : public IRemoteStub<ICameraService> {
public:
HCameraServiceStub();
~HCameraServiceStub();
virtual int OnRemoteRequest(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option) override;
int OnRemoteRequest(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option) override;
private:
int HandleGetCameras(MessageParcel& reply);
@@ -50,3 +50,4 @@ private:
} // namespace CameraStandard
} // namespace OHOS
#endif // OHOS_CAMERA_HCAMERA_SERVICE_STUB_H
@@ -23,7 +23,7 @@ namespace OHOS {
namespace CameraStandard {
class HCaptureSessionCallbackStub : public IRemoteStub<ICaptureSessionCallback> {
public:
virtual int OnRemoteRequest(uint32_t code, MessageParcel &data,
int OnRemoteRequest(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option) override;
private:
@@ -23,8 +23,8 @@ namespace OHOS {
namespace CameraStandard {
class HCaptureSessionStub : public IRemoteStub<ICaptureSession> {
public:
virtual int OnRemoteRequest(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option) override;
int OnRemoteRequest(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option) override;
private:
int HandleAddInput(MessageParcel &data);
@@ -34,4 +34,5 @@ private:
};
} // namespace CameraStandard
} // namespace OHOS
#endif // OHOS_CAMERA_HSTREAM_CAPTURE_CALLBACK_STUB_H
#endif // OHOS_CAMERA_HSTREAM_CAPTURE_CALLBACK_STUB_H
@@ -23,7 +23,7 @@ namespace OHOS {
namespace CameraStandard {
class HStreamCaptureStub : public IRemoteStub<IStreamCapture> {
public:
virtual int OnRemoteRequest(uint32_t code, MessageParcel &data,
int OnRemoteRequest(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option) override;
public:
@@ -23,8 +23,8 @@ namespace OHOS {
namespace CameraStandard {
class HStreamRepeatCallbackStub : public IRemoteStub<IStreamRepeatCallback> {
public:
virtual int OnRemoteRequest(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option) override;
int OnRemoteRequest(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option) override;
private:
int HandleOnFrameEnded(MessageParcel& data);
@@ -23,8 +23,8 @@ namespace OHOS {
namespace CameraStandard {
class HStreamRepeatStub : public IRemoteStub<IStreamRepeat> {
public:
virtual int OnRemoteRequest(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option) override;
int OnRemoteRequest(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option) override;
private:
int HandleSetCallback(MessageParcel &data);
@@ -12,11 +12,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "hcamera_listener_stub.h"
#include <cinttypes>
#include "media_log.h"
#include "camera_util.h"
#include "hcamera_listener_stub.h"
namespace OHOS {
namespace CameraStandard {
@@ -32,4 +33,4 @@ CameraListenerStub::~CameraListenerStub()
(POINTER_MASK & reinterpret_cast<uintptr_t>(this)));
}
} // namespace CameraStandard
} // namespace OHOS
} // namespace OHOS
@@ -12,6 +12,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "hcamera_service_stub.h"
#include <cinttypes>
#include "camera_util.h"
@@ -22,7 +25,6 @@
#include "hcamera_service.h"
#include "input/i_standard_camera_listener.h"
#include "ipc_skeleton.h"
#include "hcamera_service_stub.h"
namespace OHOS {
namespace CameraStandard {
@@ -103,8 +105,7 @@ int HCameraServiceStub::HandleGetCameras(MessageParcel& reply)
}
for (auto cameraAbility : cameraAbilityList) {
bool bRet = MetadataUtils::EncodeCameraMetadata(cameraAbility, reply);
if (!bRet) {
if (!(MetadataUtils::EncodeCameraMetadata(cameraAbility, reply))) {
MEDIA_ERR_LOG("HCameraServiceStub HandleGetCameras write ability failed");
return IPC_STUB_WRITE_PARCEL_ERR;
}
@@ -81,3 +81,4 @@ int HStreamCaptureCallbackStub::HandleOnFrameShutter(MessageParcel& data)
}
} // namespace CameraStandard
} // namespace OHOS
@@ -67,11 +67,11 @@ private:
class CameraDeviceCallback : public Camera::CameraDeviceCallbackStub {
public:
CameraDeviceCallback() = default;
CameraDeviceCallback(sptr<HCameraDevice> hCameraDevice);
explicit CameraDeviceCallback(sptr<HCameraDevice> hCameraDevice);
virtual ~CameraDeviceCallback() = default;
virtual void OnError(Camera::ErrorType type, int32_t errorMsg) override;
virtual void OnResult(const uint64_t timestamp,
const std::shared_ptr<CameraStandard::CameraMetadata> &result) override;
void OnError(Camera::ErrorType type, int32_t errorMsg) override;
void OnResult(const uint64_t timestamp,
const std::shared_ptr<CameraStandard::CameraMetadata> &result) override;
void SetHCameraDevice(sptr<HCameraDevice> hcameraDevice);
private:
@@ -105,16 +105,16 @@ private:
class StreamOperatorCallback : public Camera::StreamOperatorCallbackStub {
public:
StreamOperatorCallback() = default;
StreamOperatorCallback(sptr<HCaptureSession> session);
explicit StreamOperatorCallback(sptr<HCaptureSession> session);
virtual ~StreamOperatorCallback() = default;
virtual void OnCaptureStarted(int32_t captureId, const std::vector<int32_t> &streamId) override;
virtual void OnCaptureEnded(int32_t captureId,
const std::vector<std::shared_ptr<Camera::CaptureEndedInfo>> &info) override;
virtual void OnCaptureError(int32_t captureId,
const std::vector<std::shared_ptr<Camera::CaptureErrorInfo>> &info) override;
virtual void OnFrameShutter(int32_t captureId,
const std::vector<int32_t> &streamId, uint64_t timestamp) override;
void OnCaptureStarted(int32_t captureId, const std::vector<int32_t> &streamId) override;
void OnCaptureEnded(int32_t captureId,
const std::vector<std::shared_ptr<Camera::CaptureEndedInfo>> &info) override;
void OnCaptureError(int32_t captureId,
const std::vector<std::shared_ptr<Camera::CaptureErrorInfo>> &info) override;
void OnFrameShutter(int32_t captureId,
const std::vector<int32_t> &streamId, uint64_t timestamp) override;
void SetCaptureSession(sptr<HCaptureSession> captureSession);
private:
+2 -1
View File
@@ -14,6 +14,7 @@
*/
#include "camera_util.h"
#include <securec.h>
#include "media_log.h"
namespace OHOS {
@@ -93,7 +94,7 @@ int32_t HdiToServiceError(Camera::CamRetCode ret)
bool IsValidSize(std::shared_ptr<CameraMetadata> cameraAbility, int32_t format, int32_t width, int32_t height)
{
#ifndef BALTIMORE_CAMERA
#ifndef PRODUCT_M40
return true;
#endif
uint32_t unitLen = 3;
@@ -13,9 +13,10 @@
* limitations under the License.
*/
#include "hcamera_device.h"
#include "camera_util.h"
#include "media_log.h"
#include "hcamera_device.h"
namespace OHOS {
namespace CameraStandard {
@@ -109,14 +110,11 @@ int32_t HCameraDevice::Release()
int32_t HCameraDevice::GetEnabledResults(std::vector<int32_t> &results)
{
std::vector<int32_t> settings;
Camera::CamRetCode rc = hdiCameraDevice_->GetEnabledResults(settings);
Camera::CamRetCode rc = hdiCameraDevice_->GetEnabledResults(results);
if (rc != Camera::NO_ERROR) {
MEDIA_ERR_LOG("HCameraDevice::GetEnabledResults failed with error Code:%{public}d", rc);
return HdiToServiceError(rc);
}
results = settings;
return CAMERA_OK;
}
@@ -14,6 +14,7 @@
*/
#include "hcamera_host_manager.h"
#include "camera_host_callback_stub.h"
#include "camera_util.h"
#include "hdf_io_service_if.h"
@@ -133,6 +134,10 @@ int32_t HCameraHostManager::CameraHostInfo::GetCameraAbility(std::string& camera
ability = deviceInfo->ability;
} else {
std::lock_guard<std::mutex> lock(deviceInfo->mutex);
if (!cameraHostProxy_) {
MEDIA_ERR_LOG("CameraHostInfo::GetCameraAbility cameraHostProxy_ is null");
return CAMERA_UNKNOWN_ERROR;
}
if (!deviceInfo->ability) {
Camera::CamRetCode rc = cameraHostProxy_->GetCameraAbility(cameraId, ability);
if (rc != Camera::NO_ERROR) {
@@ -157,6 +162,10 @@ int32_t HCameraHostManager::CameraHostInfo::OpenCamera(std::string& cameraId,
}
std::lock_guard<std::mutex> lock(deviceInfo->mutex);
if (!cameraHostProxy_) {
MEDIA_ERR_LOG("CameraHostInfo::OpenCamera cameraHostProxy_ is null");
return CAMERA_UNKNOWN_ERROR;
}
Camera::CamRetCode rc = cameraHostProxy_->OpenCamera(cameraId, callback, pDevice);
if (rc != Camera::NO_ERROR) {
MEDIA_ERR_LOG("CameraHostInfo::OpenCamera failed with error Code:%{public}d", rc);
@@ -168,6 +177,10 @@ int32_t HCameraHostManager::CameraHostInfo::OpenCamera(std::string& cameraId,
int32_t HCameraHostManager::CameraHostInfo::SetFlashlight(const std::string& cameraId, bool isEnable)
{
std::lock_guard<std::mutex> lock(mutex_);
if (!cameraHostProxy_) {
MEDIA_ERR_LOG("CameraHostInfo::SetFlashlight cameraHostProxy_ is null");
return CAMERA_UNKNOWN_ERROR;
}
Camera::CamRetCode rc = cameraHostProxy_->SetFlashlight(cameraId, isEnable);
if (rc != Camera::NO_ERROR) {
MEDIA_ERR_LOG("CameraHostInfo::SetFlashlight failed with error Code:%{public}d", rc);
@@ -178,7 +191,7 @@ int32_t HCameraHostManager::CameraHostInfo::SetFlashlight(const std::string& cam
void HCameraHostManager::CameraHostInfo::OnCameraStatus(const std::string& cameraId, Camera::CameraStatus status)
{
if (cameraHostManager_->statusCallback_ == nullptr) {
if ((cameraHostManager_ == nullptr) || (cameraHostManager_->statusCallback_ == nullptr)) {
MEDIA_WARNING_LOG("CameraHostInfo::OnCameraStatus for %{public}s with status %{public}d "
"failed due to no callback",
cameraId.c_str(), status);
@@ -208,9 +221,9 @@ void HCameraHostManager::CameraHostInfo::OnCameraStatus(const std::string& camer
void HCameraHostManager::CameraHostInfo::OnFlashlightStatus(const std::string& cameraId,
Camera::FlashlightStatus status)
{
if (cameraHostManager_->statusCallback_ == nullptr) {
if ((cameraHostManager_ == nullptr) || (cameraHostManager_->statusCallback_ == nullptr)) {
MEDIA_WARNING_LOG("CameraHostInfo::OnFlashlightStatus for %{public}s with status %{public}d "
"failed due to no callback",
"failed due to no callback or cameraHostManager_ is null",
cameraId.c_str(), status);
return;
}
@@ -243,9 +256,9 @@ void HCameraHostManager::CameraHostInfo::OnFlashlightStatus(const std::string& c
void HCameraHostManager::CameraHostInfo::OnCameraEvent(const std::string &cameraId, Camera::CameraEvent event)
{
if (cameraHostManager_->statusCallback_ == nullptr) {
if ((cameraHostManager_ == nullptr) || (cameraHostManager_->statusCallback_ == nullptr)) {
MEDIA_WARNING_LOG("CameraHostInfo::OnCameraEvent for %{public}s with status %{public}d "
"failed due to no callback",
"failed due to no callback or cameraHostManager_ is null",
cameraId.c_str(), event);
return;
}
@@ -13,19 +13,18 @@
* limitations under the License.
*/
#include <iostream>
#include <map>
#include <string>
#include "hcamera_service.h"
#include <securec.h>
#include <unordered_set>
#include "access_token.h"
#include "accesstoken_kit.h"
#include "camera_util.h"
#include "iservice_registry.h"
#include "media_log.h"
#include "system_ability_definition.h"
#include "ipc_skeleton.h"
#include "access_token.h"
#include "accesstoken_kit.h"
#include "hcamera_service.h"
namespace OHOS {
namespace CameraStandard {
@@ -47,6 +46,10 @@ void HCameraService::OnStart()
{
if (!cameraHostManager_) {
cameraHostManager_ = new HCameraHostManager(this);
if (!cameraHostManager_) {
MEDIA_ERR_LOG("HCameraService OnStart failed to create HCameraHostManager obj");
return;
}
}
if (cameraHostManager_->Init() != CAMERA_OK) {
MEDIA_ERR_LOG("HCameraService OnStart failed to init camera host manager.");
@@ -113,6 +116,10 @@ int32_t HCameraService::CreateCameraDevice(std::string cameraId, sptr<ICameraDev
if (cameraDeviceCallback_ == nullptr) {
cameraDeviceCallback_ = new CameraDeviceCallback();
if (!cameraDeviceCallback_) {
MEDIA_ERR_LOG("HCameraService::CreateCameraDevice CameraDeviceCallback allocation failed");
return CAMERA_ALLOC_ERROR;
}
}
cameraDevice = new HCameraDevice(cameraHostManager_, cameraDeviceCallback_, cameraId);
if (cameraDevice == nullptr) {
@@ -129,6 +136,10 @@ int32_t HCameraService::CreateCaptureSession(sptr<ICaptureSession> &session)
sptr<HCaptureSession> captureSession;
if (streamOperatorCallback_ == nullptr) {
streamOperatorCallback_ = new StreamOperatorCallback();
if (streamOperatorCallback_ == nullptr) {
MEDIA_ERR_LOG("HCameraService::CreateCaptureSession streamOperatorCallback_ allocation failed");
return CAMERA_ALLOC_ERROR;
}
}
captureSession = new HCaptureSession(cameraHostManager_, streamOperatorCallback_);
@@ -179,7 +190,7 @@ int32_t HCameraService::CreateCustomPreviewOutput(const sptr<OHOS::IBufferProduc
{
sptr<HStreamRepeat> streamRepeatPreview;
if (producer == nullptr || width == 0 || height == 0) {
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;
}
@@ -13,11 +13,12 @@
* limitations under the License.
*/
#include "hcapture_session.h"
#include "camera_util.h"
#include "media_log.h"
#include "surface.h"
#include "ipc_skeleton.h"
#include "hcapture_session.h"
namespace OHOS {
namespace CameraStandard {
@@ -300,8 +301,8 @@ int32_t HCaptureSession::GetCurrentStreamInfos(sptr<HCameraDevice> &device,
curStreamCapture->SetStreamInfo(curStreamInfo);
streamInfos.push_back(curStreamInfo);
}
for (auto item = streamRepeats_.begin(); item != streamRepeats_.end(); ++item) {
curStreamRepeat = *item;
for (auto item_ = streamRepeats_.begin(); item_ != streamRepeats_.end(); ++item_) {
curStreamRepeat = *item_;
if (curStreamRepeat->IsReleaseStream()) {
continue;
}
@@ -334,12 +335,12 @@ int32_t HCaptureSession::CreateAndCommitStreams(sptr<HCameraDevice> &device,
sptr<Camera::IStreamOperator> streamOperator;
streamOperator = device->GetStreamOperator();
if (!streamInfos.empty()) {
if (streamOperator != nullptr && !streamInfos.empty()) {
hdiRc = streamOperator->CreateStreams(streamInfos);
} else {
MEDIA_INFO_LOG("HCaptureSession::CreateAndCommitStreams(), No new streams to create");
}
if (hdiRc == Camera::NO_ERROR) {
if (streamOperator != nullptr && hdiRc == Camera::NO_ERROR) {
hdiRc = streamOperator->CommitStreams(Camera::NORMAL, deviceSettings);
if (hdiRc != Camera::NO_ERROR) {
MEDIA_ERR_LOG("HCaptureSession::CreateAndCommitStreams(), Failed to commit %{public}d", hdiRc);
@@ -360,7 +361,7 @@ int32_t HCaptureSession::CheckAndCommitStreams(sptr<HCameraDevice> &device,
std::vector<std::shared_ptr<Camera::StreamInfo>> &allStreamInfos,
std::vector<std::shared_ptr<Camera::StreamInfo>> &newStreamInfos)
{
#ifndef BALTIMORE_CAMERA
#ifndef PRODUCT_M40
Camera::CamRetCode hdiRc = Camera::NO_ERROR;
Camera::StreamSupportType supportType = Camera::DYNAMIC_SUPPORTED;
@@ -389,11 +390,11 @@ void HCaptureSession::DeleteReleasedStream()
streamCaptures_.erase(item--);
}
}
for (auto item = streamRepeats_.begin(); item != streamRepeats_.end(); ++item) {
curStreamRepeat = *item;
for (auto item_ = streamRepeats_.begin(); item_ != streamRepeats_.end(); ++item_) {
curStreamRepeat = *item_;
if (curStreamRepeat->IsReleaseStream()) {
curStreamRepeat->Release();
streamRepeats_.erase(item--);
streamRepeats_.erase(item_--);
}
}
}
@@ -417,8 +418,8 @@ void HCaptureSession::RestorePreviousState(sptr<HCameraDevice> &device, bool isC
}
curStreamCapture->SetReleaseStream(false);
}
for (auto item = streamRepeats_.begin(); item != streamRepeats_.end(); ++item) {
curStreamRepeat = *item;
for (auto item_ = streamRepeats_.begin(); item_ != streamRepeats_.end(); ++item_) {
curStreamRepeat = *item_;
if (isCreateReleaseStreams && curStreamRepeat->IsReleaseStream()) {
streamInfo = std::make_shared<Camera::StreamInfo>();
curStreamRepeat->SetStreamInfo(streamInfo);
@@ -427,13 +428,13 @@ void HCaptureSession::RestorePreviousState(sptr<HCameraDevice> &device, bool isC
curStreamRepeat->SetReleaseStream(false);
}
for (auto item = tempStreamCaptures_.begin(); item != tempStreamCaptures_.end(); ++item) {
curStreamCapture = *item;
for (auto item_x = tempStreamCaptures_.begin(); item_x != tempStreamCaptures_.end(); ++item_x) {
curStreamCapture = *item_x;
curStreamCapture->Release();
}
tempStreamCaptures_.clear();
for (auto item = tempStreamRepeats_.begin(); item != tempStreamRepeats_.end(); ++item) {
curStreamRepeat = *item;
for (auto item_y = tempStreamRepeats_.begin(); item_y != tempStreamRepeats_.end(); ++item_y) {
curStreamRepeat = *item_y;
curStreamRepeat->Release();
}
tempStreamRepeats_.clear();
@@ -459,14 +460,13 @@ void HCaptureSession::UpdateSessionConfig(sptr<HCameraDevice> &device)
streamCaptures_.emplace_back(*item);
}
tempStreamCaptures_.clear();
for (auto item = tempStreamRepeats_.begin(); item != tempStreamRepeats_.end(); ++item) {
streamRepeats_.emplace_back(*item);
for (auto item_ = tempStreamRepeats_.begin(); item_ != tempStreamRepeats_.end(); ++item_) {
streamRepeats_.emplace_back(*item_);
}
tempStreamRepeats_.clear();
streamOperatorCallback_->SetCaptureSession(this);
cameraDevice_ = device;
curState_ = CaptureSessionState::SESSION_CONFIG_COMMITTED;
return;
}
int32_t HCaptureSession::HandleCaptureOuputsConfig(sptr<HCameraDevice> &device)
@@ -500,6 +500,10 @@ int32_t HCaptureSession::HandleCaptureOuputsConfig(sptr<HCameraDevice> &device)
streamId = streamId_;
for (auto item = tempStreamCaptures_.begin(); item != tempStreamCaptures_.end(); ++item) {
curStreamCapture = *item;
if (!curStreamCapture) {
MEDIA_ERR_LOG("HCaptureSession::HandleCaptureOuputsConfig() curStreamCapture is null");
return CAMERA_UNKNOWN_ERROR;
}
rc = curStreamCapture->LinkInput(streamOperator, settings, streamId);
if (rc != CAMERA_OK) {
MEDIA_ERR_LOG("HCaptureSession::HandleCaptureOuputsConfig() Failed to link Output, %{public}d", rc);
@@ -511,8 +515,8 @@ int32_t HCaptureSession::HandleCaptureOuputsConfig(sptr<HCameraDevice> &device)
allStreamInfos.push_back(curStreamInfo);
streamId++;
}
for (auto item = tempStreamRepeats_.begin(); item != tempStreamRepeats_.end(); ++item) {
curStreamRepeat = *item;
for (auto item_ = tempStreamRepeats_.begin(); item_ != tempStreamRepeats_.end(); ++item_) {
curStreamRepeat = *item_;
rc = curStreamRepeat->LinkInput(streamOperator, settings, streamId);
if (rc != CAMERA_OK) {
MEDIA_ERR_LOG("HCaptureSession::HandleCaptureOuputsConfig() Failed to link Output, %{public}d", rc);
@@ -649,8 +653,8 @@ void HCaptureSession::ReleaseStreams()
}
streamRepeats_.clear();
HStreamRepeat::ResetCaptureIds();
for (auto item = streamCaptures_.begin(); item != streamCaptures_.end(); ++item) {
curStreamCapture = *item;
for (auto item_ = streamCaptures_.begin(); item_ != streamCaptures_.end(); ++item_) {
curStreamCapture = *item_;
streamIds.emplace_back(curStreamCapture->GetStreamId());
curStreamCapture->Release();
}
@@ -13,11 +13,12 @@
* limitations under the License.
*/
#include "hstream_capture.h"
#include <iostream>
#include "camera_util.h"
#include "media_log.h"
#include "hstream_capture.h"
namespace OHOS {
namespace CameraStandard {
@@ -13,11 +13,12 @@
* limitations under the License.
*/
#include "hstream_repeat.h"
#include <iostream>
#include "camera_util.h"
#include "media_log.h"
#include "hstream_repeat.h"
namespace OHOS {
namespace CameraStandard {
@@ -93,6 +94,11 @@ void HStreamRepeat::SetStreamInfo(std::shared_ptr<Camera::StreamInfo> streamInfo
#endif
}
MEDIA_INFO_LOG("HStreamRepeat::SetStreamInfo pixelFormat is %{public}d", pixelFormat);
if (!streamInfo) {
MEDIA_ERR_LOG("HStreamRepeat::SetStreamInfo null");
return;
}
streamInfo->format_ = pixelFormat;
streamInfo->tunneledMode_ = true;
streamInfo->datasapce_ = CAMERA_PREVIEW_COLOR_SPACE;
@@ -153,7 +159,7 @@ bool HStreamRepeat::IsvalidCaptureID()
startValue = PREVIEW_CAPTURE_ID_START;
endValue = PREVIEW_CAPTURE_ID_END;
}
return (captureID >= startValue && captureID <= endValue);
return ((captureID >= startValue) && (captureID <= endValue));
}
int32_t HStreamRepeat::StartVideo()