blob: ff6f4e295ffe7b012d5204dd2e275e5a7944a6aa [file] [log] [blame]
Igor Murashkin69e22432013-02-20 18:24:43 -08001/*
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 Murashkin418e4932013-02-21 12:02:29 -080022#include "camera2/ProFrameProcessor.h"
Igor Murashkin69e22432013-02-20 18:24:43 -080023
24namespace android {
25
26class IMemory;
27/**
28 * Implements the binder IProCameraUser API,
29 * meant for HAL2-level private API access.
30 */
31class ProCamera2Client :
32 public CameraService::ProClient,
Igor Murashkin418e4932013-02-21 12:02:29 -080033 public Camera2Device::NotificationListener,
34 public camera2::ProFrameProcessor::FilteredListener
Igor Murashkin69e22432013-02-20 18:24:43 -080035{
36public:
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 Murashkin5494cdc2013-02-20 19:15:15 -080058 const sp<IGraphicBufferProducer>& bufferProducer,
59 /*out*/
60 int* streamId);
Igor Murashkin69e22432013-02-20 18:24:43 -080061
62 // Create a request object from a template.
Igor Murashkin9fb7fa12013-02-20 19:02:36 -080063 // -- Caller owns the newly allocated metadata
Igor Murashkin69e22432013-02-20 18:24:43 -080064 virtual status_t createDefaultRequest(int templateId,
65 /*out*/
66 camera_metadata** request);
67
Igor Murashkind127c2c2013-02-21 13:49:26 -080068 // 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 Murashkin69e22432013-02-20 18:24:43 -080073
74 /**
75 * Interface used by CameraService
76 */
77
78 ProCamera2Client(const sp<CameraService>& cameraService,
79 const sp<IProCameraCallbacks>& remoteCallback,
Eino-Ville Talvala48af7e82013-02-19 10:40:14 -080080 const String16& clientPackageName,
Igor Murashkin69e22432013-02-20 18:24:43 -080081 int cameraId,
82 int cameraFacing,
83 int clientPid,
Eino-Ville Talvala48af7e82013-02-19 10:40:14 -080084 uid_t clientUid,
Igor Murashkin69e22432013-02-20 18:24:43 -080085 int servicePid);
86 virtual ~ProCamera2Client();
87
88 status_t initialize(camera_module_t *module);
89
90 virtual status_t dump(int fd, const Vector<String16>& args);
91
92 /**
93 * Interface used by Camera2Device
94 */
95
96 virtual void notifyError(int errorCode, int arg1, int arg2);
97 virtual void notifyShutter(int frameNumber, nsecs_t timestamp);
98 virtual void notifyAutoFocus(uint8_t newState, int triggerId);
99 virtual void notifyAutoExposure(uint8_t newState, int triggerId);
100 virtual void notifyAutoWhitebalance(uint8_t newState, int triggerId);
101
102
103 int getCameraId() const;
104 const sp<Camera2Device>& getCameraDevice();
105 const sp<CameraService>& getCameraService();
106
Igor Murashkin8fdfbe22013-02-27 12:55:20 -0800107 // Callbacks from camera service
108 virtual void onExclusiveLockStolen();
109
Igor Murashkin69e22432013-02-20 18:24:43 -0800110 /**
111 * Interface used by independent components of ProCamera2Client.
112 */
113
114 // Simple class to ensure that access to IProCameraCallbacks is serialized
115 // by requiring mRemoteCallbackLock to be locked before access to
116 // mCameraClient is possible.
117 class SharedCameraCallbacks {
118 public:
119 class Lock {
120 public:
121 Lock(SharedCameraCallbacks &client);
122 ~Lock();
123 sp<IProCameraCallbacks> &mRemoteCallback;
124 private:
125 SharedCameraCallbacks &mSharedClient;
126 };
127 SharedCameraCallbacks(const sp<IProCameraCallbacks>& client);
128 SharedCameraCallbacks& operator=(const sp<IProCameraCallbacks>& client);
129 void clear();
130 private:
131 sp<IProCameraCallbacks> mRemoteCallback;
132 mutable Mutex mRemoteCallbackLock;
133 } mSharedCameraCallbacks;
134
Igor Murashkin418e4932013-02-21 12:02:29 -0800135protected:
136 /** FilteredListener implementation **/
137 virtual void onFrameAvailable(int32_t frameId, const CameraMetadata& frame);
138
Igor Murashkin69e22432013-02-20 18:24:43 -0800139private:
140 /** IProCameraUser interface-related private members */
141
142 // Mutex that must be locked by methods implementing the IProCameraUser
143 // interface. Ensures serialization between incoming IProCameraUser calls.
144 // All methods below that append 'L' to the name assume that
145 // mIProCameraUserLock is locked when they're called
146 mutable Mutex mIProCameraUserLock;
147
148 // Used with stream IDs
149 static const int NO_STREAM = -1;
150
151 /* Preview/Recording related members */
152
153 sp<IBinder> mPreviewSurface;
154
155 /** Preview callback related members */
Igor Murashkin418e4932013-02-21 12:02:29 -0800156 sp<camera2::ProFrameProcessor> mFrameProcessor;
157 static const int32_t FRAME_PROCESSOR_LISTENER_MIN_ID = 0;
158 static const int32_t FRAME_PROCESSOR_LISTENER_MAX_ID = 0x7fffffffL;
159
Igor Murashkin69e22432013-02-20 18:24:43 -0800160 /** Camera2Device instance wrapping HAL2 entry */
161
162 sp<Camera2Device> mDevice;
163
164 /** Utility members */
165
166 // Verify that caller is the owner of the camera
167 status_t checkPid(const char *checkLocation) const;
168
169 // Whether or not we have an exclusive lock on the device
170 // - if no we can't modify the request queue.
171 // note that creating/deleting streams we own is still OK
172 bool mExclusiveLock;
Igor Murashkin8fdfbe22013-02-27 12:55:20 -0800173
174 void detachDevice();
Igor Murashkin69e22432013-02-20 18:24:43 -0800175};
176
177}; // namespace android
178
179#endif