blob: b1d1762b892190114ee37d9a8658795643c72661 [file] [log] [blame]
Igor Murashkine7ee7632013-06-11 18:10:18 -07001/*
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_PHOTOGRAPHY_CAMERADEVICECLIENT_H
18#define ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERADEVICECLIENT_H
19
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070020#include <camera/camera2/ICameraDeviceUser.h>
21#include <camera/camera2/ICameraDeviceCallbacks.h>
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070022#include <camera/camera2/OutputConfiguration.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070023
Igor Murashkine7ee7632013-06-11 18:10:18 -070024#include "CameraService.h"
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070025#include "common/FrameProcessorBase.h"
26#include "common/Camera2ClientBase.h"
Igor Murashkine7ee7632013-06-11 18:10:18 -070027
28namespace android {
29
Ruben Brunk77a77f62015-06-12 16:15:35 -070030struct CameraDeviceClientBase : public CameraService::BasicClient, public BnCameraDeviceUser
Igor Murashkine7ee7632013-06-11 18:10:18 -070031{
32 typedef ICameraDeviceCallbacks TCamCallbacks;
33
34 const sp<ICameraDeviceCallbacks>& getRemoteCallback() {
35 return mRemoteCallback;
36 }
37
38protected:
39 CameraDeviceClientBase(const sp<CameraService>& cameraService,
40 const sp<ICameraDeviceCallbacks>& remoteCallback,
41 const String16& clientPackageName,
42 int cameraId,
43 int cameraFacing,
44 int clientPid,
45 uid_t clientUid,
46 int servicePid);
47
Igor Murashkine7ee7632013-06-11 18:10:18 -070048 sp<ICameraDeviceCallbacks> mRemoteCallback;
49};
50
51/**
52 * Implements the binder ICameraDeviceUser API,
53 * meant for HAL3-public implementation of
54 * android.hardware.photography.CameraDevice
55 */
56class CameraDeviceClient :
57 public Camera2ClientBase<CameraDeviceClientBase>,
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070058 public camera2::FrameProcessorBase::FilteredListener
Igor Murashkine7ee7632013-06-11 18:10:18 -070059{
60public:
61 /**
62 * ICameraDeviceUser interface (see ICameraDeviceUser for details)
63 */
64
65 // Note that the callee gets a copy of the metadata.
Jianing Wei90e59c92014-03-12 18:29:36 -070066 virtual status_t submitRequest(sp<CaptureRequest> request,
Jianing Weicb0652e2014-03-12 18:29:36 -070067 bool streaming = false,
68 /*out*/
69 int64_t* lastFrameNumber = NULL);
Jianing Wei90e59c92014-03-12 18:29:36 -070070 // List of requests are copied.
71 virtual status_t submitRequestList(List<sp<CaptureRequest> > requests,
Jianing Weicb0652e2014-03-12 18:29:36 -070072 bool streaming = false,
73 /*out*/
74 int64_t* lastFrameNumber = NULL);
75 virtual status_t cancelRequest(int requestId,
76 /*out*/
77 int64_t* lastFrameNumber = NULL);
Igor Murashkine7ee7632013-06-11 18:10:18 -070078
Ruben Brunkb2119af2014-05-09 19:57:56 -070079 virtual status_t beginConfigure();
80
Zhijun He1fa89992015-06-01 15:44:31 -070081 virtual status_t endConfigure(bool isConstrainedHighSpeed = false);
Ruben Brunkb2119af2014-05-09 19:57:56 -070082
Igor Murashkine7ee7632013-06-11 18:10:18 -070083 // Returns -EBUSY if device is not idle
84 virtual status_t deleteStream(int streamId);
85
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070086 virtual status_t createStream(const OutputConfiguration &outputConfiguration);
Igor Murashkine7ee7632013-06-11 18:10:18 -070087
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -070088 // Create an input stream of width, height, and format.
89 virtual status_t createInputStream(int width, int height, int format);
90
91 // Get the buffer producer of the input stream
92 virtual status_t getInputBufferProducer(
93 /*out*/sp<IGraphicBufferProducer> *producer);
94
Igor Murashkine7ee7632013-06-11 18:10:18 -070095 // Create a request object from a template.
96 virtual status_t createDefaultRequest(int templateId,
97 /*out*/
98 CameraMetadata* request);
99
100 // Get the static metadata for the camera
101 // -- Caller owns the newly allocated metadata
Igor Murashkin099b4572013-07-12 17:52:16 -0700102 virtual status_t getCameraInfo(/*out*/CameraMetadata* info);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700103
Zhijun He2ab500c2013-07-23 08:02:53 -0700104 // Wait until all the submitted requests have finished processing
105 virtual status_t waitUntilIdle();
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700106
107 // Flush all active and pending requests as fast as possible
Jianing Weicb0652e2014-03-12 18:29:36 -0700108 virtual status_t flush(/*out*/
109 int64_t* lastFrameNumber = NULL);
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700110
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700111 // Prepare stream by preallocating its buffers
112 virtual status_t prepare(int streamId);
113
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -0700114 // Tear down stream resources by freeing its unused buffers
115 virtual status_t tearDown(int streamId);
116
Ruben Brunkc78ac262015-08-13 17:58:46 -0700117 // Prepare stream by preallocating up to maxCount of its buffers
118 virtual status_t prepare2(int maxCount, int streamId);
119
Igor Murashkine7ee7632013-06-11 18:10:18 -0700120 /**
121 * Interface used by CameraService
122 */
123
124 CameraDeviceClient(const sp<CameraService>& cameraService,
125 const sp<ICameraDeviceCallbacks>& remoteCallback,
126 const String16& clientPackageName,
127 int cameraId,
128 int cameraFacing,
129 int clientPid,
130 uid_t clientUid,
131 int servicePid);
132 virtual ~CameraDeviceClient();
133
Yin-Chia Yehe074a932015-01-30 10:29:02 -0800134 virtual status_t initialize(CameraModule *module);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700135
136 virtual status_t dump(int fd, const Vector<String16>& args);
137
Eino-Ville Talvalac4003962016-01-13 10:07:04 -0800138 virtual status_t dumpClient(int fd, const Vector<String16>& args);
139
Igor Murashkine7ee7632013-06-11 18:10:18 -0700140 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700141 * Device listener interface
142 */
143
144 virtual void notifyIdle();
Jianing Weicb0652e2014-03-12 18:29:36 -0700145 virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
146 const CaptureResultExtras& resultExtras);
147 virtual void notifyShutter(const CaptureResultExtras& resultExtras, nsecs_t timestamp);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700148 virtual void notifyPrepared(int streamId);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700149
150 /**
Igor Murashkine7ee7632013-06-11 18:10:18 -0700151 * Interface used by independent components of CameraDeviceClient.
152 */
153protected:
154 /** FilteredListener implementation **/
Jianing Weicb0652e2014-03-12 18:29:36 -0700155 virtual void onResultAvailable(const CaptureResult& result);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700156 virtual void detachDevice();
157
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -0700158 // Calculate the ANativeWindow transform from android.sensor.orientation
159 status_t getRotationTransformLocked(/*out*/int32_t* transform);
160
Igor Murashkine7ee7632013-06-11 18:10:18 -0700161private:
162 /** ICameraDeviceUser interface-related private members */
163
164 /** Preview callback related members */
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -0700165 sp<camera2::FrameProcessorBase> mFrameProcessor;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700166 static const int32_t FRAME_PROCESSOR_LISTENER_MIN_ID = 0;
167 static const int32_t FRAME_PROCESSOR_LISTENER_MAX_ID = 0x7fffffffL;
168
169 /** Utility members */
170 bool enforceRequestPermissions(CameraMetadata& metadata);
171
Ruben Brunkbba75572014-11-20 17:29:50 -0800172 // Find the square of the euclidean distance between two points
173 static int64_t euclidDistSquare(int32_t x0, int32_t y0, int32_t x1, int32_t y1);
174
175 // Find the closest dimensions for a given format in available stream configurations with
176 // a width <= ROUNDING_WIDTH_CAP
Ruben Brunk77a77f62015-06-12 16:15:35 -0700177 static const int32_t ROUNDING_WIDTH_CAP = 1920;
Ruben Brunkbba75572014-11-20 17:29:50 -0800178 static bool roundBufferDimensionNearest(int32_t width, int32_t height, int32_t format,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800179 android_dataspace dataSpace, const CameraMetadata& info,
180 /*out*/int32_t* outWidth, /*out*/int32_t* outHeight);
Ruben Brunkbba75572014-11-20 17:29:50 -0800181
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700182 // IGraphicsBufferProducer binder -> Stream ID for output streams
Igor Murashkine7ee7632013-06-11 18:10:18 -0700183 KeyedVector<sp<IBinder>, int> mStreamMap;
184
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700185 struct InputStreamConfiguration {
186 bool configured;
187 int32_t width;
188 int32_t height;
189 int32_t format;
190 int32_t id;
191 } mInputStream;
192
193 // Request ID
Igor Murashkine7ee7632013-06-11 18:10:18 -0700194 Vector<int> mStreamingRequestList;
195
196 int32_t mRequestIdCounter;
Eino-Ville Talvala412fe562015-08-20 17:08:32 -0700197
Igor Murashkine7ee7632013-06-11 18:10:18 -0700198};
199
200}; // namespace android
201
202#endif