From f6c318ebae89bc1a6fac1207a0f32380e6508d33 Mon Sep 17 00:00:00 2001 From: Jon Hjelle Date: Mon, 11 Jan 2016 14:39:01 -0800 Subject: Update API for Objective-C RTCMediaSource. BUG= R=tkchin@webrtc.org Review URL: https://codereview.webrtc.org/1538263002 . Patch from Jon Hjelle . Cr-Commit-Position: refs/heads/master@{#11210} --- webrtc/api/BUILD.gn | 3 ++ webrtc/api/api.gyp | 3 ++ webrtc/api/objc/RTCMediaSource+Private.h | 41 ++++++++++++++++ webrtc/api/objc/RTCMediaSource.h | 31 ++++++++++++ webrtc/api/objc/RTCMediaSource.mm | 84 ++++++++++++++++++++++++++++++++ 5 files changed, 162 insertions(+) create mode 100644 webrtc/api/objc/RTCMediaSource+Private.h create mode 100644 webrtc/api/objc/RTCMediaSource.h create mode 100644 webrtc/api/objc/RTCMediaSource.mm (limited to 'webrtc') diff --git a/webrtc/api/BUILD.gn b/webrtc/api/BUILD.gn index c5ed3c804a..7cfa083a6b 100644 --- a/webrtc/api/BUILD.gn +++ b/webrtc/api/BUILD.gn @@ -32,6 +32,9 @@ if (is_ios) { #"objc/RTCIceCandidate+Private.h", #"objc/RTCIceCandidate.h", #"objc/RTCIceCandidate.mm", + #"objc/RTCMediaSource+Private.h", + #"objc/RTCMediaSource.h", + #"objc/RTCMediaSource.mm", #"objc/RTCMediaStreamTrack+Private.h", #"objc/RTCMediaStreamTrack.h", #"objc/RTCMediaStreamTrack.mm", diff --git a/webrtc/api/api.gyp b/webrtc/api/api.gyp index 430fee70d9..ba3fe8d0bd 100644 --- a/webrtc/api/api.gyp +++ b/webrtc/api/api.gyp @@ -28,6 +28,9 @@ 'objc/RTCMediaConstraints+Private.h', 'objc/RTCMediaConstraints.h', 'objc/RTCMediaConstraints.mm', + 'objc/RTCMediaSource+Private.h', + 'objc/RTCMediaSource.h', + 'objc/RTCMediaSource.mm', 'objc/RTCMediaStreamTrack+Private.h', 'objc/RTCMediaStreamTrack.h', 'objc/RTCMediaStreamTrack.mm', diff --git a/webrtc/api/objc/RTCMediaSource+Private.h b/webrtc/api/objc/RTCMediaSource+Private.h new file mode 100644 index 0000000000..fcbaad8e45 --- /dev/null +++ b/webrtc/api/objc/RTCMediaSource+Private.h @@ -0,0 +1,41 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCMediaSource.h" + +#include "talk/app/webrtc/mediastreaminterface.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCMediaSource () + +/** + * The MediaSourceInterface object passed to this RTCMediaSource during + * construction. + */ +@property(nonatomic, readonly) + rtc::scoped_refptr nativeMediaSource; + +/** Initialize an RTCMediaSource from a native MediaSourceInterface. */ +- (instancetype)initWithNativeMediaSource: + (rtc::scoped_refptr)nativeMediaSource + NS_DESIGNATED_INITIALIZER; + ++ (webrtc::MediaSourceInterface::SourceState)nativeSourceStateForState: + (RTCSourceState)state; + ++ (RTCSourceState)sourceStateForNativeState: + (webrtc::MediaSourceInterface::SourceState)nativeState; + ++ (NSString *)stringForState:(RTCSourceState)state; + +@end + +NS_ASSUME_NONNULL_END diff --git a/webrtc/api/objc/RTCMediaSource.h b/webrtc/api/objc/RTCMediaSource.h new file mode 100644 index 0000000000..0b36b8d709 --- /dev/null +++ b/webrtc/api/objc/RTCMediaSource.h @@ -0,0 +1,31 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import + +typedef NS_ENUM(NSInteger, RTCSourceState) { + RTCSourceStateInitializing, + RTCSourceStateLive, + RTCSourceStateEnded, + RTCSourceStateMuted, +}; + +NS_ASSUME_NONNULL_BEGIN + +@interface RTCMediaSource : NSObject + +/** The current state of the RTCMediaSource. */ +@property(nonatomic, readonly) RTCSourceState state; + +- (instancetype)init NS_UNAVAILABLE; + +@end + +NS_ASSUME_NONNULL_END diff --git a/webrtc/api/objc/RTCMediaSource.mm b/webrtc/api/objc/RTCMediaSource.mm new file mode 100644 index 0000000000..5f46ab8318 --- /dev/null +++ b/webrtc/api/objc/RTCMediaSource.mm @@ -0,0 +1,84 @@ +/* + * Copyright 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "RTCMediaSource.h" + +#import "webrtc/api/objc/RTCMediaSource+Private.h" + +@implementation RTCMediaSource { + rtc::scoped_refptr _nativeMediaSource; +} + +- (RTCSourceState)state { + return [[self class] sourceStateForNativeState:_nativeMediaSource->state()]; +} + +- (NSString *)description { + return [NSString stringWithFormat:@"RTCMediaSource:\n%@", + [[self class] stringForState:self.state]]; +} + +#pragma mark - Private + +- (rtc::scoped_refptr)nativeMediaSource { + return _nativeMediaSource; +} + +- (instancetype)initWithNativeMediaSource: + (rtc::scoped_refptr)nativeMediaSource { + NSParameterAssert(nativeMediaSource); + if (self = [super init]) { + _nativeMediaSource = nativeMediaSource; + } + return self; +} + ++ (webrtc::MediaSourceInterface::SourceState)nativeSourceStateForState: + (RTCSourceState)state { + switch (state) { + case RTCSourceStateInitializing: + return webrtc::MediaSourceInterface::kInitializing; + case RTCSourceStateLive: + return webrtc::MediaSourceInterface::kLive; + case RTCSourceStateEnded: + return webrtc::MediaSourceInterface::kEnded; + case RTCSourceStateMuted: + return webrtc::MediaSourceInterface::kMuted; + } +} + ++ (RTCSourceState)sourceStateForNativeState: + (webrtc::MediaSourceInterface::SourceState)nativeState { + switch (nativeState) { + case webrtc::MediaSourceInterface::kInitializing: + return RTCSourceStateInitializing; + case webrtc::MediaSourceInterface::kLive: + return RTCSourceStateLive; + case webrtc::MediaSourceInterface::kEnded: + return RTCSourceStateEnded; + case webrtc::MediaSourceInterface::kMuted: + return RTCSourceStateMuted; + } +} + ++ (NSString *)stringForState:(RTCSourceState)state { + switch (state) { + case RTCSourceStateInitializing: + return @"Initializing"; + case RTCSourceStateLive: + return @"Live"; + case RTCSourceStateEnded: + return @"Ended"; + case RTCSourceStateMuted: + return @"Muted"; + } +} + +@end -- cgit v1.2.3