• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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_FRAMEWORKS_CAMERASERVICE_V2_0_CAMERASERVICE_H
18 #define ANDROID_FRAMEWORKS_CAMERASERVICE_V2_0_CAMERASERVICE_H
19 
20 #include <mutex>
21 #include <thread>
22 
23 #include <android/frameworks/cameraservice/common/2.0/types.h>
24 #include <android/frameworks/cameraservice/service/2.0/ICameraService.h>
25 #include <android/frameworks/cameraservice/service/2.0/types.h>
26 #include <android/frameworks/cameraservice/device/2.0/types.h>
27 
28 #include <hidl/Status.h>
29 
30 #include <CameraService.h>
31 
32 namespace android {
33 namespace frameworks {
34 namespace cameraservice {
35 namespace service {
36 namespace V2_0 {
37 namespace implementation {
38 
39 using hardware::hidl_string;
40 using hardware::ICameraServiceListener;
41 using hardware::Return;
42 
43 using HCameraDeviceCallback = frameworks::cameraservice::device::V2_0::ICameraDeviceCallback;
44 using HCameraMetadata = frameworks::cameraservice::service::V2_0::CameraMetadata;
45 using HCameraService = frameworks::cameraservice::service::V2_0::ICameraService;
46 using HCameraServiceListener = frameworks::cameraservice::service::V2_0::ICameraServiceListener;
47 using HStatus = frameworks::cameraservice::common::V2_0::Status;
48 using HCameraStatusAndId = frameworks::cameraservice::service::V2_0::CameraStatusAndId;
49 
50 struct HidlCameraService final : public HCameraService {
51 
~HidlCameraServicefinal52     ~HidlCameraService() { };
53 
54     // Methods from ::android::frameworks::cameraservice::service::V2.0::ICameraService follow.
55 
56     Return<void> connectDevice(const sp<HCameraDeviceCallback>& callback,
57                                const hidl_string& cameraId, connectDevice_cb _hidl_cb) override;
58 
59     Return<void> addListener(const sp<HCameraServiceListener>& listener,
60                              addListener_cb _hidl_cb) override;
61 
62     Return<HStatus> removeListener(const sp<HCameraServiceListener>& listener) override;
63 
64     Return<void> getCameraCharacteristics(const hidl_string& cameraId,
65                                           getCameraCharacteristics_cb _hidl_cb) override;
66 
67     Return<void> getCameraVendorTagSections(getCameraVendorTagSections_cb _hidl_cb) override;
68 
69     // This method should only be called by the cameraservers main thread to
70     // instantiate the hidl cameraserver.
71     static sp<HidlCameraService> getInstance(android::CameraService *cs);
72 
73 private:
HidlCameraServicefinal74     HidlCameraService(android::CameraService *cs) : mAidlICameraService(cs) { };
75 
76     sp<hardware::ICameraServiceListener> searchListenerCacheLocked(
77         sp<HCameraServiceListener> listener, /*removeIfFound*/ bool shouldRemove = false);
78 
79     void addToListenerCacheLocked(sp<HCameraServiceListener> hListener,
80                                   sp<hardware::ICameraServiceListener> csListener);
81 
82     android::CameraService *const mAidlICameraService = nullptr;
83 
84     Mutex mListenerListLock;
85 
86     using HIListeners =
87         std::pair<sp<HCameraServiceListener>, sp<ICameraServiceListener>>;
88     std::list<HIListeners> mListeners;
89 };
90 
91 }  // namespace implementation
92 }  // namespace V2_0
93 }  // namespace service
94 }  // namespace cameraservice
95 }  // namespace frameworks
96 }  // namespace android
97 
98 #endif  // ANDROID_FRAMEWORKS_CAMERASERVICE_V2_0_CAMERASERVICE_H
99