Format /sdk/objc/api folder

There are a lot of changes in /sdk so I'm splitting it

Formatting done via:

git ls-files | grep -E '^sdk\/objc\/api\/.*\.(h|cc|mm)' | xargs clang-format -i

No-Iwyu: Includes didn't change and it isn't related to formatting
Bug: webrtc:42225392
Change-Id: Ieebcd026e77db31f94df2b5dd5cd18ccc4f06674
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/373883
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43682}
This commit is contained in:
Boris Tsirkin 2025-01-08 05:45:56 -08:00 committed by WebRTC LUCI CQ
parent 725f931f2f
commit 536c19a64d
121 changed files with 1762 additions and 1131 deletions

View File

@ -23,17 +23,20 @@ NS_ASSUME_NONNULL_BEGIN
* Calls made to the webrtc::VideoRenderInterface will be adapted and passed to * Calls made to the webrtc::VideoRenderInterface will be adapted and passed to
* this video renderer. * this video renderer.
*/ */
@property(nonatomic, readonly) id<RTC_OBJC_TYPE(RTCVideoRenderer)> videoRenderer; @property(nonatomic, readonly) id<RTC_OBJC_TYPE(RTCVideoRenderer)>
videoRenderer;
/** /**
* The native VideoSinkInterface surface exposed by this adapter. Calls made * The native VideoSinkInterface surface exposed by this adapter. Calls made
* to this interface will be adapted and passed to the RTCVideoRenderer supplied * to this interface will be adapted and passed to the RTCVideoRenderer supplied
* during construction. This pointer is unsafe and owned by this class. * during construction. This pointer is unsafe and owned by this class.
*/ */
@property(nonatomic, readonly) rtc::VideoSinkInterface<webrtc::VideoFrame> *nativeVideoRenderer; @property(nonatomic, readonly)
rtc::VideoSinkInterface<webrtc::VideoFrame> *nativeVideoRenderer;
/** Initialize an RTCVideoRendererAdapter with an RTCVideoRenderer. */ /** Initialize an RTCVideoRendererAdapter with an RTCVideoRenderer. */
- (instancetype)initWithNativeRenderer:(id<RTC_OBJC_TYPE(RTCVideoRenderer)>)videoRenderer - (instancetype)initWithNativeRenderer:
(id<RTC_OBJC_TYPE(RTCVideoRenderer)>)videoRenderer
NS_DESIGNATED_INITIALIZER; NS_DESIGNATED_INITIALIZER;
@end @end

View File

