blob: 133c2c83250eb446f8a1d512f9328878ff75c1a1 [file] [log] [blame]
Yin-Chia Yehead91462016-01-06 16:45:08 -08001/*
2 * Copyright (C) 2016 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#ifndef _ACAMERA_CAPTURE_SESSION_H
17#define _ACAMERA_CAPTURE_SESSION_H
18
19#include <set>
20#include <hardware/camera3.h>
Colin Cross7e8d4ba2017-05-04 16:17:42 -070021#include <camera/NdkCameraDevice.h>
Jayant Chowdhary6df26072018-11-06 23:55:12 -080022
23#ifdef __ANDROID_VNDK__
24#include "ndk_vendor/impl/ACameraDevice.h"
25#include "ndk_vendor/impl/ACameraCaptureSessionVendor.h"
26#else
Yin-Chia Yehead91462016-01-06 16:45:08 -080027#include "ACameraDevice.h"
28
29using namespace android;
30
31struct ACaptureSessionOutput {
Jayant Chowdhary6df26072018-11-06 23:55:12 -080032 explicit ACaptureSessionOutput(ACameraWindowType* window, bool isShared = false) :
Emilian Peev40ead602017-09-26 15:46:36 +010033 mWindow(window), mIsShared(isShared) {};
Yin-Chia Yehead91462016-01-06 16:45:08 -080034
35 bool operator == (const ACaptureSessionOutput& other) const {
36 return mWindow == other.mWindow;
37 }
38 bool operator != (const ACaptureSessionOutput& other) const {
39 return mWindow != other.mWindow;
40 }
41 bool operator < (const ACaptureSessionOutput& other) const {
42 return mWindow < other.mWindow;
43 }
44 bool operator > (const ACaptureSessionOutput& other) const {
45 return mWindow > other.mWindow;
46 }
47
Jayant Chowdhary6df26072018-11-06 23:55:12 -080048 ACameraWindowType* mWindow;
49 std::set<ACameraWindowType *> mSharedWindows;
Emilian Peev40ead602017-09-26 15:46:36 +010050 bool mIsShared;
Yin-Chia Yehead91462016-01-06 16:45:08 -080051 int mRotation = CAMERA3_STREAM_ROTATION_0;
52};
Jayant Chowdhary6df26072018-11-06 23:55:12 -080053#endif
Yin-Chia Yehead91462016-01-06 16:45:08 -080054
55struct ACaptureSessionOutputContainer {
56 std::set<ACaptureSessionOutput> mOutputs;
57};
58
59/**
60 * ACameraCaptureSession opaque struct definition
61 * Leave outside of android namespace because it's NDK struct
62 */
63struct ACameraCaptureSession : public RefBase {
64 public:
65 ACameraCaptureSession(
66 int id,
67 const ACaptureSessionOutputContainer* outputs,
68 const ACameraCaptureSession_stateCallbacks* cb,
Jayant Chowdhary6df26072018-11-06 23:55:12 -080069 android::acam::CameraDevice* device) :
Yin-Chia Yehead91462016-01-06 16:45:08 -080070 mId(id), mOutput(*outputs), mUserSessionCallback(*cb),
71 mDevice(device) {}
72
73 // This can be called in app calling close() or after some app callback is finished
74 // Make sure the caller does not hold device or session lock!
75 ~ACameraCaptureSession();
76
77 // No API except Session_Close will work if device is closed
78 // A session will enter closed state when one of the following happens:
79 // 1. Explicitly closed by app
80 // 2. Replaced by a newer session
81 // 3. Device is closed
82 bool isClosed() { Mutex::Autolock _l(mSessionLock); return mIsClosed; }
83
84 // Close the session and mark app no longer need this session.
85 void closeByApp();
86
87 camera_status_t stopRepeating();
88
Yin-Chia Yeh309d05d2016-03-28 10:15:31 -070089 camera_status_t abortCaptures();
90
Yin-Chia Yehead91462016-01-06 16:45:08 -080091 camera_status_t setRepeatingRequest(
92 /*optional*/ACameraCaptureSession_captureCallbacks* cbs,
93 int numRequests, ACaptureRequest** requests,
94 /*optional*/int* captureSequenceId);
95
96 camera_status_t capture(
97 /*optional*/ACameraCaptureSession_captureCallbacks* cbs,
98 int numRequests, ACaptureRequest** requests,
99 /*optional*/int* captureSequenceId);
100
Emilian Peev40ead602017-09-26 15:46:36 +0100101 camera_status_t updateOutputConfiguration(ACaptureSessionOutput *output);
102
Yin-Chia Yehead91462016-01-06 16:45:08 -0800103 ACameraDevice* getDevice();
104
105 private:
Jayant Chowdhary6df26072018-11-06 23:55:12 -0800106 friend class android::acam::CameraDevice;
Yin-Chia Yehead91462016-01-06 16:45:08 -0800107
108 // Close session because app close camera device, camera device got ERROR_DISCONNECTED,
109 // or a new session is replacing this session.
110 void closeByDevice();
111
Jayant Chowdhary6df26072018-11-06 23:55:12 -0800112 sp<android::acam::CameraDevice> getDeviceSp();
Yin-Chia Yehead91462016-01-06 16:45:08 -0800113
114 const int mId;
115 const ACaptureSessionOutputContainer mOutput;
116 const ACameraCaptureSession_stateCallbacks mUserSessionCallback;
Jayant Chowdhary6df26072018-11-06 23:55:12 -0800117 const wp<android::acam::CameraDevice> mDevice;
Yin-Chia Yehead91462016-01-06 16:45:08 -0800118 bool mIsClosed = false;
Yin-Chia Yeh085dd092016-03-02 14:16:31 -0800119 bool mClosedByApp = false;
Yin-Chia Yehead91462016-01-06 16:45:08 -0800120 Mutex mSessionLock;
121};
122
123#endif // _ACAMERA_CAPTURE_SESSION_H