deviceMap = mUsbManager.getDeviceList();
140 | if (deviceMap != null) {
141 | for (UsbDevice usbDevice : deviceMap.values()) {
142 | if (isUsbCamera(usbDevice)) {
143 | return usbDevice;
144 | }
145 | }
146 | }
147 | return null;
148 | }
149 |
150 | /**
151 | * 判断某usb设备是否摄像头,usb摄像头的大小类是239-2
152 | *
153 | * @param usbDevice
154 | * @return
155 | */
156 | public boolean isUsbCamera(UsbDevice usbDevice) {
157 | return usbDevice != null && 239 == usbDevice.getDeviceClass() && 2 == usbDevice.getDeviceSubclass();
158 | }
159 |
160 | /**
161 | * 是否目标设备,是相机并且产品id和供应商id跟配置的一致
162 | *
163 | * @param usbDevice
164 | * @return
165 | */
166 | public boolean isTargetDevice(UsbDevice usbDevice) {
167 | if (!isUsbCamera(usbDevice)
168 | || mConfig == null
169 | || (mConfig.getProductId() != 0 && mConfig.getProductId() != usbDevice.getProductId())
170 | || (mConfig.getVendorId() != 0 && mConfig.getVendorId() != usbDevice.getVendorId())) {
171 | LogUtil.i("No target camera device");
172 | return false;
173 | }
174 | LogUtil.i("Find target camera device");
175 | return true;
176 | }
177 |
178 | /**
179 | * usb插拔广播监听类
180 | */
181 | private class USBReceiver extends BroadcastReceiver {
182 | @Override
183 | public void onReceive(Context context, Intent intent) {
184 | UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
185 | LogUtil.i("usbDevice-->" + usbDevice);
186 | if (!isTargetDevice(usbDevice) || mConnectCallback == null) {
187 | return;
188 | }
189 |
190 | switch (intent.getAction()) {
191 | case UsbManager.ACTION_USB_DEVICE_ATTACHED:
192 | LogUtil.i("onAttached");
193 | mConnectCallback.onAttached(usbDevice);
194 | break;
195 |
196 | case ACTION_USB_DEVICE_PERMISSION:
197 | boolean granted = intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false);
198 | mConnectCallback.onGranted(usbDevice, granted);
199 | LogUtil.i("onGranted-->" + granted);
200 | break;
201 |
202 | case UsbManager.ACTION_USB_DEVICE_DETACHED:
203 | LogUtil.i("onDetached");
204 | mConnectCallback.onDetached(usbDevice);
205 | break;
206 |
207 | default:
208 | break;
209 | }
210 | }
211 | }
212 |
213 | }
214 |
--------------------------------------------------------------------------------
/uvccamerasdk/src/main/java/com/lgh/uvccamera/utils/FileUtil.java:
--------------------------------------------------------------------------------
1 | package com.lgh.uvccamera.utils;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.os.Environment;
6 |
7 | import java.io.File;
8 | import java.io.FileOutputStream;
9 |
10 | /**
11 | * 描述:文件存取工具类
12 | * 作者:liugh
13 | * 日期:2018/12/25
14 | * 版本:v2.0.0
15 | */
16 | public class FileUtil {
17 |
18 | /**
19 | * 判断当前系统中是否存在外部存储器(一般为SD卡)
20 | *
21 | * @return 当前系统中是否存在外部存储器
22 | */
23 | public static boolean hasExternalStorage() {
24 | return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
25 | }
26 |
27 | /**
28 | * 获取外部存储器(一般为SD卡)的路径
29 | *
30 | * @return 外部存储器的绝对路径
31 | */
32 | public static String getExternalStoragePath() {
33 | return Environment.getExternalStorageDirectory().getAbsolutePath();
34 | }
35 |
36 | /**
37 | * 获取SD卡目录
38 | *
39 | * @param foderName
40 | * @param fileName
41 | * @return
42 | */
43 | public static File getSDCardDir(String foderName) {
44 | if (!hasExternalStorage()) {
45 | return null;
46 | }
47 | return new File(getExternalStoragePath() + File.separator + foderName);
48 | }
49 |
50 | /**
51 | * 获取SD卡文件
52 | *
53 | * @param foderName
54 | * @param fileName
55 | * @return
56 | */
57 | public static File getSDCardFile(String foderName, String fileName) {
58 | File foder = getSDCardDir(foderName);
59 | if (foder == null) {
60 | return null;
61 | }
62 | if (!foder.exists()) {
63 | if (!foder.mkdirs()) {
64 | return null;
65 | }
66 | }
67 | return new File(foder, fileName);
68 | }
69 |
70 | /**
71 | * 获取缓存目录
72 | *
73 | * @param context
74 | * @param dirName
75 | * @return
76 | */
77 | public static String getDiskCacheDir(Context context, String dirName) {
78 | String cachePath;
79 | if ((Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
80 | || !Environment.isExternalStorageRemovable())
81 | && context.getExternalCacheDir() != null) {
82 | cachePath = context.getExternalCacheDir().getPath();
83 | } else {
84 | cachePath = context.getCacheDir().getPath();
85 | }
86 | return cachePath + File.separator + dirName;
87 | }
88 |
89 | /**
90 | * 获取缓存目录文件
91 | *
92 | * @param context
93 | * @param dirName
94 | * @param fileName
95 | * @return
96 | */
97 | public static File getCacheFile(Context context, String dirName, String fileName) {
98 | File dirFile = new File(getDiskCacheDir(context, dirName));
99 | if (!dirFile.exists()) {
100 | if (!dirFile.mkdirs()) {
101 | LogUtil.d("failed to create directory");
102 | return null;
103 | }
104 | }
105 | return new File(dirFile.getPath() + File.separator + fileName);
106 | }
107 |
108 | /**
109 | * 删除文件或文件夹
110 | *
111 | * @param dirFile
112 | * @return
113 | */
114 | public static boolean deleteFile(File dirFile) {
115 | if (!dirFile.exists()) {
116 | return false;
117 | }
118 | if (dirFile.isFile()) {
119 | return dirFile.delete();
120 | } else {
121 | for (File file : dirFile.listFiles()) {
122 | deleteFile(file);
123 | }
124 | }
125 | return dirFile.delete();
126 | }
127 |
128 | /**
129 | * 将yuv格式byte数组转化成jpeg图片并保存
130 | *
131 | * @param file
132 | * @param yuv
133 | * @param width
134 | * @param height
135 | */
136 | public static String saveYuv2Jpeg(File file, byte[] yuv, int width, int height) {
137 | return saveBitmap(file, ImageUtil.yuv2Bitmap(yuv, width, height));
138 | }
139 |
140 | /**
141 | * 将yuv格式byte数组转化成jpeg图片并保存
142 | *
143 | * @param file
144 | * @param yuv
145 | * @param width
146 | * @param height
147 | * @param rotation
148 | */
149 | public static String saveYuv2Jpeg(File file, byte[] yuv, int width, int height, float rotation) {
150 | return saveBitmap(file, ImageUtil.yuv2Bitmap(yuv, width, height, rotation));
151 | }
152 |
153 | /**
154 | * 保存bitmap
155 | *
156 | * @param file
157 | * @param bitmap
158 | */
159 | public static String saveBitmap(File file, Bitmap bitmap) {
160 | if (file == null || bitmap == null) {
161 | return null;
162 | }
163 | try {
164 | FileOutputStream fos = new FileOutputStream(file);
165 | bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
166 | if (bitmap != null && !bitmap.isRecycled()) {
167 | bitmap.recycle();
168 | bitmap = null;
169 | }
170 | fos.flush();
171 | fos.close();
172 | } catch (Exception e) {
173 | e.printStackTrace();
174 | }
175 | return file.getAbsolutePath();
176 | }
177 |
178 | }
179 |
--------------------------------------------------------------------------------
/uvccamerasdk/src/main/java/com/lgh/uvccamera/utils/ImageUtil.java:
--------------------------------------------------------------------------------
1 | package com.lgh.uvccamera.utils;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.graphics.ImageFormat;
6 | import android.graphics.Matrix;
7 | import android.graphics.Rect;
8 | import android.graphics.YuvImage;
9 |
10 | import java.io.ByteArrayOutputStream;
11 |
12 | /**
13 | * 描述:图片工具类
14 | * 作者:liugh
15 | * 日期:2018/12/11
16 | * 版本:v2.0.0
17 | */
18 | public class ImageUtil {
19 |
20 | /**
21 | * yuv数据转bitmap
22 | *
23 | * @param yuv
24 | * @param width
25 | * @param height
26 | * @return
27 | */
28 | public static Bitmap yuv2Bitmap(byte[] yuv, int width, int height) {
29 | Bitmap bitmap = null;
30 | try {
31 | ByteArrayOutputStream bos = new ByteArrayOutputStream(yuv.length);
32 | YuvImage yuvImage = new YuvImage(yuv, ImageFormat.NV21, width, height, null);
33 | boolean success = yuvImage.compressToJpeg(new Rect(0, 0, width, height), 100, bos);
34 | if (success) {
35 | byte[] buffer = bos.toByteArray();
36 | bitmap = BitmapFactory.decodeByteArray(buffer, 0, buffer.length);
37 | }
38 | bos.flush();
39 | bos.close();
40 | } catch (Exception e) {
41 | e.printStackTrace();
42 | }
43 | return bitmap;
44 | }
45 |
46 | /**
47 | * yuv数据转bitmap
48 | *
49 | * @param yuv
50 | * @param width
51 | * @param height
52 | * @param rotation
53 | * @return
54 | */
55 | public static Bitmap yuv2Bitmap(byte[] yuv, int width, int height, float rotation) {
56 | Bitmap bitmap = yuv2Bitmap(yuv, width, height);
57 | return rotateBimap(bitmap, rotation);
58 | }
59 |
60 | /**
61 | * 旋转图片
62 | *
63 | * @param bitmap
64 | * @param rotation 旋转角度
65 | * @return
66 | */
67 | public static Bitmap rotateBimap(Bitmap bitmap, float rotation) {
68 | if (bitmap == null || rotation == 0) {
69 | return bitmap;
70 | }
71 | Matrix matrix = new Matrix();
72 | matrix.postRotate(rotation);
73 | Bitmap rotateBimap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
74 | if (bitmap != null && !bitmap.isRecycled()) {
75 | bitmap.recycle();
76 | bitmap = null;
77 | }
78 | return rotateBimap;
79 | }
80 |
81 | /**
82 | * Bitmap缩放
83 | *
84 | * @param bitmap
85 | * @param newWidth
86 | * @param newHeight
87 | * @return
88 | */
89 | public static Bitmap scaleBitmap(Bitmap bitmap, int newWidth, int newHeight) {
90 | if (bitmap == null) {
91 | return null;
92 | }
93 | int width = bitmap.getWidth();
94 | int height = bitmap.getHeight();
95 | float scaleWidth = (float) newWidth / (float) width;
96 | float scaleHeight = (float) newHeight / (float) height;
97 | Matrix matrix = new Matrix();
98 | matrix.postScale(scaleWidth, scaleHeight);
99 | Bitmap scaleBitmap = null;
100 | try {
101 | scaleBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
102 | } catch (OutOfMemoryError e) {
103 | while (scaleBitmap == null) {
104 | System.gc();
105 | System.runFinalization();
106 | scaleBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
107 | }
108 | }
109 | if (bitmap != scaleBitmap && !bitmap.isRecycled()) {
110 | bitmap.recycle();
111 | bitmap = null;
112 | }
113 | return scaleBitmap;
114 | }
115 |
116 | }
117 |
--------------------------------------------------------------------------------
/uvccamerasdk/src/main/java/com/lgh/uvccamera/utils/LogUtil.java:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | * Copyright (C) 2017 HET, Inc.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | *
17 | */
18 |
19 | package com.lgh.uvccamera.utils;
20 |
21 | import android.text.TextUtils;
22 | import android.util.Log;
23 |
24 | /**
25 | * 描述:Log工具,类似android.util.Log。
26 | * tag自动产生,格式: customTagPrefix:className.methodName(L:lineNumber),
27 | * customTagPrefix为空时只输出:className.methodName(L:lineNumber)。
28 | *
29 | *
30 | * @author ~若相惜
31 | * @version v1.0
32 | * @date 2015-8-25 下午1:57:44
33 | */
34 | public class LogUtil {
35 |
36 | public static String customTagPrefix = "uvc_camera";
37 |
38 | private LogUtil() {
39 | }
40 |
41 | public static boolean allowD = true;
42 | public static boolean allowE = true;
43 | public static boolean allowI = true;
44 | public static boolean allowV = true;
45 | public static boolean allowW = true;
46 | public static boolean allowWtf = true;
47 |
48 | private static String generateTag(StackTraceElement caller) {
49 | String tag = "%s.%s(L:%d)";
50 | String callerClazzName = caller.getClassName();
51 | callerClazzName = callerClazzName.substring(callerClazzName.lastIndexOf(".") + 1);
52 | tag = String.format(tag, callerClazzName, caller.getMethodName(), caller.getLineNumber());
53 | tag = TextUtils.isEmpty(customTagPrefix) ? tag : customTagPrefix + ":" + tag;
54 | return tag;
55 | }
56 |
57 | public static CustomLogger customLogger;
58 |
59 | public interface CustomLogger {
60 | void d(String tag, String content);
61 |
62 | void d(String tag, String content, Throwable tr);
63 |
64 | void e(String tag, String content);
65 |
66 | void e(String tag, String content, Throwable tr);
67 |
68 | void i(String tag, String content);
69 |
70 | void i(String tag, String content, Throwable tr);
71 |
72 | void v(String tag, String content);
73 |
74 | void v(String tag, String content, Throwable tr);
75 |
76 | void w(String tag, String content);
77 |
78 | void w(String tag, String content, Throwable tr);
79 |
80 | void w(String tag, Throwable tr);
81 |
82 | void wtf(String tag, String content);
83 |
84 | void wtf(String tag, String content, Throwable tr);
85 |
86 | void wtf(String tag, Throwable tr);
87 | }
88 |
89 | public static void d(String content) {
90 | if (!allowD) return;
91 | StackTraceElement caller = getCallerStackTraceElement();
92 | String tag = generateTag(caller);
93 |
94 | if (customLogger != null) {
95 | customLogger.d(tag, content);
96 | } else {
97 | Log.d(tag, content);
98 | }
99 | }
100 |
101 | public static StackTraceElement getCallerStackTraceElement() {
102 | return Thread.currentThread().getStackTrace()[4];
103 | }
104 |
105 | public static void d(String content, Throwable tr) {
106 | if (!allowD) return;
107 | StackTraceElement caller = getCallerStackTraceElement();
108 | String tag = generateTag(caller);
109 |
110 | if (customLogger != null) {
111 | customLogger.d(tag, content, tr);
112 | } else {
113 | Log.d(tag, content, tr);
114 | }
115 | }
116 |
117 | public static void e(String content) {
118 | if (!allowE) return;
119 | StackTraceElement caller = getCallerStackTraceElement();
120 | String tag = generateTag(caller);
121 |
122 | if (customLogger != null) {
123 | customLogger.e(tag, content);
124 | } else {
125 | Log.e(tag, content);
126 | }
127 | }
128 |
129 | public static void e(String content, Throwable tr) {
130 | if (!allowE) return;
131 | StackTraceElement caller = getCallerStackTraceElement();
132 | String tag = generateTag(caller);
133 |
134 | if (customLogger != null) {
135 | customLogger.e(tag, content, tr);
136 | } else {
137 | Log.e(tag, content, tr);
138 | }
139 | }
140 |
141 | public static void i(String content) {
142 | if (!allowI) return;
143 | StackTraceElement caller = getCallerStackTraceElement();
144 | String tag = generateTag(caller);
145 |
146 | if (customLogger != null) {
147 | customLogger.i(tag, content);
148 | } else {
149 | Log.i(tag, content);
150 | }
151 | }
152 |
153 | public static void i(String content, Throwable tr) {
154 | if (!allowI) return;
155 | StackTraceElement caller = getCallerStackTraceElement();
156 | String tag = generateTag(caller);
157 |
158 | if (customLogger != null) {
159 | customLogger.i(tag, content, tr);
160 | } else {
161 | Log.i(tag, content, tr);
162 | }
163 | }
164 |
165 | public static void v(String content) {
166 | if (!allowV) return;
167 | StackTraceElement caller = getCallerStackTraceElement();
168 | String tag = generateTag(caller);
169 |
170 | if (customLogger != null) {
171 | customLogger.v(tag, content);
172 | } else {
173 | Log.v(tag, content);
174 | }
175 | }
176 |
177 | public static void v(String content, Throwable tr) {
178 | if (!allowV) return;
179 | StackTraceElement caller = getCallerStackTraceElement();
180 | String tag = generateTag(caller);
181 |
182 | if (customLogger != null) {
183 | customLogger.v(tag, content, tr);
184 | } else {
185 | Log.v(tag, content, tr);
186 | }
187 | }
188 |
189 | public static void w(String content) {
190 | if (!allowW) return;
191 | StackTraceElement caller = getCallerStackTraceElement();
192 | String tag = generateTag(caller);
193 |
194 | if (customLogger != null) {
195 | customLogger.w(tag, content);
196 | } else {
197 | Log.w(tag, content);
198 | }
199 | }
200 |
201 | public static void w(String content, Throwable tr) {
202 | if (!allowW) return;
203 | StackTraceElement caller = getCallerStackTraceElement();
204 | String tag = generateTag(caller);
205 |
206 | if (customLogger != null) {
207 | customLogger.w(tag, content, tr);
208 | } else {
209 | Log.w(tag, content, tr);
210 | }
211 | }
212 |
213 | public static void w(Throwable tr) {
214 | if (!allowW) return;
215 | StackTraceElement caller = getCallerStackTraceElement();
216 | String tag = generateTag(caller);
217 |
218 | if (customLogger != null) {
219 | customLogger.w(tag, tr);
220 | } else {
221 | Log.w(tag, tr);
222 | }
223 | }
224 |
225 | public static void wtf(String content) {
226 | if (!allowWtf) return;
227 | StackTraceElement caller = getCallerStackTraceElement();
228 | String tag = generateTag(caller);
229 |
230 | if (customLogger != null) {
231 | customLogger.wtf(tag, content);
232 | } else {
233 | Log.wtf(tag, content);
234 | }
235 | }
236 |
237 | public static void wtf(String content, Throwable tr) {
238 | if (!allowWtf) return;
239 | StackTraceElement caller = getCallerStackTraceElement();
240 | String tag = generateTag(caller);
241 |
242 | if (customLogger != null) {
243 | customLogger.wtf(tag, content, tr);
244 | } else {
245 | Log.wtf(tag, content, tr);
246 | }
247 | }
248 |
249 | public static void wtf(Throwable tr) {
250 | if (!allowWtf) return;
251 | StackTraceElement caller = getCallerStackTraceElement();
252 | String tag = generateTag(caller);
253 |
254 | if (customLogger != null) {
255 | customLogger.wtf(tag, tr);
256 | } else {
257 | Log.wtf(tag, tr);
258 | }
259 | }
260 |
261 | }
262 |
--------------------------------------------------------------------------------
/uvccamerasdk/src/main/java/com/lgh/uvccamera/utils/RxUtil.java:
--------------------------------------------------------------------------------
1 | package com.lgh.uvccamera.utils;
2 |
3 | import rx.Observable;
4 | import rx.Subscription;
5 | import rx.android.schedulers.AndroidSchedulers;
6 | import rx.schedulers.Schedulers;
7 |
8 | public class RxUtil {
9 |
10 | public static Observable.Transformer io_main() {
11 | return new Observable.Transformer() {
12 | @Override
13 | public Object call(Object observable) {
14 | return ((Observable) observable)
15 | .subscribeOn(Schedulers.io())
16 | .unsubscribeOn(Schedulers.io())
17 | .observeOn(AndroidSchedulers.mainThread());
18 | }
19 | };
20 | }
21 |
22 | public static void unsubscribe(Subscription subscription) {
23 | if (subscription != null && !subscription.isUnsubscribed()) {
24 | subscription.unsubscribe();
25 | }
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/uvccamerasdk/src/main/java/com/serenegiant/usb/IButtonCallback.java:
--------------------------------------------------------------------------------
1 | package com.serenegiant.usb;
2 |
3 | public interface IButtonCallback {
4 | void onButton(int button, int state);
5 | }
6 |
--------------------------------------------------------------------------------
/uvccamerasdk/src/main/java/com/serenegiant/usb/IFrameCallback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * UVCCamera
3 | * library and sample to access to UVC web camera on non-rooted Android device
4 | *
5 | * Copyright (c) 2014-2017 saki t_saki@serenegiant.com
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | *
19 | * All files in the folder are under this Apache License, Version 2.0.
20 | * Files in the libjpeg-turbo, libusb, libuvc, rapidjson folder
21 | * may have a different license, see the respective files.
22 | */
23 |
24 | package com.serenegiant.usb;
25 |
26 | import java.nio.ByteBuffer;
27 |
28 | /**
29 | * Callback interface for UVCCamera class
30 | * If you need frame data as ByteBuffer, you can use this callback interface with UVCCamera#setFrameCallback
31 | */
32 | public interface IFrameCallback {
33 | /**
34 | * This method is called from native library via JNI on the same thread as UVCCamera#startCapture.
35 | * You can use both UVCCamera#startCapture and #setFrameCallback
36 | * but it is better to use either for better performance.
37 | * You can also pass pixel format type to UVCCamera#setFrameCallback for this method.
38 | * Some frames may drops if this method takes a time.
39 | * When you use some color format like NV21, this library never execute color space conversion,
40 | * just execute pixel format conversion. If you want to get same result as on screen, please try to
41 | * consider to get images via texture(SurfaceTexture) and read pixel buffer from it using OpenGL|ES2/3
42 | * instead of using IFrameCallback(this way is much efficient in most case than using IFrameCallback).
43 | *
44 | * @param frame this is direct ByteBuffer from JNI layer and you should handle it's byte order and limitation.
45 | */
46 | void onFrame(ByteBuffer frame);
47 | }
48 |
--------------------------------------------------------------------------------
/uvccamerasdk/src/main/java/com/serenegiant/usb/IStatusCallback.java:
--------------------------------------------------------------------------------
1 | package com.serenegiant.usb;
2 |
3 | import java.nio.ByteBuffer;
4 |
5 | public interface IStatusCallback {
6 | void onStatus(int statusClass, int event, int selector, int statusAttribute, ByteBuffer data);
7 | }
8 |
--------------------------------------------------------------------------------
/uvccamerasdk/src/main/java/com/serenegiant/usb/Size.java:
--------------------------------------------------------------------------------
1 | /*
2 | * UVCCamera
3 | * library and sample to access to UVC web camera on non-rooted Android device
4 | *
5 | * Copyright (c) 2014-2017 saki t_saki@serenegiant.com
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | *
19 | * All files in the folder are under this Apache License, Version 2.0.
20 | * Files in the libjpeg-turbo, libusb, libuvc, rapidjson folder
21 | * may have a different license, see the respective files.
22 | */
23 |
24 | package com.serenegiant.usb;
25 |
26 | import android.os.Parcel;
27 | import android.os.Parcelable;
28 |
29 | import java.util.Locale;
30 |
31 | public class Size implements Parcelable {
32 | /**
33 | * native側のuvc_raw_format_tの値, こっちは主にlibuvc用
34 | * 9999 is still image
35 | */
36 | public int type;
37 | /**
38 | * native側のraw_frame_tの値, androusb用,
39 | * libuvcは対応していない
40 | */
41 | public int frame_type;
42 | public int index;
43 | public int width;
44 | public int height;
45 | public int frameIntervalType;
46 | public int frameIntervalIndex;
47 | public int[] intervals;
48 | // ここ以下はframeIntervalTypeとintervalsから#updateFrameRateで計算する
49 | public float[] fps;
50 | private String frameRates;
51 |
52 | /**
53 | * コンストラクタ
54 | *
55 | * @param _type native側のraw_format_tの値, ただし9999は静止画
56 | * @param _frame_type native側のraw_frame_tの値
57 | * @param _index
58 | * @param _width
59 | * @param _height
60 | */
61 | public Size(final int _type, final int _frame_type, final int _index, final int _width, final int _height) {
62 | type = _type;
63 | frame_type = _frame_type;
64 | index = _index;
65 | width = _width;
66 | height = _height;
67 | frameIntervalType = -1;
68 | frameIntervalIndex = 0;
69 | intervals = null;
70 | updateFrameRate();
71 | }
72 |
73 | /**
74 | * コンストラクタ
75 | *
76 | * @param _type native側のraw_format_tの値, ただし9999は静止画
77 | * @param _frame_type native側のraw_frame_tの値
78 | * @param _index
79 | * @param _width
80 | * @param _height
81 | * @param _min_intervals
82 | * @param _max_intervals
83 | */
84 | public Size(final int _type, final int _frame_type, final int _index, final int _width, final int _height, final int _min_intervals, final int _max_intervals, final int _step) {
85 | type = _type;
86 | frame_type = _frame_type;
87 | index = _index;
88 | width = _width;
89 | height = _height;
90 | frameIntervalType = 0;
91 | frameIntervalIndex = 0;
92 | intervals = new int[3];
93 | intervals[0] = _min_intervals;
94 | intervals[1] = _max_intervals;
95 | intervals[2] = _step;
96 | updateFrameRate();
97 | }
98 |
99 | /**
100 | * コンストラクタ
101 | *
102 | * @param _type native側のraw_format_tの値, ただし9999は静止画
103 | * @param _frame_type native側のraw_frame_tの値
104 | * @param _index
105 | * @param _width
106 | * @param _height
107 | * @param _intervals
108 | */
109 | public Size(final int _type, final int _frame_type, final int _index, final int _width, final int _height, final int[] _intervals) {
110 | type = _type;
111 | frame_type = _frame_type;
112 | index = _index;
113 | width = _width;
114 | height = _height;
115 | final int n = _intervals != null ? _intervals.length : -1;
116 | if (n > 0) {
117 | frameIntervalType = n;
118 | intervals = new int[n];
119 | System.arraycopy(_intervals, 0, intervals, 0, n);
120 | } else {
121 | frameIntervalType = -1;
122 | intervals = null;
123 | }
124 | frameIntervalIndex = 0;
125 | updateFrameRate();
126 | }
127 |
128 | /**
129 | * コピーコンストラクタ
130 | *
131 | * @param other
132 | */
133 | public Size(final Size other) {
134 | type = other.type;
135 | frame_type = other.frame_type;
136 | index = other.index;
137 | width = other.width;
138 | height = other.height;
139 | frameIntervalType = other.frameIntervalType;
140 | frameIntervalIndex = other.frameIntervalIndex;
141 | final int n = other.intervals != null ? other.intervals.length : -1;
142 | if (n > 0) {
143 | intervals = new int[n];
144 | System.arraycopy(other.intervals, 0, intervals, 0, n);
145 | } else {
146 | intervals = null;
147 | }
148 | updateFrameRate();
149 | }
150 |
151 | private Size(final Parcel source) {
152 | // 読み取り順はwriteToParcelでの書き込み順と同じでないとダメ
153 | type = source.readInt();
154 | frame_type = source.readInt();
155 | index = source.readInt();
156 | width = source.readInt();
157 | height = source.readInt();
158 | frameIntervalType = source.readInt();
159 | frameIntervalIndex = source.readInt();
160 | if (frameIntervalType >= 0) {
161 | if (frameIntervalType > 0) {
162 | intervals = new int[frameIntervalType];
163 | } else {
164 | intervals = new int[3];
165 | }
166 | source.readIntArray(intervals);
167 | } else {
168 | intervals = null;
169 | }
170 | updateFrameRate();
171 | }
172 |
173 | public Size set(final Size other) {
174 | if (other != null) {
175 | type = other.type;
176 | frame_type = other.frame_type;
177 | index = other.index;
178 | width = other.width;
179 | height = other.height;
180 | frameIntervalType = other.frameIntervalType;
181 | frameIntervalIndex = other.frameIntervalIndex;
182 | final int n = other.intervals != null ? other.intervals.length : -1;
183 | if (n > 0) {
184 | intervals = new int[n];
185 | System.arraycopy(other.intervals, 0, intervals, 0, n);
186 | } else {
187 | intervals = null;
188 | }
189 | updateFrameRate();
190 | }
191 | return this;
192 | }
193 |
194 | public float getCurrentFrameRate() throws IllegalStateException {
195 | final int n = fps != null ? fps.length : 0;
196 | if ((frameIntervalIndex >= 0) && (frameIntervalIndex < n)) {
197 | return fps[frameIntervalIndex];
198 | }
199 | throw new IllegalStateException("unknown frame rate or not ready");
200 | }
201 |
202 | public void setCurrentFrameRate(final float frameRate) {
203 | // 一番近いのを選ぶ
204 | int index = -1;
205 | final int n = fps != null ? fps.length : 0;
206 | for (int i = 0; i < n; i++) {
207 | if (fps[i] <= frameRate) {
208 | index = i;
209 | break;
210 | }
211 | }
212 | frameIntervalIndex = index;
213 | }
214 |
215 | @Override
216 | public int describeContents() {
217 | return 0;
218 | }
219 |
220 | @Override
221 | public void writeToParcel(final Parcel dest, final int flags) {
222 | dest.writeInt(type);
223 | dest.writeInt(frame_type);
224 | dest.writeInt(index);
225 | dest.writeInt(width);
226 | dest.writeInt(height);
227 | dest.writeInt(frameIntervalType);
228 | dest.writeInt(frameIntervalIndex);
229 | if (intervals != null) {
230 | dest.writeIntArray(intervals);
231 | }
232 | }
233 |
234 | public void updateFrameRate() {
235 | final int n = frameIntervalType;
236 | if (n > 0) {
237 | fps = new float[n];
238 | for (int i = 0; i < n; i++) {
239 | final float _fps = fps[i] = 10000000.0f / intervals[i];
240 | }
241 | } else if (n == 0) {
242 | try {
243 | final int min = Math.min(intervals[0], intervals[1]);
244 | final int max = Math.max(intervals[0], intervals[1]);
245 | final int step = intervals[2];
246 | if (step > 0) {
247 | int m = 0;
248 | for (int i = min; i <= max; i += step) {
249 | m++;
250 | }
251 | fps = new float[m];
252 | m = 0;
253 | for (int i = min; i <= max; i += step) {
254 | final float _fps = fps[m++] = 10000000.0f / i;
255 | }
256 | } else {
257 | final float max_fps = 10000000.0f / min;
258 | int m = 0;
259 | for (float fps = 10000000.0f / min; fps <= max_fps; fps += 1.0f) {
260 | m++;
261 | }
262 | fps = new float[m];
263 | m = 0;
264 | for (float fps = 10000000.0f / min; fps <= max_fps; fps += 1.0f) {
265 | this.fps[m++] = fps;
266 | }
267 | }
268 | } catch (final Exception e) {
269 | // ignore, なんでかminとmaxが0になってるんちゃうかな
270 | fps = null;
271 | }
272 | }
273 | final int m = fps != null ? fps.length : 0;
274 | final StringBuilder sb = new StringBuilder();
275 | sb.append("[");
276 | for (int i = 0; i < m; i++) {
277 | sb.append(String.format(Locale.US, "%4.1f", fps[i]));
278 | if (i < m - 1) {
279 | sb.append(",");
280 | }
281 | }
282 | sb.append("]");
283 | frameRates = sb.toString();
284 | if (frameIntervalIndex > m) {
285 | frameIntervalIndex = 0;
286 | }
287 | }
288 |
289 | @Override
290 | public String toString() {
291 | float frame_rate = 0.0f;
292 | try {
293 | frame_rate = getCurrentFrameRate();
294 | } catch (final Exception e) {
295 | }
296 | return String.format(Locale.US, "Size(%dx%d@%4.1f,type:%d,frame:%d,index:%d,%s)", width, height, frame_rate, type, frame_type, index, frameRates);
297 | }
298 |
299 | public static final Creator CREATOR = new Creator() {
300 | @Override
301 | public Size createFromParcel(final Parcel source) {
302 | return new Size(source);
303 | }
304 |
305 | @Override
306 | public Size[] newArray(final int size) {
307 | return new Size[size];
308 | }
309 | };
310 | }
311 |
--------------------------------------------------------------------------------
/uvccamerasdk/src/main/java/com/serenegiant/usb/UVCCamera.java:
--------------------------------------------------------------------------------
1 | /*
2 | * UVCCamera
3 | * library and sample to access to UVC web camera on non-rooted Android device
4 | *
5 | * Copyright (c) 2014-2017 saki t_saki@serenegiant.com
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | *
19 | * All files in the folder are under this Apache License, Version 2.0.
20 | * Files in the libjpeg-turbo, libusb, libuvc, rapidjson folder
21 | * may have a different license, see the respective files.
22 | */
23 |
24 | package com.serenegiant.usb;
25 |
26 | import android.graphics.SurfaceTexture;
27 | import android.text.TextUtils;
28 | import android.view.Surface;
29 | import android.view.SurfaceHolder;
30 |
31 | import com.lgh.uvccamera.usb.UsbController;
32 |
33 | import org.json.JSONArray;
34 | import org.json.JSONException;
35 | import org.json.JSONObject;
36 |
37 | import java.util.ArrayList;
38 | import java.util.List;
39 |
40 | public class UVCCamera {
41 | public static final int DEFAULT_PREVIEW_WIDTH = 640;
42 | public static final int DEFAULT_PREVIEW_HEIGHT = 480;
43 | public static final int DEFAULT_PREVIEW_MODE = 0;
44 | public static final int DEFAULT_PREVIEW_MIN_FPS = 1;
45 | public static final int DEFAULT_PREVIEW_MAX_FPS = 31;
46 | public static final float DEFAULT_BANDWIDTH = 1.0f;
47 |
48 | public static final int FRAME_FORMAT_YUYV = 0;
49 | public static final int FRAME_FORMAT_MJPEG = 1;
50 |
51 | public static final int PIXEL_FORMAT_RAW = 0;
52 | public static final int PIXEL_FORMAT_YUV = 1;
53 | public static final int PIXEL_FORMAT_RGB565 = 2;
54 | public static final int PIXEL_FORMAT_RGBX = 3;
55 | public static final int PIXEL_FORMAT_YUV420SP = 4; // NV12
56 | public static final int PIXEL_FORMAT_NV21 = 5; // = YVU420SemiPlanar,NV21,但是保存到jpg颜色失真
57 |
58 | //--------------------------------------------------------------------------------
59 | public static final int CTRL_SCANNING = 0x00000001; // D0: Scanning Mode
60 | public static final int CTRL_AE = 0x00000002; // D1: Auto-Exposure Mode
61 | public static final int CTRL_AE_PRIORITY = 0x00000004; // D2: Auto-Exposure Priority
62 | public static final int CTRL_AE_ABS = 0x00000008; // D3: Exposure Time (Absolute)
63 | public static final int CTRL_AR_REL = 0x00000010; // D4: Exposure Time (Relative)
64 | public static final int CTRL_FOCUS_ABS = 0x00000020; // D5: Focus (Absolute)
65 | public static final int CTRL_FOCUS_REL = 0x00000040; // D6: Focus (Relative)
66 | public static final int CTRL_IRIS_ABS = 0x00000080; // D7: Iris (Absolute)
67 | public static final int CTRL_IRIS_REL = 0x00000100; // D8: Iris (Relative)
68 | public static final int CTRL_ZOOM_ABS = 0x00000200; // D9: Zoom (Absolute)
69 | public static final int CTRL_ZOOM_REL = 0x00000400; // D10: Zoom (Relative)
70 | public static final int CTRL_PANTILT_ABS = 0x00000800; // D11: PanTilt (Absolute)
71 | public static final int CTRL_PANTILT_REL = 0x00001000; // D12: PanTilt (Relative)
72 | public static final int CTRL_ROLL_ABS = 0x00002000; // D13: Roll (Absolute)
73 | public static final int CTRL_ROLL_REL = 0x00004000; // D14: Roll (Relative)
74 | public static final int CTRL_FOCUS_AUTO = 0x00020000; // D17: Focus, Auto
75 | public static final int CTRL_PRIVACY = 0x00040000; // D18: Privacy
76 | public static final int CTRL_FOCUS_SIMPLE = 0x00080000; // D19: Focus, Simple
77 | public static final int CTRL_WINDOW = 0x00100000; // D20: Window
78 |
79 | public static final int PU_BRIGHTNESS = 0x80000001; // D0: Brightness
80 | public static final int PU_CONTRAST = 0x80000002; // D1: Contrast
81 | public static final int PU_HUE = 0x80000004; // D2: Hue
82 | public static final int PU_SATURATION = 0x80000008; // D3: Saturation
83 | public static final int PU_SHARPNESS = 0x80000010; // D4: Sharpness
84 | public static final int PU_GAMMA = 0x80000020; // D5: Gamma
85 | public static final int PU_WB_TEMP = 0x80000040; // D6: White Balance Temperature
86 | public static final int PU_WB_COMPO = 0x80000080; // D7: White Balance Component
87 | public static final int PU_BACKLIGHT = 0x80000100; // D8: Backlight Compensation
88 | public static final int PU_GAIN = 0x80000200; // D9: Gain
89 | public static final int PU_POWER_LF = 0x80000400; // D10: Power Line Frequency
90 | public static final int PU_HUE_AUTO = 0x80000800; // D11: Hue, Auto
91 | public static final int PU_WB_TEMP_AUTO = 0x80001000; // D12: White Balance Temperature, Auto
92 | public static final int PU_WB_COMPO_AUTO = 0x80002000; // D13: White Balance Component, Auto
93 | public static final int PU_DIGITAL_MULT = 0x80004000; // D14: Digital Multiplier
94 | public static final int PU_DIGITAL_LIMIT = 0x80008000; // D15: Digital Multiplier Limit
95 | public static final int PU_AVIDEO_STD = 0x80010000; // D16: Analog Video Standard
96 | public static final int PU_AVIDEO_LOCK = 0x80020000; // D17: Analog Video Lock Status
97 | public static final int PU_CONTRAST_AUTO = 0x80040000; // D18: Contrast, Auto
98 |
99 | // uvc_status_class from libuvc.h
100 | public static final int STATUS_CLASS_CONTROL = 0x10;
101 | public static final int STATUS_CLASS_CONTROL_CAMERA = 0x11;
102 | public static final int STATUS_CLASS_CONTROL_PROCESSING = 0x12;
103 |
104 | // uvc_status_attribute from libuvc.h
105 | public static final int STATUS_ATTRIBUTE_VALUE_CHANGE = 0x00;
106 | public static final int STATUS_ATTRIBUTE_INFO_CHANGE = 0x01;
107 | public static final int STATUS_ATTRIBUTE_FAILURE_CHANGE = 0x02;
108 | public static final int STATUS_ATTRIBUTE_UNKNOWN = 0xff;
109 |
110 | private static boolean isLoaded;
111 |
112 | static {
113 | if (!isLoaded) {
114 | System.loadLibrary("jpeg-turbo1500");
115 | System.loadLibrary("usb100");
116 | System.loadLibrary("uvc");
117 | System.loadLibrary("UVCCamera");
118 | isLoaded = true;
119 | }
120 | }
121 |
122 | private UsbController mControlBlock;
123 | protected long mControlSupports;
124 | protected long mProcSupports;
125 | protected int mCurrentFrameFormat = FRAME_FORMAT_YUYV;
126 | protected int mCurrentWidth = DEFAULT_PREVIEW_WIDTH, mCurrentHeight = DEFAULT_PREVIEW_HEIGHT;
127 | protected float mCurrentBandwidthFactor = DEFAULT_BANDWIDTH;
128 | protected String mSupportedSize;
129 | protected List mCurrentSizeList;
130 |
131 | // these fields from here are accessed from native code and do not change name and remove
132 | protected long mNativePtr;
133 | protected int mScanningModeMin, mScanningModeMax, mScanningModeDef;
134 | protected int mExposureModeMin, mExposureModeMax, mExposureModeDef;
135 | protected int mExposurePriorityMin, mExposurePriorityMax, mExposurePriorityDef;
136 | protected int mExposureMin, mExposureMax, mExposureDef;
137 | protected int mAutoFocusMin, mAutoFocusMax, mAutoFocusDef;
138 | protected int mFocusMin, mFocusMax, mFocusDef;
139 | protected int mFocusRelMin, mFocusRelMax, mFocusRelDef;
140 | protected int mFocusSimpleMin, mFocusSimpleMax, mFocusSimpleDef;
141 | protected int mIrisMin, mIrisMax, mIrisDef;
142 | protected int mIrisRelMin, mIrisRelMax, mIrisRelDef;
143 | protected int mPanMin, mPanMax, mPanDef;
144 | protected int mTiltMin, mTiltMax, mTiltDef;
145 | protected int mRollMin, mRollMax, mRollDef;
146 | protected int mPanRelMin, mPanRelMax, mPanRelDef;
147 | protected int mTiltRelMin, mTiltRelMax, mTiltRelDef;
148 | protected int mRollRelMin, mRollRelMax, mRollRelDef;
149 | protected int mPrivacyMin, mPrivacyMax, mPrivacyDef;
150 | protected int mAutoWhiteBlanceMin, mAutoWhiteBlanceMax, mAutoWhiteBlanceDef;
151 | protected int mAutoWhiteBlanceCompoMin, mAutoWhiteBlanceCompoMax, mAutoWhiteBlanceCompoDef;
152 | protected int mWhiteBlanceMin, mWhiteBlanceMax, mWhiteBlanceDef;
153 | protected int mWhiteBlanceCompoMin, mWhiteBlanceCompoMax, mWhiteBlanceCompoDef;
154 | protected int mWhiteBlanceRelMin, mWhiteBlanceRelMax, mWhiteBlanceRelDef;
155 | protected int mBacklightCompMin, mBacklightCompMax, mBacklightCompDef;
156 | protected int mBrightnessMin, mBrightnessMax, mBrightnessDef;
157 | protected int mContrastMin, mContrastMax, mContrastDef;
158 | protected int mSharpnessMin, mSharpnessMax, mSharpnessDef;
159 | protected int mGainMin, mGainMax, mGainDef;
160 | protected int mGammaMin, mGammaMax, mGammaDef;
161 | protected int mSaturationMin, mSaturationMax, mSaturationDef;
162 | protected int mHueMin, mHueMax, mHueDef;
163 | protected int mZoomMin, mZoomMax, mZoomDef;
164 | protected int mZoomRelMin, mZoomRelMax, mZoomRelDef;
165 | protected int mPowerlineFrequencyMin, mPowerlineFrequencyMax, mPowerlineFrequencyDef;
166 | protected int mMultiplierMin, mMultiplierMax, mMultiplierDef;
167 | protected int mMultiplierLimitMin, mMultiplierLimitMax, mMultiplierLimitDef;
168 | protected int mAnalogVideoStandardMin, mAnalogVideoStandardMax, mAnalogVideoStandardDef;
169 | protected int mAnalogVideoLockStateMin, mAnalogVideoLockStateMax, mAnalogVideoLockStateDef;
170 | // until here
171 |
172 | /**
173 | * the sonctructor of this class should be call within the thread that has a looper
174 | * (UI thread or a thread that called Looper.prepare)
175 | */
176 | public UVCCamera() {
177 | mNativePtr = nativeCreate();
178 | mSupportedSize = null;
179 | }
180 |
181 | /**
182 | * connect to a UVC camera
183 | * USB permission is necessary before this method is called
184 | *
185 | * @param controlBlock
186 | */
187 | public synchronized void open(final UsbController controlBlock) {
188 | int result;
189 | try {
190 | mControlBlock = controlBlock;
191 | result = nativeConnect(mNativePtr,
192 | controlBlock.getVendorId(),
193 | controlBlock.getProductId(),
194 | controlBlock.getFileDescriptor(),
195 | controlBlock.getBusNum(),
196 | controlBlock.getDevNum(),
197 | controlBlock.getUSBFSName());
198 | } catch (final Exception e) {
199 | e.printStackTrace();
200 | result = -1;
201 | }
202 | if (result != 0) {
203 | throw new UnsupportedOperationException("open failed:result=" + result);
204 | }
205 | if (mNativePtr != 0 && TextUtils.isEmpty(mSupportedSize)) {
206 | mSupportedSize = nativeGetSupportedSize(mNativePtr);
207 | }
208 | nativeSetPreviewSize(mNativePtr, DEFAULT_PREVIEW_WIDTH, DEFAULT_PREVIEW_HEIGHT,
209 | DEFAULT_PREVIEW_MIN_FPS, DEFAULT_PREVIEW_MAX_FPS, DEFAULT_PREVIEW_MODE, DEFAULT_BANDWIDTH);
210 | }
211 |
212 | /**
213 | * destroy UVCCamera object
214 | */
215 | public synchronized void destroy() {
216 | close();
217 | if (mNativePtr != 0) {
218 | nativeDestroy(mNativePtr);
219 | mNativePtr = 0;
220 | }
221 | }
222 |
223 | /**
224 | * close and release UVC camera
225 | */
226 | public synchronized void close() {
227 | stopPreview();
228 | if (mNativePtr != 0) {
229 | nativeRelease(mNativePtr);
230 | // mNativePtr = 0;
231 | }
232 | if (mControlBlock != null) {
233 | mControlBlock.close();
234 | mControlBlock = null;
235 | }
236 | mControlSupports = mProcSupports = 0;
237 | mCurrentFrameFormat = -1;
238 | mCurrentBandwidthFactor = 0;
239 | mSupportedSize = null;
240 | mCurrentSizeList = null;
241 | }
242 |
243 | public Size getPreviewSize() {
244 | Size result = null;
245 | final List list = getSupportedSizeList();
246 | for (final Size sz : list) {
247 | if ((sz.width == mCurrentWidth)
248 | || (sz.height == mCurrentHeight)) {
249 | result = sz;
250 | break;
251 | }
252 | }
253 | return result;
254 | }
255 |
256 | /**
257 | * Set preview size and preview mode
258 | *
259 | * @param width
260 | * @param height
261 | */
262 | public void setPreviewSize(final int width, final int height) {
263 | setPreviewSize(width, height, DEFAULT_PREVIEW_MIN_FPS, DEFAULT_PREVIEW_MAX_FPS, mCurrentFrameFormat, mCurrentBandwidthFactor);
264 | }
265 |
266 | /**
267 | * Set preview size and preview mode
268 | *
269 | * @param width
270 | * @param height
271 | * @param frameFormat either FRAME_FORMAT_YUYV(0) or FRAME_FORMAT_MJPEG(1)
272 | */
273 | public void setPreviewSize(final int width, final int height, final int frameFormat) {
274 | setPreviewSize(width, height, DEFAULT_PREVIEW_MIN_FPS, DEFAULT_PREVIEW_MAX_FPS, frameFormat, mCurrentBandwidthFactor);
275 | }
276 |
277 | /**
278 | * Set preview size and preview mode
279 | *
280 | * @param width
281 | * @param height
282 | * @param frameFormat either FRAME_FORMAT_YUYV(0) or FRAME_FORMAT_MJPEG(1)
283 | * @param bandwidth [0.0f,1.0f]
284 | */
285 | public void setPreviewSize(final int width, final int height, final int frameFormat, final float bandwidth) {
286 | setPreviewSize(width, height, DEFAULT_PREVIEW_MIN_FPS, DEFAULT_PREVIEW_MAX_FPS, frameFormat, bandwidth);
287 | }
288 |
289 | /**
290 | * Set preview size and preview mode
291 | *
292 | * @param width
293 | * @param height
294 | * @param min_fps
295 | * @param max_fps
296 | * @param frameFormat either FRAME_FORMAT_YUYV(0) or FRAME_FORMAT_MJPEG(1)
297 | * @param bandwidthFactor
298 | */
299 | public void setPreviewSize(final int width, final int height, final int min_fps, final int max_fps, final int frameFormat, final float bandwidthFactor) {
300 | if ((width == 0) || (height == 0))
301 | throw new IllegalArgumentException("invalid preview size");
302 | if (mNativePtr != 0) {
303 | final int result = nativeSetPreviewSize(mNativePtr, width, height, min_fps, max_fps, frameFormat, bandwidthFactor);
304 | if (result != 0)
305 | throw new IllegalArgumentException("Failed to set preview size");
306 | mCurrentFrameFormat = frameFormat;
307 | mCurrentWidth = width;
308 | mCurrentHeight = height;
309 | mCurrentBandwidthFactor = bandwidthFactor;
310 | }
311 | }
312 |
313 | public synchronized String getSupportedSize() {
314 | return !TextUtils.isEmpty(mSupportedSize) ? mSupportedSize : (mSupportedSize = nativeGetSupportedSize(mNativePtr));
315 | }
316 |
317 | public List getSupportedSizeList() {
318 | // final int type = (mCurrentFrameFormat > 0) ? 6 : 4;
319 | return getSupportedSize(-1, mSupportedSize);
320 | }
321 |
322 | public static List getSupportedSize(final int type, final String supportedSize) {
323 | final List result = new ArrayList<>();
324 | if (!TextUtils.isEmpty(supportedSize))
325 | try {
326 | final JSONObject json = new JSONObject(supportedSize);
327 | final JSONArray formats = json.getJSONArray("formats");
328 | final int format_nums = formats.length();
329 | for (int i = 0; i < format_nums; i++) {
330 | final JSONObject format = formats.getJSONObject(i);
331 | if (format.has("type") && format.has("size")) {
332 | final int format_type = format.getInt("type");
333 | if ((format_type == type) || (type == -1)) {
334 | addSize(format, format_type, 0, result);
335 | }
336 | }
337 | }
338 | } catch (final JSONException e) {
339 | e.printStackTrace();
340 | }
341 | return result;
342 | }
343 |
344 | private static final void addSize(final JSONObject format, final int formatType, final int frameType, final List size_list) throws JSONException {
345 | final JSONArray size = format.getJSONArray("size");
346 | final int size_nums = size.length();
347 | for (int j = 0; j < size_nums; j++) {
348 | final String[] sz = size.getString(j).split("x");
349 | try {
350 | size_list.add(new Size(formatType, frameType, j, Integer.parseInt(sz[0]), Integer.parseInt(sz[1])));
351 | } catch (final Exception e) {
352 | break;
353 | }
354 | }
355 | }
356 |
357 | /**
358 | * set preview surface with SurfaceHolder
359 | * you can use SurfaceHolder came from SurfaceView/GLSurfaceView
360 | *
361 | * @param holder
362 | */
363 | public synchronized void setPreviewDisplay(final SurfaceHolder holder) {
364 | nativeSetPreviewDisplay(mNativePtr, holder.getSurface());
365 | }
366 |
367 | /**
368 | * set preview surface with Surface
369 | *
370 | * @param surface
371 | */
372 | public synchronized void setPreviewDisplay(final Surface surface) {
373 | nativeSetPreviewDisplay(mNativePtr, surface);
374 | }
375 |
376 | /**
377 | * set preview surface with SurfaceTexture.
378 | * this method require API >= 14
379 | *
380 | * @param texture
381 | */
382 | public synchronized void setPreviewTexture(final SurfaceTexture texture) { // API >= 11
383 | final Surface surface = new Surface(texture); // XXX API >= 14
384 | nativeSetPreviewDisplay(mNativePtr, surface);
385 | }
386 |
387 | /**
388 | * start preview
389 | */
390 | public synchronized void startPreview() {
391 | if (mControlBlock != null) {
392 | nativeStartPreview(mNativePtr);
393 | }
394 | }
395 |
396 | /**
397 | * stop preview
398 | */
399 | public synchronized void stopPreview() {
400 | setFrameCallback(null, 0);
401 | if (mControlBlock != null) {
402 | nativeStopPreview(mNativePtr);
403 | }
404 | }
405 |
406 | /**
407 | * wrong result may return when you call this just after camera open.it is better to wait several hundreads millseconds.
408 | *
409 | * @param flag
410 | * @return
411 | */
412 | public boolean checkSupportFlag(final long flag) {
413 | updateCameraParams();
414 | if ((flag & 0x80000000) == 0x80000000)
415 | return ((mProcSupports & flag) == (flag & 0x7ffffffF));
416 | else
417 | return (mControlSupports & flag) == flag;
418 | }
419 |
420 | public synchronized void setAutoFocus(final boolean autoFocus) {
421 | if (mNativePtr != 0) {
422 | nativeSetAutoFocus(mNativePtr, autoFocus);
423 | }
424 | }
425 |
426 | public synchronized boolean getAutoFocus() {
427 | boolean result = true;
428 | if (mNativePtr != 0) {
429 | result = nativeGetAutoFocus(mNativePtr) > 0;
430 | }
431 | return result;
432 | }
433 |
434 | public synchronized void setFocus(final int focus) {
435 | if (mNativePtr != 0) {
436 | final float range = Math.abs(mFocusMax - mFocusMin);
437 | if (range > 0)
438 | nativeSetFocus(mNativePtr, (int) (focus / 100.f * range) + mFocusMin);
439 | }
440 | }
441 |
442 | public synchronized int getFocus(final int focus_abs) {
443 | int result = 0;
444 | if (mNativePtr != 0) {
445 | nativeUpdateFocusLimit(mNativePtr);
446 | final float range = Math.abs(mFocusMax - mFocusMin);
447 | if (range > 0) {
448 | result = (int) ((focus_abs - mFocusMin) * 100.f / range);
449 | }
450 | }
451 | return result;
452 | }
453 |
454 | public synchronized int getFocus() {
455 | return getFocus(nativeGetFocus(mNativePtr));
456 | }
457 |
458 | public synchronized void resetFocus() {
459 | if (mNativePtr != 0) {
460 | nativeSetFocus(mNativePtr, mFocusDef);
461 | }
462 | }
463 |
464 | public synchronized void setAutoWhiteBlance(final boolean autoWhiteBlance) {
465 | if (mNativePtr != 0) {
466 | nativeSetAutoWhiteBlance(mNativePtr, autoWhiteBlance);
467 | }
468 | }
469 |
470 | public synchronized boolean getAutoWhiteBlance() {
471 | boolean result = true;
472 | if (mNativePtr != 0) {
473 | result = nativeGetAutoWhiteBlance(mNativePtr) > 0;
474 | }
475 | return result;
476 | }
477 |
478 | public synchronized void setWhiteBlance(final int whiteBlance) {
479 | if (mNativePtr != 0) {
480 | final float range = Math.abs(mWhiteBlanceMax - mWhiteBlanceMin);
481 | if (range > 0)
482 | nativeSetWhiteBlance(mNativePtr, (int) (whiteBlance / 100.f * range) + mWhiteBlanceMin);
483 | }
484 | }
485 |
486 | public synchronized int getWhiteBlance(final int whiteBlance_abs) {
487 | int result = 0;
488 | if (mNativePtr != 0) {
489 | nativeUpdateWhiteBlanceLimit(mNativePtr);
490 | final float range = Math.abs(mWhiteBlanceMax - mWhiteBlanceMin);
491 | if (range > 0) {
492 | result = (int) ((whiteBlance_abs - mWhiteBlanceMin) * 100.f / range);
493 | }
494 | }
495 | return result;
496 | }
497 |
498 | public synchronized int getWhiteBlance() {
499 | return getFocus(nativeGetWhiteBlance(mNativePtr));
500 | }
501 |
502 | public synchronized void resetWhiteBlance() {
503 | if (mNativePtr != 0) {
504 | nativeSetWhiteBlance(mNativePtr, mWhiteBlanceDef);
505 | }
506 | }
507 |
508 | public synchronized void setBrightness(final int brightness) {
509 | if (mNativePtr != 0) {
510 | final float range = Math.abs(mBrightnessMax - mBrightnessMin);
511 | if (range > 0)
512 | nativeSetBrightness(mNativePtr, (int) (brightness / 100.f * range) + mBrightnessMin);
513 | }
514 | }
515 |
516 | public synchronized int getBrightness(final int brightness_abs) {
517 | int result = 0;
518 | if (mNativePtr != 0) {
519 | nativeUpdateBrightnessLimit(mNativePtr);
520 | final float range = Math.abs(mBrightnessMax - mBrightnessMin);
521 | if (range > 0) {
522 | result = (int) ((brightness_abs - mBrightnessMin) * 100.f / range);
523 | }
524 | }
525 | return result;
526 | }
527 |
528 | public synchronized int getBrightness() {
529 | return getBrightness(nativeGetBrightness(mNativePtr));
530 | }
531 |
532 | public synchronized void resetBrightness() {
533 | if (mNativePtr != 0) {
534 | nativeSetBrightness(mNativePtr, mBrightnessDef);
535 | }
536 | }
537 |
538 | public synchronized void setContrast(final int contrast) {
539 | if (mNativePtr != 0) {
540 | nativeUpdateContrastLimit(mNativePtr);
541 | final float range = Math.abs(mContrastMax - mContrastMin);
542 | if (range > 0)
543 | nativeSetContrast(mNativePtr, (int) (contrast / 100.f * range) + mContrastMin);
544 | }
545 | }
546 |
547 | public synchronized int getContrast(final int contrast_abs) {
548 | int result = 0;
549 | if (mNativePtr != 0) {
550 | final float range = Math.abs(mContrastMax - mContrastMin);
551 | if (range > 0) {
552 | result = (int) ((contrast_abs - mContrastMin) * 100.f / range);
553 | }
554 | }
555 | return result;
556 | }
557 |
558 | public synchronized int getContrast() {
559 | return getContrast(nativeGetContrast(mNativePtr));
560 | }
561 |
562 | public synchronized void resetContrast() {
563 | if (mNativePtr != 0) {
564 | nativeSetContrast(mNativePtr, mContrastDef);
565 | }
566 | }
567 |
568 | public synchronized void setSharpness(final int sharpness) {
569 | if (mNativePtr != 0) {
570 | final float range = Math.abs(mSharpnessMax - mSharpnessMin);
571 | if (range > 0)
572 | nativeSetSharpness(mNativePtr, (int) (sharpness / 100.f * range) + mSharpnessMin);
573 | }
574 | }
575 |
576 | public synchronized int getSharpness(final int sharpness_abs) {
577 | int result = 0;
578 | if (mNativePtr != 0) {
579 | nativeUpdateSharpnessLimit(mNativePtr);
580 | final float range = Math.abs(mSharpnessMax - mSharpnessMin);
581 | if (range > 0) {
582 | result = (int) ((sharpness_abs - mSharpnessMin) * 100.f / range);
583 | }
584 | }
585 | return result;
586 | }
587 |
588 | public synchronized int getSharpness() {
589 | return getSharpness(nativeGetSharpness(mNativePtr));
590 | }
591 |
592 | public synchronized void resetSharpness() {
593 | if (mNativePtr != 0) {
594 | nativeSetSharpness(mNativePtr, mSharpnessDef);
595 | }
596 | }
597 |
598 | public synchronized void setGain(final int gain) {
599 | if (mNativePtr != 0) {
600 | /*final float range = Math.abs(mGainMax - mGainMin);
601 | if (range > 0)
602 | nativeSetGain(mNativePtr, (int) (gain / 100.f * range) + mGainMin);*/
603 | nativeSetGain(mNativePtr, gain);
604 | }
605 | }
606 |
607 | public synchronized int getGain(final int gain_abs) {
608 | int result = 0;
609 | if (mNativePtr != 0) {
610 | nativeUpdateGainLimit(mNativePtr);
611 | final float range = Math.abs(mGainMax - mGainMin);
612 | if (range > 0) {
613 | result = (int) ((gain_abs - mGainMin) * 100.f / range);
614 | }
615 | }
616 | return result;
617 | }
618 |
619 | public synchronized int getGain() {
620 | return getGain(nativeGetGain(mNativePtr));
621 | }
622 |
623 | public synchronized void resetGain() {
624 | if (mNativePtr != 0) {
625 | nativeSetGain(mNativePtr, mGainDef);
626 | }
627 | }
628 |
629 | public synchronized void setGamma(final int gamma) {
630 | if (mNativePtr != 0) {
631 | final float range = Math.abs(mGammaMax - mGammaMin);
632 | if (range > 0)
633 | nativeSetGamma(mNativePtr, (int) (gamma / 100.f * range) + mGammaMin);
634 | }
635 | }
636 |
637 | public synchronized int getGamma(final int gamma_abs) {
638 | int result = 0;
639 | if (mNativePtr != 0) {
640 | nativeUpdateGammaLimit(mNativePtr);
641 | final float range = Math.abs(mGammaMax - mGammaMin);
642 | if (range > 0) {
643 | result = (int) ((gamma_abs - mGammaMin) * 100.f / range);
644 | }
645 | }
646 | return result;
647 | }
648 |
649 | public synchronized int getGamma() {
650 | return getGamma(nativeGetGamma(mNativePtr));
651 | }
652 |
653 | public synchronized void resetGamma() {
654 | if (mNativePtr != 0) {
655 | nativeSetGamma(mNativePtr, mGammaDef);
656 | }
657 | }
658 |
659 | public synchronized void setSaturation(final int saturation) {
660 | if (mNativePtr != 0) {
661 | final float range = Math.abs(mSaturationMax - mSaturationMin);
662 | if (range > 0)
663 | nativeSetSaturation(mNativePtr, (int) (saturation / 100.f * range) + mSaturationMin);
664 | }
665 | }
666 |
667 | public synchronized int getSaturation(final int saturation_abs) {
668 | int result = 0;
669 | if (mNativePtr != 0) {
670 | nativeUpdateSaturationLimit(mNativePtr);
671 | final float range = Math.abs(mSaturationMax - mSaturationMin);
672 | if (range > 0) {
673 | result = (int) ((saturation_abs - mSaturationMin) * 100.f / range);
674 | }
675 | }
676 | return result;
677 | }
678 |
679 | public synchronized int getSaturation() {
680 | return getSaturation(nativeGetSaturation(mNativePtr));
681 | }
682 |
683 | public synchronized void resetSaturation() {
684 | if (mNativePtr != 0) {
685 | nativeSetSaturation(mNativePtr, mSaturationDef);
686 | }
687 | }
688 |
689 | public synchronized void setHue(final int hue) {
690 | if (mNativePtr != 0) {
691 | final float range = Math.abs(mHueMax - mHueMin);
692 | if (range > 0)
693 | nativeSetHue(mNativePtr, (int) (hue / 100.f * range) + mHueMin);
694 | }
695 | }
696 |
697 | public synchronized int getHue(final int hue_abs) {
698 | int result = 0;
699 | if (mNativePtr != 0) {
700 | nativeUpdateHueLimit(mNativePtr);
701 | final float range = Math.abs(mHueMax - mHueMin);
702 | if (range > 0) {
703 | result = (int) ((hue_abs - mHueMin) * 100.f / range);
704 | }
705 | }
706 | return result;
707 | }
708 |
709 | public synchronized int getHue() {
710 | return getHue(nativeGetHue(mNativePtr));
711 | }
712 |
713 | public synchronized void resetHue() {
714 | if (mNativePtr != 0) {
715 | nativeSetHue(mNativePtr, mSaturationDef);
716 | }
717 | }
718 |
719 | public void setPowerlineFrequency(final int frequency) {
720 | if (mNativePtr != 0)
721 | nativeSetPowerlineFrequency(mNativePtr, frequency);
722 | }
723 |
724 | public int getPowerlineFrequency() {
725 | return nativeGetPowerlineFrequency(mNativePtr);
726 | }
727 |
728 | /**
729 | * this may not work well with some combination of camera and device
730 | *
731 | * @param zoom [%]
732 | */
733 | public synchronized void setZoom(final int zoom) {
734 | if (mNativePtr != 0) {
735 | final float range = Math.abs(mZoomMax - mZoomMin);
736 | if (range > 0) {
737 | final int z = (int) (zoom / 100.f * range) + mZoomMin;
738 | // Log.d(TAG, "setZoom:zoom=" + zoom + " ,value=" + z);
739 | nativeSetZoom(mNativePtr, z);
740 | }
741 | }
742 | }
743 |
744 | public synchronized int getZoom(final int zoom_abs) {
745 | int result = 0;
746 | if (mNativePtr != 0) {
747 | nativeUpdateZoomLimit(mNativePtr);
748 | final float range = Math.abs(mZoomMax - mZoomMin);
749 | if (range > 0) {
750 | result = (int) ((zoom_abs - mZoomMin) * 100.f / range);
751 | }
752 | }
753 | return result;
754 | }
755 |
756 | public synchronized int getZoom() {
757 | return getZoom(nativeGetZoom(mNativePtr));
758 | }
759 |
760 | public synchronized void resetZoom() {
761 | if (mNativePtr != 0) {
762 | nativeSetZoom(mNativePtr, mZoomDef);
763 | }
764 | }
765 |
766 | /**
767 | * start movie capturing(this should call while previewing)
768 | *
769 | * @param surface
770 | */
771 | public void startCapture(final Surface surface) {
772 | if (mControlBlock != null && surface != null) {
773 | nativeSetCaptureDisplay(mNativePtr, surface);
774 | } else
775 | throw new NullPointerException("startCapture");
776 | }
777 |
778 | /**
779 | * stop movie capturing
780 | */
781 | public void stopCapture() {
782 | if (mControlBlock != null) {
783 | nativeSetCaptureDisplay(mNativePtr, null);
784 | }
785 | }
786 |
787 | /**
788 | * set status callback
789 | *
790 | * @param callback
791 | */
792 | public void setStatusCallback(final IStatusCallback callback) {
793 | if (mNativePtr != 0) {
794 | nativeSetStatusCallback(mNativePtr, callback);
795 | }
796 | }
797 |
798 | /**
799 | * set button callback
800 | *
801 | * @param callback
802 | */
803 | public void setButtonCallback(final IButtonCallback callback) {
804 | if (mNativePtr != 0) {
805 | nativeSetButtonCallback(mNativePtr, callback);
806 | }
807 | }
808 |
809 | /**
810 | * set frame callback
811 | *
812 | * @param callback
813 | * @param pixelFormat
814 | */
815 | public void setFrameCallback(final IFrameCallback callback, final int pixelFormat) {
816 | if (mNativePtr != 0) {
817 | nativeSetFrameCallback(mNativePtr, callback, pixelFormat);
818 | }
819 | }
820 |
821 | public synchronized void updateCameraParams() {
822 | if (mNativePtr != 0) {
823 | if ((mControlSupports == 0) || (mProcSupports == 0)) {
824 | if (mControlSupports == 0)
825 | mControlSupports = nativeGetCtrlSupports(mNativePtr);
826 | if (mProcSupports == 0)
827 | mProcSupports = nativeGetProcSupports(mNativePtr);
828 | if ((mControlSupports != 0) && (mProcSupports != 0)) {
829 | nativeUpdateBrightnessLimit(mNativePtr);
830 | nativeUpdateContrastLimit(mNativePtr);
831 | nativeUpdateSharpnessLimit(mNativePtr);
832 | nativeUpdateGainLimit(mNativePtr);
833 | nativeUpdateGammaLimit(mNativePtr);
834 | nativeUpdateSaturationLimit(mNativePtr);
835 | nativeUpdateHueLimit(mNativePtr);
836 | nativeUpdateZoomLimit(mNativePtr);
837 | nativeUpdateWhiteBlanceLimit(mNativePtr);
838 | nativeUpdateFocusLimit(mNativePtr);
839 | }
840 | }
841 | } else {
842 | mControlSupports = mProcSupports = 0;
843 | }
844 | }
845 |
846 | // #nativeCreate and #nativeDestroy are not static methods.
847 | private final native long nativeCreate();
848 |
849 | private final native void nativeDestroy(final long id_camera);
850 |
851 | private final native int nativeConnect(long id_camera, int venderId, int productId, int fileDescriptor, int busNum, int devAddr, String usbfs);
852 |
853 | private static final native int nativeRelease(final long id_camera);
854 |
855 | private static final native int nativeSetStatusCallback(final long mNativePtr, final IStatusCallback callback);
856 |
857 | private static final native int nativeSetButtonCallback(final long mNativePtr, final IButtonCallback callback);
858 |
859 | private static final native int nativeSetPreviewSize(final long id_camera, final int width, final int height, final int min_fps, final int max_fps, final int mode, final float bandwidth);
860 |
861 | private static final native String nativeGetSupportedSize(final long id_camera);
862 |
863 | private static final native int nativeStartPreview(final long id_camera);
864 |
865 | private static final native int nativeStopPreview(final long id_camera);
866 |
867 | private static final native int nativeSetPreviewDisplay(final long id_camera, final Surface surface);
868 |
869 | private static final native int nativeSetFrameCallback(final long mNativePtr, final IFrameCallback callback, final int pixelFormat);
870 |
871 | private static final native int nativeSetCaptureDisplay(final long id_camera, final Surface surface);
872 |
873 | private static final native long nativeGetCtrlSupports(final long id_camera);
874 |
875 | private static final native long nativeGetProcSupports(final long id_camera);
876 |
877 | private final native int nativeUpdateScanningModeLimit(final long id_camera);
878 |
879 | private static final native int nativeSetScanningMode(final long id_camera, final int scanning_mode);
880 |
881 | private static final native int nativeGetScanningMode(final long id_camera);
882 |
883 | private final native int nativeUpdateExposureModeLimit(final long id_camera);
884 |
885 | private static final native int nativeSetExposureMode(final long id_camera, final int exposureMode);
886 |
887 | private static final native int nativeGetExposureMode(final long id_camera);
888 |
889 | private final native int nativeUpdateExposurePriorityLimit(final long id_camera);
890 |
891 | private static final native int nativeSetExposurePriority(final long id_camera, final int priority);
892 |
893 | private static final native int nativeGetExposurePriority(final long id_camera);
894 |
895 | private final native int nativeUpdateExposureLimit(final long id_camera);
896 |
897 | private static final native int nativeSetExposure(final long id_camera, final int exposure);
898 |
899 | private static final native int nativeGetExposure(final long id_camera);
900 |
901 | private final native int nativeUpdateExposureRelLimit(final long id_camera);
902 |
903 | private static final native int nativeSetExposureRel(final long id_camera, final int exposure_rel);
904 |
905 | private static final native int nativeGetExposureRel(final long id_camera);
906 |
907 | private final native int nativeUpdateAutoFocusLimit(final long id_camera);
908 |
909 | private static final native int nativeSetAutoFocus(final long id_camera, final boolean autofocus);
910 |
911 | private static final native int nativeGetAutoFocus(final long id_camera);
912 |
913 | private final native int nativeUpdateFocusLimit(final long id_camera);
914 |
915 | private static final native int nativeSetFocus(final long id_camera, final int focus);
916 |
917 | private static final native int nativeGetFocus(final long id_camera);
918 |
919 | private final native int nativeUpdateFocusRelLimit(final long id_camera);
920 |
921 | private static final native int nativeSetFocusRel(final long id_camera, final int focus_rel);
922 |
923 | private static final native int nativeGetFocusRel(final long id_camera);
924 |
925 | private final native int nativeUpdateIrisLimit(final long id_camera);
926 |
927 | private static final native int nativeSetIris(final long id_camera, final int iris);
928 |
929 | private static final native int nativeGetIris(final long id_camera);
930 |
931 | private final native int nativeUpdateIrisRelLimit(final long id_camera);
932 |
933 | private static final native int nativeSetIrisRel(final long id_camera, final int iris_rel);
934 |
935 | private static final native int nativeGetIrisRel(final long id_camera);
936 |
937 | private final native int nativeUpdatePanLimit(final long id_camera);
938 |
939 | private static final native int nativeSetPan(final long id_camera, final int pan);
940 |
941 | private static final native int nativeGetPan(final long id_camera);
942 |
943 | private final native int nativeUpdatePanRelLimit(final long id_camera);
944 |
945 | private static final native int nativeSetPanRel(final long id_camera, final int pan_rel);
946 |
947 | private static final native int nativeGetPanRel(final long id_camera);
948 |
949 | private final native int nativeUpdateTiltLimit(final long id_camera);
950 |
951 | private static final native int nativeSetTilt(final long id_camera, final int tilt);
952 |
953 | private static final native int nativeGetTilt(final long id_camera);
954 |
955 | private final native int nativeUpdateTiltRelLimit(final long id_camera);
956 |
957 | private static final native int nativeSetTiltRel(final long id_camera, final int tilt_rel);
958 |
959 | private static final native int nativeGetTiltRel(final long id_camera);
960 |
961 | private final native int nativeUpdateRollLimit(final long id_camera);
962 |
963 | private static final native int nativeSetRoll(final long id_camera, final int roll);
964 |
965 | private static final native int nativeGetRoll(final long id_camera);
966 |
967 | private final native int nativeUpdateRollRelLimit(final long id_camera);
968 |
969 | private static final native int nativeSetRollRel(final long id_camera, final int roll_rel);
970 |
971 | private static final native int nativeGetRollRel(final long id_camera);
972 |
973 | private final native int nativeUpdateAutoWhiteBlanceLimit(final long id_camera);
974 |
975 | private static final native int nativeSetAutoWhiteBlance(final long id_camera, final boolean autoWhiteBlance);
976 |
977 | private static final native int nativeGetAutoWhiteBlance(final long id_camera);
978 |
979 | private final native int nativeUpdateAutoWhiteBlanceCompoLimit(final long id_camera);
980 |
981 | private static final native int nativeSetAutoWhiteBlanceCompo(final long id_camera, final boolean autoWhiteBlanceCompo);
982 |
983 | private static final native int nativeGetAutoWhiteBlanceCompo(final long id_camera);
984 |
985 | private final native int nativeUpdateWhiteBlanceLimit(final long id_camera);
986 |
987 | private static final native int nativeSetWhiteBlance(final long id_camera, final int whiteBlance);
988 |
989 | private static final native int nativeGetWhiteBlance(final long id_camera);
990 |
991 | private final native int nativeUpdateWhiteBlanceCompoLimit(final long id_camera);
992 |
993 | private static final native int nativeSetWhiteBlanceCompo(final long id_camera, final int whiteBlance_compo);
994 |
995 | private static final native int nativeGetWhiteBlanceCompo(final long id_camera);
996 |
997 | private final native int nativeUpdateBacklightCompLimit(final long id_camera);
998 |
999 | private static final native int nativeSetBacklightComp(final long id_camera, final int backlight_comp);
1000 |
1001 | private static final native int nativeGetBacklightComp(final long id_camera);
1002 |
1003 | private final native int nativeUpdateBrightnessLimit(final long id_camera);
1004 |
1005 | private static final native int nativeSetBrightness(final long id_camera, final int brightness);
1006 |
1007 | private static final native int nativeGetBrightness(final long id_camera);
1008 |
1009 | private final native int nativeUpdateContrastLimit(final long id_camera);
1010 |
1011 | private static final native int nativeSetContrast(final long id_camera, final int contrast);
1012 |
1013 | private static final native int nativeGetContrast(final long id_camera);
1014 |
1015 | private final native int nativeUpdateAutoContrastLimit(final long id_camera);
1016 |
1017 | private static final native int nativeSetAutoContrast(final long id_camera, final boolean autocontrast);
1018 |
1019 | private static final native int nativeGetAutoContrast(final long id_camera);
1020 |
1021 | private final native int nativeUpdateSharpnessLimit(final long id_camera);
1022 |
1023 | private static final native int nativeSetSharpness(final long id_camera, final int sharpness);
1024 |
1025 | private static final native int nativeGetSharpness(final long id_camera);
1026 |
1027 | private final native int nativeUpdateGainLimit(final long id_camera);
1028 |
1029 | private static final native int nativeSetGain(final long id_camera, final int gain);
1030 |
1031 | private static final native int nativeGetGain(final long id_camera);
1032 |
1033 | private final native int nativeUpdateGammaLimit(final long id_camera);
1034 |
1035 | private static final native int nativeSetGamma(final long id_camera, final int gamma);
1036 |
1037 | private static final native int nativeGetGamma(final long id_camera);
1038 |
1039 | private final native int nativeUpdateSaturationLimit(final long id_camera);
1040 |
1041 | private static final native int nativeSetSaturation(final long id_camera, final int saturation);
1042 |
1043 | private static final native int nativeGetSaturation(final long id_camera);
1044 |
1045 | private final native int nativeUpdateHueLimit(final long id_camera);
1046 |
1047 | private static final native int nativeSetHue(final long id_camera, final int hue);
1048 |
1049 | private static final native int nativeGetHue(final long id_camera);
1050 |
1051 | private final native int nativeUpdateAutoHueLimit(final long id_camera);
1052 |
1053 | private static final native int nativeSetAutoHue(final long id_camera, final boolean autohue);
1054 |
1055 | private static final native int nativeGetAutoHue(final long id_camera);
1056 |
1057 | private final native int nativeUpdatePowerlineFrequencyLimit(final long id_camera);
1058 |
1059 | private static final native int nativeSetPowerlineFrequency(final long id_camera, final int frequency);
1060 |
1061 | private static final native int nativeGetPowerlineFrequency(final long id_camera);
1062 |
1063 | private final native int nativeUpdateZoomLimit(final long id_camera);
1064 |
1065 | private static final native int nativeSetZoom(final long id_camera, final int zoom);
1066 |
1067 | private static final native int nativeGetZoom(final long id_camera);
1068 |
1069 | private final native int nativeUpdateZoomRelLimit(final long id_camera);
1070 |
1071 | private static final native int nativeSetZoomRel(final long id_camera, final int zoom_rel);
1072 |
1073 | private static final native int nativeGetZoomRel(final long id_camera);
1074 |
1075 | private final native int nativeUpdateDigitalMultiplierLimit(final long id_camera);
1076 |
1077 | private static final native int nativeSetDigitalMultiplier(final long id_camera, final int multiplier);
1078 |
1079 | private static final native int nativeGetDigitalMultiplier(final long id_camera);
1080 |
1081 | private final native int nativeUpdateDigitalMultiplierLimitLimit(final long id_camera);
1082 |
1083 | private static final native int nativeSetDigitalMultiplierLimit(final long id_camera, final int multiplier_limit);
1084 |
1085 | private static final native int nativeGetDigitalMultiplierLimit(final long id_camera);
1086 |
1087 | private final native int nativeUpdateAnalogVideoStandardLimit(final long id_camera);
1088 |
1089 | private static final native int nativeSetAnalogVideoStandard(final long id_camera, final int standard);
1090 |
1091 | private static final native int nativeGetAnalogVideoStandard(final long id_camera);
1092 |
1093 | private final native int nativeUpdateAnalogVideoLockStateLimit(final long id_camera);
1094 |
1095 | private static final native int nativeSetAnalogVideoLoackState(final long id_camera, final int state);
1096 |
1097 | private static final native int nativeGetAnalogVideoLoackState(final long id_camera);
1098 |
1099 | private final native int nativeUpdatePrivacyLimit(final long id_camera);
1100 |
1101 | private static final native int nativeSetPrivacy(final long id_camera, final boolean privacy);
1102 |
1103 | private static final native int nativeGetPrivacy(final long id_camera);
1104 |
1105 | }
1106 |
--------------------------------------------------------------------------------
/uvccamerasdk/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | uvccamerasdk
3 |
4 |
--------------------------------------------------------------------------------
/uvccamerasdk/src/test/java/com/lgh/uvccamera/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.lgh.uvccamera;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------