Debian Codegraph @

Xpjproject/pjmedia/src/pjmedia-videodev/android/PjCameraInfo.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2015 Teluu Inc. (http://www.teluu.com)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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; // [w1, h1, w2, h2, ...]
29 public int[] supportedFps1000; // [min1, max1, min2, max2, ...]
30 public int[] supportedFormat; // [fmt1, fmt2, ...]
31
32 // convert Format list {fmt1, fmt2, ...} to [fmt1, fmt2, ...]
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 // convert Fps list {[min1, max1], [min2, max2], ...} to
44 // [min1, max1, min2, max2, ...]
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 // convert Size list {{w1, h1}, {w2, h2}, ...} to [w1, h1, w2, h2, ...]
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 // Get camera info: facing, orientation, supported size/fps/format.
74 // Camera must not be opened.
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 }