Fix cameraID=0 on Galaxy tab GT-P1000.

Move sdk9 code from Video manager to dedicated class to avoid dalvik errors.
Add phone information dump at Linphone startup.
Add "Hack" class to centralize call to hackish code.
This commit is contained in:
Guillaume Beraudo 2011-01-25 15:45:15 +01:00
parent ed6a5bf841
commit 7f43336078
4 changed files with 139 additions and 89 deletions

77
AndroidCameraConf.java Normal file
View file

@ -0,0 +1,77 @@
/*
AndroidCameraConf.java
Copyright (C) 2010 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.linphone.core;
import org.linphone.Hacks;
import android.util.Log;
public class AndroidCameraConf {
private static final String tag = "Linphone";
public void findFrontAndRearCameraIds(Integer frontCameraId, Integer rearCameraId, Integer cameraId) {
if (Hacks.isGalaxyS()) {
Log.d(tag, "Hack Galaxy S : has 2 cameras front=2; rear=1");
frontCameraId = 2;
rearCameraId = 1;
cameraId = rearCameraId;
return;
}
// default to 0/0
}
public int getNumberOfCameras() {
// Use hacks to guess the number of cameras
if (Hacks.isGalaxyS()) {
Log.d(tag, "Hack Galaxy S : has 2 cameras");
return 2;
} else
return 1;
}
public int getCameraOrientation(int cameraId) {
// Use hacks to guess orientation of the camera
if (cameraId == 2 && Hacks.isGalaxyS()) {
Log.d(tag, "Hack Galaxy S : rear camera id=2 ; mounted landscape");
// mounted in landscape for a portrait phone orientation
return 90;
}
return 0;
}
public boolean isFrontCamera(int cameraId) {
// Use hacks to guess facing of the camera
if (cameraId == 2 && Hacks.isGalaxyS()) {
Log.d(tag, "Hack Galaxy S : front camera has id=2");
return true;
}
return false;
}
}

50
AndroidCameraConf9.java Normal file
View file

@ -0,0 +1,50 @@
/*
AndroidCameraConf9.java
Copyright (C) 2010 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.linphone.core;
import android.hardware.Camera;
public class AndroidCameraConf9 extends AndroidCameraConf {
public void findFrontAndRearCameraIds9(Integer frontCameraId, Integer rearCameraId, Integer cameraId) {
for (int id=0; id < getNumberOfCameras(); id++) {
if (isFrontCamera(id)) {
frontCameraId = id;
} else {
rearCameraId = id;
}
}
}
public int getNumberOfCameras() {
return Camera.getNumberOfCameras();
}
public int getCameraOrientation(int cameraId) {
android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
Camera.getCameraInfo(cameraId, info);
return info.orientation;
}
public boolean isFrontCamera(int cameraId) {
android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
Camera.getCameraInfo(cameraId, info);
return info.facing == android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT ? true : false;
}
}

View file

@ -22,9 +22,7 @@ import java.util.List;
import org.linphone.core.AndroidCameraRecord.RecorderParams;
import android.hardware.Camera;
import android.hardware.Camera.Size;
import android.os.Build;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
@ -53,6 +51,7 @@ public class AndroidCameraRecordManager {
}
private AndroidCameraRecord.RecorderParams parameters;
private final AndroidCameraConf cc;
private SurfaceView surfaceView;
private boolean muted;
private int cameraId;
@ -68,36 +67,15 @@ public class AndroidCameraRecordManager {
// singleton
private AndroidCameraRecordManager() {
findFrontAndRearCameraIds();
cc = Version.sdkAbove(9) ? new AndroidCameraConf9() : new AndroidCameraConf();
Integer fId = -1;Integer rId = -1;Integer cId = -1;
cc.findFrontAndRearCameraIds(fId, rId, cId);
frontCameraId=fId;rearCameraId=rId;cameraId=cId;
}
private void findFrontAndRearCameraIds() {
if (Version.sdkAbove(9)) {
findFrontAndRearCameraIds9();
return;
}
if (Build.DEVICE.startsWith("GT-I9000")) {
// Galaxy S has 2 cameras
frontCameraId = 2;
rearCameraId = 1;
cameraId = rearCameraId;
return;
}
// default to 0/0
}
private void findFrontAndRearCameraIds9() {
for (int id=0; id < getNumberOfCameras9(); id++) {
if (isFrontCamera9(id)) {
frontCameraId = id;
} else {
rearCameraId = id;
}
}
}
public boolean hasSeveralCameras() {
return frontCameraId != rearCameraId;
@ -105,14 +83,14 @@ public class AndroidCameraRecordManager {
public void setUseFrontCamera(boolean value) {
if (isFrontCamera() == value) return; // already OK
if (cc.isFrontCamera(cameraId) == value) return; // already OK
toggleUseFrontCamera();
}
public boolean isUseFrontCamera() {return isFrontCamera();}
public boolean isUseFrontCamera() {return cc.isFrontCamera(cameraId);}
public boolean toggleUseFrontCamera() {
boolean previousUseFront = isFrontCamera();
boolean previousUseFront = cc.isFrontCamera(cameraId);
cameraId = previousUseFront ? rearCameraId : frontCameraId;
@ -265,69 +243,16 @@ public class AndroidCameraRecordManager {
public static int getNumberOfCameras() {
if (Version.sdkAbove(9)) return getNumberOfCameras9();
// Use hacks to guess the number of cameras
if (Build.DEVICE.startsWith("GT-I9000")) {
// Galaxy S has 2 cameras
return 2;
} else
return 1;
}
private static int getNumberOfCameras9() {
return Camera.getNumberOfCameras();
}
public boolean isCameraOrientationPortrait() {
return (getCameraOrientation() % 180) == 90;
}
public int getCameraOrientation() {
if (Version.sdkAbove(9)) return getCameraOrientation9();
// Use hacks to guess orientation of the camera
if (cameraId == 2 && Build.DEVICE.startsWith("GT-I9000")) {
// Galaxy S rear camera
// mounted in landscape for a portrait phone orientation
return 90;
}
return 0;
return (cc.getCameraOrientation(cameraId) % 180) == 90;
}
private int getCameraOrientation9() {
android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
Camera.getCameraInfo(cameraId, info);
return info.orientation;
}
public boolean isFrontCamera() {
if (Version.sdkAbove(9)) return isFrontCamera9();
// Use hacks to guess facing of the camera
if (cameraId == 2 && Build.DEVICE.startsWith("GT-I9000")) {
return true;
}
return false;
}
private boolean isFrontCamera9() {
return isFrontCamera9(cameraId);
}
private boolean isFrontCamera9(int cameraId) {
android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
Camera.getCameraInfo(cameraId, info);
return info.facing == android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT ? true : false;
}
private int bufferRotationForCorrectImageOrientation() {
final int cameraOrientation = getCameraOrientation();
final int cameraOrientation = cc.getCameraOrientation(cameraId);
final int rotation = Version.sdkAbove(8) ?
(360 - cameraOrientation + 90 - phoneOrientation) % 360
: 0;

View file

@ -90,8 +90,6 @@ class LinphoneCoreImpl implements LinphoneCore {
private native long[] listVideoPayloadTypes(long nativePtr);
private static final String TAG = "LinphoneCore";
LinphoneCoreImpl(LinphoneCoreListener listener, File userConfig,File factoryConfig,Object userdata) throws IOException {
mListener=listener;
nativePtr = newLinphoneCore(listener,userConfig.getCanonicalPath(),factoryConfig.getCanonicalPath(),userdata);