Add stats overlay to iOS AppRTCDemo.

BUG=
R=jiayl@webrtc.org

Review URL: https://codereview.webrtc.org/1289623005 .

Cr-Commit-Position: refs/heads/master@{#9714}
diff --git a/webrtc/examples/objc/AppRTCDemo/ios/ARDStatsView.h b/webrtc/examples/objc/AppRTCDemo/ios/ARDStatsView.h
new file mode 100644
index 0000000..9c86364
--- /dev/null
+++ b/webrtc/examples/objc/AppRTCDemo/ios/ARDStatsView.h
@@ -0,0 +1,17 @@
+/*
+ *  Copyright 2015 The WebRTC Project Authors. All rights reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#import <UIKit/UIKit.h>
+
+@interface ARDStatsView : UIView
+
+- (void)setStats:(NSArray *)stats;
+
+@end
diff --git a/webrtc/examples/objc/AppRTCDemo/ios/ARDStatsView.m b/webrtc/examples/objc/AppRTCDemo/ios/ARDStatsView.m
new file mode 100644
index 0000000..bcc538e
--- /dev/null
+++ b/webrtc/examples/objc/AppRTCDemo/ios/ARDStatsView.m
@@ -0,0 +1,52 @@
+/*
+ *  Copyright 2015 The WebRTC Project Authors. All rights reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#import "ARDStatsView.h"
+
+#import "RTCStatsReport.h"
+
+#import "ARDStatsBuilder.h"
+
+@implementation ARDStatsView {
+  UILabel *_statsLabel;
+  ARDStatsBuilder *_statsBuilder;
+}
+
+- (instancetype)initWithFrame:(CGRect)frame {
+  if (self = [super initWithFrame:frame]) {
+    _statsLabel = [[UILabel alloc] initWithFrame:CGRectZero];
+    _statsLabel.numberOfLines = 0;
+    _statsLabel.font = [UIFont fontWithName:@"Roboto" size:12];
+    _statsLabel.adjustsFontSizeToFitWidth = YES;
+    _statsLabel.minimumScaleFactor = 0.6;
+    _statsLabel.textColor = [UIColor greenColor];
+    [self addSubview:_statsLabel];
+    self.backgroundColor = [UIColor colorWithWhite:0 alpha:.6];
+    _statsBuilder = [[ARDStatsBuilder alloc] init];
+  }
+  return self;
+}
+
+- (void)setStats:(NSArray *)stats {
+  for (RTCStatsReport *report in stats) {
+    [_statsBuilder parseStatsReport:report];
+  }
+  _statsLabel.text = _statsBuilder.statsString;
+}
+
+- (void)layoutSubviews {
+  _statsLabel.frame = self.bounds;
+}
+
+- (CGSize)sizeThatFits:(CGSize)size {
+  return [_statsLabel sizeThatFits:size];
+}
+
+@end
diff --git a/webrtc/examples/objc/AppRTCDemo/ios/ARDVideoCallView.h b/webrtc/examples/objc/AppRTCDemo/ios/ARDVideoCallView.h
index 3208925..209bcd4 100644
--- a/webrtc/examples/objc/AppRTCDemo/ios/ARDVideoCallView.h
+++ b/webrtc/examples/objc/AppRTCDemo/ios/ARDVideoCallView.h
@@ -12,6 +12,8 @@
 
 #import "RTCEAGLVideoView.h"
 
+#import "ARDStatsView.h"
+
 @class ARDVideoCallView;
 @protocol ARDVideoCallViewDelegate <NSObject>
 
@@ -21,6 +23,9 @@
 // Called when the hangup button is pressed.
 - (void)videoCallViewDidHangup:(ARDVideoCallView *)view;
 
+// Called when stats are enabled by triple tapping.
+- (void)videoCallViewDidEnableStats:(ARDVideoCallView *)view;
+
 @end
 
 // Video call view that shows local and remote video, provides a label to
@@ -30,6 +35,7 @@
 @property(nonatomic, readonly) UILabel *statusLabel;
 @property(nonatomic, readonly) RTCEAGLVideoView *localVideoView;
 @property(nonatomic, readonly) RTCEAGLVideoView *remoteVideoView;
+@property(nonatomic, readonly) ARDStatsView *statsView;
 @property(nonatomic, weak) id<ARDVideoCallViewDelegate> delegate;
 
 @end
diff --git a/webrtc/examples/objc/AppRTCDemo/ios/ARDVideoCallView.m b/webrtc/examples/objc/AppRTCDemo/ios/ARDVideoCallView.m
index 45a69cf..4048b84 100644
--- a/webrtc/examples/objc/AppRTCDemo/ios/ARDVideoCallView.m
+++ b/webrtc/examples/objc/AppRTCDemo/ios/ARDVideoCallView.m
@@ -17,6 +17,7 @@
 static CGFloat const kButtonSize = 48;
 static CGFloat const kLocalVideoViewSize = 120;
 static CGFloat const kLocalVideoViewPadding = 8;
+static CGFloat const kStatusBarHeight = 20;
 
 @interface ARDVideoCallView () <RTCEAGLVideoViewDelegate>
 @end
@@ -32,6 +33,7 @@
 @synthesize statusLabel = _statusLabel;
 @synthesize localVideoView = _localVideoView;
 @synthesize remoteVideoView = _remoteVideoView;
+@synthesize statsView = _statsView;
 @synthesize delegate = _delegate;
 
 - (instancetype)initWithFrame:(CGRect)frame {
@@ -46,6 +48,10 @@
     _localVideoView.delegate = self;
     [self addSubview:_localVideoView];
 
+    _statsView = [[ARDStatsView alloc] initWithFrame:CGRectZero];
+    _statsView.hidden = YES;
+    [self addSubview:_statsView];
+
     // TODO(tkchin): don't display this if we can't actually do camera switch.
     _cameraSwitchButton = [UIButton buttonWithType:UIButtonTypeCustom];
     _cameraSwitchButton.backgroundColor = [UIColor whiteColor];
@@ -74,6 +80,13 @@
     _statusLabel.font = [UIFont fontWithName:@"Roboto" size:16];
     _statusLabel.textColor = [UIColor whiteColor];
     [self addSubview:_statusLabel];
+
+    UITapGestureRecognizer *tapRecognizer =
+        [[UITapGestureRecognizer alloc]
+            initWithTarget:self
+                    action:@selector(didTripleTap:)];
+    tapRecognizer.numberOfTapsRequired = 3;
+    [self addGestureRecognizer:tapRecognizer];
   }
   return self;
 }
@@ -118,6 +131,12 @@
     _localVideoView.frame = bounds;
   }
 
+  // Place stats at the top.
+  CGSize statsSize = [_statsView sizeThatFits:bounds.size];
+  _statsView.frame = CGRectMake(CGRectGetMinX(bounds),
+                                CGRectGetMinY(bounds) + kStatusBarHeight,
+                                statsSize.width, statsSize.height);
+
   // Place hangup button in the bottom left.
   _hangupButton.frame =
       CGRectMake(CGRectGetMinX(bounds) + kButtonPadding,
@@ -159,4 +178,8 @@
   [_delegate videoCallViewDidHangup:self];
 }
 
+- (void)didTripleTap:(UITapGestureRecognizer *)recognizer {
+  [_delegate videoCallViewDidEnableStats:self];
+}
+
 @end
diff --git a/webrtc/examples/objc/AppRTCDemo/ios/ARDVideoCallViewController.m b/webrtc/examples/objc/AppRTCDemo/ios/ARDVideoCallViewController.m
index 36c0902..a26068f 100644
--- a/webrtc/examples/objc/AppRTCDemo/ios/ARDVideoCallViewController.m
+++ b/webrtc/examples/objc/AppRTCDemo/ios/ARDVideoCallViewController.m
@@ -88,6 +88,12 @@
 }
 
 - (void)appClient:(ARDAppClient *)client
+      didGetStats:(NSArray *)stats {
+  _videoCallView.statsView.stats = stats;
+  [_videoCallView setNeedsLayout];
+}
+
+- (void)appClient:(ARDAppClient *)client
          didError:(NSError *)error {
   NSString *message =
       [NSString stringWithFormat:@"%@", error.localizedDescription];
@@ -107,6 +113,11 @@
   [self switchCamera];
 }
 
+- (void)videoCallViewDidEnableStats:(ARDVideoCallView *)view {
+  _client.shouldGetStats = YES;
+  _videoCallView.statsView.hidden = NO;
+}
+
 #pragma mark - Private
 
 - (void)setLocalVideoTrack:(RTCVideoTrack *)localVideoTrack {