CameraDeviceClient.h revision f8b2a6f7dea06234c7966798d9363d2d236488a6
190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)/* 290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) * Copyright (C) 2013 The Android Open Source Project 390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) * 490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) * Licensed under the Apache License, Version 2.0 (the "License"); 590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) * you may not use this file except in compliance with the License. 690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) * You may obtain a copy of the License at 790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) * 890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) * http://www.apache.org/licenses/LICENSE-2.0 990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) * 1090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) * Unless required by applicable law or agreed to in writing, software 1190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) * distributed under the License is distributed on an "AS IS" BASIS, 1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) * See the License for the specific language governing permissions and 1490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) * limitations under the License. 1590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) */ 1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#ifndef ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERADEVICECLIENT_H 18cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#define ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERADEVICECLIENT_H 1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include <camera/camera2/ICameraDeviceUser.h> 2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include <camera/camera2/ICameraDeviceCallbacks.h> 2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "CameraService.h" 2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "common/FrameProcessorBase.h" 2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "common/Camera2ClientBase.h" 2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace android { 2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct 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 virtual void notifyError(); 49 50 sp<ICameraDeviceCallbacks> mRemoteCallback; 51}; 52 53/** 54 * Implements the binder ICameraDeviceUser API, 55 * meant for HAL3-public implementation of 56 * android.hardware.photography.CameraDevice 57 */ 58class CameraDeviceClient : 59 public Camera2ClientBase<CameraDeviceClientBase>, 60 public camera2::FrameProcessorBase::FilteredListener 61{ 62public: 63 /** 64 * ICameraDeviceUser interface (see ICameraDeviceUser for details) 65 */ 66 67 // Note that the callee gets a copy of the metadata. 68 virtual int submitRequest(sp<CaptureRequest> request, 69 bool streaming = false); 70 virtual status_t cancelRequest(int requestId); 71 72 // Returns -EBUSY if device is not idle 73 virtual status_t deleteStream(int streamId); 74 75 virtual status_t createStream( 76 int width, 77 int height, 78 int format, 79 const sp<IGraphicBufferProducer>& bufferProducer); 80 81 // Create a request object from a template. 82 virtual status_t createDefaultRequest(int templateId, 83 /*out*/ 84 CameraMetadata* request); 85 86 // Get the static metadata for the camera 87 // -- Caller owns the newly allocated metadata 88 virtual status_t getCameraInfo(/*out*/CameraMetadata* info); 89 90 // Wait until all the submitted requests have finished processing 91 virtual status_t waitUntilIdle(); 92 93 // Flush all active and pending requests as fast as possible 94 virtual status_t flush(); 95 96 /** 97 * Interface used by CameraService 98 */ 99 100 CameraDeviceClient(const sp<CameraService>& cameraService, 101 const sp<ICameraDeviceCallbacks>& remoteCallback, 102 const String16& clientPackageName, 103 int cameraId, 104 int cameraFacing, 105 int clientPid, 106 uid_t clientUid, 107 int servicePid); 108 virtual ~CameraDeviceClient(); 109 110 virtual status_t initialize(camera_module_t *module); 111 112 virtual status_t dump(int fd, const Vector<String16>& args); 113 114 /** 115 * Interface used by independent components of CameraDeviceClient. 116 */ 117protected: 118 /** FilteredListener implementation **/ 119 virtual void onFrameAvailable(int32_t frameId, 120 const CameraMetadata& frame); 121 virtual void detachDevice(); 122 123 // Calculate the ANativeWindow transform from android.sensor.orientation 124 status_t getRotationTransformLocked(/*out*/int32_t* transform); 125 126private: 127 /** ICameraDeviceUser interface-related private members */ 128 129 /** Preview callback related members */ 130 sp<camera2::FrameProcessorBase> mFrameProcessor; 131 static const int32_t FRAME_PROCESSOR_LISTENER_MIN_ID = 0; 132 static const int32_t FRAME_PROCESSOR_LISTENER_MAX_ID = 0x7fffffffL; 133 134 /** Utility members */ 135 bool enforceRequestPermissions(CameraMetadata& metadata); 136 137 // IGraphicsBufferProducer binder -> Stream ID 138 KeyedVector<sp<IBinder>, int> mStreamMap; 139 140 // Stream ID 141 Vector<int> mStreamingRequestList; 142 143 int32_t mRequestIdCounter; 144}; 145 146}; // namespace android 147 148#endif 149