blob: a2068e71b102652ed4e87286416289a26aa1f47a [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>
Yin-Chia Yehead91462016-01-06 16:45:08 -080022#include "ACameraDevice.h"
23
24using namespace android;
25
26struct ACaptureSessionOutput {
Emilian Peev40ead602017-09-26 15:46:36 +010027 explicit ACaptureSessionOutput(ANativeWindow* window, bool isShared = false) :
28 mWindow(window), mIsShared(isShared) {};
Yin-Chia Yehead91462016-01-06 16:45:08 -080029
30 bool operator == (const ACaptureSessionOutput& other) const {
31 return mWindow == other.mWindow;
32 }
33 bool operator != (const ACaptureSessionOutput& other) const {
34 return mWindow != other.mWindow;
35 }
36 bool operator < (const ACaptureSessionOutput& other) const {
37 return mWindow < other.mWindow;
38 }
39 bool operator > (const ACaptureSessionOutput& other) const {
40 return mWindow > other.mWindow;
41 }
42
43 ANativeWindow* mWindow;
Emilian Peev40ead602017-09-26 15:46:36 +010044 std::set<ANativeWindow *> mSharedWindows;
45 bool mIsShared;
Yin-Chia Yehead91462016-01-06 16:45:08 -080046 int mRotation = CAMERA3_STREAM_ROTATION_0;
47};
48
49struct ACaptureSessionOutputContainer {
50 std::set<ACaptureSessionOutput> mOutputs;
51};
52
53/**
54 * ACameraCaptureSession opaque struct definition
55 * Leave outside of android namespace because it's NDK struct
56 */
57struct ACameraCaptureSession : public RefBase {
58 public:
59 ACameraCaptureSession(
60 int id,
61 const ACaptureSessionOutputContainer* outputs,
62 const ACameraCaptureSession_stateCallbacks* cb,
63 CameraDevice* device) :
64 mId(id), mOutput(*outputs), mUserSessionCallback(*cb),
65 mDevice(device) {}
66
67 // This can be called in app calling close() or after some app callback is finished
68 // Make sure the caller does not hold device or session lock!
69 ~ACameraCaptureSession();
70
71 // No API except Session_Close will work if device is closed
72 // A session will enter closed state when one of the following happens:
73 // 1. Explicitly closed by app
74 // 2. Replaced by a newer session
75 // 3. Device is closed
76 bool isClosed() { Mutex::Autolock _l(mSessionLock); return mIsClosed; }
77
78 // Close the session and mark app no longer need this session.
79 void closeByApp();
80
81 camera_status_t stopRepeating();
82
Yin-Chia Yeh309d05d2016-03-28 10:15:31 -070083 camera_status_t abortCaptures();
84
Yin-Chia Yehead91462016-01-06 16:45:08 -080085 camera_status_t setRepeatingRequest(
86 /*optional*/ACameraCaptureSession_captureCallbacks* cbs,
87 int numRequests, ACaptureRequest** requests,
88 /*optional*/int* captureSequenceId);
89
90 camera_status_t capture(
91 /*optional*/ACameraCaptureSession_captureCallbacks* cbs,
92 int numRequests, ACaptureRequest** requests,
93 /*optional*/int* captureSequenceId);
94
Emilian Peev40ead602017-09-26 15:46:36 +010095 camera_status_t updateOutputConfiguration(ACaptureSessionOutput *output);
96
Yin-Chia Yehead91462016-01-06 16:45:08 -080097 ACameraDevice* getDevice();
98
99 private:
100 friend class CameraDevice;
101
102 // Close session because app close camera device, camera device got ERROR_DISCONNECTED,
103 // or a new session is replacing this session.
104 void closeByDevice();
105
106 sp<CameraDevice> getDeviceSp();
107
108 const int mId;
109 const ACaptureSessionOutputContainer mOutput;
110 const ACameraCaptureSession_stateCallbacks mUserSessionCallback;
111 const wp<CameraDevice> mDevice;
112 bool mIsClosed = false;
Yin-Chia Yeh085dd092016-03-02 14:16:31 -0800113 bool mClosedByApp = false;
Yin-Chia Yehead91462016-01-06 16:45:08 -0800114 Mutex mSessionLock;
115};
116
117#endif // _ACAMERA_CAPTURE_SESSION_H