Multiple Video orientation fixes and cleaning
- 0000083 : Video orientation not updated outside video call activity; - 0000082 : Video started landscape sent portrait; - use of accelerometer sensor in spite of orientation sensor.
This commit is contained in:
parent
1cca9a7b84
commit
c906073ea8
2 changed files with 51 additions and 83 deletions
|
@ -28,7 +28,6 @@ import org.linphone.core.Log;
|
||||||
import org.linphone.core.LinphoneCall.State;
|
import org.linphone.core.LinphoneCall.State;
|
||||||
import org.linphone.core.LinphoneCore.RegistrationState;
|
import org.linphone.core.LinphoneCore.RegistrationState;
|
||||||
import org.linphone.mediastream.Version;
|
import org.linphone.mediastream.Version;
|
||||||
import org.linphone.mediastream.video.AndroidVideoWindowImpl;
|
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.TabActivity;
|
import android.app.TabActivity;
|
||||||
|
@ -37,10 +36,6 @@ import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.hardware.Sensor;
|
|
||||||
import android.hardware.SensorEvent;
|
|
||||||
import android.hardware.SensorEventListener;
|
|
||||||
import android.hardware.SensorManager;
|
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -50,31 +45,26 @@ import android.text.Html;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.view.OrientationEventListener;
|
||||||
import android.widget.TabWidget;
|
import android.widget.TabWidget;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import android.widget.TabHost.TabSpec;
|
import android.widget.TabHost.TabSpec;
|
||||||
|
|
||||||
public class LinphoneActivity extends TabActivity implements
|
public class LinphoneActivity extends TabActivity implements ContactPicked
|
||||||
SensorEventListener
|
|
||||||
, ContactPicked
|
|
||||||
, LinphoneOnCallStateChangedListener
|
, LinphoneOnCallStateChangedListener
|
||||||
{
|
{
|
||||||
public static final String DIALER_TAB = "dialer";
|
public static final String DIALER_TAB = "dialer";
|
||||||
public static final String PREF_FIRST_LAUNCH = "pref_first_launch";
|
public static final String PREF_FIRST_LAUNCH = "pref_first_launch";
|
||||||
private static final int video_activity = 100;
|
private static final int video_activity = 100;
|
||||||
static final int FIRST_LOGIN_ACTIVITY = 101;
|
private static final int FIRST_LOGIN_ACTIVITY = 101;
|
||||||
static final int INCOMING_CALL_ACTIVITY = 103;
|
private static final int INCOMING_CALL_ACTIVITY = 103;
|
||||||
private static final int incall_activity = 104;
|
private static final int incall_activity = 104;
|
||||||
private static final int conferenceDetailsActivity = 105;
|
private static final int conferenceDetailsActivity = 105;
|
||||||
private static final String PREF_CHECK_CONFIG = "pref_check_config";
|
private static final String PREF_CHECK_CONFIG = "pref_check_config";
|
||||||
|
|
||||||
private static LinphoneActivity instance;
|
private static LinphoneActivity instance;
|
||||||
|
private OrientationEventListener mOrientationHelper;
|
||||||
private SensorManager mSensorManager;
|
|
||||||
private Sensor mAccelerometer;
|
|
||||||
private int previousRotation = -1;
|
|
||||||
|
|
||||||
private Handler mHandler = new Handler();
|
private Handler mHandler = new Handler();
|
||||||
|
|
||||||
// Customization
|
// Customization
|
||||||
|
@ -111,7 +101,6 @@ public class LinphoneActivity extends TabActivity implements
|
||||||
useMenuAbout = getResources().getBoolean(R.bool.useMenuAbout);
|
useMenuAbout = getResources().getBoolean(R.bool.useMenuAbout);
|
||||||
checkAccount = !useFirstLoginActivity;
|
checkAccount = !useFirstLoginActivity;
|
||||||
|
|
||||||
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
|
|
||||||
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
if (!useFirstLoginActivity || pref.getBoolean(getString(R.string.first_launch_suceeded_once_key), false)) {
|
if (!useFirstLoginActivity || pref.getBoolean(getString(R.string.first_launch_suceeded_once_key), false)) {
|
||||||
|
@ -214,26 +203,6 @@ public class LinphoneActivity extends TabActivity implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
|
||||||
|
|
||||||
}
|
|
||||||
public void onSensorChanged(SensorEvent event) {
|
|
||||||
if (event==null || event.sensor == mAccelerometer) {
|
|
||||||
int rot;
|
|
||||||
|
|
||||||
rot = AndroidVideoWindowImpl.rotationToAngle(getWindowManager().getDefaultDisplay().getOrientation());
|
|
||||||
|
|
||||||
if (rot != previousRotation) {
|
|
||||||
Log.d("New device rotation: ", rot);
|
|
||||||
// Returning rotation FROM ITS NATURAL ORIENTATION
|
|
||||||
LinphoneCore lc=LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
|
||||||
if (lc!=null) lc.setDeviceRotation(rot);
|
|
||||||
//else ignore, we are probably exiting.
|
|
||||||
previousRotation = rot;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
@ -296,24 +265,6 @@ public class LinphoneActivity extends TabActivity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized void stopOrientationSensor() {
|
|
||||||
if (mSensorManager!=null)
|
|
||||||
mSensorManager.unregisterListener(this, mAccelerometer);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public synchronized void startOrientationSensor() {
|
|
||||||
if (mSensorManager!=null) {
|
|
||||||
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
|
|
||||||
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* init LC orientation value on orientation sensor startup */
|
|
||||||
previousRotation = -1;
|
|
||||||
onSensorChanged(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
void showPreferenceErrorDialog(String message) {
|
void showPreferenceErrorDialog(String message) {
|
||||||
if (!useMenuSettings) {
|
if (!useMenuSettings) {
|
||||||
Toast.makeText(this, message, Toast.LENGTH_LONG);
|
Toast.makeText(this, message, Toast.LENGTH_LONG);
|
||||||
|
@ -437,6 +388,7 @@ public class LinphoneActivity extends TabActivity implements
|
||||||
mHandler.postDelayed(new Runnable() {
|
mHandler.postDelayed(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (VideoCallActivity.launched) return;
|
if (VideoCallActivity.launched) return;
|
||||||
|
startOrientationSensor();
|
||||||
LinphoneManager.getInstance().enableCamera(call, true);
|
LinphoneManager.getInstance().enableCamera(call, true);
|
||||||
startActivityForResult(new Intent().setClass(
|
startActivityForResult(new Intent().setClass(
|
||||||
LinphoneActivity.this,
|
LinphoneActivity.this,
|
||||||
|
@ -462,6 +414,42 @@ public class LinphoneActivity extends TabActivity implements
|
||||||
startActivityForResult(intent, INCOMING_CALL_ACTIVITY);
|
startActivityForResult(intent, INCOMING_CALL_ACTIVITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a sensor to track phoneOrientation changes
|
||||||
|
*/
|
||||||
|
private synchronized void startOrientationSensor() {
|
||||||
|
if (mOrientationHelper == null) {
|
||||||
|
mOrientationHelper = new LocalOrientationEventListener(this);
|
||||||
|
}
|
||||||
|
mOrientationHelper.enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int mAlwaysChangingPhoneAngle = -1;
|
||||||
|
private class LocalOrientationEventListener extends OrientationEventListener {
|
||||||
|
public LocalOrientationEventListener(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onOrientationChanged(final int o) {
|
||||||
|
if (o == OrientationEventListener.ORIENTATION_UNKNOWN) return;
|
||||||
|
|
||||||
|
int degrees=270;
|
||||||
|
if (o < 45 || o >315) degrees=0;
|
||||||
|
else if (o<135) degrees=90;
|
||||||
|
else if (o<225) degrees=180;
|
||||||
|
|
||||||
|
if (mAlwaysChangingPhoneAngle == degrees) return;
|
||||||
|
mAlwaysChangingPhoneAngle = degrees;
|
||||||
|
|
||||||
|
Log.d("Phone orientation changed to ", degrees);
|
||||||
|
int rotation = (360 - degrees) % 360;
|
||||||
|
LinphoneManager.getLc().setDeviceRotation(rotation);
|
||||||
|
LinphoneCall currentCall = LinphoneManager.getLc().getCurrentCall();
|
||||||
|
if (currentCall != null && currentCall.cameraEnabled() && currentCall.getCurrentParamsCopy().getVideoEnabled()) {
|
||||||
|
LinphoneManager.getLc().updateCall(currentCall, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCallStateChanged(LinphoneCall call, State state,
|
public void onCallStateChanged(LinphoneCall call, State state,
|
||||||
|
@ -473,17 +461,14 @@ public class LinphoneActivity extends TabActivity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state==State.IncomingReceived) {
|
if (state==State.IncomingReceived) {
|
||||||
|
if (call.getCurrentParamsCopy().getVideoEnabled()) startOrientationSensor();
|
||||||
startIncomingCallActivity();
|
startIncomingCallActivity();
|
||||||
}
|
}
|
||||||
if (state == State.OutgoingInit) {
|
if (state == State.OutgoingInit) {
|
||||||
|
if (call.getCurrentParamsCopy().getVideoEnabled()) startOrientationSensor();
|
||||||
startIncallActivity();
|
startIncallActivity();
|
||||||
}
|
}
|
||||||
if (state==State.OutgoingInit || state==State.IncomingReceived) {
|
|
||||||
startOrientationSensor();
|
|
||||||
} else if (state==State.Error || state==State.CallEnd){
|
|
||||||
stopOrientationSensor();
|
|
||||||
finishActivity(INCOMING_CALL_ACTIVITY);
|
|
||||||
}
|
|
||||||
if (state == LinphoneCall.State.StreamsRunning && Version.isVideoCapable() && !call.isInConference()) {
|
if (state == LinphoneCall.State.StreamsRunning && Version.isVideoCapable() && !call.isInConference()) {
|
||||||
// call.cameraEnabled() contains the wish of the user
|
// call.cameraEnabled() contains the wish of the user
|
||||||
// set in LinphoneManager#onCallStateChanged(OutgoingInit||IncomingReceived)
|
// set in LinphoneManager#onCallStateChanged(OutgoingInit||IncomingReceived)
|
||||||
|
@ -505,8 +490,11 @@ public class LinphoneActivity extends TabActivity implements
|
||||||
showToast(R.string.call_error, message);
|
showToast(R.string.call_error, message);
|
||||||
}
|
}
|
||||||
if (state==State.Error || state==State.CallEnd) {
|
if (state==State.Error || state==State.CallEnd) {
|
||||||
|
finishActivity(INCOMING_CALL_ACTIVITY);
|
||||||
if (lc.getCallsNb() == 0){
|
if (lc.getCallsNb() == 0){
|
||||||
exitIncallActivity();
|
exitIncallActivity();
|
||||||
|
// Might be possible to optimize by disabling it before
|
||||||
|
if (mOrientationHelper != null) mOrientationHelper.disable();
|
||||||
}
|
}
|
||||||
if (ConferenceDetailsActivity.active && lc.getConferenceSize() == 0) {
|
if (ConferenceDetailsActivity.active && lc.getConferenceSize() == 0) {
|
||||||
finishActivity(conferenceDetailsActivity);
|
finishActivity(conferenceDetailsActivity);
|
||||||
|
@ -530,12 +518,6 @@ public class LinphoneActivity extends TabActivity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class VideoCallActivity extends Activity implements LinphoneOnCallStateCh
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (!LinphoneManager.isInstanciated() || LinphoneManager.getLc().getCallsNb() == 0) {
|
if (!LinphoneManager.isInstanciated() || LinphoneManager.getLc().getCallsNb() == 0) {
|
||||||
Log.e("No service running: avoid crash by finishing ", this.getClass().getName());
|
Log.e("No service running: avoid crash by finishing ", getClass().getName());
|
||||||
// super.onCreate called earlier
|
// super.onCreate called earlier
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
|
@ -78,9 +78,7 @@ public class VideoCallActivity extends Activity implements LinphoneOnCallStateCh
|
||||||
captureView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
captureView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
||||||
|
|
||||||
/* force surfaces Z ordering */
|
/* force surfaces Z ordering */
|
||||||
if (org.linphone.mediastream.Version.sdkAboveOrEqual(5)) {
|
|
||||||
fixZOrder(videoView, captureView);
|
fixZOrder(videoView, captureView);
|
||||||
}
|
|
||||||
|
|
||||||
androidVideoWindowImpl = new AndroidVideoWindowImpl(videoView, captureView);
|
androidVideoWindowImpl = new AndroidVideoWindowImpl(videoView, captureView);
|
||||||
androidVideoWindowImpl.setListener(new AndroidVideoWindowImpl.VideoWindowListener() {
|
androidVideoWindowImpl.setListener(new AndroidVideoWindowImpl.VideoWindowListener() {
|
||||||
|
@ -107,13 +105,6 @@ public class VideoCallActivity extends Activity implements LinphoneOnCallStateCh
|
||||||
|
|
||||||
androidVideoWindowImpl.init();
|
androidVideoWindowImpl.init();
|
||||||
|
|
||||||
// When changing phone orientation _DURING_ a call, VideoCallActivity is destroyed then recreated
|
|
||||||
// In this case, the following sequence happen:
|
|
||||||
// * onDestroy -> sendStaticImage(true) => destroy video graph
|
|
||||||
// * onCreate -> sendStaticImage(false) => recreate the video graph.
|
|
||||||
// Before creating the graph, the orientation must be known to LC => this is done here
|
|
||||||
LinphoneManager.getLc().setDeviceRotation(AndroidVideoWindowImpl.rotationToAngle(getWindowManager().getDefaultDisplay().getOrientation()));
|
|
||||||
|
|
||||||
videoCall = LinphoneManager.getLc().getCurrentCall();
|
videoCall = LinphoneManager.getLc().getCurrentCall();
|
||||||
if (videoCall != null) {
|
if (videoCall != null) {
|
||||||
updatePreview(videoCall.cameraEnabled());
|
updatePreview(videoCall.cameraEnabled());
|
||||||
|
@ -287,7 +278,7 @@ public class VideoCallActivity extends Activity implements LinphoneOnCallStateCh
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
Log.d("onPause VideoCallActivity (isFinishing:", isFinishing(), ", inCall:", LinphoneManager.getLc().isIncall(), ", changingConf:", getChangingConfigurations());
|
Log.d("onPause VideoCallActivity (isFinishing:", isFinishing(), ", inCall:", LinphoneManager.getLc().isIncall(),")");
|
||||||
LinphoneManager.removeListener(this);
|
LinphoneManager.removeListener(this);
|
||||||
if (isFinishing()) {
|
if (isFinishing()) {
|
||||||
videoCall = null; // release reference
|
videoCall = null; // release reference
|
||||||
|
@ -302,11 +293,6 @@ public class VideoCallActivity extends Activity implements LinphoneOnCallStateCh
|
||||||
|
|
||||||
LinphoneManager.getLc().setPreviewWindow(null);
|
LinphoneManager.getLc().setPreviewWindow(null);
|
||||||
|
|
||||||
final LinphoneCall currentCall = LinphoneManager.getLc().getCurrentCall();
|
|
||||||
if (currentCall != null && getChangingConfigurations() != 0) {
|
|
||||||
LinphoneManager.getLc().setDeviceRotation(AndroidVideoWindowImpl.rotationToAngle(getWindowManager().getDefaultDisplay().getOrientation()));
|
|
||||||
LinphoneManager.getLc().updateCall(currentCall, null);
|
|
||||||
}
|
|
||||||
if (mCallQualityUpdater!=null){
|
if (mCallQualityUpdater!=null){
|
||||||
refreshHandler.removeCallbacks(mCallQualityUpdater);
|
refreshHandler.removeCallbacks(mCallQualityUpdater);
|
||||||
mCallQualityUpdater=null;
|
mCallQualityUpdater=null;
|
||||||
|
|
Loading…
Reference in a new issue