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