CameraDevice_3_2.h revision 50fe43099495dcb388fdd7eb1ff78609aaa0cf88
1/*
2 * Copyright (C) 2016 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_HARDWARE_CAMERA_DEVICE_V3_2_CAMERADEVICE_H
18#define ANDROID_HARDWARE_CAMERA_DEVICE_V3_2_CAMERADEVICE_H
19
20#include "utils/Mutex.h"
21#include "CameraModule.h"
22#include "CameraMetadata.h"
23#include "CameraDeviceSession.h"
24
25#include <android/hardware/camera/device/3.2/ICameraDevice.h>
26#include <hidl/Status.h>
27#include <hidl/MQDescriptor.h>
28
29namespace android {
30namespace hardware {
31namespace camera {
32namespace device {
33namespace V3_2 {
34namespace implementation {
35
36using ::android::hardware::camera::device::V3_2::RequestTemplate;
37using ::android::hardware::camera::device::V3_2::ICameraDevice;
38using ::android::hardware::camera::device::V3_2::ICameraDeviceCallback;
39using ::android::hardware::camera::device::V3_2::ICameraDeviceSession;
40using ::android::hardware::camera::common::V1_0::CameraResourceCost;
41using ::android::hardware::camera::common::V1_0::Status;
42using ::android::hardware::camera::common::V1_0::TorchMode;
43using ::android::hardware::camera::common::V1_0::helper::CameraModule;
44using ::android::hardware::Return;
45using ::android::hardware::Void;
46using ::android::hardware::hidl_vec;
47using ::android::hardware::hidl_string;
48using ::android::sp;
49using ::android::Mutex;
50
51/*
52 * The camera device HAL implementation is opened lazily (via the open call)
53 */
54struct CameraDevice : public ICameraDevice {
55    // Called by provider HAL. Provider HAL must ensure the uniqueness of
56    // CameraDevice object per cameraId, or there could be multiple CameraDevice
57    // trying to access the same physical camera.
58    // Also, provider will have to keep track of all CameraDevice objects in
59    // order to notify CameraDevice when the underlying camera is detached
60    CameraDevice(sp<CameraModule> module,
61                 const std::string& cameraId,
62                 const SortedVector<std::pair<std::string, std::string>>& cameraDeviceNames);
63    ~CameraDevice();
64    // Caller must use this method to check if CameraDevice ctor failed
65    bool isInitFailed() { return mInitFail; }
66    // Used by provider HAL to signal external camera disconnected
67    void setConnectionStatus(bool connected);
68
69    /* Methods from ::android::hardware::camera::device::V3_2::ICameraDevice follow. */
70    // The following method can be called without opening the actual camera device
71    Return<void> getResourceCost(getResourceCost_cb _hidl_cb) override;
72    Return<void> getCameraCharacteristics(getCameraCharacteristics_cb _hidl_cb) override;
73    Return<Status> setTorchMode(TorchMode mode) override;
74
75    // Open the device HAL and also return a default capture session
76    Return<void> open(const sp<ICameraDeviceCallback>& callback, open_cb _hidl_cb) override;
77
78
79    // Forward the dump call to the opened session, or do nothing
80    Return<void> dumpState(const ::android::hardware::hidl_handle& fd) override;
81    /* End of Methods from ::android::hardware::camera::device::V3_2::ICameraDevice */
82
83protected:
84
85    // Overridden by child implementations for returning different versions of CameraDeviceSession
86    virtual sp<CameraDeviceSession> createSession(camera3_device_t*,
87            const camera_metadata_t* deviceInfo,
88            const sp<ICameraDeviceCallback>&);
89
90    const sp<CameraModule> mModule;
91    const std::string mCameraId;
92    // const after ctor
93    int   mCameraIdInt;
94    int   mDeviceVersion;
95    bool  mInitFail = false;
96    // Set by provider (when external camera is connected/disconnected)
97    bool  mDisconnected;
98    wp<CameraDeviceSession> mSession = nullptr;
99
100    const SortedVector<std::pair<std::string, std::string>>& mCameraDeviceNames;
101
102    // gating access to mSession and mDisconnected
103    mutable Mutex mLock;
104
105    // convert conventional HAL status to HIDL Status
106    static Status getHidlStatus(int);
107
108    Status initStatus() const;
109};
110
111}  // namespace implementation
112}  // namespace V3_2
113}  // namespace device
114}  // namespace camera
115}  // namespace hardware
116}  // namespace android
117
118#endif  // ANDROID_HARDWARE_CAMERA_DEVICE_V3_2_CAMERADEVICE_H
119