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.

129 lines
3.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #import "RTCRtpSender+Private.h"
  11. #import "RTCDtmfSender+Private.h"
  12. #import "RTCMediaStreamTrack+Private.h"
  13. #import "RTCRtpParameters+Private.h"
  14. #import "RTCRtpSender+Native.h"
  15. #import "base/RTCLogging.h"
  16. #import "helpers/NSString+StdString.h"
  17. #include "api/media_stream_interface.h"
  18. @implementation RTCRtpSender {
  19. RTCPeerConnectionFactory *_factory;
  20. rtc::scoped_refptr<webrtc::RtpSenderInterface> _nativeRtpSender;
  21. }
  22. @synthesize dtmfSender = _dtmfSender;
  23. - (NSString *)senderId {
  24. return [NSString stringForStdString:_nativeRtpSender->id()];
  25. }
  26. - (RTCRtpParameters *)parameters {
  27. return [[RTCRtpParameters alloc]
  28. initWithNativeParameters:_nativeRtpSender->GetParameters()];
  29. }
  30. - (void)setParameters:(RTCRtpParameters *)parameters {
  31. if (!_nativeRtpSender->SetParameters(parameters.nativeParameters).ok()) {
  32. RTCLogError(@"RTCRtpSender(%p): Failed to set parameters: %@", self,
  33. parameters);
  34. }
  35. }
  36. - (RTCMediaStreamTrack *)track {
  37. rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> nativeTrack(
  38. _nativeRtpSender->track());
  39. if (nativeTrack) {
  40. return [RTCMediaStreamTrack mediaTrackForNativeTrack:nativeTrack factory:_factory];
  41. }
  42. return nil;
  43. }
  44. - (void)setTrack:(RTCMediaStreamTrack *)track {
  45. if (!_nativeRtpSender->SetTrack(track.nativeTrack)) {
  46. RTCLogError(@"RTCRtpSender(%p): Failed to set track %@", self, track);
  47. }
  48. }
  49. - (NSArray<NSString *> *)streamIds {
  50. std::vector<std::string> nativeStreamIds = _nativeRtpSender->stream_ids();
  51. NSMutableArray *streamIds = [NSMutableArray arrayWithCapacity:nativeStreamIds.size()];
  52. for (const auto &s : nativeStreamIds) {
  53. [streamIds addObject:[NSString stringForStdString:s]];
  54. }
  55. return streamIds;
  56. }
  57. - (void)setStreamIds:(NSArray<NSString *> *)streamIds {
  58. std::vector<std::string> nativeStreamIds;
  59. for (NSString *streamId in streamIds) {
  60. nativeStreamIds.push_back([streamId UTF8String]);
  61. }
  62. _nativeRtpSender->SetStreams(nativeStreamIds);
  63. }
  64. - (NSString *)description {
  65. return [NSString stringWithFormat:@"RTCRtpSender {\n senderId: %@\n}",
  66. self.senderId];
  67. }
  68. - (BOOL)isEqual:(id)object {
  69. if (self == object) {
  70. return YES;
  71. }
  72. if (object == nil) {
  73. return NO;
  74. }
  75. if (![object isMemberOfClass:[self class]]) {
  76. return NO;
  77. }
  78. RTCRtpSender *sender = (RTCRtpSender *)object;
  79. return _nativeRtpSender == sender.nativeRtpSender;
  80. }
  81. - (NSUInteger)hash {
  82. return (NSUInteger)_nativeRtpSender.get();
  83. }
  84. #pragma mark - Native
  85. - (void)setFrameEncryptor:(rtc::scoped_refptr<webrtc::FrameEncryptorInterface>)frameEncryptor {
  86. _nativeRtpSender->SetFrameEncryptor(frameEncryptor);
  87. }
  88. #pragma mark - Private
  89. - (rtc::scoped_refptr<webrtc::RtpSenderInterface>)nativeRtpSender {
  90. return _nativeRtpSender;
  91. }
  92. - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
  93. nativeRtpSender:(rtc::scoped_refptr<webrtc::RtpSenderInterface>)nativeRtpSender {
  94. NSParameterAssert(factory);
  95. NSParameterAssert(nativeRtpSender);
  96. if (self = [super init]) {
  97. _factory = factory;
  98. _nativeRtpSender = nativeRtpSender;
  99. rtc::scoped_refptr<webrtc::DtmfSenderInterface> nativeDtmfSender(
  100. _nativeRtpSender->GetDtmfSender());
  101. if (nativeDtmfSender) {
  102. _dtmfSender = [[RTCDtmfSender alloc] initWithNativeDtmfSender:nativeDtmfSender];
  103. }
  104. RTCLogInfo(@"RTCRtpSender(%p): created sender: %@", self, self.description);
  105. }
  106. return self;
  107. }
  108. @end