Home | History | Annotate | Download | only in hidl
      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 HSessionConfiguration = frameworks::cameraservice::device::V2_0::SessionConfiguration;
     57 using HOutputConfiguration = frameworks::cameraservice::device::V2_0::OutputConfiguration;
     58 using HPhysicalCameraSettings = frameworks::cameraservice::device::V2_0::PhysicalCameraSettings;
     59 using HStatus = frameworks::cameraservice::common::V2_0::Status;
     60 
     61 static constexpr int32_t REQUEST_ID_NONE = -1;
     62 
     63 struct HidlCameraDeviceUser final : public HCameraDeviceUser {
     64     HidlCameraDeviceUser(const sp<hardware::camera2::ICameraDeviceUser> &deviceRemote);
     65 
     66     ~HidlCameraDeviceUser() { }
     67 
     68     virtual Return<void> disconnect() override;
     69 
     70     virtual Return<void> getCaptureRequestMetadataQueue(
     71         getCaptureRequestMetadataQueue_cb _hidl_cb) override;
     72 
     73     virtual Return<void> getCaptureResultMetadataQueue(
     74         getCaptureResultMetadataQueue_cb _hidl_cb) override;
     75 
     76     virtual Return<void> submitRequestList(const hidl_vec<HCaptureRequest>& requestList,
     77                                            bool streaming, submitRequestList_cb _hidl_cb) override;
     78 
     79     virtual Return<void> cancelRepeatingRequest(cancelRepeatingRequest_cb _hidl_cb) override;
     80 
     81     virtual Return<HStatus> beginConfigure() override;
     82 
     83     virtual Return<HStatus> endConfigure(StreamConfigurationMode operatingMode,
     84                                          const hidl_vec<uint8_t>& sessionParams);
     85 
     86     virtual Return<HStatus> deleteStream(int32_t streamId) override;
     87 
     88     virtual Return<void> createStream(const HOutputConfiguration& outputConfiguration,
     89                                       createStream_cb _hidl_cb) override;
     90 
     91     Return<void> createDefaultRequest(TemplateId templateId,
     92                                       createDefaultRequest_cb _hidl_cb) override;
     93 
     94     virtual Return<HStatus> waitUntilIdle() override;
     95 
     96     virtual Return<void> flush(flush_cb _hidl_cb) override;
     97 
     98     virtual Return<HStatus> updateOutputConfiguration(
     99         int32_t streamId, const HOutputConfiguration& outputConfiguration) override;
    100 
    101     virtual Return<void> isSessionConfigurationSupported(
    102         const HSessionConfiguration& sessionConfiguration,
    103         isSessionConfigurationSupported_cb _hidl_cb) override;
    104 
    105     bool initStatus() { return mInitSuccess; }
    106 
    107     std::shared_ptr<CaptureResultMetadataQueue> getCaptureResultMetadataQueue() {
    108         return mCaptureResultMetadataQueue;
    109     }
    110 
    111  private:
    112     bool initDevice();
    113 
    114     bool convertRequestFromHidl(const HCaptureRequest &hRequest, CaptureRequest *request);
    115 
    116     bool copyPhysicalCameraSettings(
    117         const hidl_vec<HPhysicalCameraSettings> &hPhysicalCameraSettings,
    118         std::vector<CaptureRequest::PhysicalCameraSettings> *physicalCameraSettings);
    119 
    120     const sp<hardware::camera2::ICameraDeviceUser> mDeviceRemote;
    121     std::unique_ptr<CaptureRequestMetadataQueue> mCaptureRequestMetadataQueue = nullptr;
    122     std::shared_ptr<CaptureResultMetadataQueue> mCaptureResultMetadataQueue = nullptr;
    123     bool mInitSuccess = false;
    124     int32_t mRequestId = REQUEST_ID_NONE;
    125 };
    126 
    127 } // implementation
    128 } // V2_0
    129 } // device
    130 } // cameraservice
    131 } // frameworks
    132 } // android
    133 #endif // ANDROID_FRAMEOWORKS_CAMERADEVICEUSER_V2_0_CAMERADEVICEUSER_H
    134