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