| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
package org.pjsip; |
| 19 |
|
| 20 |
import java.util.List; |
| 21 |
|
| 22 |
import android.hardware.Camera; |
| 23 |
import android.util.Log; |
| 24 |
|
| 25 |
public class PjCameraInfo { |
| 26 |
public int facing; |
| 27 |
public int orient; |
| 28 |
public int[] supportedSize; |
| 29 |
public int[] supportedFps1000; |
| 30 |
public int[] supportedFormat; |
| 31 |
|
| 32 |
|
| 33 |
private static int[] IntegerListToIntArray(List<Integer> list) |
| 34 |
{ |
| 35 |
int[] li = new int[list.size()]; |
| 36 |
int i = 0; |
| 37 |
for (Integer e : list) { |
| 38 |
li[i++] = e.intValue(); |
| 39 |
} |
| 40 |
return li; |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
private static int[] IntArrayListToIntArray(List<int[]> list) |
| 46 |
{ |
| 47 |
int[] li = new int[list.size() * 2]; |
| 48 |
int i = 0; |
| 49 |
for (int[] e : list) { |
| 50 |
li[i++] = e[0]; |
| 51 |
li[i++] = e[1]; |
| 52 |
} |
| 53 |
return li; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
private static int[] CameraSizeListToIntArray(List<Camera.Size> list) |
| 58 |
{ |
| 59 |
int[] li = new int[list.size() * 2]; |
| 60 |
int i = 0; |
| 61 |
for (Camera.Size e : list) { |
| 62 |
li[i++] = e.width; |
| 63 |
li[i++] = e.height; |
| 64 |
} |
| 65 |
return li; |
| 66 |
} |
| 67 |
|
| 68 |
public static int GetCameraCount() |
| 69 |
{ |
| 70 |
return Camera.getNumberOfCameras(); |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
public static PjCameraInfo GetCameraInfo(int idx) |
| 76 |
{ |
| 77 |
if (idx < 0 || idx >= GetCameraCount()) |
| 78 |
return null; |
| 79 |
|
| 80 |
Camera cam; |
| 81 |
try { |
| 82 |
cam = Camera.open(idx); |
| 83 |
} catch (Exception e) { |
| 84 |
Log.d("IOException", e.getMessage()); |
| 85 |
return null; |
| 86 |
} |
| 87 |
|
| 88 |
PjCameraInfo pjci = new PjCameraInfo(); |
| 89 |
|
| 90 |
Camera.CameraInfo ci = new Camera.CameraInfo(); |
| 91 |
Camera.getCameraInfo(idx, ci); |
| 92 |
|
| 93 |
pjci.facing = ci.facing; |
| 94 |
pjci.orient = ci.orientation; |
| 95 |
|
| 96 |
Camera.Parameters param = cam.getParameters(); |
| 97 |
cam.release(); |
| 98 |
cam = null; |
| 99 |
|
| 100 |
pjci.supportedFormat = IntegerListToIntArray( |
| 101 |
param.getSupportedPreviewFormats()); |
| 102 |
pjci.supportedFps1000 = IntArrayListToIntArray( |
| 103 |
param.getSupportedPreviewFpsRange()); |
| 104 |
pjci.supportedSize = CameraSizeListToIntArray( |
| 105 |
param.getSupportedPreviewSizes()); |
| 106 |
|
| 107 |
return pjci; |
| 108 |
} |
| 109 |
} |