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 f1fbf1c714
commit 8b4cbbfcc5
7 changed files with 221 additions and 95 deletions

View file

@ -188,7 +188,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
lLinphoneCore.terminateCall(lLinphoneCore.getCurrentCall());
Toast toast = Toast.makeText(DialerActivity.this
,String.format(getString(R.string.warning_wrong_destination_address),mAddress.getText().toString())
, Toast.LENGTH_LONG);
,Toast.LENGTH_LONG);
toast.show();
}
return;
@ -220,11 +220,11 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
mInCallAddressLayout = (View) findViewById(R.id.IncallAddressLayout);
mMute = (ToggleImageButton)findViewById(R.id.mic_mute_button);
mSpeaker = (ToggleImageButton)findViewById(R.id.speaker_button);
if (Build.DEVICE.startsWith("GT-I9000")) {
/* if (Hacks.isGalaxyS()) {
// Galaxy S doesn't handle audio routing properly
// so disabling it totally
mSpeaker.setVisibility(View.GONE);
}
}*/
mInCallControlRow.setVisibility(View.GONE);
mInCallAddressLayout.setVisibility(View.GONE);
mDecline.setEnabled(false);
@ -564,9 +564,9 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
private void resetCameraFromPreferences() {
boolean useFrontCam = mPref.getBoolean(getString(R.string.pref_video_use_front_camera_key), false);
AndroidCameraRecordManager.getInstance().setUseFrontCamera(useFrontCam);
getVideoManager().setUseFrontCamera(useFrontCam);
final int phoneOrientation = 90 * getWindowManager().getDefaultDisplay().getOrientation();
AndroidCameraRecordManager.getInstance().setPhoneOrientation(phoneOrientation);
getVideoManager().setPhoneOrientation(phoneOrientation);
}
private void exitCallMode() {
@ -610,7 +610,8 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL);
} else {
mAudioManager.setSpeakerphoneOn(false);
}
}
LinphoneCore lLinphoneCore = LinphoneService.instance().getLinphoneCore();
if (lLinphoneCore.isIncall()) {
//Restore default value

View file

@ -0,0 +1,72 @@
/*
Hacks.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;
import android.media.AudioManager;
import android.os.Build;
import android.util.Log;
public class Hacks {
public static boolean isGalaxyS() {
return Build.DEVICE.startsWith("GT-I9000") || Build.DEVICE.startsWith("GT-P1000");
}
/* private static final boolean log(final String msg) {
Log.d("Linphone", msg);
return true;
}*/
/* Not working as now
* Calling from Galaxy S to PC is "usable" even with no hack; other side is not even with this one*/
public static void galaxySSwitchToCallStreamUnMuteLowerVolume(AudioManager am) {
// Switch to call audio channel (Galaxy S)
am.setSpeakerphoneOn(false);
sleep(200);
// Lower volume
am.setStreamVolume(AudioManager.STREAM_VOICE_CALL, 1, 0);
// Another way to select call channel
am.setMode(AudioManager.MODE_NORMAL);
sleep(200);
// Mic is muted if not doing this
am.setMicrophoneMute(true);
sleep(200);
am.setMicrophoneMute(false);
sleep(200);
}
private static final void sleep(int time) {
try {
Thread.sleep(time);
} catch(InterruptedException ie){}
}
public static void dumpDeviceInformation() {
StringBuilder sb = new StringBuilder(" ==== Phone information dump ====\n");
sb.append("DEVICE=").append(Build.DEVICE).append("\n");
sb.append("MODEL=").append(Build.MODEL).append("\n");
sb.append("MANUFACTURER=").append(Build.MANUFACTURER).append("\n");
sb.append("SDK=").append(Build.VERSION.SDK);
Log.d("Linphone", sb.toString());
}
}

View file

@ -104,6 +104,9 @@ public class LinphoneService extends Service implements LinphoneCoreListener {
super.onCreate();
theLinphone = this;
// Dump some debugging information to the logs
Hacks.dumpDeviceInformation();
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotification = new Notification(R.drawable.status_level
, ""

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;
}
}

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);