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}
This commit is contained in:
parent
09c3a1e291
commit
f3cb49f3ef
@ -18,6 +18,10 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@property(nonatomic, readonly) webrtc::AVFoundationVideoCapturer *capturer;
|
||||
|
||||
/** Initialize an RTCAVFoundationVideoSource with constraints. */
|
||||
- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
|
||||
constraints:(nullable RTCMediaConstraints *)constraints;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@ -25,8 +25,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
*/
|
||||
@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;
|
||||
|
||||
@ -20,6 +20,10 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@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
|
||||
|
||||
@ -18,10 +18,6 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
/** Initialize an RTCAudioTrack with an id. */
|
||||
- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
|
||||
trackId:(NSString *)trackId;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@ -23,6 +23,10 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@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;
|
||||
|
||||
@ -29,10 +29,6 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (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;
|
||||
|
||||
|
||||
@ -58,6 +58,19 @@ class PeerConnectionDelegateAdapter : public PeerConnectionObserver {
|
||||
@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;
|
||||
|
||||
|
||||
@ -117,19 +117,6 @@ typedef NS_ENUM(NSInteger, RTCStatsOutputLevel) {
|
||||
|
||||
- (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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -20,6 +20,11 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@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
|
||||
|
||||
@ -23,11 +23,6 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (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;
|
||||
|
||||
|
||||
@ -502,10 +502,9 @@ static BOOL const kARDAppClientEnableTracing = NO;
|
||||
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 @@ static BOOL const kARDAppClientEnableTracing = NO;
|
||||
}
|
||||
|
||||
- (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 @@ static BOOL const kARDAppClientEnableTracing = NO;
|
||||
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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user