blob: 839c435354dfeb2f6e5109224b02a6b85d80ba98 [file] [log] [blame]
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001/*
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 Peevd99c8ae2019-11-26 13:19:13 -080022#include "common/FrameProcessorBase.h"
23#include "common/CameraDeviceBase.h"
Yin-Chia Yehb978c382019-10-30 00:22:37 -070024#include "CameraService.h"
Emilian Peev4697b642019-11-19 17:11:14 -080025#include "CompositeStream.h"
Yin-Chia Yehb978c382019-10-30 00:22:37 -070026
27namespace android {
28
29using android::hardware::camera2::ICameraDeviceCallbacks;
Emilian Peev4697b642019-11-19 17:11:14 -080030using camera3::CompositeStream;
Yin-Chia Yehb978c382019-10-30 00:22:37 -070031
Emilian Peevb2bc5a42019-11-20 16:02:14 -080032// 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 Yehb978c382019-10-30 00:22:37 -070038class CameraOfflineSessionClient :
Emilian Peevb2bc5a42019-11-20 16:02:14 -080039 public CameraService::BasicClient,
Emilian Peevd99c8ae2019-11-26 13:19:13 -080040 public hardware::camera2::BnCameraOfflineSession,
41 public camera2::FrameProcessorBase::FilteredListener,
42 public NotificationListener
Yin-Chia Yehb978c382019-10-30 00:22:37 -070043{
44public:
45 CameraOfflineSessionClient(
46 const sp<CameraService>& cameraService,
47 sp<CameraOfflineSessionBase> session,
Emilian Peev4697b642019-11-19 17:11:14 -080048 const KeyedVector<sp<IBinder>, sp<CompositeStream>>& offlineCompositeStreamMap,
Yin-Chia Yehb978c382019-10-30 00:22:37 -070049 const sp<ICameraDeviceCallbacks>& remoteCallback,
50 const String16& clientPackageName,
Jooyung Han3f9a3b42020-01-23 12:27:18 +090051 const std::optional<String16>& clientFeatureId,
Emilian Peevb2bc5a42019-11-20 16:02:14 -080052 const String8& cameraIdStr, int cameraFacing,
Yin-Chia Yehb978c382019-10-30 00:22:37 -070053 int clientPid, uid_t clientUid, int servicePid) :
Emilian Peevb2bc5a42019-11-20 16:02:14 -080054 CameraService::BasicClient(
55 cameraService,
56 IInterface::asBinder(remoteCallback),
57 clientPackageName, clientFeatureId,
58 cameraIdStr, cameraFacing, clientPid, clientUid, servicePid),
Emilian Peev4697b642019-11-19 17:11:14 -080059 mRemoteCallback(remoteCallback), mOfflineSession(session),
60 mCompositeStreamMap(offlineCompositeStreamMap) {}
Yin-Chia Yehb978c382019-10-30 00:22:37 -070061
Emilian Peevb2bc5a42019-11-20 16:02:14 -080062 virtual ~CameraOfflineSessionClient() {}
Yin-Chia Yehb978c382019-10-30 00:22:37 -070063
Emilian Peevd99c8ae2019-11-26 13:19:13 -080064 sp<IBinder> asBinderWrapper() override {
Emilian Peevb2bc5a42019-11-20 16:02:14 -080065 return IInterface::asBinder(this);
Yin-Chia Yehb978c382019-10-30 00:22:37 -070066 }
67
Emilian Peevd99c8ae2019-11-26 13:19:13 -080068 binder::Status disconnect() override;
Yin-Chia Yehb978c382019-10-30 00:22:37 -070069
Emilian Peevd99c8ae2019-11-26 13:19:13 -080070 status_t dump(int /*fd*/, const Vector<String16>& /*args*/) override;
Yin-Chia Yehb978c382019-10-30 00:22:37 -070071
Emilian Peevd99c8ae2019-11-26 13:19:13 -080072 status_t dumpClient(int /*fd*/, const Vector<String16>& /*args*/) override;
Emilian Peevb2bc5a42019-11-20 16:02:14 -080073
Emilian Peevd99c8ae2019-11-26 13:19:13 -080074 status_t initialize(sp<CameraProviderManager> /*manager*/,
Emilian Peevb2bc5a42019-11-20 16:02:14 -080075 const String8& /*monitorTags*/) override;
Yin-Chia Yehb978c382019-10-30 00:22:37 -070076
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -080077 status_t setRotateAndCropOverride(uint8_t rotateAndCrop) override;
78
Emilian Peevb2bc5a42019-11-20 16:02:14 -080079 // permissions management
Emilian Peevd99c8ae2019-11-26 13:19:13 -080080 status_t startCameraOps() override;
81 status_t finishCameraOps() override;
Yin-Chia Yehb978c382019-10-30 00:22:37 -070082
Emilian Peevd99c8ae2019-11-26 13:19:13 -080083 // 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;
Shuzhen Wang316781a2020-08-18 18:11:01 -070089 void notifyIdle(int64_t requestCount, int64_t resultErrorCount, bool deviceError,
90 const std::vector<hardware::CameraStreamStats>& streamStats) override;
Emilian Peevd99c8ae2019-11-26 13:19:13 -080091 void notifyAutoFocus(uint8_t newState, int triggerId) override;
92 void notifyAutoExposure(uint8_t newState, int triggerId) override;
93 void notifyAutoWhitebalance(uint8_t newState, int triggerId) override;
94 void notifyPrepared(int streamId) override;
95 void notifyRequestQueueEmpty() override;
96 void notifyRepeatingRequestError(long lastFrameNumber) override;
Emilian Peev4697b642019-11-19 17:11:14 -080097
Yin-Chia Yehb978c382019-10-30 00:22:37 -070098private:
Emilian Peevd99c8ae2019-11-26 13:19:13 -080099 mutable Mutex mBinderSerializationLock;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700100
101 sp<hardware::camera2::ICameraDeviceCallbacks> mRemoteCallback;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700102
103 sp<CameraOfflineSessionBase> mOfflineSession;
Emilian Peev4697b642019-11-19 17:11:14 -0800104
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800105 sp<camera2::FrameProcessorBase> mFrameProcessor;
106
Emilian Peevd99c8ae2019-11-26 13:19:13 -0800107 // Offline composite stream map, output surface -> composite stream
Emilian Peev4697b642019-11-19 17:11:14 -0800108 KeyedVector<sp<IBinder>, sp<CompositeStream>> mCompositeStreamMap;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700109};
110
111} // namespace android
112
113#endif // ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERAOFFLINESESSIONCLIENT_H