diff --git a/talk/examples/android/res/layout/activity_fullscreen.xml b/talk/examples/android/res/layout/activity_fullscreen.xml
index fc9ee9e28..f3fc003e8 100644
--- a/talk/examples/android/res/layout/activity_fullscreen.xml
+++ b/talk/examples/android/res/layout/activity_fullscreen.xml
@@ -12,6 +12,15 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
+
getReportMap(StatsReport report) {
+ Map reportMap = new HashMap();
+ for (StatsReport.Value value : report.values) {
+ reportMap.put(value.name, value.value);
+ }
+ return reportMap;
+ }
+
+ // Update encoder statistics view with information from |reports|.
+ private void updateEncoderStatistics(StatsReport[] reports) {
+ if (!iceConnected) {
+ return;
+ }
+ String fps = null;
+ String targetBitrate = null;
+ String actualBitrate = null;
+ for (StatsReport report : reports) {
+ if (report.type.equals("ssrc") && report.id.contains("ssrc") &&
+ report.id.contains("send")) {
+ Map reportMap = getReportMap(report);
+ String trackId = reportMap.get("googTrackId");
+ if (trackId != null &&
+ trackId.contains(PeerConnectionClient.VIDEO_TRACK_ID)) {
+ fps = reportMap.get("googFrameRateSent");
+ }
+ } else if (report.id.equals("bweforvideo")) {
+ Map reportMap = getReportMap(report);
+ targetBitrate = reportMap.get("googTargetEncBitrate");
+ actualBitrate = reportMap.get("googActualEncBitrate");
+ }
+ }
+ String stat = "";
+ if (fps != null) {
+ stat += "Fps: " + fps + "\n";
+ }
+ if (targetBitrate != null) {
+ stat += "Target BR: " + targetBitrate + "\n";
+ }
+ if (actualBitrate != null) {
+ stat += "Actual BR: " + actualBitrate;
+ }
+ encoderStatView.setText(stat);
+ }
+
// -----Implementation of AppRTCClient.AppRTCSignalingEvents ---------------
// All events are called from UI thread.
@Override
@@ -410,37 +463,39 @@ public class AppRTCDemoActivity extends Activity
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}
- {
- final Runnable repeatedStatsLogger = new Runnable() {
- public void run() {
- if (pc == null) {
- return;
- }
- final Runnable runnableThis = this;
- if (hudView.getVisibility() == View.INVISIBLE) {
- videoView.postDelayed(runnableThis, 1000);
- return;
- }
- boolean success = pc.getStats(new StatsObserver() {
- public void onComplete(final StatsReport[] reports) {
- runOnUiThread(new Runnable() {
- public void run() {
- updateHUD(reports);
- }
- });
- for (StatsReport report : reports) {
- Log.d(TAG, "Stats: " + report.toString());
+ // Schedule statistics display.
+ final Runnable repeatedStatsLogger = new Runnable() {
+ public void run() {
+ if (pc == null) {
+ return;
+ }
+ final Runnable runnableThis = this;
+ if (hudView.getVisibility() == View.INVISIBLE &&
+ encoderStatView.getVisibility() == View.INVISIBLE) {
+ videoView.postDelayed(runnableThis, 1000);
+ return;
+ }
+ boolean success = pc.getStats(new StatsObserver() {
+ public void onComplete(final StatsReport[] reports) {
+ runOnUiThread(new Runnable() {
+ public void run() {
+ if (hudView.getVisibility() == View.VISIBLE) {
+ updateHUD(reports);
+ }
+ if (encoderStatView.getVisibility() == View.VISIBLE) {
+ updateEncoderStatistics(reports);
+ }
}
- videoView.postDelayed(runnableThis, 1000);
- }
- }, null);
- if (!success) {
- throw new RuntimeException("getStats() return false!");
+ });
+ videoView.postDelayed(runnableThis, 1000);
}
- }
- };
- videoView.postDelayed(repeatedStatsLogger, 1000);
- }
+ }, null);
+ if (!success) {
+ throw new RuntimeException("getStats() return false!");
+ }
+ }
+ };
+ videoView.postDelayed(repeatedStatsLogger, 1000);
logAndToast("Waiting for remote connection...");
}
diff --git a/talk/examples/android/src/org/appspot/apprtc/PeerConnectionClient.java b/talk/examples/android/src/org/appspot/apprtc/PeerConnectionClient.java
index 247b0aa66..0b357e02d 100644
--- a/talk/examples/android/src/org/appspot/apprtc/PeerConnectionClient.java
+++ b/talk/examples/android/src/org/appspot/apprtc/PeerConnectionClient.java
@@ -54,6 +54,9 @@ import java.util.regex.Pattern;
public class PeerConnectionClient {
private static final String TAG = "PCRTCClient";
+ public static final String VIDEO_TRACK_ID = "ARDAMSv0";
+ public static final String AUDIO_TRACK_ID = "ARDAMSa0";
+
private final Activity activity;
private PeerConnectionFactory factory;
private PeerConnection pc;
@@ -119,7 +122,7 @@ public class PeerConnectionClient {
if (signalingParameters.audioConstraints != null) {
MediaStream lMS = factory.createLocalMediaStream("ARDAMSAudio");
lMS.addTrack(factory.createAudioTrack(
- "ARDAMSa0",
+ AUDIO_TRACK_ID,
factory.createAudioSource(signalingParameters.audioConstraints)));
pc.addStream(lMS);
}
@@ -320,7 +323,7 @@ public class PeerConnectionClient {
capturer, videoConstraints);
String trackExtension = frontFacing ? "frontFacing" : "backFacing";
VideoTrack videoTrack =
- factory.createVideoTrack("ARDAMSv0" + trackExtension, videoSource);
+ factory.createVideoTrack(VIDEO_TRACK_ID + trackExtension, videoSource);
videoTrack.addRenderer(new VideoRenderer(localRender));
return videoTrack;
}