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
|
/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.android.incallui;
import android.graphics.SurfaceTexture;
import android.util.Log;
/**
* The class is used to hold an {@code android.hardware.Camera} instance.
* <p>
* The {@code open()} and {@code release()} calls are similar to the ones in
* {@code android.hardware.Camera}.
*/
public class ImsCamera {
private static final String TAG = "VideoCallImsCamera";
private static final boolean DBG = true;
private static final short IMS_CAMERA_OPERATION_SUCCESS = 0;
static {
System.loadLibrary("imscamera_jni");
}
public static native short native_open(int cameraId);
public native short native_release();
public native short native_startPreview();
public native short native_stopPreview();
public native short native_startRecording();
public native short native_stopRecording();
public native short native_setPreviewTexture(SurfaceTexture st);
public native short native_setDisplayOrientation(int rotation);
public native boolean native_isZoomSupported();
public native int native_getMaxZoom();
public native void native_setZoom(int zoomValue);
public native short native_setPreviewSize(int width, int height);
public native short native_setPreviewFpsRange(short fps);
public static ImsCamera open(int cameraId) throws Exception {
Log.d(TAG, "open cameraId=" + cameraId);
short error = native_open(cameraId);
if (error != IMS_CAMERA_OPERATION_SUCCESS) {
Log.e(TAG, "open cameraId=" + cameraId + " failed with error=" + error);
throw new Exception();
} else {
return new ImsCamera();
}
}
public short release() {
if(DBG) log("release");
short error = native_release();
logIfError("release", error);
return error;
}
public short startPreview() {
if (DBG) log("startPreview");
short error = native_startPreview();
logIfError("startPreview", error);
return error;
}
public short stopPreview() {
if(DBG) log("stopPreview");
short error = native_stopPreview();
logIfError("stopPreview", error);
return error;
}
public short startRecording() {
if(DBG) log("startRecording");
short error = native_startRecording();
logIfError("startRecording", error);
return error;
}
public short stopRecording() {
if(DBG) log("stopRecording");
short error = native_stopRecording();
logIfError("stopRecording", error);
return error;
}
public short setPreviewTexture(SurfaceTexture st) {
if(DBG) log("setPreviewTexture");
short error = native_setPreviewTexture(st);
logIfError("setPreviewTexture", error);
return error;
}
public short setDisplayOrientation(int rotation) {
if(DBG) log("setDisplayOrientation rotation=" + rotation);
short error = native_setDisplayOrientation(rotation);
logIfError("setDisplayOrientation", error);
return error;
}
public boolean isZoomSupported() {
boolean result = native_isZoomSupported();
if(DBG) log("isZoomSupported result=" + result);
return result;
}
public int getMaxZoom() {
int result = native_getMaxZoom();
if(DBG) log("getMaxZoom result = " + result);
return result;
}
public void setZoom(int zoomValue) {
if (DBG) log("setZoom " + zoomValue);
native_setZoom(zoomValue);
}
public short setPreviewSize(int width, int height) {
if(DBG) log("setPreviewSize");
short error = native_setPreviewSize(width, height);
logIfError("setPreviewSize", error);
return error;
}
public short setPreviewFpsRange(short fps) {
if(DBG) log("setPreviewFpsRange");
short error = native_setPreviewFpsRange(fps);
logIfError("setPreviewFpsRange", error);
return error;
}
private void log(String msg) {
Log.d(TAG, msg);
}
private void loge(String msg) {
Log.e(TAG, msg);
}
private void logIfError(String methodName, short error) {
if (error != IMS_CAMERA_OPERATION_SUCCESS) {
loge(methodName + " failed with error=" + error);
}
}
}
|