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