ACameraCaptureSession.h revision d19d994770a04f02c204affd29985c5aeaa58baa
1a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora/* 29aea642eefa7a641ab8b89d953251939221d2719Eric Hassold * Copyright (C) 2016 The Android Open Source Project 30406ce1417f76f2034833414dcecc9f56253640cVikas Arora * 40406ce1417f76f2034833414dcecc9f56253640cVikas Arora * Licensed under the Apache License, Version 2.0 (the "License"); 50406ce1417f76f2034833414dcecc9f56253640cVikas Arora * you may not use this file except in compliance with the License. 60406ce1417f76f2034833414dcecc9f56253640cVikas Arora * You may obtain a copy of the License at 70406ce1417f76f2034833414dcecc9f56253640cVikas Arora * 89aea642eefa7a641ab8b89d953251939221d2719Eric Hassold * http://www.apache.org/licenses/LICENSE-2.0 99aea642eefa7a641ab8b89d953251939221d2719Eric Hassold * 109aea642eefa7a641ab8b89d953251939221d2719Eric Hassold * Unless required by applicable law or agreed to in writing, software 119aea642eefa7a641ab8b89d953251939221d2719Eric Hassold * distributed under the License is distributed on an "AS IS" BASIS, 129aea642eefa7a641ab8b89d953251939221d2719Eric Hassold * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139aea642eefa7a641ab8b89d953251939221d2719Eric Hassold * See the License for the specific language governing permissions and 1403d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora * limitations under the License. 1503d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora */ 169aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#ifndef _ACAMERA_CAPTURE_SESSION_H 179aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#define _ACAMERA_CAPTURE_SESSION_H 18fa39824bb690c5806358871f46940d0450973d8aJames Zern 19fa39824bb690c5806358871f46940d0450973d8aJames Zern#include <set> 20fa39824bb690c5806358871f46940d0450973d8aJames Zern#include <hardware/camera3.h> 21fa39824bb690c5806358871f46940d0450973d8aJames Zern#include <NdkCameraDevice.h> 22fa39824bb690c5806358871f46940d0450973d8aJames Zern#include "ACameraDevice.h" 23a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 249aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldusing namespace android; 258b720228d581a84fd173b6dcb2fa295b59db489aVikas Arora 269aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstruct ACaptureSessionOutput { 279aea642eefa7a641ab8b89d953251939221d2719Eric Hassold explicit ACaptureSessionOutput(ANativeWindow* window) : mWindow(window) {}; 289aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 29a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora bool operator == (const ACaptureSessionOutput& other) const { 309aea642eefa7a641ab8b89d953251939221d2719Eric Hassold return mWindow == other.mWindow; 319aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 3203d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora bool operator != (const ACaptureSessionOutput& other) const { 3303d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora return mWindow != other.mWindow; 34fa39824bb690c5806358871f46940d0450973d8aJames Zern } 35fa39824bb690c5806358871f46940d0450973d8aJames Zern bool operator < (const ACaptureSessionOutput& other) const { 367c8da7ce66017295a65ec028084b90800be377f8James Zern return mWindow < other.mWindow; 377c8da7ce66017295a65ec028084b90800be377f8James Zern } 389aea642eefa7a641ab8b89d953251939221d2719Eric Hassold bool operator > (const ACaptureSessionOutput& other) const { 399aea642eefa7a641ab8b89d953251939221d2719Eric Hassold return mWindow > other.mWindow; 409aea642eefa7a641ab8b89d953251939221d2719Eric Hassold } 419aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 429aea642eefa7a641ab8b89d953251939221d2719Eric Hassold ANativeWindow* mWindow; 439aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int mRotation = CAMERA3_STREAM_ROTATION_0; 449aea642eefa7a641ab8b89d953251939221d2719Eric Hassold}; 459aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 469aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstruct ACaptureSessionOutputContainer { 479aea642eefa7a641ab8b89d953251939221d2719Eric Hassold std::set<ACaptureSessionOutput> mOutputs; 489aea642eefa7a641ab8b89d953251939221d2719Eric Hassold}; 499aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 509aea642eefa7a641ab8b89d953251939221d2719Eric Hassold/** 519aea642eefa7a641ab8b89d953251939221d2719Eric Hassold * ACameraCaptureSession opaque struct definition 529aea642eefa7a641ab8b89d953251939221d2719Eric Hassold * Leave outside of android namespace because it's NDK struct 539aea642eefa7a641ab8b89d953251939221d2719Eric Hassold */ 549aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldstruct ACameraCaptureSession : public RefBase { 559aea642eefa7a641ab8b89d953251939221d2719Eric Hassold public: 569aea642eefa7a641ab8b89d953251939221d2719Eric Hassold ACameraCaptureSession( 579aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int id, 589aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const ACaptureSessionOutputContainer* outputs, 599aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const ACameraCaptureSession_stateCallbacks* cb, 609aea642eefa7a641ab8b89d953251939221d2719Eric Hassold CameraDevice* device) : 619aea642eefa7a641ab8b89d953251939221d2719Eric Hassold mId(id), mOutput(*outputs), mUserSessionCallback(*cb), 629aea642eefa7a641ab8b89d953251939221d2719Eric Hassold mDevice(device) {} 639aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 649aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // This can be called in app calling close() or after some app callback is finished 658b720228d581a84fd173b6dcb2fa295b59db489aVikas Arora // Make sure the caller does not hold device or session lock! 668b720228d581a84fd173b6dcb2fa295b59db489aVikas Arora ~ACameraCaptureSession(); 678b720228d581a84fd173b6dcb2fa295b59db489aVikas Arora 68a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora // No API except Session_Close will work if device is closed 699aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // A session will enter closed state when one of the following happens: 709aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // 1. Explicitly closed by app 719aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // 2. Replaced by a newer session 729aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // 3. Device is closed 739aea642eefa7a641ab8b89d953251939221d2719Eric Hassold bool isClosed() { Mutex::Autolock _l(mSessionLock); return mIsClosed; } 749aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 759aea642eefa7a641ab8b89d953251939221d2719Eric Hassold // Close the session and mark app no longer need this session. 769aea642eefa7a641ab8b89d953251939221d2719Eric Hassold void closeByApp(); 779aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 789aea642eefa7a641ab8b89d953251939221d2719Eric Hassold camera_status_t stopRepeating(); 799aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 809aea642eefa7a641ab8b89d953251939221d2719Eric Hassold camera_status_t abortCaptures(); 819aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 829aea642eefa7a641ab8b89d953251939221d2719Eric Hassold camera_status_t setRepeatingRequest( 839aea642eefa7a641ab8b89d953251939221d2719Eric Hassold /*optional*/ACameraCaptureSession_captureCallbacks* cbs, 849aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int numRequests, ACaptureRequest** requests, 859aea642eefa7a641ab8b89d953251939221d2719Eric Hassold /*optional*/int* captureSequenceId); 869aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 879aea642eefa7a641ab8b89d953251939221d2719Eric Hassold camera_status_t capture( 889aea642eefa7a641ab8b89d953251939221d2719Eric Hassold /*optional*/ACameraCaptureSession_captureCallbacks* cbs, 899aea642eefa7a641ab8b89d953251939221d2719Eric Hassold int numRequests, ACaptureRequest** requests, 909aea642eefa7a641ab8b89d953251939221d2719Eric Hassold /*optional*/int* captureSequenceId); 919aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 929aea642eefa7a641ab8b89d953251939221d2719Eric Hassold ACameraDevice* getDevice(); 939aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 949aea642eefa7a641ab8b89d953251939221d2719Eric Hassold private: 959aea642eefa7a641ab8b89d953251939221d2719Eric Hassold friend class CameraDevice; 968b720228d581a84fd173b6dcb2fa295b59db489aVikas Arora 978b720228d581a84fd173b6dcb2fa295b59db489aVikas Arora // Close session because app close camera device, camera device got ERROR_DISCONNECTED, 988b720228d581a84fd173b6dcb2fa295b59db489aVikas Arora // or a new session is replacing this session. 998b720228d581a84fd173b6dcb2fa295b59db489aVikas Arora void closeByDevice(); 1008b720228d581a84fd173b6dcb2fa295b59db489aVikas Arora 1018b720228d581a84fd173b6dcb2fa295b59db489aVikas Arora sp<CameraDevice> getDeviceSp(); 1028b720228d581a84fd173b6dcb2fa295b59db489aVikas Arora 1039aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const int mId; 1049aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const ACaptureSessionOutputContainer mOutput; 1059aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const ACameraCaptureSession_stateCallbacks mUserSessionCallback; 1069aea642eefa7a641ab8b89d953251939221d2719Eric Hassold const wp<CameraDevice> mDevice; 1078b720228d581a84fd173b6dcb2fa295b59db489aVikas Arora bool mIsClosed = false; 1087c8da7ce66017295a65ec028084b90800be377f8James Zern bool mClosedByApp = false; 1099aea642eefa7a641ab8b89d953251939221d2719Eric Hassold Mutex mSessionLock; 1109aea642eefa7a641ab8b89d953251939221d2719Eric Hassold}; 1119aea642eefa7a641ab8b89d953251939221d2719Eric Hassold 1129aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#endif // _ACAMERA_CAPTURE_SESSION_H 1139aea642eefa7a641ab8b89d953251939221d2719Eric Hassold