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 | |
Jon Hjelle | 065aacc | 2016-01-20 13:25:44 -0800 | [diff] [blame] | 11 | #import "RTCVideoSource.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 | #import "webrtc/api/objc/RTCVideoSource+Private.h" |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 14 | |
Jon Hjelle | 065aacc | 2016-01-20 13:25:44 -0800 | [diff] [blame] | 15 | @implementation RTCVideoSource { |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame^] | 16 | rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> _nativeVideoSource; |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | - (RTCSourceState)state { |
Jon Hjelle | 065aacc | 2016-01-20 13:25:44 -0800 | [diff] [blame] | 20 | return [[self class] sourceStateForNativeState:_nativeVideoSource->state()]; |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | - (NSString *)description { |
Jon Hjelle | 065aacc | 2016-01-20 13:25:44 -0800 | [diff] [blame] | 24 | return [NSString stringWithFormat:@"RTCVideoSource:\n%@", |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 25 | [[self class] stringForState:self.state]]; |
| 26 | } |
| 27 | |
| 28 | #pragma mark - Private |
| 29 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame^] | 30 | - (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource { |
Jon Hjelle | 065aacc | 2016-01-20 13:25:44 -0800 | [diff] [blame] | 31 | return _nativeVideoSource; |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 32 | } |
| 33 | |
Jon Hjelle | 065aacc | 2016-01-20 13:25:44 -0800 | [diff] [blame] | 34 | - (instancetype)initWithNativeVideoSource: |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame^] | 35 | (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource { |
Jon Hjelle | 065aacc | 2016-01-20 13:25:44 -0800 | [diff] [blame] | 36 | NSParameterAssert(nativeVideoSource); |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 37 | if (self = [super init]) { |
Jon Hjelle | 065aacc | 2016-01-20 13:25:44 -0800 | [diff] [blame] | 38 | _nativeVideoSource = nativeVideoSource; |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 39 | } |
| 40 | return self; |
| 41 | } |
| 42 | |
| 43 | + (webrtc::MediaSourceInterface::SourceState)nativeSourceStateForState: |
| 44 | (RTCSourceState)state { |
| 45 | switch (state) { |
| 46 | case RTCSourceStateInitializing: |
| 47 | return webrtc::MediaSourceInterface::kInitializing; |
| 48 | case RTCSourceStateLive: |
| 49 | return webrtc::MediaSourceInterface::kLive; |
| 50 | case RTCSourceStateEnded: |
| 51 | return webrtc::MediaSourceInterface::kEnded; |
| 52 | case RTCSourceStateMuted: |
| 53 | return webrtc::MediaSourceInterface::kMuted; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | + (RTCSourceState)sourceStateForNativeState: |
| 58 | (webrtc::MediaSourceInterface::SourceState)nativeState { |
| 59 | switch (nativeState) { |
| 60 | case webrtc::MediaSourceInterface::kInitializing: |
| 61 | return RTCSourceStateInitializing; |
| 62 | case webrtc::MediaSourceInterface::kLive: |
| 63 | return RTCSourceStateLive; |
| 64 | case webrtc::MediaSourceInterface::kEnded: |
| 65 | return RTCSourceStateEnded; |
| 66 | case webrtc::MediaSourceInterface::kMuted: |
| 67 | return RTCSourceStateMuted; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | + (NSString *)stringForState:(RTCSourceState)state { |
| 72 | switch (state) { |
| 73 | case RTCSourceStateInitializing: |
| 74 | return @"Initializing"; |
| 75 | case RTCSourceStateLive: |
| 76 | return @"Live"; |
| 77 | case RTCSourceStateEnded: |
| 78 | return @"Ended"; |
| 79 | case RTCSourceStateMuted: |
| 80 | return @"Muted"; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | @end |