blob: 8f7681952e11aaf782f21c214f5e60ef0b66dd9c [file] [log] [blame]
Igor Murashkin985fd302013-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,
56 const sp<Surface>& surface,
57 /*out*/
58 int* streamId);
59
60 // Create a request object from a template.
61 virtual status_t createDefaultRequest(int templateId,
62 /*out*/
63 camera_metadata** request);
64
65
66 /**
67 * Interface used by CameraService
68 */
69
70 ProCamera2Client(const sp<CameraService>& cameraService,
71 const sp<IProCameraCallbacks>& remoteCallback,
72 int cameraId,
73 int cameraFacing,
74 int clientPid,
75 int servicePid);
76 virtual ~ProCamera2Client();
77
78 status_t initialize(camera_module_t *module);
79
80 virtual status_t dump(int fd, const Vector<String16>& args);
81
82 /**
83 * Interface used by Camera2Device
84 */
85
86 virtual void notifyError(int errorCode, int arg1, int arg2);
87 virtual void notifyShutter(int frameNumber, nsecs_t timestamp);
88 virtual void notifyAutoFocus(uint8_t newState, int triggerId);
89 virtual void notifyAutoExposure(uint8_t newState, int triggerId);
90 virtual void notifyAutoWhitebalance(uint8_t newState, int triggerId);
91
92
93 int getCameraId() const;
94 const sp<Camera2Device>& getCameraDevice();
95 const sp<CameraService>& getCameraService();
96
97 /**
98 * Interface used by independent components of ProCamera2Client.
99 */
100
101 // Simple class to ensure that access to IProCameraCallbacks is serialized
102 // by requiring mRemoteCallbackLock to be locked before access to
103 // mCameraClient is possible.
104 class SharedCameraCallbacks {
105 public:
106 class Lock {
107 public:
108 Lock(SharedCameraCallbacks &client);
109 ~Lock();
110 sp<IProCameraCallbacks> &mRemoteCallback;
111 private:
112 SharedCameraCallbacks &mSharedClient;
113 };
114 SharedCameraCallbacks(const sp<IProCameraCallbacks>& client);
115 SharedCameraCallbacks& operator=(const sp<IProCameraCallbacks>& client);
116 void clear();
117 private:
118 sp<IProCameraCallbacks> mRemoteCallback;
119 mutable Mutex mRemoteCallbackLock;
120 } mSharedCameraCallbacks;
121
122private:
123 /** IProCameraUser interface-related private members */
124
125 // Mutex that must be locked by methods implementing the IProCameraUser
126 // interface. Ensures serialization between incoming IProCameraUser calls.
127 // All methods below that append 'L' to the name assume that
128 // mIProCameraUserLock is locked when they're called
129 mutable Mutex mIProCameraUserLock;
130
131 // Used with stream IDs
132 static const int NO_STREAM = -1;
133
134 /* Preview/Recording related members */
135
136 sp<IBinder> mPreviewSurface;
137
138 /** Preview callback related members */
139 /** Camera2Device instance wrapping HAL2 entry */
140
141 sp<Camera2Device> mDevice;
142
143 /** Utility members */
144
145 // Verify that caller is the owner of the camera
146 status_t checkPid(const char *checkLocation) const;
147
148 // Whether or not we have an exclusive lock on the device
149 // - if no we can't modify the request queue.
150 // note that creating/deleting streams we own is still OK
151 bool mExclusiveLock;
152};
153
154}; // namespace android
155
156#endif