blob: c74af1303fcd93153d64f3591185da80a1a73329 [file] [log] [blame]
hjonf396f602016-02-11 16:19:06 -08001/*
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
tkchin9eeb6242016-04-27 01:54:20 -070013#import <WebRTC/RTCMacros.h>
tkchin8b577ed2016-04-19 10:04:41 -070014
hjonf396f602016-02-11 16:19:06 -080015@class RTCConfiguration;
16@class RTCDataChannel;
17@class RTCDataChannelConfiguration;
18@class RTCIceCandidate;
19@class RTCMediaConstraints;
20@class RTCMediaStream;
21@class RTCMediaStreamTrack;
22@class RTCPeerConnectionFactory;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -070023@class RTCRtpReceiver;
skvlad79b4b872016-04-08 17:28:55 -070024@class RTCRtpSender;
hjonf396f602016-02-11 16:19:06 -080025@class RTCSessionDescription;
hbosbd3dda62016-09-09 01:36:28 -070026@class RTCLegacyStatsReport;
Alex Narest54d1da12017-10-17 19:49:15 +020027@class RTCBitrateAllocationStrategy;
hjonf396f602016-02-11 16:19:06 -080028
29NS_ASSUME_NONNULL_BEGIN
30
Jon Hjelle32e0c012016-03-08 16:04:46 -080031extern NSString * const kRTCPeerConnectionErrorDomain;
hjonf396f602016-02-11 16:19:06 -080032extern int const kRTCSessionDescriptionErrorCode;
33
34/** Represents the signaling state of the peer connection. */
35typedef NS_ENUM(NSInteger, RTCSignalingState) {
36 RTCSignalingStateStable,
37 RTCSignalingStateHaveLocalOffer,
38 RTCSignalingStateHaveLocalPrAnswer,
39 RTCSignalingStateHaveRemoteOffer,
40 RTCSignalingStateHaveRemotePrAnswer,
hjon8bbbf2c2016-03-14 13:15:44 -070041 // Not an actual state, represents the total number of states.
hjonf396f602016-02-11 16:19:06 -080042 RTCSignalingStateClosed,
43};
44
45/** Represents the ice connection state of the peer connection. */
46typedef NS_ENUM(NSInteger, RTCIceConnectionState) {
47 RTCIceConnectionStateNew,
48 RTCIceConnectionStateChecking,
49 RTCIceConnectionStateConnected,
50 RTCIceConnectionStateCompleted,
51 RTCIceConnectionStateFailed,
52 RTCIceConnectionStateDisconnected,
53 RTCIceConnectionStateClosed,
hjon8bbbf2c2016-03-14 13:15:44 -070054 RTCIceConnectionStateCount,
hjonf396f602016-02-11 16:19:06 -080055};
56
57/** Represents the ice gathering state of the peer connection. */
58typedef NS_ENUM(NSInteger, RTCIceGatheringState) {
59 RTCIceGatheringStateNew,
60 RTCIceGatheringStateGathering,
61 RTCIceGatheringStateComplete,
62};
63
64/** Represents the stats output level. */
65typedef NS_ENUM(NSInteger, RTCStatsOutputLevel) {
66 RTCStatsOutputLevelStandard,
67 RTCStatsOutputLevelDebug,
68};
69
70@class RTCPeerConnection;
71
tkchin8b577ed2016-04-19 10:04:41 -070072RTC_EXPORT
hjonf396f602016-02-11 16:19:06 -080073@protocol RTCPeerConnectionDelegate <NSObject>
74
75/** Called when the SignalingState changed. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080076- (void)peerConnection:(RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080077 didChangeSignalingState:(RTCSignalingState)stateChanged;
78
79/** Called when media is received on a new stream from remote peer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080080- (void)peerConnection:(RTCPeerConnection *)peerConnection
81 didAddStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -080082
83/** Called when a remote peer closes a stream. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080084- (void)peerConnection:(RTCPeerConnection *)peerConnection
85 didRemoveStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -080086
87/** Called when negotiation is needed, for example ICE has restarted. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080088- (void)peerConnectionShouldNegotiate:(RTCPeerConnection *)peerConnection;
hjonf396f602016-02-11 16:19:06 -080089
90/** Called any time the IceConnectionState changes. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080091- (void)peerConnection:(RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080092 didChangeIceConnectionState:(RTCIceConnectionState)newState;
93
94/** Called any time the IceGatheringState changes. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080095- (void)peerConnection:(RTCPeerConnection *)peerConnection
hjonf396f602016-02-11 16:19:06 -080096 didChangeIceGatheringState:(RTCIceGatheringState)newState;
97
98/** New ice candidate has been found. */
Jon Hjelle32e0c012016-03-08 16:04:46 -080099- (void)peerConnection:(RTCPeerConnection *)peerConnection
100 didGenerateIceCandidate:(RTCIceCandidate *)candidate;
hjonf396f602016-02-11 16:19:06 -0800101
Honghai Zhangda2ba4d2016-05-23 11:53:14 -0700102/** Called when a group of local Ice candidates have been removed. */
103- (void)peerConnection:(RTCPeerConnection *)peerConnection
104 didRemoveIceCandidates:(NSArray<RTCIceCandidate *> *)candidates;
105
hjonf396f602016-02-11 16:19:06 -0800106/** New data channel has been opened. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800107- (void)peerConnection:(RTCPeerConnection *)peerConnection
108 didOpenDataChannel:(RTCDataChannel *)dataChannel;
hjonf396f602016-02-11 16:19:06 -0800109
110@end
111
tkchin8b577ed2016-04-19 10:04:41 -0700112RTC_EXPORT
hjonf396f602016-02-11 16:19:06 -0800113@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 */
hjon6b039952016-02-25 12:32:58 -0800118@property(nonatomic, weak, nullable) id<RTCPeerConnectionDelegate> delegate;
vopatop.skam96b6b832016-08-18 14:21:20 -0700119@property(nonatomic, readonly) NSArray<RTCMediaStream *> *localStreams;
hjonf396f602016-02-11 16:19:06 -0800120@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;
jtteh4eeb5372017-04-03 15:06:37 -0700127@property(nonatomic, readonly, copy) RTCConfiguration *configuration;
hjonf396f602016-02-11 16:19:06 -0800128
skvlad79b4b872016-04-08 17:28:55 -0700129/** 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 Brandstetterdb0cd9e2016-05-16 11:40:30 -0700135/** 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 Hjelle32e0c012016-03-08 16:04:46 -0800141- (instancetype)init NS_UNAVAILABLE;
hjonf396f602016-02-11 16:19:06 -0800142
tkchinaac3eb22016-03-09 21:49:40 -0800143/** 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
hjonf396f602016-02-11 16:19:06 -0800151/** Terminate all media and close the transport. */
152- (void)close;
153
154/** Provide a remote candidate to the ICE Agent. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800155- (void)addIceCandidate:(RTCIceCandidate *)candidate;
hjonf396f602016-02-11 16:19:06 -0800156
Honghai Zhangda2ba4d2016-05-23 11:53:14 -0700157/** Remove a group of remote candidates from the ICE Agent. */
158- (void)removeIceCandidates:(NSArray<RTCIceCandidate *> *)candidates;
159
hjonf396f602016-02-11 16:19:06 -0800160/** Add a new media stream to be sent on this peer connection. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800161- (void)addStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -0800162
163/** Remove the given media stream from this peer connection. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800164- (void)removeStream:(RTCMediaStream *)stream;
hjonf396f602016-02-11 16:19:06 -0800165
166/** Generate an SDP offer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800167- (void)offerForConstraints:(RTCMediaConstraints *)constraints
hjon6b039952016-02-25 12:32:58 -0800168 completionHandler:(nullable void (^)
169 (RTCSessionDescription * _Nullable sdp,
170 NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800171
172/** Generate an SDP answer. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800173- (void)answerForConstraints:(RTCMediaConstraints *)constraints
hjon6b039952016-02-25 12:32:58 -0800174 completionHandler:(nullable void (^)
175 (RTCSessionDescription * _Nullable sdp,
176 NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800177
178/** Apply the supplied RTCSessionDescription as the local description. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800179- (void)setLocalDescription:(RTCSessionDescription *)sdp
hjon6b039952016-02-25 12:32:58 -0800180 completionHandler:
181 (nullable void (^)(NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800182
183/** Apply the supplied RTCSessionDescription as the remote description. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800184- (void)setRemoteDescription:(RTCSessionDescription *)sdp
hjon6b039952016-02-25 12:32:58 -0800185 completionHandler:
186 (nullable void (^)(NSError * _Nullable error))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800187
zstein8b476172017-09-05 14:43:03 -0700188/** 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.
zstein03adb7c2017-08-09 14:29:42 -0700192 */
zstein8b476172017-09-05 14:43:03 -0700193- (BOOL)setBweMinBitrateBps:(nullable NSNumber *)minBitrateBps
194 currentBitrateBps:(nullable NSNumber *)currentBitrateBps
195 maxBitrateBps:(nullable NSNumber *)maxBitrateBps;
zstein03adb7c2017-08-09 14:29:42 -0700196
Alex Narest54d1da12017-10-17 19:49:15 +0200197/** 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
ivoc14d5dbe2016-07-04 07:06:55 -0700204/** Start or stop recording an Rtc EventLog. */
205- (BOOL)startRtcEventLogWithFilePath:(NSString *)filePath
206 maxSizeInBytes:(int64_t)maxSizeInBytes;
207- (void)stopRtcEventLog;
208
hjonf396f602016-02-11 16:19:06 -0800209@end
210
skvladf3569c82016-04-29 15:30:16 -0700211@interface RTCPeerConnection (Media)
212
zstein8b476172017-09-05 14:43:03 -0700213/** Create an RTCRtpSender with the specified kind and media stream ID.
214 * See RTCMediaStreamTrack.h for available kinds.
skvladf3569c82016-04-29 15:30:16 -0700215 */
216- (RTCRtpSender *)senderWithKind:(NSString *)kind streamId:(NSString *)streamId;
217
218@end
219
hjonf396f602016-02-11 16:19:06 -0800220@interface RTCPeerConnection (DataChannel)
221
222/** Create a new data channel with the given label and configuration. */
Jon Hjelle32e0c012016-03-08 16:04:46 -0800223- (RTCDataChannel *)dataChannelForLabel:(NSString *)label
224 configuration:(RTCDataChannelConfiguration *)configuration;
hjonf396f602016-02-11 16:19:06 -0800225
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:
hjona2f77982016-03-04 07:09:09 -0800234 (nullable RTCMediaStreamTrack *)mediaStreamTrack
hjonf396f602016-02-11 16:19:06 -0800235 statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel
236 completionHandler:
hbosbd3dda62016-09-09 01:36:28 -0700237 (nullable void (^)(NSArray<RTCLegacyStatsReport *> *stats))completionHandler;
hjonf396f602016-02-11 16:19:06 -0800238
239@end
240
241NS_ASSUME_NONNULL_END