Portrait mode.

This commit is contained in:
Guillaume Beraudo 2010-12-01 11:39:19 +01:00
parent 95070d1345
commit 3c000dca8c
8 changed files with 53 additions and 21 deletions

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="menu_videocall_back_to_dialer_title">Display dialer</string>
<string name="menu_videocall_change_resolution_when_low_resolution">High resolution</string>
<string name="menu_videocall_change_resolution_when_low_resolution">Try High resolution</string>
<string name="menu_videocall_change_resolution_when_high_resolution">Low resolution</string>
<string name="menu_videocall_change_resolution_title">Change resolution</string>
<string name="menu_videocall_toggle_camera_title">Mute/Unmute camera</string>

View file

@ -114,8 +114,12 @@ public class BandwidthManager {
}
private VideoSize closestVideoSize(VideoSize vSize) {
boolean invert = vSize.getHeight() > vSize.getWidth();
int testHeight = invert?vSize.getWidth():vSize.getHeight();
int testWidth = invert?vSize.getHeight():vSize.getWidth();
for (Size s : AndroidCameraRecordManager.getInstance().supportedVideoSizes()) {
if (s.height == vSize.getHeight() && s.width == vSize.getWidth()) {
if (s.height == testHeight && s.width == testWidth) {
return vSize;
}
}

View file

@ -457,15 +457,9 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
} else if (state == LinphoneCall.State.CallEnd) {
exitCallMode();
} else if (state == LinphoneCall.State.StreamsRunning) {
if (LinphoneService.instance().getLinphoneCore().getCurrentCall().getCurrentParamsReadOnly().getVideoEnabled()) {
if (!VideoCallActivity.launched && LinphoneService.instance().getLinphoneCore().getCurrentCall().getCurrentParamsReadOnly().getVideoEnabled()) {
startVideoView(VIDEO_VIEW_ACTIVITY);
}
} else if (state == LinphoneCall.State.CallUpdated) {
if (LinphoneService.instance().getLinphoneCore().getCurrentCall().getCurrentParamsReadOnly().getVideoEnabled()) {
// getVideoManager().invalidateParameters(); // no, when addinv video to audio call the filters are created before callupdated event is received
// so the parameters are invalidated and the record is never launched
finishActivity(VIDEO_VIEW_ACTIVITY);
}
}
mCurrentCallState = state;
}

View file

@ -36,8 +36,12 @@ public class VideoCallActivity extends Activity {
SurfaceView mVideoView;
SurfaceView mVideoCaptureView;
AndroidCameraRecordManager recordManager;
private static final String tag = "Linphone";
public static boolean launched = false;
public void onCreate(Bundle savedInstanceState) {
Log.d(tag, "onCreate VideoCallActivity");
launched = true;
super.onCreate(savedInstanceState);
setContentView(R.layout.videocall);
@ -51,7 +55,7 @@ public class VideoCallActivity extends Activity {
recordManager.setSurfaceView(mVideoCaptureView, rotation);
mVideoCaptureView.setZOrderOnTop(true);
}
private void rewriteToggleCameraItem(MenuItem item) {
if (recordManager.isRecording()) {
@ -63,13 +67,13 @@ public class VideoCallActivity extends Activity {
private void rewriteChangeResolutionItem(MenuItem item) {
if (BandwidthManager.getInstance().isUserRestriction()) {
item.setTitle(getString(R.string.menu_videocall_change_resolution_when_high_resolution));
} else {
item.setTitle(getString(R.string.menu_videocall_change_resolution_when_low_resolution));
} else {
item.setTitle(getString(R.string.menu_videocall_change_resolution_when_high_resolution));
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the currently selected menu XML resource.
@ -103,6 +107,10 @@ public class VideoCallActivity extends Activity {
break;
case R.id.videocall_menu_toggle_camera:
recordManager.toggleMute();
LinphoneCore lc = LinphoneService.instance().getLinphoneCore();
if (lc.isIncall()) {
lc.getCurrentCall().enableCamera(!recordManager.isMuted());
}
rewriteToggleCameraItem(item);
break;
default:
@ -121,9 +129,16 @@ public class VideoCallActivity extends Activity {
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
Log.d(tag, "onDestroy VideoCallActivity");
launched = false;
super.onDestroy();
}
@Override
protected void onPause() {
Log.d(tag, "onPause VideoCallActivity");
super.onPause();
}
}

View file

@ -77,7 +77,11 @@ public abstract class AndroidCameraRecord {
}
parameters.set("camera-id", params.cameraId);
parameters.setPreviewSize(params.width, params.height);
if (!params.videoDimensionsInverted) {
parameters.setPreviewSize(params.width, params.height);
} else {
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");
@ -182,6 +186,7 @@ public abstract class AndroidCameraRecord {
int cameraId;
int rotation;
public SurfaceView surfaceView;
boolean videoDimensionsInverted;
public RecorderParams(long ptr) {
filterDataNativePtr = ptr;

View file

@ -35,17 +35,19 @@ public class AndroidCameraRecordImpl extends AndroidCameraRecord implements Prev
private double timeElapsedBetweenFrames = 0;
private long lastFrameTime = 0;
private final double expectedTimeBetweenFrames;
private boolean videoDimensionsInverted;
public AndroidCameraRecordImpl(RecorderParams parameters) {
super(parameters);
expectedTimeBetweenFrames = 1d / Math.round(parameters.fps);
filterCtxPtr = parameters.filterDataNativePtr;
videoDimensionsInverted = parameters.videoDimensionsInverted;
storePreviewCallBack(this);
}
private native void putImage(long filterCtxPtr, byte[] buffer, int orientation);
private native void putImage(long filterCtxPtr, byte[] buffer, int orientation, boolean videoDimensionsInverted);
public void onPreviewFrame(byte[] data, Camera camera) {
@ -69,7 +71,7 @@ public class AndroidCameraRecordImpl extends AndroidCameraRecord implements Prev
long curTime = System.currentTimeMillis();
if (lastFrameTime == 0) {
lastFrameTime = curTime;
putImage(filterCtxPtr, data, getOrientationCode());
putImage(filterCtxPtr, data, getOrientationCode(), videoDimensionsInverted);
return;
}
@ -82,7 +84,7 @@ public class AndroidCameraRecordImpl extends AndroidCameraRecord implements Prev
timeElapsedBetweenFrames = currentTimeElapsed;
// Log.d("onPreviewFrame: ", Integer.toString(data.length));
putImage(filterCtxPtr, data, getOrientationCode());
putImage(filterCtxPtr, data, getOrientationCode(), videoDimensionsInverted);
}

View file

@ -44,7 +44,7 @@ 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>();
// singleton
private AndroidCameraRecordManager(int cameraId) {
@ -83,16 +83,19 @@ public class AndroidCameraRecordManager {
private List<Size> supportedVideoSizes;
private int rotation;
private static final String tag = "Linphone";
public void setParametersFromFilter(long filterDataPtr, int height, int width, float fps) {
stopVideoRecording();
RecorderParams p = new RecorderParams(filterDataPtr);
p.fps = fps;
p.width = width;
p.height = height;
p.cameraId = cameraId;
p.videoDimensionsInverted = width < height;
parameters = p;
}
}
public final void setSurfaceView(final SurfaceView sv, final int rotation) {
@ -103,16 +106,20 @@ public class AndroidCameraRecordManager {
holder.addCallback(new Callback() {
public void surfaceDestroyed(SurfaceHolder holder) {
surfaceView = null;
Log.d(tag , "Video capture surface destroyed");
stopVideoRecording();
}
public void surfaceCreated(SurfaceHolder holder) {
surfaceView = sv;
Log.d(tag , "Video capture surface created");
tryToStartVideoRecording();
}
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {}
int height) {
Log.d(tag , "Video capture surface changed");
}
});
}

View file

@ -30,6 +30,7 @@ class LinphoneCallImpl implements LinphoneCall {
native private long getRemoteAddress(long nativePtr);
native private int getState(long nativePtr);
private native long getCurrentParams(long nativePtr);
private native void enableCamera(long nativePtr, boolean enabled);
protected LinphoneCallImpl(long aNativePtr) {
nativePtr = aNativePtr;
@ -66,4 +67,8 @@ class LinphoneCallImpl implements LinphoneCall {
public LinphoneCallParams getCurrentParamsReadWrite() {
return getCurrentParamsReadOnly().copy();
}
public void enableCamera(boolean enabled) {
enableCamera(nativePtr, enabled);
}
}