• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 
17 #ifndef ANDROID_SERVERS_AIDL_CAMERA3OFFLINESESSION_H
18 #define ANDROID_SERVERS_AIDL_CAMERA3OFFLINESESSION_H
19 
20 #include <memory>
21 #include <mutex>
22 
23 #include <utils/String16.h>
24 
25 #include "AidlCamera3OutputUtils.h"
26 #include <aidl/android/hardware/camera/device/BnCameraDeviceCallback.h>
27 #include <aidl/android/hardware/camera/device/ICameraOfflineSession.h>
28 
29 #include <fmq/AidlMessageQueue.h>
30 
31 #include "common/CameraOfflineSessionBase.h"
32 
33 #include "device3/Camera3BufferManager.h"
34 #include "device3/Camera3OfflineSession.h"
35 #include "utils/TagMonitor.h"
36 #include <camera_metadata_hidden.h>
37 
38 namespace android {
39 
40 namespace camera3 {
41 
42 class Camera3Stream;
43 class Camera3OutputStreamInterface;
44 class Camera3StreamInterface;
45 
46 } // namespace camera3
47 
48 /**
49  * AidlCamera3OfflineSession for offline session defined in AIDL ICameraOfflineSession
50  */
51 class AidlCamera3OfflineSession :
52             public Camera3OfflineSession {
53   public:
54 
55     virtual ~AidlCamera3OfflineSession();
56 
57     virtual status_t initialize(wp<NotificationListener> listener) override;
58 
59     /**
60      * Implementation of aidl::android::hardware::camera::device::ICameraDeviceCallback
61      */
62     ::ndk::ScopedAStatus processCaptureResult(
63             const std::vector<aidl::android::hardware::camera::device::CaptureResult>& results);
64     ::ndk::ScopedAStatus notify(
65             const std::vector<aidl::android::hardware::camera::device::NotifyMsg>& msgs);
66     ::ndk::ScopedAStatus requestStreamBuffers(
67             const std::vector<aidl::android::hardware::camera::device::BufferRequest>& bufReqs,
68             std::vector<aidl::android::hardware::camera::device::StreamBufferRet>* outBuffers,
69             aidl::android::hardware::camera::device::BufferRequestStatus* status);
70 
71     ::ndk::ScopedAStatus returnStreamBuffers(
72             const std::vector<aidl::android::hardware::camera::device::StreamBuffer>& buffers);
73 
74     // See explanation for why we need a separate class for this in
75     // AidlCamera3Device::AidlCameraDeviceCallbacks in AidlCamera3Device.h
76     class AidlCameraDeviceCallbacks :
77             public aidl::android::hardware::camera::device::BnCameraDeviceCallback {
78       public:
79 
AidlCameraDeviceCallbacks(wp<AidlCamera3OfflineSession> parent)80         AidlCameraDeviceCallbacks(wp<AidlCamera3OfflineSession> parent) : mParent(parent)  { }
~AidlCameraDeviceCallbacks()81         ~AidlCameraDeviceCallbacks() {}
82         ::ndk::ScopedAStatus processCaptureResult(
83                 const std::vector<
84                         aidl::android::hardware::camera::device::CaptureResult>& results) override;
85         ::ndk::ScopedAStatus notify(
86                 const std::vector<
87                         aidl::android::hardware::camera::device::NotifyMsg>& msgs) override;
88 
89         ::ndk::ScopedAStatus requestStreamBuffers(
90                 const std::vector<
91                         aidl::android::hardware::camera::device::BufferRequest>& bufReqs,
92                 std::vector<aidl::android::hardware::camera::device::StreamBufferRet>* out_buffers,
93                 aidl::android::hardware::camera::device::BufferRequestStatus* _aidl_return
94                 ) override;
95 
96         ::ndk::ScopedAStatus returnStreamBuffers(
97                 const std::vector<
98                         aidl::android::hardware::camera::device::StreamBuffer>& buffers) override;
99         protected:
100 
101         ::ndk::SpAIBinder createBinder() override;
102 
103         private:
104             wp<AidlCamera3OfflineSession> mParent = nullptr;
105     };
106 
107     // initialize by Camera3Device.
AidlCamera3OfflineSession(const std::string & id,const sp<camera3::Camera3Stream> & inputStream,const camera3::StreamSet & offlineStreamSet,camera3::BufferRecords && bufferRecords,const camera3::InFlightRequestMap & offlineReqs,const Camera3OfflineStates & offlineStates,std::shared_ptr<aidl::android::hardware::camera::device::ICameraOfflineSession> offlineSession,bool sensorReadoutTimestampSupported)108     explicit AidlCamera3OfflineSession(
109             const std::string& id, const sp<camera3::Camera3Stream>& inputStream,
110             const camera3::StreamSet& offlineStreamSet, camera3::BufferRecords&& bufferRecords,
111             const camera3::InFlightRequestMap& offlineReqs,
112             const Camera3OfflineStates& offlineStates,
113             std::shared_ptr<aidl::android::hardware::camera::device::ICameraOfflineSession>
114                     offlineSession,
115             bool sensorReadoutTimestampSupported)
116         : Camera3OfflineSession(id, inputStream, offlineStreamSet, std::move(bufferRecords),
117                                 offlineReqs, offlineStates),
118           mSession(offlineSession),
119           mSensorReadoutTimestampSupported(sensorReadoutTimestampSupported) {
120             mCallbacks = ndk::SharedRefBase::make<AidlCameraDeviceCallbacks>(this);
121     };
122 
123     /**
124      * End of CameraOfflineSessionBase interface
125      */
126 
127   private:
128     std::shared_ptr<aidl::android::hardware::camera::device::ICameraOfflineSession> mSession;
129     // FMQ to write result on. Must be guarded by mProcessCaptureResultLock.
130     std::unique_ptr<AidlResultMetadataQueue> mResultMetadataQueue;
131 
132     std::shared_ptr<AidlCameraDeviceCallbacks> mCallbacks;
133 
134     bool mSensorReadoutTimestampSupported;
135 
136     virtual void closeSessionLocked() override;
137 
138     virtual void releaseSessionLocked() override;
139 
140 }; // class AidlCamera3OfflineSession
141 
142 }; // namespace android
143 
144 #endif
145