CameraDeviceClient.h revision 90e59c98c343e941b1a75307ffa4b4b5f1eb50d6
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 23#include "CameraService.h" 24#include "common/FrameProcessorBase.h" 25#include "common/Camera2ClientBase.h" 26 27namespace android { 28 29struct CameraDeviceClientBase : 30 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 // List of requests are copied. 69 virtual status_t submitRequestList(List<sp<CaptureRequest> > requests, 70 bool streaming = false); 71 virtual status_t cancelRequest(int requestId); 72 73 // Returns -EBUSY if device is not idle 74 virtual status_t deleteStream(int streamId); 75 76 virtual status_t createStream( 77 int width, 78 int height, 79 int format, 80 const sp<IGraphicBufferProducer>& bufferProducer); 81 82 // Create a request object from a template. 83 virtual status_t createDefaultRequest(int templateId, 84 /*out*/ 85 CameraMetadata* request); 86 87 // Get the static metadata for the camera 88 // -- Caller owns the newly allocated metadata 89 virtual status_t getCameraInfo(/*out*/CameraMetadata* info); 90 91 // Wait until all the submitted requests have finished processing 92 virtual status_t waitUntilIdle(); 93 94 // Flush all active and pending requests as fast as possible 95 virtual status_t flush(); 96 97 /** 98 * Interface used by CameraService 99 */ 100 101 CameraDeviceClient(const sp<CameraService>& cameraService, 102 const sp<ICameraDeviceCallbacks>& remoteCallback, 103 const String16& clientPackageName, 104 int cameraId, 105 int cameraFacing, 106 int clientPid, 107 uid_t clientUid, 108 int servicePid); 109 virtual ~CameraDeviceClient(); 110 111 virtual status_t initialize(camera_module_t *module); 112 113 virtual status_t dump(int fd, const Vector<String16>& args); 114 115 /** 116 * Device listener interface 117 */ 118 119 virtual void notifyIdle(); 120 virtual void notifyError(); 121 virtual void notifyShutter(int requestId, nsecs_t timestamp); 122 123 /** 124 * Interface used by independent components of CameraDeviceClient. 125 */ 126protected: 127 /** FilteredListener implementation **/ 128 virtual void onFrameAvailable(int32_t requestId, 129 const CameraMetadata& frame); 130 virtual void detachDevice(); 131 132 // Calculate the ANativeWindow transform from android.sensor.orientation 133 status_t getRotationTransformLocked(/*out*/int32_t* transform); 134 135private: 136 /** ICameraDeviceUser interface-related private members */ 137 138 /** Preview callback related members */ 139 sp<camera2::FrameProcessorBase> mFrameProcessor; 140 static const int32_t FRAME_PROCESSOR_LISTENER_MIN_ID = 0; 141 static const int32_t FRAME_PROCESSOR_LISTENER_MAX_ID = 0x7fffffffL; 142 143 /** Utility members */ 144 bool enforceRequestPermissions(CameraMetadata& metadata); 145 146 // IGraphicsBufferProducer binder -> Stream ID 147 KeyedVector<sp<IBinder>, int> mStreamMap; 148 149 // Stream ID 150 Vector<int> mStreamingRequestList; 151 152 int32_t mRequestIdCounter; 153}; 154 155}; // namespace android 156 157#endif 158