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