diff --git a/AndroidCameraRecord.java b/AndroidCameraRecord.java index 9d8b2f144..7fa4746bb 100644 --- a/AndroidCameraRecord.java +++ b/AndroidCameraRecord.java @@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. package org.linphone.core; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import android.hardware.Camera; @@ -39,7 +40,7 @@ public abstract class AndroidCameraRecord { private PreviewCallback storedPreviewCallback; private boolean previewStarted; protected int orientationCode; - private static final String tag="Linphone"; + protected static final String tag="Linphone"; private List supportedVideoSizes; public AndroidCameraRecord(RecorderParams parameters) { @@ -47,7 +48,9 @@ public abstract class AndroidCameraRecord { setRotation(parameters.rotation); } - + protected List getSupportedPreviewSizes(Camera.Parameters parameters) { + return Collections.emptyList(); + } public void startPreview() { // FIXME throws exception? if (previewStarted) { @@ -73,7 +76,7 @@ public abstract class AndroidCameraRecord { Camera.Parameters parameters=camera.getParameters(); if (supportedVideoSizes == null) { - supportedVideoSizes = camera.getParameters().getSupportedPreviewSizes(); + supportedVideoSizes = getSupportedPreviewSizes(camera.getParameters()); } parameters.set("camera-id", params.cameraId); @@ -83,18 +86,7 @@ public abstract class AndroidCameraRecord { parameters.setPreviewSize(params.height, params.width); } parameters.setPreviewFrameRate(Math.round(params.fps)); - if (parameters.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_AUTO)) { - Log.w(tag, "Auto Focus supported by camera device"); - parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); - } else { - Log.w(tag, "Auto Focus not supported by camera device"); - if (parameters.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_INFINITY)) { - Log.w(tag, "Infinity Focus supported by camera device"); - parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY); - } else { - Log.w(tag, "Infinity Focus not supported by camera device"); - } - } + onSettingCameraParameters(parameters); camera.setParameters(parameters); diff --git a/AndroidCameraRecordBufferedImpl.java b/AndroidCameraRecordBufferedImpl.java index f58698df2..9f8b2d1c0 100644 --- a/AndroidCameraRecordBufferedImpl.java +++ b/AndroidCameraRecordBufferedImpl.java @@ -30,7 +30,7 @@ import android.util.Log; * @author Guillaume Beraudo * */ -public class AndroidCameraRecordBufferedImpl extends AndroidCameraRecordImpl { +public class AndroidCameraRecordBufferedImpl extends AndroidCameraRecordImplAPI5 { public AndroidCameraRecordBufferedImpl(RecorderParams parameters) { diff --git a/AndroidCameraRecordImplAPI5.java b/AndroidCameraRecordImplAPI5.java new file mode 100644 index 000000000..7ff307d03 --- /dev/null +++ b/AndroidCameraRecordImplAPI5.java @@ -0,0 +1,64 @@ +/* +AndroidCameraRecordImplAPI5.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 java.util.List; + +import android.hardware.Camera; +import android.hardware.Camera.Parameters; +import android.hardware.Camera.Size; +import android.util.Log; + + +public class AndroidCameraRecordImplAPI5 extends AndroidCameraRecordImpl { + + public AndroidCameraRecordImplAPI5(RecorderParams parameters) { + super(parameters); + } + + @Override + protected void onSettingCameraParameters(Parameters parameters) { + super.onSettingCameraParameters(parameters); + + if (parameters.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_AUTO)) { + Log.w(tag, "Auto Focus supported by camera device"); + parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); + } else { + Log.w(tag, "Auto Focus not supported by camera device"); + if (parameters.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_INFINITY)) { + Log.w(tag, "Infinity Focus supported by camera device"); + parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY); + } else { + Log.w(tag, "Infinity Focus not supported by camera device"); + } + } + } + + public static List oneShotSupportedVideoSizes() { + Camera camera = Camera.open(); + List supportedVideoSizes =camera.getParameters().getSupportedPreviewSizes(); + camera.release(); + return supportedVideoSizes; + } + + @Override + protected List getSupportedPreviewSizes(Parameters parameters) { + return parameters.getSupportedPreviewSizes(); + } +} diff --git a/AndroidCameraRecordManager.java b/AndroidCameraRecordManager.java index 4c767b887..c6bae18da 100644 --- a/AndroidCameraRecordManager.java +++ b/AndroidCameraRecordManager.java @@ -24,7 +24,6 @@ import java.util.Map; import org.linphone.core.AndroidCameraRecord.RecorderParams; -import android.hardware.Camera; import android.hardware.Camera.Size; import android.os.Build; import android.util.Log; @@ -41,7 +40,6 @@ import android.view.SurfaceHolder.Callback; * */ public class AndroidCameraRecordManager { - public static final int CAMERA_ID_FIXME_USE_PREFERENCE = 0; private static final int version = Integer.parseInt(Build.VERSION.SDK); private static Map instances = new HashMap(); @@ -52,7 +50,8 @@ public class AndroidCameraRecordManager { } /** - * @param cameraId : see max_camera_id + * Instance for a given camera + * @param cameraId : starting from 0 * @return */ public static final synchronized AndroidCameraRecordManager getInstance(int cameraId) { @@ -69,6 +68,9 @@ public class AndroidCameraRecordManager { return m; } + /** + * @return instance for the default camera + */ public static final synchronized AndroidCameraRecordManager getInstance() { return getInstance(0); } @@ -148,6 +150,8 @@ public class AndroidCameraRecordManager { parameters.surfaceView = surfaceView; if (version >= 8) { recorder = new AndroidCameraRecordBufferedImpl(parameters); + } else if (version >= 5) { + recorder = new AndroidCameraRecordImplAPI5(parameters); } else { recorder = new AndroidCameraRecordImpl(parameters); } @@ -164,6 +168,10 @@ public class AndroidCameraRecordManager { // FIXME select right camera + /** + * Eventually null if API < 5. + * + */ public List supportedVideoSizes() { if (supportedVideoSizes != null) { return supportedVideoSizes; @@ -174,9 +182,12 @@ public class AndroidCameraRecordManager { if (supportedVideoSizes != null) return supportedVideoSizes; } - Camera camera = Camera.open(); - supportedVideoSizes = camera.getParameters().getSupportedPreviewSizes(); - camera.release(); + if (version >= 5) { + supportedVideoSizes = AndroidCameraRecordImplAPI5.oneShotSupportedVideoSizes(); + } + + // eventually null + return supportedVideoSizes; }