diff options
Diffstat (limited to 'chromium/third_party/webrtc/sdk')
117 files changed, 8664 insertions, 0 deletions
diff --git a/chromium/third_party/webrtc/sdk/BUILD.gn b/chromium/third_party/webrtc/sdk/BUILD.gn new file mode 100644 index 00000000000..91a4c8828ed --- /dev/null +++ b/chromium/third_party/webrtc/sdk/BUILD.gn @@ -0,0 +1,155 @@ +# Copyright 2016 The WebRTC project authors. All Rights Reserved. +# +# Use of this source code is governed by a BSD-style license +# that can be found in the LICENSE file in the root of the source +# tree. An additional intellectual property rights grant can be found +# in the file PATENTS. All contributing project authors may +# be found in the AUTHORS file in the root of the source tree. + +import("../build/webrtc.gni") +import("//build_overrides/webrtc.gni") + +if (is_ios) { + source_set("rtc_sdk_common_objc") { + deps = [ + "../base:rtc_base", + ] + cflags = [ "-fobjc-arc" ] + configs += [ "..:common_config" ] + public_configs = [ "..:common_inherited_config" ] + include_dirs = [ + "objc/Framework/Classes", + "objc/Framework/Headers", + ] + sources = [ + "objc/Framework/Classes/NSString+StdString.h", + "objc/Framework/Classes/NSString+StdString.mm", + "objc/Framework/Classes/RTCCameraPreviewView.m", + "objc/Framework/Classes/RTCDispatcher.m", + "objc/Framework/Classes/RTCFieldTrials.mm", + "objc/Framework/Classes/RTCLogging.mm", + "objc/Framework/Classes/RTCSSLAdapter.mm", + "objc/Framework/Classes/RTCTracing.mm", + "objc/Framework/Classes/RTCUIApplication.h", + "objc/Framework/Classes/RTCUIApplication.mm", + "objc/Framework/Headers/WebRTC/RTCCameraPreviewView.h", + "objc/Framework/Headers/WebRTC/RTCDispatcher.h", + "objc/Framework/Headers/WebRTC/RTCFieldTrials.h", + "objc/Framework/Headers/WebRTC/RTCLogging.h", + "objc/Framework/Headers/WebRTC/RTCMacros.h", + "objc/Framework/Headers/WebRTC/RTCSSLAdapter.h", + "objc/Framework/Headers/WebRTC/RTCTracing.h", + ] + if (!build_with_chromium) { + sources += [ + "objc/Framework/Classes/RTCFileLogger.mm", + "objc/Framework/Headers/WebRTC/RTCFileLogger.h", + ] + } + libs = [ "AVFoundation.framework" ] + } + + source_set("rtc_sdk_peerconnection_objc") { + deps = [ + ":rtc_sdk_common_objc", + #"../../talk/libjingle:libjingle_peerconnection", + ] + cflags = [ + "-fobjc-arc", + "-Wobjc-missing-property-synthesis", + ] + include_dirs = [ + "objc/Framework/Classes", + "objc/Framework/Headers", + ] + sources = [ + # Add these when there's a BUILD.gn for peer connection APIs + #"objc/Framework/Classes/RTCAVFoundationVideoSource+Private.h", + #"objc/Framework/Classes/RTCAVFoundationVideoSource.mm", + #"objc/Framework/Classes/RTCAudioTrack+Private.h", + #"objc/Framework/Classes/RTCAudioTrack.mm", + #"objc/Framework/Classes/RTCConfiguration+Private.h", + #"objc/Framework/Classes/RTCConfiguration.mm", + #"objc/Framework/Classes/RTCDataChannel+Private.h", + #"objc/Framework/Classes/RTCDataChannel.mm", + #"objc/Framework/Classes/RTCDataChannelConfiguration+Private.h", + #"objc/Framework/Classes/RTCDataChannelConfiguration.mm", + #"objc/Framework/Classes/RTCIceCandidate+Private.h", + #"objc/Framework/Classes/RTCIceCandidate.mm", + #"objc/Framework/Classes/RTCIceServer+Private.h", + #"objc/Framework/Classes/RTCIceServer.mm", + #"objc/Framework/Classes/RTCMediaConstraints+Private.h", + #"objc/Framework/Classes/RTCMediaConstraints.mm", + #"objc/Framework/Classes/RTCMediaStream+Private.h", + #"objc/Framework/Classes/RTCMediaStream.mm", + #"objc/Framework/Classes/RTCMediaStreamTrack+Private.h", + #"objc/Framework/Classes/RTCMediaStreamTrack.mm", + #"objc/Framework/Classes/RTCOpenGLVideoRenderer.mm", + #"objc/Framework/Classes/RTCPeerConnection+Private.h", + #"objc/Framework/Classes/RTCPeerConnection.mm", + #"objc/Framework/Classes/RTCPeerConnectionFactory+Private.h", + #"objc/Framework/Classes/RTCPeerConnectionFactory.mm", + #"objc/Framework/Classes/RTCRtpEncodingParameters+Private.h", + #"objc/Framework/Classes/RTCRtpEncodingParameters.mm", + #"objc/Framework/Classes/RTCRtpParameters+Private.h", + #"objc/Framework/Classes/RTCRtpParameters.mm", + #"objc/Framework/Classes/RTCRtpReceiver+Private.h", + #"objc/Framework/Classes/RTCRtpReceiver.mm", + #"objc/Framework/Classes/RTCRtpSender+Private.h", + #"objc/Framework/Classes/RTCRtpSender.mm", + #"objc/Framework/Classes/RTCSessionDescription+Private.h", + #"objc/Framework/Classes/RTCSessionDescription.mm", + #"objc/Framework/Classes/RTCStatsReport+Private.h", + #"objc/Framework/Classes/RTCStatsReport.mm", + #"objc/Framework/Classes/RTCVideoFrame+Private.h", + #"objc/Framework/Classes/RTCVideoFrame.mm", + #"objc/Framework/Classes/RTCVideoRendererAdapter+Private.h", + #"objc/Framework/Classes/RTCVideoRendererAdapter.h", + #"objc/Framework/Classes/RTCVideoRendererAdapter.mm", + #"objc/Framework/Classes/RTCVideoSource+Private.h", + #"objc/Framework/Classes/RTCVideoSource.mm", + #"objc/Framework/Classes/RTCVideoTrack+Private.h", + #"objc/Framework/Classes/RTCVideoTrack.mm", + #"objc/Framework/Classes/avfoundationvideocapturer.h", + #"objc/Framework/Classes/avfoundationvideocapturer.mm", + #"objc/Framework/Headers/WebRTC/RTCAVFoundationVideoSource.h", + #"objc/Framework/Headers/WebRTC/RTCAudioTrack.h", + #"objc/Framework/Headers/WebRTC/RTCConfiguration.h", + #"objc/Framework/Headers/WebRTC/RTCDataChannel.h", + #"objc/Framework/Headers/WebRTC/RTCDataChannelConfiguration.h", + #"objc/Framework/Headers/WebRTC/RTCIceCandidate.h", + #"objc/Framework/Headers/WebRTC/RTCIceServer.h", + #"objc/Framework/Headers/WebRTC/RTCMediaConstraints.h", + #"objc/Framework/Headers/WebRTC/RTCMediaStream.h", + #"objc/Framework/Headers/WebRTC/RTCMediaStreamTrack.h", + #"objc/Framework/Headers/WebRTC/RTCOpenGLVideoRenderer.h", + #"objc/Framework/Headers/WebRTC/RTCPeerConnection.h", + #"objc/Framework/Headers/WebRTC/RTCPeerConnectionFactory.h", + #"objc/Framework/Headers/WebRTC/RTCRtpCodecParameters.h", + #"objc/Framework/Headers/WebRTC/RTCRtpEncodingParameters.h", + #"objc/Framework/Headers/WebRTC/RTCRtpParameters.h", + #"objc/Framework/Headers/WebRTC/RTCRtpReceiver.h", + #"objc/Framework/Headers/WebRTC/RTCRtpSender.h", + #"objc/Framework/Headers/WebRTC/RTCSessionDescription.h", + #"objc/Framework/Headers/WebRTC/RTCStatsReport.h", + #"objc/Framework/Headers/WebRTC/RTCVideoFrame.h", + #"objc/Framework/Headers/WebRTC/RTCVideoRenderer.h", + #"objc/Framework/Headers/WebRTC/RTCVideoSource.h", + #"objc/Framework/Headers/WebRTC/RTCVideoTrack.h", + ] + + if (is_ios) { + sources += [ + "objc/Framework/Classes/RTCEAGLVideoView.m", + "objc/Framework/Headers/WebRTC/RTCEAGLVideoView.h", + ] + } + + if (is_mac) { + sources += [ + "objc/Framework/Classes/RTCNSGLVideoView.m", + "objc/Framework/Headers/WebRTC/RTCNSGLVideoView.h", + ] + } + } +} diff --git a/chromium/third_party/webrtc/sdk/DEPS b/chromium/third_party/webrtc/sdk/DEPS new file mode 100644 index 00000000000..1bb7a2fe8c8 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/DEPS @@ -0,0 +1,6 @@ +include_rules = [ + "+WebRTC", + "+webrtc/api", + "+webrtc/media", + "+webrtc/system_wrappers", +] diff --git a/chromium/third_party/webrtc/sdk/OWNERS b/chromium/third_party/webrtc/sdk/OWNERS new file mode 100644 index 00000000000..cd06158b7fc --- /dev/null +++ b/chromium/third_party/webrtc/sdk/OWNERS @@ -0,0 +1 @@ +tkchin@webrtc.org diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/NSString+StdString.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/NSString+StdString.h new file mode 100644 index 00000000000..8bf6cc94be0 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/NSString+StdString.h @@ -0,0 +1,26 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#include <string> + +NS_ASSUME_NONNULL_BEGIN + +@interface NSString (StdString) + +@property(nonatomic, readonly) std::string stdString; + ++ (std::string)stdStringForString:(NSString *)nsString; ++ (NSString *)stringForStdString:(const std::string&)stdString; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/NSString+StdString.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/NSString+StdString.mm new file mode 100644 index 00000000000..3210ff0b65d --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/NSString+StdString.mm @@ -0,0 +1,33 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "NSString+StdString.h" + +@implementation NSString (StdString) + +- (std::string)stdString { + return [NSString stdStringForString:self]; +} + ++ (std::string)stdStringForString:(NSString *)nsString { + NSData *charData = [nsString dataUsingEncoding:NSUTF8StringEncoding]; + return std::string(reinterpret_cast<const char *>(charData.bytes), + charData.length); +} + ++ (NSString *)stringForStdString:(const std::string&)stdString { + // std::string may contain null termination character so we construct + // using length. + return [[NSString alloc] initWithBytes:stdString.data() + length:stdString.length() + encoding:NSUTF8StringEncoding]; +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCAVFoundationVideoSource+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCAVFoundationVideoSource+Private.h new file mode 100644 index 00000000000..7a4de08240b --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCAVFoundationVideoSource+Private.h @@ -0,0 +1,27 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCAVFoundationVideoSource.h" + +#include "avfoundationvideocapturer.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCAVFoundationVideoSource () + +@property(nonatomic, readonly) webrtc::AVFoundationVideoCapturer *capturer; + +/** Initialize an RTCAVFoundationVideoSource with constraints. */ +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + constraints:(nullable RTCMediaConstraints *)constraints; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCAVFoundationVideoSource.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCAVFoundationVideoSource.mm new file mode 100644 index 00000000000..528e8cb6244 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCAVFoundationVideoSource.mm @@ -0,0 +1,55 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCAVFoundationVideoSource+Private.h" + +#import "RTCMediaConstraints+Private.h" +#import "RTCPeerConnectionFactory+Private.h" +#import "RTCVideoSource+Private.h" + +@implementation RTCAVFoundationVideoSource { + webrtc::AVFoundationVideoCapturer *_capturer; +} + +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + constraints:(RTCMediaConstraints *)constraints { + NSParameterAssert(factory); + // We pass ownership of the capturer to the source, but since we own + // the source, it should be ok to keep a raw pointer to the + // capturer. + _capturer = new webrtc::AVFoundationVideoCapturer(); + rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source = + factory.nativeFactory->CreateVideoSource( + _capturer, constraints.nativeConstraints.get()); + + return [super initWithNativeVideoSource:source]; +} + +- (BOOL)canUseBackCamera { + return self.capturer->CanUseBackCamera(); +} + +- (BOOL)useBackCamera { + return self.capturer->GetUseBackCamera(); +} + +- (void)setUseBackCamera:(BOOL)useBackCamera { + self.capturer->SetUseBackCamera(useBackCamera); +} + +- (AVCaptureSession *)captureSession { + return self.capturer->GetCaptureSession(); +} + +- (webrtc::AVFoundationVideoCapturer *)capturer { + return _capturer; +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCAudioTrack+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCAudioTrack+Private.h new file mode 100644 index 00000000000..cb5f1865aee --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCAudioTrack+Private.h @@ -0,0 +1,30 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCAudioTrack.h" + +#include "webrtc/api/mediastreaminterface.h" + +NS_ASSUME_NONNULL_BEGIN + +@class RTCPeerConnectionFactory; +@interface RTCAudioTrack () + +/** AudioTrackInterface created or passed in at construction. */ +@property(nonatomic, readonly) + rtc::scoped_refptr<webrtc::AudioTrackInterface> nativeAudioTrack; + +/** Initialize an RTCAudioTrack with an id. */ +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + trackId:(NSString *)trackId; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCAudioTrack.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCAudioTrack.mm new file mode 100644 index 00000000000..42542b8b8f0 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCAudioTrack.mm @@ -0,0 +1,43 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCAudioTrack+Private.h" + +#import "NSString+StdString.h" +#import "RTCMediaStreamTrack+Private.h" +#import "RTCPeerConnectionFactory+Private.h" + +@implementation RTCAudioTrack + +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + trackId:(NSString *)trackId { + NSParameterAssert(factory); + NSParameterAssert(trackId.length); + std::string nativeId = [NSString stdStringForString:trackId]; + rtc::scoped_refptr<webrtc::AudioTrackInterface> track = + factory.nativeFactory->CreateAudioTrack(nativeId, nullptr); + return [self initWithNativeTrack:track type:RTCMediaStreamTrackTypeAudio]; +} + +- (instancetype)initWithNativeTrack: + (rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack + type:(RTCMediaStreamTrackType)type { + NSParameterAssert(nativeTrack); + NSParameterAssert(type == RTCMediaStreamTrackTypeAudio); + return [super initWithNativeTrack:nativeTrack type:type]; +} + +#pragma mark - Private + +- (rtc::scoped_refptr<webrtc::AudioTrackInterface>)nativeAudioTrack { + return static_cast<webrtc::AudioTrackInterface *>(self.nativeTrack.get()); +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCCameraPreviewView.m b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCCameraPreviewView.m new file mode 100644 index 00000000000..659973ff180 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCCameraPreviewView.m @@ -0,0 +1,43 @@ +/* + * Copyright 2015 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCCameraPreviewView.h" + +#import <AVFoundation/AVFoundation.h> + +#import "RTCDispatcher+Private.h" + +@implementation RTCCameraPreviewView + +@synthesize captureSession = _captureSession; + ++ (Class)layerClass { + return [AVCaptureVideoPreviewLayer class]; +} + +- (void)setCaptureSession:(AVCaptureSession *)captureSession { + if (_captureSession == captureSession) { + return; + } + _captureSession = captureSession; + AVCaptureVideoPreviewLayer *previewLayer = [self previewLayer]; + [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeCaptureSession + block:^{ + previewLayer.session = captureSession; + }]; +} + +#pragma mark - Private + +- (AVCaptureVideoPreviewLayer *)previewLayer { + return (AVCaptureVideoPreviewLayer *)self.layer; +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCConfiguration+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCConfiguration+Private.h new file mode 100644 index 00000000000..7f90b35246b --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCConfiguration+Private.h @@ -0,0 +1,60 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCConfiguration.h" + +#include "webrtc/api/peerconnectioninterface.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCConfiguration () + ++ (webrtc::PeerConnectionInterface::IceTransportsType) + nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy; + ++ (RTCIceTransportPolicy)transportPolicyForTransportsType: + (webrtc::PeerConnectionInterface::IceTransportsType)nativeType; + ++ (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy; + ++ (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy: + (RTCBundlePolicy)policy; + ++ (RTCBundlePolicy)bundlePolicyForNativePolicy: + (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy; + ++ (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy; + ++ (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy: + (RTCRtcpMuxPolicy)policy; + ++ (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy: + (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy; + ++ (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy; + ++ (webrtc::PeerConnectionInterface::TcpCandidatePolicy) + nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy; + ++ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy: + (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy; + ++ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy; + +/** + * RTCConfiguration struct representation of this RTCConfiguration. This is + * needed to pass to the underlying C++ APIs. + */ +- (webrtc::PeerConnectionInterface::RTCConfiguration *) + createNativeConfiguration; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCConfiguration.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCConfiguration.mm new file mode 100644 index 00000000000..0a63f69fd98 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCConfiguration.mm @@ -0,0 +1,293 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCConfiguration+Private.h" + +#include <memory> + +#import "RTCIceServer+Private.h" +#import "WebRTC/RTCLogging.h" + +#include "webrtc/base/rtccertificategenerator.h" +#include "webrtc/base/sslidentity.h" + +@implementation RTCConfiguration + +@synthesize iceServers = _iceServers; +@synthesize iceTransportPolicy = _iceTransportPolicy; +@synthesize bundlePolicy = _bundlePolicy; +@synthesize rtcpMuxPolicy = _rtcpMuxPolicy; +@synthesize tcpCandidatePolicy = _tcpCandidatePolicy; +@synthesize continualGatheringPolicy = _continualGatheringPolicy; +@synthesize audioJitterBufferMaxPackets = _audioJitterBufferMaxPackets; +@synthesize iceConnectionReceivingTimeout = _iceConnectionReceivingTimeout; +@synthesize iceBackupCandidatePairPingInterval = + _iceBackupCandidatePairPingInterval; +@synthesize keyType = _keyType; + +- (instancetype)init { + if (self = [super init]) { + _iceServers = [NSMutableArray array]; + // Copy defaults. + webrtc::PeerConnectionInterface::RTCConfiguration config; + _iceTransportPolicy = + [[self class] transportPolicyForTransportsType:config.type]; + _bundlePolicy = + [[self class] bundlePolicyForNativePolicy:config.bundle_policy]; + _rtcpMuxPolicy = + [[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy]; + _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy: + config.tcp_candidate_policy]; + webrtc::PeerConnectionInterface::ContinualGatheringPolicy nativePolicy = + config.continual_gathering_policy; + _continualGatheringPolicy = + [[self class] continualGatheringPolicyForNativePolicy:nativePolicy]; + _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets; + _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout; + _iceBackupCandidatePairPingInterval = + config.ice_backup_candidate_pair_ping_interval; + _keyType = RTCEncryptionKeyTypeECDSA; + } + return self; +} + +- (NSString *)description { + return [NSString stringWithFormat: + @"RTCConfiguration: {\n%@\n%@\n%@\n%@\n%@\n%@\n%d\n%d\n%d\n}\n", + _iceServers, + [[self class] stringForTransportPolicy:_iceTransportPolicy], + [[self class] stringForBundlePolicy:_bundlePolicy], + [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy], + [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy], + [[self class] + stringForContinualGatheringPolicy:_continualGatheringPolicy], + _audioJitterBufferMaxPackets, + _iceConnectionReceivingTimeout, + _iceBackupCandidatePairPingInterval]; +} + +#pragma mark - Private + +- (webrtc::PeerConnectionInterface::RTCConfiguration *) + createNativeConfiguration { + std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> + nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration()); + + for (RTCIceServer *iceServer in _iceServers) { + nativeConfig->servers.push_back(iceServer.nativeServer); + } + nativeConfig->type = + [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy]; + nativeConfig->bundle_policy = + [[self class] nativeBundlePolicyForPolicy:_bundlePolicy]; + nativeConfig->rtcp_mux_policy = + [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy]; + nativeConfig->tcp_candidate_policy = + [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy]; + nativeConfig->continual_gathering_policy = [[self class] + nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy]; + nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets; + nativeConfig->ice_connection_receiving_timeout = + _iceConnectionReceivingTimeout; + nativeConfig->ice_backup_candidate_pair_ping_interval = + _iceBackupCandidatePairPingInterval; + rtc::KeyType keyType = + [[self class] nativeEncryptionKeyTypeForKeyType:_keyType]; + // Generate non-default certificate. + if (keyType != rtc::KT_DEFAULT) { + rtc::scoped_refptr<rtc::RTCCertificate> certificate = + rtc::RTCCertificateGenerator::GenerateCertificate( + rtc::KeyParams(keyType), rtc::Optional<uint64_t>()); + if (!certificate) { + RTCLogError(@"Failed to generate certificate."); + return nullptr; + } + nativeConfig->certificates.push_back(certificate); + } + + return nativeConfig.release(); +} + ++ (webrtc::PeerConnectionInterface::IceTransportsType) + nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy { + switch (policy) { + case RTCIceTransportPolicyNone: + return webrtc::PeerConnectionInterface::kNone; + case RTCIceTransportPolicyRelay: + return webrtc::PeerConnectionInterface::kRelay; + case RTCIceTransportPolicyNoHost: + return webrtc::PeerConnectionInterface::kNoHost; + case RTCIceTransportPolicyAll: + return webrtc::PeerConnectionInterface::kAll; + } +} + ++ (RTCIceTransportPolicy)transportPolicyForTransportsType: + (webrtc::PeerConnectionInterface::IceTransportsType)nativeType { + switch (nativeType) { + case webrtc::PeerConnectionInterface::kNone: + return RTCIceTransportPolicyNone; + case webrtc::PeerConnectionInterface::kRelay: + return RTCIceTransportPolicyRelay; + case webrtc::PeerConnectionInterface::kNoHost: + return RTCIceTransportPolicyNoHost; + case webrtc::PeerConnectionInterface::kAll: + return RTCIceTransportPolicyAll; + } +} + ++ (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy { + switch (policy) { + case RTCIceTransportPolicyNone: + return @"NONE"; + case RTCIceTransportPolicyRelay: + return @"RELAY"; + case RTCIceTransportPolicyNoHost: + return @"NO_HOST"; + case RTCIceTransportPolicyAll: + return @"ALL"; + } +} + ++ (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy: + (RTCBundlePolicy)policy { + switch (policy) { + case RTCBundlePolicyBalanced: + return webrtc::PeerConnectionInterface::kBundlePolicyBalanced; + case RTCBundlePolicyMaxCompat: + return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat; + case RTCBundlePolicyMaxBundle: + return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle; + } +} + ++ (RTCBundlePolicy)bundlePolicyForNativePolicy: + (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy { + switch (nativePolicy) { + case webrtc::PeerConnectionInterface::kBundlePolicyBalanced: + return RTCBundlePolicyBalanced; + case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat: + return RTCBundlePolicyMaxCompat; + case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle: + return RTCBundlePolicyMaxBundle; + } +} + ++ (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy { + switch (policy) { + case RTCBundlePolicyBalanced: + return @"BALANCED"; + case RTCBundlePolicyMaxCompat: + return @"MAX_COMPAT"; + case RTCBundlePolicyMaxBundle: + return @"MAX_BUNDLE"; + } +} + ++ (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy: + (RTCRtcpMuxPolicy)policy { + switch (policy) { + case RTCRtcpMuxPolicyNegotiate: + return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate; + case RTCRtcpMuxPolicyRequire: + return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire; + } +} + ++ (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy: + (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy { + switch (nativePolicy) { + case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate: + return RTCRtcpMuxPolicyNegotiate; + case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire: + return RTCRtcpMuxPolicyRequire; + } +} + ++ (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy { + switch (policy) { + case RTCRtcpMuxPolicyNegotiate: + return @"NEGOTIATE"; + case RTCRtcpMuxPolicyRequire: + return @"REQUIRE"; + } +} + ++ (webrtc::PeerConnectionInterface::TcpCandidatePolicy) + nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy { + switch (policy) { + case RTCTcpCandidatePolicyEnabled: + return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled; + case RTCTcpCandidatePolicyDisabled: + return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled; + } +} + ++ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType: + (RTCEncryptionKeyType)keyType { + switch (keyType) { + case RTCEncryptionKeyTypeRSA: + return rtc::KT_RSA; + case RTCEncryptionKeyTypeECDSA: + return rtc::KT_ECDSA; + } +} + ++ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy: + (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy { + switch (nativePolicy) { + case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled: + return RTCTcpCandidatePolicyEnabled; + case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled: + return RTCTcpCandidatePolicyDisabled; + } +} + ++ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy { + switch (policy) { + case RTCTcpCandidatePolicyEnabled: + return @"TCP_ENABLED"; + case RTCTcpCandidatePolicyDisabled: + return @"TCP_DISABLED"; + } +} + ++ (webrtc::PeerConnectionInterface::ContinualGatheringPolicy) + nativeContinualGatheringPolicyForPolicy: + (RTCContinualGatheringPolicy)policy { + switch (policy) { + case RTCContinualGatheringPolicyGatherOnce: + return webrtc::PeerConnectionInterface::GATHER_ONCE; + case RTCContinualGatheringPolicyGatherContinually: + return webrtc::PeerConnectionInterface::GATHER_CONTINUALLY; + } +} + ++ (RTCContinualGatheringPolicy)continualGatheringPolicyForNativePolicy: + (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)nativePolicy { + switch (nativePolicy) { + case webrtc::PeerConnectionInterface::GATHER_ONCE: + return RTCContinualGatheringPolicyGatherOnce; + case webrtc::PeerConnectionInterface::GATHER_CONTINUALLY: + return RTCContinualGatheringPolicyGatherContinually; + } +} + ++ (NSString *)stringForContinualGatheringPolicy: + (RTCContinualGatheringPolicy)policy { + switch (policy) { + case RTCContinualGatheringPolicyGatherOnce: + return @"GATHER_ONCE"; + case RTCContinualGatheringPolicyGatherContinually: + return @"GATHER_CONTINUALLY"; + } +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCDataChannel+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCDataChannel+Private.h new file mode 100644 index 00000000000..82e132fa2e0 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCDataChannel+Private.h @@ -0,0 +1,49 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCDataChannel.h" + +#include "webrtc/api/datachannelinterface.h" +#include "webrtc/base/scoped_ref_ptr.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCDataBuffer () + +/** + * 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; + +/** Initialize an RTCDataBuffer from a native DataBuffer. */ +- (instancetype)initWithNativeBuffer:(const webrtc::DataBuffer&)nativeBuffer; + +@end + + +@interface RTCDataChannel () + +/** Initialize an RTCDataChannel from a native DataChannelInterface. */ +- (instancetype)initWithNativeDataChannel: + (rtc::scoped_refptr<webrtc::DataChannelInterface>)nativeDataChannel + NS_DESIGNATED_INITIALIZER; + ++ (webrtc::DataChannelInterface::DataState) + nativeDataChannelStateForState:(RTCDataChannelState)state; + ++ (RTCDataChannelState)dataChannelStateForNativeState: + (webrtc::DataChannelInterface::DataState)nativeState; + ++ (NSString *)stringForState:(RTCDataChannelState)state; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCDataChannel.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCDataChannel.mm new file mode 100644 index 00000000000..706e43e2ed5 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCDataChannel.mm @@ -0,0 +1,220 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCDataChannel+Private.h" + +#import "NSString+StdString.h" + +#include <memory> + +namespace webrtc { + +class DataChannelDelegateAdapter : public DataChannelObserver { + public: + DataChannelDelegateAdapter(RTCDataChannel *channel) { channel_ = channel; } + + void OnStateChange() override { + [channel_.delegate dataChannelDidChangeState:channel_]; + } + + void OnMessage(const DataBuffer& buffer) override { + RTCDataBuffer *data_buffer = + [[RTCDataBuffer alloc] initWithNativeBuffer:buffer]; + [channel_.delegate dataChannel:channel_ + didReceiveMessageWithBuffer:data_buffer]; + } + + void OnBufferedAmountChange(uint64_t previousAmount) override { + id<RTCDataChannelDelegate> delegate = channel_.delegate; + SEL sel = @selector(dataChannel:didChangeBufferedAmount:); + if ([delegate respondsToSelector:sel]) { + [delegate dataChannel:channel_ didChangeBufferedAmount:previousAmount]; + } + } + + private: + __weak RTCDataChannel *channel_; +}; +} + + +@implementation RTCDataBuffer { + std::unique_ptr<webrtc::DataBuffer> _dataBuffer; +} + +- (instancetype)initWithData:(NSData *)data isBinary:(BOOL)isBinary { + NSParameterAssert(data); + if (self = [super init]) { + rtc::CopyOnWriteBuffer buffer( + reinterpret_cast<const uint8_t*>(data.bytes), data.length); + _dataBuffer.reset(new webrtc::DataBuffer(buffer, isBinary)); + } + return self; +} + +- (NSData *)data { + return [NSData dataWithBytes:_dataBuffer->data.data() + length:_dataBuffer->data.size()]; +} + +- (BOOL)isBinary { + return _dataBuffer->binary; +} + +#pragma mark - Private + +- (instancetype)initWithNativeBuffer:(const webrtc::DataBuffer&)nativeBuffer { + if (self = [super init]) { + _dataBuffer.reset(new webrtc::DataBuffer(nativeBuffer)); + } + return self; +} + +- (const webrtc::DataBuffer *)nativeDataBuffer { + return _dataBuffer.get(); +} + +@end + + +@implementation RTCDataChannel { + rtc::scoped_refptr<webrtc::DataChannelInterface> _nativeDataChannel; + std::unique_ptr<webrtc::DataChannelDelegateAdapter> _observer; + BOOL _isObserverRegistered; +} + +@synthesize delegate = _delegate; + +- (void)dealloc { + // Handles unregistering the observer properly. We need to do this because + // there may still be other references to the underlying data channel. + _nativeDataChannel->UnregisterObserver(); +} + +- (NSString *)label { + return [NSString stringForStdString:_nativeDataChannel->label()]; +} + +- (BOOL)isReliable { + return _nativeDataChannel->reliable(); +} + +- (BOOL)isOrdered { + return _nativeDataChannel->ordered(); +} + +- (NSUInteger)maxRetransmitTime { + return self.maxPacketLifeTime; +} + +- (uint16_t)maxPacketLifeTime { + return _nativeDataChannel->maxRetransmitTime(); +} + +- (uint16_t)maxRetransmits { + return _nativeDataChannel->maxRetransmits(); +} + +- (NSString *)protocol { + return [NSString stringForStdString:_nativeDataChannel->protocol()]; +} + +- (BOOL)isNegotiated { + return _nativeDataChannel->negotiated(); +} + +- (NSInteger)streamId { + return self.channelId; +} + +- (int)channelId { + return _nativeDataChannel->id(); +} + +- (RTCDataChannelState)readyState { + return [[self class] dataChannelStateForNativeState: + _nativeDataChannel->state()]; +} + +- (uint64_t)bufferedAmount { + return _nativeDataChannel->buffered_amount(); +} + +- (void)close { + _nativeDataChannel->Close(); +} + +- (BOOL)sendData:(RTCDataBuffer *)data { + return _nativeDataChannel->Send(*data.nativeDataBuffer); +} + +- (NSString *)description { + return [NSString stringWithFormat:@"RTCDataChannel:\n%ld\n%@\n%@", + (long)self.channelId, + self.label, + [[self class] + stringForState:self.readyState]]; +} + +#pragma mark - Private + +- (instancetype)initWithNativeDataChannel: + (rtc::scoped_refptr<webrtc::DataChannelInterface>)nativeDataChannel { + NSParameterAssert(nativeDataChannel); + if (self = [super init]) { + _nativeDataChannel = nativeDataChannel; + _observer.reset(new webrtc::DataChannelDelegateAdapter(self)); + _nativeDataChannel->RegisterObserver(_observer.get()); + } + return self; +} + ++ (webrtc::DataChannelInterface::DataState) + nativeDataChannelStateForState:(RTCDataChannelState)state { + switch (state) { + case RTCDataChannelStateConnecting: + return webrtc::DataChannelInterface::DataState::kConnecting; + case RTCDataChannelStateOpen: + return webrtc::DataChannelInterface::DataState::kOpen; + case RTCDataChannelStateClosing: + return webrtc::DataChannelInterface::DataState::kClosing; + case RTCDataChannelStateClosed: + return webrtc::DataChannelInterface::DataState::kClosed; + } +} + ++ (RTCDataChannelState)dataChannelStateForNativeState: + (webrtc::DataChannelInterface::DataState)nativeState { + switch (nativeState) { + case webrtc::DataChannelInterface::DataState::kConnecting: + return RTCDataChannelStateConnecting; + case webrtc::DataChannelInterface::DataState::kOpen: + return RTCDataChannelStateOpen; + case webrtc::DataChannelInterface::DataState::kClosing: + return RTCDataChannelStateClosing; + case webrtc::DataChannelInterface::DataState::kClosed: + return RTCDataChannelStateClosed; + } +} + ++ (NSString *)stringForState:(RTCDataChannelState)state { + switch (state) { + case RTCDataChannelStateConnecting: + return @"Connecting"; + case RTCDataChannelStateOpen: + return @"Open"; + case RTCDataChannelStateClosing: + return @"Closing"; + case RTCDataChannelStateClosed: + return @"Closed"; + } +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCDataChannelConfiguration+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCDataChannelConfiguration+Private.h new file mode 100644 index 00000000000..e9ea74705d4 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCDataChannelConfiguration+Private.h @@ -0,0 +1,23 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCDataChannelConfiguration.h" + +#include "webrtc/api/datachannelinterface.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCDataChannelConfiguration () + +@property(nonatomic, readonly) webrtc::DataChannelInit nativeDataChannelInit; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCDataChannelConfiguration.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCDataChannelConfiguration.mm new file mode 100644 index 00000000000..89c56de7863 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCDataChannelConfiguration.mm @@ -0,0 +1,83 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCDataChannelConfiguration+Private.h" + +#import "NSString+StdString.h" + +@implementation RTCDataChannelConfiguration + +@synthesize nativeDataChannelInit = _nativeDataChannelInit; + +- (BOOL)isOrdered { + return _nativeDataChannelInit.ordered; +} + +- (void)setIsOrdered:(BOOL)isOrdered { + _nativeDataChannelInit.ordered = isOrdered; +} + +- (NSInteger)maxRetransmitTimeMs { + return self.maxPacketLifeTime; +} + +- (void)setMaxRetransmitTimeMs:(NSInteger)maxRetransmitTimeMs { + self.maxPacketLifeTime = maxRetransmitTimeMs; +} + +- (int)maxPacketLifeTime { + return _nativeDataChannelInit.maxRetransmitTime; +} + +- (void)setMaxPacketLifeTime:(int)maxPacketLifeTime { + _nativeDataChannelInit.maxRetransmitTime = maxPacketLifeTime; +} + +- (int)maxRetransmits { + return _nativeDataChannelInit.maxRetransmits; +} + +- (void)setMaxRetransmits:(int)maxRetransmits { + _nativeDataChannelInit.maxRetransmits = maxRetransmits; +} + +- (NSString *)protocol { + return [NSString stringForStdString:_nativeDataChannelInit.protocol]; +} + +- (void)setProtocol:(NSString *)protocol { + _nativeDataChannelInit.protocol = [NSString stdStringForString:protocol]; +} + +- (BOOL)isNegotiated { + return _nativeDataChannelInit.negotiated; +} + +- (void)setIsNegotiated:(BOOL)isNegotiated { + _nativeDataChannelInit.negotiated = isNegotiated; +} + +- (int)streamId { + return self.channelId; +} + +- (void)setStreamId:(int)streamId { + self.channelId = streamId; +} + +- (int)channelId { + return _nativeDataChannelInit.id; +} + +- (void)setChannelId:(int)channelId { + _nativeDataChannelInit.id = channelId; +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCDispatcher+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCDispatcher+Private.h new file mode 100644 index 00000000000..3c114e553df --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCDispatcher+Private.h @@ -0,0 +1,17 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCDispatcher.h" + +@interface RTCDispatcher () + ++ (dispatch_queue_t)dispatchQueueForType:(RTCDispatcherQueueType)dispatchType; + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCDispatcher.m b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCDispatcher.m new file mode 100644 index 00000000000..94176ac6d81 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCDispatcher.m @@ -0,0 +1,50 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCDispatcher+Private.h" + +static dispatch_queue_t kAudioSessionQueue = nil; +static dispatch_queue_t kCaptureSessionQueue = nil; + +@implementation RTCDispatcher + ++ (void)initialize { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + kAudioSessionQueue = dispatch_queue_create( + "org.webrtc.RTCDispatcherAudioSession", + DISPATCH_QUEUE_SERIAL); + kCaptureSessionQueue = dispatch_queue_create( + "org.webrtc.RTCDispatcherCaptureSession", + DISPATCH_QUEUE_SERIAL); + }); +} + ++ (void)dispatchAsyncOnType:(RTCDispatcherQueueType)dispatchType + block:(dispatch_block_t)block { + dispatch_queue_t queue = [self dispatchQueueForType:dispatchType]; + dispatch_async(queue, block); +} + +#pragma mark - Private + ++ (dispatch_queue_t)dispatchQueueForType:(RTCDispatcherQueueType)dispatchType { + switch (dispatchType) { + case RTCDispatcherTypeMain: + return dispatch_get_main_queue(); + case RTCDispatcherTypeCaptureSession: + return kCaptureSessionQueue; + case RTCDispatcherTypeAudioSession: + return kAudioSessionQueue; + } +} + +@end + diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCEAGLVideoView.m b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCEAGLVideoView.m new file mode 100644 index 00000000000..d215265d3b0 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCEAGLVideoView.m @@ -0,0 +1,263 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCEAGLVideoView.h" + +#import <GLKit/GLKit.h> + +#import "RTCOpenGLVideoRenderer.h" +#import "WebRTC//RTCVideoFrame.h" + +// RTCDisplayLinkTimer wraps a CADisplayLink and is set to fire every two screen +// refreshes, which should be 30fps. We wrap the display link in order to avoid +// a retain cycle since CADisplayLink takes a strong reference onto its target. +// The timer is paused by default. +@interface RTCDisplayLinkTimer : NSObject + +@property(nonatomic) BOOL isPaused; + +- (instancetype)initWithTimerHandler:(void (^)(void))timerHandler; +- (void)invalidate; + +@end + +@implementation RTCDisplayLinkTimer { + CADisplayLink *_displayLink; + void (^_timerHandler)(void); +} + +- (instancetype)initWithTimerHandler:(void (^)(void))timerHandler { + NSParameterAssert(timerHandler); + if (self = [super init]) { + _timerHandler = timerHandler; + _displayLink = + [CADisplayLink displayLinkWithTarget:self + selector:@selector(displayLinkDidFire:)]; + _displayLink.paused = YES; + // Set to half of screen refresh, which should be 30fps. + [_displayLink setFrameInterval:2]; + [_displayLink addToRunLoop:[NSRunLoop currentRunLoop] + forMode:NSRunLoopCommonModes]; + } + return self; +} + +- (void)dealloc { + [self invalidate]; +} + +- (BOOL)isPaused { + return _displayLink.paused; +} + +- (void)setIsPaused:(BOOL)isPaused { + _displayLink.paused = isPaused; +} + +- (void)invalidate { + [_displayLink invalidate]; +} + +- (void)displayLinkDidFire:(CADisplayLink *)displayLink { + _timerHandler(); +} + +@end + +// RTCEAGLVideoView wraps a GLKView which is setup with +// enableSetNeedsDisplay = NO for the purpose of gaining control of +// exactly when to call -[GLKView display]. This need for extra +// control is required to avoid triggering method calls on GLKView +// that results in attempting to bind the underlying render buffer +// when the drawable size would be empty which would result in the +// error GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT. -[GLKView display] is +// the method that will trigger the binding of the render +// buffer. Because the standard behaviour of -[UIView setNeedsDisplay] +// is disabled for the reasons above, the RTCEAGLVideoView maintains +// its own |isDirty| flag. + +@interface RTCEAGLVideoView () <GLKViewDelegate> +// |videoFrame| is set when we receive a frame from a worker thread and is read +// from the display link callback so atomicity is required. +@property(atomic, strong) RTCVideoFrame *videoFrame; +@property(nonatomic, readonly) GLKView *glkView; +@property(nonatomic, readonly) RTCOpenGLVideoRenderer *glRenderer; +@end + +@implementation RTCEAGLVideoView { + RTCDisplayLinkTimer *_timer; + // This flag should only be set and read on the main thread (e.g. by + // setNeedsDisplay) + BOOL _isDirty; +} + +@synthesize delegate = _delegate; +@synthesize videoFrame = _videoFrame; +@synthesize glkView = _glkView; +@synthesize glRenderer = _glRenderer; + +- (instancetype)initWithFrame:(CGRect)frame { + if (self = [super initWithFrame:frame]) { + [self configure]; + } + return self; +} + +- (instancetype)initWithCoder:(NSCoder *)aDecoder { + if (self = [super initWithCoder:aDecoder]) { + [self configure]; + } + return self; +} + +- (void)configure { + EAGLContext *glContext = + [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; + if (!glContext) { + glContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; + } + _glRenderer = [[RTCOpenGLVideoRenderer alloc] initWithContext:glContext]; + + // GLKView manages a framebuffer for us. + _glkView = [[GLKView alloc] initWithFrame:CGRectZero + context:glContext]; + _glkView.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888; + _glkView.drawableDepthFormat = GLKViewDrawableDepthFormatNone; + _glkView.drawableStencilFormat = GLKViewDrawableStencilFormatNone; + _glkView.drawableMultisample = GLKViewDrawableMultisampleNone; + _glkView.delegate = self; + _glkView.layer.masksToBounds = YES; + _glkView.enableSetNeedsDisplay = NO; + [self addSubview:_glkView]; + + // Listen to application state in order to clean up OpenGL before app goes + // away. + NSNotificationCenter *notificationCenter = + [NSNotificationCenter defaultCenter]; + [notificationCenter addObserver:self + selector:@selector(willResignActive) + name:UIApplicationWillResignActiveNotification + object:nil]; + [notificationCenter addObserver:self + selector:@selector(didBecomeActive) + name:UIApplicationDidBecomeActiveNotification + object:nil]; + + // Frames are received on a separate thread, so we poll for current frame + // using a refresh rate proportional to screen refresh frequency. This + // occurs on the main thread. + __weak RTCEAGLVideoView *weakSelf = self; + _timer = [[RTCDisplayLinkTimer alloc] initWithTimerHandler:^{ + RTCEAGLVideoView *strongSelf = weakSelf; + [strongSelf displayLinkTimerDidFire]; + }]; + [self setupGL]; +} + +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + UIApplicationState appState = + [UIApplication sharedApplication].applicationState; + if (appState == UIApplicationStateActive) { + [self teardownGL]; + } + [_timer invalidate]; +} + +#pragma mark - UIView + +- (void)setNeedsDisplay { + [super setNeedsDisplay]; + _isDirty = YES; +} + +- (void)setNeedsDisplayInRect:(CGRect)rect { + [super setNeedsDisplayInRect:rect]; + _isDirty = YES; +} + +- (void)layoutSubviews { + [super layoutSubviews]; + _glkView.frame = self.bounds; +} + +#pragma mark - GLKViewDelegate + +// This method is called when the GLKView's content is dirty and needs to be +// redrawn. This occurs on main thread. +- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect { + // The renderer will draw the frame to the framebuffer corresponding to the + // one used by |view|. + [_glRenderer drawFrame:self.videoFrame]; +} + +#pragma mark - RTCVideoRenderer + +// These methods may be called on non-main thread. +- (void)setSize:(CGSize)size { + __weak RTCEAGLVideoView *weakSelf = self; + dispatch_async(dispatch_get_main_queue(), ^{ + RTCEAGLVideoView *strongSelf = weakSelf; + [strongSelf.delegate videoView:strongSelf didChangeVideoSize:size]; + }); +} + +- (void)renderFrame:(RTCVideoFrame *)frame { + // Generate the i420 frame on video send thread instead of main thread. + // TODO(tkchin): Remove this once RTCEAGLVideoView supports uploading + // CVPixelBuffer textures. + [frame convertBufferIfNeeded]; + self.videoFrame = frame; +} + +#pragma mark - Private + +- (void)displayLinkTimerDidFire { + // Don't render unless video frame have changed or the view content + // has explicitly been marked dirty. + if (!_isDirty && _glRenderer.lastDrawnFrame == self.videoFrame) { + return; + } + + // Always reset isDirty at this point, even if -[GLKView display] + // won't be called in the case the drawable size is empty. + _isDirty = NO; + + // Only call -[GLKView display] if the drawable size is + // non-empty. Calling display will make the GLKView setup its + // render buffer if necessary, but that will fail with error + // GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT if size is empty. + if (self.bounds.size.width > 0 && self.bounds.size.height > 0) { + [_glkView display]; + } +} + +- (void)setupGL { + self.videoFrame = nil; + [_glRenderer setupGL]; + _timer.isPaused = NO; +} + +- (void)teardownGL { + self.videoFrame = nil; + _timer.isPaused = YES; + [_glkView deleteDrawable]; + [_glRenderer teardownGL]; +} + +- (void)didBecomeActive { + [self setupGL]; +} + +- (void)willResignActive { + [self teardownGL]; +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCFieldTrials.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCFieldTrials.mm new file mode 100644 index 00000000000..38c293f0ecd --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCFieldTrials.mm @@ -0,0 +1,37 @@ +/* + * Copyright 2016 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCFieldTrials.h" + +#include <memory> + +#import "WebRTC/RTCLogging.h" + +#include "webrtc/system_wrappers/include/field_trial_default.h" + +static NSString * const kRTCEnableSendSideBweString = + @"WebRTC-SendSideBwe/Enabled/"; +static std::unique_ptr<char[]> gFieldTrialInitString; + +void RTCInitFieldTrials(RTCFieldTrialOptions options) { + NSMutableString *fieldTrialInitString = [NSMutableString string]; + if (options & RTCFieldTrialOptionsSendSideBwe) { + [fieldTrialInitString appendString:kRTCEnableSendSideBweString]; + } + size_t len = fieldTrialInitString.length + 1; + gFieldTrialInitString.reset(new char[len]); + if (![fieldTrialInitString getCString:gFieldTrialInitString.get() + maxLength:len + encoding:NSUTF8StringEncoding]) { + RTCLogError(@"Failed to convert field trial string."); + return; + } + webrtc::field_trial::InitFieldTrialsFromString(gFieldTrialInitString.get()); +} diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCFileLogger.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCFileLogger.mm new file mode 100644 index 00000000000..c1fbd747c3c --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCFileLogger.mm @@ -0,0 +1,176 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCFileLogger.h" + +#include <memory> + +#include "webrtc/base/checks.h" +#include "webrtc/base/filerotatingstream.h" +#include "webrtc/base/logging.h" +#include "webrtc/base/logsinks.h" + +NSString *const kDefaultLogDirName = @"webrtc_logs"; +NSUInteger const kDefaultMaxFileSize = 10 * 1024 * 1024; // 10MB. +const char *kRTCFileLoggerRotatingLogPrefix = "rotating_log"; + +@implementation RTCFileLogger { + BOOL _hasStarted; + NSString *_dirPath; + NSUInteger _maxFileSize; + std::unique_ptr<rtc::FileRotatingLogSink> _logSink; +} + +@synthesize severity = _severity; +@synthesize rotationType = _rotationType; +@synthesize shouldDisableBuffering = _shouldDisableBuffering; + +- (instancetype)init { + NSArray *paths = NSSearchPathForDirectoriesInDomains( + NSDocumentDirectory, NSUserDomainMask, YES); + NSString *documentsDirPath = [paths firstObject]; + NSString *defaultDirPath = + [documentsDirPath stringByAppendingPathComponent:kDefaultLogDirName]; + return [self initWithDirPath:defaultDirPath + maxFileSize:kDefaultMaxFileSize]; +} + +- (instancetype)initWithDirPath:(NSString *)dirPath + maxFileSize:(NSUInteger)maxFileSize { + return [self initWithDirPath:dirPath + maxFileSize:maxFileSize + rotationType:RTCFileLoggerTypeCall]; +} + +- (instancetype)initWithDirPath:(NSString *)dirPath + maxFileSize:(NSUInteger)maxFileSize + rotationType:(RTCFileLoggerRotationType)rotationType { + NSParameterAssert(dirPath.length); + NSParameterAssert(maxFileSize); + if (self = [super init]) { + BOOL isDir = NO; + NSFileManager *fileManager = [NSFileManager defaultManager]; + if ([fileManager fileExistsAtPath:dirPath isDirectory:&isDir]) { + if (!isDir) { + // Bail if something already exists there. + return nil; + } + } else { + if (![fileManager createDirectoryAtPath:dirPath + withIntermediateDirectories:NO + attributes:nil + error:nil]) { + // Bail if we failed to create a directory. + return nil; + } + } + _dirPath = dirPath; + _maxFileSize = maxFileSize; + _severity = RTCFileLoggerSeverityInfo; + } + return self; +} + +- (void)dealloc { + [self stop]; +} + +- (void)start { + if (_hasStarted) { + return; + } + switch (_rotationType) { + case RTCFileLoggerTypeApp: + _logSink.reset( + new rtc::FileRotatingLogSink(_dirPath.UTF8String, + kRTCFileLoggerRotatingLogPrefix, + _maxFileSize, + _maxFileSize / 10)); + break; + case RTCFileLoggerTypeCall: + _logSink.reset( + new rtc::CallSessionFileRotatingLogSink(_dirPath.UTF8String, + _maxFileSize)); + break; + } + if (!_logSink->Init()) { + LOG(LS_ERROR) << "Failed to open log files at path: " + << _dirPath.UTF8String; + _logSink.reset(); + return; + } + if (_shouldDisableBuffering) { + _logSink->DisableBuffering(); + } + rtc::LogMessage::LogThreads(true); + rtc::LogMessage::LogTimestamps(true); + rtc::LogMessage::AddLogToStream(_logSink.get(), [self rtcSeverity]); + _hasStarted = YES; +} + +- (void)stop { + if (!_hasStarted) { + return; + } + RTC_DCHECK(_logSink); + rtc::LogMessage::RemoveLogToStream(_logSink.get()); + _hasStarted = NO; + _logSink.reset(); +} + +- (NSData *)logData { + if (_hasStarted) { + return nil; + } + NSMutableData* logData = [NSMutableData data]; + std::unique_ptr<rtc::FileRotatingStream> stream; + switch(_rotationType) { + case RTCFileLoggerTypeApp: + stream.reset( + new rtc::FileRotatingStream(_dirPath.UTF8String, + kRTCFileLoggerRotatingLogPrefix)); + break; + case RTCFileLoggerTypeCall: + stream.reset(new rtc::CallSessionFileRotatingStream(_dirPath.UTF8String)); + break; + } + if (!stream->Open()) { + return logData; + } + size_t bufferSize = 0; + if (!stream->GetSize(&bufferSize) || bufferSize == 0) { + return logData; + } + size_t read = 0; + // 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))); + stream->ReadAll(buffer.get(), bufferSize, &read, nullptr); + logData = [[NSMutableData alloc] initWithBytesNoCopy:buffer.release() + length:read]; + return logData; +} + +#pragma mark - Private + +- (rtc::LoggingSeverity)rtcSeverity { + switch (_severity) { + case RTCFileLoggerSeverityVerbose: + return rtc::LS_VERBOSE; + case RTCFileLoggerSeverityInfo: + return rtc::LS_INFO; + case RTCFileLoggerSeverityWarning: + return rtc::LS_WARNING; + case RTCFileLoggerSeverityError: + return rtc::LS_ERROR; + } +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCIceCandidate+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCIceCandidate+Private.h new file mode 100644 index 00000000000..b00c8da3a3e --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCIceCandidate+Private.h @@ -0,0 +1,37 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCIceCandidate.h" + +#include <memory> + +#include "webrtc/api/jsep.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCIceCandidate () + +/** + * 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; + +/** + * Initialize an RTCIceCandidate from a native IceCandidateInterface. No + * ownership is taken of the native candidate. + */ +- (instancetype)initWithNativeCandidate: + (const webrtc::IceCandidateInterface *)candidate; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCIceCandidate.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCIceCandidate.mm new file mode 100644 index 00000000000..193403d11d8 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCIceCandidate.mm @@ -0,0 +1,71 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCIceCandidate+Private.h" + +#include <memory> + +#import "NSString+StdString.h" +#import "WebRTC/RTCLogging.h" + +@implementation RTCIceCandidate + +@synthesize sdpMid = _sdpMid; +@synthesize sdpMLineIndex = _sdpMLineIndex; +@synthesize sdp = _sdp; + +- (instancetype)initWithSdp:(NSString *)sdp + sdpMLineIndex:(int)sdpMLineIndex + sdpMid:(NSString *)sdpMid { + NSParameterAssert(sdp.length); + if (self = [super init]) { + _sdpMid = [sdpMid copy]; + _sdpMLineIndex = sdpMLineIndex; + _sdp = [sdp copy]; + } + return self; +} + +- (NSString *)description { + return [NSString stringWithFormat:@"RTCIceCandidate:\n%@\n%d\n%@", + _sdpMid, + _sdpMLineIndex, + _sdp]; +} + +#pragma mark - Private + +- (instancetype)initWithNativeCandidate: + (const webrtc::IceCandidateInterface *)candidate { + NSParameterAssert(candidate); + std::string sdp; + candidate->ToString(&sdp); + + return [self initWithSdp:[NSString stringForStdString:sdp] + sdpMLineIndex:candidate->sdp_mline_index() + sdpMid:[NSString stringForStdString:candidate->sdp_mid()]]; +} + +- (std::unique_ptr<webrtc::IceCandidateInterface>)nativeCandidate { + webrtc::SdpParseError error; + + webrtc::IceCandidateInterface *candidate = webrtc::CreateIceCandidate( + _sdpMid.stdString, _sdpMLineIndex, _sdp.stdString, &error); + + if (!candidate) { + RTCLog(@"Failed to create ICE candidate: %s\nline: %s", + error.description.c_str(), + error.line.c_str()); + } + + return std::unique_ptr<webrtc::IceCandidateInterface>(candidate); +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCIceServer+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCIceServer+Private.h new file mode 100644 index 00000000000..7efeda412fc --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCIceServer+Private.h @@ -0,0 +1,32 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCIceServer.h" + +#include "webrtc/api/peerconnectioninterface.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCIceServer () + +/** + * 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; + +/** Initialize an RTCIceServer from a native IceServer. */ +- (instancetype)initWithNativeServer: + (webrtc::PeerConnectionInterface::IceServer)nativeServer; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCIceServer.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCIceServer.mm new file mode 100644 index 00000000000..41084b93571 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCIceServer.mm @@ -0,0 +1,78 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCIceServer+Private.h" + +#import "NSString+StdString.h" + +@implementation RTCIceServer + +@synthesize urlStrings = _urlStrings; +@synthesize username = _username; +@synthesize credential = _credential; + +- (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings { + NSParameterAssert(urlStrings.count); + return [self initWithURLStrings:urlStrings + username:nil + credential:nil]; +} + +- (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings + username:(NSString *)username + credential:(NSString *)credential { + NSParameterAssert(urlStrings.count); + if (self = [super init]) { + _urlStrings = [[NSArray alloc] initWithArray:urlStrings copyItems:YES]; + _username = [username copy]; + _credential = [credential copy]; + } + return self; +} + +- (NSString *)description { + return [NSString stringWithFormat:@"RTCIceServer:\n%@\n%@\n%@", + _urlStrings, + _username, + _credential]; +} + +#pragma mark - Private + +- (webrtc::PeerConnectionInterface::IceServer)nativeServer { + __block webrtc::PeerConnectionInterface::IceServer iceServer; + + iceServer.username = [NSString stdStringForString:_username]; + iceServer.password = [NSString stdStringForString:_credential]; + + [_urlStrings enumerateObjectsUsingBlock:^(NSString *url, + NSUInteger idx, + BOOL *stop) { + iceServer.urls.push_back(url.stdString); + }]; + return iceServer; +} + +- (instancetype)initWithNativeServer: + (webrtc::PeerConnectionInterface::IceServer)nativeServer { + NSMutableArray *urls = + [NSMutableArray arrayWithCapacity:nativeServer.urls.size()]; + for (auto const &url : nativeServer.urls) { + [urls addObject:[NSString stringForStdString:url]]; + } + NSString *username = [NSString stringForStdString:nativeServer.username]; + NSString *credential = [NSString stringForStdString:nativeServer.password]; + self = [self initWithURLStrings:urls + username:username + credential:credential]; + return self; +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCLogging.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCLogging.mm new file mode 100644 index 00000000000..ef62d1f6697 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCLogging.mm @@ -0,0 +1,47 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCLogging.h" + +#include "webrtc/base/logging.h" + +rtc::LoggingSeverity RTCGetNativeLoggingSeverity(RTCLoggingSeverity severity) { + switch (severity) { + case RTCLoggingSeverityVerbose: + return rtc::LS_VERBOSE; + case RTCLoggingSeverityInfo: + return rtc::LS_INFO; + case RTCLoggingSeverityWarning: + return rtc::LS_WARNING; + case RTCLoggingSeverityError: + return rtc::LS_ERROR; + } +} + +void RTCLogEx(RTCLoggingSeverity severity, NSString* log_string) { + if (log_string.length) { + const char* utf8_string = log_string.UTF8String; + LOG_V(RTCGetNativeLoggingSeverity(severity)) << utf8_string; + } +} + +void RTCSetMinDebugLogLevel(RTCLoggingSeverity severity) { + rtc::LogMessage::LogToDebug(RTCGetNativeLoggingSeverity(severity)); +} + +NSString* RTCFileName(const char* file_path) { + NSString* ns_file_path = + [[NSString alloc] initWithBytesNoCopy:const_cast<char*>(file_path) + length:strlen(file_path) + encoding:NSUTF8StringEncoding + freeWhenDone:NO]; + return ns_file_path.lastPathComponent; +} + diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCMediaConstraints+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCMediaConstraints+Private.h new file mode 100644 index 00000000000..606a132da64 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCMediaConstraints+Private.h @@ -0,0 +1,54 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCMediaConstraints.h" + +#include <memory> + +#include "webrtc/api/mediaconstraintsinterface.h" + +namespace webrtc { + +class MediaConstraints : public MediaConstraintsInterface { + public: + virtual ~MediaConstraints(); + MediaConstraints(); + MediaConstraints( + const MediaConstraintsInterface::Constraints& mandatory, + const MediaConstraintsInterface::Constraints& optional); + virtual const Constraints& GetMandatory() const; + virtual const Constraints& GetOptional() const; + + private: + MediaConstraintsInterface::Constraints mandatory_; + MediaConstraintsInterface::Constraints optional_; +}; + +} // namespace webrtc + + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCMediaConstraints () + +/** + * A MediaConstraints representation of this RTCMediaConstraints object. This is + * needed to pass to the underlying C++ APIs. + */ +- (std::unique_ptr<webrtc::MediaConstraints>)nativeConstraints; + +/** Return a native Constraints object representing these constraints */ ++ (webrtc::MediaConstraintsInterface::Constraints) + nativeConstraintsForConstraints: + (NSDictionary<NSString *, NSString *> *)constraints; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCMediaConstraints.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCMediaConstraints.mm new file mode 100644 index 00000000000..11be2ec026c --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCMediaConstraints.mm @@ -0,0 +1,94 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCMediaConstraints+Private.h" + +#import "NSString+StdString.h" + +#include <memory> + +namespace webrtc { + +MediaConstraints::~MediaConstraints() {} + +MediaConstraints::MediaConstraints() {} + +MediaConstraints::MediaConstraints( + const MediaConstraintsInterface::Constraints& mandatory, + const MediaConstraintsInterface::Constraints& optional) + : mandatory_(mandatory), optional_(optional) {} + +const MediaConstraintsInterface::Constraints& +MediaConstraints::GetMandatory() const { + return mandatory_; +} + +const MediaConstraintsInterface::Constraints& +MediaConstraints::GetOptional() const { + return optional_; +} + +} // namespace webrtc + + +@implementation RTCMediaConstraints { + NSDictionary<NSString *, NSString *> *_mandatory; + NSDictionary<NSString *, NSString *> *_optional; +} + +- (instancetype)initWithMandatoryConstraints: + (NSDictionary<NSString *, NSString *> *)mandatory + optionalConstraints: + (NSDictionary<NSString *, NSString *> *)optional { + if (self = [super init]) { + _mandatory = [[NSDictionary alloc] initWithDictionary:mandatory + copyItems:YES]; + _optional = [[NSDictionary alloc] initWithDictionary:optional + copyItems:YES]; + } + return self; +} + +- (NSString *)description { + return [NSString stringWithFormat:@"RTCMediaConstraints:\n%@\n%@", + _mandatory, + _optional]; +} + +#pragma mark - Private + +- (std::unique_ptr<webrtc::MediaConstraints>)nativeConstraints { + webrtc::MediaConstraintsInterface::Constraints mandatory = + [[self class] nativeConstraintsForConstraints:_mandatory]; + webrtc::MediaConstraintsInterface::Constraints optional = + [[self class] nativeConstraintsForConstraints:_optional]; + + webrtc::MediaConstraints *nativeConstraints = + new webrtc::MediaConstraints(mandatory, optional); + return std::unique_ptr<webrtc::MediaConstraints>(nativeConstraints); +} + ++ (webrtc::MediaConstraintsInterface::Constraints) + nativeConstraintsForConstraints: + (NSDictionary<NSString *, NSString *> *)constraints { + webrtc::MediaConstraintsInterface::Constraints nativeConstraints; + for (NSString *key in constraints) { + 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); + nativeConstraints.push_back(webrtc::MediaConstraintsInterface::Constraint( + key.stdString, value.stdString)); + } + return nativeConstraints; +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCMediaStream+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCMediaStream+Private.h new file mode 100644 index 00000000000..7f8707228d3 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCMediaStream+Private.h @@ -0,0 +1,36 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCMediaStream.h" + +#include "webrtc/api/mediastreaminterface.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCMediaStream () + +/** + * 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; + +/** Initialize an RTCMediaStream with an id. */ +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + streamId:(NSString *)streamId; + +/** Initialize an RTCMediaStream from a native MediaStreamInterface. */ +- (instancetype)initWithNativeMediaStream: + (rtc::scoped_refptr<webrtc::MediaStreamInterface>)nativeMediaStream; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCMediaStream.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCMediaStream.mm new file mode 100644 index 00000000000..0737dee8a93 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCMediaStream.mm @@ -0,0 +1,122 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCMediaStream+Private.h" + +#include <vector> + +#import "NSString+StdString.h" +#import "RTCAudioTrack+Private.h" +#import "RTCMediaStreamTrack+Private.h" +#import "RTCPeerConnectionFactory+Private.h" +#import "RTCVideoTrack+Private.h" + +@implementation RTCMediaStream { + NSMutableArray *_audioTracks; + NSMutableArray *_videoTracks; + rtc::scoped_refptr<webrtc::MediaStreamInterface> _nativeMediaStream; +} + +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + streamId:(NSString *)streamId { + NSParameterAssert(factory); + NSParameterAssert(streamId.length); + std::string nativeId = [NSString stdStringForString:streamId]; + rtc::scoped_refptr<webrtc::MediaStreamInterface> stream = + factory.nativeFactory->CreateLocalMediaStream(nativeId); + return [self initWithNativeMediaStream:stream]; +} + +- (NSArray<RTCAudioTrack *> *)audioTracks { + return [_audioTracks copy]; +} + +- (NSArray<RTCVideoTrack *> *)videoTracks { + return [_videoTracks copy]; +} + +- (NSString *)streamId { + return [NSString stringForStdString:_nativeMediaStream->label()]; +} + +- (void)addAudioTrack:(RTCAudioTrack *)audioTrack { + if (_nativeMediaStream->AddTrack(audioTrack.nativeAudioTrack)) { + [_audioTracks addObject:audioTrack]; + } +} + +- (void)addVideoTrack:(RTCVideoTrack *)videoTrack { + if (_nativeMediaStream->AddTrack(videoTrack.nativeVideoTrack)) { + [_videoTracks addObject:videoTrack]; + } +} + +- (void)removeAudioTrack:(RTCAudioTrack *)audioTrack { + NSUInteger index = [_audioTracks indexOfObjectIdenticalTo:audioTrack]; + NSAssert(index != NSNotFound, + @"|removeAudioTrack| called on unexpected RTCAudioTrack"); + if (index != NSNotFound && + _nativeMediaStream->RemoveTrack(audioTrack.nativeAudioTrack)) { + [_audioTracks removeObjectAtIndex:index]; + } +} + +- (void)removeVideoTrack:(RTCVideoTrack *)videoTrack { + NSUInteger index = [_videoTracks indexOfObjectIdenticalTo:videoTrack]; + NSAssert(index != NSNotFound, + @"|removeVideoTrack| called on unexpected RTCVideoTrack"); + if (index != NSNotFound && + _nativeMediaStream->RemoveTrack(videoTrack.nativeVideoTrack)) { + [_videoTracks removeObjectAtIndex:index]; + } +} + +- (NSString *)description { + return [NSString stringWithFormat:@"RTCMediaStream:\n%@\nA=%lu\nV=%lu", + self.streamId, + (unsigned long)self.audioTracks.count, + (unsigned long)self.videoTracks.count]; +} + +#pragma mark - Private + +- (rtc::scoped_refptr<webrtc::MediaStreamInterface>)nativeMediaStream { + return _nativeMediaStream; +} + +- (instancetype)initWithNativeMediaStream: + (rtc::scoped_refptr<webrtc::MediaStreamInterface>)nativeMediaStream { + NSParameterAssert(nativeMediaStream); + if (self = [super init]) { + webrtc::AudioTrackVector audioTracks = nativeMediaStream->GetAudioTracks(); + webrtc::VideoTrackVector videoTracks = nativeMediaStream->GetVideoTracks(); + + _audioTracks = [NSMutableArray arrayWithCapacity:audioTracks.size()]; + _videoTracks = [NSMutableArray arrayWithCapacity:videoTracks.size()]; + _nativeMediaStream = nativeMediaStream; + + for (auto &track : audioTracks) { + RTCMediaStreamTrackType type = RTCMediaStreamTrackTypeAudio; + RTCAudioTrack *audioTrack = + [[RTCAudioTrack alloc] initWithNativeTrack:track type:type]; + [_audioTracks addObject:audioTrack]; + } + + for (auto &track : videoTracks) { + RTCMediaStreamTrackType type = RTCMediaStreamTrackTypeVideo; + RTCVideoTrack *videoTrack = + [[RTCVideoTrack alloc] initWithNativeTrack:track type:type]; + [_videoTracks addObject:videoTrack]; + } + } + return self; +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCMediaStreamTrack+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCMediaStreamTrack+Private.h new file mode 100644 index 00000000000..d5261266b89 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCMediaStreamTrack+Private.h @@ -0,0 +1,54 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCMediaStreamTrack.h" + +#include "webrtc/api/mediastreaminterface.h" + +typedef NS_ENUM(NSInteger, RTCMediaStreamTrackType) { + RTCMediaStreamTrackTypeAudio, + RTCMediaStreamTrackTypeVideo, +}; + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCMediaStreamTrack () + +/** + * The native MediaStreamTrackInterface passed in or created during + * construction. + */ +@property(nonatomic, readonly) + rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> nativeTrack; + +/** + * Initialize an RTCMediaStreamTrack from a native MediaStreamTrackInterface. + */ +- (instancetype)initWithNativeTrack: + (rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack + type:(RTCMediaStreamTrackType)type + NS_DESIGNATED_INITIALIZER; + +- (instancetype)initWithNativeTrack: + (rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack; + +- (BOOL)isEqualToTrack:(RTCMediaStreamTrack *)track; + ++ (webrtc::MediaStreamTrackInterface::TrackState)nativeTrackStateForState: + (RTCMediaStreamTrackState)state; + ++ (RTCMediaStreamTrackState)trackStateForNativeState: + (webrtc::MediaStreamTrackInterface::TrackState)nativeState; + ++ (NSString *)stringForState:(RTCMediaStreamTrackState)state; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCMediaStreamTrack.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCMediaStreamTrack.mm new file mode 100644 index 00000000000..208550f6c86 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCMediaStreamTrack.mm @@ -0,0 +1,137 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCMediaStreamTrack+Private.h" + +#import "NSString+StdString.h" + +NSString * const kRTCMediaStreamTrackKindAudio = + @(webrtc::MediaStreamTrackInterface::kAudioKind); +NSString * const kRTCMediaStreamTrackKindVideo = + @(webrtc::MediaStreamTrackInterface::kVideoKind); + +@implementation RTCMediaStreamTrack { + rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> _nativeTrack; + RTCMediaStreamTrackType _type; +} + +- (NSString *)kind { + return [NSString stringForStdString:_nativeTrack->kind()]; +} + +- (NSString *)trackId { + return [NSString stringForStdString:_nativeTrack->id()]; +} + +- (BOOL)isEnabled { + return _nativeTrack->enabled(); +} + +- (void)setIsEnabled:(BOOL)isEnabled { + _nativeTrack->set_enabled(isEnabled); +} + +- (RTCMediaStreamTrackState)readyState { + return [[self class] trackStateForNativeState:_nativeTrack->state()]; +} + +- (NSString *)description { + NSString *readyState = [[self class] stringForState:self.readyState]; + return [NSString stringWithFormat:@"RTCMediaStreamTrack:\n%@\n%@\n%@\n%@", + self.kind, + self.trackId, + self.isEnabled ? @"enabled" : @"disabled", + readyState]; +} + +- (BOOL)isEqual:(id)object { + if (self == object) { + return YES; + } + if (![object isMemberOfClass:[self class]]) { + return NO; + } + return [self isEqualToTrack:(RTCMediaStreamTrack *)object]; +} + +- (NSUInteger)hash { + return (NSUInteger)_nativeTrack.get(); +} + +#pragma mark - Private + +- (rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack { + return _nativeTrack; +} + +- (instancetype)initWithNativeTrack: + (rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack + type:(RTCMediaStreamTrackType)type { + NSParameterAssert(nativeTrack); + if (self = [super init]) { + _nativeTrack = nativeTrack; + _type = type; + } + return self; +} + +- (instancetype)initWithNativeTrack: + (rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack { + NSParameterAssert(nativeTrack); + if (nativeTrack->kind() == + std::string(webrtc::MediaStreamTrackInterface::kAudioKind)) { + return [self initWithNativeTrack:nativeTrack + type:RTCMediaStreamTrackTypeAudio]; + } + if (nativeTrack->kind() == + std::string(webrtc::MediaStreamTrackInterface::kVideoKind)) { + return [self initWithNativeTrack:nativeTrack + type:RTCMediaStreamTrackTypeVideo]; + } + return nil; +} + +- (BOOL)isEqualToTrack:(RTCMediaStreamTrack *)track { + if (!track) { + return NO; + } + return _nativeTrack == track.nativeTrack; +} + ++ (webrtc::MediaStreamTrackInterface::TrackState)nativeTrackStateForState: + (RTCMediaStreamTrackState)state { + switch (state) { + case RTCMediaStreamTrackStateLive: + return webrtc::MediaStreamTrackInterface::kLive; + case RTCMediaStreamTrackStateEnded: + return webrtc::MediaStreamTrackInterface::kEnded; + } +} + ++ (RTCMediaStreamTrackState)trackStateForNativeState: + (webrtc::MediaStreamTrackInterface::TrackState)nativeState { + switch (nativeState) { + case webrtc::MediaStreamTrackInterface::kLive: + return RTCMediaStreamTrackStateLive; + case webrtc::MediaStreamTrackInterface::kEnded: + return RTCMediaStreamTrackStateEnded; + } +} + ++ (NSString *)stringForState:(RTCMediaStreamTrackState)state { + switch (state) { + case RTCMediaStreamTrackStateLive: + return @"Live"; + case RTCMediaStreamTrackStateEnded: + return @"Ended"; + } +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCNSGLVideoView.m b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCNSGLVideoView.m new file mode 100644 index 00000000000..415efe82282 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCNSGLVideoView.m @@ -0,0 +1,146 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#if !TARGET_OS_IPHONE + +#import "WebRTC/RTCNSGLVideoView.h" + +#import <CoreVideo/CVDisplayLink.h> +#import <OpenGL/gl3.h> + +#import "RTCOpenGLVideoRenderer.h" +#import "WebRTC/RTCVideoFrame.h" + +@interface RTCNSGLVideoView () +// |videoFrame| is set when we receive a frame from a worker thread and is read +// from the display link callback so atomicity is required. +@property(atomic, strong) RTCVideoFrame *videoFrame; +@property(atomic, strong) RTCOpenGLVideoRenderer *glRenderer; +- (void)drawFrame; +@end + +static CVReturn OnDisplayLinkFired(CVDisplayLinkRef displayLink, + const CVTimeStamp *now, + const CVTimeStamp *outputTime, + CVOptionFlags flagsIn, + CVOptionFlags *flagsOut, + void *displayLinkContext) { + RTCNSGLVideoView *view = (__bridge RTCNSGLVideoView *)displayLinkContext; + [view drawFrame]; + return kCVReturnSuccess; +} + +@implementation RTCNSGLVideoView { + CVDisplayLinkRef _displayLink; +} + +@synthesize delegate = _delegate; +@synthesize videoFrame = _videoFrame; +@synthesize glRenderer = _glRenderer; + +- (void)dealloc { + [self teardownDisplayLink]; +} + +- (void)drawRect:(NSRect)rect { + [self drawFrame]; +} + +- (void)reshape { + [super reshape]; + NSRect frame = [self frame]; + CGLLockContext([[self openGLContext] CGLContextObj]); + glViewport(0, 0, frame.size.width, frame.size.height); + CGLUnlockContext([[self openGLContext] CGLContextObj]); +} + +- (void)lockFocus { + NSOpenGLContext *context = [self openGLContext]; + [super lockFocus]; + if ([context view] != self) { + [context setView:self]; + } + [context makeCurrentContext]; +} + +- (void)prepareOpenGL { + [super prepareOpenGL]; + if (!self.glRenderer) { + self.glRenderer = + [[RTCOpenGLVideoRenderer alloc] initWithContext:[self openGLContext]]; + } + [self.glRenderer setupGL]; + [self setupDisplayLink]; +} + +- (void)clearGLContext { + [self.glRenderer teardownGL]; + self.glRenderer = nil; + [super clearGLContext]; +} + +#pragma mark - RTCVideoRenderer + +// These methods may be called on non-main thread. +- (void)setSize:(CGSize)size { + dispatch_async(dispatch_get_main_queue(), ^{ + [self.delegate videoView:self didChangeVideoSize:size]; + }); +} + +- (void)renderFrame:(RTCVideoFrame *)frame { + self.videoFrame = frame; +} + +#pragma mark - Private + +- (void)drawFrame { + RTCVideoFrame *videoFrame = self.videoFrame; + if (self.glRenderer.lastDrawnFrame != videoFrame) { + // This method may be called from CVDisplayLink callback which isn't on the + // main thread so we have to lock the GL context before drawing. + CGLLockContext([[self openGLContext] CGLContextObj]); + [self.glRenderer drawFrame:videoFrame]; + CGLUnlockContext([[self openGLContext] CGLContextObj]); + } +} + +- (void)setupDisplayLink { + if (_displayLink) { + return; + } + // Synchronize buffer swaps with vertical refresh rate. + GLint swapInt = 1; + [[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval]; + + // Create display link. + CVDisplayLinkCreateWithActiveCGDisplays(&_displayLink); + CVDisplayLinkSetOutputCallback(_displayLink, + &OnDisplayLinkFired, + (__bridge void *)self); + // Set the display link for the current renderer. + CGLContextObj cglContext = [[self openGLContext] CGLContextObj]; + CGLPixelFormatObj cglPixelFormat = [[self pixelFormat] CGLPixelFormatObj]; + CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext( + _displayLink, cglContext, cglPixelFormat); + CVDisplayLinkStart(_displayLink); +} + +- (void)teardownDisplayLink { + if (!_displayLink) { + return; + } + CVDisplayLinkRelease(_displayLink); + _displayLink = NULL; +} + +@end + +#endif // !TARGET_OS_IPHONE diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCOpenGLVideoRenderer.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCOpenGLVideoRenderer.h new file mode 100644 index 00000000000..7041861014a --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCOpenGLVideoRenderer.h @@ -0,0 +1,61 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> +#if TARGET_OS_IPHONE +#import <GLKit/GLKit.h> +#else +#import <AppKit/NSOpenGL.h> +#endif + +#import "WebRTC/RTCMacros.h" + +NS_ASSUME_NONNULL_BEGIN + +@class RTCVideoFrame; + +// RTCOpenGLVideoRenderer issues appropriate OpenGL commands to draw a frame to +// the currently bound framebuffer. Supports OpenGL 3.2 and OpenGLES 2.0. OpenGL +// framebuffer creation and management should be handled elsewhere using the +// same context used to initialize this class. +RTC_EXPORT +@interface RTCOpenGLVideoRenderer : NSObject + +// The last successfully drawn frame. Used to avoid drawing frames unnecessarily +// hence saving battery life by reducing load. +@property(nonatomic, readonly) RTCVideoFrame *lastDrawnFrame; + +#if TARGET_OS_IPHONE +- (instancetype)initWithContext:(EAGLContext *)context + NS_DESIGNATED_INITIALIZER; +#else +- (instancetype)initWithContext:(NSOpenGLContext *)context + NS_DESIGNATED_INITIALIZER; +#endif + +// Draws |frame| onto the currently bound OpenGL framebuffer. |setupGL| must be +// called before this function will succeed. +- (BOOL)drawFrame:(RTCVideoFrame *)frame; + +// The following methods are used to manage OpenGL resources. On iOS +// applications should release resources when placed in background for use in +// the foreground application. In fact, attempting to call OpenGLES commands +// while in background will result in application termination. + +// Sets up the OpenGL state needed for rendering. +- (void)setupGL; +// Tears down the OpenGL state created by |setupGL|. +- (void)teardownGL; + +- (instancetype)init NS_UNAVAILABLE; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCOpenGLVideoRenderer.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCOpenGLVideoRenderer.mm new file mode 100644 index 00000000000..7d7b416b888 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCOpenGLVideoRenderer.mm @@ -0,0 +1,484 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCOpenGLVideoRenderer.h" + +#if TARGET_OS_IPHONE +#import <OpenGLES/ES3/gl.h> +#else +#import <OpenGL/gl3.h> +#endif +#include <string.h> +#include <memory> + +#import "WebRTC/RTCVideoFrame.h" + + +// TODO(tkchin): check and log openGL errors. Methods here return BOOLs in +// anticipation of that happening in the future. + +#if TARGET_OS_IPHONE +#define RTC_PIXEL_FORMAT GL_LUMINANCE +#define SHADER_VERSION +#define VERTEX_SHADER_IN "attribute" +#define VERTEX_SHADER_OUT "varying" +#define FRAGMENT_SHADER_IN "varying" +#define FRAGMENT_SHADER_OUT +#define FRAGMENT_SHADER_COLOR "gl_FragColor" +#define FRAGMENT_SHADER_TEXTURE "texture2D" +#else +#define RTC_PIXEL_FORMAT GL_RED +#define SHADER_VERSION "#version 150\n" +#define VERTEX_SHADER_IN "in" +#define VERTEX_SHADER_OUT "out" +#define FRAGMENT_SHADER_IN "in" +#define FRAGMENT_SHADER_OUT "out vec4 fragColor;\n" +#define FRAGMENT_SHADER_COLOR "fragColor" +#define FRAGMENT_SHADER_TEXTURE "texture" +#endif + +// Vertex shader doesn't do anything except pass coordinates through. +static const char kVertexShaderSource[] = + SHADER_VERSION + VERTEX_SHADER_IN " vec2 position;\n" + VERTEX_SHADER_IN " vec2 texcoord;\n" + VERTEX_SHADER_OUT " vec2 v_texcoord;\n" + "void main() {\n" + " gl_Position = vec4(position.x, position.y, 0.0, 1.0);\n" + " v_texcoord = texcoord;\n" + "}\n"; + +// Fragment shader converts YUV values from input textures into a final RGB +// pixel. The conversion formula is from http://www.fourcc.org/fccyvrgb.php. +static const char kFragmentShaderSource[] = + SHADER_VERSION + "precision highp float;" + FRAGMENT_SHADER_IN " vec2 v_texcoord;\n" + "uniform lowp sampler2D s_textureY;\n" + "uniform lowp sampler2D s_textureU;\n" + "uniform lowp sampler2D s_textureV;\n" + FRAGMENT_SHADER_OUT + "void main() {\n" + " float y, u, v, r, g, b;\n" + " y = " FRAGMENT_SHADER_TEXTURE "(s_textureY, v_texcoord).r;\n" + " u = " FRAGMENT_SHADER_TEXTURE "(s_textureU, v_texcoord).r;\n" + " v = " FRAGMENT_SHADER_TEXTURE "(s_textureV, v_texcoord).r;\n" + " u = u - 0.5;\n" + " v = v - 0.5;\n" + " r = y + 1.403 * v;\n" + " g = y - 0.344 * u - 0.714 * v;\n" + " b = y + 1.770 * u;\n" + " " FRAGMENT_SHADER_COLOR " = vec4(r, g, b, 1.0);\n" + " }\n"; + +// Compiles a shader of the given |type| with GLSL source |source| and returns +// the shader handle or 0 on error. +GLuint CreateShader(GLenum type, const GLchar *source) { + GLuint shader = glCreateShader(type); + if (!shader) { + return 0; + } + glShaderSource(shader, 1, &source, NULL); + glCompileShader(shader); + GLint compileStatus = GL_FALSE; + glGetShaderiv(shader, GL_COMPILE_STATUS, &compileStatus); + if (compileStatus == GL_FALSE) { + glDeleteShader(shader); + shader = 0; + } + return shader; +} + +// Links a shader program with the given vertex and fragment shaders and +// returns the program handle or 0 on error. +GLuint CreateProgram(GLuint vertexShader, GLuint fragmentShader) { + if (vertexShader == 0 || fragmentShader == 0) { + return 0; + } + GLuint program = glCreateProgram(); + if (!program) { + return 0; + } + glAttachShader(program, vertexShader); + glAttachShader(program, fragmentShader); + glLinkProgram(program); + GLint linkStatus = GL_FALSE; + glGetProgramiv(program, GL_LINK_STATUS, &linkStatus); + if (linkStatus == GL_FALSE) { + glDeleteProgram(program); + program = 0; + } + return program; +} + +// When modelview and projection matrices are identity (default) the world is +// contained in the square around origin with unit size 2. Drawing to these +// coordinates is equivalent to drawing to the entire screen. The texture is +// stretched over that square using texture coordinates (u, v) that range +// from (0, 0) to (1, 1) inclusive. Texture coordinates are flipped vertically +// here because the incoming frame has origin in upper left hand corner but +// OpenGL expects origin in bottom left corner. +const GLfloat gVertices[] = { + // X, Y, U, V. + -1, -1, 0, 1, // Bottom left. + 1, -1, 1, 1, // Bottom right. + 1, 1, 1, 0, // Top right. + -1, 1, 0, 0, // Top left. +}; + +// |kNumTextures| must not exceed 8, which is the limit in OpenGLES2. Two sets +// of 3 textures are used here, one for each of the Y, U and V planes. Having +// two sets alleviates CPU blockage in the event that the GPU is asked to render +// to a texture that is already in use. +static const GLsizei kNumTextureSets = 2; +static const GLsizei kNumTextures = 3 * kNumTextureSets; + +@implementation RTCOpenGLVideoRenderer { +#if TARGET_OS_IPHONE + EAGLContext *_context; +#else + NSOpenGLContext *_context; +#endif + BOOL _isInitialized; + GLint _currentTextureSet; + // Handles for OpenGL constructs. + GLuint _textures[kNumTextures]; + GLuint _program; +#if !TARGET_OS_IPHONE + GLuint _vertexArray; +#endif + GLuint _vertexBuffer; + GLint _position; + GLint _texcoord; + GLint _ySampler; + GLint _uSampler; + GLint _vSampler; + // Used to create a non-padded plane for GPU upload when we receive padded + // frames. + std::unique_ptr<uint8_t[]> _planeBuffer; +} + +@synthesize lastDrawnFrame = _lastDrawnFrame; + ++ (void)initialize { + // Disable dithering for performance. + glDisable(GL_DITHER); +} + +#if TARGET_OS_IPHONE +- (instancetype)initWithContext:(EAGLContext *)context { +#else +- (instancetype)initWithContext:(NSOpenGLContext *)context { +#endif + NSAssert(context != nil, @"context cannot be nil"); + if (self = [super init]) { + _context = context; + } + return self; +} + +- (BOOL)drawFrame:(RTCVideoFrame *)frame { + if (!_isInitialized) { + return NO; + } + if (_lastDrawnFrame == frame) { + return NO; + } + [self ensureGLContext]; + glClear(GL_COLOR_BUFFER_BIT); + if (frame) { + if (![self updateTextureSizesForFrame:frame] || + ![self updateTextureDataForFrame:frame]) { + return NO; + } +#if !TARGET_OS_IPHONE + glBindVertexArray(_vertexArray); +#endif + glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + } +#if !TARGET_OS_IPHONE + [_context flushBuffer]; +#endif + _lastDrawnFrame = frame; + return YES; +} + +- (void)setupGL { + if (_isInitialized) { + return; + } + [self ensureGLContext]; + if (![self setupProgram]) { + return; + } + if (![self setupTextures]) { + return; + } + if (![self setupVertices]) { + return; + } + glUseProgram(_program); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + _isInitialized = YES; +} + +- (void)teardownGL { + if (!_isInitialized) { + return; + } + [self ensureGLContext]; + glDeleteProgram(_program); + _program = 0; + glDeleteTextures(kNumTextures, _textures); + glDeleteBuffers(1, &_vertexBuffer); + _vertexBuffer = 0; +#if !TARGET_OS_IPHONE + glDeleteVertexArrays(1, &_vertexArray); +#endif + _isInitialized = NO; +} + +#pragma mark - Private + +- (void)ensureGLContext { + NSAssert(_context, @"context shouldn't be nil"); +#if TARGET_OS_IPHONE + if ([EAGLContext currentContext] != _context) { + [EAGLContext setCurrentContext:_context]; + } +#else + if ([NSOpenGLContext currentContext] != _context) { + [_context makeCurrentContext]; + } +#endif +} + +- (BOOL)setupProgram { + NSAssert(!_program, @"program already set up"); + GLuint vertexShader = CreateShader(GL_VERTEX_SHADER, kVertexShaderSource); + NSAssert(vertexShader, @"failed to create vertex shader"); + GLuint fragmentShader = + CreateShader(GL_FRAGMENT_SHADER, kFragmentShaderSource); + NSAssert(fragmentShader, @"failed to create fragment shader"); + _program = CreateProgram(vertexShader, fragmentShader); + // Shaders are created only to generate program. + if (vertexShader) { + glDeleteShader(vertexShader); + } + if (fragmentShader) { + glDeleteShader(fragmentShader); + } + if (!_program) { + return NO; + } + _position = glGetAttribLocation(_program, "position"); + _texcoord = glGetAttribLocation(_program, "texcoord"); + _ySampler = glGetUniformLocation(_program, "s_textureY"); + _uSampler = glGetUniformLocation(_program, "s_textureU"); + _vSampler = glGetUniformLocation(_program, "s_textureV"); + if (_position < 0 || _texcoord < 0 || _ySampler < 0 || _uSampler < 0 || + _vSampler < 0) { + return NO; + } + return YES; +} + +- (BOOL)setupTextures { + glGenTextures(kNumTextures, _textures); + // Set parameters for each of the textures we created. + for (GLsizei i = 0; i < kNumTextures; i++) { + glActiveTexture(GL_TEXTURE0 + i); + glBindTexture(GL_TEXTURE_2D, _textures[i]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + } + return YES; +} + +- (BOOL)updateTextureSizesForFrame:(RTCVideoFrame *)frame { + if (frame.height == _lastDrawnFrame.height && + frame.width == _lastDrawnFrame.width && + frame.chromaWidth == _lastDrawnFrame.chromaWidth && + frame.chromaHeight == _lastDrawnFrame.chromaHeight) { + return YES; + } + GLsizei lumaWidth = static_cast<GLsizei>(frame.width); + GLsizei lumaHeight = static_cast<GLsizei>(frame.height); + GLsizei chromaWidth = static_cast<GLsizei>(frame.chromaWidth); + GLsizei chromaHeight = static_cast<GLsizei>(frame.chromaHeight); + for (GLint i = 0; i < kNumTextureSets; i++) { + glActiveTexture(GL_TEXTURE0 + i * 3); + glTexImage2D(GL_TEXTURE_2D, + 0, + RTC_PIXEL_FORMAT, + lumaWidth, + lumaHeight, + 0, + RTC_PIXEL_FORMAT, + GL_UNSIGNED_BYTE, + 0); + glActiveTexture(GL_TEXTURE0 + i * 3 + 1); + glTexImage2D(GL_TEXTURE_2D, + 0, + RTC_PIXEL_FORMAT, + chromaWidth, + chromaHeight, + 0, + RTC_PIXEL_FORMAT, + GL_UNSIGNED_BYTE, + 0); + glActiveTexture(GL_TEXTURE0 + i * 3 + 2); + glTexImage2D(GL_TEXTURE_2D, + 0, + RTC_PIXEL_FORMAT, + chromaWidth, + chromaHeight, + 0, + RTC_PIXEL_FORMAT, + GL_UNSIGNED_BYTE, + 0); + } + if ((NSUInteger)frame.yPitch != frame.width || + (NSUInteger)frame.uPitch != frame.chromaWidth || + (NSUInteger)frame.vPitch != frame.chromaWidth) { + _planeBuffer.reset(new uint8_t[frame.width * frame.height]); + } else { + _planeBuffer.reset(); + } + return YES; +} + +- (void)uploadPlane:(const uint8_t *)plane + sampler:(GLint)sampler + offset:(GLint)offset + width:(size_t)width + height:(size_t)height + stride:(int32_t)stride { + glActiveTexture(static_cast<GLenum>(GL_TEXTURE0 + offset)); + // When setting texture sampler uniforms, the texture index is used not + // the texture handle. + glUniform1i(sampler, offset); +#if TARGET_OS_IPHONE + BOOL hasUnpackRowLength = _context.API == kEAGLRenderingAPIOpenGLES3; +#else + BOOL hasUnpackRowLength = YES; +#endif + const uint8_t *uploadPlane = plane; + if ((size_t)stride != width) { + if (hasUnpackRowLength) { + // GLES3 allows us to specify stride. + glPixelStorei(GL_UNPACK_ROW_LENGTH, stride); + glTexImage2D(GL_TEXTURE_2D, + 0, + RTC_PIXEL_FORMAT, + static_cast<GLsizei>(width), + static_cast<GLsizei>(height), + 0, + RTC_PIXEL_FORMAT, + GL_UNSIGNED_BYTE, + uploadPlane); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + return; + } else { + // Make an unpadded copy and upload that instead. Quick profiling showed + // that this is faster than uploading row by row using glTexSubImage2D. + uint8_t *unpaddedPlane = _planeBuffer.get(); + for (size_t y = 0; y < height; ++y) { + memcpy(unpaddedPlane + y * width, plane + y * stride, width); + } + uploadPlane = unpaddedPlane; + } + } + glTexImage2D(GL_TEXTURE_2D, + 0, + RTC_PIXEL_FORMAT, + static_cast<GLsizei>(width), + static_cast<GLsizei>(height), + 0, + RTC_PIXEL_FORMAT, + GL_UNSIGNED_BYTE, + uploadPlane); +} + +- (BOOL)updateTextureDataForFrame:(RTCVideoFrame *)frame { + GLint textureOffset = _currentTextureSet * 3; + NSAssert(textureOffset + 3 <= kNumTextures, @"invalid offset"); + + [self uploadPlane:frame.yPlane + sampler:_ySampler + offset:textureOffset + width:frame.width + height:frame.height + stride:frame.yPitch]; + + [self uploadPlane:frame.uPlane + sampler:_uSampler + offset:textureOffset + 1 + width:frame.chromaWidth + height:frame.chromaHeight + stride:frame.uPitch]; + + [self uploadPlane:frame.vPlane + sampler:_vSampler + offset:textureOffset + 2 + width:frame.chromaWidth + height:frame.chromaHeight + stride:frame.vPitch]; + + _currentTextureSet = (_currentTextureSet + 1) % kNumTextureSets; + return YES; +} + +- (BOOL)setupVertices { +#if !TARGET_OS_IPHONE + NSAssert(!_vertexArray, @"vertex array already set up"); + glGenVertexArrays(1, &_vertexArray); + if (!_vertexArray) { + return NO; + } + glBindVertexArray(_vertexArray); +#endif + NSAssert(!_vertexBuffer, @"vertex buffer already set up"); + glGenBuffers(1, &_vertexBuffer); + if (!_vertexBuffer) { +#if !TARGET_OS_IPHONE + glDeleteVertexArrays(1, &_vertexArray); + _vertexArray = 0; +#endif + return NO; + } + glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); + glBufferData(GL_ARRAY_BUFFER, sizeof(gVertices), gVertices, GL_DYNAMIC_DRAW); + + // Read position attribute from |gVertices| with size of 2 and stride of 4 + // beginning at the start of the array. The last argument indicates offset + // of data within |gVertices| as supplied to the vertex buffer. + glVertexAttribPointer( + _position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (void *)0); + glEnableVertexAttribArray(_position); + + // Read texcoord attribute from |gVertices| with size of 2 and stride of 4 + // beginning at the first texcoord in the array. The last argument indicates + // offset of data within |gVertices| as supplied to the vertex buffer. + glVertexAttribPointer(_texcoord, + 2, + GL_FLOAT, + GL_FALSE, + 4 * sizeof(GLfloat), + (void *)(2 * sizeof(GLfloat))); + glEnableVertexAttribArray(_texcoord); + + return YES; +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection+DataChannel.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection+DataChannel.mm new file mode 100644 index 00000000000..b3825d4e4eb --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection+DataChannel.mm @@ -0,0 +1,31 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCPeerConnection+Private.h" + +#import "NSString+StdString.h" +#import "RTCDataChannel+Private.h" +#import "RTCDataChannelConfiguration+Private.h" + +@implementation RTCPeerConnection (DataChannel) + +- (RTCDataChannel *)dataChannelForLabel:(NSString *)label + configuration: + (RTCDataChannelConfiguration *)configuration { + std::string labelString = [NSString stdStringForString:label]; + const webrtc::DataChannelInit nativeInit = + configuration.nativeDataChannelInit; + rtc::scoped_refptr<webrtc::DataChannelInterface> dataChannel = + self.nativePeerConnection->CreateDataChannel(labelString, + &nativeInit); + return [[RTCDataChannel alloc] initWithNativeDataChannel:dataChannel]; +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection+Private.h new file mode 100644 index 00000000000..cbae3607cf6 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection+Private.h @@ -0,0 +1,103 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCPeerConnection.h" + +#include "webrtc/api/peerconnectioninterface.h" + +NS_ASSUME_NONNULL_BEGIN + +namespace webrtc { + +/** + * These objects are created by RTCPeerConnectionFactory to wrap an + * id<RTCPeerConnectionDelegate> and call methods on that interface. + */ +class PeerConnectionDelegateAdapter : public PeerConnectionObserver { + + public: + PeerConnectionDelegateAdapter(RTCPeerConnection *peerConnection); + virtual ~PeerConnectionDelegateAdapter(); + + void OnSignalingChange( + PeerConnectionInterface::SignalingState new_state) override; + + void OnAddStream(MediaStreamInterface *stream) override; + + void OnRemoveStream(MediaStreamInterface *stream) override; + + void OnDataChannel(DataChannelInterface *data_channel) override; + + void OnRenegotiationNeeded() override; + + void OnIceConnectionChange( + PeerConnectionInterface::IceConnectionState new_state) override; + + void OnIceGatheringChange( + PeerConnectionInterface::IceGatheringState new_state) override; + + void OnIceCandidate(const IceCandidateInterface *candidate) override; + + private: + __weak RTCPeerConnection *peer_connection_; +}; + +} // namespace webrtc + + +@interface RTCPeerConnection () + +/** The native PeerConnectionInterface created during construction. */ +@property(nonatomic, readonly) + rtc::scoped_refptr<webrtc::PeerConnectionInterface> nativePeerConnection; + +/** Initialize an RTCPeerConnection with a configuration, constraints, and + * delegate. + */ +- (instancetype)initWithFactory: + (RTCPeerConnectionFactory *)factory + configuration: + (RTCConfiguration *)configuration + constraints: + (RTCMediaConstraints *)constraints + delegate: + (nullable id<RTCPeerConnectionDelegate>)delegate + NS_DESIGNATED_INITIALIZER; + ++ (webrtc::PeerConnectionInterface::SignalingState)nativeSignalingStateForState: + (RTCSignalingState)state; + ++ (RTCSignalingState)signalingStateForNativeState: + (webrtc::PeerConnectionInterface::SignalingState)nativeState; + ++ (NSString *)stringForSignalingState:(RTCSignalingState)state; + ++ (webrtc::PeerConnectionInterface::IceConnectionState) + nativeIceConnectionStateForState:(RTCIceConnectionState)state; + ++ (RTCIceConnectionState)iceConnectionStateForNativeState: + (webrtc::PeerConnectionInterface::IceConnectionState)nativeState; + ++ (NSString *)stringForIceConnectionState:(RTCIceConnectionState)state; + ++ (webrtc::PeerConnectionInterface::IceGatheringState) + nativeIceGatheringStateForState:(RTCIceGatheringState)state; + ++ (RTCIceGatheringState)iceGatheringStateForNativeState: + (webrtc::PeerConnectionInterface::IceGatheringState)nativeState; + ++ (NSString *)stringForIceGatheringState:(RTCIceGatheringState)state; + ++ (webrtc::PeerConnectionInterface::StatsOutputLevel) + nativeStatsOutputLevelForLevel:(RTCStatsOutputLevel)level; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection+Stats.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection+Stats.mm new file mode 100644 index 00000000000..ccbd58f103d --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection+Stats.mm @@ -0,0 +1,64 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCPeerConnection+Private.h" + +#import "NSString+StdString.h" +#import "RTCMediaStreamTrack+Private.h" +#import "RTCStatsReport+Private.h" + +#include "webrtc/base/checks.h" + +namespace webrtc { + +class StatsObserverAdapter : public StatsObserver { + public: + StatsObserverAdapter(void (^completionHandler) + (NSArray<RTCStatsReport *> *stats)) { + completion_handler_ = completionHandler; + } + + ~StatsObserverAdapter() { + completion_handler_ = nil; + } + + void OnComplete(const StatsReports& reports) override { + RTC_DCHECK(completion_handler_); + NSMutableArray *stats = [NSMutableArray arrayWithCapacity:reports.size()]; + for (const auto* report : reports) { + RTCStatsReport *statsReport = + [[RTCStatsReport alloc] initWithNativeReport:*report]; + [stats addObject:statsReport]; + } + completion_handler_(stats); + completion_handler_ = nil; + } + + private: + void (^completion_handler_)(NSArray<RTCStatsReport *> *stats); +}; +} // namespace webrtc + +@implementation RTCPeerConnection (Stats) + +- (void)statsForTrack:(RTCMediaStreamTrack *)mediaStreamTrack + statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel + completionHandler: + (void (^)(NSArray<RTCStatsReport *> *stats))completionHandler { + rtc::scoped_refptr<webrtc::StatsObserverAdapter> observer( + new rtc::RefCountedObject<webrtc::StatsObserverAdapter> + (completionHandler)); + webrtc::PeerConnectionInterface::StatsOutputLevel nativeOutputLevel = + [[self class] nativeStatsOutputLevelForLevel:statsOutputLevel]; + self.nativePeerConnection->GetStats( + observer, mediaStreamTrack.nativeTrack, nativeOutputLevel); +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection.mm new file mode 100644 index 00000000000..9a488fdf494 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection.mm @@ -0,0 +1,529 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCPeerConnection+Private.h" + +#import "NSString+StdString.h" +#import "RTCConfiguration+Private.h" +#import "RTCDataChannel+Private.h" +#import "RTCIceCandidate+Private.h" +#import "RTCMediaConstraints+Private.h" +#import "RTCMediaStream+Private.h" +#import "RTCPeerConnectionFactory+Private.h" +#import "RTCRtpReceiver+Private.h" +#import "RTCRtpSender+Private.h" +#import "RTCSessionDescription+Private.h" +#import "RTCStatsReport+Private.h" +#import "WebRTC/RTCLogging.h" + +#include <memory> + +#include "webrtc/base/checks.h" + +NSString * const kRTCPeerConnectionErrorDomain = + @"org.webrtc.RTCPeerConnection"; +int const kRTCPeerConnnectionSessionDescriptionError = -1; + +namespace webrtc { + +class CreateSessionDescriptionObserverAdapter + : public CreateSessionDescriptionObserver { + public: + CreateSessionDescriptionObserverAdapter( + void (^completionHandler)(RTCSessionDescription *sessionDescription, + NSError *error)) { + completion_handler_ = completionHandler; + } + + ~CreateSessionDescriptionObserverAdapter() { + completion_handler_ = nil; + } + + void OnSuccess(SessionDescriptionInterface *desc) override { + RTC_DCHECK(completion_handler_); + std::unique_ptr<webrtc::SessionDescriptionInterface> description = + std::unique_ptr<webrtc::SessionDescriptionInterface>(desc); + RTCSessionDescription* session = + [[RTCSessionDescription alloc] initWithNativeDescription: + description.get()]; + completion_handler_(session, nil); + completion_handler_ = nil; + } + + void OnFailure(const std::string& error) override { + RTC_DCHECK(completion_handler_); + NSString* str = [NSString stringForStdString:error]; + NSError* err = + [NSError errorWithDomain:kRTCPeerConnectionErrorDomain + code:kRTCPeerConnnectionSessionDescriptionError + userInfo:@{ NSLocalizedDescriptionKey : str }]; + completion_handler_(nil, err); + completion_handler_ = nil; + } + + private: + void (^completion_handler_) + (RTCSessionDescription *sessionDescription, NSError *error); +}; + +class SetSessionDescriptionObserverAdapter : + public SetSessionDescriptionObserver { + public: + SetSessionDescriptionObserverAdapter(void (^completionHandler) + (NSError *error)) { + completion_handler_ = completionHandler; + } + + ~SetSessionDescriptionObserverAdapter() { + completion_handler_ = nil; + } + + void OnSuccess() override { + RTC_DCHECK(completion_handler_); + completion_handler_(nil); + completion_handler_ = nil; + } + + void OnFailure(const std::string& error) override { + RTC_DCHECK(completion_handler_); + NSString* str = [NSString stringForStdString:error]; + NSError* err = + [NSError errorWithDomain:kRTCPeerConnectionErrorDomain + code:kRTCPeerConnnectionSessionDescriptionError + userInfo:@{ NSLocalizedDescriptionKey : str }]; + completion_handler_(err); + completion_handler_ = nil; + } + + private: + void (^completion_handler_)(NSError *error); +}; + +PeerConnectionDelegateAdapter::PeerConnectionDelegateAdapter( + RTCPeerConnection *peerConnection) { + peer_connection_ = peerConnection; +} + +PeerConnectionDelegateAdapter::~PeerConnectionDelegateAdapter() { + peer_connection_ = nil; +} + +void PeerConnectionDelegateAdapter::OnSignalingChange( + PeerConnectionInterface::SignalingState new_state) { + RTCSignalingState state = + [[RTCPeerConnection class] signalingStateForNativeState:new_state]; + RTCPeerConnection *peer_connection = peer_connection_; + [peer_connection.delegate peerConnection:peer_connection + didChangeSignalingState:state]; +} + +void PeerConnectionDelegateAdapter::OnAddStream( + MediaStreamInterface *stream) { + RTCMediaStream *mediaStream = + [[RTCMediaStream alloc] initWithNativeMediaStream:stream]; + RTCPeerConnection *peer_connection = peer_connection_; + [peer_connection.delegate peerConnection:peer_connection + didAddStream:mediaStream]; +} + +void PeerConnectionDelegateAdapter::OnRemoveStream( + MediaStreamInterface *stream) { + RTCMediaStream *mediaStream = + [[RTCMediaStream alloc] initWithNativeMediaStream:stream]; + RTCPeerConnection *peer_connection = peer_connection_; + [peer_connection.delegate peerConnection:peer_connection + didRemoveStream:mediaStream]; +} + +void PeerConnectionDelegateAdapter::OnDataChannel( + DataChannelInterface *data_channel) { + RTCDataChannel *dataChannel = + [[RTCDataChannel alloc] initWithNativeDataChannel:data_channel]; + RTCPeerConnection *peer_connection = peer_connection_; + [peer_connection.delegate peerConnection:peer_connection + didOpenDataChannel:dataChannel]; +} + +void PeerConnectionDelegateAdapter::OnRenegotiationNeeded() { + RTCPeerConnection *peer_connection = peer_connection_; + [peer_connection.delegate peerConnectionShouldNegotiate:peer_connection]; +} + +void PeerConnectionDelegateAdapter::OnIceConnectionChange( + PeerConnectionInterface::IceConnectionState new_state) { + RTCIceConnectionState state = + [[RTCPeerConnection class] iceConnectionStateForNativeState:new_state]; + RTCPeerConnection *peer_connection = peer_connection_; + [peer_connection.delegate peerConnection:peer_connection + didChangeIceConnectionState:state]; +} + +void PeerConnectionDelegateAdapter::OnIceGatheringChange( + PeerConnectionInterface::IceGatheringState new_state) { + RTCIceGatheringState state = + [[RTCPeerConnection class] iceGatheringStateForNativeState:new_state]; + RTCPeerConnection *peer_connection = peer_connection_; + [peer_connection.delegate peerConnection:peer_connection + didChangeIceGatheringState:state]; +} + +void PeerConnectionDelegateAdapter::OnIceCandidate( + const IceCandidateInterface *candidate) { + RTCIceCandidate *iceCandidate = + [[RTCIceCandidate alloc] initWithNativeCandidate:candidate]; + RTCPeerConnection *peer_connection = peer_connection_; + [peer_connection.delegate peerConnection:peer_connection + didGenerateIceCandidate:iceCandidate]; +} +} // namespace webrtc + + +@implementation RTCPeerConnection { + NSMutableArray *_localStreams; + std::unique_ptr<webrtc::PeerConnectionDelegateAdapter> _observer; + rtc::scoped_refptr<webrtc::PeerConnectionInterface> _peerConnection; +} + +@synthesize delegate = _delegate; + +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + configuration:(RTCConfiguration *)configuration + constraints:(RTCMediaConstraints *)constraints + delegate:(id<RTCPeerConnectionDelegate>)delegate { + NSParameterAssert(factory); + std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config( + [configuration createNativeConfiguration]); + if (!config) { + return nil; + } + if (self = [super init]) { + _observer.reset(new webrtc::PeerConnectionDelegateAdapter(self)); + std::unique_ptr<webrtc::MediaConstraints> nativeConstraints = + constraints.nativeConstraints; + _peerConnection = + factory.nativeFactory->CreatePeerConnection(*config, + nativeConstraints.get(), + nullptr, + nullptr, + _observer.get()); + _localStreams = [[NSMutableArray alloc] init]; + _delegate = delegate; + } + return self; +} + +- (NSArray *)localStreams { + return [_localStreams copy]; +} + +- (RTCSessionDescription *)localDescription { + const webrtc::SessionDescriptionInterface *description = + _peerConnection->local_description(); + return description ? + [[RTCSessionDescription alloc] initWithNativeDescription:description] + : nil; +} + +- (RTCSessionDescription *)remoteDescription { + const webrtc::SessionDescriptionInterface *description = + _peerConnection->remote_description(); + return description ? + [[RTCSessionDescription alloc] initWithNativeDescription:description] + : nil; +} + +- (RTCSignalingState)signalingState { + return [[self class] + signalingStateForNativeState:_peerConnection->signaling_state()]; +} + +- (RTCIceConnectionState)iceConnectionState { + return [[self class] iceConnectionStateForNativeState: + _peerConnection->ice_connection_state()]; +} + +- (RTCIceGatheringState)iceGatheringState { + return [[self class] iceGatheringStateForNativeState: + _peerConnection->ice_gathering_state()]; +} + +- (BOOL)setConfiguration:(RTCConfiguration *)configuration { + std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config( + [configuration createNativeConfiguration]); + if (!config) { + return NO; + } + return _peerConnection->SetConfiguration(*config); +} + +- (void)close { + _peerConnection->Close(); +} + +- (void)addIceCandidate:(RTCIceCandidate *)candidate { + std::unique_ptr<const webrtc::IceCandidateInterface> iceCandidate( + candidate.nativeCandidate); + _peerConnection->AddIceCandidate(iceCandidate.get()); +} + +- (void)addStream:(RTCMediaStream *)stream { + if (!_peerConnection->AddStream(stream.nativeMediaStream)) { + RTCLogError(@"Failed to add stream: %@", stream); + return; + } + [_localStreams addObject:stream]; +} + +- (void)removeStream:(RTCMediaStream *)stream { + _peerConnection->RemoveStream(stream.nativeMediaStream); + [_localStreams removeObject:stream]; +} + +- (void)offerForConstraints:(RTCMediaConstraints *)constraints + completionHandler: + (void (^)(RTCSessionDescription *sessionDescription, + NSError *error))completionHandler { + rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserverAdapter> + observer(new rtc::RefCountedObject + <webrtc::CreateSessionDescriptionObserverAdapter>(completionHandler)); + _peerConnection->CreateOffer(observer, constraints.nativeConstraints.get()); +} + +- (void)answerForConstraints:(RTCMediaConstraints *)constraints + completionHandler: + (void (^)(RTCSessionDescription *sessionDescription, + NSError *error))completionHandler { + rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserverAdapter> + observer(new rtc::RefCountedObject + <webrtc::CreateSessionDescriptionObserverAdapter>(completionHandler)); + _peerConnection->CreateAnswer(observer, constraints.nativeConstraints.get()); +} + +- (void)setLocalDescription:(RTCSessionDescription *)sdp + completionHandler:(void (^)(NSError *error))completionHandler { + rtc::scoped_refptr<webrtc::SetSessionDescriptionObserverAdapter> observer( + new rtc::RefCountedObject<webrtc::SetSessionDescriptionObserverAdapter>( + completionHandler)); + _peerConnection->SetLocalDescription(observer, sdp.nativeDescription); +} + +- (void)setRemoteDescription:(RTCSessionDescription *)sdp + completionHandler:(void (^)(NSError *error))completionHandler { + rtc::scoped_refptr<webrtc::SetSessionDescriptionObserverAdapter> observer( + new rtc::RefCountedObject<webrtc::SetSessionDescriptionObserverAdapter>( + completionHandler)); + _peerConnection->SetRemoteDescription(observer, sdp.nativeDescription); +} + +- (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 ? + [[RTCRtpSender alloc] initWithNativeRtpSender:nativeSender] + : nil; +} + +- (NSArray<RTCRtpSender *> *)senders { + std::vector<rtc::scoped_refptr<webrtc::RtpSenderInterface>> nativeSenders( + _peerConnection->GetSenders()); + NSMutableArray *senders = [[NSMutableArray alloc] init]; + for (const auto &nativeSender : nativeSenders) { + RTCRtpSender *sender = + [[RTCRtpSender alloc] initWithNativeRtpSender:nativeSender]; + [senders addObject:sender]; + } + return senders; +} + +- (NSArray<RTCRtpReceiver *> *)receivers { + std::vector<rtc::scoped_refptr<webrtc::RtpReceiverInterface>> nativeReceivers( + _peerConnection->GetReceivers()); + NSMutableArray *receivers = [[NSMutableArray alloc] init]; + for (const auto &nativeReceiver : nativeReceivers) { + RTCRtpReceiver *receiver = + [[RTCRtpReceiver alloc] initWithNativeRtpReceiver:nativeReceiver]; + [receivers addObject:receiver]; + } + return receivers; +} + +#pragma mark - Private + ++ (webrtc::PeerConnectionInterface::SignalingState)nativeSignalingStateForState: + (RTCSignalingState)state { + switch (state) { + case RTCSignalingStateStable: + return webrtc::PeerConnectionInterface::kStable; + case RTCSignalingStateHaveLocalOffer: + return webrtc::PeerConnectionInterface::kHaveLocalOffer; + case RTCSignalingStateHaveLocalPrAnswer: + return webrtc::PeerConnectionInterface::kHaveLocalPrAnswer; + case RTCSignalingStateHaveRemoteOffer: + return webrtc::PeerConnectionInterface::kHaveRemoteOffer; + case RTCSignalingStateHaveRemotePrAnswer: + return webrtc::PeerConnectionInterface::kHaveRemotePrAnswer; + case RTCSignalingStateClosed: + return webrtc::PeerConnectionInterface::kClosed; + } +} + ++ (RTCSignalingState)signalingStateForNativeState: + (webrtc::PeerConnectionInterface::SignalingState)nativeState { + switch (nativeState) { + case webrtc::PeerConnectionInterface::kStable: + return RTCSignalingStateStable; + case webrtc::PeerConnectionInterface::kHaveLocalOffer: + return RTCSignalingStateHaveLocalOffer; + case webrtc::PeerConnectionInterface::kHaveLocalPrAnswer: + return RTCSignalingStateHaveLocalPrAnswer; + case webrtc::PeerConnectionInterface::kHaveRemoteOffer: + return RTCSignalingStateHaveRemoteOffer; + case webrtc::PeerConnectionInterface::kHaveRemotePrAnswer: + return RTCSignalingStateHaveRemotePrAnswer; + case webrtc::PeerConnectionInterface::kClosed: + return RTCSignalingStateClosed; + } +} + ++ (NSString *)stringForSignalingState:(RTCSignalingState)state { + switch (state) { + case RTCSignalingStateStable: + return @"STABLE"; + case RTCSignalingStateHaveLocalOffer: + return @"HAVE_LOCAL_OFFER"; + case RTCSignalingStateHaveLocalPrAnswer: + return @"HAVE_LOCAL_PRANSWER"; + case RTCSignalingStateHaveRemoteOffer: + return @"HAVE_REMOTE_OFFER"; + case RTCSignalingStateHaveRemotePrAnswer: + return @"HAVE_REMOTE_PRANSWER"; + case RTCSignalingStateClosed: + return @"CLOSED"; + } +} + ++ (webrtc::PeerConnectionInterface::IceConnectionState) + nativeIceConnectionStateForState:(RTCIceConnectionState)state { + switch (state) { + case RTCIceConnectionStateNew: + return webrtc::PeerConnectionInterface::kIceConnectionNew; + case RTCIceConnectionStateChecking: + return webrtc::PeerConnectionInterface::kIceConnectionChecking; + case RTCIceConnectionStateConnected: + return webrtc::PeerConnectionInterface::kIceConnectionConnected; + case RTCIceConnectionStateCompleted: + return webrtc::PeerConnectionInterface::kIceConnectionCompleted; + case RTCIceConnectionStateFailed: + return webrtc::PeerConnectionInterface::kIceConnectionFailed; + case RTCIceConnectionStateDisconnected: + return webrtc::PeerConnectionInterface::kIceConnectionDisconnected; + case RTCIceConnectionStateClosed: + return webrtc::PeerConnectionInterface::kIceConnectionClosed; + case RTCIceConnectionStateCount: + return webrtc::PeerConnectionInterface::kIceConnectionMax; + } +} + ++ (RTCIceConnectionState)iceConnectionStateForNativeState: + (webrtc::PeerConnectionInterface::IceConnectionState)nativeState { + switch (nativeState) { + case webrtc::PeerConnectionInterface::kIceConnectionNew: + return RTCIceConnectionStateNew; + case webrtc::PeerConnectionInterface::kIceConnectionChecking: + return RTCIceConnectionStateChecking; + case webrtc::PeerConnectionInterface::kIceConnectionConnected: + return RTCIceConnectionStateConnected; + case webrtc::PeerConnectionInterface::kIceConnectionCompleted: + return RTCIceConnectionStateCompleted; + case webrtc::PeerConnectionInterface::kIceConnectionFailed: + return RTCIceConnectionStateFailed; + case webrtc::PeerConnectionInterface::kIceConnectionDisconnected: + return RTCIceConnectionStateDisconnected; + case webrtc::PeerConnectionInterface::kIceConnectionClosed: + return RTCIceConnectionStateClosed; + case webrtc::PeerConnectionInterface::kIceConnectionMax: + return RTCIceConnectionStateCount; + } +} + ++ (NSString *)stringForIceConnectionState:(RTCIceConnectionState)state { + switch (state) { + case RTCIceConnectionStateNew: + return @"NEW"; + case RTCIceConnectionStateChecking: + return @"CHECKING"; + case RTCIceConnectionStateConnected: + return @"CONNECTED"; + case RTCIceConnectionStateCompleted: + return @"COMPLETED"; + case RTCIceConnectionStateFailed: + return @"FAILED"; + case RTCIceConnectionStateDisconnected: + return @"DISCONNECTED"; + case RTCIceConnectionStateClosed: + return @"CLOSED"; + case RTCIceConnectionStateCount: + return @"COUNT"; + } +} + ++ (webrtc::PeerConnectionInterface::IceGatheringState) + nativeIceGatheringStateForState:(RTCIceGatheringState)state { + switch (state) { + case RTCIceGatheringStateNew: + return webrtc::PeerConnectionInterface::kIceGatheringNew; + case RTCIceGatheringStateGathering: + return webrtc::PeerConnectionInterface::kIceGatheringGathering; + case RTCIceGatheringStateComplete: + return webrtc::PeerConnectionInterface::kIceGatheringComplete; + } +} + ++ (RTCIceGatheringState)iceGatheringStateForNativeState: + (webrtc::PeerConnectionInterface::IceGatheringState)nativeState { + switch (nativeState) { + case webrtc::PeerConnectionInterface::kIceGatheringNew: + return RTCIceGatheringStateNew; + case webrtc::PeerConnectionInterface::kIceGatheringGathering: + return RTCIceGatheringStateGathering; + case webrtc::PeerConnectionInterface::kIceGatheringComplete: + return RTCIceGatheringStateComplete; + } +} + ++ (NSString *)stringForIceGatheringState:(RTCIceGatheringState)state { + switch (state) { + case RTCIceGatheringStateNew: + return @"NEW"; + case RTCIceGatheringStateGathering: + return @"GATHERING"; + case RTCIceGatheringStateComplete: + return @"COMPLETE"; + } +} + ++ (webrtc::PeerConnectionInterface::StatsOutputLevel) + nativeStatsOutputLevelForLevel:(RTCStatsOutputLevel)level { + switch (level) { + case RTCStatsOutputLevelStandard: + return webrtc::PeerConnectionInterface::kStatsOutputLevelStandard; + case RTCStatsOutputLevelDebug: + return webrtc::PeerConnectionInterface::kStatsOutputLevelDebug; + } +} + +- (rtc::scoped_refptr<webrtc::PeerConnectionInterface>)nativePeerConnection { + return _peerConnection; +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCPeerConnectionFactory+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCPeerConnectionFactory+Private.h new file mode 100644 index 00000000000..a7e453c917f --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCPeerConnectionFactory+Private.h @@ -0,0 +1,30 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCPeerConnectionFactory.h" + +#include "webrtc/api/peerconnectionfactory.h" +#include "webrtc/base/scoped_ref_ptr.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCPeerConnectionFactory () + +/** + * PeerConnectionFactoryInterface created and held by this + * RTCPeerConnectionFactory object. This is needed to pass to the underlying + * C++ APIs. + */ +@property(nonatomic, readonly) + rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> nativeFactory; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCPeerConnectionFactory.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCPeerConnectionFactory.mm new file mode 100644 index 00000000000..2398ce5ddc4 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCPeerConnectionFactory.mm @@ -0,0 +1,94 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCPeerConnectionFactory+Private.h" + +#import "NSString+StdString.h" +#if defined(WEBRTC_IOS) +#import "RTCAVFoundationVideoSource+Private.h" +#endif +#import "RTCAudioTrack+Private.h" +#import "RTCMediaStream+Private.h" +#import "RTCPeerConnection+Private.h" +#import "RTCVideoSource+Private.h" +#import "RTCVideoTrack+Private.h" + +#include <memory> + +@implementation RTCPeerConnectionFactory { + std::unique_ptr<rtc::Thread> _networkThread; + std::unique_ptr<rtc::Thread> _workerThread; + std::unique_ptr<rtc::Thread> _signalingThread; +} + +@synthesize nativeFactory = _nativeFactory; + +- (instancetype)init { + if ((self = [super init])) { + _networkThread = rtc::Thread::CreateWithSocketServer(); + BOOL result = _networkThread->Start(); + NSAssert(result, @"Failed to start network thread."); + + _workerThread = rtc::Thread::Create(); + result = _workerThread->Start(); + NSAssert(result, @"Failed to start worker thread."); + + _signalingThread = rtc::Thread::Create(); + result = _signalingThread->Start(); + NSAssert(result, @"Failed to start signaling thread."); + + _nativeFactory = webrtc::CreatePeerConnectionFactory( + _networkThread.get(), _workerThread.get(), _signalingThread.get(), + nullptr, nullptr, nullptr); + NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!"); + } + return self; +} + +- (RTCAVFoundationVideoSource *)avFoundationVideoSourceWithConstraints: + (nullable RTCMediaConstraints *)constraints { +#if defined(WEBRTC_IOS) + return [[RTCAVFoundationVideoSource alloc] initWithFactory:self + constraints:constraints]; +#else + return nil; +#endif +} + +- (RTCAudioTrack *)audioTrackWithTrackId:(NSString *)trackId { + return [[RTCAudioTrack alloc] initWithFactory:self + trackId:trackId]; +} + +- (RTCVideoTrack *)videoTrackWithSource:(RTCVideoSource *)source + trackId:(NSString *)trackId { + return [[RTCVideoTrack alloc] initWithFactory:self + source:source + trackId:trackId]; +} + +- (RTCMediaStream *)mediaStreamWithStreamId:(NSString *)streamId { + return [[RTCMediaStream alloc] initWithFactory:self + streamId:streamId]; +} + +- (RTCPeerConnection *)peerConnectionWithConfiguration: + (RTCConfiguration *)configuration + constraints: + (RTCMediaConstraints *)constraints + delegate: + (nullable id<RTCPeerConnectionDelegate>)delegate { + return [[RTCPeerConnection alloc] initWithFactory:self + configuration:configuration + constraints:constraints + delegate:delegate]; +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpCodecParameters+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpCodecParameters+Private.h new file mode 100644 index 00000000000..fe33e9e9633 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpCodecParameters+Private.h @@ -0,0 +1,28 @@ +/* + * Copyright 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCRtpCodecParameters.h" + +#include "webrtc/api/rtpparameters.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCRtpCodecParameters () + +/** Returns the equivalent native RtpCodecParameters structure. */ +@property(nonatomic, readonly) webrtc::RtpCodecParameters nativeParameters; + +/** Initialize the object with a native RtpCodecParameters structure. */ +- (instancetype)initWithNativeParameters: + (const webrtc::RtpCodecParameters &)nativeParameters; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpCodecParameters.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpCodecParameters.mm new file mode 100644 index 00000000000..77047694723 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpCodecParameters.mm @@ -0,0 +1,65 @@ +/* + * Copyright 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCRtpCodecParameters+Private.h" + +#import "NSString+StdString.h" + +#include "webrtc/media/base/mediaconstants.h" + +const NSString * const kRTCRtxCodecMimeType = @(cricket::kRtxCodecName); +const NSString * const kRTCRedCodecMimeType = @(cricket::kRedCodecName); +const NSString * const kRTCUlpfecCodecMimeType = @(cricket::kUlpfecCodecName); +const NSString * const kRTCOpusCodecMimeType = @(cricket::kOpusCodecName); +const NSString * const kRTCIsacCodecMimeType = @(cricket::kIsacCodecName); +const NSString * const kRTCL16CodecMimeType = @(cricket::kL16CodecName); +const NSString * const kRTCG722CodecMimeType = @(cricket::kG722CodecName); +const NSString * const kRTCIlbcCodecMimeType = @(cricket::kIlbcCodecName); +const NSString * const kRTCPcmuCodecMimeType = @(cricket::kPcmuCodecName); +const NSString * const kRTCPcmaCodecMimeType = @(cricket::kPcmaCodecName); +const NSString * const kRTCDtmfCodecMimeType = @(cricket::kDtmfCodecName); +const NSString * const kRTCComfortNoiseCodecMimeType = + @(cricket::kComfortNoiseCodecName); +const NSString * const kVp8CodecMimeType = @(cricket::kVp8CodecName); +const NSString * const kVp9CodecMimeType = @(cricket::kVp9CodecName); +const NSString * const kH264CodecMimeType = @(cricket::kH264CodecName); + +@implementation RTCRtpCodecParameters + +@synthesize payloadType = _payloadType; +@synthesize mimeType = _mimeType; +@synthesize clockRate = _clockRate; +@synthesize channels = _channels; + +- (instancetype)init { + return [super init]; +} + +- (instancetype)initWithNativeParameters: + (const webrtc::RtpCodecParameters &)nativeParameters { + if (self = [self init]) { + _payloadType = nativeParameters.payload_type; + _mimeType = [NSString stringForStdString:nativeParameters.mime_type]; + _clockRate = nativeParameters.clock_rate; + _channels = nativeParameters.channels; + } + return self; +} + +- (webrtc::RtpCodecParameters)nativeParameters { + webrtc::RtpCodecParameters parameters; + parameters.payload_type = _payloadType; + parameters.mime_type = [NSString stdStringForString:_mimeType]; + parameters.clock_rate = _clockRate; + parameters.channels = _channels; + return parameters; +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpEncodingParameters+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpEncodingParameters+Private.h new file mode 100644 index 00000000000..1d752684785 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpEncodingParameters+Private.h @@ -0,0 +1,28 @@ +/* + * Copyright 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCRtpEncodingParameters.h" + +#include "webrtc/api/rtpparameters.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCRtpEncodingParameters () + +/** Returns the equivalent native RtpEncodingParameters structure. */ +@property(nonatomic, readonly) webrtc::RtpEncodingParameters nativeParameters; + +/** Initialize the object with a native RtpEncodingParameters structure. */ +- (instancetype)initWithNativeParameters: + (const webrtc::RtpEncodingParameters &)nativeParameters; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpEncodingParameters.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpEncodingParameters.mm new file mode 100644 index 00000000000..af07a0485d6 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpEncodingParameters.mm @@ -0,0 +1,46 @@ +/* + * Copyright 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCRtpEncodingParameters+Private.h" + +@implementation RTCRtpEncodingParameters + +@synthesize isActive = _isActive; +@synthesize maxBitrateBps = _maxBitrateBps; + +static const int kBitrateUnlimited = -1; + +- (instancetype)init { + return [super init]; +} + +- (instancetype)initWithNativeParameters: + (const webrtc::RtpEncodingParameters &)nativeParameters { + if (self = [self init]) { + _isActive = nativeParameters.active; + // TODO(skvlad): Replace with rtc::Optional once the C++ code is updated. + if (nativeParameters.max_bitrate_bps != kBitrateUnlimited) { + _maxBitrateBps = + [NSNumber numberWithInt:nativeParameters.max_bitrate_bps]; + } + } + return self; +} + +- (webrtc::RtpEncodingParameters)nativeParameters { + webrtc::RtpEncodingParameters parameters; + parameters.active = _isActive; + if (_maxBitrateBps != nil) { + parameters.max_bitrate_bps = _maxBitrateBps.intValue; + } + return parameters; +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpParameters+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpParameters+Private.h new file mode 100644 index 00000000000..0cb1ffed814 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpParameters+Private.h @@ -0,0 +1,28 @@ +/* + * Copyright 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCRtpParameters.h" + +#include "webrtc/api/rtpparameters.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCRtpParameters () + +/** Returns the equivalent native RtpParameters structure. */ +@property(nonatomic, readonly) webrtc::RtpParameters nativeParameters; + +/** Initialize the object with a native RtpParameters structure. */ +- (instancetype)initWithNativeParameters: + (const webrtc::RtpParameters &)nativeParameters; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpParameters.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpParameters.mm new file mode 100644 index 00000000000..5e791066df1 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpParameters.mm @@ -0,0 +1,56 @@ +/* + * Copyright 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCRtpParameters+Private.h" + +#import "RTCRtpCodecParameters+Private.h" +#import "RTCRtpEncodingParameters+Private.h" + +@implementation RTCRtpParameters + +@synthesize encodings = _encodings; +@synthesize codecs = _codecs; + +- (instancetype)init { + return [super init]; +} + +- (instancetype)initWithNativeParameters: + (const webrtc::RtpParameters &)nativeParameters { + if (self = [self init]) { + NSMutableArray *encodings = [[NSMutableArray alloc] init]; + for (const auto &encoding : nativeParameters.encodings) { + [encodings addObject:[[RTCRtpEncodingParameters alloc] + initWithNativeParameters:encoding]]; + } + _encodings = encodings; + + NSMutableArray *codecs = [[NSMutableArray alloc] init]; + for (const auto &codec : nativeParameters.codecs) { + [codecs addObject:[[RTCRtpCodecParameters alloc] + initWithNativeParameters:codec]]; + } + _codecs = codecs; + } + return self; +} + +- (webrtc::RtpParameters)nativeParameters { + webrtc::RtpParameters parameters; + for (RTCRtpEncodingParameters *encoding in _encodings) { + parameters.encodings.push_back(encoding.nativeParameters); + } + for (RTCRtpCodecParameters *codec in _codecs) { + parameters.codecs.push_back(codec.nativeParameters); + } + return parameters; +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpReceiver+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpReceiver+Private.h new file mode 100644 index 00000000000..14b68fa0113 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpReceiver+Private.h @@ -0,0 +1,29 @@ +/* + * Copyright 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCRtpReceiver.h" + +#include "webrtc/api/rtpreceiverinterface.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCRtpReceiver () + +@property(nonatomic, readonly) + rtc::scoped_refptr<webrtc::RtpReceiverInterface> nativeRtpReceiver; + +/** Initialize an RTCRtpReceiver with a native RtpReceiverInterface. */ +- (instancetype)initWithNativeRtpReceiver: + (rtc::scoped_refptr<webrtc::RtpReceiverInterface>)nativeRtpReceiver + NS_DESIGNATED_INITIALIZER; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpReceiver.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpReceiver.mm new file mode 100644 index 00000000000..46c0e6544a4 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpReceiver.mm @@ -0,0 +1,88 @@ +/* + * Copyright 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCRtpReceiver+Private.h" + +#import "NSString+StdString.h" +#import "RTCMediaStreamTrack+Private.h" +#import "RTCRtpParameters+Private.h" +#import "WebRTC/RTCLogging.h" + +#include "webrtc/api/mediastreaminterface.h" + +@implementation RTCRtpReceiver { + rtc::scoped_refptr<webrtc::RtpReceiverInterface> _nativeRtpReceiver; +} + +- (NSString *)receiverId { + return [NSString stringForStdString:_nativeRtpReceiver->id()]; +} + +- (RTCRtpParameters *)parameters { + return [[RTCRtpParameters alloc] + initWithNativeParameters:_nativeRtpReceiver->GetParameters()]; +} + +- (void)setParameters:(RTCRtpParameters *)parameters { + if (!_nativeRtpReceiver->SetParameters(parameters.nativeParameters)) { + RTCLogError(@"RTCRtpReceiver(%p): Failed to set parameters: %@", self, + parameters); + } +} + +- (RTCMediaStreamTrack *)track { + rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> nativeTrack( + _nativeRtpReceiver->track()); + if (nativeTrack) { + return [[RTCMediaStreamTrack alloc] initWithNativeTrack:nativeTrack]; + } + return nil; +} + +- (NSString *)description { + return [NSString stringWithFormat:@"RTCRtpReceiver {\n receiverId: %@\n}", + self.receiverId]; +} + +- (BOOL)isEqual:(id)object { + if (self == object) { + return YES; + } + if (object == nil) { + return NO; + } + if (![object isMemberOfClass:[self class]]) { + return NO; + } + RTCRtpReceiver *receiver = (RTCRtpReceiver *)object; + return _nativeRtpReceiver == receiver.nativeRtpReceiver; +} + +- (NSUInteger)hash { + return (NSUInteger)_nativeRtpReceiver.get(); +} + +#pragma mark - Private + +- (rtc::scoped_refptr<webrtc::RtpReceiverInterface>)nativeRtpReceiver { + return _nativeRtpReceiver; +} + +- (instancetype)initWithNativeRtpReceiver: + (rtc::scoped_refptr<webrtc::RtpReceiverInterface>)nativeRtpReceiver { + if (self = [super init]) { + _nativeRtpReceiver = nativeRtpReceiver; + RTCLogInfo( + @"RTCRtpReceiver(%p): created receiver: %@", self, self.description); + } + return self; +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpSender+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpSender+Private.h new file mode 100644 index 00000000000..e372c523325 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpSender+Private.h @@ -0,0 +1,29 @@ +/* + * Copyright 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCRtpSender.h" + +#include "webrtc/api/rtpsenderinterface.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCRtpSender () + +@property(nonatomic, readonly) + rtc::scoped_refptr<webrtc::RtpSenderInterface> nativeRtpSender; + +/** Initialize an RTCRtpSender with a native RtpSenderInterface. */ +- (instancetype)initWithNativeRtpSender: + (rtc::scoped_refptr<webrtc::RtpSenderInterface>)nativeRtpSender + NS_DESIGNATED_INITIALIZER; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpSender.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpSender.mm new file mode 100644 index 00000000000..9ecf0ae5ae9 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCRtpSender.mm @@ -0,0 +1,94 @@ +/* + * Copyright 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCRtpSender+Private.h" + +#import "NSString+StdString.h" +#import "RTCMediaStreamTrack+Private.h" +#import "RTCRtpParameters+Private.h" +#import "WebRTC/RTCLogging.h" + +#include "webrtc/api/mediastreaminterface.h" + +@implementation RTCRtpSender { + rtc::scoped_refptr<webrtc::RtpSenderInterface> _nativeRtpSender; +} + +- (NSString *)senderId { + return [NSString stringForStdString:_nativeRtpSender->id()]; +} + +- (RTCRtpParameters *)parameters { + return [[RTCRtpParameters alloc] + initWithNativeParameters:_nativeRtpSender->GetParameters()]; +} + +- (void)setParameters:(RTCRtpParameters *)parameters { + if (!_nativeRtpSender->SetParameters(parameters.nativeParameters)) { + RTCLogError(@"RTCRtpSender(%p): Failed to set parameters: %@", self, + parameters); + } +} + +- (RTCMediaStreamTrack *)track { + rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> nativeTrack( + _nativeRtpSender->track()); + if (nativeTrack) { + return [[RTCMediaStreamTrack alloc] initWithNativeTrack:nativeTrack]; + } + return nil; +} + +- (void)setTrack:(RTCMediaStreamTrack *)track { + if (!_nativeRtpSender->SetTrack(track.nativeTrack)) { + RTCLogError(@"RTCRtpSender(%p): Failed to set track %@", self, track); + } +} + +- (NSString *)description { + return [NSString stringWithFormat:@"RTCRtpSender {\n senderId: %@\n}", + self.senderId]; +} + +- (BOOL)isEqual:(id)object { + if (self == object) { + return YES; + } + if (object == nil) { + return NO; + } + if (![object isMemberOfClass:[self class]]) { + return NO; + } + RTCRtpSender *sender = (RTCRtpSender *)object; + return _nativeRtpSender == sender.nativeRtpSender; +} + +- (NSUInteger)hash { + return (NSUInteger)_nativeRtpSender.get(); +} + +#pragma mark - Private + +- (rtc::scoped_refptr<webrtc::RtpSenderInterface>)nativeRtpSender { + return _nativeRtpSender; +} + +- (instancetype)initWithNativeRtpSender: + (rtc::scoped_refptr<webrtc::RtpSenderInterface>)nativeRtpSender { + NSParameterAssert(nativeRtpSender); + if (self = [super init]) { + _nativeRtpSender = nativeRtpSender; + RTCLogInfo(@"RTCRtpSender(%p): created sender: %@", self, self.description); + } + return self; +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCSSLAdapter.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCSSLAdapter.mm new file mode 100644 index 00000000000..a0da105bc35 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCSSLAdapter.mm @@ -0,0 +1,26 @@ +/* + * Copyright 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCSSLAdapter.h" + +#include "webrtc/base/checks.h" +#include "webrtc/base/ssladapter.h" + +BOOL RTCInitializeSSL() { + BOOL initialized = rtc::InitializeSSL(); + RTC_DCHECK(initialized); + return initialized; +} + +BOOL RTCCleanupSSL() { + BOOL cleanedUp = rtc::CleanupSSL(); + RTC_DCHECK(cleanedUp); + return cleanedUp; +} diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCSessionDescription+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCSessionDescription+Private.h new file mode 100644 index 00000000000..04b6fbe8642 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCSessionDescription+Private.h @@ -0,0 +1,41 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCSessionDescription.h" + +#include "webrtc/api/jsep.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCSessionDescription () + +/** + * The native SessionDescriptionInterface representation of this + * RTCSessionDescription object. This is needed to pass to the underlying C++ + * APIs. + */ +@property(nonatomic, readonly) + webrtc::SessionDescriptionInterface *nativeDescription; + +/** + * Initialize an RTCSessionDescription from a native + * SessionDescriptionInterface. No ownership is taken of the native session + * description. + */ +- (instancetype)initWithNativeDescription: + (const webrtc::SessionDescriptionInterface *)nativeDescription; + ++ (std::string)stdStringForType:(RTCSdpType)type; + ++ (RTCSdpType)typeForStdString:(const std::string &)string; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCSessionDescription.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCSessionDescription.mm new file mode 100644 index 00000000000..417ff7dfca2 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCSessionDescription.mm @@ -0,0 +1,102 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCSessionDescription+Private.h" + +#import "NSString+StdString.h" +#import "WebRTC/RTCLogging.h" + +#include "webrtc/base/checks.h" + +@implementation RTCSessionDescription + +@synthesize type = _type; +@synthesize sdp = _sdp; + ++ (NSString *)stringForType:(RTCSdpType)type { + std::string string = [[self class] stdStringForType:type]; + return [NSString stringForStdString:string]; +} + ++ (RTCSdpType)typeForString:(NSString *)string { + std::string typeString = string.stdString; + return [[self class] typeForStdString:typeString]; +} + +- (instancetype)initWithType:(RTCSdpType)type sdp:(NSString *)sdp { + NSParameterAssert(sdp.length); + if (self = [super init]) { + _type = type; + _sdp = [sdp copy]; + } + return self; +} + +- (NSString *)description { + return [NSString stringWithFormat:@"RTCSessionDescription:\n%@\n%@", + [[self class] stringForType:_type], + _sdp]; +} + +#pragma mark - Private + +- (webrtc::SessionDescriptionInterface *)nativeDescription { + webrtc::SdpParseError error; + + webrtc::SessionDescriptionInterface *description = + webrtc::CreateSessionDescription([[self class] stdStringForType:_type], + _sdp.stdString, + &error); + + if (!description) { + RTCLogError(@"Failed to create session description: %s\nline: %s", + error.description.c_str(), + error.line.c_str()); + } + + return description; +} + +- (instancetype)initWithNativeDescription: + (const webrtc::SessionDescriptionInterface *)nativeDescription { + NSParameterAssert(nativeDescription); + std::string sdp; + nativeDescription->ToString(&sdp); + RTCSdpType type = [[self class] typeForStdString:nativeDescription->type()]; + + return [self initWithType:type + sdp:[NSString stringForStdString:sdp]]; +} + ++ (std::string)stdStringForType:(RTCSdpType)type { + switch (type) { + case RTCSdpTypeOffer: + return webrtc::SessionDescriptionInterface::kOffer; + case RTCSdpTypePrAnswer: + return webrtc::SessionDescriptionInterface::kPrAnswer; + case RTCSdpTypeAnswer: + return webrtc::SessionDescriptionInterface::kAnswer; + } +} + ++ (RTCSdpType)typeForStdString:(const std::string &)string { + if (string == webrtc::SessionDescriptionInterface::kOffer) { + return RTCSdpTypeOffer; + } else if (string == webrtc::SessionDescriptionInterface::kPrAnswer) { + return RTCSdpTypePrAnswer; + } else if (string == webrtc::SessionDescriptionInterface::kAnswer) { + return RTCSdpTypeAnswer; + } else { + RTC_NOTREACHED(); + return RTCSdpTypeOffer; + } +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCStatsReport+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCStatsReport+Private.h new file mode 100644 index 00000000000..e1af6f75ea6 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCStatsReport+Private.h @@ -0,0 +1,24 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCStatsReport.h" + +#include "webrtc/api/statstypes.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCStatsReport () + +/** Initialize an RTCStatsReport object from a native StatsReport. */ +- (instancetype)initWithNativeReport:(const webrtc::StatsReport &)nativeReport; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCStatsReport.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCStatsReport.mm new file mode 100644 index 00000000000..1bc3eb9f0ee --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCStatsReport.mm @@ -0,0 +1,60 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCStatsReport+Private.h" + +#import "NSString+StdString.h" +#import "WebRTC/RTCLogging.h" + +#include "webrtc/base/checks.h" + +@implementation RTCStatsReport + +@synthesize timestamp = _timestamp; +@synthesize type = _type; +@synthesize reportId = _reportId; +@synthesize values = _values; + +- (NSString *)description { + return [NSString stringWithFormat:@"RTCStatsReport:\n%@\n%@\n%f\n%@", + _reportId, + _type, + _timestamp, + _values]; +} + +#pragma mark - Private + +- (instancetype)initWithNativeReport:(const webrtc::StatsReport &)nativeReport { + if (self = [super init]) { + _timestamp = nativeReport.timestamp(); + _type = [NSString stringForStdString:nativeReport.TypeToString()]; + _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()]; + + // Not expecting duplicate keys. + RTC_DCHECK(![values objectForKey:key]); + [values setObject:value forKey:key]; + } + _values = values; + } + return self; +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCTracing.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCTracing.mm new file mode 100644 index 00000000000..37755a6b9ab --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCTracing.mm @@ -0,0 +1,29 @@ +/* + * Copyright 2016 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCTracing.h" + +#include "webrtc/base/event_tracer.h" + +void RTCSetupInternalTracer() { + rtc::tracing::SetupInternalTracer(); +} + +BOOL RTCStartInternalCapture(NSString *filePath) { + return rtc::tracing::StartInternalCapture(filePath.UTF8String); +} + +void RTCStopInternalCapture() { + rtc::tracing::StopInternalCapture(); +} + +void RTCShutdownInternalTracer() { + rtc::tracing::ShutdownInternalTracer(); +} diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCUIApplication.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCUIApplication.h new file mode 100644 index 00000000000..fb11edef44e --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCUIApplication.h @@ -0,0 +1,21 @@ +/* + * Copyright 2016 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef WEBRTC_BASE_OBJC_RTC_UI_APPLICATION_H_ +#define WEBRTC_BASE_OBJC_RTC_UI_APPLICATION_H_ + +#include "WebRTC/RTCMacros.h" + +#if defined(WEBRTC_IOS) +/** Convenience function to get UIApplicationState from C++. */ +RTC_EXTERN bool RTCIsUIApplicationActive(); +#endif // WEBRTC_IOS + +#endif // WEBRTC_BASE_OBJC_RTC_UI_APPLICATION_H_ diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCUIApplication.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCUIApplication.mm new file mode 100644 index 00000000000..7e8aea62955 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCUIApplication.mm @@ -0,0 +1,22 @@ +/* + * Copyright 2016 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "RTCUIApplication.h" + +#if defined(WEBRTC_IOS) + +#import <UIKit/UIKit.h> + +bool RTCIsUIApplicationActive() { + UIApplicationState state = [UIApplication sharedApplication].applicationState; + return state == UIApplicationStateActive; +} + +#endif // WEBRTC_IOS diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoFrame+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoFrame+Private.h new file mode 100644 index 00000000000..a4807127ca7 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoFrame+Private.h @@ -0,0 +1,27 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCVideoFrame.h" + +#include "webrtc/media/base/videoframe.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCVideoFrame () + +@property(nonatomic, readonly) + rtc::scoped_refptr<webrtc::VideoFrameBuffer> i420Buffer; + +- (instancetype)initWithNativeFrame:(const cricket::VideoFrame *)nativeFrame + NS_DESIGNATED_INITIALIZER; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoFrame.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoFrame.mm new file mode 100644 index 00000000000..1fb26954a39 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoFrame.mm @@ -0,0 +1,117 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCVideoFrame+Private.h" + +#include <memory> + +@implementation RTCVideoFrame { + std::unique_ptr<cricket::VideoFrame> _videoFrame; + rtc::scoped_refptr<webrtc::VideoFrameBuffer> _i420Buffer; +} + +- (size_t)width { + return _videoFrame->width(); +} + +- (size_t)height { + return _videoFrame->height(); +} + +// TODO(nisse): chromaWidth and chromaHeight are used only in +// RTCOpenGLVideoRenderer.mm. Update, and then delete these +// properties. +- (size_t)chromaWidth { + return (self.width + 1) / 2; +} + +- (size_t)chromaHeight { + return (self.height + 1) / 2; +} + +- (const uint8_t *)yPlane { + if (!self.i420Buffer) { + return nullptr; + } + return self.i420Buffer->data(webrtc::kYPlane); +} + +- (const uint8_t *)uPlane { + if (!self.i420Buffer) { + return nullptr; + } + return self.i420Buffer->data(webrtc::kUPlane); +} + +- (const uint8_t *)vPlane { + if (!self.i420Buffer) { + return nullptr; + } + return self.i420Buffer->data(webrtc::kVPlane); +} + +- (int32_t)yPitch { + if (!self.i420Buffer) { + return 0; + } + return self.i420Buffer->stride(webrtc::kYPlane); +} + +- (int32_t)uPitch { + if (!self.i420Buffer) { + return 0; + } + return self.i420Buffer->stride(webrtc::kUPlane); +} + +- (int32_t)vPitch { + if (!self.i420Buffer) { + return 0; + } + return self.i420Buffer->stride(webrtc::kVPlane); +} + +- (int64_t)timeStamp { + return _videoFrame->GetTimeStamp(); +} + +- (CVPixelBufferRef)nativeHandle { + return static_cast<CVPixelBufferRef>(_videoFrame->GetNativeHandle()); +} + +- (void)convertBufferIfNeeded { + if (!_i420Buffer) { + if (_videoFrame->GetNativeHandle()) { + // Convert to I420. + _i420Buffer = _videoFrame->video_frame_buffer()->NativeToI420Buffer(); + } else { + // Should already be I420. + _i420Buffer = _videoFrame->video_frame_buffer(); + } + } +} + +#pragma mark - Private + +- (instancetype)initWithNativeFrame:(const cricket::VideoFrame *)nativeFrame { + if (self = [super init]) { + // Keep a shallow copy of the video frame. The underlying frame buffer is + // not copied. + _videoFrame.reset(nativeFrame->Copy()); + } + return self; +} + +- (rtc::scoped_refptr<webrtc::VideoFrameBuffer>)i420Buffer { + [self convertBufferIfNeeded]; + return _i420Buffer; +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoRendererAdapter+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoRendererAdapter+Private.h new file mode 100644 index 00000000000..b413f7e3f6b --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoRendererAdapter+Private.h @@ -0,0 +1,42 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCVideoRendererAdapter.h" + +#import "WebRTC/RTCVideoRenderer.h" + +#include "webrtc/api/mediastreaminterface.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCVideoRendererAdapter () + +/** + * The Objective-C video renderer passed to this adapter during construction. + * Calls made to the webrtc::VideoRenderInterface will be adapted and passed to + * this video renderer. + */ +@property(nonatomic, readonly) id<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<cricket::VideoFrame> *nativeVideoRenderer; + +/** Initialize an RTCVideoRendererAdapter with an RTCVideoRenderer. */ +- (instancetype)initWithNativeRenderer:(id<RTCVideoRenderer>)videoRenderer + NS_DESIGNATED_INITIALIZER; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoRendererAdapter.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoRendererAdapter.h new file mode 100644 index 00000000000..b0b6f044884 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoRendererAdapter.h @@ -0,0 +1,27 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +NS_ASSUME_NONNULL_BEGIN + +/* + * Creates a rtc::VideoSinkInterface surface for an RTCVideoRenderer. The + * rtc::VideoSinkInterface is used by WebRTC rendering code - this + * adapter adapts calls made to that interface to the RTCVideoRenderer supplied + * during construction. + */ +@interface RTCVideoRendererAdapter : NSObject + +- (instancetype)init NS_UNAVAILABLE; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoRendererAdapter.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoRendererAdapter.mm new file mode 100644 index 00000000000..4976ba9f1f1 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoRendererAdapter.mm @@ -0,0 +1,83 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCVideoRendererAdapter+Private.h" + +#import "RTCVideoFrame+Private.h" + +#include <memory> + +#include "webrtc/media/engine/webrtcvideoframe.h" + +namespace webrtc { + +class VideoRendererAdapter + : public rtc::VideoSinkInterface<cricket::VideoFrame> { + public: + VideoRendererAdapter(RTCVideoRendererAdapter* adapter) { + adapter_ = adapter; + size_ = CGSizeZero; + } + + void OnFrame(const cricket::VideoFrame& nativeVideoFrame) override { + RTCVideoFrame *videoFrame = nil; + // Rotation of native handles is unsupported right now. Convert to CPU + // I420 buffer for rotation before calling the rotation method otherwise + // it will hit a DCHECK. + if (nativeVideoFrame.rotation() != webrtc::kVideoRotation_0 && + nativeVideoFrame.GetNativeHandle()) { + rtc::scoped_refptr<webrtc::VideoFrameBuffer> i420Buffer = + nativeVideoFrame.video_frame_buffer()->NativeToI420Buffer(); + std::unique_ptr<cricket::VideoFrame> cpuFrame( + new cricket::WebRtcVideoFrame(i420Buffer, + nativeVideoFrame.rotation(), + nativeVideoFrame.timestamp_us())); + const cricket::VideoFrame *rotatedFrame = + cpuFrame->GetCopyWithRotationApplied(); + videoFrame = [[RTCVideoFrame alloc] initWithNativeFrame:rotatedFrame]; + } else { + const cricket::VideoFrame *rotatedFrame = + nativeVideoFrame.GetCopyWithRotationApplied(); + videoFrame = [[RTCVideoFrame alloc] initWithNativeFrame:rotatedFrame]; + } + CGSize current_size = CGSizeMake(videoFrame.width, videoFrame.height); + if (!CGSizeEqualToSize(size_, current_size)) { + size_ = current_size; + [adapter_.videoRenderer setSize:size_]; + } + [adapter_.videoRenderer renderFrame:videoFrame]; + } + + private: + __weak RTCVideoRendererAdapter *adapter_; + CGSize size_; +}; +} + +@implementation RTCVideoRendererAdapter { + std::unique_ptr<webrtc::VideoRendererAdapter> _adapter; +} + +@synthesize videoRenderer = _videoRenderer; + +- (instancetype)initWithNativeRenderer:(id<RTCVideoRenderer>)videoRenderer { + NSParameterAssert(videoRenderer); + if (self = [super init]) { + _videoRenderer = videoRenderer; + _adapter.reset(new webrtc::VideoRendererAdapter(self)); + } + return self; +} + +- (rtc::VideoSinkInterface<cricket::VideoFrame> *)nativeVideoRenderer { + return _adapter.get(); +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoSource+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoSource+Private.h new file mode 100644 index 00000000000..757c1746ef7 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoSource+Private.h @@ -0,0 +1,42 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCVideoSource.h" + +#include "webrtc/api/mediastreaminterface.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCVideoSource () + +/** + * The VideoTrackSourceInterface object passed to this RTCVideoSource during + * construction. + */ +@property(nonatomic, readonly) + rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> + nativeVideoSource; + +/** Initialize an RTCVideoSource from a native VideoTrackSourceInterface. */ +- (instancetype)initWithNativeVideoSource: + (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource + NS_DESIGNATED_INITIALIZER; + ++ (webrtc::MediaSourceInterface::SourceState)nativeSourceStateForState: + (RTCSourceState)state; + ++ (RTCSourceState)sourceStateForNativeState: + (webrtc::MediaSourceInterface::SourceState)nativeState; + ++ (NSString *)stringForState:(RTCSourceState)state; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoSource.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoSource.mm new file mode 100644 index 00000000000..eddf5e0c684 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoSource.mm @@ -0,0 +1,82 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCVideoSource+Private.h" + +@implementation RTCVideoSource { + rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> _nativeVideoSource; +} + +- (RTCSourceState)state { + return [[self class] sourceStateForNativeState:_nativeVideoSource->state()]; +} + +- (NSString *)description { + return [NSString stringWithFormat:@"RTCVideoSource:\n%@", + [[self class] stringForState:self.state]]; +} + +#pragma mark - Private + +- (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource { + return _nativeVideoSource; +} + +- (instancetype)initWithNativeVideoSource: + (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource { + NSParameterAssert(nativeVideoSource); + if (self = [super init]) { + _nativeVideoSource = nativeVideoSource; + } + return self; +} + ++ (webrtc::MediaSourceInterface::SourceState)nativeSourceStateForState: + (RTCSourceState)state { + switch (state) { + case RTCSourceStateInitializing: + return webrtc::MediaSourceInterface::kInitializing; + case RTCSourceStateLive: + return webrtc::MediaSourceInterface::kLive; + case RTCSourceStateEnded: + return webrtc::MediaSourceInterface::kEnded; + case RTCSourceStateMuted: + return webrtc::MediaSourceInterface::kMuted; + } +} + ++ (RTCSourceState)sourceStateForNativeState: + (webrtc::MediaSourceInterface::SourceState)nativeState { + switch (nativeState) { + case webrtc::MediaSourceInterface::kInitializing: + return RTCSourceStateInitializing; + case webrtc::MediaSourceInterface::kLive: + return RTCSourceStateLive; + case webrtc::MediaSourceInterface::kEnded: + return RTCSourceStateEnded; + case webrtc::MediaSourceInterface::kMuted: + return RTCSourceStateMuted; + } +} + ++ (NSString *)stringForState:(RTCSourceState)state { + switch (state) { + case RTCSourceStateInitializing: + return @"Initializing"; + case RTCSourceStateLive: + return @"Live"; + case RTCSourceStateEnded: + return @"Ended"; + case RTCSourceStateMuted: + return @"Muted"; + } +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoTrack+Private.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoTrack+Private.h new file mode 100644 index 00000000000..5199be3b26c --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoTrack+Private.h @@ -0,0 +1,30 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "WebRTC/RTCVideoTrack.h" + +#include "webrtc/api/mediastreaminterface.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCVideoTrack () + +/** VideoTrackInterface created or passed in at construction. */ +@property(nonatomic, readonly) + rtc::scoped_refptr<webrtc::VideoTrackInterface> nativeVideoTrack; + +/** Initialize an RTCVideoTrack with its source and an id. */ +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + source:(RTCVideoSource *)source + trackId:(NSString *)trackId; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoTrack.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoTrack.mm new file mode 100644 index 00000000000..6691375fbff --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/RTCVideoTrack.mm @@ -0,0 +1,110 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCVideoTrack+Private.h" + +#import "NSString+StdString.h" +#import "RTCMediaStreamTrack+Private.h" +#import "RTCPeerConnectionFactory+Private.h" +#import "RTCVideoRendererAdapter+Private.h" +#import "RTCVideoSource+Private.h" + +@implementation RTCVideoTrack { + NSMutableArray *_adapters; +} + +@synthesize source = _source; + +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + source:(RTCVideoSource *)source + trackId:(NSString *)trackId { + NSParameterAssert(factory); + NSParameterAssert(source); + NSParameterAssert(trackId.length); + std::string nativeId = [NSString stdStringForString:trackId]; + rtc::scoped_refptr<webrtc::VideoTrackInterface> track = + factory.nativeFactory->CreateVideoTrack(nativeId, + source.nativeVideoSource); + if ([self initWithNativeTrack:track type:RTCMediaStreamTrackTypeVideo]) { + _source = source; + } + return self; +} + +- (instancetype)initWithNativeTrack: + (rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeMediaTrack + type:(RTCMediaStreamTrackType)type { + NSParameterAssert(nativeMediaTrack); + NSParameterAssert(type == RTCMediaStreamTrackTypeVideo); + if (self = [super initWithNativeTrack:nativeMediaTrack type:type]) { + _adapters = [NSMutableArray array]; + } + return self; +} + +- (void)dealloc { + for (RTCVideoRendererAdapter *adapter in _adapters) { + self.nativeVideoTrack->RemoveSink(adapter.nativeVideoRenderer); + } +} + +- (RTCVideoSource *)source { + if (!_source) { + rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source = + self.nativeVideoTrack->GetSource(); + if (source) { + _source = [[RTCVideoSource alloc] initWithNativeVideoSource:source.get()]; + } + } + return _source; +} + +- (void)addRenderer:(id<RTCVideoRenderer>)renderer { + // Make sure we don't have this renderer yet. + for (RTCVideoRendererAdapter *adapter in _adapters) { + // Getting around unused variable error + if (adapter.videoRenderer != renderer) { + NSAssert(NO, @"|renderer| is already attached to this track"); + } + } + // Create a wrapper that provides a native pointer for us. + RTCVideoRendererAdapter* adapter = + [[RTCVideoRendererAdapter alloc] initWithNativeRenderer:renderer]; + [_adapters addObject:adapter]; + self.nativeVideoTrack->AddOrUpdateSink(adapter.nativeVideoRenderer, + rtc::VideoSinkWants()); +} + +- (void)removeRenderer:(id<RTCVideoRenderer>)renderer { + __block NSUInteger indexToRemove = NSNotFound; + [_adapters enumerateObjectsUsingBlock:^(RTCVideoRendererAdapter *adapter, + NSUInteger idx, + BOOL *stop) { + if (adapter.videoRenderer == renderer) { + indexToRemove = idx; + *stop = YES; + } + }]; + if (indexToRemove == NSNotFound) { + return; + } + RTCVideoRendererAdapter *adapterToRemove = + [_adapters objectAtIndex:indexToRemove]; + self.nativeVideoTrack->RemoveSink(adapterToRemove.nativeVideoRenderer); + [_adapters removeObjectAtIndex:indexToRemove]; +} + +#pragma mark - Private + +- (rtc::scoped_refptr<webrtc::VideoTrackInterface>)nativeVideoTrack { + return static_cast<webrtc::VideoTrackInterface *>(self.nativeTrack.get()); +} + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.h b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.h new file mode 100644 index 00000000000..c523b527bbb --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.h @@ -0,0 +1,72 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef WEBRTC_API_OBJC_AVFOUNDATION_VIDEO_CAPTURER_H_ +#define WEBRTC_API_OBJC_AVFOUNDATION_VIDEO_CAPTURER_H_ + +#import <AVFoundation/AVFoundation.h> + +#include "webrtc/media/base/videocapturer.h" +#include "webrtc/video_frame.h" + +@class RTCAVFoundationVideoCapturerInternal; + +namespace rtc { +class Thread; +} // namespace rtc + +namespace webrtc { + +class AVFoundationVideoCapturer : public cricket::VideoCapturer, + public rtc::MessageHandler { + public: + AVFoundationVideoCapturer(); + ~AVFoundationVideoCapturer(); + + cricket::CaptureState Start(const cricket::VideoFormat& format) override; + void Stop() override; + bool IsRunning() override; + bool IsScreencast() const override { + return false; + } + bool GetPreferredFourccs(std::vector<uint32_t> *fourccs) override { + fourccs->push_back(cricket::FOURCC_NV12); + return true; + } + + // Returns the active capture session. Calls to the capture session should + // occur on the RTCDispatcherTypeCaptureSession queue in RTCDispatcher. + AVCaptureSession* GetCaptureSession(); + + // Returns whether the rear-facing camera can be used. + // e.g. It can't be used because it doesn't exist. + bool CanUseBackCamera() const; + + // Switches the camera being used (either front or back). + void SetUseBackCamera(bool useBackCamera); + bool GetUseBackCamera() const; + + // Converts the sample buffer into a cricket::CapturedFrame and signals the + // frame for capture. + void CaptureSampleBuffer(CMSampleBufferRef sampleBuffer); + + // Handles messages from posts. + void OnMessage(rtc::Message *msg) override; + + private: + void OnFrameMessage(CVImageBufferRef image_buffer, int64_t capture_time); + + RTCAVFoundationVideoCapturerInternal *_capturer; + rtc::Thread *_startThread; // Set in Start(), unset in Stop(). +}; // AVFoundationVideoCapturer + +} // namespace webrtc + +#endif // WEBRTC_API_OBJC_AVFOUNDATION_VIDEO_CAPTURER_H_ diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm new file mode 100644 index 00000000000..cb945f41cae --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm @@ -0,0 +1,545 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "avfoundationvideocapturer.h" + +#import <AVFoundation/AVFoundation.h> +#import <Foundation/Foundation.h> +#import <UIKit/UIKit.h> + +#import "RTCDispatcher+Private.h" +#import "WebRTC/RTCLogging.h" + +#include "webrtc/base/bind.h" +#include "webrtc/base/checks.h" +#include "webrtc/base/thread.h" + +// TODO(tkchin): support other formats. +static NSString *const kDefaultPreset = AVCaptureSessionPreset640x480; +static cricket::VideoFormat const kDefaultFormat = + cricket::VideoFormat(640, + 480, + cricket::VideoFormat::FpsToInterval(30), + cricket::FOURCC_NV12); + +// This class used to capture frames using AVFoundation APIs on iOS. It is meant +// to be owned by an instance of AVFoundationVideoCapturer. The reason for this +// because other webrtc objects own cricket::VideoCapturer, which is not +// ref counted. To prevent bad behavior we do not expose this class directly. +@interface RTCAVFoundationVideoCapturerInternal : NSObject + <AVCaptureVideoDataOutputSampleBufferDelegate> + +@property(nonatomic, readonly) AVCaptureSession *captureSession; +@property(nonatomic, readonly) BOOL isRunning; +@property(nonatomic, readonly) BOOL canUseBackCamera; +@property(nonatomic, assign) BOOL useBackCamera; // Defaults to NO. + +// We keep a pointer back to AVFoundationVideoCapturer to make callbacks on it +// when we receive frames. This is safe because this object should be owned by +// it. +- (instancetype)initWithCapturer:(webrtc::AVFoundationVideoCapturer *)capturer; + +// Starts and stops the capture session asynchronously. We cannot do this +// synchronously without blocking a WebRTC thread. +- (void)start; +- (void)stop; + +@end + +@implementation RTCAVFoundationVideoCapturerInternal { + // Keep pointers to inputs for convenience. + AVCaptureDeviceInput *_frontCameraInput; + AVCaptureDeviceInput *_backCameraInput; + AVCaptureVideoDataOutput *_videoDataOutput; + // The cricket::VideoCapturer that owns this class. Should never be NULL. + webrtc::AVFoundationVideoCapturer *_capturer; + BOOL _orientationHasChanged; +} + +@synthesize captureSession = _captureSession; +@synthesize isRunning = _isRunning; +@synthesize useBackCamera = _useBackCamera; + +// This is called from the thread that creates the video source, which is likely +// the main thread. +- (instancetype)initWithCapturer:(webrtc::AVFoundationVideoCapturer *)capturer { + RTC_DCHECK(capturer); + if (self = [super init]) { + _capturer = capturer; + // Create the capture session and all relevant inputs and outputs. We need + // to do this in init because the application may want the capture session + // before we start the capturer for e.g. AVCapturePreviewLayer. All objects + // created here are retained until dealloc and never recreated. + if (![self setupCaptureSession]) { + return nil; + } + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + [center addObserver:self + selector:@selector(deviceOrientationDidChange:) + name:UIDeviceOrientationDidChangeNotification + object:nil]; + [center addObserverForName:AVCaptureSessionRuntimeErrorNotification + object:nil + queue:nil + usingBlock:^(NSNotification *notification) { + RTCLogError(@"Capture session error: %@", notification.userInfo); + }]; + } + return self; +} + +- (void)dealloc { + RTC_DCHECK(!_isRunning); + [[NSNotificationCenter defaultCenter] removeObserver:self]; + _capturer = nullptr; +} + +- (AVCaptureSession *)captureSession { + return _captureSession; +} + +// Called from any thread (likely main thread). +- (BOOL)canUseBackCamera { + return _backCameraInput != nil; +} + +// Called from any thread (likely main thread). +- (BOOL)useBackCamera { + @synchronized(self) { + return _useBackCamera; + } +} + +// Called from any thread (likely main thread). +- (void)setUseBackCamera:(BOOL)useBackCamera { + if (!self.canUseBackCamera) { + if (useBackCamera) { + RTCLogWarning(@"No rear-facing camera exists or it cannot be used;" + "not switching."); + } + return; + } + @synchronized(self) { + if (_useBackCamera == useBackCamera) { + return; + } + _useBackCamera = useBackCamera; + [self updateSessionInputForUseBackCamera:useBackCamera]; + } +} + +// Called from WebRTC thread. +- (void)start { + if (_isRunning) { + return; + } + _isRunning = YES; + [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeCaptureSession + block:^{ + _orientationHasChanged = NO; + [self updateOrientation]; + [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; + AVCaptureSession *captureSession = self.captureSession; + [captureSession startRunning]; + }]; +} + +// Called from same thread as start. +- (void)stop { + if (!_isRunning) { + return; + } + _isRunning = NO; + [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeCaptureSession + block:^{ + [_videoDataOutput setSampleBufferDelegate:nil queue:nullptr]; + [_captureSession stopRunning]; + [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; + }]; +} + +#pragma mark AVCaptureVideoDataOutputSampleBufferDelegate + +- (void)captureOutput:(AVCaptureOutput *)captureOutput + didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer + fromConnection:(AVCaptureConnection *)connection { + NSParameterAssert(captureOutput == _videoDataOutput); + if (!_isRunning) { + return; + } + _capturer->CaptureSampleBuffer(sampleBuffer); +} + +- (void)captureOutput:(AVCaptureOutput *)captureOutput + didDropSampleBuffer:(CMSampleBufferRef)sampleBuffer + fromConnection:(AVCaptureConnection *)connection { + RTCLogError(@"Dropped sample buffer."); +} + +#pragma mark - Private + +- (BOOL)setupCaptureSession { + AVCaptureSession *captureSession = [[AVCaptureSession alloc] init]; +#if defined(__IPHONE_7_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0 + NSString *version = [[UIDevice currentDevice] systemVersion]; + if ([version integerValue] >= 7) { + captureSession.usesApplicationAudioSession = NO; + } +#endif + if (![captureSession canSetSessionPreset:kDefaultPreset]) { + RTCLogError(@"Session preset unsupported."); + return NO; + } + captureSession.sessionPreset = kDefaultPreset; + + // Add the output. + AVCaptureVideoDataOutput *videoDataOutput = [self videoDataOutput]; + if (![captureSession canAddOutput:videoDataOutput]) { + RTCLogError(@"Video data output unsupported."); + return NO; + } + [captureSession addOutput:videoDataOutput]; + + // Get the front and back cameras. If there isn't a front camera + // give up. + AVCaptureDeviceInput *frontCameraInput = [self frontCameraInput]; + AVCaptureDeviceInput *backCameraInput = [self backCameraInput]; + if (!frontCameraInput) { + RTCLogError(@"No front camera for capture session."); + return NO; + } + + // Add the inputs. + if (![captureSession canAddInput:frontCameraInput] || + (backCameraInput && ![captureSession canAddInput:backCameraInput])) { + RTCLogError(@"Session does not support capture inputs."); + return NO; + } + AVCaptureDeviceInput *input = self.useBackCamera ? + backCameraInput : frontCameraInput; + [captureSession addInput:input]; + _captureSession = captureSession; + return YES; +} + +- (AVCaptureVideoDataOutput *)videoDataOutput { + if (!_videoDataOutput) { + // Make the capturer output NV12. Ideally we want I420 but that's not + // currently supported on iPhone / iPad. + AVCaptureVideoDataOutput *videoDataOutput = + [[AVCaptureVideoDataOutput alloc] init]; + videoDataOutput = [[AVCaptureVideoDataOutput alloc] init]; + videoDataOutput.videoSettings = @{ + (NSString *)kCVPixelBufferPixelFormatTypeKey : + @(kCVPixelFormatType_420YpCbCr8BiPlanarFullRange) + }; + videoDataOutput.alwaysDiscardsLateVideoFrames = NO; + dispatch_queue_t queue = + [RTCDispatcher dispatchQueueForType:RTCDispatcherTypeCaptureSession]; + [videoDataOutput setSampleBufferDelegate:self queue:queue]; + _videoDataOutput = videoDataOutput; + } + return _videoDataOutput; +} + +- (AVCaptureDevice *)videoCaptureDeviceForPosition: + (AVCaptureDevicePosition)position { + for (AVCaptureDevice *captureDevice in + [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]) { + if (captureDevice.position == position) { + return captureDevice; + } + } + return nil; +} + +- (AVCaptureDeviceInput *)frontCameraInput { + if (!_frontCameraInput) { + AVCaptureDevice *frontCameraDevice = + [self videoCaptureDeviceForPosition:AVCaptureDevicePositionFront]; + if (!frontCameraDevice) { + RTCLogWarning(@"Failed to find front capture device."); + return nil; + } + NSError *error = nil; + AVCaptureDeviceInput *frontCameraInput = + [AVCaptureDeviceInput deviceInputWithDevice:frontCameraDevice + error:&error]; + if (!frontCameraInput) { + RTCLogError(@"Failed to create front camera input: %@", + error.localizedDescription); + return nil; + } + _frontCameraInput = frontCameraInput; + } + return _frontCameraInput; +} + +- (AVCaptureDeviceInput *)backCameraInput { + if (!_backCameraInput) { + AVCaptureDevice *backCameraDevice = + [self videoCaptureDeviceForPosition:AVCaptureDevicePositionBack]; + if (!backCameraDevice) { + RTCLogWarning(@"Failed to find front capture device."); + return nil; + } + NSError *error = nil; + AVCaptureDeviceInput *backCameraInput = + [AVCaptureDeviceInput deviceInputWithDevice:backCameraDevice + error:&error]; + if (!backCameraInput) { + RTCLogError(@"Failed to create front camera input: %@", + error.localizedDescription); + return nil; + } + _backCameraInput = backCameraInput; + } + return _backCameraInput; +} + +- (void)deviceOrientationDidChange:(NSNotification *)notification { + [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeCaptureSession + block:^{ + _orientationHasChanged = YES; + [self updateOrientation]; + }]; +} + +// Called from capture session queue. +- (void)updateOrientation { + AVCaptureConnection *connection = + [_videoDataOutput connectionWithMediaType:AVMediaTypeVideo]; + if (!connection.supportsVideoOrientation) { + // TODO(tkchin): set rotation bit on frames. + return; + } + AVCaptureVideoOrientation orientation = AVCaptureVideoOrientationPortrait; + switch ([UIDevice currentDevice].orientation) { + case UIDeviceOrientationPortrait: + orientation = AVCaptureVideoOrientationPortrait; + break; + case UIDeviceOrientationPortraitUpsideDown: + orientation = AVCaptureVideoOrientationPortraitUpsideDown; + break; + case UIDeviceOrientationLandscapeLeft: + orientation = AVCaptureVideoOrientationLandscapeRight; + break; + case UIDeviceOrientationLandscapeRight: + orientation = AVCaptureVideoOrientationLandscapeLeft; + break; + case UIDeviceOrientationFaceUp: + case UIDeviceOrientationFaceDown: + case UIDeviceOrientationUnknown: + if (!_orientationHasChanged) { + connection.videoOrientation = orientation; + } + return; + } + connection.videoOrientation = orientation; +} + +// Update the current session input to match what's stored in _useBackCamera. +- (void)updateSessionInputForUseBackCamera:(BOOL)useBackCamera { + [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeCaptureSession + block:^{ + [_captureSession beginConfiguration]; + AVCaptureDeviceInput *oldInput = _backCameraInput; + AVCaptureDeviceInput *newInput = _frontCameraInput; + if (useBackCamera) { + oldInput = _frontCameraInput; + newInput = _backCameraInput; + } + if (oldInput) { + // Ok to remove this even if it's not attached. Will be no-op. + [_captureSession removeInput:oldInput]; + } + if (newInput) { + [_captureSession addInput:newInput]; + } + [self updateOrientation]; + [_captureSession commitConfiguration]; + }]; +} + +@end + +namespace webrtc { + +enum AVFoundationVideoCapturerMessageType : uint32_t { + kMessageTypeFrame, +}; + +struct AVFoundationFrame { + AVFoundationFrame(CVImageBufferRef buffer, int64_t time) + : image_buffer(buffer), capture_time(time) {} + CVImageBufferRef image_buffer; + int64_t capture_time; +}; + +AVFoundationVideoCapturer::AVFoundationVideoCapturer() + : _capturer(nil), _startThread(nullptr) { + // Set our supported formats. This matches kDefaultPreset. + std::vector<cricket::VideoFormat> supportedFormats; + supportedFormats.push_back(cricket::VideoFormat(kDefaultFormat)); + SetSupportedFormats(supportedFormats); + _capturer = + [[RTCAVFoundationVideoCapturerInternal alloc] initWithCapturer:this]; +} + +AVFoundationVideoCapturer::~AVFoundationVideoCapturer() { + _capturer = nil; +} + +cricket::CaptureState AVFoundationVideoCapturer::Start( + const cricket::VideoFormat& format) { + if (!_capturer) { + LOG(LS_ERROR) << "Failed to create AVFoundation capturer."; + return cricket::CaptureState::CS_FAILED; + } + if (_capturer.isRunning) { + LOG(LS_ERROR) << "The capturer is already running."; + return cricket::CaptureState::CS_FAILED; + } + if (format != kDefaultFormat) { + LOG(LS_ERROR) << "Unsupported format provided."; + return cricket::CaptureState::CS_FAILED; + } + + // Keep track of which thread capture started on. This is the thread that + // frames need to be sent to. + RTC_DCHECK(!_startThread); + _startThread = rtc::Thread::Current(); + + SetCaptureFormat(&format); + // This isn't super accurate because it takes a while for the AVCaptureSession + // to spin up, and this call returns async. + // TODO(tkchin): make this better. + [_capturer start]; + SetCaptureState(cricket::CaptureState::CS_RUNNING); + + return cricket::CaptureState::CS_STARTING; +} + +void AVFoundationVideoCapturer::Stop() { + [_capturer stop]; + SetCaptureFormat(NULL); + _startThread = nullptr; +} + +bool AVFoundationVideoCapturer::IsRunning() { + return _capturer.isRunning; +} + +AVCaptureSession* AVFoundationVideoCapturer::GetCaptureSession() { + return _capturer.captureSession; +} + +bool AVFoundationVideoCapturer::CanUseBackCamera() const { + return _capturer.canUseBackCamera; +} + +void AVFoundationVideoCapturer::SetUseBackCamera(bool useBackCamera) { + _capturer.useBackCamera = useBackCamera; +} + +bool AVFoundationVideoCapturer::GetUseBackCamera() const { + return _capturer.useBackCamera; +} + +void AVFoundationVideoCapturer::CaptureSampleBuffer( + CMSampleBufferRef sampleBuffer) { + if (CMSampleBufferGetNumSamples(sampleBuffer) != 1 || + !CMSampleBufferIsValid(sampleBuffer) || + !CMSampleBufferDataIsReady(sampleBuffer)) { + return; + } + + CVImageBufferRef image_buffer = CMSampleBufferGetImageBuffer(sampleBuffer); + if (image_buffer == NULL) { + return; + } + + // Retain the buffer and post it to the webrtc thread. It will be released + // after it has successfully been signaled. + CVBufferRetain(image_buffer); + AVFoundationFrame frame(image_buffer, rtc::TimeNanos()); + _startThread->Post(this, kMessageTypeFrame, + new rtc::TypedMessageData<AVFoundationFrame>(frame)); +} + +void AVFoundationVideoCapturer::OnMessage(rtc::Message *msg) { + switch (msg->message_id) { + case kMessageTypeFrame: { + rtc::TypedMessageData<AVFoundationFrame>* data = + static_cast<rtc::TypedMessageData<AVFoundationFrame>*>(msg->pdata); + const AVFoundationFrame& frame = data->data(); + OnFrameMessage(frame.image_buffer, frame.capture_time); + delete data; + break; + } + } +} + +void AVFoundationVideoCapturer::OnFrameMessage(CVImageBufferRef image_buffer, + int64_t capture_time) { + RTC_DCHECK(_startThread->IsCurrent()); + + // Base address must be unlocked to access frame data. + CVOptionFlags lock_flags = kCVPixelBufferLock_ReadOnly; + CVReturn ret = CVPixelBufferLockBaseAddress(image_buffer, lock_flags); + if (ret != kCVReturnSuccess) { + return; + } + + static size_t const kYPlaneIndex = 0; + static size_t const kUVPlaneIndex = 1; + uint8_t* y_plane_address = + static_cast<uint8_t*>(CVPixelBufferGetBaseAddressOfPlane(image_buffer, + kYPlaneIndex)); + size_t y_plane_height = + CVPixelBufferGetHeightOfPlane(image_buffer, kYPlaneIndex); + size_t y_plane_width = + CVPixelBufferGetWidthOfPlane(image_buffer, kYPlaneIndex); + size_t y_plane_bytes_per_row = + CVPixelBufferGetBytesPerRowOfPlane(image_buffer, kYPlaneIndex); + size_t uv_plane_height = + CVPixelBufferGetHeightOfPlane(image_buffer, kUVPlaneIndex); + size_t uv_plane_bytes_per_row = + CVPixelBufferGetBytesPerRowOfPlane(image_buffer, kUVPlaneIndex); + size_t frame_size = y_plane_bytes_per_row * y_plane_height + + uv_plane_bytes_per_row * uv_plane_height; + + // Sanity check assumption that planar bytes are contiguous. + uint8_t* uv_plane_address = + static_cast<uint8_t*>(CVPixelBufferGetBaseAddressOfPlane(image_buffer, + kUVPlaneIndex)); + RTC_DCHECK(uv_plane_address == + y_plane_address + y_plane_height * y_plane_bytes_per_row); + + // Stuff data into a cricket::CapturedFrame. + cricket::CapturedFrame frame; + frame.width = y_plane_width; + frame.height = y_plane_height; + frame.pixel_width = 1; + frame.pixel_height = 1; + frame.fourcc = static_cast<uint32_t>(cricket::FOURCC_NV12); + frame.time_stamp = capture_time; + frame.data = y_plane_address; + frame.data_size = frame_size; + + // This will call a superclass method that will perform the frame conversion + // to I420. + SignalFrameCaptured(this, &frame); + + CVPixelBufferUnlockBaseAddress(image_buffer, lock_flags); + CVBufferRelease(image_buffer); +} + +} // namespace webrtc diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCAVFoundationVideoSource.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCAVFoundationVideoSource.h new file mode 100644 index 00000000000..2a732b9686b --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCAVFoundationVideoSource.h @@ -0,0 +1,43 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <WebRTC/RTCMacros.h> +#import <WebRTC/RTCVideoSource.h> + +@class AVCaptureSession; +@class RTCMediaConstraints; +@class RTCPeerConnectionFactory; + +NS_ASSUME_NONNULL_BEGIN + +/** + * RTCAVFoundationVideoSource is a video source that uses + * webrtc::AVFoundationVideoCapturer. We do not currently provide a wrapper for + * that capturer because cricket::VideoCapturer is not ref counted and we cannot + * guarantee its lifetime. Instead, we expose its properties through the ref + * counted video source interface. + */ +RTC_EXPORT +@interface RTCAVFoundationVideoSource : RTCVideoSource + +- (instancetype)init NS_UNAVAILABLE; + +/** Returns whether rear-facing camera is available for use. */ +@property(nonatomic, readonly) BOOL canUseBackCamera; + +/** Switches the camera being used (either front or back). */ +@property(nonatomic, assign) BOOL useBackCamera; + +/** Returns the active capture session. */ +@property(nonatomic, readonly) AVCaptureSession *captureSession; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCAudioTrack.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCAudioTrack.h new file mode 100644 index 00000000000..a9f5fe22777 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCAudioTrack.h @@ -0,0 +1,23 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <WebRTC/RTCMacros.h> +#import <WebRTC/RTCMediaStreamTrack.h> + +NS_ASSUME_NONNULL_BEGIN + +RTC_EXPORT +@interface RTCAudioTrack : RTCMediaStreamTrack + +- (instancetype)init NS_UNAVAILABLE; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCCameraPreviewView.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCCameraPreviewView.h new file mode 100644 index 00000000000..9018aec3d18 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCCameraPreviewView.h @@ -0,0 +1,31 @@ +/* + * Copyright 2015 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> +#import <UIKit/UIKit.h> + +#import <WebRTC/RTCMacros.h> + +@class AVCaptureSession; +@class RTCAVFoundationVideoSource; + +/** RTCCameraPreviewView is a view that renders local video from an + * AVCaptureSession. + */ +RTC_EXPORT +@interface RTCCameraPreviewView : UIView + +/** The capture session being rendered in the view. Capture session + * is assigned to AVCaptureVideoPreviewLayer async in the same + * queue that the AVCaptureSession is started/stopped. + */ +@property(nonatomic, strong) AVCaptureSession *captureSession; + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCConfiguration.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCConfiguration.h new file mode 100644 index 00000000000..74e7801ac05 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCConfiguration.h @@ -0,0 +1,90 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +@class RTCIceServer; + +/** + * Represents the ice transport policy. This exposes the same states in C++, + * which include one more state than what exists in the W3C spec. + */ +typedef NS_ENUM(NSInteger, RTCIceTransportPolicy) { + RTCIceTransportPolicyNone, + RTCIceTransportPolicyRelay, + RTCIceTransportPolicyNoHost, + RTCIceTransportPolicyAll +}; + +/** Represents the bundle policy. */ +typedef NS_ENUM(NSInteger, RTCBundlePolicy) { + RTCBundlePolicyBalanced, + RTCBundlePolicyMaxCompat, + RTCBundlePolicyMaxBundle +}; + +/** Represents the rtcp mux policy. */ +typedef NS_ENUM(NSInteger, RTCRtcpMuxPolicy) { + RTCRtcpMuxPolicyNegotiate, + RTCRtcpMuxPolicyRequire +}; + +/** Represents the tcp candidate policy. */ +typedef NS_ENUM(NSInteger, RTCTcpCandidatePolicy) { + RTCTcpCandidatePolicyEnabled, + RTCTcpCandidatePolicyDisabled +}; + +/** Represents the continual gathering policy. */ +typedef NS_ENUM(NSInteger, RTCContinualGatheringPolicy) { + RTCContinualGatheringPolicyGatherOnce, + RTCContinualGatheringPolicyGatherContinually +}; + +/** Represents the encryption key type. */ +typedef NS_ENUM(NSInteger, RTCEncryptionKeyType) { + RTCEncryptionKeyTypeRSA, + RTCEncryptionKeyTypeECDSA, +}; + +NS_ASSUME_NONNULL_BEGIN + +RTC_EXPORT +@interface RTCConfiguration : NSObject + +/** An array of Ice Servers available to be used by ICE. */ +@property(nonatomic, copy) NSArray<RTCIceServer *> *iceServers; + +/** Which candidates the ICE agent is allowed to use. The W3C calls it + * |iceTransportPolicy|, while in C++ it is called |type|. */ +@property(nonatomic, assign) RTCIceTransportPolicy iceTransportPolicy; + +/** The media-bundling policy to use when gathering ICE candidates. */ +@property(nonatomic, assign) RTCBundlePolicy bundlePolicy; + +/** The rtcp-mux policy to use when gathering ICE candidates. */ +@property(nonatomic, assign) RTCRtcpMuxPolicy rtcpMuxPolicy; +@property(nonatomic, assign) RTCTcpCandidatePolicy tcpCandidatePolicy; +@property(nonatomic, assign) + RTCContinualGatheringPolicy continualGatheringPolicy; +@property(nonatomic, assign) int audioJitterBufferMaxPackets; +@property(nonatomic, assign) int iceConnectionReceivingTimeout; +@property(nonatomic, assign) int iceBackupCandidatePairPingInterval; + +/** Key type used to generate SSL identity. Default is ECDSA. */ +@property(nonatomic, assign) RTCEncryptionKeyType keyType; + +- (instancetype)init NS_DESIGNATED_INITIALIZER; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCDataChannel.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCDataChannel.h new file mode 100644 index 00000000000..893bd0a3365 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCDataChannel.h @@ -0,0 +1,134 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <AvailabilityMacros.h> +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +NS_ASSUME_NONNULL_BEGIN + +RTC_EXPORT +@interface RTCDataBuffer : NSObject + +/** NSData representation of the underlying buffer. */ +@property(nonatomic, readonly) NSData *data; + +/** Indicates whether |data| contains UTF-8 or binary data. */ +@property(nonatomic, readonly) BOOL isBinary; + +- (instancetype)init NS_UNAVAILABLE; + +/** + * Initialize an RTCDataBuffer from NSData. |isBinary| indicates whether |data| + * contains UTF-8 or binary data. + */ +- (instancetype)initWithData:(NSData *)data isBinary:(BOOL)isBinary; + +@end + + +@class RTCDataChannel; +RTC_EXPORT +@protocol RTCDataChannelDelegate <NSObject> + +/** The data channel state changed. */ +- (void)dataChannelDidChangeState:(RTCDataChannel *)dataChannel; + +/** The data channel successfully received a data buffer. */ +- (void)dataChannel:(RTCDataChannel *)dataChannel + didReceiveMessageWithBuffer:(RTCDataBuffer *)buffer; + +@optional +/** The data channel's |bufferedAmount| changed. */ +- (void)dataChannel:(RTCDataChannel *)dataChannel + didChangeBufferedAmount:(uint64_t)amount; + +@end + + +/** Represents the state of the data channel. */ +typedef NS_ENUM(NSInteger, RTCDataChannelState) { + RTCDataChannelStateConnecting, + RTCDataChannelStateOpen, + RTCDataChannelStateClosing, + RTCDataChannelStateClosed, +}; + +RTC_EXPORT +@interface RTCDataChannel : NSObject + +/** + * A label that can be used to distinguish this data channel from other data + * channel objects. + */ +@property(nonatomic, readonly) NSString *label; + +/** Whether the data channel can send messages in unreliable mode. */ +@property(nonatomic, readonly) BOOL isReliable DEPRECATED_ATTRIBUTE; + +/** Returns whether this data channel is ordered or not. */ +@property(nonatomic, readonly) BOOL isOrdered; + +/** Deprecated. Use maxPacketLifeTime. */ +@property(nonatomic, readonly) NSUInteger maxRetransmitTime + DEPRECATED_ATTRIBUTE; + +/** + * The length of the time window (in milliseconds) during which transmissions + * and retransmissions may occur in unreliable mode. + */ +@property(nonatomic, readonly) uint16_t maxPacketLifeTime; + +/** + * The maximum number of retransmissions that are attempted in unreliable mode. + */ +@property(nonatomic, readonly) uint16_t maxRetransmits; + +/** + * The name of the sub-protocol used with this data channel, if any. Otherwise + * this returns an empty string. + */ +@property(nonatomic, readonly) NSString *protocol; + +/** + * Returns whether this data channel was negotiated by the application or not. + */ +@property(nonatomic, readonly) BOOL isNegotiated; + +/** Deprecated. Use channelId. */ +@property(nonatomic, readonly) NSInteger streamId DEPRECATED_ATTRIBUTE; + +/** The identifier for this data channel. */ +@property(nonatomic, readonly) int channelId; + +/** The state of the data channel. */ +@property(nonatomic, readonly) RTCDataChannelState readyState; + +/** + * The number of bytes of application data that have been queued using + * |sendData:| but that have not yet been transmitted to the network. + */ +@property(nonatomic, readonly) uint64_t bufferedAmount; + +/** The delegate for this data channel. */ +@property(nonatomic, weak) id<RTCDataChannelDelegate> delegate; + +- (instancetype)init NS_UNAVAILABLE; + +/** Closes the data channel. */ +- (void)close; + +/** Attempt to send |data| on this data channel's underlying data transport. */ +- (BOOL)sendData:(RTCDataBuffer *)data; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCDataChannelConfiguration.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCDataChannelConfiguration.h new file mode 100644 index 00000000000..65f59318447 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCDataChannelConfiguration.h @@ -0,0 +1,52 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <AvailabilityMacros.h> +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +NS_ASSUME_NONNULL_BEGIN + +RTC_EXPORT +@interface RTCDataChannelConfiguration : NSObject + +/** Set to YES if ordered delivery is required. */ +@property(nonatomic, assign) BOOL isOrdered; + +/** Deprecated. Use maxPacketLifeTime. */ +@property(nonatomic, assign) NSInteger maxRetransmitTimeMs DEPRECATED_ATTRIBUTE; + +/** + * Max period in milliseconds in which retransmissions will be sent. After this + * time, no more retransmissions will be sent. -1 if unset. + */ +@property(nonatomic, assign) int maxPacketLifeTime; + +/** The max number of retransmissions. -1 if unset. */ +@property(nonatomic, assign) int maxRetransmits; + +/** Set to YES if the channel has been externally negotiated and we do not send + * an in-band signalling in the form of an "open" message. + */ +@property(nonatomic, assign) BOOL isNegotiated; + +/** Deprecated. Use channelId. */ +@property(nonatomic, assign) int streamId DEPRECATED_ATTRIBUTE; + +/** The id of the data channel. */ +@property(nonatomic, assign) int channelId; + +/** Set by the application and opaque to the WebRTC implementation. */ +@property(nonatomic) NSString *protocol; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCDispatcher.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCDispatcher.h new file mode 100644 index 00000000000..328beaf8728 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCDispatcher.h @@ -0,0 +1,40 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +typedef NS_ENUM(NSInteger, RTCDispatcherQueueType) { + // Main dispatcher queue. + RTCDispatcherTypeMain, + // Used for starting/stopping AVCaptureSession, and assigning + // capture session to AVCaptureVideoPreviewLayer. + RTCDispatcherTypeCaptureSession, + // Used for operations on AVAudioSession. + RTCDispatcherTypeAudioSession, +}; + +/** Dispatcher that asynchronously dispatches blocks to a specific + * shared dispatch queue. + */ +RTC_EXPORT +@interface RTCDispatcher : NSObject + +- (instancetype)init NS_UNAVAILABLE; + +/** Dispatch the block asynchronously on the queue for dispatchType. + * @param dispatchType The queue type to dispatch on. + * @param block The block to dispatch asynchronously. + */ ++ (void)dispatchAsyncOnType:(RTCDispatcherQueueType)dispatchType + block:(dispatch_block_t)block; + +@end diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCEAGLVideoView.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCEAGLVideoView.h new file mode 100644 index 00000000000..5f8d73bc8d6 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCEAGLVideoView.h @@ -0,0 +1,38 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> +#import <UIKit/UIKit.h> + +#import <WebRTC/RTCMacros.h> +#import <WebRTC/RTCVideoRenderer.h> + +NS_ASSUME_NONNULL_BEGIN + +@class RTCEAGLVideoView; +RTC_EXPORT +@protocol RTCEAGLVideoViewDelegate + +- (void)videoView:(RTCEAGLVideoView *)videoView didChangeVideoSize:(CGSize)size; + +@end + +/** + * RTCEAGLVideoView is an RTCVideoRenderer which renders video frames in its + * bounds using OpenGLES 2.0. + */ +RTC_EXPORT +@interface RTCEAGLVideoView : UIView <RTCVideoRenderer> + +@property(nonatomic, weak) id<RTCEAGLVideoViewDelegate> delegate; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCFieldTrials.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCFieldTrials.h new file mode 100644 index 00000000000..7e7c1c4480a --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCFieldTrials.h @@ -0,0 +1,23 @@ +/* + * Copyright 2016 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +typedef NS_OPTIONS(NSUInteger, RTCFieldTrialOptions) { + RTCFieldTrialOptionsNone = 0, + RTCFieldTrialOptionsSendSideBwe = 1 << 0, +}; + +/** Must be called before any other call into WebRTC. See: + * webrtc/system_wrappers/include/field_trial_default.h + */ +RTC_EXTERN void RTCInitFieldTrials(RTCFieldTrialOptions options); diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCFileLogger.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCFileLogger.h new file mode 100644 index 00000000000..5656b7bf43f --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCFileLogger.h @@ -0,0 +1,77 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +typedef NS_ENUM(NSUInteger, RTCFileLoggerSeverity) { + RTCFileLoggerSeverityVerbose, + RTCFileLoggerSeverityInfo, + RTCFileLoggerSeverityWarning, + RTCFileLoggerSeverityError +}; + +typedef NS_ENUM(NSUInteger, RTCFileLoggerRotationType) { + RTCFileLoggerTypeCall, + RTCFileLoggerTypeApp, +}; + +NS_ASSUME_NONNULL_BEGIN + +// This class intercepts WebRTC logs and saves them to a file. The file size +// will not exceed the given maximum bytesize. When the maximum bytesize is +// reached, logs are rotated according to the rotationType specified. +// For kRTCFileLoggerTypeCall, logs from the beginning and the end +// are preserved while the middle section is overwritten instead. +// For kRTCFileLoggerTypeApp, the oldest log is overwritten. +// This class is not threadsafe. +RTC_EXPORT +@interface RTCFileLogger : NSObject + +// The severity level to capture. The default is kRTCFileLoggerSeverityInfo. +@property(nonatomic, assign) RTCFileLoggerSeverity severity; + +// The rotation type for this file logger. The default is +// kRTCFileLoggerTypeCall. +@property(nonatomic, readonly) RTCFileLoggerRotationType rotationType; + +// Disables buffering disk writes. Should be set before |start|. Buffering +// is enabled by default for performance. +@property(nonatomic, assign) BOOL shouldDisableBuffering; + +// Default constructor provides default settings for dir path, file size and +// rotation type. +- (instancetype)init; + +// Create file logger with default rotation type. +- (instancetype)initWithDirPath:(NSString *)dirPath + maxFileSize:(NSUInteger)maxFileSize; + +- (instancetype)initWithDirPath:(NSString *)dirPath + maxFileSize:(NSUInteger)maxFileSize + rotationType:(RTCFileLoggerRotationType)rotationType + NS_DESIGNATED_INITIALIZER; + +// Starts writing WebRTC logs to disk if not already started. Overwrites any +// existing file(s). +- (void)start; + +// Stops writing WebRTC logs to disk. This method is also called on dealloc. +- (void)stop; + +// Returns the current contents of the logs, or nil if start has been called +// without a stop. +- (NSData *)logData; + +@end + +NS_ASSUME_NONNULL_END + diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCIceCandidate.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCIceCandidate.h new file mode 100644 index 00000000000..9f472b8df05 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCIceCandidate.h @@ -0,0 +1,47 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +NS_ASSUME_NONNULL_BEGIN + +RTC_EXPORT +@interface RTCIceCandidate : NSObject + +/** + * If present, the identifier of the "media stream identification" for the media + * component this candidate is associated with. + */ +@property(nonatomic, readonly, nullable) NSString *sdpMid; + +/** + * The index (starting at zero) of the media description this candidate is + * associated with in the SDP. + */ +@property(nonatomic, readonly) int sdpMLineIndex; + +/** The SDP string for this candidate. */ +@property(nonatomic, readonly) NSString *sdp; + +- (instancetype)init NS_UNAVAILABLE; + +/** + * Initialize an RTCIceCandidate from SDP. + */ +- (instancetype)initWithSdp:(NSString *)sdp + sdpMLineIndex:(int)sdpMLineIndex + sdpMid:(nullable NSString *)sdpMid + NS_DESIGNATED_INITIALIZER; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCIceServer.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCIceServer.h new file mode 100644 index 00000000000..ff5489cb412 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCIceServer.h @@ -0,0 +1,45 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +NS_ASSUME_NONNULL_BEGIN + +RTC_EXPORT +@interface RTCIceServer : NSObject + +/** URI(s) for this server represented as NSStrings. */ +@property(nonatomic, readonly) NSArray<NSString *> *urlStrings; + +/** Username to use if this RTCIceServer object is a TURN server. */ +@property(nonatomic, readonly, nullable) NSString *username; + +/** Credential to use if this RTCIceServer object is a TURN server. */ +@property(nonatomic, readonly, nullable) NSString *credential; + +- (nonnull instancetype)init NS_UNAVAILABLE; + +/** Convenience initializer for a server with no authentication (e.g. STUN). */ +- (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings; + +/** + * Initialize an RTCIceServer with its associated URLs, optional username, + * optional credential, and credentialType. + */ +- (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings + username:(nullable NSString *)username + credential:(nullable NSString *)credential + NS_DESIGNATED_INITIALIZER; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCLogging.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCLogging.h new file mode 100644 index 00000000000..e4f19203829 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCLogging.h @@ -0,0 +1,69 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +// Subset of rtc::LoggingSeverity. +typedef NS_ENUM(NSInteger, RTCLoggingSeverity) { + RTCLoggingSeverityVerbose, + RTCLoggingSeverityInfo, + RTCLoggingSeverityWarning, + RTCLoggingSeverityError, +}; + +// Wrapper for C++ LOG(sev) macros. +// Logs the log string to the webrtc logstream for the given severity. +RTC_EXTERN void RTCLogEx(RTCLoggingSeverity severity, NSString* log_string); + +// Wrapper for rtc::LogMessage::LogToDebug. +// Sets the minimum severity to be logged to console. +RTC_EXTERN void RTCSetMinDebugLogLevel(RTCLoggingSeverity severity); + +// Returns the filename with the path prefix removed. +RTC_EXTERN NSString* RTCFileName(const char* filePath); + +// Some convenience macros. + +#define RTCLogString(format, ...) \ + [NSString stringWithFormat:@"(%@:%d %s): " format, \ + RTCFileName(__FILE__), \ + __LINE__, \ + __FUNCTION__, \ + ##__VA_ARGS__] + +#define RTCLogFormat(severity, format, ...) \ + do { \ + NSString* log_string = RTCLogString(format, ##__VA_ARGS__); \ + RTCLogEx(severity, log_string); \ + } while (false) + +#define RTCLogVerbose(format, ...) \ + RTCLogFormat(RTCLoggingSeverityVerbose, format, ##__VA_ARGS__) \ + +#define RTCLogInfo(format, ...) \ + RTCLogFormat(RTCLoggingSeverityInfo, format, ##__VA_ARGS__) \ + +#define RTCLogWarning(format, ...) \ + RTCLogFormat(RTCLoggingSeverityWarning, format, ##__VA_ARGS__) \ + +#define RTCLogError(format, ...) \ + RTCLogFormat(RTCLoggingSeverityError, format, ##__VA_ARGS__) \ + +#if !defined(NDEBUG) +#define RTCLogDebug(format, ...) RTCLogInfo(format, ##__VA_ARGS__) +#else +#define RTCLogDebug(format, ...) \ + do { \ + } while (false) +#endif + +#define RTCLog(format, ...) RTCLogInfo(format, ##__VA_ARGS__) diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCMacros.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCMacros.h new file mode 100644 index 00000000000..f9f15c37d39 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCMacros.h @@ -0,0 +1,28 @@ +/* + * Copyright 2016 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef WEBRTC_BASE_OBJC_RTC_MACROS_H_ +#define WEBRTC_BASE_OBJC_RTC_MACROS_H_ + +#define RTC_EXPORT __attribute__((visibility("default"))) + +#if defined(__cplusplus) +#define RTC_EXTERN extern "C" RTC_EXPORT +#else +#define RTC_EXTERN extern RTC_EXPORT +#endif + +#ifdef __OBJC__ +#define RTC_FWD_DECL_OBJC_CLASS(classname) @class classname +#else +#define RTC_FWD_DECL_OBJC_CLASS(classname) typedef struct objc_object classname +#endif + +#endif // WEBRTC_BASE_OBJC_RTC_MACROS_H_ diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCMediaConstraints.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCMediaConstraints.h new file mode 100644 index 00000000000..adc73f2f432 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCMediaConstraints.h @@ -0,0 +1,31 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +NS_ASSUME_NONNULL_BEGIN + +RTC_EXPORT +@interface RTCMediaConstraints : NSObject + +- (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; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCMediaStream.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCMediaStream.h new file mode 100644 index 00000000000..b97960d436c --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCMediaStream.h @@ -0,0 +1,49 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +NS_ASSUME_NONNULL_BEGIN + +@class RTCAudioTrack; +@class RTCPeerConnectionFactory; +@class RTCVideoTrack; + +RTC_EXPORT +@interface RTCMediaStream : NSObject + +/** The audio tracks in this stream. */ +@property(nonatomic, strong, readonly) NSArray<RTCAudioTrack *> *audioTracks; + +/** The video tracks in this stream. */ +@property(nonatomic, strong, readonly) NSArray<RTCVideoTrack *> *videoTracks; + +/** An identifier for this media stream. */ +@property(nonatomic, readonly) NSString *streamId; + +- (instancetype)init NS_UNAVAILABLE; + +/** Adds the given audio track to this media stream. */ +- (void)addAudioTrack:(RTCAudioTrack *)audioTrack; + +/** Adds the given video track to this media stream. */ +- (void)addVideoTrack:(RTCVideoTrack *)videoTrack; + +/** Removes the given audio track to this media stream. */ +- (void)removeAudioTrack:(RTCAudioTrack *)audioTrack; + +/** Removes the given video track to this media stream. */ +- (void)removeVideoTrack:(RTCVideoTrack *)videoTrack; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCMediaStreamTrack.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCMediaStreamTrack.h new file mode 100644 index 00000000000..c42f0cfb1a0 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCMediaStreamTrack.h @@ -0,0 +1,50 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +/** + * Represents the state of the track. This exposes the same states in C++. + */ +typedef NS_ENUM(NSInteger, RTCMediaStreamTrackState) { + RTCMediaStreamTrackStateLive, + RTCMediaStreamTrackStateEnded +}; + +NS_ASSUME_NONNULL_BEGIN + +RTC_EXTERN NSString * const kRTCMediaStreamTrackKindAudio; +RTC_EXTERN NSString * const kRTCMediaStreamTrackKindVideo; + +RTC_EXPORT +@interface RTCMediaStreamTrack : NSObject + +/** + * The kind of track. For example, "audio" if this track represents an audio + * track and "video" if this track represents a video track. + */ +@property(nonatomic, readonly) NSString *kind; + +/** An identifier string. */ +@property(nonatomic, readonly) NSString *trackId; + +/** The enabled state of the track. */ +@property(nonatomic, assign) BOOL isEnabled; + +/** The state of the track. */ +@property(nonatomic, readonly) RTCMediaStreamTrackState readyState; + +- (instancetype)init NS_UNAVAILABLE; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCNSGLVideoView.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCNSGLVideoView.h new file mode 100644 index 00000000000..d9ed6fb9f26 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCNSGLVideoView.h @@ -0,0 +1,34 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#if !TARGET_OS_IPHONE + +#import <AppKit/NSOpenGLView.h> + +#import <WebRTC/RTCVideoRenderer.h> + +NS_ASSUME_NONNULL_BEGIN + +@class RTCNSGLVideoView; +@protocol RTCNSGLVideoViewDelegate + +- (void)videoView:(RTCNSGLVideoView *)videoView didChangeVideoSize:(CGSize)size; + +@end + +@interface RTCNSGLVideoView : NSOpenGLView <RTCVideoRenderer> + +@property(nonatomic, weak) id<RTCNSGLVideoViewDelegate> delegate; + +@end + +NS_ASSUME_NONNULL_END + +#endif diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnection.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnection.h new file mode 100644 index 00000000000..2ba8661d13a --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnection.h @@ -0,0 +1,212 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +@class RTCConfiguration; +@class RTCDataChannel; +@class RTCDataChannelConfiguration; +@class RTCIceCandidate; +@class RTCMediaConstraints; +@class RTCMediaStream; +@class RTCMediaStreamTrack; +@class RTCPeerConnectionFactory; +@class RTCRtpReceiver; +@class RTCRtpSender; +@class RTCSessionDescription; +@class RTCStatsReport; + +NS_ASSUME_NONNULL_BEGIN + +extern NSString * const kRTCPeerConnectionErrorDomain; +extern int const kRTCSessionDescriptionErrorCode; + +/** Represents the signaling state of the peer connection. */ +typedef NS_ENUM(NSInteger, RTCSignalingState) { + RTCSignalingStateStable, + RTCSignalingStateHaveLocalOffer, + RTCSignalingStateHaveLocalPrAnswer, + RTCSignalingStateHaveRemoteOffer, + RTCSignalingStateHaveRemotePrAnswer, + // Not an actual state, represents the total number of states. + RTCSignalingStateClosed, +}; + +/** Represents the ice connection state of the peer connection. */ +typedef NS_ENUM(NSInteger, RTCIceConnectionState) { + RTCIceConnectionStateNew, + RTCIceConnectionStateChecking, + RTCIceConnectionStateConnected, + RTCIceConnectionStateCompleted, + RTCIceConnectionStateFailed, + RTCIceConnectionStateDisconnected, + RTCIceConnectionStateClosed, + RTCIceConnectionStateCount, +}; + +/** Represents the ice gathering state of the peer connection. */ +typedef NS_ENUM(NSInteger, RTCIceGatheringState) { + RTCIceGatheringStateNew, + RTCIceGatheringStateGathering, + RTCIceGatheringStateComplete, +}; + +/** Represents the stats output level. */ +typedef NS_ENUM(NSInteger, RTCStatsOutputLevel) { + RTCStatsOutputLevelStandard, + RTCStatsOutputLevelDebug, +}; + +@class RTCPeerConnection; + +RTC_EXPORT +@protocol RTCPeerConnectionDelegate <NSObject> + +/** Called when the SignalingState changed. */ +- (void)peerConnection:(RTCPeerConnection *)peerConnection + didChangeSignalingState:(RTCSignalingState)stateChanged; + +/** Called when media is received on a new stream from remote peer. */ +- (void)peerConnection:(RTCPeerConnection *)peerConnection + didAddStream:(RTCMediaStream *)stream; + +/** Called when a remote peer closes a stream. */ +- (void)peerConnection:(RTCPeerConnection *)peerConnection + didRemoveStream:(RTCMediaStream *)stream; + +/** Called when negotiation is needed, for example ICE has restarted. */ +- (void)peerConnectionShouldNegotiate:(RTCPeerConnection *)peerConnection; + +/** Called any time the IceConnectionState changes. */ +- (void)peerConnection:(RTCPeerConnection *)peerConnection + didChangeIceConnectionState:(RTCIceConnectionState)newState; + +/** Called any time the IceGatheringState changes. */ +- (void)peerConnection:(RTCPeerConnection *)peerConnection + didChangeIceGatheringState:(RTCIceGatheringState)newState; + +/** New ice candidate has been found. */ +- (void)peerConnection:(RTCPeerConnection *)peerConnection + didGenerateIceCandidate:(RTCIceCandidate *)candidate; + +/** New data channel has been opened. */ +- (void)peerConnection:(RTCPeerConnection *)peerConnection + didOpenDataChannel:(RTCDataChannel *)dataChannel; + +@end + +RTC_EXPORT +@interface RTCPeerConnection : NSObject + +/** The object that will be notifed about events such as state changes and + * streams being added or removed. + */ +@property(nonatomic, weak, nullable) id<RTCPeerConnectionDelegate> delegate; +@property(nonatomic, readonly) NSArray *localStreams; +@property(nonatomic, readonly, nullable) + RTCSessionDescription *localDescription; +@property(nonatomic, readonly, nullable) + RTCSessionDescription *remoteDescription; +@property(nonatomic, readonly) RTCSignalingState signalingState; +@property(nonatomic, readonly) RTCIceConnectionState iceConnectionState; +@property(nonatomic, readonly) RTCIceGatheringState iceGatheringState; + +/** Gets all RTCRtpSenders associated with this peer connection. + * Note: reading this property returns different instances of RTCRtpSender. + * Use isEqual: instead of == to compare RTCRtpSender instances. + */ +@property(nonatomic, readonly) NSArray<RTCRtpSender *> *senders; + +/** Gets all RTCRtpReceivers associated with this peer connection. + * Note: reading this property returns different instances of RTCRtpReceiver. + * Use isEqual: instead of == to compare RTCRtpReceiver instances. + */ +@property(nonatomic, readonly) NSArray<RTCRtpReceiver *> *receivers; + +- (instancetype)init NS_UNAVAILABLE; + +/** Sets the PeerConnection's global configuration to |configuration|. + * Any changes to STUN/TURN servers or ICE candidate policy will affect the + * next gathering phase, and cause the next call to createOffer to generate + * new ICE credentials. Note that the BUNDLE and RTCP-multiplexing policies + * cannot be changed with this method. + */ +- (BOOL)setConfiguration:(RTCConfiguration *)configuration; + +/** Terminate all media and close the transport. */ +- (void)close; + +/** Provide a remote candidate to the ICE Agent. */ +- (void)addIceCandidate:(RTCIceCandidate *)candidate; + +/** Add a new media stream to be sent on this peer connection. */ +- (void)addStream:(RTCMediaStream *)stream; + +/** Remove the given media stream from this peer connection. */ +- (void)removeStream:(RTCMediaStream *)stream; + +/** Generate an SDP offer. */ +- (void)offerForConstraints:(RTCMediaConstraints *)constraints + completionHandler:(nullable void (^) + (RTCSessionDescription * _Nullable sdp, + NSError * _Nullable error))completionHandler; + +/** Generate an SDP answer. */ +- (void)answerForConstraints:(RTCMediaConstraints *)constraints + completionHandler:(nullable void (^) + (RTCSessionDescription * _Nullable sdp, + NSError * _Nullable error))completionHandler; + +/** Apply the supplied RTCSessionDescription as the local description. */ +- (void)setLocalDescription:(RTCSessionDescription *)sdp + completionHandler: + (nullable void (^)(NSError * _Nullable error))completionHandler; + +/** Apply the supplied RTCSessionDescription as the remote description. */ +- (void)setRemoteDescription:(RTCSessionDescription *)sdp + completionHandler: + (nullable void (^)(NSError * _Nullable error))completionHandler; + +@end + +@interface RTCPeerConnection (Media) + +/** + * Create an RTCRtpSender with the specified kind and media stream ID. + * See RTCMediaStreamTrack.h for available kinds. + */ +- (RTCRtpSender *)senderWithKind:(NSString *)kind streamId:(NSString *)streamId; + +@end + +@interface RTCPeerConnection (DataChannel) + +/** Create a new data channel with the given label and configuration. */ +- (RTCDataChannel *)dataChannelForLabel:(NSString *)label + configuration:(RTCDataChannelConfiguration *)configuration; + +@end + +@interface RTCPeerConnection (Stats) + +/** Gather stats for the given RTCMediaStreamTrack. If |mediaStreamTrack| is nil + * statistics are gathered for all tracks. + */ +- (void)statsForTrack: + (nullable RTCMediaStreamTrack *)mediaStreamTrack + statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel + completionHandler: + (nullable void (^)(NSArray<RTCStatsReport *> *stats))completionHandler; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnectionFactory.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnectionFactory.h new file mode 100644 index 00000000000..f21c107581e --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnectionFactory.h @@ -0,0 +1,58 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +NS_ASSUME_NONNULL_BEGIN + +@class RTCAVFoundationVideoSource; +@class RTCAudioTrack; +@class RTCConfiguration; +@class RTCMediaConstraints; +@class RTCMediaStream; +@class RTCPeerConnection; +@class RTCVideoSource; +@class RTCVideoTrack; +@protocol RTCPeerConnectionDelegate; + +RTC_EXPORT +@interface RTCPeerConnectionFactory : NSObject + +- (instancetype)init NS_DESIGNATED_INITIALIZER; + +/** Initialize an RTCAVFoundationVideoSource with constraints. */ +- (RTCAVFoundationVideoSource *)avFoundationVideoSourceWithConstraints: + (nullable RTCMediaConstraints *)constraints; + +/** Initialize an RTCAudioTrack with an id. */ +- (RTCAudioTrack *)audioTrackWithTrackId:(NSString *)trackId; + +/** Initialize an RTCVideoTrack with a source and an id. */ +- (RTCVideoTrack *)videoTrackWithSource:(RTCVideoSource *)source + trackId:(NSString *)trackId; + +/** Initialize an RTCMediaStream with an id. */ +- (RTCMediaStream *)mediaStreamWithStreamId:(NSString *)streamId; + +/** Initialize an RTCPeerConnection with a configuration, constraints, and + * delegate. + */ +- (RTCPeerConnection *)peerConnectionWithConfiguration: + (RTCConfiguration *)configuration + constraints: + (RTCMediaConstraints *)constraints + delegate: + (nullable id<RTCPeerConnectionDelegate>)delegate; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCRtpCodecParameters.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCRtpCodecParameters.h new file mode 100644 index 00000000000..fef8429803c --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCRtpCodecParameters.h @@ -0,0 +1,58 @@ +/* + * Copyright 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +NS_ASSUME_NONNULL_BEGIN + +RTC_EXTERN const NSString * const kRTCRtxCodecMimeType; +RTC_EXTERN const NSString * const kRTCRedCodecMimeType; +RTC_EXTERN const NSString * const kRTCUlpfecCodecMimeType; +RTC_EXTERN const NSString * const kRTCOpusCodecMimeType; +RTC_EXTERN const NSString * const kRTCIsacCodecMimeType; +RTC_EXTERN const NSString * const kRTCL16CodecMimeType; +RTC_EXTERN const NSString * const kRTCG722CodecMimeType; +RTC_EXTERN const NSString * const kRTCIlbcCodecMimeType; +RTC_EXTERN const NSString * const kRTCPcmuCodecMimeType; +RTC_EXTERN const NSString * const kRTCPcmaCodecMimeType; +RTC_EXTERN const NSString * const kRTCDtmfCodecMimeType; +RTC_EXTERN const NSString * const kRTCComfortNoiseCodecMimeType; +RTC_EXTERN const NSString * const kRTCVp8CodecMimeType; +RTC_EXTERN const NSString * const kRTCVp9CodecMimeType; +RTC_EXTERN const NSString * const kRTCH264CodecMimeType; + +/** Defined in http://w3c.github.io/webrtc-pc/#idl-def-RTCRtpCodecParameters */ +RTC_EXPORT +@interface RTCRtpCodecParameters : NSObject + +/** The RTP payload type. */ +@property(nonatomic, assign) int payloadType; + +/** + * The codec MIME type. Valid types are listed in: + * http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-2 + * + * Several supported types are represented by the constants above. + */ +@property(nonatomic, nonnull) NSString *mimeType; + +/** The codec clock rate expressed in Hertz. */ +@property(nonatomic, assign) int clockRate; + +/** The number of channels (mono=1, stereo=2). */ +@property(nonatomic, assign) int channels; + +- (instancetype)init NS_DESIGNATED_INITIALIZER; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCRtpEncodingParameters.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCRtpEncodingParameters.h new file mode 100644 index 00000000000..65b8deafc08 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCRtpEncodingParameters.h @@ -0,0 +1,32 @@ +/* + * Copyright 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +NS_ASSUME_NONNULL_BEGIN + +RTC_EXPORT +@interface RTCRtpEncodingParameters : NSObject + +/** Controls whether the encoding is currently transmitted. */ +@property(nonatomic, assign) BOOL isActive; + +/** The maximum bitrate to use for the encoding, or nil if there is no + * limit. + */ +@property(nonatomic, copy, nullable) NSNumber *maxBitrateBps; + +- (instancetype)init NS_DESIGNATED_INITIALIZER; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCRtpParameters.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCRtpParameters.h new file mode 100644 index 00000000000..bdebf84884c --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCRtpParameters.h @@ -0,0 +1,32 @@ +/* + * Copyright 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> +#import <WebRTC/RTCRtpCodecParameters.h> +#import <WebRTC/RTCRtpEncodingParameters.h> + +NS_ASSUME_NONNULL_BEGIN + +RTC_EXPORT +@interface RTCRtpParameters : NSObject + +/** The currently active encodings in the order of preference. */ +@property(nonatomic, copy) NSArray<RTCRtpEncodingParameters *> *encodings; + +/** The negotiated set of send codecs in order of preference. */ +@property(nonatomic, copy) NSArray<RTCRtpCodecParameters *> *codecs; + +- (instancetype)init NS_DESIGNATED_INITIALIZER; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCRtpReceiver.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCRtpReceiver.h new file mode 100644 index 00000000000..e98a8f3bea1 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCRtpReceiver.h @@ -0,0 +1,50 @@ +/* + * Copyright 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> +#import <WebRTC/RTCMediaStreamTrack.h> +#import <WebRTC/RTCRtpParameters.h> + +NS_ASSUME_NONNULL_BEGIN + +RTC_EXPORT +@protocol RTCRtpReceiver <NSObject> + +/** A unique identifier for this receiver. */ +@property(nonatomic, readonly) NSString *receiverId; + +/** The currently active RTCRtpParameters, as defined in + * https://www.w3.org/TR/webrtc/#idl-def-RTCRtpParameters. + * + * The WebRTC specification only defines RTCRtpParameters in terms of senders, + * but this API also applies them to receivers, similar to ORTC: + * http://ortc.org/wp-content/uploads/2016/03/ortc.html#rtcrtpparameters*. + */ +@property(nonatomic, readonly) RTCRtpParameters *parameters; + +/** The RTCMediaStreamTrack associated with the receiver. + * Note: reading this property returns a new instance of + * RTCMediaStreamTrack. Use isEqual: instead of == to compare + * RTCMediaStreamTrack instances. + */ +@property(nonatomic, readonly) RTCMediaStreamTrack *track; + +@end + +RTC_EXPORT +@interface RTCRtpReceiver : NSObject <RTCRtpReceiver> + +- (instancetype)init NS_UNAVAILABLE; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCRtpSender.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCRtpSender.h new file mode 100644 index 00000000000..d910c6ceb28 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCRtpSender.h @@ -0,0 +1,46 @@ +/* + * Copyright 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> +#import <WebRTC/RTCMediaStreamTrack.h> +#import <WebRTC/RTCRtpParameters.h> + +NS_ASSUME_NONNULL_BEGIN + +RTC_EXPORT +@protocol RTCRtpSender <NSObject> + +/** A unique identifier for this sender. */ +@property(nonatomic, readonly) NSString *senderId; + +/** The currently active RTCRtpParameters, as defined in + * https://www.w3.org/TR/webrtc/#idl-def-RTCRtpParameters. + */ +@property(nonatomic, copy) RTCRtpParameters *parameters; + +/** The RTCMediaStreamTrack associated with the sender. + * Note: reading this property returns a new instance of + * RTCMediaStreamTrack. Use isEqual: instead of == to compare + * RTCMediaStreamTrack instances. + */ +@property(nonatomic, copy, nullable) RTCMediaStreamTrack *track; + +@end + +RTC_EXPORT +@interface RTCRtpSender : NSObject <RTCRtpSender> + +- (instancetype)init NS_UNAVAILABLE; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCSSLAdapter.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCSSLAdapter.h new file mode 100644 index 00000000000..1341a5c003c --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCSSLAdapter.h @@ -0,0 +1,20 @@ +/* + * Copyright 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +/** + * Initialize and clean up the SSL library. Failure is fatal. These call the + * corresponding functions in webrtc/base/ssladapter.h. + */ +RTC_EXTERN BOOL RTCInitializeSSL(); +RTC_EXTERN BOOL RTCCleanupSSL(); diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCSessionDescription.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCSessionDescription.h new file mode 100644 index 00000000000..41439804a8a --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCSessionDescription.h @@ -0,0 +1,48 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +/** + * Represents the session description type. This exposes the same types that are + * in C++, which doesn't include the rollback type that is in the W3C spec. + */ +typedef NS_ENUM(NSInteger, RTCSdpType) { + RTCSdpTypeOffer, + RTCSdpTypePrAnswer, + RTCSdpTypeAnswer, +}; + +NS_ASSUME_NONNULL_BEGIN + +RTC_EXPORT +@interface RTCSessionDescription : NSObject + +/** The type of session description. */ +@property(nonatomic, readonly) RTCSdpType type; + +/** The SDP string representation of this session description. */ +@property(nonatomic, readonly) NSString *sdp; + +- (instancetype)init NS_UNAVAILABLE; + +/** Initialize a session description with a type and SDP string. */ +- (instancetype)initWithType:(RTCSdpType)type sdp:(NSString *)sdp + NS_DESIGNATED_INITIALIZER; + ++ (NSString *)stringForType:(RTCSdpType)type; + ++ (RTCSdpType)typeForString:(NSString *)string; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCStatsReport.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCStatsReport.h new file mode 100644 index 00000000000..5a559679991 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCStatsReport.h @@ -0,0 +1,37 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +NS_ASSUME_NONNULL_BEGIN + +/** This does not currently conform to the spec. */ +RTC_EXPORT +@interface RTCStatsReport : NSObject + +/** Time since 1970-01-01T00:00:00Z in milliseconds. */ +@property(nonatomic, readonly) CFTimeInterval timestamp; + +/** The type of stats held by this object. */ +@property(nonatomic, readonly) NSString *type; + +/** The identifier for this object. */ +@property(nonatomic, readonly) NSString *reportId; + +/** A dictionary holding the actual stats. */ +@property(nonatomic, readonly) NSDictionary<NSString *, NSString *> *values; + +- (instancetype)init NS_UNAVAILABLE; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCTracing.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCTracing.h new file mode 100644 index 00000000000..136479118b5 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCTracing.h @@ -0,0 +1,21 @@ +/* + * Copyright 2016 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +RTC_EXTERN void RTCSetupInternalTracer(); +/** Starts capture to specified file. Must be a valid writable path. + * Returns YES if capture starts. + */ +RTC_EXTERN BOOL RTCStartInternalCapture(NSString *filePath); +RTC_EXTERN void RTCStopInternalCapture(); +RTC_EXTERN void RTCShutdownInternalTracer(); diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCVideoFrame.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCVideoFrame.h new file mode 100644 index 00000000000..efb666e4bf2 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCVideoFrame.h @@ -0,0 +1,52 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <AVFoundation/AVFoundation.h> +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +NS_ASSUME_NONNULL_BEGIN + +// RTCVideoFrame is an ObjectiveC version of cricket::VideoFrame. +RTC_EXPORT +@interface RTCVideoFrame : NSObject + +/** Width without rotation applied. */ +@property(nonatomic, readonly) size_t width; + +/** Height without rotation applied. */ +@property(nonatomic, readonly) size_t height; +@property(nonatomic, readonly) size_t chromaWidth; +@property(nonatomic, readonly) size_t chromaHeight; +// These can return NULL if the object is not backed by a buffer. +@property(nonatomic, readonly, nullable) const uint8_t *yPlane; +@property(nonatomic, readonly, nullable) const uint8_t *uPlane; +@property(nonatomic, readonly, nullable) const uint8_t *vPlane; +@property(nonatomic, readonly) int32_t yPitch; +@property(nonatomic, readonly) int32_t uPitch; +@property(nonatomic, readonly) int32_t vPitch; + +/** Timestamp in nanoseconds. */ +@property(nonatomic, readonly) int64_t timeStamp; + +/** The native handle should be a pixel buffer on iOS. */ +@property(nonatomic, readonly) CVPixelBufferRef nativeHandle; + +- (instancetype)init NS_UNAVAILABLE; + +/** If the frame is backed by a CVPixelBuffer, creates a backing i420 frame. + * Calling the yuv plane properties will call this method if needed. + */ +- (void)convertBufferIfNeeded; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCVideoRenderer.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCVideoRenderer.h new file mode 100644 index 00000000000..5e2e820918a --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCVideoRenderer.h @@ -0,0 +1,33 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> +#if TARGET_OS_IPHONE +#import <UIKit/UIKit.h> +#endif + +#import <WebRTC/RTCMacros.h> + +NS_ASSUME_NONNULL_BEGIN + +@class RTCVideoFrame; + +RTC_EXPORT +@protocol RTCVideoRenderer <NSObject> + +/** The size of the frame. */ +- (void)setSize:(CGSize)size; + +/** The frame to be displayed. */ +- (void)renderFrame:(nullable RTCVideoFrame *)frame; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCVideoSource.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCVideoSource.h new file mode 100644 index 00000000000..e234c3e0896 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCVideoSource.h @@ -0,0 +1,34 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#import <WebRTC/RTCMacros.h> + +typedef NS_ENUM(NSInteger, RTCSourceState) { + RTCSourceStateInitializing, + RTCSourceStateLive, + RTCSourceStateEnded, + RTCSourceStateMuted, +}; + +NS_ASSUME_NONNULL_BEGIN + +RTC_EXPORT +@interface RTCVideoSource : NSObject + +/** The current state of the RTCVideoSource. */ +@property(nonatomic, readonly) RTCSourceState state; + +- (instancetype)init NS_UNAVAILABLE; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCVideoTrack.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCVideoTrack.h new file mode 100644 index 00000000000..899d7c34780 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCVideoTrack.h @@ -0,0 +1,37 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <WebRTC/RTCMediaStreamTrack.h> + +#import <WebRTC/RTCMacros.h> + +NS_ASSUME_NONNULL_BEGIN + +@protocol RTCVideoRenderer; +@class RTCPeerConnectionFactory; +@class RTCVideoSource; + +RTC_EXPORT +@interface RTCVideoTrack : RTCMediaStreamTrack + +/** The video source for this video track. */ +@property(nonatomic, readonly) RTCVideoSource *source; + +- (instancetype)init NS_UNAVAILABLE; + +/** Register a renderer that will render all frames received on this track. */ +- (void)addRenderer:(id<RTCVideoRenderer>)renderer; + +/** Deregister a renderer. */ +- (void)removeRenderer:(id<RTCVideoRenderer>)renderer; + +@end + +NS_ASSUME_NONNULL_END diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/WebRTC.h b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/WebRTC.h new file mode 100644 index 00000000000..bf08a0d3478 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/WebRTC.h @@ -0,0 +1,42 @@ +/* + * Copyright 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <WebRTC/RTCAVFoundationVideoSource.h> +#import <WebRTC/RTCAudioTrack.h> +#import <WebRTC/RTCCameraPreviewView.h> +#import <WebRTC/RTCConfiguration.h> +#import <WebRTC/RTCDataChannel.h> +#import <WebRTC/RTCDataChannelConfiguration.h> +#import <WebRTC/RTCDispatcher.h> +#import <WebRTC/RTCEAGLVideoView.h> +#import <WebRTC/RTCFieldTrials.h> +#import <WebRTC/RTCFileLogger.h> +#import <WebRTC/RTCIceCandidate.h> +#import <WebRTC/RTCIceServer.h> +#import <WebRTC/RTCLogging.h> +#import <WebRTC/RTCMacros.h> +#import <WebRTC/RTCMediaConstraints.h> +#import <WebRTC/RTCMediaStream.h> +#import <WebRTC/RTCMediaStreamTrack.h> +#import <WebRTC/RTCPeerConnection.h> +#import <WebRTC/RTCPeerConnectionFactory.h> +#import <WebRTC/RTCRtpCodecParameters.h> +#import <WebRTC/RTCRtpEncodingParameters.h> +#import <WebRTC/RTCRtpParameters.h> +#import <WebRTC/RTCRtpReceiver.h> +#import <WebRTC/RTCRtpSender.h> +#import <WebRTC/RTCSSLAdapter.h> +#import <WebRTC/RTCSessionDescription.h> +#import <WebRTC/RTCStatsReport.h> +#import <WebRTC/RTCTracing.h> +#import <WebRTC/RTCVideoFrame.h> +#import <WebRTC/RTCVideoRenderer.h> +#import <WebRTC/RTCVideoSource.h> +#import <WebRTC/RTCVideoTrack.h> diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Info.plist b/chromium/third_party/webrtc/sdk/objc/Framework/Info.plist new file mode 100644 index 00000000000..38c437e7fed --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Info.plist @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleDevelopmentRegion</key> + <string>en</string> + <key>CFBundleExecutable</key> + <string>WebRTC</string> + <key>CFBundleIdentifier</key> + <string>org.webrtc.WebRTC</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundleName</key> + <string>WebRTC</string> + <key>CFBundlePackageType</key> + <string>FMWK</string> + <key>CFBundleShortVersionString</key> + <string>1.0</string> + <key>CFBundleSignature</key> + <string>????</string> + <key>CFBundleVersion</key> + <string>1.0</string> + <key>NSPrincipalClass</key> + <string></string> +</dict> +</plist> diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/Modules/module.modulemap b/chromium/third_party/webrtc/sdk/objc/Framework/Modules/module.modulemap new file mode 100644 index 00000000000..cd485a4e81e --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/Modules/module.modulemap @@ -0,0 +1,6 @@ +framework module WebRTC { + umbrella header "WebRTC.h" + + export * + module * { export * } +} diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/UnitTests/RTCConfigurationTest.mm b/chromium/third_party/webrtc/sdk/objc/Framework/UnitTests/RTCConfigurationTest.mm new file mode 100644 index 00000000000..f565adbefd0 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/UnitTests/RTCConfigurationTest.mm @@ -0,0 +1,78 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#include <vector> + +#include "webrtc/base/gunit.h" + +#import "NSString+StdString.h" +#import "RTCConfiguration+Private.h" +#import "WebRTC/RTCConfiguration.h" +#import "WebRTC/RTCIceServer.h" + +@interface RTCConfigurationTest : NSObject +- (void)testConversionToNativeConfiguration; +@end + +@implementation RTCConfigurationTest + +- (void)testConversionToNativeConfiguration { + NSArray *urlStrings = @[ @"stun:stun1.example.net" ]; + RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:urlStrings]; + + RTCConfiguration *config = [[RTCConfiguration alloc] init]; + config.iceServers = @[ server ]; + config.iceTransportPolicy = RTCIceTransportPolicyRelay; + config.bundlePolicy = RTCBundlePolicyMaxBundle; + config.rtcpMuxPolicy = RTCRtcpMuxPolicyNegotiate; + config.tcpCandidatePolicy = RTCTcpCandidatePolicyDisabled; + const int maxPackets = 60; + const int timeout = 1; + const int interval = 2; + config.audioJitterBufferMaxPackets = maxPackets; + config.iceConnectionReceivingTimeout = timeout; + config.iceBackupCandidatePairPingInterval = interval; + config.continualGatheringPolicy = + RTCContinualGatheringPolicyGatherContinually; + + std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> + nativeConfig([config createNativeConfiguration]); + EXPECT_TRUE(nativeConfig.get()); + EXPECT_EQ(1u, nativeConfig->servers.size()); + webrtc::PeerConnectionInterface::IceServer nativeServer = + nativeConfig->servers.front(); + EXPECT_EQ(1u, nativeServer.urls.size()); + EXPECT_EQ("stun:stun1.example.net", nativeServer.urls.front()); + + EXPECT_EQ(webrtc::PeerConnectionInterface::kRelay, nativeConfig->type); + EXPECT_EQ(webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle, + nativeConfig->bundle_policy); + EXPECT_EQ(webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate, + nativeConfig->rtcp_mux_policy); + EXPECT_EQ(webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled, + nativeConfig->tcp_candidate_policy); + EXPECT_EQ(maxPackets, nativeConfig->audio_jitter_buffer_max_packets); + EXPECT_EQ(timeout, nativeConfig->ice_connection_receiving_timeout); + EXPECT_EQ(interval, nativeConfig->ice_backup_candidate_pair_ping_interval); + EXPECT_EQ(webrtc::PeerConnectionInterface::GATHER_CONTINUALLY, + nativeConfig->continual_gathering_policy); +} + +@end + +TEST(RTCConfigurationTest, NativeConfigurationConversionTest) { + @autoreleasepool { + RTCConfigurationTest *test = [[RTCConfigurationTest alloc] init]; + [test testConversionToNativeConfiguration]; + } +} + diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/UnitTests/RTCDataChannelConfigurationTest.mm b/chromium/third_party/webrtc/sdk/objc/Framework/UnitTests/RTCDataChannelConfigurationTest.mm new file mode 100644 index 00000000000..275898dba85 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/UnitTests/RTCDataChannelConfigurationTest.mm @@ -0,0 +1,59 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#include "webrtc/base/gunit.h" + +#import "NSString+StdString.h" +#import "RTCDataChannelConfiguration+Private.h" +#import "WebRTC/RTCDataChannelConfiguration.h" + +@interface RTCDataChannelConfigurationTest : NSObject +- (void)testConversionToNativeDataChannelInit; +@end + +@implementation RTCDataChannelConfigurationTest + +- (void)testConversionToNativeDataChannelInit { + BOOL isOrdered = NO; + int maxPacketLifeTime = 5; + int maxRetransmits = 4; + BOOL isNegotiated = YES; + int channelId = 4; + NSString *protocol = @"protocol"; + + RTCDataChannelConfiguration *dataChannelConfig = + [[RTCDataChannelConfiguration alloc] init]; + dataChannelConfig.isOrdered = isOrdered; + dataChannelConfig.maxPacketLifeTime = maxPacketLifeTime; + dataChannelConfig.maxRetransmits = maxRetransmits; + dataChannelConfig.isNegotiated = isNegotiated; + dataChannelConfig.channelId = channelId; + dataChannelConfig.protocol = protocol; + + webrtc::DataChannelInit nativeInit = dataChannelConfig.nativeDataChannelInit; + EXPECT_EQ(isOrdered, nativeInit.ordered); + EXPECT_EQ(maxPacketLifeTime, nativeInit.maxRetransmitTime); + EXPECT_EQ(maxRetransmits, nativeInit.maxRetransmits); + EXPECT_EQ(isNegotiated, nativeInit.negotiated); + EXPECT_EQ(channelId, nativeInit.id); + EXPECT_EQ(protocol.stdString, nativeInit.protocol); +} + +@end + +TEST(RTCDataChannelConfiguration, NativeDataChannelInitConversionTest) { + @autoreleasepool { + RTCDataChannelConfigurationTest *test = + [[RTCDataChannelConfigurationTest alloc] init]; + [test testConversionToNativeDataChannelInit]; + } +} diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/UnitTests/RTCIceCandidateTest.mm b/chromium/third_party/webrtc/sdk/objc/Framework/UnitTests/RTCIceCandidateTest.mm new file mode 100644 index 00000000000..20a9d739a96 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/UnitTests/RTCIceCandidateTest.mm @@ -0,0 +1,76 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#include <memory> + +#include "webrtc/base/gunit.h" + +#import "NSString+StdString.h" +#import "RTCIceCandidate+Private.h" +#import "WebRTC/RTCIceCandidate.h" + +@interface RTCIceCandidateTest : NSObject +- (void)testCandidate; +- (void)testInitFromNativeCandidate; +@end + +@implementation RTCIceCandidateTest + +- (void)testCandidate { + NSString *sdp = @"candidate:4025901590 1 udp 2122265343 " + "fdff:2642:12a6:fe38:c001:beda:fcf9:51aa " + "59052 typ host generation 0"; + + RTCIceCandidate *candidate = [[RTCIceCandidate alloc] initWithSdp:sdp + sdpMLineIndex:0 + sdpMid:@"audio"]; + + std::unique_ptr<webrtc::IceCandidateInterface> nativeCandidate = + candidate.nativeCandidate; + EXPECT_EQ("audio", nativeCandidate->sdp_mid()); + EXPECT_EQ(0, nativeCandidate->sdp_mline_index()); + + std::string sdpString; + nativeCandidate->ToString(&sdpString); + EXPECT_EQ(sdp.stdString, sdpString); +} + +- (void)testInitFromNativeCandidate { + std::string sdp("candidate:4025901590 1 udp 2122265343 " + "fdff:2642:12a6:fe38:c001:beda:fcf9:51aa " + "59052 typ host generation 0"); + webrtc::IceCandidateInterface *nativeCandidate = + webrtc::CreateIceCandidate("audio", 0, sdp, nullptr); + + RTCIceCandidate *iceCandidate = + [[RTCIceCandidate alloc] initWithNativeCandidate:nativeCandidate]; + EXPECT_TRUE([@"audio" isEqualToString:iceCandidate.sdpMid]); + EXPECT_EQ(0, iceCandidate.sdpMLineIndex); + + EXPECT_EQ(sdp, iceCandidate.sdp.stdString); +} + +@end + +TEST(RTCIceCandidateTest, CandidateTest) { + @autoreleasepool { + RTCIceCandidateTest *test = [[RTCIceCandidateTest alloc] init]; + [test testCandidate]; + } +} + +TEST(RTCIceCandidateTest, InitFromCandidateTest) { + @autoreleasepool { + RTCIceCandidateTest *test = [[RTCIceCandidateTest alloc] init]; + [test testInitFromNativeCandidate]; + } +} diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/UnitTests/RTCIceServerTest.mm b/chromium/third_party/webrtc/sdk/objc/Framework/UnitTests/RTCIceServerTest.mm new file mode 100644 index 00000000000..a5159dcaad3 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/UnitTests/RTCIceServerTest.mm @@ -0,0 +1,108 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#include <vector> + +#include "webrtc/base/gunit.h" + +#import "NSString+StdString.h" +#import "RTCIceServer+Private.h" +#import "WebRTC/RTCIceServer.h" + +@interface RTCIceServerTest : NSObject +- (void)testOneURLServer; +- (void)testTwoURLServer; +- (void)testPasswordCredential; +- (void)testInitFromNativeServer; +@end + +@implementation RTCIceServerTest + +- (void)testOneURLServer { + RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:@[ + @"stun:stun1.example.net" ]]; + + webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer; + EXPECT_EQ(1u, iceStruct.urls.size()); + EXPECT_EQ("stun:stun1.example.net", iceStruct.urls.front()); + EXPECT_EQ("", iceStruct.username); + EXPECT_EQ("", iceStruct.password); +} + +- (void)testTwoURLServer { + RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:@[ + @"turn1:turn1.example.net", @"turn2:turn2.example.net" ]]; + + webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer; + EXPECT_EQ(2u, iceStruct.urls.size()); + EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front()); + EXPECT_EQ("turn2:turn2.example.net", iceStruct.urls.back()); + EXPECT_EQ("", iceStruct.username); + EXPECT_EQ("", iceStruct.password); +} + +- (void)testPasswordCredential { + RTCIceServer *server = [[RTCIceServer alloc] + initWithURLStrings:@[ @"turn1:turn1.example.net" ] + username:@"username" + credential:@"credential"]; + webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer; + EXPECT_EQ(1u, iceStruct.urls.size()); + EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front()); + EXPECT_EQ("username", iceStruct.username); + EXPECT_EQ("credential", iceStruct.password); +} + +- (void)testInitFromNativeServer { + webrtc::PeerConnectionInterface::IceServer nativeServer; + nativeServer.username = "username"; + nativeServer.password = "password"; + nativeServer.urls.push_back("stun:stun.example.net"); + + RTCIceServer *iceServer = + [[RTCIceServer alloc] initWithNativeServer:nativeServer]; + EXPECT_EQ(1u, iceServer.urlStrings.count); + EXPECT_EQ("stun:stun.example.net", + [NSString stdStringForString:iceServer.urlStrings.firstObject]); + EXPECT_EQ("username", [NSString stdStringForString:iceServer.username]); + EXPECT_EQ("password", [NSString stdStringForString:iceServer.credential]); +} + +@end + +TEST(RTCIceServerTest, OneURLTest) { + @autoreleasepool { + RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; + [test testOneURLServer]; + } +} + +TEST(RTCIceServerTest, TwoURLTest) { + @autoreleasepool { + RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; + [test testTwoURLServer]; + } +} + +TEST(RTCIceServerTest, PasswordCredentialTest) { + @autoreleasepool { + RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; + [test testPasswordCredential]; + } +} + +TEST(RTCIceServerTest, InitFromNativeServerTest) { + @autoreleasepool { + RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; + [test testInitFromNativeServer]; + } +} diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/UnitTests/RTCMediaConstraintsTest.mm b/chromium/third_party/webrtc/sdk/objc/Framework/UnitTests/RTCMediaConstraintsTest.mm new file mode 100644 index 00000000000..3413dfc039a --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/UnitTests/RTCMediaConstraintsTest.mm @@ -0,0 +1,68 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#include <memory> + +#include "webrtc/base/gunit.h" + +#import "NSString+StdString.h" +#import "RTCMediaConstraints+Private.h" +#import "WebRTC/RTCMediaConstraints.h" + +@interface RTCMediaConstraintsTest : NSObject +- (void)testMediaConstraints; +@end + +@implementation RTCMediaConstraintsTest + +- (void)testMediaConstraints { + NSDictionary *mandatory = @{@"key1": @"value1", @"key2": @"value2"}; + NSDictionary *optional = @{@"key3": @"value3", @"key4": @"value4"}; + + RTCMediaConstraints *constraints = [[RTCMediaConstraints alloc] + initWithMandatoryConstraints:mandatory + optionalConstraints:optional]; + std::unique_ptr<webrtc::MediaConstraints> nativeConstraints = + [constraints nativeConstraints]; + + webrtc::MediaConstraintsInterface::Constraints nativeMandatory = + nativeConstraints->GetMandatory(); + [self expectConstraints:mandatory inNativeConstraints:nativeMandatory]; + + webrtc::MediaConstraintsInterface::Constraints nativeOptional = + nativeConstraints->GetOptional(); + [self expectConstraints:optional inNativeConstraints:nativeOptional]; +} + +- (void)expectConstraints:(NSDictionary *)constraints + inNativeConstraints: + (webrtc::MediaConstraintsInterface::Constraints)nativeConstraints { + EXPECT_EQ(constraints.count, nativeConstraints.size()); + + for (NSString *key in constraints) { + NSString *value = [constraints objectForKey:key]; + + std::string nativeValue; + bool found = nativeConstraints.FindFirst(key.stdString, &nativeValue); + EXPECT_TRUE(found); + EXPECT_EQ(value.stdString, nativeValue); + } +} + +@end + +TEST(RTCMediaConstraintsTest, MediaConstraintsTest) { + @autoreleasepool { + RTCMediaConstraintsTest *test = [[RTCMediaConstraintsTest alloc] init]; + [test testMediaConstraints]; + } +} diff --git a/chromium/third_party/webrtc/sdk/objc/Framework/UnitTests/RTCSessionDescriptionTest.mm b/chromium/third_party/webrtc/sdk/objc/Framework/UnitTests/RTCSessionDescriptionTest.mm new file mode 100644 index 00000000000..90f4698b301 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/Framework/UnitTests/RTCSessionDescriptionTest.mm @@ -0,0 +1,144 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> + +#include "webrtc/base/gunit.h" + +#import "NSString+StdString.h" +#import "RTCSessionDescription+Private.h" +#import "WebRTC/RTCSessionDescription.h" + +@interface RTCSessionDescriptionTest : NSObject +- (void)testSessionDescriptionConversion; +- (void)testInitFromNativeSessionDescription; +@end + +@implementation RTCSessionDescriptionTest + +/** + * Test conversion of an Objective-C RTCSessionDescription to a native + * SessionDescriptionInterface (based on the types and SDP strings being equal). + */ +- (void)testSessionDescriptionConversion { + RTCSessionDescription *description = + [[RTCSessionDescription alloc] initWithType:RTCSdpTypeAnswer + sdp:[self sdp]]; + + webrtc::SessionDescriptionInterface *nativeDescription = + description.nativeDescription; + + EXPECT_EQ(RTCSdpTypeAnswer, + [RTCSessionDescription typeForStdString:nativeDescription->type()]); + + std::string sdp; + nativeDescription->ToString(&sdp); + EXPECT_EQ([self sdp].stdString, sdp); +} + +- (void)testInitFromNativeSessionDescription { + webrtc::SessionDescriptionInterface *nativeDescription; + + nativeDescription = webrtc::CreateSessionDescription( + webrtc::SessionDescriptionInterface::kAnswer, + [self sdp].stdString, + nullptr); + + RTCSessionDescription *description = + [[RTCSessionDescription alloc] initWithNativeDescription: + nativeDescription]; + EXPECT_EQ(webrtc::SessionDescriptionInterface::kAnswer, + [RTCSessionDescription stdStringForType:description.type]); + EXPECT_TRUE([[self sdp] isEqualToString:description.sdp]); +} + +- (NSString *)sdp { + return @"v=0\r\n" + "o=- 5319989746393411314 2 IN IP4 127.0.0.1\r\n" + "s=-\r\n" + "t=0 0\r\n" + "a=group:BUNDLE audio video\r\n" + "a=msid-semantic: WMS ARDAMS\r\n" + "m=audio 9 UDP/TLS/RTP/SAVPF 111 103 9 0 8 126\r\n" + "c=IN IP4 0.0.0.0\r\n" + "a=rtcp:9 IN IP4 0.0.0.0\r\n" + "a=ice-ufrag:f3o+0HG7l9nwIWFY\r\n" + "a=ice-pwd:VDctmJNCptR2TB7+meDpw7w5\r\n" + "a=fingerprint:sha-256 A9:D5:8D:A8:69:22:39:60:92:AD:94:1A:22:2D:5E:" + "A5:4A:A9:18:C2:35:5D:46:5E:59:BD:1C:AF:38:9F:E6:E1\r\n" + "a=setup:active\r\n" + "a=mid:audio\r\n" + "a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\n" + "a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/" + "abs-send-time\r\n" + "a=sendrecv\r\n" + "a=rtcp-mux\r\n" + "a=rtpmap:111 opus/48000/2\r\n" + "a=fmtp:111 minptime=10;useinbandfec=1\r\n" + "a=rtpmap:103 ISAC/16000\r\n" + "a=rtpmap:9 G722/8000\r\n" + "a=rtpmap:0 PCMU/8000\r\n" + "a=rtpmap:8 PCMA/8000\r\n" + "a=rtpmap:126 telephone-event/8000\r\n" + "a=maxptime:60\r\n" + "a=ssrc:1504474588 cname:V+FdIC5AJpxLhdYQ\r\n" + "a=ssrc:1504474588 msid:ARDAMS ARDAMSa0\r\n" + "a=ssrc:1504474588 mslabel:ARDAMS\r\n" + "a=ssrc:1504474588 label:ARDAMSa0\r\n" + "m=video 9 UDP/TLS/RTP/SAVPF 100 116 117 96\r\n" + "c=IN IP4 0.0.0.0\r\n" + "a=rtcp:9 IN IP4 0.0.0.0\r\n" + "a=ice-ufrag:f3o+0HG7l9nwIWFY\r\n" + "a=ice-pwd:VDctmJNCptR2TB7+meDpw7w5\r\n" + "a=fingerprint:sha-256 A9:D5:8D:A8:69:22:39:60:92:AD:94:1A:22:2D:5E:" + "A5:4A:A9:18:C2:35:5D:46:5E:59:BD:1C:AF:38:9F:E6:E1\r\n" + "a=setup:active\r\n" + "a=mid:video\r\n" + "a=extmap:2 urn:ietf:params:rtp-hdrext:toffset\r\n" + "a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/" + "abs-send-time\r\n" + "a=extmap:4 urn:3gpp:video-orientation\r\n" + "a=sendrecv\r\n" + "a=rtcp-mux\r\n" + "a=rtpmap:100 VP8/90000\r\n" + "a=rtcp-fb:100 ccm fir\r\n" + "a=rtcp-fb:100 nack\r\n" + "a=rtcp-fb:100 nack pli\r\n" + "a=rtcp-fb:100 goog-remb\r\n" + "a=rtpmap:116 red/90000\r\n" + "a=rtpmap:117 ulpfec/90000\r\n" + "a=rtpmap:96 rtx/90000\r\n" + "a=fmtp:96 apt=100\r\n" + "a=ssrc-group:FID 498297514 1644357692\r\n" + "a=ssrc:498297514 cname:V+FdIC5AJpxLhdYQ\r\n" + "a=ssrc:498297514 msid:ARDAMS ARDAMSv0\r\n" + "a=ssrc:498297514 mslabel:ARDAMS\r\n" + "a=ssrc:498297514 label:ARDAMSv0\r\n" + "a=ssrc:1644357692 cname:V+FdIC5AJpxLhdYQ\r\n" + "a=ssrc:1644357692 msid:ARDAMS ARDAMSv0\r\n" + "a=ssrc:1644357692 mslabel:ARDAMS\r\n" + "a=ssrc:1644357692 label:ARDAMSv0\r\n"; +} + +@end + +TEST(RTCSessionDescriptionTest, SessionDescriptionConversionTest) { + @autoreleasepool { + RTCSessionDescriptionTest *test = [[RTCSessionDescriptionTest alloc] init]; + [test testSessionDescriptionConversion]; + } +} + +TEST(RTCSessionDescriptionTest, InitFromSessionDescriptionTest) { + @autoreleasepool { + RTCSessionDescriptionTest *test = [[RTCSessionDescriptionTest alloc] init]; + [test testInitFromNativeSessionDescription]; + } +} diff --git a/chromium/third_party/webrtc/sdk/objc/WebRTC-Prefix.pch b/chromium/third_party/webrtc/sdk/objc/WebRTC-Prefix.pch new file mode 100644 index 00000000000..c56cb48ab87 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/WebRTC-Prefix.pch @@ -0,0 +1,36 @@ +/* + * Copyright 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifdef __OBJC__ + +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + +#if !defined(__has_feature) || !__has_feature(nullability) +#error "This file requires nullability support." +#endif + +#import <Foundation/Foundation.h> + +// The following nonnull macros were introduced in OSX SDK 10.10.3. However, +// the bots appear to be running something older. We define them here if they +// aren't already defined in NSObjCRuntime.h, which is included by +// Foundation/Foundation.h. + +#if !defined(NS_ASSUME_NONNULL_BEGIN) +#define NS_ASSUME_NONNULL_BEGIN +#endif + +#if !defined(NS_ASSUME_NONNULL_END) +#define NS_ASSUME_NONNULL_END +#endif + +#endif // __OBJC__ diff --git a/chromium/third_party/webrtc/sdk/objc/WebRTC.podspec b/chromium/third_party/webrtc/sdk/objc/WebRTC.podspec new file mode 100644 index 00000000000..37ab166b0c5 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/objc/WebRTC.podspec @@ -0,0 +1,18 @@ +Pod::Spec.new do |s| + s.name = "WebRTC" + s.version = "${FRAMEWORK_VERSION_NUMBER}" + s.summary = "WebRTC SDK for iOS" + s.description = <<-DESC + WebRTC is a free, open project that provides browsers and mobile + applications with Real-Time Communications (RTC) capabilities via simple + APIs. + DESC + s.homepage = "http://webrtc.org/" + s.license = { :type => "BSD", :file => "LICENSE" } + s.author = "Google Inc." + + s.platform = :ios, "8.0" + + s.public_header_files = "WebRTC.framework/Headers/**/*.h" + s.vendored_frameworks = "WebRTC.framework" +end diff --git a/chromium/third_party/webrtc/sdk/sdk.gyp b/chromium/third_party/webrtc/sdk/sdk.gyp new file mode 100644 index 00000000000..5bfbb249ea6 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/sdk.gyp @@ -0,0 +1,274 @@ +# Copyright 2016 The WebRTC project authors. All Rights Reserved. +# +# Use of this source code is governed by a BSD-style license +# that can be found in the LICENSE file in the root of the source +# tree. An additional intellectual property rights grant can be found +# in the file PATENTS. All contributing project authors may +# be found in the AUTHORS file in the root of the source tree. + +{ + 'includes': [ + '../build/common.gypi', + 'sdk.gypi', + ], + 'conditions': [ + ['OS=="ios" or (OS=="mac" and mac_deployment_target=="10.7")', { + 'targets': [ + { + 'target_name': 'rtc_sdk_common_objc', + 'type': 'static_library', + 'includes': [ '../build/objc_common.gypi' ], + 'dependencies': [ + '../base/base.gyp:rtc_base', + ], + 'include_dirs': [ + 'objc/Framework/Classes', + 'objc/Framework/Headers', + ], + 'direct_dependent_settings': { + 'include_dirs': [ + 'objc/Framework/Classes', + 'objc/Framework/Headers', + ], + }, + 'sources': [ + 'objc/Framework/Classes/NSString+StdString.h', + 'objc/Framework/Classes/NSString+StdString.mm', + 'objc/Framework/Classes/RTCDispatcher.m', + 'objc/Framework/Classes/RTCFieldTrials.mm', + 'objc/Framework/Classes/RTCLogging.mm', + 'objc/Framework/Classes/RTCSSLAdapter.mm', + 'objc/Framework/Classes/RTCTracing.mm', + 'objc/Framework/Headers/WebRTC/RTCDispatcher.h', + 'objc/Framework/Headers/WebRTC/RTCFieldTrials.h', + 'objc/Framework/Headers/WebRTC/RTCLogging.h', + 'objc/Framework/Headers/WebRTC/RTCMacros.h', + 'objc/Framework/Headers/WebRTC/RTCSSLAdapter.h', + 'objc/Framework/Headers/WebRTC/RTCTracing.h', + ], + 'conditions': [ + ['OS=="ios"', { + 'sources': [ + 'objc/Framework/Classes/RTCCameraPreviewView.m', + 'objc/Framework/Classes/RTCUIApplication.h', + 'objc/Framework/Classes/RTCUIApplication.mm', + 'objc/Framework/Headers/WebRTC/RTCCameraPreviewView.h', + ], + 'link_settings': { + 'xcode_settings': { + 'OTHER_LDFLAGS': [ + '-framework AVFoundation', + ], + }, + }, + }], # OS=="ios" + ['build_with_chromium==0', { + 'sources': [ + 'objc/Framework/Classes/RTCFileLogger.mm', + 'objc/Framework/Headers/WebRTC/RTCFileLogger.h', + ], + }], + ], + }, + { + 'target_name': 'rtc_sdk_peerconnection_objc', + 'type': 'static_library', + 'includes': [ '../build/objc_common.gypi' ], + 'dependencies': [ + '<(webrtc_root)/api/api.gyp:libjingle_peerconnection', + 'rtc_sdk_common_objc', + ], + 'include_dirs': [ + 'objc/Framework/Classes', + 'objc/Framework/Headers', + ], + 'direct_dependent_settings': { + 'include_dirs': [ + 'objc/Framework/Classes', + 'objc/Framework/Headers', + ], + }, + 'link_settings': { + 'libraries': [ + '-lstdc++', + ], + }, # link_settings + 'sources': [ + 'objc/Framework/Classes/RTCAudioTrack+Private.h', + 'objc/Framework/Classes/RTCAudioTrack.mm', + 'objc/Framework/Classes/RTCConfiguration+Private.h', + 'objc/Framework/Classes/RTCConfiguration.mm', + 'objc/Framework/Classes/RTCDataChannel+Private.h', + 'objc/Framework/Classes/RTCDataChannel.mm', + 'objc/Framework/Classes/RTCDataChannelConfiguration+Private.h', + 'objc/Framework/Classes/RTCDataChannelConfiguration.mm', + 'objc/Framework/Classes/RTCIceCandidate+Private.h', + 'objc/Framework/Classes/RTCIceCandidate.mm', + 'objc/Framework/Classes/RTCIceServer+Private.h', + 'objc/Framework/Classes/RTCIceServer.mm', + 'objc/Framework/Classes/RTCMediaConstraints+Private.h', + 'objc/Framework/Classes/RTCMediaConstraints.mm', + 'objc/Framework/Classes/RTCMediaStream+Private.h', + 'objc/Framework/Classes/RTCMediaStream.mm', + 'objc/Framework/Classes/RTCMediaStreamTrack+Private.h', + 'objc/Framework/Classes/RTCMediaStreamTrack.mm', + 'objc/Framework/Classes/RTCOpenGLVideoRenderer.h', + 'objc/Framework/Classes/RTCOpenGLVideoRenderer.mm', + 'objc/Framework/Classes/RTCPeerConnection+DataChannel.mm', + 'objc/Framework/Classes/RTCPeerConnection+Private.h', + 'objc/Framework/Classes/RTCPeerConnection+Stats.mm', + 'objc/Framework/Classes/RTCPeerConnection.mm', + 'objc/Framework/Classes/RTCPeerConnectionFactory+Private.h', + 'objc/Framework/Classes/RTCPeerConnectionFactory.mm', + 'objc/Framework/Classes/RTCRtpCodecParameters+Private.h', + 'objc/Framework/Classes/RTCRtpCodecParameters.mm', + 'objc/Framework/Classes/RTCRtpEncodingParameters+Private.h', + 'objc/Framework/Classes/RTCRtpEncodingParameters.mm', + 'objc/Framework/Classes/RTCRtpParameters+Private.h', + 'objc/Framework/Classes/RTCRtpParameters.mm', + 'objc/Framework/Classes/RTCRtpReceiver+Private.h', + 'objc/Framework/Classes/RTCRtpReceiver.mm', + 'objc/Framework/Classes/RTCRtpSender+Private.h', + 'objc/Framework/Classes/RTCRtpSender.mm', + 'objc/Framework/Classes/RTCSessionDescription+Private.h', + 'objc/Framework/Classes/RTCSessionDescription.mm', + 'objc/Framework/Classes/RTCStatsReport+Private.h', + 'objc/Framework/Classes/RTCStatsReport.mm', + 'objc/Framework/Classes/RTCVideoFrame+Private.h', + 'objc/Framework/Classes/RTCVideoFrame.mm', + 'objc/Framework/Classes/RTCVideoRendererAdapter+Private.h', + 'objc/Framework/Classes/RTCVideoRendererAdapter.h', + 'objc/Framework/Classes/RTCVideoRendererAdapter.mm', + 'objc/Framework/Classes/RTCVideoSource+Private.h', + 'objc/Framework/Classes/RTCVideoSource.mm', + 'objc/Framework/Classes/RTCVideoTrack+Private.h', + 'objc/Framework/Classes/RTCVideoTrack.mm', + 'objc/Framework/Headers/WebRTC/RTCAudioTrack.h', + 'objc/Framework/Headers/WebRTC/RTCConfiguration.h', + 'objc/Framework/Headers/WebRTC/RTCDataChannel.h', + 'objc/Framework/Headers/WebRTC/RTCDataChannelConfiguration.h', + 'objc/Framework/Headers/WebRTC/RTCIceCandidate.h', + 'objc/Framework/Headers/WebRTC/RTCIceServer.h', + 'objc/Framework/Headers/WebRTC/RTCMediaConstraints.h', + 'objc/Framework/Headers/WebRTC/RTCMediaStream.h', + 'objc/Framework/Headers/WebRTC/RTCMediaStreamTrack.h', + 'objc/Framework/Headers/WebRTC/RTCPeerConnection.h', + 'objc/Framework/Headers/WebRTC/RTCPeerConnectionFactory.h', + 'objc/Framework/Headers/WebRTC/RTCRtpCodecParameters.h', + 'objc/Framework/Headers/WebRTC/RTCRtpEncodingParameters.h', + 'objc/Framework/Headers/WebRTC/RTCRtpParameters.h', + 'objc/Framework/Headers/WebRTC/RTCRtpReceiver.h', + 'objc/Framework/Headers/WebRTC/RTCRtpSender.h', + 'objc/Framework/Headers/WebRTC/RTCSessionDescription.h', + 'objc/Framework/Headers/WebRTC/RTCStatsReport.h', + 'objc/Framework/Headers/WebRTC/RTCVideoFrame.h', + 'objc/Framework/Headers/WebRTC/RTCVideoRenderer.h', + 'objc/Framework/Headers/WebRTC/RTCVideoSource.h', + 'objc/Framework/Headers/WebRTC/RTCVideoTrack.h', + ], # sources + 'conditions': [ + ['OS=="ios"', { + 'sources': [ + 'objc/Framework/Classes/RTCAVFoundationVideoSource+Private.h', + 'objc/Framework/Classes/RTCAVFoundationVideoSource.mm', + 'objc/Framework/Classes/RTCEAGLVideoView.m', + 'objc/Framework/Classes/avfoundationvideocapturer.h', + 'objc/Framework/Classes/avfoundationvideocapturer.mm', + 'objc/Framework/Headers/WebRTC/RTCAVFoundationVideoSource.h', + 'objc/Framework/Headers/WebRTC/RTCEAGLVideoView.h', + ], + 'link_settings': { + 'xcode_settings': { + 'OTHER_LDFLAGS': [ + '-framework CoreGraphics', + '-framework GLKit', + '-framework OpenGLES', + '-framework QuartzCore', + ], + }, + }, # link_settings + }], # OS=="ios" + ['OS=="mac"', { + 'sources': [ + 'objc/Framework/Classes/RTCNSGLVideoView.m', + 'objc/Framework/Headers/WebRTC/RTCNSGLVideoView.h', + ], + 'link_settings': { + 'xcode_settings': { + 'OTHER_LDFLAGS': [ + '-framework OpenGL', + ], + }, + }, + }], + ], # conditions + }, # rtc_sdk_peerconnection_objc + { + 'target_name': 'rtc_sdk_framework_objc', + 'type': 'shared_library', + 'product_name': 'WebRTC', + 'mac_bundle': 1, + 'includes': [ '../build/objc_common.gypi' ], + # Slightly hacky, but we need to re-declare files here that are C + # interfaces because otherwise they will be dead-stripped during + # linking (ObjC classes cannot be dead-stripped). We might consider + # just only using ObjC interfaces. + 'sources': [ + 'objc/Framework/Classes/RTCFieldTrials.mm', + 'objc/Framework/Classes/RTCLogging.mm', + 'objc/Framework/Classes/RTCSSLAdapter.mm', + 'objc/Framework/Classes/RTCTracing.mm', + 'objc/Framework/Headers/WebRTC/RTCFieldTrials.h', + 'objc/Framework/Headers/WebRTC/RTCLogging.h', + 'objc/Framework/Headers/WebRTC/RTCSSLAdapter.h', + 'objc/Framework/Headers/WebRTC/RTCTracing.h', + 'objc/Framework/Headers/WebRTC/WebRTC.h', + 'objc/Framework/Modules/module.modulemap', + ], + 'mac_framework_headers': [ + '<!@(find -E objc/Framework/Headers -regex ".*(h)")', + ], + 'dependencies': [ + '<(webrtc_root)/system_wrappers/system_wrappers.gyp:field_trial_default', + 'rtc_sdk_peerconnection_objc', + ], + 'xcode_settings': { + 'CODE_SIGNING_REQUIRED': 'NO', + 'CODE_SIGN_IDENTITY': '', + 'DEFINES_MODULE': 'YES', + 'INFOPLIST_FILE': 'objc/Framework/Info.plist', + 'LD_DYLIB_INSTALL_NAME': '@rpath/WebRTC.framework/WebRTC', + 'MODULEMAP_FILE': '<(webrtc_root)/sdk/Framework/Modules/module.modulemap', + }, + 'link_settings': { + 'xcode_settings': { + 'OTHER_LDFLAGS': [ + '-framework AVFoundation', + '-framework AudioToolbox', + '-framework CoreGraphics', + '-framework CoreMedia', + '-framework GLKit', + '-framework VideoToolbox', + ], + }, + }, # link_settings + 'conditions': [ + # TODO(tkchin): Generate WebRTC.h based off of + # mac_framework_headers instead of hard-coding. Ok for now since we + # only really care about dynamic lib on iOS outside of chromium. + ['OS!="mac"', { + 'mac_framework_headers!': [ + 'objc/Framework/Headers/WebRTC/RTCNSGLVideoView.h', + ], + }], + ['build_with_chromium==1', { + 'mac_framework_headers!': [ + 'objc/Framework/Headers/WebRTC/RTCFileLogger.h', + ], + }], + ], # conditions + }, # rtc_sdk_framework_objc + ], # targets + }], # OS=="ios" or (OS=="mac" and mac_deployment_target=="10.7") + ], +} diff --git a/chromium/third_party/webrtc/sdk/sdk.gypi b/chromium/third_party/webrtc/sdk/sdk.gypi new file mode 100644 index 00000000000..8f8ee97a9d2 --- /dev/null +++ b/chromium/third_party/webrtc/sdk/sdk.gypi @@ -0,0 +1,26 @@ +# Copyright 2016 The WebRTC project authors. All Rights Reserved. +# +# Use of this source code is governed by a BSD-style license +# that can be found in the LICENSE file in the root of the source +# tree. An additional intellectual property rights grant can be found +# in the file PATENTS. All contributing project authors may +# be found in the AUTHORS file in the root of the source tree. + +{ + 'target_defaults': { + 'configurations': { + 'Profile': { + 'xcode_settings': { + 'DEBUG_INFORMARTION_FORMAT': 'dwarf-with-dsym', + # We manually strip using strip -S and strip -x. We need to run + # dsymutil ourselves so we need symbols around before that. + 'DEPLOYMENT_POSTPROCESSING': 'NO', + 'GCC_OPTIMIZATION_LEVEL': 's', + 'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', + 'STRIP_INSTALLED_PRODUCT': 'NO', + 'USE_HEADERMAP': 'YES', + }, + }, + }, + }, +} diff --git a/chromium/third_party/webrtc/sdk/sdk_tests.gyp b/chromium/third_party/webrtc/sdk/sdk_tests.gyp new file mode 100644 index 00000000000..70e8e7b901f --- /dev/null +++ b/chromium/third_party/webrtc/sdk/sdk_tests.gyp @@ -0,0 +1,42 @@ +# Copyright 2016 The WebRTC project authors. All Rights Reserved. +# +# Use of this source code is governed by a BSD-style license +# that can be found in the LICENSE file in the root of the source +# tree. An additional intellectual property rights grant can be found +# in the file PATENTS. All contributing project authors may +# be found in the AUTHORS file in the root of the source tree. + +{ + 'includes': [ '../build/common.gypi', ], + 'conditions': [ + ['OS=="ios" or (OS=="mac" and mac_deployment_target=="10.7")', { + 'targets': [ + { + 'target_name': 'rtc_sdk_peerconnection_objc_tests', + 'type': 'executable', + 'includes': [ + '../build/objc_common.gypi', + ], + 'dependencies': [ + '<(webrtc_root)/base/base_tests.gyp:rtc_base_tests_utils', + '<(webrtc_root)/sdk/sdk.gyp:rtc_sdk_peerconnection_objc', + ], + 'sources': [ + 'objc/Framework/UnitTests/RTCConfigurationTest.mm', + 'objc/Framework/UnitTests/RTCDataChannelConfigurationTest.mm', + 'objc/Framework/UnitTests/RTCIceCandidateTest.mm', + 'objc/Framework/UnitTests/RTCIceServerTest.mm', + 'objc/Framework/UnitTests/RTCMediaConstraintsTest.mm', + 'objc/Framework/UnitTests/RTCSessionDescriptionTest.mm', + ], + 'xcode_settings': { + # |-ObjC| flag needed to make sure category method implementations + # are included: + # https://developer.apple.com/library/mac/qa/qa1490/_index.html + 'OTHER_LDFLAGS': ['-ObjC'], + }, + }, + ], + }], # OS=="ios" or (OS=="mac" and mac_deployment_target=="10.7") + ], +} |