blob: dfea1e143a039d0dc1433752695e29427894f3d4 [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
68
69 /**
70 * Interface used by CameraService
71 */
72
73 ProCamera2Client(const sp<CameraService>& cameraService,
74 const sp<IProCameraCallbacks>& remoteCallback,
75 int cameraId,
76 int cameraFacing,
77 int clientPid,
78 int servicePid);
79 virtual ~ProCamera2Client();
80
81 status_t initialize(camera_module_t *module);
82
83 virtual status_t dump(int fd, const Vector<String16>& args);
84
85 /**
86 * Interface used by Camera2Device
87 */
88
89 virtual void notifyError(int errorCode, int arg1, int arg2);
90 virtual void notifyShutter(int frameNumber, nsecs_t timestamp);
91 virtual void notifyAutoFocus(uint8_t newState, int triggerId);
92 virtual void notifyAutoExposure(uint8_t newState, int triggerId);
93 virtual void notifyAutoWhitebalance(uint8_t newState, int triggerId);
94
95
96 int getCameraId() const;
97 const sp<Camera2Device>& getCameraDevice();
98 const sp<CameraService>& getCameraService();
99
100 /**
101 * Interface used by independent components of ProCamera2Client.
102 */
103
104 // Simple class to ensure that access to IProCameraCallbacks is serialized
105 // by requiring mRemoteCallbackLock to be locked before access to
106 // mCameraClient is possible.
107 class SharedCameraCallbacks {
108 public:
109 class Lock {
110 public:
111 Lock(SharedCameraCallbacks &client);
112 ~Lock();
113 sp<IProCameraCallbacks> &mRemoteCallback;
114 private:
115 SharedCameraCallbacks &mSharedClient;
116 };
117 SharedCameraCallbacks(const sp<IProCameraCallbacks>& client);
118 SharedCameraCallbacks& operator=(const sp<IProCameraCallbacks>& client);
119 void clear();
120 private:
121 sp<IProCameraCallbacks> mRemoteCallback;
122 mutable Mutex mRemoteCallbackLock;
123 } mSharedCameraCallbacks;
124
Igor Murashkin418e4932013-02-21 12:02:29 -0800125protected:
126 /** FilteredListener implementation **/
127 virtual void onFrameAvailable(int32_t frameId, const CameraMetadata& frame);
128
Igor Murashkin69e22432013-02-20 18:24:43 -0800129private:
130 /** IProCameraUser interface-related private members */
131
132 // Mutex that must be locked by methods implementing the IProCameraUser
133 // interface. Ensures serialization between incoming IProCameraUser calls.
134 // All methods below that append 'L' to the name assume that
135 // mIProCameraUserLock is locked when they're called
136 mutable Mutex mIProCameraUserLock;
137
138 // Used with stream IDs
139 static const int NO_STREAM = -1;
140
141 /* Preview/Recording related members */
142
143 sp<IBinder> mPreviewSurface;
144
145 /** Preview callback related members */
Igor Murashkin418e4932013-02-21 12:02:29 -0800146 sp<camera2::ProFrameProcessor> mFrameProcessor;
147 static const int32_t FRAME_PROCESSOR_LISTENER_MIN_ID = 0;
148 static const int32_t FRAME_PROCESSOR_LISTENER_MAX_ID = 0x7fffffffL;
149
Igor Murashkin69e22432013-02-20 18:24:43 -0800150 /** Camera2Device instance wrapping HAL2 entry */
151
152 sp<Camera2Device> mDevice;
153
154 /** Utility members */
155
156 // Verify that caller is the owner of the camera
157 status_t checkPid(const char *checkLocation) const;
158
159 // Whether or not we have an exclusive lock on the device
160 // - if no we can't modify the request queue.
161 // note that creating/deleting streams we own is still OK
162 bool mExclusiveLock;
163};
164
165}; // namespace android
166
167#endif