| Jayant Chowdhary | 0c94727 | 2018-08-15 14:42:04 -0700 | [diff] [blame] | 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.0/types.h> | 
|  | 28 | #include <android/hardware/camera2/ICameraDeviceCallbacks.h> | 
|  | 29 | #include <fmq/MessageQueue.h> | 
|  | 30 | #include <hidl/MQDescriptor.h> | 
|  | 31 | #include <hidl/Status.h> | 
|  | 32 |  | 
|  | 33 | #include <CameraService.h> | 
|  | 34 |  | 
|  | 35 | namespace android { | 
|  | 36 | namespace frameworks { | 
|  | 37 | namespace cameraservice { | 
|  | 38 | namespace device { | 
|  | 39 | namespace V2_0 { | 
|  | 40 | namespace implementation { | 
|  | 41 |  | 
|  | 42 | using frameworks::cameraservice::device::V2_0::StreamConfigurationMode; | 
|  | 43 | using hardware::camera2::CaptureRequest; | 
|  | 44 | using hardware::hidl_vec; | 
|  | 45 | using hardware::kSynchronizedReadWrite; | 
|  | 46 | using hardware::MessageQueue; | 
|  | 47 | using hardware::MQDescriptorSync; | 
|  | 48 | using hardware::Return; | 
|  | 49 | using CaptureResultMetadataQueue = MessageQueue<uint8_t, kSynchronizedReadWrite>; | 
|  | 50 | using CaptureRequestMetadataQueue = MessageQueue<uint8_t, kSynchronizedReadWrite>; | 
|  | 51 | using TemplateId = frameworks::cameraservice::device::V2_0::TemplateId; | 
|  | 52 |  | 
|  | 53 | using HCameraDeviceUser = device::V2_0::ICameraDeviceUser; | 
|  | 54 | using HCameraMetadata = cameraservice::service::V2_0::CameraMetadata; | 
|  | 55 | using HCaptureRequest = device::V2_0::CaptureRequest; | 
|  | 56 | using HOutputConfiguration = frameworks::cameraservice::device::V2_0::OutputConfiguration; | 
|  | 57 | using HPhysicalCameraSettings = frameworks::cameraservice::device::V2_0::PhysicalCameraSettings; | 
|  | 58 | using HStatus = frameworks::cameraservice::common::V2_0::Status; | 
|  | 59 |  | 
|  | 60 | static constexpr int32_t REQUEST_ID_NONE = -1; | 
|  | 61 |  | 
|  | 62 | struct HidlCameraDeviceUser final : public HCameraDeviceUser { | 
|  | 63 | HidlCameraDeviceUser(const sp<hardware::camera2::ICameraDeviceUser> &deviceRemote); | 
|  | 64 |  | 
|  | 65 | ~HidlCameraDeviceUser() { } | 
|  | 66 |  | 
|  | 67 | virtual Return<void> disconnect() override; | 
|  | 68 |  | 
|  | 69 | virtual Return<void> getCaptureRequestMetadataQueue( | 
|  | 70 | getCaptureRequestMetadataQueue_cb _hidl_cb) override; | 
|  | 71 |  | 
|  | 72 | virtual Return<void> getCaptureResultMetadataQueue( | 
|  | 73 | getCaptureResultMetadataQueue_cb _hidl_cb) override; | 
|  | 74 |  | 
|  | 75 | virtual Return<void> submitRequestList(const hidl_vec<HCaptureRequest>& requestList, | 
|  | 76 | bool streaming, submitRequestList_cb _hidl_cb) override; | 
|  | 77 |  | 
|  | 78 | virtual Return<void> cancelRepeatingRequest(cancelRepeatingRequest_cb _hidl_cb) override; | 
|  | 79 |  | 
|  | 80 | virtual Return<HStatus> beginConfigure() override; | 
|  | 81 |  | 
|  | 82 | virtual Return<HStatus> endConfigure(StreamConfigurationMode operatingMode, | 
|  | 83 | const hidl_vec<uint8_t>& sessionParams); | 
|  | 84 |  | 
|  | 85 | virtual Return<HStatus> deleteStream(int32_t streamId) override; | 
|  | 86 |  | 
|  | 87 | virtual Return<void> createStream(const HOutputConfiguration& outputConfiguration, | 
|  | 88 | createStream_cb _hidl_cb) override; | 
|  | 89 |  | 
|  | 90 | Return<void> createDefaultRequest(TemplateId templateId, | 
|  | 91 | createDefaultRequest_cb _hidl_cb) override; | 
|  | 92 |  | 
|  | 93 | virtual Return<HStatus> waitUntilIdle() override; | 
|  | 94 |  | 
|  | 95 | virtual Return<void> flush(flush_cb _hidl_cb) override; | 
|  | 96 |  | 
|  | 97 | virtual Return<HStatus> updateOutputConfiguration( | 
|  | 98 | int32_t streamId, const HOutputConfiguration& outputConfiguration) override; | 
|  | 99 |  | 
|  | 100 | bool initStatus() { return mInitSuccess; } | 
|  | 101 |  | 
|  | 102 | std::shared_ptr<CaptureResultMetadataQueue> getCaptureResultMetadataQueue() { | 
|  | 103 | return mCaptureResultMetadataQueue; | 
|  | 104 | } | 
|  | 105 |  | 
|  | 106 | private: | 
|  | 107 | bool initDevice(); | 
|  | 108 |  | 
|  | 109 | bool convertRequestFromHidl(const HCaptureRequest &hRequest, CaptureRequest *request); | 
|  | 110 |  | 
|  | 111 | bool copyPhysicalCameraSettings( | 
|  | 112 | const hidl_vec<HPhysicalCameraSettings> &hPhysicalCameraSettings, | 
|  | 113 | std::vector<CaptureRequest::PhysicalCameraSettings> *physicalCameraSettings); | 
|  | 114 |  | 
|  | 115 | const sp<hardware::camera2::ICameraDeviceUser> mDeviceRemote; | 
|  | 116 | std::unique_ptr<CaptureRequestMetadataQueue> mCaptureRequestMetadataQueue = nullptr; | 
|  | 117 | std::shared_ptr<CaptureResultMetadataQueue> mCaptureResultMetadataQueue = nullptr; | 
|  | 118 | bool mInitSuccess = false; | 
|  | 119 | int32_t mRequestId = REQUEST_ID_NONE; | 
|  | 120 | }; | 
|  | 121 |  | 
|  | 122 | } // implementation | 
|  | 123 | } // V2_0 | 
|  | 124 | } // device | 
|  | 125 | } // cameraservice | 
|  | 126 | } // frameworks | 
|  | 127 | } // android | 
|  | 128 | #endif // ANDROID_FRAMEOWORKS_CAMERADEVICEUSER_V2_0_CAMERADEVICEUSER_H |