1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_FRAMEWORKS_CAMERADEVICEUSER_V2_0_CAMERADEVICEUSER_H 18 #define ANDROID_FRAMEWORKS_CAMERADEVICEUSER_V2_0_CAMERADEVICEUSER_H 19 20 #include <mutex> 21 #include <memory> 22 #include <thread> 23 24 #include <android/frameworks/cameraservice/common/2.0/types.h> 25 #include <android/frameworks/cameraservice/service/2.0/types.h> 26 #include <android/frameworks/cameraservice/device/2.0/ICameraDeviceUser.h> 27 #include <android/frameworks/cameraservice/device/2.1/ICameraDeviceUser.h> 28 #include <android/frameworks/cameraservice/device/2.0/types.h> 29 #include <android/hardware/camera2/ICameraDeviceCallbacks.h> 30 #include <fmq/MessageQueue.h> 31 #include <hidl/MQDescriptor.h> 32 #include <hidl/Status.h> 33 34 #include <CameraService.h> 35 36 namespace android { 37 namespace frameworks { 38 namespace cameraservice { 39 namespace device { 40 namespace V2_1 { 41 namespace implementation { 42 43 using frameworks::cameraservice::device::V2_0::StreamConfigurationMode; 44 using hardware::camera2::CaptureRequest; 45 using hardware::hidl_vec; 46 using hardware::kSynchronizedReadWrite; 47 using hardware::MessageQueue; 48 using hardware::MQDescriptorSync; 49 using hardware::Return; 50 using CaptureResultMetadataQueue = MessageQueue<uint8_t, kSynchronizedReadWrite>; 51 using CaptureRequestMetadataQueue = MessageQueue<uint8_t, kSynchronizedReadWrite>; 52 using TemplateId = frameworks::cameraservice::device::V2_0::TemplateId; 53 54 using HCameraDeviceUser = device::V2_1::ICameraDeviceUser; 55 using HCameraMetadata = cameraservice::service::V2_0::CameraMetadata; 56 using HCaptureRequest = device::V2_0::CaptureRequest; 57 using HSessionConfiguration = frameworks::cameraservice::device::V2_0::SessionConfiguration; 58 using HOutputConfiguration = frameworks::cameraservice::device::V2_0::OutputConfiguration; 59 using HPhysicalCameraSettings = frameworks::cameraservice::device::V2_0::PhysicalCameraSettings; 60 using HStatus = frameworks::cameraservice::common::V2_0::Status; 61 62 static constexpr int32_t REQUEST_ID_NONE = -1; 63 64 struct HidlCameraDeviceUser final : public HCameraDeviceUser { 65 HidlCameraDeviceUser(const sp<hardware::camera2::ICameraDeviceUser> &deviceRemote); 66 ~HidlCameraDeviceUserfinal67 ~HidlCameraDeviceUser() { } 68 69 virtual Return<void> disconnect() override; 70 71 virtual Return<void> getCaptureRequestMetadataQueue( 72 getCaptureRequestMetadataQueue_cb _hidl_cb) override; 73 74 virtual Return<void> getCaptureResultMetadataQueue( 75 getCaptureResultMetadataQueue_cb _hidl_cb) override; 76 77 virtual Return<void> submitRequestList(const hidl_vec<HCaptureRequest>& requestList, 78 bool streaming, submitRequestList_cb _hidl_cb) override; 79 80 virtual Return<void> cancelRepeatingRequest(cancelRepeatingRequest_cb _hidl_cb) override; 81 82 virtual Return<HStatus> beginConfigure() override; 83 84 virtual Return<HStatus> endConfigure(StreamConfigurationMode operatingMode, 85 const hidl_vec<uint8_t>& sessionParams); 86 87 virtual Return<HStatus> endConfigure_2_1(StreamConfigurationMode operatingMode, 88 const hidl_vec<uint8_t>& sessionParams, 89 nsecs_t startTimeNs); 90 91 virtual Return<HStatus> deleteStream(int32_t streamId) override; 92 93 virtual Return<void> createStream(const HOutputConfiguration& outputConfiguration, 94 createStream_cb _hidl_cb) override; 95 96 Return<void> createDefaultRequest(TemplateId templateId, 97 createDefaultRequest_cb _hidl_cb) override; 98 99 virtual Return<HStatus> waitUntilIdle() override; 100 101 virtual Return<void> flush(flush_cb _hidl_cb) override; 102 103 virtual Return<HStatus> updateOutputConfiguration( 104 int32_t streamId, const HOutputConfiguration& outputConfiguration) override; 105 106 virtual Return<void> isSessionConfigurationSupported( 107 const HSessionConfiguration& sessionConfiguration, 108 isSessionConfigurationSupported_cb _hidl_cb) override; 109 initStatusfinal110 bool initStatus() { return mInitSuccess; } 111 getCaptureResultMetadataQueuefinal112 std::shared_ptr<CaptureResultMetadataQueue> getCaptureResultMetadataQueue() { 113 return mCaptureResultMetadataQueue; 114 } 115 116 private: 117 bool initDevice(); 118 119 bool convertRequestFromHidl(const HCaptureRequest &hRequest, CaptureRequest *request); 120 121 bool copyPhysicalCameraSettings( 122 const hidl_vec<HPhysicalCameraSettings> &hPhysicalCameraSettings, 123 std::vector<CaptureRequest::PhysicalCameraSettings> *physicalCameraSettings); 124 125 const sp<hardware::camera2::ICameraDeviceUser> mDeviceRemote; 126 std::unique_ptr<CaptureRequestMetadataQueue> mCaptureRequestMetadataQueue = nullptr; 127 std::shared_ptr<CaptureResultMetadataQueue> mCaptureResultMetadataQueue = nullptr; 128 bool mInitSuccess = false; 129 int32_t mRequestId = REQUEST_ID_NONE; 130 }; 131 132 } // implementation 133 } // V2_0 134 } // device 135 } // cameraservice 136 } // frameworks 137 } // android 138 #endif // ANDROID_FRAMEOWORKS_CAMERADEVICEUSER_V2_0_CAMERADEVICEUSER_H 139