android: improved Java integration

parent bc0532c0
......@@ -94,7 +94,7 @@ public class MediastreamerActivity extends Activity {
previewSurface.setZOrderOnTop(true);
/* instanciate object responsible of video rendering */
mVideoWindow = new AndroidVideoWindowImpl(this, view, previewSurface);
mVideoWindow = new AndroidVideoWindowImpl(view, previewSurface);
mVideoWindow
.setListener(new AndroidVideoWindowImpl.VideoWindowListener() {
......@@ -115,12 +115,6 @@ public class MediastreamerActivity extends Activity {
setDeviceRotation(rotationToAngle(getWindowManager().getDefaultDisplay()
.getRotation()));
}
@Override
public void onDeviceOrientationChanged(
int rotationDegrees) {
setDeviceRotation(rotationDegrees);
}
});
mVideoWindow.init();
......
/*
AndroidCameraRecordManager.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.mediastream.video.capture;
import org.linphone.LinphoneManager;
import org.linphone.core.Log;
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration.AndroidCamera;
/**
* Provide simple API to the applications to manage camera selection
*
* @author Guillaume Beraudo
*
*/
public class AndroidCameraPreferences {
// current camera
public static int cameraId = 0;
// send video ?
public static boolean muted = false;
public static void setUseFrontCamera(boolean value) {
AndroidCamera[] cameras = AndroidCameraConfiguration.retrieveCameras();
for (AndroidCamera cam: cameras) {
if (cam.frontFacing == value) {
if (cameraId != cam.id) {
cameraId = cam.id;
if (LinphoneManager.getLc().getCurrentCall() != null) {
Log.w("Should we restart video ??");
}
}
return;
}
}
Log.e("setUseFrontCamera(true) while no front camera detected on device: using rear");
}
public static void useNextCamera() {
AndroidCamera[] cameras = AndroidCameraConfiguration.retrieveCameras();
int newid = (cameraId + 1) % cameras.length;
if (newid != cameraId) {
Log.d("Change camera to use : ", cameraId, " -> ", newid);
cameraId = newid;
}
}
}
......@@ -135,29 +135,20 @@ public class AndroidVideoApi5JniWrapper {
int rH = Math.min(requestedW, requestedH);
try {
// look for exact match
// look for nearest size
Size result = null;
int req = rW * rH;
int minDist = Integer.MAX_VALUE;
for(Size s: supportedSizes) {
int dist = Math.abs(req - s.width * s.height);
if (dist < minDist) {
minDist = dist;
result = s;
}
if (s.width == rW && s.height == rH)
return new int[] {s.width, s.height};
}
// look for just above match (120%)
for(Size s: supportedSizes) {
if (s.width < rW || s.height < rH)
continue;
if (s.width <= rW * 1.2 && s.height <= rH * 1.2)
return new int[] {s.width, s.height};
}
// return nearest smaller (or the 1st one, if no smaller is found)
Size n = supportedSizes.get(0);
for(Size s: supportedSizes) {
if (s.width > rW || s.height > rH)
continue;
if (n == null)
n = s;
else if (s.width > n.width && s.height > n.height)
n = s;
}
return new int[] {n.width, n.height};
return new int[] {result.width, result.height};
} catch (Exception exc) {
exc.printStackTrace();
return null;
......
......@@ -21,10 +21,10 @@ package org.linphone.mediastream.video.capture.hwconf;
import java.util.ArrayList;
import java.util.List;
import org.linphone.core.Hacks;
import org.linphone.core.Log;
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration.AndroidCamera;
import android.util.Log;
/**
* Android cameras detection, using SDK < 9
*
......@@ -35,20 +35,20 @@ class AndroidCameraConfigurationReader5 {
// Defaults
if (Hacks.isGalaxySOrTab()) {
Log.d("Hack Galaxy S : has one or more cameras");
Log.d("mediastreamer", "Hack Galaxy S : has one or more cameras");
if (Hacks.isGalaxySOrTabWithFrontCamera()) {
Log.d("Hack Galaxy S : HAS a front camera with id=2");
Log.d("mediastreamer", "Hack Galaxy S : HAS a front camera with id=2");
cam.add(new AndroidCamera(2, true, 90));
} else {
Log.d("Hack Galaxy S : NO front camera");
Log.d("mediastreamer", "Hack Galaxy S : NO front camera");
}
Log.d("Hack Galaxy S : HAS a rear camera with id=1");
Log.d("mediastreamer", "Hack Galaxy S : HAS a rear camera with id=1");
cam.add(new AndroidCamera(1, false, 90));
} else {
cam.add(new AndroidCamera(0, false, 90));
if (Hacks.hasTwoCamerasRear0Front1()) {
Log.d("Hack SPHD700 has 2 cameras a rear with id=0 and a front with id=1");
Log.d("mediastreamer", "Hack SPHD700 has 2 cameras a rear with id=0 and a front with id=1");
cam.add(new AndroidCamera(1, true, 90));
}
}
......
/*
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.mediastream.video.capture.hwconf;
import android.hardware.Camera;
import android.media.AudioManager;
import android.os.Build;
import android.util.Log;
public final class Hacks {
private Hacks() {}
public static boolean isGalaxySOrTabWithFrontCamera() {
return isGalaxySOrTab() && !isGalaxySOrTabWithoutFrontCamera();
}
private static boolean isGalaxySOrTabWithoutFrontCamera() {
return isSC02B() || isSGHI896();
}
public static boolean isGalaxySOrTab() {
return isGalaxyS() || isGalaxyTab();
}
public static boolean isGalaxyTab() {
return isGTP1000();
}
private static boolean isGalaxyS() {
return isGT9000() || isSC02B() || isSGHI896() || isSPHD700();
}
public static final boolean hasTwoCamerasRear0Front1() {
return isSPHD700() || isADR6400();
}
// HTC
private static final boolean isADR6400() {
return Build.MODEL.startsWith("ADR6400") || Build.DEVICE.startsWith("ADR6400");
} // HTC Thunderbolt
// Galaxy S variants
private static final boolean isSPHD700() {return Build.DEVICE.startsWith("SPH-D700");} // Epic
private static boolean isSGHI896() {return Build.DEVICE.startsWith("SGH-I896");} // Captivate
private static boolean isGT9000() {return Build.DEVICE.startsWith("GT-I9000");} // Galaxy S
private static boolean isSC02B() {return Build.DEVICE.startsWith("SC-02B");} // Docomo
private static boolean isGTP1000() {return Build.DEVICE.startsWith("GT-P1000");} // Tab
/* private static final boolean log(final String msg) {
Log.d(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);
}
public 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");
//MANUFACTURER doesn't exist in android 1.5.
//sb.append("MANUFACTURER=").append(Build.MANUFACTURER).append("\n");
sb.append("SDK=").append(Build.VERSION.SDK);
Log.i("mediastreamer", sb.toString());
}
public static boolean needSoftvolume() {
return isGalaxySOrTab();
}
public static boolean needRoutingAPI() {
return Build.VERSION.SDK_INT < 5;
}
public static boolean needGalaxySAudioHack() {
return isGalaxySOrTab() && !isSC02B();
}
public static boolean needPausingCallForSpeakers() {
// return false;
return isGalaxySOrTab() && !isSC02B();
}
public static boolean hasTwoCameras() {
return isSPHD700() || isGalaxySOrTabWithFrontCamera();
}
public static boolean hasCamera() {
if (Build.VERSION.SDK_INT >= 9) {
int nb = 0;
try {
nb = (Integer) Camera.class.getMethod("getNumberOfCameras", (Class[])null).invoke(null);
} catch (Exception e) {
Log.e("mediastreamer", "Error getting number of cameras");
}
return nb > 0;
}
Log.i("mediastreamer", "Hack: considering there IS a camera.\n"
+ "If it is not the case, report DEVICE and MODEL to linphone-users@nongnu.org");
return true;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment