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/api/objc/RTCAVFoundationVideoSource+Private.h b/webrtc/api/objc/RTCAVFoundationVideoSource+Private.h
index 64da9aa..067e506 100644
--- a/webrtc/api/objc/RTCAVFoundationVideoSource+Private.h
+++ b/webrtc/api/objc/RTCAVFoundationVideoSource+Private.h
@@ -18,6 +18,10 @@
@property(nonatomic, readonly) webrtc::AVFoundationVideoCapturer *capturer;
+/** Initialize an RTCAVFoundationVideoSource with constraints. */
+- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
+ constraints:(nullable RTCMediaConstraints *)constraints;
+
@end
NS_ASSUME_NONNULL_END
diff --git a/webrtc/api/objc/RTCAVFoundationVideoSource.h b/webrtc/api/objc/RTCAVFoundationVideoSource.h
index 1d1eac0..d7cdbef 100644
--- a/webrtc/api/objc/RTCAVFoundationVideoSource.h
+++ b/webrtc/api/objc/RTCAVFoundationVideoSource.h
@@ -25,8 +25,7 @@
*/
@interface RTCAVFoundationVideoSource : RTCVideoSource
-- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
- constraints:(nullable RTCMediaConstraints *)constraints;
+- (instancetype)init NS_UNAVAILABLE;
/** Returns whether rear-facing camera is available for use. */
@property(nonatomic, readonly) BOOL canUseBackCamera;
diff --git a/webrtc/api/objc/RTCAudioTrack+Private.h b/webrtc/api/objc/RTCAudioTrack+Private.h
index ce3298e..bcedca6 100644
--- a/webrtc/api/objc/RTCAudioTrack+Private.h
+++ b/webrtc/api/objc/RTCAudioTrack+Private.h
@@ -20,6 +20,10 @@
@property(nonatomic, readonly)
rtc::scoped_refptr<webrtc::AudioTrackInterface> nativeAudioTrack;
+/** Initialize an RTCAudioTrack with an id. */
+- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
+ trackId:(NSString *)trackId;
+
@end
NS_ASSUME_NONNULL_END
diff --git a/webrtc/api/objc/RTCAudioTrack.h b/webrtc/api/objc/RTCAudioTrack.h
index 76036cc..284206e 100644
--- a/webrtc/api/objc/RTCAudioTrack.h
+++ b/webrtc/api/objc/RTCAudioTrack.h
@@ -18,10 +18,6 @@
- (instancetype)init NS_UNAVAILABLE;
-/** Initialize an RTCAudioTrack with an id. */
-- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
- trackId:(NSString *)trackId;
-
@end
NS_ASSUME_NONNULL_END
diff --git a/webrtc/api/objc/RTCMediaStream+Private.h b/webrtc/api/objc/RTCMediaStream+Private.h
index 4c83288..b03b091 100644
--- a/webrtc/api/objc/RTCMediaStream+Private.h
+++ b/webrtc/api/objc/RTCMediaStream+Private.h
@@ -23,6 +23,10 @@
@property(nonatomic, readonly)
rtc::scoped_refptr<webrtc::MediaStreamInterface> nativeMediaStream;
+/** Initialize an RTCMediaStream with an id. */
+- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
+ streamId:(NSString *)streamId;
+
/** Initialize an RTCMediaStream from a native MediaStreamInterface. */
- (instancetype)initWithNativeMediaStream:
(rtc::scoped_refptr<webrtc::MediaStreamInterface>)nativeMediaStream;
diff --git a/webrtc/api/objc/RTCMediaStream.h b/webrtc/api/objc/RTCMediaStream.h
index e3ab754..50ae7df 100644
--- a/webrtc/api/objc/RTCMediaStream.h
+++ b/webrtc/api/objc/RTCMediaStream.h
@@ -29,10 +29,6 @@
- (instancetype)init NS_UNAVAILABLE;
-/** Initialize an RTCMediaStream with an id. */
-- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
- streamId:(NSString *)streamId;
-
/** Adds the given audio track to this media stream. */
- (void)addAudioTrack:(RTCAudioTrack *)audioTrack;
diff --git a/webrtc/api/objc/RTCPeerConnection+Private.h b/webrtc/api/objc/RTCPeerConnection+Private.h
index feac8be..031631a 100644
--- a/webrtc/api/objc/RTCPeerConnection+Private.h
+++ b/webrtc/api/objc/RTCPeerConnection+Private.h
@@ -58,6 +58,19 @@
@property(nonatomic, readonly)
rtc::scoped_refptr<webrtc::PeerConnectionInterface> nativePeerConnection;
+/** Initialize an RTCPeerConnection with a configuration, constraints, and
+ * delegate.
+ */
+- (instancetype)initWithFactory:
+ (RTCPeerConnectionFactory *)factory
+ configuration:
+ (RTCConfiguration *)configuration
+ constraints:
+ (RTCMediaConstraints *)constraints
+ delegate:
+ (nullable id<RTCPeerConnectionDelegate>)delegate
+ NS_DESIGNATED_INITIALIZER;
+
+ (webrtc::PeerConnectionInterface::SignalingState)nativeSignalingStateForState:
(RTCSignalingState)state;
diff --git a/webrtc/api/objc/RTCPeerConnection.h b/webrtc/api/objc/RTCPeerConnection.h
index 2c5c19e..e0f9b78 100644
--- a/webrtc/api/objc/RTCPeerConnection.h
+++ b/webrtc/api/objc/RTCPeerConnection.h
@@ -117,19 +117,6 @@
- (instancetype)init NS_UNAVAILABLE;
-/** Initialize an RTCPeerConnection with a configuration, constraints, and
- * delegate.
- */
-- (instancetype)initWithFactory:
- (RTCPeerConnectionFactory *)factory
- configuration:
- (RTCConfiguration *)configuration
- constraints:
- (RTCMediaConstraints *)constraints
- delegate:
- (nullable id<RTCPeerConnectionDelegate>)delegate
- NS_DESIGNATED_INITIALIZER;
-
/** Sets the PeerConnection's global configuration to |configuration|.
* Any changes to STUN/TURN servers or ICE candidate policy will affect the
* next gathering phase, and cause the next call to createOffer to generate
diff --git a/webrtc/api/objc/RTCPeerConnectionFactory.h b/webrtc/api/objc/RTCPeerConnectionFactory.h
index c427c1b..8897c99 100644
--- a/webrtc/api/objc/RTCPeerConnectionFactory.h
+++ b/webrtc/api/objc/RTCPeerConnectionFactory.h
@@ -12,7 +12,48 @@
NS_ASSUME_NONNULL_BEGIN
+#if defined(WEBRTC_IOS)
+@class RTCAVFoundationVideoSource;
+#endif
+@class RTCAudioTrack;
+@class RTCConfiguration;
+@class RTCMediaConstraints;
+@class RTCMediaStream;
+@class RTCPeerConnection;
+@class RTCVideoSource;
+@class RTCVideoTrack;
+@protocol RTCPeerConnectionDelegate;
+
@interface RTCPeerConnectionFactory : NSObject
+
+- (instancetype)init NS_DESIGNATED_INITIALIZER;
+
+#if defined(WEBRTC_IOS)
+/** Initialize an RTCAVFoundationVideoSource with constraints. */
+- (RTCAVFoundationVideoSource *)avFoundationVideoSourceWithConstraints:
+ (nullable RTCMediaConstraints *)constraints;
+#endif
+
+/** Initialize an RTCAudioTrack with an id. */
+- (RTCAudioTrack *)audioTrackWithTrackId:(NSString *)trackId;
+
+/** Initialize an RTCVideoTrack with a source and an id. */
+- (RTCVideoTrack *)videoTrackWithSource:(RTCVideoSource *)source
+ trackId:(NSString *)trackId;
+
+/** Initialize an RTCMediaStream with an id. */
+- (RTCMediaStream *)mediaStreamWithStreamId:(NSString *)streamId;
+
+/** Initialize an RTCPeerConnection with a configuration, constraints, and
+ * delegate.
+ */
+- (RTCPeerConnection *)peerConnectionWithConfiguration:
+ (RTCConfiguration *)configuration
+ constraints:
+ (RTCMediaConstraints *)constraints
+ delegate:
+ (nullable id<RTCPeerConnectionDelegate>)delegate;
+
@end
NS_ASSUME_NONNULL_END
diff --git a/webrtc/api/objc/RTCPeerConnectionFactory.mm b/webrtc/api/objc/RTCPeerConnectionFactory.mm
index 31f3dda..a7f9c59 100644
--- a/webrtc/api/objc/RTCPeerConnectionFactory.mm
+++ b/webrtc/api/objc/RTCPeerConnectionFactory.mm
@@ -10,7 +10,16 @@
#import "RTCPeerConnectionFactory.h"
+#if defined(WEBRTC_IOS)
+#import "webrtc/api/objc/RTCAVFoundationVideoSource+Private.h"
+#endif
+#import "webrtc/api/objc/RTCAudioTrack+Private.h"
+#import "webrtc/api/objc/RTCMediaStream+Private.h"
+#import "webrtc/api/objc/RTCPeerConnection+Private.h"
#import "webrtc/api/objc/RTCPeerConnectionFactory+Private.h"
+#import "webrtc/api/objc/RTCVideoSource+Private.h"
+#import "webrtc/api/objc/RTCVideoTrack+Private.h"
+#import "webrtc/base/objc/NSString+StdString.h"
@implementation RTCPeerConnectionFactory {
rtc::scoped_ptr<rtc::Thread> _signalingThread;
@@ -35,4 +44,41 @@
return self;
}
+#if defined(WEBRTC_IOS)
+- (RTCAVFoundationVideoSource *)avFoundationVideoSourceWithConstraints:
+ (nullable RTCMediaConstraints *)constraints {
+ return [[RTCAVFoundationVideoSource alloc] initWithFactory:self
+ constraints:constraints];
+}
+#endif
+
+- (RTCAudioTrack *)audioTrackWithTrackId:(NSString *)trackId {
+ return [[RTCAudioTrack alloc] initWithFactory:self
+ trackId:trackId];
+}
+
+- (RTCVideoTrack *)videoTrackWithSource:(RTCVideoSource *)source
+ trackId:(NSString *)trackId {
+ return [[RTCVideoTrack alloc] initWithFactory:self
+ source:source
+ trackId:trackId];
+}
+
+- (RTCMediaStream *)mediaStreamWithStreamId:(NSString *)streamId {
+ return [[RTCMediaStream alloc] initWithFactory:self
+ streamId:streamId];
+}
+
+- (RTCPeerConnection *)peerConnectionWithConfiguration:
+ (RTCConfiguration *)configuration
+ constraints:
+ (RTCMediaConstraints *)constraints
+ delegate:
+ (nullable id<RTCPeerConnectionDelegate>)delegate {
+ return [[RTCPeerConnection alloc] initWithFactory:self
+ configuration:configuration
+ constraints:constraints
+ delegate:delegate];
+}
+
@end
diff --git a/webrtc/api/objc/RTCVideoTrack+Private.h b/webrtc/api/objc/RTCVideoTrack+Private.h
index cd7de48..be04124 100644
--- a/webrtc/api/objc/RTCVideoTrack+Private.h
+++ b/webrtc/api/objc/RTCVideoTrack+Private.h
@@ -20,6 +20,11 @@
@property(nonatomic, readonly)
rtc::scoped_refptr<webrtc::VideoTrackInterface> nativeVideoTrack;
+/** Initialize an RTCVideoTrack with its source and an id. */
+- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
+ source:(RTCVideoSource *)source
+ trackId:(NSString *)trackId;
+
@end
NS_ASSUME_NONNULL_END
diff --git a/webrtc/api/objc/RTCVideoTrack.h b/webrtc/api/objc/RTCVideoTrack.h
index e8dad3b..1d88376 100644
--- a/webrtc/api/objc/RTCVideoTrack.h
+++ b/webrtc/api/objc/RTCVideoTrack.h
@@ -23,11 +23,6 @@
- (instancetype)init NS_UNAVAILABLE;
-/** Initialize an RTCVideoTrack with its source and an id. */
-- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
- source:(RTCVideoSource *)source
- trackId:(NSString *)trackId;
-
/** Register a renderer that will render all frames received on this track. */
- (void)addRenderer:(id<RTCVideoRenderer>)renderer;