You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
5.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2018 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. #import "RTCRtpTransceiver+Private.h"
  11. #import "RTCRtpEncodingParameters+Private.h"
  12. #import "RTCRtpParameters+Private.h"
  13. #import "RTCRtpReceiver+Private.h"
  14. #import "RTCRtpSender+Private.h"
  15. #import "base/RTCLogging.h"
  16. #import "helpers/NSString+StdString.h"
  17. @implementation RTCRtpTransceiverInit
  18. @synthesize direction = _direction;
  19. @synthesize streamIds = _streamIds;
  20. @synthesize sendEncodings = _sendEncodings;
  21. - (instancetype)init {
  22. if (self = [super init]) {
  23. _direction = RTCRtpTransceiverDirectionSendRecv;
  24. }
  25. return self;
  26. }
  27. - (webrtc::RtpTransceiverInit)nativeInit {
  28. webrtc::RtpTransceiverInit init;
  29. init.direction = [RTCRtpTransceiver nativeRtpTransceiverDirectionFromDirection:_direction];
  30. for (NSString *streamId in _streamIds) {
  31. init.stream_ids.push_back([streamId UTF8String]);
  32. }
  33. for (RTCRtpEncodingParameters *sendEncoding in _sendEncodings) {
  34. init.send_encodings.push_back(sendEncoding.nativeParameters);
  35. }
  36. return init;
  37. }
  38. @end
  39. @implementation RTCRtpTransceiver {
  40. RTCPeerConnectionFactory *_factory;
  41. rtc::scoped_refptr<webrtc::RtpTransceiverInterface> _nativeRtpTransceiver;
  42. }
  43. - (RTCRtpMediaType)mediaType {
  44. return [RTCRtpReceiver mediaTypeForNativeMediaType:_nativeRtpTransceiver->media_type()];
  45. }
  46. - (NSString *)mid {
  47. if (_nativeRtpTransceiver->mid()) {
  48. return [NSString stringForStdString:*_nativeRtpTransceiver->mid()];
  49. } else {
  50. return nil;
  51. }
  52. }
  53. @synthesize sender = _sender;
  54. @synthesize receiver = _receiver;
  55. - (BOOL)isStopped {
  56. return _nativeRtpTransceiver->stopped();
  57. }
  58. - (RTCRtpTransceiverDirection)direction {
  59. return [RTCRtpTransceiver
  60. rtpTransceiverDirectionFromNativeDirection:_nativeRtpTransceiver->direction()];
  61. }
  62. - (void)setDirection:(RTCRtpTransceiverDirection)direction {
  63. _nativeRtpTransceiver->SetDirection(
  64. [RTCRtpTransceiver nativeRtpTransceiverDirectionFromDirection:direction]);
  65. }
  66. - (BOOL)currentDirection:(RTCRtpTransceiverDirection *)currentDirectionOut {
  67. if (_nativeRtpTransceiver->current_direction()) {
  68. *currentDirectionOut = [RTCRtpTransceiver
  69. rtpTransceiverDirectionFromNativeDirection:*_nativeRtpTransceiver->current_direction()];
  70. return YES;
  71. } else {
  72. return NO;
  73. }
  74. }
  75. - (void)stop {
  76. _nativeRtpTransceiver->Stop();
  77. }
  78. - (NSString *)description {
  79. return [NSString
  80. stringWithFormat:@"RTCRtpTransceiver {\n sender: %@\n receiver: %@\n}", _sender, _receiver];
  81. }
  82. - (BOOL)isEqual:(id)object {
  83. if (self == object) {
  84. return YES;
  85. }
  86. if (object == nil) {
  87. return NO;
  88. }
  89. if (![object isMemberOfClass:[self class]]) {
  90. return NO;
  91. }
  92. RTCRtpTransceiver *transceiver = (RTCRtpTransceiver *)object;
  93. return _nativeRtpTransceiver == transceiver.nativeRtpTransceiver;
  94. }
  95. - (NSUInteger)hash {
  96. return (NSUInteger)_nativeRtpTransceiver.get();
  97. }
  98. #pragma mark - Private
  99. - (rtc::scoped_refptr<webrtc::RtpTransceiverInterface>)nativeRtpTransceiver {
  100. return _nativeRtpTransceiver;
  101. }
  102. - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
  103. nativeRtpTransceiver:
  104. (rtc::scoped_refptr<webrtc::RtpTransceiverInterface>)nativeRtpTransceiver {
  105. NSParameterAssert(factory);
  106. NSParameterAssert(nativeRtpTransceiver);
  107. if (self = [super init]) {
  108. _factory = factory;
  109. _nativeRtpTransceiver = nativeRtpTransceiver;
  110. _sender = [[RTCRtpSender alloc] initWithFactory:_factory
  111. nativeRtpSender:nativeRtpTransceiver->sender()];
  112. _receiver = [[RTCRtpReceiver alloc] initWithFactory:_factory
  113. nativeRtpReceiver:nativeRtpTransceiver->receiver()];
  114. RTCLogInfo(@"RTCRtpTransceiver(%p): created transceiver: %@", self, self.description);
  115. }
  116. return self;
  117. }
  118. + (webrtc::RtpTransceiverDirection)nativeRtpTransceiverDirectionFromDirection:
  119. (RTCRtpTransceiverDirection)direction {
  120. switch (direction) {
  121. case RTCRtpTransceiverDirectionSendRecv:
  122. return webrtc::RtpTransceiverDirection::kSendRecv;
  123. case RTCRtpTransceiverDirectionSendOnly:
  124. return webrtc::RtpTransceiverDirection::kSendOnly;
  125. case RTCRtpTransceiverDirectionRecvOnly:
  126. return webrtc::RtpTransceiverDirection::kRecvOnly;
  127. case RTCRtpTransceiverDirectionInactive:
  128. return webrtc::RtpTransceiverDirection::kInactive;
  129. }
  130. }
  131. + (RTCRtpTransceiverDirection)rtpTransceiverDirectionFromNativeDirection:
  132. (webrtc::RtpTransceiverDirection)nativeDirection {
  133. switch (nativeDirection) {
  134. case webrtc::RtpTransceiverDirection::kSendRecv:
  135. return RTCRtpTransceiverDirectionSendRecv;
  136. case webrtc::RtpTransceiverDirection::kSendOnly:
  137. return RTCRtpTransceiverDirectionSendOnly;
  138. case webrtc::RtpTransceiverDirection::kRecvOnly:
  139. return RTCRtpTransceiverDirectionRecvOnly;
  140. case webrtc::RtpTransceiverDirection::kInactive:
  141. return RTCRtpTransceiverDirectionInactive;
  142. }
  143. }
  144. @end