Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCMediaStream.mm

Issue 2890513002: Revert of Split iOS sdk in to separate targets (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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+Private.h"
12
13 #include <vector>
14
15 #import "NSString+StdString.h"
16 #import "RTCAudioTrack+Private.h"
17 #import "RTCMediaStreamTrack+Private.h"
18 #import "RTCPeerConnectionFactory+Private.h"
19 #import "RTCVideoTrack+Private.h"
20
21 @implementation RTCMediaStream {
22 NSMutableArray *_audioTracks;
23 NSMutableArray *_videoTracks;
24 rtc::scoped_refptr<webrtc::MediaStreamInterface> _nativeMediaStream;
25 }
26
27 - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
28 streamId:(NSString *)streamId {
29 NSParameterAssert(factory);
30 NSParameterAssert(streamId.length);
31 std::string nativeId = [NSString stdStringForString:streamId];
32 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream =
33 factory.nativeFactory->CreateLocalMediaStream(nativeId);
34 return [self initWithNativeMediaStream:stream];
35 }
36
37 - (NSArray<RTCAudioTrack *> *)audioTracks {
38 return [_audioTracks copy];
39 }
40
41 - (NSArray<RTCVideoTrack *> *)videoTracks {
42 return [_videoTracks copy];
43 }
44
45 - (NSString *)streamId {
46 return [NSString stringForStdString:_nativeMediaStream->label()];
47 }
48
49 - (void)addAudioTrack:(RTCAudioTrack *)audioTrack {
50 if (_nativeMediaStream->AddTrack(audioTrack.nativeAudioTrack)) {
51 [_audioTracks addObject:audioTrack];
52 }
53 }
54
55 - (void)addVideoTrack:(RTCVideoTrack *)videoTrack {
56 if (_nativeMediaStream->AddTrack(videoTrack.nativeVideoTrack)) {
57 [_videoTracks addObject:videoTrack];
58 }
59 }
60
61 - (void)removeAudioTrack:(RTCAudioTrack *)audioTrack {
62 NSUInteger index = [_audioTracks indexOfObjectIdenticalTo:audioTrack];
63 NSAssert(index != NSNotFound,
64 @"|removeAudioTrack| called on unexpected RTCAudioTrack");
65 if (index != NSNotFound &&
66 _nativeMediaStream->RemoveTrack(audioTrack.nativeAudioTrack)) {
67 [_audioTracks removeObjectAtIndex:index];
68 }
69 }
70
71 - (void)removeVideoTrack:(RTCVideoTrack *)videoTrack {
72 NSUInteger index = [_videoTracks indexOfObjectIdenticalTo:videoTrack];
73 NSAssert(index != NSNotFound,
74 @"|removeVideoTrack| called on unexpected RTCVideoTrack");
75 if (index != NSNotFound &&
76 _nativeMediaStream->RemoveTrack(videoTrack.nativeVideoTrack)) {
77 [_videoTracks removeObjectAtIndex:index];
78 }
79 }
80
81 - (NSString *)description {
82 return [NSString stringWithFormat:@"RTCMediaStream:\n%@\nA=%lu\nV=%lu",
83 self.streamId,
84 (unsigned long)self.audioTracks.count,
85 (unsigned long)self.videoTracks.count];
86 }
87
88 #pragma mark - Private
89
90 - (rtc::scoped_refptr<webrtc::MediaStreamInterface>)nativeMediaStream {
91 return _nativeMediaStream;
92 }
93
94 - (instancetype)initWithNativeMediaStream:
95 (rtc::scoped_refptr<webrtc::MediaStreamInterface>)nativeMediaStream {
96 NSParameterAssert(nativeMediaStream);
97 if (self = [super init]) {
98 webrtc::AudioTrackVector audioTracks = nativeMediaStream->GetAudioTracks();
99 webrtc::VideoTrackVector videoTracks = nativeMediaStream->GetVideoTracks();
100
101 _audioTracks = [NSMutableArray arrayWithCapacity:audioTracks.size()];
102 _videoTracks = [NSMutableArray arrayWithCapacity:videoTracks.size()];
103 _nativeMediaStream = nativeMediaStream;
104
105 for (auto &track : audioTracks) {
106 RTCMediaStreamTrackType type = RTCMediaStreamTrackTypeAudio;
107 RTCAudioTrack *audioTrack =
108 [[RTCAudioTrack alloc] initWithNativeTrack:track type:type];
109 [_audioTracks addObject:audioTrack];
110 }
111
112 for (auto &track : videoTracks) {
113 RTCMediaStreamTrackType type = RTCMediaStreamTrackTypeVideo;
114 RTCVideoTrack *videoTrack =
115 [[RTCVideoTrack alloc] initWithNativeTrack:track type:type];
116 [_videoTracks addObject:videoTrack];
117 }
118 }
119 return self;
120 }
121
122 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698