OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #import "RTCMediaStream.h" | |
12 | |
13 #include <vector> | |
14 | |
15 #import "webrtc/api/objc/RTCAudioTrack+Private.h" | |
16 #import "webrtc/api/objc/RTCMediaStream+Private.h" | |
17 #import "webrtc/api/objc/RTCMediaStreamTrack+Private.h" | |
18 #import "webrtc/api/objc/RTCVideoTrack+Private.h" | |
19 #import "webrtc/base/objc/NSString+StdString.h" | |
20 | |
21 @implementation RTCMediaStream { | |
22 NSMutableArray* _audioTracks; | |
tkchin_webrtc
2016/01/21 23:51:53
space *
rest of file too
hjon
2016/01/21 23:56:22
Done.
| |
23 NSMutableArray* _videoTracks; | |
24 rtc::scoped_refptr<webrtc::MediaStreamInterface> _mediaStream; | |
tkchin_webrtc
2016/01/21 23:51:53
_nativeMediaStream
hjon
2016/01/21 23:56:22
Done.
| |
25 } | |
26 | |
27 - (NSArray<RTCAudioTrack *> *)audioTracks { | |
28 return [_audioTracks copy]; | |
29 } | |
30 | |
31 - (NSArray<RTCVideoTrack *> *)videoTracks { | |
32 return [_videoTracks copy]; | |
33 } | |
34 | |
35 - (NSString *)streamId { | |
36 return [NSString stringForStdString:_mediaStream->label()]; | |
37 } | |
38 | |
39 - (void)addAudioTrack:(RTCAudioTrack *)audioTrack { | |
40 if (_mediaStream->AddTrack(audioTrack.nativeAudioTrack)) { | |
41 [_audioTracks addObject:audioTrack]; | |
42 } | |
43 } | |
44 | |
45 - (void)addVideoTrack:(RTCVideoTrack *)videoTrack { | |
46 if (_mediaStream->AddTrack(videoTrack.nativeVideoTrack)) { | |
47 [_videoTracks addObject:videoTrack]; | |
48 } | |
49 } | |
50 | |
51 - (void)removeAudioTrack:(RTCAudioTrack *)audioTrack { | |
52 NSUInteger index = [_audioTracks indexOfObjectIdenticalTo:audioTrack]; | |
53 NSAssert(index != NSNotFound, | |
54 @"|removeAudioTrack| called on unexpected RTCAudioTrack"); | |
55 if (index != NSNotFound && | |
56 _mediaStream->RemoveTrack(audioTrack.nativeAudioTrack)) { | |
57 [_audioTracks removeObjectAtIndex:index]; | |
58 } | |
59 } | |
60 | |
61 - (void)removeVideoTrack:(RTCVideoTrack *)videoTrack { | |
62 NSUInteger index = [_videoTracks indexOfObjectIdenticalTo:videoTrack]; | |
63 NSAssert(index != NSNotFound, | |
64 @"|removeVideoTrack| called on unexpected RTCVideoTrack"); | |
65 if (index != NSNotFound && | |
66 _mediaStream->RemoveTrack(videoTrack.nativeVideoTrack)) { | |
67 [_videoTracks removeObjectAtIndex:index]; | |
68 } | |
69 } | |
70 | |
71 - (NSString *)description { | |
72 return [NSString stringWithFormat:@"RTCMediaStream:\n%@\nA=%lu\nV=%lu", | |
73 self.streamId, | |
74 (unsigned long)self.audioTracks.count, | |
75 (unsigned long)self.videoTracks.count]; | |
76 } | |
77 | |
78 #pragma mark - Private | |
79 | |
80 - (rtc::scoped_refptr<webrtc::MediaStreamInterface>)nativeMediaStream { | |
81 return _mediaStream; | |
82 } | |
83 | |
84 - (instancetype)initWithNativeStream: | |
85 (rtc::scoped_refptr<webrtc::MediaStreamInterface>)nativeMediaStream { | |
86 NSParameterAssert(nativeMediaStream); | |
87 if (self = [super init]) { | |
88 webrtc::AudioTrackVector audioTracks = nativeMediaStream->GetAudioTracks(); | |
89 webrtc::VideoTrackVector videoTracks = nativeMediaStream->GetVideoTracks(); | |
90 | |
91 _audioTracks = [NSMutableArray arrayWithCapacity:audioTracks.size()]; | |
92 _videoTracks = [NSMutableArray arrayWithCapacity:videoTracks.size()]; | |
93 _mediaStream = nativeMediaStream; | |
94 | |
95 for ( auto &track : audioTracks ) { | |
tkchin_webrtc
2016/01/21 23:51:53
remove spaces
(auto ... tracks) {
hjon
2016/01/21 23:56:22
Done.
| |
96 RTCAudioTrack *audioTrack = | |
97 [[RTCAudioTrack alloc] initWithNativeMediaTrack:track | |
98 type:RTCMediaStreamTrackTypeAudio]; | |
tkchin_webrtc
2016/01/21 23:51:53
align :
hjon
2016/01/21 23:56:22
Done.
| |
99 [_audioTracks addObject:audioTrack]; | |
100 } | |
101 | |
102 for ( auto &track : videoTracks ) { | |
tkchin_webrtc
2016/01/21 23:51:53
ditto
hjon
2016/01/21 23:56:22
Done.
| |
103 RTCVideoTrack *videoTrack = | |
104 [[RTCVideoTrack alloc] initWithNativeMediaTrack:track | |
105 type:RTCMediaStreamTrackTypeVideo]; | |
106 [_videoTracks addObject:videoTrack]; | |
107 } | |
108 } | |
109 return self; | |
110 } | |
111 | |
112 @end | |
OLD | NEW |