1985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin/*
2985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin * Copyright (C) 2013 The Android Open Source Project
3985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin *
4985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin * Licensed under the Apache License, Version 2.0 (the "License");
5985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin * you may not use this file except in compliance with the License.
6985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin * You may obtain a copy of the License at
7985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin *
8985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin *      http://www.apache.org/licenses/LICENSE-2.0
9985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin *
10985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin * Unless required by applicable law or agreed to in writing, software
11985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin * distributed under the License is distributed on an "AS IS" BASIS,
12985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin * See the License for the specific language governing permissions and
14985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin * limitations under the License.
15985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin */
16985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin
17985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin#ifndef ANDROID_SERVERS_CAMERA_PROCAMERA2CLIENT_H
18985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin#define ANDROID_SERVERS_CAMERA_PROCAMERA2CLIENT_H
19985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin
20985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin#include "CameraService.h"
217b82efe7a376c882f8f938e1c41b8311a8cdda4aEino-Ville Talvala#include "common/FrameProcessorBase.h"
227b82efe7a376c882f8f938e1c41b8311a8cdda4aEino-Ville Talvala#include "common/Camera2ClientBase.h"
237b82efe7a376c882f8f938e1c41b8311a8cdda4aEino-Ville Talvala#include "device2/Camera2Device.h"
24985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin
25985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkinnamespace android {
26985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin
27985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkinclass IMemory;
28985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin/**
29985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin * Implements the binder IProCameraUser API,
30985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin * meant for HAL2-level private API access.
31985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin */
32985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkinclass ProCamera2Client :
3344cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin        public Camera2ClientBase<CameraService::ProClient>,
347b82efe7a376c882f8f938e1c41b8311a8cdda4aEino-Ville Talvala        public camera2::FrameProcessorBase::FilteredListener
35985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin{
36985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkinpublic:
37985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin    /**
38985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin     * IProCameraUser interface (see IProCameraUser for details)
39985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin     */
40985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin    virtual status_t      exclusiveTryLock();
41985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin    virtual status_t      exclusiveLock();
42985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin    virtual status_t      exclusiveUnlock();
43985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin
44985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin    virtual bool          hasExclusiveLock();
45985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin
46985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin    // Note that the callee gets a copy of the metadata.
47985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin    virtual int           submitRequest(camera_metadata_t* metadata,
48985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin                                        bool streaming = false);
49985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin    virtual status_t      cancelRequest(int requestId);
50985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin
51fa4cf9d310685b4c25877cba772ff7da84caf517Igor Murashkin    virtual status_t      deleteStream(int streamId);
52985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin
5344cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin    virtual status_t      createStream(
5444cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin            int width,
5544cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin            int height,
5644cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin            int format,
5744cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin            const sp<IGraphicBufferProducer>& bufferProducer,
5844cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin            /*out*/
5944cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin            int* streamId);
60985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin
61985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin    // Create a request object from a template.
623261fd3f1d8f798fab2f1b3efaa92d5a35cd42e7Igor Murashkin    // -- Caller owns the newly allocated metadata
63985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin    virtual status_t      createDefaultRequest(int templateId,
64985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin                                               /*out*/
65985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin                                               camera_metadata** request);
66985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin
677b33a74bbc514b99c16be7fff9a34e892bc19264Igor Murashkin    // Get the static metadata for the camera
687b33a74bbc514b99c16be7fff9a34e892bc19264Igor Murashkin    // -- Caller owns the newly allocated metadata
697b33a74bbc514b99c16be7fff9a34e892bc19264Igor Murashkin    virtual status_t      getCameraInfo(int cameraId,
707b33a74bbc514b99c16be7fff9a34e892bc19264Igor Murashkin                                        /*out*/
717b33a74bbc514b99c16be7fff9a34e892bc19264Igor Murashkin                                        camera_metadata** info);
72985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin
73985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin    /**
74985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin     * Interface used by CameraService
75985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin     */
76985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin
77985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin    ProCamera2Client(const sp<CameraService>& cameraService,
78985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin            const sp<IProCameraCallbacks>& remoteCallback,
79ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala            const String16& clientPackageName,
80985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin            int cameraId,
81985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin            int cameraFacing,
82985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin            int clientPid,
83ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala            uid_t clientUid,
84985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin            int servicePid);
85985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin    virtual ~ProCamera2Client();
86985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin
8744cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin    virtual status_t      initialize(camera_module_t *module);
88985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin
8944cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin    virtual status_t      dump(int fd, const Vector<String16>& args);
90985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin
91bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin    // Callbacks from camera service
92bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin    virtual void onExclusiveLockStolen();
93bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin
94985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin    /**
95985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin     * Interface used by independent components of ProCamera2Client.
96985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin     */
97985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin
98a91537e268f2b35f9f0dfdc0c4f84655c93285aeIgor Murashkinprotected:
99a91537e268f2b35f9f0dfdc0c4f84655c93285aeIgor Murashkin    /** FilteredListener implementation **/
100f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala    virtual void          onFrameAvailable(int32_t requestId,
10144cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin                                           const CameraMetadata& frame);
10244cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin    virtual void          detachDevice();
103a91537e268f2b35f9f0dfdc0c4f84655c93285aeIgor Murashkin
104985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkinprivate:
105985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin    /** IProCameraUser interface-related private members */
106985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin
107985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin    /** Preview callback related members */
1087b82efe7a376c882f8f938e1c41b8311a8cdda4aEino-Ville Talvala    sp<camera2::FrameProcessorBase> mFrameProcessor;
109a91537e268f2b35f9f0dfdc0c4f84655c93285aeIgor Murashkin    static const int32_t FRAME_PROCESSOR_LISTENER_MIN_ID = 0;
110a91537e268f2b35f9f0dfdc0c4f84655c93285aeIgor Murashkin    static const int32_t FRAME_PROCESSOR_LISTENER_MAX_ID = 0x7fffffffL;
111a91537e268f2b35f9f0dfdc0c4f84655c93285aeIgor Murashkin
112985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin    /** Utility members */
11303ac850527ffb90348dcdaad95caceb97649fd6bIgor Murashkin    bool enforceRequestPermissions(CameraMetadata& metadata);
114985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin
115985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin    // Whether or not we have an exclusive lock on the device
116985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin    // - if no we can't modify the request queue.
117985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin    // note that creating/deleting streams we own is still OK
118985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin    bool mExclusiveLock;
119985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin};
120985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin
121985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin}; // namespace android
122985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin
123985fd30a10f6fec4293f071fd258c4726cff5a3dIgor Murashkin#endif
124