Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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_SERVERS_CAMERA_CAMERA3DEVICE_H |
| 18 | #define ANDROID_SERVERS_CAMERA_CAMERA3DEVICE_H |
| 19 | |
| 20 | #include <utils/Condition.h> |
| 21 | #include <utils/Errors.h> |
| 22 | #include <utils/List.h> |
| 23 | #include <utils/Mutex.h> |
| 24 | #include <utils/Thread.h> |
| 25 | |
| 26 | #include "CameraDeviceBase.h" |
| 27 | |
| 28 | #include "hardware/camera3.h" |
| 29 | |
| 30 | /** |
| 31 | * Function pointer types with C calling convention to |
| 32 | * use for HAL callback functions. |
| 33 | */ |
| 34 | extern "C" { |
| 35 | typedef void (callbacks_process_capture_result_t)( |
| 36 | const struct camera3_callback_ops *, |
| 37 | const camera3_capture_result_t *); |
| 38 | |
| 39 | typedef void (callbacks_notify_t)( |
| 40 | const struct camera3_callback_ops *, |
| 41 | const camera3_notify_msg_t *); |
| 42 | } |
| 43 | |
| 44 | namespace android { |
| 45 | |
| 46 | /** |
| 47 | * CameraDevice for HAL devices with version CAMERA_DEVICE_API_VERSION_3_0 |
| 48 | */ |
| 49 | class Camera3Device : |
| 50 | public CameraDeviceBase, |
| 51 | private camera3_callback_ops { |
| 52 | public: |
| 53 | Camera3Device(int id); |
| 54 | |
| 55 | virtual ~Camera3Device(); |
| 56 | |
| 57 | /** |
| 58 | * CameraDevice interface |
| 59 | */ |
Igor Murashkin | 7138105 | 2013-03-04 14:53:08 -0800 | [diff] [blame^] | 60 | virtual int getId() const; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 61 | virtual status_t initialize(camera_module_t *module); |
| 62 | virtual status_t disconnect(); |
| 63 | virtual status_t dump(int fd, const Vector<String16> &args); |
| 64 | virtual const CameraMetadata& info() const; |
| 65 | virtual status_t capture(CameraMetadata &request); |
| 66 | virtual status_t setStreamingRequest(const CameraMetadata &request); |
| 67 | virtual status_t clearStreamingRequest(); |
| 68 | virtual status_t waitUntilRequestReceived(int32_t requestId, nsecs_t timeout); |
| 69 | virtual status_t createStream(sp<ANativeWindow> consumer, |
| 70 | uint32_t width, uint32_t height, int format, size_t size, |
| 71 | int *id); |
| 72 | virtual status_t createReprocessStreamFromStream(int outputId, int *id); |
| 73 | virtual status_t getStreamInfo(int id, |
| 74 | uint32_t *width, uint32_t *height, uint32_t *format); |
| 75 | virtual status_t setStreamTransform(int id, int transform); |
| 76 | virtual status_t deleteStream(int id); |
| 77 | virtual status_t deleteReprocessStream(int id); |
| 78 | virtual status_t createDefaultRequest(int templateId, CameraMetadata *request); |
| 79 | virtual status_t waitUntilDrained(); |
| 80 | virtual status_t setNotifyCallback(NotificationListener *listener); |
| 81 | virtual status_t waitForNextFrame(nsecs_t timeout); |
| 82 | virtual status_t getNextFrame(CameraMetadata *frame); |
| 83 | virtual status_t triggerAutofocus(uint32_t id); |
| 84 | virtual status_t triggerCancelAutofocus(uint32_t id); |
| 85 | virtual status_t triggerPrecaptureMetering(uint32_t id); |
| 86 | virtual status_t pushReprocessBuffer(int reprocessStreamId, |
| 87 | buffer_handle_t *buffer, wp<BufferReleasedListener> listener); |
| 88 | |
| 89 | private: |
| 90 | const int mId; |
| 91 | camera3_device_t *mHal3Device; |
| 92 | |
| 93 | CameraMetadata mDeviceInfo; |
| 94 | vendor_tag_query_ops_t mVendorTagOps; |
| 95 | |
| 96 | /** |
| 97 | * Thread for managing capture request submission to HAL device. |
| 98 | */ |
| 99 | class RequestThread: public Thread { |
| 100 | |
| 101 | public: |
| 102 | |
| 103 | RequestThread(wp<Camera3Device> parent); |
| 104 | |
| 105 | protected: |
| 106 | |
| 107 | virtual bool threadLoop(); |
| 108 | |
| 109 | private: |
| 110 | |
| 111 | wp<Camera3Device> mParent; |
| 112 | |
| 113 | }; |
| 114 | sp<RequestThread> requestThread; |
| 115 | |
| 116 | /** |
| 117 | * Callback functions from HAL device |
| 118 | */ |
| 119 | void processCaptureResult(const camera3_capture_result *result); |
| 120 | |
| 121 | void notify(const camera3_notify_msg *msg); |
| 122 | |
| 123 | /** |
| 124 | * Static callback forwarding methods from HAL to instance |
| 125 | */ |
| 126 | static callbacks_process_capture_result_t sProcessCaptureResult; |
| 127 | |
| 128 | static callbacks_notify_t sNotify; |
| 129 | |
| 130 | }; // class Camera3Device |
| 131 | |
| 132 | }; // namespace android |
| 133 | |
| 134 | #endif |