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