summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfischman@webrtc.org <fischman@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d>2014-05-01 20:57:55 +0000
committerfischman@webrtc.org <fischman@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d>2014-05-01 20:57:55 +0000
commit4b152724823c01ba69b8eb4ef1db9633cbced1c4 (patch)
tree1633a768c03e6c87a31fab5d8017ff4e13c8cd22
parent86c7f60d38092f09e2d6c25b79274d15028713b4 (diff)
downloadtalk-4b152724823c01ba69b8eb4ef1db9633cbced1c4.tar.gz
AppRTCDemo(android): added a Heads-Up Display for bandwidth estimation.
- tap display to toggle visibility - increased getStats frequency to 1hz. R=glaznev@google.com Review URL: https://webrtc-codereview.appspot.com/19419004 git-svn-id: http://webrtc.googlecode.com/svn/trunk/talk@6039 4adac7df-926f-26a2-2b94-8c16560cd09d
-rw-r--r--examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java59
1 files changed, 56 insertions, 3 deletions
diff --git a/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java b/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java
index ad0b3fa..28ac53d 100644
--- a/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java
+++ b/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java
@@ -31,13 +31,18 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
+import android.graphics.Color;
import android.graphics.Point;
import android.media.AudioManager;
import android.os.Bundle;
import android.util.Log;
+import android.util.TypedValue;
+import android.view.View;
+import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.webkit.JavascriptInterface;
import android.widget.EditText;
+import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONException;
@@ -84,6 +89,9 @@ public class AppRTCDemoActivity extends Activity
private AppRTCClient appRtcClient = new AppRTCClient(this, gaeHandler, this);
private VideoStreamsView vsv;
private Toast logToast;
+ private final LayoutParams hudLayout =
+ new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
+ private TextView hudView;
private LinkedList<IceCandidate> queuedRemoteCandidates =
new LinkedList<IceCandidate>();
// Synchronize on quit[0] to avoid teardown-related crashes.
@@ -103,7 +111,18 @@ public class AppRTCDemoActivity extends Activity
Point displaySize = new Point();
getWindowManager().getDefaultDisplay().getSize(displaySize);
vsv = new VideoStreamsView(this, displaySize);
+ vsv.setOnClickListener(new View.OnClickListener() {
+ @Override public void onClick(View v) {
+ toggleHUD();
+ }
+ });
setContentView(vsv);
+ hudView = new TextView(this);
+ hudView.setTextColor(Color.BLACK);
+ hudView.setBackgroundColor(Color.WHITE);
+ hudView.setAlpha(0.4f);
+ hudView.setTextSize(TypedValue.COMPLEX_UNIT_PT, 5);
+ addContentView(hudView, hudLayout);
if (!factoryStaticInitialized) {
abortUnless(PeerConnectionFactory.initializeAndroidGlobals(this),
@@ -158,6 +177,35 @@ public class AppRTCDemoActivity extends Activity
appRtcClient.connectToRoom(roomUrl);
}
+ // Toggle visibility of the heads-up display.
+ private void toggleHUD() {
+ if (hudView.getVisibility() == View.VISIBLE) {
+ hudView.setVisibility(View.INVISIBLE);
+ } else {
+ hudView.setVisibility(View.VISIBLE);
+ }
+ }
+
+ // Update the heads-up display with information from |reports|.
+ private void updateHUD(StatsReport[] reports) {
+ if (hudView.getText().length() == 0) {
+ logAndToast("Tap the screen to toggle stats visibility");
+ }
+ StringBuilder builder = new StringBuilder();
+ for (StatsReport report : reports) {
+ if (!report.id.equals("bweforvideo")) {
+ continue;
+ }
+ for (StatsReport.Value value : report.values) {
+ String name = value.name.replace("goog", "").replace("Available", "")
+ .replace("Bandwidth", "").replace("Bitrate", "").replace("Enc", "");
+ builder.append(name).append("=").append(value.value).append(" ");
+ }
+ builder.append("\n");
+ }
+ hudView.setText(builder.toString() + hudView.getText());
+ }
+
@Override
public void onPause() {
super.onPause();
@@ -216,11 +264,16 @@ public class AppRTCDemoActivity extends Activity
}
final Runnable runnableThis = this;
boolean success = finalPC.getStats(new StatsObserver() {
- public void onComplete(StatsReport[] reports) {
+ public void onComplete(final StatsReport[] reports) {
+ runOnUiThread(new Runnable() {
+ public void run() {
+ updateHUD(reports);
+ }
+ });
for (StatsReport report : reports) {
Log.d(TAG, "Stats: " + report.toString());
}
- vsv.postDelayed(runnableThis, 10000);
+ vsv.postDelayed(runnableThis, 1000);
}
}, null);
if (!success) {
@@ -229,7 +282,7 @@ public class AppRTCDemoActivity extends Activity
}
}
};
- vsv.postDelayed(repeatedStatsLogger, 10000);
+ vsv.postDelayed(repeatedStatsLogger, 1000);
}
{