blob: bb2949ca6d1c6721e06513534fdbe43954b34f2d [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
20#include "CameraDeviceBase.h"
21#include "CameraService.h"
22#include "camera2/ProFrameProcessor.h"
23#include "Camera2ClientBase.h"
24#include <camera/photography/ICameraDeviceUser.h>
25#include <camera/photography/ICameraDeviceCallbacks.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 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::ProFrameProcessor::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
Igor Murashkin099b4572013-07-12 17:52:16 -070088 virtual status_t getCameraInfo(/*out*/CameraMetadata* info);
Igor Murashkine7ee7632013-06-11 18:10:18 -070089
Zhijun He2ab500c2013-07-23 08:02:53 -070090 // Wait until all the submitted requests have finished processing
91 virtual status_t waitUntilIdle();
Igor Murashkine7ee7632013-06-11 18:10:18 -070092 /**
93 * Interface used by CameraService
94 */
95
96 CameraDeviceClient(const sp<CameraService>& cameraService,
97 const sp<ICameraDeviceCallbacks>& remoteCallback,
98 const String16& clientPackageName,
99 int cameraId,
100 int cameraFacing,
101 int clientPid,
102 uid_t clientUid,
103 int servicePid);
104 virtual ~CameraDeviceClient();
105
106 virtual status_t initialize(camera_module_t *module);
107
108 virtual status_t dump(int fd, const Vector<String16>& args);
109
110 /**
111 * Interface used by independent components of CameraDeviceClient.
112 */
113protected:
114 /** FilteredListener implementation **/
115 virtual void onFrameAvailable(int32_t frameId,
116 const CameraMetadata& frame);
117 virtual void detachDevice();
118
119private:
120 /** ICameraDeviceUser interface-related private members */
121
122 /** Preview callback related members */
123 sp<camera2::ProFrameProcessor> mFrameProcessor;
124 static const int32_t FRAME_PROCESSOR_LISTENER_MIN_ID = 0;
125 static const int32_t FRAME_PROCESSOR_LISTENER_MAX_ID = 0x7fffffffL;
126
127 /** Utility members */
128 bool enforceRequestPermissions(CameraMetadata& metadata);
129
130 // IGraphicsBufferProducer binder -> Stream ID
131 KeyedVector<sp<IBinder>, int> mStreamMap;
132
133 // Stream ID
134 Vector<int> mStreamingRequestList;
135
136 int32_t mRequestIdCounter;
137};
138
139}; // namespace android
140
141#endif