Add a few functions to android test application

1. Add playing ringtone
2. Add receiving headset plug intent
3. Add a runnable to simulate cpu load

BUG=
TEST=trybot
Review URL: https://webrtc-codereview.appspot.com/858007

git-svn-id: http://webrtc.googlecode.com/svn/trunk@2892 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
leozwang@webrtc.org 2012-10-09 20:20:37 +00:00
parent e4c920fb3d
commit 71c13765ad
5 changed files with 116 additions and 18 deletions

View File

@ -13,16 +13,11 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.HEADSET_PLUG"/>
</intent-filter>
</activity>
</application>
<receiver android:name="com.juno.brheadset.HeadsetStateReceiver">
<intent-filter>
<action android:name="android.intent.action.HEADSET_PLUG"/>
</intent-filter>
</receiver>
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<uses-feature android:name="android.hardware.camera" />

View File

@ -447,7 +447,6 @@ JNIEXPORT jint JNICALL Java_org_webrtc_videoengineapp_ViEAndroidJavaAPI_Terminat
return -1;
}
memset(&vieData, 0, sizeof(vieData));
VideoEngine::SetAndroidObjects(NULL, NULL);
return 0;
}
else {

View File

@ -61,6 +61,12 @@
android:id="@+id/LinearLayout03"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cbCPULoad"
android:text="@string/cpuload">
</CheckBox>
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"

View File

@ -10,6 +10,7 @@
<string name="remoteIp">Remote IP address</string>
<string name="loopback">Loopback</string>
<string name="stats">Stats</string>
<string name="cpuload">CPULoad</string>
<string name="startListen">Start Listen</string>
<string name="startSend">Start Send</string>
<string name="startBoth">Start Both</string>

View File

@ -11,6 +11,7 @@
package org.webrtc.videoengineapp;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
@ -37,11 +38,12 @@ import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.hardware.SensorManager;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
@ -51,15 +53,14 @@ import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.view.Display;
import android.view.OrientationEventListener;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
@ -68,7 +69,6 @@ import android.widget.TabHost;
import android.widget.TextView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.TabHost.TabSpec;
import android.view.OrientationEventListener;
public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
View.OnClickListener,
@ -99,6 +99,7 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
private static final int SEND_CODEC_FRAMERATE = 15;
private static final int INIT_BITRATE = 500;
private static final String LOOPBACK_IP = "127.0.0.1";
private static final String RINGTONE_URL = "content://settings/system/ringtone";
private int volumeLevel = 204;
@ -127,6 +128,8 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
private boolean loopbackMode = true;
private CheckBox cbStats;
private boolean isStatsOn = true;
private CheckBox cbCPULoad;
private boolean isCPULoadOn = true;
private boolean useOpenGLRender = true;
// Video settings
@ -181,6 +184,9 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
"352x288", "640x480" };
private String[] mVoiceCodecsStrings = null;
private Thread mBackgroundLoad = null;
private boolean mIsBackgroudLoadRunning = false;
private OrientationEventListener orientationListener;
int currentOrientation = OrientationEventListener.ORIENTATION_UNKNOWN;
int currentCameraOrientation = 0;
@ -241,14 +247,21 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
if (am.isWiredHeadsetOn()) {
enableSpeaker = false;
if (intent.getAction().compareTo(Intent.ACTION_HEADSET_PLUG)
== 0) {
int state = intent.getIntExtra("state", 0);
Log.v(TAG, "Intent.ACTION_HEADSET_PLUG state: " + state +
" microphone: " + intent.getIntExtra("microphone", 0));
if (voERunning) {
if (state == 1) {
enableSpeaker = true;
}
else {
enableSpeaker = false;
}
RouteAudio(enableSpeaker);
}
}
else {
enableSpeaker = true;
}
RouteAudio(enableSpeaker);
}
};
registerReceiver(receiver, receiverFilter );
@ -309,6 +322,14 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
return;
}
// Called before the activity is destroyed.
@Override
public void onDestroy() {
Log.d(TAG, "onDestroy");
super.onDestroy();
unregisterReceiver(receiver);
}
private class StatsView extends View{
public StatsView(Context context){
super(context);
@ -378,6 +399,9 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
Log.d(TAG, "StopAll");
if (ViEAndroidAPI != null) {
StopCPULoad();
if (voERunning) {
voERunning = false;
StopVoiceEngine();
@ -506,6 +530,9 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
cbStats = (CheckBox) findViewById(R.id.cbStats);
cbStats.setChecked(isStatsOn);
cbCPULoad = (CheckBox) findViewById(R.id.cbCPULoad);
cbCPULoad.setChecked(isCPULoadOn);
cbVoice = (CheckBox) findViewById(R.id.cbVoice);
cbVoice.setChecked(enableVoice);
@ -550,6 +577,7 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
etRemoteIp.setOnClickListener(this);
cbLoopback.setOnClickListener(this);
cbStats.setOnClickListener(this);
cbCPULoad.setOnClickListener(this);
cbEnableNack.setOnClickListener(this);
cbEnableSpeaker.setOnClickListener(this);
cbEnableAECM.setOnClickListener(this);
@ -576,9 +604,23 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
return etRemoteIp.getText().toString();
}
private void StartPlayingRingtone() {
MediaPlayer mMediaPlayer = new MediaPlayer();
try {
mMediaPlayer.setDataSource(this, Uri.parse(RINGTONE_URL));
mMediaPlayer.prepare();
mMediaPlayer.seekTo(0);
mMediaPlayer.start();
} catch (IOException e) {
Log.v(TAG, "MediaPlayer Failed: " + e);
}
}
private void StartCall() {
int ret = 0;
StartPlayingRingtone();
if (enableVoice) {
StartVoiceEngine();
}
@ -660,6 +702,14 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
RemoveSatsView();
}
isCPULoadOn = cbCPULoad.isChecked();
if (isCPULoadOn) {
StartCPULoad();
}
else {
StopCPULoad();
}
viERunning = true;
}
}
@ -837,6 +887,15 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
RemoveSatsView();
}
break;
case R.id.cbCPULoad:
isCPULoadOn = cbCPULoad.isChecked();
if (isCPULoadOn) {
StartCPULoad();
}
else {
StopCPULoad();
}
break;
case R.id.radio_surface:
useOpenGLRender = false;
break;
@ -1008,4 +1067,42 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
mTabHost.removeView(statsView);
statsView = null;
}
private void StartCPULoad() {
if (null == mBackgroundLoad) {
mBackgroundLoad = new Thread(new Runnable() {
public void run() {
Log.v(TAG, "Background load started");
mIsBackgroudLoadRunning = true;
try{
while (mIsBackgroudLoadRunning) {
// This while simulates cpu load.
// Log.v(TAG, "Runnable!!!");
}
}
catch(Throwable t) {
Log.v(TAG, "StartCPULoad failed");
}
}
});
mBackgroundLoad.start();
}
else {
if (mBackgroundLoad.getState() == Thread.State.TERMINATED) {
mBackgroundLoad.start();
}
}
}
private void StopCPULoad() {
if (null != mBackgroundLoad) {
mIsBackgroudLoadRunning = false;
try{
mBackgroundLoad.join();
}
catch(Throwable t) {
Log.v(TAG, "StopCPULoad failed");
}
}
}
}