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.
|
||||
* The camera will be restarted when mediastreamer chain is recreated and setParameters is called.
|
||||
*/
|
||||
public void updateCall() {
|
||||
LinphoneCore lc = lc();
|
||||
|
@ -122,7 +123,6 @@ public class CallManager {
|
|||
LinphoneCallParams params = lCall.getCurrentParamsCopy();
|
||||
bm().updateWithProfileSettings(lc, params);
|
||||
lc.updateCall(lCall, null);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -183,4 +183,33 @@ public class LinphoneManager {
|
|||
|
||||
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.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
|
|
@ -46,7 +46,6 @@ public class VideoCallActivity extends Activity {
|
|||
public static boolean launched = false;
|
||||
private WakeLock mWakeLock;
|
||||
private static final int capturePreviewLargestDimension = 150;
|
||||
// private static final float similarRatio = 0.1f;
|
||||
private int previousPhoneOrientation;
|
||||
private int phoneOrientation;
|
||||
|
||||
|
@ -81,23 +80,17 @@ public class VideoCallActivity extends Activity {
|
|||
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
}
|
||||
|
||||
// Base capture frame on streamed dimensions and orientation.
|
||||
resizeCapturePreview(mVideoCaptureView, lc.getPreferredVideoSize());
|
||||
resizeCapturePreview(mVideoCaptureView);
|
||||
}
|
||||
|
||||
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
|
||||
protected void onResume() {
|
||||
updateCallIfOrientationChanged();
|
||||
// Update call if orientation changed
|
||||
if (Version.sdkAbove(8) && previousPhoneOrientation != phoneOrientation) {
|
||||
CallManager.getInstance().updateCall();
|
||||
resizeCapturePreview(mVideoCaptureView);
|
||||
}
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
|
@ -110,6 +103,7 @@ public class VideoCallActivity extends Activity {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void rewriteChangeResolutionItem(MenuItem item) {
|
||||
if (BandwidthManager.getInstance().isUserRestriction()) {
|
||||
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 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();
|
||||
float newRatio = ratioWidthHeight(vs);
|
||||
VideoSize vs = LinphoneService.getLc().getPreferredVideoSize();
|
||||
|
||||
// float previewRatio = (float) lp.width / lp.height;
|
||||
// if (Math.abs((newRatio-previewRatio)/newRatio) < similarRatio) return;
|
||||
float newRatio = (float) vs.width / vs.height;
|
||||
|
||||
if (vs.isPortrait()) {
|
||||
lp.height = capturePreviewLargestDimension;
|
||||
|
@ -157,43 +151,33 @@ public class VideoCallActivity extends Activity {
|
|||
|
||||
sv.setLayoutParams(lp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.videocall_menu_back_to_dialer:
|
||||
if (!recordManager.isMuted()) LinphoneManager.getInstance().sendStaticImage(true);
|
||||
if (!recordManager.isMuted())
|
||||
LinphoneManager.getInstance().sendStaticImage(true);
|
||||
finish();
|
||||
break;
|
||||
case R.id.videocall_menu_change_resolution:
|
||||
BandwidthManager manager = BandwidthManager.getInstance();
|
||||
manager.setUserRestriction(!manager.isUserRestriction());
|
||||
LinphoneManager.getInstance().sendStaticImage(recordManager.isMuted());
|
||||
LinphoneManager.getInstance().changeResolution();
|
||||
rewriteChangeResolutionItem(item);
|
||||
|
||||
// Resize preview frame
|
||||
VideoSize newVideoSize = LinphoneService.getLc().getPreferredVideoSize();
|
||||
resizeCapturePreview(mVideoCaptureView, newVideoSize);
|
||||
resizeCapturePreview(mVideoCaptureView);
|
||||
break;
|
||||
case R.id.videocall_menu_terminate_call:
|
||||
LinphoneCore lc = LinphoneService.getLc();
|
||||
if (lc.isIncall()) {
|
||||
lc.terminateCall(lc.getCurrentCall());
|
||||
}
|
||||
LinphoneManager.getInstance().terminateCall();
|
||||
finish();
|
||||
break;
|
||||
case R.id.videocall_menu_toggle_camera:
|
||||
LinphoneManager.getInstance().sendStaticImage(recordManager.toggleMute());
|
||||
LinphoneManager.getInstance().toggleCameraMuting();
|
||||
rewriteToggleCameraItem(item);
|
||||
break;
|
||||
case R.id.videocall_menu_switch_camera:
|
||||
recordManager.stopVideoRecording();
|
||||
recordManager.toggleUseFrontCamera();
|
||||
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());
|
||||
LinphoneManager.getInstance().switchCamera();
|
||||
resizeCapturePreview(mVideoCaptureView);
|
||||
break;
|
||||
default:
|
||||
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