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.

82 lines
2.4 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 "RTCMediaSource+Private.h"
  11. #include "rtc_base/checks.h"
  12. @implementation RTCMediaSource {
  13. RTCPeerConnectionFactory *_factory;
  14. RTCMediaSourceType _type;
  15. }
  16. @synthesize nativeMediaSource = _nativeMediaSource;
  17. - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
  18. nativeMediaSource:(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource
  19. type:(RTCMediaSourceType)type {
  20. RTC_DCHECK(factory);
  21. RTC_DCHECK(nativeMediaSource);
  22. if (self = [super init]) {
  23. _factory = factory;
  24. _nativeMediaSource = nativeMediaSource;
  25. _type = type;
  26. }
  27. return self;
  28. }
  29. - (RTCSourceState)state {
  30. return [[self class] sourceStateForNativeState:_nativeMediaSource->state()];
  31. }
  32. #pragma mark - Private
  33. + (webrtc::MediaSourceInterface::SourceState)nativeSourceStateForState:
  34. (RTCSourceState)state {
  35. switch (state) {
  36. case RTCSourceStateInitializing:
  37. return webrtc::MediaSourceInterface::kInitializing;
  38. case RTCSourceStateLive:
  39. return webrtc::MediaSourceInterface::kLive;
  40. case RTCSourceStateEnded:
  41. return webrtc::MediaSourceInterface::kEnded;
  42. case RTCSourceStateMuted:
  43. return webrtc::MediaSourceInterface::kMuted;
  44. }
  45. }
  46. + (RTCSourceState)sourceStateForNativeState:
  47. (webrtc::MediaSourceInterface::SourceState)nativeState {
  48. switch (nativeState) {
  49. case webrtc::MediaSourceInterface::kInitializing:
  50. return RTCSourceStateInitializing;
  51. case webrtc::MediaSourceInterface::kLive:
  52. return RTCSourceStateLive;
  53. case webrtc::MediaSourceInterface::kEnded:
  54. return RTCSourceStateEnded;
  55. case webrtc::MediaSourceInterface::kMuted:
  56. return RTCSourceStateMuted;
  57. }
  58. }
  59. + (NSString *)stringForState:(RTCSourceState)state {
  60. switch (state) {
  61. case RTCSourceStateInitializing:
  62. return @"Initializing";
  63. case RTCSourceStateLive:
  64. return @"Live";
  65. case RTCSourceStateEnded:
  66. return @"Ended";
  67. case RTCSourceStateMuted:
  68. return @"Muted";
  69. }
  70. }
  71. @end