Refactor some ObjC API init methods.

initWithFactory: is clumsy and makes classes difficult to mock out in
tests. By keeping methods on the factory, we can simply mock out the
factory's methods instead.

We can consider adding regular Obj-C like ctors if we move to making
the factory a singleton, but that requires further discussion.

BUG=
R=haysc@webrtc.org, hjon@webrtc.org

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

Cr-Commit-Position: refs/heads/master@{#12089}
diff --git a/webrtc/examples/objc/AppRTCDemo/ARDAppClient.m b/webrtc/examples/objc/AppRTCDemo/ARDAppClient.m
index 32d237a..d8dc771 100644
--- a/webrtc/examples/objc/AppRTCDemo/ARDAppClient.m
+++ b/webrtc/examples/objc/AppRTCDemo/ARDAppClient.m
@@ -502,10 +502,9 @@
   RTCMediaConstraints *constraints = [self defaultPeerConnectionConstraints];
   RTCConfiguration *config = [[RTCConfiguration alloc] init];
   config.iceServers = _iceServers;
-  _peerConnection = [[RTCPeerConnection alloc] initWithFactory:_factory
-                                                 configuration:config
-                                                   constraints:constraints
-                                                      delegate:self];
+  _peerConnection = [_factory peerConnectionWithConfiguration:config
+                                                  constraints:constraints
+                                                     delegate:self];
   // Create AV media stream and add it to the peer connection.
   RTCMediaStream *localStream = [self createLocalMediaStream];
   [_peerConnection addStream:localStream];
@@ -608,16 +607,14 @@
 }
 
 - (RTCMediaStream *)createLocalMediaStream {
-  RTCMediaStream *localStream =
-      [[RTCMediaStream alloc] initWithFactory:_factory streamId:@"ARDAMS"];
+  RTCMediaStream *localStream = [_factory mediaStreamWithStreamId:@"ARDAMS"];
   RTCVideoTrack *localVideoTrack = [self createLocalVideoTrack];
   if (localVideoTrack) {
     [localStream addVideoTrack:localVideoTrack];
     [_delegate appClient:self didReceiveLocalVideoTrack:localVideoTrack];
   }
   RTCAudioTrack *localAudioTrack =
-        [[RTCAudioTrack alloc] initWithFactory:_factory
-                                       trackId:@"ARDAMSa0"];
+      [_factory audioTrackWithTrackId:@"ARDAMSa0"];
   [localStream addAudioTrack:localAudioTrack];
   return localStream;
 }
@@ -634,12 +631,10 @@
     RTCMediaConstraints *mediaConstraints =
         [self defaultMediaStreamConstraints];
     RTCAVFoundationVideoSource *source =
-        [[RTCAVFoundationVideoSource alloc] initWithFactory:_factory
-                                                constraints:mediaConstraints];
+        [_factory avFoundationVideoSourceWithConstraints:mediaConstraints];
     localVideoTrack =
-        [[RTCVideoTrack alloc] initWithFactory:_factory
-                                        source:source
-                                       trackId:@"ARDAMSv0"];
+        [_factory videoTrackWithSource:source
+                               trackId:@"ARDAMSv0"];
   }
 #endif
   return localVideoTrack;