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

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

Issue 1553743003: Update API for Objective-C RTCAudioTrack and RTCVideoTrack. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@updateRTCMediaStreamTrack
Patch Set: Improve comments a bit 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
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #import "RTCMediaStreamTrack.h" 11 #import "RTCMediaStreamTrack.h"
12 12
13 #import "webrtc/api/objc/RTCMediaStreamTrack+Private.h" 13 #import "webrtc/api/objc/RTCMediaStreamTrack+Private.h"
14 #import "webrtc/base/objc/NSString+StdString.h" 14 #import "webrtc/base/objc/NSString+StdString.h"
15 15
16 @implementation RTCMediaStreamTrack { 16 @implementation RTCMediaStreamTrack {
17 rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> _nativeTrack; 17 rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> _nativeAudioTrack;
18 rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> _nativeVideoTrack;
19 RTCMediaStreamTrackType _type;
18 } 20 }
19 21
20 - (NSString *)kind { 22 - (NSString *)kind {
21 return [NSString stringForStdString:_nativeTrack->kind()]; 23 return [NSString stringForStdString:self.nativeMediaTrack->kind()];
22 } 24 }
23 25
24 - (NSString *)trackId { 26 - (NSString *)trackId {
25 return [NSString stringForStdString:_nativeTrack->id()]; 27 return [NSString stringForStdString:self.nativeMediaTrack->id()];
26 } 28 }
27 29
28 - (BOOL)isEnabled { 30 - (BOOL)isEnabled {
29 return _nativeTrack->enabled(); 31 return self.nativeMediaTrack->enabled();
30 } 32 }
31 33
32 - (void)setIsEnabled:(BOOL)isEnabled { 34 - (void)setIsEnabled:(BOOL)isEnabled {
33 _nativeTrack->set_enabled(isEnabled); 35 self.nativeMediaTrack->set_enabled(isEnabled);
34 } 36 }
35 37
36 - (RTCMediaStreamTrackState)readyState { 38 - (RTCMediaStreamTrackState)readyState {
37 return [[self class] trackStateForNativeState:_nativeTrack->state()]; 39 return [[self class] trackStateForNativeState:self.nativeMediaTrack->state()];
38 } 40 }
39 41
40 - (NSString *)description { 42 - (NSString *)description {
41 NSString *readyState = [[self class] stringForState:self.readyState]; 43 NSString *readyState = [[self class] stringForState:self.readyState];
42 return [NSString stringWithFormat:@"RTCMediaStreamTrack:\n%@\n%@\n%@\n%@", 44 return [NSString stringWithFormat:@"RTCMediaStreamTrack:\n%@\n%@\n%@\n%@",
43 self.kind, 45 self.kind,
44 self.trackId, 46 self.trackId,
45 self.isEnabled ? @"enabled" : @"disabled", 47 self.isEnabled ? @"enabled" : @"disabled",
46 readyState]; 48 readyState];
47 } 49 }
48 50
49 #pragma mark - Private 51 #pragma mark - Private
50 52
51 - (rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack { 53 - (rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeMediaTrack {
52 return _nativeTrack; 54 switch (_type) {
55 case RTCMediaStreamTrackTypeAudio:
56 return _nativeAudioTrack;
57 case RTCMediaStreamTrackTypeVideo:
58 return _nativeVideoTrack;
59 }
53 } 60 }
54 61
55 - (instancetype)initWithNativeTrack: 62 - (rtc::scoped_refptr<webrtc::AudioTrackInterface>)nativeAudioTrack {
56 (rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack { 63 return static_cast<webrtc::AudioTrackInterface *>(_nativeAudioTrack.get());
tkchin_webrtc 2016/01/21 01:23:30 If we're static casting on the getter, might as we
hjon 2016/01/21 19:53:27 This should be taken care of.
57 NSParameterAssert(nativeTrack); 64 }
65
66 - (rtc::scoped_refptr<webrtc::VideoTrackInterface>)nativeVideoTrack {
67 return static_cast<webrtc::VideoTrackInterface *>(_nativeVideoTrack.get());
68 }
69
70 - (instancetype)initWithNativeMediaTrack:
71 (rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeMediaTrack
72 type:(RTCMediaStreamTrackType)type {
73 NSParameterAssert(nativeMediaTrack);
58 if (self = [super init]) { 74 if (self = [super init]) {
59 _nativeTrack = nativeTrack; 75 switch (_type) {
76 case RTCMediaStreamTrackTypeAudio:
77 _nativeAudioTrack = nativeMediaTrack;
78 case RTCMediaStreamTrackTypeVideo:
79 _nativeVideoTrack = nativeMediaTrack;
80 }
81 _type = type;
60 } 82 }
61 return self; 83 return self;
62 } 84 }
63 85
64 + (webrtc::MediaStreamTrackInterface::TrackState)nativeTrackStateForState: 86 + (webrtc::MediaStreamTrackInterface::TrackState)nativeTrackStateForState:
65 (RTCMediaStreamTrackState)state { 87 (RTCMediaStreamTrackState)state {
66 switch (state) { 88 switch (state) {
67 case RTCMediaStreamTrackStateInitializing: 89 case RTCMediaStreamTrackStateInitializing:
68 return webrtc::MediaStreamTrackInterface::kInitializing; 90 return webrtc::MediaStreamTrackInterface::kInitializing;
69 case RTCMediaStreamTrackStateLive: 91 case RTCMediaStreamTrackStateLive:
(...skipping 26 matching lines...) Expand all
96 case RTCMediaStreamTrackStateLive: 118 case RTCMediaStreamTrackStateLive:
97 return @"Live"; 119 return @"Live";
98 case RTCMediaStreamTrackStateEnded: 120 case RTCMediaStreamTrackStateEnded:
99 return @"Ended"; 121 return @"Ended";
100 case RTCMediaStreamTrackStateFailed: 122 case RTCMediaStreamTrackStateFailed:
101 return @"Failed"; 123 return @"Failed";
102 } 124 }
103 } 125 }
104 126
105 @end 127 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698