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