1ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh/* 2ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh * Copyright (C) 2016 The Android Open Source Project 3ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh * 4ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh * Licensed under the Apache License, Version 2.0 (the "License"); 5ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh * you may not use this file except in compliance with the License. 6ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh * You may obtain a copy of the License at 7ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh * 8ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh * http://www.apache.org/licenses/LICENSE-2.0 9ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh * 10ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh * Unless required by applicable law or agreed to in writing, software 11ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh * distributed under the License is distributed on an "AS IS" BASIS, 12ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh * See the License for the specific language governing permissions and 14ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh * limitations under the License. 15ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh */ 16ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh#ifndef _ACAMERA_CAPTURE_SESSION_H 17ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh#define _ACAMERA_CAPTURE_SESSION_H 18ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh 19ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh#include <set> 20ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh#include <hardware/camera3.h> 21ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh#include <NdkCameraDevice.h> 22ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh#include "ACameraDevice.h" 23ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh 24ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yehusing namespace android; 25ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh 26ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yehstruct ACaptureSessionOutput { 27d19d994770a04f02c204affd29985c5aeaa58baaChih-Hung Hsieh explicit ACaptureSessionOutput(ANativeWindow* window) : mWindow(window) {}; 28ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh 29ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh bool operator == (const ACaptureSessionOutput& other) const { 30ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh return mWindow == other.mWindow; 31ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh } 32ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh bool operator != (const ACaptureSessionOutput& other) const { 33ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh return mWindow != other.mWindow; 34ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh } 35ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh bool operator < (const ACaptureSessionOutput& other) const { 36ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh return mWindow < other.mWindow; 37ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh } 38ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh bool operator > (const ACaptureSessionOutput& other) const { 39ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh return mWindow > other.mWindow; 40ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh } 41ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh 42ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh ANativeWindow* mWindow; 43ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh int mRotation = CAMERA3_STREAM_ROTATION_0; 44ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh}; 45ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh 46ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yehstruct ACaptureSessionOutputContainer { 47ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh std::set<ACaptureSessionOutput> mOutputs; 48ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh}; 49ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh 50ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh/** 51ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh * ACameraCaptureSession opaque struct definition 52ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh * Leave outside of android namespace because it's NDK struct 53ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh */ 54ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yehstruct ACameraCaptureSession : public RefBase { 55ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh public: 56ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh ACameraCaptureSession( 57ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh int id, 58ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh const ACaptureSessionOutputContainer* outputs, 59ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh const ACameraCaptureSession_stateCallbacks* cb, 60ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh CameraDevice* device) : 61ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh mId(id), mOutput(*outputs), mUserSessionCallback(*cb), 62ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh mDevice(device) {} 63ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh 64ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh // This can be called in app calling close() or after some app callback is finished 65ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh // Make sure the caller does not hold device or session lock! 66ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh ~ACameraCaptureSession(); 67ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh 68ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh // No API except Session_Close will work if device is closed 69ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh // A session will enter closed state when one of the following happens: 70ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh // 1. Explicitly closed by app 71ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh // 2. Replaced by a newer session 72ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh // 3. Device is closed 73ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh bool isClosed() { Mutex::Autolock _l(mSessionLock); return mIsClosed; } 74ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh 75ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh // Close the session and mark app no longer need this session. 76ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh void closeByApp(); 77ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh 78ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh camera_status_t stopRepeating(); 79ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh 80309d05d030903e7849affd60c58d4236147aa390Yin-Chia Yeh camera_status_t abortCaptures(); 81309d05d030903e7849affd60c58d4236147aa390Yin-Chia Yeh 82ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh camera_status_t setRepeatingRequest( 83ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh /*optional*/ACameraCaptureSession_captureCallbacks* cbs, 84ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh int numRequests, ACaptureRequest** requests, 85ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh /*optional*/int* captureSequenceId); 86ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh 87ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh camera_status_t capture( 88ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh /*optional*/ACameraCaptureSession_captureCallbacks* cbs, 89ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh int numRequests, ACaptureRequest** requests, 90ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh /*optional*/int* captureSequenceId); 91ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh 92ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh ACameraDevice* getDevice(); 93ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh 94ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh private: 95ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh friend class CameraDevice; 96ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh 97ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh // Close session because app close camera device, camera device got ERROR_DISCONNECTED, 98ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh // or a new session is replacing this session. 99ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh void closeByDevice(); 100ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh 101ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh sp<CameraDevice> getDeviceSp(); 102ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh 103ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh const int mId; 104ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh const ACaptureSessionOutputContainer mOutput; 105ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh const ACameraCaptureSession_stateCallbacks mUserSessionCallback; 106ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh const wp<CameraDevice> mDevice; 107ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh bool mIsClosed = false; 108085dd0935c9cd19791a9a58a4df4a05e29eadca7Yin-Chia Yeh bool mClosedByApp = false; 109ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh Mutex mSessionLock; 110ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh}; 111ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh 112ead9146f844ee194a4f4244ba8ae1a3aece12b63Yin-Chia Yeh#endif // _ACAMERA_CAPTURE_SESSION_H 113