hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #import <Foundation/Foundation.h> |
| 12 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 13 | #import <WebRTC/RTCMacros.h> |
tkchin | 8b577ed | 2016-04-19 10:04:41 -0700 | [diff] [blame] | 14 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 15 | @class RTCConfiguration; |
| 16 | @class RTCDataChannel; |
| 17 | @class RTCDataChannelConfiguration; |
| 18 | @class RTCIceCandidate; |
| 19 | @class RTCMediaConstraints; |
| 20 | @class RTCMediaStream; |
| 21 | @class RTCMediaStreamTrack; |
| 22 | @class RTCPeerConnectionFactory; |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 23 | @class RTCRtpReceiver; |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 24 | @class RTCRtpSender; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 25 | @class RTCSessionDescription; |
hbos | bd3dda6 | 2016-09-09 01:36:28 -0700 | [diff] [blame] | 26 | @class RTCLegacyStatsReport; |
Alex Narest | 54d1da1 | 2017-10-17 19:49:15 +0200 | [diff] [blame^] | 27 | @class RTCBitrateAllocationStrategy; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 28 | |
| 29 | NS_ASSUME_NONNULL_BEGIN |
| 30 | |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 31 | extern NSString * const kRTCPeerConnectionErrorDomain; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 32 | extern int const kRTCSessionDescriptionErrorCode; |
| 33 | |
| 34 | /** Represents the signaling state of the peer connection. */ |
| 35 | typedef NS_ENUM(NSInteger, RTCSignalingState) { |
| 36 | RTCSignalingStateStable, |
| 37 | RTCSignalingStateHaveLocalOffer, |
| 38 | RTCSignalingStateHaveLocalPrAnswer, |
| 39 | RTCSignalingStateHaveRemoteOffer, |
| 40 | RTCSignalingStateHaveRemotePrAnswer, |
hjon | 8bbbf2c | 2016-03-14 13:15:44 -0700 | [diff] [blame] | 41 | // Not an actual state, represents the total number of states. |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 42 | RTCSignalingStateClosed, |
| 43 | }; |
| 44 | |
| 45 | /** Represents the ice connection state of the peer connection. */ |
| 46 | typedef NS_ENUM(NSInteger, RTCIceConnectionState) { |
| 47 | RTCIceConnectionStateNew, |
| 48 | RTCIceConnectionStateChecking, |
| 49 | RTCIceConnectionStateConnected, |
| 50 | RTCIceConnectionStateCompleted, |
| 51 | RTCIceConnectionStateFailed, |
| 52 | RTCIceConnectionStateDisconnected, |
| 53 | RTCIceConnectionStateClosed, |
hjon | 8bbbf2c | 2016-03-14 13:15:44 -0700 | [diff] [blame] | 54 | RTCIceConnectionStateCount, |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | /** Represents the ice gathering state of the peer connection. */ |
| 58 | typedef NS_ENUM(NSInteger, RTCIceGatheringState) { |
| 59 | RTCIceGatheringStateNew, |
| 60 | RTCIceGatheringStateGathering, |
| 61 | RTCIceGatheringStateComplete, |
| 62 | }; |
| 63 | |
| 64 | /** Represents the stats output level. */ |
| 65 | typedef NS_ENUM(NSInteger, RTCStatsOutputLevel) { |
| 66 | RTCStatsOutputLevelStandard, |
| 67 | RTCStatsOutputLevelDebug, |
| 68 | }; |
| 69 | |
| 70 | @class RTCPeerConnection; |
| 71 | |
tkchin | 8b577ed | 2016-04-19 10:04:41 -0700 | [diff] [blame] | 72 | RTC_EXPORT |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 73 | @protocol RTCPeerConnectionDelegate <NSObject> |
| 74 | |
| 75 | /** Called when the SignalingState changed. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 76 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 77 | didChangeSignalingState:(RTCSignalingState)stateChanged; |
| 78 | |
| 79 | /** Called when media is received on a new stream from remote peer. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 80 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 81 | didAddStream:(RTCMediaStream *)stream; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 82 | |
| 83 | /** Called when a remote peer closes a stream. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 84 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 85 | didRemoveStream:(RTCMediaStream *)stream; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 86 | |
| 87 | /** Called when negotiation is needed, for example ICE has restarted. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 88 | - (void)peerConnectionShouldNegotiate:(RTCPeerConnection *)peerConnection; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 89 | |
| 90 | /** Called any time the IceConnectionState changes. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 91 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 92 | didChangeIceConnectionState:(RTCIceConnectionState)newState; |
| 93 | |
| 94 | /** Called any time the IceGatheringState changes. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 95 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 96 | didChangeIceGatheringState:(RTCIceGatheringState)newState; |
| 97 | |
| 98 | /** New ice candidate has been found. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 99 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 100 | didGenerateIceCandidate:(RTCIceCandidate *)candidate; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 101 | |
Honghai Zhang | da2ba4d | 2016-05-23 11:53:14 -0700 | [diff] [blame] | 102 | /** Called when a group of local Ice candidates have been removed. */ |
| 103 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 104 | didRemoveIceCandidates:(NSArray<RTCIceCandidate *> *)candidates; |
| 105 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 106 | /** New data channel has been opened. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 107 | - (void)peerConnection:(RTCPeerConnection *)peerConnection |
| 108 | didOpenDataChannel:(RTCDataChannel *)dataChannel; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 109 | |
| 110 | @end |
| 111 | |
tkchin | 8b577ed | 2016-04-19 10:04:41 -0700 | [diff] [blame] | 112 | RTC_EXPORT |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 113 | @interface RTCPeerConnection : NSObject |
| 114 | |
| 115 | /** The object that will be notifed about events such as state changes and |
| 116 | * streams being added or removed. |
| 117 | */ |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 118 | @property(nonatomic, weak, nullable) id<RTCPeerConnectionDelegate> delegate; |
vopatop.skam | 96b6b83 | 2016-08-18 14:21:20 -0700 | [diff] [blame] | 119 | @property(nonatomic, readonly) NSArray<RTCMediaStream *> *localStreams; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 120 | @property(nonatomic, readonly, nullable) |
| 121 | RTCSessionDescription *localDescription; |
| 122 | @property(nonatomic, readonly, nullable) |
| 123 | RTCSessionDescription *remoteDescription; |
| 124 | @property(nonatomic, readonly) RTCSignalingState signalingState; |
| 125 | @property(nonatomic, readonly) RTCIceConnectionState iceConnectionState; |
| 126 | @property(nonatomic, readonly) RTCIceGatheringState iceGatheringState; |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 127 | @property(nonatomic, readonly, copy) RTCConfiguration *configuration; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 128 | |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 129 | /** Gets all RTCRtpSenders associated with this peer connection. |
| 130 | * Note: reading this property returns different instances of RTCRtpSender. |
| 131 | * Use isEqual: instead of == to compare RTCRtpSender instances. |
| 132 | */ |
| 133 | @property(nonatomic, readonly) NSArray<RTCRtpSender *> *senders; |
| 134 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 135 | /** Gets all RTCRtpReceivers associated with this peer connection. |
| 136 | * Note: reading this property returns different instances of RTCRtpReceiver. |
| 137 | * Use isEqual: instead of == to compare RTCRtpReceiver instances. |
| 138 | */ |
| 139 | @property(nonatomic, readonly) NSArray<RTCRtpReceiver *> *receivers; |
| 140 | |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 141 | - (instancetype)init NS_UNAVAILABLE; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 142 | |
tkchin | aac3eb2 | 2016-03-09 21:49:40 -0800 | [diff] [blame] | 143 | /** Sets the PeerConnection's global configuration to |configuration|. |
| 144 | * Any changes to STUN/TURN servers or ICE candidate policy will affect the |
| 145 | * next gathering phase, and cause the next call to createOffer to generate |
| 146 | * new ICE credentials. Note that the BUNDLE and RTCP-multiplexing policies |
| 147 | * cannot be changed with this method. |
| 148 | */ |
| 149 | - (BOOL)setConfiguration:(RTCConfiguration *)configuration; |
| 150 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 151 | /** Terminate all media and close the transport. */ |
| 152 | - (void)close; |
| 153 | |
| 154 | /** Provide a remote candidate to the ICE Agent. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 155 | - (void)addIceCandidate:(RTCIceCandidate *)candidate; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 156 | |
Honghai Zhang | da2ba4d | 2016-05-23 11:53:14 -0700 | [diff] [blame] | 157 | /** Remove a group of remote candidates from the ICE Agent. */ |
| 158 | - (void)removeIceCandidates:(NSArray<RTCIceCandidate *> *)candidates; |
| 159 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 160 | /** Add a new media stream to be sent on this peer connection. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 161 | - (void)addStream:(RTCMediaStream *)stream; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 162 | |
| 163 | /** Remove the given media stream from this peer connection. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 164 | - (void)removeStream:(RTCMediaStream *)stream; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 165 | |
| 166 | /** Generate an SDP offer. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 167 | - (void)offerForConstraints:(RTCMediaConstraints *)constraints |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 168 | completionHandler:(nullable void (^) |
| 169 | (RTCSessionDescription * _Nullable sdp, |
| 170 | NSError * _Nullable error))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 171 | |
| 172 | /** Generate an SDP answer. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 173 | - (void)answerForConstraints:(RTCMediaConstraints *)constraints |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 174 | completionHandler:(nullable void (^) |
| 175 | (RTCSessionDescription * _Nullable sdp, |
| 176 | NSError * _Nullable error))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 177 | |
| 178 | /** Apply the supplied RTCSessionDescription as the local description. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 179 | - (void)setLocalDescription:(RTCSessionDescription *)sdp |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 180 | completionHandler: |
| 181 | (nullable void (^)(NSError * _Nullable error))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 182 | |
| 183 | /** Apply the supplied RTCSessionDescription as the remote description. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 184 | - (void)setRemoteDescription:(RTCSessionDescription *)sdp |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 185 | completionHandler: |
| 186 | (nullable void (^)(NSError * _Nullable error))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 187 | |
zstein | 8b47617 | 2017-09-05 14:43:03 -0700 | [diff] [blame] | 188 | /** Limits the bandwidth allocated for all RTP streams sent by this |
| 189 | * PeerConnection. Nil parameters will be unchanged. Setting |
| 190 | * |currentBitrateBps| will force the available bitrate estimate to the given |
| 191 | * value. Returns YES if the parameters were successfully updated. |
zstein | 03adb7c | 2017-08-09 14:29:42 -0700 | [diff] [blame] | 192 | */ |
zstein | 8b47617 | 2017-09-05 14:43:03 -0700 | [diff] [blame] | 193 | - (BOOL)setBweMinBitrateBps:(nullable NSNumber *)minBitrateBps |
| 194 | currentBitrateBps:(nullable NSNumber *)currentBitrateBps |
| 195 | maxBitrateBps:(nullable NSNumber *)maxBitrateBps; |
zstein | 03adb7c | 2017-08-09 14:29:42 -0700 | [diff] [blame] | 196 | |
Alex Narest | 54d1da1 | 2017-10-17 19:49:15 +0200 | [diff] [blame^] | 197 | /** Sets current strategy. If not set default WebRTC allocator will be used. |
| 198 | * May be changed during an active session. The strategy |
| 199 | * ownership is passed with std::unique_ptr |
| 200 | */ |
| 201 | - (void)setBitrateAllocationStrategy: |
| 202 | (RTCBitrateAllocationStrategy *_Nullable)bitrateAllocationStrategy; |
| 203 | |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 204 | /** Start or stop recording an Rtc EventLog. */ |
| 205 | - (BOOL)startRtcEventLogWithFilePath:(NSString *)filePath |
| 206 | maxSizeInBytes:(int64_t)maxSizeInBytes; |
| 207 | - (void)stopRtcEventLog; |
| 208 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 209 | @end |
| 210 | |
skvlad | f3569c8 | 2016-04-29 15:30:16 -0700 | [diff] [blame] | 211 | @interface RTCPeerConnection (Media) |
| 212 | |
zstein | 8b47617 | 2017-09-05 14:43:03 -0700 | [diff] [blame] | 213 | /** Create an RTCRtpSender with the specified kind and media stream ID. |
| 214 | * See RTCMediaStreamTrack.h for available kinds. |
skvlad | f3569c8 | 2016-04-29 15:30:16 -0700 | [diff] [blame] | 215 | */ |
| 216 | - (RTCRtpSender *)senderWithKind:(NSString *)kind streamId:(NSString *)streamId; |
| 217 | |
| 218 | @end |
| 219 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 220 | @interface RTCPeerConnection (DataChannel) |
| 221 | |
| 222 | /** Create a new data channel with the given label and configuration. */ |
Jon Hjelle | 32e0c01 | 2016-03-08 16:04:46 -0800 | [diff] [blame] | 223 | - (RTCDataChannel *)dataChannelForLabel:(NSString *)label |
| 224 | configuration:(RTCDataChannelConfiguration *)configuration; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 225 | |
| 226 | @end |
| 227 | |
| 228 | @interface RTCPeerConnection (Stats) |
| 229 | |
| 230 | /** Gather stats for the given RTCMediaStreamTrack. If |mediaStreamTrack| is nil |
| 231 | * statistics are gathered for all tracks. |
| 232 | */ |
| 233 | - (void)statsForTrack: |
hjon | a2f7798 | 2016-03-04 07:09:09 -0800 | [diff] [blame] | 234 | (nullable RTCMediaStreamTrack *)mediaStreamTrack |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 235 | statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel |
| 236 | completionHandler: |
hbos | bd3dda6 | 2016-09-09 01:36:28 -0700 | [diff] [blame] | 237 | (nullable void (^)(NSArray<RTCLegacyStatsReport *> *stats))completionHandler; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 238 | |
| 239 | @end |
| 240 | |
| 241 | NS_ASSUME_NONNULL_END |