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

Side by Side Diff: webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCVideoTrack.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 "RTCVideoTrack+Private.h"
12
13 #import "NSString+StdString.h"
14 #import "RTCMediaStreamTrack+Private.h"
15 #import "RTCPeerConnectionFactory+Private.h"
16 #import "RTCVideoRendererAdapter+Private.h"
17 #import "RTCVideoSource+Private.h"
18
19 @implementation RTCVideoTrack {
20 NSMutableArray *_adapters;
21 }
22
23 @synthesize source = _source;
24
25 - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
26 source:(RTCVideoSource *)source
27 trackId:(NSString *)trackId {
28 NSParameterAssert(factory);
29 NSParameterAssert(source);
30 NSParameterAssert(trackId.length);
31 std::string nativeId = [NSString stdStringForString:trackId];
32 rtc::scoped_refptr<webrtc::VideoTrackInterface> track =
33 factory.nativeFactory->CreateVideoTrack(nativeId,
34 source.nativeVideoSource);
35 if ([self initWithNativeTrack:track type:RTCMediaStreamTrackTypeVideo]) {
36 _source = source;
37 }
38 return self;
39 }
40
41 - (instancetype)initWithNativeTrack:
42 (rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeMediaTrack
43 type:(RTCMediaStreamTrackType)type {
44 NSParameterAssert(nativeMediaTrack);
45 NSParameterAssert(type == RTCMediaStreamTrackTypeVideo);
46 if (self = [super initWithNativeTrack:nativeMediaTrack type:type]) {
47 _adapters = [NSMutableArray array];
48 }
49 return self;
50 }
51
52 - (void)dealloc {
53 for (RTCVideoRendererAdapter *adapter in _adapters) {
54 self.nativeVideoTrack->RemoveSink(adapter.nativeVideoRenderer);
55 }
56 }
57
58 - (RTCVideoSource *)source {
59 if (!_source) {
60 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source =
61 self.nativeVideoTrack->GetSource();
62 if (source) {
63 _source = [[RTCVideoSource alloc] initWithNativeVideoSource:source.get()];
64 }
65 }
66 return _source;
67 }
68
69 - (void)addRenderer:(id<RTCVideoRenderer>)renderer {
70 // Make sure we don't have this renderer yet.
71 for (RTCVideoRendererAdapter *adapter in _adapters) {
72 if (adapter.videoRenderer == renderer) {
73 NSAssert(NO, @"|renderer| is already attached to this track");
74 return;
75 }
76 }
77 // Create a wrapper that provides a native pointer for us.
78 RTCVideoRendererAdapter* adapter =
79 [[RTCVideoRendererAdapter alloc] initWithNativeRenderer:renderer];
80 [_adapters addObject:adapter];
81 self.nativeVideoTrack->AddOrUpdateSink(adapter.nativeVideoRenderer,
82 rtc::VideoSinkWants());
83 }
84
85 - (void)removeRenderer:(id<RTCVideoRenderer>)renderer {
86 __block NSUInteger indexToRemove = NSNotFound;
87 [_adapters enumerateObjectsUsingBlock:^(RTCVideoRendererAdapter *adapter,
88 NSUInteger idx,
89 BOOL *stop) {
90 if (adapter.videoRenderer == renderer) {
91 indexToRemove = idx;
92 *stop = YES;
93 }
94 }];
95 if (indexToRemove == NSNotFound) {
96 return;
97 }
98 RTCVideoRendererAdapter *adapterToRemove =
99 [_adapters objectAtIndex:indexToRemove];
100 self.nativeVideoTrack->RemoveSink(adapterToRemove.nativeVideoRenderer);
101 [_adapters removeObjectAtIndex:indexToRemove];
102 }
103
104 #pragma mark - Private
105
106 - (rtc::scoped_refptr<webrtc::VideoTrackInterface>)nativeVideoTrack {
107 return static_cast<webrtc::VideoTrackInterface *>(self.nativeTrack.get());
108 }
109
110 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698