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