• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PROCAMERA2CLIENT_H
18 #define ANDROID_SERVERS_CAMERA_PROCAMERA2CLIENT_H
19 
20 #include "CameraService.h"
21 #include "common/FrameProcessorBase.h"
22 #include "common/Camera2ClientBase.h"
23 #include "device2/Camera2Device.h"
24 #include "camera/CaptureResult.h"
25 
26 namespace android {
27 
28 class IMemory;
29 /**
30  * Implements the binder IProCameraUser API,
31  * meant for HAL2-level private API access.
32  */
33 class ProCamera2Client :
34         public Camera2ClientBase<CameraService::ProClient>,
35         public camera2::FrameProcessorBase::FilteredListener
36 {
37 public:
38     /**
39      * IProCameraUser interface (see IProCameraUser for details)
40      */
41     virtual status_t      exclusiveTryLock();
42     virtual status_t      exclusiveLock();
43     virtual status_t      exclusiveUnlock();
44 
45     virtual bool          hasExclusiveLock();
46 
47     // Note that the callee gets a copy of the metadata.
48     virtual int           submitRequest(camera_metadata_t* metadata,
49                                         bool streaming = false);
50     virtual status_t      cancelRequest(int requestId);
51 
52     virtual status_t      deleteStream(int streamId);
53 
54     virtual status_t      createStream(
55             int width,
56             int height,
57             int format,
58             const sp<IGraphicBufferProducer>& bufferProducer,
59             /*out*/
60             int* streamId);
61 
62     // Create a request object from a template.
63     // -- Caller owns the newly allocated metadata
64     virtual status_t      createDefaultRequest(int templateId,
65                                                /*out*/
66                                                camera_metadata** request);
67 
68     // Get the static metadata for the camera
69     // -- Caller owns the newly allocated metadata
70     virtual status_t      getCameraInfo(int cameraId,
71                                         /*out*/
72                                         camera_metadata** info);
73 
74     /**
75      * Interface used by CameraService
76      */
77 
78     ProCamera2Client(const sp<CameraService>& cameraService,
79             const sp<IProCameraCallbacks>& remoteCallback,
80             const String16& clientPackageName,
81             int cameraId,
82             int cameraFacing,
83             int clientPid,
84             uid_t clientUid,
85             int servicePid);
86     virtual ~ProCamera2Client();
87 
88     virtual status_t      initialize(camera_module_t *module);
89 
90     virtual status_t      dump(int fd, const Vector<String16>& args);
91 
92     // Callbacks from camera service
93     virtual void onExclusiveLockStolen();
94 
95     /**
96      * Interface used by independent components of ProCamera2Client.
97      */
98 
99 protected:
100     /** FilteredListener implementation **/
101     virtual void onResultAvailable(const CaptureResult& result);
102 
103     virtual void          detachDevice();
104 
105 private:
106     /** IProCameraUser interface-related private members */
107 
108     /** Preview callback related members */
109     sp<camera2::FrameProcessorBase> mFrameProcessor;
110     static const int32_t FRAME_PROCESSOR_LISTENER_MIN_ID = 0;
111     static const int32_t FRAME_PROCESSOR_LISTENER_MAX_ID = 0x7fffffffL;
112 
113     /** Utility members */
114     bool enforceRequestPermissions(CameraMetadata& metadata);
115 
116     // Whether or not we have an exclusive lock on the device
117     // - if no we can't modify the request queue.
118     // note that creating/deleting streams we own is still OK
119     bool mExclusiveLock;
120 };
121 
122 }; // namespace android
123 
124 #endif
125