| Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2019 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_CAMERA_PHOTOGRAPHY_CAMERAOFFLINESESSIONCLIENT_H | 
|  | 18 | #define ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERAOFFLINESESSIONCLIENT_H | 
|  | 19 |  | 
|  | 20 | #include <android/hardware/camera2/BnCameraOfflineSession.h> | 
|  | 21 | #include <android/hardware/camera2/ICameraDeviceCallbacks.h> | 
| Emilian Peev | d99c8ae | 2019-11-26 13:19:13 -0800 | [diff] [blame] | 22 | #include "common/FrameProcessorBase.h" | 
|  | 23 | #include "common/CameraDeviceBase.h" | 
| Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 24 | #include "CameraService.h" | 
| Emilian Peev | 4697b64 | 2019-11-19 17:11:14 -0800 | [diff] [blame] | 25 | #include "CompositeStream.h" | 
| Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 26 |  | 
|  | 27 | namespace android { | 
|  | 28 |  | 
|  | 29 | using android::hardware::camera2::ICameraDeviceCallbacks; | 
| Emilian Peev | 4697b64 | 2019-11-19 17:11:14 -0800 | [diff] [blame] | 30 | using camera3::CompositeStream; | 
| Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 31 |  | 
| Emilian Peev | b2bc5a4 | 2019-11-20 16:02:14 -0800 | [diff] [blame] | 32 | // Client for offline session. Note that offline session client does not affect camera service's | 
|  | 33 | // client arbitration logic. It is camera HAL's decision to decide whether a normal camera | 
|  | 34 | // client is conflicting with existing offline client(s). | 
|  | 35 | // The other distinctive difference between offline clients and normal clients is that normal | 
|  | 36 | // clients are created through ICameraService binder calls, while the offline session client | 
|  | 37 | // is created through ICameraDeviceUser::switchToOffline call. | 
| Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 38 | class CameraOfflineSessionClient : | 
| Emilian Peev | b2bc5a4 | 2019-11-20 16:02:14 -0800 | [diff] [blame] | 39 | public CameraService::BasicClient, | 
| Emilian Peev | d99c8ae | 2019-11-26 13:19:13 -0800 | [diff] [blame] | 40 | public hardware::camera2::BnCameraOfflineSession, | 
|  | 41 | public camera2::FrameProcessorBase::FilteredListener, | 
|  | 42 | public NotificationListener | 
| Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 43 | { | 
|  | 44 | public: | 
|  | 45 | CameraOfflineSessionClient( | 
|  | 46 | const sp<CameraService>& cameraService, | 
|  | 47 | sp<CameraOfflineSessionBase> session, | 
| Emilian Peev | 4697b64 | 2019-11-19 17:11:14 -0800 | [diff] [blame] | 48 | const KeyedVector<sp<IBinder>, sp<CompositeStream>>& offlineCompositeStreamMap, | 
| Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 49 | const sp<ICameraDeviceCallbacks>& remoteCallback, | 
|  | 50 | const String16& clientPackageName, | 
| Jooyung Han | b3f7cd2 | 2020-01-23 12:27:18 +0900 | [diff] [blame] | 51 | const std::optional<String16>& clientFeatureId, | 
| Emilian Peev | b2bc5a4 | 2019-11-20 16:02:14 -0800 | [diff] [blame] | 52 | const String8& cameraIdStr, int cameraFacing, | 
| Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 53 | int clientPid, uid_t clientUid, int servicePid) : | 
| Emilian Peev | b2bc5a4 | 2019-11-20 16:02:14 -0800 | [diff] [blame] | 54 | CameraService::BasicClient( | 
|  | 55 | cameraService, | 
|  | 56 | IInterface::asBinder(remoteCallback), | 
|  | 57 | clientPackageName, clientFeatureId, | 
|  | 58 | cameraIdStr, cameraFacing, clientPid, clientUid, servicePid), | 
| Emilian Peev | 4697b64 | 2019-11-19 17:11:14 -0800 | [diff] [blame] | 59 | mRemoteCallback(remoteCallback), mOfflineSession(session), | 
|  | 60 | mCompositeStreamMap(offlineCompositeStreamMap) {} | 
| Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 61 |  | 
| Emilian Peev | b2bc5a4 | 2019-11-20 16:02:14 -0800 | [diff] [blame] | 62 | virtual ~CameraOfflineSessionClient() {} | 
| Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 63 |  | 
| Emilian Peev | d99c8ae | 2019-11-26 13:19:13 -0800 | [diff] [blame] | 64 | sp<IBinder> asBinderWrapper() override { | 
| Emilian Peev | b2bc5a4 | 2019-11-20 16:02:14 -0800 | [diff] [blame] | 65 | return IInterface::asBinder(this); | 
| Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 66 | } | 
|  | 67 |  | 
| Emilian Peev | d99c8ae | 2019-11-26 13:19:13 -0800 | [diff] [blame] | 68 | binder::Status disconnect() override; | 
| Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 69 |  | 
| Emilian Peev | d99c8ae | 2019-11-26 13:19:13 -0800 | [diff] [blame] | 70 | status_t dump(int /*fd*/, const Vector<String16>& /*args*/) override; | 
| Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 71 |  | 
| Emilian Peev | d99c8ae | 2019-11-26 13:19:13 -0800 | [diff] [blame] | 72 | status_t dumpClient(int /*fd*/, const Vector<String16>& /*args*/) override; | 
| Emilian Peev | b2bc5a4 | 2019-11-20 16:02:14 -0800 | [diff] [blame] | 73 |  | 
| Emilian Peev | d99c8ae | 2019-11-26 13:19:13 -0800 | [diff] [blame] | 74 | status_t initialize(sp<CameraProviderManager> /*manager*/, | 
| Emilian Peev | b2bc5a4 | 2019-11-20 16:02:14 -0800 | [diff] [blame] | 75 | const String8& /*monitorTags*/) override; | 
| Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 76 |  | 
| Eino-Ville Talvala | f2e3709 | 2020-01-07 15:32:32 -0800 | [diff] [blame] | 77 | status_t setRotateAndCropOverride(uint8_t rotateAndCrop) override; | 
|  | 78 |  | 
| Emilian Peev | b2bc5a4 | 2019-11-20 16:02:14 -0800 | [diff] [blame] | 79 | // permissions management | 
| Emilian Peev | d99c8ae | 2019-11-26 13:19:13 -0800 | [diff] [blame] | 80 | status_t startCameraOps() override; | 
|  | 81 | status_t finishCameraOps() override; | 
| Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 82 |  | 
| Emilian Peev | d99c8ae | 2019-11-26 13:19:13 -0800 | [diff] [blame] | 83 | // FilteredResultListener API | 
|  | 84 | void onResultAvailable(const CaptureResult& result) override; | 
|  | 85 |  | 
|  | 86 | // NotificationListener API | 
|  | 87 | void notifyError(int32_t errorCode, const CaptureResultExtras& resultExtras) override; | 
|  | 88 | void notifyShutter(const CaptureResultExtras& resultExtras, nsecs_t timestamp) override; | 
|  | 89 | void notifyIdle() override; | 
|  | 90 | void notifyAutoFocus(uint8_t newState, int triggerId) override; | 
|  | 91 | void notifyAutoExposure(uint8_t newState, int triggerId) override; | 
|  | 92 | void notifyAutoWhitebalance(uint8_t newState, int triggerId) override; | 
|  | 93 | void notifyPrepared(int streamId) override; | 
|  | 94 | void notifyRequestQueueEmpty() override; | 
|  | 95 | void notifyRepeatingRequestError(long lastFrameNumber) override; | 
| Emilian Peev | 4697b64 | 2019-11-19 17:11:14 -0800 | [diff] [blame] | 96 |  | 
| Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 97 | private: | 
| Emilian Peev | d99c8ae | 2019-11-26 13:19:13 -0800 | [diff] [blame] | 98 | mutable Mutex mBinderSerializationLock; | 
| Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 99 |  | 
|  | 100 | sp<hardware::camera2::ICameraDeviceCallbacks> mRemoteCallback; | 
| Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 101 |  | 
|  | 102 | sp<CameraOfflineSessionBase> mOfflineSession; | 
| Emilian Peev | 4697b64 | 2019-11-19 17:11:14 -0800 | [diff] [blame] | 103 |  | 
| Emilian Peev | faa4bde | 2020-01-23 12:19:37 -0800 | [diff] [blame] | 104 | sp<camera2::FrameProcessorBase> mFrameProcessor; | 
|  | 105 |  | 
| Emilian Peev | d99c8ae | 2019-11-26 13:19:13 -0800 | [diff] [blame] | 106 | // Offline composite stream map, output surface -> composite stream | 
| Emilian Peev | 4697b64 | 2019-11-19 17:11:14 -0800 | [diff] [blame] | 107 | KeyedVector<sp<IBinder>, sp<CompositeStream>> mCompositeStreamMap; | 
| Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 108 | }; | 
|  | 109 |  | 
|  | 110 | } // namespace android | 
|  | 111 |  | 
|  | 112 | #endif // ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERAOFFLINESESSIONCLIENT_H |