Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -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_PROCAMERA2CLIENT_H |
| 18 | #define ANDROID_SERVERS_CAMERA_PROCAMERA2CLIENT_H |
| 19 | |
| 20 | #include "Camera2Device.h" |
| 21 | #include "CameraService.h" |
Igor Murashkin | a91537e | 2013-02-21 12:02:29 -0800 | [diff] [blame] | 22 | #include "camera2/ProFrameProcessor.h" |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | class IMemory; |
| 27 | /** |
| 28 | * Implements the binder IProCameraUser API, |
| 29 | * meant for HAL2-level private API access. |
| 30 | */ |
| 31 | class ProCamera2Client : |
| 32 | public CameraService::ProClient, |
Igor Murashkin | a91537e | 2013-02-21 12:02:29 -0800 | [diff] [blame] | 33 | public Camera2Device::NotificationListener, |
| 34 | public camera2::ProFrameProcessor::FilteredListener |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 35 | { |
| 36 | public: |
| 37 | /** |
| 38 | * IProCameraUser interface (see IProCameraUser for details) |
| 39 | */ |
| 40 | virtual status_t connect(const sp<IProCameraCallbacks>& callbacks); |
| 41 | virtual void disconnect(); |
| 42 | |
| 43 | virtual status_t exclusiveTryLock(); |
| 44 | virtual status_t exclusiveLock(); |
| 45 | virtual status_t exclusiveUnlock(); |
| 46 | |
| 47 | virtual bool hasExclusiveLock(); |
| 48 | |
| 49 | // Note that the callee gets a copy of the metadata. |
| 50 | virtual int submitRequest(camera_metadata_t* metadata, |
| 51 | bool streaming = false); |
| 52 | virtual status_t cancelRequest(int requestId); |
| 53 | |
| 54 | virtual status_t requestStream(int streamId); |
| 55 | virtual status_t cancelStream(int streamId); |
| 56 | |
| 57 | virtual status_t createStream(int width, int height, int format, |
Igor Murashkin | 76f8b43 | 2013-02-20 19:15:15 -0800 | [diff] [blame] | 58 | const sp<IGraphicBufferProducer>& bufferProducer, |
| 59 | /*out*/ |
| 60 | int* streamId); |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 61 | |
| 62 | // Create a request object from a template. |
Igor Murashkin | 3261fd3 | 2013-02-20 19:02:36 -0800 | [diff] [blame] | 63 | // -- Caller owns the newly allocated metadata |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 64 | virtual status_t createDefaultRequest(int templateId, |
| 65 | /*out*/ |
| 66 | camera_metadata** request); |
| 67 | |
Igor Murashkin | 7b33a74 | 2013-02-21 13:49:26 -0800 | [diff] [blame] | 68 | // Get the static metadata for the camera |
| 69 | // -- Caller owns the newly allocated metadata |
| 70 | virtual status_t getCameraInfo(int cameraId, |
| 71 | /*out*/ |
| 72 | camera_metadata** info); |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 73 | |
| 74 | /** |
| 75 | * Interface used by CameraService |
| 76 | */ |
| 77 | |
| 78 | ProCamera2Client(const sp<CameraService>& cameraService, |
| 79 | const sp<IProCameraCallbacks>& remoteCallback, |
| 80 | int cameraId, |
| 81 | int cameraFacing, |
| 82 | int clientPid, |
| 83 | int servicePid); |
| 84 | virtual ~ProCamera2Client(); |
| 85 | |
| 86 | status_t initialize(camera_module_t *module); |
| 87 | |
| 88 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 89 | |
| 90 | /** |
| 91 | * Interface used by Camera2Device |
| 92 | */ |
| 93 | |
| 94 | virtual void notifyError(int errorCode, int arg1, int arg2); |
| 95 | virtual void notifyShutter(int frameNumber, nsecs_t timestamp); |
| 96 | virtual void notifyAutoFocus(uint8_t newState, int triggerId); |
| 97 | virtual void notifyAutoExposure(uint8_t newState, int triggerId); |
| 98 | virtual void notifyAutoWhitebalance(uint8_t newState, int triggerId); |
| 99 | |
| 100 | |
| 101 | int getCameraId() const; |
| 102 | const sp<Camera2Device>& getCameraDevice(); |
| 103 | const sp<CameraService>& getCameraService(); |
| 104 | |
| 105 | /** |
| 106 | * Interface used by independent components of ProCamera2Client. |
| 107 | */ |
| 108 | |
| 109 | // Simple class to ensure that access to IProCameraCallbacks is serialized |
| 110 | // by requiring mRemoteCallbackLock to be locked before access to |
| 111 | // mCameraClient is possible. |
| 112 | class SharedCameraCallbacks { |
| 113 | public: |
| 114 | class Lock { |
| 115 | public: |
| 116 | Lock(SharedCameraCallbacks &client); |
| 117 | ~Lock(); |
| 118 | sp<IProCameraCallbacks> &mRemoteCallback; |
| 119 | private: |
| 120 | SharedCameraCallbacks &mSharedClient; |
| 121 | }; |
| 122 | SharedCameraCallbacks(const sp<IProCameraCallbacks>& client); |
| 123 | SharedCameraCallbacks& operator=(const sp<IProCameraCallbacks>& client); |
| 124 | void clear(); |
| 125 | private: |
| 126 | sp<IProCameraCallbacks> mRemoteCallback; |
| 127 | mutable Mutex mRemoteCallbackLock; |
| 128 | } mSharedCameraCallbacks; |
| 129 | |
Igor Murashkin | a91537e | 2013-02-21 12:02:29 -0800 | [diff] [blame] | 130 | protected: |
| 131 | /** FilteredListener implementation **/ |
| 132 | virtual void onFrameAvailable(int32_t frameId, const CameraMetadata& frame); |
| 133 | |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 134 | private: |
| 135 | /** IProCameraUser interface-related private members */ |
| 136 | |
| 137 | // Mutex that must be locked by methods implementing the IProCameraUser |
| 138 | // interface. Ensures serialization between incoming IProCameraUser calls. |
| 139 | // All methods below that append 'L' to the name assume that |
| 140 | // mIProCameraUserLock is locked when they're called |
| 141 | mutable Mutex mIProCameraUserLock; |
| 142 | |
| 143 | // Used with stream IDs |
| 144 | static const int NO_STREAM = -1; |
| 145 | |
| 146 | /* Preview/Recording related members */ |
| 147 | |
| 148 | sp<IBinder> mPreviewSurface; |
| 149 | |
| 150 | /** Preview callback related members */ |
Igor Murashkin | a91537e | 2013-02-21 12:02:29 -0800 | [diff] [blame] | 151 | sp<camera2::ProFrameProcessor> mFrameProcessor; |
| 152 | static const int32_t FRAME_PROCESSOR_LISTENER_MIN_ID = 0; |
| 153 | static const int32_t FRAME_PROCESSOR_LISTENER_MAX_ID = 0x7fffffffL; |
| 154 | |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 155 | /** Camera2Device instance wrapping HAL2 entry */ |
| 156 | |
| 157 | sp<Camera2Device> mDevice; |
| 158 | |
| 159 | /** Utility members */ |
| 160 | |
| 161 | // Verify that caller is the owner of the camera |
| 162 | status_t checkPid(const char *checkLocation) const; |
| 163 | |
| 164 | // Whether or not we have an exclusive lock on the device |
| 165 | // - if no we can't modify the request queue. |
| 166 | // note that creating/deleting streams we own is still OK |
| 167 | bool mExclusiveLock; |
| 168 | }; |
| 169 | |
| 170 | }; // namespace android |
| 171 | |
| 172 | #endif |