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@6039 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
		| @@ -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); | ||||
|     } | ||||
|  | ||||
|     { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 fischman@webrtc.org
					fischman@webrtc.org