Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
QtVideoDeviceManager.java
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4package org.qtproject.qt.android.multimedia;
5
6import android.annotation.TargetApi;
7import android.content.Context;
8import android.graphics.ImageFormat;
9import android.graphics.Rect;
10import android.hardware.camera2.CameraCharacteristics;
11import android.hardware.camera2.CameraManager;
12import android.hardware.camera2.CaptureRequest;
13import android.hardware.camera2.params.StreamConfigurationMap;
14import android.util.Range;
15import android.util.Size;
16import android.util.Log;
17
18import java.lang.String;
19import java.util.ArrayList;
20import java.util.Map;
21import java.util.WeakHashMap;
22
24
25 CameraManager mCameraManager;
26 Map<String, CameraCharacteristics> cache;
27
28 public QtVideoDeviceManager(Context context) {
29 mCameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
30 cache = new WeakHashMap<String, CameraCharacteristics>();
31 }
32
33 public CameraCharacteristics getCameraCharacteristics(String cameraId) {
34
35 if (cache.containsKey(cameraId))
36 return cache.get(cameraId);
37
38 try {
39 CameraCharacteristics cameraCharacteristics = mCameraManager.getCameraCharacteristics(cameraId);
40 cache.put(cameraId, cameraCharacteristics);
41 return cameraCharacteristics;
42 } catch (Exception e) {
43 e.printStackTrace();
44 }
45 return null;
46 }
47
48 public String[] getCameraIdList() {
49 try {
50 return mCameraManager.getCameraIdList();
51 } catch (Exception e) {
52 e.printStackTrace();
53 }
54 return null;
55 }
56
57 public int getSensorOrientation(String cameraId) {
58 CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
59 if (characteristics == null)
60 return 0;
61 return characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
62 }
63
64 public int getLensFacing(String cameraId) {
65 CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
66 if (characteristics == null)
67 return 0;
68 return characteristics.get(CameraCharacteristics.LENS_FACING);
69 }
70
71 public String[] getFpsRange(String cameraId) {
72
73 CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
74 if (characteristics == null)
75 return new String[0];
76
77 Range<Integer>[] ranges = characteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
78
79 String[] fps = new String[ranges.length];
80
81 for (int index = 0; index < ranges.length; index++) {
82 fps[index] = ranges[index].toString();
83 }
84
85 return fps;
86 }
87
88 public float getMaxZoom(String cameraId) {
89
90 float maxZoom = 1.0f;
91 final CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
92 if (characteristics != null)
93 maxZoom = characteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM);
94 return maxZoom;
95 }
96
97 public Rect getActiveArraySize(String cameraId) {
98 Rect activeArraySize = new Rect();
99 final CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
100 if (characteristics != null)
101 activeArraySize = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
102 return activeArraySize;
103 }
104
105 public String[] getStreamConfigurationsSizes(String cameraId, int imageFormat) {
106
107 CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
108 if (characteristics == null)
109 return new String[0];
110
111 StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
112 Size[] sizes = map.getOutputSizes(imageFormat);
113
114 String[] stream = new String[sizes.length];
115
116 for (int index = 0; index < sizes.length; index++) {
117 stream[index] = sizes[index].toString();
118 }
119
120 return stream;
121 }
122
123 public int stringToControlAEMode(String mode) {
124 switch (mode) {
125 case "off":
126 return CaptureRequest.CONTROL_AE_MODE_ON;
127 case "auto":
128 return CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH;
129 case "on":
130 return CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH;
131 case "redeye":
132 return CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH_REDEYE;
133 case "external":
134 return CaptureRequest.CONTROL_AE_MODE_ON_EXTERNAL_FLASH;
135 default:
136 return -1;
137 }
138 }
139
140 public String controlAEModeToString(int mode) {
141 switch (mode) {
142 case CaptureRequest.CONTROL_AE_MODE_ON:
143 return "off";
144 case CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH:
145 return "auto";
146 case CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH:
147 return "on";
148 case CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH_REDEYE:
149 return "redeye";
150 case CaptureRequest.CONTROL_AE_MODE_ON_EXTERNAL_FLASH:
151 return "external";
152 case CaptureRequest.CONTROL_AE_MODE_OFF:
153 default:
154 return "unknown";
155 }
156 }
157
158 public String[] getSupportedFlashModes(String cameraId) {
159
160 CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
161 if (characteristics == null)
162 return new String[0];
163
164 int supportedFlashModes[] = characteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_MODES);
165 ArrayList<String> supportedFlashModesList = new ArrayList<String>();
166 for (int index = 0; index < supportedFlashModes.length; index++) {
167 supportedFlashModesList.add(controlAEModeToString(supportedFlashModes[index]));
168 }
169
170 String[] ret = new String[ supportedFlashModesList.size() ];
171 return supportedFlashModesList.toArray(ret);
172 }
173
174 public boolean isTorchModeSupported(String cameraId) {
175 boolean ret = false;
176 final CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
177 if (characteristics != null)
178 ret = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
179 return ret;
180 }
181}
String[] getStreamConfigurationsSizes(String cameraId, int imageFormat)
CameraCharacteristics getCameraCharacteristics(String cameraId)
QMap< QString, QString > map
[6]
double e
QCache< int, Employee > cache
[0]
static void * context
EGLStreamKHR stream
#define Size(name)
return ret
GLenum mode
GLuint index
[2]
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes