From abe01dd634cd92245b7836e687de0f6e7c0723b9 Mon Sep 17 00:00:00 2001 From: "fischman@webrtc.org" Date: Thu, 29 May 2014 21:46:52 +0000 Subject: [PATCH] AppRTCDemo(android): run in full-screen & immersive mode. Also: - Only show stats HUD on demand - Only collect stats when HUD is showing - Don't render solid green frame when video is not present in either direction R=glaznev@webrtc.org Review URL: https://webrtc-codereview.appspot.com/12639004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@6275 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../appspot/apprtc/AppRTCDemoActivity.java | 12 +++++++---- .../org/appspot/apprtc/VideoStreamsView.java | 20 +++++++++++++++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/talk/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java b/talk/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java index 0ab47a9629..dea251a5ff 100644 --- a/talk/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java +++ b/talk/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java @@ -109,7 +109,7 @@ public class AppRTCDemoActivity extends Activity getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); Point displaySize = new Point(); - getWindowManager().getDefaultDisplay().getSize(displaySize); + getWindowManager().getDefaultDisplay().getRealSize(displaySize); vsv = new VideoStreamsView(this, displaySize); vsv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -117,11 +117,14 @@ public class AppRTCDemoActivity extends Activity } }); setContentView(vsv); + logAndToast("Tap the screen to toggle stats visibility"); + hudView = new TextView(this); hudView.setTextColor(Color.BLACK); hudView.setBackgroundColor(Color.WHITE); hudView.setAlpha(0.4f); hudView.setTextSize(TypedValue.COMPLEX_UNIT_PT, 5); + hudView.setVisibility(View.INVISIBLE); addContentView(hudView, hudLayout); if (!factoryStaticInitialized) { @@ -189,9 +192,6 @@ public class AppRTCDemoActivity extends Activity // 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")) { @@ -264,6 +264,10 @@ public class AppRTCDemoActivity extends Activity return; } final Runnable runnableThis = this; + if (hudView.getVisibility() == View.INVISIBLE) { + vsv.postDelayed(runnableThis, 1000); + return; + } boolean success = finalPC.getStats(new StatsObserver() { public void onComplete(final StatsReport[] reports) { runOnUiThread(new Runnable() { diff --git a/talk/examples/android/src/org/appspot/apprtc/VideoStreamsView.java b/talk/examples/android/src/org/appspot/apprtc/VideoStreamsView.java index 906aa92ced..ca9cd4e1a7 100644 --- a/talk/examples/android/src/org/appspot/apprtc/VideoStreamsView.java +++ b/talk/examples/android/src/org/appspot/apprtc/VideoStreamsView.java @@ -40,6 +40,7 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import java.util.EnumMap; +import java.util.EnumSet; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; @@ -64,6 +65,8 @@ public class VideoStreamsView private Point screenDimensions; // [0] are local Y,U,V, [1] are remote Y,U,V. private int[][] yuvTextures = { { -1, -1, -1}, {-1, -1, -1 }}; + private EnumSet seenFrameInDirection = + EnumSet.noneOf(Endpoint.class); private int posLocation = -1; private long lastFPSLogTime = System.nanoTime(); private long numFramesSinceLastLog = 0; @@ -115,10 +118,12 @@ public class VideoStreamsView remoteFrame = framesToRender.remove(Endpoint.REMOTE); } if (localFrame != null) { + seenFrameInDirection.add(Endpoint.LOCAL); texImage2D(localFrame, yuvTextures[0]); framePool.returnFrame(localFrame); } if (remoteFrame != null) { + seenFrameInDirection.add(Endpoint.REMOTE); texImage2D(remoteFrame, yuvTextures[1]); framePool.returnFrame(remoteFrame); } @@ -167,8 +172,12 @@ public class VideoStreamsView @Override public void onDrawFrame(GL10 unused) { GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); - drawRectangle(yuvTextures[1], remoteVertices); - drawRectangle(yuvTextures[0], localVertices); + if (seenFrameInDirection.contains(Endpoint.REMOTE)) { + drawRectangle(yuvTextures[1], remoteVertices); + } + if (seenFrameInDirection.contains(Endpoint.LOCAL)) { + drawRectangle(yuvTextures[0], localVertices); + } ++numFramesSinceLastLog; long now = System.nanoTime(); if (lastFPSLogTime == -1 || now - lastFPSLogTime > 1e9) { @@ -210,6 +219,13 @@ public class VideoStreamsView checkNoGLES2Error(); } + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + setSystemUiVisibility(SYSTEM_UI_FLAG_HIDE_NAVIGATION | + SYSTEM_UI_FLAG_FULLSCREEN | SYSTEM_UI_FLAG_IMMERSIVE_STICKY); + } + // Wrap a float[] in a direct FloatBuffer using native byte order. private static FloatBuffer directNativeFloatBuffer(float[] array) { FloatBuffer buffer = ByteBuffer.allocateDirect(array.length * 4).order(