skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 11 | #import "RTCRtpSender+Private.h" |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 12 | |
skvlad | f3569c8 | 2016-04-29 15:30:16 -0700 | [diff] [blame] | 13 | #import "NSString+StdString.h" |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 14 | #import "RTCMediaStreamTrack+Private.h" |
| 15 | #import "RTCRtpParameters+Private.h" |
skvlad | f3569c8 | 2016-04-29 15:30:16 -0700 | [diff] [blame] | 16 | #import "WebRTC/RTCLogging.h" |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 17 | |
| 18 | #include "webrtc/api/mediastreaminterface.h" |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 19 | |
| 20 | @implementation RTCRtpSender { |
| 21 | rtc::scoped_refptr<webrtc::RtpSenderInterface> _nativeRtpSender; |
| 22 | } |
| 23 | |
skvlad | f3569c8 | 2016-04-29 15:30:16 -0700 | [diff] [blame] | 24 | - (NSString *)senderId { |
| 25 | return [NSString stringForStdString:_nativeRtpSender->id()]; |
| 26 | } |
| 27 | |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 28 | - (RTCRtpParameters *)parameters { |
| 29 | return [[RTCRtpParameters alloc] |
| 30 | initWithNativeParameters:_nativeRtpSender->GetParameters()]; |
| 31 | } |
| 32 | |
skvlad | f3569c8 | 2016-04-29 15:30:16 -0700 | [diff] [blame] | 33 | - (void)setParameters:(RTCRtpParameters *)parameters { |
| 34 | if (!_nativeRtpSender->SetParameters(parameters.nativeParameters)) { |
| 35 | RTCLogError(@"RTCRtpSender(%p): Failed to set parameters: %@", self, |
| 36 | parameters); |
| 37 | } |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | - (RTCMediaStreamTrack *)track { |
| 41 | rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> nativeTrack( |
| 42 | _nativeRtpSender->track()); |
| 43 | if (nativeTrack) { |
| 44 | return [[RTCMediaStreamTrack alloc] initWithNativeTrack:nativeTrack]; |
| 45 | } |
| 46 | return nil; |
| 47 | } |
| 48 | |
skvlad | f3569c8 | 2016-04-29 15:30:16 -0700 | [diff] [blame] | 49 | - (void)setTrack:(RTCMediaStreamTrack *)track { |
| 50 | if (!_nativeRtpSender->SetTrack(track.nativeTrack)) { |
| 51 | RTCLogError(@"RTCRtpSender(%p): Failed to set track %@", self, track); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | - (NSString *)description { |
| 56 | return [NSString stringWithFormat:@"RTCRtpSender {\n senderId: %@\n}", |
| 57 | self.senderId]; |
| 58 | } |
| 59 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 60 | - (BOOL)isEqual:(id)object { |
| 61 | if (self == object) { |
| 62 | return YES; |
| 63 | } |
| 64 | if (object == nil) { |
| 65 | return NO; |
| 66 | } |
| 67 | if (![object isMemberOfClass:[self class]]) { |
| 68 | return NO; |
| 69 | } |
| 70 | RTCRtpSender *sender = (RTCRtpSender *)object; |
| 71 | return _nativeRtpSender == sender.nativeRtpSender; |
| 72 | } |
| 73 | |
| 74 | - (NSUInteger)hash { |
| 75 | return (NSUInteger)_nativeRtpSender.get(); |
| 76 | } |
| 77 | |
| 78 | #pragma mark - Private |
| 79 | |
| 80 | - (rtc::scoped_refptr<webrtc::RtpSenderInterface>)nativeRtpSender { |
| 81 | return _nativeRtpSender; |
| 82 | } |
| 83 | |
| 84 | - (instancetype)initWithNativeRtpSender: |
| 85 | (rtc::scoped_refptr<webrtc::RtpSenderInterface>)nativeRtpSender { |
| 86 | NSParameterAssert(nativeRtpSender); |
| 87 | if (self = [super init]) { |
| 88 | _nativeRtpSender = nativeRtpSender; |
| 89 | RTCLogInfo(@"RTCRtpSender(%p): created sender: %@", self, self.description); |
| 90 | } |
| 91 | return self; |
| 92 | } |
| 93 | |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 94 | @end |