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
This commit is contained in:
fischman@webrtc.org 2014-05-29 21:46:52 +00:00
parent 21a5d449b7
commit abe01dd634
2 changed files with 26 additions and 6 deletions

View File

@ -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() {

View File

@ -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<Endpoint> 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(