blob: 3a9d3072f2d10cb359f86675eac3d9f17122b376 [file] [log] [blame]
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -07001/*
2 * Copyright (C) 2012 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_H
18#define ANDROID_SERVERS_CAMERA_CAMERA2CLIENT_H
19
20#include "Camera2Device.h"
21#include "CameraService.h"
Eino-Ville Talvala2e19c3c2012-08-26 09:29:28 -070022#include "camera2/Parameters.h"
Eino-Ville Talvalaa16733e2012-08-27 23:41:56 -070023#include "camera2/FrameProcessor.h"
Eino-Ville Talvala73bbd1f2012-09-26 10:45:47 -070024#include "camera2/StreamingProcessor.h"
Eino-Ville Talvalada6665c2012-08-29 17:37:16 -070025#include "camera2/JpegProcessor.h"
26#include "camera2/ZslProcessor.h"
27#include "camera2/CaptureSequencer.h"
Eino-Ville Talvalad86a6882012-08-28 11:34:14 -070028#include "camera2/CallbackProcessor.h"
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -070029
30namespace android {
31
Eino-Ville Talvala73bbd1f2012-09-26 10:45:47 -070032class IMemory;
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -070033/**
34 * Implements the android.hardware.camera API on top of
35 * camera device HAL version 2.
36 */
Eino-Ville Talvala8ce89d92012-08-10 08:40:26 -070037class Camera2Client :
38 public CameraService::Client,
Eino-Ville Talvalac8474b62012-08-24 16:30:44 -070039 public Camera2Device::NotificationListener
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -070040{
41public:
Eino-Ville Talvalaea0d51b2012-08-28 01:25:43 -070042 /**
43 * ICamera interface (see ICamera for details)
44 */
Eino-Ville Talvala160d4af2012-08-03 09:40:16 -070045
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -070046 virtual void disconnect();
47 virtual status_t connect(const sp<ICameraClient>& client);
48 virtual status_t lock();
49 virtual status_t unlock();
50 virtual status_t setPreviewDisplay(const sp<Surface>& surface);
Eino-Ville Talvala6db981c2012-05-21 18:54:30 -070051 virtual status_t setPreviewTexture(
52 const sp<ISurfaceTexture>& surfaceTexture);
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -070053 virtual void setPreviewCallbackFlag(int flag);
54 virtual status_t startPreview();
55 virtual void stopPreview();
56 virtual bool previewEnabled();
57 virtual status_t storeMetaDataInBuffers(bool enabled);
58 virtual status_t startRecording();
59 virtual void stopRecording();
60 virtual bool recordingEnabled();
61 virtual void releaseRecordingFrame(const sp<IMemory>& mem);
62 virtual status_t autoFocus();
63 virtual status_t cancelAutoFocus();
64 virtual status_t takePicture(int msgType);
65 virtual status_t setParameters(const String8& params);
66 virtual String8 getParameters() const;
67 virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
68
Eino-Ville Talvalaea0d51b2012-08-28 01:25:43 -070069 /**
70 * Interface used by CameraService
71 */
Eino-Ville Talvala160d4af2012-08-03 09:40:16 -070072
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -070073 Camera2Client(const sp<CameraService>& cameraService,
74 const sp<ICameraClient>& cameraClient,
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -070075 int cameraId,
76 int cameraFacing,
77 int clientPid);
Eino-Ville Talvala160d4af2012-08-03 09:40:16 -070078 virtual ~Camera2Client();
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -070079
Eino-Ville Talvalaf69c70d2012-05-20 15:59:14 -070080 status_t initialize(camera_module_t *module);
81
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -070082 virtual status_t dump(int fd, const Vector<String16>& args);
83
Eino-Ville Talvalaea0d51b2012-08-28 01:25:43 -070084 /**
85 * Interface used by Camera2Device
86 */
Eino-Ville Talvala160d4af2012-08-03 09:40:16 -070087
88 virtual void notifyError(int errorCode, int arg1, int arg2);
89 virtual void notifyShutter(int frameNumber, nsecs_t timestamp);
90 virtual void notifyAutoFocus(uint8_t newState, int triggerId);
91 virtual void notifyAutoExposure(uint8_t newState, int triggerId);
92 virtual void notifyAutoWhitebalance(uint8_t newState, int triggerId);
93
Eino-Ville Talvalaea0d51b2012-08-28 01:25:43 -070094 /**
95 * Interface used by independent components of Camera2Client.
96 */
Eino-Ville Talvalaa16733e2012-08-27 23:41:56 -070097
Eino-Ville Talvalada6665c2012-08-29 17:37:16 -070098 int getCameraId() const;
Eino-Ville Talvalaa16733e2012-08-27 23:41:56 -070099 const sp<Camera2Device>& getCameraDevice();
Eino-Ville Talvala609acc02012-09-06 18:26:58 -0700100 const sp<CameraService>& getCameraService();
Eino-Ville Talvalaa16733e2012-08-27 23:41:56 -0700101 camera2::SharedParameters& getParameters();
102
Eino-Ville Talvalada6665c2012-08-29 17:37:16 -0700103 int getPreviewStreamId() const;
104 int getCaptureStreamId() const;
105 int getCallbackStreamId() const;
106 int getRecordingStreamId() const;
107 int getZslStreamId() const;
108
109 status_t registerFrameListener(int32_t id,
110 wp<camera2::FrameProcessor::FilteredListener> listener);
111 status_t removeFrameListener(int32_t id);
112
Eino-Ville Talvalaa16733e2012-08-27 23:41:56 -0700113 // Simple class to ensure that access to ICameraClient is serialized by
114 // requiring mCameraClientLock to be locked before access to mCameraClient
115 // is possible.
116 class SharedCameraClient {
117 public:
118 class Lock {
119 public:
120 Lock(SharedCameraClient &client);
121 ~Lock();
122 sp<ICameraClient> &mCameraClient;
123 private:
124 SharedCameraClient &mSharedClient;
125 };
Eino-Ville Talvalaea0d51b2012-08-28 01:25:43 -0700126 SharedCameraClient(const sp<ICameraClient>& client);
Eino-Ville Talvalaa16733e2012-08-27 23:41:56 -0700127 SharedCameraClient& operator=(const sp<ICameraClient>& client);
128 void clear();
129 private:
130 sp<ICameraClient> mCameraClient;
131 mutable Mutex mCameraClientLock;
132 } mSharedCameraClient;
133
Eino-Ville Talvalaea0d51b2012-08-28 01:25:43 -0700134 static size_t calculateBufferSize(int width, int height,
135 int format, int stride);
136
Eino-Ville Talvalada6665c2012-08-29 17:37:16 -0700137 static const int32_t kPreviewRequestId = 1000;
138 static const int32_t kRecordRequestId = 2000;
139 static const int32_t kFirstCaptureRequestId = 3000;
140
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -0700141private:
Eino-Ville Talvala3cca1362012-06-07 10:07:18 -0700142 /** ICamera interface-related private members */
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -0700143
Eino-Ville Talvalaac45eb32012-06-07 10:24:51 -0700144 // Mutex that must be locked by methods implementing the ICamera interface.
Eino-Ville Talvala36cdfb12012-08-02 17:34:15 -0700145 // Ensures serialization between incoming ICamera calls. All methods below
146 // that append 'L' to the name assume that mICameraLock is locked when
147 // they're called
Eino-Ville Talvalaac45eb32012-06-07 10:24:51 -0700148 mutable Mutex mICameraLock;
149
Eino-Ville Talvala2e19c3c2012-08-26 09:29:28 -0700150 typedef camera2::Parameters Parameters;
151 typedef camera2::CameraMetadata CameraMetadata;
Eino-Ville Talvala228a5382012-08-13 12:16:06 -0700152
Eino-Ville Talvala36cdfb12012-08-02 17:34:15 -0700153 status_t setPreviewWindowL(const sp<IBinder>& binder,
Eino-Ville Talvalabe0573b2012-06-15 12:42:30 -0700154 sp<ANativeWindow> window);
Eino-Ville Talvala228a5382012-08-13 12:16:06 -0700155 status_t startPreviewL(Parameters &params, bool restart);
156 void stopPreviewL();
157 status_t startRecordingL(Parameters &params, bool restart);
158 bool recordingEnabledL();
James Dong8da4cd72012-08-04 19:58:07 -0700159
Eino-Ville Talvala36cdfb12012-08-02 17:34:15 -0700160 // Individual commands for sendCommand()
161 status_t commandStartSmoothZoomL();
162 status_t commandStopSmoothZoomL();
163 status_t commandSetDisplayOrientationL(int degrees);
164 status_t commandEnableShutterSoundL(bool enable);
165 status_t commandPlayRecordingSoundL();
166 status_t commandStartFaceDetectionL(int type);
Eino-Ville Talvala228a5382012-08-13 12:16:06 -0700167 status_t commandStopFaceDetectionL(Parameters &params);
Eino-Ville Talvala36cdfb12012-08-02 17:34:15 -0700168 status_t commandEnableFocusMoveMsgL(bool enable);
169 status_t commandPingL();
170 status_t commandSetVideoBufferCountL(size_t count);
Eino-Ville Talvalad4bcfde2012-06-07 17:12:38 -0700171
Eino-Ville Talvala2e19c3c2012-08-26 09:29:28 -0700172 // Current camera device configuration
173 camera2::SharedParameters mParameters;
Eino-Ville Talvala8ce89d92012-08-10 08:40:26 -0700174
Eino-Ville Talvala3cca1362012-06-07 10:07:18 -0700175 /** Camera device-related private members */
176
Eino-Ville Talvala228a5382012-08-13 12:16:06 -0700177 void setPreviewCallbackFlagL(Parameters &params, int flag);
Eino-Ville Talvala5a4f93e2012-08-29 18:06:32 -0700178 status_t updateRequests(Parameters &params);
Eino-Ville Talvala8ce89d92012-08-10 08:40:26 -0700179
Eino-Ville Talvala9cca4c62012-06-15 15:41:44 -0700180 // Used with stream IDs
181 static const int NO_STREAM = -1;
182
Eino-Ville Talvalaa16733e2012-08-27 23:41:56 -0700183 sp<camera2::FrameProcessor> mFrameProcessor;
Eino-Ville Talvala8ce89d92012-08-10 08:40:26 -0700184
Eino-Ville Talvala73bbd1f2012-09-26 10:45:47 -0700185 /* Preview/Recording related members */
Eino-Ville Talvala9cca4c62012-06-15 15:41:44 -0700186
Eino-Ville Talvala9cca4c62012-06-15 15:41:44 -0700187 sp<IBinder> mPreviewSurface;
Eino-Ville Talvala73bbd1f2012-09-26 10:45:47 -0700188 sp<camera2::StreamingProcessor> mStreamingProcessor;
Eino-Ville Talvala9cca4c62012-06-15 15:41:44 -0700189
Eino-Ville Talvala228a5382012-08-13 12:16:06 -0700190 /** Preview callback related members */
191
Eino-Ville Talvalad86a6882012-08-28 11:34:14 -0700192 sp<camera2::CallbackProcessor> mCallbackProcessor;
Eino-Ville Talvala228a5382012-08-13 12:16:06 -0700193
Eino-Ville Talvala9cca4c62012-06-15 15:41:44 -0700194 /* Still image capture related members */
195
Eino-Ville Talvalada6665c2012-08-29 17:37:16 -0700196 sp<camera2::CaptureSequencer> mCaptureSequencer;
197 sp<camera2::JpegProcessor> mJpegProcessor;
198 sp<camera2::ZslProcessor> mZslProcessor;
Eino-Ville Talvala9cca4c62012-06-15 15:41:44 -0700199
Eino-Ville Talvala174181e2012-08-03 13:53:39 -0700200 /** Notification-related members */
201
202 bool mAfInMotion;
203
Eino-Ville Talvala9cca4c62012-06-15 15:41:44 -0700204 /** Camera2Device instance wrapping HAL2 entry */
Eino-Ville Talvala3cca1362012-06-07 10:07:18 -0700205
206 sp<Camera2Device> mDevice;
207
Eino-Ville Talvala9cca4c62012-06-15 15:41:44 -0700208 /** Utility members */
209
Eino-Ville Talvala3a609142012-07-31 14:36:26 -0700210 // Verify that caller is the owner of the camera
211 status_t checkPid(const char *checkLocation) const;
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -0700212};
213
214}; // namespace android
215
216#endif