henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2013, Google Inc. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 29 | #error "This file requires ARC support." |
| 30 | #endif |
| 31 | |
| 32 | #import "RTCPeerConnectionFactory.h" |
| 33 | |
| 34 | #include <vector> |
| 35 | |
fischman@webrtc.org | c693a2a | 2014-03-24 18:56:37 +0000 | [diff] [blame] | 36 | #import "RTCAudioTrack+Internal.h" |
| 37 | #import "RTCICEServer+Internal.h" |
| 38 | #import "RTCMediaConstraints+Internal.h" |
| 39 | #import "RTCMediaSource+Internal.h" |
| 40 | #import "RTCMediaStream+Internal.h" |
| 41 | #import "RTCMediaStreamTrack+Internal.h" |
| 42 | #import "RTCPeerConnection+Internal.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 43 | #import "RTCPeerConnectionDelegate.h" |
fischman@webrtc.org | c693a2a | 2014-03-24 18:56:37 +0000 | [diff] [blame] | 44 | #import "RTCVideoCapturer+Internal.h" |
| 45 | #import "RTCVideoSource+Internal.h" |
| 46 | #import "RTCVideoTrack+Internal.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 47 | |
| 48 | #include "talk/app/webrtc/audiotrack.h" |
| 49 | #include "talk/app/webrtc/mediastreaminterface.h" |
| 50 | #include "talk/app/webrtc/peerconnectionfactory.h" |
| 51 | #include "talk/app/webrtc/peerconnectioninterface.h" |
| 52 | #include "talk/app/webrtc/videosourceinterface.h" |
| 53 | #include "talk/app/webrtc/videotrack.h" |
| 54 | #include "talk/base/logging.h" |
fischman@webrtc.org | 1bc1954 | 2013-08-01 18:29:45 +0000 | [diff] [blame] | 55 | #include "talk/base/ssladapter.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 56 | |
| 57 | @interface RTCPeerConnectionFactory () |
| 58 | |
| 59 | @property(nonatomic, assign) talk_base::scoped_refptr< |
| 60 | webrtc::PeerConnectionFactoryInterface> nativeFactory; |
| 61 | |
| 62 | @end |
| 63 | |
| 64 | @implementation RTCPeerConnectionFactory |
| 65 | |
fischman@webrtc.org | 9ca93a8 | 2013-10-29 00:14:15 +0000 | [diff] [blame] | 66 | @synthesize nativeFactory = _nativeFactory; |
| 67 | |
fischman@webrtc.org | 1bc1954 | 2013-08-01 18:29:45 +0000 | [diff] [blame] | 68 | + (void)initializeSSL { |
| 69 | BOOL initialized = talk_base::InitializeSSL(); |
| 70 | NSAssert(initialized, @"Failed to initialize SSL library"); |
| 71 | } |
| 72 | |
| 73 | + (void)deinitializeSSL { |
| 74 | BOOL deinitialized = talk_base::CleanupSSL(); |
| 75 | NSAssert(deinitialized, @"Failed to deinitialize SSL library"); |
| 76 | } |
| 77 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 78 | - (id)init { |
| 79 | if ((self = [super init])) { |
| 80 | _nativeFactory = webrtc::CreatePeerConnectionFactory(); |
| 81 | NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!"); |
| 82 | // Uncomment to get sensitive logs emitted (to stderr or logcat). |
| 83 | // talk_base::LogMessage::LogToDebug(talk_base::LS_SENSITIVE); |
| 84 | } |
| 85 | return self; |
| 86 | } |
| 87 | |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 88 | - (RTCPeerConnection*) |
| 89 | peerConnectionWithICEServers:(NSArray*)servers |
| 90 | constraints:(RTCMediaConstraints*)constraints |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 91 | delegate:(id<RTCPeerConnectionDelegate>)delegate { |
| 92 | webrtc::PeerConnectionInterface::IceServers iceServers; |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 93 | for (RTCICEServer* server in servers) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 94 | iceServers.push_back(server.iceServer); |
| 95 | } |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 96 | RTCPeerConnection* pc = |
tkchin@webrtc.org | acca675 | 2014-05-30 22:26:06 +0000 | [diff] [blame^] | 97 | [[RTCPeerConnection alloc] initWithFactory:self.nativeFactory.get() |
| 98 | iceServers:iceServers |
| 99 | constraints:constraints.constraints]; |
| 100 | pc.delegate = delegate; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 101 | return pc; |
| 102 | } |
| 103 | |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 104 | - (RTCMediaStream*)mediaStreamWithLabel:(NSString*)label { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 105 | talk_base::scoped_refptr<webrtc::MediaStreamInterface> nativeMediaStream = |
| 106 | self.nativeFactory->CreateLocalMediaStream([label UTF8String]); |
| 107 | return [[RTCMediaStream alloc] initWithMediaStream:nativeMediaStream]; |
| 108 | } |
| 109 | |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 110 | - (RTCVideoSource*)videoSourceWithCapturer:(RTCVideoCapturer*)capturer |
| 111 | constraints:(RTCMediaConstraints*)constraints { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 112 | if (!capturer) { |
| 113 | return nil; |
| 114 | } |
| 115 | talk_base::scoped_refptr<webrtc::VideoSourceInterface> source = |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 116 | self.nativeFactory->CreateVideoSource([capturer takeNativeCapturer], |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 117 | constraints.constraints); |
| 118 | return [[RTCVideoSource alloc] initWithMediaSource:source]; |
| 119 | } |
| 120 | |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 121 | - (RTCVideoTrack*)videoTrackWithID:(NSString*)videoId |
| 122 | source:(RTCVideoSource*)source { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 123 | talk_base::scoped_refptr<webrtc::VideoTrackInterface> track = |
| 124 | self.nativeFactory->CreateVideoTrack([videoId UTF8String], |
| 125 | source.videoSource); |
| 126 | return [[RTCVideoTrack alloc] initWithMediaTrack:track]; |
| 127 | } |
| 128 | |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 129 | - (RTCAudioTrack*)audioTrackWithID:(NSString*)audioId { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 130 | talk_base::scoped_refptr<webrtc::AudioTrackInterface> track = |
| 131 | self.nativeFactory->CreateAudioTrack([audioId UTF8String], NULL); |
| 132 | return [[RTCAudioTrack alloc] initWithMediaTrack:track]; |
| 133 | } |
| 134 | |
| 135 | @end |