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

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

Issue 2862543002: Split iOS sdk in to separate targets (Closed)
Patch Set: rebase and minor fixes 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 "RTCMediaStreamTrack+Private.h"
12
13 #import "NSString+StdString.h"
14
15 NSString * const kRTCMediaStreamTrackKindAudio =
16 @(webrtc::MediaStreamTrackInterface::kAudioKind);
17 NSString * const kRTCMediaStreamTrackKindVideo =
18 @(webrtc::MediaStreamTrackInterface::kVideoKind);
19
20 @implementation RTCMediaStreamTrack {
21 rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> _nativeTrack;
22 RTCMediaStreamTrackType _type;
23 }
24
25 - (NSString *)kind {
26 return [NSString stringForStdString:_nativeTrack->kind()];
27 }
28
29 - (NSString *)trackId {
30 return [NSString stringForStdString:_nativeTrack->id()];
31 }
32
33 - (BOOL)isEnabled {
34 return _nativeTrack->enabled();
35 }
36
37 - (void)setIsEnabled:(BOOL)isEnabled {
38 _nativeTrack->set_enabled(isEnabled);
39 }
40
41 - (RTCMediaStreamTrackState)readyState {
42 return [[self class] trackStateForNativeState:_nativeTrack->state()];
43 }
44
45 - (NSString *)description {
46 NSString *readyState = [[self class] stringForState:self.readyState];
47 return [NSString stringWithFormat:@"RTCMediaStreamTrack:\n%@\n%@\n%@\n%@",
48 self.kind,
49 self.trackId,
50 self.isEnabled ? @"enabled" : @"disabled",
51 readyState];
52 }
53
54 - (BOOL)isEqual:(id)object {
55 if (self == object) {
56 return YES;
57 }
58 if (![object isMemberOfClass:[self class]]) {
59 return NO;
60 }
61 return [self isEqualToTrack:(RTCMediaStreamTrack *)object];
62 }
63
64 - (NSUInteger)hash {
65 return (NSUInteger)_nativeTrack.get();
66 }
67
68 #pragma mark - Private
69
70 - (rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack {
71 return _nativeTrack;
72 }
73
74 - (instancetype)initWithNativeTrack:
75 (rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack
76 type:(RTCMediaStreamTrackType)type {
77 NSParameterAssert(nativeTrack);
78 if (self = [super init]) {
79 _nativeTrack = nativeTrack;
80 _type = type;
81 }
82 return self;
83 }
84
85 - (instancetype)initWithNativeTrack:
86 (rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack {
87 NSParameterAssert(nativeTrack);
88 if (nativeTrack->kind() ==
89 std::string(webrtc::MediaStreamTrackInterface::kAudioKind)) {
90 return [self initWithNativeTrack:nativeTrack
91 type:RTCMediaStreamTrackTypeAudio];
92 }
93 if (nativeTrack->kind() ==
94 std::string(webrtc::MediaStreamTrackInterface::kVideoKind)) {
95 return [self initWithNativeTrack:nativeTrack
96 type:RTCMediaStreamTrackTypeVideo];
97 }
98 return nil;
99 }
100
101 - (BOOL)isEqualToTrack:(RTCMediaStreamTrack *)track {
102 if (!track) {
103 return NO;
104 }
105 return _nativeTrack == track.nativeTrack;
106 }
107
108 + (webrtc::MediaStreamTrackInterface::TrackState)nativeTrackStateForState:
109 (RTCMediaStreamTrackState)state {
110 switch (state) {
111 case RTCMediaStreamTrackStateLive:
112 return webrtc::MediaStreamTrackInterface::kLive;
113 case RTCMediaStreamTrackStateEnded:
114 return webrtc::MediaStreamTrackInterface::kEnded;
115 }
116 }
117
118 + (RTCMediaStreamTrackState)trackStateForNativeState:
119 (webrtc::MediaStreamTrackInterface::TrackState)nativeState {
120 switch (nativeState) {
121 case webrtc::MediaStreamTrackInterface::kLive:
122 return RTCMediaStreamTrackStateLive;
123 case webrtc::MediaStreamTrackInterface::kEnded:
124 return RTCMediaStreamTrackStateEnded;
125 }
126 }
127
128 + (NSString *)stringForState:(RTCMediaStreamTrackState)state {
129 switch (state) {
130 case RTCMediaStreamTrackStateLive:
131 return @"Live";
132 case RTCMediaStreamTrackStateEnded:
133 return @"Ended";
134 }
135 }
136
137 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698