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.

68 lines
2.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2015 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 "RTCAudioTrack+Private.h"
  11. #import "RTCAudioSource+Private.h"
  12. #import "RTCMediaStreamTrack+Private.h"
  13. #import "RTCPeerConnectionFactory+Private.h"
  14. #import "helpers/NSString+StdString.h"
  15. #include "rtc_base/checks.h"
  16. @implementation RTCAudioTrack
  17. @synthesize source = _source;
  18. - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
  19. source:(RTCAudioSource *)source
  20. trackId:(NSString *)trackId {
  21. RTC_DCHECK(factory);
  22. RTC_DCHECK(source);
  23. RTC_DCHECK(trackId.length);
  24. std::string nativeId = [NSString stdStringForString:trackId];
  25. rtc::scoped_refptr<webrtc::AudioTrackInterface> track =
  26. factory.nativeFactory->CreateAudioTrack(nativeId, source.nativeAudioSource);
  27. if (self = [self initWithFactory:factory nativeTrack:track type:RTCMediaStreamTrackTypeAudio]) {
  28. _source = source;
  29. }
  30. return self;
  31. }
  32. - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
  33. nativeTrack:(rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack
  34. type:(RTCMediaStreamTrackType)type {
  35. NSParameterAssert(factory);
  36. NSParameterAssert(nativeTrack);
  37. NSParameterAssert(type == RTCMediaStreamTrackTypeAudio);
  38. return [super initWithFactory:factory nativeTrack:nativeTrack type:type];
  39. }
  40. - (RTCAudioSource *)source {
  41. if (!_source) {
  42. rtc::scoped_refptr<webrtc::AudioSourceInterface> source =
  43. self.nativeAudioTrack->GetSource();
  44. if (source) {
  45. _source =
  46. [[RTCAudioSource alloc] initWithFactory:self.factory nativeAudioSource:source.get()];
  47. }
  48. }
  49. return _source;
  50. }
  51. #pragma mark - Private
  52. - (rtc::scoped_refptr<webrtc::AudioTrackInterface>)nativeAudioTrack {
  53. return static_cast<webrtc::AudioTrackInterface *>(self.nativeTrack.get());
  54. }
  55. @end