blob: 6ec41c3b507da3d88e842b4c8aea8ce5ad47b6b2 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "rtc_base/checks.h"
tkchind4bfbfc2016-08-30 11:56:05 -070014
15@implementation RTCMediaSource {
Yura Yaroshevich01cee072018-07-11 15:35:40 +030016 RTCPeerConnectionFactory *_factory;
tkchind4bfbfc2016-08-30 11:56:05 -070017 RTCMediaSourceType _type;
18}
19
20@synthesize nativeMediaSource = _nativeMediaSource;
21
Yura Yaroshevich01cee072018-07-11 15:35:40 +030022- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
23 nativeMediaSource:(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource
24 type:(RTCMediaSourceType)type {
25 RTC_DCHECK(factory);
tkchind4bfbfc2016-08-30 11:56:05 -070026 RTC_DCHECK(nativeMediaSource);
27 if (self = [super init]) {
Yura Yaroshevich01cee072018-07-11 15:35:40 +030028 _factory = factory;
tkchind4bfbfc2016-08-30 11:56:05 -070029 _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