forked from saki4510t/UVCCamera
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathUVCCamera.java
More file actions
1234 lines (1101 loc) · 46.3 KB
/
Copy pathUVCCamera.java
File metadata and controls
1234 lines (1101 loc) · 46.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* UVCCamera
* library and sample to access to UVC web camera on non-rooted Android device
*
* Copyright (c) 2014-2017 saki t_saki@serenegiant.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* All files in the folder are under this Apache License, Version 2.0.
* Files in the libjpeg-turbo, libusb, libuvc, rapidjson folder
* may have a different license, see the respective files.
*/
package com.serenegiant.usb;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.graphics.SurfaceTexture;
import android.hardware.usb.UsbDevice;
import android.text.TextUtils;
import android.util.Log;
import android.view.Surface;
import android.view.SurfaceHolder;
import com.serenegiant.usb.USBMonitor.UsbControlBlock;
public class UVCCamera {
private static final boolean DEBUG = false; // TODO set false when releasing
private static final String TAG = UVCCamera.class.getSimpleName();
private static final String DEFAULT_USBFS = "/dev/bus/usb";
public static final int DEFAULT_PREVIEW_WIDTH = 640;
public static final int DEFAULT_PREVIEW_HEIGHT = 480;
public static final int DEFAULT_PREVIEW_MODE = 0;
public static final int DEFAULT_PREVIEW_MIN_FPS = 1;
public static final int DEFAULT_PREVIEW_MAX_FPS = 30;
public static final float DEFAULT_BANDWIDTH = 1.0f;
public static final int FRAME_FORMAT_YUYV = 0;
public static final int FRAME_FORMAT_MJPEG = 1;
public static final int PIXEL_FORMAT_RAW = 0;
public static final int PIXEL_FORMAT_YUV = 1;
public static final int PIXEL_FORMAT_RGB565 = 2;
public static final int PIXEL_FORMAT_RGBX = 3;
public static final int PIXEL_FORMAT_YUV420SP = 4;
public static final int PIXEL_FORMAT_NV21 = 5; // = YVU420SemiPlanar
//--------------------------------------------------------------------------------
public static final int CTRL_SCANNING = 0x00000001; // D0: Scanning Mode
public static final int CTRL_AE = 0x00000002; // D1: Auto-Exposure Mode
public static final int CTRL_AE_PRIORITY = 0x00000004; // D2: Auto-Exposure Priority
public static final int CTRL_AE_ABS = 0x00000008; // D3: Exposure Time (Absolute)
public static final int CTRL_AR_REL = 0x00000010; // D4: Exposure Time (Relative)
public static final int CTRL_FOCUS_ABS = 0x00000020; // D5: Focus (Absolute)
public static final int CTRL_FOCUS_REL = 0x00000040; // D6: Focus (Relative)
public static final int CTRL_IRIS_ABS = 0x00000080; // D7: Iris (Absolute)
public static final int CTRL_IRIS_REL = 0x00000100; // D8: Iris (Relative)
public static final int CTRL_ZOOM_ABS = 0x00000200; // D9: Zoom (Absolute)
public static final int CTRL_ZOOM_REL = 0x00000400; // D10: Zoom (Relative)
public static final int CTRL_PANTILT_ABS = 0x00000800; // D11: PanTilt (Absolute)
public static final int CTRL_PANTILT_REL = 0x00001000; // D12: PanTilt (Relative)
public static final int CTRL_ROLL_ABS = 0x00002000; // D13: Roll (Absolute)
public static final int CTRL_ROLL_REL = 0x00004000; // D14: Roll (Relative)
public static final int CTRL_FOCUS_AUTO = 0x00020000; // D17: Focus, Auto
public static final int CTRL_PRIVACY = 0x00040000; // D18: Privacy
public static final int CTRL_FOCUS_SIMPLE = 0x00080000; // D19: Focus, Simple
public static final int CTRL_WINDOW = 0x00100000; // D20: Window
public static final int PU_BRIGHTNESS = 0x80000001; // D0: Brightness
public static final int PU_CONTRAST = 0x80000002; // D1: Contrast
public static final int PU_HUE = 0x80000004; // D2: Hue
public static final int PU_SATURATION = 0x80000008; // D3: Saturation
public static final int PU_SHARPNESS = 0x80000010; // D4: Sharpness
public static final int PU_GAMMA = 0x80000020; // D5: Gamma
public static final int PU_WB_TEMP = 0x80000040; // D6: White Balance Temperature
public static final int PU_WB_COMPO = 0x80000080; // D7: White Balance Component
public static final int PU_BACKLIGHT = 0x80000100; // D8: Backlight Compensation
public static final int PU_GAIN = 0x80000200; // D9: Gain
public static final int PU_POWER_LF = 0x80000400; // D10: Power Line Frequency
public static final int PU_HUE_AUTO = 0x80000800; // D11: Hue, Auto
public static final int PU_WB_TEMP_AUTO = 0x80001000; // D12: White Balance Temperature, Auto
public static final int PU_WB_COMPO_AUTO = 0x80002000; // D13: White Balance Component, Auto
public static final int PU_DIGITAL_MULT = 0x80004000; // D14: Digital Multiplier
public static final int PU_DIGITAL_LIMIT = 0x80008000; // D15: Digital Multiplier Limit
public static final int PU_AVIDEO_STD = 0x80010000; // D16: Analog Video Standard
public static final int PU_AVIDEO_LOCK = 0x80020000; // D17: Analog Video Lock Status
public static final int PU_CONTRAST_AUTO = 0x80040000; // D18: Contrast, Auto
// uvc_status_class from libuvc.h
public static final int STATUS_CLASS_CONTROL = 0x10;
public static final int STATUS_CLASS_CONTROL_CAMERA = 0x11;
public static final int STATUS_CLASS_CONTROL_PROCESSING = 0x12;
// uvc_status_attribute from libuvc.h
public static final int STATUS_ATTRIBUTE_VALUE_CHANGE = 0x00;
public static final int STATUS_ATTRIBUTE_INFO_CHANGE = 0x01;
public static final int STATUS_ATTRIBUTE_FAILURE_CHANGE = 0x02;
public static final int STATUS_ATTRIBUTE_UNKNOWN = 0xff;
private static boolean isLoaded;
static {
if (!isLoaded) {
System.loadLibrary("jpeg-turbo1500");
System.loadLibrary("usb100");
System.loadLibrary("uvc");
System.loadLibrary("UVCCamera");
isLoaded = true;
}
}
private UsbControlBlock mCtrlBlock;
protected long mControlSupports; // カメラコントロールでサポートしている機能フラグ
protected long mProcSupports; // プロセッシングユニットでサポートしている機能フラグ
protected int mCurrentFrameFormat = FRAME_FORMAT_MJPEG;
protected int mCurrentWidth = DEFAULT_PREVIEW_WIDTH, mCurrentHeight = DEFAULT_PREVIEW_HEIGHT;
protected float mCurrentBandwidthFactor = DEFAULT_BANDWIDTH;
protected String mSupportedSize;
protected List<Size> mCurrentSizeList;
// these fields from here are accessed from native code and do not change name and remove
protected long mNativePtr;
protected int mScanningModeMin, mScanningModeMax, mScanningModeDef;
protected int mExposureModeMin, mExposureModeMax, mExposureModeDef;
protected int mExposurePriorityMin, mExposurePriorityMax, mExposurePriorityDef;
protected int mExposureMin, mExposureMax, mExposureDef;
protected int mAutoFocusMin, mAutoFocusMax, mAutoFocusDef;
protected int mFocusMin, mFocusMax, mFocusDef;
protected int mFocusRelMin, mFocusRelMax, mFocusRelDef;
protected int mFocusSimpleMin, mFocusSimpleMax, mFocusSimpleDef;
protected int mIrisMin, mIrisMax, mIrisDef;
protected int mIrisRelMin, mIrisRelMax, mIrisRelDef;
protected int mPanMin, mPanMax, mPanDef;
protected int mTiltMin, mTiltMax, mTiltDef;
protected int mRollMin, mRollMax, mRollDef;
protected int mPanRelMin, mPanRelMax, mPanRelDef;
protected int mTiltRelMin, mTiltRelMax, mTiltRelDef;
protected int mRollRelMin, mRollRelMax, mRollRelDef;
protected int mPrivacyMin, mPrivacyMax, mPrivacyDef;
protected int mAutoWhiteBlanceMin, mAutoWhiteBlanceMax, mAutoWhiteBlanceDef;
protected int mAutoWhiteBlanceCompoMin, mAutoWhiteBlanceCompoMax, mAutoWhiteBlanceCompoDef;
protected int mWhiteBlanceMin, mWhiteBlanceMax, mWhiteBlanceDef;
protected int mWhiteBlanceCompoMin, mWhiteBlanceCompoMax, mWhiteBlanceCompoDef;
protected int mWhiteBlanceRelMin, mWhiteBlanceRelMax, mWhiteBlanceRelDef;
protected int mBacklightCompMin, mBacklightCompMax, mBacklightCompDef;
protected int mBrightnessMin, mBrightnessMax, mBrightnessDef;
protected int mContrastMin, mContrastMax, mContrastDef;
protected int mSharpnessMin, mSharpnessMax, mSharpnessDef;
protected int mGainMin, mGainMax, mGainDef;
protected int mGammaMin, mGammaMax, mGammaDef;
protected int mSaturationMin, mSaturationMax, mSaturationDef;
protected int mHueMin, mHueMax, mHueDef;
protected int mZoomMin, mZoomMax, mZoomDef;
protected int mZoomRelMin, mZoomRelMax, mZoomRelDef;
protected int mPowerlineFrequencyMin, mPowerlineFrequencyMax, mPowerlineFrequencyDef;
protected int mMultiplierMin, mMultiplierMax, mMultiplierDef;
protected int mMultiplierLimitMin, mMultiplierLimitMax, mMultiplierLimitDef;
protected int mAnalogVideoStandardMin, mAnalogVideoStandardMax, mAnalogVideoStandardDef;
protected int mAnalogVideoLockStateMin, mAnalogVideoLockStateMax, mAnalogVideoLockStateDef;
// until here
/**
* the sonctructor of this class should be call within the thread that has a looper
* (UI thread or a thread that called Looper.prepare)
*/
public UVCCamera() {
mNativePtr = nativeCreate();
mSupportedSize = null;
}
/**
* connect to a UVC camera
* USB permission is necessary before this method is called
* @param ctrlBlock
*/
public synchronized void open(final UsbControlBlock ctrlBlock) {
int result;
try {
mCtrlBlock = ctrlBlock.clone();
result = nativeConnect(mNativePtr,
mCtrlBlock.getVenderId(), mCtrlBlock.getProductId(),
mCtrlBlock.getFileDescriptor(),
mCtrlBlock.getBusNum(),
mCtrlBlock.getDevNum(),
getUSBFSName(mCtrlBlock));
} catch (final Exception e) {
Log.w(TAG, e);
result = -1;
}
if (result != 0) {
throw new UnsupportedOperationException("open failed:result=" + result);
}
if (mNativePtr != 0 && TextUtils.isEmpty(mSupportedSize)) {
mSupportedSize = nativeGetSupportedSize(mNativePtr);
}
nativeSetPreviewSize(mNativePtr, DEFAULT_PREVIEW_WIDTH, DEFAULT_PREVIEW_HEIGHT,
DEFAULT_PREVIEW_MIN_FPS, DEFAULT_PREVIEW_MAX_FPS, DEFAULT_PREVIEW_MODE, DEFAULT_BANDWIDTH);
}
/**
* set status callback
* @param callback
*/
public void setStatusCallback(final IStatusCallback callback) {
if (mNativePtr != 0) {
nativeSetStatusCallback(mNativePtr, callback);
}
}
/**
* set button callback
* @param callback
*/
public void setButtonCallback(final IButtonCallback callback) {
if (mNativePtr != 0) {
nativeSetButtonCallback(mNativePtr, callback);
}
}
/**
* close and release UVC camera
*/
public synchronized void close() {
stopPreview();
if (mNativePtr != 0) {
nativeRelease(mNativePtr);
// mNativePtr = 0; // nativeDestroyを呼ぶのでここでクリアしちゃダメ
}
if (mCtrlBlock != null) {
mCtrlBlock.close();
mCtrlBlock = null;
}
mControlSupports = mProcSupports = 0;
mCurrentFrameFormat = -1;
mCurrentBandwidthFactor = 0;
mSupportedSize = null;
mCurrentSizeList = null;
if (DEBUG) Log.v(TAG, "close:finished");
}
public UsbDevice getDevice() {
return mCtrlBlock != null ? mCtrlBlock.getDevice() : null;
}
public String getDeviceName(){
return mCtrlBlock != null ? mCtrlBlock.getDeviceName() : null;
}
public UsbControlBlock getUsbControlBlock() {
return mCtrlBlock;
}
public synchronized String getSupportedSize() {
return !TextUtils.isEmpty(mSupportedSize) ? mSupportedSize : (mSupportedSize = nativeGetSupportedSize(mNativePtr));
}
public Size getPreviewSize() {
Size result = null;
final List<Size> list = getSupportedSizeList();
for (final Size sz: list) {
if ((sz.width == mCurrentWidth)
|| (sz.height == mCurrentHeight)) {
result =sz;
break;
}
}
return result;
}
/**
* Set preview size and preview mode
* @param width
@param height
*/
public void setPreviewSize(final int width, final int height) {
setPreviewSize(width, height, DEFAULT_PREVIEW_MIN_FPS, DEFAULT_PREVIEW_MAX_FPS, mCurrentFrameFormat, mCurrentBandwidthFactor);
}
/**
* Set preview size and preview mode
* @param width
* @param height
* @param frameFormat either FRAME_FORMAT_YUYV(0) or FRAME_FORMAT_MJPEG(1)
*/
public void setPreviewSize(final int width, final int height, final int frameFormat) {
setPreviewSize(width, height, DEFAULT_PREVIEW_MIN_FPS, DEFAULT_PREVIEW_MAX_FPS, frameFormat, mCurrentBandwidthFactor);
}
/**
* Set preview size and preview mode
* @param width
@param height
@param frameFormat either FRAME_FORMAT_YUYV(0) or FRAME_FORMAT_MJPEG(1)
@param bandwidth [0.0f,1.0f]
*/
public void setPreviewSize(final int width, final int height, final int frameFormat, final float bandwidth) {
setPreviewSize(width, height, DEFAULT_PREVIEW_MIN_FPS, DEFAULT_PREVIEW_MAX_FPS, frameFormat, bandwidth);
}
/**
* Set preview size and preview mode
* @param width
* @param height
* @param min_fps
* @param max_fps
* @param frameFormat either FRAME_FORMAT_YUYV(0) or FRAME_FORMAT_MJPEG(1)
* @param bandwidthFactor
*/
public void setPreviewSize(final int width, final int height, final int min_fps, final int max_fps, final int frameFormat, final float bandwidthFactor) {
if ((width == 0) || (height == 0))
throw new IllegalArgumentException("invalid preview size");
if (mNativePtr != 0) {
final int result = nativeSetPreviewSize(mNativePtr, width, height, min_fps, max_fps, frameFormat, bandwidthFactor);
if (result != 0)
throw new IllegalArgumentException("Failed to set preview size");
mCurrentFrameFormat = frameFormat;
mCurrentWidth = width;
mCurrentHeight = height;
mCurrentBandwidthFactor = bandwidthFactor;
}
}
public List<Size> getSupportedSizeList() {
final int type = (mCurrentFrameFormat > 0) ? 6 : 4;
return getSupportedSize(type, mSupportedSize);
}
public static List<Size> getSupportedSize(final int type, final String supportedSize) {
final List<Size> result = new ArrayList<Size>();
if (!TextUtils.isEmpty(supportedSize))
try {
final JSONObject json = new JSONObject(supportedSize);
final JSONArray formats = json.getJSONArray("formats");
final int format_nums = formats.length();
for (int i = 0; i < format_nums; i++) {
final JSONObject format = formats.getJSONObject(i);
if(format.has("type") && format.has("frameDescriptors")) {
final int format_type = format.getInt("type");
if ((format_type == type) || (type == -1)) {
addSize(format, format_type, 0, result);
}
}
}
} catch (final JSONException e) {
e.printStackTrace();
}
return result;
}
private static final void addSize(final JSONObject format, final int formatType, final int frameType, final List<Size> size_list) throws JSONException {
final JSONArray frameDescriptors = format.getJSONArray("frameDescriptors");
final int size_nums = frameDescriptors.length();
for (int j = 0; j < size_nums; j++) {
try {
final JSONObject descriptor = frameDescriptors.getJSONObject(j);
final int width = descriptor.getInt("width");
final int height = descriptor.getInt("height");
final JSONArray intervalArray = descriptor.getJSONArray("intervals");
final int intervalCount = intervalArray.length();
final int[] intervals = new int[intervalCount];
for (int k = 0; k < intervalCount; k++) {
final JSONObject interval = intervalArray.getJSONObject(k);
intervals[k] = interval.getInt("value");
}
size_list.add(new Size(formatType, frameType, j, width, height, intervals));
} catch (final Exception e) {
break;
}
}
}
/**
* set preview surface with SurfaceHolder</br>
* you can use SurfaceHolder came from SurfaceView/GLSurfaceView
* @param holder
*/
public synchronized void setPreviewDisplay(final SurfaceHolder holder) {
nativeSetPreviewDisplay(mNativePtr, holder.getSurface());
}
/**
* set preview surface with SurfaceTexture.
* this method require API >= 14
* @param texture
*/
public synchronized void setPreviewTexture(final SurfaceTexture texture) { // API >= 11
final Surface surface = new Surface(texture); // XXX API >= 14
nativeSetPreviewDisplay(mNativePtr, surface);
}
/**
* set preview surface with Surface
* @param surface
*/
public synchronized void setPreviewDisplay(final Surface surface) {
nativeSetPreviewDisplay(mNativePtr, surface);
}
/**
* set frame callback
* @param callback
* @param pixelFormat
*/
public void setFrameCallback(final IFrameCallback callback, final int pixelFormat) {
if (mNativePtr != 0) {
nativeSetFrameCallback(mNativePtr, callback, pixelFormat);
}
}
/**
* start preview
*/
public synchronized void startPreview() {
if (mCtrlBlock != null) {
nativeStartPreview(mNativePtr);
}
}
/**
* stop preview
*/
public synchronized void stopPreview() {
setFrameCallback(null, 0);
if (mCtrlBlock != null) {
nativeStopPreview(mNativePtr);
}
}
/**
* destroy UVCCamera object
*/
public synchronized void destroy() {
close();
if (mNativePtr != 0) {
nativeDestroy(mNativePtr);
mNativePtr = 0;
}
}
// wrong result may return when you call this just after camera open.
// it is better to wait several hundreads millseconds.
public boolean checkSupportFlag(final long flag) {
updateCameraParams();
if ((flag & 0x80000000) == 0x80000000)
return ((mProcSupports & flag) == (flag & 0x7ffffffF));
else
return (mControlSupports & flag) == flag;
}
//================================================================================
public synchronized void setAutoFocus(final boolean autoFocus) {
if (mNativePtr != 0) {
nativeSetAutoFocus(mNativePtr, autoFocus);
}
}
public synchronized boolean getAutoFocus() {
boolean result = true;
if (mNativePtr != 0) {
result = nativeGetAutoFocus(mNativePtr) > 0;
}
return result;
}
//================================================================================
/**
* @param focus [%]
*/
public synchronized void setFocus(final int focus) {
if (mNativePtr != 0) {
final float range = Math.abs(mFocusMax - mFocusMin);
if (range > 0)
nativeSetFocus(mNativePtr, (int)(focus / 100.f * range) + mFocusMin);
}
}
/**
* @param focus_abs
* @return focus[%]
*/
public synchronized int getFocus(final int focus_abs) {
int result = 0;
if (mNativePtr != 0) {
nativeUpdateFocusLimit(mNativePtr);
final float range = Math.abs(mFocusMax - mFocusMin);
if (range > 0) {
result = (int)((focus_abs - mFocusMin) * 100.f / range);
}
}
return result;
}
/**
* @return focus[%]
*/
public synchronized int getFocus() {
return getFocus(nativeGetFocus(mNativePtr));
}
public synchronized void resetFocus() {
if (mNativePtr != 0) {
nativeSetFocus(mNativePtr, mFocusDef);
}
}
//================================================================================
public synchronized void setAutoWhiteBlance(final boolean autoWhiteBlance) {
if (mNativePtr != 0) {
nativeSetAutoWhiteBlance(mNativePtr, autoWhiteBlance);
}
}
public synchronized boolean getAutoWhiteBlance() {
boolean result = true;
if (mNativePtr != 0) {
result = nativeGetAutoWhiteBlance(mNativePtr) > 0;
}
return result;
}
//================================================================================
/**
* @param whiteBlance [%]
*/
public synchronized void setWhiteBlance(final int whiteBlance) {
if (mNativePtr != 0) {
final float range = Math.abs(mWhiteBlanceMax - mWhiteBlanceMin);
if (range > 0)
nativeSetWhiteBlance(mNativePtr, (int)(whiteBlance / 100.f * range) + mWhiteBlanceMin);
}
}
/**
* @param whiteBlance_abs
* @return whiteBlance[%]
*/
public synchronized int getWhiteBlance(final int whiteBlance_abs) {
int result = 0;
if (mNativePtr != 0) {
nativeUpdateWhiteBlanceLimit(mNativePtr);
final float range = Math.abs(mWhiteBlanceMax - mWhiteBlanceMin);
if (range > 0) {
result = (int)((whiteBlance_abs - mWhiteBlanceMin) * 100.f / range);
}
}
return result;
}
/**
* @return white blance[%]
*/
public synchronized int getWhiteBlance() {
return getFocus(nativeGetWhiteBlance(mNativePtr));
}
public synchronized void resetWhiteBlance() {
if (mNativePtr != 0) {
nativeSetWhiteBlance(mNativePtr, mWhiteBlanceDef);
}
}
//================================================================================
/**
* @param brightness [%]
*/
public synchronized void setBrightness(final int brightness) {
if (mNativePtr != 0) {
final float range = Math.abs(mBrightnessMax - mBrightnessMin);
if (range > 0)
nativeSetBrightness(mNativePtr, (int)(brightness / 100.f * range) + mBrightnessMin);
}
}
/**
* @param brightness_abs
* @return brightness[%]
*/
public synchronized int getBrightness(final int brightness_abs) {
int result = 0;
if (mNativePtr != 0) {
nativeUpdateBrightnessLimit(mNativePtr);
final float range = Math.abs(mBrightnessMax - mBrightnessMin);
if (range > 0) {
result = (int)((brightness_abs - mBrightnessMin) * 100.f / range);
}
}
return result;
}
/**
* @return brightness[%]
*/
public synchronized int getBrightness() {
return getBrightness(nativeGetBrightness(mNativePtr));
}
public synchronized void resetBrightness() {
if (mNativePtr != 0) {
nativeSetBrightness(mNativePtr, mBrightnessDef);
}
}
//================================================================================
/**
* @param contrast [%]
*/
public synchronized void setContrast(final int contrast) {
if (mNativePtr != 0) {
nativeUpdateContrastLimit(mNativePtr);
final float range = Math.abs(mContrastMax - mContrastMin);
if (range > 0)
nativeSetContrast(mNativePtr, (int)(contrast / 100.f * range) + mContrastMin);
}
}
/**
* @param contrast_abs
* @return contrast[%]
*/
public synchronized int getContrast(final int contrast_abs) {
int result = 0;
if (mNativePtr != 0) {
final float range = Math.abs(mContrastMax - mContrastMin);
if (range > 0) {
result = (int)((contrast_abs - mContrastMin) * 100.f / range);
}
}
return result;
}
/**
* @return contrast[%]
*/
public synchronized int getContrast() {
return getContrast(nativeGetContrast(mNativePtr));
}
public synchronized void resetContrast() {
if (mNativePtr != 0) {
nativeSetContrast(mNativePtr, mContrastDef);
}
}
//================================================================================
/**
* @param sharpness [%]
*/
public synchronized void setSharpness(final int sharpness) {
if (mNativePtr != 0) {
final float range = Math.abs(mSharpnessMax - mSharpnessMin);
if (range > 0)
nativeSetSharpness(mNativePtr, (int)(sharpness / 100.f * range) + mSharpnessMin);
}
}
/**
* @param sharpness_abs
* @return sharpness[%]
*/
public synchronized int getSharpness(final int sharpness_abs) {
int result = 0;
if (mNativePtr != 0) {
nativeUpdateSharpnessLimit(mNativePtr);
final float range = Math.abs(mSharpnessMax - mSharpnessMin);
if (range > 0) {
result = (int)((sharpness_abs - mSharpnessMin) * 100.f / range);
}
}
return result;
}
/**
* @return sharpness[%]
*/
public synchronized int getSharpness() {
return getSharpness(nativeGetSharpness(mNativePtr));
}
public synchronized void resetSharpness() {
if (mNativePtr != 0) {
nativeSetSharpness(mNativePtr, mSharpnessDef);
}
}
//================================================================================
/**
* @param gain [%]
*/
public synchronized void setGain(final int gain) {
if (mNativePtr != 0) {
final float range = Math.abs(mGainMax - mGainMin);
if (range > 0)
nativeSetGain(mNativePtr, (int)(gain / 100.f * range) + mGainMin);
}
}
/**
* @param gain_abs
* @return gain[%]
*/
public synchronized int getGain(final int gain_abs) {
int result = 0;
if (mNativePtr != 0) {
nativeUpdateGainLimit(mNativePtr);
final float range = Math.abs(mGainMax - mGainMin);
if (range > 0) {
result = (int)((gain_abs - mGainMin) * 100.f / range);
}
}
return result;
}
/**
* @return gain[%]
*/
public synchronized int getGain() {
return getGain(nativeGetGain(mNativePtr));
}
public synchronized void resetGain() {
if (mNativePtr != 0) {
nativeSetGain(mNativePtr, mGainDef);
}
}
//================================================================================
/**
* @param gamma [%]
*/
public synchronized void setGamma(final int gamma) {
if (mNativePtr != 0) {
final float range = Math.abs(mGammaMax - mGammaMin);
if (range > 0)
nativeSetGamma(mNativePtr, (int)(gamma / 100.f * range) + mGammaMin);
}
}
/**
* @param gamma_abs
* @return gamma[%]
*/
public synchronized int getGamma(final int gamma_abs) {
int result = 0;
if (mNativePtr != 0) {
nativeUpdateGammaLimit(mNativePtr);
final float range = Math.abs(mGammaMax - mGammaMin);
if (range > 0) {
result = (int)((gamma_abs - mGammaMin) * 100.f / range);
}
}
return result;
}
/**
* @return gamma[%]
*/
public synchronized int getGamma() {
return getGamma(nativeGetGamma(mNativePtr));
}
public synchronized void resetGamma() {
if (mNativePtr != 0) {
nativeSetGamma(mNativePtr, mGammaDef);
}
}
//================================================================================
/**
* @param saturation [%]
*/
public synchronized void setSaturation(final int saturation) {
if (mNativePtr != 0) {
final float range = Math.abs(mSaturationMax - mSaturationMin);
if (range > 0)
nativeSetSaturation(mNativePtr, (int)(saturation / 100.f * range) + mSaturationMin);
}
}
/**
* @param saturation_abs
* @return saturation[%]
*/
public synchronized int getSaturation(final int saturation_abs) {
int result = 0;
if (mNativePtr != 0) {
nativeUpdateSaturationLimit(mNativePtr);
final float range = Math.abs(mSaturationMax - mSaturationMin);
if (range > 0) {
result = (int)((saturation_abs - mSaturationMin) * 100.f / range);
}
}
return result;
}
/**
* @return saturation[%]
*/
public synchronized int getSaturation() {
return getSaturation(nativeGetSaturation(mNativePtr));
}
public synchronized void resetSaturation() {
if (mNativePtr != 0) {
nativeSetSaturation(mNativePtr, mSaturationDef);
}
}
//================================================================================
/**
* @param hue [%]
*/
public synchronized void setHue(final int hue) {
if (mNativePtr != 0) {
final float range = Math.abs(mHueMax - mHueMin);
if (range > 0)
nativeSetHue(mNativePtr, (int)(hue / 100.f * range) + mHueMin);
}
}
/**
* @param hue_abs
* @return hue[%]
*/
public synchronized int getHue(final int hue_abs) {
int result = 0;
if (mNativePtr != 0) {
nativeUpdateHueLimit(mNativePtr);
final float range = Math.abs(mHueMax - mHueMin);
if (range > 0) {
result = (int)((hue_abs - mHueMin) * 100.f / range);
}
}
return result;
}
/**
* @return hue[%]
*/
public synchronized int getHue() {
return getHue(nativeGetHue(mNativePtr));
}
public synchronized void resetHue() {
if (mNativePtr != 0) {
nativeSetHue(mNativePtr, mSaturationDef);
}
}
//================================================================================
public void setPowerlineFrequency(final int frequency) {
if (mNativePtr != 0)
nativeSetPowerlineFrequency(mNativePtr, frequency);
}
public int getPowerlineFrequency() {
return nativeGetPowerlineFrequency(mNativePtr);
}
//================================================================================
/**
* this may not work well with some combination of camera and device
* @param zoom [%]
*/
public synchronized void setZoom(final int zoom) {
if (mNativePtr != 0) {
final float range = Math.abs(mZoomMax - mZoomMin);
if (range > 0) {
final int z = (int)(zoom / 100.f * range) + mZoomMin;
// Log.d(TAG, "setZoom:zoom=" + zoom + " ,value=" + z);
nativeSetZoom(mNativePtr, z);
}
}
}
/**
* @param zoom_abs
* @return zoom[%]
*/
public synchronized int getZoom(final int zoom_abs) {
int result = 0;
if (mNativePtr != 0) {
nativeUpdateZoomLimit(mNativePtr);
final float range = Math.abs(mZoomMax - mZoomMin);
if (range > 0) {
result = (int)((zoom_abs - mZoomMin) * 100.f / range);
}
}
return result;
}
/**
* @return zoom[%]
*/
public synchronized int getZoom() {
return getZoom(nativeGetZoom(mNativePtr));
}
public synchronized void resetZoom() {
if (mNativePtr != 0) {
nativeSetZoom(mNativePtr, mZoomDef);
}
}
//================================================================================
public synchronized void updateCameraParams() {
if (mNativePtr != 0) {
if ((mControlSupports == 0) || (mProcSupports == 0)) {
// サポートしている機能フラグを取得
if (mControlSupports == 0)
mControlSupports = nativeGetCtrlSupports(mNativePtr);
if (mProcSupports == 0)
mProcSupports = nativeGetProcSupports(mNativePtr);
// 設定値を取得
if ((mControlSupports != 0) && (mProcSupports != 0)) {
nativeUpdateBrightnessLimit(mNativePtr);
nativeUpdateContrastLimit(mNativePtr);
nativeUpdateSharpnessLimit(mNativePtr);
nativeUpdateGainLimit(mNativePtr);
nativeUpdateGammaLimit(mNativePtr);
nativeUpdateSaturationLimit(mNativePtr);
nativeUpdateHueLimit(mNativePtr);
nativeUpdateZoomLimit(mNativePtr);
nativeUpdateWhiteBlanceLimit(mNativePtr);
nativeUpdateFocusLimit(mNativePtr);
}
if (DEBUG) {
dumpControls(mControlSupports);
dumpProc(mProcSupports);
Log.v(TAG, String.format("Brightness:min=%d,max=%d,def=%d", mBrightnessMin, mBrightnessMax, mBrightnessDef));
Log.v(TAG, String.format("Contrast:min=%d,max=%d,def=%d", mContrastMin, mContrastMax, mContrastDef));
Log.v(TAG, String.format("Sharpness:min=%d,max=%d,def=%d", mSharpnessMin, mSharpnessMax, mSharpnessDef));
Log.v(TAG, String.format("Gain:min=%d,max=%d,def=%d", mGainMin, mGainMax, mGainDef));
Log.v(TAG, String.format("Gamma:min=%d,max=%d,def=%d", mGammaMin, mGammaMax, mGammaDef));
Log.v(TAG, String.format("Saturation:min=%d,max=%d,def=%d", mSaturationMin, mSaturationMax, mSaturationDef));
Log.v(TAG, String.format("Hue:min=%d,max=%d,def=%d", mHueMin, mHueMax, mHueDef));
Log.v(TAG, String.format("Zoom:min=%d,max=%d,def=%d", mZoomMin, mZoomMax, mZoomDef));
Log.v(TAG, String.format("WhiteBlance:min=%d,max=%d,def=%d", mWhiteBlanceMin, mWhiteBlanceMax, mWhiteBlanceDef));
Log.v(TAG, String.format("Focus:min=%d,max=%d,def=%d", mFocusMin, mFocusMax, mFocusDef));
}
}
} else {
mControlSupports = mProcSupports = 0;
}
}
private static final String[] SUPPORTS_CTRL = {
"D0: Scanning Mode",
"D1: Auto-Exposure Mode",
"D2: Auto-Exposure Priority",
"D3: Exposure Time (Absolute)",
"D4: Exposure Time (Relative)",
"D5: Focus (Absolute)",
"D6: Focus (Relative)",
"D7: Iris (Absolute)",
"D8: Iris (Relative)",
"D9: Zoom (Absolute)",
"D10: Zoom (Relative)",
"D11: PanTilt (Absolute)",
"D12: PanTilt (Relative)",
"D13: Roll (Absolute)",
"D14: Roll (Relative)",
"D15: Reserved",
"D16: Reserved",
"D17: Focus, Auto",
"D18: Privacy",
"D19: Focus, Simple",
"D20: Window",
"D21: Region of Interest",
"D22: Reserved, set to zero",
"D23: Reserved, set to zero",
};
private static final String[] SUPPORTS_PROC = {
"D0: Brightness",
"D1: Contrast",
"D2: Hue",
"D3: Saturation",
"D4: Sharpness",
"D5: Gamma",
"D6: White Balance Temperature",
"D7: White Balance Component",
"D8: Backlight Compensation",
"D9: Gain",
"D10: Power Line Frequency",
"D11: Hue, Auto",
"D12: White Balance Temperature, Auto",
"D13: White Balance Component, Auto",
"D14: Digital Multiplier",
"D15: Digital Multiplier Limit",
"D16: Analog Video Standard",