CameraDeviceClient.h revision c78ac26e3a65328fc0118f16ee76a800d0687eb7
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_PHOTOGRAPHY_CAMERADEVICECLIENT_H 18#define ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERADEVICECLIENT_H 19 20#include <camera/camera2/ICameraDeviceUser.h> 21#include <camera/camera2/ICameraDeviceCallbacks.h> 22#include <camera/camera2/OutputConfiguration.h> 23 24#include "CameraService.h" 25#include "common/FrameProcessorBase.h" 26#include "common/Camera2ClientBase.h" 27 28namespace android { 29 30struct CameraDeviceClientBase : public CameraService::BasicClient, public BnCameraDeviceUser 31{ 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 48 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>, 58 public camera2::FrameProcessorBase::FilteredListener 59{ 60public: 61 /** 62 * ICameraDeviceUser interface (see ICameraDeviceUser for details) 63 */ 64 65 // Note that the callee gets a copy of the metadata. 66 virtual status_t submitRequest(sp<CaptureRequest> request, 67 bool streaming = false, 68 /*out*/ 69 int64_t* lastFrameNumber = NULL); 70 // List of requests are copied. 71 virtual status_t submitRequestList(List<sp<CaptureRequest> > requests, 72 bool streaming = false, 73 /*out*/ 74 int64_t* lastFrameNumber = NULL); 75 virtual status_t cancelRequest(int requestId, 76 /*out*/ 77 int64_t* lastFrameNumber = NULL); 78 79 virtual status_t beginConfigure(); 80 81 virtual status_t endConfigure(bool isConstrainedHighSpeed = false); 82 83 // Returns -EBUSY if device is not idle 84 virtual status_t deleteStream(int streamId); 85 86 virtual status_t createStream(const OutputConfiguration &outputConfiguration); 87 88 // 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 95 // 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 102 virtual status_t getCameraInfo(/*out*/CameraMetadata* info); 103 104 // Wait until all the submitted requests have finished processing 105 virtual status_t waitUntilIdle(); 106 107 // Flush all active and pending requests as fast as possible 108 virtual status_t flush(/*out*/ 109 int64_t* lastFrameNumber = NULL); 110 111 // Prepare stream by preallocating its buffers 112 virtual status_t prepare(int streamId); 113 114 // Tear down stream resources by freeing its unused buffers 115 virtual status_t tearDown(int streamId); 116 117 // Prepare stream by preallocating up to maxCount of its buffers 118 virtual status_t prepare2(int maxCount, int streamId); 119 120 /** 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 134 virtual status_t initialize(CameraModule *module); 135 136 virtual status_t dump(int fd, const Vector<String16>& args); 137 138 /** 139 * Device listener interface 140 */ 141 142 virtual void notifyIdle(); 143 virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode, 144 const CaptureResultExtras& resultExtras); 145 virtual void notifyShutter(const CaptureResultExtras& resultExtras, nsecs_t timestamp); 146 virtual void notifyPrepared(int streamId); 147 148 /** 149 * Interface used by independent components of CameraDeviceClient. 150 */ 151protected: 152 /** FilteredListener implementation **/ 153 virtual void onResultAvailable(const CaptureResult& result); 154 virtual void detachDevice(); 155 156 // Calculate the ANativeWindow transform from android.sensor.orientation 157 status_t getRotationTransformLocked(/*out*/int32_t* transform); 158 159private: 160 /** ICameraDeviceUser interface-related private members */ 161 162 /** Preview callback related members */ 163 sp<camera2::FrameProcessorBase> mFrameProcessor; 164 static const int32_t FRAME_PROCESSOR_LISTENER_MIN_ID = 0; 165 static const int32_t FRAME_PROCESSOR_LISTENER_MAX_ID = 0x7fffffffL; 166 167 /** Utility members */ 168 bool enforceRequestPermissions(CameraMetadata& metadata); 169 170 // Find the square of the euclidean distance between two points 171 static int64_t euclidDistSquare(int32_t x0, int32_t y0, int32_t x1, int32_t y1); 172 173 // Find the closest dimensions for a given format in available stream configurations with 174 // a width <= ROUNDING_WIDTH_CAP 175 static const int32_t ROUNDING_WIDTH_CAP = 1920; 176 static bool roundBufferDimensionNearest(int32_t width, int32_t height, int32_t format, 177 android_dataspace dataSpace, const CameraMetadata& info, 178 /*out*/int32_t* outWidth, /*out*/int32_t* outHeight); 179 180 // IGraphicsBufferProducer binder -> Stream ID for output streams 181 KeyedVector<sp<IBinder>, int> mStreamMap; 182 183 struct InputStreamConfiguration { 184 bool configured; 185 int32_t width; 186 int32_t height; 187 int32_t format; 188 int32_t id; 189 } mInputStream; 190 191 // Request ID 192 Vector<int> mStreamingRequestList; 193 194 int32_t mRequestIdCounter; 195}; 196 197}; // namespace android 198 199#endif 200