blob: b8d8beaaf651a8f4ae8d0f16d49394c66c4c85a2 [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
30struct CameraDeviceClientBase :
31 public CameraService::BasicClient, public BnCameraDeviceUser
32{
33 typedef ICameraDeviceCallbacks TCamCallbacks;
34
35 const sp<ICameraDeviceCallbacks>& getRemoteCallback() {
36 return mRemoteCallback;
37 }
38
39protected:
40 CameraDeviceClientBase(const sp<CameraService>& cameraService,
41 const sp<ICameraDeviceCallbacks>& remoteCallback,
42 const String16& clientPackageName,
43 int cameraId,
44 int cameraFacing,
45 int clientPid,
46 uid_t clientUid,
47 int servicePid);
48
Igor Murashkine7ee7632013-06-11 18:10:18 -070049 sp<ICameraDeviceCallbacks> mRemoteCallback;
50};
51
52/**
53 * Implements the binder ICameraDeviceUser API,
54 * meant for HAL3-public implementation of
55 * android.hardware.photography.CameraDevice
56 */
57class CameraDeviceClient :
58 public Camera2ClientBase<CameraDeviceClientBase>,
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070059 public camera2::FrameProcessorBase::FilteredListener
Igor Murashkine7ee7632013-06-11 18:10:18 -070060{
61public:
62 /**
63 * ICameraDeviceUser interface (see ICameraDeviceUser for details)
64 */
65
66 // Note that the callee gets a copy of the metadata.
Jianing Wei90e59c92014-03-12 18:29:36 -070067 virtual status_t submitRequest(sp<CaptureRequest> request,
Jianing Weicb0652e2014-03-12 18:29:36 -070068 bool streaming = false,
69 /*out*/
70 int64_t* lastFrameNumber = NULL);
Jianing Wei90e59c92014-03-12 18:29:36 -070071 // List of requests are copied.
72 virtual status_t submitRequestList(List<sp<CaptureRequest> > requests,
Jianing Weicb0652e2014-03-12 18:29:36 -070073 bool streaming = false,
74 /*out*/
75 int64_t* lastFrameNumber = NULL);
76 virtual status_t cancelRequest(int requestId,
77 /*out*/
78 int64_t* lastFrameNumber = NULL);
Igor Murashkine7ee7632013-06-11 18:10:18 -070079
Ruben Brunkb2119af2014-05-09 19:57:56 -070080 virtual status_t beginConfigure();
81
82 virtual status_t endConfigure();
83
Igor Murashkine7ee7632013-06-11 18:10:18 -070084 // Returns -EBUSY if device is not idle
85 virtual status_t deleteStream(int streamId);
86
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070087 virtual status_t createStream(const OutputConfiguration &outputConfiguration);
Igor Murashkine7ee7632013-06-11 18:10:18 -070088
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -070089 // Create an input stream of width, height, and format.
90 virtual status_t createInputStream(int width, int height, int format);
91
92 // Get the buffer producer of the input stream
93 virtual status_t getInputBufferProducer(
94 /*out*/sp<IGraphicBufferProducer> *producer);
95
Igor Murashkine7ee7632013-06-11 18:10:18 -070096 // Create a request object from a template.
97 virtual status_t createDefaultRequest(int templateId,
98 /*out*/
99 CameraMetadata* request);
100
101 // Get the static metadata for the camera
102 // -- Caller owns the newly allocated metadata
Igor Murashkin099b4572013-07-12 17:52:16 -0700103 virtual status_t getCameraInfo(/*out*/CameraMetadata* info);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700104
Zhijun He2ab500c2013-07-23 08:02:53 -0700105 // Wait until all the submitted requests have finished processing
106 virtual status_t waitUntilIdle();
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700107
108 // Flush all active and pending requests as fast as possible
Jianing Weicb0652e2014-03-12 18:29:36 -0700109 virtual status_t flush(/*out*/
110 int64_t* lastFrameNumber = NULL);
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700111
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700112 // Prepare stream by preallocating its buffers
113 virtual status_t prepare(int streamId);
114
Igor Murashkine7ee7632013-06-11 18:10:18 -0700115 /**
116 * Interface used by CameraService
117 */
118
119 CameraDeviceClient(const sp<CameraService>& cameraService,
120 const sp<ICameraDeviceCallbacks>& remoteCallback,
121 const String16& clientPackageName,
122 int cameraId,
123 int cameraFacing,
124 int clientPid,
125 uid_t clientUid,
126 int servicePid);
127 virtual ~CameraDeviceClient();
128
Yin-Chia Yehe074a932015-01-30 10:29:02 -0800129 virtual status_t initialize(CameraModule *module);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700130
131 virtual status_t dump(int fd, const Vector<String16>& args);
132
133 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700134 * Device listener interface
135 */
136
137 virtual void notifyIdle();
Jianing Weicb0652e2014-03-12 18:29:36 -0700138 virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
139 const CaptureResultExtras& resultExtras);
140 virtual void notifyShutter(const CaptureResultExtras& resultExtras, nsecs_t timestamp);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700141 virtual void notifyPrepared(int streamId);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700142
143 /**
Igor Murashkine7ee7632013-06-11 18:10:18 -0700144 * Interface used by independent components of CameraDeviceClient.
145 */
146protected:
147 /** FilteredListener implementation **/
Jianing Weicb0652e2014-03-12 18:29:36 -0700148 virtual void onResultAvailable(const CaptureResult& result);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700149 virtual void detachDevice();
150
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -0700151 // Calculate the ANativeWindow transform from android.sensor.orientation
152 status_t getRotationTransformLocked(/*out*/int32_t* transform);
153
Igor Murashkine7ee7632013-06-11 18:10:18 -0700154private:
155 /** ICameraDeviceUser interface-related private members */
156
157 /** Preview callback related members */
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -0700158 sp<camera2::FrameProcessorBase> mFrameProcessor;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700159 static const int32_t FRAME_PROCESSOR_LISTENER_MIN_ID = 0;
160 static const int32_t FRAME_PROCESSOR_LISTENER_MAX_ID = 0x7fffffffL;
161
162 /** Utility members */
163 bool enforceRequestPermissions(CameraMetadata& metadata);
164
Ruben Brunkbba75572014-11-20 17:29:50 -0800165 // Find the square of the euclidean distance between two points
166 static int64_t euclidDistSquare(int32_t x0, int32_t y0, int32_t x1, int32_t y1);
167
168 // Find the closest dimensions for a given format in available stream configurations with
169 // a width <= ROUNDING_WIDTH_CAP
170 static const int32_t ROUNDING_WIDTH_CAP = 1080;
171 static bool roundBufferDimensionNearest(int32_t width, int32_t height, int32_t format,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800172 android_dataspace dataSpace, const CameraMetadata& info,
173 /*out*/int32_t* outWidth, /*out*/int32_t* outHeight);
Ruben Brunkbba75572014-11-20 17:29:50 -0800174
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700175 // IGraphicsBufferProducer binder -> Stream ID for output streams
Igor Murashkine7ee7632013-06-11 18:10:18 -0700176 KeyedVector<sp<IBinder>, int> mStreamMap;
177
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700178 struct InputStreamConfiguration {
179 bool configured;
180 int32_t width;
181 int32_t height;
182 int32_t format;
183 int32_t id;
184 } mInputStream;
185
186 // Request ID
Igor Murashkine7ee7632013-06-11 18:10:18 -0700187 Vector<int> mStreamingRequestList;
188
189 int32_t mRequestIdCounter;
190};
191
192}; // namespace android
193
194#endif