blob: 4c67ac72ccbc4b48080ef0e415738b77f1de8512 [file] [log] [blame]
Avichal Rakeshfcb78cb2022-10-27 15:45:54 -07001/*
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 FRAMEWORKS_AV_SERVICES_CAMERA_LIBCAMERASERVICE_AIDL_AIDLCAMERASERVICE_H_
18#define FRAMEWORKS_AV_SERVICES_CAMERA_LIBCAMERASERVICE_AIDL_AIDLCAMERASERVICE_H_
19
20#include <CameraService.h>
21#include <aidl/android/frameworks/cameraservice/common/Status.h>
22#include <aidl/android/frameworks/cameraservice/service/BnCameraService.h>
23
24namespace android::frameworks::cameraservice::service::implementation {
25
26// VNDK classes
27using SBnCameraService = ::aidl::android::frameworks::cameraservice::service::BnCameraService;
28using SCameraMetadata = ::aidl::android::frameworks::cameraservice::device::CameraMetadata;
29using SCameraStatusAndId = ::aidl::android::frameworks::cameraservice::service::CameraStatusAndId;
30using SICameraDeviceCallback =
31 ::aidl::android::frameworks::cameraservice::device::ICameraDeviceCallback;
32using SICameraDeviceUser = ::aidl::android::frameworks::cameraservice::device::ICameraDeviceUser;
33using SICameraServiceListener =
34 ::aidl::android::frameworks::cameraservice::service::ICameraServiceListener;
35using SProviderIdAndVendorTagSections =
36 ::aidl::android::frameworks::cameraservice::common::ProviderIdAndVendorTagSections;
37using SStatus = ::aidl::android::frameworks::cameraservice::common::Status;
38// NDK classes
39using UICameraServiceListener = ::android::hardware::ICameraServiceListener;
40
41class AidlCameraService: public SBnCameraService {
42 public:
43 static bool registerService(::android::CameraService* cameraService);
44
45 explicit AidlCameraService(::android::CameraService* cameraService);
46 ~AidlCameraService() override = default;
47 ndk::ScopedAStatus getCameraCharacteristics(const std::string& in_cameraId,
48 SCameraMetadata* _aidl_return) override;
49
50 ndk::ScopedAStatus connectDevice(const std::shared_ptr<SICameraDeviceCallback>& in_callback,
51 const std::string& in_cameraId,
52 std::shared_ptr<SICameraDeviceUser>* _aidl_return) override;
53
54 ndk::ScopedAStatus addListener(const std::shared_ptr<SICameraServiceListener>& in_listener,
55 std::vector<SCameraStatusAndId>* _aidl_return) override;
56
57 ndk::ScopedAStatus getCameraVendorTagSections(
58 std::vector<SProviderIdAndVendorTagSections>* _aidl_return) override;
59
60 ndk::ScopedAStatus removeListener(
61 const std::shared_ptr<SICameraServiceListener>& in_listener) override;
62
63 private:
64 void addToListenerCacheLocked(std::shared_ptr<SICameraServiceListener> stableCsListener,
65 sp<hardware::ICameraServiceListener> csListener);
66
67 sp<UICameraServiceListener> searchListenerCacheLocked(
68 const std::shared_ptr<SICameraServiceListener>& listener, bool removeIfFound = false);
69
70 SStatus addListenerInternal(const std::shared_ptr<SICameraServiceListener>& listener,
71 std::vector<hardware::CameraStatus>* cameraStatusAndIds);
72
73
74 ::android::CameraService* mCameraService;
75
76 Mutex mListenerListLock;
77 std::list<std::pair<std::shared_ptr<SICameraServiceListener>,
78 sp<UICameraServiceListener>>> mListeners;
79 int mVndkVersion = -1;
80
81};
82
83} // namespace android::frameworks::cameraservice::service::implementation
84
85#endif // FRAMEWORKS_AV_SERVICES_CAMERA_LIBCAMERASERVICE_AIDL_AIDLCAMERASERVICE_H_