Update API for Objective-C RTCMediaStream.
BUG= R=tkchin@webrtc.org Review URL: https://codereview.webrtc.org/1558733002 . Patch from Jon Hjelle <hjon@andyet.net>. Cr-Commit-Position: refs/heads/master@{#11351}
This commit is contained in:
parent
ca91e38a3a
commit
2bf9a5f11b
@ -29,15 +29,18 @@ if (is_ios) {
|
||||
]
|
||||
sources = [
|
||||
# Add these when there's a BUILD.gn for peer connection APIs
|
||||
#"objc/RTCAudioTrack+Private.h",
|
||||
#"objc/RTCAudioTrack.h",
|
||||
#"objc/RTCAudioTrack.mm",s
|
||||
#"objc/RTCAVFoundationVideoSource+Private.h",
|
||||
#"objc/RTCAVFoundationVideoSource.h",
|
||||
#"objc/RTCAVFoundationVideoSource.mm",
|
||||
#"objc/RTCAudioTrack+Private.h",
|
||||
#"objc/RTCAudioTrack.h",
|
||||
#"objc/RTCAudioTrack.mm",
|
||||
#"objc/RTCIceCandidate+Private.h",
|
||||
#"objc/RTCIceCandidate.h",
|
||||
#"objc/RTCIceCandidate.mm",
|
||||
#"objc/RTCMediaStream+Private.h",
|
||||
#"objc/RTCMediaStream.h",
|
||||
#"objc/RTCMediaStream.mm",
|
||||
#"objc/RTCMediaStreamTrack+Private.h",
|
||||
#"objc/RTCMediaStreamTrack.h",
|
||||
#"objc/RTCMediaStreamTrack.mm",
|
||||
|
||||
@ -19,12 +19,12 @@
|
||||
'../../talk/libjingle.gyp:libjingle_peerconnection',
|
||||
],
|
||||
'sources': [
|
||||
'objc/RTCAudioTrack+Private.h',
|
||||
'objc/RTCAudioTrack.h',
|
||||
'objc/RTCAudioTrack.mm',
|
||||
'objc/RTCAVFoundationVideoSource+Private.h',
|
||||
'objc/RTCAVFoundationVideoSource.h',
|
||||
'objc/RTCAVFoundationVideoSource.mm',
|
||||
'objc/RTCAudioTrack+Private.h',
|
||||
'objc/RTCAudioTrack.h',
|
||||
'objc/RTCAudioTrack.mm',
|
||||
'objc/RTCIceCandidate+Private.h',
|
||||
'objc/RTCIceCandidate.h',
|
||||
'objc/RTCIceCandidate.mm',
|
||||
@ -34,6 +34,9 @@
|
||||
'objc/RTCMediaConstraints+Private.h',
|
||||
'objc/RTCMediaConstraints.h',
|
||||
'objc/RTCMediaConstraints.mm',
|
||||
'objc/RTCMediaStream+Private.h',
|
||||
'objc/RTCMediaStream.h',
|
||||
'objc/RTCMediaStream.mm',
|
||||
'objc/RTCMediaStreamTrack+Private.h',
|
||||
'objc/RTCMediaStreamTrack.h',
|
||||
'objc/RTCMediaStreamTrack.mm',
|
||||
|
||||
32
webrtc/api/objc/RTCMediaStream+Private.h
Normal file
32
webrtc/api/objc/RTCMediaStream+Private.h
Normal file
@ -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 "RTCMediaStream.h"
|
||||
|
||||
#include "talk/app/webrtc/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 from a native MediaStreamInterface. */
|
||||
- (instancetype)initWithNativeMediaStream:
|
||||
(rtc::scoped_refptr<webrtc::MediaStreamInterface>)nativeMediaStream;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
45
webrtc/api/objc/RTCMediaStream.h
Normal file
45
webrtc/api/objc/RTCMediaStream.h
Normal file
@ -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>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class RTCAudioTrack;
|
||||
@class RTCVideoTrack;
|
||||
|
||||
@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
|
||||
112
webrtc/api/objc/RTCMediaStream.mm
Normal file
112
webrtc/api/objc/RTCMediaStream.mm
Normal file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#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/RTCVideoTrack+Private.h"
|
||||
#import "webrtc/base/objc/NSString+StdString.h"
|
||||
|
||||
@implementation RTCMediaStream {
|
||||
NSMutableArray *_audioTracks;
|
||||
NSMutableArray *_videoTracks;
|
||||
rtc::scoped_refptr<webrtc::MediaStreamInterface> _nativeMediaStream;
|
||||
}
|
||||
|
||||
- (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
|
||||
Loading…
x
Reference in New Issue
Block a user