Launch echo canceller calibration on first startup and automatically configure echo canceller according to the results.

This commit is contained in:
Ghislain MARY 2012-10-12 16:42:09 +02:00
parent 501373d96c
commit 2f99e1ba1b
2 changed files with 36 additions and 9 deletions

View file

@ -25,6 +25,7 @@ import java.util.Calendar;
import java.util.List;
import org.linphone.LinphoneManager.AddressType;
import org.linphone.LinphoneManager.EcCalibrationListener;
import org.linphone.LinphoneManager.LinphoneConfigException;
import org.linphone.LinphoneSimpleListener.LinphoneOnCallStateChangedListener;
import org.linphone.LinphoneSimpleListener.LinphoneOnMessageReceivedListener;
@ -38,6 +39,7 @@ import org.linphone.core.LinphoneCallLog;
import org.linphone.core.LinphoneCallLog.CallStatus;
import org.linphone.core.LinphoneChatMessage;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCore.EcCalibratorStatus;
import org.linphone.core.LinphoneCore.RegistrationState;
import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneCoreFactory;
@ -87,7 +89,8 @@ import android.widget.Toast;
public class LinphoneActivity extends FragmentActivity implements OnClickListener, ContactPicked,
LinphoneOnCallStateChangedListener,
LinphoneOnMessageReceivedListener,
LinphoneOnRegistrationStateChangedListener {
LinphoneOnRegistrationStateChangedListener,
EcCalibrationListener {
public static final String PREF_FIRST_LAUNCH = "pref_first_launch";
private static final int SETTINGS_ACTIVITY = 123;
private static final int FIRST_LOGIN_ACTIVITY = 101;
@ -1133,9 +1136,30 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
stopService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class));
}
public void onEcCalibrationStatus(final EcCalibratorStatus status, final int delayMs) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = prefs.edit();
if (status == EcCalibratorStatus.DoneNoEcho) {
editor.putBoolean(getString(R.string.pref_echo_limiter_key), false);
editor.putBoolean(getString(R.string.pref_echo_cancellation_key), false);
} else if ((status == EcCalibratorStatus.Done) || (status == EcCalibratorStatus.Failed)) {
editor.putBoolean(getString(R.string.pref_echo_limiter_key), false);
editor.putBoolean(getString(R.string.pref_echo_cancellation_key), true);
}
editor.commit();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_FIRST_USER && requestCode == SETTINGS_ACTIVITY) {
if ((requestCode == FIRST_LOGIN_ACTIVITY) && (resultCode == RESULT_OK)) {
Toast.makeText(this, getString(R.string.ec_calibration_launch_message), Toast.LENGTH_LONG).show();
try {
LinphoneManager.getInstance().startEcCalibration(this);
} catch (LinphoneCoreException e) {
Log.e(e, "Unable to calibrate EC");
}
}
else if (resultCode == Activity.RESULT_FIRST_USER && requestCode == SETTINGS_ACTIVITY) {
if (data.getExtras().getBoolean("Exit", false)) {
exit();
} else {

View file

@ -130,7 +130,6 @@ public class PreferencesFragment extends PreferencesListFragment implements EcCa
findPreference(pref_codec_speex16_key).setEnabled(true);
//findPreference(pref_codec_speex32_key)).setEnabled(enableIlbc);
}
findPreference(pref_echo_limiter_key).setEnabled(true);
initializeMediaEncryptionPreferences();
@ -213,7 +212,6 @@ public class PreferencesFragment extends PreferencesListFragment implements EcCa
}
private void doOnFirstLaunch() {
manageCheckbox(R.string.pref_echo_limiter_key, !Hacks.hasBuiltInEchoCanceller(), true, false);
prefs().edit().putBoolean(LinphoneActivity.PREF_FIRST_LAUNCH, false).commit();
}
@ -306,12 +304,17 @@ public class PreferencesFragment extends PreferencesListFragment implements EcCa
public void onEcCalibrationStatus(final EcCalibratorStatus status, final int delayMs) {
mHandler.post(new Runnable() {
public void run() {
if (status == EcCalibratorStatus.Done) {
if (status == EcCalibratorStatus.DoneNoEcho) {
elPref.setChecked(false);
ecPref.setChecked(false);
} else if (status == EcCalibratorStatus.Done) {
ecCalibratePref.setSummary(String.format(getString(R.string.ec_calibrated), delayMs));
elPref.setChecked(false);
ecPref.setChecked(true);
} else if (status == EcCalibratorStatus.Failed) {
ecCalibratePref.setSummary(R.string.failed);
elPref.setChecked(true);
ecPref.setChecked(false);
elPref.setChecked(false);
ecPref.setChecked(true);
}
}
});