android: improvements to MediastreamerActivity sample

parent aadeaaa8
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/video_frame" android:orientation="vertical"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<org.linphone.mediastream.video.display.GL2JNIView android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/video_surface"></org.linphone.mediastream.video.display.GL2JNIView >
<SurfaceView android:layout_height="72dip" android:layout_width="88dip" android:id="@+id/video_capture_surface" android:layout_gravity="right|bottom"
android:layout_margin="15dip"></SurfaceView>
</FrameLayout>
<org.linphone.mediastream.video.display.GL2JNIView android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/video_surface"></org.linphone.mediastream.video.display.GL2JNIView>
<SurfaceView
android:layout_height="72dip"
android:layout_width="88dip"
android:id="@+id/video_capture_surface"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="15dip"
android:layout_marginRight="15dip" >
</SurfaceView>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/video_frame"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<org.linphone.mediastream.video.display.GL2JNIView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/video_surface">
</org.linphone.mediastream.video.display.GL2JNIView>
<SurfaceView
android:layout_height="88dip"
android:layout_width="72dip"
android:id="@+id/video_capture_surface"
android:layout_gravity="right|bottom"
android:layout_margin="15dip">
</SurfaceView>
</FrameLayout>
\ No newline at end of file
android:layout_height="fill_parent" android:layout_width="fill_parent">
<org.linphone.mediastream.video.display.GL2JNIView android:visibility="visible" android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/video_surface"></org.linphone.mediastream.video.display.GL2JNIView>
<SurfaceView
android:layout_height="88dip"
android:layout_width="72dip"
android:id="@+id/video_capture_surface"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="15dip"
android:layout_marginRight="15dip" >
</SurfaceView>
</RelativeLayout>
\ No newline at end of file
......@@ -5,5 +5,34 @@
<item android:title="Change camera" android:id="@+id/videocall_menu_change_camera"></item>
<item android:title="Change codec">
<menu>
<group android:checkableBehavior="single">
<item android:id="@+id/videocall_menu_codec_vp8"
android:title="VP8" />
<item android:id="@+id/videocall_menu_codec_mpeg4"
android:title="MPEG4" />
<item android:id="@+id/videocall_menu_codec_h264"
android:title="H264" />
</group>
</menu>
</item>
<item android:title="Change bitrate">
<menu>
<group android:checkableBehavior="single">
<item android:id="@+id/videocall_menu_bitrate_64_kbps"
android:title="64 kb/s" />
<item android:id="@+id/videocall_menu_bitrate_128_kbps"
android:title="128 kb/s" />
<item android:id="@+id/videocall_menu_bitrate_256_kbps"
android:title="256 kb/s" />
<item android:id="@+id/videocall_menu_bitrate_512_kbps"
android:title="512 kb/s" />
<item android:id="@+id/videocall_menu_bitrate_1024_kbps"
android:title="1024 kb/s" />
</group>
</menu>
</item>
<item android:title="Exit" android:id="@+id/videocall_menu_exit"></item>
</menu>
......@@ -20,11 +20,13 @@ package org.linphone.mediastream;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.linphone.mediastream.video.AndroidVideoWindowImpl;
import org.linphone.mediastream.video.capture.AndroidVideoApi5JniWrapper;
import android.app.Activity;
import android.content.Intent;
import android.hardware.Camera;
import android.opengl.GLSurfaceView;
import android.os.Build;
......@@ -52,9 +54,22 @@ public class MediastreamerActivity extends Activity {
Thread msThread;
int cameraId = 0;
String videoCodec = VP8_MIME_TYPE;
String videoCodec = MPEG4_MIME_TYPE; //VP8_MIME_TYPE;
String remoteIp = "192.168.0.117";//127.0.0.1";
short remotePort = 4000, localPort = 4000;
int bitrate = 256;
boolean pleaseRestart;
AndroidVideoWindowImpl mVideoWindow;
static String BUNDLE_CAMERA_ID_KEY = "CameraIdKey";
static String BUNDLE_VIDEO_CODEC_KEY = "VideoCodecKey";
static String BUNDLE_REMOTE_IP_KEY = "RemoteIpKey";
static String BUNDLE_REMOTE_PORT_KEY = "RemotePortKey";
static String BUNDLE_LOCAL_PORT_KEY = "LocalPortKey";
static String BUNDLE_BITRATE_KEY = "BitrateKey";
static String VP8_MIME_TYPE = "VP8-DRAFT-0-3-2";
static String H264_MIME_TYPE = "H264";
static String MPEG4_MIME_TYPE = "MP4V-ES";
......@@ -92,53 +107,50 @@ public class MediastreamerActivity extends Activity {
/* force surfaces Z ordering */
view.setZOrderOnTop(false);
previewSurface.setZOrderOnTop(true);
// init args from bundle/default values
Bundle bundleToUse = savedInstanceState;
if (bundleToUse == null) {
bundleToUse = getIntent().getExtras();
/* instanciate object responsible of video rendering */
mVideoWindow = new AndroidVideoWindowImpl(view, previewSurface);
mVideoWindow
.setListener(new AndroidVideoWindowImpl.VideoWindowListener() {
public void onVideoPreviewSurfaceReady(AndroidVideoWindowImpl vw) {
setVideoPreviewWindowId(previewSurface);
};
@Override
public void onVideoPreviewSurfaceDestroyed(
AndroidVideoWindowImpl vw) {
}
public void onVideoRenderingSurfaceDestroyed(AndroidVideoWindowImpl vw) {};
public void onVideoRenderingSurfaceReady(AndroidVideoWindowImpl vw) {
setVideoWindowId(vw);
// set device rotation too
setDeviceRotation(rotationToAngle(getWindowManager().getDefaultDisplay()
.getRotation()));
}
});
}
if (bundleToUse != null) {
Set<String> keys = bundleToUse.keySet();
for(String s: keys)
Log.e("sm", "Key: " + s + ", value: " + bundleToUse.get(s));
cameraId = bundleToUse.getInt(BUNDLE_CAMERA_ID_KEY, 0);
if (bundleToUse.containsKey(BUNDLE_VIDEO_CODEC_KEY))
videoCodec = bundleToUse.getString(BUNDLE_VIDEO_CODEC_KEY);
if (bundleToUse.containsKey(BUNDLE_REMOTE_IP_KEY))
remoteIp = bundleToUse.getString(BUNDLE_REMOTE_IP_KEY);
remotePort = bundleToUse.getShort(BUNDLE_REMOTE_PORT_KEY, (short)4000);
localPort = bundleToUse.getShort(BUNDLE_LOCAL_PORT_KEY, (short)4000);
bitrate = bundleToUse.getInt(BUNDLE_BITRATE_KEY, 256);
} else {
Log.w("mediastreamer", "No bundle to restore params from");
}
mVideoWindow.init();
pleaseRestart = false;
// pass arguments to native code
final List<String> args = new ArrayList<String>();
args.add("prog_name");
args.add("--local");
args.add("4000");
args.add(Short.toString(localPort));
args.add("--remote");
args.add("127.0.0.1:4000");
args.add(remoteIp + ":" + remotePort);
args.add("--payload");
args.add("video/" + videoCodec + "/90000");
args.add("--camera");
args.add("Android0");
// if the phone is vertical => supply portrait mode resolution
args.add("Android" + cameraId);
// we pass device rotation as an argument (so mediastream.c can tell the videostream about it BEFORE it's configured)
args.add("--device-rotation");
int rot = rotationToAngle(getWindowManager().getDefaultDisplay()
.getRotation());
if (rot % 180 == 0) {
args.add("--width");
args.add("240");
args.add("--height");
args.add("320");
}
args.add(Integer.toString(rot));
args.add("--bitrate");
args.add(Integer.toString(bitrate*1000));
msThread = new Thread() {
public void run() {
Log.e("ms", "Starting mediastream !");
......@@ -150,6 +162,47 @@ public class MediastreamerActivity extends Activity {
/* start mediastream */
msThread.start();
/* instanciate object responsible of video rendering */
mVideoWindow = new AndroidVideoWindowImpl(view, previewSurface);
mVideoWindow
.setListener(new AndroidVideoWindowImpl.VideoWindowListener() {
public void onVideoPreviewSurfaceReady(AndroidVideoWindowImpl vw, SurfaceView sv) {
setVideoPreviewWindowId(previewSurface);
};
@Override
public void onVideoPreviewSurfaceDestroyed(
AndroidVideoWindowImpl vw) {
}
public void onVideoRenderingSurfaceDestroyed(AndroidVideoWindowImpl vw) {};
public void onVideoRenderingSurfaceReady(AndroidVideoWindowImpl vw, SurfaceView sv) {
setVideoWindowId(vw);
// set device rotation too
setDeviceRotation(rotationToAngle(getWindowManager().getDefaultDisplay()
.getRotation()));
}
});
mVideoWindow.init();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
saveStateToBundle(outState);
}
void saveStateToBundle(Bundle b) {
b.putInt(BUNDLE_CAMERA_ID_KEY, cameraId);
b.putString(BUNDLE_VIDEO_CODEC_KEY, videoCodec);
b.putString(BUNDLE_REMOTE_IP_KEY, remoteIp);
b.putShort(BUNDLE_REMOTE_PORT_KEY, remotePort);
b.putShort(BUNDLE_LOCAL_PORT_KEY, localPort);
b.putInt(BUNDLE_BITRATE_KEY, bitrate);
}
@Override
......@@ -157,12 +210,23 @@ public class MediastreamerActivity extends Activity {
mVideoWindow.release();
stopMediaStream();
try {
msThread.join(100000);
msThread.join(2000);
} catch (Exception exc) {
}
Log.d("ms", "MediastreamerActivity destroyed");
super.onDestroy();
if (pleaseRestart) {
Intent intent = getIntent();
intent.putExtra(BUNDLE_CAMERA_ID_KEY, cameraId);
intent.putExtra(BUNDLE_VIDEO_CODEC_KEY, videoCodec);
intent.putExtra(BUNDLE_REMOTE_IP_KEY, remoteIp);
intent.putExtra(BUNDLE_REMOTE_PORT_KEY, remotePort);
intent.putExtra(BUNDLE_LOCAL_PORT_KEY, localPort);
intent.putExtra(BUNDLE_BITRATE_KEY, bitrate);
startActivity(intent);
}
}
@Override
......@@ -177,6 +241,27 @@ public class MediastreamerActivity extends Activity {
if (Camera.getNumberOfCameras() == 1)
menu.findItem(R.id.videocall_menu_change_camera).setVisible(false);
}
// init UI
if (videoCodec.equals(VP8_MIME_TYPE))
menu.findItem(R.id.videocall_menu_codec_vp8).setChecked(true);
else if (videoCodec.equals(MPEG4_MIME_TYPE))
menu.findItem(R.id.videocall_menu_codec_mpeg4).setChecked(true);
else if (videoCodec.equals(H264_MIME_TYPE))
menu.findItem(R.id.videocall_menu_codec_h264).setChecked(true);
switch (bitrate) {
case 64:
menu.findItem(R.id.videocall_menu_bitrate_64_kbps).setChecked(true); break;
case 128:
menu.findItem(R.id.videocall_menu_bitrate_128_kbps).setChecked(true); break;
case 256:
menu.findItem(R.id.videocall_menu_bitrate_256_kbps).setChecked(true); break;
case 512:
menu.findItem(R.id.videocall_menu_bitrate_512_kbps).setChecked(true); break;
case 1024:
menu.findItem(R.id.videocall_menu_bitrate_1024_kbps).setChecked(true); break;
}
return true;
}
......@@ -191,11 +276,51 @@ public class MediastreamerActivity extends Activity {
changeCamera(cameraId);
setVideoPreviewWindowId(findViewById(R.id.video_capture_surface));
break;
case R.id.videocall_menu_codec_vp8:
updateVideoCodec(VP8_MIME_TYPE);
break;
case R.id.videocall_menu_codec_mpeg4:
updateVideoCodec(MPEG4_MIME_TYPE);
break;
case R.id.videocall_menu_codec_h264:
updateVideoCodec(H264_MIME_TYPE);
break;
case R.id.videocall_menu_bitrate_64_kbps:
updateBitrate(64);
break;
case R.id.videocall_menu_bitrate_128_kbps:
updateBitrate(128);
break;
case R.id.videocall_menu_bitrate_256_kbps:
updateBitrate(256);
break;
case R.id.videocall_menu_bitrate_512_kbps:
updateBitrate(512);
break;
case R.id.videocall_menu_bitrate_1024_kbps:
updateBitrate(1024);
break;
}
return true;
}
private void updateVideoCodec(String newCodec) {
if (newCodec != videoCodec) {
videoCodec = newCodec;
// restart ourself
pleaseRestart = true;
finish();
}
}
private void updateBitrate(int newBr) {
if (newBr != bitrate) {
bitrate = newBr;
pleaseRestart = true;
finish();
}
}
private static void loadOptionalLibrary(String s) {
try {
System.loadLibrary(s);
......
......@@ -23,14 +23,9 @@ import javax.microedition.khronos.opengles.GL10;
import org.linphone.mediastream.video.display.OpenGLESDisplay;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Bitmap.Config;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.opengl.GLSurfaceView;
import android.util.Log;
import android.view.Surface;
......
......@@ -81,7 +81,7 @@ static int preview_window_id = -1;
static int ec_len_ms=0, ec_delay_ms=0, ec_framesize=0;
static void run_media_streams(int localport, const char *remote_ip, int remoteport, int payload, const char *fmtp,
int jitter, int bitrate, MSVideoSize vs, bool_t ec, bool_t agc, bool_t eq);
int jitter, int bitrate, MSVideoSize vs, bool_t ec, bool_t agc, bool_t eq, int device_rotation);
static void stop_handler(int signum)
{
......@@ -383,6 +383,7 @@ int main(int argc, char * argv[])
bool_t agc=FALSE;
bool_t eq=FALSE;
bool_t is_verbose=FALSE;
int device_rotation=-1;
cond = 1;
......@@ -499,7 +500,9 @@ int main(int argc, char * argv[])
printf("%s",usage);
return -1;
}
} else if (strcmp(argv[i], "--device-rotation")==0) {
i++;
device_rotation=atoi(argv[i]);
}else if (strcmp(argv[i],"--help")==0){
printf("%s",usage);
return -1;
......@@ -530,8 +533,7 @@ int main(int argc, char * argv[])
rtp_profile_set_payload(&av_profile,102,&payload_type_h264);
rtp_profile_set_payload(&av_profile,103,&payload_type_vp8);
#endif
run_media_streams(localport,ip,remoteport,payload,fmtp,jitter,bitrate,vs,ec,agc,eq);
run_media_streams(localport,ip,remoteport,payload,fmtp,jitter,bitrate,vs,ec,agc,eq,device_rotation);
ms_exit();
......@@ -542,9 +544,20 @@ int main(int argc, char * argv[])
return 0;
}
static void run_media_streams(int localport, const char *remote_ip, int remoteport, int payload, const char *fmtp,
int jitter, int bitrate, MSVideoSize vs, bool_t ec, bool_t agc, bool_t eq)
{
static void run_media_streams(
int localport,
const char *remote_ip,
int remoteport,
int payload,
const char *fmtp,
int jitter,
int bitrate,
MSVideoSize vs,
bool_t ec,
bool_t agc,
bool_t eq,
int device_rotation
) {
AudioStream *audio=NULL;
#ifdef VIDEO_ENABLED
MSWebCam *cam=NULL;
......@@ -558,6 +571,9 @@ static void run_media_streams(int localport, const char *remote_ip, int remotepo
ms_filter_enable_statistics(TRUE);
ms_filter_reset_statistics();
ms_message("YOUPI: %d\n", bitrate);
signal(SIGINT,stop_handler);
pt=rtp_profile_get_payload(profile,payload);
if (pt==NULL){
......@@ -626,6 +642,10 @@ static void run_media_streams(int localport, const char *remote_ip, int remotepo
}
printf("Starting video stream.\n");
video=video_stream_new(localport, ms_is_ipv6(remote_ip));
#ifdef ANDROID
if (device_rotation >= 0)
video_stream_set_device_rotation(video, device_rotation);
#endif
video_stream_set_sent_video_size(video,vs);
video_stream_use_preview_video_window(video,two_windows);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment