Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 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 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 11 | #import "RTCVideoSource+Private.h" |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 12 | |
Jon Hjelle | 065aacc | 2016-01-20 13:25:44 -0800 | [diff] [blame] | 13 | @implementation RTCVideoSource { |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 14 | rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> _nativeVideoSource; |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 15 | } |
| 16 | |
| 17 | - (RTCSourceState)state { |
Jon Hjelle | 065aacc | 2016-01-20 13:25:44 -0800 | [diff] [blame] | 18 | return [[self class] sourceStateForNativeState:_nativeVideoSource->state()]; |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | - (NSString *)description { |
Jon Hjelle | 065aacc | 2016-01-20 13:25:44 -0800 | [diff] [blame] | 22 | return [NSString stringWithFormat:@"RTCVideoSource:\n%@", |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 23 | [[self class] stringForState:self.state]]; |
| 24 | } |
| 25 | |
| 26 | #pragma mark - Private |
| 27 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 28 | - (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource { |
Jon Hjelle | 065aacc | 2016-01-20 13:25:44 -0800 | [diff] [blame] | 29 | return _nativeVideoSource; |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 30 | } |
| 31 | |
Jon Hjelle | 065aacc | 2016-01-20 13:25:44 -0800 | [diff] [blame] | 32 | - (instancetype)initWithNativeVideoSource: |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 33 | (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource { |
Jon Hjelle | 065aacc | 2016-01-20 13:25:44 -0800 | [diff] [blame] | 34 | NSParameterAssert(nativeVideoSource); |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 35 | if (self = [super init]) { |
Jon Hjelle | 065aacc | 2016-01-20 13:25:44 -0800 | [diff] [blame] | 36 | _nativeVideoSource = nativeVideoSource; |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 37 | } |
| 38 | return self; |
| 39 | } |
| 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 |