Add a UIView for rendering a video track.

RTCEAGLVideoView provides functionality to render a supplied RTCVideoTrack using OpenGLES2.

R=fischman@webrtc.org
BUG=3188

Review URL: https://webrtc-codereview.appspot.com/12489004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6192 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/talk/examples/ios/AppRTCDemo/APPRTCViewController.m b/talk/examples/ios/AppRTCDemo/APPRTCViewController.m
index 0ac9282..bdd8b50 100644
--- a/talk/examples/ios/AppRTCDemo/APPRTCViewController.m
+++ b/talk/examples/ios/AppRTCDemo/APPRTCViewController.m
@@ -27,12 +27,11 @@
 
 #import "APPRTCViewController.h"
 
-#import "APPRTCVideoView.h"
+#import <AVFoundation/AVFoundation.h>
+#import "RTCEAGLVideoView.h"
 
 @interface APPRTCViewController ()
-
 @property(nonatomic, assign) UIInterfaceOrientation statusBarOrientation;
-
 @end
 
 @implementation APPRTCViewController
@@ -75,12 +74,10 @@
   self.logView.text = nil;
   self.blackView.hidden = YES;
 
-  [_remoteVideoView renderVideoTrackInterface:nil];
-  [_remoteVideoView removeFromSuperview];
+  [self.remoteVideoView removeFromSuperview];
   self.remoteVideoView = nil;
 
-  [_localVideoView renderVideoTrackInterface:nil];
-  [_localVideoView removeFromSuperview];
+  [self.localVideoView removeFromSuperview];
   self.localVideoView = nil;
 }
 
@@ -97,46 +94,29 @@
 - (void)setupCaptureSession {
   self.blackView.hidden = NO;
 
-  CGRect frame =
-      CGRectMake((self.blackView.bounds.size.width - kRemoteVideoWidth) / 2,
-                 (self.blackView.bounds.size.height - kRemoteVideoHeight) / 2,
-                 kRemoteVideoWidth,
-                 kRemoteVideoHeight);
-  APPRTCVideoView* videoView = [[APPRTCVideoView alloc] initWithFrame:frame];
-  videoView.isRemote = TRUE;
+  CGSize videoSize =
+        CGSizeMake(kRemoteVideoWidth, kRemoteVideoHeight);
+  CGRect remoteVideoFrame =
+      AVMakeRectWithAspectRatioInsideRect(videoSize,
+                                          self.blackView.bounds);
+  CGRect localVideoFrame = remoteVideoFrame;
+  // TODO(tkchin): use video dimensions from incoming video stream
+  // and handle rotation.
+  localVideoFrame.size.width = remoteVideoFrame.size.height / 4;
+  localVideoFrame.size.height = remoteVideoFrame.size.width / 4;
+  localVideoFrame.origin.x = CGRectGetMaxX(remoteVideoFrame)
+      - localVideoFrame.size.width - kLocalViewPadding;
+  localVideoFrame.origin.y = CGRectGetMaxY(remoteVideoFrame)
+      - localVideoFrame.size.height - kLocalViewPadding;
 
-  [self.blackView addSubview:videoView];
-  videoView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin |
-                               UIViewAutoresizingFlexibleRightMargin |
-                               UIViewAutoresizingFlexibleBottomMargin |
-                               UIViewAutoresizingFlexibleTopMargin;
-  videoView.translatesAutoresizingMaskIntoConstraints = YES;
-  _remoteVideoView = videoView;
+  self.remoteVideoView =
+      [[RTCEAGLVideoView alloc] initWithFrame:remoteVideoFrame];
+  [self.blackView addSubview:self.remoteVideoView];
+  self.remoteVideoView.transform = CGAffineTransformMakeScale(-1, 1);
 
-  CGSize screenSize = [[UIScreen mainScreen] bounds].size;
-  CGFloat localVideoViewWidth =
-      UIInterfaceOrientationIsPortrait(self.statusBarOrientation)
-          ? screenSize.width / 4
-          : screenSize.height / 4;
-  CGFloat localVideoViewHeight =
-      UIInterfaceOrientationIsPortrait(self.statusBarOrientation)
-          ? screenSize.height / 4
-          : screenSize.width / 4;
-  frame = CGRectMake(self.blackView.bounds.size.width - localVideoViewWidth -
-                         kLocalViewPadding,
-                     kLocalViewPadding,
-                     localVideoViewWidth,
-                     localVideoViewHeight);
-  videoView = [[APPRTCVideoView alloc] initWithFrame:frame];
-  videoView.isRemote = FALSE;
-
-  [self.blackView addSubview:videoView];
-  videoView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin |
-                               UIViewAutoresizingFlexibleBottomMargin |
-                               UIViewAutoresizingFlexibleHeight |
-                               UIViewAutoresizingFlexibleWidth;
-  videoView.translatesAutoresizingMaskIntoConstraints = YES;
-  _localVideoView = videoView;
+  self.localVideoView =
+      [[RTCEAGLVideoView alloc] initWithFrame:localVideoFrame];
+  [self.blackView addSubview:self.localVideoView];
 }
 
 #pragma mark - UITextFieldDelegate