Tweaks for new Objective-C API.

BUG=

Review URL: https://codereview.webrtc.org/1696673003

Cr-Commit-Position: refs/heads/master@{#11872}
This commit is contained in:
hjon 2016-03-04 07:09:09 -08:00 committed by Commit bot
parent 78417cf7c0
commit a2f7798ec2
22 changed files with 97 additions and 48 deletions

View File

@ -192,6 +192,13 @@
'objc/RTCVideoTrack.h',
'objc/RTCVideoTrack.mm',
],
# TODO(hjon): Make this compile without linking to libstdc++
# See https://bugs.chromium.org/p/webrtc/issues/detail?id=5593
'link_settings': {
'libraries': [
'-lstdc++',
],
},
'conditions': [
['OS=="ios"', {
'sources': [

View File

@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface RTCAVFoundationVideoSource : RTCVideoSource
- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
constraints:(RTCMediaConstraints *)constraints;
constraints:(nullable RTCMediaConstraints *)constraints;
/** Switches the camera being used (either front or back). */
@property(nonatomic, assign) BOOL useBackCamera;

View File

@ -70,7 +70,7 @@
webrtc::PeerConnectionInterface::RTCConfiguration nativeConfig;
for (RTCIceServer *iceServer in _iceServers) {
nativeConfig.servers.push_back(iceServer.iceServer);
nativeConfig.servers.push_back(iceServer.nativeServer);
}
nativeConfig.type =
[[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy];

View File

@ -93,7 +93,7 @@ typedef NS_ENUM(NSInteger, RTCDataChannelState) {
@property(nonatomic, readonly) BOOL isNegotiated;
/** The identifier for this data channel. */
@property(nonatomic, readonly) int id;
@property(nonatomic, readonly) int channelId;
/** The state of the data channel. */
@property(nonatomic, readonly) RTCDataChannelState readyState;

View File

@ -123,7 +123,7 @@ class DataChannelDelegateAdapter : public DataChannelObserver {
return _nativDataChannel->negotiated();
}
- (int)id {
- (int)channelId {
return _nativDataChannel->id();
}
@ -161,7 +161,7 @@ class DataChannelDelegateAdapter : public DataChannelObserver {
- (NSString *)description {
return [NSString stringWithFormat:@"RTCDataChannel:\n%ld\n%@\n%@",
(long)self.id,
(long)self.channelId,
self.label,
[[self class]
stringForState:self.readyState]];

View File

@ -15,24 +15,24 @@ NS_ASSUME_NONNULL_BEGIN
@interface RTCDataChannelConfiguration : NSObject
/** Set to YES if ordered delivery is required. */
@property(nonatomic) BOOL isOrdered;
@property(nonatomic, assign) BOOL isOrdered;
/**
* Max period in milliseconds in which retransmissions will be sent. After this
* time, no more retransmissions will be sent. -1 if unset.
*/
@property(nonatomic) int maxPacketLifeTime;
@property(nonatomic, assign) int maxPacketLifeTime;
/** The max number of retransmissions. -1 if unset. */
@property(nonatomic) int maxRetransmits;
@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) BOOL isNegotiated;
@property(nonatomic, assign) BOOL isNegotiated;
/** The stream id, or SID, for SCTP data channels. -1 if unset. */
@property(nonatomic) int streamId;
@property(nonatomic, assign) int streamId;
/** Set by the application and opaque to the WebRTC implementation. */
@property(nonatomic) NSString *protocol;

View File

@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
* This is needed to pass to the underlying C++ APIs.
*/
@property(nonatomic, readonly)
webrtc::PeerConnectionInterface::IceServer iceServer;
webrtc::PeerConnectionInterface::IceServer nativeServer;
/** Initialize an RTCIceServer from a native IceServer. */
- (instancetype)initWithNativeServer:

View File

@ -16,14 +16,14 @@ NS_ASSUME_NONNULL_BEGIN
@interface RTCIceServer : NSObject
/** URI(s) for this server represented as NSStrings. */
@property(nonatomic, copy, readonly, nonnull) NSArray *urlStrings;
// @property(nonatomic, copy, readonly) NSArray<NSString *> *urlStrings;
@property(nonatomic, readonly, nonnull) NSArray *urlStrings;
// @property(nonatomic, readonly) NSArray<NSString *> *urlStrings;
/** Username to use if this RTCIceServer object is a TURN server. */
@property(nonatomic, copy, readonly, nullable) NSString *username;
@property(nonatomic, readonly, nullable) NSString *username;
/** Credential to use if this RTCIceServer object is a TURN server. */
@property(nonatomic, copy, readonly, nullable) NSString *credential;
@property(nonatomic, readonly, nullable) NSString *credential;
- (nonnull instancetype)init NS_UNAVAILABLE;

View File

@ -50,7 +50,7 @@
#pragma mark - Private
- (webrtc::PeerConnectionInterface::IceServer)iceServer {
- (webrtc::PeerConnectionInterface::IceServer)nativeServer {
__block webrtc::PeerConnectionInterface::IceServer iceServer;
iceServer.username = [NSString stdStringForString:_username];

View File

@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
// TODO(hjon): Update nullability types. See http://crbug/webrtc/5592
@class RTCAudioTrack;
@class RTCPeerConnectionFactory;
@class RTCVideoTrack;
@interface RTCMediaStream : NSObject
@ -31,6 +32,10 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)init NS_UNAVAILABLE;
/** Initialize an RTCMediaStream with an id. */
- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
streamId:(NSString *)streamId;
/** Adds the given audio track to this media stream. */
- (void)addAudioTrack:(RTCAudioTrack *)audioTrack;

View File

@ -15,6 +15,7 @@
#import "webrtc/api/objc/RTCAudioTrack+Private.h"
#import "webrtc/api/objc/RTCMediaStream+Private.h"
#import "webrtc/api/objc/RTCMediaStreamTrack+Private.h"
#import "webrtc/api/objc/RTCPeerConnectionFactory+Private.h"
#import "webrtc/api/objc/RTCVideoTrack+Private.h"
#import "webrtc/base/objc/NSString+StdString.h"
@ -26,6 +27,16 @@
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 *)audioTracks {
// - (NSArray<RTCAudioTrack *> *)audioTracks {
return [_audioTracks copy];

View File

@ -35,7 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, readonly) NSString *trackId;
/** The enabled state of the track. */
@property(nonatomic) BOOL isEnabled;
@property(nonatomic, assign) BOOL isEnabled;
/** The state of the track. */
@property(nonatomic, readonly) RTCMediaStreamTrackState readyState;

View File

@ -181,7 +181,7 @@ typedef NS_ENUM(NSInteger, RTCStatsOutputLevel) {
* statistics are gathered for all tracks.
*/
- (void)statsForTrack:
(nonnull RTCMediaStreamTrack *)mediaStreamTrack
(nullable RTCMediaStreamTrack *)mediaStreamTrack
statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel
completionHandler:
(nullable void (^)(NSArray * _Nonnull stats))completionHandler;

View File

@ -199,11 +199,11 @@ void PeerConnectionDelegateAdapter::OnIceCandidate(
_observer.reset(new webrtc::PeerConnectionDelegateAdapter(self));
webrtc::PeerConnectionInterface::RTCConfiguration config =
configuration.nativeConfiguration;
webrtc::MediaConstraints *nativeConstraints =
constraints.nativeConstraints.get();
rtc::scoped_ptr<webrtc::MediaConstraints> nativeConstraints =
constraints.nativeConstraints;
_peerConnection =
factory.nativeFactory->CreatePeerConnection(config,
nativeConstraints,
nativeConstraints.get(),
nullptr,
nullptr,
_observer.get());
@ -259,7 +259,7 @@ void PeerConnectionDelegateAdapter::OnIceCandidate(
}
- (void)addStream:(RTCMediaStream *)stream {
if (_peerConnection->AddStream(stream.nativeMediaStream)) {
if (!_peerConnection->AddStream(stream.nativeMediaStream)) {
RTCLogError(@"Failed to add stream: %@", stream);
return;
}

View File

@ -32,9 +32,9 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithNativeDescription:
(const webrtc::SessionDescriptionInterface *)nativeDescription;
+ (std::string)stringForType:(RTCSdpType)type;
+ (std::string)stdStringForType:(RTCSdpType)type;
+ (RTCSdpType)typeForString:(const std::string &)string;
+ (RTCSdpType)typeForStdString:(const std::string &)string;
@end

View File

@ -36,6 +36,10 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithType:(RTCSdpType)type sdp:(NSString *)sdp
NS_DESIGNATED_INITIALIZER;
+ (NSString *)stringForType:(RTCSdpType)type;
+ (RTCSdpType)typeForString:(NSString *)string;
@end
NS_ASSUME_NONNULL_END

View File

@ -21,6 +21,16 @@
@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]) {
@ -31,8 +41,8 @@
}
- (NSString *)description {
return [NSString stringWithFormat:@"RTCSessionDescription:\n%s\n%@",
[[self class] stringForType:_type].c_str(),
return [NSString stringWithFormat:@"RTCSessionDescription:\n%@\n%@",
[[self class] stringForType:_type],
_sdp];
}
@ -42,7 +52,7 @@
webrtc::SdpParseError error;
webrtc::SessionDescriptionInterface *description =
webrtc::CreateSessionDescription([[self class] stringForType:_type],
webrtc::CreateSessionDescription([[self class] stdStringForType:_type],
_sdp.stdString,
&error);
@ -60,13 +70,13 @@
NSParameterAssert(nativeDescription);
std::string sdp;
nativeDescription->ToString(&sdp);
RTCSdpType type = [[self class] typeForString:nativeDescription->type()];
RTCSdpType type = [[self class] typeForStdString:nativeDescription->type()];
return [self initWithType:type
sdp:[NSString stringForStdString:sdp]];
}
+ (std::string)stringForType:(RTCSdpType)type {
+ (std::string)stdStringForType:(RTCSdpType)type {
switch (type) {
case RTCSdpTypeOffer:
return webrtc::SessionDescriptionInterface::kOffer;
@ -77,7 +87,7 @@
}
}
+ (RTCSdpType)typeForString:(const std::string &)string {
+ (RTCSdpType)typeForStdString:(const std::string &)string {
if (string == webrtc::SessionDescriptionInterface::kOffer) {
return RTCSdpTypeOffer;
} else if (string == webrtc::SessionDescriptionInterface::kPrAnswer) {

View File

@ -23,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)setSize:(CGSize)size;
/** The frame to be displayed. */
- (void)renderFrame:(RTCVideoFrame *)frame;
- (void)renderFrame:(nullable RTCVideoFrame *)frame;
@end

View File

@ -33,21 +33,19 @@
rtc::scoped_refptr<webrtc::VideoTrackInterface> track =
factory.nativeFactory->CreateVideoTrack(nativeId,
source.nativeVideoSource);
return [self initWithNativeTrack:track type:RTCMediaStreamTrackTypeVideo];
if ([self initWithNativeTrack:track type:RTCMediaStreamTrackTypeVideo]) {
_source = source;
}
return self;
}
- (instancetype)initWithNativeMediaTrack:
- (instancetype)initWithNativeTrack:
(rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeMediaTrack
type:(RTCMediaStreamTrackType)type {
type:(RTCMediaStreamTrackType)type {
NSParameterAssert(nativeMediaTrack);
NSParameterAssert(type == RTCMediaStreamTrackTypeVideo);
if (self = [super initWithNativeTrack:nativeMediaTrack type:type]) {
_adapters = [NSMutableArray array];
rtc::scoped_refptr<webrtc::VideoSourceInterface> source =
self.nativeVideoTrack->GetSource();
if (source) {
_source = [[RTCVideoSource alloc] initWithNativeVideoSource:source.get()];
}
}
return self;
}
@ -58,6 +56,17 @@
}
}
- (RTCVideoSource *)source {
if (!_source) {
rtc::scoped_refptr<webrtc::VideoSourceInterface> 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) {
@ -74,7 +83,6 @@
}
- (void)removeRenderer:(id<RTCVideoRenderer>)renderer {
RTCVideoRendererAdapter *adapter;
__block NSUInteger indexToRemove = NSNotFound;
[_adapters enumerateObjectsUsingBlock:^(RTCVideoRendererAdapter *adapter,
NSUInteger idx,
@ -87,7 +95,9 @@
if (indexToRemove == NSNotFound) {
return;
}
self.nativeVideoTrack->RemoveRenderer(adapter.nativeVideoRenderer);
RTCVideoRendererAdapter *adapterToRemove =
[_adapters objectAtIndex:indexToRemove];
self.nativeVideoTrack->RemoveRenderer(adapterToRemove.nativeVideoRenderer);
[_adapters removeObjectAtIndex:indexToRemove];
}

View File

@ -31,7 +31,7 @@
RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:@[
@"stun:stun1.example.net" ]];
webrtc::PeerConnectionInterface::IceServer iceStruct = server.iceServer;
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);
@ -42,7 +42,7 @@
RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:@[
@"turn1:turn1.example.net", @"turn2:turn2.example.net" ]];
webrtc::PeerConnectionInterface::IceServer iceStruct = server.iceServer;
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());
@ -55,7 +55,7 @@
initWithURLStrings:@[ @"turn1:turn1.example.net" ]
username:@"username"
credential:@"credential"];
webrtc::PeerConnectionInterface::IceServer iceStruct = server.iceServer;
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);

View File

@ -36,7 +36,7 @@
description.nativeDescription;
EXPECT_EQ(RTCSdpTypeAnswer,
[RTCSessionDescription typeForString:nativeDescription->type()]);
[RTCSessionDescription typeForStdString:nativeDescription->type()]);
std::string sdp;
nativeDescription->ToString(&sdp);
@ -55,7 +55,7 @@
[[RTCSessionDescription alloc] initWithNativeDescription:
nativeDescription];
EXPECT_EQ(webrtc::SessionDescriptionInterface::kAnswer,
[RTCSessionDescription stringForType:description.type]);
[RTCSessionDescription stdStringForType:description.type]);
EXPECT_TRUE([[self sdp] isEqualToString:description.sdp]);
}

View File

@ -10,9 +10,11 @@
#import <Foundation/Foundation.h>
#import "webrtc/base/objc/RTCMacros.h"
/**
* Initialize and clean up the SSL library. Failure is fatal. These call the
* corresponding functions in webrtc/base/ssladapter.h.
*/
BOOL RTCInitializeSSL();
BOOL RTCCleanupSSL();
RTC_EXPORT BOOL RTCInitializeSSL();
RTC_EXPORT BOOL RTCCleanupSSL();