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 | |
| 24 | - (instancetype)initWithNativeRtpSender: |
| 25 | (rtc::scoped_refptr<webrtc::RtpSenderInterface>)nativeRtpSender { |
skvlad | f3569c8 | 2016-04-29 15:30:16 -0700 | [diff] [blame^] | 26 | NSParameterAssert(nativeRtpSender); |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 27 | if (self = [super init]) { |
| 28 | _nativeRtpSender = nativeRtpSender; |
skvlad | f3569c8 | 2016-04-29 15:30:16 -0700 | [diff] [blame^] | 29 | RTCLogInfo(@"RTCRtpSender(%p): created sender: %@", self, self.description); |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 30 | } |
| 31 | return self; |
| 32 | } |
| 33 | |
skvlad | f3569c8 | 2016-04-29 15:30:16 -0700 | [diff] [blame^] | 34 | - (NSString *)senderId { |
| 35 | return [NSString stringForStdString:_nativeRtpSender->id()]; |
| 36 | } |
| 37 | |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 38 | - (RTCRtpParameters *)parameters { |
| 39 | return [[RTCRtpParameters alloc] |
| 40 | initWithNativeParameters:_nativeRtpSender->GetParameters()]; |
| 41 | } |
| 42 | |
skvlad | f3569c8 | 2016-04-29 15:30:16 -0700 | [diff] [blame^] | 43 | - (void)setParameters:(RTCRtpParameters *)parameters { |
| 44 | if (!_nativeRtpSender->SetParameters(parameters.nativeParameters)) { |
| 45 | RTCLogError(@"RTCRtpSender(%p): Failed to set parameters: %@", self, |
| 46 | parameters); |
| 47 | } |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | - (RTCMediaStreamTrack *)track { |
| 51 | rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> nativeTrack( |
| 52 | _nativeRtpSender->track()); |
| 53 | if (nativeTrack) { |
| 54 | return [[RTCMediaStreamTrack alloc] initWithNativeTrack:nativeTrack]; |
| 55 | } |
| 56 | return nil; |
| 57 | } |
| 58 | |
skvlad | f3569c8 | 2016-04-29 15:30:16 -0700 | [diff] [blame^] | 59 | - (void)setTrack:(RTCMediaStreamTrack *)track { |
| 60 | if (!_nativeRtpSender->SetTrack(track.nativeTrack)) { |
| 61 | RTCLogError(@"RTCRtpSender(%p): Failed to set track %@", self, track); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | - (NSString *)description { |
| 66 | return [NSString stringWithFormat:@"RTCRtpSender {\n senderId: %@\n}", |
| 67 | self.senderId]; |
| 68 | } |
| 69 | |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 70 | @end |