Fix links to ABI>=5 in video code preventing use with old telephones.

Disable video when ABI<5 or ILBC not found.
Automatically open preference activity on linphone first launch.
This commit is contained in:
Guillaume Beraudo 2010-12-02 12:29:51 +01:00
parent a7c66cff38
commit c4cf0434ff
8 changed files with 178 additions and 87 deletions

View file

@ -15,7 +15,7 @@
<EditTextPreference android:title="@string/pref_stun_server" android:key="@string/pref_stun_server_key"></EditTextPreference>
<PreferenceScreen android:title="@string/pref_codecs" android:key="@string/pref_codecs_key">
<CheckBoxPreference android:key="@string/pref_codec_speex16_key"
android:title="@string/pref_codec_speex16" android:defaultValue="true"></CheckBoxPreference>
android:title="@string/pref_codec_speex16" android:defaultValue="true" android:enabled="false"></CheckBoxPreference>
<CheckBoxPreference android:key="@string/pref_codec_speex8_key"
android:title="@string/pref_codec_speex8" android:defaultValue="true"></CheckBoxPreference>
<CheckBoxPreference android:key="@string/pref_codec_ilbc_key" android:title="@string/pref_codec_ilbc" android:enabled="false" android:shouldDisableView="true" android:defaultValue="true" android:summary="@string/pref_ilbc_summary"></CheckBoxPreference>
@ -36,8 +36,8 @@
<CheckBoxPreference android:defaultValue="true" android:title="@string/pref_video_enable_title" android:key="@string/pref_video_enable_key"></CheckBoxPreference>
<PreferenceScreen android:title="@string/pref_video_settings_title" android:dependency="@string/pref_video_enable_key"><CheckBoxPreference android:key="@string/pref_video_initiate_call_with_video_key" android:defaultValue="false" android:title="@string/pref_video_initiate_call_with_video_title" android:summary="@string/pref_video_initiate_call_with_video" android:dependency="@string/pref_video_enable_key"></CheckBoxPreference>
<CheckBoxPreference android:defaultValue="true" android:title="@string/pref_video_enable_title" android:key="@string/pref_video_enable_key" />
<PreferenceScreen android:title="@string/pref_video_settings_title" android:dependency="@string/pref_video_enable_key" android:shouldDisableView="true"><CheckBoxPreference android:key="@string/pref_video_initiate_call_with_video_key" android:defaultValue="false" android:title="@string/pref_video_initiate_call_with_video_title" android:summary="@string/pref_video_initiate_call_with_video" android:dependency="@string/pref_video_enable_key"></CheckBoxPreference>
<CheckBoxPreference android:key="@string/pref_video_automatically_share_my_video_key" android:title="@string/pref_video_automatically_share_my_video_title" android:defaultValue="false" android:summary="@string/pref_video_automatically_share_my_video" android:dependency="@string/pref_video_enable_key"></CheckBoxPreference>
</PreferenceScreen>
</PreferenceCategory>

View file

