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

Side by Side Diff: webrtc/api/objc/RTCMediaStream.mm

Issue 1558733002: Update API for Objective-C RTCMediaStream. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix build issues Created 4 years, 11 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
« no previous file with comments | « webrtc/api/objc/RTCMediaStream.h ('k') | webrtc/api/objc/RTCMediaStream+Private.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.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;
23 NSMutableArray *_videoTracks;
24 rtc::scoped_refptr<webrtc::MediaStreamInterface> _nativeMediaStream;
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:_nativeMediaStream->label()];
37 }
38
39 - (void)addAudioTrack:(RTCAudioTrack *)audioTrack {
40 if (_nativeMediaStream->AddTrack(audioTrack.nativeAudioTrack)) {
41 [_audioTracks addObject:audioTrack];
42 }
43 }
44
45 - (void)addVideoTrack:(RTCVideoTrack *)videoTrack {
46 if (_nativeMediaStream->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 _nativeMediaStream->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 _nativeMediaStream->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 _nativeMediaStream;
82 }
83
84 - (instancetype)initWithNativeMediaStream:
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 _nativeMediaStream = nativeMediaStream;
94
95 for (auto &track : audioTracks) {
96 RTCMediaStreamTrackType type = RTCMediaStreamTrackTypeAudio;
97 RTCAudioTrack *audioTrack =
98 [[RTCAudioTrack alloc] initWithNativeTrack:track type:type];
99 [_audioTracks addObject:audioTrack];
100 }
101
102 for (auto &track : videoTracks) {
103 RTCMediaStreamTrackType type = RTCMediaStreamTrackTypeVideo;
104 RTCVideoTrack *videoTrack =
105 [[RTCVideoTrack alloc] initWithNativeTrack:track type:type];
106 [_videoTracks addObject:videoTrack];
107 }
108 }
109 return self;
110 }
111
112 @end
OLDNEW
« no previous file with comments | « webrtc/api/objc/RTCMediaStream.h ('k') | webrtc/api/objc/RTCMediaStream+Private.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698