blob: d23197c2d041c72a01b6a9951b8f6c23c9af52cb [file] [log] [blame]
Igor Murashkin44cfcf02013-03-01 16:22:28 -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_CAMERA2CLIENT_BASE_H
18#define ANDROID_SERVERS_CAMERA_CAMERA2CLIENT_BASE_H
19
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070020#include "common/CameraDeviceBase.h"
Igor Murashkin44cfcf02013-03-01 16:22:28 -080021
22namespace android {
23
24class IMemory;
25
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070026class CameraService;
27
Igor Murashkin44cfcf02013-03-01 16:22:28 -080028template <typename TClientBase>
29class Camera2ClientBase :
30 public TClientBase,
31 public CameraDeviceBase::NotificationListener
32{
33public:
34 typedef typename TClientBase::TCamCallbacks TCamCallbacks;
35
36 /**
37 * Base binder interface (see ICamera/IProCameraUser for details)
38 */
39 virtual status_t connect(const sp<TCamCallbacks>& callbacks);
40 virtual void disconnect();
41
42 /**
43 * Interface used by CameraService
44 */
45
46 // TODO: too many params, move into a ClientArgs<T>
47 Camera2ClientBase(const sp<CameraService>& cameraService,
48 const sp<TCamCallbacks>& remoteCallback,
49 const String16& clientPackageName,
50 int cameraId,
51 int cameraFacing,
52 int clientPid,
53 uid_t clientUid,
54 int servicePid);
55 virtual ~Camera2ClientBase();
56
57 virtual status_t initialize(camera_module_t *module);
58 virtual status_t dump(int fd, const Vector<String16>& args);
59
60 /**
61 * CameraDeviceBase::NotificationListener implementation
62 */
63
64 virtual void notifyError(int errorCode, int arg1, int arg2);
65 virtual void notifyShutter(int frameNumber, nsecs_t timestamp);
66 virtual void notifyAutoFocus(uint8_t newState, int triggerId);
67 virtual void notifyAutoExposure(uint8_t newState, int triggerId);
68 virtual void notifyAutoWhitebalance(uint8_t newState,
69 int triggerId);
70
71
72 int getCameraId() const;
73 const sp<CameraDeviceBase>&
74 getCameraDevice();
75 const sp<CameraService>&
76 getCameraService();
77
78 /**
79 * Interface used by independent components of CameraClient2Base.
80 */
81
82 // Simple class to ensure that access to TCamCallbacks is serialized
83 // by requiring mRemoteCallbackLock to be locked before access to
84 // mRemoteCallback is possible.
85 class SharedCameraCallbacks {
86 public:
87 class Lock {
88 public:
89 Lock(SharedCameraCallbacks &client);
90 ~Lock();
91 sp<TCamCallbacks> &mRemoteCallback;
92 private:
93 SharedCameraCallbacks &mSharedClient;
94 };
95 SharedCameraCallbacks(const sp<TCamCallbacks>& client);
96 SharedCameraCallbacks& operator=(const sp<TCamCallbacks>& client);
97 void clear();
98 private:
99 sp<TCamCallbacks> mRemoteCallback;
100 mutable Mutex mRemoteCallbackLock;
101 } mSharedCameraCallbacks;
102
103protected:
104
Igor Murashkine7ee7632013-06-11 18:10:18 -0700105 virtual sp<IBinder> asBinderWrapper() {
106 return IInterface::asBinder();
107 }
108
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800109 virtual status_t dumpDevice(int fd, const Vector<String16>& args);
110
111 /** Binder client interface-related private members */
112
113 // Mutex that must be locked by methods implementing the binder client
114 // interface. Ensures serialization between incoming client calls.
115 // All methods in this class hierarchy that append 'L' to the name assume
116 // that mBinderSerializationLock is locked when they're called
117 mutable Mutex mBinderSerializationLock;
118
119 /** CameraDeviceBase instance wrapping HAL2+ entry */
120
121 sp<CameraDeviceBase> mDevice;
122
123 /** Utility members */
124
125 // Verify that caller is the owner of the camera
126 status_t checkPid(const char *checkLocation) const;
127
128 virtual void detachDevice();
129};
130
131}; // namespace android
132
133#endif