@ -101,7 +101,8 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
private SharedPreferences mPref;
private ImageButton mAddVideo;
static String PREF_CHECK_CONFIG = "pref_check_config";
private static final String PREF_CHECK_CONFIG = "pref_check_config";
private static final String PREF_FIRST_LAUNCH = "pref_first_launch";
private static String CURRENT_ADDRESS = "org.linphone.current-address";
private static String CURRENT_DISPLAYNAME = "org.linphone.current-displayname";
static int VIDEO_VIEW_ACTIVITY = 100;
@ -256,7 +257,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
} else {
mDisplayNameView.setText(lLinphoneCore.getRemoteAddress().getUserName());
}
configureMuteButtons();
configureMuteAndSpeakerButtons();
mWakeLock.acquire();
}
}
@ -391,12 +392,17 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
try{
LinphoneService.instance().initFromConf();
} catch (LinphoneConfigException ec) {
Log.w(LinphoneService.TAG,"no valid settings found",ec);
if (mPref.getBoolean(PREF_FIRST_LAUNCH, true)) {
Log.w(LinphoneService.TAG,"no valid settings found - first launch",ec);
LinphoneActivity.instance().startprefActivity();
mPref.edit().putBoolean(PREF_FIRST_LAUNCH, false).commit();
} else {
Log.w(LinphoneService.TAG,"no valid settings found", ec);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
TextView lDialogTextView = new TextView(this);
lDialogTextView.setAutoLinkMask(0x0f/*all*/);
lDialogTextView.setPadding(10, 10, 10, 10);
lDialogTextView.setText(Html.fromHtml(getString(R.string.initial_config_error) ));
lDialogTextView.setText(Html.fromHtml(getString(R.string.initial_config_error)));
builder.setCustomTitle(lDialogTextView)
.setCancelable(false)
.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
@ -417,7 +423,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
if (mPref.getBoolean(PREF_CHECK_CONFIG, false) == false) {
builder.create().show();
}
}
} catch (Exception e ) {
Log.e(LinphoneService.TAG,"Cannot get initial config", e);
}
@ -457,10 +463,12 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
} else if (state == LinphoneCall.State.CallEnd) {
exitCallMode();
} else if (state == LinphoneCall.State.StreamsRunning) {
if (!VideoCallActivity.launched && LinphoneService.instance().getLinphoneCore().getCurrentCall().getCurrentParamsReadOnly().getVideoEnabled()) {
if (LinphoneService.instance().getLinphoneCore().getCurrentCall().getCurrentParamsReadOnly().getVideoEnabled()) {
if (!VideoCallActivity.launched) {
startVideoView(VIDEO_VIEW_ACTIVITY);
}
}
}
mCurrentCallState = state;
}
@ -488,7 +496,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
mDisplayNameView.setText(lc.getRemoteAddress().toString());
}
}
configureMuteButtons();
configureMuteAndSpeakerButtons();
if (mSpeaker.isChecked()) {
routeAudioToSpeaker();
@ -497,9 +505,9 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
}
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
}
private void configureMuteButtons() {
private void configureMuteAndSpeakerButtons() {
mMute.setChecked(LinphoneService.instance().getLinphoneCore().isMicMuted());
if ((Integer.parseInt(Build.VERSION.SDK) <=4 && mAudioManager.getMode() == AudioManager.MODE_NORMAL)
if ((Integer.parseInt(Build.VERSION.SDK) <=4 && mAudioManager.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_SPEAKER)
|| Integer.parseInt(Build.VERSION.SDK) >4 &&mAudioManager.isSpeakerphoneOn()) {
mSpeaker.setChecked(true);
} else {
@ -534,7 +542,6 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
}
private void routeAudioToReceiver() {
if (Integer.parseInt(Build.VERSION.SDK) <=4 /*<donut*/) {
mAudioManager.setRouting(AudioManager.MODE_NORMAL,
AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL);
} else {
@ -700,7 +707,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
}
private AndroidCameraRecordManager getVideoManager() {
return AndroidCameraRecordManager.getInstance(AndroidCameraRecordManager.CAMERA_ID_FIXME_USE_PREFERENCE);
return AndroidCameraRecordManager.getInstance();
}
}

View file

@ -21,31 +21,48 @@ package org.linphone;
import android.os.Build;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.PreferenceActivity;
import android.util.Log;
public class LinphonePreferencesActivity extends PreferenceActivity {
private static final int version = Integer.parseInt(Build.VERSION.SDK);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean enableIlbc=false;
if (LinphoneService.isready()) {
enableIlbc = LinphoneService.instance().getLinphoneCore().findPayloadType("iLBC", 8000)!=null?true:false;;
// if not ilbc, we are on low end cpu.
enableIlbc = LinphoneService.instance().getLinphoneCore().findPayloadType("iLBC", 8000)!=null?true:false;
if (enableIlbc && !getPreferenceManager().getSharedPreferences().contains(getString(R.string.pref_echo_cancellation_key))) {
getPreferenceManager().getSharedPreferences().edit().putBoolean(getString(R.string.pref_echo_cancellation_key), true).commit();
}
if (!enableIlbc) {
getPreferenceManager().getSharedPreferences().edit().putBoolean(getString(R.string.pref_codec_ilbc_key), false).commit();
getPreferenceManager().getSharedPreferences().edit().putBoolean(getString(R.string.pref_codec_speex16_key), false).commit();
getPreferenceManager().getSharedPreferences().edit().putBoolean(getString(R.string.pref_codec_speex32_key), false).commit();
}
}
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
if (enableIlbc) {
getPreferenceScreen().findPreference(getString(R.string.pref_codec_ilbc_key)).setEnabled(enableIlbc);
getPreferenceScreen().findPreference(getString(R.string.pref_codec_speex16_key)).setEnabled(enableIlbc);
//getPreferenceScreen().findPreference(getString(R.string.pref_codec_speex32_key)).setEnabled(enableIlbc);
}
// Force disable video
if (version < 5 || !enableIlbc) {
getPreferenceManager().getSharedPreferences().edit().putBoolean(getString(R.string.pref_video_enable_key), false).commit();
CheckBoxPreference videoPref = (CheckBoxPreference) getPreferenceScreen().findPreference(getString(R.string.pref_video_enable_key));
videoPref.setEnabled(false);
videoPref.setChecked(false);
}
}
@Override

View file

@ -45,12 +45,12 @@ public class VideoCallActivity extends Activity {
setContentView(R.layout.videocall);
mVideoView = (SurfaceView) findViewById(R.id.video_surface);
LinphoneService.instance().getLinphoneCore().setVideoWindow((Object) mVideoView);
LinphoneService.instance().getLinphoneCore().setVideoWindow(mVideoView);
mVideoCaptureView = (SurfaceView) findViewById(R.id.video_capture_surface);
final int rotation = getWindowManager().getDefaultDisplay().getRotation();
recordManager = AndroidCameraRecordManager.getInstance(AndroidCameraRecordManager.CAMERA_ID_FIXME_USE_PREFERENCE);
recordManager = AndroidCameraRecordManager.getInstance();
recordManager.setSurfaceView(mVideoCaptureView, rotation);
mVideoCaptureView.setZOrderOnTop(true);
}

View file

@ -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 <Size> supportedVideoSizes;
public AndroidCameraRecord(RecorderParams parameters) {
@ -47,7 +48,9 @@ public abstract class AndroidCameraRecord {
setRotation(parameters.rotation);
}
protected List<Size> 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);

View file

@ -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) {

View file

@ -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<Size> oneShotSupportedVideoSizes() {
Camera camera = Camera.open();
List<Size> supportedVideoSizes =camera.getParameters().getSupportedPreviewSizes();
camera.release();
return supportedVideoSizes;
}
@Override
protected List<Size> getSupportedPreviewSizes(Parameters parameters) {
return parameters.getSupportedPreviewSizes();
}
}

View file

@ -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<Integer, AndroidCameraRecordManager> instances = new HashMap<Integer, AndroidCameraRecordManager>();
@ -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<Size> 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;
}