• 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 CAMERA_NDK_VENDOR_UTILS_H
18 #define CAMERA_NDK_VENDOR_UTILS_H
19 
20 #include <CameraMetadata.h>
21 #include <aidl/android/frameworks/cameraservice/common/Status.h>
22 #include <aidl/android/frameworks/cameraservice/device/CameraMetadata.h>
23 #include <aidl/android/frameworks/cameraservice/device/CaptureRequest.h>
24 #include <aidl/android/frameworks/cameraservice/device/ICameraDeviceUser.h>
25 #include <aidl/android/frameworks/cameraservice/device/OutputConfiguration.h>
26 #include <aidl/android/frameworks/cameraservice/device/PhysicalCameraSettings.h>
27 #include <aidl/android/frameworks/cameraservice/device/TemplateId.h>
28 #include <aidl/android/frameworks/cameraservice/service/ICameraService.h>
29 #include <camera/NdkCameraDevice.h>
30 #include <hardware/camera3.h>
31 #include <utils/RefBase.h>
32 
33 namespace android {
34 namespace acam {
35 namespace utils {
36 
37 using ::aidl::android::frameworks::cameraservice::common::Status;
38 using ::aidl::android::frameworks::cameraservice::device::OutputConfiguration;
39 using ::aidl::android::frameworks::cameraservice::device::PhysicalCameraSettings;
40 using ::aidl::android::frameworks::cameraservice::device::TemplateId;
41 using ::aidl::android::hardware::common::NativeHandle;
42 using ::android::hardware::camera::common::V1_0::helper::CameraMetadata;
43 using AidlCameraMetadata = ::aidl::android::frameworks::cameraservice::device::CameraMetadata;
44 using AidlCaptureRequest = ::aidl::android::frameworks::cameraservice::device::CaptureRequest;
45 
46 bool isWindowNativeHandleEqual(const native_handle_t *nh1, const native_handle_t *nh2);
47 
48 bool isWindowNativeHandleEqual(const native_handle_t* nh1, const NativeHandle& nh2);
49 
50 bool isWindowNativeHandleLessThan(const native_handle_t *nh1, const native_handle_t *nh2);
51 
52 // Convenience wrapper over isWindowNativeHandleLessThan and isWindowNativeHandleEqual
53 bool isWindowNativeHandleGreaterThan(const native_handle_t *nh1, const native_handle_t *nh2);
54 
55 // Utility class so the native_handle_t can be compared with  its contents instead
56 // of just raw pointer comparisons.
57 struct native_handle_ptr_wrapper {
58     const native_handle_t *mWindow = nullptr;
59 
native_handle_ptr_wrappernative_handle_ptr_wrapper60     native_handle_ptr_wrapper(const native_handle_t *nh) : mWindow(nh) { }
61 
62     native_handle_ptr_wrapper() = default;
63 
64     operator const native_handle_t *() const { return mWindow; }
65 
66     bool operator ==(const native_handle_ptr_wrapper other) const {
67         return isWindowNativeHandleEqual(mWindow, other.mWindow);
68     }
69 
70     bool operator != (const native_handle_ptr_wrapper& other) const {
71         return !isWindowNativeHandleEqual(mWindow, other.mWindow);
72     }
73 
74     bool operator < (const native_handle_ptr_wrapper& other) const {
75         return isWindowNativeHandleLessThan(mWindow, other.mWindow);
76     }
77 
78     bool operator > (const native_handle_ptr_wrapper& other) const {
79         return !isWindowNativeHandleGreaterThan(mWindow, other.mWindow);
80     }
81 
82 };
83 
84 // Utility class so that CaptureRequest can be stored by sp<>
85 struct CaptureRequest: public RefBase {
86   AidlCaptureRequest mCaptureRequest;
87   std::vector<native_handle_ptr_wrapper> mSurfaceList;
88   // Physical camera settings metadata is stored here, as the capture request
89   // might not contain it. That's since, fmq might have consumed it.
90   std::vector<PhysicalCameraSettings> mPhysicalCameraSettings;
91 };
92 
93 AidlCaptureRequest convertToAidl(const CaptureRequest *captureRequest);
94 
95 OutputConfiguration::Rotation convertToAidl(int rotation);
96 
97 bool cloneFromAidl(const AidlCameraMetadata & srcMetadata, camera_metadata_t** dst);
98 
99 // Note: existing data in dst will be gone.
100 void convertToAidl(const camera_metadata_t *src, AidlCameraMetadata * dst);
101 
102 TemplateId convertToAidl(ACameraDevice_request_template templateId);
103 
104 camera_status_t convertFromAidl(Status status);
105 
106 } // namespace utils
107 } // namespace acam
108 } // namespace android
109 
110 #endif // CAMERA_NDK_VENDOR_UTILS_H
111