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
* 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
* to this interface will be adapted and passed to the RTCVideoRenderer supplied
* 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. */
- (instancetype)initWithNativeRenderer:(id<RTC_OBJC_TYPE(RTCVideoRenderer)>)videoRenderer
- (instancetype)initWithNativeRenderer:
(id<RTC_OBJC_TYPE(RTCVideoRenderer)>)videoRenderer
NS_DESIGNATED_INITIALIZER;
@end

View File

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

View File

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

View File

@ -42,24 +42,32 @@ class CallbackLogSink final : public rtc::LogSink {
class CallbackWithSeverityLogSink final : public rtc::LogSink {
public:
CallbackWithSeverityLogSink(RTCCallbackLoggerMessageAndSeverityHandler callbackHandler)
CallbackWithSeverityLogSink(
RTCCallbackLoggerMessageAndSeverityHandler 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);
}
void OnLogMessage(absl::string_view message, rtc::LoggingSeverity severity) override {
void OnLogMessage(absl::string_view message,
rtc::LoggingSeverity severity) override {
if (callback_handler_) {
RTCLoggingSeverity loggingSeverity = NativeSeverityToObjcSeverity(severity);
callback_handler_([NSString stringForAbslStringView:message], loggingSeverity);
RTCLoggingSeverity loggingSeverity =
NativeSeverityToObjcSeverity(severity);
callback_handler_([NSString stringForAbslStringView:message],
loggingSeverity);
}
}
private:
static RTCLoggingSeverity NativeSeverityToObjcSeverity(rtc::LoggingSeverity severity) {
static RTCLoggingSeverity NativeSeverityToObjcSeverity(
rtc::LoggingSeverity severity) {
switch (severity) {
case rtc::LS_VERBOSE:
return RTCLoggingSeverityVerbose;
@ -77,7 +85,7 @@ class CallbackWithSeverityLogSink final : public rtc::LogSink {
RTCCallbackLoggerMessageAndSeverityHandler callback_handler_;
};
}
} // namespace
@implementation RTC_OBJC_TYPE (RTCCallbackLogger) {
BOOL _hasStarted;

View File

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

View File

@ -18,7 +18,8 @@
@synthesize volume = _volume;
@synthesize nativeAudioSource = _nativeAudioSource;
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
- (instancetype)
initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
nativeAudioSource:
(rtc::scoped_refptr<webrtc::AudioSourceInterface>)nativeAudioSource {
RTC_DCHECK(factory);
@ -33,8 +34,10 @@
return self;
}
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
nativeMediaSource:(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource
- (instancetype)
initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
nativeMediaSource:
(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource
type:(RTCMediaSourceType)type {
RTC_DCHECK_NOTREACHED();
return nil;
@ -42,7 +45,9 @@
- (NSString *)description {
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 {

View File

@ -19,10 +19,12 @@ NS_ASSUME_NONNULL_BEGIN
()
/** 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. */
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
- (instancetype)initWithFactory:
(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
source:(RTC_OBJC_TYPE(RTCAudioSource) *)source
trackId:(NSString *)trackId;

View File

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

View File

@ -24,10 +24,12 @@ RTC_OBJC_EXPORT
@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
certificate:(NSString *)certificate NS_DESIGNATED_INITIALIZER;
certificate:(NSString *)certificate
NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
@ -37,7 +39,8 @@ RTC_OBJC_EXPORT
* provided.
* - name: "ECDSA" or "RSASSA-PKCS1-v1_5"
*/
+ (nullable RTC_OBJC_TYPE(RTCCertificate) *)generateCertificateWithParams:(NSDictionary *)params;
+ (nullable RTC_OBJC_TYPE(RTCCertificate) *)generateCertificateWithParams:
(NSDictionary *)params;
@end

View File

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

View File

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

View File

@ -35,7 +35,10 @@ typedef NS_ENUM(NSInteger, RTCBundlePolicy) {
};
/** Represents the rtcp mux policy. */
typedef NS_ENUM(NSInteger, RTCRtcpMuxPolicy) { RTCRtcpMuxPolicyNegotiate, RTCRtcpMuxPolicyRequire };
typedef NS_ENUM(NSInteger, RTCRtcpMuxPolicy) {
RTCRtcpMuxPolicyNegotiate,
RTCRtcpMuxPolicyRequire
};
/** Represents the tcp candidate policy. */
typedef NS_ENUM(NSInteger, RTCTcpCandidatePolicy) {
@ -95,7 +98,8 @@ RTC_OBJC_EXPORT
@property(nonatomic, assign) RTCRtcpMuxPolicy rtcpMuxPolicy;
@property(nonatomic, assign) RTCTcpCandidatePolicy tcpCandidatePolicy;
@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.
* 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,
* 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
* check packets.
@ -225,7 +230,8 @@ RTC_OBJC_EXPORT
* when ICE is strongly connected, and it overrides the
* 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

View File

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

View File

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

View File

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

View File

@ -21,8 +21,8 @@ NS_ASSUME_NONNULL_BEGIN
()
/**
* The native DataBuffer representation of this RTCDatabuffer object. This is
* needed to pass to the underlying C++ APIs.
* The native DataBuffer representation of this RTCDatabuffer object. This
* is needed to pass to the underlying C++ APIs.
*/
@property(nonatomic, readonly) const webrtc::DataBuffer *nativeDataBuffer;
@ -37,7 +37,8 @@ NS_ASSUME_NONNULL_BEGIN
/** Initialize an RTCDataChannel from a native DataChannelInterface. */
- (instancetype)initWithFactory
: (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:
(RTCDataChannelState)state;

View File

@ -40,7 +40,8 @@ RTC_OBJC_EXPORT
(RTCDataChannelDelegate)<NSObject>
/** 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. */
- (void)dataChannel:(RTC_OBJC_TYPE(RTCDataChannel) *)dataChannel
@ -77,7 +78,8 @@ RTC_OBJC_EXPORT
@property(nonatomic, readonly) BOOL isOrdered;
/** 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

View File

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

View File

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

View File

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

View File

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

View File

@ -30,7 +30,8 @@
RTC_DCHECK(tones != nil);
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(
[NSString stdStringForString:tones], durationMs, interToneGapMs);
}
@ -40,7 +41,8 @@
}
- (NSTimeInterval)duration {
return static_cast<NSTimeInterval>(_nativeDtmfSender->duration()) / rtc::kNumMillisecsPerSec;
return static_cast<NSTimeInterval>(_nativeDtmfSender->duration()) /
rtc::kNumMillisecsPerSec;
}
- (NSTimeInterval)interToneGap {
@ -49,7 +51,9 @@
}
- (NSString *)description {
return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCDtmfSender) {\n remainingTones: %@\n "
return
[NSString stringWithFormat:
@"RTC_OBJC_TYPE(RTCDtmfSender) {\n remainingTones: %@\n "
@"duration: %f sec\n interToneGap: %f sec\n}",
[self remainingTones],
[self duration],
@ -68,8 +72,9 @@
self = [super init];
if (self) {
_nativeDtmfSender = nativeDtmfSender;
RTCLogInfo(
@"RTC_OBJC_TYPE(RTCDtmfSender)(%p): created DTMF sender: %@", self, self.description);
RTCLogInfo(@"RTC_OBJC_TYPE(RTCDtmfSender)(%p): created DTMF sender: %@",
self,
self.description);
}
return self;
}

View File

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

View File

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

View File

@ -12,7 +12,8 @@
#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 kRTCFieldTrialFlexFec03AdvertisedKey;
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
* 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"
NSString *const kRTCFieldTrialAudioForceABWENoTWCCKey = @"WebRTC-Audio-ABWENoTWCC";
NSString * const kRTCFieldTrialFlexFec03AdvertisedKey = @"WebRTC-FlexFEC-03-Advertised";
NSString * const kRTCFieldTrialFlexFec03Key = @"WebRTC-FlexFEC-03";
NSString * const kRTCFieldTrialH264HighProfileKey = @"WebRTC-H264HighProfile";
NSString * const kRTCFieldTrialMinimizeResamplingOnMobileKey =
NSString *const kRTCFieldTrialAudioForceABWENoTWCCKey =
@"WebRTC-Audio-ABWENoTWCC";
NSString *const kRTCFieldTrialFlexFec03AdvertisedKey =
@"WebRTC-FlexFEC-03-Advertised";
NSString *const kRTCFieldTrialFlexFec03Key = @"WebRTC-FlexFEC-03";
NSString *const kRTCFieldTrialH264HighProfileKey = @"WebRTC-H264HighProfile";
NSString *const kRTCFieldTrialMinimizeResamplingOnMobileKey =
@"WebRTC-Audio-MinimizeResamplingOnMobile";
NSString *const kRTCFieldTrialUseNWPathMonitor = @"WebRTC-Network-UseNWPathMonitor";
NSString * const kRTCFieldTrialEnabledValue = @"Enabled";
NSString *const kRTCFieldTrialUseNWPathMonitor =
@"WebRTC-Network-UseNWPathMonitor";
NSString *const kRTCFieldTrialEnabledValue = @"Enabled";
// InitFieldTrialsFromString stores the char*, so the char array must outlive
// the application.
static char *gFieldTrialInitString = nullptr;
void RTCInitFieldTrialDictionary(NSDictionary<NSString *, NSString *> *fieldTrials) {
void RTCInitFieldTrialDictionary(
NSDictionary<NSString *, NSString *> *fieldTrials) {
if (!fieldTrials) {
RTCLogWarning(@"No fieldTrials provided.");
return;
}
// 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];
for (NSString *key in fieldTrials) {
NSString *fieldTrialEntry = [NSString stringWithFormat:@"%@/%@/", key, fieldTrials[key]];
NSString *fieldTrialEntry =
[NSString stringWithFormat:@"%@/%@/", key, fieldTrials[key]];
[fieldTrialInitString appendString:fieldTrialEntry];
}
size_t len = fieldTrialInitString.length + 1;

View File

@ -52,11 +52,13 @@ RTC_OBJC_EXPORT
- (instancetype)init;
// 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
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
// existing file(s).

View File

@ -38,8 +38,7 @@ const char *kRTCFileLoggerRotatingLogPrefix = "rotating_log";
NSString *documentsDirPath = [paths firstObject];
NSString *defaultDirPath =
[documentsDirPath stringByAppendingPathComponent:kDefaultLogDirName];
return [self initWithDirPath:defaultDirPath
maxFileSize:kDefaultMaxFileSize];
return [self initWithDirPath:defaultDirPath maxFileSize:kDefaultMaxFileSize];
}
- (instancetype)initWithDirPath:(NSString *)dirPath
@ -96,13 +95,13 @@ const char *kRTCFileLoggerRotatingLogPrefix = "rotating_log";
_maxFileSize / 10));
break;
case RTCFileLoggerTypeCall:
_logSink.reset(
new rtc::CallSessionFileRotatingLogSink(_dirPath.UTF8String,
_maxFileSize));
_logSink.reset(new rtc::CallSessionFileRotatingLogSink(
_dirPath.UTF8String, _maxFileSize));
break;
}
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();
return;
}
@ -129,15 +128,16 @@ const char *kRTCFileLoggerRotatingLogPrefix = "rotating_log";
if (_hasStarted) {
return nil;
}
NSMutableData* logData = [NSMutableData data];
NSMutableData *logData = [NSMutableData data];
std::unique_ptr<rtc::FileRotatingStreamReader> stream;
switch(_rotationType) {
switch (_rotationType) {
case RTCFileLoggerTypeApp:
stream = std::make_unique<rtc::FileRotatingStreamReader>(_dirPath.UTF8String,
kRTCFileLoggerRotatingLogPrefix);
stream = std::make_unique<rtc::FileRotatingStreamReader>(
_dirPath.UTF8String, kRTCFileLoggerRotatingLogPrefix);
break;
case RTCFileLoggerTypeCall:
stream = std::make_unique<rtc::CallSessionFileRotatingStreamReader>(_dirPath.UTF8String);
stream = std::make_unique<rtc::CallSessionFileRotatingStreamReader>(
_dirPath.UTF8String);
break;
}
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
// 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);
logData = [[NSMutableData alloc] initWithBytesNoCopy:buffer.release()
length:read];

View File

@ -23,13 +23,15 @@ NS_ASSUME_NONNULL_BEGIN
* The native IceCandidateInterface representation of this RTCIceCandidate
* 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
* ownership is taken of the native candidate.
*/
- (instancetype)initWithNativeCandidate:(const webrtc::IceCandidateInterface *)candidate;
- (instancetype)initWithNativeCandidate:
(const webrtc::IceCandidateInterface *)candidate;
@end

View File

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

View File

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

View File

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

View File

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

View File

@ -21,10 +21,12 @@ NS_ASSUME_NONNULL_BEGIN
* IceServer struct representation of this RTCIceServer object's data.
* 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. */
- (instancetype)initWithNativeServer:(webrtc::PeerConnectionInterface::IceServer)nativeServer;
- (instancetype)initWithNativeServer:
(webrtc::PeerConnectionInterface::IceServer)nativeServer;
@end

View File

@ -100,7 +100,8 @@ RTC_OBJC_EXPORT
* optional credential, TLS cert policy, hostname, ALPN protocols and
* elliptic curves.
*/
- (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings
- (instancetype)
initWithURLStrings:(NSArray<NSString *> *)urlStrings
username:(nullable NSString *)username
credential:(nullable NSString *)credential
tlsCertPolicy:(RTCTlsCertPolicy)tlsCertPolicy

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -24,16 +24,20 @@ typedef NS_ENUM(NSInteger, RTCMediaSourceType) {
@interface RTC_OBJC_TYPE (RTCMediaSource)
()
@property(nonatomic,
readonly) rtc::scoped_refptr<webrtc::MediaSourceInterface> nativeMediaSource;
@property(nonatomic, readonly)
rtc::scoped_refptr<webrtc::MediaSourceInterface> nativeMediaSource;
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
nativeMediaSource:(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource
- (instancetype)
initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
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;

View File

@ -19,8 +19,10 @@
@synthesize nativeMediaSource = _nativeMediaSource;
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
nativeMediaSource:(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource
- (instancetype)
initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
nativeMediaSource:
(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource
type:(RTCMediaSourceType)type {
RTC_DCHECK(factory);
RTC_DCHECK(nativeMediaSource);

View File

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

View File

@ -25,7 +25,8 @@ RTC_OBJC_EXPORT
@property(nonatomic, strong, readonly) NSArray<RTC_OBJC_TYPE(RTCAudioTrack) *> *audioTracks;
/** 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. */
@property(nonatomic, readonly) NSString *streamId;

View File

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

View File

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

View File

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

View File

@ -20,4 +20,5 @@
RTC_EXTERN void RTCEnableMetrics(void);
/** 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) {
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;
webrtc::metrics::GetAndReset(&histograms);
@ -27,7 +29,8 @@ NSArray<RTC_OBJC_TYPE(RTCMetricsSampleInfo) *> *RTCGetAndResetMetrics(void) {
[NSMutableArray arrayWithCapacity:histograms.size()];
for (auto const &histogram : histograms) {
RTC_OBJC_TYPE(RTCMetricsSampleInfo) *metric =
[[RTC_OBJC_TYPE(RTCMetricsSampleInfo) alloc] initWithNativeSampleInfo:*histogram.second];
[[RTC_OBJC_TYPE(RTCMetricsSampleInfo) alloc]
initWithNativeSampleInfo:*histogram.second];
[metrics addObject:metric];
}
return metrics;

View File

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

View File

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

View File

@ -22,29 +22,36 @@ namespace webrtc {
*/
class PeerConnectionDelegateAdapter : public PeerConnectionObserver {
public:
PeerConnectionDelegateAdapter(RTC_OBJC_TYPE(RTCPeerConnection) * peerConnection);
PeerConnectionDelegateAdapter(RTC_OBJC_TYPE(RTCPeerConnection) *
peerConnection);
~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 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 OnIceConnectionChange(PeerConnectionInterface::IceConnectionState new_state) override;
void OnIceConnectionChange(
PeerConnectionInterface::IceConnectionState new_state) override;
void OnStandardizedIceConnectionChange(
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;
@ -54,14 +61,18 @@ class PeerConnectionDelegateAdapter : public PeerConnectionObserver {
int error_code,
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,
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:
__weak RTC_OBJC_TYPE(RTCPeerConnection) * peer_connection_;
@ -79,7 +90,8 @@ class PeerConnectionDelegateAdapter : public PeerConnectionObserver {
factory;
/** The native PeerConnectionInterface created during construction. */
@property(nonatomic, readonly) rtc::scoped_refptr<webrtc::PeerConnectionInterface>
@property(nonatomic, readonly)
rtc::scoped_refptr<webrtc::PeerConnectionInterface>
nativePeerConnection;
/** Initialize an RTCPeerConnection with a configuration, constraints, and
@ -89,8 +101,10 @@ class PeerConnectionDelegateAdapter : public PeerConnectionObserver {
initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
configuration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration
constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
certificateVerifier:(nullable id<RTC_OBJC_TYPE(RTCSSLCertificateVerifier)>)certificateVerifier
delegate:(nullable id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate;
certificateVerifier:(nullable id<RTC_OBJC_TYPE(RTCSSLCertificateVerifier)>)
certificateVerifier
delegate:(nullable id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)
delegate;
/** Initialize an RTCPeerConnection with a configuration, constraints,
* delegate and PeerConnectionDependencies.
@ -99,9 +113,10 @@ class PeerConnectionDelegateAdapter : public PeerConnectionObserver {
initWithDependencies:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
configuration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration
constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
dependencies:(std::unique_ptr<webrtc::PeerConnectionDependencies>)dependencies
delegate:(nullable id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate
NS_DESIGNATED_INITIALIZER;
dependencies:(std::unique_ptr<webrtc::PeerConnectionDependencies>)
dependencies
delegate:(nullable id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)
delegate NS_DESIGNATED_INITIALIZER;
+ (webrtc::PeerConnectionInterface::SignalingState)nativeSignalingStateForState:
(RTCSignalingState)state;
@ -111,11 +126,11 @@ class PeerConnectionDelegateAdapter : public PeerConnectionObserver {
+ (NSString *)stringForSignalingState:(RTCSignalingState)state;
+ (webrtc::PeerConnectionInterface::IceConnectionState)nativeIceConnectionStateForState:
(RTCIceConnectionState)state;
+ (webrtc::PeerConnectionInterface::IceConnectionState)
nativeIceConnectionStateForState:(RTCIceConnectionState)state;
+ (webrtc::PeerConnectionInterface::PeerConnectionState)nativeConnectionStateForState:
(RTCPeerConnectionState)state;
+ (webrtc::PeerConnectionInterface::PeerConnectionState)
nativeConnectionStateForState:(RTCPeerConnectionState)state;
+ (RTCIceConnectionState)iceConnectionStateForNativeState:
(webrtc::PeerConnectionInterface::IceConnectionState)nativeState;
@ -127,16 +142,16 @@ class PeerConnectionDelegateAdapter : public PeerConnectionObserver {
+ (NSString *)stringForConnectionState:(RTCPeerConnectionState)state;
+ (webrtc::PeerConnectionInterface::IceGatheringState)nativeIceGatheringStateForState:
(RTCIceGatheringState)state;
+ (webrtc::PeerConnectionInterface::IceGatheringState)
nativeIceGatheringStateForState:(RTCIceGatheringState)state;
+ (RTCIceGatheringState)iceGatheringStateForNativeState:
(webrtc::PeerConnectionInterface::IceGatheringState)nativeState;
+ (NSString *)stringForIceGatheringState:(RTCIceGatheringState)state;
+ (webrtc::PeerConnectionInterface::StatsOutputLevel)nativeStatsOutputLevelForLevel:
(RTCStatsOutputLevel)level;
+ (webrtc::PeerConnectionInterface::StatsOutputLevel)
nativeStatsOutputLevelForLevel:(RTCStatsOutputLevel)level;
@end

View File

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

View File

@ -83,9 +83,11 @@ typedef NS_ENUM(NSInteger, RTCStatsOutputLevel) {
};
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);
@ -109,7 +111,8 @@ RTC_OBJC_EXPORT
didRemoveStream:(RTC_OBJC_TYPE(RTCMediaStream) *)stream;
/** 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. */
- (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. */
- (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. */
- (void)peerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)peerConnection
@ -146,7 +150,8 @@ RTC_OBJC_EXPORT
didChangeConnectionState:(RTCPeerConnectionState)newState;
- (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. */
- (void)peerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)peerConnection
@ -166,7 +171,8 @@ RTC_OBJC_EXPORT
/** Called when gathering of an ICE candidate failed. */
- (void)peerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)peerConnection
didFailToGatherIceCandidate:(RTC_OBJC_TYPE(RTCIceCandidateErrorEvent) *)event;
didFailToGatherIceCandidate:
(RTC_OBJC_TYPE(RTCIceCandidateErrorEvent) *)event;
@end
@ -180,14 +186,18 @@ RTC_OBJC_EXPORT
/** This property is not available with RTCSdpSemanticsUnifiedPlan. Please use
* `senders` instead.
*/
@property(nonatomic, readonly) NSArray<RTC_OBJC_TYPE(RTCMediaStream) *> *localStreams;
@property(nonatomic, readonly, nullable) RTC_OBJC_TYPE(RTCSessionDescription) * localDescription;
@property(nonatomic, readonly, nullable) RTC_OBJC_TYPE(RTCSessionDescription) * remoteDescription;
@property(nonatomic, readonly)
NSArray<RTC_OBJC_TYPE(RTCMediaStream) *> *localStreams;
@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) RTCIceConnectionState iceConnectionState;
@property(nonatomic, readonly) RTCPeerConnectionState connectionState;
@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.
* 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.
* 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.
* Note: reading this property returns different instances of
@ -207,7 +218,8 @@ RTC_OBJC_EXPORT
* RTCRtpTransceiver instances. This is only available with
* RTCSdpSemanticsUnifiedPlan specified.
*/
@property(nonatomic, readonly) NSArray<RTC_OBJC_TYPE(RTCRtpTransceiver) *> *transceivers;
@property(nonatomic, readonly)
NSArray<RTC_OBJC_TYPE(RTCRtpTransceiver) *> *transceivers;
- (instancetype)init NS_UNAVAILABLE;
@ -224,14 +236,16 @@ RTC_OBJC_EXPORT
/** Provide a remote candidate to the ICE Agent. */
- (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. */
- (void)addIceCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)candidate
completionHandler:(void (^)(NSError *_Nullable error))completionHandler;
/** 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.
* This method is not supported with RTCSdpSemanticsUnifiedPlan. Please use
@ -253,7 +267,8 @@ RTC_OBJC_EXPORT
* - A sender already exists for the track.
* - The peer connection is closed.
*/
- (nullable RTC_OBJC_TYPE(RTCRtpSender) *)addTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track
- (nullable RTC_OBJC_TYPE(RTCRtpSender) *)
addTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track
streamIds:(NSArray<NSString *> *)streamIds;
/** 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
* or RTCRtpMediaTypeVideo.
*/
- (nullable RTC_OBJC_TYPE(RTCRtpTransceiver) *)addTransceiverOfType:(RTCRtpMediaType)mediaType;
- (nullable RTC_OBJC_TYPE(RTCRtpTransceiver) *)addTransceiverOfType:
(RTCRtpMediaType)mediaType;
- (nullable RTC_OBJC_TYPE(RTCRtpTransceiver) *)
addTransceiverOfType:(RTCRtpMediaType)mediaType
init:(RTC_OBJC_TYPE(RTCRtpTransceiverInit) *)init;
/** Tells the PeerConnection that ICE should be restarted. This triggers a need
* for negotiation and subsequent offerForConstraints:completionHandler call will act as if
* RTCOfferAnswerOptions::ice_restart is true.
* for negotiation and subsequent offerForConstraints:completionHandler call
* will act as if RTCOfferAnswerOptions::ice_restart is true.
*/
- (void)restartIce;
/** Generate an SDP offer. */
- (void)offerForConstraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
completionHandler:(RTCCreateSessionDescriptionCompletionHandler)completionHandler;
completionHandler:
(RTCCreateSessionDescriptionCompletionHandler)completionHandler;
/** Generate an SDP answer. */
- (void)answerForConstraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
completionHandler:(RTCCreateSessionDescriptionCompletionHandler)completionHandler;
completionHandler:
(RTCCreateSessionDescriptionCompletionHandler)completionHandler;
/** Apply the supplied RTCSessionDescription as the local description. */
- (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
* it as the local session description. */
@ -325,7 +344,8 @@ RTC_OBJC_EXPORT
/** Apply the supplied RTCSessionDescription as the remote description. */
- (void)setRemoteDescription:(RTC_OBJC_TYPE(RTCSessionDescription) *)sdp
completionHandler:(RTCSetSessionDescriptionCompletionHandler)completionHandler;
completionHandler:
(RTCSetSessionDescriptionCompletionHandler)completionHandler;
/** Limits the bandwidth allocated for all RTP streams sent by this
* PeerConnection. Nil parameters will be unchanged. Setting
@ -337,7 +357,8 @@ RTC_OBJC_EXPORT
maxBitrateBps:(nullable NSNumber *)maxBitrateBps;
/** 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;
@end
@ -360,25 +381,29 @@ RTC_OBJC_EXPORT
/** Create a new data channel with the given label and configuration. */
- (nullable RTC_OBJC_TYPE(RTCDataChannel) *)dataChannelForLabel
: (NSString *)label configuration : (RTC_OBJC_TYPE(RTCDataChannelConfiguration) *)configuration;
: (NSString *)label configuration
: (RTC_OBJC_TYPE(RTCDataChannelConfiguration) *)configuration;
@end
typedef void (^RTCStatisticsCompletionHandler)(RTC_OBJC_TYPE(RTCStatisticsReport) *);
typedef void (^RTCStatisticsCompletionHandler)(
RTC_OBJC_TYPE(RTCStatisticsReport) *);
@interface RTC_OBJC_TYPE (RTCPeerConnection)
(Stats)
/** Gather stats for the given RTCMediaStreamTrack. If `mediaStreamTrack` is nil
* statistics are gathered for all tracks.
/** Gather stats for the given RTCMediaStreamTrack. If `mediaStreamTrack` is
* nil statistics are gathered for all tracks.
*/
- (void)statsForTrack
: (nullable RTC_OBJC_TYPE(RTCMediaStreamTrack) *)mediaStreamTrack statsOutputLevel
- (void)statsForTrack : (nullable RTC_OBJC_TYPE(RTCMediaStreamTrack) *)
mediaStreamTrack statsOutputLevel
: (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. */
- (void)statisticsWithCompletionHandler:(RTCStatisticsCompletionHandler)completionHandler;
- (void)statisticsWithCompletionHandler:
(RTCStatisticsCompletionHandler)completionHandler;
/** Spec-compliant getStats() performing the stats selection algorithm with the
* sender.

View File

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

View File

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

View File

@ -24,8 +24,8 @@ NS_ASSUME_NONNULL_BEGIN
* RTCPeerConnectionFactory object. This is needed to pass to the underlying
* C++ APIs.
*/
@property(nonatomic,
readonly) rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> nativeFactory;
@property(nonatomic, readonly) rtc::scoped_refptr<
webrtc::PeerConnectionFactoryInterface> nativeFactory;
@property(nonatomic, readonly) rtc::Thread* signalingThread;
@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 */
- (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)
initWithEncoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory
decoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)>)decoderFactory;
initWithEncoderFactory:
(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)
initWithEncoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory
decoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)>)decoderFactory
audioDevice:(nullable id<RTC_OBJC_TYPE(RTCAudioDevice)>)audioDevice;
initWithEncoderFactory:
(nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory
decoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)>)
decoderFactory
audioDevice:
(nullable id<RTC_OBJC_TYPE(RTCAudioDevice)>)audioDevice;
/**
* Valid kind values are kRTCMediaStreamTrackKindAudio and
* kRTCMediaStreamTrackKindVideo.
*/
- (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpSenderCapabilitiesForKind:(NSString *)kind;
- (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpSenderCapabilitiesForKind:
(NSString *)kind;
/**
* Valid kind values are kRTCMediaStreamTrackKindAudio and
* kRTCMediaStreamTrackKindVideo.
*/
- (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpReceiverCapabilitiesForKind:(NSString *)kind;
- (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpReceiverCapabilitiesForKind:
(NSString *)kind;
/** Initialize an RTCAudioSource with constraints. */
- (RTC_OBJC_TYPE(RTCAudioSource) *)audioSourceWithConstraints:
(nullable RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints;
/** Initialize an RTCAudioTrack with an id. Convenience ctor to use an audio source
* with no constraints.
/** Initialize an RTCAudioTrack with an id. Convenience ctor to use an audio
* source with no constraints.
*/
- (RTC_OBJC_TYPE(RTCAudioTrack) *)audioTrackWithTrackId:(NSString *)trackId;
/** 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;
/** Initialize a generic RTCVideoSource. The RTCVideoSource should be
@ -91,7 +101,8 @@ RTC_OBJC_EXPORT
- (RTC_OBJC_TYPE(RTCVideoSource) *)videoSourceForScreenCast:(BOOL)forScreenCast;
/** 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;
/** Initialize an RTCMediaStream with an id. */
@ -101,22 +112,32 @@ RTC_OBJC_EXPORT
* delegate.
*/
- (nullable RTC_OBJC_TYPE(RTCPeerConnection) *)
peerConnectionWithConfiguration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration
constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
delegate:(nullable id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate;
peerConnectionWithConfiguration:
(RTC_OBJC_TYPE(RTCConfiguration) *)configuration
constraints:
(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
delegate:(nullable id<RTC_OBJC_TYPE(
RTCPeerConnectionDelegate)>)delegate;
- (nullable RTC_OBJC_TYPE(RTCPeerConnection) *)
peerConnectionWithConfiguration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration
constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
peerConnectionWithConfiguration:
(RTC_OBJC_TYPE(RTCConfiguration) *)configuration
constraints:
(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
certificateVerifier:
(id<RTC_OBJC_TYPE(RTCSSLCertificateVerifier)>)certificateVerifier
delegate:(nullable id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate;
(id<RTC_OBJC_TYPE(RTCSSLCertificateVerifier)>)
certificateVerifier
delegate:(nullable id<RTC_OBJC_TYPE(
RTCPeerConnectionDelegate)>)delegate;
/** 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. */
- (BOOL)startAecDumpWithFilePath:(NSString *)filePath maxSizeInBytes:(int64_t)maxSizeInBytes;
/** Start an AecDump recording. This API call will likely change in the future.
*/
- (BOOL)startAecDumpWithFilePath:(NSString *)filePath
maxSizeInBytes:(int64_t)maxSizeInBytes;
/* Stop an active AecDump recording */
- (void)stopAecDump;

View File

@ -72,8 +72,10 @@
- (instancetype)init {
webrtc::PeerConnectionFactoryDependencies dependencies;
dependencies.audio_encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory();
dependencies.audio_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory();
dependencies.audio_encoder_factory =
webrtc::CreateBuiltinAudioEncoderFactory();
dependencies.audio_decoder_factory =
webrtc::CreateBuiltinAudioDecoderFactory();
dependencies.video_encoder_factory = webrtc::ObjCToNativeVideoEncoderFactory(
[[RTC_OBJC_TYPE(RTCVideoEncoderFactoryH264) alloc] init]);
dependencies.video_decoder_factory = webrtc::ObjCToNativeVideoDecoderFactory(
@ -83,26 +85,37 @@
}
- (instancetype)
initWithEncoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory
decoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)>)decoderFactory {
return [self initWithEncoderFactory:encoderFactory decoderFactory:decoderFactory audioDevice:nil];
initWithEncoderFactory:
(nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory
decoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)>)
decoderFactory {
return [self initWithEncoderFactory:encoderFactory
decoderFactory:decoderFactory
audioDevice:nil];
}
- (instancetype)
initWithEncoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory
decoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)>)decoderFactory
audioDevice:(nullable id<RTC_OBJC_TYPE(RTCAudioDevice)>)audioDevice {
initWithEncoderFactory:
(nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory
decoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)>)
decoderFactory
audioDevice:
(nullable id<RTC_OBJC_TYPE(RTCAudioDevice)>)audioDevice {
#ifdef HAVE_NO_MEDIA
return [self initWithNoMedia];
#else
webrtc::PeerConnectionFactoryDependencies dependencies;
dependencies.audio_encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory();
dependencies.audio_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory();
dependencies.audio_encoder_factory =
webrtc::CreateBuiltinAudioEncoderFactory();
dependencies.audio_decoder_factory =
webrtc::CreateBuiltinAudioDecoderFactory();
if (encoderFactory) {
dependencies.video_encoder_factory = webrtc::ObjCToNativeVideoEncoderFactory(encoderFactory);
dependencies.video_encoder_factory =
webrtc::ObjCToNativeVideoEncoderFactory(encoderFactory);
}
if (decoderFactory) {
dependencies.video_decoder_factory = webrtc::ObjCToNativeVideoDecoderFactory(decoderFactory);
dependencies.video_decoder_factory =
webrtc::ObjCToNativeVideoDecoderFactory(decoderFactory);
}
if (audioDevice) {
dependencies.adm = webrtc::CreateAudioDeviceModule(audioDevice);
@ -113,7 +126,8 @@
#endif
}
- (instancetype)initWithNativeDependencies:(webrtc::PeerConnectionFactoryDependencies)dependencies {
- (instancetype)initWithNativeDependencies:
(webrtc::PeerConnectionFactoryDependencies)dependencies {
self = [super init];
if (self) {
_networkThread = rtc::Thread::CreateWithSocketServer();
@ -131,7 +145,8 @@
result = _signalingThread->Start();
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.worker_thread = _workerThread.get();
dependencies.signaling_thread = _signalingThread.get();
@ -140,30 +155,39 @@
}
if (dependencies.network_monitor_factory == nullptr &&
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!");
}
return self;
}
- (instancetype)initWithNoMedia {
return [self initWithNativeDependencies:webrtc::PeerConnectionFactoryDependencies()];
return [self
initWithNativeDependencies:webrtc::PeerConnectionFactoryDependencies()];
}
- (instancetype)initWithNativeAudioEncoderFactory:
- (instancetype)
initWithNativeAudioEncoderFactory:
(rtc::scoped_refptr<webrtc::AudioEncoderFactory>)audioEncoderFactory
nativeAudioDecoderFactory:
(rtc::scoped_refptr<webrtc::AudioDecoderFactory>)audioDecoderFactory
(rtc::scoped_refptr<webrtc::AudioDecoderFactory>)
audioDecoderFactory
nativeVideoEncoderFactory:
(std::unique_ptr<webrtc::VideoEncoderFactory>)videoEncoderFactory
(std::unique_ptr<webrtc::VideoEncoderFactory>)
videoEncoderFactory
nativeVideoDecoderFactory:
(std::unique_ptr<webrtc::VideoDecoderFactory>)videoDecoderFactory
audioDeviceModule:(webrtc::AudioDeviceModule *)audioDeviceModule
(std::unique_ptr<webrtc::VideoDecoderFactory>)
videoDecoderFactory
audioDeviceModule:
(webrtc::AudioDeviceModule *)audioDeviceModule
audioProcessingModule:
(rtc::scoped_refptr<webrtc::AudioProcessing>)audioProcessingModule {
(rtc::scoped_refptr<webrtc::AudioProcessing>)
audioProcessingModule {
webrtc::PeerConnectionFactoryDependencies dependencies;
dependencies.audio_encoder_factory = std::move(audioEncoderFactory);
dependencies.audio_decoder_factory = std::move(audioDecoderFactory);
@ -171,22 +195,29 @@
dependencies.video_decoder_factory = std::move(videoDecoderFactory);
dependencies.adm = std::move(audioDeviceModule);
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)];
}
- (instancetype)initWithNativeAudioEncoderFactory:
- (instancetype)
initWithNativeAudioEncoderFactory:
(rtc::scoped_refptr<webrtc::AudioEncoderFactory>)audioEncoderFactory
nativeAudioDecoderFactory:
(rtc::scoped_refptr<webrtc::AudioDecoderFactory>)audioDecoderFactory
(rtc::scoped_refptr<webrtc::AudioDecoderFactory>)
audioDecoderFactory
nativeVideoEncoderFactory:
(std::unique_ptr<webrtc::VideoEncoderFactory>)videoEncoderFactory
(std::unique_ptr<webrtc::VideoEncoderFactory>)
videoEncoderFactory
nativeVideoDecoderFactory:
(std::unique_ptr<webrtc::VideoDecoderFactory>)videoDecoderFactory
audioDeviceModule:(webrtc::AudioDeviceModule *)audioDeviceModule
(std::unique_ptr<webrtc::VideoDecoderFactory>)
videoDecoderFactory
audioDeviceModule:
(webrtc::AudioDeviceModule *)audioDeviceModule
audioProcessingModule:
(rtc::scoped_refptr<webrtc::AudioProcessing>)audioProcessingModule
(rtc::scoped_refptr<webrtc::AudioProcessing>)
audioProcessingModule
networkControllerFactory:
(std::unique_ptr<webrtc::NetworkControllerFactoryInterface>)
networkControllerFactory {
@ -197,7 +228,8 @@
dependencies.video_encoder_factory = std::move(videoEncoderFactory);
dependencies.video_decoder_factory = std::move(videoDecoderFactory);
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);
return [self initWithMediaAndDependencies:std::move(dependencies)];
@ -218,24 +250,31 @@
}
#endif
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);
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];
webrtc::RtpCapabilities rtpCapabilities = _nativeFactory->GetRtpSenderCapabilities(mediaType);
return [[RTC_OBJC_TYPE(RTCRtpCapabilities) alloc] initWithNativeRtpCapabilities:rtpCapabilities];
webrtc::RtpCapabilities 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];
webrtc::RtpCapabilities rtpCapabilities = _nativeFactory->GetRtpReceiverCapabilities(mediaType);
return [[RTC_OBJC_TYPE(RTCRtpCapabilities) alloc] initWithNativeRtpCapabilities:rtpCapabilities];
webrtc::RtpCapabilities rtpCapabilities =
_nativeFactory->GetRtpReceiverCapabilities(mediaType);
return [[RTC_OBJC_TYPE(RTCRtpCapabilities) alloc]
initWithNativeRtpCapabilities:rtpCapabilities];
}
- (RTC_OBJC_TYPE(RTCAudioSource) *)audioSourceWithConstraints:
@ -249,46 +288,61 @@
rtc::scoped_refptr<webrtc::AudioSourceInterface> source =
_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(RTCAudioSource) *audioSource = [self audioSourceWithConstraints:nil];
RTC_OBJC_TYPE(RTCAudioSource) *audioSource =
[self audioSourceWithConstraints:nil];
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 {
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 {
return [[RTC_OBJC_TYPE(RTCVideoSource) alloc] initWithFactory:self
return [[RTC_OBJC_TYPE(RTCVideoSource) alloc]
initWithFactory:self
signalingThread:_signalingThread.get()
workerThread:_workerThread.get()];
}
- (RTC_OBJC_TYPE(RTCVideoSource) *)videoSourceForScreenCast:(BOOL)forScreenCast {
return [[RTC_OBJC_TYPE(RTCVideoSource) alloc] initWithFactory:self
- (RTC_OBJC_TYPE(RTCVideoSource) *)videoSourceForScreenCast:
(BOOL)forScreenCast {
return [[RTC_OBJC_TYPE(RTCVideoSource) alloc]
initWithFactory:self
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 {
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 {
return [[RTC_OBJC_TYPE(RTCMediaStream) alloc] initWithFactory:self streamId:streamId];
- (RTC_OBJC_TYPE(RTCMediaStream) *)mediaStreamWithStreamId:
(NSString *)streamId {
return [[RTC_OBJC_TYPE(RTCMediaStream) alloc] initWithFactory:self
streamId:streamId];
}
- (nullable RTC_OBJC_TYPE(RTCPeerConnection) *)
peerConnectionWithConfiguration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration
constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
delegate:
(nullable id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate {
peerConnectionWithConfiguration:
(RTC_OBJC_TYPE(RTCConfiguration) *)configuration
constraints:
(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
delegate:(nullable id<RTC_OBJC_TYPE(
RTCPeerConnectionDelegate)>)delegate {
return [[RTC_OBJC_TYPE(RTCPeerConnection) alloc] initWithFactory:self
configuration:configuration
constraints:constraints
@ -297,13 +351,17 @@
}
- (nullable RTC_OBJC_TYPE(RTCPeerConnection) *)
peerConnectionWithConfiguration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration
constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
peerConnectionWithConfiguration:
(RTC_OBJC_TYPE(RTCConfiguration) *)configuration
constraints:
(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
certificateVerifier:
(id<RTC_OBJC_TYPE(RTCSSLCertificateVerifier)>)certificateVerifier
delegate:
(nullable id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate {
return [[RTC_OBJC_TYPE(RTCPeerConnection) alloc] initWithFactory:self
(id<RTC_OBJC_TYPE(RTCSSLCertificateVerifier)>)
certificateVerifier
delegate:(nullable id<RTC_OBJC_TYPE(
RTCPeerConnectionDelegate)>)delegate {
return [[RTC_OBJC_TYPE(RTCPeerConnection) alloc]
initWithFactory:self
configuration:configuration
constraints:constraints
certificateVerifier:certificateVerifier
@ -311,18 +369,26 @@
}
- (nullable RTC_OBJC_TYPE(RTCPeerConnection) *)
peerConnectionWithDependencies:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration
constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
dependencies:(std::unique_ptr<webrtc::PeerConnectionDependencies>)dependencies
delegate:(id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate {
return [[RTC_OBJC_TYPE(RTCPeerConnection) alloc] initWithDependencies:self
peerConnectionWithDependencies:
(RTC_OBJC_TYPE(RTCConfiguration) *)configuration
constraints:
(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
dependencies:
(std::unique_ptr<webrtc::PeerConnectionDependencies>)
dependencies
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);
_nativeFactory->SetOptions(options.nativeOptions);
}
@ -338,7 +404,8 @@
}
FILE *f = fopen(filePath.UTF8String, "wb");
if (!f) {
RTCLogError(@"Error opening file: %@. Error: %s", filePath, strerror(errno));
RTCLogError(
@"Error opening file: %@. Error: %s", filePath, strerror(errno));
return NO;
}
_hasStartedAecDump = _nativeFactory->StartAecDump(f, maxSizeInBytes);

View File

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

View File

@ -29,20 +29,27 @@ NS_ASSUME_NONNULL_BEGIN
- (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:
(std::unique_ptr<webrtc::AudioProcessingBuilderInterface>)audioProcessingBuilder;
(std::unique_ptr<webrtc::AudioProcessingBuilderInterface>)
audioProcessingBuilder;
@end

View File

@ -35,11 +35,13 @@
_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);
}
- (void)setVideoDecoderFactory:(std::unique_ptr<webrtc::VideoDecoderFactory>)videoDecoderFactory {
- (void)setVideoDecoderFactory:
(std::unique_ptr<webrtc::VideoDecoderFactory>)videoDecoderFactory {
_dependencies.video_decoder_factory = std::move(videoDecoderFactory);
}
@ -53,17 +55,20 @@
_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);
}
- (void)setAudioProcessingModule:
(rtc::scoped_refptr<webrtc::AudioProcessing>)audioProcessingModule {
_dependencies.audio_processing_builder = CustomAudioProcessing(std::move(audioProcessingModule));
_dependencies.audio_processing_builder =
CustomAudioProcessing(std::move(audioProcessingModule));
}
- (void)setAudioProcessingBuilder:
(std::unique_ptr<webrtc::AudioProcessingBuilderInterface>)audioProcessingBuilder {
(std::unique_ptr<webrtc::AudioProcessingBuilderInterface>)
audioProcessingBuilder {
_dependencies.audio_processing_builder = std::move(audioProcessingBuilder);
}

View File

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

View File

@ -44,11 +44,15 @@ void setNetworkBit(webrtc::PeerConnectionFactoryInterface::Options* options,
options.disable_encryption = self.disableEncryption;
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_CELLULAR, self.ignoreCellularNetworkAdapter);
setNetworkBit(&options, rtc::ADAPTER_TYPE_WIFI, self.ignoreWiFiNetworkAdapter);
setNetworkBit(&options, rtc::ADAPTER_TYPE_ETHERNET, self.ignoreEthernetNetworkAdapter);
setNetworkBit(
&options, rtc::ADAPTER_TYPE_CELLULAR, self.ignoreCellularNetworkAdapter);
setNetworkBit(
&options, rtc::ADAPTER_TYPE_WIFI, self.ignoreWiFiNetworkAdapter);
setNetworkBit(
&options, rtc::ADAPTER_TYPE_ETHERNET, self.ignoreEthernetNetworkAdapter);
return options;
}

View File

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

View File

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

View File

@ -14,18 +14,21 @@
NS_ASSUME_NONNULL_BEGIN
@interface RTC_OBJC_TYPE (RTCRtpCapabilities)()
@interface RTC_OBJC_TYPE (RTCRtpCapabilities)
()
/**
/**
* The native RtpCapabilities representation of this RTCRtpCapabilities
* 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.
*/
- (instancetype)initWithNativeRtpCapabilities:(const webrtc::RtpCapabilities &)rtpCapabilities;
- (instancetype)initWithNativeRtpCapabilities:
(const webrtc::RtpCapabilities &)rtpCapabilities;
@end

View File

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

View File

@ -14,13 +14,16 @@
NS_ASSUME_NONNULL_BEGIN
@interface RTC_OBJC_TYPE (RTCRtpCodecCapability)()
@interface RTC_OBJC_TYPE (RTCRtpCodecCapability)
()
/**
* The native RtpCodecCapability representation of this RTCRtpCodecCapability
* object. This is needed to pass to the underlying C++ APIs.
/**
* The native RtpCodecCapability representation of this
* 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.

View File

@ -36,8 +36,8 @@
self = [super init];
if (self) {
if (nativeRtpCodecCapability.preferred_payload_type) {
_preferredPayloadType =
[NSNumber numberWithInt:*nativeRtpCodecCapability.preferred_payload_type];
_preferredPayloadType = [NSNumber
numberWithInt:*nativeRtpCodecCapability.preferred_payload_type];
}
_name = [NSString stringForStdString:nativeRtpCodecCapability.name];
switch (nativeRtpCodecCapability.kind) {
@ -55,10 +55,12 @@
break;
}
if (nativeRtpCodecCapability.clock_rate) {
_clockRate = [NSNumber numberWithInt:*nativeRtpCodecCapability.clock_rate];
_clockRate =
[NSNumber numberWithInt:*nativeRtpCodecCapability.clock_rate];
}
if (nativeRtpCodecCapability.num_channels) {
_numChannels = [NSNumber numberWithInt:*nativeRtpCodecCapability.num_channels];
_numChannels =
[NSNumber numberWithInt:*nativeRtpCodecCapability.num_channels];
}
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
for (const auto &parameter : nativeRtpCodecCapability.parameters) {
@ -66,13 +68,15 @@
forKey:[NSString stringForStdString:parameter.first]];
}
_parameters = parameters;
_mimeType = [NSString stringForStdString:nativeRtpCodecCapability.mime_type()];
_mimeType =
[NSString stringForStdString:nativeRtpCodecCapability.mime_type()];
}
return self;
}
- (NSString *)description {
return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCRtpCodecCapability) {\n "
return [NSString
stringWithFormat:@"RTC_OBJC_TYPE(RTCRtpCodecCapability) {\n "
@"preferredPayloadType: %@\n name: %@\n kind: %@\n "
@"clockRate: %@\n numChannels: %@\n parameters: %@\n "
@"mimeType: %@\n}",
@ -88,7 +92,8 @@
- (webrtc::RtpCodecCapability)nativeRtpCodecCapability {
webrtc::RtpCodecCapability rtpCodecCapability;
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];
// 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;
/** Initialize the object with a native RtpCodecParameters structure. */
- (instancetype)initWithNativeParameters:(const webrtc::RtpCodecParameters &)nativeParameters
- (instancetype)initWithNativeParameters:
(const webrtc::RtpCodecParameters &)nativeParameters
NS_DESIGNATED_INITIALIZER;
@end

View File

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

View File

@ -18,10 +18,12 @@ NS_ASSUME_NONNULL_BEGIN
()
/** 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. */
- (instancetype)initWithNativeParameters:(const webrtc::RtpEncodingParameters &)nativeParameters
- (instancetype)initWithNativeParameters:
(const webrtc::RtpEncodingParameters &)nativeParameters
NS_DESIGNATED_INITIALIZER;
@end

View File

@ -66,7 +66,8 @@ RTC_OBJC_EXPORT
@property(nonatomic, assign) RTCPriority networkPriority;
/** 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;
- (instancetype)init;

View File

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

View File

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

View File

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

View File

@ -14,17 +14,20 @@
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
* RTCRtpHeaderExtensionCapability object. This is needed to pass to the underlying C++ APIs.
*/
@property(nonatomic,
readonly) webrtc::RtpHeaderExtensionCapability nativeRtpHeaderExtensionCapability;
/**
* Initialize an RTCRtpHeaderExtensionCapability from a native RtpHeaderExtensionCapability.
* Initialize an RTCRtpHeaderExtensionCapability from a native
* RtpHeaderExtensionCapability.
*/
- (instancetype)initWithNativeRtpHeaderExtensionCapability:
(const webrtc::RtpHeaderExtensionCapability &)rtpHeaderExtensionCapability;

View File

@ -26,7 +26,8 @@ RTC_OBJC_EXPORT
@property(nonatomic, readonly, nullable) NSNumber* preferredId;
/** 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. */
@property(nonatomic) RTCRtpTransceiverDirection direction;

View File

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

View File

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

View File

@ -40,10 +40,12 @@ RTC_OBJC_EXPORT
NSArray<RTC_OBJC_TYPE(RTCRtpHeaderExtension) *> *headerExtensions;
/** 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. */
@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.

View File

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

View File

@ -16,7 +16,8 @@
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)
()
@ -25,7 +26,8 @@ NS_ASSUME_NONNULL_BEGIN
* This will decrypt the entire frame using the user provided decryption
* 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

View File

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

View File

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

View File

@ -21,7 +21,8 @@
namespace webrtc {
RtpReceiverDelegateAdapter::RtpReceiverDelegateAdapter(RTC_OBJC_TYPE(RTCRtpReceiver) * receiver) {
RtpReceiverDelegateAdapter::RtpReceiverDelegateAdapter(
RTC_OBJC_TYPE(RTCRtpReceiver) * receiver) {
RTC_CHECK(receiver);
receiver_ = receiver;
}
@ -31,7 +32,8 @@ void RtpReceiverDelegateAdapter::OnFirstPacketReceived(
RTCRtpMediaType packet_media_type =
[RTC_OBJC_TYPE(RTCRtpReceiver) mediaTypeForNativeMediaType:media_type];
RTC_OBJC_TYPE(RTCRtpReceiver) *receiver = receiver_;
[receiver.delegate rtpReceiver:receiver didReceiveFirstPacketForMediaType:packet_media_type];
[receiver.delegate rtpReceiver:receiver
didReceiveFirstPacketForMediaType:packet_media_type];
}
} // namespace webrtc
@ -57,7 +59,8 @@ void RtpReceiverDelegateAdapter::OnFirstPacketReceived(
rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> nativeTrack(
_nativeRtpReceiver->track());
if (nativeTrack) {
return [RTC_OBJC_TYPE(RTCMediaStreamTrack) mediaTrackForNativeTrack:nativeTrack
return
[RTC_OBJC_TYPE(RTCMediaStreamTrack) mediaTrackForNativeTrack:nativeTrack
factory:_factory];
}
return nil;
@ -65,15 +68,18 @@ void RtpReceiverDelegateAdapter::OnFirstPacketReceived(
- (NSString *)description {
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 {
std::vector<webrtc::RtpSource> nativeSources = _nativeRtpReceiver->GetSources();
std::vector<webrtc::RtpSource> nativeSources =
_nativeRtpReceiver->GetSources();
NSMutableArray<RTC_OBJC_TYPE(RTCRtpSource) *> *result =
[[NSMutableArray alloc] initWithCapacity:nativeSources.size()];
for (auto nativeSource : nativeSources) {
[result addObject:[[RTC_OBJC_TYPE(RTCRtpSource) alloc] initWithNativeRtpSource:nativeSource]];
[result addObject:[[RTC_OBJC_TYPE(RTCRtpSource) alloc]
initWithNativeRtpSource:nativeSource]];
}
return result;
}
@ -94,7 +100,8 @@ void RtpReceiverDelegateAdapter::OnFirstPacketReceived(
if (![object isMemberOfClass:[self class]]) {
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;
}
@ -104,7 +111,8 @@ void RtpReceiverDelegateAdapter::OnFirstPacketReceived(
#pragma mark - Native
- (void)setFrameDecryptor:(rtc::scoped_refptr<webrtc::FrameDecryptorInterface>)frameDecryptor {
- (void)setFrameDecryptor:
(rtc::scoped_refptr<webrtc::FrameDecryptorInterface>)frameDecryptor {
_nativeRtpReceiver->SetFrameDecryptor(frameDecryptor);
}
@ -114,14 +122,17 @@ void RtpReceiverDelegateAdapter::OnFirstPacketReceived(
return _nativeRtpReceiver;
}
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
- (instancetype)
initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
nativeRtpReceiver:
(rtc::scoped_refptr<webrtc::RtpReceiverInterface>)nativeRtpReceiver {
self = [super init];
if (self) {
_factory = factory;
_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));
_nativeRtpReceiver->SetObserver(_observer.get());
}

View File

@ -16,17 +16,19 @@
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)
()
/** Sets a defined frame encryptor that 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
* enabled or not.
* using the user provided encryption mechanism regardless of whether SRTP
* is enabled or not.
*/
- (void)setFrameEncryptor : (rtc::scoped_refptr<webrtc::FrameEncryptorInterface>)frameEncryptor;
- (void)setFrameEncryptor
: (rtc::scoped_refptr<webrtc::FrameEncryptorInterface>)frameEncryptor;
@end

View File

@ -19,12 +19,14 @@ NS_ASSUME_NONNULL_BEGIN
@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. */
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
nativeRtpSender:(rtc::scoped_refptr<webrtc::RtpSenderInterface>)nativeRtpSender
NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithFactory:
(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
nativeRtpSender:(rtc::scoped_refptr<webrtc::RtpSenderInterface>)
nativeRtpSender NS_DESIGNATED_INITIALIZER;
@end

View File

@ -40,7 +40,8 @@ RTC_OBJC_EXPORT
@property(nonatomic, copy) NSArray<NSString *> *streamIds;
/** 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

View File

@ -37,7 +37,10 @@
- (void)setParameters:(RTC_OBJC_TYPE(RTCRtpParameters) *)parameters {
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);
}
}
@ -45,7 +48,8 @@
rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> nativeTrack(
_nativeRtpSender->track());
if (nativeTrack) {
return [RTC_OBJC_TYPE(RTCMediaStreamTrack) mediaTrackForNativeTrack:nativeTrack
return
[RTC_OBJC_TYPE(RTCMediaStreamTrack) mediaTrackForNativeTrack:nativeTrack
factory:_factory];
}
return nil;
@ -53,13 +57,16 @@
- (void)setTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track {
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 {
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) {
[streamIds addObject:[NSString stringForStdString:s]];
}
@ -76,7 +83,8 @@
- (NSString *)description {
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 {
@ -99,7 +107,8 @@
#pragma mark - Native
- (void)setFrameEncryptor:(rtc::scoped_refptr<webrtc::FrameEncryptorInterface>)frameEncryptor {
- (void)setFrameEncryptor:
(rtc::scoped_refptr<webrtc::FrameEncryptorInterface>)frameEncryptor {
_nativeRtpSender->SetFrameEncryptor(frameEncryptor);
}
@ -109,8 +118,10 @@
return _nativeRtpSender;
}
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
nativeRtpSender:(rtc::scoped_refptr<webrtc::RtpSenderInterface>)nativeRtpSender {
- (instancetype)
initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
nativeRtpSender:
(rtc::scoped_refptr<webrtc::RtpSenderInterface>)nativeRtpSender {
NSParameterAssert(factory);
NSParameterAssert(nativeRtpSender);
self = [super init];
@ -121,11 +132,13 @@
rtc::scoped_refptr<webrtc::DtmfSenderInterface> nativeDtmfSender(
_nativeRtpSender->GetDtmfSender());
if (nativeDtmfSender) {
_dtmfSender =
[[RTC_OBJC_TYPE(RTCDtmfSender) alloc] initWithNativeDtmfSender:nativeDtmfSender];
_dtmfSender = [[RTC_OBJC_TYPE(RTCDtmfSender) alloc]
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;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -37,7 +37,8 @@ RTC_OBJC_EXPORT
- (instancetype)init NS_UNAVAILABLE;
/** 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;

View File

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

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