Yin-Chia Yeh | faef8f9 | 2016-10-31 12:53:56 -0700 | [diff] [blame] | 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_CAMERADEVICE3SESSION_H |
| 18 | #define ANDROID_HARDWARE_CAMERA_DEVICE_V3_2_CAMERADEVICE3SESSION_H |
| 19 | |
| 20 | #include "hardware/camera_common.h" |
| 21 | #include "hardware/camera3.h" |
| 22 | #include "utils/Mutex.h" |
| 23 | #include <android/hardware/camera/device/3.2/ICameraDevice.h> |
| 24 | #include <android/hardware/camera/device/3.2/ICameraDeviceSession.h> |
| 25 | #include <hidl/Status.h> |
| 26 | #include <hidl/MQDescriptor.h> |
| 27 | #include <include/convert.h> |
| 28 | |
| 29 | namespace android { |
| 30 | namespace hardware { |
| 31 | namespace camera { |
| 32 | namespace device { |
| 33 | namespace V3_2 { |
| 34 | namespace implementation { |
| 35 | |
| 36 | using ::android::hardware::camera::device::V3_2::CaptureRequest; |
| 37 | using ::android::hardware::camera::device::V3_2::HalStreamConfiguration; |
| 38 | using ::android::hardware::camera::device::V3_2::StreamConfiguration; |
| 39 | using ::android::hardware::camera::device::V3_2::ICameraDeviceSession; |
| 40 | using ::android::hardware::camera::common::V1_0::Status; |
| 41 | using ::android::hardware::Return; |
| 42 | using ::android::hardware::Void; |
| 43 | using ::android::hardware::hidl_vec; |
| 44 | using ::android::hardware::hidl_string; |
| 45 | using ::android::sp; |
| 46 | using ::android::Mutex; |
| 47 | |
| 48 | /** |
| 49 | * Function pointer types with C calling convention to |
| 50 | * use for HAL callback functions. |
| 51 | */ |
| 52 | extern "C" { |
| 53 | typedef void (callbacks_process_capture_result_t)( |
| 54 | const struct camera3_callback_ops *, |
| 55 | const camera3_capture_result_t *); |
| 56 | |
| 57 | typedef void (callbacks_notify_t)( |
| 58 | const struct camera3_callback_ops *, |
| 59 | const camera3_notify_msg_t *); |
| 60 | } |
| 61 | |
| 62 | struct CameraDeviceSession : public ICameraDeviceSession, private camera3_callback_ops { |
| 63 | |
| 64 | CameraDeviceSession(camera3_device_t*, const sp<ICameraDeviceCallback>&); |
| 65 | ~CameraDeviceSession(); |
| 66 | // Call by CameraDevice to dump active device states |
| 67 | void dumpState(const native_handle_t* fd); |
| 68 | // Caller must use this method to check if CameraDeviceSession ctor failed |
| 69 | bool isInitFailed() { return mInitFail; } |
| 70 | // Used by CameraDevice to signal external camera disconnected |
| 71 | void disconnect(); |
| 72 | bool isClosed(); |
| 73 | |
| 74 | // Methods from ::android::hardware::camera::device::V3_2::ICameraDeviceSession follow. |
| 75 | Return<void> constructDefaultRequestSettings(RequestTemplate type, constructDefaultRequestSettings_cb _hidl_cb) override; |
| 76 | Return<void> configureStreams(const StreamConfiguration& requestedConfiguration, configureStreams_cb _hidl_cb) override; |
| 77 | Return<Status> processCaptureRequest(const CaptureRequest& request) override; |
| 78 | Return<Status> flush() override; |
| 79 | Return<void> close() override; |
| 80 | |
| 81 | private: |
| 82 | // protecting mClosed/mDisconnected/mInitFail |
| 83 | mutable Mutex mStateLock; |
| 84 | // device is closed either |
| 85 | // - closed by user |
| 86 | // - init failed |
| 87 | // - camera disconnected |
| 88 | bool mClosed = false; |
| 89 | |
| 90 | // Set by CameraDevice (when external camera is disconnected) |
| 91 | bool mDisconnected = false; |
| 92 | |
| 93 | camera3_device_t* mDevice; |
| 94 | const sp<ICameraDeviceCallback>& mCallback; |
| 95 | // Stream ID -> Camera3Stream cache |
| 96 | std::map<int, Camera3Stream> mStreamMap; |
| 97 | // (streamID, frameNumber) -> inflight buffer cache |
| 98 | std::map<std::pair<int, uint32_t>, StreamBufferCache> mInflightBuffers; |
| 99 | |
| 100 | bool mInitFail; |
| 101 | bool initialize(); |
| 102 | |
| 103 | Status initStatus() const; |
| 104 | |
| 105 | // Validate and import request's input buffer and acquire fence |
| 106 | static Status importRequest( |
| 107 | const CaptureRequest& request, |
| 108 | hidl_vec<buffer_handle_t>& allBufs, |
| 109 | hidl_vec<int>& allFences); |
| 110 | |
| 111 | static void cleanupInflightBufferFences( |
| 112 | hidl_vec<buffer_handle_t>& allBufs, size_t numBufs, |
| 113 | hidl_vec<int>& allFences, size_t numFences); |
| 114 | |
| 115 | /** |
| 116 | * Static callback forwarding methods from HAL to instance |
| 117 | */ |
| 118 | static callbacks_process_capture_result_t sProcessCaptureResult; |
| 119 | static callbacks_notify_t sNotify; |
| 120 | }; |
| 121 | |
| 122 | } // namespace implementation |
| 123 | } // namespace V3_2 |
| 124 | } // namespace device |
| 125 | } // namespace camera |
| 126 | } // namespace hardware |
| 127 | } // namespace android |
| 128 | |
| 129 | #endif // ANDROID_HARDWARE_CAMERA_DEVICE_V3_2_CAMERADEVICE3SESSION_H |