blob: b9c16aa812c2c70e185e498a039d2a6695e915aa [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>
22
Igor Murashkine7ee7632013-06-11 18:10:18 -070023#include "CameraService.h"
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070024#include "common/FrameProcessorBase.h"
25#include "common/Camera2ClientBase.h"
Igor Murashkine7ee7632013-06-11 18:10:18 -070026
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
Igor Murashkine7ee7632013-06-11 18:10:18 -070048 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>,
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070058 public camera2::FrameProcessorBase::FilteredListener
Igor Murashkine7ee7632013-06-11 18:10:18 -070059{
60public:
61 /**
62 * ICameraDeviceUser interface (see ICameraDeviceUser for details)
63 */
64
65 // Note that the callee gets a copy of the metadata.
66 virtual int submitRequest(sp<CaptureRequest> request,
67 bool streaming = false);
68 virtual status_t cancelRequest(int requestId);
69
70 // Returns -EBUSY if device is not idle
71 virtual status_t deleteStream(int streamId);
72
73 virtual status_t createStream(
74 int width,
75 int height,
76 int format,
77 const sp<IGraphicBufferProducer>& bufferProducer);
78
79 // Create a request object from a template.
80 virtual status_t createDefaultRequest(int templateId,
81 /*out*/
82 CameraMetadata* request);
83
84 // Get the static metadata for the camera
85 // -- Caller owns the newly allocated metadata
Igor Murashkin099b4572013-07-12 17:52:16 -070086 virtual status_t getCameraInfo(/*out*/CameraMetadata* info);
Igor Murashkine7ee7632013-06-11 18:10:18 -070087
Zhijun He2ab500c2013-07-23 08:02:53 -070088 // Wait until all the submitted requests have finished processing
89 virtual status_t waitUntilIdle();
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -070090
91 // Flush all active and pending requests as fast as possible
92 virtual status_t flush();
93
Igor Murashkine7ee7632013-06-11 18:10:18 -070094 /**
95 * Interface used by CameraService
96 */
97
98 CameraDeviceClient(const sp<CameraService>& cameraService,
99 const sp<ICameraDeviceCallbacks>& remoteCallback,
100 const String16& clientPackageName,
101 int cameraId,
102 int cameraFacing,
103 int clientPid,
104 uid_t clientUid,
105 int servicePid);
106 virtual ~CameraDeviceClient();
107
108 virtual status_t initialize(camera_module_t *module);
109
110 virtual status_t dump(int fd, const Vector<String16>& args);
111
112 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700113 * Device listener interface
114 */
115
116 virtual void notifyIdle();
117 virtual void notifyError();
118 virtual void notifyShutter(int requestId, nsecs_t timestamp);
119
120 /**
Igor Murashkine7ee7632013-06-11 18:10:18 -0700121 * Interface used by independent components of CameraDeviceClient.
122 */
123protected:
124 /** FilteredListener implementation **/
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700125 virtual void onFrameAvailable(int32_t requestId,
Igor Murashkine7ee7632013-06-11 18:10:18 -0700126 const CameraMetadata& frame);
127 virtual void detachDevice();
128
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -0700129 // Calculate the ANativeWindow transform from android.sensor.orientation
130 status_t getRotationTransformLocked(/*out*/int32_t* transform);
131
Igor Murashkine7ee7632013-06-11 18:10:18 -0700132private:
133 /** ICameraDeviceUser interface-related private members */
134
135 /** Preview callback related members */
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -0700136 sp<camera2::FrameProcessorBase> mFrameProcessor;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700137 static const int32_t FRAME_PROCESSOR_LISTENER_MIN_ID = 0;
138 static const int32_t FRAME_PROCESSOR_LISTENER_MAX_ID = 0x7fffffffL;
139
140 /** Utility members */
141 bool enforceRequestPermissions(CameraMetadata& metadata);
142
143 // IGraphicsBufferProducer binder -> Stream ID
144 KeyedVector<sp<IBinder>, int> mStreamMap;
145
146 // Stream ID
147 Vector<int> mStreamingRequestList;
148
149 int32_t mRequestIdCounter;
150};
151
152}; // namespace android
153
154#endif