Moved videocall activity logics to LinphoneManager.
This commit is contained in:
parent
58dc345e77
commit
ef93c28b72
4 changed files with 52 additions and 44 deletions
|
@ -115,6 +115,7 @@ public class CallManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update current call, without reinvite.
|
* Update current call, without reinvite.
|
||||||
|
* The camera will be restarted when mediastreamer chain is recreated and setParameters is called.
|
||||||
*/
|
*/
|
||||||
public void updateCall() {
|
public void updateCall() {
|
||||||
LinphoneCore lc = lc();
|
LinphoneCore lc = lc();
|
||||||
|
@ -122,7 +123,6 @@ public class CallManager {
|
||||||
LinphoneCallParams params = lCall.getCurrentParamsCopy();
|
LinphoneCallParams params = lCall.getCurrentParamsCopy();
|
||||||
bm().updateWithProfileSettings(lc, params);
|
bm().updateWithProfileSettings(lc, params);
|
||||||
lc.updateCall(lCall, null);
|
lc.updateCall(lCall, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,4 +183,33 @@ public class LinphoneManager {
|
||||||
|
|
||||||
getLc().playDtmf(dtmf, -1);
|
getLc().playDtmf(dtmf, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void changeResolution() {
|
||||||
|
BandwidthManager manager = BandwidthManager.getInstance();
|
||||||
|
manager.setUserRestriction(!manager.isUserRestriction());
|
||||||
|
LinphoneManager.getInstance().sendStaticImage(AndroidCameraRecordManager.getInstance().isMuted());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void terminateCall() {
|
||||||
|
LinphoneCore lc = LinphoneService.getLc();
|
||||||
|
if (lc.isIncall()) {
|
||||||
|
lc.terminateCall(lc.getCurrentCall());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Camera will be restarted when mediastreamer chain is recreated and setParameters is called.
|
||||||
|
*/
|
||||||
|
public void switchCamera() {
|
||||||
|
AndroidCameraRecordManager rm = AndroidCameraRecordManager.getInstance();
|
||||||
|
rm.stopVideoRecording();
|
||||||
|
rm.toggleUseFrontCamera();
|
||||||
|
CallManager.getInstance().updateCall();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleCameraMuting() {
|
||||||
|
AndroidCameraRecordManager rm = AndroidCameraRecordManager.getInstance();
|
||||||
|
LinphoneManager.getInstance().sendStaticImage(rm.toggleMute());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,6 @@ import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
|
|
@ -46,7 +46,6 @@ public class VideoCallActivity extends Activity {
|
||||||
public static boolean launched = false;
|
public static boolean launched = false;
|
||||||
private WakeLock mWakeLock;
|
private WakeLock mWakeLock;
|
||||||
private static final int capturePreviewLargestDimension = 150;
|
private static final int capturePreviewLargestDimension = 150;
|
||||||
// private static final float similarRatio = 0.1f;
|
|
||||||
private int previousPhoneOrientation;
|
private int previousPhoneOrientation;
|
||||||
private int phoneOrientation;
|
private int phoneOrientation;
|
||||||
|
|
||||||
|
@ -81,23 +80,17 @@ public class VideoCallActivity extends Activity {
|
||||||
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Base capture frame on streamed dimensions and orientation.
|
resizeCapturePreview(mVideoCaptureView);
|
||||||
resizeCapturePreview(mVideoCaptureView, lc.getPreferredVideoSize());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCallIfOrientationChanged() {
|
|
||||||
if (Version.sdkAbove(8) && previousPhoneOrientation != phoneOrientation) {
|
|
||||||
CallManager.getInstance().updateCall();
|
|
||||||
// camera will be restarted when mediastreamer chain is recreated and setParameters is called
|
|
||||||
|
|
||||||
// Base capture frame on streamed dimensions and orientation.
|
|
||||||
resizeCapturePreview(mVideoCaptureView, LinphoneService.getLc().getPreferredVideoSize());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
updateCallIfOrientationChanged();
|
// Update call if orientation changed
|
||||||
|
if (Version.sdkAbove(8) && previousPhoneOrientation != phoneOrientation) {
|
||||||
|
CallManager.getInstance().updateCall();
|
||||||
|
resizeCapturePreview(mVideoCaptureView);
|
||||||
|
}
|
||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,6 +103,7 @@ public class VideoCallActivity extends Activity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void rewriteChangeResolutionItem(MenuItem item) {
|
private void rewriteChangeResolutionItem(MenuItem item) {
|
||||||
if (BandwidthManager.getInstance().isUserRestriction()) {
|
if (BandwidthManager.getInstance().isUserRestriction()) {
|
||||||
item.setTitle(getString(R.string.menu_videocall_change_resolution_when_low_resolution));
|
item.setTitle(getString(R.string.menu_videocall_change_resolution_when_low_resolution));
|
||||||
|
@ -137,15 +131,15 @@ public class VideoCallActivity extends Activity {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Base capture frame on streamed dimensions and orientation.
|
||||||
* @param sv capture surface view to resize the layout
|
* @param sv capture surface view to resize the layout
|
||||||
* @param vs video size from which to calculate the dimensions
|
* @param vs video size from which to calculate the dimensions
|
||||||
*/
|
*/
|
||||||
private void resizeCapturePreview(SurfaceView sv, VideoSize vs) {
|
private void resizeCapturePreview(SurfaceView sv) {
|
||||||
LayoutParams lp = sv.getLayoutParams();
|
LayoutParams lp = sv.getLayoutParams();
|
||||||
float newRatio = ratioWidthHeight(vs);
|
VideoSize vs = LinphoneService.getLc().getPreferredVideoSize();
|
||||||
|
|
||||||
// float previewRatio = (float) lp.width / lp.height;
|
float newRatio = (float) vs.width / vs.height;
|
||||||
// if (Math.abs((newRatio-previewRatio)/newRatio) < similarRatio) return;
|
|
||||||
|
|
||||||
if (vs.isPortrait()) {
|
if (vs.isPortrait()) {
|
||||||
lp.height = capturePreviewLargestDimension;
|
lp.height = capturePreviewLargestDimension;
|
||||||
|
@ -157,43 +151,33 @@ public class VideoCallActivity extends Activity {
|
||||||
|
|
||||||
sv.setLayoutParams(lp);
|
sv.setLayoutParams(lp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.videocall_menu_back_to_dialer:
|
case R.id.videocall_menu_back_to_dialer:
|
||||||
if (!recordManager.isMuted()) LinphoneManager.getInstance().sendStaticImage(true);
|
if (!recordManager.isMuted())
|
||||||
|
LinphoneManager.getInstance().sendStaticImage(true);
|
||||||
finish();
|
finish();
|
||||||
break;
|
break;
|
||||||
case R.id.videocall_menu_change_resolution:
|
case R.id.videocall_menu_change_resolution:
|
||||||
BandwidthManager manager = BandwidthManager.getInstance();
|
LinphoneManager.getInstance().changeResolution();
|
||||||
manager.setUserRestriction(!manager.isUserRestriction());
|
|
||||||
LinphoneManager.getInstance().sendStaticImage(recordManager.isMuted());
|
|
||||||
rewriteChangeResolutionItem(item);
|
rewriteChangeResolutionItem(item);
|
||||||
|
resizeCapturePreview(mVideoCaptureView);
|
||||||
// Resize preview frame
|
|
||||||
VideoSize newVideoSize = LinphoneService.getLc().getPreferredVideoSize();
|
|
||||||
resizeCapturePreview(mVideoCaptureView, newVideoSize);
|
|
||||||
break;
|
break;
|
||||||
case R.id.videocall_menu_terminate_call:
|
case R.id.videocall_menu_terminate_call:
|
||||||
LinphoneCore lc = LinphoneService.getLc();
|
LinphoneManager.getInstance().terminateCall();
|
||||||
if (lc.isIncall()) {
|
|
||||||
lc.terminateCall(lc.getCurrentCall());
|
|
||||||
}
|
|
||||||
finish();
|
finish();
|
||||||
break;
|
break;
|
||||||
case R.id.videocall_menu_toggle_camera:
|
case R.id.videocall_menu_toggle_camera:
|
||||||
LinphoneManager.getInstance().sendStaticImage(recordManager.toggleMute());
|
LinphoneManager.getInstance().toggleCameraMuting();
|
||||||
rewriteToggleCameraItem(item);
|
rewriteToggleCameraItem(item);
|
||||||
break;
|
break;
|
||||||
case R.id.videocall_menu_switch_camera:
|
case R.id.videocall_menu_switch_camera:
|
||||||
recordManager.stopVideoRecording();
|
LinphoneManager.getInstance().switchCamera();
|
||||||
recordManager.toggleUseFrontCamera();
|
resizeCapturePreview(mVideoCaptureView);
|
||||||
CallManager.getInstance().updateCall();
|
|
||||||
// camera will be restarted when mediastreamer chain is recreated and setParameters is called
|
|
||||||
|
|
||||||
// Base capture frame on streamed dimensions and orientation.
|
|
||||||
resizeCapturePreview(mVideoCaptureView, LinphoneService.getLc().getPreferredVideoSize());
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Log.e(LinphoneService.TAG, "Unknown menu item ["+item+"]");
|
Log.e(LinphoneService.TAG, "Unknown menu item ["+item+"]");
|
||||||
|
@ -218,8 +202,4 @@ public class VideoCallActivity extends Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public float ratioWidthHeight(VideoSize vs) {
|
|
||||||
return (float) vs.width / vs.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue