Note: We no longer publish the latest version of our code here. We primarily use a kumc-bmi github organization. The heron ETL repository, in particular, is not public. Peers in the informatics community should see MultiSiteDev for details on requesting access.

source: webrtc/talk/app/webrtc/objc/RTCPeerConnectionFactory.mm @ 0:4bda6873e34c

pub_scrub_3792 tip
Last change on this file since 0:4bda6873e34c was 0:4bda6873e34c, checked in by Michael Prittie <mprittie@…>, 6 years ago

Scrubbed password for publication.

File size: 5.5 KB
Line 
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
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"
43#import "RTCPeerConnectionDelegate.h"
44#import "RTCPeerConnectionObserver.h"
45#import "RTCVideoCapturer+internal.h"
46#import "RTCVideoSource+internal.h"
47#import "RTCVideoTrack+internal.h"
48
49#include "talk/app/webrtc/audiotrack.h"
50#include "talk/app/webrtc/mediastreaminterface.h"
51#include "talk/app/webrtc/peerconnectionfactory.h"
52#include "talk/app/webrtc/peerconnectioninterface.h"
53#include "talk/app/webrtc/videosourceinterface.h"
54#include "talk/app/webrtc/videotrack.h"
55#include "talk/base/logging.h"
56#include "talk/base/ssladapter.h"
57
58@interface RTCPeerConnectionFactory ()
59
60@property(nonatomic, assign) talk_base::scoped_refptr<
61    webrtc::PeerConnectionFactoryInterface> nativeFactory;
62
63@end
64
65@implementation RTCPeerConnectionFactory
66
67@synthesize nativeFactory = _nativeFactory;
68
69+ (void)initializeSSL {
70  BOOL initialized = talk_base::InitializeSSL();
71  NSAssert(initialized, @"Failed to initialize SSL library");
72}
73
74+ (void)deinitializeSSL {
75  BOOL deinitialized = talk_base::CleanupSSL();
76  NSAssert(deinitialized, @"Failed to deinitialize SSL library");
77}
78
79- (id)init {
80  if ((self = [super init])) {
81    _nativeFactory = webrtc::CreatePeerConnectionFactory();
82    NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!");
83    // Uncomment to get sensitive logs emitted (to stderr or logcat).
84    // talk_base::LogMessage::LogToDebug(talk_base::LS_SENSITIVE);
85  }
86  return self;
87}
88
89- (RTCPeerConnection *)
90    peerConnectionWithICEServers:(NSArray *)servers
91                     constraints:(RTCMediaConstraints *)constraints
92                        delegate:(id<RTCPeerConnectionDelegate>)delegate {
93  webrtc::PeerConnectionInterface::IceServers iceServers;
94  for (RTCICEServer *server in servers) {
95    iceServers.push_back(server.iceServer);
96  }
97  webrtc::RTCPeerConnectionObserver *observer =
98      new webrtc::RTCPeerConnectionObserver(delegate);
99  webrtc::DTLSIdentityServiceInterface* dummy_dtls_identity_service = NULL;
100  talk_base::scoped_refptr<webrtc::PeerConnectionInterface> peerConnection =
101      self.nativeFactory->CreatePeerConnection(
102          iceServers, constraints.constraints, dummy_dtls_identity_service,
103          observer);
104  RTCPeerConnection *pc =
105      [[RTCPeerConnection alloc] initWithPeerConnection:peerConnection
106                                               observer:observer];
107  observer->SetPeerConnection(pc);
108  return pc;
109}
110
111- (RTCMediaStream *)mediaStreamWithLabel:(NSString *)label {
112  talk_base::scoped_refptr<webrtc::MediaStreamInterface> nativeMediaStream =
113      self.nativeFactory->CreateLocalMediaStream([label UTF8String]);
114  return [[RTCMediaStream alloc] initWithMediaStream:nativeMediaStream];
115}
116
117- (RTCVideoSource *)videoSourceWithCapturer:(RTCVideoCapturer *)capturer
118                                constraints:(RTCMediaConstraints *)constraints {
119  if (!capturer) {
120    return nil;
121  }
122  talk_base::scoped_refptr<webrtc::VideoSourceInterface> source =
123      self.nativeFactory->CreateVideoSource(capturer.capturer.get(),
124                                            constraints.constraints);
125  return [[RTCVideoSource alloc] initWithMediaSource:source];
126}
127
128- (RTCVideoTrack *)videoTrackWithID:(NSString *)videoId
129                             source:(RTCVideoSource *)source {
130  talk_base::scoped_refptr<webrtc::VideoTrackInterface> track =
131      self.nativeFactory->CreateVideoTrack([videoId UTF8String],
132                                           source.videoSource);
133  return [[RTCVideoTrack alloc] initWithMediaTrack:track];
134}
135
136- (RTCAudioTrack *)audioTrackWithID:(NSString *)audioId {
137  talk_base::scoped_refptr<webrtc::AudioTrackInterface> track =
138      self.nativeFactory->CreateAudioTrack([audioId UTF8String], NULL);
139  return [[RTCAudioTrack alloc] initWithMediaTrack:track];
140}
141
142@end
Note: See TracBrowser for help on using the repository browser.