OLD | NEW |
(Empty) | |
| 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 namespace webrtc { |
| 21 |
| 22 RtpReceiverDelegateAdapter::RtpReceiverDelegateAdapter( |
| 23 RTCRtpReceiver *receiver) { |
| 24 RTC_CHECK(receiver); |
| 25 receiver_ = receiver; |
| 26 } |
| 27 |
| 28 void RtpReceiverDelegateAdapter::OnFirstPacketReceived( |
| 29 cricket::MediaType media_type) { |
| 30 RTCRtpMediaType packet_media_type = |
| 31 [RTCRtpReceiver mediaTypeForNativeMediaType:media_type]; |
| 32 RTCRtpReceiver *receiver = receiver_; |
| 33 [receiver.delegate rtpReceiver:receiver didReceiveFirstPacketForMediaType:pack
et_media_type]; |
| 34 } |
| 35 |
| 36 } // namespace webrtc |
| 37 |
| 38 @implementation RTCRtpReceiver { |
| 39 rtc::scoped_refptr<webrtc::RtpReceiverInterface> _nativeRtpReceiver; |
| 40 std::unique_ptr<webrtc::RtpReceiverDelegateAdapter> _observer; |
| 41 } |
| 42 |
| 43 @synthesize delegate = _delegate; |
| 44 |
| 45 - (NSString *)receiverId { |
| 46 return [NSString stringForStdString:_nativeRtpReceiver->id()]; |
| 47 } |
| 48 |
| 49 - (RTCRtpParameters *)parameters { |
| 50 return [[RTCRtpParameters alloc] |
| 51 initWithNativeParameters:_nativeRtpReceiver->GetParameters()]; |
| 52 } |
| 53 |
| 54 - (void)setParameters:(RTCRtpParameters *)parameters { |
| 55 if (!_nativeRtpReceiver->SetParameters(parameters.nativeParameters)) { |
| 56 RTCLogError(@"RTCRtpReceiver(%p): Failed to set parameters: %@", self, |
| 57 parameters); |
| 58 } |
| 59 } |
| 60 |
| 61 - (RTCMediaStreamTrack *)track { |
| 62 rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> nativeTrack( |
| 63 _nativeRtpReceiver->track()); |
| 64 if (nativeTrack) { |
| 65 return [[RTCMediaStreamTrack alloc] initWithNativeTrack:nativeTrack]; |
| 66 } |
| 67 return nil; |
| 68 } |
| 69 |
| 70 - (NSString *)description { |
| 71 return [NSString stringWithFormat:@"RTCRtpReceiver {\n receiverId: %@\n}", |
| 72 self.receiverId]; |
| 73 } |
| 74 |
| 75 - (BOOL)isEqual:(id)object { |
| 76 if (self == object) { |
| 77 return YES; |
| 78 } |
| 79 if (object == nil) { |
| 80 return NO; |
| 81 } |
| 82 if (![object isMemberOfClass:[self class]]) { |
| 83 return NO; |
| 84 } |
| 85 RTCRtpReceiver *receiver = (RTCRtpReceiver *)object; |
| 86 return _nativeRtpReceiver == receiver.nativeRtpReceiver; |
| 87 } |
| 88 |
| 89 - (NSUInteger)hash { |
| 90 return (NSUInteger)_nativeRtpReceiver.get(); |
| 91 } |
| 92 |
| 93 #pragma mark - Private |
| 94 |
| 95 - (rtc::scoped_refptr<webrtc::RtpReceiverInterface>)nativeRtpReceiver { |
| 96 return _nativeRtpReceiver; |
| 97 } |
| 98 |
| 99 - (instancetype)initWithNativeRtpReceiver: |
| 100 (rtc::scoped_refptr<webrtc::RtpReceiverInterface>)nativeRtpReceiver { |
| 101 if (self = [super init]) { |
| 102 _nativeRtpReceiver = nativeRtpReceiver; |
| 103 RTCLogInfo( |
| 104 @"RTCRtpReceiver(%p): created receiver: %@", self, self.description); |
| 105 _observer.reset(new webrtc::RtpReceiverDelegateAdapter(self)); |
| 106 _nativeRtpReceiver->SetObserver(_observer.get()); |
| 107 } |
| 108 return self; |
| 109 } |
| 110 |
| 111 + (RTCRtpMediaType)mediaTypeForNativeMediaType: |
| 112 (cricket::MediaType)nativeMediaType { |
| 113 switch (nativeMediaType) { |
| 114 case cricket::MEDIA_TYPE_AUDIO: |
| 115 return RTCRtpMediaTypeAudio; |
| 116 case cricket::MEDIA_TYPE_VIDEO: |
| 117 return RTCRtpMediaTypeVideo; |
| 118 case cricket::MEDIA_TYPE_DATA: |
| 119 return RTCRtpMediaTypeData; |
| 120 } |
| 121 } |
| 122 |
| 123 @end |
OLD | NEW |