@ -26,11 +26,12 @@ class VideoRendererAdapter
} }
void OnFrame(const webrtc::VideoFrame& nativeVideoFrame) override { void OnFrame(const webrtc::VideoFrame& nativeVideoFrame) override {
RTC_OBJC_TYPE(RTCVideoFrame)* videoFrame = NativeToObjCVideoFrame(nativeVideoFrame); RTC_OBJC_TYPE(RTCVideoFrame)* videoFrame =
NativeToObjCVideoFrame(nativeVideoFrame);
CGSize current_size = (videoFrame.rotation % 180 == 0) CGSize current_size = (videoFrame.rotation % 180 == 0) ?
? CGSizeMake(videoFrame.width, videoFrame.height) CGSizeMake(videoFrame.width, videoFrame.height) :
: CGSizeMake(videoFrame.height, videoFrame.width); CGSizeMake(videoFrame.height, videoFrame.width);
if (!CGSizeEqualToSize(size_, current_size)) { if (!CGSizeEqualToSize(size_, current_size)) {
size_ = current_size; size_ = current_size;
@ -40,10 +41,10 @@ class VideoRendererAdapter
} }
private: private:
__weak RTCVideoRendererAdapter *adapter_; __weak RTCVideoRendererAdapter* adapter_;
CGSize size_; CGSize size_;
}; };
} } // namespace webrtc
@implementation RTCVideoRendererAdapter { @implementation RTCVideoRendererAdapter {
std::unique_ptr<webrtc::VideoRendererAdapter> _adapter; std::unique_ptr<webrtc::VideoRendererAdapter> _adapter;
@ -51,7 +52,8 @@ class VideoRendererAdapter
@synthesize videoRenderer = _videoRenderer; @synthesize videoRenderer = _videoRenderer;
- (instancetype)initWithNativeRenderer:(id<RTC_OBJC_TYPE(RTCVideoRenderer)>)videoRenderer { - (instancetype)initWithNativeRenderer:
(id<RTC_OBJC_TYPE(RTCVideoRenderer)>)videoRenderer {
NSParameterAssert(videoRenderer); NSParameterAssert(videoRenderer);
self = [super init]; self = [super init];
if (self) { if (self) {
@ -61,7 +63,7 @@ class VideoRendererAdapter
return self; return self;
} }
- (rtc::VideoSinkInterface<webrtc::VideoFrame> *)nativeVideoRenderer { - (rtc::VideoSinkInterface<webrtc::VideoFrame>*)nativeVideoRenderer {
return _adapter.get(); return _adapter.get();
} }

View File

@ -16,8 +16,8 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
typedef void (^RTCCallbackLoggerMessageHandler)(NSString *message); typedef void (^RTCCallbackLoggerMessageHandler)(NSString *message);
typedef void (^RTCCallbackLoggerMessageAndSeverityHandler)(NSString *message, typedef void (^RTCCallbackLoggerMessageAndSeverityHandler)(
RTCLoggingSeverity severity); NSString *message, RTCLoggingSeverity severity);
// This class intercepts WebRTC logs and forwards them to a registered block. // This class intercepts WebRTC logs and forwards them to a registered block.
// This class is not threadsafe. // This class is not threadsafe.

View File

@ -42,24 +42,32 @@ class CallbackLogSink final : public rtc::LogSink {
class CallbackWithSeverityLogSink final : public rtc::LogSink { class CallbackWithSeverityLogSink final : public rtc::LogSink {
public: public:
CallbackWithSeverityLogSink(RTCCallbackLoggerMessageAndSeverityHandler callbackHandler) CallbackWithSeverityLogSink(
RTCCallbackLoggerMessageAndSeverityHandler callbackHandler)
: callback_handler_(callbackHandler) {} : callback_handler_(callbackHandler) {}
void OnLogMessage(const std::string& message) override { RTC_DCHECK_NOTREACHED(); } void OnLogMessage(const std::string& message) override {
RTC_DCHECK_NOTREACHED();
}
void OnLogMessage(const std::string& message, rtc::LoggingSeverity severity) override { void OnLogMessage(const std::string& message,
rtc::LoggingSeverity severity) override {
OnLogMessage(absl::string_view(message), severity); OnLogMessage(absl::string_view(message), severity);
} }
void OnLogMessage(absl::string_view message, rtc::LoggingSeverity severity) override { void OnLogMessage(absl::string_view message,
rtc::LoggingSeverity severity) override {
if (callback_handler_) { if (callback_handler_) {
RTCLoggingSeverity loggingSeverity = NativeSeverityToObjcSeverity(severity); RTCLoggingSeverity loggingSeverity =
callback_handler_([NSString stringForAbslStringView:message], loggingSeverity); NativeSeverityToObjcSeverity(severity);
callback_handler_([NSString stringForAbslStringView:message],
loggingSeverity);
} }
} }
private: private:
static RTCLoggingSeverity NativeSeverityToObjcSeverity(rtc::LoggingSeverity severity) { static RTCLoggingSeverity NativeSeverityToObjcSeverity(
rtc::LoggingSeverity severity) {
switch (severity) { switch (severity) {
case rtc::LS_VERBOSE: case rtc::LS_VERBOSE:
return RTCLoggingSeverityVerbose; return RTCLoggingSeverityVerbose;
@ -77,7 +85,7 @@ class CallbackWithSeverityLogSink final : public rtc::LogSink {
RTCCallbackLoggerMessageAndSeverityHandler callback_handler_; RTCCallbackLoggerMessageAndSeverityHandler callback_handler_;
}; };
} } // namespace
@implementation RTC_OBJC_TYPE (RTCCallbackLogger) { @implementation RTC_OBJC_TYPE (RTCCallbackLogger) {
BOOL _hasStarted; BOOL _hasStarted;
@ -110,7 +118,7 @@ class CallbackWithSeverityLogSink final : public rtc::LogSink {
} }
- (void)startWithMessageAndSeverityHandler: - (void)startWithMessageAndSeverityHandler:
(nullable RTCCallbackLoggerMessageAndSeverityHandler)handler { (nullable RTCCallbackLoggerMessageAndSeverityHandler)handler {
if (_hasStarted) { if (_hasStarted) {
return; return;
} }

View File

@ -19,16 +19,20 @@
* The AudioSourceInterface object passed to this RTCAudioSource during * The AudioSourceInterface object passed to this RTCAudioSource during
* construction. * construction.
*/ */
@property(nonatomic, @property(nonatomic, readonly)
readonly) rtc::scoped_refptr<webrtc::AudioSourceInterface> nativeAudioSource; rtc::scoped_refptr<webrtc::AudioSourceInterface> nativeAudioSource;
/** Initialize an RTCAudioSource from a native AudioSourceInterface. */ /** Initialize an RTCAudioSource from a native AudioSourceInterface. */
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)
nativeAudioSource:(rtc::scoped_refptr<webrtc::AudioSourceInterface>)nativeAudioSource initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
nativeAudioSource:
(rtc::scoped_refptr<webrtc::AudioSourceInterface>)nativeAudioSource
NS_DESIGNATED_INITIALIZER; NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)
nativeMediaSource:(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
type:(RTCMediaSourceType)type NS_UNAVAILABLE; nativeMediaSource:
(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource
type:(RTCMediaSourceType)type NS_UNAVAILABLE;
@end @end

View File

@ -18,9 +18,10 @@
@synthesize volume = _volume; @synthesize volume = _volume;
@synthesize nativeAudioSource = _nativeAudioSource; @synthesize nativeAudioSource = _nativeAudioSource;
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)
nativeAudioSource: initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
(rtc::scoped_refptr<webrtc::AudioSourceInterface>)nativeAudioSource { nativeAudioSource:
(rtc::scoped_refptr<webrtc::AudioSourceInterface>)nativeAudioSource {
RTC_DCHECK(factory); RTC_DCHECK(factory);
RTC_DCHECK(nativeAudioSource); RTC_DCHECK(nativeAudioSource);
@ -33,16 +34,20 @@
return self; return self;
} }
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)
nativeMediaSource:(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
type:(RTCMediaSourceType)type { nativeMediaSource:
(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource
type:(RTCMediaSourceType)type {
RTC_DCHECK_NOTREACHED(); RTC_DCHECK_NOTREACHED();
return nil; return nil;
} }
- (NSString *)description { - (NSString *)description {
NSString *stateString = [[self class] stringForState:self.state]; NSString *stateString = [[self class] stringForState:self.state];
return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCAudioSource)( %p ): %@", self, stateString]; return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCAudioSource)( %p ): %@",
self,
stateString];
} }
- (void)setVolume:(double)volume { - (void)setVolume:(double)volume {

View File

@ -19,10 +19,12 @@ NS_ASSUME_NONNULL_BEGIN
() ()
/** AudioTrackInterface created or passed in at construction. */ /** AudioTrackInterface created or passed in at construction. */
@property(nonatomic, readonly) rtc::scoped_refptr<webrtc::AudioTrackInterface> nativeAudioTrack; @property(nonatomic, readonly)
rtc::scoped_refptr<webrtc::AudioTrackInterface> nativeAudioTrack;
/** Initialize an RTCAudioTrack with an id. */ /** Initialize an RTCAudioTrack with an id. */
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)initWithFactory:
(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
source:(RTC_OBJC_TYPE(RTCAudioSource) *)source source:(RTC_OBJC_TYPE(RTCAudioSource) *)source
trackId:(NSString *)trackId; trackId:(NSString *)trackId;

View File

@ -21,7 +21,8 @@
@synthesize source = _source; @synthesize source = _source;
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)initWithFactory:
(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
source:(RTC_OBJC_TYPE(RTCAudioSource) *)source source:(RTC_OBJC_TYPE(RTCAudioSource) *)source
trackId:(NSString *)trackId { trackId:(NSString *)trackId {
RTC_DCHECK(factory); RTC_DCHECK(factory);
@ -30,17 +31,22 @@
std::string nativeId = [NSString stdStringForString:trackId]; std::string nativeId = [NSString stdStringForString:trackId];
rtc::scoped_refptr<webrtc::AudioTrackInterface> track = rtc::scoped_refptr<webrtc::AudioTrackInterface> track =
factory.nativeFactory->CreateAudioTrack(nativeId, source.nativeAudioSource.get()); factory.nativeFactory->CreateAudioTrack(nativeId,
self = [self initWithFactory:factory nativeTrack:track type:RTCMediaStreamTrackTypeAudio]; source.nativeAudioSource.get());
self = [self initWithFactory:factory
nativeTrack:track
type:RTCMediaStreamTrackTypeAudio];
if (self) { if (self) {
_source = source; _source = source;
} }
return self; return self;
} }
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)
nativeTrack:(rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
type:(RTCMediaStreamTrackType)type { nativeTrack:
(rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack
type:(RTCMediaStreamTrackType)type {
NSParameterAssert(factory); NSParameterAssert(factory);
NSParameterAssert(nativeTrack); NSParameterAssert(nativeTrack);
NSParameterAssert(type == RTCMediaStreamTrackTypeAudio); NSParameterAssert(type == RTCMediaStreamTrackTypeAudio);
@ -49,10 +55,12 @@
- (RTC_OBJC_TYPE(RTCAudioSource) *)source { - (RTC_OBJC_TYPE(RTCAudioSource) *)source {
if (!_source) { if (!_source) {
rtc::scoped_refptr<webrtc::AudioSourceInterface> source(self.nativeAudioTrack->GetSource()); rtc::scoped_refptr<webrtc::AudioSourceInterface> source(
self.nativeAudioTrack->GetSource());
if (source) { if (source) {
_source = [[RTC_OBJC_TYPE(RTCAudioSource) alloc] initWithFactory:self.factory _source =
nativeAudioSource:source]; [[RTC_OBJC_TYPE(RTCAudioSource) alloc] initWithFactory:self.factory
nativeAudioSource:source];
} }
} }
return _source; return _source;

View File

@ -24,10 +24,12 @@ RTC_OBJC_EXPORT
@property(nonatomic, readonly, copy) NSString *certificate; @property(nonatomic, readonly, copy) NSString *certificate;
/** /**
* Initialize an RTCCertificate with PEM strings for private_key and certificate. * Initialize an RTCCertificate with PEM strings for private_key and
* certificate.
*/ */
- (instancetype)initWithPrivateKey:(NSString *)private_key - (instancetype)initWithPrivateKey:(NSString *)private_key
certificate:(NSString *)certificate NS_DESIGNATED_INITIALIZER; certificate:(NSString *)certificate
NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
@ -37,7 +39,8 @@ RTC_OBJC_EXPORT
* provided. * provided.
* - name: "ECDSA" or "RSASSA-PKCS1-v1_5" * - name: "ECDSA" or "RSASSA-PKCS1-v1_5"
*/ */
+ (nullable RTC_OBJC_TYPE(RTCCertificate) *)generateCertificateWithParams:(NSDictionary *)params; + (nullable RTC_OBJC_TYPE(RTCCertificate) *)generateCertificateWithParams:
(NSDictionary *)params;
@end @end

View File

@ -22,12 +22,14 @@
@synthesize certificate = _certificate; @synthesize certificate = _certificate;
- (id)copyWithZone:(NSZone *)zone { - (id)copyWithZone:(NSZone *)zone {
id copy = [[[self class] alloc] initWithPrivateKey:[self.private_key copyWithZone:zone] id copy = [[[self class] alloc]
certificate:[self.certificate copyWithZone:zone]]; initWithPrivateKey:[self.private_key copyWithZone:zone]
certificate:[self.certificate copyWithZone:zone]];
return copy; return copy;
} }
- (instancetype)initWithPrivateKey:(NSString *)private_key certificate:(NSString *)certificate { - (instancetype)initWithPrivateKey:(NSString *)private_key
certificate:(NSString *)certificate {
self = [super init]; self = [super init];
if (self) { if (self) {
_private_key = [private_key copy]; _private_key = [private_key copy];
@ -36,7 +38,8 @@
return self; return self;
} }
+ (nullable RTC_OBJC_TYPE(RTCCertificate) *)generateCertificateWithParams:(NSDictionary *)params { + (nullable RTC_OBJC_TYPE(RTCCertificate) *)generateCertificateWithParams:
(NSDictionary *)params {
rtc::KeyType keyType = rtc::KT_ECDSA; rtc::KeyType keyType = rtc::KT_ECDSA;
NSString *keyTypeString = [params valueForKey:@"name"]; NSString *keyTypeString = [params valueForKey:@"name"];
if (keyTypeString && [keyTypeString isEqualToString:@"RSASSA-PKCS1-v1_5"]) { if (keyTypeString && [keyTypeString isEqualToString:@"RSASSA-PKCS1-v1_5"]) {
@ -47,11 +50,11 @@
rtc::scoped_refptr<rtc::RTCCertificate> cc_certificate = nullptr; rtc::scoped_refptr<rtc::RTCCertificate> cc_certificate = nullptr;
if (expires != nil) { if (expires != nil) {
uint64_t expirationTimestamp = [expires unsignedLongLongValue]; uint64_t expirationTimestamp = [expires unsignedLongLongValue];
cc_certificate = rtc::RTCCertificateGenerator::GenerateCertificate(rtc::KeyParams(keyType), cc_certificate = rtc::RTCCertificateGenerator::GenerateCertificate(
expirationTimestamp); rtc::KeyParams(keyType), expirationTimestamp);
} else { } else {
cc_certificate = cc_certificate = rtc::RTCCertificateGenerator::GenerateCertificate(
rtc::RTCCertificateGenerator::GenerateCertificate(rtc::KeyParams(keyType), std::nullopt); rtc::KeyParams(keyType), std::nullopt);
} }
if (!cc_certificate) { if (!cc_certificate) {
RTCLogError(@"Failed to generate certificate."); RTCLogError(@"Failed to generate certificate.");
@ -64,9 +67,9 @@
RTC_LOG(LS_INFO) << "CERT PEM "; RTC_LOG(LS_INFO) << "CERT PEM ";
RTC_LOG(LS_INFO) << pem_certificate; RTC_LOG(LS_INFO) << pem_certificate;
RTC_OBJC_TYPE(RTCCertificate) *cert = RTC_OBJC_TYPE(RTCCertificate) *cert = [[RTC_OBJC_TYPE(RTCCertificate) alloc]
[[RTC_OBJC_TYPE(RTCCertificate) alloc] initWithPrivateKey:@(pem_private_key.c_str()) initWithPrivateKey:@(pem_private_key.c_str())
certificate:@(pem_certificate.c_str())]; certificate:@(pem_certificate.c_str())];
return cert; return cert;
} }

View File

@ -17,7 +17,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface RTC_OBJC_TYPE (RTCConfiguration) @interface RTC_OBJC_TYPE (RTCConfiguration)
() ()
+ (webrtc::PeerConnectionInterface::IceTransportsType)nativeTransportsTypeForTransportPolicy + (webrtc::PeerConnectionInterface::IceTransportsType)
nativeTransportsTypeForTransportPolicy
: (RTCIceTransportPolicy)policy; : (RTCIceTransportPolicy)policy;
+ (RTCIceTransportPolicy)transportPolicyForTransportsType: + (RTCIceTransportPolicy)transportPolicyForTransportsType:
@ -41,16 +42,16 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy; + (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy;
+ (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativeTcpCandidatePolicyForPolicy: + (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
(RTCTcpCandidatePolicy)policy; nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy;
+ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy: + (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
(webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy; (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy;
+ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy; + (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy;
+ (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)nativeCandidateNetworkPolicyForPolicy: + (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)
(RTCCandidateNetworkPolicy)policy; nativeCandidateNetworkPolicyForPolicy:(RTCCandidateNetworkPolicy)policy;
+ (RTCCandidateNetworkPolicy)candidateNetworkPolicyForNativePolicy: + (RTCCandidateNetworkPolicy)candidateNetworkPolicyForNativePolicy:
(webrtc::PeerConnectionInterface::CandidateNetworkPolicy)nativePolicy; (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)nativePolicy;
@ -59,9 +60,11 @@ NS_ASSUME_NONNULL_BEGIN
+ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:(RTCEncryptionKeyType)keyType; + (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:(RTCEncryptionKeyType)keyType;
+ (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:(RTCSdpSemantics)sdpSemantics; + (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:
(RTCSdpSemantics)sdpSemantics;
+ (RTCSdpSemantics)sdpSemanticsForNativeSdpSemantics:(webrtc::SdpSemantics)sdpSemantics; + (RTCSdpSemantics)sdpSemanticsForNativeSdpSemantics:
(webrtc::SdpSemantics)sdpSemantics;
+ (NSString *)stringForSdpSemantics:(RTCSdpSemantics)sdpSemantics; + (NSString *)stringForSdpSemantics:(RTCSdpSemantics)sdpSemantics;
@ -69,10 +72,12 @@ NS_ASSUME_NONNULL_BEGIN
* RTCConfiguration struct representation of this RTCConfiguration. * RTCConfiguration struct representation of this RTCConfiguration.
* This is needed to pass to the underlying C++ APIs. * This is needed to pass to the underlying C++ APIs.
*/ */
- (nullable webrtc::PeerConnectionInterface::RTCConfiguration *)createNativeConfiguration; - (nullable webrtc::PeerConnectionInterface::RTCConfiguration *)
createNativeConfiguration;
- (instancetype)initWithNativeConfiguration: - (instancetype)initWithNativeConfiguration:
(const webrtc::PeerConnectionInterface::RTCConfiguration &)config NS_DESIGNATED_INITIALIZER; (const webrtc::PeerConnectionInterface::RTCConfiguration &)config
NS_DESIGNATED_INITIALIZER;
@end @end

View File

@ -35,7 +35,10 @@ typedef NS_ENUM(NSInteger, RTCBundlePolicy) {
}; };
/** Represents the rtcp mux policy. */ /** Represents the rtcp mux policy. */
typedef NS_ENUM(NSInteger, RTCRtcpMuxPolicy) { RTCRtcpMuxPolicyNegotiate, RTCRtcpMuxPolicyRequire }; typedef NS_ENUM(NSInteger, RTCRtcpMuxPolicy) {
RTCRtcpMuxPolicyNegotiate,
RTCRtcpMuxPolicyRequire
};
/** Represents the tcp candidate policy. */ /** Represents the tcp candidate policy. */
typedef NS_ENUM(NSInteger, RTCTcpCandidatePolicy) { typedef NS_ENUM(NSInteger, RTCTcpCandidatePolicy) {
@ -95,7 +98,8 @@ RTC_OBJC_EXPORT
@property(nonatomic, assign) RTCRtcpMuxPolicy rtcpMuxPolicy; @property(nonatomic, assign) RTCRtcpMuxPolicy rtcpMuxPolicy;
@property(nonatomic, assign) RTCTcpCandidatePolicy tcpCandidatePolicy; @property(nonatomic, assign) RTCTcpCandidatePolicy tcpCandidatePolicy;
@property(nonatomic, assign) RTCCandidateNetworkPolicy candidateNetworkPolicy; @property(nonatomic, assign) RTCCandidateNetworkPolicy candidateNetworkPolicy;
@property(nonatomic, assign) RTCContinualGatheringPolicy continualGatheringPolicy; @property(nonatomic, assign)
RTCContinualGatheringPolicy continualGatheringPolicy;
/** If set to YES, don't gather IPv6 ICE candidates on Wi-Fi. /** If set to YES, don't gather IPv6 ICE candidates on Wi-Fi.
* Only intended to be used on specific devices. Certain phones disable IPv6 * Only intended to be used on specific devices. Certain phones disable IPv6
@ -150,7 +154,8 @@ RTC_OBJC_EXPORT
* transport type and as a result not observed by PeerConnectionDelegateAdapter, * transport type and as a result not observed by PeerConnectionDelegateAdapter,
* will be surfaced to the delegate. * will be surfaced to the delegate.
*/ */
@property(nonatomic, assign) BOOL shouldSurfaceIceCandidatesOnIceTransportTypeChanged; @property(nonatomic, assign)
BOOL shouldSurfaceIceCandidatesOnIceTransportTypeChanged;
/** If set to non-nil, controls the minimal interval between consecutive ICE /** If set to non-nil, controls the minimal interval between consecutive ICE
* check packets. * check packets.
@ -225,7 +230,8 @@ RTC_OBJC_EXPORT
* when ICE is strongly connected, and it overrides the * when ICE is strongly connected, and it overrides the
* default value of this interval in the ICE implementation; * default value of this interval in the ICE implementation;
*/ */
@property(nonatomic, copy, nullable) NSNumber *iceCheckIntervalStrongConnectivity; @property(nonatomic, copy, nullable)
NSNumber *iceCheckIntervalStrongConnectivity;
/** /**
* Defines the counterpart for ALL pairs when ICE is * Defines the counterpart for ALL pairs when ICE is

View File

@ -57,8 +57,10 @@
@synthesize rtcpVideoReportIntervalMs = _rtcpVideoReportIntervalMs; @synthesize rtcpVideoReportIntervalMs = _rtcpVideoReportIntervalMs;
@synthesize enableImplicitRollback = _enableImplicitRollback; @synthesize enableImplicitRollback = _enableImplicitRollback;
@synthesize offerExtmapAllowMixed = _offerExtmapAllowMixed; @synthesize offerExtmapAllowMixed = _offerExtmapAllowMixed;
@synthesize iceCheckIntervalStrongConnectivity = _iceCheckIntervalStrongConnectivity; @synthesize iceCheckIntervalStrongConnectivity =
@synthesize iceCheckIntervalWeakConnectivity = _iceCheckIntervalWeakConnectivity; _iceCheckIntervalStrongConnectivity;
@synthesize iceCheckIntervalWeakConnectivity =
_iceCheckIntervalWeakConnectivity;
@synthesize iceUnwritableTimeout = _iceUnwritableTimeout; @synthesize iceUnwritableTimeout = _iceUnwritableTimeout;
@synthesize iceUnwritableMinChecks = _iceUnwritableMinChecks; @synthesize iceUnwritableMinChecks = _iceUnwritableMinChecks;
@synthesize iceInactiveTimeout = _iceInactiveTimeout; @synthesize iceInactiveTimeout = _iceInactiveTimeout;
@ -76,7 +78,8 @@
if (self) { if (self) {
_enableDscp = config.dscp(); _enableDscp = config.dscp();
NSMutableArray *iceServers = [NSMutableArray array]; NSMutableArray *iceServers = [NSMutableArray array];
for (const webrtc::PeerConnectionInterface::IceServer& server : config.servers) { for (const webrtc::PeerConnectionInterface::IceServer &server :
config.servers) {
RTC_OBJC_TYPE(RTCIceServer) *iceServer = RTC_OBJC_TYPE(RTCIceServer) *iceServer =
[[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithNativeServer:server]; [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithNativeServer:server];
[iceServers addObject:iceServer]; [iceServers addObject:iceServer];
@ -96,18 +99,20 @@
[[self class] bundlePolicyForNativePolicy:config.bundle_policy]; [[self class] bundlePolicyForNativePolicy:config.bundle_policy];
_rtcpMuxPolicy = _rtcpMuxPolicy =
[[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy]; [[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy];
_tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy: _tcpCandidatePolicy = [[self class]
config.tcp_candidate_policy]; tcpCandidatePolicyForNativePolicy:config.tcp_candidate_policy];
_candidateNetworkPolicy = [[self class] _candidateNetworkPolicy = [[self class]
candidateNetworkPolicyForNativePolicy:config.candidate_network_policy]; candidateNetworkPolicyForNativePolicy:config.candidate_network_policy];
webrtc::PeerConnectionInterface::ContinualGatheringPolicy nativePolicy = webrtc::PeerConnectionInterface::ContinualGatheringPolicy nativePolicy =
config.continual_gathering_policy; config.continual_gathering_policy;
_continualGatheringPolicy = [[self class] continualGatheringPolicyForNativePolicy:nativePolicy]; _continualGatheringPolicy =
[[self class] continualGatheringPolicyForNativePolicy:nativePolicy];
_disableIPV6OnWiFi = config.disable_ipv6_on_wifi; _disableIPV6OnWiFi = config.disable_ipv6_on_wifi;
_maxIPv6Networks = config.max_ipv6_networks; _maxIPv6Networks = config.max_ipv6_networks;
_disableLinkLocalNetworks = config.disable_link_local_networks; _disableLinkLocalNetworks = config.disable_link_local_networks;
_audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets; _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets;
_audioJitterBufferFastAccelerate = config.audio_jitter_buffer_fast_accelerate; _audioJitterBufferFastAccelerate =
config.audio_jitter_buffer_fast_accelerate;
_iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout; _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout;
_iceBackupCandidatePairPingInterval = _iceBackupCandidatePairPingInterval =
config.ice_backup_candidate_pair_ping_interval; config.ice_backup_candidate_pair_ping_interval;
@ -122,30 +127,34 @@
_iceCheckMinInterval = _iceCheckMinInterval =
[NSNumber numberWithInt:*config.ice_check_min_interval]; [NSNumber numberWithInt:*config.ice_check_min_interval];
} }
_sdpSemantics = [[self class] sdpSemanticsForNativeSdpSemantics:config.sdp_semantics]; _sdpSemantics =
[[self class] sdpSemanticsForNativeSdpSemantics:config.sdp_semantics];
_turnCustomizer = config.turn_customizer; _turnCustomizer = config.turn_customizer;
_activeResetSrtpParams = config.active_reset_srtp_params; _activeResetSrtpParams = config.active_reset_srtp_params;
if (config.crypto_options) { if (config.crypto_options) {
_cryptoOptions = [[RTC_OBJC_TYPE(RTCCryptoOptions) alloc] _cryptoOptions = [[RTC_OBJC_TYPE(RTCCryptoOptions) alloc]
initWithSrtpEnableGcmCryptoSuites:config.crypto_options->srtp initWithSrtpEnableGcmCryptoSuites:config.crypto_options->srtp
.enable_gcm_crypto_suites .enable_gcm_crypto_suites
srtpEnableAes128Sha1_32CryptoCipher:config.crypto_options->srtp srtpEnableAes128Sha1_32CryptoCipher:
.enable_aes128_sha1_32_crypto_cipher config.crypto_options->srtp.enable_aes128_sha1_32_crypto_cipher
srtpEnableEncryptedRtpHeaderExtensions:config.crypto_options->srtp srtpEnableEncryptedRtpHeaderExtensions:
.enable_encrypted_rtp_header_extensions config.crypto_options->srtp.enable_encrypted_rtp_header_extensions
sframeRequireFrameEncryption:config.crypto_options->sframe sframeRequireFrameEncryption:config.crypto_options->sframe
.require_frame_encryption]; .require_frame_encryption];
} }
_turnLoggingId = [NSString stringWithUTF8String:config.turn_logging_id.c_str()]; _turnLoggingId =
[NSString stringWithUTF8String:config.turn_logging_id.c_str()];
_rtcpAudioReportIntervalMs = config.audio_rtcp_report_interval_ms(); _rtcpAudioReportIntervalMs = config.audio_rtcp_report_interval_ms();
_rtcpVideoReportIntervalMs = config.video_rtcp_report_interval_ms(); _rtcpVideoReportIntervalMs = config.video_rtcp_report_interval_ms();
_enableImplicitRollback = config.enable_implicit_rollback; _enableImplicitRollback = config.enable_implicit_rollback;
_offerExtmapAllowMixed = config.offer_extmap_allow_mixed; _offerExtmapAllowMixed = config.offer_extmap_allow_mixed;
_iceCheckIntervalStrongConnectivity = _iceCheckIntervalStrongConnectivity =
config.ice_check_interval_strong_connectivity.has_value() ? config.ice_check_interval_strong_connectivity.has_value() ?
[NSNumber numberWithInt:*config.ice_check_interval_strong_connectivity] : [NSNumber
numberWithInt:*config.ice_check_interval_strong_connectivity] :
nil; nil;
_iceCheckIntervalWeakConnectivity = config.ice_check_interval_weak_connectivity.has_value() ? _iceCheckIntervalWeakConnectivity =
config.ice_check_interval_weak_connectivity.has_value() ?
[NSNumber numberWithInt:*config.ice_check_interval_weak_connectivity] : [NSNumber numberWithInt:*config.ice_check_interval_weak_connectivity] :
nil; nil;
_iceUnwritableTimeout = config.ice_unwritable_timeout.has_value() ? _iceUnwritableTimeout = config.ice_unwritable_timeout.has_value() ?
@ -162,35 +171,39 @@
} }
- (NSString *)description { - (NSString *)description {
static NSString *formatString = @"RTC_OBJC_TYPE(RTCConfiguration): " static NSString *formatString =
@"{\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%d\n%d\n%d\n%d\n%d\n%d\n" @"RTC_OBJC_TYPE(RTCConfiguration): "
@"%d\n%@\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n}\n"; @"{\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%d\n%d\n%d\n%d\n%d\n%d\n"
@"%d\n%@\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n}\n";
return [NSString return [NSString
stringWithFormat:formatString, stringWithFormat:
_iceServers, formatString,
[[self class] stringForTransportPolicy:_iceTransportPolicy], _iceServers,
[[self class] stringForBundlePolicy:_bundlePolicy], [[self class] stringForTransportPolicy:_iceTransportPolicy],
[[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy], [[self class] stringForBundlePolicy:_bundlePolicy],
[[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy], [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy],
[[self class] stringForCandidateNetworkPolicy:_candidateNetworkPolicy], [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy],
[[self class] stringForContinualGatheringPolicy:_continualGatheringPolicy], [[self class]
[[self class] stringForSdpSemantics:_sdpSemantics], stringForCandidateNetworkPolicy:_candidateNetworkPolicy],
_audioJitterBufferMaxPackets, [[self class]
_audioJitterBufferFastAccelerate, stringForContinualGatheringPolicy:_continualGatheringPolicy],
_iceConnectionReceivingTimeout, [[self class] stringForSdpSemantics:_sdpSemantics],
_iceBackupCandidatePairPingInterval, _audioJitterBufferMaxPackets,
_iceCandidatePoolSize, _audioJitterBufferFastAccelerate,
_shouldPruneTurnPorts, _iceConnectionReceivingTimeout,
_shouldPresumeWritableWhenFullyRelayed, _iceBackupCandidatePairPingInterval,
_shouldSurfaceIceCandidatesOnIceTransportTypeChanged, _iceCandidatePoolSize,
_iceCheckMinInterval, _shouldPruneTurnPorts,
_disableLinkLocalNetworks, _shouldPresumeWritableWhenFullyRelayed,
_disableIPV6OnWiFi, _shouldSurfaceIceCandidatesOnIceTransportTypeChanged,
_maxIPv6Networks, _iceCheckMinInterval,
_activeResetSrtpParams, _disableLinkLocalNetworks,
_enableDscp, _disableIPV6OnWiFi,
_enableImplicitRollback]; _maxIPv6Networks,
_activeResetSrtpParams,
_enableDscp,
_enableImplicitRollback];
} }
#pragma mark - Private #pragma mark - Private
@ -215,14 +228,14 @@
[[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy]; [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy];
nativeConfig->candidate_network_policy = [[self class] nativeConfig->candidate_network_policy = [[self class]
nativeCandidateNetworkPolicyForPolicy:_candidateNetworkPolicy]; nativeCandidateNetworkPolicyForPolicy:_candidateNetworkPolicy];
nativeConfig->continual_gathering_policy = nativeConfig->continual_gathering_policy = [[self class]
[[self class] nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy]; nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy];
nativeConfig->disable_ipv6_on_wifi = _disableIPV6OnWiFi; nativeConfig->disable_ipv6_on_wifi = _disableIPV6OnWiFi;
nativeConfig->max_ipv6_networks = _maxIPv6Networks; nativeConfig->max_ipv6_networks = _maxIPv6Networks;
nativeConfig->disable_link_local_networks = _disableLinkLocalNetworks; nativeConfig->disable_link_local_networks = _disableLinkLocalNetworks;
nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets; nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
nativeConfig->audio_jitter_buffer_fast_accelerate = nativeConfig->audio_jitter_buffer_fast_accelerate =
_audioJitterBufferFastAccelerate ? true : false; _audioJitterBufferFastAccelerate ? true : false;
nativeConfig->ice_connection_receiving_timeout = nativeConfig->ice_connection_receiving_timeout =
_iceConnectionReceivingTimeout; _iceConnectionReceivingTimeout;
nativeConfig->ice_backup_candidate_pair_ping_interval = nativeConfig->ice_backup_candidate_pair_ping_interval =
@ -234,8 +247,10 @@
RTC_LOG(LS_INFO) << "Have configured cert - using it."; RTC_LOG(LS_INFO) << "Have configured cert - using it.";
std::string pem_private_key = [[_certificate private_key] UTF8String]; std::string pem_private_key = [[_certificate private_key] UTF8String];
std::string pem_certificate = [[_certificate certificate] UTF8String]; std::string pem_certificate = [[_certificate certificate] UTF8String];
rtc::RTCCertificatePEM pem = rtc::RTCCertificatePEM(pem_private_key, pem_certificate); rtc::RTCCertificatePEM pem =
rtc::scoped_refptr<rtc::RTCCertificate> certificate = rtc::RTCCertificate::FromPEM(pem); rtc::RTCCertificatePEM(pem_private_key, pem_certificate);
rtc::scoped_refptr<rtc::RTCCertificate> certificate =
rtc::RTCCertificate::FromPEM(pem);
RTC_LOG(LS_INFO) << "Created cert from PEM strings."; RTC_LOG(LS_INFO) << "Created cert from PEM strings.";
if (!certificate) { if (!certificate) {
RTC_LOG(LS_ERROR) << "Failed to generate certificate from PEM."; RTC_LOG(LS_ERROR) << "Failed to generate certificate from PEM.";
@ -247,8 +262,8 @@
// Generate non-default certificate. // Generate non-default certificate.
if (keyType != rtc::KT_DEFAULT) { if (keyType != rtc::KT_DEFAULT) {
rtc::scoped_refptr<rtc::RTCCertificate> certificate = rtc::scoped_refptr<rtc::RTCCertificate> certificate =
rtc::RTCCertificateGenerator::GenerateCertificate(rtc::KeyParams(keyType), rtc::RTCCertificateGenerator::GenerateCertificate(
std::optional<uint64_t>()); rtc::KeyParams(keyType), std::optional<uint64_t>());
if (!certificate) { if (!certificate) {
RTCLogError(@"Failed to generate certificate."); RTCLogError(@"Failed to generate certificate.");
return nullptr; return nullptr;
@ -263,13 +278,16 @@
nativeConfig->surface_ice_candidates_on_ice_transport_type_changed = nativeConfig->surface_ice_candidates_on_ice_transport_type_changed =
_shouldSurfaceIceCandidatesOnIceTransportTypeChanged ? true : false; _shouldSurfaceIceCandidatesOnIceTransportTypeChanged ? true : false;
if (_iceCheckMinInterval != nil) { if (_iceCheckMinInterval != nil) {
nativeConfig->ice_check_min_interval = std::optional<int>(_iceCheckMinInterval.intValue); nativeConfig->ice_check_min_interval =
std::optional<int>(_iceCheckMinInterval.intValue);
} }
nativeConfig->sdp_semantics = [[self class] nativeSdpSemanticsForSdpSemantics:_sdpSemantics]; nativeConfig->sdp_semantics =
[[self class] nativeSdpSemanticsForSdpSemantics:_sdpSemantics];
if (_turnCustomizer) { if (_turnCustomizer) {
nativeConfig->turn_customizer = _turnCustomizer; nativeConfig->turn_customizer = _turnCustomizer;
} }
nativeConfig->active_reset_srtp_params = _activeResetSrtpParams ? true : false; nativeConfig->active_reset_srtp_params =
_activeResetSrtpParams ? true : false;
if (_cryptoOptions) { if (_cryptoOptions) {
webrtc::CryptoOptions nativeCryptoOptions; webrtc::CryptoOptions nativeCryptoOptions;
nativeCryptoOptions.srtp.enable_gcm_crypto_suites = nativeCryptoOptions.srtp.enable_gcm_crypto_suites =
@ -280,7 +298,8 @@
_cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions ? true : false; _cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions ? true : false;
nativeCryptoOptions.sframe.require_frame_encryption = nativeCryptoOptions.sframe.require_frame_encryption =
_cryptoOptions.sframeRequireFrameEncryption ? true : false; _cryptoOptions.sframeRequireFrameEncryption ? true : false;
nativeConfig->crypto_options = std::optional<webrtc::CryptoOptions>(nativeCryptoOptions); nativeConfig->crypto_options =
std::optional<webrtc::CryptoOptions>(nativeCryptoOptions);
} }
nativeConfig->turn_logging_id = [_turnLoggingId UTF8String]; nativeConfig->turn_logging_id = [_turnLoggingId UTF8String];
nativeConfig->set_audio_rtcp_report_interval_ms(_rtcpAudioReportIntervalMs); nativeConfig->set_audio_rtcp_report_interval_ms(_rtcpAudioReportIntervalMs);
@ -296,13 +315,16 @@
std::optional<int>(_iceCheckIntervalWeakConnectivity.intValue); std::optional<int>(_iceCheckIntervalWeakConnectivity.intValue);
} }
if (_iceUnwritableTimeout != nil) { if (_iceUnwritableTimeout != nil) {
nativeConfig->ice_unwritable_timeout = std::optional<int>(_iceUnwritableTimeout.intValue); nativeConfig->ice_unwritable_timeout =
std::optional<int>(_iceUnwritableTimeout.intValue);
} }
if (_iceUnwritableMinChecks != nil) { if (_iceUnwritableMinChecks != nil) {
nativeConfig->ice_unwritable_min_checks = std::optional<int>(_iceUnwritableMinChecks.intValue); nativeConfig->ice_unwritable_min_checks =
std::optional<int>(_iceUnwritableMinChecks.intValue);
} }
if (_iceInactiveTimeout != nil) { if (_iceInactiveTimeout != nil) {
nativeConfig->ice_inactive_timeout = std::optional<int>(_iceInactiveTimeout.intValue); nativeConfig->ice_inactive_timeout =
std::optional<int>(_iceInactiveTimeout.intValue);
} }
return nativeConfig.release(); return nativeConfig.release();
} }
@ -512,7 +534,8 @@
} }
} }
+ (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:(RTCSdpSemantics)sdpSemantics { + (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:
(RTCSdpSemantics)sdpSemantics {
switch (sdpSemantics) { switch (sdpSemantics) {
case RTCSdpSemanticsPlanB: case RTCSdpSemanticsPlanB:
return webrtc::SdpSemantics::kPlanB_DEPRECATED; return webrtc::SdpSemantics::kPlanB_DEPRECATED;
@ -521,7 +544,8 @@
} }
} }
+ (RTCSdpSemantics)sdpSemanticsForNativeSdpSemantics:(webrtc::SdpSemantics)sdpSemantics { + (RTCSdpSemantics)sdpSemanticsForNativeSdpSemantics:
(webrtc::SdpSemantics)sdpSemantics {
switch (sdpSemantics) { switch (sdpSemantics) {
case webrtc::SdpSemantics::kPlanB_DEPRECATED: case webrtc::SdpSemantics::kPlanB_DEPRECATED:
return RTCSdpSemanticsPlanB; return RTCSdpSemanticsPlanB;

View File

@ -50,10 +50,13 @@ RTC_OBJC_EXPORT
* Initializes CryptoOptions with all possible options set explicitly. This * Initializes CryptoOptions with all possible options set explicitly. This
* is done when converting from a native RTCConfiguration.crypto_options. * is done when converting from a native RTCConfiguration.crypto_options.
*/ */
- (instancetype)initWithSrtpEnableGcmCryptoSuites:(BOOL)srtpEnableGcmCryptoSuites - (instancetype)
srtpEnableAes128Sha1_32CryptoCipher:(BOOL)srtpEnableAes128Sha1_32CryptoCipher initWithSrtpEnableGcmCryptoSuites:(BOOL)srtpEnableGcmCryptoSuites
srtpEnableEncryptedRtpHeaderExtensions:(BOOL)srtpEnableEncryptedRtpHeaderExtensions srtpEnableAes128Sha1_32CryptoCipher:
sframeRequireFrameEncryption:(BOOL)sframeRequireFrameEncryption (BOOL)srtpEnableAes128Sha1_32CryptoCipher
srtpEnableEncryptedRtpHeaderExtensions:
(BOOL)srtpEnableEncryptedRtpHeaderExtensions
sframeRequireFrameEncryption:(BOOL)sframeRequireFrameEncryption
NS_DESIGNATED_INITIALIZER; NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;

View File

@ -13,19 +13,25 @@
@implementation RTC_OBJC_TYPE (RTCCryptoOptions) @implementation RTC_OBJC_TYPE (RTCCryptoOptions)
@synthesize srtpEnableGcmCryptoSuites = _srtpEnableGcmCryptoSuites; @synthesize srtpEnableGcmCryptoSuites = _srtpEnableGcmCryptoSuites;
@synthesize srtpEnableAes128Sha1_32CryptoCipher = _srtpEnableAes128Sha1_32CryptoCipher; @synthesize srtpEnableAes128Sha1_32CryptoCipher =
@synthesize srtpEnableEncryptedRtpHeaderExtensions = _srtpEnableEncryptedRtpHeaderExtensions; _srtpEnableAes128Sha1_32CryptoCipher;
@synthesize srtpEnableEncryptedRtpHeaderExtensions =
_srtpEnableEncryptedRtpHeaderExtensions;
@synthesize sframeRequireFrameEncryption = _sframeRequireFrameEncryption; @synthesize sframeRequireFrameEncryption = _sframeRequireFrameEncryption;
- (instancetype)initWithSrtpEnableGcmCryptoSuites:(BOOL)srtpEnableGcmCryptoSuites - (instancetype)
srtpEnableAes128Sha1_32CryptoCipher:(BOOL)srtpEnableAes128Sha1_32CryptoCipher initWithSrtpEnableGcmCryptoSuites:(BOOL)srtpEnableGcmCryptoSuites
srtpEnableEncryptedRtpHeaderExtensions:(BOOL)srtpEnableEncryptedRtpHeaderExtensions srtpEnableAes128Sha1_32CryptoCipher:
sframeRequireFrameEncryption:(BOOL)sframeRequireFrameEncryption { (BOOL)srtpEnableAes128Sha1_32CryptoCipher
srtpEnableEncryptedRtpHeaderExtensions:
(BOOL)srtpEnableEncryptedRtpHeaderExtensions
sframeRequireFrameEncryption:(BOOL)sframeRequireFrameEncryption {
self = [super init]; self = [super init];
if (self) { if (self) {
_srtpEnableGcmCryptoSuites = srtpEnableGcmCryptoSuites; _srtpEnableGcmCryptoSuites = srtpEnableGcmCryptoSuites;
_srtpEnableAes128Sha1_32CryptoCipher = srtpEnableAes128Sha1_32CryptoCipher; _srtpEnableAes128Sha1_32CryptoCipher = srtpEnableAes128Sha1_32CryptoCipher;
_srtpEnableEncryptedRtpHeaderExtensions = srtpEnableEncryptedRtpHeaderExtensions; _srtpEnableEncryptedRtpHeaderExtensions =
srtpEnableEncryptedRtpHeaderExtensions;
_sframeRequireFrameEncryption = sframeRequireFrameEncryption; _sframeRequireFrameEncryption = sframeRequireFrameEncryption;
} }
return self; return self;

View File

@ -21,8 +21,8 @@ NS_ASSUME_NONNULL_BEGIN
() ()
/** /**
* The native DataBuffer representation of this RTCDatabuffer object. This is * The native DataBuffer representation of this RTCDatabuffer object. This
* needed to pass to the underlying C++ APIs. * is needed to pass to the underlying C++ APIs.
*/ */
@property(nonatomic, readonly) const webrtc::DataBuffer *nativeDataBuffer; @property(nonatomic, readonly) const webrtc::DataBuffer *nativeDataBuffer;
@ -37,7 +37,8 @@ NS_ASSUME_NONNULL_BEGIN
/** Initialize an RTCDataChannel from a native DataChannelInterface. */ /** Initialize an RTCDataChannel from a native DataChannelInterface. */
- (instancetype)initWithFactory - (instancetype)initWithFactory
: (RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory nativeDataChannel : (RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory nativeDataChannel
: (rtc::scoped_refptr<webrtc::DataChannelInterface>)nativeDataChannel NS_DESIGNATED_INITIALIZER; : (rtc::scoped_refptr<webrtc::DataChannelInterface>)
nativeDataChannel NS_DESIGNATED_INITIALIZER;
+ (webrtc::DataChannelInterface::DataState)nativeDataChannelStateForState: + (webrtc::DataChannelInterface::DataState)nativeDataChannelStateForState:
(RTCDataChannelState)state; (RTCDataChannelState)state;

View File

@ -40,7 +40,8 @@ RTC_OBJC_EXPORT
(RTCDataChannelDelegate)<NSObject> (RTCDataChannelDelegate)<NSObject>
/** The data channel state changed. */ /** The data channel state changed. */
- (void)dataChannelDidChangeState : (RTC_OBJC_TYPE(RTCDataChannel) *)dataChannel; - (void)dataChannelDidChangeState
: (RTC_OBJC_TYPE(RTCDataChannel) *)dataChannel;
/** The data channel successfully received a data buffer. */ /** The data channel successfully received a data buffer. */
- (void)dataChannel:(RTC_OBJC_TYPE(RTCDataChannel) *)dataChannel - (void)dataChannel:(RTC_OBJC_TYPE(RTCDataChannel) *)dataChannel
@ -77,7 +78,8 @@ RTC_OBJC_EXPORT
@property(nonatomic, readonly) BOOL isOrdered; @property(nonatomic, readonly) BOOL isOrdered;
/** Deprecated. Use maxPacketLifeTime. */ /** Deprecated. Use maxPacketLifeTime. */
@property(nonatomic, readonly) NSUInteger maxRetransmitTime DEPRECATED_ATTRIBUTE; @property(nonatomic, readonly)
NSUInteger maxRetransmitTime DEPRECATED_ATTRIBUTE;
/** /**
* The length of the time window (in milliseconds) during which transmissions * The length of the time window (in milliseconds) during which transmissions

View File

@ -18,17 +18,19 @@ namespace webrtc {
class DataChannelDelegateAdapter : public DataChannelObserver { class DataChannelDelegateAdapter : public DataChannelObserver {
public: public:
DataChannelDelegateAdapter(RTC_OBJC_TYPE(RTCDataChannel) * channel) { channel_ = channel; } DataChannelDelegateAdapter(RTC_OBJC_TYPE(RTCDataChannel) * channel) {
channel_ = channel;
}
void OnStateChange() override { void OnStateChange() override {
[channel_.delegate dataChannelDidChangeState:channel_]; [channel_.delegate dataChannelDidChangeState:channel_];
} }
void OnMessage(const DataBuffer& buffer) override { void OnMessage(const DataBuffer &buffer) override {
RTC_OBJC_TYPE(RTCDataBuffer) *data_buffer = RTC_OBJC_TYPE(RTCDataBuffer) *data_buffer =
[[RTC_OBJC_TYPE(RTCDataBuffer) alloc] initWithNativeBuffer:buffer]; [[RTC_OBJC_TYPE(RTCDataBuffer) alloc] initWithNativeBuffer:buffer];
[channel_.delegate dataChannel:channel_ [channel_.delegate dataChannel:channel_
didReceiveMessageWithBuffer:data_buffer]; didReceiveMessageWithBuffer:data_buffer];
} }
void OnBufferedAmountChange(uint64_t previousAmount) override { void OnBufferedAmountChange(uint64_t previousAmount) override {
@ -42,7 +44,7 @@ class DataChannelDelegateAdapter : public DataChannelObserver {
private: private:
__weak RTC_OBJC_TYPE(RTCDataChannel) * channel_; __weak RTC_OBJC_TYPE(RTCDataChannel) * channel_;
}; };
} } // namespace webrtc
@implementation RTC_OBJC_TYPE (RTCDataBuffer) { @implementation RTC_OBJC_TYPE (RTCDataBuffer) {
std::unique_ptr<webrtc::DataBuffer> _dataBuffer; std::unique_ptr<webrtc::DataBuffer> _dataBuffer;
@ -52,8 +54,8 @@ class DataChannelDelegateAdapter : public DataChannelObserver {
NSParameterAssert(data); NSParameterAssert(data);
self = [super init]; self = [super init];
if (self) { if (self) {
rtc::CopyOnWriteBuffer buffer( rtc::CopyOnWriteBuffer buffer(reinterpret_cast<const uint8_t *>(data.bytes),
reinterpret_cast<const uint8_t*>(data.bytes), data.length); data.length);
_dataBuffer.reset(new webrtc::DataBuffer(buffer, isBinary)); _dataBuffer.reset(new webrtc::DataBuffer(buffer, isBinary));
} }
return self; return self;
@ -70,7 +72,7 @@ class DataChannelDelegateAdapter : public DataChannelObserver {
#pragma mark - Private #pragma mark - Private
- (instancetype)initWithNativeBuffer:(const webrtc::DataBuffer&)nativeBuffer { - (instancetype)initWithNativeBuffer:(const webrtc::DataBuffer &)nativeBuffer {
self = [super init]; self = [super init];
if (self) { if (self) {
_dataBuffer.reset(new webrtc::DataBuffer(nativeBuffer)); _dataBuffer.reset(new webrtc::DataBuffer(nativeBuffer));
@ -140,8 +142,8 @@ class DataChannelDelegateAdapter : public DataChannelObserver {
} }
- (RTCDataChannelState)readyState { - (RTCDataChannelState)readyState {
return [[self class] dataChannelStateForNativeState: return
_nativeDataChannel->state()]; [[self class] dataChannelStateForNativeState:_nativeDataChannel->state()];
} }
- (uint64_t)bufferedAmount { - (uint64_t)bufferedAmount {
@ -157,17 +159,19 @@ class DataChannelDelegateAdapter : public DataChannelObserver {
} }
- (NSString *)description { - (NSString *)description {
return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCDataChannel):\n%ld\n%@\n%@", return
(long)self.channelId, [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCDataChannel):\n%ld\n%@\n%@",
self.label, (long)self.channelId,
[[self class] stringForState:self.readyState]]; self.label,
[[self class] stringForState:self.readyState]];
} }
#pragma mark - Private #pragma mark - Private
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)
nativeDataChannel: initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
(rtc::scoped_refptr<webrtc::DataChannelInterface>)nativeDataChannel { nativeDataChannel:
(rtc::scoped_refptr<webrtc::DataChannelInterface>)nativeDataChannel {
NSParameterAssert(nativeDataChannel); NSParameterAssert(nativeDataChannel);
self = [super init]; self = [super init];
if (self) { if (self) {
@ -179,8 +183,8 @@ class DataChannelDelegateAdapter : public DataChannelObserver {
return self; return self;
} }
+ (webrtc::DataChannelInterface::DataState) + (webrtc::DataChannelInterface::DataState)nativeDataChannelStateForState:
nativeDataChannelStateForState:(RTCDataChannelState)state { (RTCDataChannelState)state {
switch (state) { switch (state) {
case RTCDataChannelStateConnecting: case RTCDataChannelStateConnecting:
return webrtc::DataChannelInterface::DataState::kConnecting; return webrtc::DataChannelInterface::DataState::kConnecting;

View File

@ -17,7 +17,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface RTC_OBJC_TYPE (RTCDataChannelConfiguration) @interface RTC_OBJC_TYPE (RTCDataChannelConfiguration)
() ()
@property(nonatomic, readonly) webrtc::DataChannelInit nativeDataChannelInit; @property(nonatomic,
readonly) webrtc::DataChannelInit nativeDataChannelInit;
@end @end

View File

@ -23,7 +23,8 @@ NS_ASSUME_NONNULL_BEGIN
/** Initialize an RTCDtmfSender with a native DtmfSenderInterface. */ /** Initialize an RTCDtmfSender with a native DtmfSenderInterface. */
- (instancetype)initWithNativeDtmfSender: - (instancetype)initWithNativeDtmfSender:
(rtc::scoped_refptr<webrtc::DtmfSenderInterface>)nativeDtmfSender NS_DESIGNATED_INITIALIZER; (rtc::scoped_refptr<webrtc::DtmfSenderInterface>)nativeDtmfSender
NS_DESIGNATED_INITIALIZER;
@end @end

View File

@ -20,8 +20,9 @@ RTC_OBJC_EXPORT
/** /**
* Returns true if this RTCDtmfSender is capable of sending DTMF. Otherwise * Returns true if this RTCDtmfSender is capable of sending DTMF. Otherwise
* returns false. To be able to send DTMF, the associated RTCRtpSender must be * returns false. To be able to send DTMF, the associated RTCRtpSender must
* able to send packets, and a "telephone-event" codec must be negotiated. * be able to send packets, and a "telephone-event" codec must be
* negotiated.
*/ */
@property(nonatomic, readonly) BOOL canInsertDtmf; @property(nonatomic, readonly) BOOL canInsertDtmf;
@ -54,15 +55,16 @@ RTC_OBJC_EXPORT
- (nonnull NSString *)remainingTones; - (nonnull NSString *)remainingTones;
/** /**
* The current tone duration value. This value will be the value last set via the * The current tone duration value. This value will be the value last set via
* insertDtmf method, or the default value of 100 ms if insertDtmf was never called. * the insertDtmf method, or the default value of 100 ms if insertDtmf was never
* called.
*/ */
- (NSTimeInterval)duration; - (NSTimeInterval)duration;
/** /**
* The current value of the between-tone gap. This value will be the value last set * The current value of the between-tone gap. This value will be the value last
* via the insertDtmf() method, or the default value of 50 ms if insertDtmf() was never * set via the insertDtmf() method, or the default value of 50 ms if
* called. * insertDtmf() was never called.
*/ */
- (NSTimeInterval)interToneGap; - (NSTimeInterval)interToneGap;

View File

@ -30,7 +30,8 @@
RTC_DCHECK(tones != nil); RTC_DCHECK(tones != nil);
int durationMs = static_cast<int>(duration * rtc::kNumMillisecsPerSec); int durationMs = static_cast<int>(duration * rtc::kNumMillisecsPerSec);
int interToneGapMs = static_cast<int>(interToneGap * rtc::kNumMillisecsPerSec); int interToneGapMs =
static_cast<int>(interToneGap * rtc::kNumMillisecsPerSec);
return _nativeDtmfSender->InsertDtmf( return _nativeDtmfSender->InsertDtmf(
[NSString stdStringForString:tones], durationMs, interToneGapMs); [NSString stdStringForString:tones], durationMs, interToneGapMs);
} }
@ -40,7 +41,8 @@
} }
- (NSTimeInterval)duration { - (NSTimeInterval)duration {
return static_cast<NSTimeInterval>(_nativeDtmfSender->duration()) / rtc::kNumMillisecsPerSec; return static_cast<NSTimeInterval>(_nativeDtmfSender->duration()) /
rtc::kNumMillisecsPerSec;
} }
- (NSTimeInterval)interToneGap { - (NSTimeInterval)interToneGap {
@ -49,11 +51,13 @@
} }
- (NSString *)description { - (NSString *)description {
return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCDtmfSender) {\n remainingTones: %@\n " return
@"duration: %f sec\n interToneGap: %f sec\n}", [NSString stringWithFormat:
[self remainingTones], @"RTC_OBJC_TYPE(RTCDtmfSender) {\n remainingTones: %@\n "
[self duration], @"duration: %f sec\n interToneGap: %f sec\n}",
[self interToneGap]]; [self remainingTones],
[self duration],
[self interToneGap]];
} }
#pragma mark - Private #pragma mark - Private
@ -63,13 +67,14 @@
} }
- (instancetype)initWithNativeDtmfSender: - (instancetype)initWithNativeDtmfSender:
(rtc::scoped_refptr<webrtc::DtmfSenderInterface>)nativeDtmfSender { (rtc::scoped_refptr<webrtc::DtmfSenderInterface>)nativeDtmfSender {
NSParameterAssert(nativeDtmfSender); NSParameterAssert(nativeDtmfSender);
self = [super init]; self = [super init];
if (self) { if (self) {
_nativeDtmfSender = nativeDtmfSender; _nativeDtmfSender = nativeDtmfSender;
RTCLogInfo( RTCLogInfo(@"RTC_OBJC_TYPE(RTCDtmfSender)(%p): created DTMF sender: %@",
@"RTC_OBJC_TYPE(RTCDtmfSender)(%p): created DTMF sender: %@", self, self.description); self,
self.description);
} }
return self; return self;
} }

View File

@ -18,7 +18,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface RTC_OBJC_TYPE (RTCEncodedImage) @interface RTC_OBJC_TYPE (RTCEncodedImage)
(Private) (Private)
- (instancetype)initWithNativeEncodedImage : (const webrtc::EncodedImage &)encodedImage; - (instancetype)initWithNativeEncodedImage
: (const webrtc::EncodedImage &)encodedImage;
- (webrtc::EncodedImage)nativeEncodedImage; - (webrtc::EncodedImage)nativeEncodedImage;
@end @end

View File

@ -15,13 +15,16 @@
#include "rtc_base/numerics/safe_conversions.h" #include "rtc_base/numerics/safe_conversions.h"
namespace { namespace {
// An implementation of EncodedImageBufferInterface that doesn't perform any copies. // An implementation of EncodedImageBufferInterface that doesn't perform any
// copies.
class ObjCEncodedImageBuffer : public webrtc::EncodedImageBufferInterface { class ObjCEncodedImageBuffer : public webrtc::EncodedImageBufferInterface {
public: public:
static rtc::scoped_refptr<ObjCEncodedImageBuffer> Create(NSData *data) { static rtc::scoped_refptr<ObjCEncodedImageBuffer> Create(NSData *data) {
return rtc::make_ref_counted<ObjCEncodedImageBuffer>(data); return rtc::make_ref_counted<ObjCEncodedImageBuffer>(data);
} }
const uint8_t *data() const override { return static_cast<const uint8_t *>(data_.bytes); } const uint8_t *data() const override {
return static_cast<const uint8_t *>(data_.bytes);
}
// TODO(bugs.webrtc.org/9378): delete this non-const data method. // TODO(bugs.webrtc.org/9378): delete this non-const data method.
uint8_t *data() override { uint8_t *data() override {
return const_cast<uint8_t *>(static_cast<const uint8_t *>(data_.bytes)); return const_cast<uint8_t *>(static_cast<const uint8_t *>(data_.bytes));
@ -34,12 +37,13 @@ class ObjCEncodedImageBuffer : public webrtc::EncodedImageBufferInterface {
NSData *data_; NSData *data_;
}; };
} } // namespace
// A simple wrapper around webrtc::EncodedImageBufferInterface to make it usable with associated // A simple wrapper around webrtc::EncodedImageBufferInterface to make it usable
// objects. // with associated objects.
@interface RTCWrappedEncodedImageBuffer : NSObject @interface RTCWrappedEncodedImageBuffer : NSObject
@property(nonatomic) rtc::scoped_refptr<webrtc::EncodedImageBufferInterface> buffer; @property(nonatomic) rtc::scoped_refptr<webrtc::EncodedImageBufferInterface>
buffer;
- (instancetype)initWithEncodedImageBuffer: - (instancetype)initWithEncodedImageBuffer:
(rtc::scoped_refptr<webrtc::EncodedImageBufferInterface>)buffer; (rtc::scoped_refptr<webrtc::EncodedImageBufferInterface>)buffer;
@end @end
@ -64,7 +68,8 @@ class ObjCEncodedImageBuffer : public webrtc::EncodedImageBufferInterface {
return wrappedBuffer.buffer; return wrappedBuffer.buffer;
} }
- (void)setEncodedData:(rtc::scoped_refptr<webrtc::EncodedImageBufferInterface>)buffer { - (void)setEncodedData:
(rtc::scoped_refptr<webrtc::EncodedImageBufferInterface>)buffer {
return objc_setAssociatedObject( return objc_setAssociatedObject(
self, self,
@selector(encodedData), @selector(encodedData),
@ -72,18 +77,20 @@ class ObjCEncodedImageBuffer : public webrtc::EncodedImageBufferInterface {
OBJC_ASSOCIATION_RETAIN_NONATOMIC); OBJC_ASSOCIATION_RETAIN_NONATOMIC);
} }
- (instancetype)initWithNativeEncodedImage:(const webrtc::EncodedImage &)encodedImage { - (instancetype)initWithNativeEncodedImage:
(const webrtc::EncodedImage &)encodedImage {
self = [super init]; self = [super init];
if (self) { if (self) {
// A reference to the encodedData must be stored so that it's kept alive as long // A reference to the encodedData must be stored so that it's kept alive as
// self.buffer references its underlying data. // long self.buffer references its underlying data.
self.encodedData = encodedImage.GetEncodedData(); self.encodedData = encodedImage.GetEncodedData();
// Wrap the buffer in NSData without copying, do not take ownership. // Wrap the buffer in NSData without copying, do not take ownership.
self.buffer = [NSData dataWithBytesNoCopy:self.encodedData->data() self.buffer = [NSData dataWithBytesNoCopy:self.encodedData->data()
length:encodedImage.size() length:encodedImage.size()
freeWhenDone:NO]; freeWhenDone:NO];
self.encodedWidth = rtc::dchecked_cast<int32_t>(encodedImage._encodedWidth); self.encodedWidth = rtc::dchecked_cast<int32_t>(encodedImage._encodedWidth);
self.encodedHeight = rtc::dchecked_cast<int32_t>(encodedImage._encodedHeight); self.encodedHeight =
rtc::dchecked_cast<int32_t>(encodedImage._encodedHeight);
self.timeStamp = encodedImage.RtpTimestamp(); self.timeStamp = encodedImage.RtpTimestamp();
self.captureTimeMs = encodedImage.capture_time_ms_; self.captureTimeMs = encodedImage.capture_time_ms_;
self.ntpTimeMs = encodedImage.ntp_time_ms_; self.ntpTimeMs = encodedImage.ntp_time_ms_;
@ -93,7 +100,8 @@ class ObjCEncodedImageBuffer : public webrtc::EncodedImageBufferInterface {
self.frameType = static_cast<RTCFrameType>(encodedImage._frameType); self.frameType = static_cast<RTCFrameType>(encodedImage._frameType);
self.rotation = static_cast<RTCVideoRotation>(encodedImage.rotation_); self.rotation = static_cast<RTCVideoRotation>(encodedImage.rotation_);
self.qp = @(encodedImage.qp_); self.qp = @(encodedImage.qp_);
self.contentType = (encodedImage.content_type_ == webrtc::VideoContentType::SCREENSHARE) ? self.contentType =
(encodedImage.content_type_ == webrtc::VideoContentType::SCREENSHARE) ?
RTCVideoContentTypeScreenshare : RTCVideoContentTypeScreenshare :
RTCVideoContentTypeUnspecified; RTCVideoContentTypeUnspecified;
} }
@ -111,7 +119,8 @@ class ObjCEncodedImageBuffer : public webrtc::EncodedImageBufferInterface {
} }
encodedImage.set_size(self.buffer.length); encodedImage.set_size(self.buffer.length);
encodedImage._encodedWidth = rtc::dchecked_cast<uint32_t>(self.encodedWidth); encodedImage._encodedWidth = rtc::dchecked_cast<uint32_t>(self.encodedWidth);
encodedImage._encodedHeight = rtc::dchecked_cast<uint32_t>(self.encodedHeight); encodedImage._encodedHeight =
rtc::dchecked_cast<uint32_t>(self.encodedHeight);
encodedImage.SetRtpTimestamp(self.timeStamp); encodedImage.SetRtpTimestamp(self.timeStamp);
encodedImage.capture_time_ms_ = self.captureTimeMs; encodedImage.capture_time_ms_ = self.captureTimeMs;
encodedImage.ntp_time_ms_ = self.ntpTimeMs; encodedImage.ntp_time_ms_ = self.ntpTimeMs;
@ -121,7 +130,8 @@ class ObjCEncodedImageBuffer : public webrtc::EncodedImageBufferInterface {
encodedImage._frameType = webrtc::VideoFrameType(self.frameType); encodedImage._frameType = webrtc::VideoFrameType(self.frameType);
encodedImage.rotation_ = webrtc::VideoRotation(self.rotation); encodedImage.rotation_ = webrtc::VideoRotation(self.rotation);
encodedImage.qp_ = self.qp ? self.qp.intValue : -1; encodedImage.qp_ = self.qp ? self.qp.intValue : -1;
encodedImage.content_type_ = (self.contentType == RTCVideoContentTypeScreenshare) ? encodedImage.content_type_ =
(self.contentType == RTCVideoContentTypeScreenshare) ?
webrtc::VideoContentType::SCREENSHARE : webrtc::VideoContentType::SCREENSHARE :
webrtc::VideoContentType::UNSPECIFIED; webrtc::VideoContentType::UNSPECIFIED;

View File

@ -12,7 +12,8 @@
#import "sdk/objc/base/RTCMacros.h" #import "sdk/objc/base/RTCMacros.h"
/** The only valid value for the following if set is kRTCFieldTrialEnabledValue. */ /** The only valid value for the following if set is kRTCFieldTrialEnabledValue.
*/
RTC_EXTERN NSString *const kRTCFieldTrialAudioForceABWENoTWCCKey; RTC_EXTERN NSString *const kRTCFieldTrialAudioForceABWENoTWCCKey;
RTC_EXTERN NSString *const kRTCFieldTrialFlexFec03AdvertisedKey; RTC_EXTERN NSString *const kRTCFieldTrialFlexFec03AdvertisedKey;
RTC_EXTERN NSString *const kRTCFieldTrialFlexFec03Key; RTC_EXTERN NSString *const kRTCFieldTrialFlexFec03Key;
@ -27,4 +28,5 @@ RTC_EXTERN NSString *const kRTCFieldTrialEnabledValue;
* values. See above for valid keys and values. Must be called before any other * values. See above for valid keys and values. Must be called before any other
* call into WebRTC. See: webrtc/system_wrappers/include/field_trial.h * call into WebRTC. See: webrtc/system_wrappers/include/field_trial.h
*/ */
RTC_EXTERN void RTCInitFieldTrialDictionary(NSDictionary<NSString *, NSString *> *fieldTrials); RTC_EXTERN void RTCInitFieldTrialDictionary(
NSDictionary<NSString *, NSString *> *fieldTrials);

View File

@ -16,29 +16,35 @@
#include "system_wrappers/include/field_trial.h" #include "system_wrappers/include/field_trial.h"
NSString *const kRTCFieldTrialAudioForceABWENoTWCCKey = @"WebRTC-Audio-ABWENoTWCC"; NSString *const kRTCFieldTrialAudioForceABWENoTWCCKey =
NSString * const kRTCFieldTrialFlexFec03AdvertisedKey = @"WebRTC-FlexFEC-03-Advertised"; @"WebRTC-Audio-ABWENoTWCC";
NSString * const kRTCFieldTrialFlexFec03Key = @"WebRTC-FlexFEC-03"; NSString *const kRTCFieldTrialFlexFec03AdvertisedKey =
NSString * const kRTCFieldTrialH264HighProfileKey = @"WebRTC-H264HighProfile"; @"WebRTC-FlexFEC-03-Advertised";
NSString * const kRTCFieldTrialMinimizeResamplingOnMobileKey = NSString *const kRTCFieldTrialFlexFec03Key = @"WebRTC-FlexFEC-03";
NSString *const kRTCFieldTrialH264HighProfileKey = @"WebRTC-H264HighProfile";
NSString *const kRTCFieldTrialMinimizeResamplingOnMobileKey =
@"WebRTC-Audio-MinimizeResamplingOnMobile"; @"WebRTC-Audio-MinimizeResamplingOnMobile";
NSString *const kRTCFieldTrialUseNWPathMonitor = @"WebRTC-Network-UseNWPathMonitor"; NSString *const kRTCFieldTrialUseNWPathMonitor =
NSString * const kRTCFieldTrialEnabledValue = @"Enabled"; @"WebRTC-Network-UseNWPathMonitor";
NSString *const kRTCFieldTrialEnabledValue = @"Enabled";
// InitFieldTrialsFromString stores the char*, so the char array must outlive // InitFieldTrialsFromString stores the char*, so the char array must outlive
// the application. // the application.
static char *gFieldTrialInitString = nullptr; static char *gFieldTrialInitString = nullptr;
void RTCInitFieldTrialDictionary(NSDictionary<NSString *, NSString *> *fieldTrials) { void RTCInitFieldTrialDictionary(
NSDictionary<NSString *, NSString *> *fieldTrials) {
if (!fieldTrials) { if (!fieldTrials) {
RTCLogWarning(@"No fieldTrials provided."); RTCLogWarning(@"No fieldTrials provided.");
return; return;
} }
// Assemble the keys and values into the field trial string. // Assemble the keys and values into the field trial string.
// We don't perform any extra format checking. That should be done by the underlying WebRTC calls. // We don't perform any extra format checking. That should be done by the
// underlying WebRTC calls.
NSMutableString *fieldTrialInitString = [NSMutableString string]; NSMutableString *fieldTrialInitString = [NSMutableString string];
for (NSString *key in fieldTrials) { for (NSString *key in fieldTrials) {
NSString *fieldTrialEntry = [NSString stringWithFormat:@"%@/%@/", key, fieldTrials[key]]; NSString *fieldTrialEntry =
[NSString stringWithFormat:@"%@/%@/", key, fieldTrials[key]];
[fieldTrialInitString appendString:fieldTrialEntry]; [fieldTrialInitString appendString:fieldTrialEntry];
} }
size_t len = fieldTrialInitString.length + 1; size_t len = fieldTrialInitString.length + 1;

View File

@ -52,11 +52,13 @@ RTC_OBJC_EXPORT
- (instancetype)init; - (instancetype)init;
// Create file logger with default rotation type. // Create file logger with default rotation type.
- (instancetype)initWithDirPath:(NSString *)dirPath maxFileSize:(NSUInteger)maxFileSize; - (instancetype)initWithDirPath:(NSString *)dirPath
maxFileSize:(NSUInteger)maxFileSize;
- (instancetype)initWithDirPath:(NSString *)dirPath - (instancetype)initWithDirPath:(NSString *)dirPath
maxFileSize:(NSUInteger)maxFileSize maxFileSize:(NSUInteger)maxFileSize
rotationType:(RTCFileLoggerRotationType)rotationType NS_DESIGNATED_INITIALIZER; rotationType:(RTCFileLoggerRotationType)rotationType
NS_DESIGNATED_INITIALIZER;
// Starts writing WebRTC logs to disk if not already started. Overwrites any // Starts writing WebRTC logs to disk if not already started. Overwrites any
// existing file(s). // existing file(s).

View File

@ -18,7 +18,7 @@
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
NSString *const kDefaultLogDirName = @"webrtc_logs"; NSString *const kDefaultLogDirName = @"webrtc_logs";
NSUInteger const kDefaultMaxFileSize = 10 * 1024 * 1024; // 10MB. NSUInteger const kDefaultMaxFileSize = 10 * 1024 * 1024; // 10MB.
const char *kRTCFileLoggerRotatingLogPrefix = "rotating_log"; const char *kRTCFileLoggerRotatingLogPrefix = "rotating_log";
@implementation RTC_OBJC_TYPE (RTCFileLogger) { @implementation RTC_OBJC_TYPE (RTCFileLogger) {
@ -38,8 +38,7 @@ const char *kRTCFileLoggerRotatingLogPrefix = "rotating_log";
NSString *documentsDirPath = [paths firstObject]; NSString *documentsDirPath = [paths firstObject];
NSString *defaultDirPath = NSString *defaultDirPath =
[documentsDirPath stringByAppendingPathComponent:kDefaultLogDirName]; [documentsDirPath stringByAppendingPathComponent:kDefaultLogDirName];
return [self initWithDirPath:defaultDirPath return [self initWithDirPath:defaultDirPath maxFileSize:kDefaultMaxFileSize];
maxFileSize:kDefaultMaxFileSize];
} }
- (instancetype)initWithDirPath:(NSString *)dirPath - (instancetype)initWithDirPath:(NSString *)dirPath
@ -96,13 +95,13 @@ const char *kRTCFileLoggerRotatingLogPrefix = "rotating_log";
_maxFileSize / 10)); _maxFileSize / 10));
break; break;
case RTCFileLoggerTypeCall: case RTCFileLoggerTypeCall:
_logSink.reset( _logSink.reset(new rtc::CallSessionFileRotatingLogSink(
new rtc::CallSessionFileRotatingLogSink(_dirPath.UTF8String, _dirPath.UTF8String, _maxFileSize));
_maxFileSize));
break; break;
} }
if (!_logSink->Init()) { if (!_logSink->Init()) {
RTC_LOG(LS_ERROR) << "Failed to open log files at path: " << _dirPath.UTF8String; RTC_LOG(LS_ERROR) << "Failed to open log files at path: "
<< _dirPath.UTF8String;
_logSink.reset(); _logSink.reset();
return; return;
} }
@ -129,15 +128,16 @@ const char *kRTCFileLoggerRotatingLogPrefix = "rotating_log";
if (_hasStarted) { if (_hasStarted) {
return nil; return nil;
} }
NSMutableData* logData = [NSMutableData data]; NSMutableData *logData = [NSMutableData data];
std::unique_ptr<rtc::FileRotatingStreamReader> stream; std::unique_ptr<rtc::FileRotatingStreamReader> stream;
switch(_rotationType) { switch (_rotationType) {
case RTCFileLoggerTypeApp: case RTCFileLoggerTypeApp:
stream = std::make_unique<rtc::FileRotatingStreamReader>(_dirPath.UTF8String, stream = std::make_unique<rtc::FileRotatingStreamReader>(
kRTCFileLoggerRotatingLogPrefix); _dirPath.UTF8String, kRTCFileLoggerRotatingLogPrefix);
break; break;
case RTCFileLoggerTypeCall: case RTCFileLoggerTypeCall:
stream = std::make_unique<rtc::CallSessionFileRotatingStreamReader>(_dirPath.UTF8String); stream = std::make_unique<rtc::CallSessionFileRotatingStreamReader>(
_dirPath.UTF8String);
break; break;
} }
size_t bufferSize = stream->GetSize(); size_t bufferSize = stream->GetSize();
@ -146,7 +146,7 @@ const char *kRTCFileLoggerRotatingLogPrefix = "rotating_log";
} }
// Allocate memory using malloc so we can pass it direcly to NSData without // Allocate memory using malloc so we can pass it direcly to NSData without
// copying. // copying.
std::unique_ptr<uint8_t[]> buffer(static_cast<uint8_t*>(malloc(bufferSize))); std::unique_ptr<uint8_t[]> buffer(static_cast<uint8_t *>(malloc(bufferSize)));
size_t read = stream->ReadAll(buffer.get(), bufferSize); size_t read = stream->ReadAll(buffer.get(), bufferSize);
logData = [[NSMutableData alloc] initWithBytesNoCopy:buffer.release() logData = [[NSMutableData alloc] initWithBytesNoCopy:buffer.release()
length:read]; length:read];

View File

@ -23,13 +23,15 @@ NS_ASSUME_NONNULL_BEGIN
* The native IceCandidateInterface representation of this RTCIceCandidate * The native IceCandidateInterface representation of this RTCIceCandidate
* object. This is needed to pass to the underlying C++ APIs. * object. This is needed to pass to the underlying C++ APIs.
*/ */
@property(nonatomic, readonly) std::unique_ptr<webrtc::IceCandidateInterface> nativeCandidate; @property(nonatomic, readonly)
std::unique_ptr<webrtc::IceCandidateInterface> nativeCandidate;
/** /**
* Initialize an RTCIceCandidate from a native IceCandidateInterface. No * Initialize an RTCIceCandidate from a native IceCandidateInterface. No
* ownership is taken of the native candidate. * ownership is taken of the native candidate.
*/ */
- (instancetype)initWithNativeCandidate:(const webrtc::IceCandidateInterface *)candidate; - (instancetype)initWithNativeCandidate:
(const webrtc::IceCandidateInterface *)candidate;
@end @end

View File

@ -42,7 +42,8 @@ RTC_OBJC_EXPORT
*/ */
- (instancetype)initWithSdp:(NSString *)sdp - (instancetype)initWithSdp:(NSString *)sdp
sdpMLineIndex:(int)sdpMLineIndex sdpMLineIndex:(int)sdpMLineIndex
sdpMid:(nullable NSString *)sdpMid NS_DESIGNATED_INITIALIZER; sdpMid:(nullable NSString *)sdpMid
NS_DESIGNATED_INITIALIZER;
@end @end

View File

@ -36,11 +36,12 @@
} }
- (NSString *)description { - (NSString *)description {
return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCIceCandidate):\n%@\n%d\n%@\n%@", return [NSString
_sdpMid, stringWithFormat:@"RTC_OBJC_TYPE(RTCIceCandidate):\n%@\n%d\n%@\n%@",
_sdpMLineIndex, _sdpMid,
_sdp, _sdpMLineIndex,
_serverUrl]; _sdp,
_serverUrl];
} }
#pragma mark - Private #pragma mark - Private
@ -55,7 +56,8 @@
[self initWithSdp:[NSString stringForStdString:sdp] [self initWithSdp:[NSString stringForStdString:sdp]
sdpMLineIndex:candidate->sdp_mline_index() sdpMLineIndex:candidate->sdp_mline_index()
sdpMid:[NSString stringForStdString:candidate->sdp_mid()]]; sdpMid:[NSString stringForStdString:candidate->sdp_mid()]];
rtcCandidate->_serverUrl = [NSString stringForStdString:candidate->server_url()]; rtcCandidate->_serverUrl =
[NSString stringForStdString:candidate->server_url()];
return rtcCandidate; return rtcCandidate;
} }

View File

@ -17,9 +17,9 @@ NS_ASSUME_NONNULL_BEGIN
@interface RTC_OBJC_TYPE (RTCIceCandidateErrorEvent) @interface RTC_OBJC_TYPE (RTCIceCandidateErrorEvent)
() ()
- (instancetype)initWithAddress : (const std::string&)address port : (const int)port url - (instancetype)initWithAddress : (const std::string&)address port
: (const std::string&)url errorCode : (const int)errorCode errorText : (const int)port url : (const std::string&)url errorCode
: (const std::string&)errorText; : (const int)errorCode errorText : (const std::string&)errorText;
@end @end

View File

@ -23,16 +23,19 @@ RTC_OBJC_EXPORT
/** The port used to communicate with the STUN or TURN server. */ /** The port used to communicate with the STUN or TURN server. */
@property(nonatomic, readonly) int port; @property(nonatomic, readonly) int port;
/** The STUN or TURN URL that identifies the STUN or TURN server for which the failure occurred. */ /** The STUN or TURN URL that identifies the STUN or TURN server for which the
* failure occurred. */
@property(nonatomic, readonly) NSString *url; @property(nonatomic, readonly) NSString *url;
/** The numeric STUN error code returned by the STUN or TURN server. If no host candidate can reach /** The numeric STUN error code returned by the STUN or TURN server. If no host
* the server, errorCode will be set to the value 701 which is outside the STUN error code range. * candidate can reach the server, errorCode will be set to the value 701 which
* This error is only fired once per server URL while in the RTCIceGatheringState of "gathering". */ * is outside the STUN error code range. This error is only fired once per
* server URL while in the RTCIceGatheringState of "gathering". */
@property(nonatomic, readonly) int errorCode; @property(nonatomic, readonly) int errorCode;
/** The STUN reason text returned by the STUN or TURN server. If the server could not be reached, /** The STUN reason text returned by the STUN or TURN server. If the server
* errorText will be set to an implementation-specific value providing details about the error. */ * could not be reached, errorText will be set to an implementation-specific
* value providing details about the error. */
@property(nonatomic, readonly) NSString *errorText; @property(nonatomic, readonly) NSString *errorText;
- (instancetype)init NS_DESIGNATED_INITIALIZER; - (instancetype)init NS_DESIGNATED_INITIALIZER;

View File

@ -21,10 +21,12 @@ NS_ASSUME_NONNULL_BEGIN
* IceServer struct representation of this RTCIceServer object's data. * IceServer struct representation of this RTCIceServer object's data.
* This is needed to pass to the underlying C++ APIs. * This is needed to pass to the underlying C++ APIs.
*/ */
@property(nonatomic, readonly) webrtc::PeerConnectionInterface::IceServer nativeServer; @property(nonatomic,
readonly) webrtc::PeerConnectionInterface::IceServer nativeServer;
/** Initialize an RTCIceServer from a native IceServer. */ /** Initialize an RTCIceServer from a native IceServer. */
- (instancetype)initWithNativeServer:(webrtc::PeerConnectionInterface::IceServer)nativeServer; - (instancetype)initWithNativeServer:
(webrtc::PeerConnectionInterface::IceServer)nativeServer;
@end @end

View File

@ -100,13 +100,14 @@ RTC_OBJC_EXPORT
* optional credential, TLS cert policy, hostname, ALPN protocols and * optional credential, TLS cert policy, hostname, ALPN protocols and
* elliptic curves. * elliptic curves.
*/ */
- (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings - (instancetype)
username:(nullable NSString *)username initWithURLStrings:(NSArray<NSString *> *)urlStrings
credential:(nullable NSString *)credential username:(nullable NSString *)username
tlsCertPolicy:(RTCTlsCertPolicy)tlsCertPolicy credential:(nullable NSString *)credential
hostname:(nullable NSString *)hostname tlsCertPolicy:(RTCTlsCertPolicy)tlsCertPolicy
tlsAlpnProtocols:(nullable NSArray<NSString *> *)tlsAlpnProtocols hostname:(nullable NSString *)hostname
tlsEllipticCurves:(nullable NSArray<NSString *> *)tlsEllipticCurves tlsAlpnProtocols:(nullable NSArray<NSString *> *)tlsAlpnProtocols
tlsEllipticCurves:(nullable NSArray<NSString *> *)tlsEllipticCurves
NS_DESIGNATED_INITIALIZER; NS_DESIGNATED_INITIALIZER;
@end @end

View File

@ -23,9 +23,7 @@
@synthesize tlsEllipticCurves = _tlsEllipticCurves; @synthesize tlsEllipticCurves = _tlsEllipticCurves;
- (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings { - (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings {
return [self initWithURLStrings:urlStrings return [self initWithURLStrings:urlStrings username:nil credential:nil];
username:nil
credential:nil];
} }
- (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings - (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings
@ -91,21 +89,25 @@
_credential = [credential copy]; _credential = [credential copy];
_tlsCertPolicy = tlsCertPolicy; _tlsCertPolicy = tlsCertPolicy;
_hostname = [hostname copy]; _hostname = [hostname copy];
_tlsAlpnProtocols = [[NSArray alloc] initWithArray:tlsAlpnProtocols copyItems:YES]; _tlsAlpnProtocols = [[NSArray alloc] initWithArray:tlsAlpnProtocols
_tlsEllipticCurves = [[NSArray alloc] initWithArray:tlsEllipticCurves copyItems:YES]; copyItems:YES];
_tlsEllipticCurves = [[NSArray alloc] initWithArray:tlsEllipticCurves
copyItems:YES];
} }
return self; return self;
} }
- (NSString *)description { - (NSString *)description {
return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCIceServer):\n%@\n%@\n%@\n%@\n%@\n%@\n%@", return
_urlStrings, [NSString stringWithFormat:
_username, @"RTC_OBJC_TYPE(RTCIceServer):\n%@\n%@\n%@\n%@\n%@\n%@\n%@",
_credential, _urlStrings,
[self stringForTlsCertPolicy:_tlsCertPolicy], _username,
_hostname, _credential,
_tlsAlpnProtocols, [self stringForTlsCertPolicy:_tlsCertPolicy],
_tlsEllipticCurves]; _hostname,
_tlsAlpnProtocols,
_tlsEllipticCurves];
} }
#pragma mark - Private #pragma mark - Private
@ -126,19 +128,20 @@
iceServer.password = [NSString stdStringForString:_credential]; iceServer.password = [NSString stdStringForString:_credential];
iceServer.hostname = [NSString stdStringForString:_hostname]; iceServer.hostname = [NSString stdStringForString:_hostname];
[_tlsAlpnProtocols enumerateObjectsUsingBlock:^(NSString *proto, NSUInteger idx, BOOL *stop) { [_tlsAlpnProtocols enumerateObjectsUsingBlock:^(
NSString *proto, NSUInteger idx, BOOL *stop) {
iceServer.tls_alpn_protocols.push_back(proto.stdString); iceServer.tls_alpn_protocols.push_back(proto.stdString);
}]; }];
[_tlsEllipticCurves enumerateObjectsUsingBlock:^(NSString *curve, NSUInteger idx, BOOL *stop) { [_tlsEllipticCurves enumerateObjectsUsingBlock:^(
NSString *curve, NSUInteger idx, BOOL *stop) {
iceServer.tls_elliptic_curves.push_back(curve.stdString); iceServer.tls_elliptic_curves.push_back(curve.stdString);
}]; }];
[_urlStrings enumerateObjectsUsingBlock:^(NSString *url, [_urlStrings
NSUInteger idx, enumerateObjectsUsingBlock:^(NSString *url, NSUInteger idx, BOOL *stop) {
BOOL *stop) { iceServer.urls.push_back(url.stdString);
iceServer.urls.push_back(url.stdString); }];
}];
switch (_tlsCertPolicy) { switch (_tlsCertPolicy) {
case RTCTlsCertPolicySecure: case RTCTlsCertPolicySecure:
@ -168,8 +171,8 @@
for (auto const &proto : nativeServer.tls_alpn_protocols) { for (auto const &proto : nativeServer.tls_alpn_protocols) {
[tlsAlpnProtocols addObject:[NSString stringForStdString:proto]]; [tlsAlpnProtocols addObject:[NSString stringForStdString:proto]];
} }
NSMutableArray *tlsEllipticCurves = NSMutableArray *tlsEllipticCurves = [NSMutableArray
[NSMutableArray arrayWithCapacity:nativeServer.tls_elliptic_curves.size()]; arrayWithCapacity:nativeServer.tls_elliptic_curves.size()];
for (auto const &curve : nativeServer.tls_elliptic_curves) { for (auto const &curve : nativeServer.tls_elliptic_curves) {
[tlsEllipticCurves addObject:[NSString stringForStdString:curve]]; [tlsEllipticCurves addObject:[NSString stringForStdString:curve]];
} }

View File

@ -18,7 +18,8 @@ NS_ASSUME_NONNULL_BEGIN
() ()
/** Initialize an RTCLegacyStatsReport object from a native StatsReport. */ /** Initialize an RTCLegacyStatsReport object from a native StatsReport. */
- (instancetype)initWithNativeReport : (const webrtc::StatsReport &)nativeReport; - (instancetype)initWithNativeReport
: (const webrtc::StatsReport &)nativeReport;
@end @end

View File

@ -23,11 +23,12 @@
@synthesize values = _values; @synthesize values = _values;
- (NSString *)description { - (NSString *)description {
return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCLegacyStatsReport):\n%@\n%@\n%f\n%@", return [NSString
_reportId, stringWithFormat:@"RTC_OBJC_TYPE(RTCLegacyStatsReport):\n%@\n%@\n%f\n%@",
_type, _reportId,
_timestamp, _type,
_values]; _timestamp,
_values];
} }
#pragma mark - Private #pragma mark - Private
@ -37,17 +38,16 @@
if (self) { if (self) {
_timestamp = nativeReport.timestamp(); _timestamp = nativeReport.timestamp();
_type = [NSString stringForStdString:nativeReport.TypeToString()]; _type = [NSString stringForStdString:nativeReport.TypeToString()];
_reportId = [NSString stringForStdString: _reportId = [NSString stringForStdString:nativeReport.id()->ToString()];
nativeReport.id()->ToString()];
NSUInteger capacity = nativeReport.values().size(); NSUInteger capacity = nativeReport.values().size();
NSMutableDictionary *values = NSMutableDictionary *values =
[NSMutableDictionary dictionaryWithCapacity:capacity]; [NSMutableDictionary dictionaryWithCapacity:capacity];
for (auto const &valuePair : nativeReport.values()) { for (auto const &valuePair : nativeReport.values()) {
NSString *key = [NSString stringForStdString: NSString *key =
valuePair.second->display_name()]; [NSString stringForStdString:valuePair.second->display_name()];
NSString *value = [NSString stringForStdString: NSString *value =
valuePair.second->ToString()]; [NSString stringForStdString:valuePair.second->ToString()];
// Not expecting duplicate keys. // Not expecting duplicate keys.
RTC_DCHECK(![values objectForKey:key]); RTC_DCHECK(![values objectForKey:key]);

View File

@ -20,8 +20,8 @@ NS_ASSUME_NONNULL_BEGIN
() ()
/** /**
* A MediaConstraints representation of this RTCMediaConstraints object. This is * A MediaConstraints representation of this RTCMediaConstraints object.
* needed to pass to the underlying C++ APIs. * This is needed to pass to the underlying C++ APIs.
*/ */
- (std::unique_ptr<webrtc::MediaConstraints>)nativeConstraints; - (std::unique_ptr<webrtc::MediaConstraints>)nativeConstraints;

View File

@ -36,10 +36,11 @@ RTC_OBJC_EXPORT
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
/** Initialize with mandatory and/or optional constraints. */ /** Initialize with mandatory and/or optional constraints. */
- (instancetype) - (instancetype)initWithMandatoryConstraints:
initWithMandatoryConstraints:(nullable NSDictionary<NSString *, NSString *> *)mandatory (nullable NSDictionary<NSString *, NSString *> *)mandatory
optionalConstraints:(nullable NSDictionary<NSString *, NSString *> *)optional optionalConstraints:
NS_DESIGNATED_INITIALIZER; (nullable NSDictionary<NSString *, NSString *> *)
optional NS_DESIGNATED_INITIALIZER;
@end @end

View File

@ -17,7 +17,8 @@
NSString *const kRTCMediaConstraintsAudioNetworkAdaptorConfig = NSString *const kRTCMediaConstraintsAudioNetworkAdaptorConfig =
@(webrtc::MediaConstraints::kAudioNetworkAdaptorConfig); @(webrtc::MediaConstraints::kAudioNetworkAdaptorConfig);
NSString *const kRTCMediaConstraintsIceRestart = @(webrtc::MediaConstraints::kIceRestart); NSString *const kRTCMediaConstraintsIceRestart =
@(webrtc::MediaConstraints::kIceRestart);
NSString *const kRTCMediaConstraintsOfferToReceiveAudio = NSString *const kRTCMediaConstraintsOfferToReceiveAudio =
@(webrtc::MediaConstraints::kOfferToReceiveAudio); @(webrtc::MediaConstraints::kOfferToReceiveAudio);
NSString *const kRTCMediaConstraintsOfferToReceiveVideo = NSString *const kRTCMediaConstraintsOfferToReceiveVideo =
@ -25,8 +26,10 @@ NSString *const kRTCMediaConstraintsOfferToReceiveVideo =
NSString *const kRTCMediaConstraintsVoiceActivityDetection = NSString *const kRTCMediaConstraintsVoiceActivityDetection =
@(webrtc::MediaConstraints::kVoiceActivityDetection); @(webrtc::MediaConstraints::kVoiceActivityDetection);
NSString *const kRTCMediaConstraintsValueTrue = @(webrtc::MediaConstraints::kValueTrue); NSString *const kRTCMediaConstraintsValueTrue =
NSString *const kRTCMediaConstraintsValueFalse = @(webrtc::MediaConstraints::kValueFalse); @(webrtc::MediaConstraints::kValueTrue);
NSString *const kRTCMediaConstraintsValueFalse =
@(webrtc::MediaConstraints::kValueFalse);
@implementation RTC_OBJC_TYPE (RTCMediaConstraints) { @implementation RTC_OBJC_TYPE (RTCMediaConstraints) {
NSDictionary<NSString *, NSString *> *_mandatory; NSDictionary<NSString *, NSString *> *_mandatory;
@ -34,9 +37,9 @@ NSString *const kRTCMediaConstraintsValueFalse = @(webrtc::MediaConstraints::kVa
} }
- (instancetype)initWithMandatoryConstraints: - (instancetype)initWithMandatoryConstraints:
(NSDictionary<NSString *, NSString *> *)mandatory (NSDictionary<NSString *, NSString *> *)mandatory
optionalConstraints: optionalConstraints:
(NSDictionary<NSString *, NSString *> *)optional { (NSDictionary<NSString *, NSString *> *)optional {
self = [super init]; self = [super init];
if (self) { if (self) {
_mandatory = [[NSDictionary alloc] initWithDictionary:mandatory _mandatory = [[NSDictionary alloc] initWithDictionary:mandatory
@ -48,8 +51,10 @@ NSString *const kRTCMediaConstraintsValueFalse = @(webrtc::MediaConstraints::kVa
} }
- (NSString *)description { - (NSString *)description {
return [NSString return
stringWithFormat:@"RTC_OBJC_TYPE(RTCMediaConstraints):\n%@\n%@", _mandatory, _optional]; [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCMediaConstraints):\n%@\n%@",
_mandatory,
_optional];
} }
#pragma mark - Private #pragma mark - Private
@ -69,17 +74,20 @@ NSString *const kRTCMediaConstraintsValueFalse = @(webrtc::MediaConstraints::kVa
(NSDictionary<NSString *, NSString *> *)constraints { (NSDictionary<NSString *, NSString *> *)constraints {
webrtc::MediaConstraints::Constraints nativeConstraints; webrtc::MediaConstraints::Constraints nativeConstraints;
for (NSString *key in constraints) { for (NSString *key in constraints) {
NSAssert([key isKindOfClass:[NSString class]], NSAssert(
@"%@ is not an NSString.", key); [key isKindOfClass:[NSString class]], @"%@ is not an NSString.", key);
NSString *value = [constraints objectForKey:key]; NSString *value = [constraints objectForKey:key];
NSAssert([value isKindOfClass:[NSString class]], NSAssert([value isKindOfClass:[NSString class]],
@"%@ is not an NSString.", value); @"%@ is not an NSString.",
value);
if ([kRTCMediaConstraintsAudioNetworkAdaptorConfig isEqualToString:key]) { if ([kRTCMediaConstraintsAudioNetworkAdaptorConfig isEqualToString:key]) {
// This value is base64 encoded. // This value is base64 encoded.
NSData *charData = [[NSData alloc] initWithBase64EncodedString:value options:0]; NSData *charData = [[NSData alloc] initWithBase64EncodedString:value
std::string configValue = options:0];
std::string(reinterpret_cast<const char *>(charData.bytes), charData.length); std::string configValue = std::string(
nativeConstraints.push_back(webrtc::MediaConstraints::Constraint(key.stdString, configValue)); reinterpret_cast<const char *>(charData.bytes), charData.length);
nativeConstraints.push_back(
webrtc::MediaConstraints::Constraint(key.stdString, configValue));
} else { } else {
nativeConstraints.push_back( nativeConstraints.push_back(
webrtc::MediaConstraints::Constraint(key.stdString, value.stdString)); webrtc::MediaConstraints::Constraint(key.stdString, value.stdString));

View File

@ -24,16 +24,20 @@ typedef NS_ENUM(NSInteger, RTCMediaSourceType) {
@interface RTC_OBJC_TYPE (RTCMediaSource) @interface RTC_OBJC_TYPE (RTCMediaSource)
() ()
@property(nonatomic, @property(nonatomic, readonly)
readonly) rtc::scoped_refptr<webrtc::MediaSourceInterface> nativeMediaSource; rtc::scoped_refptr<webrtc::MediaSourceInterface> nativeMediaSource;
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)
nativeMediaSource:(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
type:(RTCMediaSourceType)type NS_DESIGNATED_INITIALIZER; nativeMediaSource:
(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource
type:(RTCMediaSourceType)type NS_DESIGNATED_INITIALIZER;
+ (webrtc::MediaSourceInterface::SourceState)nativeSourceStateForState:(RTCSourceState)state; + (webrtc::MediaSourceInterface::SourceState)nativeSourceStateForState:
(RTCSourceState)state;
+ (RTCSourceState)sourceStateForNativeState:(webrtc::MediaSourceInterface::SourceState)nativeState; + (RTCSourceState)sourceStateForNativeState:
(webrtc::MediaSourceInterface::SourceState)nativeState;
+ (NSString *)stringForState:(RTCSourceState)state; + (NSString *)stringForState:(RTCSourceState)state;

View File

@ -19,9 +19,11 @@
@synthesize nativeMediaSource = _nativeMediaSource; @synthesize nativeMediaSource = _nativeMediaSource;
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)
nativeMediaSource:(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
type:(RTCMediaSourceType)type { nativeMediaSource:
(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource
type:(RTCMediaSourceType)type {
RTC_DCHECK(factory); RTC_DCHECK(factory);
RTC_DCHECK(nativeMediaSource); RTC_DCHECK(nativeMediaSource);
self = [super init]; self = [super init];

View File

@ -18,19 +18,22 @@ NS_ASSUME_NONNULL_BEGIN
() ()
/** /**
* MediaStreamInterface representation of this RTCMediaStream object. This is * MediaStreamInterface representation of this RTCMediaStream object. This
* needed to pass to the underlying C++ APIs. * is needed to pass to the underlying C++ APIs.
*/ */
@property(nonatomic, @property(nonatomic, readonly)
readonly) rtc::scoped_refptr<webrtc::MediaStreamInterface> nativeMediaStream; rtc::scoped_refptr<webrtc::MediaStreamInterface> nativeMediaStream;
/** Initialize an RTCMediaStream with an id. */ /** Initialize an RTCMediaStream with an id. */
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)initWithFactory:
(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
streamId:(NSString *)streamId; streamId:(NSString *)streamId;
/** Initialize an RTCMediaStream from a native MediaStreamInterface. */ /** Initialize an RTCMediaStream from a native MediaStreamInterface. */
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)
nativeMediaStream:(rtc::scoped_refptr<webrtc::MediaStreamInterface>)nativeMediaStream; initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
nativeMediaStream:
(rtc::scoped_refptr<webrtc::MediaStreamInterface>)nativeMediaStream;
@end @end

View File

@ -25,7 +25,8 @@ RTC_OBJC_EXPORT
@property(nonatomic, strong, readonly) NSArray<RTC_OBJC_TYPE(RTCAudioTrack) *> *audioTracks; @property(nonatomic, strong, readonly) NSArray<RTC_OBJC_TYPE(RTCAudioTrack) *> *audioTracks;
/** The video tracks in this stream. */ /** The video tracks in this stream. */
@property(nonatomic, strong, readonly) NSArray<RTC_OBJC_TYPE(RTCVideoTrack) *> *videoTracks; @property(nonatomic, strong, readonly)
NSArray<RTC_OBJC_TYPE(RTCVideoTrack) *> *videoTracks;
/** An identifier for this media stream. */ /** An identifier for this media stream. */
@property(nonatomic, readonly) NSString *streamId; @property(nonatomic, readonly) NSString *streamId;

View File

@ -24,7 +24,8 @@
rtc::scoped_refptr<webrtc::MediaStreamInterface> _nativeMediaStream; rtc::scoped_refptr<webrtc::MediaStreamInterface> _nativeMediaStream;
} }
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)initWithFactory:
(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
streamId:(NSString *)streamId { streamId:(NSString *)streamId {
NSParameterAssert(factory); NSParameterAssert(factory);
NSParameterAssert(streamId.length); NSParameterAssert(streamId.length);
@ -36,14 +37,16 @@
- (NSArray<RTC_OBJC_TYPE(RTCAudioTrack) *> *)audioTracks { - (NSArray<RTC_OBJC_TYPE(RTCAudioTrack) *> *)audioTracks {
if (!_signalingThread->IsCurrent()) { if (!_signalingThread->IsCurrent()) {
return _signalingThread->BlockingCall([self]() { return self.audioTracks; }); return _signalingThread->BlockingCall(
[self]() { return self.audioTracks; });
} }
return [_audioTracks copy]; return [_audioTracks copy];
} }
- (NSArray<RTC_OBJC_TYPE(RTCVideoTrack) *> *)videoTracks { - (NSArray<RTC_OBJC_TYPE(RTCVideoTrack) *> *)videoTracks {
if (!_signalingThread->IsCurrent()) { if (!_signalingThread->IsCurrent()) {
return _signalingThread->BlockingCall([self]() { return self.videoTracks; }); return _signalingThread->BlockingCall(
[self]() { return self.videoTracks; });
} }
return [_videoTracks copy]; return [_videoTracks copy];
} }
@ -79,7 +82,8 @@
} }
NSUInteger index = [_audioTracks indexOfObjectIdenticalTo:audioTrack]; NSUInteger index = [_audioTracks indexOfObjectIdenticalTo:audioTrack];
if (index == NSNotFound) { if (index == NSNotFound) {
RTC_LOG(LS_INFO) << "|removeAudioTrack| called on unexpected RTC_OBJC_TYPE(RTCAudioTrack)"; RTC_LOG(LS_INFO) << "|removeAudioTrack| called on unexpected "
"RTC_OBJC_TYPE(RTCAudioTrack)";
return; return;
} }
if (_nativeMediaStream->RemoveTrack(audioTrack.nativeAudioTrack)) { if (_nativeMediaStream->RemoveTrack(audioTrack.nativeAudioTrack)) {
@ -94,7 +98,8 @@
} }
NSUInteger index = [_videoTracks indexOfObjectIdenticalTo:videoTrack]; NSUInteger index = [_videoTracks indexOfObjectIdenticalTo:videoTrack];
if (index == NSNotFound) { if (index == NSNotFound) {
RTC_LOG(LS_INFO) << "|removeVideoTrack| called on unexpected RTC_OBJC_TYPE(RTCVideoTrack)"; RTC_LOG(LS_INFO) << "|removeVideoTrack| called on unexpected "
"RTC_OBJC_TYPE(RTCVideoTrack)";
return; return;
} }
@ -104,10 +109,11 @@
} }
- (NSString *)description { - (NSString *)description {
return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCMediaStream):\n%@\nA=%lu\nV=%lu", return [NSString
self.streamId, stringWithFormat:@"RTC_OBJC_TYPE(RTCMediaStream):\n%@\nA=%lu\nV=%lu",
(unsigned long)self.audioTracks.count, self.streamId,
(unsigned long)self.videoTracks.count]; (unsigned long)self.audioTracks.count,
(unsigned long)self.videoTracks.count];
} }
#pragma mark - Private #pragma mark - Private
@ -116,9 +122,10 @@
return _nativeMediaStream; return _nativeMediaStream;
} }
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)
nativeMediaStream: initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
(rtc::scoped_refptr<webrtc::MediaStreamInterface>)nativeMediaStream { nativeMediaStream:
(rtc::scoped_refptr<webrtc::MediaStreamInterface>)nativeMediaStream {
NSParameterAssert(nativeMediaStream); NSParameterAssert(nativeMediaStream);
self = [super init]; self = [super init];
if (self) { if (self) {

View File

@ -31,17 +31,23 @@ NS_ASSUME_NONNULL_BEGIN
* The native MediaStreamTrackInterface passed in or created during * The native MediaStreamTrackInterface passed in or created during
* construction. * construction.
*/ */
@property(nonatomic, readonly) rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> nativeTrack; @property(nonatomic, readonly)
rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>
nativeTrack;
/** /**
* Initialize an RTCMediaStreamTrack from a native MediaStreamTrackInterface. * Initialize an RTCMediaStreamTrack from a native MediaStreamTrackInterface.
*/ */
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)
nativeTrack:(rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
type:(RTCMediaStreamTrackType)type NS_DESIGNATED_INITIALIZER; nativeTrack:
(rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack
type:(RTCMediaStreamTrackType)type NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)
nativeTrack:(rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack; initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
nativeTrack:
(rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack;
- (BOOL)isEqualToTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track; - (BOOL)isEqualToTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track;
@ -54,7 +60,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSString *)stringForState:(RTCMediaStreamTrackState)state; + (NSString *)stringForState:(RTCMediaStreamTrackState)state;
+ (RTC_OBJC_TYPE(RTCMediaStreamTrack) *) + (RTC_OBJC_TYPE(RTCMediaStreamTrack) *)
mediaTrackForNativeTrack:(rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack mediaTrackForNativeTrack:
(rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack
factory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory; factory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory;
@end @end

View File

@ -14,9 +14,9 @@
#import "helpers/NSString+StdString.h" #import "helpers/NSString+StdString.h"
NSString * const kRTCMediaStreamTrackKindAudio = NSString *const kRTCMediaStreamTrackKindAudio =
@(webrtc::MediaStreamTrackInterface::kAudioKind); @(webrtc::MediaStreamTrackInterface::kAudioKind);
NSString * const kRTCMediaStreamTrackKindVideo = NSString *const kRTCMediaStreamTrackKindVideo =
@(webrtc::MediaStreamTrackInterface::kVideoKind); @(webrtc::MediaStreamTrackInterface::kVideoKind);
@implementation RTC_OBJC_TYPE (RTCMediaStreamTrack) { @implementation RTC_OBJC_TYPE (RTCMediaStreamTrack) {
@ -47,11 +47,12 @@ NSString * const kRTCMediaStreamTrackKindVideo =
- (NSString *)description { - (NSString *)description {
NSString *readyState = [[self class] stringForState:self.readyState]; NSString *readyState = [[self class] stringForState:self.readyState];
return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCMediaStreamTrack):\n%@\n%@\n%@\n%@", return [NSString
self.kind, stringWithFormat:@"RTC_OBJC_TYPE(RTCMediaStreamTrack):\n%@\n%@\n%@\n%@",
self.trackId, self.kind,
self.isEnabled ? @"enabled" : @"disabled", self.trackId,
readyState]; self.isEnabled ? @"enabled" : @"disabled",
readyState];
} }
- (BOOL)isEqual:(id)object { - (BOOL)isEqual:(id)object {
@ -76,9 +77,11 @@ NSString * const kRTCMediaStreamTrackKindVideo =
@synthesize factory = _factory; @synthesize factory = _factory;
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)
nativeTrack:(rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
type:(RTCMediaStreamTrackType)type { nativeTrack:
(rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack
type:(RTCMediaStreamTrackType)type {
NSParameterAssert(nativeTrack); NSParameterAssert(nativeTrack);
NSParameterAssert(factory); NSParameterAssert(factory);
self = [super init]; self = [super init];
@ -90,16 +93,22 @@ NSString * const kRTCMediaStreamTrackKindVideo =
return self; return self;
} }
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)
nativeTrack:(rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack { initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
nativeTrack:
(rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack {
NSParameterAssert(nativeTrack); NSParameterAssert(nativeTrack);
if (nativeTrack->kind() == if (nativeTrack->kind() ==
std::string(webrtc::MediaStreamTrackInterface::kAudioKind)) { std::string(webrtc::MediaStreamTrackInterface::kAudioKind)) {
return [self initWithFactory:factory nativeTrack:nativeTrack type:RTCMediaStreamTrackTypeAudio]; return [self initWithFactory:factory
nativeTrack:nativeTrack
type:RTCMediaStreamTrackTypeAudio];
} }
if (nativeTrack->kind() == if (nativeTrack->kind() ==
std::string(webrtc::MediaStreamTrackInterface::kVideoKind)) { std::string(webrtc::MediaStreamTrackInterface::kVideoKind)) {
return [self initWithFactory:factory nativeTrack:nativeTrack type:RTCMediaStreamTrackTypeVideo]; return [self initWithFactory:factory
nativeTrack:nativeTrack
type:RTCMediaStreamTrackTypeVideo];
} }
return nil; return nil;
} }
@ -141,21 +150,27 @@ NSString * const kRTCMediaStreamTrackKindVideo =
} }
+ (RTC_OBJC_TYPE(RTCMediaStreamTrack) *) + (RTC_OBJC_TYPE(RTCMediaStreamTrack) *)
mediaTrackForNativeTrack:(rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack mediaTrackForNativeTrack:
factory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory { (rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack
factory:
(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory {
NSParameterAssert(nativeTrack); NSParameterAssert(nativeTrack);
NSParameterAssert(factory); NSParameterAssert(factory);
if (nativeTrack->kind() == webrtc::MediaStreamTrackInterface::kAudioKind) { if (nativeTrack->kind() == webrtc::MediaStreamTrackInterface::kAudioKind) {
return [[RTC_OBJC_TYPE(RTCAudioTrack) alloc] initWithFactory:factory return [[RTC_OBJC_TYPE(RTCAudioTrack) alloc]
nativeTrack:nativeTrack initWithFactory:factory
type:RTCMediaStreamTrackTypeAudio]; nativeTrack:nativeTrack
} else if (nativeTrack->kind() == webrtc::MediaStreamTrackInterface::kVideoKind) { type:RTCMediaStreamTrackTypeAudio];
return [[RTC_OBJC_TYPE(RTCVideoTrack) alloc] initWithFactory:factory } else if (nativeTrack->kind() ==
nativeTrack:nativeTrack webrtc::MediaStreamTrackInterface::kVideoKind) {
type:RTCMediaStreamTrackTypeVideo]; return [[RTC_OBJC_TYPE(RTCVideoTrack) alloc]
initWithFactory:factory
nativeTrack:nativeTrack
type:RTCMediaStreamTrackTypeVideo];
} else { } else {
return [[RTC_OBJC_TYPE(RTCMediaStreamTrack) alloc] initWithFactory:factory return [[RTC_OBJC_TYPE(RTCMediaStreamTrack) alloc]
nativeTrack:nativeTrack]; initWithFactory:factory
nativeTrack:nativeTrack];
} }
} }

View File

@ -20,4 +20,5 @@
RTC_EXTERN void RTCEnableMetrics(void); RTC_EXTERN void RTCEnableMetrics(void);
/** Gets and clears native histograms. */ /** Gets and clears native histograms. */
RTC_EXTERN NSArray<RTC_OBJC_TYPE(RTCMetricsSampleInfo) *>* RTCGetAndResetMetrics(void); RTC_EXTERN NSArray<RTC_OBJC_TYPE(RTCMetricsSampleInfo) *>*
RTCGetAndResetMetrics(void);

View File

@ -19,7 +19,9 @@ void RTCEnableMetrics(void) {
} }
NSArray<RTC_OBJC_TYPE(RTCMetricsSampleInfo) *> *RTCGetAndResetMetrics(void) { NSArray<RTC_OBJC_TYPE(RTCMetricsSampleInfo) *> *RTCGetAndResetMetrics(void) {
std::map<std::string, std::unique_ptr<webrtc::metrics::SampleInfo>, rtc::AbslStringViewCmp> std::map<std::string,
std::unique_ptr<webrtc::metrics::SampleInfo>,
rtc::AbslStringViewCmp>
histograms; histograms;
webrtc::metrics::GetAndReset(&histograms); webrtc::metrics::GetAndReset(&histograms);
@ -27,7 +29,8 @@ NSArray<RTC_OBJC_TYPE(RTCMetricsSampleInfo) *> *RTCGetAndResetMetrics(void) {
[NSMutableArray arrayWithCapacity:histograms.size()]; [NSMutableArray arrayWithCapacity:histograms.size()];
for (auto const &histogram : histograms) { for (auto const &histogram : histograms) {
RTC_OBJC_TYPE(RTCMetricsSampleInfo) *metric = RTC_OBJC_TYPE(RTCMetricsSampleInfo) *metric =
[[RTC_OBJC_TYPE(RTCMetricsSampleInfo) alloc] initWithNativeSampleInfo:*histogram.second]; [[RTC_OBJC_TYPE(RTCMetricsSampleInfo) alloc]
initWithNativeSampleInfo:*histogram.second];
[metrics addObject:metric]; [metrics addObject:metric];
} }
return metrics; return metrics;

View File

@ -18,7 +18,8 @@ NS_ASSUME_NONNULL_BEGIN
() ()
/** Initialize an RTCMetricsSampleInfo object from native SampleInfo. */ /** Initialize an RTCMetricsSampleInfo object from native SampleInfo. */
- (instancetype)initWithNativeSampleInfo : (const webrtc::metrics::SampleInfo &)info; - (instancetype)initWithNativeSampleInfo
: (const webrtc::metrics::SampleInfo &)info;
@end @end

View File

@ -23,12 +23,14 @@
std::string labelString = [NSString stdStringForString:label]; std::string labelString = [NSString stdStringForString:label];
const webrtc::DataChannelInit nativeInit = const webrtc::DataChannelInit nativeInit =
configuration.nativeDataChannelInit; configuration.nativeDataChannelInit;
auto result = self.nativePeerConnection->CreateDataChannelOrError(labelString, &nativeInit); auto result = self.nativePeerConnection->CreateDataChannelOrError(
labelString, &nativeInit);
if (!result.ok()) { if (!result.ok()) {
return nil; return nil;
} }
return [[RTC_OBJC_TYPE(RTCDataChannel) alloc] initWithFactory:self.factory return [[RTC_OBJC_TYPE(RTCDataChannel) alloc]
nativeDataChannel:result.MoveValue()]; initWithFactory:self.factory
nativeDataChannel:result.MoveValue()];
} }
@end @end

View File

@ -22,29 +22,36 @@ namespace webrtc {
*/ */
class PeerConnectionDelegateAdapter : public PeerConnectionObserver { class PeerConnectionDelegateAdapter : public PeerConnectionObserver {
public: public:
PeerConnectionDelegateAdapter(RTC_OBJC_TYPE(RTCPeerConnection) * peerConnection); PeerConnectionDelegateAdapter(RTC_OBJC_TYPE(RTCPeerConnection) *
peerConnection);
~PeerConnectionDelegateAdapter() override; ~PeerConnectionDelegateAdapter() override;
void OnSignalingChange(PeerConnectionInterface::SignalingState new_state) override; void OnSignalingChange(
PeerConnectionInterface::SignalingState new_state) override;
void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) override; void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) override;
void OnRemoveStream(rtc::scoped_refptr<MediaStreamInterface> stream) override; void OnRemoveStream(rtc::scoped_refptr<MediaStreamInterface> stream) override;
void OnTrack(rtc::scoped_refptr<RtpTransceiverInterface> transceiver) override; void OnTrack(
rtc::scoped_refptr<RtpTransceiverInterface> transceiver) override;
void OnDataChannel(rtc::scoped_refptr<DataChannelInterface> data_channel) override; void OnDataChannel(
rtc::scoped_refptr<DataChannelInterface> data_channel) override;
void OnRenegotiationNeeded() override; void OnRenegotiationNeeded() override;
void OnIceConnectionChange(PeerConnectionInterface::IceConnectionState new_state) override; void OnIceConnectionChange(
PeerConnectionInterface::IceConnectionState new_state) override;
void OnStandardizedIceConnectionChange( void OnStandardizedIceConnectionChange(
PeerConnectionInterface::IceConnectionState new_state) override; PeerConnectionInterface::IceConnectionState new_state) override;
void OnConnectionChange(PeerConnectionInterface::PeerConnectionState new_state) override; void OnConnectionChange(
PeerConnectionInterface::PeerConnectionState new_state) override;
void OnIceGatheringChange(PeerConnectionInterface::IceGatheringState new_state) override; void OnIceGatheringChange(
PeerConnectionInterface::IceGatheringState new_state) override;
void OnIceCandidate(const IceCandidateInterface *candidate) override; void OnIceCandidate(const IceCandidateInterface *candidate) override;
@ -54,14 +61,18 @@ class PeerConnectionDelegateAdapter : public PeerConnectionObserver {
int error_code, int error_code,
const std::string &error_text) override; const std::string &error_text) override;
void OnIceCandidatesRemoved(const std::vector<cricket::Candidate> &candidates) override; void OnIceCandidatesRemoved(
const std::vector<cricket::Candidate> &candidates) override;
void OnIceSelectedCandidatePairChanged(const cricket::CandidatePairChangeEvent &event) override; void OnIceSelectedCandidatePairChanged(
const cricket::CandidatePairChangeEvent &event) override;
void OnAddTrack(rtc::scoped_refptr<RtpReceiverInterface> receiver, void OnAddTrack(rtc::scoped_refptr<RtpReceiverInterface> receiver,
const std::vector<rtc::scoped_refptr<MediaStreamInterface>> &streams) override; const std::vector<rtc::scoped_refptr<MediaStreamInterface>>
&streams) override;
void OnRemoveTrack(rtc::scoped_refptr<RtpReceiverInterface> receiver) override; void OnRemoveTrack(
rtc::scoped_refptr<RtpReceiverInterface> receiver) override;
private: private:
__weak RTC_OBJC_TYPE(RTCPeerConnection) * peer_connection_; __weak RTC_OBJC_TYPE(RTCPeerConnection) * peer_connection_;
@ -79,8 +90,9 @@ class PeerConnectionDelegateAdapter : public PeerConnectionObserver {
factory; factory;
/** The native PeerConnectionInterface created during construction. */ /** The native PeerConnectionInterface created during construction. */
@property(nonatomic, readonly) rtc::scoped_refptr<webrtc::PeerConnectionInterface> @property(nonatomic, readonly)
nativePeerConnection; rtc::scoped_refptr<webrtc::PeerConnectionInterface>
nativePeerConnection;
/** Initialize an RTCPeerConnection with a configuration, constraints, and /** Initialize an RTCPeerConnection with a configuration, constraints, and
* delegate. * delegate.
@ -89,8 +101,10 @@ class PeerConnectionDelegateAdapter : public PeerConnectionObserver {
initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
configuration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration configuration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration
constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
certificateVerifier:(nullable id<RTC_OBJC_TYPE(RTCSSLCertificateVerifier)>)certificateVerifier certificateVerifier:(nullable id<RTC_OBJC_TYPE(RTCSSLCertificateVerifier)>)
delegate:(nullable id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate; certificateVerifier
delegate:(nullable id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)
delegate;
/** Initialize an RTCPeerConnection with a configuration, constraints, /** Initialize an RTCPeerConnection with a configuration, constraints,
* delegate and PeerConnectionDependencies. * delegate and PeerConnectionDependencies.
@ -99,9 +113,10 @@ class PeerConnectionDelegateAdapter : public PeerConnectionObserver {
initWithDependencies:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory initWithDependencies:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
configuration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration configuration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration
constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
dependencies:(std::unique_ptr<webrtc::PeerConnectionDependencies>)dependencies dependencies:(std::unique_ptr<webrtc::PeerConnectionDependencies>)
delegate:(nullable id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate dependencies
NS_DESIGNATED_INITIALIZER; delegate:(nullable id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)
delegate NS_DESIGNATED_INITIALIZER;
+ (webrtc::PeerConnectionInterface::SignalingState)nativeSignalingStateForState: + (webrtc::PeerConnectionInterface::SignalingState)nativeSignalingStateForState:
(RTCSignalingState)state; (RTCSignalingState)state;
@ -111,11 +126,11 @@ class PeerConnectionDelegateAdapter : public PeerConnectionObserver {
+ (NSString *)stringForSignalingState:(RTCSignalingState)state; + (NSString *)stringForSignalingState:(RTCSignalingState)state;
+ (webrtc::PeerConnectionInterface::IceConnectionState)nativeIceConnectionStateForState: + (webrtc::PeerConnectionInterface::IceConnectionState)
(RTCIceConnectionState)state; nativeIceConnectionStateForState:(RTCIceConnectionState)state;
+ (webrtc::PeerConnectionInterface::PeerConnectionState)nativeConnectionStateForState: + (webrtc::PeerConnectionInterface::PeerConnectionState)
(RTCPeerConnectionState)state; nativeConnectionStateForState:(RTCPeerConnectionState)state;
+ (RTCIceConnectionState)iceConnectionStateForNativeState: + (RTCIceConnectionState)iceConnectionStateForNativeState:
(webrtc::PeerConnectionInterface::IceConnectionState)nativeState; (webrtc::PeerConnectionInterface::IceConnectionState)nativeState;
@ -127,16 +142,16 @@ class PeerConnectionDelegateAdapter : public PeerConnectionObserver {
+ (NSString *)stringForConnectionState:(RTCPeerConnectionState)state; + (NSString *)stringForConnectionState:(RTCPeerConnectionState)state;
+ (webrtc::PeerConnectionInterface::IceGatheringState)nativeIceGatheringStateForState: + (webrtc::PeerConnectionInterface::IceGatheringState)
(RTCIceGatheringState)state; nativeIceGatheringStateForState:(RTCIceGatheringState)state;
+ (RTCIceGatheringState)iceGatheringStateForNativeState: + (RTCIceGatheringState)iceGatheringStateForNativeState:
(webrtc::PeerConnectionInterface::IceGatheringState)nativeState; (webrtc::PeerConnectionInterface::IceGatheringState)nativeState;
+ (NSString *)stringForIceGatheringState:(RTCIceGatheringState)state; + (NSString *)stringForIceGatheringState:(RTCIceGatheringState)state;
+ (webrtc::PeerConnectionInterface::StatsOutputLevel)nativeStatsOutputLevelForLevel: + (webrtc::PeerConnectionInterface::StatsOutputLevel)
(RTCStatsOutputLevel)level; nativeStatsOutputLevelForLevel:(RTCStatsOutputLevel)level;
@end @end

View File

@ -23,10 +23,12 @@ namespace webrtc {
class StatsCollectorCallbackAdapter : public RTCStatsCollectorCallback { class StatsCollectorCallbackAdapter : public RTCStatsCollectorCallback {
public: public:
StatsCollectorCallbackAdapter(RTCStatisticsCompletionHandler completion_handler) StatsCollectorCallbackAdapter(
RTCStatisticsCompletionHandler completion_handler)
: completion_handler_(completion_handler) {} : completion_handler_(completion_handler) {}
void OnStatsDelivered(const rtc::scoped_refptr<const RTCStatsReport> &report) override { void OnStatsDelivered(
const rtc::scoped_refptr<const RTCStatsReport> &report) override {
RTC_DCHECK(completion_handler_); RTC_DCHECK(completion_handler_);
RTC_OBJC_TYPE(RTCStatisticsReport) *statisticsReport = RTC_OBJC_TYPE(RTCStatisticsReport) *statisticsReport =
[[RTC_OBJC_TYPE(RTCStatisticsReport) alloc] initWithReport:*report]; [[RTC_OBJC_TYPE(RTCStatisticsReport) alloc] initWithReport:*report];
@ -40,19 +42,20 @@ class StatsCollectorCallbackAdapter : public RTCStatsCollectorCallback {
class StatsObserverAdapter : public StatsObserver { class StatsObserverAdapter : public StatsObserver {
public: public:
StatsObserverAdapter( StatsObserverAdapter(void (^completionHandler)(
void (^completionHandler)(NSArray<RTC_OBJC_TYPE(RTCLegacyStatsReport) *> *stats)) { NSArray<RTC_OBJC_TYPE(RTCLegacyStatsReport) *> *stats)) {
completion_handler_ = completionHandler; completion_handler_ = completionHandler;
} }
~StatsObserverAdapter() override { completion_handler_ = nil; } ~StatsObserverAdapter() override { completion_handler_ = nil; }
void OnComplete(const StatsReports& reports) override { void OnComplete(const StatsReports &reports) override {
RTC_DCHECK(completion_handler_); RTC_DCHECK(completion_handler_);
NSMutableArray *stats = [NSMutableArray arrayWithCapacity:reports.size()]; NSMutableArray *stats = [NSMutableArray arrayWithCapacity:reports.size()];
for (const auto* report : reports) { for (const auto *report : reports) {
RTC_OBJC_TYPE(RTCLegacyStatsReport) *statsReport = RTC_OBJC_TYPE(RTCLegacyStatsReport) *statsReport =
[[RTC_OBJC_TYPE(RTCLegacyStatsReport) alloc] initWithNativeReport:*report]; [[RTC_OBJC_TYPE(RTCLegacyStatsReport) alloc]
initWithNativeReport:*report];
[stats addObject:statsReport]; [stats addObject:statsReport];
} }
completion_handler_(stats); completion_handler_(stats);
@ -60,37 +63,45 @@ class StatsObserverAdapter : public StatsObserver {
} }
private: private:
void (^completion_handler_)(NSArray<RTC_OBJC_TYPE(RTCLegacyStatsReport) *> *stats); void (^completion_handler_)(
NSArray<RTC_OBJC_TYPE(RTCLegacyStatsReport) *> *stats);
}; };
} // namespace webrtc } // namespace webrtc
@implementation RTC_OBJC_TYPE (RTCPeerConnection) @implementation RTC_OBJC_TYPE (RTCPeerConnection)
(Stats) (Stats)
- (void)statisticsForSender : (RTC_OBJC_TYPE(RTCRtpSender) *)sender completionHandler - (void)statisticsForSender
: (RTC_OBJC_TYPE(RTCRtpSender) *)sender completionHandler
: (RTCStatisticsCompletionHandler)completionHandler { : (RTCStatisticsCompletionHandler)completionHandler {
rtc::scoped_refptr<webrtc::StatsCollectorCallbackAdapter> collector = rtc::scoped_refptr<webrtc::StatsCollectorCallbackAdapter> collector =
rtc::make_ref_counted<webrtc::StatsCollectorCallbackAdapter>(completionHandler); rtc::make_ref_counted<webrtc::StatsCollectorCallbackAdapter>(
completionHandler);
self.nativePeerConnection->GetStats(sender.nativeRtpSender, collector); self.nativePeerConnection->GetStats(sender.nativeRtpSender, collector);
} }
- (void)statisticsForReceiver:(RTC_OBJC_TYPE(RTCRtpReceiver) *)receiver - (void)statisticsForReceiver:(RTC_OBJC_TYPE(RTCRtpReceiver) *)receiver
completionHandler:(RTCStatisticsCompletionHandler)completionHandler { completionHandler:
(RTCStatisticsCompletionHandler)completionHandler {
rtc::scoped_refptr<webrtc::StatsCollectorCallbackAdapter> collector = rtc::scoped_refptr<webrtc::StatsCollectorCallbackAdapter> collector =
rtc::make_ref_counted<webrtc::StatsCollectorCallbackAdapter>(completionHandler); rtc::make_ref_counted<webrtc::StatsCollectorCallbackAdapter>(
completionHandler);
self.nativePeerConnection->GetStats(receiver.nativeRtpReceiver, collector); self.nativePeerConnection->GetStats(receiver.nativeRtpReceiver, collector);
} }
- (void)statisticsWithCompletionHandler:(RTCStatisticsCompletionHandler)completionHandler { - (void)statisticsWithCompletionHandler:
(RTCStatisticsCompletionHandler)completionHandler {
rtc::scoped_refptr<webrtc::StatsCollectorCallbackAdapter> collector = rtc::scoped_refptr<webrtc::StatsCollectorCallbackAdapter> collector =
rtc::make_ref_counted<webrtc::StatsCollectorCallbackAdapter>(completionHandler); rtc::make_ref_counted<webrtc::StatsCollectorCallbackAdapter>(
completionHandler);
self.nativePeerConnection->GetStats(collector.get()); self.nativePeerConnection->GetStats(collector.get());
} }
- (void)statsForTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)mediaStreamTrack - (void)statsForTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)mediaStreamTrack
statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel
completionHandler: completionHandler:
(void (^)(NSArray<RTC_OBJC_TYPE(RTCLegacyStatsReport) *> *stats))completionHandler { (void (^)(NSArray<RTC_OBJC_TYPE(RTCLegacyStatsReport) *> *stats))
completionHandler {
rtc::scoped_refptr<webrtc::StatsObserverAdapter> observer = rtc::scoped_refptr<webrtc::StatsObserverAdapter> observer =
rtc::make_ref_counted<webrtc::StatsObserverAdapter>(completionHandler); rtc::make_ref_counted<webrtc::StatsObserverAdapter>(completionHandler);
webrtc::PeerConnectionInterface::StatsOutputLevel nativeOutputLevel = webrtc::PeerConnectionInterface::StatsOutputLevel nativeOutputLevel =

View File

@ -83,9 +83,11 @@ typedef NS_ENUM(NSInteger, RTCStatsOutputLevel) {
}; };
typedef void (^RTCCreateSessionDescriptionCompletionHandler)( typedef void (^RTCCreateSessionDescriptionCompletionHandler)(
RTC_OBJC_TYPE(RTCSessionDescription) *_Nullable sdp, NSError *_Nullable error); RTC_OBJC_TYPE(RTCSessionDescription) *_Nullable sdp,
NSError *_Nullable error);
typedef void (^RTCSetSessionDescriptionCompletionHandler)(NSError *_Nullable error); typedef void (^RTCSetSessionDescriptionCompletionHandler)(
NSError *_Nullable error);
@class RTC_OBJC_TYPE(RTCPeerConnection); @class RTC_OBJC_TYPE(RTCPeerConnection);
@ -109,7 +111,8 @@ RTC_OBJC_EXPORT
didRemoveStream:(RTC_OBJC_TYPE(RTCMediaStream) *)stream; didRemoveStream:(RTC_OBJC_TYPE(RTCMediaStream) *)stream;
/** Called when negotiation is needed, for example ICE has restarted. */ /** Called when negotiation is needed, for example ICE has restarted. */
- (void)peerConnectionShouldNegotiate:(RTC_OBJC_TYPE(RTCPeerConnection) *)peerConnection; - (void)peerConnectionShouldNegotiate:
(RTC_OBJC_TYPE(RTCPeerConnection) *)peerConnection;
/** Called any time the IceConnectionState changes. */ /** Called any time the IceConnectionState changes. */
- (void)peerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)peerConnection - (void)peerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)peerConnection
@ -125,7 +128,8 @@ RTC_OBJC_EXPORT
/** Called when a group of local Ice candidates have been removed. */ /** Called when a group of local Ice candidates have been removed. */
- (void)peerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)peerConnection - (void)peerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)peerConnection
didRemoveIceCandidates:(NSArray<RTC_OBJC_TYPE(RTCIceCandidate) *> *)candidates; didRemoveIceCandidates:
(NSArray<RTC_OBJC_TYPE(RTCIceCandidate) *> *)candidates;
/** New data channel has been opened. */ /** New data channel has been opened. */
- (void)peerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)peerConnection - (void)peerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)peerConnection
@ -146,7 +150,8 @@ RTC_OBJC_EXPORT
didChangeConnectionState:(RTCPeerConnectionState)newState; didChangeConnectionState:(RTCPeerConnectionState)newState;
- (void)peerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)peerConnection - (void)peerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)peerConnection
didStartReceivingOnTransceiver:(RTC_OBJC_TYPE(RTCRtpTransceiver) *)transceiver; didStartReceivingOnTransceiver:
(RTC_OBJC_TYPE(RTCRtpTransceiver) *)transceiver;
/** Called when a receiver and its track are created. */ /** Called when a receiver and its track are created. */
- (void)peerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)peerConnection - (void)peerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)peerConnection
@ -166,7 +171,8 @@ RTC_OBJC_EXPORT
/** Called when gathering of an ICE candidate failed. */ /** Called when gathering of an ICE candidate failed. */
- (void)peerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)peerConnection - (void)peerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)peerConnection
didFailToGatherIceCandidate:(RTC_OBJC_TYPE(RTCIceCandidateErrorEvent) *)event; didFailToGatherIceCandidate:
(RTC_OBJC_TYPE(RTCIceCandidateErrorEvent) *)event;
@end @end
@ -180,14 +186,18 @@ RTC_OBJC_EXPORT
/** This property is not available with RTCSdpSemanticsUnifiedPlan. Please use /** This property is not available with RTCSdpSemanticsUnifiedPlan. Please use
* `senders` instead. * `senders` instead.
*/ */
@property(nonatomic, readonly) NSArray<RTC_OBJC_TYPE(RTCMediaStream) *> *localStreams; @property(nonatomic, readonly)
@property(nonatomic, readonly, nullable) RTC_OBJC_TYPE(RTCSessionDescription) * localDescription; NSArray<RTC_OBJC_TYPE(RTCMediaStream) *> *localStreams;
@property(nonatomic, readonly, nullable) RTC_OBJC_TYPE(RTCSessionDescription) * remoteDescription; @property(nonatomic, readonly, nullable) RTC_OBJC_TYPE(RTCSessionDescription) *
localDescription;
@property(nonatomic, readonly, nullable) RTC_OBJC_TYPE(RTCSessionDescription) *
remoteDescription;
@property(nonatomic, readonly) RTCSignalingState signalingState; @property(nonatomic, readonly) RTCSignalingState signalingState;
@property(nonatomic, readonly) RTCIceConnectionState iceConnectionState; @property(nonatomic, readonly) RTCIceConnectionState iceConnectionState;
@property(nonatomic, readonly) RTCPeerConnectionState connectionState; @property(nonatomic, readonly) RTCPeerConnectionState connectionState;
@property(nonatomic, readonly) RTCIceGatheringState iceGatheringState; @property(nonatomic, readonly) RTCIceGatheringState iceGatheringState;
@property(nonatomic, readonly, copy) RTC_OBJC_TYPE(RTCConfiguration) * configuration; @property(nonatomic, readonly, copy) RTC_OBJC_TYPE(RTCConfiguration) *
configuration;
/** Gets all RTCRtpSenders associated with this peer connection. /** Gets all RTCRtpSenders associated with this peer connection.
* Note: reading this property returns different instances of RTCRtpSender. * Note: reading this property returns different instances of RTCRtpSender.
@ -199,7 +209,8 @@ RTC_OBJC_EXPORT
* Note: reading this property returns different instances of RTCRtpReceiver. * Note: reading this property returns different instances of RTCRtpReceiver.
* Use isEqual: instead of == to compare RTCRtpReceiver instances. * Use isEqual: instead of == to compare RTCRtpReceiver instances.
*/ */
@property(nonatomic, readonly) NSArray<RTC_OBJC_TYPE(RTCRtpReceiver) *> *receivers; @property(nonatomic, readonly)
NSArray<RTC_OBJC_TYPE(RTCRtpReceiver) *> *receivers;
/** Gets all RTCRtpTransceivers associated with this peer connection. /** Gets all RTCRtpTransceivers associated with this peer connection.
* Note: reading this property returns different instances of * Note: reading this property returns different instances of
@ -207,7 +218,8 @@ RTC_OBJC_EXPORT
* RTCRtpTransceiver instances. This is only available with * RTCRtpTransceiver instances. This is only available with
* RTCSdpSemanticsUnifiedPlan specified. * RTCSdpSemanticsUnifiedPlan specified.
*/ */
@property(nonatomic, readonly) NSArray<RTC_OBJC_TYPE(RTCRtpTransceiver) *> *transceivers; @property(nonatomic, readonly)
NSArray<RTC_OBJC_TYPE(RTCRtpTransceiver) *> *transceivers;
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
@ -224,14 +236,16 @@ RTC_OBJC_EXPORT
/** Provide a remote candidate to the ICE Agent. */ /** Provide a remote candidate to the ICE Agent. */
- (void)addIceCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)candidate - (void)addIceCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)candidate
DEPRECATED_MSG_ATTRIBUTE("Please use addIceCandidate:completionHandler: instead"); DEPRECATED_MSG_ATTRIBUTE(
"Please use addIceCandidate:completionHandler: instead");
/** Provide a remote candidate to the ICE Agent. */ /** Provide a remote candidate to the ICE Agent. */
- (void)addIceCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)candidate - (void)addIceCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)candidate
completionHandler:(void (^)(NSError *_Nullable error))completionHandler; completionHandler:(void (^)(NSError *_Nullable error))completionHandler;
/** Remove a group of remote candidates from the ICE Agent. */ /** Remove a group of remote candidates from the ICE Agent. */
- (void)removeIceCandidates:(NSArray<RTC_OBJC_TYPE(RTCIceCandidate) *> *)candidates; - (void)removeIceCandidates:
(NSArray<RTC_OBJC_TYPE(RTCIceCandidate) *> *)candidates;
/** Add a new media stream to be sent on this peer connection. /** Add a new media stream to be sent on this peer connection.
* This method is not supported with RTCSdpSemanticsUnifiedPlan. Please use * This method is not supported with RTCSdpSemanticsUnifiedPlan. Please use
@ -253,8 +267,9 @@ RTC_OBJC_EXPORT
* - A sender already exists for the track. * - A sender already exists for the track.
* - The peer connection is closed. * - The peer connection is closed.
*/ */
- (nullable RTC_OBJC_TYPE(RTCRtpSender) *)addTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track - (nullable RTC_OBJC_TYPE(RTCRtpSender) *)
streamIds:(NSArray<NSString *> *)streamIds; addTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track
streamIds:(NSArray<NSString *> *)streamIds;
/** With PlanB semantics, removes an RTCRtpSender from this peer connection. /** With PlanB semantics, removes an RTCRtpSender from this peer connection.
* *
@ -295,28 +310,32 @@ RTC_OBJC_EXPORT
/** Adds a transceiver with the given kind. Can either be RTCRtpMediaTypeAudio /** Adds a transceiver with the given kind. Can either be RTCRtpMediaTypeAudio
* or RTCRtpMediaTypeVideo. * or RTCRtpMediaTypeVideo.
*/ */
- (nullable RTC_OBJC_TYPE(RTCRtpTransceiver) *)addTransceiverOfType:(RTCRtpMediaType)mediaType; - (nullable RTC_OBJC_TYPE(RTCRtpTransceiver) *)addTransceiverOfType:
(RTCRtpMediaType)mediaType;
- (nullable RTC_OBJC_TYPE(RTCRtpTransceiver) *) - (nullable RTC_OBJC_TYPE(RTCRtpTransceiver) *)
addTransceiverOfType:(RTCRtpMediaType)mediaType addTransceiverOfType:(RTCRtpMediaType)mediaType
init:(RTC_OBJC_TYPE(RTCRtpTransceiverInit) *)init; init:(RTC_OBJC_TYPE(RTCRtpTransceiverInit) *)init;
/** Tells the PeerConnection that ICE should be restarted. This triggers a need /** Tells the PeerConnection that ICE should be restarted. This triggers a need
* for negotiation and subsequent offerForConstraints:completionHandler call will act as if * for negotiation and subsequent offerForConstraints:completionHandler call
* RTCOfferAnswerOptions::ice_restart is true. * will act as if RTCOfferAnswerOptions::ice_restart is true.
*/ */
- (void)restartIce; - (void)restartIce;
/** Generate an SDP offer. */ /** Generate an SDP offer. */
- (void)offerForConstraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints - (void)offerForConstraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
completionHandler:(RTCCreateSessionDescriptionCompletionHandler)completionHandler; completionHandler:
(RTCCreateSessionDescriptionCompletionHandler)completionHandler;
/** Generate an SDP answer. */ /** Generate an SDP answer. */
- (void)answerForConstraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints - (void)answerForConstraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
completionHandler:(RTCCreateSessionDescriptionCompletionHandler)completionHandler; completionHandler:
(RTCCreateSessionDescriptionCompletionHandler)completionHandler;
/** Apply the supplied RTCSessionDescription as the local description. */ /** Apply the supplied RTCSessionDescription as the local description. */
- (void)setLocalDescription:(RTC_OBJC_TYPE(RTCSessionDescription) *)sdp - (void)setLocalDescription:(RTC_OBJC_TYPE(RTCSessionDescription) *)sdp
completionHandler:(RTCSetSessionDescriptionCompletionHandler)completionHandler; completionHandler:
(RTCSetSessionDescriptionCompletionHandler)completionHandler;
/** Creates an offer or answer (depending on current signaling state) and sets /** Creates an offer or answer (depending on current signaling state) and sets
* it as the local session description. */ * it as the local session description. */
@ -325,7 +344,8 @@ RTC_OBJC_EXPORT
/** Apply the supplied RTCSessionDescription as the remote description. */ /** Apply the supplied RTCSessionDescription as the remote description. */
- (void)setRemoteDescription:(RTC_OBJC_TYPE(RTCSessionDescription) *)sdp - (void)setRemoteDescription:(RTC_OBJC_TYPE(RTCSessionDescription) *)sdp
completionHandler:(RTCSetSessionDescriptionCompletionHandler)completionHandler; completionHandler:
(RTCSetSessionDescriptionCompletionHandler)completionHandler;
/** Limits the bandwidth allocated for all RTP streams sent by this /** Limits the bandwidth allocated for all RTP streams sent by this
* PeerConnection. Nil parameters will be unchanged. Setting * PeerConnection. Nil parameters will be unchanged. Setting
@ -337,7 +357,8 @@ RTC_OBJC_EXPORT
maxBitrateBps:(nullable NSNumber *)maxBitrateBps; maxBitrateBps:(nullable NSNumber *)maxBitrateBps;
/** Start or stop recording an Rtc EventLog. */ /** Start or stop recording an Rtc EventLog. */
- (BOOL)startRtcEventLogWithFilePath:(NSString *)filePath maxSizeInBytes:(int64_t)maxSizeInBytes; - (BOOL)startRtcEventLogWithFilePath:(NSString *)filePath
maxSizeInBytes:(int64_t)maxSizeInBytes;
- (void)stopRtcEventLog; - (void)stopRtcEventLog;
@end @end
@ -360,25 +381,29 @@ RTC_OBJC_EXPORT
/** Create a new data channel with the given label and configuration. */ /** Create a new data channel with the given label and configuration. */
- (nullable RTC_OBJC_TYPE(RTCDataChannel) *)dataChannelForLabel - (nullable RTC_OBJC_TYPE(RTCDataChannel) *)dataChannelForLabel
: (NSString *)label configuration : (RTC_OBJC_TYPE(RTCDataChannelConfiguration) *)configuration; : (NSString *)label configuration
: (RTC_OBJC_TYPE(RTCDataChannelConfiguration) *)configuration;
@end @end
typedef void (^RTCStatisticsCompletionHandler)(RTC_OBJC_TYPE(RTCStatisticsReport) *); typedef void (^RTCStatisticsCompletionHandler)(
RTC_OBJC_TYPE(RTCStatisticsReport) *);
@interface RTC_OBJC_TYPE (RTCPeerConnection) @interface RTC_OBJC_TYPE (RTCPeerConnection)
(Stats) (Stats)
/** Gather stats for the given RTCMediaStreamTrack. If `mediaStreamTrack` is nil /** Gather stats for the given RTCMediaStreamTrack. If `mediaStreamTrack` is
* statistics are gathered for all tracks. * nil statistics are gathered for all tracks.
*/ */
- (void)statsForTrack - (void)statsForTrack : (nullable RTC_OBJC_TYPE(RTCMediaStreamTrack) *)
: (nullable RTC_OBJC_TYPE(RTCMediaStreamTrack) *)mediaStreamTrack statsOutputLevel mediaStreamTrack statsOutputLevel
: (RTCStatsOutputLevel)statsOutputLevel completionHandler : (RTCStatsOutputLevel)statsOutputLevel completionHandler
: (nullable void (^)(NSArray<RTC_OBJC_TYPE(RTCLegacyStatsReport) *> *stats))completionHandler; : (nullable void (^)(NSArray<RTC_OBJC_TYPE(RTCLegacyStatsReport) *> *stats))
completionHandler;
/** Gather statistic through the v2 statistics API. */ /** Gather statistic through the v2 statistics API. */
- (void)statisticsWithCompletionHandler:(RTCStatisticsCompletionHandler)completionHandler; - (void)statisticsWithCompletionHandler:
(RTCStatisticsCompletionHandler)completionHandler;
/** Spec-compliant getStats() performing the stats selection algorithm with the /** Spec-compliant getStats() performing the stats selection algorithm with the
* sender. * sender.

View File

@ -36,15 +36,18 @@
#include "rtc_base/numerics/safe_conversions.h" #include "rtc_base/numerics/safe_conversions.h"
#include "sdk/objc/native/api/ssl_certificate_verifier.h" #include "sdk/objc/native/api/ssl_certificate_verifier.h"
NSString *const kRTCPeerConnectionErrorDomain = @"org.webrtc.RTC_OBJC_TYPE(RTCPeerConnection)"; NSString *const kRTCPeerConnectionErrorDomain =
@"org.webrtc.RTC_OBJC_TYPE(RTCPeerConnection)";
int const kRTCPeerConnnectionSessionDescriptionError = -1; int const kRTCPeerConnnectionSessionDescriptionError = -1;
namespace { namespace {
class SetSessionDescriptionObserver : public webrtc::SetLocalDescriptionObserverInterface, class SetSessionDescriptionObserver
public webrtc::SetRemoteDescriptionObserverInterface { : public webrtc::SetLocalDescriptionObserverInterface,
public webrtc::SetRemoteDescriptionObserverInterface {
public: public:
SetSessionDescriptionObserver(RTCSetSessionDescriptionCompletionHandler completionHandler) { SetSessionDescriptionObserver(
RTCSetSessionDescriptionCompletionHandler completionHandler) {
completion_handler_ = completionHandler; completion_handler_ = completionHandler;
} }
@ -64,9 +67,10 @@ class SetSessionDescriptionObserver : public webrtc::SetLocalDescriptionObserver
} else { } else {
// TODO(hta): Add handling of error.type() // TODO(hta): Add handling of error.type()
NSString *str = [NSString stringForStdString:error.message()]; NSString *str = [NSString stringForStdString:error.message()];
NSError *err = [NSError errorWithDomain:kRTCPeerConnectionErrorDomain NSError *err =
code:kRTCPeerConnnectionSessionDescriptionError [NSError errorWithDomain:kRTCPeerConnectionErrorDomain
userInfo:@{NSLocalizedDescriptionKey : str}]; code:kRTCPeerConnnectionSessionDescriptionError
userInfo:@{NSLocalizedDescriptionKey : str}];
completion_handler_(err); completion_handler_(err);
} }
completion_handler_ = nil; completion_handler_ = nil;
@ -82,18 +86,22 @@ class CreateSessionDescriptionObserverAdapter
: public CreateSessionDescriptionObserver { : public CreateSessionDescriptionObserver {
public: public:
CreateSessionDescriptionObserverAdapter(void (^completionHandler)( CreateSessionDescriptionObserverAdapter(void (^completionHandler)(
RTC_OBJC_TYPE(RTCSessionDescription) * sessionDescription, NSError *error)) { RTC_OBJC_TYPE(RTCSessionDescription) * sessionDescription,
NSError *error)) {
completion_handler_ = completionHandler; completion_handler_ = completionHandler;
} }
~CreateSessionDescriptionObserverAdapter() override { completion_handler_ = nil; } ~CreateSessionDescriptionObserverAdapter() override {
completion_handler_ = nil;
}
void OnSuccess(SessionDescriptionInterface *desc) override { void OnSuccess(SessionDescriptionInterface *desc) override {
RTC_DCHECK(completion_handler_); RTC_DCHECK(completion_handler_);
std::unique_ptr<webrtc::SessionDescriptionInterface> description = std::unique_ptr<webrtc::SessionDescriptionInterface> description =
std::unique_ptr<webrtc::SessionDescriptionInterface>(desc); std::unique_ptr<webrtc::SessionDescriptionInterface>(desc);
RTC_OBJC_TYPE(RTCSessionDescription) *session = RTC_OBJC_TYPE(RTCSessionDescription) *session =
[[RTC_OBJC_TYPE(RTCSessionDescription) alloc] initWithNativeDescription:description.get()]; [[RTC_OBJC_TYPE(RTCSessionDescription) alloc]
initWithNativeDescription:description.get()];
completion_handler_(session, nil); completion_handler_(session, nil);
completion_handler_ = nil; completion_handler_ = nil;
} }
@ -102,21 +110,22 @@ class CreateSessionDescriptionObserverAdapter
RTC_DCHECK(completion_handler_); RTC_DCHECK(completion_handler_);
// TODO(hta): Add handling of error.type() // TODO(hta): Add handling of error.type()
NSString *str = [NSString stringForStdString:error.message()]; NSString *str = [NSString stringForStdString:error.message()];
NSError* err = NSError *err =
[NSError errorWithDomain:kRTCPeerConnectionErrorDomain [NSError errorWithDomain:kRTCPeerConnectionErrorDomain
code:kRTCPeerConnnectionSessionDescriptionError code:kRTCPeerConnnectionSessionDescriptionError
userInfo:@{ NSLocalizedDescriptionKey : str }]; userInfo:@{NSLocalizedDescriptionKey : str}];
completion_handler_(nil, err); completion_handler_(nil, err);
completion_handler_ = nil; completion_handler_ = nil;
} }
private: private:
void (^completion_handler_)(RTC_OBJC_TYPE(RTCSessionDescription) * sessionDescription, void (^completion_handler_)(RTC_OBJC_TYPE(RTCSessionDescription) *
sessionDescription,
NSError *error); NSError *error);
}; };
PeerConnectionDelegateAdapter::PeerConnectionDelegateAdapter(RTC_OBJC_TYPE(RTCPeerConnection) * PeerConnectionDelegateAdapter::PeerConnectionDelegateAdapter(
peerConnection) { RTC_OBJC_TYPE(RTCPeerConnection) * peerConnection) {
peer_connection_ = peerConnection; peer_connection_ = peerConnection;
} }
@ -126,8 +135,8 @@ PeerConnectionDelegateAdapter::~PeerConnectionDelegateAdapter() {
void PeerConnectionDelegateAdapter::OnSignalingChange( void PeerConnectionDelegateAdapter::OnSignalingChange(
PeerConnectionInterface::SignalingState new_state) { PeerConnectionInterface::SignalingState new_state) {
RTCSignalingState state = RTCSignalingState state = [[RTC_OBJC_TYPE(RTCPeerConnection) class]
[[RTC_OBJC_TYPE(RTCPeerConnection) class] signalingStateForNativeState:new_state]; signalingStateForNativeState:new_state];
RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_;
[peer_connection.delegate peerConnection:peer_connection [peer_connection.delegate peerConnection:peer_connection
didChangeSignalingState:state]; didChangeSignalingState:state];
@ -136,9 +145,8 @@ void PeerConnectionDelegateAdapter::OnSignalingChange(
void PeerConnectionDelegateAdapter::OnAddStream( void PeerConnectionDelegateAdapter::OnAddStream(
rtc::scoped_refptr<MediaStreamInterface> stream) { rtc::scoped_refptr<MediaStreamInterface> stream) {
RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_;
RTC_OBJC_TYPE(RTCMediaStream) *mediaStream = RTC_OBJC_TYPE(RTCMediaStream) *mediaStream = [[RTC_OBJC_TYPE(RTCMediaStream)
[[RTC_OBJC_TYPE(RTCMediaStream) alloc] initWithFactory:peer_connection.factory alloc] initWithFactory:peer_connection.factory nativeMediaStream:stream];
nativeMediaStream:stream];
[peer_connection.delegate peerConnection:peer_connection [peer_connection.delegate peerConnection:peer_connection
didAddStream:mediaStream]; didAddStream:mediaStream];
} }
@ -146,9 +154,8 @@ void PeerConnectionDelegateAdapter::OnAddStream(
void PeerConnectionDelegateAdapter::OnRemoveStream( void PeerConnectionDelegateAdapter::OnRemoveStream(
rtc::scoped_refptr<MediaStreamInterface> stream) { rtc::scoped_refptr<MediaStreamInterface> stream) {
RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_;
RTC_OBJC_TYPE(RTCMediaStream) *mediaStream = RTC_OBJC_TYPE(RTCMediaStream) *mediaStream = [[RTC_OBJC_TYPE(RTCMediaStream)
[[RTC_OBJC_TYPE(RTCMediaStream) alloc] initWithFactory:peer_connection.factory alloc] initWithFactory:peer_connection.factory nativeMediaStream:stream];
nativeMediaStream:stream];
[peer_connection.delegate peerConnection:peer_connection [peer_connection.delegate peerConnection:peer_connection
didRemoveStream:mediaStream]; didRemoveStream:mediaStream];
@ -158,10 +165,12 @@ void PeerConnectionDelegateAdapter::OnTrack(
rtc::scoped_refptr<RtpTransceiverInterface> nativeTransceiver) { rtc::scoped_refptr<RtpTransceiverInterface> nativeTransceiver) {
RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_;
RTC_OBJC_TYPE(RTCRtpTransceiver) *transceiver = RTC_OBJC_TYPE(RTCRtpTransceiver) *transceiver =
[[RTC_OBJC_TYPE(RTCRtpTransceiver) alloc] initWithFactory:peer_connection.factory [[RTC_OBJC_TYPE(RTCRtpTransceiver) alloc]
nativeRtpTransceiver:nativeTransceiver]; initWithFactory:peer_connection.factory
nativeRtpTransceiver:nativeTransceiver];
if ([peer_connection.delegate if ([peer_connection.delegate
respondsToSelector:@selector(peerConnection:didStartReceivingOnTransceiver:)]) { respondsToSelector:@selector(peerConnection:
didStartReceivingOnTransceiver:)]) {
[peer_connection.delegate peerConnection:peer_connection [peer_connection.delegate peerConnection:peer_connection
didStartReceivingOnTransceiver:transceiver]; didStartReceivingOnTransceiver:transceiver];
} }
@ -170,9 +179,9 @@ void PeerConnectionDelegateAdapter::OnTrack(
void PeerConnectionDelegateAdapter::OnDataChannel( void PeerConnectionDelegateAdapter::OnDataChannel(
rtc::scoped_refptr<DataChannelInterface> data_channel) { rtc::scoped_refptr<DataChannelInterface> data_channel) {
RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_;
RTC_OBJC_TYPE(RTCDataChannel) *dataChannel = RTC_OBJC_TYPE(RTCDataChannel) *dataChannel = [[RTC_OBJC_TYPE(RTCDataChannel)
[[RTC_OBJC_TYPE(RTCDataChannel) alloc] initWithFactory:peer_connection.factory alloc] initWithFactory:peer_connection.factory
nativeDataChannel:data_channel]; nativeDataChannel:data_channel];
[peer_connection.delegate peerConnection:peer_connection [peer_connection.delegate peerConnection:peer_connection
didOpenDataChannel:dataChannel]; didOpenDataChannel:dataChannel];
} }
@ -184,17 +193,19 @@ void PeerConnectionDelegateAdapter::OnRenegotiationNeeded() {
void PeerConnectionDelegateAdapter::OnIceConnectionChange( void PeerConnectionDelegateAdapter::OnIceConnectionChange(
PeerConnectionInterface::IceConnectionState new_state) { PeerConnectionInterface::IceConnectionState new_state) {
RTCIceConnectionState state = RTCIceConnectionState state = [RTC_OBJC_TYPE(RTCPeerConnection)
[RTC_OBJC_TYPE(RTCPeerConnection) iceConnectionStateForNativeState:new_state]; iceConnectionStateForNativeState:new_state];
[peer_connection_.delegate peerConnection:peer_connection_ didChangeIceConnectionState:state]; [peer_connection_.delegate peerConnection:peer_connection_
didChangeIceConnectionState:state];
} }
void PeerConnectionDelegateAdapter::OnStandardizedIceConnectionChange( void PeerConnectionDelegateAdapter::OnStandardizedIceConnectionChange(
PeerConnectionInterface::IceConnectionState new_state) { PeerConnectionInterface::IceConnectionState new_state) {
if ([peer_connection_.delegate if ([peer_connection_.delegate
respondsToSelector:@selector(peerConnection:didChangeStandardizedIceConnectionState:)]) { respondsToSelector:@selector(peerConnection:
RTCIceConnectionState state = didChangeStandardizedIceConnectionState:)]) {
[RTC_OBJC_TYPE(RTCPeerConnection) iceConnectionStateForNativeState:new_state]; RTCIceConnectionState state = [RTC_OBJC_TYPE(RTCPeerConnection)
iceConnectionStateForNativeState:new_state];
[peer_connection_.delegate peerConnection:peer_connection_ [peer_connection_.delegate peerConnection:peer_connection_
didChangeStandardizedIceConnectionState:state]; didChangeStandardizedIceConnectionState:state];
} }
@ -202,18 +213,19 @@ void PeerConnectionDelegateAdapter::OnStandardizedIceConnectionChange(
void PeerConnectionDelegateAdapter::OnConnectionChange( void PeerConnectionDelegateAdapter::OnConnectionChange(
PeerConnectionInterface::PeerConnectionState new_state) { PeerConnectionInterface::PeerConnectionState new_state) {
if ([peer_connection_.delegate if ([peer_connection_.delegate respondsToSelector:@selector
respondsToSelector:@selector(peerConnection:didChangeConnectionState:)]) { (peerConnection:didChangeConnectionState:)]) {
RTCPeerConnectionState state = RTCPeerConnectionState state = [RTC_OBJC_TYPE(RTCPeerConnection)
[RTC_OBJC_TYPE(RTCPeerConnection) connectionStateForNativeState:new_state]; connectionStateForNativeState:new_state];
[peer_connection_.delegate peerConnection:peer_connection_ didChangeConnectionState:state]; [peer_connection_.delegate peerConnection:peer_connection_
didChangeConnectionState:state];
} }
} }
void PeerConnectionDelegateAdapter::OnIceGatheringChange( void PeerConnectionDelegateAdapter::OnIceGatheringChange(
PeerConnectionInterface::IceGatheringState new_state) { PeerConnectionInterface::IceGatheringState new_state) {
RTCIceGatheringState state = RTCIceGatheringState state = [[RTC_OBJC_TYPE(RTCPeerConnection) class]
[[RTC_OBJC_TYPE(RTCPeerConnection) class] iceGatheringStateForNativeState:new_state]; iceGatheringStateForNativeState:new_state];
RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_;
[peer_connection.delegate peerConnection:peer_connection [peer_connection.delegate peerConnection:peer_connection
didChangeIceGatheringState:state]; didChangeIceGatheringState:state];
@ -222,38 +234,45 @@ void PeerConnectionDelegateAdapter::OnIceGatheringChange(
void PeerConnectionDelegateAdapter::OnIceCandidate( void PeerConnectionDelegateAdapter::OnIceCandidate(
const IceCandidateInterface *candidate) { const IceCandidateInterface *candidate) {
RTC_OBJC_TYPE(RTCIceCandidate) *iceCandidate = RTC_OBJC_TYPE(RTCIceCandidate) *iceCandidate =
[[RTC_OBJC_TYPE(RTCIceCandidate) alloc] initWithNativeCandidate:candidate]; [[RTC_OBJC_TYPE(RTCIceCandidate) alloc]
initWithNativeCandidate:candidate];
RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_;
[peer_connection.delegate peerConnection:peer_connection [peer_connection.delegate peerConnection:peer_connection
didGenerateIceCandidate:iceCandidate]; didGenerateIceCandidate:iceCandidate];
} }
void PeerConnectionDelegateAdapter::OnIceCandidateError(const std::string &address, void PeerConnectionDelegateAdapter::OnIceCandidateError(
int port, const std::string &address,
const std::string &url, int port,
int error_code, const std::string &url,
const std::string &error_text) { int error_code,
const std::string &error_text) {
RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_;
RTC_OBJC_TYPE(RTCIceCandidateErrorEvent) *event = RTC_OBJC_TYPE(RTCIceCandidateErrorEvent) *event =
[[RTC_OBJC_TYPE(RTCIceCandidateErrorEvent) alloc] initWithAddress:address [[RTC_OBJC_TYPE(RTCIceCandidateErrorEvent) alloc]
port:port initWithAddress:address
url:url port:port
errorCode:error_code url:url
errorText:error_text]; errorCode:error_code
if ([peer_connection.delegate respondsToSelector:@selector(peerConnection: errorText:error_text];
didFailToGatherIceCandidate:)]) { if ([peer_connection.delegate
[peer_connection.delegate peerConnection:peer_connection didFailToGatherIceCandidate:event]; respondsToSelector:@selector(peerConnection:
didFailToGatherIceCandidate:)]) {
[peer_connection.delegate peerConnection:peer_connection
didFailToGatherIceCandidate:event];
} }
} }
void PeerConnectionDelegateAdapter::OnIceCandidatesRemoved( void PeerConnectionDelegateAdapter::OnIceCandidatesRemoved(
const std::vector<cricket::Candidate>& candidates) { const std::vector<cricket::Candidate> &candidates) {
NSMutableArray* ice_candidates = NSMutableArray *ice_candidates =
[NSMutableArray arrayWithCapacity:candidates.size()]; [NSMutableArray arrayWithCapacity:candidates.size()];
for (const auto& candidate : candidates) { for (const auto &candidate : candidates) {
JsepIceCandidate candidate_wrapper(candidate.transport_name(), -1, candidate); JsepIceCandidate candidate_wrapper(
candidate.transport_name(), -1, candidate);
RTC_OBJC_TYPE(RTCIceCandidate) *ice_candidate = RTC_OBJC_TYPE(RTCIceCandidate) *ice_candidate =
[[RTC_OBJC_TYPE(RTCIceCandidate) alloc] initWithNativeCandidate:&candidate_wrapper]; [[RTC_OBJC_TYPE(RTCIceCandidate) alloc]
initWithNativeCandidate:&candidate_wrapper];
[ice_candidates addObject:ice_candidate]; [ice_candidates addObject:ice_candidate];
} }
RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_;
@ -265,18 +284,26 @@ void PeerConnectionDelegateAdapter::OnIceSelectedCandidatePairChanged(
const cricket::CandidatePairChangeEvent &event) { const cricket::CandidatePairChangeEvent &event) {
const auto &selected_pair = event.selected_candidate_pair; const auto &selected_pair = event.selected_candidate_pair;
JsepIceCandidate local_candidate_wrapper( JsepIceCandidate local_candidate_wrapper(
selected_pair.local_candidate().transport_name(), -1, selected_pair.local_candidate()); selected_pair.local_candidate().transport_name(),
-1,
selected_pair.local_candidate());
RTC_OBJC_TYPE(RTCIceCandidate) *local_candidate = RTC_OBJC_TYPE(RTCIceCandidate) *local_candidate =
[[RTC_OBJC_TYPE(RTCIceCandidate) alloc] initWithNativeCandidate:&local_candidate_wrapper]; [[RTC_OBJC_TYPE(RTCIceCandidate) alloc]
initWithNativeCandidate:&local_candidate_wrapper];
JsepIceCandidate remote_candidate_wrapper( JsepIceCandidate remote_candidate_wrapper(
selected_pair.remote_candidate().transport_name(), -1, selected_pair.remote_candidate()); selected_pair.remote_candidate().transport_name(),
-1,
selected_pair.remote_candidate());
RTC_OBJC_TYPE(RTCIceCandidate) *remote_candidate = RTC_OBJC_TYPE(RTCIceCandidate) *remote_candidate =
[[RTC_OBJC_TYPE(RTCIceCandidate) alloc] initWithNativeCandidate:&remote_candidate_wrapper]; [[RTC_OBJC_TYPE(RTCIceCandidate) alloc]
initWithNativeCandidate:&remote_candidate_wrapper];
RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_;
NSString *nsstr_reason = [NSString stringForStdString:event.reason]; NSString *nsstr_reason = [NSString stringForStdString:event.reason];
if ([peer_connection.delegate if ([peer_connection.delegate
respondsToSelector:@selector respondsToSelector:@selector
(peerConnection:didChangeLocalCandidate:remoteCandidate:lastReceivedMs:changeReason:)]) { (peerConnection:
didChangeLocalCandidate:remoteCandidate:lastReceivedMs
:changeReason:)]) {
[peer_connection.delegate peerConnection:peer_connection [peer_connection.delegate peerConnection:peer_connection
didChangeLocalCandidate:local_candidate didChangeLocalCandidate:local_candidate
remoteCandidate:remote_candidate remoteCandidate:remote_candidate
@ -289,18 +316,20 @@ void PeerConnectionDelegateAdapter::OnAddTrack(
rtc::scoped_refptr<RtpReceiverInterface> receiver, rtc::scoped_refptr<RtpReceiverInterface> receiver,
const std::vector<rtc::scoped_refptr<MediaStreamInterface>> &streams) { const std::vector<rtc::scoped_refptr<MediaStreamInterface>> &streams) {
RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_;
if ([peer_connection.delegate respondsToSelector:@selector(peerConnection: if ([peer_connection.delegate respondsToSelector:@selector
didAddReceiver:streams:)]) { (peerConnection:didAddReceiver:streams:)]) {
NSMutableArray *mediaStreams = [NSMutableArray arrayWithCapacity:streams.size()]; NSMutableArray *mediaStreams =
[NSMutableArray arrayWithCapacity:streams.size()];
for (const auto &nativeStream : streams) { for (const auto &nativeStream : streams) {
RTC_OBJC_TYPE(RTCMediaStream) *mediaStream = RTC_OBJC_TYPE(RTCMediaStream) *mediaStream =
[[RTC_OBJC_TYPE(RTCMediaStream) alloc] initWithFactory:peer_connection.factory [[RTC_OBJC_TYPE(RTCMediaStream) alloc]
nativeMediaStream:nativeStream]; initWithFactory:peer_connection.factory
nativeMediaStream:nativeStream];
[mediaStreams addObject:mediaStream]; [mediaStreams addObject:mediaStream];
} }
RTC_OBJC_TYPE(RTCRtpReceiver) *rtpReceiver = RTC_OBJC_TYPE(RTCRtpReceiver) *rtpReceiver = [[RTC_OBJC_TYPE(RTCRtpReceiver)
[[RTC_OBJC_TYPE(RTCRtpReceiver) alloc] initWithFactory:peer_connection.factory alloc] initWithFactory:peer_connection.factory
nativeRtpReceiver:receiver]; nativeRtpReceiver:receiver];
[peer_connection.delegate peerConnection:peer_connection [peer_connection.delegate peerConnection:peer_connection
didAddReceiver:rtpReceiver didAddReceiver:rtpReceiver
@ -311,11 +340,13 @@ void PeerConnectionDelegateAdapter::OnAddTrack(
void PeerConnectionDelegateAdapter::OnRemoveTrack( void PeerConnectionDelegateAdapter::OnRemoveTrack(
rtc::scoped_refptr<RtpReceiverInterface> receiver) { rtc::scoped_refptr<RtpReceiverInterface> receiver) {
RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_;
if ([peer_connection.delegate respondsToSelector:@selector(peerConnection:didRemoveReceiver:)]) { if ([peer_connection.delegate
RTC_OBJC_TYPE(RTCRtpReceiver) *rtpReceiver = respondsToSelector:@selector(peerConnection:didRemoveReceiver:)]) {
[[RTC_OBJC_TYPE(RTCRtpReceiver) alloc] initWithFactory:peer_connection.factory RTC_OBJC_TYPE(RTCRtpReceiver) *rtpReceiver = [[RTC_OBJC_TYPE(RTCRtpReceiver)
nativeRtpReceiver:receiver]; alloc] initWithFactory:peer_connection.factory
[peer_connection.delegate peerConnection:peer_connection didRemoveReceiver:rtpReceiver]; nativeRtpReceiver:receiver];
[peer_connection.delegate peerConnection:peer_connection
didRemoveReceiver:rtpReceiver];
} }
} }
@ -333,17 +364,19 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
@synthesize delegate = _delegate; @synthesize delegate = _delegate;
@synthesize factory = _factory; @synthesize factory = _factory;
- (nullable instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (nullable instancetype)
configuration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints configuration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration
certificateVerifier: constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
(nullable id<RTC_OBJC_TYPE(RTCSSLCertificateVerifier)>)certificateVerifier certificateVerifier:(nullable id<RTC_OBJC_TYPE(RTCSSLCertificateVerifier)>)
delegate:(id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate { certificateVerifier
delegate:(id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate {
NSParameterAssert(factory); NSParameterAssert(factory);
std::unique_ptr<webrtc::PeerConnectionDependencies> dependencies = std::unique_ptr<webrtc::PeerConnectionDependencies> dependencies =
std::make_unique<webrtc::PeerConnectionDependencies>(nullptr); std::make_unique<webrtc::PeerConnectionDependencies>(nullptr);
if (certificateVerifier != nil) { if (certificateVerifier != nil) {
dependencies->tls_cert_verifier = webrtc::ObjCToNativeCertificateVerifier(certificateVerifier); dependencies->tls_cert_verifier =
webrtc::ObjCToNativeCertificateVerifier(certificateVerifier);
} }
return [self initWithDependencies:factory return [self initWithDependencies:factory
configuration:configuration configuration:configuration
@ -356,8 +389,10 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
initWithDependencies:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory initWithDependencies:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
configuration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration configuration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration
constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
dependencies:(std::unique_ptr<webrtc::PeerConnectionDependencies>)dependencies dependencies:(std::unique_ptr<webrtc::PeerConnectionDependencies>)
delegate:(id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate { dependencies
delegate:
(id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate {
NSParameterAssert(factory); NSParameterAssert(factory);
NSParameterAssert(dependencies.get()); NSParameterAssert(dependencies.get());
std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config( std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config(
@ -373,7 +408,8 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
webrtc::PeerConnectionDependencies deps = std::move(*dependencies); webrtc::PeerConnectionDependencies deps = std::move(*dependencies);
deps.observer = _observer.get(); deps.observer = _observer.get();
auto result = factory.nativeFactory->CreatePeerConnectionOrError(*config, std::move(deps)); auto result = factory.nativeFactory->CreatePeerConnectionOrError(
*config, std::move(deps));
if (!result.ok()) { if (!result.ok()) {
return nil; return nil;
@ -391,22 +427,26 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
} }
- (RTC_OBJC_TYPE(RTCSessionDescription) *)localDescription { - (RTC_OBJC_TYPE(RTCSessionDescription) *)localDescription {
// It's only safe to operate on SessionDescriptionInterface on the signaling thread. // It's only safe to operate on SessionDescriptionInterface on the signaling
// thread.
return _peerConnection->signaling_thread()->BlockingCall([self] { return _peerConnection->signaling_thread()->BlockingCall([self] {
const webrtc::SessionDescriptionInterface *description = _peerConnection->local_description(); const webrtc::SessionDescriptionInterface *description =
return description ? _peerConnection->local_description();
[[RTC_OBJC_TYPE(RTCSessionDescription) alloc] initWithNativeDescription:description] : return description ? [[RTC_OBJC_TYPE(RTCSessionDescription) alloc]
nil; initWithNativeDescription:description] :
nil;
}); });
} }
- (RTC_OBJC_TYPE(RTCSessionDescription) *)remoteDescription { - (RTC_OBJC_TYPE(RTCSessionDescription) *)remoteDescription {
// It's only safe to operate on SessionDescriptionInterface on the signaling thread. // It's only safe to operate on SessionDescriptionInterface on the signaling
// thread.
return _peerConnection->signaling_thread()->BlockingCall([self] { return _peerConnection->signaling_thread()->BlockingCall([self] {
const webrtc::SessionDescriptionInterface *description = _peerConnection->remote_description(); const webrtc::SessionDescriptionInterface *description =
return description ? _peerConnection->remote_description();
[[RTC_OBJC_TYPE(RTCSessionDescription) alloc] initWithNativeDescription:description] : return description ? [[RTC_OBJC_TYPE(RTCSessionDescription) alloc]
nil; initWithNativeDescription:description] :
nil;
}); });
} }
@ -416,17 +456,18 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
} }
- (RTCIceConnectionState)iceConnectionState { - (RTCIceConnectionState)iceConnectionState {
return [[self class] iceConnectionStateForNativeState: return [[self class]
_peerConnection->ice_connection_state()]; iceConnectionStateForNativeState:_peerConnection->ice_connection_state()];
} }
- (RTCPeerConnectionState)connectionState { - (RTCPeerConnectionState)connectionState {
return [[self class] connectionStateForNativeState:_peerConnection->peer_connection_state()]; return [[self class]
connectionStateForNativeState:_peerConnection->peer_connection_state()];
} }
- (RTCIceGatheringState)iceGatheringState { - (RTCIceGatheringState)iceGatheringState {
return [[self class] iceGatheringStateForNativeState: return [[self class]
_peerConnection->ice_gathering_state()]; iceGatheringStateForNativeState:_peerConnection->ice_gathering_state()];
} }
- (BOOL)setConfiguration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration { - (BOOL)setConfiguration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration {
@ -435,15 +476,15 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
if (!config) { if (!config) {
return NO; return NO;
} }
CopyConstraintsIntoRtcConfiguration(_nativeConstraints.get(), CopyConstraintsIntoRtcConfiguration(_nativeConstraints.get(), config.get());
config.get());
return _peerConnection->SetConfiguration(*config).ok(); return _peerConnection->SetConfiguration(*config).ok();
} }
- (RTC_OBJC_TYPE(RTCConfiguration) *)configuration { - (RTC_OBJC_TYPE(RTCConfiguration) *)configuration {
webrtc::PeerConnectionInterface::RTCConfiguration config = webrtc::PeerConnectionInterface::RTCConfiguration config =
_peerConnection->GetConfiguration(); _peerConnection->GetConfiguration();
return [[RTC_OBJC_TYPE(RTCConfiguration) alloc] initWithNativeConfiguration:config]; return [[RTC_OBJC_TYPE(RTCConfiguration) alloc]
initWithNativeConfiguration:config];
} }
- (void)close { - (void)close {
@ -464,14 +505,16 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
completionHandler(nil); completionHandler(nil);
} else { } else {
NSString *str = [NSString stringForStdString:error.message()]; NSString *str = [NSString stringForStdString:error.message()];
NSError *err = [NSError errorWithDomain:kRTCPeerConnectionErrorDomain NSError *err =
code:static_cast<NSInteger>(error.type()) [NSError errorWithDomain:kRTCPeerConnectionErrorDomain
userInfo:@{NSLocalizedDescriptionKey : str}]; code:static_cast<NSInteger>(error.type())
userInfo:@{NSLocalizedDescriptionKey : str}];
completionHandler(err); completionHandler(err);
} }
}); });
} }
- (void)removeIceCandidates:(NSArray<RTC_OBJC_TYPE(RTCIceCandidate) *> *)iceCandidates { - (void)removeIceCandidates:
(NSArray<RTC_OBJC_TYPE(RTCIceCandidate) *> *)iceCandidates {
std::vector<cricket::Candidate> candidates; std::vector<cricket::Candidate> candidates;
for (RTC_OBJC_TYPE(RTCIceCandidate) * iceCandidate in iceCandidates) { for (RTC_OBJC_TYPE(RTCIceCandidate) * iceCandidate in iceCandidates) {
std::unique_ptr<const webrtc::IceCandidateInterface> candidate( std::unique_ptr<const webrtc::IceCandidateInterface> candidate(
@ -500,24 +543,30 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
[_localStreams removeObject:stream]; [_localStreams removeObject:stream];
} }
- (nullable RTC_OBJC_TYPE(RTCRtpSender) *)addTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track - (nullable RTC_OBJC_TYPE(RTCRtpSender) *)
streamIds:(NSArray<NSString *> *)streamIds { addTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track
streamIds:(NSArray<NSString *> *)streamIds {
std::vector<std::string> nativeStreamIds; std::vector<std::string> nativeStreamIds;
for (NSString *streamId in streamIds) { for (NSString *streamId in streamIds) {
nativeStreamIds.push_back([streamId UTF8String]); nativeStreamIds.push_back([streamId UTF8String]);
} }
webrtc::RTCErrorOr<rtc::scoped_refptr<webrtc::RtpSenderInterface>> nativeSenderOrError = webrtc::RTCErrorOr<rtc::scoped_refptr<webrtc::RtpSenderInterface>>
_peerConnection->AddTrack(track.nativeTrack, nativeStreamIds); nativeSenderOrError =
_peerConnection->AddTrack(track.nativeTrack, nativeStreamIds);
if (!nativeSenderOrError.ok()) { if (!nativeSenderOrError.ok()) {
RTCLogError(@"Failed to add track %@: %s", track, nativeSenderOrError.error().message()); RTCLogError(@"Failed to add track %@: %s",
track,
nativeSenderOrError.error().message());
return nil; return nil;
} }
return [[RTC_OBJC_TYPE(RTCRtpSender) alloc] initWithFactory:self.factory return [[RTC_OBJC_TYPE(RTCRtpSender) alloc]
nativeRtpSender:nativeSenderOrError.MoveValue()]; initWithFactory:self.factory
nativeRtpSender:nativeSenderOrError.MoveValue()];
} }
- (BOOL)removeTrack:(RTC_OBJC_TYPE(RTCRtpSender) *)sender { - (BOOL)removeTrack:(RTC_OBJC_TYPE(RTCRtpSender) *)sender {
bool result = _peerConnection->RemoveTrackOrError(sender.nativeRtpSender).ok(); bool result =
_peerConnection->RemoveTrackOrError(sender.nativeRtpSender).ok();
if (!result) { if (!result) {
RTCLogError(@"Failed to remote track %@", sender); RTCLogError(@"Failed to remote track %@", sender);
} }
@ -527,17 +576,20 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
- (nullable RTC_OBJC_TYPE(RTCRtpTransceiver) *)addTransceiverWithTrack: - (nullable RTC_OBJC_TYPE(RTCRtpTransceiver) *)addTransceiverWithTrack:
(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track { (RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track {
return [self addTransceiverWithTrack:track return [self addTransceiverWithTrack:track
init:[[RTC_OBJC_TYPE(RTCRtpTransceiverInit) alloc] init]]; init:[[RTC_OBJC_TYPE(RTCRtpTransceiverInit)
alloc] init]];
} }
- (nullable RTC_OBJC_TYPE(RTCRtpTransceiver) *) - (nullable RTC_OBJC_TYPE(RTCRtpTransceiver) *)
addTransceiverWithTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track addTransceiverWithTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track
init:(RTC_OBJC_TYPE(RTCRtpTransceiverInit) *)init { init:(RTC_OBJC_TYPE(RTCRtpTransceiverInit) *)init {
webrtc::RTCErrorOr<rtc::scoped_refptr<webrtc::RtpTransceiverInterface>> nativeTransceiverOrError = webrtc::RTCErrorOr<rtc::scoped_refptr<webrtc::RtpTransceiverInterface>>
_peerConnection->AddTransceiver(track.nativeTrack, init.nativeInit); nativeTransceiverOrError =
_peerConnection->AddTransceiver(track.nativeTrack, init.nativeInit);
if (!nativeTransceiverOrError.ok()) { if (!nativeTransceiverOrError.ok()) {
RTCLogError( RTCLogError(@"Failed to add transceiver %@: %s",
@"Failed to add transceiver %@: %s", track, nativeTransceiverOrError.error().message()); track,
nativeTransceiverOrError.error().message());
return nil; return nil;
} }
return [[RTC_OBJC_TYPE(RTCRtpTransceiver) alloc] return [[RTC_OBJC_TYPE(RTCRtpTransceiver) alloc]
@ -545,17 +597,20 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
nativeRtpTransceiver:nativeTransceiverOrError.MoveValue()]; nativeRtpTransceiver:nativeTransceiverOrError.MoveValue()];
} }
- (nullable RTC_OBJC_TYPE(RTCRtpTransceiver) *)addTransceiverOfType:(RTCRtpMediaType)mediaType { - (nullable RTC_OBJC_TYPE(RTCRtpTransceiver) *)addTransceiverOfType:
return [self addTransceiverOfType:mediaType (RTCRtpMediaType)mediaType {
init:[[RTC_OBJC_TYPE(RTCRtpTransceiverInit) alloc] init]]; return [self
addTransceiverOfType:mediaType
init:[[RTC_OBJC_TYPE(RTCRtpTransceiverInit) alloc] init]];
} }
- (nullable RTC_OBJC_TYPE(RTCRtpTransceiver) *) - (nullable RTC_OBJC_TYPE(RTCRtpTransceiver) *)
addTransceiverOfType:(RTCRtpMediaType)mediaType addTransceiverOfType:(RTCRtpMediaType)mediaType
init:(RTC_OBJC_TYPE(RTCRtpTransceiverInit) *)init { init:(RTC_OBJC_TYPE(RTCRtpTransceiverInit) *)init {
webrtc::RTCErrorOr<rtc::scoped_refptr<webrtc::RtpTransceiverInterface>> nativeTransceiverOrError = webrtc::RTCErrorOr<rtc::scoped_refptr<webrtc::RtpTransceiverInterface>>
_peerConnection->AddTransceiver( nativeTransceiverOrError = _peerConnection->AddTransceiver(
[RTC_OBJC_TYPE(RTCRtpReceiver) nativeMediaTypeForMediaType:mediaType], init.nativeInit); [RTC_OBJC_TYPE(RTCRtpReceiver) nativeMediaTypeForMediaType:mediaType],
init.nativeInit);
if (!nativeTransceiverOrError.ok()) { if (!nativeTransceiverOrError.ok()) {
RTCLogError(@"Failed to add transceiver %@: %s", RTCLogError(@"Failed to add transceiver %@: %s",
[RTC_OBJC_TYPE(RTCRtpReceiver) stringForMediaType:mediaType], [RTC_OBJC_TYPE(RTCRtpReceiver) stringForMediaType:mediaType],
@ -572,29 +627,36 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
} }
- (void)offerForConstraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints - (void)offerForConstraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
completionHandler:(RTCCreateSessionDescriptionCompletionHandler)completionHandler { completionHandler:
(RTCCreateSessionDescriptionCompletionHandler)completionHandler {
RTC_DCHECK(completionHandler != nil); RTC_DCHECK(completionHandler != nil);
rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserverAdapter> observer = rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserverAdapter> observer =
rtc::make_ref_counted<webrtc::CreateSessionDescriptionObserverAdapter>(completionHandler); rtc::make_ref_counted<webrtc::CreateSessionDescriptionObserverAdapter>(
completionHandler);
webrtc::PeerConnectionInterface::RTCOfferAnswerOptions options; webrtc::PeerConnectionInterface::RTCOfferAnswerOptions options;
CopyConstraintsIntoOfferAnswerOptions(constraints.nativeConstraints.get(), &options); CopyConstraintsIntoOfferAnswerOptions(constraints.nativeConstraints.get(),
&options);
_peerConnection->CreateOffer(observer.get(), options); _peerConnection->CreateOffer(observer.get(), options);
} }
- (void)answerForConstraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints - (void)answerForConstraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
completionHandler:(RTCCreateSessionDescriptionCompletionHandler)completionHandler { completionHandler:
(RTCCreateSessionDescriptionCompletionHandler)completionHandler {
RTC_DCHECK(completionHandler != nil); RTC_DCHECK(completionHandler != nil);
rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserverAdapter> observer = rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserverAdapter> observer =
rtc::make_ref_counted<webrtc::CreateSessionDescriptionObserverAdapter>(completionHandler); rtc::make_ref_counted<webrtc::CreateSessionDescriptionObserverAdapter>(
completionHandler);
webrtc::PeerConnectionInterface::RTCOfferAnswerOptions options; webrtc::PeerConnectionInterface::RTCOfferAnswerOptions options;
CopyConstraintsIntoOfferAnswerOptions(constraints.nativeConstraints.get(), &options); CopyConstraintsIntoOfferAnswerOptions(constraints.nativeConstraints.get(),
&options);
_peerConnection->CreateAnswer(observer.get(), options); _peerConnection->CreateAnswer(observer.get(), options);
} }
- (void)setLocalDescription:(RTC_OBJC_TYPE(RTCSessionDescription) *)sdp - (void)setLocalDescription:(RTC_OBJC_TYPE(RTCSessionDescription) *)sdp
completionHandler:(RTCSetSessionDescriptionCompletionHandler)completionHandler { completionHandler:
(RTCSetSessionDescriptionCompletionHandler)completionHandler {
RTC_DCHECK(completionHandler != nil); RTC_DCHECK(completionHandler != nil);
rtc::scoped_refptr<webrtc::SetLocalDescriptionObserverInterface> observer = rtc::scoped_refptr<webrtc::SetLocalDescriptionObserverInterface> observer =
rtc::make_ref_counted<::SetSessionDescriptionObserver>(completionHandler); rtc::make_ref_counted<::SetSessionDescriptionObserver>(completionHandler);
@ -610,7 +672,8 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
} }
- (void)setRemoteDescription:(RTC_OBJC_TYPE(RTCSessionDescription) *)sdp - (void)setRemoteDescription:(RTC_OBJC_TYPE(RTCSessionDescription) *)sdp
completionHandler:(RTCSetSessionDescriptionCompletionHandler)completionHandler { completionHandler:
(RTCSetSessionDescriptionCompletionHandler)completionHandler {
RTC_DCHECK(completionHandler != nil); RTC_DCHECK(completionHandler != nil);
rtc::scoped_refptr<webrtc::SetRemoteDescriptionObserverInterface> observer = rtc::scoped_refptr<webrtc::SetRemoteDescriptionObserverInterface> observer =
rtc::make_ref_counted<::SetSessionDescriptionObserver>(completionHandler); rtc::make_ref_counted<::SetSessionDescriptionObserver>(completionHandler);
@ -648,8 +711,9 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
return NO; return NO;
} }
// TODO(eladalon): It would be better to not allow negative values into PC. // TODO(eladalon): It would be better to not allow negative values into PC.
const size_t max_size = (maxSizeInBytes < 0) ? webrtc::RtcEventLog::kUnlimitedOutput : const size_t max_size = (maxSizeInBytes < 0) ?
rtc::saturated_cast<size_t>(maxSizeInBytes); webrtc::RtcEventLog::kUnlimitedOutput :
rtc::saturated_cast<size_t>(maxSizeInBytes);
_hasStartedRtcEventLog = _peerConnection->StartRtcEventLog( _hasStartedRtcEventLog = _peerConnection->StartRtcEventLog(
std::make_unique<webrtc::RtcEventLogOutputFile>(f, max_size)); std::make_unique<webrtc::RtcEventLogOutputFile>(f, max_size));
@ -661,14 +725,16 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
_hasStartedRtcEventLog = NO; _hasStartedRtcEventLog = NO;
} }
- (RTC_OBJC_TYPE(RTCRtpSender) *)senderWithKind:(NSString *)kind streamId:(NSString *)streamId { - (RTC_OBJC_TYPE(RTCRtpSender) *)senderWithKind:(NSString *)kind
streamId:(NSString *)streamId {
std::string nativeKind = [NSString stdStringForString:kind]; std::string nativeKind = [NSString stdStringForString:kind];
std::string nativeStreamId = [NSString stdStringForString:streamId]; std::string nativeStreamId = [NSString stdStringForString:streamId];
rtc::scoped_refptr<webrtc::RtpSenderInterface> nativeSender( rtc::scoped_refptr<webrtc::RtpSenderInterface> nativeSender(
_peerConnection->CreateSender(nativeKind, nativeStreamId)); _peerConnection->CreateSender(nativeKind, nativeStreamId));
return nativeSender ? [[RTC_OBJC_TYPE(RTCRtpSender) alloc] initWithFactory:self.factory return nativeSender ?
nativeRtpSender:nativeSender] : [[RTC_OBJC_TYPE(RTCRtpSender) alloc] initWithFactory:self.factory
nil; nativeRtpSender:nativeSender] :
nil;
} }
- (NSArray<RTC_OBJC_TYPE(RTCRtpSender) *> *)senders { - (NSArray<RTC_OBJC_TYPE(RTCRtpSender) *> *)senders {
@ -698,13 +764,14 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
} }
- (NSArray<RTC_OBJC_TYPE(RTCRtpTransceiver) *> *)transceivers { - (NSArray<RTC_OBJC_TYPE(RTCRtpTransceiver) *> *)transceivers {
std::vector<rtc::scoped_refptr<webrtc::RtpTransceiverInterface>> nativeTransceivers( std::vector<rtc::scoped_refptr<webrtc::RtpTransceiverInterface>>
_peerConnection->GetTransceivers()); nativeTransceivers(_peerConnection->GetTransceivers());
NSMutableArray *transceivers = [[NSMutableArray alloc] init]; NSMutableArray *transceivers = [[NSMutableArray alloc] init];
for (const auto &nativeTransceiver : nativeTransceivers) { for (const auto &nativeTransceiver : nativeTransceivers) {
RTC_OBJC_TYPE(RTCRtpTransceiver) *transceiver = RTC_OBJC_TYPE(RTCRtpTransceiver) *transceiver =
[[RTC_OBJC_TYPE(RTCRtpTransceiver) alloc] initWithFactory:self.factory [[RTC_OBJC_TYPE(RTCRtpTransceiver) alloc]
nativeRtpTransceiver:nativeTransceiver]; initWithFactory:self.factory
nativeRtpTransceiver:nativeTransceiver];
[transceivers addObject:transceiver]; [transceivers addObject:transceiver];
} }
return transceivers; return transceivers;
@ -765,8 +832,8 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
} }
} }
+ (webrtc::PeerConnectionInterface::PeerConnectionState)nativeConnectionStateForState: + (webrtc::PeerConnectionInterface::PeerConnectionState)
(RTCPeerConnectionState)state { nativeConnectionStateForState:(RTCPeerConnectionState)state {
switch (state) { switch (state) {
case RTCPeerConnectionStateNew: case RTCPeerConnectionStateNew:
return webrtc::PeerConnectionInterface::PeerConnectionState::kNew; return webrtc::PeerConnectionInterface::PeerConnectionState::kNew;
@ -777,14 +844,15 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
case RTCPeerConnectionStateFailed: case RTCPeerConnectionStateFailed:
return webrtc::PeerConnectionInterface::PeerConnectionState::kFailed; return webrtc::PeerConnectionInterface::PeerConnectionState::kFailed;
case RTCPeerConnectionStateDisconnected: case RTCPeerConnectionStateDisconnected:
return webrtc::PeerConnectionInterface::PeerConnectionState::kDisconnected; return webrtc::PeerConnectionInterface::PeerConnectionState::
kDisconnected;
case RTCPeerConnectionStateClosed: case RTCPeerConnectionStateClosed:
return webrtc::PeerConnectionInterface::PeerConnectionState::kClosed; return webrtc::PeerConnectionInterface::PeerConnectionState::kClosed;
} }
} }
+ (RTCPeerConnectionState)connectionStateForNativeState: + (RTCPeerConnectionState)connectionStateForNativeState:
(webrtc::PeerConnectionInterface::PeerConnectionState)nativeState { (webrtc::PeerConnectionInterface::PeerConnectionState)nativeState {
switch (nativeState) { switch (nativeState) {
case webrtc::PeerConnectionInterface::PeerConnectionState::kNew: case webrtc::PeerConnectionInterface::PeerConnectionState::kNew:
return RTCPeerConnectionStateNew; return RTCPeerConnectionStateNew;

View File

@ -23,59 +23,79 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
/** /**
* This class extension exposes methods that work directly with injectable C++ components. * This class extension exposes methods that work directly with injectable C++
* components.
*/ */
@interface RTC_OBJC_TYPE (RTCPeerConnectionFactory) @interface RTC_OBJC_TYPE (RTCPeerConnectionFactory)
() ()
/* Initializer used when WebRTC is compiled with no media support */ /* Initializer used when WebRTC is compiled with no media support */
- (instancetype)initWithNoMedia; - (instancetype)initWithNoMedia;
/* Initialize object with provided dependencies and with media support. */ /* Initialize object with provided dependencies and with media support. */
- (instancetype)initWithMediaAndDependencies: - (instancetype)initWithMediaAndDependencies:
(webrtc::PeerConnectionFactoryDependencies)dependencies; (webrtc::PeerConnectionFactoryDependencies)dependencies;
/* Initialize object with injectable native audio/video encoder/decoder factories */ /* Initialize object with injectable native audio/video encoder/decoder
- (instancetype)initWithNativeAudioEncoderFactory: * factories */
(rtc::scoped_refptr<webrtc::AudioEncoderFactory>)audioEncoderFactory - (instancetype)
nativeAudioDecoderFactory: initWithNativeAudioEncoderFactory:
(rtc::scoped_refptr<webrtc::AudioDecoderFactory>)audioDecoderFactory (rtc::scoped_refptr<webrtc::AudioEncoderFactory>)audioEncoderFactory
nativeVideoEncoderFactory: nativeAudioDecoderFactory:
(std::unique_ptr<webrtc::VideoEncoderFactory>)videoEncoderFactory (rtc::scoped_refptr<webrtc::AudioDecoderFactory>)
nativeVideoDecoderFactory: audioDecoderFactory
(std::unique_ptr<webrtc::VideoDecoderFactory>)videoDecoderFactory nativeVideoEncoderFactory:
audioDeviceModule: (std::unique_ptr<webrtc::VideoEncoderFactory>)
(nullable webrtc::AudioDeviceModule *)audioDeviceModule videoEncoderFactory
audioProcessingModule: nativeVideoDecoderFactory:
(rtc::scoped_refptr<webrtc::AudioProcessing>)audioProcessingModule; (std::unique_ptr<webrtc::VideoDecoderFactory>)
videoDecoderFactory
audioDeviceModule:
(nullable webrtc::AudioDeviceModule *)audioDeviceModule
audioProcessingModule:
(rtc::scoped_refptr<webrtc::AudioProcessing>)
audioProcessingModule;
- (instancetype) - (instancetype)
initWithNativeAudioEncoderFactory: initWithNativeAudioEncoderFactory:
(rtc::scoped_refptr<webrtc::AudioEncoderFactory>)audioEncoderFactory (rtc::scoped_refptr<webrtc::AudioEncoderFactory>)audioEncoderFactory
nativeAudioDecoderFactory: nativeAudioDecoderFactory:
(rtc::scoped_refptr<webrtc::AudioDecoderFactory>)audioDecoderFactory (rtc::scoped_refptr<webrtc::AudioDecoderFactory>)
audioDecoderFactory
nativeVideoEncoderFactory: nativeVideoEncoderFactory:
(std::unique_ptr<webrtc::VideoEncoderFactory>)videoEncoderFactory (std::unique_ptr<webrtc::VideoEncoderFactory>)
videoEncoderFactory
nativeVideoDecoderFactory: nativeVideoDecoderFactory:
(std::unique_ptr<webrtc::VideoDecoderFactory>)videoDecoderFactory (std::unique_ptr<webrtc::VideoDecoderFactory>)
audioDeviceModule:(nullable webrtc::AudioDeviceModule *)audioDeviceModule videoDecoderFactory
audioDeviceModule:
(nullable webrtc::AudioDeviceModule *)audioDeviceModule
audioProcessingModule: audioProcessingModule:
(rtc::scoped_refptr<webrtc::AudioProcessing>)audioProcessingModule (rtc::scoped_refptr<webrtc::AudioProcessing>)
networkControllerFactory:(std::unique_ptr<webrtc::NetworkControllerFactoryInterface>) audioProcessingModule
networkControllerFactory; networkControllerFactory:
(std::unique_ptr<webrtc::NetworkControllerFactoryInterface>)
networkControllerFactory;
- (instancetype) - (instancetype)
initWithEncoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory initWithEncoderFactory:
decoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)>)decoderFactory; (nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory
decoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)>)
decoderFactory;
/** Initialize an RTCPeerConnection with a configuration, constraints, and /** Initialize an RTCPeerConnection with a configuration, constraints, and
* dependencies. * dependencies.
*/ */
- (nullable RTC_OBJC_TYPE(RTCPeerConnection) *) - (nullable RTC_OBJC_TYPE(RTCPeerConnection) *)
peerConnectionWithDependencies:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration peerConnectionWithDependencies:
constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints (RTC_OBJC_TYPE(RTCConfiguration) *)configuration
dependencies:(std::unique_ptr<webrtc::PeerConnectionDependencies>)dependencies constraints:
delegate:(nullable id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate; (RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
dependencies:
(std::unique_ptr<webrtc::PeerConnectionDependencies>)
dependencies
delegate:(nullable id<RTC_OBJC_TYPE(
RTCPeerConnectionDelegate)>)delegate;
@end @end

View File

@ -24,8 +24,8 @@ NS_ASSUME_NONNULL_BEGIN
* RTCPeerConnectionFactory object. This is needed to pass to the underlying * RTCPeerConnectionFactory object. This is needed to pass to the underlying
* C++ APIs. * C++ APIs.
*/ */
@property(nonatomic, @property(nonatomic, readonly) rtc::scoped_refptr<
readonly) rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> nativeFactory; webrtc::PeerConnectionFactoryInterface> nativeFactory;
@property(nonatomic, readonly) rtc::Thread* signalingThread; @property(nonatomic, readonly) rtc::Thread* signalingThread;
@property(nonatomic, readonly) rtc::Thread* workerThread; @property(nonatomic, readonly) rtc::Thread* workerThread;

View File

@ -41,40 +41,50 @@ RTC_OBJC_EXPORT
/* Initialize object with default H264 video encoder/decoder factories and default ADM */ /* Initialize object with default H264 video encoder/decoder factories and default ADM */
- (instancetype)init; - (instancetype)init;
/* Initialize object with injectable video encoder/decoder factories and default ADM */ /* Initialize object with injectable video encoder/decoder factories and default
* ADM */
- (instancetype) - (instancetype)
initWithEncoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory initWithEncoderFactory:
decoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)>)decoderFactory; (nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory
decoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)>)
decoderFactory;
/* Initialize object with injectable video encoder/decoder factories and injectable ADM */ /* Initialize object with injectable video encoder/decoder factories and
* injectable ADM */
- (instancetype) - (instancetype)
initWithEncoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory initWithEncoderFactory:
decoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)>)decoderFactory (nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory
audioDevice:(nullable id<RTC_OBJC_TYPE(RTCAudioDevice)>)audioDevice; decoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)>)
decoderFactory
audioDevice:
(nullable id<RTC_OBJC_TYPE(RTCAudioDevice)>)audioDevice;
/** /**
* Valid kind values are kRTCMediaStreamTrackKindAudio and * Valid kind values are kRTCMediaStreamTrackKindAudio and
* kRTCMediaStreamTrackKindVideo. * kRTCMediaStreamTrackKindVideo.
*/ */
- (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpSenderCapabilitiesForKind:(NSString *)kind; - (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpSenderCapabilitiesForKind:
(NSString *)kind;
/** /**
* Valid kind values are kRTCMediaStreamTrackKindAudio and * Valid kind values are kRTCMediaStreamTrackKindAudio and
* kRTCMediaStreamTrackKindVideo. * kRTCMediaStreamTrackKindVideo.
*/ */
- (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpReceiverCapabilitiesForKind:(NSString *)kind; - (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpReceiverCapabilitiesForKind:
(NSString *)kind;
/** Initialize an RTCAudioSource with constraints. */ /** Initialize an RTCAudioSource with constraints. */
- (RTC_OBJC_TYPE(RTCAudioSource) *)audioSourceWithConstraints: - (RTC_OBJC_TYPE(RTCAudioSource) *)audioSourceWithConstraints:
(nullable RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints; (nullable RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints;
/** Initialize an RTCAudioTrack with an id. Convenience ctor to use an audio source /** Initialize an RTCAudioTrack with an id. Convenience ctor to use an audio
* with no constraints. * source with no constraints.
*/ */
- (RTC_OBJC_TYPE(RTCAudioTrack) *)audioTrackWithTrackId:(NSString *)trackId; - (RTC_OBJC_TYPE(RTCAudioTrack) *)audioTrackWithTrackId:(NSString *)trackId;
/** Initialize an RTCAudioTrack with a source and an id. */ /** Initialize an RTCAudioTrack with a source and an id. */
- (RTC_OBJC_TYPE(RTCAudioTrack) *)audioTrackWithSource:(RTC_OBJC_TYPE(RTCAudioSource) *)source - (RTC_OBJC_TYPE(RTCAudioTrack) *)audioTrackWithSource:
(RTC_OBJC_TYPE(RTCAudioSource) *)source
trackId:(NSString *)trackId; trackId:(NSString *)trackId;
/** Initialize a generic RTCVideoSource. The RTCVideoSource should be /** Initialize a generic RTCVideoSource. The RTCVideoSource should be
@ -91,7 +101,8 @@ RTC_OBJC_EXPORT
- (RTC_OBJC_TYPE(RTCVideoSource) *)videoSourceForScreenCast:(BOOL)forScreenCast; - (RTC_OBJC_TYPE(RTCVideoSource) *)videoSourceForScreenCast:(BOOL)forScreenCast;
/** Initialize an RTCVideoTrack with a source and an id. */ /** Initialize an RTCVideoTrack with a source and an id. */
- (RTC_OBJC_TYPE(RTCVideoTrack) *)videoTrackWithSource:(RTC_OBJC_TYPE(RTCVideoSource) *)source - (RTC_OBJC_TYPE(RTCVideoTrack) *)videoTrackWithSource:
(RTC_OBJC_TYPE(RTCVideoSource) *)source
trackId:(NSString *)trackId; trackId:(NSString *)trackId;
/** Initialize an RTCMediaStream with an id. */ /** Initialize an RTCMediaStream with an id. */
@ -101,22 +112,32 @@ RTC_OBJC_EXPORT
* delegate. * delegate.
*/ */
- (nullable RTC_OBJC_TYPE(RTCPeerConnection) *) - (nullable RTC_OBJC_TYPE(RTCPeerConnection) *)
peerConnectionWithConfiguration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration peerConnectionWithConfiguration:
constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints (RTC_OBJC_TYPE(RTCConfiguration) *)configuration
delegate:(nullable id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate; constraints:
(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
delegate:(nullable id<RTC_OBJC_TYPE(
RTCPeerConnectionDelegate)>)delegate;
- (nullable RTC_OBJC_TYPE(RTCPeerConnection) *) - (nullable RTC_OBJC_TYPE(RTCPeerConnection) *)
peerConnectionWithConfiguration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration peerConnectionWithConfiguration:
constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints (RTC_OBJC_TYPE(RTCConfiguration) *)configuration
constraints:
(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
certificateVerifier: certificateVerifier:
(id<RTC_OBJC_TYPE(RTCSSLCertificateVerifier)>)certificateVerifier (id<RTC_OBJC_TYPE(RTCSSLCertificateVerifier)>)
delegate:(nullable id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate; certificateVerifier
delegate:(nullable id<RTC_OBJC_TYPE(
RTCPeerConnectionDelegate)>)delegate;
/** Set the options to be used for subsequently created RTCPeerConnections */ /** Set the options to be used for subsequently created RTCPeerConnections */
- (void)setOptions:(nonnull RTC_OBJC_TYPE(RTCPeerConnectionFactoryOptions) *)options; - (void)setOptions:
(nonnull RTC_OBJC_TYPE(RTCPeerConnectionFactoryOptions) *)options;
/** Start an AecDump recording. This API call will likely change in the future. */ /** Start an AecDump recording. This API call will likely change in the future.
- (BOOL)startAecDumpWithFilePath:(NSString *)filePath maxSizeInBytes:(int64_t)maxSizeInBytes; */
- (BOOL)startAecDumpWithFilePath:(NSString *)filePath
maxSizeInBytes:(int64_t)maxSizeInBytes;
/* Stop an active AecDump recording */ /* Stop an active AecDump recording */
- (void)stopAecDump; - (void)stopAecDump;

View File

@ -72,8 +72,10 @@
- (instancetype)init { - (instancetype)init {
webrtc::PeerConnectionFactoryDependencies dependencies; webrtc::PeerConnectionFactoryDependencies dependencies;
dependencies.audio_encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory(); dependencies.audio_encoder_factory =
dependencies.audio_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory(); webrtc::CreateBuiltinAudioEncoderFactory();
dependencies.audio_decoder_factory =
webrtc::CreateBuiltinAudioDecoderFactory();
dependencies.video_encoder_factory = webrtc::ObjCToNativeVideoEncoderFactory( dependencies.video_encoder_factory = webrtc::ObjCToNativeVideoEncoderFactory(
[[RTC_OBJC_TYPE(RTCVideoEncoderFactoryH264) alloc] init]); [[RTC_OBJC_TYPE(RTCVideoEncoderFactoryH264) alloc] init]);
dependencies.video_decoder_factory = webrtc::ObjCToNativeVideoDecoderFactory( dependencies.video_decoder_factory = webrtc::ObjCToNativeVideoDecoderFactory(
@ -83,26 +85,37 @@
} }
- (instancetype) - (instancetype)
initWithEncoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory initWithEncoderFactory:
decoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)>)decoderFactory { (nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory
return [self initWithEncoderFactory:encoderFactory decoderFactory:decoderFactory audioDevice:nil]; decoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)>)
decoderFactory {
return [self initWithEncoderFactory:encoderFactory
decoderFactory:decoderFactory
audioDevice:nil];
} }
- (instancetype) - (instancetype)
initWithEncoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory initWithEncoderFactory:
decoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)>)decoderFactory (nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory
audioDevice:(nullable id<RTC_OBJC_TYPE(RTCAudioDevice)>)audioDevice { decoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)>)
decoderFactory
audioDevice:
(nullable id<RTC_OBJC_TYPE(RTCAudioDevice)>)audioDevice {
#ifdef HAVE_NO_MEDIA #ifdef HAVE_NO_MEDIA
return [self initWithNoMedia]; return [self initWithNoMedia];
#else #else
webrtc::PeerConnectionFactoryDependencies dependencies; webrtc::PeerConnectionFactoryDependencies dependencies;
dependencies.audio_encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory(); dependencies.audio_encoder_factory =
dependencies.audio_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory(); webrtc::CreateBuiltinAudioEncoderFactory();
dependencies.audio_decoder_factory =
webrtc::CreateBuiltinAudioDecoderFactory();
if (encoderFactory) { if (encoderFactory) {
dependencies.video_encoder_factory = webrtc::ObjCToNativeVideoEncoderFactory(encoderFactory); dependencies.video_encoder_factory =
webrtc::ObjCToNativeVideoEncoderFactory(encoderFactory);
} }
if (decoderFactory) { if (decoderFactory) {
dependencies.video_decoder_factory = webrtc::ObjCToNativeVideoDecoderFactory(decoderFactory); dependencies.video_decoder_factory =
webrtc::ObjCToNativeVideoDecoderFactory(decoderFactory);
} }
if (audioDevice) { if (audioDevice) {
dependencies.adm = webrtc::CreateAudioDeviceModule(audioDevice); dependencies.adm = webrtc::CreateAudioDeviceModule(audioDevice);
@ -113,7 +126,8 @@
#endif #endif
} }
- (instancetype)initWithNativeDependencies:(webrtc::PeerConnectionFactoryDependencies)dependencies { - (instancetype)initWithNativeDependencies:
(webrtc::PeerConnectionFactoryDependencies)dependencies {
self = [super init]; self = [super init];
if (self) { if (self) {
_networkThread = rtc::Thread::CreateWithSocketServer(); _networkThread = rtc::Thread::CreateWithSocketServer();
@ -131,7 +145,8 @@
result = _signalingThread->Start(); result = _signalingThread->Start();
RTC_DCHECK(result) << "Failed to start signaling thread."; RTC_DCHECK(result) << "Failed to start signaling thread.";
// Set fields that are relevant both to 'no media' and 'with media' scenarios. // Set fields that are relevant both to 'no media' and 'with media'
// scenarios.
dependencies.network_thread = _networkThread.get(); dependencies.network_thread = _networkThread.get();
dependencies.worker_thread = _workerThread.get(); dependencies.worker_thread = _workerThread.get();
dependencies.signaling_thread = _signalingThread.get(); dependencies.signaling_thread = _signalingThread.get();
@ -140,30 +155,39 @@
} }
if (dependencies.network_monitor_factory == nullptr && if (dependencies.network_monitor_factory == nullptr &&
dependencies.trials->IsEnabled("WebRTC-Network-UseNWPathMonitor")) { dependencies.trials->IsEnabled("WebRTC-Network-UseNWPathMonitor")) {
dependencies.network_monitor_factory = webrtc::CreateNetworkMonitorFactory(); dependencies.network_monitor_factory =
webrtc::CreateNetworkMonitorFactory();
} }
_nativeFactory = webrtc::CreateModularPeerConnectionFactory(std::move(dependencies)); _nativeFactory =
webrtc::CreateModularPeerConnectionFactory(std::move(dependencies));
NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!"); NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!");
} }
return self; return self;
} }
- (instancetype)initWithNoMedia { - (instancetype)initWithNoMedia {
return [self initWithNativeDependencies:webrtc::PeerConnectionFactoryDependencies()]; return [self
initWithNativeDependencies:webrtc::PeerConnectionFactoryDependencies()];
} }
- (instancetype)initWithNativeAudioEncoderFactory: - (instancetype)
(rtc::scoped_refptr<webrtc::AudioEncoderFactory>)audioEncoderFactory initWithNativeAudioEncoderFactory:
nativeAudioDecoderFactory: (rtc::scoped_refptr<webrtc::AudioEncoderFactory>)audioEncoderFactory
(rtc::scoped_refptr<webrtc::AudioDecoderFactory>)audioDecoderFactory nativeAudioDecoderFactory:
nativeVideoEncoderFactory: (rtc::scoped_refptr<webrtc::AudioDecoderFactory>)
(std::unique_ptr<webrtc::VideoEncoderFactory>)videoEncoderFactory audioDecoderFactory
nativeVideoDecoderFactory: nativeVideoEncoderFactory:
(std::unique_ptr<webrtc::VideoDecoderFactory>)videoDecoderFactory (std::unique_ptr<webrtc::VideoEncoderFactory>)
audioDeviceModule:(webrtc::AudioDeviceModule *)audioDeviceModule videoEncoderFactory
audioProcessingModule: nativeVideoDecoderFactory:
(rtc::scoped_refptr<webrtc::AudioProcessing>)audioProcessingModule { (std::unique_ptr<webrtc::VideoDecoderFactory>)
videoDecoderFactory
audioDeviceModule:
(webrtc::AudioDeviceModule *)audioDeviceModule
audioProcessingModule:
(rtc::scoped_refptr<webrtc::AudioProcessing>)
audioProcessingModule {
webrtc::PeerConnectionFactoryDependencies dependencies; webrtc::PeerConnectionFactoryDependencies dependencies;
dependencies.audio_encoder_factory = std::move(audioEncoderFactory); dependencies.audio_encoder_factory = std::move(audioEncoderFactory);
dependencies.audio_decoder_factory = std::move(audioDecoderFactory); dependencies.audio_decoder_factory = std::move(audioDecoderFactory);
@ -171,25 +195,32 @@
dependencies.video_decoder_factory = std::move(videoDecoderFactory); dependencies.video_decoder_factory = std::move(videoDecoderFactory);
dependencies.adm = std::move(audioDeviceModule); dependencies.adm = std::move(audioDeviceModule);
if (audioProcessingModule != nullptr) { if (audioProcessingModule != nullptr) {
dependencies.audio_processing_builder = CustomAudioProcessing(std::move(audioProcessingModule)); dependencies.audio_processing_builder =
CustomAudioProcessing(std::move(audioProcessingModule));
} }
return [self initWithMediaAndDependencies:std::move(dependencies)]; return [self initWithMediaAndDependencies:std::move(dependencies)];
} }
- (instancetype)initWithNativeAudioEncoderFactory: - (instancetype)
(rtc::scoped_refptr<webrtc::AudioEncoderFactory>)audioEncoderFactory initWithNativeAudioEncoderFactory:
nativeAudioDecoderFactory: (rtc::scoped_refptr<webrtc::AudioEncoderFactory>)audioEncoderFactory
(rtc::scoped_refptr<webrtc::AudioDecoderFactory>)audioDecoderFactory nativeAudioDecoderFactory:
nativeVideoEncoderFactory: (rtc::scoped_refptr<webrtc::AudioDecoderFactory>)
(std::unique_ptr<webrtc::VideoEncoderFactory>)videoEncoderFactory audioDecoderFactory
nativeVideoDecoderFactory: nativeVideoEncoderFactory:
(std::unique_ptr<webrtc::VideoDecoderFactory>)videoDecoderFactory (std::unique_ptr<webrtc::VideoEncoderFactory>)
audioDeviceModule:(webrtc::AudioDeviceModule *)audioDeviceModule videoEncoderFactory
audioProcessingModule: nativeVideoDecoderFactory:
(rtc::scoped_refptr<webrtc::AudioProcessing>)audioProcessingModule (std::unique_ptr<webrtc::VideoDecoderFactory>)
networkControllerFactory: videoDecoderFactory
(std::unique_ptr<webrtc::NetworkControllerFactoryInterface>) audioDeviceModule:
networkControllerFactory { (webrtc::AudioDeviceModule *)audioDeviceModule
audioProcessingModule:
(rtc::scoped_refptr<webrtc::AudioProcessing>)
audioProcessingModule
networkControllerFactory:
(std::unique_ptr<webrtc::NetworkControllerFactoryInterface>)
networkControllerFactory {
webrtc::PeerConnectionFactoryDependencies dependencies; webrtc::PeerConnectionFactoryDependencies dependencies;
dependencies.adm = std::move(audioDeviceModule); dependencies.adm = std::move(audioDeviceModule);
dependencies.audio_encoder_factory = std::move(audioEncoderFactory); dependencies.audio_encoder_factory = std::move(audioEncoderFactory);
@ -197,7 +228,8 @@
dependencies.video_encoder_factory = std::move(videoEncoderFactory); dependencies.video_encoder_factory = std::move(videoEncoderFactory);
dependencies.video_decoder_factory = std::move(videoDecoderFactory); dependencies.video_decoder_factory = std::move(videoDecoderFactory);
if (audioProcessingModule != nullptr) { if (audioProcessingModule != nullptr) {
dependencies.audio_processing_builder = CustomAudioProcessing(std::move(audioProcessingModule)); dependencies.audio_processing_builder =
CustomAudioProcessing(std::move(audioProcessingModule));
} }
dependencies.network_controller_factory = std::move(networkControllerFactory); dependencies.network_controller_factory = std::move(networkControllerFactory);
return [self initWithMediaAndDependencies:std::move(dependencies)]; return [self initWithMediaAndDependencies:std::move(dependencies)];
@ -218,24 +250,31 @@
} }
#endif #endif
if (dependencies.event_log_factory == nullptr) { if (dependencies.event_log_factory == nullptr) {
dependencies.event_log_factory = std::make_unique<webrtc::RtcEventLogFactory>(); dependencies.event_log_factory =
std::make_unique<webrtc::RtcEventLogFactory>();
} }
webrtc::EnableMedia(dependencies); webrtc::EnableMedia(dependencies);
return [self initWithNativeDependencies:std::move(dependencies)]; return [self initWithNativeDependencies:std::move(dependencies)];
} }
- (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpSenderCapabilitiesForKind:(NSString *)kind { - (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpSenderCapabilitiesForKind:
(NSString *)kind {
cricket::MediaType mediaType = [[self class] mediaTypeForKind:kind]; cricket::MediaType mediaType = [[self class] mediaTypeForKind:kind];
webrtc::RtpCapabilities rtpCapabilities = _nativeFactory->GetRtpSenderCapabilities(mediaType); webrtc::RtpCapabilities rtpCapabilities =
return [[RTC_OBJC_TYPE(RTCRtpCapabilities) alloc] initWithNativeRtpCapabilities:rtpCapabilities]; _nativeFactory->GetRtpSenderCapabilities(mediaType);
return [[RTC_OBJC_TYPE(RTCRtpCapabilities) alloc]
initWithNativeRtpCapabilities:rtpCapabilities];
} }
- (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpReceiverCapabilitiesForKind:(NSString *)kind { - (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpReceiverCapabilitiesForKind:
(NSString *)kind {
cricket::MediaType mediaType = [[self class] mediaTypeForKind:kind]; cricket::MediaType mediaType = [[self class] mediaTypeForKind:kind];
webrtc::RtpCapabilities rtpCapabilities = _nativeFactory->GetRtpReceiverCapabilities(mediaType); webrtc::RtpCapabilities rtpCapabilities =
return [[RTC_OBJC_TYPE(RTCRtpCapabilities) alloc] initWithNativeRtpCapabilities:rtpCapabilities]; _nativeFactory->GetRtpReceiverCapabilities(mediaType);
return [[RTC_OBJC_TYPE(RTCRtpCapabilities) alloc]
initWithNativeRtpCapabilities:rtpCapabilities];
} }
- (RTC_OBJC_TYPE(RTCAudioSource) *)audioSourceWithConstraints: - (RTC_OBJC_TYPE(RTCAudioSource) *)audioSourceWithConstraints:
@ -249,46 +288,61 @@
rtc::scoped_refptr<webrtc::AudioSourceInterface> source = rtc::scoped_refptr<webrtc::AudioSourceInterface> source =
_nativeFactory->CreateAudioSource(options); _nativeFactory->CreateAudioSource(options);
return [[RTC_OBJC_TYPE(RTCAudioSource) alloc] initWithFactory:self nativeAudioSource:source]; return [[RTC_OBJC_TYPE(RTCAudioSource) alloc] initWithFactory:self
nativeAudioSource:source];
} }
- (RTC_OBJC_TYPE(RTCAudioTrack) *)audioTrackWithTrackId:(NSString *)trackId { - (RTC_OBJC_TYPE(RTCAudioTrack) *)audioTrackWithTrackId:(NSString *)trackId {
RTC_OBJC_TYPE(RTCAudioSource) *audioSource = [self audioSourceWithConstraints:nil]; RTC_OBJC_TYPE(RTCAudioSource) *audioSource =
[self audioSourceWithConstraints:nil];
return [self audioTrackWithSource:audioSource trackId:trackId]; return [self audioTrackWithSource:audioSource trackId:trackId];
} }
- (RTC_OBJC_TYPE(RTCAudioTrack) *)audioTrackWithSource:(RTC_OBJC_TYPE(RTCAudioSource) *)source - (RTC_OBJC_TYPE(RTCAudioTrack) *)audioTrackWithSource:
(RTC_OBJC_TYPE(RTCAudioSource) *)source
trackId:(NSString *)trackId { trackId:(NSString *)trackId {
return [[RTC_OBJC_TYPE(RTCAudioTrack) alloc] initWithFactory:self source:source trackId:trackId]; return [[RTC_OBJC_TYPE(RTCAudioTrack) alloc] initWithFactory:self
source:source
trackId:trackId];
} }
- (RTC_OBJC_TYPE(RTCVideoSource) *)videoSource { - (RTC_OBJC_TYPE(RTCVideoSource) *)videoSource {
return [[RTC_OBJC_TYPE(RTCVideoSource) alloc] initWithFactory:self return [[RTC_OBJC_TYPE(RTCVideoSource) alloc]
signalingThread:_signalingThread.get() initWithFactory:self
workerThread:_workerThread.get()]; signalingThread:_signalingThread.get()
workerThread:_workerThread.get()];
} }
- (RTC_OBJC_TYPE(RTCVideoSource) *)videoSourceForScreenCast:(BOOL)forScreenCast { - (RTC_OBJC_TYPE(RTCVideoSource) *)videoSourceForScreenCast:
return [[RTC_OBJC_TYPE(RTCVideoSource) alloc] initWithFactory:self (BOOL)forScreenCast {
signalingThread:_signalingThread.get() return [[RTC_OBJC_TYPE(RTCVideoSource) alloc]
workerThread:_workerThread.get() initWithFactory:self
isScreenCast:forScreenCast]; signalingThread:_signalingThread.get()
workerThread:_workerThread.get()
isScreenCast:forScreenCast];
} }
- (RTC_OBJC_TYPE(RTCVideoTrack) *)videoTrackWithSource:(RTC_OBJC_TYPE(RTCVideoSource) *)source - (RTC_OBJC_TYPE(RTCVideoTrack) *)videoTrackWithSource:
(RTC_OBJC_TYPE(RTCVideoSource) *)source
trackId:(NSString *)trackId { trackId:(NSString *)trackId {
return [[RTC_OBJC_TYPE(RTCVideoTrack) alloc] initWithFactory:self source:source trackId:trackId]; return [[RTC_OBJC_TYPE(RTCVideoTrack) alloc] initWithFactory:self
source:source
trackId:trackId];
} }
- (RTC_OBJC_TYPE(RTCMediaStream) *)mediaStreamWithStreamId:(NSString *)streamId { - (RTC_OBJC_TYPE(RTCMediaStream) *)mediaStreamWithStreamId:
return [[RTC_OBJC_TYPE(RTCMediaStream) alloc] initWithFactory:self streamId:streamId]; (NSString *)streamId {
return [[RTC_OBJC_TYPE(RTCMediaStream) alloc] initWithFactory:self
streamId:streamId];
} }
- (nullable RTC_OBJC_TYPE(RTCPeerConnection) *) - (nullable RTC_OBJC_TYPE(RTCPeerConnection) *)
peerConnectionWithConfiguration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration peerConnectionWithConfiguration:
constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints (RTC_OBJC_TYPE(RTCConfiguration) *)configuration
delegate: constraints:
(nullable id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate { (RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
delegate:(nullable id<RTC_OBJC_TYPE(
RTCPeerConnectionDelegate)>)delegate {
return [[RTC_OBJC_TYPE(RTCPeerConnection) alloc] initWithFactory:self return [[RTC_OBJC_TYPE(RTCPeerConnection) alloc] initWithFactory:self
configuration:configuration configuration:configuration
constraints:constraints constraints:constraints
@ -297,32 +351,44 @@
} }
- (nullable RTC_OBJC_TYPE(RTCPeerConnection) *) - (nullable RTC_OBJC_TYPE(RTCPeerConnection) *)
peerConnectionWithConfiguration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration peerConnectionWithConfiguration:
constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints (RTC_OBJC_TYPE(RTCConfiguration) *)configuration
constraints:
(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
certificateVerifier: certificateVerifier:
(id<RTC_OBJC_TYPE(RTCSSLCertificateVerifier)>)certificateVerifier (id<RTC_OBJC_TYPE(RTCSSLCertificateVerifier)>)
delegate: certificateVerifier
(nullable id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate { delegate:(nullable id<RTC_OBJC_TYPE(
return [[RTC_OBJC_TYPE(RTCPeerConnection) alloc] initWithFactory:self RTCPeerConnectionDelegate)>)delegate {
configuration:configuration return [[RTC_OBJC_TYPE(RTCPeerConnection) alloc]
constraints:constraints initWithFactory:self
certificateVerifier:certificateVerifier configuration:configuration
delegate:delegate]; constraints:constraints
certificateVerifier:certificateVerifier
delegate:delegate];
} }
- (nullable RTC_OBJC_TYPE(RTCPeerConnection) *) - (nullable RTC_OBJC_TYPE(RTCPeerConnection) *)
peerConnectionWithDependencies:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration peerConnectionWithDependencies:
constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints (RTC_OBJC_TYPE(RTCConfiguration) *)configuration
dependencies:(std::unique_ptr<webrtc::PeerConnectionDependencies>)dependencies constraints:
delegate:(id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate { (RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
return [[RTC_OBJC_TYPE(RTCPeerConnection) alloc] initWithDependencies:self dependencies:
configuration:configuration (std::unique_ptr<webrtc::PeerConnectionDependencies>)
constraints:constraints dependencies
dependencies:std::move(dependencies) delegate:
delegate:delegate]; (id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)
delegate {
return [[RTC_OBJC_TYPE(RTCPeerConnection) alloc]
initWithDependencies:self
configuration:configuration
constraints:constraints
dependencies:std::move(dependencies)
delegate:delegate];
} }
- (void)setOptions:(nonnull RTC_OBJC_TYPE(RTCPeerConnectionFactoryOptions) *)options { - (void)setOptions:
(nonnull RTC_OBJC_TYPE(RTCPeerConnectionFactoryOptions) *)options {
RTC_DCHECK(options != nil); RTC_DCHECK(options != nil);
_nativeFactory->SetOptions(options.nativeOptions); _nativeFactory->SetOptions(options.nativeOptions);
} }
@ -338,7 +404,8 @@
} }
FILE *f = fopen(filePath.UTF8String, "wb"); FILE *f = fopen(filePath.UTF8String, "wb");
if (!f) { if (!f) {
RTCLogError(@"Error opening file: %@. Error: %s", filePath, strerror(errno)); RTCLogError(
@"Error opening file: %@. Error: %s", filePath, strerror(errno));
return NO; return NO;
} }
_hasStartedAecDump = _nativeFactory->StartAecDump(f, maxSizeInBytes); _hasStartedAecDump = _nativeFactory->StartAecDump(f, maxSizeInBytes);

View File

@ -25,7 +25,8 @@
@implementation RTCPeerConnectionFactoryBuilder (DefaultComponents) @implementation RTCPeerConnectionFactoryBuilder (DefaultComponents)
+ (RTCPeerConnectionFactoryBuilder *)defaultBuilder { + (RTCPeerConnectionFactoryBuilder *)defaultBuilder {
RTCPeerConnectionFactoryBuilder *builder = [[RTCPeerConnectionFactoryBuilder alloc] init]; RTCPeerConnectionFactoryBuilder *builder =
[[RTCPeerConnectionFactoryBuilder alloc] init];
auto audioEncoderFactory = webrtc::CreateBuiltinAudioEncoderFactory(); auto audioEncoderFactory = webrtc::CreateBuiltinAudioEncoderFactory();
[builder setAudioEncoderFactory:audioEncoderFactory]; [builder setAudioEncoderFactory:audioEncoderFactory];

View File

@ -29,20 +29,27 @@ NS_ASSUME_NONNULL_BEGIN
- (void)setFieldTrials:(std::unique_ptr<webrtc::FieldTrialsView>)fieldTrials; - (void)setFieldTrials:(std::unique_ptr<webrtc::FieldTrialsView>)fieldTrials;
- (void)setVideoEncoderFactory:(std::unique_ptr<webrtc::VideoEncoderFactory>)videoEncoderFactory; - (void)setVideoEncoderFactory:
(std::unique_ptr<webrtc::VideoEncoderFactory>)videoEncoderFactory;
- (void)setVideoDecoderFactory:(std::unique_ptr<webrtc::VideoDecoderFactory>)videoDecoderFactory; - (void)setVideoDecoderFactory:
(std::unique_ptr<webrtc::VideoDecoderFactory>)videoDecoderFactory;
- (void)setAudioEncoderFactory:(rtc::scoped_refptr<webrtc::AudioEncoderFactory>)audioEncoderFactory; - (void)setAudioEncoderFactory:
(rtc::scoped_refptr<webrtc::AudioEncoderFactory>)audioEncoderFactory;
- (void)setAudioDecoderFactory:(rtc::scoped_refptr<webrtc::AudioDecoderFactory>)audioDecoderFactory; - (void)setAudioDecoderFactory:
(rtc::scoped_refptr<webrtc::AudioDecoderFactory>)audioDecoderFactory;
- (void)setAudioDeviceModule:(rtc::scoped_refptr<webrtc::AudioDeviceModule>)audioDeviceModule; - (void)setAudioDeviceModule:
(rtc::scoped_refptr<webrtc::AudioDeviceModule>)audioDeviceModule;
- (void)setAudioProcessingModule:(rtc::scoped_refptr<webrtc::AudioProcessing>)audioProcessingModule; - (void)setAudioProcessingModule:
(rtc::scoped_refptr<webrtc::AudioProcessing>)audioProcessingModule;
- (void)setAudioProcessingBuilder: - (void)setAudioProcessingBuilder:
(std::unique_ptr<webrtc::AudioProcessingBuilderInterface>)audioProcessingBuilder; (std::unique_ptr<webrtc::AudioProcessingBuilderInterface>)
audioProcessingBuilder;
@end @end

View File

@ -35,35 +35,40 @@
_dependencies.trials = std::move(fieldTrials); _dependencies.trials = std::move(fieldTrials);
} }
- (void)setVideoEncoderFactory:(std::unique_ptr<webrtc::VideoEncoderFactory>)videoEncoderFactory { - (void)setVideoEncoderFactory:
(std::unique_ptr<webrtc::VideoEncoderFactory>)videoEncoderFactory {
_dependencies.video_encoder_factory = std::move(videoEncoderFactory); _dependencies.video_encoder_factory = std::move(videoEncoderFactory);
} }
- (void)setVideoDecoderFactory:(std::unique_ptr<webrtc::VideoDecoderFactory>)videoDecoderFactory { - (void)setVideoDecoderFactory:
(std::unique_ptr<webrtc::VideoDecoderFactory>)videoDecoderFactory {
_dependencies.video_decoder_factory = std::move(videoDecoderFactory); _dependencies.video_decoder_factory = std::move(videoDecoderFactory);
} }
- (void)setAudioEncoderFactory: - (void)setAudioEncoderFactory:
(rtc::scoped_refptr<webrtc::AudioEncoderFactory>)audioEncoderFactory { (rtc::scoped_refptr<webrtc::AudioEncoderFactory>)audioEncoderFactory {
_dependencies.audio_encoder_factory = std::move(audioEncoderFactory); _dependencies.audio_encoder_factory = std::move(audioEncoderFactory);
} }
- (void)setAudioDecoderFactory: - (void)setAudioDecoderFactory:
(rtc::scoped_refptr<webrtc::AudioDecoderFactory>)audioDecoderFactory { (rtc::scoped_refptr<webrtc::AudioDecoderFactory>)audioDecoderFactory {
_dependencies.audio_decoder_factory = std::move(audioDecoderFactory); _dependencies.audio_decoder_factory = std::move(audioDecoderFactory);
} }
- (void)setAudioDeviceModule:(rtc::scoped_refptr<webrtc::AudioDeviceModule>)audioDeviceModule { - (void)setAudioDeviceModule:
(rtc::scoped_refptr<webrtc::AudioDeviceModule>)audioDeviceModule {
_dependencies.adm = std::move(audioDeviceModule); _dependencies.adm = std::move(audioDeviceModule);
} }
- (void)setAudioProcessingModule: - (void)setAudioProcessingModule:
(rtc::scoped_refptr<webrtc::AudioProcessing>)audioProcessingModule { (rtc::scoped_refptr<webrtc::AudioProcessing>)audioProcessingModule {
_dependencies.audio_processing_builder = CustomAudioProcessing(std::move(audioProcessingModule)); _dependencies.audio_processing_builder =
CustomAudioProcessing(std::move(audioProcessingModule));
} }
- (void)setAudioProcessingBuilder: - (void)setAudioProcessingBuilder:
(std::unique_ptr<webrtc::AudioProcessingBuilderInterface>)audioProcessingBuilder { (std::unique_ptr<webrtc::AudioProcessingBuilderInterface>)
audioProcessingBuilder {
_dependencies.audio_processing_builder = std::move(audioProcessingBuilder); _dependencies.audio_processing_builder = std::move(audioProcessingBuilder);
} }

View File

@ -19,7 +19,8 @@ NS_ASSUME_NONNULL_BEGIN
/** Returns the equivalent native PeerConnectionFactoryInterface::Options /** Returns the equivalent native PeerConnectionFactoryInterface::Options
* structure. */ * structure. */
@property(nonatomic, readonly) webrtc::PeerConnectionFactoryInterface::Options nativeOptions; @property(nonatomic, readonly)
webrtc::PeerConnectionFactoryInterface::Options nativeOptions;
@end @end

View File

@ -44,11 +44,15 @@ void setNetworkBit(webrtc::PeerConnectionFactoryInterface::Options* options,
options.disable_encryption = self.disableEncryption; options.disable_encryption = self.disableEncryption;
options.disable_network_monitor = self.disableNetworkMonitor; options.disable_network_monitor = self.disableNetworkMonitor;
setNetworkBit(&options, rtc::ADAPTER_TYPE_LOOPBACK, self.ignoreLoopbackNetworkAdapter); setNetworkBit(
&options, rtc::ADAPTER_TYPE_LOOPBACK, self.ignoreLoopbackNetworkAdapter);
setNetworkBit(&options, rtc::ADAPTER_TYPE_VPN, self.ignoreVPNNetworkAdapter); setNetworkBit(&options, rtc::ADAPTER_TYPE_VPN, self.ignoreVPNNetworkAdapter);
setNetworkBit(&options, rtc::ADAPTER_TYPE_CELLULAR, self.ignoreCellularNetworkAdapter); setNetworkBit(
setNetworkBit(&options, rtc::ADAPTER_TYPE_WIFI, self.ignoreWiFiNetworkAdapter); &options, rtc::ADAPTER_TYPE_CELLULAR, self.ignoreCellularNetworkAdapter);
setNetworkBit(&options, rtc::ADAPTER_TYPE_ETHERNET, self.ignoreEthernetNetworkAdapter); setNetworkBit(
&options, rtc::ADAPTER_TYPE_WIFI, self.ignoreWiFiNetworkAdapter);
setNetworkBit(
&options, rtc::ADAPTER_TYPE_ETHERNET, self.ignoreEthernetNetworkAdapter);
return options; return options;
} }

View File

@ -21,8 +21,8 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, readonly) webrtc::RtcpParameters nativeParameters; @property(nonatomic, readonly) webrtc::RtcpParameters nativeParameters;
/** Initialize the object with a native RtcpParameters structure. */ /** Initialize the object with a native RtcpParameters structure. */
- (instancetype)initWithNativeParameters:(const webrtc::RtcpParameters &)nativeParameters - (instancetype)initWithNativeParameters:
NS_DESIGNATED_INITIALIZER; (const webrtc::RtcpParameters &)nativeParameters NS_DESIGNATED_INITIALIZER;
@end @end

View File

@ -22,7 +22,8 @@
return [self initWithNativeParameters:nativeParameters]; return [self initWithNativeParameters:nativeParameters];
} }
- (instancetype)initWithNativeParameters:(const webrtc::RtcpParameters &)nativeParameters { - (instancetype)initWithNativeParameters:
(const webrtc::RtcpParameters &)nativeParameters {
self = [super init]; self = [super init];
if (self) { if (self) {
_cname = [NSString stringForStdString:nativeParameters.cname]; _cname = [NSString stringForStdString:nativeParameters.cname];

View File

@ -14,18 +14,21 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface RTC_OBJC_TYPE (RTCRtpCapabilities)() @interface RTC_OBJC_TYPE (RTCRtpCapabilities)
()
/** /**
* The native RtpCapabilities representation of this RTCRtpCapabilities * The native RtpCapabilities representation of this RTCRtpCapabilities
* object. This is needed to pass to the underlying C++ APIs. * object. This is needed to pass to the underlying C++ APIs.
*/ */
@property(nonatomic, readonly) webrtc::RtpCapabilities nativeRtpCapabilities; @property(nonatomic,
readonly) webrtc::RtpCapabilities nativeRtpCapabilities;
/** /**
* Initialize an RTCRtpCapabilities from a native RtpCapabilities. * Initialize an RTCRtpCapabilities from a native RtpCapabilities.
*/ */
- (instancetype)initWithNativeRtpCapabilities:(const webrtc::RtpCapabilities &)rtpCapabilities; - (instancetype)initWithNativeRtpCapabilities:
(const webrtc::RtpCapabilities &)rtpCapabilities;
@end @end

View File

@ -38,9 +38,12 @@
_codecs = codecs; _codecs = codecs;
NSMutableArray *headerExtensions = [[NSMutableArray alloc] init]; NSMutableArray *headerExtensions = [[NSMutableArray alloc] init];
for (const auto &headerExtension : nativeRtpCapabilities.header_extensions) { for (const auto &headerExtension :
[headerExtensions addObject:[[RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) alloc] nativeRtpCapabilities.header_extensions) {
initWithNativeRtpHeaderExtensionCapability:headerExtension]]; [headerExtensions
addObject:
[[RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) alloc]
initWithNativeRtpHeaderExtensionCapability:headerExtension]];
} }
_headerExtensions = headerExtensions; _headerExtensions = headerExtensions;
} }
@ -52,8 +55,10 @@
for (RTC_OBJC_TYPE(RTCRtpCodecCapability) * codec in _codecs) { for (RTC_OBJC_TYPE(RTCRtpCodecCapability) * codec in _codecs) {
rtpCapabilities.codecs.push_back(codec.nativeRtpCodecCapability); rtpCapabilities.codecs.push_back(codec.nativeRtpCodecCapability);
} }
for (RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) * headerExtension in _headerExtensions) { for (RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) *
rtpCapabilities.header_extensions.push_back(headerExtension.nativeRtpHeaderExtensionCapability); headerExtension in _headerExtensions) {
rtpCapabilities.header_extensions.push_back(
headerExtension.nativeRtpHeaderExtensionCapability);
} }
return rtpCapabilities; return rtpCapabilities;
} }

View File

@ -14,13 +14,16 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface RTC_OBJC_TYPE (RTCRtpCodecCapability)() @interface RTC_OBJC_TYPE (RTCRtpCodecCapability)
()
/** /**
* The native RtpCodecCapability representation of this RTCRtpCodecCapability * The native RtpCodecCapability representation of this
* object. This is needed to pass to the underlying C++ APIs. * RTCRtpCodecCapability object. This is needed to pass to the underlying
*/ * C++ APIs.
@property(nonatomic, readonly) webrtc::RtpCodecCapability nativeRtpCodecCapability; */
@property(nonatomic,
readonly) webrtc::RtpCodecCapability nativeRtpCodecCapability;
/** /**
* Initialize an RTCRtpCodecCapability from a native RtpCodecCapability. * Initialize an RTCRtpCodecCapability from a native RtpCodecCapability.

View File

@ -36,8 +36,8 @@
self = [super init]; self = [super init];
if (self) { if (self) {
if (nativeRtpCodecCapability.preferred_payload_type) { if (nativeRtpCodecCapability.preferred_payload_type) {
_preferredPayloadType = _preferredPayloadType = [NSNumber
[NSNumber numberWithInt:*nativeRtpCodecCapability.preferred_payload_type]; numberWithInt:*nativeRtpCodecCapability.preferred_payload_type];
} }
_name = [NSString stringForStdString:nativeRtpCodecCapability.name]; _name = [NSString stringForStdString:nativeRtpCodecCapability.name];
switch (nativeRtpCodecCapability.kind) { switch (nativeRtpCodecCapability.kind) {
@ -55,10 +55,12 @@
break; break;
} }
if (nativeRtpCodecCapability.clock_rate) { if (nativeRtpCodecCapability.clock_rate) {
_clockRate = [NSNumber numberWithInt:*nativeRtpCodecCapability.clock_rate]; _clockRate =
[NSNumber numberWithInt:*nativeRtpCodecCapability.clock_rate];
} }
if (nativeRtpCodecCapability.num_channels) { if (nativeRtpCodecCapability.num_channels) {
_numChannels = [NSNumber numberWithInt:*nativeRtpCodecCapability.num_channels]; _numChannels =
[NSNumber numberWithInt:*nativeRtpCodecCapability.num_channels];
} }
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
for (const auto &parameter : nativeRtpCodecCapability.parameters) { for (const auto &parameter : nativeRtpCodecCapability.parameters) {
@ -66,29 +68,32 @@
forKey:[NSString stringForStdString:parameter.first]]; forKey:[NSString stringForStdString:parameter.first]];
} }
_parameters = parameters; _parameters = parameters;
_mimeType = [NSString stringForStdString:nativeRtpCodecCapability.mime_type()]; _mimeType =
[NSString stringForStdString:nativeRtpCodecCapability.mime_type()];
} }
return self; return self;
} }
- (NSString *)description { - (NSString *)description {
return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCRtpCodecCapability) {\n " return [NSString
@"preferredPayloadType: %@\n name: %@\n kind: %@\n " stringWithFormat:@"RTC_OBJC_TYPE(RTCRtpCodecCapability) {\n "
@"clockRate: %@\n numChannels: %@\n parameters: %@\n " @"preferredPayloadType: %@\n name: %@\n kind: %@\n "
@"mimeType: %@\n}", @"clockRate: %@\n numChannels: %@\n parameters: %@\n "
_preferredPayloadType, @"mimeType: %@\n}",
_name, _preferredPayloadType,
_kind, _name,
_clockRate, _kind,
_numChannels, _clockRate,
_parameters, _numChannels,
_mimeType]; _parameters,
_mimeType];
} }
- (webrtc::RtpCodecCapability)nativeRtpCodecCapability { - (webrtc::RtpCodecCapability)nativeRtpCodecCapability {
webrtc::RtpCodecCapability rtpCodecCapability; webrtc::RtpCodecCapability rtpCodecCapability;
if (_preferredPayloadType != nil) { if (_preferredPayloadType != nil) {
rtpCodecCapability.preferred_payload_type = std::optional<int>(_preferredPayloadType.intValue); rtpCodecCapability.preferred_payload_type =
std::optional<int>(_preferredPayloadType.intValue);
} }
rtpCodecCapability.name = [NSString stdStringForString:_name]; rtpCodecCapability.name = [NSString stdStringForString:_name];
// NSString pointer comparison is safe here since "kind" is readonly and only // NSString pointer comparison is safe here since "kind" is readonly and only

View File

@ -21,7 +21,8 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, readonly) webrtc::RtpCodecParameters nativeParameters; @property(nonatomic, readonly) webrtc::RtpCodecParameters nativeParameters;
/** Initialize the object with a native RtpCodecParameters structure. */ /** Initialize the object with a native RtpCodecParameters structure. */
- (instancetype)initWithNativeParameters:(const webrtc::RtpCodecParameters &)nativeParameters - (instancetype)initWithNativeParameters:
(const webrtc::RtpCodecParameters &)nativeParameters
NS_DESIGNATED_INITIALIZER; NS_DESIGNATED_INITIALIZER;
@end @end

View File

@ -16,22 +16,22 @@
#include "media/base/media_constants.h" #include "media/base/media_constants.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
const NSString * const kRTCRtxCodecName = @(cricket::kRtxCodecName); const NSString *const kRTCRtxCodecName = @(cricket::kRtxCodecName);
const NSString * const kRTCRedCodecName = @(cricket::kRedCodecName); const NSString *const kRTCRedCodecName = @(cricket::kRedCodecName);
const NSString * const kRTCUlpfecCodecName = @(cricket::kUlpfecCodecName); const NSString *const kRTCUlpfecCodecName = @(cricket::kUlpfecCodecName);
const NSString * const kRTCFlexfecCodecName = @(cricket::kFlexfecCodecName); const NSString *const kRTCFlexfecCodecName = @(cricket::kFlexfecCodecName);
const NSString * const kRTCOpusCodecName = @(cricket::kOpusCodecName); const NSString *const kRTCOpusCodecName = @(cricket::kOpusCodecName);
const NSString * const kRTCL16CodecName = @(cricket::kL16CodecName); const NSString *const kRTCL16CodecName = @(cricket::kL16CodecName);
const NSString * const kRTCG722CodecName = @(cricket::kG722CodecName); const NSString *const kRTCG722CodecName = @(cricket::kG722CodecName);
const NSString * const kRTCIlbcCodecName = @(cricket::kIlbcCodecName); const NSString *const kRTCIlbcCodecName = @(cricket::kIlbcCodecName);
const NSString * const kRTCPcmuCodecName = @(cricket::kPcmuCodecName); const NSString *const kRTCPcmuCodecName = @(cricket::kPcmuCodecName);
const NSString * const kRTCPcmaCodecName = @(cricket::kPcmaCodecName); const NSString *const kRTCPcmaCodecName = @(cricket::kPcmaCodecName);
const NSString * const kRTCDtmfCodecName = @(cricket::kDtmfCodecName); const NSString *const kRTCDtmfCodecName = @(cricket::kDtmfCodecName);
const NSString * const kRTCComfortNoiseCodecName = const NSString *const kRTCComfortNoiseCodecName =
@(cricket::kComfortNoiseCodecName); @(cricket::kComfortNoiseCodecName);
const NSString * const kRTCVp8CodecName = @(cricket::kVp8CodecName); const NSString *const kRTCVp8CodecName = @(cricket::kVp8CodecName);
const NSString * const kRTCVp9CodecName = @(cricket::kVp9CodecName); const NSString *const kRTCVp9CodecName = @(cricket::kVp9CodecName);
const NSString * const kRTCH264CodecName = @(cricket::kH264CodecName); const NSString *const kRTCH264CodecName = @(cricket::kH264CodecName);
@implementation RTC_OBJC_TYPE (RTCRtpCodecParameters) @implementation RTC_OBJC_TYPE (RTCRtpCodecParameters)

View File

@ -18,10 +18,12 @@ NS_ASSUME_NONNULL_BEGIN
() ()
/** Returns the equivalent native RtpEncodingParameters structure. */ /** Returns the equivalent native RtpEncodingParameters structure. */
@property(nonatomic, readonly) webrtc::RtpEncodingParameters nativeParameters; @property(nonatomic,
readonly) webrtc::RtpEncodingParameters nativeParameters;
/** Initialize the object with a native RtpEncodingParameters structure. */ /** Initialize the object with a native RtpEncodingParameters structure. */
- (instancetype)initWithNativeParameters:(const webrtc::RtpEncodingParameters &)nativeParameters - (instancetype)initWithNativeParameters:
(const webrtc::RtpEncodingParameters &)nativeParameters
NS_DESIGNATED_INITIALIZER; NS_DESIGNATED_INITIALIZER;
@end @end

View File

@ -66,7 +66,8 @@ RTC_OBJC_EXPORT
@property(nonatomic, assign) RTCPriority networkPriority; @property(nonatomic, assign) RTCPriority networkPriority;
/** Allow dynamic frame length changes for audio: /** Allow dynamic frame length changes for audio:
https://w3c.github.io/webrtc-extensions/#dom-rtcrtpencodingparameters-adaptiveptime */ https://w3c.github.io/webrtc-extensions/#dom-rtcrtpencodingparameters-adaptiveptime
*/
@property(nonatomic, assign) BOOL adaptiveAudioPacketTime; @property(nonatomic, assign) BOOL adaptiveAudioPacketTime;
- (instancetype)init; - (instancetype)init;

View File

@ -51,11 +51,12 @@
_maxFramerate = [NSNumber numberWithInt:*nativeParameters.max_framerate]; _maxFramerate = [NSNumber numberWithInt:*nativeParameters.max_framerate];
} }
if (nativeParameters.num_temporal_layers) { if (nativeParameters.num_temporal_layers) {
_numTemporalLayers = [NSNumber numberWithInt:*nativeParameters.num_temporal_layers]; _numTemporalLayers =
[NSNumber numberWithInt:*nativeParameters.num_temporal_layers];
} }
if (nativeParameters.scale_resolution_down_by) { if (nativeParameters.scale_resolution_down_by) {
_scaleResolutionDownBy = _scaleResolutionDownBy = [NSNumber
[NSNumber numberWithDouble:*nativeParameters.scale_resolution_down_by]; numberWithDouble:*nativeParameters.scale_resolution_down_by];
} }
if (nativeParameters.ssrc) { if (nativeParameters.ssrc) {
_ssrc = [NSNumber numberWithUnsignedLong:*nativeParameters.ssrc]; _ssrc = [NSNumber numberWithUnsignedLong:*nativeParameters.ssrc];
@ -84,17 +85,19 @@
parameters.max_framerate = std::optional<int>(_maxFramerate.intValue); parameters.max_framerate = std::optional<int>(_maxFramerate.intValue);
} }
if (_numTemporalLayers != nil) { if (_numTemporalLayers != nil) {
parameters.num_temporal_layers = std::optional<int>(_numTemporalLayers.intValue); parameters.num_temporal_layers =
std::optional<int>(_numTemporalLayers.intValue);
} }
if (_scaleResolutionDownBy != nil) { if (_scaleResolutionDownBy != nil) {
parameters.scale_resolution_down_by = std::optional<double>(_scaleResolutionDownBy.doubleValue); parameters.scale_resolution_down_by =
std::optional<double>(_scaleResolutionDownBy.doubleValue);
} }
if (_ssrc != nil) { if (_ssrc != nil) {
parameters.ssrc = std::optional<uint32_t>(_ssrc.unsignedLongValue); parameters.ssrc = std::optional<uint32_t>(_ssrc.unsignedLongValue);
} }
parameters.bitrate_priority = _bitratePriority; parameters.bitrate_priority = _bitratePriority;
parameters.network_priority = parameters.network_priority = [RTC_OBJC_TYPE(RTCRtpEncodingParameters)
[RTC_OBJC_TYPE(RTCRtpEncodingParameters) nativePriorityFromPriority:_networkPriority]; nativePriorityFromPriority:_networkPriority];
parameters.adaptive_ptime = _adaptiveAudioPacketTime; parameters.adaptive_ptime = _adaptiveAudioPacketTime;
return parameters; return parameters;
} }

View File

@ -21,8 +21,8 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, readonly) webrtc::RtpExtension nativeParameters; @property(nonatomic, readonly) webrtc::RtpExtension nativeParameters;
/** Initialize the object with a native RtpExtension structure. */ /** Initialize the object with a native RtpExtension structure. */
- (instancetype)initWithNativeParameters:(const webrtc::RtpExtension &)nativeParameters - (instancetype)initWithNativeParameters:
NS_DESIGNATED_INITIALIZER; (const webrtc::RtpExtension &)nativeParameters NS_DESIGNATED_INITIALIZER;
@end @end

View File

@ -23,7 +23,8 @@
return [self initWithNativeParameters:nativeExtension]; return [self initWithNativeParameters:nativeExtension];
} }
- (instancetype)initWithNativeParameters:(const webrtc::RtpExtension &)nativeParameters { - (instancetype)initWithNativeParameters:
(const webrtc::RtpExtension &)nativeParameters {
self = [super init]; self = [super init];
if (self) { if (self) {
_uri = [NSString stringForStdString:nativeParameters.uri]; _uri = [NSString stringForStdString:nativeParameters.uri];

View File

@ -14,17 +14,20 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface RTC_OBJC_TYPE (RTCRtpHeaderExtensionCapability)() @interface RTC_OBJC_TYPE (RTCRtpHeaderExtensionCapability)
()
/**
* The native RtpHeaderExtensionCapability representation of this
* RTCRtpHeaderExtensionCapability object. This is needed to pass to the
* underlying C++ APIs.
*/
@property(nonatomic, readonly) webrtc::RtpHeaderExtensionCapability
nativeRtpHeaderExtensionCapability;
/** /**
* The native RtpHeaderExtensionCapability representation of this * Initialize an RTCRtpHeaderExtensionCapability from a native
* RTCRtpHeaderExtensionCapability object. This is needed to pass to the underlying C++ APIs. * RtpHeaderExtensionCapability.
*/
@property(nonatomic,
readonly) webrtc::RtpHeaderExtensionCapability nativeRtpHeaderExtensionCapability;
/**
* Initialize an RTCRtpHeaderExtensionCapability from a native RtpHeaderExtensionCapability.
*/ */
- (instancetype)initWithNativeRtpHeaderExtensionCapability: - (instancetype)initWithNativeRtpHeaderExtensionCapability:
(const webrtc::RtpHeaderExtensionCapability &)rtpHeaderExtensionCapability; (const webrtc::RtpHeaderExtensionCapability &)rtpHeaderExtensionCapability;

View File

@ -26,7 +26,8 @@ RTC_OBJC_EXPORT
@property(nonatomic, readonly, nullable) NSNumber* preferredId; @property(nonatomic, readonly, nullable) NSNumber* preferredId;
/** Whether the header extension is encrypted or not. */ /** Whether the header extension is encrypted or not. */
@property(nonatomic, readonly, getter=isPreferredEncrypted) BOOL preferredEncrypted; @property(nonatomic, readonly, getter=isPreferredEncrypted)
BOOL preferredEncrypted;
/** Direction of the header extension. */ /** Direction of the header extension. */
@property(nonatomic) RTCRtpTransceiverDirection direction; @property(nonatomic) RTCRtpTransceiverDirection direction;

View File

@ -22,41 +22,48 @@
- (instancetype)init { - (instancetype)init {
webrtc::RtpHeaderExtensionCapability nativeRtpHeaderExtensionCapability; webrtc::RtpHeaderExtensionCapability nativeRtpHeaderExtensionCapability;
return [self initWithNativeRtpHeaderExtensionCapability:nativeRtpHeaderExtensionCapability]; return [self initWithNativeRtpHeaderExtensionCapability:
nativeRtpHeaderExtensionCapability];
} }
- (instancetype)initWithNativeRtpHeaderExtensionCapability: - (instancetype)initWithNativeRtpHeaderExtensionCapability:
(const webrtc::RtpHeaderExtensionCapability &)nativeRtpHeaderExtensionCapability { (const webrtc::RtpHeaderExtensionCapability &)
nativeRtpHeaderExtensionCapability {
self = [super init]; self = [super init];
if (self) { if (self) {
_uri = [NSString stringForStdString:nativeRtpHeaderExtensionCapability.uri]; _uri = [NSString stringForStdString:nativeRtpHeaderExtensionCapability.uri];
if (nativeRtpHeaderExtensionCapability.preferred_id) { if (nativeRtpHeaderExtensionCapability.preferred_id) {
_preferredId = [NSNumber numberWithInt:*nativeRtpHeaderExtensionCapability.preferred_id]; _preferredId = [NSNumber
numberWithInt:*nativeRtpHeaderExtensionCapability.preferred_id];
} }
_preferredEncrypted = nativeRtpHeaderExtensionCapability.preferred_encrypt; _preferredEncrypted = nativeRtpHeaderExtensionCapability.preferred_encrypt;
_direction = [RTC_OBJC_TYPE(RTCRtpTransceiver) _direction = [RTC_OBJC_TYPE(RTCRtpTransceiver)
rtpTransceiverDirectionFromNativeDirection:nativeRtpHeaderExtensionCapability.direction]; rtpTransceiverDirectionFromNativeDirection:
nativeRtpHeaderExtensionCapability.direction];
} }
return self; return self;
} }
- (NSString *)description { - (NSString *)description {
return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) {\n uri: " return
@"%@\n preferredId: %@\n preferredEncrypted: %d\n}", [NSString stringWithFormat:
_uri, @"RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) {\n uri: "
_preferredId, @"%@\n preferredId: %@\n preferredEncrypted: %d\n}",
_preferredEncrypted]; _uri,
_preferredId,
_preferredEncrypted];
} }
- (webrtc::RtpHeaderExtensionCapability)nativeRtpHeaderExtensionCapability { - (webrtc::RtpHeaderExtensionCapability)nativeRtpHeaderExtensionCapability {
webrtc::RtpHeaderExtensionCapability rtpHeaderExtensionCapability; webrtc::RtpHeaderExtensionCapability rtpHeaderExtensionCapability;
rtpHeaderExtensionCapability.uri = [NSString stdStringForString:_uri]; rtpHeaderExtensionCapability.uri = [NSString stdStringForString:_uri];
if (_preferredId != nil) { if (_preferredId != nil) {
rtpHeaderExtensionCapability.preferred_id = std::optional<int>(_preferredId.intValue); rtpHeaderExtensionCapability.preferred_id =
std::optional<int>(_preferredId.intValue);
} }
rtpHeaderExtensionCapability.preferred_encrypt = _preferredEncrypted; rtpHeaderExtensionCapability.preferred_encrypt = _preferredEncrypted;
rtpHeaderExtensionCapability.direction = rtpHeaderExtensionCapability.direction = [RTC_OBJC_TYPE(RTCRtpTransceiver)
[RTC_OBJC_TYPE(RTCRtpTransceiver) nativeRtpTransceiverDirectionFromDirection:_direction]; nativeRtpTransceiverDirectionFromDirection:_direction];
return rtpHeaderExtensionCapability; return rtpHeaderExtensionCapability;
} }

View File

@ -21,8 +21,8 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, readonly) webrtc::RtpParameters nativeParameters; @property(nonatomic, readonly) webrtc::RtpParameters nativeParameters;
/** Initialize the object with a native RtpParameters structure. */ /** Initialize the object with a native RtpParameters structure. */
- (instancetype)initWithNativeParameters:(const webrtc::RtpParameters &)nativeParameters - (instancetype)initWithNativeParameters:
NS_DESIGNATED_INITIALIZER; (const webrtc::RtpParameters &)nativeParameters NS_DESIGNATED_INITIALIZER;
@end @end

View File

@ -40,10 +40,12 @@ RTC_OBJC_EXPORT
NSArray<RTC_OBJC_TYPE(RTCRtpHeaderExtension) *> *headerExtensions; NSArray<RTC_OBJC_TYPE(RTCRtpHeaderExtension) *> *headerExtensions;
/** The currently active encodings in the order of preference. */ /** The currently active encodings in the order of preference. */
@property(nonatomic, copy) NSArray<RTC_OBJC_TYPE(RTCRtpEncodingParameters) *> *encodings; @property(nonatomic, copy)
NSArray<RTC_OBJC_TYPE(RTCRtpEncodingParameters) *> *encodings;
/** The negotiated set of send codecs in order of preference. */ /** The negotiated set of send codecs in order of preference. */
@property(nonatomic, copy) NSArray<RTC_OBJC_TYPE(RTCRtpCodecParameters) *> *codecs; @property(nonatomic, copy)
NSArray<RTC_OBJC_TYPE(RTCRtpCodecParameters) *> *codecs;
/** /**
* Degradation preference in case of CPU adaptation or constrained bandwidth. * Degradation preference in case of CPU adaptation or constrained bandwidth.

View File

@ -34,14 +34,16 @@
(const webrtc::RtpParameters &)nativeParameters { (const webrtc::RtpParameters &)nativeParameters {
self = [super init]; self = [super init];
if (self) { if (self) {
_transactionId = [NSString stringForStdString:nativeParameters.transaction_id]; _transactionId =
_rtcp = [NSString stringForStdString:nativeParameters.transaction_id];
[[RTC_OBJC_TYPE(RTCRtcpParameters) alloc] initWithNativeParameters:nativeParameters.rtcp]; _rtcp = [[RTC_OBJC_TYPE(RTCRtcpParameters) alloc]
initWithNativeParameters:nativeParameters.rtcp];
NSMutableArray *headerExtensions = [[NSMutableArray alloc] init]; NSMutableArray *headerExtensions = [[NSMutableArray alloc] init];
for (const auto &headerExtension : nativeParameters.header_extensions) { for (const auto &headerExtension : nativeParameters.header_extensions) {
[headerExtensions addObject:[[RTC_OBJC_TYPE(RTCRtpHeaderExtension) alloc] [headerExtensions
initWithNativeParameters:headerExtension]]; addObject:[[RTC_OBJC_TYPE(RTCRtpHeaderExtension) alloc]
initWithNativeParameters:headerExtension]];
} }
_headerExtensions = headerExtensions; _headerExtensions = headerExtensions;
@ -54,14 +56,14 @@
NSMutableArray *codecs = [[NSMutableArray alloc] init]; NSMutableArray *codecs = [[NSMutableArray alloc] init];
for (const auto &codec : nativeParameters.codecs) { for (const auto &codec : nativeParameters.codecs) {
[codecs [codecs addObject:[[RTC_OBJC_TYPE(RTCRtpCodecParameters) alloc]
addObject:[[RTC_OBJC_TYPE(RTCRtpCodecParameters) alloc] initWithNativeParameters:codec]]; initWithNativeParameters:codec]];
} }
_codecs = codecs; _codecs = codecs;
_degradationPreference = [RTC_OBJC_TYPE(RTCRtpParameters) _degradationPreference = [RTC_OBJC_TYPE(RTCRtpParameters)
degradationPreferenceFromNativeDegradationPreference:nativeParameters degradationPreferenceFromNativeDegradationPreference:
.degradation_preference]; nativeParameters.degradation_preference];
} }
return self; return self;
} }
@ -70,7 +72,8 @@
webrtc::RtpParameters parameters; webrtc::RtpParameters parameters;
parameters.transaction_id = [NSString stdStringForString:_transactionId]; parameters.transaction_id = [NSString stdStringForString:_transactionId];
parameters.rtcp = [_rtcp nativeParameters]; parameters.rtcp = [_rtcp nativeParameters];
for (RTC_OBJC_TYPE(RTCRtpHeaderExtension) * headerExtension in _headerExtensions) { for (RTC_OBJC_TYPE(RTCRtpHeaderExtension) *
headerExtension in _headerExtensions) {
parameters.header_extensions.push_back(headerExtension.nativeParameters); parameters.header_extensions.push_back(headerExtension.nativeParameters);
} }
for (RTC_OBJC_TYPE(RTCRtpEncodingParameters) * encoding in _encodings) { for (RTC_OBJC_TYPE(RTCRtpEncodingParameters) * encoding in _encodings) {
@ -81,14 +84,15 @@
} }
if (_degradationPreference) { if (_degradationPreference) {
parameters.degradation_preference = [RTC_OBJC_TYPE(RTCRtpParameters) parameters.degradation_preference = [RTC_OBJC_TYPE(RTCRtpParameters)
nativeDegradationPreferenceFromDegradationPreference:(RTCDegradationPreference) nativeDegradationPreferenceFromDegradationPreference:
_degradationPreference.intValue]; (RTCDegradationPreference)_degradationPreference.intValue];
} }
return parameters; return parameters;
} }
+ (webrtc::DegradationPreference)nativeDegradationPreferenceFromDegradationPreference: + (webrtc::DegradationPreference)
(RTCDegradationPreference)degradationPreference { nativeDegradationPreferenceFromDegradationPreference:
(RTCDegradationPreference)degradationPreference {
switch (degradationPreference) { switch (degradationPreference) {
case RTCDegradationPreferenceDisabled: case RTCDegradationPreferenceDisabled:
return webrtc::DegradationPreference::DISABLED; return webrtc::DegradationPreference::DISABLED;

View File

@ -16,7 +16,8 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
/** /**
* This class extension exposes methods that work directly with injectable C++ components. * This class extension exposes methods that work directly with injectable C++
* components.
*/ */
@interface RTC_OBJC_TYPE (RTCRtpReceiver) @interface RTC_OBJC_TYPE (RTCRtpReceiver)
() ()
@ -25,7 +26,8 @@ NS_ASSUME_NONNULL_BEGIN
* This will decrypt the entire frame using the user provided decryption * This will decrypt the entire frame using the user provided decryption
* mechanism regardless of whether SRTP is enabled or not. * mechanism regardless of whether SRTP is enabled or not.
*/ */
- (void)setFrameDecryptor : (rtc::scoped_refptr<webrtc::FrameDecryptorInterface>)frameDecryptor; - (void)setFrameDecryptor
: (rtc::scoped_refptr<webrtc::FrameDecryptorInterface>)frameDecryptor;
@end @end

View File

@ -33,15 +33,18 @@ class RtpReceiverDelegateAdapter : public RtpReceiverObserverInterface {
@interface RTC_OBJC_TYPE (RTCRtpReceiver) @interface RTC_OBJC_TYPE (RTCRtpReceiver)
() ()
@property(nonatomic, @property(nonatomic, readonly)
readonly) rtc::scoped_refptr<webrtc::RtpReceiverInterface> nativeRtpReceiver; rtc::scoped_refptr<webrtc::RtpReceiverInterface> nativeRtpReceiver;
/** Initialize an RTCRtpReceiver with a native RtpReceiverInterface. */ /** Initialize an RTCRtpReceiver with a native RtpReceiverInterface. */
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)
nativeRtpReceiver:(rtc::scoped_refptr<webrtc::RtpReceiverInterface>)nativeRtpReceiver initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
nativeRtpReceiver:
(rtc::scoped_refptr<webrtc::RtpReceiverInterface>)nativeRtpReceiver
NS_DESIGNATED_INITIALIZER; NS_DESIGNATED_INITIALIZER;
+ (RTCRtpMediaType)mediaTypeForNativeMediaType:(cricket::MediaType)nativeMediaType; + (RTCRtpMediaType)mediaTypeForNativeMediaType:
(cricket::MediaType)nativeMediaType;
+ (cricket::MediaType)nativeMediaTypeForMediaType:(RTCRtpMediaType)mediaType; + (cricket::MediaType)nativeMediaTypeForMediaType:(RTCRtpMediaType)mediaType;

View File

@ -33,18 +33,19 @@ RTC_OBJC_EXPORT
/** Called when the first RTP packet is received. /** Called when the first RTP packet is received.
* *
* Note: Currently if there are multiple RtpReceivers of the same media type, * Note: Currently if there are multiple RtpReceivers of the same media
* they will all call OnFirstPacketReceived at once. * type, they will all call OnFirstPacketReceived at once.
* *
* For example, if we create three audio receivers, A/B/C, they will listen to * For example, if we create three audio receivers, A/B/C, they will listen
* the same signal from the underneath network layer. Whenever the first audio packet * to the same signal from the underneath network layer. Whenever the first
* is received, the underneath signal will be fired. All the receivers A/B/C will be * audio packet is received, the underneath signal will be fired. All the
* notified and the callback of the receiver's delegate will be called. * receivers A/B/C will be notified and the callback of the receiver's
* delegate will be called.
* *
* The process is the same for video receivers. * The process is the same for video receivers.
*/ */
- (void)rtpReceiver - (void)rtpReceiver : (RTC_OBJC_TYPE(RTCRtpReceiver) *)
: (RTC_OBJC_TYPE(RTCRtpReceiver) *)rtpReceiver didReceiveFirstPacketForMediaType rtpReceiver didReceiveFirstPacketForMediaType
: (RTCRtpMediaType)mediaType; : (RTCRtpMediaType)mediaType;
@end @end
@ -70,12 +71,13 @@ RTC_OBJC_EXPORT
* RTCMediaStreamTrack. Use isEqual: instead of == to compare * RTCMediaStreamTrack. Use isEqual: instead of == to compare
* RTCMediaStreamTrack instances. * RTCMediaStreamTrack instances.
*/ */
@property(nonatomic, readonly, nullable) RTC_OBJC_TYPE(RTCMediaStreamTrack) * track; @property(nonatomic, readonly, nullable) RTC_OBJC_TYPE(RTCMediaStreamTrack) *
track;
/** /**
Returns an array that contains an object for each unique SSRC (synchronization source) identifier Returns an array that contains an object for each unique SSRC (synchronization
and for each unique CSRC (contributing source) received by the current RTCRtpReceiver in the last source) identifier and for each unique CSRC (contributing source) received by
ten seconds. the current RTCRtpReceiver in the last ten seconds.
*/ */
@property(nonatomic, readonly) NSArray<RTC_OBJC_TYPE(RTCRtpSource) *> *sources; @property(nonatomic, readonly) NSArray<RTC_OBJC_TYPE(RTCRtpSource) *> *sources;

View File

@ -21,7 +21,8 @@
namespace webrtc { namespace webrtc {
RtpReceiverDelegateAdapter::RtpReceiverDelegateAdapter(RTC_OBJC_TYPE(RTCRtpReceiver) * receiver) { RtpReceiverDelegateAdapter::RtpReceiverDelegateAdapter(
RTC_OBJC_TYPE(RTCRtpReceiver) * receiver) {
RTC_CHECK(receiver); RTC_CHECK(receiver);
receiver_ = receiver; receiver_ = receiver;
} }
@ -31,7 +32,8 @@ void RtpReceiverDelegateAdapter::OnFirstPacketReceived(
RTCRtpMediaType packet_media_type = RTCRtpMediaType packet_media_type =
[RTC_OBJC_TYPE(RTCRtpReceiver) mediaTypeForNativeMediaType:media_type]; [RTC_OBJC_TYPE(RTCRtpReceiver) mediaTypeForNativeMediaType:media_type];
RTC_OBJC_TYPE(RTCRtpReceiver) *receiver = receiver_; RTC_OBJC_TYPE(RTCRtpReceiver) *receiver = receiver_;
[receiver.delegate rtpReceiver:receiver didReceiveFirstPacketForMediaType:packet_media_type]; [receiver.delegate rtpReceiver:receiver
didReceiveFirstPacketForMediaType:packet_media_type];
} }
} // namespace webrtc } // namespace webrtc
@ -55,25 +57,29 @@ void RtpReceiverDelegateAdapter::OnFirstPacketReceived(
- (nullable RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track { - (nullable RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track {
rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> nativeTrack( rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> nativeTrack(
_nativeRtpReceiver->track()); _nativeRtpReceiver->track());
if (nativeTrack) { if (nativeTrack) {
return [RTC_OBJC_TYPE(RTCMediaStreamTrack) mediaTrackForNativeTrack:nativeTrack return
factory:_factory]; [RTC_OBJC_TYPE(RTCMediaStreamTrack) mediaTrackForNativeTrack:nativeTrack
factory:_factory];
} }
return nil; return nil;
} }
- (NSString *)description { - (NSString *)description {
return [NSString return [NSString
stringWithFormat:@"RTC_OBJC_TYPE(RTCRtpReceiver) {\n receiverId: %@\n}", self.receiverId]; stringWithFormat:@"RTC_OBJC_TYPE(RTCRtpReceiver) {\n receiverId: %@\n}",
self.receiverId];
} }
- (NSArray<RTC_OBJC_TYPE(RTCRtpSource) *> *)sources { - (NSArray<RTC_OBJC_TYPE(RTCRtpSource) *> *)sources {
std::vector<webrtc::RtpSource> nativeSources = _nativeRtpReceiver->GetSources(); std::vector<webrtc::RtpSource> nativeSources =
_nativeRtpReceiver->GetSources();
NSMutableArray<RTC_OBJC_TYPE(RTCRtpSource) *> *result = NSMutableArray<RTC_OBJC_TYPE(RTCRtpSource) *> *result =
[[NSMutableArray alloc] initWithCapacity:nativeSources.size()]; [[NSMutableArray alloc] initWithCapacity:nativeSources.size()];
for (auto nativeSource : nativeSources) { for (auto nativeSource : nativeSources) {
[result addObject:[[RTC_OBJC_TYPE(RTCRtpSource) alloc] initWithNativeRtpSource:nativeSource]]; [result addObject:[[RTC_OBJC_TYPE(RTCRtpSource) alloc]
initWithNativeRtpSource:nativeSource]];
} }
return result; return result;
} }
@ -94,7 +100,8 @@ void RtpReceiverDelegateAdapter::OnFirstPacketReceived(
if (![object isMemberOfClass:[self class]]) { if (![object isMemberOfClass:[self class]]) {
return NO; return NO;
} }
RTC_OBJC_TYPE(RTCRtpReceiver) *receiver = (RTC_OBJC_TYPE(RTCRtpReceiver) *)object; RTC_OBJC_TYPE(RTCRtpReceiver) *receiver =
(RTC_OBJC_TYPE(RTCRtpReceiver) *)object;
return _nativeRtpReceiver == receiver.nativeRtpReceiver; return _nativeRtpReceiver == receiver.nativeRtpReceiver;
} }
@ -104,7 +111,8 @@ void RtpReceiverDelegateAdapter::OnFirstPacketReceived(
#pragma mark - Native #pragma mark - Native
- (void)setFrameDecryptor:(rtc::scoped_refptr<webrtc::FrameDecryptorInterface>)frameDecryptor { - (void)setFrameDecryptor:
(rtc::scoped_refptr<webrtc::FrameDecryptorInterface>)frameDecryptor {
_nativeRtpReceiver->SetFrameDecryptor(frameDecryptor); _nativeRtpReceiver->SetFrameDecryptor(frameDecryptor);
} }
@ -114,14 +122,17 @@ void RtpReceiverDelegateAdapter::OnFirstPacketReceived(
return _nativeRtpReceiver; return _nativeRtpReceiver;
} }
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)
nativeRtpReceiver: initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
(rtc::scoped_refptr<webrtc::RtpReceiverInterface>)nativeRtpReceiver { nativeRtpReceiver:
(rtc::scoped_refptr<webrtc::RtpReceiverInterface>)nativeRtpReceiver {
self = [super init]; self = [super init];
if (self) { if (self) {
_factory = factory; _factory = factory;
_nativeRtpReceiver = nativeRtpReceiver; _nativeRtpReceiver = nativeRtpReceiver;
RTCLogInfo(@"RTC_OBJC_TYPE(RTCRtpReceiver)(%p): created receiver: %@", self, self.description); RTCLogInfo(@"RTC_OBJC_TYPE(RTCRtpReceiver)(%p): created receiver: %@",
self,
self.description);
_observer.reset(new webrtc::RtpReceiverDelegateAdapter(self)); _observer.reset(new webrtc::RtpReceiverDelegateAdapter(self));
_nativeRtpReceiver->SetObserver(_observer.get()); _nativeRtpReceiver->SetObserver(_observer.get());
} }

View File

@ -16,17 +16,19 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
/** /**
* This class extension exposes methods that work directly with injectable C++ components. * This class extension exposes methods that work directly with injectable C++
* components.
*/ */
@interface RTC_OBJC_TYPE (RTCRtpSender) @interface RTC_OBJC_TYPE (RTCRtpSender)
() ()
/** Sets a defined frame encryptor that will encrypt the entire frame /** Sets a defined frame encryptor that will encrypt the entire frame
* before it is sent across the network. This will encrypt the entire frame * before it is sent across the network. This will encrypt the entire frame
* using the user provided encryption mechanism regardless of whether SRTP is * using the user provided encryption mechanism regardless of whether SRTP
* enabled or not. * is enabled or not.
*/ */
- (void)setFrameEncryptor : (rtc::scoped_refptr<webrtc::FrameEncryptorInterface>)frameEncryptor; - (void)setFrameEncryptor
: (rtc::scoped_refptr<webrtc::FrameEncryptorInterface>)frameEncryptor;
@end @end

View File

@ -19,12 +19,14 @@ NS_ASSUME_NONNULL_BEGIN
@interface RTC_OBJC_TYPE (RTCRtpSender) @interface RTC_OBJC_TYPE (RTCRtpSender)
() ()
@property(nonatomic, readonly) rtc::scoped_refptr<webrtc::RtpSenderInterface> nativeRtpSender; @property(nonatomic, readonly)
rtc::scoped_refptr<webrtc::RtpSenderInterface> nativeRtpSender;
/** Initialize an RTCRtpSender with a native RtpSenderInterface. */ /** Initialize an RTCRtpSender with a native RtpSenderInterface. */
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)initWithFactory:
nativeRtpSender:(rtc::scoped_refptr<webrtc::RtpSenderInterface>)nativeRtpSender (RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
NS_DESIGNATED_INITIALIZER; nativeRtpSender:(rtc::scoped_refptr<webrtc::RtpSenderInterface>)
nativeRtpSender NS_DESIGNATED_INITIALIZER;
@end @end

View File

@ -40,7 +40,8 @@ RTC_OBJC_EXPORT
@property(nonatomic, copy) NSArray<NSString *> *streamIds; @property(nonatomic, copy) NSArray<NSString *> *streamIds;
/** The RTCDtmfSender accociated with the RTP sender. */ /** The RTCDtmfSender accociated with the RTP sender. */
@property(nonatomic, readonly, nullable) id<RTC_OBJC_TYPE(RTCDtmfSender)> dtmfSender; @property(nonatomic, readonly, nullable) id<RTC_OBJC_TYPE(RTCDtmfSender)>
dtmfSender;
@end @end

View File

@ -37,29 +37,36 @@
- (void)setParameters:(RTC_OBJC_TYPE(RTCRtpParameters) *)parameters { - (void)setParameters:(RTC_OBJC_TYPE(RTCRtpParameters) *)parameters {
if (!_nativeRtpSender->SetParameters(parameters.nativeParameters).ok()) { if (!_nativeRtpSender->SetParameters(parameters.nativeParameters).ok()) {
RTCLogError(@"RTC_OBJC_TYPE(RTCRtpSender)(%p): Failed to set parameters: %@", self, parameters); RTCLogError(
@"RTC_OBJC_TYPE(RTCRtpSender)(%p): Failed to set parameters: %@",
self,
parameters);
} }
} }
- (RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track { - (RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track {
rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> nativeTrack( rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> nativeTrack(
_nativeRtpSender->track()); _nativeRtpSender->track());
if (nativeTrack) { if (nativeTrack) {
return [RTC_OBJC_TYPE(RTCMediaStreamTrack) mediaTrackForNativeTrack:nativeTrack return
factory:_factory]; [RTC_OBJC_TYPE(RTCMediaStreamTrack) mediaTrackForNativeTrack:nativeTrack
factory:_factory];
} }
return nil; return nil;
} }
- (void)setTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track { - (void)setTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track {
if (!_nativeRtpSender->SetTrack(track.nativeTrack.get())) { if (!_nativeRtpSender->SetTrack(track.nativeTrack.get())) {
RTCLogError(@"RTC_OBJC_TYPE(RTCRtpSender)(%p): Failed to set track %@", self, track); RTCLogError(@"RTC_OBJC_TYPE(RTCRtpSender)(%p): Failed to set track %@",
self,
track);
} }
} }
- (NSArray<NSString *> *)streamIds { - (NSArray<NSString *> *)streamIds {
std::vector<std::string> nativeStreamIds = _nativeRtpSender->stream_ids(); std::vector<std::string> nativeStreamIds = _nativeRtpSender->stream_ids();
NSMutableArray *streamIds = [NSMutableArray arrayWithCapacity:nativeStreamIds.size()]; NSMutableArray *streamIds =
[NSMutableArray arrayWithCapacity:nativeStreamIds.size()];
for (const auto &s : nativeStreamIds) { for (const auto &s : nativeStreamIds) {
[streamIds addObject:[NSString stringForStdString:s]]; [streamIds addObject:[NSString stringForStdString:s]];
} }
@ -76,7 +83,8 @@
- (NSString *)description { - (NSString *)description {
return [NSString return [NSString
stringWithFormat:@"RTC_OBJC_TYPE(RTCRtpSender) {\n senderId: %@\n}", self.senderId]; stringWithFormat:@"RTC_OBJC_TYPE(RTCRtpSender) {\n senderId: %@\n}",
self.senderId];
} }
- (BOOL)isEqual:(id)object { - (BOOL)isEqual:(id)object {
@ -99,7 +107,8 @@
#pragma mark - Native #pragma mark - Native
- (void)setFrameEncryptor:(rtc::scoped_refptr<webrtc::FrameEncryptorInterface>)frameEncryptor { - (void)setFrameEncryptor:
(rtc::scoped_refptr<webrtc::FrameEncryptorInterface>)frameEncryptor {
_nativeRtpSender->SetFrameEncryptor(frameEncryptor); _nativeRtpSender->SetFrameEncryptor(frameEncryptor);
} }
@ -109,8 +118,10 @@
return _nativeRtpSender; return _nativeRtpSender;
} }
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)
nativeRtpSender:(rtc::scoped_refptr<webrtc::RtpSenderInterface>)nativeRtpSender { initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
nativeRtpSender:
(rtc::scoped_refptr<webrtc::RtpSenderInterface>)nativeRtpSender {
NSParameterAssert(factory); NSParameterAssert(factory);
NSParameterAssert(nativeRtpSender); NSParameterAssert(nativeRtpSender);
self = [super init]; self = [super init];
@ -121,11 +132,13 @@
rtc::scoped_refptr<webrtc::DtmfSenderInterface> nativeDtmfSender( rtc::scoped_refptr<webrtc::DtmfSenderInterface> nativeDtmfSender(
_nativeRtpSender->GetDtmfSender()); _nativeRtpSender->GetDtmfSender());
if (nativeDtmfSender) { if (nativeDtmfSender) {
_dtmfSender = _dtmfSender = [[RTC_OBJC_TYPE(RTCDtmfSender) alloc]
[[RTC_OBJC_TYPE(RTCDtmfSender) alloc] initWithNativeDtmfSender:nativeDtmfSender]; initWithNativeDtmfSender:nativeDtmfSender];
} }
} }
RTCLogInfo(@"RTC_OBJC_TYPE(RTCRtpSender)(%p): created sender: %@", self, self.description); RTCLogInfo(@"RTC_OBJC_TYPE(RTCRtpSender)(%p): created sender: %@",
self,
self.description);
} }
return self; return self;
} }

View File

@ -27,29 +27,30 @@ RTC_OBJC_EXPORT
(RTCRtpSource)<NSObject> (RTCRtpSource)<NSObject>
/** /**
A positive integer value specifying the CSRC identifier of the contributing source or SSRC A positive integer value specifying the CSRC identifier of the contributing
identifier of the synchronization source. This uniquely identifies the source of the particular source or SSRC identifier of the synchronization source. This uniquely
stream RTP packets. */ identifies the source of the particular stream RTP packets. */
@property(nonatomic, readonly) uint32_t sourceId; @property(nonatomic, readonly) uint32_t sourceId;
@property(nonatomic, readonly) RTCRtpSourceType sourceType; @property(nonatomic, readonly) RTCRtpSourceType sourceType;
/** /**
A floating-point value between 0.0 and 1.0 specifying the audio level contained in the last RTP A floating-point value between 0.0 and 1.0 specifying the audio level contained
packet played from the contributing source. in the last RTP packet played from the contributing source.
*/ */
@property(nonatomic, readonly, nullable) NSNumber *audioLevel; @property(nonatomic, readonly, nullable) NSNumber *audioLevel;
/** /**
A timestamp indicating the most recent time at which a frame originating from this source was A timestamp indicating the most recent time at which a frame originating from
delivered to the receiver's track this source was delivered to the receiver's track
*/ */
@property(nonatomic, readonly) CFTimeInterval timestampUs; @property(nonatomic, readonly) CFTimeInterval timestampUs;
/** /**
The RTP timestamp of the media. This source-generated timestamp indicates the time at which the The RTP timestamp of the media. This source-generated timestamp indicates the
media in this packet, scheduled for play out at the time indicated by timestamp, was initially time at which the media in this packet, scheduled for play out at the time
sampled or generated. It may be useful for sequencing and synchronization purposes. indicated by timestamp, was initially sampled or generated. It may be useful for
sequencing and synchronization purposes.
*/ */
@property(nonatomic, readonly) uint32_t rtpTimestamp; @property(nonatomic, readonly) uint32_t rtpTimestamp;

View File

@ -37,7 +37,8 @@
- (RTCRtpSourceType)sourceType { - (RTCRtpSourceType)sourceType {
return [RTC_OBJC_TYPE(RTCRtpSource) return [RTC_OBJC_TYPE(RTCRtpSource)
rtpSourceTypeForNativeRtpSourceType:_nativeRtpSource.value().source_type()]; rtpSourceTypeForNativeRtpSourceType:_nativeRtpSource.value()
.source_type()];
} }
- (NSNumber *)audioLevel { - (NSNumber *)audioLevel {
@ -59,12 +60,14 @@
- (NSString *)description { - (NSString *)description {
return [NSString return [NSString
stringWithFormat:@"RTC_OBJC_TYPE(RTCRtpSource) {\n sourceId: %d, sourceType: %@\n}", stringWithFormat:
self.sourceId, @"RTC_OBJC_TYPE(RTCRtpSource) {\n sourceId: %d, sourceType: %@\n}",
[RTC_OBJC_TYPE(RTCRtpSource) stringForRtpSourceType:self.sourceType]]; self.sourceId,
[RTC_OBJC_TYPE(RTCRtpSource) stringForRtpSourceType:self.sourceType]];
} }
- (instancetype)initWithNativeRtpSource:(const webrtc::RtpSource &)nativeRtpSource { - (instancetype)initWithNativeRtpSource:
(const webrtc::RtpSource &)nativeRtpSource {
self = [super init]; self = [super init];
if (self) { if (self) {
_nativeRtpSource = nativeRtpSource; _nativeRtpSource = nativeRtpSource;
@ -72,7 +75,8 @@
return self; return self;
} }
+ (RTCRtpSourceType)rtpSourceTypeForNativeRtpSourceType:(webrtc::RtpSourceType)nativeRtpSourceType { + (RTCRtpSourceType)rtpSourceTypeForNativeRtpSourceType:
(webrtc::RtpSourceType)nativeRtpSourceType {
switch (nativeRtpSourceType) { switch (nativeRtpSourceType) {
case webrtc::RtpSourceType::SSRC: case webrtc::RtpSourceType::SSRC:
return RTCRtpSourceTypeSSRC; return RTCRtpSourceTypeSSRC;

View File

@ -26,14 +26,14 @@ NS_ASSUME_NONNULL_BEGIN
@interface RTC_OBJC_TYPE (RTCRtpTransceiver) @interface RTC_OBJC_TYPE (RTCRtpTransceiver)
() ()
@property(nonatomic, @property(nonatomic, readonly) rtc::scoped_refptr<
readonly) rtc::scoped_refptr<webrtc::RtpTransceiverInterface> nativeRtpTransceiver; webrtc::RtpTransceiverInterface> nativeRtpTransceiver;
/** Initialize an RTCRtpTransceiver with a native RtpTransceiverInterface. */ /** Initialize an RTCRtpTransceiver with a native RtpTransceiverInterface. */
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)
nativeRtpTransceiver: initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
(rtc::scoped_refptr<webrtc::RtpTransceiverInterface>)nativeRtpTransceiver nativeRtpTransceiver:(rtc::scoped_refptr<webrtc::RtpTransceiverInterface>)
NS_DESIGNATED_INITIALIZER; nativeRtpTransceiver NS_DESIGNATED_INITIALIZER;
+ (webrtc::RtpTransceiverDirection)nativeRtpTransceiverDirectionFromDirection: + (webrtc::RtpTransceiverDirection)nativeRtpTransceiverDirectionFromDirection:
(RTCRtpTransceiverDirection)direction; (RTCRtpTransceiverDirection)direction;

View File

@ -41,7 +41,8 @@ RTC_OBJC_EXPORT
@property(nonatomic) NSArray<NSString *> *streamIds; @property(nonatomic) NSArray<NSString *> *streamIds;
/** TODO(bugs.webrtc.org/7600): Not implemented. */ /** TODO(bugs.webrtc.org/7600): Not implemented. */
@property(nonatomic) NSArray<RTC_OBJC_TYPE(RTCRtpEncodingParameters) *> *sendEncodings; @property(nonatomic)
NSArray<RTC_OBJC_TYPE(RTCRtpEncodingParameters) *> *sendEncodings;
@end @end
@ -50,10 +51,10 @@ RTC_OBJC_EXPORT
@class RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability); @class RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability);
/** The RTCRtpTransceiver maps to the RTCRtpTransceiver defined by the /** The RTCRtpTransceiver maps to the RTCRtpTransceiver defined by the
* WebRTC specification. A transceiver represents a combination of an RTCRtpSender * WebRTC specification. A transceiver represents a combination of an
* and an RTCRtpReceiver that share a common mid. As defined in JSEP, an * RTCRtpSender and an RTCRtpReceiver that share a common mid. As defined in
* RTCRtpTransceiver is said to be associated with a media description if its * JSEP, an RTCRtpTransceiver is said to be associated with a media description
* mid property is non-nil; otherwise, it is said to be disassociated. * if its mid property is non-nil; otherwise, it is said to be disassociated.
* JSEP: https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-24 * JSEP: https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-24
* *
* Note that RTCRtpTransceivers are only supported when using * Note that RTCRtpTransceivers are only supported when using
@ -66,8 +67,8 @@ RTC_OBJC_EXPORT
@protocol RTC_OBJC_TYPE @protocol RTC_OBJC_TYPE
(RTCRtpTransceiver)<NSObject> (RTCRtpTransceiver)<NSObject>
/** Media type of the transceiver. The sender and receiver will also have this /** Media type of the transceiver. The sender and receiver will also have
* type. * this type.
*/ */
@property(nonatomic, readonly) RTCRtpMediaType mediaType; @property(nonatomic, readonly) RTCRtpMediaType mediaType;
@ -107,15 +108,18 @@ RTC_OBJC_EXPORT
@property(nonatomic, readonly) RTCRtpTransceiverDirection direction; @property(nonatomic, readonly) RTCRtpTransceiverDirection direction;
/** It will contain all the RTP header extensions that are supported. /** It will contain all the RTP header extensions that are supported.
* The direction attribute for all extensions that are mandatory to use MUST be initialized to an * The direction attribute for all extensions that are mandatory to use MUST be
* appropriate value other than RTCRtpTransceiverDirectionStopped. The direction attribute for * initialized to an appropriate value other than
* extensions that will not be offered by default in an initial offer MUST be initialized to * RTCRtpTransceiverDirectionStopped. The direction attribute for extensions
* RTCRtpTransceiverDirectionStopped. * that will not be offered by default in an initial offer MUST be initialized
* to RTCRtpTransceiverDirectionStopped.
*/ */
@property(nonatomic, readonly, copy) @property(nonatomic, readonly, copy)
NSArray<RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) *> *headerExtensionsToNegotiate; NSArray<RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) *>
*headerExtensionsToNegotiate;
@property(nonatomic, readonly, copy) @property(nonatomic, readonly, copy)
NSArray<RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) *> *negotiatedHeaderExtensions; NSArray<RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) *>
*negotiatedHeaderExtensions;
/** The currentDirection attribute indicates the current direction negotiated /** The currentDirection attribute indicates the current direction negotiated
* for this transceiver. If this transceiver has never been represented in an * for this transceiver. If this transceiver has never been represented in an
@ -135,19 +139,22 @@ RTC_OBJC_EXPORT
* by WebRTC for this transceiver. * by WebRTC for this transceiver.
* https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-setcodecpreferences * https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-setcodecpreferences
*/ */
- (BOOL)setCodecPreferences:(NSArray<RTC_OBJC_TYPE(RTCRtpCodecCapability) *> *_Nullable)codecs - (BOOL)setCodecPreferences:
(NSArray<RTC_OBJC_TYPE(RTCRtpCodecCapability) *> *_Nullable)codecs
error:(NSError **_Nullable)error; error:(NSError **_Nullable)error;
/** Deprecated version of [RTCRtpTransceiver setCodecPreferences:error:] */ /** Deprecated version of [RTCRtpTransceiver setCodecPreferences:error:] */
- (void)setCodecPreferences:(NSArray<RTC_OBJC_TYPE(RTCRtpCodecCapability) *> *_Nullable)codecs - (void)setCodecPreferences:
(NSArray<RTC_OBJC_TYPE(RTCRtpCodecCapability) *> *_Nullable)codecs
RTC_OBJC_DEPRECATED("Use setCodecPreferences:error: instead."); RTC_OBJC_DEPRECATED("Use setCodecPreferences:error: instead.");
/** The setHeaderExtensionsToNegotiate method overrides the default header extensions used /** The setHeaderExtensionsToNegotiate method overrides the default header
* by WebRTC for this transceiver. * extensions used by WebRTC for this transceiver.
* https://w3c.github.io/webrtc-extensions/#ref-for-dom-rtcrtptransceiver-setheaderextensionstonegotiate * https://w3c.github.io/webrtc-extensions/#ref-for-dom-rtcrtptransceiver-setheaderextensionstonegotiate
*/ */
- (BOOL)setHeaderExtensionsToNegotiate: - (BOOL)setHeaderExtensionsToNegotiate:
(NSArray<RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) *> *)extensions (NSArray<RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) *> *)
extensions
error:(NSError **)error; error:(NSError **)error;
/** An update of directionality does not take effect immediately. Instead, /** An update of directionality does not take effect immediately. Instead,
@ -155,7 +162,8 @@ RTC_OBJC_EXPORT
* descriptions as sendrecv, sendonly, recvonly, or inactive. * descriptions as sendrecv, sendonly, recvonly, or inactive.
* https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction * https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction
*/ */
- (void)setDirection:(RTCRtpTransceiverDirection)direction error:(NSError **)error; - (void)setDirection:(RTCRtpTransceiverDirection)direction
error:(NSError **)error;
@end @end

View File

@ -39,12 +39,13 @@ NSString *const kRTCRtpTransceiverErrorDomain = @"org.webrtc.RTCRtpTranceiver";
- (webrtc::RtpTransceiverInit)nativeInit { - (webrtc::RtpTransceiverInit)nativeInit {
webrtc::RtpTransceiverInit init; webrtc::RtpTransceiverInit init;
init.direction = init.direction = [RTC_OBJC_TYPE(RTCRtpTransceiver)
[RTC_OBJC_TYPE(RTCRtpTransceiver) nativeRtpTransceiverDirectionFromDirection:_direction]; nativeRtpTransceiverDirectionFromDirection:_direction];
for (NSString *streamId in _streamIds) { for (NSString *streamId in _streamIds) {
init.stream_ids.push_back([streamId UTF8String]); init.stream_ids.push_back([streamId UTF8String]);
} }
for (RTC_OBJC_TYPE(RTCRtpEncodingParameters) * sendEncoding in _sendEncodings) { for (RTC_OBJC_TYPE(RTCRtpEncodingParameters) *
sendEncoding in _sendEncodings) {
init.send_encodings.push_back(sendEncoding.nativeParameters); init.send_encodings.push_back(sendEncoding.nativeParameters);
} }
return init; return init;
@ -79,43 +80,53 @@ NSString *const kRTCRtpTransceiverErrorDomain = @"org.webrtc.RTCRtpTranceiver";
- (RTCRtpTransceiverDirection)direction { - (RTCRtpTransceiverDirection)direction {
return [RTC_OBJC_TYPE(RTCRtpTransceiver) return [RTC_OBJC_TYPE(RTCRtpTransceiver)
rtpTransceiverDirectionFromNativeDirection:_nativeRtpTransceiver->direction()]; rtpTransceiverDirectionFromNativeDirection:_nativeRtpTransceiver
->direction()];
} }
- (NSArray<RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) *> *)headerExtensionsToNegotiate { - (NSArray<RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) *> *)
headerExtensionsToNegotiate {
std::vector<webrtc::RtpHeaderExtensionCapability> nativeHeaderExtensions( std::vector<webrtc::RtpHeaderExtensionCapability> nativeHeaderExtensions(
_nativeRtpTransceiver->GetHeaderExtensionsToNegotiate()); _nativeRtpTransceiver->GetHeaderExtensionsToNegotiate());
NSMutableArray *headerExtensions = NSMutableArray *headerExtensions =
[NSMutableArray arrayWithCapacity:nativeHeaderExtensions.size()]; [NSMutableArray arrayWithCapacity:nativeHeaderExtensions.size()];
for (const auto &headerExtension : nativeHeaderExtensions) { for (const auto &headerExtension : nativeHeaderExtensions) {
[headerExtensions addObject:[[RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) alloc] [headerExtensions
initWithNativeRtpHeaderExtensionCapability:headerExtension]]; addObject:
[[RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) alloc]
initWithNativeRtpHeaderExtensionCapability:headerExtension]];
} }
return headerExtensions; return headerExtensions;
} }
- (NSArray<RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) *> *)negotiatedHeaderExtensions { - (NSArray<RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) *> *)
negotiatedHeaderExtensions {
std::vector<webrtc::RtpHeaderExtensionCapability> nativeHeaderExtensions( std::vector<webrtc::RtpHeaderExtensionCapability> nativeHeaderExtensions(
_nativeRtpTransceiver->GetNegotiatedHeaderExtensions()); _nativeRtpTransceiver->GetNegotiatedHeaderExtensions());
NSMutableArray *headerExtensions = NSMutableArray *headerExtensions =
[NSMutableArray arrayWithCapacity:nativeHeaderExtensions.size()]; [NSMutableArray arrayWithCapacity:nativeHeaderExtensions.size()];
for (const auto &headerExtension : nativeHeaderExtensions) { for (const auto &headerExtension : nativeHeaderExtensions) {
[headerExtensions addObject:[[RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) alloc] [headerExtensions
initWithNativeRtpHeaderExtensionCapability:headerExtension]]; addObject:
[[RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) alloc]
initWithNativeRtpHeaderExtensionCapability:headerExtension]];
} }
return headerExtensions; return headerExtensions;
} }
- (void)setDirection:(RTCRtpTransceiverDirection)direction error:(NSError **)error { - (void)setDirection:(RTCRtpTransceiverDirection)direction
error:(NSError **)error {
webrtc::RTCError nativeError = _nativeRtpTransceiver->SetDirectionWithError( webrtc::RTCError nativeError = _nativeRtpTransceiver->SetDirectionWithError(
[RTC_OBJC_TYPE(RTCRtpTransceiver) nativeRtpTransceiverDirectionFromDirection:direction]); [RTC_OBJC_TYPE(RTCRtpTransceiver)
nativeRtpTransceiverDirectionFromDirection:direction]);
if (!nativeError.ok() && error) { if (!nativeError.ok() && error) {
NSDictionary *userInfo = @{ NSDictionary *userInfo = @{
NSLocalizedDescriptionKey : [NSString stringWithCString:nativeError.message() NSLocalizedDescriptionKey :
encoding:NSUTF8StringEncoding] [NSString stringWithCString:nativeError.message()
encoding:NSUTF8StringEncoding]
}; };
*error = [NSError errorWithDomain:kRTCRtpTransceiverErrorDomain *error = [NSError errorWithDomain:kRTCRtpTransceiverErrorDomain
code:static_cast<int>(nativeError.type()) code:static_cast<int>(nativeError.type())
@ -126,7 +137,8 @@ NSString *const kRTCRtpTransceiverErrorDomain = @"org.webrtc.RTCRtpTranceiver";
- (BOOL)currentDirection:(RTCRtpTransceiverDirection *)currentDirectionOut { - (BOOL)currentDirection:(RTCRtpTransceiverDirection *)currentDirectionOut {
if (_nativeRtpTransceiver->current_direction()) { if (_nativeRtpTransceiver->current_direction()) {
*currentDirectionOut = [RTC_OBJC_TYPE(RTCRtpTransceiver) *currentDirectionOut = [RTC_OBJC_TYPE(RTCRtpTransceiver)
rtpTransceiverDirectionFromNativeDirection:*_nativeRtpTransceiver->current_direction()]; rtpTransceiverDirectionFromNativeDirection:*_nativeRtpTransceiver
->current_direction()];
return YES; return YES;
} else { } else {
return NO; return NO;
@ -137,7 +149,8 @@ NSString *const kRTCRtpTransceiverErrorDomain = @"org.webrtc.RTCRtpTranceiver";
_nativeRtpTransceiver->StopInternal(); _nativeRtpTransceiver->StopInternal();
} }
- (BOOL)setCodecPreferences:(NSArray<RTC_OBJC_TYPE(RTCRtpCodecCapability) *> *)codecs - (BOOL)setCodecPreferences:
(NSArray<RTC_OBJC_TYPE(RTCRtpCodecCapability) *> *)codecs
error:(NSError **)error { error:(NSError **)error {
std::vector<webrtc::RtpCodecCapability> codecCapabilities; std::vector<webrtc::RtpCodecCapability> codecCapabilities;
if (codecs) { if (codecs) {
@ -145,34 +158,43 @@ NSString *const kRTCRtpTransceiverErrorDomain = @"org.webrtc.RTCRtpTranceiver";
codecCapabilities.push_back(rtpCodecCapability.nativeRtpCodecCapability); codecCapabilities.push_back(rtpCodecCapability.nativeRtpCodecCapability);
} }
} }
webrtc::RTCError nativeError = _nativeRtpTransceiver->SetCodecPreferences(codecCapabilities); webrtc::RTCError nativeError =
_nativeRtpTransceiver->SetCodecPreferences(codecCapabilities);
if (!nativeError.ok() && error) { if (!nativeError.ok() && error) {
*error = [NSError *error = [NSError errorWithDomain:kRTCRtpTransceiverErrorDomain
errorWithDomain:kRTCRtpTransceiverErrorDomain code:static_cast<int>(nativeError.type())
code:static_cast<int>(nativeError.type()) userInfo:@{
userInfo:@{@"message" : [NSString stringWithUTF8String:nativeError.message()]}]; @"message" : [NSString
stringWithUTF8String:nativeError.message()]
}];
} }
return nativeError.ok(); return nativeError.ok();
} }
- (void)setCodecPreferences:(NSArray<RTC_OBJC_TYPE(RTCRtpCodecCapability) *> *)codecs { - (void)setCodecPreferences:
(NSArray<RTC_OBJC_TYPE(RTCRtpCodecCapability) *> *)codecs {
[self setCodecPreferences:codecs error:nil]; [self setCodecPreferences:codecs error:nil];
} }
- (BOOL)setHeaderExtensionsToNegotiate: - (BOOL)setHeaderExtensionsToNegotiate:
(NSArray<RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) *> *)extensions (NSArray<RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) *> *)
extensions
error:(NSError **)error { error:(NSError **)error {
std::vector<webrtc::RtpHeaderExtensionCapability> headerExtensionCapabilities; std::vector<webrtc::RtpHeaderExtensionCapability> headerExtensionCapabilities;
for (RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) * extension in extensions) { for (RTC_OBJC_TYPE(RTCRtpHeaderExtensionCapability) *
headerExtensionCapabilities.push_back(extension.nativeRtpHeaderExtensionCapability); extension in extensions) {
headerExtensionCapabilities.push_back(
extension.nativeRtpHeaderExtensionCapability);
} }
webrtc::RTCError nativeError = webrtc::RTCError nativeError =
_nativeRtpTransceiver->SetHeaderExtensionsToNegotiate(headerExtensionCapabilities); _nativeRtpTransceiver->SetHeaderExtensionsToNegotiate(
headerExtensionCapabilities);
BOOL ok = nativeError.ok(); BOOL ok = nativeError.ok();
if (!ok && error) { if (!ok && error) {
NSDictionary *userInfo = @{ NSDictionary *userInfo = @{
NSLocalizedDescriptionKey : [NSString stringWithCString:nativeError.message() NSLocalizedDescriptionKey :
encoding:NSUTF8StringEncoding] [NSString stringWithCString:nativeError.message()
encoding:NSUTF8StringEncoding]
}; };
*error = [NSError errorWithDomain:kRTCRtpTransceiverErrorDomain *error = [NSError errorWithDomain:kRTCRtpTransceiverErrorDomain
code:static_cast<int>(nativeError.type()) code:static_cast<int>(nativeError.type())
@ -182,10 +204,10 @@ NSString *const kRTCRtpTransceiverErrorDomain = @"org.webrtc.RTCRtpTranceiver";
} }
- (NSString *)description { - (NSString *)description {
return [NSString return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCRtpTransceiver) {\n "
stringWithFormat:@"RTC_OBJC_TYPE(RTCRtpTransceiver) {\n sender: %@\n receiver: %@\n}", @"sender: %@\n receiver: %@\n}",
_sender, _sender,
_receiver]; _receiver];
} }
- (BOOL)isEqual:(id)object { - (BOOL)isEqual:(id)object {
@ -198,7 +220,8 @@ NSString *const kRTCRtpTransceiverErrorDomain = @"org.webrtc.RTCRtpTranceiver";
if (![object isMemberOfClass:[self class]]) { if (![object isMemberOfClass:[self class]]) {
return NO; return NO;
} }
RTC_OBJC_TYPE(RTCRtpTransceiver) *transceiver = (RTC_OBJC_TYPE(RTCRtpTransceiver) *)object; RTC_OBJC_TYPE(RTCRtpTransceiver) *transceiver =
(RTC_OBJC_TYPE(RTCRtpTransceiver) *)object;
return _nativeRtpTransceiver == transceiver.nativeRtpTransceiver; return _nativeRtpTransceiver == transceiver.nativeRtpTransceiver;
} }
@ -212,28 +235,31 @@ NSString *const kRTCRtpTransceiverErrorDomain = @"org.webrtc.RTCRtpTranceiver";
return _nativeRtpTransceiver; return _nativeRtpTransceiver;
} }
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory - (instancetype)
nativeRtpTransceiver: initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
(rtc::scoped_refptr<webrtc::RtpTransceiverInterface>)nativeRtpTransceiver { nativeRtpTransceiver:(rtc::scoped_refptr<webrtc::RtpTransceiverInterface>)
nativeRtpTransceiver {
NSParameterAssert(factory); NSParameterAssert(factory);
NSParameterAssert(nativeRtpTransceiver); NSParameterAssert(nativeRtpTransceiver);
self = [super init]; self = [super init];
if (self) { if (self) {
_factory = factory; _factory = factory;
_nativeRtpTransceiver = nativeRtpTransceiver; _nativeRtpTransceiver = nativeRtpTransceiver;
_sender = [[RTC_OBJC_TYPE(RTCRtpSender) alloc] initWithFactory:_factory _sender = [[RTC_OBJC_TYPE(RTCRtpSender) alloc]
nativeRtpSender:nativeRtpTransceiver->sender()]; initWithFactory:_factory
_receiver = nativeRtpSender:nativeRtpTransceiver->sender()];
[[RTC_OBJC_TYPE(RTCRtpReceiver) alloc] initWithFactory:_factory _receiver = [[RTC_OBJC_TYPE(RTCRtpReceiver) alloc]
nativeRtpReceiver:nativeRtpTransceiver->receiver()]; initWithFactory:_factory
RTCLogInfo( nativeRtpReceiver:nativeRtpTransceiver->receiver()];
@"RTC_OBJC_TYPE(RTCRtpTransceiver)(%p): created transceiver: %@", self, self.description); RTCLogInfo(@"RTC_OBJC_TYPE(RTCRtpTransceiver)(%p): created transceiver: %@",
self,
self.description);
} }
return self; return self;
} }
+ (webrtc::RtpTransceiverDirection)nativeRtpTransceiverDirectionFromDirection: + (webrtc::RtpTransceiverDirection)nativeRtpTransceiverDirectionFromDirection:
(RTCRtpTransceiverDirection)direction { (RTCRtpTransceiverDirection)direction {
switch (direction) { switch (direction) {
case RTCRtpTransceiverDirectionSendRecv: case RTCRtpTransceiverDirectionSendRecv:
return webrtc::RtpTransceiverDirection::kSendRecv; return webrtc::RtpTransceiverDirection::kSendRecv;
@ -249,7 +275,7 @@ NSString *const kRTCRtpTransceiverErrorDomain = @"org.webrtc.RTCRtpTranceiver";
} }
+ (RTCRtpTransceiverDirection)rtpTransceiverDirectionFromNativeDirection: + (RTCRtpTransceiverDirection)rtpTransceiverDirectionFromNativeDirection:
(webrtc::RtpTransceiverDirection)nativeDirection { (webrtc::RtpTransceiverDirection)nativeDirection {
switch (nativeDirection) { switch (nativeDirection) {
case webrtc::RtpTransceiverDirection::kSendRecv: case webrtc::RtpTransceiverDirection::kSendRecv:
return RTCRtpTransceiverDirectionSendRecv; return RTCRtpTransceiverDirectionSendRecv;

View File

@ -19,11 +19,11 @@ NS_ASSUME_NONNULL_BEGIN
/** /**
* The native SessionDescriptionInterface representation of this * The native SessionDescriptionInterface representation of this
* RTCSessionDescription object. This is needed to pass to the underlying C++ * RTCSessionDescription object. This is needed to pass to the underlying
* APIs. * C++ APIs.
*/ */
@property(nonatomic, @property(nonatomic, readonly)
readonly) std::unique_ptr<webrtc::SessionDescriptionInterface> nativeDescription; std::unique_ptr<webrtc::SessionDescriptionInterface> nativeDescription;
/** /**
* Initialize an RTCSessionDescription from a native * Initialize an RTCSessionDescription from a native

View File

@ -37,7 +37,8 @@ RTC_OBJC_EXPORT
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
/** Initialize a session description with a type and SDP string. */ /** Initialize a session description with a type and SDP string. */
- (instancetype)initWithType:(RTCSdpType)type sdp:(NSString *)sdp NS_DESIGNATED_INITIALIZER; - (instancetype)initWithType:(RTCSdpType)type
sdp:(NSString *)sdp NS_DESIGNATED_INITIALIZER;
+ (NSString *)stringForType:(RTCSdpType)type; + (NSString *)stringForType:(RTCSdpType)type;

View File

@ -41,9 +41,10 @@
} }
- (NSString *)description { - (NSString *)description {
return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCSessionDescription):\n%@\n%@", return [NSString
[[self class] stringForType:_type], stringWithFormat:@"RTC_OBJC_TYPE(RTCSessionDescription):\n%@\n%@",
_sdp]; [[self class] stringForType:_type],
_sdp];
} }
#pragma mark - Private #pragma mark - Private
@ -51,8 +52,9 @@
- (std::unique_ptr<webrtc::SessionDescriptionInterface>)nativeDescription { - (std::unique_ptr<webrtc::SessionDescriptionInterface>)nativeDescription {
webrtc::SdpParseError error; webrtc::SdpParseError error;
std::unique_ptr<webrtc::SessionDescriptionInterface> description(webrtc::CreateSessionDescription( std::unique_ptr<webrtc::SessionDescriptionInterface> description(
[[self class] nativeTypeForType:_type], _sdp.stdString, &error)); webrtc::CreateSessionDescription(
[[self class] nativeTypeForType:_type], _sdp.stdString, &error));
if (!description) { if (!description) {
RTCLogError(@"Failed to create session description: %s\nline: %s", RTCLogError(@"Failed to create session description: %s\nline: %s",
@ -70,8 +72,7 @@
nativeDescription->ToString(&sdp); nativeDescription->ToString(&sdp);
RTCSdpType type = [[self class] typeForStdString:nativeDescription->type()]; RTCSdpType type = [[self class] typeForStdString:nativeDescription->type()];
return [self initWithType:type return [self initWithType:type sdp:[NSString stringForStdString:sdp]];
sdp:[NSString stringForStdString:sdp]];
} }
+ (std::string)stdStringForType:(RTCSdpType)type { + (std::string)stdStringForType:(RTCSdpType)type {

Some files were not shown because too many files have changed in this diff Show More