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