summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJayant Chowdhary <jchowdhary@google.com>2022-01-16 17:29:51 -0800
committerJayant Chowdhary <jchowdhary@google.com>2022-02-08 20:02:41 -0800
commite1bb5f76855c81eb8160c794c75f8b31948888ca (patch)
treecbd4dbbff3e77dc208f83d3c7cd09db831c00f07
parent8cd7d914688799b281cdb153eac08af5cad294b5 (diff)
downloadcamera-e1bb5f76855c81eb8160c794c75f8b31948888ca.tar.gz
Move from HIDL to AIDL interface in gch.
Bug: 196432585 Test: Run GCA Test: Camera CTS Change-Id: Idaef647239b8dac3621ccad7bf45ec08c840364f Signed-off-by: Jayant Chowdhary <jchowdhary@google.com>
-rw-r--r--common/hal/aidl_service/Android.bp (renamed from common/hal/hidl_service/Android.bp)52
-rw-r--r--common/hal/aidl_service/CleanSpec.mk (renamed from common/hal/hidl_service/CleanSpec.mk)0
-rw-r--r--common/hal/aidl_service/aidl_camera_build_version.inl (renamed from common/hal/hidl_service/hidl_camera_build_version.inl)0
-rw-r--r--common/hal/aidl_service/aidl_camera_device.cc270
-rw-r--r--common/hal/aidl_service/aidl_camera_device.h110
-rw-r--r--common/hal/aidl_service/aidl_camera_device_session.cc (renamed from common/hal/hidl_service/hidl_camera_device_session.cc)621
-rw-r--r--common/hal/aidl_service/aidl_camera_device_session.h (renamed from common/hal/hidl_service/hidl_camera_device_session.h)178
-rw-r--r--common/hal/aidl_service/aidl_camera_provider.cc375
-rw-r--r--common/hal/aidl_service/aidl_camera_provider.h101
-rw-r--r--common/hal/aidl_service/aidl_profiler.cc (renamed from common/hal/hidl_service/hidl_profiler.cc)36
-rw-r--r--common/hal/aidl_service/aidl_profiler.h (renamed from common/hal/hidl_service/hidl_profiler.h)24
-rw-r--r--common/hal/aidl_service/aidl_service.cc (renamed from common/hal/hidl_service/service.cc)45
-rw-r--r--common/hal/aidl_service/aidl_utils.cc1156
-rw-r--r--common/hal/aidl_service/aidl_utils.h201
-rw-r--r--common/hal/aidl_service/android.hardware.camera.provider@2.7-service-google-lazy.rc10
-rw-r--r--common/hal/aidl_service/android.hardware.camera.provider@2.7-service-google.rc (renamed from common/hal/hidl_service/android.hardware.camera.provider@2.7-service-google.rc)0
-rw-r--r--common/hal/aidl_service/android.hardware.camera.provider@2.7-service-google.xml10
-rw-r--r--common/hal/aidl_service/hidl_thermal_utils.cc (renamed from common/hal/hidl_service/hidl_thermal_utils.cc)7
-rw-r--r--common/hal/aidl_service/hidl_thermal_utils.h (renamed from common/hal/hidl_service/hidl_thermal_utils.h)0
-rw-r--r--common/hal/aidl_service/libc_wrappers.cc (renamed from common/hal/hidl_service/libc_wrappers.cc)1
-rw-r--r--common/hal/aidl_service/version_script.py (renamed from common/hal/hidl_service/version_script.py)0
-rw-r--r--common/hal/hidl_service/android.hardware.camera.provider@2.7-service-google-lazy.rc13
-rw-r--r--common/hal/hidl_service/android.hardware.camera.provider@2.7-service-google.xml26
-rw-r--r--common/hal/hidl_service/hidl_camera_device.cc283
-rw-r--r--common/hal/hidl_service/hidl_camera_device.h111
-rw-r--r--common/hal/hidl_service/hidl_camera_provider.cc399
-rw-r--r--common/hal/hidl_service/hidl_camera_provider.h113
-rw-r--r--common/hal/hidl_service/hidl_utils.cc1251
-rw-r--r--common/hal/hidl_service/hidl_utils.h216
29 files changed, 2654 insertions, 2955 deletions
diff --git a/common/hal/hidl_service/Android.bp b/common/hal/aidl_service/Android.bp
index 13417cf..df5d70e 100644
--- a/common/hal/hidl_service/Android.bp
+++ b/common/hal/aidl_service/Android.bp
@@ -14,6 +14,10 @@
* limitations under the License.
*/
+//TODO: b/196432585
+//Change the service names to match AIDL instead of HIDL major, minor versioning. Currently
+//left alone to avoid accidentally breaking targets.
+
package {
default_applicable_licenses: ["Android-Apache-2.0"],
}
@@ -54,18 +58,18 @@ python_binary_host {
}
cc_genrule {
- name: "hidl_camera_build_version",
+ name: "aidl_camera_build_version",
tool_files: ["version_script.py"],
cmd: "python3 $(location version_script.py) $(in) $(out)",
vendor: true,
srcs: [
- "hidl_camera_build_version.inl",
+ "aidl_camera_build_version.inl",
],
- out: ["hidl_camera_build_version.h"],
+ out: ["aidl_camera_build_version.h"],
}
cc_defaults {
- name: "camera_service_defaults",
+ name: "camera_service_defaults_common",
defaults: [
"google_camera_hal_defaults",
"apex_update_listener_cc_defaults_static",
@@ -73,36 +77,28 @@ cc_defaults {
vendor: true,
relative_install_path: "hw",
srcs: [
- "hidl_camera_device.cc",
- "hidl_camera_device_session.cc",
- "hidl_camera_provider.cc",
- "hidl_profiler.cc",
+ "aidl_camera_device.cc",
+ "aidl_camera_device_session.cc",
+ "aidl_camera_provider.cc",
+ "aidl_profiler.cc",
"hidl_thermal_utils.cc",
- "hidl_utils.cc",
+ "aidl_utils.cc",
"libc_wrappers.cc",
- "service.cc",
],
generated_headers: [
- "hidl_camera_build_version",
+ "aidl_camera_build_version",
],
compile_multilib: "first",
shared_libs: [
- "android.hardware.camera.device@3.2",
- "android.hardware.camera.device@3.3",
- "android.hardware.camera.device@3.4",
- "android.hardware.camera.device@3.5",
- "android.hardware.camera.device@3.6",
- "android.hardware.camera.device@3.7",
- "android.hardware.camera.device@3.8",
- "android.hardware.camera.provider@2.4",
- "android.hardware.camera.provider@2.5",
- "android.hardware.camera.provider@2.6",
- "android.hardware.camera.provider@2.7",
+ "android.hardware.camera.device-V1-ndk",
+ "android.hardware.camera.common-V1-ndk",
+ "android.hardware.camera.provider-V1-ndk",
"android.hardware.graphics.mapper@2.0",
"android.hardware.graphics.mapper@3.0",
"android.hardware.graphics.mapper@4.0",
"android.hardware.thermal@2.0",
"libbinder",
+ "libbinder_ndk",
"libbase",
"libcamera_metadata",
"libcutils",
@@ -118,7 +114,17 @@ cc_defaults {
"lib_profiler",
],
static_libs: [
- "android.hardware.camera.common@1.0-helper",
+ "libaidlcommonsupport",
+ ],
+}
+
+cc_defaults {
+ name: "camera_service_defaults",
+ defaults: [
+ "camera_service_defaults_common",
+ ],
+ srcs: [
+ "aidl_service.cc",
],
vintf_fragments: [":android.hardware.camera.provider@2.7-service-google.xml"],
}
diff --git a/common/hal/hidl_service/CleanSpec.mk b/common/hal/aidl_service/CleanSpec.mk
index 4c964ca..4c964ca 100644
--- a/common/hal/hidl_service/CleanSpec.mk
+++ b/common/hal/aidl_service/CleanSpec.mk
diff --git a/common/hal/hidl_service/hidl_camera_build_version.inl b/common/hal/aidl_service/aidl_camera_build_version.inl
index 1d104c4..1d104c4 100644
--- a/common/hal/hidl_service/hidl_camera_build_version.inl
+++ b/common/hal/aidl_service/aidl_camera_build_version.inl
diff --git a/common/hal/aidl_service/aidl_camera_device.cc b/common/hal/aidl_service/aidl_camera_device.cc
new file mode 100644
index 0000000..00c80fe
--- /dev/null
+++ b/common/hal/aidl_service/aidl_camera_device.cc
@@ -0,0 +1,270 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "GCH_AidlCameraDevice"
+//#define LOG_NDEBUG 0
+#include "aidl_camera_device.h"
+
+#include <log/log.h>
+
+#include "aidl_camera_device_session.h"
+#include "aidl_profiler.h"
+#include "aidl_utils.h"
+
+namespace android {
+namespace hardware {
+namespace camera {
+namespace device {
+namespace implementation {
+
+namespace aidl_utils = ::android::hardware::camera::implementation::aidl_utils;
+
+using aidl::android::hardware::camera::common::Status;
+using ::android::google_camera_hal::HalCameraMetadata;
+
+const std::string AidlCameraDevice::kDeviceVersion = "1.1";
+
+std::shared_ptr<AidlCameraDevice> AidlCameraDevice::Create(
+ std::unique_ptr<CameraDevice> google_camera_device) {
+ auto device = ndk::SharedRefBase::make<AidlCameraDevice>();
+ if (device == nullptr) {
+ ALOGE("%s: Cannot create a AidlCameraDevice.", __FUNCTION__);
+ return nullptr;
+ }
+
+ status_t res = device->Initialize(std::move(google_camera_device));
+ if (res != OK) {
+ ALOGE("%s: Initializing AidlCameraDevice failed: %s(%d)", __FUNCTION__,
+ strerror(-res), res);
+ return nullptr;
+ }
+
+ return device;
+}
+
+status_t AidlCameraDevice::Initialize(
+ std::unique_ptr<CameraDevice> google_camera_device) {
+ if (google_camera_device == nullptr) {
+ ALOGE("%s: google_camera_device is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ camera_id_ = google_camera_device->GetPublicCameraId();
+ google_camera_device_ = std::move(google_camera_device);
+ aidl_profiler_ = AidlProfiler::Create(camera_id_);
+ if (aidl_profiler_ == nullptr) {
+ ALOGE("%s: Failed to create AidlProfiler.", __FUNCTION__);
+ return UNKNOWN_ERROR;
+ }
+ return OK;
+}
+
+ScopedAStatus AidlCameraDevice::getResourceCost(
+ CameraResourceCost* resource_cost) {
+ google_camera_hal::CameraResourceCost hal_cost;
+ if (resource_cost == nullptr) {
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
+ }
+ status_t res = google_camera_device_->GetResourceCost(&hal_cost);
+ if (res != OK) {
+ ALOGE("%s: Getting resource cost failed for camera %u: %s(%d)",
+ __FUNCTION__, camera_id_, strerror(-res), res);
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
+ }
+
+ res = aidl_utils::ConvertToAidlResourceCost(hal_cost, resource_cost);
+ if (res != OK) {
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
+ }
+
+ return ScopedAStatus::ok();
+}
+
+ScopedAStatus AidlCameraDevice::getCameraCharacteristics(
+ CameraMetadata* characteristics_ret) {
+ if (characteristics_ret == nullptr) {
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
+ }
+ characteristics_ret->metadata.clear();
+ std::unique_ptr<HalCameraMetadata> characteristics;
+ status_t res =
+ google_camera_device_->GetCameraCharacteristics(&characteristics);
+ if (res != OK) {
+ ALOGE("%s: Getting camera characteristics for camera %u failed: %s(%d)",
+ __FUNCTION__, camera_id_, strerror(-res), res);
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
+ }
+
+ if (characteristics == nullptr) {
+ ALOGE("%s: Camera characteristics for camera %u is nullptr.", __FUNCTION__,
+ camera_id_);
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
+ }
+
+ uint32_t metadata_size = characteristics->GetCameraMetadataSize();
+ uint8_t* chars_p = (uint8_t*)characteristics->GetRawCameraMetadata();
+ characteristics_ret->metadata.assign(chars_p, chars_p + metadata_size);
+
+ return ScopedAStatus::ok();
+}
+
+ScopedAStatus AidlCameraDevice::setTorchMode(bool on) {
+ google_camera_hal::TorchMode hal_torch_mode;
+ hal_torch_mode = on ? google_camera_hal::TorchMode::kOn
+ : google_camera_hal::TorchMode::kOff;
+ auto res = google_camera_device_->SetTorchMode(hal_torch_mode);
+ return aidl_utils::ConvertToAidlReturn(res);
+}
+
+ScopedAStatus AidlCameraDevice::turnOnTorchWithStrengthLevel(
+ int32_t torch_strength) {
+ status_t res =
+ google_camera_device_->TurnOnTorchWithStrengthLevel(torch_strength);
+ return aidl_utils::ConvertToAidlReturn(res);
+}
+
+ScopedAStatus AidlCameraDevice::getTorchStrengthLevel(int32_t* strength_level) {
+ if (strength_level == nullptr) {
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
+ }
+ *strength_level = 0;
+ int32_t torch_strength;
+ status_t res = google_camera_device_->GetTorchStrengthLevel(torch_strength);
+ if (res != OK) {
+ ALOGE(
+ "%s: Getting camera flash unit torch strength level for camera %u "
+ "failed: %s(%d)",
+ __FUNCTION__, camera_id_, strerror(-res), res);
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
+ }
+ *strength_level = torch_strength;
+ return ScopedAStatus::ok();
+}
+
+ScopedAStatus AidlCameraDevice::getPhysicalCameraCharacteristics(
+ const std::string& physicalCameraId, CameraMetadata* characteristics_ret) {
+ if (characteristics_ret == nullptr) {
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
+ }
+ characteristics_ret->metadata.clear();
+ std::unique_ptr<HalCameraMetadata> physical_characteristics;
+ uint32_t physical_camera_id = atoi(physicalCameraId.c_str());
+ status_t res = google_camera_device_->GetPhysicalCameraCharacteristics(
+ physical_camera_id, &physical_characteristics);
+ if (res != OK) {
+ ALOGE("%s: Getting physical characteristics for camera %u failed: %s(%d)",
+ __FUNCTION__, camera_id_, strerror(-res), res);
+ return aidl_utils::ConvertToAidlReturn(res);
+ }
+
+ if (physical_characteristics == nullptr) {
+ ALOGE("%s: Physical characteristics for camera %u is nullptr.",
+ __FUNCTION__, physical_camera_id);
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
+ }
+
+ uint32_t metadata_size = physical_characteristics->GetCameraMetadataSize();
+ uint8_t* physical_characteristics_p =
+ (uint8_t*)physical_characteristics->GetRawCameraMetadata();
+ characteristics_ret->metadata.assign(
+ physical_characteristics_p, physical_characteristics_p + metadata_size);
+ return ScopedAStatus::ok();
+}
+
+ScopedAStatus AidlCameraDevice::open(
+ const std::shared_ptr<ICameraDeviceCallback>& callback,
+ std::shared_ptr<ICameraDeviceSession>* session_ret) {
+ if (session_ret == nullptr) {
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
+ }
+ *session_ret = nullptr;
+ auto profiler = aidl_profiler_->MakeScopedProfiler(
+ AidlProfiler::ScopedType::kOpen,
+ google_camera_device_->GetProfiler(camera_id_,
+ aidl_profiler_->GetLatencyFlag()),
+ google_camera_device_->GetProfiler(camera_id_,
+ aidl_profiler_->GetFpsFlag()));
+
+ std::unique_ptr<google_camera_hal::CameraDeviceSession> session;
+ status_t res = google_camera_device_->CreateCameraDeviceSession(&session);
+ if (res != OK || session == nullptr) {
+ ALOGE("%s: Creating CameraDeviceSession failed: %s(%d)", __FUNCTION__,
+ strerror(-res), res);
+ return aidl_utils::ConvertToAidlReturn(res);
+ }
+
+ auto aidl_session = AidlCameraDeviceSession::Create(
+ callback, std::move(session), aidl_profiler_);
+ if (aidl_session == nullptr) {
+ ALOGE("%s: Creating AidlCameraDeviceSession failed.", __FUNCTION__);
+ return aidl_utils::ConvertToAidlReturn(res);
+ }
+ *session_ret = aidl_session;
+ return ScopedAStatus::ok();
+}
+
+ScopedAStatus AidlCameraDevice::openInjectionSession(
+ const std::shared_ptr<ICameraDeviceCallback>&,
+ std::shared_ptr<ICameraInjectionSession>* session) {
+ if (session == nullptr) {
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
+ }
+ *session = nullptr;
+ return ScopedAStatus::ok();
+}
+
+ScopedAStatus AidlCameraDevice::dumpState(const ::ndk::ScopedFileDescriptor& fd) {
+ int raw_fd = fd.get();
+ google_camera_device_->DumpState(raw_fd);
+ return ScopedAStatus::ok();
+}
+
+ScopedAStatus AidlCameraDevice::isStreamCombinationSupported(
+ const StreamConfiguration& streams, bool* supported) {
+ if (supported == nullptr) {
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
+ }
+ *supported = false;
+ google_camera_hal::StreamConfiguration stream_config;
+ status_t res = aidl_utils::ConvertToHalStreamConfig(streams, &stream_config);
+ if (res != OK) {
+ ALOGE("%s: ConverToHalStreamConfig fail", __FUNCTION__);
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
+ }
+ *supported =
+ google_camera_device_->IsStreamCombinationSupported(stream_config);
+ return ScopedAStatus::ok();
+}
+
+} // namespace implementation
+} // namespace device
+} // namespace camera
+} // namespace hardware
+} // namespace android
diff --git a/common/hal/aidl_service/aidl_camera_device.h b/common/hal/aidl_service/aidl_camera_device.h
new file mode 100644
index 0000000..4ee5c4e
--- /dev/null
+++ b/common/hal/aidl_service/aidl_camera_device.h
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_CAMERA_DEVICE_H_
+#define HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_CAMERA_DEVICE_H_
+
+#include <aidl/android/hardware/camera/device/BnCameraDevice.h>
+#include <aidl/android/hardware/camera/device/ICameraDeviceCallback.h>
+
+#include "aidl_profiler.h"
+#include "camera_device.h"
+
+namespace android {
+namespace hardware {
+namespace camera {
+namespace device {
+namespace implementation {
+
+using aidl::android::hardware::camera::common::CameraResourceCost;
+using aidl::android::hardware::camera::device::BnCameraDevice;
+using aidl::android::hardware::camera::device::CameraMetadata;
+using aidl::android::hardware::camera::device::ICameraDevice;
+using aidl::android::hardware::camera::device::ICameraDeviceCallback;
+using aidl::android::hardware::camera::device::ICameraDeviceSession;
+using aidl::android::hardware::camera::device::ICameraInjectionSession;
+using aidl::android::hardware::camera::device::StreamConfiguration;
+using ::android::hardware::camera::implementation::AidlProfiler;
+using ndk::ScopedAStatus;
+using ndk::ScopedFileDescriptor;
+
+using ::android::google_camera_hal::CameraDevice;
+
+// AidlCameraDevice implements the AIDL camera device interface, ICameraDevice,
+// using Google Camera HAL to provide information about the associated camera
+// device.
+class AidlCameraDevice : public BnCameraDevice {
+ public:
+ static const std::string kDeviceVersion;
+
+ // Create a AidlCameraDevice.
+ // google_camera_device is a google camera device that AidlCameraDevice
+ // is going to manage. Creating a AidlCameraDevice will fail if
+ // google_camera_device is nullptr.
+ static std::shared_ptr<AidlCameraDevice> Create(
+ std::unique_ptr<CameraDevice> google_camera_device);
+ virtual ~AidlCameraDevice() = default;
+
+ // Override functions in ICameraDevice
+
+ virtual ScopedAStatus dumpState(const ScopedFileDescriptor& in_fd) override;
+
+ virtual ScopedAStatus getCameraCharacteristics(
+ CameraMetadata* characteristics) override;
+
+ virtual ScopedAStatus getPhysicalCameraCharacteristics(
+ const std::string& in_physicalCameraId,
+ CameraMetadata* characteristics) override;
+
+ virtual ScopedAStatus getResourceCost(
+ CameraResourceCost* resource_cost) override;
+
+ virtual ScopedAStatus isStreamCombinationSupported(
+ const StreamConfiguration& in_streams, bool* supported) override;
+
+ virtual ScopedAStatus open(
+ const std::shared_ptr<ICameraDeviceCallback>& in_callback,
+ std::shared_ptr<ICameraDeviceSession>* session) override;
+
+ virtual ScopedAStatus openInjectionSession(
+ const std::shared_ptr<ICameraDeviceCallback>& in_callback,
+ std::shared_ptr<ICameraInjectionSession>* session) override;
+
+ virtual ScopedAStatus setTorchMode(bool on) override;
+
+ virtual ScopedAStatus turnOnTorchWithStrengthLevel(
+ int32_t torchStrength) override;
+
+ virtual ScopedAStatus getTorchStrengthLevel(int32_t* strength_level) override;
+
+ // End of override functions in ICameraDevice
+ AidlCameraDevice() = default;
+
+ private:
+ status_t Initialize(std::unique_ptr<CameraDevice> google_camera_device);
+
+ std::unique_ptr<CameraDevice> google_camera_device_;
+ uint32_t camera_id_ = 0;
+ std::shared_ptr<AidlProfiler> aidl_profiler_;
+};
+
+} // namespace implementation
+} // namespace device
+} // namespace camera
+} // namespace hardware
+} // namespace android
+
+#endif // HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_CAMERA_DEVICE_H_
diff --git a/common/hal/hidl_service/hidl_camera_device_session.cc b/common/hal/aidl_service/aidl_camera_device_session.cc
index a1e7e26..70ffc06 100644
--- a/common/hal/hidl_service/hidl_camera_device_session.cc
+++ b/common/hal/aidl_service/aidl_camera_device_session.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-#define LOG_TAG "GCH_HidlCameraDeviceSession"
+#define LOG_TAG "GCH_AidlCameraDeviceSession"
#define ATRACE_TAG ATRACE_TAG_CAMERA
//#define LOG_NDEBUG 0
-#include "hidl_camera_device_session.h"
+#include "aidl_camera_device_session.h"
#include <cutils/properties.h>
#include <cutils/trace.h>
@@ -25,47 +25,46 @@
#include <malloc.h>
#include <utils/Trace.h>
-#include "hidl_profiler.h"
-#include "hidl_utils.h"
-
+#include "aidl_profiler.h"
+#include "aidl_utils.h"
namespace android {
namespace hardware {
namespace camera {
namespace device {
-namespace V3_8 {
namespace implementation {
-namespace hidl_utils = ::android::hardware::camera::implementation::hidl_utils;
-
-using ::android::hardware::camera::device::V3_2::StreamBuffer;
-using ::android::hardware::camera::device::V3_4::CaptureResult;
-using ::android::hardware::camera::device::V3_5::BufferRequest;
-using ::android::hardware::camera::device::V3_5::BufferRequestStatus;
-using ::android::hardware::camera::device::V3_5::StreamBufferRet;
-using ::android::hardware::camera::device::V3_5::StreamBuffersVal;
-using ::android::hardware::camera::device::V3_6::HalStreamConfiguration;
-using ::android::hardware::camera::device::V3_8::NotifyMsg;
+namespace aidl_utils = ::android::hardware::camera::implementation::aidl_utils;
+
+using aidl::android::hardware::camera::common::Status;
+using aidl::android::hardware::camera::device::BufferRequest;
+using aidl::android::hardware::camera::device::BufferRequestStatus;
+using aidl::android::hardware::camera::device::CaptureResult;
+using aidl::android::hardware::camera::device::HalStream;
+using aidl::android::hardware::camera::device::NotifyMsg;
+using aidl::android::hardware::camera::device::StreamBuffer;
+using aidl::android::hardware::camera::device::StreamBufferRet;
+using aidl::android::hardware::camera::device::StreamBuffersVal;
+using aidl_utils::ConvertToAidlReturn;
using ::android::hardware::thermal::V1_0::ThermalStatus;
using ::android::hardware::thermal::V1_0::ThermalStatusCode;
using ::android::hardware::thermal::V2_0::Temperature;
using ::android::hardware::thermal::V2_0::TemperatureType;
-std::unique_ptr<HidlCameraDeviceSession> HidlCameraDeviceSession::Create(
- const sp<V3_2::ICameraDeviceCallback>& callback,
+std::shared_ptr<AidlCameraDeviceSession> AidlCameraDeviceSession::Create(
+ const std::shared_ptr<ICameraDeviceCallback>& callback,
std::unique_ptr<google_camera_hal::CameraDeviceSession> device_session,
- std::shared_ptr<HidlProfiler> hidl_profiler) {
- ATRACE_NAME("HidlCameraDeviceSession::Create");
- auto session =
- std::unique_ptr<HidlCameraDeviceSession>(new HidlCameraDeviceSession());
+ std::shared_ptr<AidlProfiler> aidl_profiler) {
+ ATRACE_NAME("AidlCameraDeviceSession::Create");
+ auto session = ndk::SharedRefBase::make<AidlCameraDeviceSession>();
if (session == nullptr) {
- ALOGE("%s: Cannot create a HidlCameraDeviceSession.", __FUNCTION__);
+ ALOGE("%s: Cannot create a AidlCameraDeviceSession.", __FUNCTION__);
return nullptr;
}
status_t res =
- session->Initialize(callback, std::move(device_session), hidl_profiler);
+ session->Initialize(callback, std::move(device_session), aidl_profiler);
if (res != OK) {
- ALOGE("%s: Initializing HidlCameraDeviceSession failed: %s(%d)",
+ ALOGE("%s: Initializing AidlCameraDeviceSession failed: %s(%d)",
__FUNCTION__, strerror(-res), res);
return nullptr;
}
@@ -73,18 +72,18 @@ std::unique_ptr<HidlCameraDeviceSession> HidlCameraDeviceSession::Create(
return session;
}
-HidlCameraDeviceSession::~HidlCameraDeviceSession() {
- ATRACE_NAME("HidlCameraDeviceSession::~HidlCameraDeviceSession");
+AidlCameraDeviceSession::~AidlCameraDeviceSession() {
+ ATRACE_NAME("AidlCameraDeviceSession::~AidlCameraDeviceSession");
close();
// camera's closing, so flush any unused malloc pages
mallopt(M_PURGE, 0);
}
-void HidlCameraDeviceSession::ProcessCaptureResult(
+void AidlCameraDeviceSession::ProcessCaptureResult(
std::unique_ptr<google_camera_hal::CaptureResult> hal_result) {
- std::shared_lock lock(hidl_device_callback_lock_);
- if (hidl_device_callback_ == nullptr) {
- ALOGE("%s: hidl_device_callback_ is nullptr", __FUNCTION__);
+ std::shared_lock lock(aidl_device_callback_lock_);
+ if (aidl_device_callback_ == nullptr) {
+ ALOGE("%s: aidl_device_callback_ is nullptr", __FUNCTION__);
return;
}
@@ -96,66 +95,72 @@ void HidlCameraDeviceSession::ProcessCaptureResult(
num_pending_first_frame_buffers_ -= hal_result->output_buffers.size();
if (num_pending_first_frame_buffers_ == 0) {
ALOGI("%s: First frame done", __FUNCTION__);
- hidl_profiler_->FirstFrameEnd();
+ aidl_profiler_->FirstFrameEnd();
ATRACE_ASYNC_END("first_frame", 0);
ATRACE_ASYNC_END("switch_mode", 0);
}
}
}
for (auto& buffer : hal_result->output_buffers) {
- hidl_profiler_->ProfileFrameRate("Stream " +
+ aidl_profiler_->ProfileFrameRate("Stream " +
std::to_string(buffer.stream_id));
}
- hidl_vec<CaptureResult> hidl_results(1);
- status_t res = hidl_utils::ConvertToHidlCaptureResult(
- result_metadata_queue_.get(), std::move(hal_result), &hidl_results[0]);
+ std::vector<CaptureResult> aidl_results(1);
+ status_t res = aidl_utils::ConvertToAidlCaptureResult(
+ result_metadata_queue_.get(), std::move(hal_result), &aidl_results[0]);
if (res != OK) {
- ALOGE("%s: Converting to HIDL result failed: %s(%d)", __FUNCTION__,
+ ALOGE("%s: Converting to AIDL result failed: %s(%d)", __FUNCTION__,
strerror(-res), res);
return;
}
- auto hidl_res = hidl_device_callback_->processCaptureResult_3_4(hidl_results);
- if (!hidl_res.isOk()) {
+ auto aidl_res = aidl_device_callback_->processCaptureResult(aidl_results);
+ if (!aidl_res.isOk()) {
ALOGE("%s: processCaptureResult transaction failed: %s.", __FUNCTION__,
- hidl_res.description().c_str());
+ aidl_res.getMessage());
return;
}
}
-void HidlCameraDeviceSession::NotifyHalMessage(
+void AidlCameraDeviceSession::NotifyHalMessage(
const google_camera_hal::NotifyMessage& hal_message) {
- std::shared_lock lock(hidl_device_callback_lock_);
- if (hidl_device_callback_ == nullptr) {
- ALOGE("%s: hidl_device_callback_ is nullptr", __FUNCTION__);
+ std::shared_lock lock(aidl_device_callback_lock_);
+ if (aidl_device_callback_ == nullptr) {
+ ALOGE("%s: aidl_device_callback_ is nullptr", __FUNCTION__);
return;
}
- hidl_vec<NotifyMsg> hidl_messages(1);
+ std::vector<NotifyMsg> aidl_messages(1);
status_t res =
- hidl_utils::ConverToHidlNotifyMessage(hal_message, &hidl_messages[0]);
+ aidl_utils::ConverToAidlNotifyMessage(hal_message, &aidl_messages[0]);
if (res != OK) {
- ALOGE("%s: Converting to HIDL message failed: %s(%d)", __FUNCTION__,
+ ALOGE("%s: Converting to AIDL message failed: %s(%d)", __FUNCTION__,
strerror(-res), res);
return;
}
- auto hidl_res = hidl_device_callback_->notify_3_8(hidl_messages);
- if (!hidl_res.isOk()) {
+ auto aidl_res = aidl_device_callback_->notify(aidl_messages);
+ if (!aidl_res.isOk()) {
ALOGE("%s: notify transaction failed: %s.", __FUNCTION__,
- hidl_res.description().c_str());
+ aidl_res.getMessage());
return;
}
}
+static void cleanupHandles(std::vector<native_handle_t*>& handles_to_delete) {
+ for (auto& handle : handles_to_delete) {
+ native_handle_delete(handle);
+ }
+}
+
google_camera_hal::BufferRequestStatus
-HidlCameraDeviceSession::RequestStreamBuffers(
+AidlCameraDeviceSession::RequestStreamBuffers(
const std::vector<google_camera_hal::BufferRequest>& hal_buffer_requests,
std::vector<google_camera_hal::BufferReturn>* hal_buffer_returns) {
- std::shared_lock lock(hidl_device_callback_lock_);
- if (hidl_device_callback_ == nullptr) {
- ALOGE("%s: hidl_device_callback_ is nullptr", __FUNCTION__);
+ std::shared_lock lock(aidl_device_callback_lock_);
+ if (aidl_device_callback_ == nullptr) {
+ ALOGE("%s: aidl_device_callback_ is nullptr", __FUNCTION__);
return google_camera_hal::BufferRequestStatus::kFailedUnknown;
}
@@ -164,32 +169,28 @@ HidlCameraDeviceSession::RequestStreamBuffers(
return google_camera_hal::BufferRequestStatus::kFailedUnknown;
}
- hidl_vec<BufferRequest> hidl_buffer_requests;
- status_t res = hidl_utils::ConvertToHidlBufferRequest(hal_buffer_requests,
- &hidl_buffer_requests);
+ std::vector<BufferRequest> aidl_buffer_requests;
+ status_t res = aidl_utils::ConvertToAidlBufferRequest(hal_buffer_requests,
+ &aidl_buffer_requests);
if (res != OK) {
- ALOGE("%s: Converting to Hidl buffer request failed: %s(%d)", __FUNCTION__,
+ ALOGE("%s: Converting to Aidl buffer request failed: %s(%d)", __FUNCTION__,
strerror(-res), res);
return google_camera_hal::BufferRequestStatus::kFailedUnknown;
}
- BufferRequestStatus hidl_status;
- hidl_vec<StreamBufferRet> stream_buffer_returns;
- auto cb_status = hidl_device_callback_->requestStreamBuffers(
- hidl_buffer_requests, [&hidl_status, &stream_buffer_returns](
- BufferRequestStatus status_ret,
- const hidl_vec<StreamBufferRet>& buffer_ret) {
- hidl_status = status_ret;
- stream_buffer_returns = std::move(buffer_ret);
- });
+ BufferRequestStatus aidl_status;
+ std::vector<StreamBufferRet> stream_buffer_returns;
+ auto cb_status = aidl_device_callback_->requestStreamBuffers(
+ aidl_buffer_requests, &stream_buffer_returns, &aidl_status);
+
if (!cb_status.isOk()) {
ALOGE("%s: Transaction request stream buffers error: %s", __FUNCTION__,
- cb_status.description().c_str());
+ cb_status.getMessage());
return google_camera_hal::BufferRequestStatus::kFailedUnknown;
}
google_camera_hal::BufferRequestStatus hal_buffer_request_status;
- res = hidl_utils::ConvertToHalBufferRequestStatus(hidl_status,
+ res = aidl_utils::ConvertToHalBufferRequestStatus(aidl_status,
&hal_buffer_request_status);
if (res != OK) {
ALOGE("%s: Converting to Hal buffer request status failed: %s(%d)",
@@ -198,10 +199,10 @@ HidlCameraDeviceSession::RequestStreamBuffers(
}
hal_buffer_returns->clear();
- // Converting HIDL stream buffer returns to HAL stream buffer returns.
+ // Converting AIDL stream buffer returns to HAL stream buffer returns.
for (auto& stream_buffer_return : stream_buffer_returns) {
google_camera_hal::BufferReturn hal_buffer_return;
- res = hidl_utils::ConvertToHalBufferReturnStatus(stream_buffer_return,
+ res = aidl_utils::ConvertToHalBufferReturnStatus(stream_buffer_return,
&hal_buffer_return);
if (res != OK) {
ALOGE("%s: Converting to Hal buffer return status failed: %s(%d)",
@@ -209,22 +210,23 @@ HidlCameraDeviceSession::RequestStreamBuffers(
return google_camera_hal::BufferRequestStatus::kFailedUnknown;
}
- if (stream_buffer_return.val.getDiscriminator() ==
- V3_5::StreamBuffersVal::hidl_discriminator::buffers) {
- const hidl_vec<StreamBuffer>& hidl_buffers =
- stream_buffer_return.val.buffers();
- for (auto& hidl_buffer : hidl_buffers) {
+ using Tag = aidl::android::hardware::camera::device::StreamBuffersVal::Tag;
+ if (stream_buffer_return.val.getTag() == Tag::buffers) {
+ const std::vector<StreamBuffer>& aidl_buffers =
+ stream_buffer_return.val.get<Tag::buffers>();
+ std::vector<native_handle_t*> native_handles_to_delete;
+ for (auto& aidl_buffer : aidl_buffers) {
google_camera_hal::StreamBuffer hal_buffer = {};
- hidl_utils::ConvertToHalStreamBuffer(hidl_buffer, &hal_buffer);
+ aidl_utils::ConvertToHalStreamBuffer(aidl_buffer, &hal_buffer,
+ &native_handles_to_delete);
if (res != OK) {
ALOGE("%s: Converting to Hal stream buffer failed: %s(%d)",
__FUNCTION__, strerror(-res), res);
return google_camera_hal::BufferRequestStatus::kFailedUnknown;
}
- if (hidl_buffer.acquireFence.getNativeHandle() != nullptr) {
- hal_buffer.acquire_fence =
- native_handle_clone(hidl_buffer.acquireFence.getNativeHandle());
+ if (!aidl_utils::IsAidlNativeHandleNull(aidl_buffer.acquireFence)) {
+ hal_buffer.acquire_fence = dupFromAidl(aidl_buffer.acquireFence);
if (hal_buffer.acquire_fence == nullptr) {
ALOGE("%s: Cloning Hal stream buffer acquire fence failed",
__FUNCTION__);
@@ -234,27 +236,32 @@ HidlCameraDeviceSession::RequestStreamBuffers(
hal_buffer.release_fence = nullptr;
// If buffer handle is not null, we need to import buffer handle and
// return to the caller.
- if (hidl_buffer.buffer.getNativeHandle() != nullptr) {
+ if (!aidl_utils::IsAidlNativeHandleNull(aidl_buffer.buffer)) {
+ native_handle_t* aidl_buffer_native_handle =
+ makeFromAidl(aidl_buffer.buffer);
if (buffer_mapper_v4_ != nullptr) {
hal_buffer.buffer = ImportBufferHandle<
android::hardware::graphics::mapper::V4_0::IMapper,
android::hardware::graphics::mapper::V4_0::Error>(
- buffer_mapper_v4_, hidl_buffer.buffer);
+ buffer_mapper_v4_, aidl_buffer_native_handle);
} else if (buffer_mapper_v3_ != nullptr) {
hal_buffer.buffer = ImportBufferHandle<
android::hardware::graphics::mapper::V3_0::IMapper,
android::hardware::graphics::mapper::V3_0::Error>(
- buffer_mapper_v3_, hidl_buffer.buffer);
+ buffer_mapper_v3_, aidl_buffer_native_handle);
} else {
hal_buffer.buffer = ImportBufferHandle<
android::hardware::graphics::mapper::V2_0::IMapper,
android::hardware::graphics::mapper::V2_0::Error>(
- buffer_mapper_v2_, hidl_buffer.buffer);
+ buffer_mapper_v2_, aidl_buffer_native_handle);
}
+ native_handle_delete(aidl_buffer_native_handle);
}
hal_buffer_return.val.buffers.push_back(hal_buffer);
}
+
+ cleanupHandles(native_handles_to_delete);
}
hal_buffer_returns->push_back(hal_buffer_return);
@@ -264,7 +271,7 @@ HidlCameraDeviceSession::RequestStreamBuffers(
}
template <class T, class U>
-buffer_handle_t HidlCameraDeviceSession::ImportBufferHandle(
+buffer_handle_t AidlCameraDeviceSession::ImportBufferHandle(
const sp<T> buffer_mapper_, const hidl_handle& buffer_hidl_handle) {
U mapper_error;
buffer_handle_t imported_buffer_handle;
@@ -283,31 +290,31 @@ buffer_handle_t HidlCameraDeviceSession::ImportBufferHandle(
return imported_buffer_handle;
}
-void HidlCameraDeviceSession::ReturnStreamBuffers(
+void AidlCameraDeviceSession::ReturnStreamBuffers(
const std::vector<google_camera_hal::StreamBuffer>& return_hal_buffers) {
- std::shared_lock lock(hidl_device_callback_lock_);
- if (hidl_device_callback_ == nullptr) {
- ALOGE("%s: hidl_device_callback_ is nullptr", __FUNCTION__);
+ std::shared_lock lock(aidl_device_callback_lock_);
+ if (aidl_device_callback_ == nullptr) {
+ ALOGE("%s: aidl_device_callback_ is nullptr", __FUNCTION__);
return;
}
status_t res = OK;
- hidl_vec<StreamBuffer> hidl_return_buffers;
- hidl_return_buffers.resize(return_hal_buffers.size());
+ std::vector<StreamBuffer> aidl_return_buffers;
+ aidl_return_buffers.resize(return_hal_buffers.size());
for (uint32_t i = 0; i < return_hal_buffers.size(); i++) {
- res = hidl_utils::ConvertToHidlStreamBuffer(return_hal_buffers[i],
- &hidl_return_buffers[i]);
+ res = aidl_utils::ConvertToAidlStreamBuffer(return_hal_buffers[i],
+ &aidl_return_buffers[i]);
if (res != OK) {
- ALOGE("%s: Converting to Hidl stream buffer failed: %s(%d)", __FUNCTION__,
+ ALOGE("%s: Converting to Aidl stream buffer failed: %s(%d)", __FUNCTION__,
strerror(-res), res);
return;
}
}
- hidl_device_callback_->returnStreamBuffers(hidl_return_buffers);
+ aidl_device_callback_->returnStreamBuffers(aidl_return_buffers);
}
-status_t HidlCameraDeviceSession::InitializeBufferMapper() {
+status_t AidlCameraDeviceSession::InitializeBufferMapper() {
buffer_mapper_v4_ =
android::hardware::graphics::mapper::V4_0::IMapper::getService();
if (buffer_mapper_v4_ != nullptr) {
@@ -330,18 +337,18 @@ status_t HidlCameraDeviceSession::InitializeBufferMapper() {
return UNKNOWN_ERROR;
}
-status_t HidlCameraDeviceSession::Initialize(
- const sp<V3_2::ICameraDeviceCallback>& callback,
+status_t AidlCameraDeviceSession::Initialize(
+ const std::shared_ptr<ICameraDeviceCallback>& callback,
std::unique_ptr<google_camera_hal::CameraDeviceSession> device_session,
- std::shared_ptr<HidlProfiler> hidl_profiler) {
- ATRACE_NAME("HidlCameraDeviceSession::Initialize");
+ std::shared_ptr<AidlProfiler> aidl_profiler) {
+ ATRACE_NAME("AidlCameraDeviceSession::Initialize");
if (device_session == nullptr) {
ALOGE("%s: device_session is nullptr.", __FUNCTION__);
return BAD_VALUE;
}
- if (hidl_profiler == nullptr) {
- ALOGE("%s: hidl_profiler is nullptr.", __FUNCTION__);
+ if (aidl_profiler == nullptr) {
+ ALOGE("%s: aidl_profiler is nullptr.", __FUNCTION__);
return BAD_VALUE;
}
@@ -363,13 +370,6 @@ status_t HidlCameraDeviceSession::Initialize(
return res;
}
- // Cast V3.2 callback to V3.8
- auto cast_res = ICameraDeviceCallback::castFrom(callback);
- if (!cast_res.isOk()) {
- ALOGE("%s: Cannot convert to V3.8 device callback.", __FUNCTION__);
- return UNKNOWN_ERROR;
- }
-
// Initialize buffer mapper
res = InitializeBufferMapper();
if (res != OK) {
@@ -384,15 +384,15 @@ status_t HidlCameraDeviceSession::Initialize(
// Continue without getting thermal information.
}
- hidl_device_callback_ = cast_res;
+ aidl_device_callback_ = callback;
device_session_ = std::move(device_session);
- hidl_profiler_ = hidl_profiler;
+ aidl_profiler_ = aidl_profiler;
SetSessionCallbacks();
return OK;
}
-void HidlCameraDeviceSession::SetSessionCallbacks() {
+void AidlCameraDeviceSession::SetSessionCallbacks() {
google_camera_hal::CameraDeviceSessionCallback session_callback = {
.process_capture_result = google_camera_hal::ProcessCaptureResultFunc(
[this](std::unique_ptr<google_camera_hal::CaptureResult> result) {
@@ -432,7 +432,7 @@ void HidlCameraDeviceSession::SetSessionCallbacks() {
device_session_->SetSessionCallback(session_callback, thermal_callback);
}
-status_t HidlCameraDeviceSession::RegisterThermalChangedCallback(
+status_t AidlCameraDeviceSession::RegisterThermalChangedCallback(
google_camera_hal::NotifyThrottlingFunc notify_throttling, bool filter_type,
google_camera_hal::TemperatureType type) {
std::lock_guard<std::mutex> lock(hidl_thermal_mutex_);
@@ -470,7 +470,7 @@ status_t HidlCameraDeviceSession::RegisterThermalChangedCallback(
return OK;
}
-void HidlCameraDeviceSession::UnregisterThermalChangedCallback() {
+void AidlCameraDeviceSession::UnregisterThermalChangedCallback() {
std::lock_guard<std::mutex> lock(hidl_thermal_mutex_);
if (thermal_changed_callback_ == nullptr) {
// no-op if no thermal changed callback is registered.
@@ -494,7 +494,7 @@ void HidlCameraDeviceSession::UnregisterThermalChangedCallback() {
thermal_changed_callback_ = nullptr;
}
-status_t HidlCameraDeviceSession::CreateMetadataQueue(
+status_t AidlCameraDeviceSession::CreateMetadataQueue(
std::unique_ptr<MetadataQueue>* metadata_queue, uint32_t default_size_bytes,
const char* override_size_property) {
if (metadata_queue == nullptr) {
@@ -510,8 +510,9 @@ status_t HidlCameraDeviceSession::CreateMetadataQueue(
size);
}
- *metadata_queue = std::make_unique<MetadataQueue>(
- static_cast<size_t>(size), /*configureEventFlagWord=*/false);
+ *metadata_queue =
+ std::make_unique<MetadataQueue>(static_cast<size_t>(size),
+ /*configureEventFlagWord*/ false);
if (!(*metadata_queue)->isValid()) {
ALOGE("%s: Creating metadata queue (size %d) failed.", __FUNCTION__, size);
return NO_INIT;
@@ -520,65 +521,68 @@ status_t HidlCameraDeviceSession::CreateMetadataQueue(
return OK;
}
-Return<void> HidlCameraDeviceSession::constructDefaultRequestSettings(
- RequestTemplate type,
- ICameraDeviceSession::constructDefaultRequestSettings_cb _hidl_cb) {
- ATRACE_NAME("HidlCameraDeviceSession::constructDefaultRequestSettings");
- V3_2::CameraMetadata hidl_metadata;
-
+ScopedAStatus AidlCameraDeviceSession::constructDefaultRequestSettings(
+ RequestTemplate type, CameraMetadata* aidl_return) {
+ ATRACE_NAME("AidlCameraDeviceSession::constructDefaultRequestSettings");
+ if (aidl_return == nullptr) {
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
+ }
+ aidl_return->metadata.clear();
if (device_session_ == nullptr) {
- _hidl_cb(Status::INTERNAL_ERROR, hidl_metadata);
- return Void();
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
}
google_camera_hal::RequestTemplate hal_type;
- status_t res = hidl_utils::ConvertToHalTemplateType(type, &hal_type);
+ status_t res = aidl_utils::ConvertToHalTemplateType(type, &hal_type);
if (res != OK) {
- _hidl_cb(Status::ILLEGAL_ARGUMENT, hidl_metadata);
- return Void();
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
}
std::unique_ptr<google_camera_hal::HalCameraMetadata> settings = nullptr;
res = device_session_->ConstructDefaultRequestSettings(hal_type, &settings);
if (res != OK) {
- _hidl_cb(hidl_utils::ConvertToHidlStatus(res), hidl_metadata);
- return Void();
+ return aidl_utils::ConvertToAidlReturn(res);
}
uint32_t metadata_size = settings->GetCameraMetadataSize();
- hidl_metadata.setToExternal((uint8_t*)settings->ReleaseCameraMetadata(),
- metadata_size, /*shouldOwn=*/true);
- _hidl_cb(Status::OK, hidl_metadata);
-
- return Void();
+ uint8_t* settings_p = (uint8_t*)settings->ReleaseCameraMetadata();
+ aidl_return->metadata.assign(settings_p, settings_p + metadata_size);
+ return ScopedAStatus::ok();
}
-Return<void> HidlCameraDeviceSession::configureStreams_3_8(
- const V3_8::StreamConfiguration& requestedConfiguration,
- ICameraDeviceSession::configureStreams_3_6_cb _hidl_cb) {
- ATRACE_NAME("HidlCameraDeviceSession::configureStreams_3_8");
- HalStreamConfiguration hidl_hal_configs;
+ScopedAStatus AidlCameraDeviceSession::configureStreams(
+ const StreamConfiguration& requestedConfiguration,
+ std::vector<HalStream>* aidl_return) {
+ ATRACE_NAME("AidlCameraDeviceSession::configureStreams");
+ if (aidl_return == nullptr) {
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
+ }
+ aidl_return->clear();
if (device_session_ == nullptr) {
- _hidl_cb(Status::ILLEGAL_ARGUMENT, hidl_hal_configs);
- return Void();
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
}
- auto profiler = hidl_profiler_->MakeScopedProfiler(
- HidlProfiler::ScopedType::kConfigureStream,
- device_session_->GetProfiler(hidl_profiler_->GetCameraId(),
- hidl_profiler_->GetLatencyFlag()),
- device_session_->GetProfiler(hidl_profiler_->GetCameraId(),
- hidl_profiler_->GetFpsFlag()));
+ auto profiler = aidl_profiler_->MakeScopedProfiler(
+ AidlProfiler::ScopedType::kConfigureStream,
+ device_session_->GetProfiler(aidl_profiler_->GetCameraId(),
+ aidl_profiler_->GetLatencyFlag()),
+ device_session_->GetProfiler(aidl_profiler_->GetCameraId(),
+ aidl_profiler_->GetFpsFlag()));
first_frame_requested_ = false;
num_pending_first_frame_buffers_ = 0;
google_camera_hal::StreamConfiguration hal_stream_config;
- status_t res = hidl_utils::ConverToHalStreamConfig(requestedConfiguration,
- &hal_stream_config);
+ status_t res = aidl_utils::ConvertToHalStreamConfig(requestedConfiguration,
+ &hal_stream_config);
if (res != OK) {
- _hidl_cb(Status::ILLEGAL_ARGUMENT, hidl_hal_configs);
- return Void();
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
}
std::vector<google_camera_hal::HalStream> hal_configured_streams;
@@ -587,123 +591,80 @@ Return<void> HidlCameraDeviceSession::configureStreams_3_8(
if (res != OK) {
ALOGE("%s: Configuring streams failed: %s(%d)", __FUNCTION__,
strerror(-res), res);
- _hidl_cb(hidl_utils::ConvertToHidlStatus(res), hidl_hal_configs);
- return Void();
- }
-
- res = hidl_utils::ConvertToHidlHalStreamConfig(hal_configured_streams,
- &hidl_hal_configs);
- _hidl_cb(hidl_utils::ConvertToHidlStatus(res), hidl_hal_configs);
-
- return Void();
-}
-
-Return<void> HidlCameraDeviceSession::configureStreams_3_7(
- const V3_7::StreamConfiguration& requestedConfiguration,
- ICameraDeviceSession::configureStreams_3_6_cb _hidl_cb) {
- ATRACE_NAME("HidlCameraDeviceSession::configureStreams_3_7");
- HalStreamConfiguration hidl_hal_configs;
- if (device_session_ == nullptr) {
- _hidl_cb(Status::ILLEGAL_ARGUMENT, hidl_hal_configs);
- return Void();
- }
-
- auto profiler = hidl_profiler_->MakeScopedProfiler(
- HidlProfiler::ScopedType::kConfigureStream,
- device_session_->GetProfiler(hidl_profiler_->GetCameraId(),
- hidl_profiler_->GetLatencyFlag()),
- device_session_->GetProfiler(hidl_profiler_->GetCameraId(),
- hidl_profiler_->GetFpsFlag()));
-
- first_frame_requested_ = false;
- num_pending_first_frame_buffers_ = 0;
-
- google_camera_hal::StreamConfiguration hal_stream_config;
- status_t res = hidl_utils::ConverToHalStreamConfig(requestedConfiguration,
- &hal_stream_config);
- if (res != OK) {
- _hidl_cb(Status::ILLEGAL_ARGUMENT, hidl_hal_configs);
- return Void();
+ return aidl_utils::ConvertToAidlReturn(res);
}
- std::vector<google_camera_hal::HalStream> hal_configured_streams;
- res = device_session_->ConfigureStreams(hal_stream_config,
- &hal_configured_streams);
+ res = aidl_utils::ConvertToAidlHalStreamConfig(hal_configured_streams,
+ aidl_return);
if (res != OK) {
- ALOGE("%s: Configuring streams failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- _hidl_cb(hidl_utils::ConvertToHidlStatus(res), hidl_hal_configs);
- return Void();
+ return aidl_utils::ConvertToAidlReturn(res);
}
-
- res = hidl_utils::ConvertToHidlHalStreamConfig(hal_configured_streams,
- &hidl_hal_configs);
- _hidl_cb(hidl_utils::ConvertToHidlStatus(res), hidl_hal_configs);
-
- return Void();
+ return ScopedAStatus::ok();
}
-Return<void> HidlCameraDeviceSession::getCaptureRequestMetadataQueue(
- ICameraDeviceSession::getCaptureRequestMetadataQueue_cb _hidl_cb) {
- _hidl_cb(*request_metadata_queue_->getDesc());
- return Void();
+ScopedAStatus AidlCameraDeviceSession::getCaptureRequestMetadataQueue(
+ ::aidl::android::hardware::common::fmq::MQDescriptor<
+ int8_t, SynchronizedReadWrite>* aidl_return) {
+ *aidl_return = request_metadata_queue_->dupeDesc();
+ return ScopedAStatus::ok();
}
-Return<void> HidlCameraDeviceSession::getCaptureResultMetadataQueue(
- ICameraDeviceSession::getCaptureResultMetadataQueue_cb _hidl_cb) {
- _hidl_cb(*result_metadata_queue_->getDesc());
- return Void();
+ScopedAStatus AidlCameraDeviceSession::getCaptureResultMetadataQueue(
+ ::aidl::android::hardware::common::fmq::MQDescriptor<
+ int8_t, SynchronizedReadWrite>* aidl_return) {
+ *aidl_return = result_metadata_queue_->dupeDesc();
+ return ScopedAStatus::ok();
}
-Return<void> HidlCameraDeviceSession::processCaptureRequest_3_7(
- const hidl_vec<CaptureRequest>& requests,
- const hidl_vec<BufferCache>& cachesToRemove,
- processCaptureRequest_3_7_cb _hidl_cb) {
- if (device_session_ == nullptr) {
- _hidl_cb(Status::ILLEGAL_ARGUMENT, 0);
- return Void();
+ScopedAStatus AidlCameraDeviceSession::processCaptureRequest(
+ const std::vector<CaptureRequest>& requests,
+ const std::vector<BufferCache>& cachesToRemove, int32_t* aidl_return) {
+ if (aidl_return == nullptr || device_session_ == nullptr) {
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
}
-
+ *aidl_return = 0;
bool profile_first_request = false;
if (!first_frame_requested_) {
first_frame_requested_ = true;
profile_first_request = true;
- ATRACE_BEGIN("HidlCameraDeviceSession::FirstRequest");
- num_pending_first_frame_buffers_ =
- requests[0].v3_4.v3_2.outputBuffers.size();
- first_request_frame_number_ = requests[0].v3_4.v3_2.frameNumber;
- hidl_profiler_->FirstFrameStart();
+ ATRACE_BEGIN("AidlCameraDeviceSession::FirstRequest");
+ num_pending_first_frame_buffers_ = requests[0].outputBuffers.size();
+ first_request_frame_number_ = requests[0].frameNumber;
+ aidl_profiler_->FirstFrameStart();
ATRACE_ASYNC_BEGIN("first_frame", 0);
}
std::vector<google_camera_hal::BufferCache> hal_buffer_caches;
status_t res =
- hidl_utils::ConvertToHalBufferCaches(cachesToRemove, &hal_buffer_caches);
+ aidl_utils::ConvertToHalBufferCaches(cachesToRemove, &hal_buffer_caches);
if (res != OK) {
- _hidl_cb(Status::ILLEGAL_ARGUMENT, 0);
if (profile_first_request) {
ATRACE_END();
}
- return Void();
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
}
device_session_->RemoveBufferCache(hal_buffer_caches);
- // Converting HIDL requests to HAL requests.
+ // Converting AIDL requests to HAL requests.
+ std::vector<native_handle_t*> handles_to_delete;
std::vector<google_camera_hal::CaptureRequest> hal_requests;
for (auto& request : requests) {
google_camera_hal::CaptureRequest hal_request = {};
- res = hidl_utils::ConvertToHalCaptureRequest(
- request, request_metadata_queue_.get(), &hal_request);
+ res = aidl_utils::ConvertToHalCaptureRequest(
+ request, request_metadata_queue_.get(), &hal_request,
+ &handles_to_delete);
if (res != OK) {
ALOGE("%s: Converting to HAL capture request failed: %s(%d)",
__FUNCTION__, strerror(-res), res);
- _hidl_cb(hidl_utils::ConvertToHidlStatus(res), 0);
if (profile_first_request) {
ATRACE_END();
}
- return Void();
+ cleanupHandles(handles_to_delete);
+ return aidl_utils::ConvertToAidlReturn(res);
}
hal_requests.push_back(std::move(hal_request));
@@ -719,189 +680,119 @@ Return<void> HidlCameraDeviceSession::processCaptureRequest_3_7(
__FUNCTION__, strerror(-res), res, num_processed_requests,
hal_requests.size());
}
-
- _hidl_cb(hidl_utils::ConvertToHidlStatus(res), num_processed_requests);
+ if (num_processed_requests > INT_MAX) {
+ cleanupHandles(handles_to_delete);
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
+ }
+ *aidl_return = (int32_t)num_processed_requests;
if (profile_first_request) {
ATRACE_END();
}
- return Void();
+ cleanupHandles(handles_to_delete);
+ return aidl_utils::ConvertToAidlReturn(res);
}
-Return<void> HidlCameraDeviceSession::signalStreamFlush(
- const hidl_vec<int32_t>& /*streamIds*/, uint32_t /*streamConfigCounter*/) {
+ScopedAStatus AidlCameraDeviceSession::signalStreamFlush(
+ const std::vector<int32_t>&, int32_t) {
// TODO(b/143902312): Implement this.
- return Void();
+ return ScopedAStatus::ok();
}
-Return<Status> HidlCameraDeviceSession::flush() {
- ATRACE_NAME("HidlCameraDeviceSession::flush");
+ScopedAStatus AidlCameraDeviceSession::flush() {
+ ATRACE_NAME("AidlCameraDeviceSession::flush");
ATRACE_ASYNC_BEGIN("switch_mode", 0);
if (device_session_ == nullptr) {
- return Status::INTERNAL_ERROR;
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
}
- auto profiler = hidl_profiler_->MakeScopedProfiler(
- HidlProfiler::ScopedType::kFlush,
- device_session_->GetProfiler(hidl_profiler_->GetCameraId(),
- hidl_profiler_->GetLatencyFlag()),
- device_session_->GetProfiler(hidl_profiler_->GetCameraId(),
- hidl_profiler_->GetFpsFlag()));
+ auto profiler = aidl_profiler_->MakeScopedProfiler(
+ AidlProfiler::ScopedType::kFlush,
+ device_session_->GetProfiler(aidl_profiler_->GetCameraId(),
+ aidl_profiler_->GetLatencyFlag()),
+ device_session_->GetProfiler(aidl_profiler_->GetCameraId(),
+ aidl_profiler_->GetFpsFlag()));
status_t res = device_session_->Flush();
if (res != OK) {
ALOGE("%s: Flushing device failed: %s(%d).", __FUNCTION__, strerror(-res),
res);
- return Status::INTERNAL_ERROR;
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
}
- return Status::OK;
+ return ScopedAStatus::ok();
}
-Return<void> HidlCameraDeviceSession::close() {
- ATRACE_NAME("HidlCameraDeviceSession::close");
+ScopedAStatus AidlCameraDeviceSession::close() {
+ ATRACE_NAME("AidlCameraDeviceSession::close");
if (device_session_ != nullptr) {
- auto profiler = hidl_profiler_->MakeScopedProfiler(
- HidlProfiler::ScopedType::kClose,
- device_session_->GetProfiler(hidl_profiler_->GetCameraId(),
- hidl_profiler_->GetLatencyFlag()),
- device_session_->GetProfiler(hidl_profiler_->GetCameraId(),
- hidl_profiler_->GetFpsFlag()));
+ auto profiler = aidl_profiler_->MakeScopedProfiler(
+ AidlProfiler::ScopedType::kClose,
+ device_session_->GetProfiler(aidl_profiler_->GetCameraId(),
+ aidl_profiler_->GetLatencyFlag()),
+ device_session_->GetProfiler(aidl_profiler_->GetCameraId(),
+ aidl_profiler_->GetFpsFlag()));
device_session_ = nullptr;
}
- return Void();
+ return ScopedAStatus::ok();
}
-Return<void> HidlCameraDeviceSession::isReconfigurationRequired(
- const V3_2::CameraMetadata& oldSessionParams,
- const V3_2::CameraMetadata& newSessionParams,
- ICameraDeviceSession::isReconfigurationRequired_cb _hidl_cb) {
- ATRACE_NAME("HidlCameraDeviceSession::isReconfigurationRequired");
+ScopedAStatus AidlCameraDeviceSession::switchToOffline(
+ const std::vector<int32_t>&,
+ CameraOfflineSessionInfo* out_offlineSessionInfo,
+ std::shared_ptr<ICameraOfflineSession>* aidl_return) {
+ *out_offlineSessionInfo = CameraOfflineSessionInfo();
+ *aidl_return = nullptr;
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
+}
+
+ScopedAStatus AidlCameraDeviceSession::isReconfigurationRequired(
+ const CameraMetadata& oldSessionParams,
+ const CameraMetadata& newSessionParams, bool* reconfiguration_required) {
+ ATRACE_NAME("AidlCameraDeviceSession::isReconfigurationRequired");
+ if (reconfiguration_required == nullptr) {
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
+ }
+ *reconfiguration_required = true;
std::unique_ptr<google_camera_hal::HalCameraMetadata> old_hal_session_metadata;
- status_t res = hidl_utils::ConvertToHalMetadata(0, nullptr, oldSessionParams,
- &old_hal_session_metadata);
+ status_t res = aidl_utils::ConvertToHalMetadata(
+ 0, nullptr, oldSessionParams.metadata, &old_hal_session_metadata);
if (res != OK) {
ALOGE("%s: Converting to old session metadata failed: %s(%d)", __FUNCTION__,
strerror(-res), res);
- _hidl_cb(Status::INTERNAL_ERROR, true);
- return Void();
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
}
std::unique_ptr<google_camera_hal::HalCameraMetadata> new_hal_session_metadata;
- res = hidl_utils::ConvertToHalMetadata(0, nullptr, newSessionParams,
+ res = aidl_utils::ConvertToHalMetadata(0, nullptr, newSessionParams.metadata,
&new_hal_session_metadata);
if (res != OK) {
ALOGE("%s: Converting to new session metadata failed: %s(%d)", __FUNCTION__,
strerror(-res), res);
- _hidl_cb(Status::INTERNAL_ERROR, true);
- return Void();
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
}
- bool reconfiguration_required = true;
res = device_session_->IsReconfigurationRequired(
old_hal_session_metadata.get(), new_hal_session_metadata.get(),
- &reconfiguration_required);
+ reconfiguration_required);
if (res != OK) {
ALOGE("%s: IsReconfigurationRequired failed: %s(%d)", __FUNCTION__,
strerror(-res), res);
- _hidl_cb(Status::INTERNAL_ERROR, true);
- return Void();
- }
-
- _hidl_cb(Status::OK, reconfiguration_required);
- return Void();
-}
-
-Return<void> HidlCameraDeviceSession::configureStreams(
- const V3_2::StreamConfiguration&, configureStreams_cb _hidl_cb) {
- _hidl_cb(Status::ILLEGAL_ARGUMENT, V3_2::HalStreamConfiguration());
- return Void();
-}
-Return<void> HidlCameraDeviceSession::configureStreams_3_3(
- const V3_2::StreamConfiguration&, configureStreams_3_3_cb _hidl_cb) {
- _hidl_cb(Status::ILLEGAL_ARGUMENT, V3_3::HalStreamConfiguration());
- return Void();
-}
-Return<void> HidlCameraDeviceSession::configureStreams_3_4(
- const V3_4::StreamConfiguration&, configureStreams_3_4_cb _hidl_cb) {
- _hidl_cb(Status::ILLEGAL_ARGUMENT, V3_4::HalStreamConfiguration());
- return Void();
-}
-
-Return<void> HidlCameraDeviceSession::configureStreams_3_5(
- const V3_5::StreamConfiguration& requestedConfiguration,
- configureStreams_3_5_cb _hidl_cb) {
- configureStreams_3_6(
- requestedConfiguration,
- [_hidl_cb](Status s, device::V3_6::HalStreamConfiguration halConfig) {
- V3_4::HalStreamConfiguration halConfig3_4;
- halConfig3_4.streams.resize(halConfig.streams.size());
- for (size_t i = 0; i < halConfig.streams.size(); i++) {
- halConfig3_4.streams[i] = halConfig.streams[i].v3_4;
- }
- _hidl_cb(s, halConfig3_4);
- });
-
- return Void();
-}
-
-Return<void> HidlCameraDeviceSession::configureStreams_3_6(
- const V3_5::StreamConfiguration& requestedConfiguration,
- configureStreams_3_6_cb _hidl_cb) {
- V3_7::StreamConfiguration requestedConfiguration3_7;
- requestedConfiguration3_7.streams.resize(
- requestedConfiguration.v3_4.streams.size());
- for (size_t i = 0; i < requestedConfiguration.v3_4.streams.size(); i++) {
- requestedConfiguration3_7.streams[i].v3_4 =
- requestedConfiguration.v3_4.streams[i];
- requestedConfiguration3_7.streams[i].groupId = -1;
- }
- requestedConfiguration3_7.operationMode =
- requestedConfiguration.v3_4.operationMode;
- requestedConfiguration3_7.sessionParams =
- requestedConfiguration.v3_4.sessionParams;
- requestedConfiguration3_7.streamConfigCounter =
- requestedConfiguration.streamConfigCounter;
- requestedConfiguration3_7.multiResolutionInputImage = false;
-
- configureStreams_3_7(requestedConfiguration3_7, _hidl_cb);
- return Void();
-}
-
-Return<void> HidlCameraDeviceSession::switchToOffline(
- const hidl_vec<int32_t>&, switchToOffline_cb _hidl_cb) {
- _hidl_cb(Status::ILLEGAL_ARGUMENT, V3_6::CameraOfflineSessionInfo(), nullptr);
- return Void();
-}
-
-Return<void> HidlCameraDeviceSession::processCaptureRequest(
- const hidl_vec<V3_2::CaptureRequest>& requests,
- const hidl_vec<BufferCache>& cachesToRemove,
- processCaptureRequest_cb _hidl_cb) {
- hidl_vec<V3_4::CaptureRequest> requests_3_4;
- requests_3_4.resize(requests.size());
- for (uint32_t i = 0; i < requests_3_4.size(); i++) {
- requests_3_4[i].v3_2 = requests[i];
- }
-
- return processCaptureRequest_3_4(requests_3_4, cachesToRemove, _hidl_cb);
-}
-
-Return<void> HidlCameraDeviceSession::processCaptureRequest_3_4(
- const hidl_vec<V3_4::CaptureRequest>& requests,
- const hidl_vec<BufferCache>& cachesToRemove,
- processCaptureRequest_cb _hidl_cb) {
- hidl_vec<V3_7::CaptureRequest> requests_3_7;
- requests_3_7.resize(requests.size());
- for (uint32_t i = 0; i < requests_3_7.size(); i++) {
- requests_3_7[i].v3_4 = requests[i];
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
}
- return processCaptureRequest_3_7(requests_3_7, cachesToRemove, _hidl_cb);
+ return ScopedAStatus::ok();
}
} // namespace implementation
-} // namespace V3_8
} // namespace device
} // namespace camera
} // namespace hardware
diff --git a/common/hal/hidl_service/hidl_camera_device_session.h b/common/hal/aidl_service/aidl_camera_device_session.h
index 330527d..3761e66 100644
--- a/common/hal/hidl_service/hidl_camera_device_session.h
+++ b/common/hal/aidl_service/aidl_camera_device_session.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,132 +14,105 @@
* limitations under the License.
*/
-#ifndef HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_CAMERA_DEVICE_SESSION_H_
-#define HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_CAMERA_DEVICE_SESSION_H_
+#ifndef HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_CAMERA_DEVICE_SESSION_H_
+#define HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_CAMERA_DEVICE_SESSION_H_
-#include <android/hardware/camera/device/3.8/ICameraDeviceSession.h>
-#include <android/hardware/camera/device/3.8/ICameraDevice.h>
-#include <android/hardware/camera/device/3.8/ICameraDeviceCallback.h>
+#include <aidl/android/hardware/camera/device/BnCameraDeviceSession.h>
+#include <aidl/android/hardware/camera/device/ICameraDevice.h>
+#include <aidl/android/hardware/camera/device/ICameraDeviceCallback.h>
#include <android/hardware/thermal/2.0/IThermal.h>
-#include <fmq/MessageQueue.h>
+#include <fmq/AidlMessageQueue.h>
#include <shared_mutex>
+#include "aidl_profiler.h"
#include "camera_device_session.h"
-#include "hidl_profiler.h"
#include "hidl_thermal_utils.h"
namespace android {
namespace hardware {
namespace camera {
namespace device {
-namespace V3_8 {
namespace implementation {
-using ::android::hardware::camera::common::V1_0::Status;
-using ::android::hardware::camera::device::V3_2::BufferCache;
-using ::android::hardware::camera::device::V3_2::RequestTemplate;
-using ::android::hardware::camera::device::V3_7::CaptureRequest;
-using ::android::hardware::camera::device::V3_8::StreamConfiguration;
-using ::android::hardware::camera::device::V3_8::ICameraDeviceCallback;
-using ::android::hardware::camera::device::V3_8::ICameraDeviceSession;
-using ::android::hardware::camera::implementation::HidlProfiler;
-
-using MetadataQueue =
- ::android::hardware::MessageQueue<uint8_t, kSynchronizedReadWrite>;
-
-// HidlCameraDeviceSession implements the HIDL camera device session interface,
+using ::aidl::android::hardware::camera::device::BnCameraDeviceSession;
+using ::aidl::android::hardware::camera::device::BufferCache;
+using ::aidl::android::hardware::camera::device::CameraMetadata;
+using ::aidl::android::hardware::camera::device::CameraOfflineSessionInfo;
+using ::aidl::android::hardware::camera::device::CaptureRequest;
+using ::aidl::android::hardware::camera::device::HalStream;
+using ::aidl::android::hardware::camera::device::ICameraDeviceCallback;
+using ::aidl::android::hardware::camera::device::ICameraOfflineSession;
+using ::aidl::android::hardware::camera::device::RequestTemplate;
+using ::aidl::android::hardware::camera::device::StreamConfiguration;
+using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite;
+using ::android::hardware::camera::implementation::AidlProfiler;
+using ndk::ScopedAStatus;
+
+using MetadataQueue = AidlMessageQueue<int8_t, SynchronizedReadWrite>;
+
+// AidlCameraDeviceSession implements the AIDL camera device session interface,
// ICameraDeviceSession, that contains the methods to configure and request
// captures from an active camera device.
-class HidlCameraDeviceSession : public ICameraDeviceSession {
+class AidlCameraDeviceSession : public BnCameraDeviceSession {
public:
- // Create a HidlCameraDeviceSession.
+ // Create a AidlCameraDeviceSession.
// device_session is a google camera device session that
- // HidlCameraDeviceSession is going to manage. Creating a
- // HidlCameraDeviceSession will fail if device_session is
+ // AidlCameraDeviceSession is going to manage. Creating a
+ // AidlCameraDeviceSession will fail if device_session is
// nullptr.
- static std::unique_ptr<HidlCameraDeviceSession> Create(
- const sp<V3_2::ICameraDeviceCallback>& callback,
+ static std::shared_ptr<AidlCameraDeviceSession> Create(
+ const std::shared_ptr<ICameraDeviceCallback>& callback,
std::unique_ptr<google_camera_hal::CameraDeviceSession> device_session,
- std::shared_ptr<HidlProfiler> hidl_profiler);
-
- virtual ~HidlCameraDeviceSession();
-
- // Override functions in ICameraDeviceSession
- Return<void> configureStreams_3_8(
- const StreamConfiguration& requestedConfiguration,
- configureStreams_3_8_cb _hidl_cb) override;
-
- Return<void> repeatingRequestEnd(
- uint32_t /*frameNumber*/,
- const hidl_vec<int32_t>& /*streamIds*/) override {
- return Void();
- }
-
- Return<void> configureStreams_3_7(
- const V3_7::StreamConfiguration& requestedConfiguration,
- configureStreams_3_7_cb _hidl_cb) override;
-
- Return<void> processCaptureRequest_3_7(
- const hidl_vec<CaptureRequest>& requests,
- const hidl_vec<BufferCache>& cachesToRemove,
- processCaptureRequest_3_7_cb _hidl_cb) override;
-
- Return<void> configureStreams_3_6(
- const V3_5::StreamConfiguration& requestedConfiguration,
- ICameraDeviceSession::configureStreams_3_6_cb _hidl_cb) override;
-
- Return<void> switchToOffline(const hidl_vec<int32_t>& streamsToKeep,
- switchToOffline_cb _hidl_cb) override;
+ std::shared_ptr<AidlProfiler> aidl_profiler);
- Return<void> constructDefaultRequestSettings(
- RequestTemplate type,
- ICameraDeviceSession::constructDefaultRequestSettings_cb _hidl_cb) override;
+ virtual ~AidlCameraDeviceSession();
- Return<void> configureStreams_3_5(
- const V3_5::StreamConfiguration& requestedConfiguration,
- ICameraDeviceSession::configureStreams_3_5_cb _hidl_cb) override;
+ // functions in ICameraDeviceSession
- Return<void> getCaptureRequestMetadataQueue(
- ICameraDeviceSession::getCaptureRequestMetadataQueue_cb _hidl_cb) override;
+ virtual ScopedAStatus close() override;
- Return<void> getCaptureResultMetadataQueue(
- ICameraDeviceSession::getCaptureResultMetadataQueue_cb _hidl_cb) override;
+ virtual ScopedAStatus configureStreams(const StreamConfiguration&,
+ std::vector<HalStream>*) override;
- Return<void> processCaptureRequest_3_4(
- const hidl_vec<V3_4::CaptureRequest>& requests,
- const hidl_vec<BufferCache>& cachesToRemove,
- processCaptureRequest_3_4_cb _hidl_cb) override;
+ virtual ScopedAStatus constructDefaultRequestSettings(
+ RequestTemplate in_type, CameraMetadata* _aidl_return) override;
- Return<void> signalStreamFlush(const hidl_vec<int32_t>& streamIds,
- uint32_t streamConfigCounter) override;
+ virtual ScopedAStatus flush() override;
- Return<void> isReconfigurationRequired(const V3_2::CameraMetadata& oldSessionParams,
- const V3_2::CameraMetadata& newSessionParams,
- ICameraDeviceSession::isReconfigurationRequired_cb _hidl_cb) override;
+ virtual ScopedAStatus getCaptureRequestMetadataQueue(
+ ::aidl::android::hardware::common::fmq::MQDescriptor<
+ int8_t, SynchronizedReadWrite>* _aidl_return) override;
- Return<Status> flush() override;
+ virtual ScopedAStatus getCaptureResultMetadataQueue(
+ ::aidl::android::hardware::common::fmq::MQDescriptor<
+ int8_t, SynchronizedReadWrite>* _aidl_return) override;
- Return<void> close() override;
+ virtual ScopedAStatus isReconfigurationRequired(
+ const CameraMetadata& in_oldSessionParams,
+ const CameraMetadata& in_newSessionParams, bool* _aidl_return) override;
- // Legacy methods
- Return<void> configureStreams(const V3_2::StreamConfiguration&,
- configureStreams_cb _hidl_cb) override;
+ virtual ScopedAStatus processCaptureRequest(
+ const std::vector<CaptureRequest>& in_requests,
+ const std::vector<BufferCache>& in_cachesToRemove,
+ int32_t* _aidl_return) override;
- Return<void> configureStreams_3_3(const V3_2::StreamConfiguration&,
- configureStreams_3_3_cb _hidl_cb) override;
+ virtual ScopedAStatus signalStreamFlush(
+ const std::vector<int32_t>& in_streamIds,
+ int32_t in_streamConfigCounter) override;
- Return<void> configureStreams_3_4(const V3_4::StreamConfiguration&,
- configureStreams_3_4_cb _hidl_cb) override;
+ virtual ScopedAStatus switchToOffline(
+ const std::vector<int32_t>& in_streamsToKeep,
+ CameraOfflineSessionInfo* out_offlineSessionInfo,
+ std::shared_ptr<ICameraOfflineSession>* _aidl_return) override;
- Return<void> processCaptureRequest(
- const hidl_vec<V3_2::CaptureRequest>& requests,
- const hidl_vec<BufferCache>& cachesToRemove,
- processCaptureRequest_cb _hidl_cb) override;
- // End of override functions in ICameraDeviceSession
+ virtual ScopedAStatus repeatingRequestEnd(
+ int32_t /*in_frameNumber*/,
+ const std::vector<int32_t>& /*in_streamIds*/) override {
+ return ScopedAStatus::ok();
+ };
- protected:
- HidlCameraDeviceSession() = default;
+ AidlCameraDeviceSession() = default;
private:
static constexpr uint32_t kRequestMetadataQueueSizeBytes = 1 << 20; // 1MB
@@ -148,11 +121,11 @@ class HidlCameraDeviceSession : public ICameraDeviceSession {
// Initialize the latest available gralloc buffer mapper.
status_t InitializeBufferMapper();
- // Initialize HidlCameraDeviceSession with a CameraDeviceSession.
+ // Initialize AidlCameraDeviceSession with a CameraDeviceSession.
status_t Initialize(
- const sp<V3_2::ICameraDeviceCallback>& callback,
+ const std::shared_ptr<ICameraDeviceCallback>& callback,
std::unique_ptr<google_camera_hal::CameraDeviceSession> device_session,
- std::shared_ptr<HidlProfiler> hidl_profiler);
+ std::shared_ptr<AidlProfiler> aidl_profiler);
// Create a metadata queue.
// If override_size_property contains a valid size, it will create a metadata
@@ -169,7 +142,7 @@ class HidlCameraDeviceSession : public ICameraDeviceSession {
void ProcessCaptureResult(
std::unique_ptr<google_camera_hal::CaptureResult> hal_result);
- // Invoked when reciving a message from HAL.
+ // Invoked when receiving a message from HAL.
void NotifyHalMessage(const google_camera_hal::NotifyMessage& hal_message);
// Invoked when requesting stream buffers from HAL.
@@ -211,9 +184,9 @@ class HidlCameraDeviceSession : public ICameraDeviceSession {
// Assuming callbacks to framework is thread-safe, the shared mutex is only
// used to protect member variable writing and reading.
- std::shared_mutex hidl_device_callback_lock_;
- // Protected by hidl_device_callback_lock_
- sp<ICameraDeviceCallback> hidl_device_callback_;
+ std::shared_mutex aidl_device_callback_lock_;
+ // Protected by aidl_device_callback_lock_
+ std::shared_ptr<ICameraDeviceCallback> aidl_device_callback_;
sp<android::hardware::graphics::mapper::V2_0::IMapper> buffer_mapper_v2_;
sp<android::hardware::graphics::mapper::V3_0::IMapper> buffer_mapper_v3_;
@@ -237,14 +210,13 @@ class HidlCameraDeviceSession : public ICameraDeviceSession {
// Must be protected by pending_first_frame_buffers_mutex_
size_t num_pending_first_frame_buffers_ = 0;
- std::shared_ptr<HidlProfiler> hidl_profiler_;
+ std::shared_ptr<AidlProfiler> aidl_profiler_;
};
} // namespace implementation
-} // namespace V3_8
} // namespace device
} // namespace camera
} // namespace hardware
} // namespace android
-#endif // HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_CAMERA_DEVICE_SESSION_H_
+#endif // HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_CAMERA_DEVICE_SESSION_H_
diff --git a/common/hal/aidl_service/aidl_camera_provider.cc b/common/hal/aidl_service/aidl_camera_provider.cc
new file mode 100644
index 0000000..ca4b650
--- /dev/null
+++ b/common/hal/aidl_service/aidl_camera_provider.cc
@@ -0,0 +1,375 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "GCH_AidlCameraProvider"
+//#define LOG_NDEBUG 0
+#include "aidl_camera_provider.h"
+
+#include <log/log.h>
+
+#include <regex>
+
+#include "aidl_camera_device.h"
+#include "aidl_utils.h"
+#include "camera_device.h"
+
+namespace android {
+namespace hardware {
+namespace camera {
+namespace provider {
+namespace implementation {
+
+namespace aidl_utils = ::android::hardware::camera::implementation::aidl_utils;
+
+using aidl::android::hardware::camera::common::CameraDeviceStatus;
+using aidl::android::hardware::camera::common::Status;
+using aidl::android::hardware::camera::common::TorchModeStatus;
+using aidl::android::hardware::camera::common::VendorTagSection;
+using ::android::google_camera_hal::CameraDevice;
+
+const std::string AidlCameraProvider::kProviderName = "internal";
+// "device@<version>/internal/<id>"
+const std::regex AidlCameraProvider::kDeviceNameRegex(
+ "device@([0-9]+\\.[0-9]+)/internal/(.+)");
+
+std::shared_ptr<AidlCameraProvider> AidlCameraProvider::Create() {
+ std::shared_ptr<AidlCameraProvider> provider =
+ ndk::SharedRefBase::make<AidlCameraProvider>();
+
+ status_t res = provider->Initialize();
+ if (res != OK) {
+ ALOGE("%s: Initializing AidlCameraProvider failed: %s(%d)", __FUNCTION__,
+ strerror(-res), res);
+ return nullptr;
+ }
+
+ return provider;
+}
+
+status_t AidlCameraProvider::Initialize() {
+ google_camera_provider_ = CameraProvider::Create();
+ if (google_camera_provider_ == nullptr) {
+ ALOGE("%s: Creating CameraProvider failed.", __FUNCTION__);
+ return NO_INIT;
+ }
+
+ camera_provider_callback_ = {
+ .camera_device_status_change = google_camera_hal::CameraDeviceStatusChangeFunc(
+ [this](std::string camera_id,
+ google_camera_hal::CameraDeviceStatus new_status) {
+ if (callbacks_ == nullptr) {
+ ALOGE("%s: callbacks_ is null", __FUNCTION__);
+ return;
+ }
+ CameraDeviceStatus aidl_camera_device_status;
+ status_t res = aidl_utils::ConvertToAidlCameraDeviceStatus(
+ new_status, &aidl_camera_device_status);
+ if (res != OK) {
+ ALOGE(
+ "%s: Converting to aidl camera device status failed: %s(%d)",
+ __FUNCTION__, strerror(-res), res);
+ return;
+ }
+
+ std::unique_lock<std::mutex> lock(callbacks_lock_);
+ callbacks_->cameraDeviceStatusChange(
+ "device@" +
+ device::implementation::AidlCameraDevice::kDeviceVersion +
+ "/" + kProviderName + "/" + camera_id,
+ aidl_camera_device_status);
+ }),
+ .physical_camera_device_status_change =
+ google_camera_hal::PhysicalCameraDeviceStatusChangeFunc(
+ [this](std::string camera_id, std::string physical_camera_id,
+ google_camera_hal::CameraDeviceStatus new_status) {
+ if (callbacks_ == nullptr) {
+ ALOGE("%s: callbacks_ is null", __FUNCTION__);
+ return;
+ }
+ /*auto castResult =
+ provider::V2_6::ICameraProviderCallback::castFrom(callbacks_);
+ if (!castResult.isOk()) {
+ ALOGE("%s: callbacks_ cannot be casted to version 2.6",
+ __FUNCTION__);
+ return;
+ }
+ sp<provider::V2_6::ICameraProviderCallback> callbacks_2_6_ =
+ castResult;
+ if (callbacks_2_6_ == nullptr) {
+ ALOGE("%s: callbacks_2_6_ is null", __FUNCTION__);
+ return;
+ }*/
+
+ CameraDeviceStatus aidl_camera_device_status;
+ status_t res = aidl_utils::ConvertToAidlCameraDeviceStatus(
+ new_status, &aidl_camera_device_status);
+ if (res != OK) {
+ ALOGE(
+ "%s: Converting to aidl camera device status failed: "
+ "%s(%d)",
+ __FUNCTION__, strerror(-res), res);
+ return;
+ }
+
+ std::unique_lock<std::mutex> lock(callbacks_lock_);
+ callbacks_->physicalCameraDeviceStatusChange(
+ "device@" +
+ device::implementation::AidlCameraDevice::kDeviceVersion +
+ "/" + kProviderName + "/" + camera_id,
+ physical_camera_id, aidl_camera_device_status);
+ }),
+ .torch_mode_status_change = google_camera_hal::TorchModeStatusChangeFunc(
+ [this](std::string camera_id,
+ google_camera_hal::TorchModeStatus new_status) {
+ if (callbacks_ == nullptr) {
+ ALOGE("%s: callbacks_ is null", __FUNCTION__);
+ return;
+ }
+
+ TorchModeStatus aidl_torch_status;
+ status_t res = aidl_utils::ConvertToAidlTorchModeStatus(
+ new_status, &aidl_torch_status);
+ if (res != OK) {
+ ALOGE("%s: Converting to aidl torch status failed: %s(%d)",
+ __FUNCTION__, strerror(-res), res);
+ return;
+ }
+
+ std::unique_lock<std::mutex> lock(callbacks_lock_);
+ callbacks_->torchModeStatusChange(
+ "device@" +
+ device::implementation::AidlCameraDevice::kDeviceVersion +
+ "/" + kProviderName + "/" + camera_id,
+ aidl_torch_status);
+ }),
+ };
+
+ google_camera_provider_->SetCallback(&camera_provider_callback_);
+ // purge pending malloc pages after initialization
+ mallopt(M_PURGE, 0);
+ return OK;
+}
+
+ScopedAStatus AidlCameraProvider::setCallback(
+ const std::shared_ptr<ICameraProviderCallback>& callback) {
+ bool first_time = false;
+ {
+ std::unique_lock<std::mutex> lock(callbacks_lock_);
+ first_time = callbacks_ == nullptr;
+ callbacks_ = callback;
+ }
+ google_camera_provider_->TriggerDeferredCallbacks();
+#ifdef __ANDROID_APEX__
+ if (first_time) {
+ std::string ready_property_name = "vendor.camera.hal.ready.count";
+ int ready_count = property_get_int32(ready_property_name.c_str(), 0);
+ property_set(ready_property_name.c_str(),
+ std::to_string(++ready_count).c_str());
+ ALOGI("AidlCameraProvider::setCallback() first time ready count: %d ",
+ ready_count);
+ }
+#endif
+ return ScopedAStatus::ok();
+}
+
+ScopedAStatus AidlCameraProvider::getVendorTags(
+ std::vector<VendorTagSection>* vts) {
+ if (vts == nullptr) {
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
+ }
+ vts->clear();
+ std::vector<google_camera_hal::VendorTagSection> hal_vendor_tag_sections;
+
+ status_t res =
+ google_camera_provider_->GetVendorTags(&hal_vendor_tag_sections);
+ if (res != OK) {
+ ALOGE("%s: Getting vendor tags failed: %s(%d)", __FUNCTION__,
+ strerror(-res), res);
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
+ }
+
+ res = aidl_utils::ConvertToAidlVendorTagSections(hal_vendor_tag_sections, vts);
+ if (res != OK) {
+ ALOGE("%s: Converting to aidl vendor tags failed: %s(%d)", __FUNCTION__,
+ strerror(-res), res);
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
+ }
+ return ScopedAStatus::ok();
+}
+
+ScopedAStatus AidlCameraProvider::getCameraIdList(
+ std::vector<std::string>* camera_ids_ret) {
+ if (camera_ids_ret == nullptr) {
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
+ }
+ camera_ids_ret->clear();
+ std::vector<uint32_t> camera_ids;
+ status_t res = google_camera_provider_->GetCameraIdList(&camera_ids);
+ if (res != OK) {
+ ALOGE("%s: Getting camera ID list failed: %s(%d)", __FUNCTION__,
+ strerror(-res), res);
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
+ }
+
+ camera_ids_ret->resize(camera_ids.size());
+ for (uint32_t i = 0; i < camera_ids_ret->size(); i++) {
+ // camera ID is in the form of "device@<major>.<minor>/<type>/<id>"
+ (*camera_ids_ret)[i] =
+ "device@" + device::implementation::AidlCameraDevice::kDeviceVersion +
+ "/" + kProviderName + "/" + std::to_string(camera_ids[i]);
+ }
+ return ScopedAStatus::ok();
+}
+
+ScopedAStatus AidlCameraProvider::getConcurrentCameraIds(
+ std::vector<ConcurrentCameraIdCombination>* aidl_camera_id_combinations) {
+ if (aidl_camera_id_combinations == nullptr) {
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
+ }
+ aidl_camera_id_combinations->clear();
+ std::vector<std::unordered_set<uint32_t>> camera_id_combinations;
+ status_t res = google_camera_provider_->GetConcurrentStreamingCameraIds(
+ &camera_id_combinations);
+ if (res != OK) {
+ ALOGE(
+ "%s: Getting the combinations of concurrent streaming camera ids "
+ "failed: %s(%d)",
+ __FUNCTION__, strerror(-res), res);
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
+ }
+ aidl_camera_id_combinations->resize(camera_id_combinations.size());
+ int i = 0;
+ for (auto& combination : camera_id_combinations) {
+ std::vector<std::string> aidl_combination(combination.size());
+ int c = 0;
+ for (auto& camera_id : combination) {
+ aidl_combination[c] = std::to_string(camera_id);
+ c++;
+ }
+ (*aidl_camera_id_combinations)[i].combination = aidl_combination;
+ i++;
+ }
+ return ScopedAStatus::ok();
+}
+
+ScopedAStatus AidlCameraProvider::isConcurrentStreamCombinationSupported(
+ const std::vector<CameraIdAndStreamCombination>& configs, bool* supported) {
+ *supported = false;
+ std::vector<google_camera_hal::CameraIdAndStreamConfiguration>
+ devices_stream_configs(configs.size());
+ status_t res = OK;
+ size_t c = 0;
+ for (auto& config : configs) {
+ res = aidl_utils::ConvertToHalStreamConfig(
+ config.streamConfiguration,
+ &devices_stream_configs[c].stream_configuration);
+ if (res != OK) {
+ ALOGE("%s: ConverToHalStreamConfig failed", __FUNCTION__);
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
+ }
+ uint32_t camera_id = atoi(config.cameraId.c_str());
+ devices_stream_configs[c].camera_id = camera_id;
+ c++;
+ }
+ res = google_camera_provider_->IsConcurrentStreamCombinationSupported(
+ devices_stream_configs, supported);
+ if (res != OK) {
+ ALOGE("%s: ConverToHalStreamConfig failed", __FUNCTION__);
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
+ }
+ return ScopedAStatus::ok();
+}
+
+bool AidlCameraProvider::ParseDeviceName(const std::string& device_name,
+ std::string* device_version,
+ std::string* camera_id) {
+ std::string device_name_std(device_name.c_str());
+ std::smatch sm;
+
+ if (std::regex_match(device_name_std, sm,
+ AidlCameraProvider::kDeviceNameRegex)) {
+ if (device_version != nullptr) {
+ *device_version = sm[1];
+ }
+ if (camera_id != nullptr) {
+ *camera_id = sm[2];
+ }
+ return true;
+ }
+ return false;
+}
+
+ScopedAStatus AidlCameraProvider::getCameraDeviceInterface(
+ const std::string& camera_device_name,
+ std::shared_ptr<ICameraDevice>* device) {
+ std::unique_ptr<CameraDevice> google_camera_device;
+ if (device == nullptr) {
+ ALOGE("%s: device is nullptr. ", __FUNCTION__);
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
+ }
+
+ // Parse camera_device_name.
+ std::string camera_id, device_version;
+
+ bool match = ParseDeviceName(camera_device_name, &device_version, &camera_id);
+ if (!match) {
+ ALOGE("%s: Device name parse fail. ", __FUNCTION__);
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
+ }
+
+ status_t res = google_camera_provider_->CreateCameraDevice(
+ atoi(camera_id.c_str()), &google_camera_device);
+ if (res != OK) {
+ ALOGE("%s: Creating CameraDevice failed: %s(%d)", __FUNCTION__,
+ strerror(-res), res);
+ return aidl_utils::ConvertToAidlReturn(res);
+ }
+
+ *device = device::implementation::AidlCameraDevice::Create(
+ std::move(google_camera_device));
+ if (*device == nullptr) {
+ ALOGE("%s: Creating AidlCameraDevice failed", __FUNCTION__);
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
+ }
+ return ScopedAStatus::ok();
+}
+
+ScopedAStatus AidlCameraProvider::notifyDeviceStateChange(int64_t new_state) {
+ google_camera_hal::DeviceState device_state =
+ google_camera_hal::DeviceState::kNormal;
+ ::android::hardware::camera::implementation::aidl_utils::ConvertToHalDeviceState(
+ new_state, device_state);
+ google_camera_provider_->NotifyDeviceStateChange(device_state);
+ return ScopedAStatus::ok();
+}
+
+} // namespace implementation
+} // namespace provider
+} // namespace camera
+} // namespace hardware
+} // namespace android
diff --git a/common/hal/aidl_service/aidl_camera_provider.h b/common/hal/aidl_service/aidl_camera_provider.h
new file mode 100644
index 0000000..8c1e5fd
--- /dev/null
+++ b/common/hal/aidl_service/aidl_camera_provider.h
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_CAMERA_PROVIDER_H_
+#define HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_CAMERA_PROVIDER_H_
+
+#include <aidl/android/hardware/camera/provider/BnCameraProvider.h>
+#include <aidl/android/hardware/camera/provider/ICameraProviderCallback.h>
+
+#include <regex>
+
+#include "camera_provider.h"
+
+namespace android {
+namespace hardware {
+namespace camera {
+namespace provider {
+namespace implementation {
+
+using aidl::android::hardware::camera::common::VendorTagSection;
+using aidl::android::hardware::camera::device::ICameraDevice;
+using aidl::android::hardware::camera::provider::BnCameraProvider;
+using aidl::android::hardware::camera::provider::CameraIdAndStreamCombination;
+using aidl::android::hardware::camera::provider::ConcurrentCameraIdCombination;
+using aidl::android::hardware::camera::provider::ICameraProviderCallback;
+
+using ::android::google_camera_hal::CameraProvider;
+using ndk::ScopedAStatus;
+
+// AidlCameraProvider implements the AIDL camera provider interface,
+// ICameraProvider, to enumerate the available individual camera devices
+// in the system, and provide updates about changes to device status.
+class AidlCameraProvider : public BnCameraProvider {
+ public:
+ static const std::string kProviderName;
+ static std::shared_ptr<AidlCameraProvider> Create();
+ virtual ~AidlCameraProvider() = default;
+
+ // Override functions in ICameraProvider.
+
+ virtual ScopedAStatus setCallback(
+ const std::shared_ptr<ICameraProviderCallback>& callback) override;
+
+ virtual ScopedAStatus getVendorTags(
+ std::vector<VendorTagSection>* vts) override;
+
+ virtual ScopedAStatus getCameraIdList(
+ std::vector<std::string>* camera_ids) override;
+
+ virtual ScopedAStatus getCameraDeviceInterface(
+ const std::string& in_cameraDeviceName,
+ std::shared_ptr<ICameraDevice>* device) override;
+
+ virtual ScopedAStatus notifyDeviceStateChange(int64_t in_deviceState) override;
+
+ virtual ScopedAStatus getConcurrentCameraIds(
+ std::vector<ConcurrentCameraIdCombination>* concurrent_camera_ids) override;
+
+ virtual ScopedAStatus isConcurrentStreamCombinationSupported(
+ const std::vector<CameraIdAndStreamCombination>& in_configs,
+ bool* support) override;
+
+ // End of override functions in ICameraProvider.
+ AidlCameraProvider() = default;
+
+ private:
+ static const std::regex kDeviceNameRegex;
+
+ status_t Initialize();
+
+ // Parse device version and camera ID.
+ bool ParseDeviceName(const std::string& device_name,
+ std::string* device_version, std::string* camera_id);
+
+ std::mutex callbacks_lock_;
+ std::shared_ptr<ICameraProviderCallback> callbacks_;
+
+ std::unique_ptr<CameraProvider> google_camera_provider_;
+ google_camera_hal::CameraProviderCallback camera_provider_callback_;
+};
+
+} // namespace implementation
+} // namespace provider
+} // namespace camera
+} // namespace hardware
+} // namespace android
+
+#endif // HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_CAMERA_PROVIDER_H_
diff --git a/common/hal/hidl_service/hidl_profiler.cc b/common/hal/aidl_service/aidl_profiler.cc
index 6d17669..5c7e90d 100644
--- a/common/hal/hidl_service/hidl_profiler.cc
+++ b/common/hal/aidl_service/aidl_profiler.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,9 +15,9 @@
*/
//#define LOG_NDEBUG 0
-#define LOG_TAG "GCH_HidlProfiler"
+#define LOG_TAG "GCH_AidlProfiler"
-#include "hidl_profiler.h"
+#include "aidl_profiler.h"
#include <log/log.h>
@@ -46,16 +46,16 @@ constexpr char kHalTotal[] = "HAL Total";
constexpr char kIdleString[] = "<-- IDLE -->";
constexpr char kOverall[] = "Overall";
-class HidlProfilerImpl : public HidlProfiler {
+class AidlProfilerImpl : public AidlProfiler {
public:
- HidlProfilerImpl(uint32_t camera_id, int32_t latency_flag, int32_t fps_flag)
+ AidlProfilerImpl(uint32_t camera_id, int32_t latency_flag, int32_t fps_flag)
: camera_id_string_("Cam" + std::to_string(camera_id)),
camera_id_(camera_id),
latency_flag_(latency_flag),
fps_flag_(fps_flag) {
}
- std::unique_ptr<HidlScopedProfiler> MakeScopedProfiler(
+ std::unique_ptr<AidlScopedProfiler> MakeScopedProfiler(
ScopedType type,
std::unique_ptr<google::camera_common::Profiler> custom_latency_profiler,
std::unique_ptr<google::camera_common::Profiler> custom_fps_profiler)
@@ -111,7 +111,7 @@ class HidlProfilerImpl : public HidlProfiler {
ALOGE("%s: Unknown type %d", __FUNCTION__, type);
return nullptr;
}
- return std::make_unique<HidlScopedProfiler>(
+ return std::make_unique<AidlScopedProfiler>(
latency_profiler_, name, id, [this, type]() {
std::lock_guard lock(api_mutex_);
if (type == ScopedType::kClose) {
@@ -158,7 +158,7 @@ class HidlProfilerImpl : public HidlProfiler {
return nullptr;
}
profiler->SetDumpFilePrefix(
- "/data/vendor/camera/profiler/hidl_open_close_");
+ "/data/vendor/camera/profiler/aidl_open_close_");
profiler->Start(kOverall, Profiler::kInvalidRequestId);
return profiler;
}
@@ -172,7 +172,7 @@ class HidlProfilerImpl : public HidlProfiler {
ALOGE("%s: Failed to create profiler", __FUNCTION__);
return nullptr;
}
- profiler->SetDumpFilePrefix("/data/vendor/camera/profiler/hidl_fps_");
+ profiler->SetDumpFilePrefix("/data/vendor/camera/profiler/aidl_fps_");
return profiler;
}
@@ -212,7 +212,7 @@ class HidlProfilerImpl : public HidlProfiler {
latency_profiler_ = std::move(profiler);
if (latency_profiler_ != nullptr) {
latency_profiler_->SetDumpFilePrefix(
- "/data/vendor/camera/profiler/hidl_open_close_");
+ "/data/vendor/camera/profiler/aidl_open_close_");
latency_profiler_->Start(kOverall, Profiler::kInvalidRequestId);
return true;
}
@@ -226,7 +226,7 @@ class HidlProfilerImpl : public HidlProfiler {
fps_profiler_ = std::move(profiler);
if (fps_profiler_ != nullptr) {
fps_profiler_->SetDumpFilePrefix(
- "/data/vendor/camera/profiler/hidl_fps_");
+ "/data/vendor/camera/profiler/aidl_fps_");
return true;
}
return false;
@@ -248,8 +248,8 @@ class HidlProfilerImpl : public HidlProfiler {
uint8_t idle_count_;
};
-class HidlProfilerMock : public HidlProfiler {
- std::unique_ptr<HidlScopedProfiler> MakeScopedProfiler(
+class AidlProfilerMock : public AidlProfiler {
+ std::unique_ptr<AidlScopedProfiler> MakeScopedProfiler(
ScopedType, std::unique_ptr<google::camera_common::Profiler>,
std::unique_ptr<google::camera_common::Profiler>) override {
return nullptr;
@@ -272,14 +272,14 @@ class HidlProfilerMock : public HidlProfiler {
} // anonymous namespace
-std::shared_ptr<HidlProfiler> HidlProfiler::Create(uint32_t camera_id) {
+std::shared_ptr<AidlProfiler> AidlProfiler::Create(uint32_t camera_id) {
int32_t latency_flag = property_get_int32(
kPropKeyProfileOpenClose, Profiler::SetPropFlag::kCustomProfiler);
int32_t fps_flag = property_get_int32(kPropKeyProfileFps,
Profiler::SetPropFlag::kCustomProfiler);
if (latency_flag == Profiler::SetPropFlag::kDisable &&
fps_flag == Profiler::SetPropFlag::kDisable) {
- return std::make_shared<HidlProfilerMock>();
+ return std::make_shared<AidlProfilerMock>();
}
// Use stopwatch flag to print result.
if ((latency_flag & Profiler::SetPropFlag::kPrintBit) != 0) {
@@ -290,10 +290,10 @@ std::shared_ptr<HidlProfiler> HidlProfiler::Create(uint32_t camera_id) {
fps_flag |= Profiler::SetPropFlag::kPrintFpsPerIntervalBit;
fps_flag &= ~Profiler::SetPropFlag::kPrintBit;
}
- return std::make_shared<HidlProfilerImpl>(camera_id, latency_flag, fps_flag);
+ return std::make_shared<AidlProfilerImpl>(camera_id, latency_flag, fps_flag);
}
-HidlScopedProfiler::HidlScopedProfiler(std::shared_ptr<Profiler> profiler,
+AidlScopedProfiler::AidlScopedProfiler(std::shared_ptr<Profiler> profiler,
const std::string name, int id,
std::function<void()> end_callback)
: profiler_(profiler),
@@ -304,7 +304,7 @@ HidlScopedProfiler::HidlScopedProfiler(std::shared_ptr<Profiler> profiler,
profiler_->Start(kHalTotal, Profiler::kInvalidRequestId);
}
-HidlScopedProfiler::~HidlScopedProfiler() {
+AidlScopedProfiler::~AidlScopedProfiler() {
profiler_->End(kHalTotal, Profiler::kInvalidRequestId);
profiler_->End(name_, id_);
if (end_callback_) {
diff --git a/common/hal/hidl_service/hidl_profiler.h b/common/hal/aidl_service/aidl_profiler.h
index b39d7c8..1491056 100644
--- a/common/hal/hidl_service/hidl_profiler.h
+++ b/common/hal/aidl_service/aidl_profiler.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_PROFILER_H_
-#define HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_PROFILER_H_
+#ifndef HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_PROFILER_H_
+#define HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_PROFILER_H_
#include <memory>
@@ -26,13 +26,13 @@ namespace hardware {
namespace camera {
namespace implementation {
-class HidlScopedProfiler {
+class AidlScopedProfiler {
public:
- HidlScopedProfiler(std::shared_ptr<google::camera_common::Profiler> profiler,
+ AidlScopedProfiler(std::shared_ptr<google::camera_common::Profiler> profiler,
const std::string name, int id,
std::function<void()> end_callback);
- ~HidlScopedProfiler();
+ ~AidlScopedProfiler();
private:
std::shared_ptr<google::camera_common::Profiler> profiler_;
@@ -41,7 +41,7 @@ class HidlScopedProfiler {
std::function<void()> end_callback_;
};
-class HidlProfiler {
+class AidlProfiler {
public:
enum class ScopedType {
kOpen,
@@ -49,12 +49,12 @@ class HidlProfiler {
kFlush,
kClose,
};
- virtual ~HidlProfiler() = default;
+ virtual ~AidlProfiler() = default;
- static std::shared_ptr<HidlProfiler> Create(uint32_t camera_id);
+ static std::shared_ptr<AidlProfiler> Create(uint32_t camera_id);
// Make a ScopedProfiler for given type.
- virtual std::unique_ptr<HidlScopedProfiler> MakeScopedProfiler(
+ virtual std::unique_ptr<AidlScopedProfiler> MakeScopedProfiler(
ScopedType type,
std::unique_ptr<google::camera_common::Profiler> custom_latency_profiler,
std::unique_ptr<google::camera_common::Profiler> custom_fps_profiler) = 0;
@@ -73,7 +73,7 @@ class HidlProfiler {
virtual int32_t GetFpsFlag() const = 0;
protected:
- HidlProfiler() = default;
+ AidlProfiler() = default;
};
} // namespace implementation
@@ -81,4 +81,4 @@ class HidlProfiler {
} // namespace hardware
} // namespace android
-#endif // HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_PROFILER_H_
+#endif // HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_PROFILER_H_
diff --git a/common/hal/hidl_service/service.cc b/common/hal/aidl_service/aidl_service.cc
index 630869e..91f52b1 100644
--- a/common/hal/hidl_service/service.cc
+++ b/common/hal/aidl_service/aidl_service.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,21 +20,23 @@
#define LOG_TAG "android.hardware.pixel.camera.provider@2.7-service"
#endif
-#include <android/hardware/camera/provider/2.7/ICameraProvider.h>
+#include <aidl/android/hardware/camera/provider/ICameraProvider.h>
+#include <android/binder_manager.h>
+#include <android/binder_process.h>
#include <apex_update_listener.h>
#include <binder/ProcessState.h>
-#include <cinttypes>
#include <cutils/properties.h>
-#include <hidl/HidlLazyUtils.h>
#include <hidl/HidlTransportSupport.h>
#include <malloc.h>
#include <utils/Errors.h>
-#include "hidl_camera_build_version.h"
-#include "hidl_camera_provider.h"
+#include <cinttypes>
+
+#include "aidl_camera_build_version.h"
+#include "aidl_camera_provider.h"
-using ::android::hardware::camera::provider::V2_7::ICameraProvider;
-using ::android::hardware::camera::provider::V2_7::implementation::HidlCameraProvider;
+using aidl::android::hardware::camera::provider::ICameraProvider;
+using ::android::hardware::camera::provider::implementation::AidlCameraProvider;
#ifdef LAZY_SERVICE
const bool kLazyService = true;
@@ -42,6 +44,8 @@ const bool kLazyService = true;
const bool kLazyService = false;
#endif
+const std::string kProviderInstance = "/internal/0";
+
int main() {
ALOGI("Google camera provider service is starting.");
// The camera HAL may communicate to other vendor components via
@@ -51,6 +55,11 @@ int main() {
android::hardware::configureRpcThreadpool(/*maxThreads=*/6,
/*callerWillJoin=*/true);
+ // Don't depend on vndbinder setting up threads in case we stop using them
+ // some day
+ ABinderProcess_setThreadPoolMaxThreadCount(6);
+ ABinderProcess_startThreadPool();
+
#ifdef __ANDROID_APEX__
int start_count = property_get_int32("vendor.camera.hal.start.count", 0);
property_set("vendor.camera.hal.start.count",
@@ -72,25 +81,27 @@ int main() {
ALOGI("Not using ApexUpdateListener since not running in an apex.");
#endif
- android::sp<ICameraProvider> camera_provider = HidlCameraProvider::Create();
+ std::shared_ptr<ICameraProvider> camera_provider =
+ AidlCameraProvider::Create();
if (camera_provider == nullptr) {
return android::NO_INIT;
}
+ std::string instance =
+ std::string() + AidlCameraProvider::descriptor + kProviderInstance;
if (kLazyService) {
- android::hardware::LazyServiceRegistrar& lazy_registrar =
- android::hardware::LazyServiceRegistrar::getInstance();
- if (lazy_registrar.registerService(camera_provider, "internal/0") !=
- android::OK) {
- ALOGE("Cannot register Google camera provider lazy service");
+ if (AServiceManager_registerLazyService(camera_provider->asBinder().get(),
+ instance.c_str()) != STATUS_OK) {
+ ALOGE("Cannot register AIDL Google camera provider lazy service");
return android::NO_INIT;
}
} else {
- if (camera_provider->registerAsService("internal/0") != android::OK) {
- ALOGE("Cannot register Google camera provider service");
+ if (AServiceManager_addService(camera_provider->asBinder().get(),
+ instance.c_str()) != STATUS_OK) {
+ ALOGE("Cannot register AIDL Google camera provider service");
return android::NO_INIT;
}
}
- android::hardware::joinRpcThreadpool();
+ ABinderProcess_joinThreadPool();
// In normal operation, the threadpool should never return.
return EXIT_FAILURE;
diff --git a/common/hal/aidl_service/aidl_utils.cc b/common/hal/aidl_service/aidl_utils.cc
new file mode 100644
index 0000000..2de7617
--- /dev/null
+++ b/common/hal/aidl_service/aidl_utils.cc
@@ -0,0 +1,1156 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "GCH_AidlUtils"
+//#define LOG_NDEBUG 0
+#include "aidl_utils.h"
+
+#include <aidlcommonsupport/NativeHandle.h>
+#include <log/log.h>
+
+#include <regex>
+
+#include "aidl_camera_device.h"
+#include "aidl_camera_provider.h"
+
+namespace android {
+namespace hardware {
+namespace camera {
+namespace implementation {
+namespace aidl_utils {
+
+using AidlCameraProvider = provider::implementation::AidlCameraProvider;
+using AidlCameraDevice = device::implementation::AidlCameraDevice;
+using AidlStatus = aidl::android::hardware::camera::common::Status;
+
+ScopedAStatus ConvertToAidlReturn(status_t hal_status) {
+ switch (hal_status) {
+ case OK:
+ return ScopedAStatus::ok();
+ case BAD_VALUE:
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::ILLEGAL_ARGUMENT));
+ case -EBUSY:
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::CAMERA_IN_USE));
+ case -EUSERS:
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::MAX_CAMERAS_IN_USE));
+ case UNKNOWN_TRANSACTION:
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::METHOD_NOT_SUPPORTED));
+ case INVALID_OPERATION:
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::OPERATION_NOT_SUPPORTED));
+ case DEAD_OBJECT:
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::CAMERA_DISCONNECTED));
+ default:
+ return ScopedAStatus::fromServiceSpecificError(
+ static_cast<int32_t>(Status::INTERNAL_ERROR));
+ }
+}
+
+status_t ConvertToAidlVendorTagType(
+ google_camera_hal::CameraMetadataType hal_type,
+ CameraMetadataType* aidl_type) {
+ if (aidl_type == nullptr) {
+ ALOGE("%s: aidl_type is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ switch (hal_type) {
+ case google_camera_hal::CameraMetadataType::kByte:
+ *aidl_type = CameraMetadataType::BYTE;
+ break;
+ case google_camera_hal::CameraMetadataType::kInt32:
+ *aidl_type = CameraMetadataType::INT32;
+ break;
+ case google_camera_hal::CameraMetadataType::kFloat:
+ *aidl_type = CameraMetadataType::FLOAT;
+ break;
+ case google_camera_hal::CameraMetadataType::kInt64:
+ *aidl_type = CameraMetadataType::INT64;
+ break;
+ case google_camera_hal::CameraMetadataType::kDouble:
+ *aidl_type = CameraMetadataType::DOUBLE;
+ break;
+ case google_camera_hal::CameraMetadataType::kRational:
+ *aidl_type = CameraMetadataType::RATIONAL;
+ break;
+ default:
+ ALOGE("%s: Unknown google_camera_hal::CameraMetadataType: %u",
+ __FUNCTION__, hal_type);
+ return BAD_VALUE;
+ }
+
+ return OK;
+}
+
+status_t ConvertToAidlVendorTagSections(
+ const std::vector<google_camera_hal::VendorTagSection>& hal_sections,
+ std::vector<VendorTagSection>* aidl_sections) {
+ if (aidl_sections == nullptr) {
+ ALOGE("%s: aidl_sections is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ aidl_sections->resize(hal_sections.size());
+ for (uint32_t i = 0; i < hal_sections.size(); i++) {
+ (*aidl_sections)[i].sectionName = hal_sections[i].section_name;
+ (*aidl_sections)[i].tags.resize(hal_sections[i].tags.size());
+
+ for (uint32_t j = 0; j < hal_sections[i].tags.size(); j++) {
+ (*aidl_sections)[i].tags[j].tagId = hal_sections[i].tags[j].tag_id;
+ (*aidl_sections)[i].tags[j].tagName = hal_sections[i].tags[j].tag_name;
+ status_t res =
+ ConvertToAidlVendorTagType(hal_sections[i].tags[j].tag_type,
+ &(*aidl_sections)[i].tags[j].tagType);
+ if (res != OK) {
+ ALOGE("%s: Converting to aidl vendor tag type failed. ", __FUNCTION__);
+ return res;
+ }
+ }
+ }
+ return OK;
+}
+
+status_t ConvertToAidlResourceCost(
+ const google_camera_hal::CameraResourceCost& hal_cost,
+ CameraResourceCost* aidl_cost) {
+ if (aidl_cost == nullptr) {
+ ALOGE("%s: aidl_cost is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ aidl_cost->resourceCost = hal_cost.resource_cost;
+ aidl_cost->conflictingDevices.resize(hal_cost.conflicting_devices.size());
+
+ for (uint32_t i = 0; i < hal_cost.conflicting_devices.size(); i++) {
+ aidl_cost->conflictingDevices[i] =
+ "device@" + AidlCameraDevice::kDeviceVersion + "/" +
+ AidlCameraProvider::kProviderName + "/" +
+ std::to_string(hal_cost.conflicting_devices[i]);
+ }
+
+ return OK;
+}
+
+AidlStatus ConvertToAidlStatus(status_t hal_status) {
+ switch (hal_status) {
+ case OK:
+ return AidlStatus::OK;
+ case BAD_VALUE:
+ return Status::ILLEGAL_ARGUMENT;
+ case -EBUSY:
+ return AidlStatus::CAMERA_IN_USE;
+ case -EUSERS:
+ return AidlStatus::MAX_CAMERAS_IN_USE;
+ case UNKNOWN_TRANSACTION:
+ return AidlStatus::METHOD_NOT_SUPPORTED;
+ case INVALID_OPERATION:
+ return AidlStatus::OPERATION_NOT_SUPPORTED;
+ case DEAD_OBJECT:
+ return AidlStatus::CAMERA_DISCONNECTED;
+ default:
+ return AidlStatus::INTERNAL_ERROR;
+ }
+}
+
+status_t ConvertToHalTemplateType(
+ RequestTemplate aidl_template,
+ google_camera_hal::RequestTemplate* hal_template) {
+ if (hal_template == nullptr) {
+ ALOGE("%s: hal_template is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ switch (aidl_template) {
+ case RequestTemplate::PREVIEW:
+ *hal_template = google_camera_hal::RequestTemplate::kPreview;
+ break;
+ case RequestTemplate::STILL_CAPTURE:
+ *hal_template = google_camera_hal::RequestTemplate::kStillCapture;
+ break;
+ case RequestTemplate::VIDEO_RECORD:
+ *hal_template = google_camera_hal::RequestTemplate::kVideoRecord;
+ break;
+ case RequestTemplate::VIDEO_SNAPSHOT:
+ *hal_template = google_camera_hal::RequestTemplate::kVideoSnapshot;
+ break;
+ case RequestTemplate::ZERO_SHUTTER_LAG:
+ *hal_template = google_camera_hal::RequestTemplate::kZeroShutterLag;
+ break;
+ case RequestTemplate::MANUAL:
+ *hal_template = google_camera_hal::RequestTemplate::kManual;
+ break;
+ default:
+ ALOGE("%s: Unknown AIDL RequestTemplate: %u", __FUNCTION__, aidl_template);
+ return BAD_VALUE;
+ }
+
+ return OK;
+}
+
+status_t ConvertToAidlHalStreamConfig(
+ const std::vector<google_camera_hal::HalStream>& hal_configured_streams,
+ std::vector<HalStream>* aidl_hal_streams) {
+ if (aidl_hal_streams == nullptr) {
+ ALOGE("%s: aidl_hal_streams is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ aidl_hal_streams->resize(hal_configured_streams.size());
+
+ for (uint32_t i = 0; i < hal_configured_streams.size(); i++) {
+ auto& dst = (*aidl_hal_streams)[i];
+ dst.supportOffline = false;
+ if (hal_configured_streams[i].is_physical_camera_stream) {
+ dst.physicalCameraId =
+ std::to_string(hal_configured_streams[i].physical_camera_id);
+ }
+
+ dst.overrideDataSpace =
+ static_cast<aidl::android::hardware::graphics::common::Dataspace>(
+ hal_configured_streams[i].override_data_space);
+
+ dst.id = hal_configured_streams[i].id;
+
+ dst.overrideFormat =
+ static_cast<aidl::android::hardware::graphics::common::PixelFormat>(
+ hal_configured_streams[i].override_format);
+
+ dst.producerUsage =
+ static_cast<aidl::android::hardware::graphics::common::BufferUsage>(
+ hal_configured_streams[i].producer_usage);
+
+ dst.consumerUsage =
+ static_cast<aidl::android::hardware::graphics::common::BufferUsage>(
+ hal_configured_streams[i].consumer_usage);
+
+ dst.maxBuffers = hal_configured_streams[i].max_buffers;
+ }
+
+ return OK;
+}
+
+status_t WriteToResultMetadataQueue(
+ camera_metadata_t* metadata,
+ AidlMessageQueue<int8_t, SynchronizedReadWrite>* result_metadata_queue) {
+ if (result_metadata_queue == nullptr) {
+ return BAD_VALUE;
+ }
+
+ if (result_metadata_queue->availableToWrite() <= 0) {
+ ALOGW("%s: result_metadata_queue is not available to write", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ uint32_t size = get_camera_metadata_size(metadata);
+ bool success = result_metadata_queue->write(
+ reinterpret_cast<const int8_t*>(metadata), size);
+ if (!success) {
+ ALOGW("%s: Writing to result metadata queue failed. (size=%u)",
+ __FUNCTION__, size);
+ return INVALID_OPERATION;
+ }
+
+ return OK;
+}
+
+// Try writing result metadata to result metadata queue. If failed, return
+// the metadata to the caller in out_hal_metadata.
+status_t TryWritingToResultMetadataQueue(
+ std::unique_ptr<google_camera_hal::HalCameraMetadata> hal_metadata,
+ AidlMessageQueue<int8_t, SynchronizedReadWrite>* result_metadata_queue,
+ uint64_t* fmq_result_size,
+ std::unique_ptr<google_camera_hal::HalCameraMetadata>* out_hal_metadata) {
+ if (out_hal_metadata == nullptr) {
+ ALOGE("%s: out_hal_metadata is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ *out_hal_metadata = std::move(hal_metadata);
+
+ if (fmq_result_size == nullptr) {
+ ALOGE("%s: fmq_result_size is nullptr", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ *fmq_result_size = 0;
+ if (*out_hal_metadata == nullptr) {
+ return OK;
+ }
+
+ camera_metadata_t* metadata = (*out_hal_metadata)->ReleaseCameraMetadata();
+ // Temporarily use the raw metadata to write to metadata queue.
+ status_t res = WriteToResultMetadataQueue(metadata, result_metadata_queue);
+ *out_hal_metadata = google_camera_hal::HalCameraMetadata::Create(metadata);
+
+ if (res != OK) {
+ ALOGW("%s: Writing to result metadata queue failed: %s(%d)", __FUNCTION__,
+ strerror(-res), res);
+ return res;
+ }
+
+ *fmq_result_size = (*out_hal_metadata)->GetCameraMetadataSize();
+ *out_hal_metadata = nullptr;
+ return OK;
+}
+
+status_t ConvertToAidlResultMetadata(
+ AidlMessageQueue<int8_t, SynchronizedReadWrite>* result_metadata_queue,
+ std::unique_ptr<google_camera_hal::HalCameraMetadata> hal_metadata,
+ std::vector<uint8_t>* aidl_metadata, uint64_t* fmq_result_size) {
+ if (TryWritingToResultMetadataQueue(std::move(hal_metadata),
+ result_metadata_queue, fmq_result_size,
+ &hal_metadata) == OK) {
+ return OK;
+ }
+
+ // If writing to metadata queue failed, attach the metadata to aidl_metadata.
+ if (aidl_metadata == nullptr) {
+ ALOGE("%s: aidl_metadata is nullptr", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ uint32_t metadata_size = hal_metadata->GetCameraMetadataSize();
+ uint8_t* metadata_p =
+ reinterpret_cast<uint8_t*>(hal_metadata->ReleaseCameraMetadata());
+ // TODO: Do we reallly need to copy here ?
+ aidl_metadata->assign(metadata_p, metadata_p + metadata_size);
+
+ return OK;
+}
+
+status_t ConvertToAidlBufferStatus(google_camera_hal::BufferStatus hal_status,
+ BufferStatus* aidl_status) {
+ if (aidl_status == nullptr) {
+ ALOGE("%s: aidl_status is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ switch (hal_status) {
+ case google_camera_hal::BufferStatus::kOk:
+ *aidl_status = BufferStatus::OK;
+ break;
+ case google_camera_hal::BufferStatus::kError:
+ *aidl_status = BufferStatus::ERROR;
+ break;
+ default:
+ ALOGE("%s: Unknown HAL buffer status: %u", __FUNCTION__, hal_status);
+ return BAD_VALUE;
+ }
+
+ return OK;
+}
+
+aidl::android::hardware::common::NativeHandle makeToAidlIfNotNull(
+ const native_handle_t* nh) {
+ if (nh == nullptr) {
+ return aidl::android::hardware::common::NativeHandle();
+ }
+ return makeToAidl(nh);
+}
+
+status_t ConvertToAidlStreamBuffer(
+ const google_camera_hal::StreamBuffer& hal_buffer,
+ StreamBuffer* aidl_buffer) {
+ if (aidl_buffer == nullptr) {
+ ALOGE("%s: aidl_buffer is nullptr", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ aidl_buffer->streamId = hal_buffer.stream_id;
+ aidl_buffer->bufferId = hal_buffer.buffer_id;
+ aidl_buffer->buffer = aidl::android::hardware::common::NativeHandle();
+
+ status_t res =
+ ConvertToAidlBufferStatus(hal_buffer.status, &aidl_buffer->status);
+ if (res != OK) {
+ ALOGE("%s: Converting to AIDL buffer status failed: %s(%d)", __FUNCTION__,
+ strerror(-res), res);
+ return res;
+ }
+
+ aidl_buffer->acquireFence = aidl::android::hardware::common::NativeHandle();
+ aidl_buffer->releaseFence = makeToAidlIfNotNull(hal_buffer.release_fence);
+ return OK;
+}
+
+status_t ConvertToAidlCaptureResultInternal(
+ AidlMessageQueue<int8_t, SynchronizedReadWrite>* result_metadata_queue,
+ google_camera_hal::CaptureResult* hal_result, CaptureResult* aidl_result) {
+ if (aidl_result == nullptr) {
+ ALOGE("%s: aidl_result is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ if (hal_result == nullptr) {
+ ALOGE("%s: hal_result is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ aidl_result->frameNumber = hal_result->frame_number;
+
+ status_t res = ConvertToAidlResultMetadata(
+ result_metadata_queue, std::move(hal_result->result_metadata),
+ &aidl_result->result.metadata, (uint64_t*)&aidl_result->fmqResultSize);
+ if (res != OK) {
+ ALOGE("%s: Converting to AIDL result metadata failed: %s(%d).",
+ __FUNCTION__, strerror(-res), res);
+ return res;
+ }
+
+ aidl_result->outputBuffers.resize(hal_result->output_buffers.size());
+ for (uint32_t i = 0; i < aidl_result->outputBuffers.size(); i++) {
+ res = ConvertToAidlStreamBuffer(hal_result->output_buffers[i],
+ &aidl_result->outputBuffers[i]);
+ if (res != OK) {
+ ALOGE("%s: Converting to AIDL output stream buffer failed: %s(%d)",
+ __FUNCTION__, strerror(-res), res);
+ return res;
+ }
+ }
+
+ uint32_t num_input_buffers = hal_result->input_buffers.size();
+ if (num_input_buffers > 0) {
+ if (num_input_buffers > 1) {
+ ALOGW("%s: HAL result should not have more than 1 input buffer. (=%u)",
+ __FUNCTION__, num_input_buffers);
+ }
+
+ res = ConvertToAidlStreamBuffer(hal_result->input_buffers[0],
+ &aidl_result->inputBuffer);
+ if (res != OK) {
+ ALOGE("%s: Converting to AIDL input stream buffer failed: %s(%d)",
+ __FUNCTION__, strerror(-res), res);
+ return res;
+ }
+ } else {
+ aidl_result->inputBuffer.streamId = -1;
+ }
+
+ aidl_result->partialResult = hal_result->partial_result;
+ return OK;
+}
+
+status_t ConvertToAidlCaptureResult(
+ AidlMessageQueue<int8_t, SynchronizedReadWrite>* result_metadata_queue,
+ std::unique_ptr<google_camera_hal::CaptureResult> hal_result,
+ CaptureResult* aidl_result) {
+ if (aidl_result == nullptr) {
+ ALOGE("%s: aidl_result is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ if (hal_result == nullptr) {
+ ALOGE("%s: hal_result is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ status_t res = ConvertToAidlCaptureResultInternal(
+ result_metadata_queue, hal_result.get(), aidl_result);
+ if (res != OK) {
+ ALOGE("%s: Converting to AIDL result internal failed: %s(%d).",
+ __FUNCTION__, strerror(-res), res);
+ return res;
+ }
+
+ uint32_t num_physical_metadata = hal_result->physical_metadata.size();
+ aidl_result->physicalCameraMetadata.resize(num_physical_metadata);
+
+ for (uint32_t i = 0; i < num_physical_metadata; i++) {
+ aidl_result->physicalCameraMetadata[i].physicalCameraId =
+ std::to_string(hal_result->physical_metadata[i].physical_camera_id);
+
+ res = ConvertToAidlResultMetadata(
+ result_metadata_queue,
+ std::move(hal_result->physical_metadata[i].metadata),
+ &aidl_result->physicalCameraMetadata[i].metadata.metadata,
+ (uint64_t*)&aidl_result->physicalCameraMetadata[i].fmqMetadataSize);
+ if (res != OK) {
+ ALOGE("%s: Converting to AIDL physical metadata failed: %s(%d).",
+ __FUNCTION__, strerror(-res), res);
+ return res;
+ }
+ }
+
+ return OK;
+}
+
+status_t ConvertToAidlErrorMessage(
+ const google_camera_hal::ErrorMessage& hal_error, NotifyMsg* aidl_msg) {
+ using Tag = aidl::android::hardware::camera::device::NotifyMsg::Tag;
+ if (aidl_msg == nullptr) {
+ ALOGE("%s: aidl_msg is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ ErrorMsg aidl_error;
+ aidl_error.frameNumber = hal_error.frame_number;
+ aidl_error.errorStreamId = hal_error.error_stream_id;
+
+ switch (hal_error.error_code) {
+ case google_camera_hal::ErrorCode::kErrorDevice:
+ aidl_error.errorCode = ErrorCode::ERROR_DEVICE;
+ break;
+ case google_camera_hal::ErrorCode::kErrorRequest:
+ aidl_error.errorCode = ErrorCode::ERROR_REQUEST;
+ break;
+ case google_camera_hal::ErrorCode::kErrorResult:
+ aidl_error.errorCode = ErrorCode::ERROR_RESULT;
+ break;
+ case google_camera_hal::ErrorCode::kErrorBuffer:
+ aidl_error.errorCode = ErrorCode::ERROR_BUFFER;
+ break;
+ default:
+ ALOGE("%s: Unknown error code: %u", __FUNCTION__, hal_error.error_code);
+ return BAD_VALUE;
+ }
+ aidl_msg->set<Tag::error>(aidl_error);
+ return OK;
+}
+
+status_t ConvertToAidlShutterMessage(
+ const google_camera_hal::ShutterMessage& hal_shutter, NotifyMsg* aidl_msg) {
+ using Tag = aidl::android::hardware::camera::device::NotifyMsg::Tag;
+ if (aidl_msg == nullptr) {
+ ALOGE("%s: aidl_msg is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+ ShutterMsg aidl_shutter;
+ aidl_shutter.frameNumber = hal_shutter.frame_number;
+ aidl_shutter.timestamp = hal_shutter.timestamp_ns;
+ aidl_shutter.readoutTimestamp = hal_shutter.readout_timestamp_ns;
+ aidl_msg->set<Tag::shutter>(aidl_shutter);
+ return OK;
+}
+
+status_t ConverToAidlNotifyMessage(
+ const google_camera_hal::NotifyMessage& hal_message,
+ NotifyMsg* aidl_message) {
+ if (aidl_message == nullptr) {
+ ALOGE("%s: aidl_message is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ status_t res;
+ switch (hal_message.type) {
+ case google_camera_hal::MessageType::kError:
+ res = ConvertToAidlErrorMessage(hal_message.message.error, aidl_message);
+ if (res != OK) {
+ ALOGE("%s: Converting to AIDL error message failed: %s(%d)",
+ __FUNCTION__, strerror(-res), res);
+ return res;
+ }
+ break;
+ case google_camera_hal::MessageType::kShutter:
+ res = ConvertToAidlShutterMessage(hal_message.message.shutter,
+ aidl_message);
+ if (res != OK) {
+ ALOGE("%s: Converting to AIDL shutter message failed: %s(%d)",
+ __FUNCTION__, strerror(-res), res);
+ return res;
+ }
+ break;
+ default:
+ ALOGE("%s: Unknown message type: %u", __FUNCTION__, hal_message.type);
+ return BAD_VALUE;
+ }
+
+ return OK;
+}
+
+status_t ConvertToAidlCameraDeviceStatus(
+ google_camera_hal::CameraDeviceStatus hal_camera_device_status,
+ CameraDeviceStatus* aidl_camera_device_status) {
+ if (aidl_camera_device_status == nullptr) {
+ ALOGE("%s: aidl_camera_device_status is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ switch (hal_camera_device_status) {
+ case google_camera_hal::CameraDeviceStatus::kNotPresent:
+ *aidl_camera_device_status = CameraDeviceStatus::NOT_PRESENT;
+ break;
+ case google_camera_hal::CameraDeviceStatus::kPresent:
+ *aidl_camera_device_status = CameraDeviceStatus::PRESENT;
+ break;
+ case google_camera_hal::CameraDeviceStatus::kEnumerating:
+ *aidl_camera_device_status = CameraDeviceStatus::ENUMERATING;
+ break;
+ default:
+ ALOGE("%s: Unknown HAL camera device status: %u", __FUNCTION__,
+ hal_camera_device_status);
+ return BAD_VALUE;
+ }
+
+ return OK;
+}
+
+status_t ConvertToAidlTorchModeStatus(
+ google_camera_hal::TorchModeStatus hal_torch_status,
+ TorchModeStatus* aidl_torch_status) {
+ if (aidl_torch_status == nullptr) {
+ ALOGE("%s: aidl_torch_status is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ switch (hal_torch_status) {
+ case google_camera_hal::TorchModeStatus::kNotAvailable:
+ *aidl_torch_status = TorchModeStatus::NOT_AVAILABLE;
+ break;
+ case google_camera_hal::TorchModeStatus::kAvailableOff:
+ *aidl_torch_status = TorchModeStatus::AVAILABLE_OFF;
+ break;
+ case google_camera_hal::TorchModeStatus::kAvailableOn:
+ *aidl_torch_status = TorchModeStatus::AVAILABLE_ON;
+ break;
+ default:
+ ALOGE("%s: Unknown HAL torch mode status: %u", __FUNCTION__,
+ hal_torch_status);
+ return BAD_VALUE;
+ }
+
+ return OK;
+}
+
+status_t ConvertToAidlBufferRequest(
+ const std::vector<google_camera_hal::BufferRequest>& hal_buffer_requests,
+ std::vector<BufferRequest>* aidl_buffer_requests) {
+ if (aidl_buffer_requests == nullptr) {
+ ALOGE("%s: aidl_buffer_request is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ aidl_buffer_requests->resize(hal_buffer_requests.size());
+ for (uint32_t i = 0; i < hal_buffer_requests.size(); i++) {
+ (*aidl_buffer_requests)[i].streamId = hal_buffer_requests[i].stream_id;
+ (*aidl_buffer_requests)[i].numBuffersRequested =
+ hal_buffer_requests[i].num_buffers_requested;
+ }
+ return OK;
+}
+
+status_t ConvertToHalBufferStatus(BufferStatus aidl_status,
+ google_camera_hal::BufferStatus* hal_status) {
+ if (hal_status == nullptr) {
+ ALOGE("%s: hal_status is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ switch (aidl_status) {
+ case BufferStatus::OK:
+ *hal_status = google_camera_hal::BufferStatus::kOk;
+ break;
+ case BufferStatus::ERROR:
+ *hal_status = google_camera_hal::BufferStatus::kError;
+ break;
+ default:
+ ALOGE("%s: Unknown AIDL buffer status: %u", __FUNCTION__, aidl_status);
+ return BAD_VALUE;
+ }
+
+ return OK;
+}
+
+bool IsAidlNativeHandleNull(const NativeHandle& handle) {
+ return (handle.fds.size() == 0 && handle.ints.size() == 0);
+}
+
+native_handle_t* makeFromAidlIfNotNull(const NativeHandle& handle) {
+ if (IsAidlNativeHandleNull(handle)) {
+ return nullptr;
+ }
+ return makeFromAidl(handle);
+}
+
+// We have a handles_to_delete parameter since makeFromAidl creates a
+// native_handle_t
+status_t ConvertToHalStreamBuffer(
+ const StreamBuffer& aidl_buffer, google_camera_hal::StreamBuffer* hal_buffer,
+ std::vector<native_handle_t*>* handles_to_delete) {
+ if (hal_buffer == nullptr || handles_to_delete == nullptr) {
+ ALOGE("%s: hal_buffer / handles_to_delete is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ hal_buffer->stream_id = aidl_buffer.streamId;
+ hal_buffer->buffer_id = aidl_buffer.bufferId;
+ native_handle_t* buf_handle = makeFromAidlIfNotNull(aidl_buffer.buffer);
+ hal_buffer->buffer = buf_handle;
+ if (buf_handle != nullptr) {
+ handles_to_delete->emplace_back(buf_handle);
+ }
+
+ status_t res =
+ ConvertToHalBufferStatus(aidl_buffer.status, &hal_buffer->status);
+ if (res != OK) {
+ ALOGE("%s: Converting to HAL buffer status failed: %s(%d)", __FUNCTION__,
+ strerror(-res), res);
+ return res;
+ }
+
+ native_handle_t* acquire_handle =
+ makeFromAidlIfNotNull(aidl_buffer.acquireFence);
+ native_handle_t* release_handle =
+ makeFromAidlIfNotNull(aidl_buffer.releaseFence);
+ hal_buffer->acquire_fence = acquire_handle;
+ hal_buffer->release_fence = release_handle;
+ if (acquire_handle != nullptr) {
+ handles_to_delete->emplace_back(acquire_handle);
+ }
+
+ if (release_handle != nullptr) {
+ handles_to_delete->emplace_back(release_handle);
+ }
+
+ return OK;
+}
+
+status_t ConvertToHalMetadata(
+ uint32_t message_queue_setting_size,
+ AidlMessageQueue<int8_t, SynchronizedReadWrite>* request_metadata_queue,
+ const std::vector<uint8_t>& request_settings,
+ std::unique_ptr<google_camera_hal::HalCameraMetadata>* hal_metadata) {
+ if (hal_metadata == nullptr) {
+ ALOGE("%s: hal_metadata is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ const camera_metadata_t* metadata = nullptr;
+ std::vector<int8_t> metadata_queue_settings;
+
+ if (message_queue_setting_size == 0) {
+ // Use the settings in the request.
+ if (request_settings.size() != 0) {
+ metadata =
+ reinterpret_cast<const camera_metadata_t*>(request_settings.data());
+ }
+ } else {
+ // Read the settings from request metadata queue.
+ if (request_metadata_queue == nullptr) {
+ ALOGE("%s: request_metadata_queue is nullptr", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ metadata_queue_settings.resize(message_queue_setting_size);
+ bool success = request_metadata_queue->read(metadata_queue_settings.data(),
+ message_queue_setting_size);
+ if (!success) {
+ ALOGE("%s: Failed to read from request metadata queue.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ metadata = reinterpret_cast<const camera_metadata_t*>(
+ metadata_queue_settings.data());
+ }
+
+ if (metadata == nullptr) {
+ *hal_metadata = nullptr;
+ return OK;
+ }
+
+ *hal_metadata = google_camera_hal::HalCameraMetadata::Clone(metadata);
+ return OK;
+}
+
+status_t ConvertToHalCaptureRequest(
+ const CaptureRequest& aidl_request,
+ AidlMessageQueue<int8_t, SynchronizedReadWrite>* request_metadata_queue,
+ google_camera_hal::CaptureRequest* hal_request,
+ std::vector<native_handle_t*>* handles_to_delete) {
+ if (hal_request == nullptr) {
+ ALOGE("%s: hal_request is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ hal_request->frame_number = aidl_request.frameNumber;
+
+ status_t res = ConvertToHalMetadata(
+ aidl_request.fmqSettingsSize, request_metadata_queue,
+ aidl_request.settings.metadata, &hal_request->settings);
+ if (res != OK) {
+ ALOGE("%s: Converting metadata failed: %s(%d)", __FUNCTION__,
+ strerror(-res), res);
+ return res;
+ }
+
+ google_camera_hal::StreamBuffer hal_buffer = {};
+ if (!IsAidlNativeHandleNull(aidl_request.inputBuffer.buffer)) {
+ res = ConvertToHalStreamBuffer(aidl_request.inputBuffer, &hal_buffer,
+ handles_to_delete);
+ if (res != OK) {
+ ALOGE("%s: Converting hal stream buffer failed: %s(%d)", __FUNCTION__,
+ strerror(-res), res);
+ return res;
+ }
+
+ hal_request->input_buffers.push_back(hal_buffer);
+ hal_request->input_width = aidl_request.inputWidth;
+ hal_request->input_height = aidl_request.inputHeight;
+ }
+
+ for (auto& buffer : aidl_request.outputBuffers) {
+ hal_buffer = {};
+ status_t res =
+ ConvertToHalStreamBuffer(buffer, &hal_buffer, handles_to_delete);
+ if (res != OK) {
+ ALOGE("%s: Converting hal stream buffer failed: %s(%d)", __FUNCTION__,
+ strerror(-res), res);
+ return res;
+ }
+
+ hal_request->output_buffers.push_back(hal_buffer);
+ }
+
+ for (auto aidl_physical_settings : aidl_request.physicalCameraSettings) {
+ std::unique_ptr<google_camera_hal::HalCameraMetadata> hal_physical_settings;
+ res = ConvertToHalMetadata(
+ aidl_physical_settings.fmqSettingsSize, request_metadata_queue,
+ aidl_physical_settings.settings.metadata, &hal_physical_settings);
+ if (res != OK) {
+ ALOGE("%s: Converting to HAL metadata failed: %s(%d)", __FUNCTION__,
+ strerror(-res), res);
+ return res;
+ }
+
+ uint32_t camera_id = std::stoul(aidl_physical_settings.physicalCameraId);
+ hal_request->physical_camera_settings.emplace(
+ camera_id, std::move(hal_physical_settings));
+ }
+
+ return OK;
+}
+
+status_t ConvertToHalBufferCaches(
+ const std::vector<BufferCache>& aidl_buffer_caches,
+ std::vector<google_camera_hal::BufferCache>* hal_buffer_caches) {
+ if (hal_buffer_caches == nullptr) {
+ ALOGE("%s: hal_buffer_caches is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ for (auto aidl_cache : aidl_buffer_caches) {
+ google_camera_hal::BufferCache hal_cache;
+ hal_cache.stream_id = aidl_cache.streamId;
+ hal_cache.buffer_id = aidl_cache.bufferId;
+
+ hal_buffer_caches->push_back(hal_cache);
+ }
+
+ return OK;
+}
+
+status_t ConvertToHalStreamConfigurationMode(
+ StreamConfigurationMode aidl_mode,
+ google_camera_hal::StreamConfigurationMode* hal_mode) {
+ if (hal_mode == nullptr) {
+ ALOGE("%s: hal_mode is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ switch (aidl_mode) {
+ case StreamConfigurationMode::NORMAL_MODE:
+ *hal_mode = google_camera_hal::StreamConfigurationMode::kNormal;
+ break;
+ case StreamConfigurationMode::CONSTRAINED_HIGH_SPEED_MODE:
+ *hal_mode =
+ google_camera_hal::StreamConfigurationMode::kConstrainedHighSpeed;
+ break;
+ default:
+ ALOGE("%s: Unknown configuration mode %u", __FUNCTION__, aidl_mode);
+ return BAD_VALUE;
+ }
+
+ return OK;
+}
+
+static bool sensorPixelModeContains(const Stream& aidl_stream, uint32_t key) {
+ using aidl::android::hardware::camera::metadata::SensorPixelMode;
+ for (auto& i : aidl_stream.sensorPixelModesUsed) {
+ if (i == static_cast<SensorPixelMode>(key)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+status_t ConvertToHalStreamConfig(
+ const StreamConfiguration& aidl_stream_config,
+ google_camera_hal::StreamConfiguration* hal_stream_config) {
+ if (hal_stream_config == nullptr) {
+ ALOGE("%s: hal_stream_config is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ status_t res;
+
+ for (auto aidl_stream : aidl_stream_config.streams) {
+ google_camera_hal::Stream hal_stream;
+ res = ConvertToHalStream(aidl_stream, &hal_stream);
+ if (res != OK) {
+ ALOGE("%s: Converting to HAL stream failed: %s(%d)", __FUNCTION__,
+ strerror(-res), res);
+ return res;
+ }
+ hal_stream_config->streams.push_back(hal_stream);
+ }
+
+ res = ConvertToHalStreamConfigurationMode(aidl_stream_config.operationMode,
+ &hal_stream_config->operation_mode);
+ if (res != OK) {
+ ALOGE("%s: Converting to HAL opeation mode failed: %s(%d)", __FUNCTION__,
+ strerror(-res), res);
+ return res;
+ }
+
+ res = ConvertToHalMetadata(0, nullptr,
+ aidl_stream_config.sessionParams.metadata,
+ &hal_stream_config->session_params);
+ if (res != OK) {
+ ALOGE("%s: Converting to HAL metadata failed: %s(%d)", __FUNCTION__,
+ strerror(-res), res);
+ return res;
+ }
+
+ hal_stream_config->stream_config_counter =
+ aidl_stream_config.streamConfigCounter;
+ hal_stream_config->multi_resolution_input_image =
+ aidl_stream_config.multiResolutionInputImage;
+
+ return OK;
+}
+
+status_t ConvertToHalStreamType(StreamType aidl_stream_type,
+ google_camera_hal::StreamType* hal_stream_type) {
+ if (hal_stream_type == nullptr) {
+ ALOGE("%s: hal_stream_type is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ switch (aidl_stream_type) {
+ case StreamType::OUTPUT:
+ *hal_stream_type = google_camera_hal::StreamType::kOutput;
+ break;
+ case StreamType::INPUT:
+ *hal_stream_type = google_camera_hal::StreamType::kInput;
+ break;
+ default:
+ ALOGE("%s: Unknown stream type: %u", __FUNCTION__, aidl_stream_type);
+ return BAD_VALUE;
+ }
+
+ return OK;
+}
+
+status_t ConvertToHalStreamRotation(
+ StreamRotation aidl_stream_rotation,
+ google_camera_hal::StreamRotation* hal_stream_rotation) {
+ if (hal_stream_rotation == nullptr) {
+ ALOGE("%s: hal_stream_rotation is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ switch (aidl_stream_rotation) {
+ case StreamRotation::ROTATION_0:
+ *hal_stream_rotation = google_camera_hal::StreamRotation::kRotation0;
+ break;
+ case StreamRotation::ROTATION_90:
+ *hal_stream_rotation = google_camera_hal::StreamRotation::kRotation90;
+ break;
+ case StreamRotation::ROTATION_180:
+ *hal_stream_rotation = google_camera_hal::StreamRotation::kRotation180;
+ break;
+ case StreamRotation::ROTATION_270:
+ *hal_stream_rotation = google_camera_hal::StreamRotation::kRotation270;
+ break;
+ default:
+ ALOGE("%s: Unknown stream rotation: %u", __FUNCTION__,
+ aidl_stream_rotation);
+ return BAD_VALUE;
+ }
+
+ return OK;
+}
+
+status_t ConvertToHalStream(const Stream& aidl_stream,
+ google_camera_hal::Stream* hal_stream) {
+ if (hal_stream == nullptr) {
+ ALOGE("%s: hal_stream is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ *hal_stream = {};
+
+ hal_stream->id = aidl_stream.id;
+
+ status_t res =
+ ConvertToHalStreamType(aidl_stream.streamType, &hal_stream->stream_type);
+ if (res != OK) {
+ ALOGE("%s: Converting to HAL stream type failed: %s(%d)", __FUNCTION__,
+ strerror(-res), res);
+ return res;
+ }
+
+ hal_stream->width = aidl_stream.width;
+ hal_stream->height = aidl_stream.height;
+ hal_stream->format = (android_pixel_format_t)aidl_stream.format;
+ hal_stream->usage = (uint64_t)aidl_stream.usage;
+ hal_stream->data_space = (android_dataspace_t)aidl_stream.dataSpace;
+
+ res = ConvertToHalStreamRotation(aidl_stream.rotation, &hal_stream->rotation);
+ if (res != OK) {
+ ALOGE("%s: Converting to HAL stream rotation failed: %s(%d)", __FUNCTION__,
+ strerror(-res), res);
+ return res;
+ }
+
+ if (aidl_stream.physicalCameraId.empty()) {
+ hal_stream->is_physical_camera_stream = false;
+ } else {
+ hal_stream->is_physical_camera_stream = true;
+ hal_stream->physical_camera_id = std::stoul(aidl_stream.physicalCameraId);
+ }
+
+ hal_stream->buffer_size = aidl_stream.bufferSize;
+ hal_stream->group_id = aidl_stream.groupId;
+
+ hal_stream->used_in_max_resolution_mode = sensorPixelModeContains(
+ aidl_stream, ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION);
+ hal_stream->used_in_default_resolution_mode =
+ aidl_stream.sensorPixelModesUsed.size() > 0
+ ? sensorPixelModeContains(aidl_stream,
+ ANDROID_SENSOR_PIXEL_MODE_DEFAULT)
+ : true;
+ hal_stream->dynamic_profile = static_cast<
+ camera_metadata_enum_android_request_available_dynamic_range_profiles_map>(
+ aidl_stream.dynamicRangeProfile);
+
+ hal_stream->use_case =
+ static_cast<camera_metadata_enum_android_scaler_available_stream_use_cases>(
+ aidl_stream.useCase);
+
+ return OK;
+}
+
+status_t ConvertToHalBufferRequestStatus(
+ const BufferRequestStatus& aidl_buffer_request_status,
+ google_camera_hal::BufferRequestStatus* hal_buffer_request_status) {
+ if (hal_buffer_request_status == nullptr) {
+ ALOGE("%s: hal_buffer_request_status is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ switch (aidl_buffer_request_status) {
+ case BufferRequestStatus::OK:
+ *hal_buffer_request_status = google_camera_hal::BufferRequestStatus::kOk;
+ break;
+ case BufferRequestStatus::FAILED_PARTIAL:
+ *hal_buffer_request_status =
+ google_camera_hal::BufferRequestStatus::kFailedPartial;
+ break;
+ case BufferRequestStatus::FAILED_CONFIGURING:
+ *hal_buffer_request_status =
+ google_camera_hal::BufferRequestStatus::kFailedConfiguring;
+ break;
+ case BufferRequestStatus::FAILED_ILLEGAL_ARGUMENTS:
+ *hal_buffer_request_status =
+ google_camera_hal::BufferRequestStatus::kFailedIllegalArgs;
+ break;
+ case BufferRequestStatus::FAILED_UNKNOWN:
+ *hal_buffer_request_status =
+ google_camera_hal::BufferRequestStatus::kFailedUnknown;
+ break;
+ default:
+ ALOGE("%s: Failed unknown buffer request error code %d", __FUNCTION__,
+ aidl_buffer_request_status);
+ return BAD_VALUE;
+ }
+
+ return OK;
+}
+
+status_t ConvertToHalBufferReturnStatus(
+ const StreamBufferRet& aidl_stream_buffer_return,
+ google_camera_hal::BufferReturn* hal_buffer_return) {
+ using Tag = aidl::android::hardware::camera::device::StreamBuffersVal::Tag;
+ if (hal_buffer_return == nullptr) {
+ ALOGE("%s: hal_buffer_return is nullptr.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ if (aidl_stream_buffer_return.val.getTag() == Tag::error) {
+ switch (aidl_stream_buffer_return.val.get<Tag::error>()) {
+ case StreamBufferRequestError::NO_BUFFER_AVAILABLE:
+ hal_buffer_return->val.error =
+ google_camera_hal::StreamBufferRequestError::kNoBufferAvailable;
+ break;
+ case StreamBufferRequestError::MAX_BUFFER_EXCEEDED:
+ hal_buffer_return->val.error =
+ google_camera_hal::StreamBufferRequestError::kMaxBufferExceeded;
+ break;
+ case StreamBufferRequestError::STREAM_DISCONNECTED:
+ hal_buffer_return->val.error =
+ google_camera_hal::StreamBufferRequestError::kStreamDisconnected;
+ break;
+ case StreamBufferRequestError::UNKNOWN_ERROR:
+ hal_buffer_return->val.error =
+ google_camera_hal::StreamBufferRequestError::kUnknownError;
+ break;
+ default:
+ ALOGE("%s: Unknown StreamBufferRequestError %d", __FUNCTION__,
+ aidl_stream_buffer_return.val.get<Tag::error>());
+ return BAD_VALUE;
+ }
+ } else {
+ hal_buffer_return->val.error =
+ google_camera_hal::StreamBufferRequestError::kOk;
+ }
+
+ return OK;
+}
+
+status_t ConvertToHalDeviceState(
+ int64_t aidl_device_state,
+ google_camera_hal::DeviceState& hal_device_state) {
+ switch (aidl_device_state) {
+ case ICameraProvider::DEVICE_STATE_NORMAL:
+ hal_device_state = google_camera_hal::DeviceState::kNormal;
+ break;
+ case ICameraProvider::DEVICE_STATE_BACK_COVERED:
+ hal_device_state = google_camera_hal::DeviceState::kBackCovered;
+ break;
+ case ICameraProvider::DEVICE_STATE_FRONT_COVERED:
+ hal_device_state = google_camera_hal::DeviceState::kFrontCovered;
+ break;
+ case ICameraProvider::DEVICE_STATE_FOLDED:
+ hal_device_state = google_camera_hal::DeviceState::kFolded;
+ break;
+ default:
+ ALOGE("%s: Failed unknown device state", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ return OK;
+}
+
+} // namespace aidl_utils
+} // namespace implementation
+} // namespace camera
+} // namespace hardware
+} // namespace android
diff --git a/common/hal/aidl_service/aidl_utils.h b/common/hal/aidl_service/aidl_utils.h
new file mode 100644
index 0000000..05873f3
--- /dev/null
+++ b/common/hal/aidl_service/aidl_utils.h
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_UTILS_H_
+#define HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_UTILS_H_
+
+#include <aidl/android/hardware/camera/common/CameraMetadataType.h>
+#include <aidl/android/hardware/camera/common/Status.h>
+#include <aidl/android/hardware/camera/device/ICameraDevice.h>
+#include <aidl/android/hardware/camera/provider/ICameraProvider.h>
+#include <aidlcommonsupport/NativeHandle.h>
+/*#include <android/hardware/camera/common/1.0/types.h>
+#include <android/hardware/camera/device/3.7/ICameraDeviceSession.h>
+#include <android/hardware/camera/device/3.8/types.h>*/
+#include <fmq/AidlMessageQueue.h>
+#include <fmq/MessageQueue.h>
+#include <hal_types.h>
+
+#include <memory>
+
+#include "aidl_camera_provider.h"
+
+namespace android {
+namespace hardware {
+namespace camera {
+namespace implementation {
+namespace aidl_utils {
+
+using aidl::android::hardware::camera::common::CameraDeviceStatus;
+using aidl::android::hardware::camera::common::CameraMetadataType;
+using aidl::android::hardware::camera::common::CameraResourceCost;
+using aidl::android::hardware::camera::common::Status;
+using aidl::android::hardware::camera::common::TorchModeStatus;
+using aidl::android::hardware::camera::common::VendorTagSection;
+using aidl::android::hardware::camera::device::BufferCache;
+using aidl::android::hardware::camera::device::BufferRequest;
+using aidl::android::hardware::camera::device::BufferRequestStatus;
+using aidl::android::hardware::camera::device::BufferStatus;
+using aidl::android::hardware::camera::device::CaptureRequest;
+using aidl::android::hardware::camera::device::CaptureResult;
+using aidl::android::hardware::camera::device::ErrorCode;
+using aidl::android::hardware::camera::device::ErrorMsg;
+using aidl::android::hardware::camera::device::HalStream;
+using aidl::android::hardware::camera::device::NotifyMsg;
+using aidl::android::hardware::camera::device::RequestTemplate;
+using aidl::android::hardware::camera::device::ShutterMsg;
+using aidl::android::hardware::camera::device::Stream;
+using aidl::android::hardware::camera::device::StreamBuffer;
+using aidl::android::hardware::camera::device::StreamBufferRequestError;
+using aidl::android::hardware::camera::device::StreamBufferRet;
+using aidl::android::hardware::camera::device::StreamBuffersVal;
+using aidl::android::hardware::camera::device::StreamConfiguration;
+using aidl::android::hardware::camera::device::StreamConfigurationMode;
+using aidl::android::hardware::camera::device::StreamRotation;
+using aidl::android::hardware::camera::device::StreamType;
+using aidl::android::hardware::camera::provider::ICameraProvider;
+using aidl::android::hardware::common::NativeHandle;
+using aidl::android::hardware::common::fmq::SynchronizedReadWrite;
+
+using ndk::ScopedAStatus;
+
+// Util functions to convert the types between AIDL and Google Camera HAL.
+
+// Conversions from HAL to AIDL
+
+ScopedAStatus ConvertToAidlReturn(status_t hal_status);
+
+status_t ConvertToAidlVendorTagSections(
+ const std::vector<google_camera_hal::VendorTagSection>& hal_sections,
+ std::vector<VendorTagSection>* aidl_sections);
+
+status_t ConvertToAidlVendorTagType(
+ google_camera_hal::CameraMetadataType hal_type,
+ CameraMetadataType* aidl_type);
+
+status_t ConvertToAidlResourceCost(
+ const google_camera_hal::CameraResourceCost& hal_cost,
+ CameraResourceCost* aidl_cost);
+
+status_t ConvertToAidlHalStreamConfig(
+ const std::vector<google_camera_hal::HalStream>& hal_configured_streams,
+ std::vector<HalStream>* aidl_hal_stream_config);
+
+status_t ConverToAidlNotifyMessage(
+ const google_camera_hal::NotifyMessage& hal_message,
+ NotifyMsg* aidl_message);
+
+// Convert from HAL CameraDeviceStatus to AIDL CameraDeviceStatus
+// kNotPresent is converted to CameraDeviceStatus::NOT_PRESENT.
+// kPresent is converted to CameraDeviceStatus::PRESENT.
+// kEnumerating is converted to CameraDeviceStatus::ENUMERATING.
+status_t ConvertToAidlCameraDeviceStatus(
+ google_camera_hal::CameraDeviceStatus hal_camera_device_status,
+ CameraDeviceStatus* aidl_camera_device_status);
+
+// Convert from HAL TorchModeStatus to AIDL TorchModeStatus
+// kNotAvailable is converted to TorchModeStatus::NOT_AVAILABLE.
+// kAvailableOff is converted to TorchModeStatus::AVAILABLE_OFF.
+// kAvailableOn is converted to TorchModeStatus::AVAILABLE_ON.
+status_t ConvertToAidlTorchModeStatus(
+ google_camera_hal::TorchModeStatus hal_torch_status,
+ TorchModeStatus* aidl_torch_status);
+
+// Convert a HAL request to a AIDL request.
+status_t ConvertToAidlBufferRequest(
+ const std::vector<google_camera_hal::BufferRequest>& hal_buffer_requests,
+ std::vector<BufferRequest>* aidl_buffer_requests);
+
+status_t ConvertToHalBufferStatus(BufferStatus aidl_status,
+ google_camera_hal::BufferStatus* hal_status);
+
+// Convert a HAL result to a AIDL result. It will try to write the result
+// metadata to result_metadata_queue. If it fails, it will write the result
+// metadata in aidl_result.
+status_t ConvertToAidlCaptureResult(
+ AidlMessageQueue<int8_t, SynchronizedReadWrite>* result_metadata_queue,
+ std::unique_ptr<google_camera_hal::CaptureResult> hal_result,
+ CaptureResult* aidl_result);
+
+// Convert a HAL stream buffer to a AIDL aidl stream buffer.
+status_t ConvertToAidlStreamBuffer(
+ const google_camera_hal::StreamBuffer& hal_buffer,
+ StreamBuffer* aidl_buffer);
+
+// Conversions from AIDL to HAL.
+status_t ConvertToHalTemplateType(
+ RequestTemplate aidl_template,
+ google_camera_hal::RequestTemplate* hal_template);
+
+bool IsAidlNativeHandleNull(const NativeHandle& handle);
+
+status_t ConvertToHalStreamBuffer(
+ const StreamBuffer& aidl_buffer, google_camera_hal::StreamBuffer* hal_buffer,
+ std::vector<native_handle_t*>* handles_to_delete);
+
+status_t ConvertToHalMetadata(
+ uint32_t message_queue_setting_size,
+ AidlMessageQueue<int8_t, SynchronizedReadWrite>* request_metadata_queue,
+ const std::vector<uint8_t>& request_settings,
+ std::unique_ptr<google_camera_hal::HalCameraMetadata>* hal_metadata);
+
+status_t ConvertToHalCaptureRequest(
+ const CaptureRequest& aidl_request,
+ AidlMessageQueue<int8_t, SynchronizedReadWrite>* request_metadata_queue,
+ google_camera_hal::CaptureRequest* hal_request,
+ std::vector<native_handle_t*>* native_handles_to_delete);
+
+status_t ConvertToHalBufferCaches(
+ const std::vector<BufferCache>& aidl_buffer_caches,
+ std::vector<google_camera_hal::BufferCache>* hal_buffer_caches);
+
+status_t ConvertToHalStreamConfig(
+ const StreamConfiguration& aidl_stream_config,
+ google_camera_hal::StreamConfiguration* hal_stream_config);
+
+status_t ConvertToHalStreamConfigurationMode(
+ StreamConfigurationMode aidl_mode,
+ google_camera_hal::StreamConfigurationMode* hal_mode);
+
+status_t ConvertToHalStream(const Stream& aidl_stream,
+ google_camera_hal::Stream* hal_stream);
+
+status_t ConvertToHalStreamRotation(
+ StreamRotation aidl_stream_rotation,
+ google_camera_hal::StreamRotation* hal_stream_rotation);
+
+status_t ConvertToHalStreamType(StreamType aidl_stream_type,
+ google_camera_hal::StreamType* hal_stream_type);
+
+status_t ConvertToHalBufferRequestStatus(
+ const BufferRequestStatus& aidl_buffer_request_status,
+ google_camera_hal::BufferRequestStatus* hal_buffer_request_status);
+
+status_t ConvertToHalBufferReturnStatus(
+ const StreamBufferRet& aidl_stream_buffer_return,
+ google_camera_hal::BufferReturn* hal_buffer_return);
+
+status_t ConvertToHalDeviceState(
+ const int64_t aidl_device_state,
+ google_camera_hal::DeviceState& hal_device_state);
+
+} // namespace aidl_utils
+} // namespace implementation
+} // namespace camera
+} // namespace hardware
+} // namespace android
+
+#endif // HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_UTILS_H_
diff --git a/common/hal/aidl_service/android.hardware.camera.provider@2.7-service-google-lazy.rc b/common/hal/aidl_service/android.hardware.camera.provider@2.7-service-google-lazy.rc
new file mode 100644
index 0000000..423a708
--- /dev/null
+++ b/common/hal/aidl_service/android.hardware.camera.provider@2.7-service-google-lazy.rc
@@ -0,0 +1,10 @@
+service vendor.camera-provider-2-7-google /vendor/bin/hw/android.hardware.camera.provider@2.7-service-google-lazy
+ interface aidl android.hardware.camera.provider.ICameraProvider/internal/0
+ oneshot
+ disabled
+ class hal
+ user system
+ group system
+ capabilities SYS_NICE
+ rlimit rtprio 10 10
+ task_profiles CameraServiceCapacity CameraServicePerformance
diff --git a/common/hal/hidl_service/android.hardware.camera.provider@2.7-service-google.rc b/common/hal/aidl_service/android.hardware.camera.provider@2.7-service-google.rc
index b5cfab5..b5cfab5 100644
--- a/common/hal/hidl_service/android.hardware.camera.provider@2.7-service-google.rc
+++ b/common/hal/aidl_service/android.hardware.camera.provider@2.7-service-google.rc
diff --git a/common/hal/aidl_service/android.hardware.camera.provider@2.7-service-google.xml b/common/hal/aidl_service/android.hardware.camera.provider@2.7-service-google.xml
new file mode 100644
index 0000000..5e74ac5
--- /dev/null
+++ b/common/hal/aidl_service/android.hardware.camera.provider@2.7-service-google.xml
@@ -0,0 +1,10 @@
+<manifest version="1.0" type="device">
+ <hal format="aidl">
+ <name>android.hardware.camera.provider</name>
+ <version>1</version>
+ <interface>
+ <name>ICameraProvider</name>
+ <instance>internal/0</instance>
+ </interface>
+ </hal>
+</manifest>
diff --git a/common/hal/hidl_service/hidl_thermal_utils.cc b/common/hal/aidl_service/hidl_thermal_utils.cc
index 578371b..cb2c915 100644
--- a/common/hal/hidl_service/hidl_thermal_utils.cc
+++ b/common/hal/aidl_service/hidl_thermal_utils.cc
@@ -16,17 +16,14 @@
#define LOG_TAG "GCH_HidlThermalUtils"
//#define LOG_NDEBUG 0
-#include <log/log.h>
-
#include "hidl_thermal_utils.h"
-#include "hidl_utils.h"
+
+#include <log/log.h>
namespace android {
namespace hardware {
namespace hidl_thermal_utils {
-namespace hidl_utils = ::android::hardware::camera::implementation::hidl_utils;
-
std::unique_ptr<HidlThermalChangedCallback> HidlThermalChangedCallback::Create(
google_camera_hal::NotifyThrottlingFunc notify_throttling) {
auto thermal_changed_callback = std::unique_ptr<HidlThermalChangedCallback>(
diff --git a/common/hal/hidl_service/hidl_thermal_utils.h b/common/hal/aidl_service/hidl_thermal_utils.h
index d815ab2..d815ab2 100644
--- a/common/hal/hidl_service/hidl_thermal_utils.h
+++ b/common/hal/aidl_service/hidl_thermal_utils.h
diff --git a/common/hal/hidl_service/libc_wrappers.cc b/common/hal/aidl_service/libc_wrappers.cc
index 45b260b..78b3534 100644
--- a/common/hal/hidl_service/libc_wrappers.cc
+++ b/common/hal/aidl_service/libc_wrappers.cc
@@ -3,6 +3,7 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
+
#include <string>
#include <unordered_map>
diff --git a/common/hal/hidl_service/version_script.py b/common/hal/aidl_service/version_script.py
index 5551ad9..5551ad9 100644
--- a/common/hal/hidl_service/version_script.py
+++ b/common/hal/aidl_service/version_script.py
diff --git a/common/hal/hidl_service/android.hardware.camera.provider@2.7-service-google-lazy.rc b/common/hal/hidl_service/android.hardware.camera.provider@2.7-service-google-lazy.rc
deleted file mode 100644
index ff619d8..0000000
--- a/common/hal/hidl_service/android.hardware.camera.provider@2.7-service-google-lazy.rc
+++ /dev/null
@@ -1,13 +0,0 @@
-service vendor.camera-provider-2-7-google /vendor/bin/hw/android.hardware.camera.provider@2.7-service-google-lazy
- interface android.hardware.camera.provider@2.4::ICameraProvider internal/0
- interface android.hardware.camera.provider@2.5::ICameraProvider internal/0
- interface android.hardware.camera.provider@2.6::ICameraProvider internal/0
- interface android.hardware.camera.provider@2.7::ICameraProvider internal/0
- oneshot
- disabled
- class hal
- user system
- group system
- capabilities SYS_NICE
- rlimit rtprio 10 10
- task_profiles CameraServiceCapacity CameraServicePerformance
diff --git a/common/hal/hidl_service/android.hardware.camera.provider@2.7-service-google.xml b/common/hal/hidl_service/android.hardware.camera.provider@2.7-service-google.xml
deleted file mode 100644
index 481b46e..0000000
--- a/common/hal/hidl_service/android.hardware.camera.provider@2.7-service-google.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<!-- Copyright (C) 2020 The Android Open Source Project
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
--->
-
-<manifest version="1.0" type="device">
- <hal format="hidl">
- <name>android.hardware.camera.provider</name>
- <transport>hwbinder</transport>
- <version>2.7</version>
- <interface>
- <name>ICameraProvider</name>
- <instance>internal/0</instance>
- </interface>
- </hal>
-</manifest>
diff --git a/common/hal/hidl_service/hidl_camera_device.cc b/common/hal/hidl_service/hidl_camera_device.cc
deleted file mode 100644
index b104c64..0000000
--- a/common/hal/hidl_service/hidl_camera_device.cc
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "GCH_HidlCameraDevice"
-//#define LOG_NDEBUG 0
-#include "hidl_camera_device.h"
-
-#include <log/log.h>
-
-#include "hidl_camera_device_session.h"
-#include "hidl_profiler.h"
-#include "hidl_utils.h"
-
-namespace android {
-namespace hardware {
-namespace camera {
-namespace device {
-namespace V3_8 {
-namespace implementation {
-
-namespace hidl_utils = ::android::hardware::camera::implementation::hidl_utils;
-
-using ::android::google_camera_hal::HalCameraMetadata;
-
-const std::string HidlCameraDevice::kDeviceVersion = "3.8";
-
-std::unique_ptr<HidlCameraDevice> HidlCameraDevice::Create(
- std::unique_ptr<CameraDevice> google_camera_device) {
- auto device = std::unique_ptr<HidlCameraDevice>(new HidlCameraDevice());
- if (device == nullptr) {
- ALOGE("%s: Cannot create a HidlCameraDevice.", __FUNCTION__);
- return nullptr;
- }
-
- status_t res = device->Initialize(std::move(google_camera_device));
- if (res != OK) {
- ALOGE("%s: Initializing HidlCameraDevice failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- return nullptr;
- }
-
- return device;
-}
-
-status_t HidlCameraDevice::Initialize(
- std::unique_ptr<CameraDevice> google_camera_device) {
- if (google_camera_device == nullptr) {
- ALOGE("%s: google_camera_device is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- camera_id_ = google_camera_device->GetPublicCameraId();
- google_camera_device_ = std::move(google_camera_device);
- hidl_profiler_ = HidlProfiler::Create(camera_id_);
- if (hidl_profiler_ == nullptr) {
- ALOGE("%s: Failed to create HidlProfiler.", __FUNCTION__);
- return UNKNOWN_ERROR;
- }
- return OK;
-}
-
-Return<void> HidlCameraDevice::getResourceCost(
- ICameraDevice::getResourceCost_cb _hidl_cb) {
- google_camera_hal::CameraResourceCost hal_cost;
- CameraResourceCost hidl_cost;
-
- status_t res = google_camera_device_->GetResourceCost(&hal_cost);
- if (res != OK) {
- ALOGE("%s: Getting resource cost failed for camera %u: %s(%d)",
- __FUNCTION__, camera_id_, strerror(-res), res);
- _hidl_cb(Status::INTERNAL_ERROR, hidl_cost);
- return Void();
- }
-
- res = hidl_utils::ConvertToHidlResourceCost(hal_cost, &hidl_cost);
- if (res != OK) {
- _hidl_cb(Status::INTERNAL_ERROR, hidl_cost);
- return Void();
- }
-
- _hidl_cb(Status::OK, hidl_cost);
- return Void();
-}
-
-Return<void> HidlCameraDevice::getCameraCharacteristics(
- ICameraDevice::getCameraCharacteristics_cb _hidl_cb) {
- V3_2::CameraMetadata hidl_characteristics;
- std::unique_ptr<HalCameraMetadata> characteristics;
- status_t res =
- google_camera_device_->GetCameraCharacteristics(&characteristics);
- if (res != OK) {
- ALOGE("%s: Getting camera characteristics for camera %u failed: %s(%d)",
- __FUNCTION__, camera_id_, strerror(-res), res);
- _hidl_cb(Status::INTERNAL_ERROR, hidl_characteristics);
- return Void();
- }
-
- if (characteristics == nullptr) {
- ALOGE("%s: Camera characteristics for camera %u is nullptr.", __FUNCTION__,
- camera_id_);
- _hidl_cb(Status::INTERNAL_ERROR, hidl_characteristics);
- return Void();
- }
-
- uint32_t metadata_size = characteristics->GetCameraMetadataSize();
- hidl_characteristics.setToExternal(
- (uint8_t*)characteristics->ReleaseCameraMetadata(), metadata_size,
- /*shouldOwn*/ true);
-
- _hidl_cb(Status::OK, hidl_characteristics);
- return Void();
-}
-
-Return<Status> HidlCameraDevice::setTorchMode(TorchMode mode) {
- google_camera_hal::TorchMode hal_torch_mode;
- status_t res = hidl_utils::ConvertToHalTorchMode(mode, &hal_torch_mode);
- if (res != OK) {
- ALOGE("%s: failed to convert torch mode", __FUNCTION__);
- return Status::INTERNAL_ERROR;
- }
-
- res = google_camera_device_->SetTorchMode(hal_torch_mode);
- return hidl_utils::ConvertToHidlStatus(res);
-}
-
-Return<Status> HidlCameraDevice::turnOnTorchWithStrengthLevel(int32_t torch_strength) {
- status_t res = google_camera_device_->TurnOnTorchWithStrengthLevel(torch_strength);
- return hidl_utils::ConvertToHidlStatus(res);
-}
-
-Return<void> HidlCameraDevice::getTorchStrengthLevel(
- ICameraDevice::getTorchStrengthLevel_cb _hidl_cb) {
- int32_t torch_strength;
- status_t res = google_camera_device_->GetTorchStrengthLevel(torch_strength);
- if (res != OK) {
- ALOGE("%s: Getting camera flash unit torch strength level for camera %u failed: %s(%d)",
- __FUNCTION__, camera_id_, strerror(-res), res);
- _hidl_cb(Status::INTERNAL_ERROR, torch_strength);
- return Void();
- }
-
- _hidl_cb(Status::OK, torch_strength);
- return Void();
-}
-
-Return<void> HidlCameraDevice::open(
- const sp<V3_2::ICameraDeviceCallback>& callback,
- ICameraDevice::open_cb _hidl_cb) {
- auto profiler = hidl_profiler_->MakeScopedProfiler(
- HidlProfiler::ScopedType::kOpen,
- google_camera_device_->GetProfiler(camera_id_,
- hidl_profiler_->GetLatencyFlag()),
- google_camera_device_->GetProfiler(camera_id_,
- hidl_profiler_->GetFpsFlag()));
-
- std::unique_ptr<google_camera_hal::CameraDeviceSession> session;
- status_t res = google_camera_device_->CreateCameraDeviceSession(&session);
- if (res != OK || session == nullptr) {
- ALOGE("%s: Creating CameraDeviceSession failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- _hidl_cb(hidl_utils::ConvertToHidlStatus(res), nullptr);
- return Void();
- }
-
- auto hidl_session = HidlCameraDeviceSession::Create(
- callback, std::move(session), hidl_profiler_);
- if (hidl_session == nullptr) {
- ALOGE("%s: Creating HidlCameraDeviceSession failed.", __FUNCTION__);
- _hidl_cb(hidl_utils::ConvertToHidlStatus(res), nullptr);
- return Void();
- }
-
- _hidl_cb(Status::OK, hidl_session.release());
- return Void();
-}
-
-Return<void> HidlCameraDevice::dumpState(
- const ::android::hardware::hidl_handle& handle) {
- if (handle.getNativeHandle() == nullptr) {
- ALOGE("%s: handle is nullptr", __FUNCTION__);
- return Void();
- }
-
- if (handle->numFds != 1 || handle->numInts != 0) {
- ALOGE("%s: handle must contain 1 fd(%d) and 0 ints(%d)", __FUNCTION__,
- handle->numFds, handle->numInts);
- return Void();
- }
-
- int fd = handle->data[0];
- google_camera_device_->DumpState(fd);
- return Void();
-}
-
-Return<void> HidlCameraDevice::getPhysicalCameraCharacteristics(
- const hidl_string& physicalCameraId,
- ICameraDevice::getPhysicalCameraCharacteristics_cb _hidl_cb) {
- V3_2::CameraMetadata hidl_characteristics;
- std::unique_ptr<HalCameraMetadata> physical_characteristics;
-
- uint32_t physical_camera_id = atoi(physicalCameraId.c_str());
- status_t res = google_camera_device_->GetPhysicalCameraCharacteristics(
- physical_camera_id, &physical_characteristics);
- if (res != OK) {
- ALOGE("%s: Getting physical characteristics for camera %u failed: %s(%d)",
- __FUNCTION__, camera_id_, strerror(-res), res);
- _hidl_cb(hidl_utils::ConvertToHidlStatus(res), hidl_characteristics);
- return Void();
- }
-
- if (physical_characteristics == nullptr) {
- ALOGE("%s: Physical characteristics for camera %u is nullptr.",
- __FUNCTION__, physical_camera_id);
- _hidl_cb(Status::INTERNAL_ERROR, hidl_characteristics);
- return Void();
- }
-
- uint32_t metadata_size = physical_characteristics->GetCameraMetadataSize();
- hidl_characteristics.setToExternal(
- (uint8_t*)physical_characteristics->ReleaseCameraMetadata(),
- metadata_size, /*shouldOwn=*/true);
-
- _hidl_cb(Status::OK, hidl_characteristics);
- return Void();
-}
-
-Return<void> HidlCameraDevice::isStreamCombinationSupported(
- const V3_4::StreamConfiguration& streams,
- ICameraDevice::isStreamCombinationSupported_cb _hidl_cb) {
- V3_7::StreamConfiguration streams3_7;
-
- hidl_utils::ConvertStreamConfigurationV34ToV37(streams, &streams3_7);
-
- return isStreamCombinationSupported_3_7(streams3_7, _hidl_cb);
-}
-
-Return<void> HidlCameraDevice::isStreamCombinationSupported_3_7(
- const V3_7::StreamConfiguration& streams,
- ICameraDevice::isStreamCombinationSupported_cb _hidl_cb) {
- StreamConfiguration streams3_8;
-
- hidl_utils::ConvertStreamConfigurationV37ToV38(streams, &streams3_8);
-
- return isStreamCombinationSupported_3_8(streams3_8, _hidl_cb);
-}
-
-Return<void> HidlCameraDevice::isStreamCombinationSupported_3_8(
- const V3_8::StreamConfiguration& streams,
- ICameraDevice::isStreamCombinationSupported_cb _hidl_cb) {
- bool is_supported = false;
- google_camera_hal::StreamConfiguration stream_config;
- status_t res = hidl_utils::ConverToHalStreamConfig(streams, &stream_config);
- if (res != OK) {
- ALOGE("%s: ConverToHalStreamConfig fail", __FUNCTION__);
- _hidl_cb(Status::INTERNAL_ERROR, is_supported);
- return Void();
- }
- is_supported =
- google_camera_device_->IsStreamCombinationSupported(stream_config);
-
- _hidl_cb(Status::OK, is_supported);
- return Void();
-}
-
-} // namespace implementation
-} // namespace V3_8
-} // namespace device
-} // namespace camera
-} // namespace hardware
-} // namespace android
diff --git a/common/hal/hidl_service/hidl_camera_device.h b/common/hal/hidl_service/hidl_camera_device.h
deleted file mode 100644
index 99fd528..0000000
--- a/common/hal/hidl_service/hidl_camera_device.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_CAMERA_DEVICE_H_
-#define HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_CAMERA_DEVICE_H_
-
-#include <android/hardware/camera/device/3.8/ICameraDevice.h>
-#include <android/hardware/camera/device/3.8/ICameraDeviceCallback.h>
-
-#include "camera_device.h"
-#include "hidl_profiler.h"
-
-namespace android {
-namespace hardware {
-namespace camera {
-namespace device {
-namespace V3_8 {
-namespace implementation {
-
-using ::android::hardware::camera::common::V1_0::CameraResourceCost;
-using ::android::hardware::camera::common::V1_0::Status;
-using ::android::hardware::camera::common::V1_0::TorchMode;
-using ::android::hardware::camera::device::V3_8::ICameraDevice;
-using ::android::hardware::camera::device::V3_8::ICameraDeviceCallback;
-using ::android::hardware::camera::implementation::HidlProfiler;
-
-using ::android::google_camera_hal::CameraDevice;
-
-// HidlCameraDevice implements the HIDL camera device interface, ICameraDevice,
-// using Google Camera HAL to provide information about the associated camera
-// device.
-class HidlCameraDevice : public ICameraDevice {
- public:
- static const std::string kDeviceVersion;
-
- // Create a HidlCameraDevice.
- // google_camera_device is a google camera device that HidlCameraDevice
- // is going to manage. Creating a HidlCameraDevice will fail if
- // google_camera_device is nullptr.
- static std::unique_ptr<HidlCameraDevice> Create(
- std::unique_ptr<CameraDevice> google_camera_device);
- virtual ~HidlCameraDevice() = default;
-
- // Override functions in ICameraDevice
- Return<void> getResourceCost(
- ICameraDevice::getResourceCost_cb _hidl_cb) override;
-
- Return<void> getCameraCharacteristics(
- ICameraDevice::getCameraCharacteristics_cb _hidl_cb) override;
-
- Return<Status> setTorchMode(TorchMode mode) override;
-
- Return<void> open(const sp<V3_2::ICameraDeviceCallback>& callback,
- ICameraDevice::open_cb _hidl_cb) override;
-
- Return<void> dumpState(const ::android::hardware::hidl_handle& handle) override;
-
- Return<void> getPhysicalCameraCharacteristics(
- const hidl_string& physicalCameraId,
- ICameraDevice::getPhysicalCameraCharacteristics_cb _hidl_cb) override;
-
- Return<void> isStreamCombinationSupported(
- const V3_4::StreamConfiguration& streams,
- ICameraDevice::isStreamCombinationSupported_cb _hidl_cb) override;
-
- Return<void> isStreamCombinationSupported_3_7(
- const V3_7::StreamConfiguration& streams,
- ICameraDevice::isStreamCombinationSupported_cb _hidl_cb) override;
-
- Return<Status> turnOnTorchWithStrengthLevel(int32_t torch_strength) override;
-
- Return<void> getTorchStrengthLevel(ICameraDevice::getTorchStrengthLevel_cb _hidl_cb) override;
-
- Return<void> isStreamCombinationSupported_3_8(
- const StreamConfiguration& streams,
- ICameraDevice::isStreamCombinationSupported_cb _hidl_cb) override;
-
- // End of override functions in ICameraDevice
-
- protected:
- HidlCameraDevice() = default;
-
- private:
- status_t Initialize(std::unique_ptr<CameraDevice> google_camera_device);
-
- std::unique_ptr<CameraDevice> google_camera_device_;
- uint32_t camera_id_ = 0;
- std::shared_ptr<HidlProfiler> hidl_profiler_;
-};
-
-} // namespace implementation
-} // namespace V3_8
-} // namespace device
-} // namespace camera
-} // namespace hardware
-} // namespace android
-
-#endif // HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_CAMERA_DEVICE_H_
diff --git a/common/hal/hidl_service/hidl_camera_provider.cc b/common/hal/hidl_service/hidl_camera_provider.cc
deleted file mode 100644
index 1d06b6a..0000000
--- a/common/hal/hidl_service/hidl_camera_provider.cc
+++ /dev/null
@@ -1,399 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "GCH_HidlCameraProvider"
-//#define LOG_NDEBUG 0
-#include <log/log.h>
-#include <regex>
-
-#include "camera_device.h"
-#include "hidl_camera_device.h"
-#include "hidl_camera_provider.h"
-#include "hidl_utils.h"
-
-namespace android {
-namespace hardware {
-namespace camera {
-namespace provider {
-namespace V2_7 {
-namespace implementation {
-
-namespace hidl_utils = ::android::hardware::camera::implementation::hidl_utils;
-
-using ::android::google_camera_hal::CameraDevice;
-using ::android::hardware::Void;
-using ::android::hardware::camera::common::V1_0::CameraDeviceStatus;
-using ::android::hardware::camera::common::V1_0::TorchModeStatus;
-using ::android::hardware::camera::common::V1_0::VendorTagSection;
-
-const std::string HidlCameraProvider::kProviderName = "internal";
-// "device@<version>/internal/<id>"
-const std::regex HidlCameraProvider::kDeviceNameRegex(
- "device@([0-9]+\\.[0-9]+)/internal/(.+)");
-
-android::sp<HidlCameraProvider> HidlCameraProvider::Create() {
- android::sp<HidlCameraProvider> provider = new HidlCameraProvider();
-
- status_t res = provider->Initialize();
- if (res != OK) {
- ALOGE("%s: Initializing HidlCameraProvider failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- return nullptr;
- }
-
- return provider;
-}
-
-status_t HidlCameraProvider::Initialize() {
- google_camera_provider_ = CameraProvider::Create();
- if (google_camera_provider_ == nullptr) {
- ALOGE("%s: Creating CameraProvider failed.", __FUNCTION__);
- return NO_INIT;
- }
-
- camera_provider_callback_ = {
- .camera_device_status_change = google_camera_hal::CameraDeviceStatusChangeFunc(
- [this](std::string camera_id,
- google_camera_hal::CameraDeviceStatus new_status) {
- if (callbacks_ == nullptr) {
- ALOGE("%s: callbacks_ is null", __FUNCTION__);
- return;
- }
- CameraDeviceStatus hidl_camera_device_status;
- status_t res = hidl_utils::ConvertToHidlCameraDeviceStatus(
- new_status, &hidl_camera_device_status);
- if (res != OK) {
- ALOGE(
- "%s: Converting to hidl camera device status failed: %s(%d)",
- __FUNCTION__, strerror(-res), res);
- return;
- }
-
- std::unique_lock<std::mutex> lock(callbacks_lock_);
- callbacks_->cameraDeviceStatusChange(
- "device@" +
- device::V3_8::implementation::HidlCameraDevice::kDeviceVersion +
- "/" + kProviderName + "/" + camera_id,
- hidl_camera_device_status);
- }),
- .physical_camera_device_status_change = google_camera_hal::
- PhysicalCameraDeviceStatusChangeFunc([this](
- std::string camera_id,
- std::string physical_camera_id,
- google_camera_hal::CameraDeviceStatus
- new_status) {
- if (callbacks_ == nullptr) {
- ALOGE("%s: callbacks_ is null", __FUNCTION__);
- return;
- }
- auto castResult =
- provider::V2_6::ICameraProviderCallback::castFrom(callbacks_);
- if (!castResult.isOk()) {
- ALOGE("%s: callbacks_ cannot be casted to version 2.6",
- __FUNCTION__);
- return;
- }
- sp<provider::V2_6::ICameraProviderCallback> callbacks_2_6_ =
- castResult;
- if (callbacks_2_6_ == nullptr) {
- ALOGE("%s: callbacks_2_6_ is null", __FUNCTION__);
- return;
- }
-
- CameraDeviceStatus hidl_camera_device_status;
- status_t res = hidl_utils::ConvertToHidlCameraDeviceStatus(
- new_status, &hidl_camera_device_status);
- if (res != OK) {
- ALOGE(
- "%s: Converting to hidl camera device status failed: %s(%d)",
- __FUNCTION__, strerror(-res), res);
- return;
- }
-
- std::unique_lock<std::mutex> lock(callbacks_lock_);
- callbacks_2_6_->physicalCameraDeviceStatusChange(
- "device@" +
- device::V3_8::implementation::HidlCameraDevice::kDeviceVersion +
- "/" + kProviderName + "/" + camera_id,
- physical_camera_id, hidl_camera_device_status);
- }),
- .torch_mode_status_change = google_camera_hal::TorchModeStatusChangeFunc(
- [this](std::string camera_id,
- google_camera_hal::TorchModeStatus new_status) {
- if (callbacks_ == nullptr) {
- ALOGE("%s: callbacks_ is null", __FUNCTION__);
- return;
- }
-
- TorchModeStatus hidl_torch_status;
- status_t res = hidl_utils::ConvertToHidlTorchModeStatus(
- new_status, &hidl_torch_status);
- if (res != OK) {
- ALOGE("%s: Converting to hidl torch status failed: %s(%d)",
- __FUNCTION__, strerror(-res), res);
- return;
- }
-
- std::unique_lock<std::mutex> lock(callbacks_lock_);
- callbacks_->torchModeStatusChange(
- "device@" +
- device::V3_8::implementation::HidlCameraDevice::kDeviceVersion +
- "/" + kProviderName + "/" + camera_id,
- hidl_torch_status);
- }),
- };
-
- google_camera_provider_->SetCallback(&camera_provider_callback_);
- // purge pending malloc pages after initialization
- mallopt(M_PURGE, 0);
- return OK;
-}
-
-Return<Status> HidlCameraProvider::setCallback(
- const sp<ICameraProviderCallback>& callback) {
- bool first_time = false;
- {
- std::unique_lock<std::mutex> lock(callbacks_lock_);
- first_time = callbacks_ == nullptr;
- callbacks_ = callback;
- }
- google_camera_provider_->TriggerDeferredCallbacks();
-#ifdef __ANDROID_APEX__
- if (first_time) {
- std::string ready_property_name = "vendor.camera.hal.ready.count";
- int ready_count = property_get_int32(ready_property_name.c_str(), 0);
- property_set(ready_property_name.c_str(),
- std::to_string(++ready_count).c_str());
- ALOGI("HidlCameraProvider::setCallback() first time ready count: %d ",
- ready_count);
- }
-#endif
- return Status::OK;
-}
-
-Return<void> HidlCameraProvider::getVendorTags(getVendorTags_cb _hidl_cb) {
- hidl_vec<VendorTagSection> hidl_vendor_tag_sections;
- std::vector<google_camera_hal::VendorTagSection> hal_vendor_tag_sections;
-
- status_t res =
- google_camera_provider_->GetVendorTags(&hal_vendor_tag_sections);
- if (res != OK) {
- ALOGE("%s: Getting vendor tags failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- _hidl_cb(Status::INTERNAL_ERROR, hidl_vendor_tag_sections);
- return Void();
- }
-
- res = hidl_utils::ConvertToHidlVendorTagSections(hal_vendor_tag_sections,
- &hidl_vendor_tag_sections);
- if (res != OK) {
- ALOGE("%s: Converting to hidl vendor tags failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- _hidl_cb(Status::INTERNAL_ERROR, hidl_vendor_tag_sections);
- return Void();
- }
-
- _hidl_cb(Status::OK, hidl_vendor_tag_sections);
- return Void();
-}
-
-Return<void> HidlCameraProvider::getCameraIdList(getCameraIdList_cb _hidl_cb) {
- std::vector<uint32_t> camera_ids;
- hidl_vec<hidl_string> hidl_camera_ids;
- status_t res = google_camera_provider_->GetCameraIdList(&camera_ids);
- if (res != OK) {
- ALOGE("%s: Getting camera ID list failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- _hidl_cb(Status::INTERNAL_ERROR, hidl_camera_ids);
- return Void();
- }
-
- hidl_camera_ids.resize(camera_ids.size());
- for (uint32_t i = 0; i < hidl_camera_ids.size(); i++) {
- // camera ID is in the form of "device@<major>.<minor>/<type>/<id>"
- hidl_camera_ids[i] =
- "device@" +
- device::V3_8::implementation::HidlCameraDevice::kDeviceVersion + "/" +
- kProviderName + "/" + std::to_string(camera_ids[i]);
- }
-
- _hidl_cb(Status::OK, hidl_camera_ids);
- return Void();
-}
-
-Return<void> HidlCameraProvider::getConcurrentStreamingCameraIds(
- getConcurrentStreamingCameraIds_cb _hidl_cb) {
- hidl_vec<hidl_vec<hidl_string>> hidl_camera_id_combinations;
- std::vector<std::unordered_set<uint32_t>> camera_id_combinations;
- status_t res = google_camera_provider_->GetConcurrentStreamingCameraIds(
- &camera_id_combinations);
- if (res != OK) {
- ALOGE(
- "%s: Getting the combinations of concurrent streaming camera ids "
- "failed: %s(%d)",
- __FUNCTION__, strerror(-res), res);
- _hidl_cb(Status::INTERNAL_ERROR, hidl_camera_id_combinations);
- return Void();
- }
- hidl_camera_id_combinations.resize(camera_id_combinations.size());
- int i = 0;
- for (auto& combination : camera_id_combinations) {
- hidl_vec<hidl_string> hidl_combination(combination.size());
- int c = 0;
- for (auto& camera_id : combination) {
- hidl_combination[c] = std::to_string(camera_id);
- c++;
- }
- hidl_camera_id_combinations[i] = hidl_combination;
- i++;
- }
- _hidl_cb(Status::OK, hidl_camera_id_combinations);
- return Void();
-}
-
-Return<void> HidlCameraProvider::isConcurrentStreamCombinationSupported(
- const hidl_vec<provider::V2_6::CameraIdAndStreamCombination>& configs,
- isConcurrentStreamCombinationSupported_cb _hidl_cb) {
- hidl_vec<CameraIdAndStreamCombination> configs2_7;
- configs2_7.resize(configs.size());
- for (size_t i = 0; i < configs.size(); i++) {
- configs2_7[i].cameraId = configs[i].cameraId;
-
- hidl_utils::ConvertStreamConfigurationV34ToV37(
- configs[i].streamConfiguration, &configs2_7[i].streamConfiguration);
- }
-
- return isConcurrentStreamCombinationSupported_2_7(configs2_7, _hidl_cb);
-}
-
-Return<void> HidlCameraProvider::isConcurrentStreamCombinationSupported_2_7(
- const hidl_vec<CameraIdAndStreamCombination>& configs,
- isConcurrentStreamCombinationSupported_cb _hidl_cb) {
- std::vector<google_camera_hal::CameraIdAndStreamConfiguration>
- devices_stream_configs(configs.size());
- status_t res = OK;
- size_t c = 0;
- for (auto& config : configs) {
- res = hidl_utils::ConverToHalStreamConfig(
- config.streamConfiguration,
- &devices_stream_configs[c].stream_configuration);
- if (res != OK) {
- ALOGE("%s: ConverToHalStreamConfig failed", __FUNCTION__);
- _hidl_cb(Status::INTERNAL_ERROR, false);
- return Void();
- }
- uint32_t camera_id = atoi(config.cameraId.c_str());
- devices_stream_configs[c].camera_id = camera_id;
- c++;
- }
- bool is_supported = false;
- res = google_camera_provider_->IsConcurrentStreamCombinationSupported(
- devices_stream_configs, &is_supported);
- if (res != OK) {
- ALOGE("%s: ConverToHalStreamConfig failed", __FUNCTION__);
- _hidl_cb(Status::INTERNAL_ERROR, false);
- return Void();
- }
- _hidl_cb(Status::OK, is_supported);
- return Void();
-}
-
-Return<void> HidlCameraProvider::isSetTorchModeSupported(
- isSetTorchModeSupported_cb _hidl_cb) {
- bool is_supported = google_camera_provider_->IsSetTorchModeSupported();
- _hidl_cb(Status::OK, is_supported);
- return Void();
-}
-
-Return<void> HidlCameraProvider::getCameraDeviceInterface_V1_x(
- const hidl_string& /*cameraDeviceName*/,
- getCameraDeviceInterface_V1_x_cb _hidl_cb) {
- _hidl_cb(Status::OPERATION_NOT_SUPPORTED, nullptr);
- return Void();
-}
-
-bool HidlCameraProvider::ParseDeviceName(const hidl_string& device_name,
- std::string* device_version,
- std::string* camera_id) {
- std::string device_name_std(device_name.c_str());
- std::smatch sm;
-
- if (std::regex_match(device_name_std, sm,
- HidlCameraProvider::kDeviceNameRegex)) {
- if (device_version != nullptr) {
- *device_version = sm[1];
- }
- if (camera_id != nullptr) {
- *camera_id = sm[2];
- }
- return true;
- }
- return false;
-}
-
-Return<void> HidlCameraProvider::getCameraDeviceInterface_V3_x(
- const hidl_string& camera_device_name,
- getCameraDeviceInterface_V3_x_cb _hidl_cb) {
- std::unique_ptr<CameraDevice> google_camera_device;
-
- // Parse camera_device_name.
- std::string camera_id, device_version;
-
- bool match = ParseDeviceName(camera_device_name, &device_version, &camera_id);
- if (!match) {
- ALOGE("%s: Device name parse fail. ", __FUNCTION__);
- _hidl_cb(Status::ILLEGAL_ARGUMENT, nullptr);
- return Void();
- }
-
- status_t res = google_camera_provider_->CreateCameraDevice(
- atoi(camera_id.c_str()), &google_camera_device);
- if (res != OK) {
- ALOGE("%s: Creating CameraDevice failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- _hidl_cb(hidl_utils::ConvertToHidlStatus(res), nullptr);
- return Void();
- }
-
- auto hidl_camera_device =
- device::V3_8::implementation::HidlCameraDevice::Create(
- std::move(google_camera_device));
- if (hidl_camera_device == nullptr) {
- ALOGE("%s: Creating HidlCameraDevice failed", __FUNCTION__);
- _hidl_cb(Status::INTERNAL_ERROR, nullptr);
- return Void();
- }
-
- _hidl_cb(Status::OK, hidl_camera_device.release());
- return Void();
-}
-
-Return<void> HidlCameraProvider::notifyDeviceStateChange(
- hardware::hidl_bitfield<DeviceState> new_state) {
- google_camera_hal::DeviceState device_state =
- google_camera_hal::DeviceState::kNormal;
- ::android::hardware::camera::implementation::hidl_utils::ConvertToHalDeviceState(
- new_state, device_state);
- google_camera_provider_->NotifyDeviceStateChange(device_state);
- return Void();
-}
-
-} // namespace implementation
-} // namespace V2_7
-} // namespace provider
-} // namespace camera
-} // namespace hardware
-} // namespace android
diff --git a/common/hal/hidl_service/hidl_camera_provider.h b/common/hal/hidl_service/hidl_camera_provider.h
deleted file mode 100644
index 31efc14..0000000
--- a/common/hal/hidl_service/hidl_camera_provider.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_CAMERA_PROVIDER_H_
-#define HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_CAMERA_PROVIDER_H_
-
-#include <android/hardware/camera/provider/2.6/ICameraProviderCallback.h>
-#include <android/hardware/camera/provider/2.7/ICameraProvider.h>
-#include <regex>
-#include "camera_provider.h"
-
-namespace android {
-namespace hardware {
-namespace camera {
-namespace provider {
-namespace V2_7 {
-namespace implementation {
-
-using ::android::sp;
-using ::android::hardware::hidl_string;
-using ::android::hardware::hidl_vec;
-using ::android::hardware::Return;
-using ::android::hardware::camera::common::V1_0::Status;
-using ::android::hardware::camera::provider::V2_4::ICameraProviderCallback;
-using ::android::hardware::camera::provider::V2_5::DeviceState;
-using ::android::hardware::camera::provider::V2_7::CameraIdAndStreamCombination;
-using ::android::hardware::camera::provider::V2_7::ICameraProvider;
-
-using ::android::google_camera_hal::CameraProvider;
-
-// HidlCameraProvider implements the HIDL camera provider interface,
-// ICameraProvider, to enumerate the available individual camera devices
-// in the system, and provide updates about changes to device status.
-class HidlCameraProvider : public ICameraProvider {
- public:
- static const std::string kProviderName;
- static android::sp<HidlCameraProvider> Create();
- virtual ~HidlCameraProvider() = default;
-
- // Override functions in ICameraProvider.
- Return<Status> setCallback(
- const sp<ICameraProviderCallback>& callback) override;
-
- Return<void> getVendorTags(getVendorTags_cb _hidl_cb) override;
-
- Return<void> getCameraIdList(getCameraIdList_cb _hidl_cb) override;
-
- Return<void> isSetTorchModeSupported(
- isSetTorchModeSupported_cb _hidl_cb) override;
-
- Return<void> getConcurrentStreamingCameraIds(
- getConcurrentStreamingCameraIds_cb _hidl_cb) override;
-
- Return<void> isConcurrentStreamCombinationSupported(
- const hidl_vec<V2_6::CameraIdAndStreamCombination>& configs,
- isConcurrentStreamCombinationSupported_cb _hidl_cb) override;
-
- Return<void> isConcurrentStreamCombinationSupported_2_7(
- const hidl_vec<CameraIdAndStreamCombination>& configs,
- isConcurrentStreamCombinationSupported_cb _hidl_cb) override;
-
- Return<void> getCameraDeviceInterface_V1_x(
- const hidl_string& cameraDeviceName,
- getCameraDeviceInterface_V1_x_cb _hidl_cb) override;
-
- Return<void> getCameraDeviceInterface_V3_x(
- const hidl_string& cameraDeviceName,
- getCameraDeviceInterface_V3_x_cb _hidl_cb) override;
-
- Return<void> notifyDeviceStateChange(
- hardware::hidl_bitfield<DeviceState> newState) override;
- // End of override functions in ICameraProvider.
-
- protected:
- HidlCameraProvider() = default;
-
- private:
- static const std::regex kDeviceNameRegex;
-
- status_t Initialize();
-
- // Parse device version and camera ID.
- bool ParseDeviceName(const hidl_string& device_name,
- std::string* device_version, std::string* camera_id);
-
- std::mutex callbacks_lock_;
- sp<ICameraProviderCallback> callbacks_;
-
- std::unique_ptr<CameraProvider> google_camera_provider_;
- google_camera_hal::CameraProviderCallback camera_provider_callback_;
-};
-
-} // namespace implementation
-} // namespace V2_7
-} // namespace provider
-} // namespace camera
-} // namespace hardware
-} // namespace android
-
-#endif // HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_CAMERA_PROVIDER_H_
diff --git a/common/hal/hidl_service/hidl_utils.cc b/common/hal/hidl_service/hidl_utils.cc
deleted file mode 100644
index 39b566e..0000000
--- a/common/hal/hidl_service/hidl_utils.cc
+++ /dev/null
@@ -1,1251 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "android/hardware/camera/metadata/3.8/types.h"
-#define LOG_TAG "GCH_HidlUtils"
-//#define LOG_NDEBUG 0
-#include <log/log.h>
-#include <regex>
-
-#include "hidl_camera_device.h"
-#include "hidl_utils.h"
-
-namespace android {
-namespace hardware {
-namespace camera {
-namespace implementation {
-namespace hidl_utils {
-
-using ::android::hardware::camera::device::V3_2::ErrorCode;
-using ::android::hardware::camera::device::V3_2::ErrorMsg;
-using ::android::hardware::camera::device::V3_2::MsgType;
-using ::android::hardware::camera::device::V3_8::ShutterMsg;
-using ::android::hardware::camera::device::V3_8::implementation::HidlCameraDevice;
-using android::hardware::camera::metadata::V3_6::
- CameraMetadataEnumAndroidSensorPixelMode;
-using ::android::hardware::camera::provider::V2_7::implementation::HidlCameraProvider;
-
-status_t ConvertToHidlVendorTagType(
- google_camera_hal::CameraMetadataType hal_type,
- CameraMetadataType* hidl_type) {
- if (hidl_type == nullptr) {
- ALOGE("%s: hidl_type is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- switch (hal_type) {
- case google_camera_hal::CameraMetadataType::kByte:
- *hidl_type = CameraMetadataType::BYTE;
- break;
- case google_camera_hal::CameraMetadataType::kInt32:
- *hidl_type = CameraMetadataType::INT32;
- break;
- case google_camera_hal::CameraMetadataType::kFloat:
- *hidl_type = CameraMetadataType::FLOAT;
- break;
- case google_camera_hal::CameraMetadataType::kInt64:
- *hidl_type = CameraMetadataType::INT64;
- break;
- case google_camera_hal::CameraMetadataType::kDouble:
- *hidl_type = CameraMetadataType::DOUBLE;
- break;
- case google_camera_hal::CameraMetadataType::kRational:
- *hidl_type = CameraMetadataType::RATIONAL;
- break;
- default:
- ALOGE("%s: Unknown google_camera_hal::CameraMetadataType: %u",
- __FUNCTION__, hal_type);
- return BAD_VALUE;
- }
-
- return OK;
-}
-
-status_t ConvertToHidlResourceCost(
- const google_camera_hal::CameraResourceCost& hal_cost,
- CameraResourceCost* hidl_cost) {
- if (hidl_cost == nullptr) {
- ALOGE("%s: hidl_cost is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- hidl_cost->resourceCost = hal_cost.resource_cost;
- hidl_cost->conflictingDevices.resize(hal_cost.conflicting_devices.size());
-
- for (uint32_t i = 0; i < hal_cost.conflicting_devices.size(); i++) {
- hidl_cost->conflictingDevices[i] =
- "device@" + HidlCameraDevice::kDeviceVersion + "/" +
- HidlCameraProvider::kProviderName + "/" +
- std::to_string(hal_cost.conflicting_devices[i]);
- }
-
- return OK;
-}
-
-status_t ConvertToHidlVendorTagSections(
- const std::vector<google_camera_hal::VendorTagSection>& hal_sections,
- hidl_vec<VendorTagSection>* hidl_sections) {
- if (hidl_sections == nullptr) {
- ALOGE("%s: hidl_sections is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- hidl_sections->resize(hal_sections.size());
- for (uint32_t i = 0; i < hal_sections.size(); i++) {
- (*hidl_sections)[i].sectionName = hal_sections[i].section_name;
- (*hidl_sections)[i].tags.resize(hal_sections[i].tags.size());
-
- for (uint32_t j = 0; j < hal_sections[i].tags.size(); j++) {
- (*hidl_sections)[i].tags[j].tagId = hal_sections[i].tags[j].tag_id;
- (*hidl_sections)[i].tags[j].tagName = hal_sections[i].tags[j].tag_name;
- status_t res =
- ConvertToHidlVendorTagType(hal_sections[i].tags[j].tag_type,
- &(*hidl_sections)[i].tags[j].tagType);
- if (res != OK) {
- ALOGE("%s: Converting to hidl vendor tag type failed. ", __FUNCTION__);
- return res;
- }
- }
- }
-
- return OK;
-}
-
-Status ConvertToHidlStatus(status_t hal_status) {
- switch (hal_status) {
- case OK:
- return Status::OK;
- case BAD_VALUE:
- return Status::ILLEGAL_ARGUMENT;
- case -EBUSY:
- return Status::CAMERA_IN_USE;
- case -EUSERS:
- return Status::MAX_CAMERAS_IN_USE;
- case UNKNOWN_TRANSACTION:
- return Status::METHOD_NOT_SUPPORTED;
- case INVALID_OPERATION:
- return Status::OPERATION_NOT_SUPPORTED;
- case DEAD_OBJECT:
- return Status::CAMERA_DISCONNECTED;
- default:
- return Status::INTERNAL_ERROR;
- }
-}
-
-status_t ConvertToHalTemplateType(
- RequestTemplate hidl_template,
- google_camera_hal::RequestTemplate* hal_template) {
- if (hal_template == nullptr) {
- ALOGE("%s: hal_template is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- switch (hidl_template) {
- case RequestTemplate::PREVIEW:
- *hal_template = google_camera_hal::RequestTemplate::kPreview;
- break;
- case RequestTemplate::STILL_CAPTURE:
- *hal_template = google_camera_hal::RequestTemplate::kStillCapture;
- break;
- case RequestTemplate::VIDEO_RECORD:
- *hal_template = google_camera_hal::RequestTemplate::kVideoRecord;
- break;
- case RequestTemplate::VIDEO_SNAPSHOT:
- *hal_template = google_camera_hal::RequestTemplate::kVideoSnapshot;
- break;
- case RequestTemplate::ZERO_SHUTTER_LAG:
- *hal_template = google_camera_hal::RequestTemplate::kZeroShutterLag;
- break;
- case RequestTemplate::MANUAL:
- *hal_template = google_camera_hal::RequestTemplate::kManual;
- break;
- default:
- ALOGE("%s: Unknown HIDL RequestTemplate: %u", __FUNCTION__,
- hidl_template);
- return BAD_VALUE;
- }
-
- return OK;
-}
-
-status_t ConvertToHidlHalStreamConfig(
- const std::vector<google_camera_hal::HalStream>& hal_configured_streams,
- HalStreamConfiguration* hidl_hal_stream_config) {
- if (hidl_hal_stream_config == nullptr) {
- ALOGE("%s: hidl_hal_stream_config is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- hidl_hal_stream_config->streams.resize(hal_configured_streams.size());
-
- for (uint32_t i = 0; i < hal_configured_streams.size(); i++) {
- hidl_hal_stream_config->streams[i].supportOffline = false;
- if (hal_configured_streams[i].is_physical_camera_stream) {
- hidl_hal_stream_config->streams[i].v3_4.physicalCameraId =
- std::to_string(hal_configured_streams[i].physical_camera_id);
- }
-
- hidl_hal_stream_config->streams[i].v3_4.v3_3.overrideDataSpace =
- hal_configured_streams[i].override_data_space;
-
- hidl_hal_stream_config->streams[i].v3_4.v3_3.v3_2.id =
- hal_configured_streams[i].id;
-
- hidl_hal_stream_config->streams[i].v3_4.v3_3.v3_2.overrideFormat =
- (::android::hardware::graphics::common::V1_0::PixelFormat)
- hal_configured_streams[i]
- .override_format;
-
- hidl_hal_stream_config->streams[i].v3_4.v3_3.v3_2.producerUsage =
- hal_configured_streams[i].producer_usage;
-
- hidl_hal_stream_config->streams[i].v3_4.v3_3.v3_2.consumerUsage =
- hal_configured_streams[i].consumer_usage;
-
- hidl_hal_stream_config->streams[i].v3_4.v3_3.v3_2.maxBuffers =
- hal_configured_streams[i].max_buffers;
- }
-
- return OK;
-}
-
-status_t WriteToResultMetadataQueue(
- camera_metadata_t* metadata,
- MessageQueue<uint8_t, kSynchronizedReadWrite>* result_metadata_queue) {
- if (result_metadata_queue == nullptr) {
- return BAD_VALUE;
- }
-
- if (result_metadata_queue->availableToWrite() <= 0) {
- ALOGW("%s: result_metadata_queue is not available to write", __FUNCTION__);
- return BAD_VALUE;
- }
-
- uint32_t size = get_camera_metadata_size(metadata);
- bool success = result_metadata_queue->write(
- reinterpret_cast<const uint8_t*>(metadata), size);
- if (!success) {
- ALOGW("%s: Writing to result metadata queue failed. (size=%u)",
- __FUNCTION__, size);
- return INVALID_OPERATION;
- }
-
- return OK;
-}
-
-// Try writing result metadata to result metadata queue. If failed, return
-// the metadata to the caller in out_hal_metadata.
-status_t TryWritingToResultMetadataQueue(
- std::unique_ptr<google_camera_hal::HalCameraMetadata> hal_metadata,
- MessageQueue<uint8_t, kSynchronizedReadWrite>* result_metadata_queue,
- uint64_t* fmq_result_size,
- std::unique_ptr<google_camera_hal::HalCameraMetadata>* out_hal_metadata) {
- if (out_hal_metadata == nullptr) {
- ALOGE("%s: out_hal_metadata is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- *out_hal_metadata = std::move(hal_metadata);
-
- if (fmq_result_size == nullptr) {
- ALOGE("%s: fmq_result_size is nullptr", __FUNCTION__);
- return BAD_VALUE;
- }
-
- *fmq_result_size = 0;
- if (*out_hal_metadata == nullptr) {
- return OK;
- }
-
- camera_metadata_t* metadata = (*out_hal_metadata)->ReleaseCameraMetadata();
- // Temporarily use the raw metadata to write to metadata queue.
- status_t res = WriteToResultMetadataQueue(metadata, result_metadata_queue);
- *out_hal_metadata = google_camera_hal::HalCameraMetadata::Create(metadata);
-
- if (res != OK) {
- ALOGW("%s: Writing to result metadata queue failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- return res;
- }
-
- *fmq_result_size = (*out_hal_metadata)->GetCameraMetadataSize();
- *out_hal_metadata = nullptr;
- return OK;
-}
-
-status_t ConverToHidlResultMetadata(
- MessageQueue<uint8_t, kSynchronizedReadWrite>* result_metadata_queue,
- std::unique_ptr<google_camera_hal::HalCameraMetadata> hal_metadata,
- CameraMetadata* hidl_metadata, uint64_t* fmq_result_size) {
- if (TryWritingToResultMetadataQueue(std::move(hal_metadata),
- result_metadata_queue, fmq_result_size,
- &hal_metadata) == OK) {
- return OK;
- }
-
- // If writing to metadata queue failed, attach the metadata to hidl_metadata.
- if (hidl_metadata == nullptr) {
- ALOGE("%s: hidl_metadata is nullptr", __FUNCTION__);
- return BAD_VALUE;
- }
-
- uint32_t metadata_size = hal_metadata->GetCameraMetadataSize();
- hidl_metadata->setToExternal(
- reinterpret_cast<uint8_t*>(hal_metadata->ReleaseCameraMetadata()),
- metadata_size, /*shouldOwn=*/true);
-
- return OK;
-}
-
-status_t ConvertToHidlBufferStatus(google_camera_hal::BufferStatus hal_status,
- BufferStatus* hidl_status) {
- if (hidl_status == nullptr) {
- ALOGE("%s: hidl_status is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- switch (hal_status) {
- case google_camera_hal::BufferStatus::kOk:
- *hidl_status = BufferStatus::OK;
- break;
- case google_camera_hal::BufferStatus::kError:
- *hidl_status = BufferStatus::ERROR;
- break;
- default:
- ALOGE("%s: Unknown HAL buffer status: %u", __FUNCTION__, hal_status);
- return BAD_VALUE;
- }
-
- return OK;
-}
-
-status_t ConvertToHidlStreamBuffer(
- const google_camera_hal::StreamBuffer& hal_buffer,
- StreamBuffer* hidl_buffer) {
- if (hidl_buffer == nullptr) {
- ALOGE("%s: hidl_buffer is nullptr", __FUNCTION__);
- return BAD_VALUE;
- }
-
- hidl_buffer->streamId = hal_buffer.stream_id;
- hidl_buffer->bufferId = hal_buffer.buffer_id;
- hidl_buffer->buffer = nullptr;
-
- status_t res =
- ConvertToHidlBufferStatus(hal_buffer.status, &hidl_buffer->status);
- if (res != OK) {
- ALOGE("%s: Converting to HIDL buffer status failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- return res;
- }
-
- hidl_buffer->acquireFence = nullptr;
- hidl_buffer->releaseFence = hal_buffer.release_fence;
- return OK;
-}
-
-status_t ConvertToHidlCaptureResult_V3_2(
- MessageQueue<uint8_t, kSynchronizedReadWrite>* result_metadata_queue,
- google_camera_hal::CaptureResult* hal_result,
- device::V3_2::CaptureResult* hidl_result) {
- if (hidl_result == nullptr) {
- ALOGE("%s: hidl_result is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- if (hal_result == nullptr) {
- ALOGE("%s: hal_result is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- hidl_result->frameNumber = hal_result->frame_number;
-
- status_t res = ConverToHidlResultMetadata(
- result_metadata_queue, std::move(hal_result->result_metadata),
- &hidl_result->result, &hidl_result->fmqResultSize);
- if (res != OK) {
- ALOGE("%s: Converting to HIDL result metadata failed: %s(%d).",
- __FUNCTION__, strerror(-res), res);
- return res;
- }
-
- hidl_result->outputBuffers.resize(hal_result->output_buffers.size());
- for (uint32_t i = 0; i < hidl_result->outputBuffers.size(); i++) {
- res = ConvertToHidlStreamBuffer(hal_result->output_buffers[i],
- &hidl_result->outputBuffers[i]);
- if (res != OK) {
- ALOGE("%s: Converting to HIDL output stream buffer failed: %s(%d)",
- __FUNCTION__, strerror(-res), res);
- return res;
- }
- }
-
- uint32_t num_input_buffers = hal_result->input_buffers.size();
- if (num_input_buffers > 0) {
- if (num_input_buffers > 1) {
- ALOGW("%s: HAL result should not have more than 1 input buffer. (=%u)",
- __FUNCTION__, num_input_buffers);
- }
-
- res = ConvertToHidlStreamBuffer(hal_result->input_buffers[0],
- &hidl_result->inputBuffer);
- if (res != OK) {
- ALOGE("%s: Converting to HIDL input stream buffer failed: %s(%d)",
- __FUNCTION__, strerror(-res), res);
- return res;
- }
- } else {
- hidl_result->inputBuffer.streamId = -1;
- }
-
- hidl_result->partialResult = hal_result->partial_result;
- return OK;
-}
-
-status_t ConvertToHidlCaptureResult(
- MessageQueue<uint8_t, kSynchronizedReadWrite>* result_metadata_queue,
- std::unique_ptr<google_camera_hal::CaptureResult> hal_result,
- CaptureResult* hidl_result) {
- if (hidl_result == nullptr) {
- ALOGE("%s: hidl_result is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- if (hal_result == nullptr) {
- ALOGE("%s: hal_result is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- status_t res = ConvertToHidlCaptureResult_V3_2(
- result_metadata_queue, hal_result.get(), &hidl_result->v3_2);
- if (res != OK) {
- ALOGE("%s: Converting to V3.2 HIDL result failed: %s(%d).", __FUNCTION__,
- strerror(-res), res);
- return res;
- }
-
- uint32_t num_physical_metadata = hal_result->physical_metadata.size();
- hidl_result->physicalCameraMetadata.resize(num_physical_metadata);
-
- for (uint32_t i = 0; i < num_physical_metadata; i++) {
- hidl_result->physicalCameraMetadata[i].physicalCameraId =
- std::to_string(hal_result->physical_metadata[i].physical_camera_id);
-
- res = ConverToHidlResultMetadata(
- result_metadata_queue,
- std::move(hal_result->physical_metadata[i].metadata),
- &hidl_result->physicalCameraMetadata[i].metadata,
- &hidl_result->physicalCameraMetadata[i].fmqMetadataSize);
- if (res != OK) {
- ALOGE("%s: Converting to HIDL physical metadata failed: %s(%d).",
- __FUNCTION__, strerror(-res), res);
- return res;
- }
- }
-
- return OK;
-}
-
-status_t ConvertToHidlErrorMessage(
- const google_camera_hal::ErrorMessage& hal_error, ErrorMsg* hidl_error) {
- if (hidl_error == nullptr) {
- ALOGE("%s: hidl_error is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- hidl_error->frameNumber = hal_error.frame_number;
- hidl_error->errorStreamId = hal_error.error_stream_id;
-
- switch (hal_error.error_code) {
- case google_camera_hal::ErrorCode::kErrorDevice:
- hidl_error->errorCode = ErrorCode::ERROR_DEVICE;
- break;
- case google_camera_hal::ErrorCode::kErrorRequest:
- hidl_error->errorCode = ErrorCode::ERROR_REQUEST;
- break;
- case google_camera_hal::ErrorCode::kErrorResult:
- hidl_error->errorCode = ErrorCode::ERROR_RESULT;
- break;
- case google_camera_hal::ErrorCode::kErrorBuffer:
- hidl_error->errorCode = ErrorCode::ERROR_BUFFER;
- break;
- default:
- ALOGE("%s: Unknown error code: %u", __FUNCTION__, hal_error.error_code);
- return BAD_VALUE;
- }
-
- return OK;
-}
-
-status_t ConvertToHidlShutterMessage(
- const google_camera_hal::ShutterMessage& hal_shutter,
- ShutterMsg* hidl_shutter) {
- if (hidl_shutter == nullptr) {
- ALOGE("%s: hidl_shutter is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- hidl_shutter->v3_2.frameNumber = hal_shutter.frame_number;
- hidl_shutter->v3_2.timestamp = hal_shutter.timestamp_ns;
- hidl_shutter->readoutTimestamp = hal_shutter.readout_timestamp_ns;
- return OK;
-}
-
-status_t ConverToHidlNotifyMessage(
- const google_camera_hal::NotifyMessage& hal_message,
- NotifyMsg* hidl_message) {
- if (hidl_message == nullptr) {
- ALOGE("%s: hidl_message is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- status_t res;
- switch (hal_message.type) {
- case google_camera_hal::MessageType::kError:
- hidl_message->type = MsgType::ERROR;
- res = ConvertToHidlErrorMessage(hal_message.message.error,
- &hidl_message->msg.error);
- if (res != OK) {
- ALOGE("%s: Converting to HIDL error message failed: %s(%d)",
- __FUNCTION__, strerror(-res), res);
- return res;
- }
- break;
- case google_camera_hal::MessageType::kShutter:
- hidl_message->type = MsgType::SHUTTER;
- res = ConvertToHidlShutterMessage(hal_message.message.shutter,
- &hidl_message->msg.shutter);
- if (res != OK) {
- ALOGE("%s: Converting to HIDL shutter message failed: %s(%d)",
- __FUNCTION__, strerror(-res), res);
- return res;
- }
- break;
- default:
- ALOGE("%s: Unknown message type: %u", __FUNCTION__, hal_message.type);
- return BAD_VALUE;
- }
-
- return OK;
-}
-
-status_t ConvertToHidlCameraDeviceStatus(
- google_camera_hal::CameraDeviceStatus hal_camera_device_status,
- CameraDeviceStatus* hidl_camera_device_status) {
- if (hidl_camera_device_status == nullptr) {
- ALOGE("%s: hidl_camera_device_status is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- switch (hal_camera_device_status) {
- case google_camera_hal::CameraDeviceStatus::kNotPresent:
- *hidl_camera_device_status = CameraDeviceStatus::NOT_PRESENT;
- break;
- case google_camera_hal::CameraDeviceStatus::kPresent:
- *hidl_camera_device_status = CameraDeviceStatus::PRESENT;
- break;
- case google_camera_hal::CameraDeviceStatus::kEnumerating:
- *hidl_camera_device_status = CameraDeviceStatus::ENUMERATING;
- break;
- default:
- ALOGE("%s: Unknown HAL camera device status: %u", __FUNCTION__,
- hal_camera_device_status);
- return BAD_VALUE;
- }
-
- return OK;
-}
-
-status_t ConvertToHidlTorchModeStatus(
- google_camera_hal::TorchModeStatus hal_torch_status,
- TorchModeStatus* hidl_torch_status) {
- if (hidl_torch_status == nullptr) {
- ALOGE("%s: hidl_torch_status is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- switch (hal_torch_status) {
- case google_camera_hal::TorchModeStatus::kNotAvailable:
- *hidl_torch_status = TorchModeStatus::NOT_AVAILABLE;
- break;
- case google_camera_hal::TorchModeStatus::kAvailableOff:
- *hidl_torch_status = TorchModeStatus::AVAILABLE_OFF;
- break;
- case google_camera_hal::TorchModeStatus::kAvailableOn:
- *hidl_torch_status = TorchModeStatus::AVAILABLE_ON;
- break;
- default:
- ALOGE("%s: Unknown HAL torch mode status: %u", __FUNCTION__,
- hal_torch_status);
- return BAD_VALUE;
- }
-
- return OK;
-}
-
-status_t ConvertToHidlBufferRequest(
- const std::vector<google_camera_hal::BufferRequest>& hal_buffer_requests,
- hidl_vec<BufferRequest>* hidl_buffer_requests) {
- if (hidl_buffer_requests == nullptr) {
- ALOGE("%s: hidl_buffer_request is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- hidl_buffer_requests->resize(hal_buffer_requests.size());
- for (uint32_t i = 0; i < hal_buffer_requests.size(); i++) {
- (*hidl_buffer_requests)[i].streamId = hal_buffer_requests[i].stream_id;
- (*hidl_buffer_requests)[i].numBuffersRequested =
- hal_buffer_requests[i].num_buffers_requested;
- }
- return OK;
-}
-
-status_t ConvertToHalBufferStatus(BufferStatus hidl_status,
- google_camera_hal::BufferStatus* hal_status) {
- if (hal_status == nullptr) {
- ALOGE("%s: hal_status is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- switch (hidl_status) {
- case BufferStatus::OK:
- *hal_status = google_camera_hal::BufferStatus::kOk;
- break;
- case BufferStatus::ERROR:
- *hal_status = google_camera_hal::BufferStatus::kError;
- break;
- default:
- ALOGE("%s: Unknown HIDL buffer status: %u", __FUNCTION__, hidl_status);
- return BAD_VALUE;
- }
-
- return OK;
-}
-
-status_t ConvertToHalStreamBuffer(const StreamBuffer& hidl_buffer,
- google_camera_hal::StreamBuffer* hal_buffer) {
- if (hal_buffer == nullptr) {
- ALOGE("%s: hal_buffer is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- hal_buffer->stream_id = hidl_buffer.streamId;
- hal_buffer->buffer_id = hidl_buffer.bufferId;
- hal_buffer->buffer = hidl_buffer.buffer.getNativeHandle();
-
- status_t res =
- ConvertToHalBufferStatus(hidl_buffer.status, &hal_buffer->status);
- if (res != OK) {
- ALOGE("%s: Converting to HAL buffer status failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- return res;
- }
-
- hal_buffer->acquire_fence = hidl_buffer.acquireFence.getNativeHandle();
- hal_buffer->release_fence = hidl_buffer.releaseFence.getNativeHandle();
-
- return OK;
-}
-
-status_t ConvertToHalMetadata(
- uint32_t message_queue_setting_size,
- MessageQueue<uint8_t, kSynchronizedReadWrite>* request_metadata_queue,
- const CameraMetadata& request_settings,
- std::unique_ptr<google_camera_hal::HalCameraMetadata>* hal_metadata) {
- if (hal_metadata == nullptr) {
- ALOGE("%s: hal_metadata is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- const camera_metadata_t* metadata = nullptr;
- CameraMetadata metadata_queue_settings;
-
- if (message_queue_setting_size == 0) {
- // Use the settings in the request.
- if (request_settings.size() != 0) {
- metadata =
- reinterpret_cast<const camera_metadata_t*>(request_settings.data());
- }
- } else {
- // Read the settings from request metadata queue.
- if (request_metadata_queue == nullptr) {
- ALOGE("%s: request_metadata_queue is nullptr", __FUNCTION__);
- return BAD_VALUE;
- }
-
- metadata_queue_settings.resize(message_queue_setting_size);
- bool success = request_metadata_queue->read(metadata_queue_settings.data(),
- message_queue_setting_size);
- if (!success) {
- ALOGE("%s: Failed to read from request metadata queue.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- metadata = reinterpret_cast<const camera_metadata_t*>(
- metadata_queue_settings.data());
- }
-
- if (metadata == nullptr) {
- *hal_metadata = nullptr;
- return OK;
- }
-
- *hal_metadata = google_camera_hal::HalCameraMetadata::Clone(metadata);
- return OK;
-}
-
-status_t ConvertToHalCaptureRequest(
- const CaptureRequest& hidl_request,
- MessageQueue<uint8_t, kSynchronizedReadWrite>* request_metadata_queue,
- google_camera_hal::CaptureRequest* hal_request) {
- if (hal_request == nullptr) {
- ALOGE("%s: hal_request is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- hal_request->frame_number = hidl_request.v3_4.v3_2.frameNumber;
-
- status_t res = ConvertToHalMetadata(
- hidl_request.v3_4.v3_2.fmqSettingsSize, request_metadata_queue,
- hidl_request.v3_4.v3_2.settings, &hal_request->settings);
- if (res != OK) {
- ALOGE("%s: Converting metadata failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- return res;
- }
-
- google_camera_hal::StreamBuffer hal_buffer = {};
- if (hidl_request.v3_4.v3_2.inputBuffer.buffer != nullptr) {
- res = ConvertToHalStreamBuffer(hidl_request.v3_4.v3_2.inputBuffer,
- &hal_buffer);
- if (res != OK) {
- ALOGE("%s: Converting hal stream buffer failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- return res;
- }
-
- hal_request->input_buffers.push_back(hal_buffer);
- hal_request->input_width = hidl_request.inputWidth;
- hal_request->input_height = hidl_request.inputHeight;
- }
-
- for (auto& buffer : hidl_request.v3_4.v3_2.outputBuffers) {
- hal_buffer = {};
- status_t res = ConvertToHalStreamBuffer(buffer, &hal_buffer);
- if (res != OK) {
- ALOGE("%s: Converting hal stream buffer failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- return res;
- }
-
- hal_request->output_buffers.push_back(hal_buffer);
- }
-
- for (auto hidl_physical_settings : hidl_request.v3_4.physicalCameraSettings) {
- std::unique_ptr<google_camera_hal::HalCameraMetadata> hal_physical_settings;
- res = ConvertToHalMetadata(
- hidl_physical_settings.fmqSettingsSize, request_metadata_queue,
- hidl_physical_settings.settings, &hal_physical_settings);
- if (res != OK) {
- ALOGE("%s: Converting to HAL metadata failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- return res;
- }
-
- uint32_t camera_id = std::stoul(hidl_physical_settings.physicalCameraId);
- hal_request->physical_camera_settings.emplace(
- camera_id, std::move(hal_physical_settings));
- }
-
- return OK;
-}
-
-status_t ConvertToHalBufferCaches(
- const hidl_vec<BufferCache>& hidl_buffer_caches,
- std::vector<google_camera_hal::BufferCache>* hal_buffer_caches) {
- if (hal_buffer_caches == nullptr) {
- ALOGE("%s: hal_buffer_caches is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- for (auto hidl_cache : hidl_buffer_caches) {
- google_camera_hal::BufferCache hal_cache;
- hal_cache.stream_id = hidl_cache.streamId;
- hal_cache.buffer_id = hidl_cache.bufferId;
-
- hal_buffer_caches->push_back(hal_cache);
- }
-
- return OK;
-}
-
-status_t ConvertToHalStreamConfigurationMode(
- StreamConfigurationMode hidl_mode,
- google_camera_hal::StreamConfigurationMode* hal_mode) {
- if (hal_mode == nullptr) {
- ALOGE("%s: hal_mode is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- switch (hidl_mode) {
- case StreamConfigurationMode::NORMAL_MODE:
- *hal_mode = google_camera_hal::StreamConfigurationMode::kNormal;
- break;
- case StreamConfigurationMode::CONSTRAINED_HIGH_SPEED_MODE:
- *hal_mode =
- google_camera_hal::StreamConfigurationMode::kConstrainedHighSpeed;
- break;
- default:
- ALOGE("%s: Unknown configuration mode %u", __FUNCTION__, hidl_mode);
- return BAD_VALUE;
- }
-
- return OK;
-}
-
-static bool sensorPixelModeContains(const device::V3_7::Stream& hidl_stream,
- uint32_t key) {
- for (auto& i : hidl_stream.sensorPixelModesUsed) {
- if (i == static_cast<CameraMetadataEnumAndroidSensorPixelMode>(key)) {
- return true;
- }
- }
- return false;
-}
-
-status_t ConverToHalStreamConfig(
- const StreamConfiguration& hidl_stream_config,
- google_camera_hal::StreamConfiguration* hal_stream_config) {
- if (hal_stream_config == nullptr) {
- ALOGE("%s: hal_stream_config is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- status_t res;
-
- for (auto hidl_stream : hidl_stream_config.streams) {
- google_camera_hal::Stream hal_stream;
- res = ConvertToHalStream(hidl_stream.v3_7.v3_4, &hal_stream);
- if (res != OK) {
- ALOGE("%s: Converting to HAL stream failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- return res;
- }
- hal_stream.group_id = hidl_stream.v3_7.groupId;
-
- hal_stream.used_in_max_resolution_mode = sensorPixelModeContains(
- hidl_stream.v3_7, ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION);
- hal_stream.used_in_default_resolution_mode =
- hidl_stream.v3_7.sensorPixelModesUsed.size() > 0
- ? sensorPixelModeContains(hidl_stream.v3_7,
- ANDROID_SENSOR_PIXEL_MODE_DEFAULT)
- : true;
- hal_stream.dynamic_profile = static_cast<
- camera_metadata_enum_android_request_available_dynamic_range_profiles_map>(
- hidl_stream.dynamicRangeProfile);
- hal_stream.use_case =
- static_cast<camera_metadata_enum_android_scaler_available_stream_use_cases>(
- hidl_stream.useCase);
- hal_stream_config->streams.push_back(hal_stream);
- }
-
- res = ConvertToHalStreamConfigurationMode(hidl_stream_config.operationMode,
- &hal_stream_config->operation_mode);
- if (res != OK) {
- ALOGE("%s: Converting to HAL opeation mode failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- return res;
- }
-
- res = ConvertToHalMetadata(0, nullptr, hidl_stream_config.sessionParams,
- &hal_stream_config->session_params);
- if (res != OK) {
- ALOGE("%s: Converting to HAL metadata failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- return res;
- }
-
- hal_stream_config->stream_config_counter =
- hidl_stream_config.streamConfigCounter;
- hal_stream_config->multi_resolution_input_image =
- hidl_stream_config.multiResolutionInputImage;
-
- return OK;
-}
-
-status_t ConverToHalStreamConfig(
- const device::V3_7::StreamConfiguration& hidl_stream_config,
- google_camera_hal::StreamConfiguration* hal_stream_config) {
- if (hal_stream_config == nullptr) {
- ALOGE("%s: hal_stream_config is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- status_t res;
-
- for (auto hidl_stream : hidl_stream_config.streams) {
- google_camera_hal::Stream hal_stream;
- res = ConvertToHalStream(hidl_stream.v3_4, &hal_stream);
- if (res != OK) {
- ALOGE("%s: Converting to HAL stream failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- return res;
- }
- hal_stream.group_id = hidl_stream.groupId;
-
- hal_stream.used_in_max_resolution_mode = sensorPixelModeContains(
- hidl_stream, ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION);
- hal_stream.used_in_default_resolution_mode =
- hidl_stream.sensorPixelModesUsed.size() > 0
- ? sensorPixelModeContains(hidl_stream,
- ANDROID_SENSOR_PIXEL_MODE_DEFAULT)
- : true;
- hal_stream_config->streams.push_back(hal_stream);
- }
-
- res = ConvertToHalStreamConfigurationMode(hidl_stream_config.operationMode,
- &hal_stream_config->operation_mode);
- if (res != OK) {
- ALOGE("%s: Converting to HAL opeation mode failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- return res;
- }
-
- res = ConvertToHalMetadata(0, nullptr, hidl_stream_config.sessionParams,
- &hal_stream_config->session_params);
- if (res != OK) {
- ALOGE("%s: Converting to HAL metadata failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- return res;
- }
-
- hal_stream_config->stream_config_counter =
- hidl_stream_config.streamConfigCounter;
- hal_stream_config->multi_resolution_input_image =
- hidl_stream_config.multiResolutionInputImage;
-
- return OK;
-}
-
-status_t ConverToHalStreamConfig(
- const device::V3_4::StreamConfiguration& hidl_stream_config,
- google_camera_hal::StreamConfiguration* hal_stream_config) {
- if (hal_stream_config == nullptr) {
- ALOGE("%s: hal_stream_config is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- status_t res;
- for (auto hidl_stream : hidl_stream_config.streams) {
- google_camera_hal::Stream hal_stream;
- res = ConvertToHalStream(hidl_stream, &hal_stream);
- if (res != OK) {
- ALOGE("%s: Converting to HAL stream failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- return res;
- }
- hal_stream_config->streams.push_back(hal_stream);
- }
-
- res = ConvertToHalStreamConfigurationMode(hidl_stream_config.operationMode,
- &hal_stream_config->operation_mode);
- if (res != OK) {
- ALOGE("%s: Converting to HAL opeation mode failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- return res;
- }
-
- res = ConvertToHalMetadata(0, nullptr, hidl_stream_config.sessionParams,
- &hal_stream_config->session_params);
- if (res != OK) {
- ALOGE("%s: Converting to HAL metadata failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- return res;
- }
-
- return OK;
-}
-
-status_t ConvertToHalStreamType(StreamType hidl_stream_type,
- google_camera_hal::StreamType* hal_stream_type) {
- if (hal_stream_type == nullptr) {
- ALOGE("%s: hal_stream_type is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- switch (hidl_stream_type) {
- case StreamType::OUTPUT:
- *hal_stream_type = google_camera_hal::StreamType::kOutput;
- break;
- case StreamType::INPUT:
- *hal_stream_type = google_camera_hal::StreamType::kInput;
- break;
- default:
- ALOGE("%s: Unknown stream type: %u", __FUNCTION__, hidl_stream_type);
- return BAD_VALUE;
- }
-
- return OK;
-}
-
-status_t ConvertToHalStreamRotation(
- StreamRotation hidl_stream_rotation,
- google_camera_hal::StreamRotation* hal_stream_rotation) {
- if (hal_stream_rotation == nullptr) {
- ALOGE("%s: hal_stream_rotation is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- switch (hidl_stream_rotation) {
- case StreamRotation::ROTATION_0:
- *hal_stream_rotation = google_camera_hal::StreamRotation::kRotation0;
- break;
- case StreamRotation::ROTATION_90:
- *hal_stream_rotation = google_camera_hal::StreamRotation::kRotation90;
- break;
- case StreamRotation::ROTATION_180:
- *hal_stream_rotation = google_camera_hal::StreamRotation::kRotation180;
- break;
- case StreamRotation::ROTATION_270:
- *hal_stream_rotation = google_camera_hal::StreamRotation::kRotation270;
- break;
- default:
- ALOGE("%s: Unknown stream rotation: %u", __FUNCTION__,
- hidl_stream_rotation);
- return BAD_VALUE;
- }
-
- return OK;
-}
-
-status_t ConvertToHalStream(const Stream& hidl_stream,
- google_camera_hal::Stream* hal_stream) {
- if (hal_stream == nullptr) {
- ALOGE("%s: hal_stream is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- *hal_stream = {};
-
- hal_stream->id = hidl_stream.v3_2.id;
-
- status_t res = ConvertToHalStreamType(hidl_stream.v3_2.streamType,
- &hal_stream->stream_type);
- if (res != OK) {
- ALOGE("%s: Converting to HAL stream type failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- return res;
- }
-
- hal_stream->width = hidl_stream.v3_2.width;
- hal_stream->height = hidl_stream.v3_2.height;
- hal_stream->format = (android_pixel_format_t)hidl_stream.v3_2.format;
- hal_stream->usage = (uint64_t)hidl_stream.v3_2.usage;
- hal_stream->data_space = (android_dataspace_t)hidl_stream.v3_2.dataSpace;
-
- res = ConvertToHalStreamRotation(hidl_stream.v3_2.rotation,
- &hal_stream->rotation);
- if (res != OK) {
- ALOGE("%s: Converting to HAL stream rotation failed: %s(%d)", __FUNCTION__,
- strerror(-res), res);
- return res;
- }
-
- if (hidl_stream.physicalCameraId.empty()) {
- hal_stream->is_physical_camera_stream = false;
- } else {
- hal_stream->is_physical_camera_stream = true;
- hal_stream->physical_camera_id = std::stoul(hidl_stream.physicalCameraId);
- }
-
- hal_stream->buffer_size = hidl_stream.bufferSize;
-
- return OK;
-}
-
-status_t ConvertToHalTorchMode(TorchMode hidl_torch_mode,
- google_camera_hal::TorchMode* hal_torch_mode) {
- if (hal_torch_mode == nullptr) {
- ALOGE("%s: hal_torch_mode is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- switch (hidl_torch_mode) {
- case TorchMode::ON:
- *hal_torch_mode = google_camera_hal::TorchMode::kOn;
- break;
- case TorchMode::OFF:
- *hal_torch_mode = google_camera_hal::TorchMode::kOff;
- break;
- default:
- ALOGE("%s: Unknown torch mode: %u", __FUNCTION__, hidl_torch_mode);
- return BAD_VALUE;
- }
-
- return OK;
-}
-
-status_t ConvertToHalBufferRequestStatus(
- const BufferRequestStatus& hidl_buffer_request_status,
- google_camera_hal::BufferRequestStatus* hal_buffer_request_status) {
- if (hal_buffer_request_status == nullptr) {
- ALOGE("%s: hal_buffer_request_status is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- switch (hidl_buffer_request_status) {
- case BufferRequestStatus::OK:
- *hal_buffer_request_status = google_camera_hal::BufferRequestStatus::kOk;
- break;
- case BufferRequestStatus::FAILED_PARTIAL:
- *hal_buffer_request_status =
- google_camera_hal::BufferRequestStatus::kFailedPartial;
- break;
- case BufferRequestStatus::FAILED_CONFIGURING:
- *hal_buffer_request_status =
- google_camera_hal::BufferRequestStatus::kFailedConfiguring;
- break;
- case BufferRequestStatus::FAILED_ILLEGAL_ARGUMENTS:
- *hal_buffer_request_status =
- google_camera_hal::BufferRequestStatus::kFailedIllegalArgs;
- break;
- case BufferRequestStatus::FAILED_UNKNOWN:
- *hal_buffer_request_status =
- google_camera_hal::BufferRequestStatus::kFailedUnknown;
- break;
- default:
- ALOGE("%s: Failed unknown buffer request error code %d", __FUNCTION__,
- hidl_buffer_request_status);
- return BAD_VALUE;
- }
-
- return OK;
-}
-
-status_t ConvertToHalBufferReturnStatus(
- const StreamBufferRet& hidl_stream_buffer_return,
- google_camera_hal::BufferReturn* hal_buffer_return) {
- if (hal_buffer_return == nullptr) {
- ALOGE("%s: hal_buffer_return is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- if (hidl_stream_buffer_return.val.getDiscriminator() ==
- StreamBuffersVal::hidl_discriminator::error) {
- switch (hidl_stream_buffer_return.val.error()) {
- case StreamBufferRequestError::NO_BUFFER_AVAILABLE:
- hal_buffer_return->val.error =
- google_camera_hal::StreamBufferRequestError::kNoBufferAvailable;
- break;
- case StreamBufferRequestError::MAX_BUFFER_EXCEEDED:
- hal_buffer_return->val.error =
- google_camera_hal::StreamBufferRequestError::kMaxBufferExceeded;
- break;
- case StreamBufferRequestError::STREAM_DISCONNECTED:
- hal_buffer_return->val.error =
- google_camera_hal::StreamBufferRequestError::kStreamDisconnected;
- break;
- case StreamBufferRequestError::UNKNOWN_ERROR:
- hal_buffer_return->val.error =
- google_camera_hal::StreamBufferRequestError::kUnknownError;
- break;
- default:
- ALOGE("%s: Unknown StreamBufferRequestError %d", __FUNCTION__,
- hidl_stream_buffer_return.val.error());
- return BAD_VALUE;
- }
- } else {
- hal_buffer_return->val.error =
- google_camera_hal::StreamBufferRequestError::kOk;
- }
-
- return OK;
-}
-
-status_t ConvertStreamConfigurationV34ToV37(
- const device::V3_4::StreamConfiguration& config_3_4,
- device::V3_7::StreamConfiguration* config_3_7) {
- if (config_3_7 == nullptr) {
- ALOGE("%s: config_3_7 is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- config_3_7->streams.resize(config_3_4.streams.size());
- for (size_t i = 0; i < config_3_4.streams.size(); i++) {
- config_3_7->streams[i].v3_4 = config_3_4.streams[i];
- config_3_7->streams[i].groupId = -1;
- }
- config_3_7->operationMode = config_3_4.operationMode;
- config_3_7->sessionParams = config_3_4.sessionParams;
- config_3_7->multiResolutionInputImage = false;
-
- return OK;
-}
-
-status_t ConvertStreamConfigurationV37ToV38(
- const device::V3_7::StreamConfiguration& config_3_7,
- device::V3_8::StreamConfiguration* config_3_8) {
- if (config_3_8 == nullptr) {
- ALOGE("%s: config_3_8 is nullptr.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- config_3_8->streams.resize(config_3_7.streams.size());
- for (size_t i = 0; i < config_3_7.streams.size(); i++) {
- config_3_8->streams[i].v3_7 = config_3_7.streams[i];
- config_3_8->streams[i].dynamicRangeProfile =
- android::hardware::camera::metadata::V3_8::
- CameraMetadataEnumAndroidRequestAvailableDynamicRangeProfilesMap::
- ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
- config_3_8->streams[i].useCase = android::hardware::camera::metadata::V3_8::
- CameraMetadataEnumAndroidScalerAvailableStreamUseCases::
- ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT;
- }
- config_3_8->operationMode = config_3_7.operationMode;
- config_3_8->sessionParams = config_3_7.sessionParams;
- config_3_8->multiResolutionInputImage = config_3_7.multiResolutionInputImage;
-
- return OK;
-}
-
-status_t ConvertToHalDeviceState(
- const hardware::hidl_bitfield<DeviceState> hidl_device_state,
- google_camera_hal::DeviceState& hal_device_state) {
- switch (static_cast<DeviceState>(hidl_device_state)) {
- case DeviceState::NORMAL:
- hal_device_state = google_camera_hal::DeviceState::kNormal;
- break;
- case DeviceState::BACK_COVERED:
- hal_device_state = google_camera_hal::DeviceState::kBackCovered;
- break;
- case DeviceState::FRONT_COVERED:
- hal_device_state = google_camera_hal::DeviceState::kFrontCovered;
- break;
- case DeviceState::FOLDED:
- hal_device_state = google_camera_hal::DeviceState::kFolded;
- break;
- default:
- ALOGE("%s: Failed unknown device state", __FUNCTION__);
- return BAD_VALUE;
- }
-
- return OK;
-}
-} // namespace hidl_utils
-} // namespace implementation
-} // namespace camera
-} // namespace hardware
-} // namespace android
diff --git a/common/hal/hidl_service/hidl_utils.h b/common/hal/hidl_service/hidl_utils.h
deleted file mode 100644
index 4190b27..0000000
--- a/common/hal/hidl_service/hidl_utils.h
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_UTILS_H_
-#define HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_UTILS_H_
-
-#include <android/hardware/camera/common/1.0/types.h>
-#include <android/hardware/camera/device/3.7/ICameraDeviceSession.h>
-#include <android/hardware/camera/device/3.8/ICameraDeviceSession.h>
-#include <android/hardware/camera/device/3.8/types.h>
-#include <fmq/MessageQueue.h>
-#include <hal_types.h>
-#include <hidl/HidlSupport.h>
-
-#include <memory>
-
-#include "hidl_camera_provider.h"
-
-namespace android {
-namespace hardware {
-namespace camera {
-namespace implementation {
-namespace hidl_utils {
-
-using ::android::hardware::hidl_vec;
-using ::android::hardware::camera::common::V1_0::CameraDeviceStatus;
-using ::android::hardware::camera::common::V1_0::CameraMetadataType;
-using ::android::hardware::camera::common::V1_0::CameraResourceCost;
-using ::android::hardware::camera::common::V1_0::Status;
-using ::android::hardware::camera::common::V1_0::TorchMode;
-using ::android::hardware::camera::common::V1_0::TorchModeStatus;
-using ::android::hardware::camera::common::V1_0::VendorTagSection;
-using ::android::hardware::camera::device::V3_2::BufferCache;
-using ::android::hardware::camera::device::V3_2::BufferStatus;
-using ::android::hardware::camera::device::V3_2::CameraMetadata;
-using ::android::hardware::camera::device::V3_2::RequestTemplate;
-using ::android::hardware::camera::device::V3_2::StreamBuffer;
-using ::android::hardware::camera::device::V3_2::StreamConfigurationMode;
-using ::android::hardware::camera::device::V3_2::StreamRotation;
-using ::android::hardware::camera::device::V3_2::StreamType;
-using ::android::hardware::camera::device::V3_4::CaptureResult;
-using ::android::hardware::camera::device::V3_4::Stream;
-using ::android::hardware::camera::device::V3_5::BufferRequest;
-using ::android::hardware::camera::device::V3_5::BufferRequestStatus;
-using ::android::hardware::camera::device::V3_5::StreamBufferRequestError;
-using ::android::hardware::camera::device::V3_5::StreamBufferRet;
-using ::android::hardware::camera::device::V3_5::StreamBuffersVal;
-using ::android::hardware::camera::device::V3_6::HalStreamConfiguration;
-using ::android::hardware::camera::device::V3_7::CaptureRequest;
-using ::android::hardware::camera::device::V3_8::NotifyMsg;
-using ::android::hardware::camera::device::V3_8::StreamConfiguration;
-using ::android::hardware::camera::provider::V2_5::DeviceState;
-
-// Util functions to convert the types between HIDL and Google Camera HAL.
-
-// Conversions from HAL to HIDL
-status_t ConvertToHidlVendorTagSections(
- const std::vector<google_camera_hal::VendorTagSection>& hal_sections,
- hidl_vec<VendorTagSection>* hidl_sections);
-
-status_t ConvertToHidlVendorTagType(
- google_camera_hal::CameraMetadataType hal_type,
- CameraMetadataType* hidl_type);
-
-status_t ConvertToHidlResourceCost(
- const google_camera_hal::CameraResourceCost& hal_cost,
- CameraResourceCost* hidl_cost);
-
-status_t ConvertToHidlHalStreamConfig(
- const std::vector<google_camera_hal::HalStream>& hal_configured_streams,
- HalStreamConfiguration* hidl_hal_stream_config);
-
-// Convert a HAL result to a HIDL result. It will try to write the result
-// metadata to result_metadata_queue. If it fails, it will write the result
-// metadata in hidl_result.
-status_t ConvertToHidlCaptureResult(
- MessageQueue<uint8_t, kSynchronizedReadWrite>* result_metadata_queue,
- std::unique_ptr<google_camera_hal::CaptureResult> hal_result,
- CaptureResult* hidl_result);
-
-status_t ConverToHidlNotifyMessage(
- const google_camera_hal::NotifyMessage& hal_message,
- NotifyMsg* hidl_message);
-
-// Convert from HAL status_t to HIDL Status
-// OK is converted to Status::OK.
-// BAD_VALUE is converted to Status::ILLEGAL_ARGUMENT.
-// -EBUSY is converted to Status::CAMERA_IN_USE.
-// -EUSERS is converted to Status::MAX_CAMERAS_IN_USE.
-// UNKNOWN_TRANSACTION is converted to Status::METHOD_NOT_SUPPORTED.
-// INVALID_OPERATION is converted to Status::OPERATION_NOT_SUPPORTED.
-// DEAD_OBJECT is converted to Status::CAMERA_DISCONNECTED.
-// All other errors are converted to Status::INTERNAL_ERROR.
-Status ConvertToHidlStatus(status_t hal_status);
-
-// Convert from HAL CameraDeviceStatus to HIDL CameraDeviceStatus
-// kNotPresent is converted to CameraDeviceStatus::NOT_PRESENT.
-// kPresent is converted to CameraDeviceStatus::PRESENT.
-// kEnumerating is converted to CameraDeviceStatus::ENUMERATING.
-status_t ConvertToHidlCameraDeviceStatus(
- google_camera_hal::CameraDeviceStatus hal_camera_device_status,
- CameraDeviceStatus* hidl_camera_device_status);
-
-// Convert from HAL TorchModeStatus to HIDL TorchModeStatus
-// kNotAvailable is converted to TorchModeStatus::NOT_AVAILABLE.
-// kAvailableOff is converted to TorchModeStatus::AVAILABLE_OFF.
-// kAvailableOn is converted to TorchModeStatus::AVAILABLE_ON.
-status_t ConvertToHidlTorchModeStatus(
- google_camera_hal::TorchModeStatus hal_torch_status,
- TorchModeStatus* hidl_torch_status);
-
-// Convert a HAL request to a HIDL request.
-status_t ConvertToHidlBufferRequest(
- const std::vector<google_camera_hal::BufferRequest>& hal_buffer_requests,
- hidl_vec<BufferRequest>* hidl_buffer_requests);
-
-// Convert a HAL stream buffer to a HIDL hidl stream buffer.
-status_t ConvertToHidlStreamBuffer(
- const google_camera_hal::StreamBuffer& hal_buffer,
- StreamBuffer* hidl_buffer);
-
-// Conversions from HIDL to HAL.
-status_t ConvertToHalTemplateType(
- RequestTemplate hidl_template,
- google_camera_hal::RequestTemplate* hal_template);
-
-status_t ConvertToHalStreamBuffer(const StreamBuffer& hidl_buffer,
- google_camera_hal::StreamBuffer* hal_buffer);
-
-status_t ConvertToHalMetadata(
- uint32_t message_queue_setting_size,
- MessageQueue<uint8_t, kSynchronizedReadWrite>* request_metadata_queue,
- const CameraMetadata& request_settings,
- std::unique_ptr<google_camera_hal::HalCameraMetadata>* hal_metadata);
-
-status_t ConvertToHalCaptureRequest(
- const CaptureRequest& hidl_request,
- MessageQueue<uint8_t, kSynchronizedReadWrite>* request_metadata_queue,
- google_camera_hal::CaptureRequest* hal_request);
-
-status_t ConvertToHalBufferCaches(
- const hidl_vec<BufferCache>& hidl_buffer_caches,
- std::vector<google_camera_hal::BufferCache>* hal_buffer_caches);
-
-status_t ConverToHalStreamConfig(
- const StreamConfiguration& hidl_stream_config,
- google_camera_hal::StreamConfiguration* hal_stream_config);
-
-status_t ConverToHalStreamConfig(
- const device::V3_7::StreamConfiguration& hidl_stream_config,
- google_camera_hal::StreamConfiguration* hal_stream_config);
-
-status_t ConverToHalStreamConfig(
- const device::V3_4::StreamConfiguration& hidl_stream_config,
- google_camera_hal::StreamConfiguration* hal_stream_config);
-
-status_t ConvertToHalStreamConfigurationMode(
- StreamConfigurationMode hidl_mode,
- google_camera_hal::StreamConfigurationMode* hal_mode);
-
-status_t ConvertToHalBufferStatus(BufferStatus hidl_status,
- google_camera_hal::BufferStatus* hal_status);
-
-status_t ConvertToHalStream(const Stream& hidl_stream,
- google_camera_hal::Stream* hal_stream);
-
-status_t ConvertToHalStreamRotation(
- StreamRotation hidl_stream_rotation,
- google_camera_hal::StreamRotation* hal_stream_rotation);
-
-status_t ConvertToHalStreamType(StreamType hidl_stream_type,
- google_camera_hal::StreamType* hal_stream_type);
-
-status_t ConvertToHalTorchMode(TorchMode hidl_torch_mode,
- google_camera_hal::TorchMode* hal_torch_mode);
-
-status_t ConvertToHalBufferRequestStatus(
- const BufferRequestStatus& hidl_buffer_request_status,
- google_camera_hal::BufferRequestStatus* hal_buffer_request_status);
-
-status_t ConvertToHalBufferReturnStatus(
- const StreamBufferRet& hidl_stream_buffer_return,
- google_camera_hal::BufferReturn* hal_buffer_return);
-
-status_t ConvertStreamConfigurationV34ToV37(
- const device::V3_4::StreamConfiguration& config_3_4,
- device::V3_7::StreamConfiguration* config_3_7);
-
-status_t ConvertStreamConfigurationV37ToV38(
- const device::V3_7::StreamConfiguration& config_3_7,
- device::V3_8::StreamConfiguration* config_3_8);
-
-status_t ConvertToHalDeviceState(
- const hardware::hidl_bitfield<DeviceState> hidl_device_state,
- google_camera_hal::DeviceState& hal_device_state);
-
-} // namespace hidl_utils
-} // namespace implementation
-} // namespace camera
-} // namespace hardware
-} // namespace android
-
-#endif // HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_UTILS_H_