Moving src/webrtc into src/.
In order to eliminate the WebRTC Subtree mirror in Chromium, WebRTC is moving the content of the src/webrtc directory up to the src/ directory. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true TBR=tommi@webrtc.org Bug: chromium:611808 Change-Id: Iac59c5b51b950f174119565bac87955a7994bc38 Reviewed-on: https://webrtc-review.googlesource.com/1560 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Henrik Kjellander <kjellander@webrtc.org> Cr-Commit-Position: refs/heads/master@{#19845}
This commit is contained in:
committed by
Commit Bot
parent
6674846b4a
commit
bb547203bf
26
sdk/objc/Framework/Classes/Common/NSString+StdString.h
Normal file
26
sdk/objc/Framework/Classes/Common/NSString+StdString.h
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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 <Foundation/Foundation.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface NSString (StdString)
|
||||
|
||||
@property(nonatomic, readonly) std::string stdString;
|
||||
|
||||
+ (std::string)stdStringForString:(NSString *)nsString;
|
||||
+ (NSString *)stringForStdString:(const std::string&)stdString;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
33
sdk/objc/Framework/Classes/Common/NSString+StdString.mm
Normal file
33
sdk/objc/Framework/Classes/Common/NSString+StdString.mm
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 "NSString+StdString.h"
|
||||
|
||||
@implementation NSString (StdString)
|
||||
|
||||
- (std::string)stdString {
|
||||
return [NSString stdStringForString:self];
|
||||
}
|
||||
|
||||
+ (std::string)stdStringForString:(NSString *)nsString {
|
||||
NSData *charData = [nsString dataUsingEncoding:NSUTF8StringEncoding];
|
||||
return std::string(reinterpret_cast<const char *>(charData.bytes),
|
||||
charData.length);
|
||||
}
|
||||
|
||||
+ (NSString *)stringForStdString:(const std::string&)stdString {
|
||||
// std::string may contain null termination character so we construct
|
||||
// using length.
|
||||
return [[NSString alloc] initWithBytes:stdString.data()
|
||||
length:stdString.length()
|
||||
encoding:NSUTF8StringEncoding];
|
||||
}
|
||||
|
||||
@end
|
||||
17
sdk/objc/Framework/Classes/Common/RTCDispatcher+Private.h
Normal file
17
sdk/objc/Framework/Classes/Common/RTCDispatcher+Private.h
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* 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 "WebRTC/RTCDispatcher.h"
|
||||
|
||||
@interface RTCDispatcher ()
|
||||
|
||||
+ (dispatch_queue_t)dispatchQueueForType:(RTCDispatcherQueueType)dispatchType;
|
||||
|
||||
@end
|
||||
61
sdk/objc/Framework/Classes/Common/RTCDispatcher.m
Normal file
61
sdk/objc/Framework/Classes/Common/RTCDispatcher.m
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 "RTCDispatcher+Private.h"
|
||||
|
||||
static dispatch_queue_t kAudioSessionQueue = nil;
|
||||
static dispatch_queue_t kCaptureSessionQueue = nil;
|
||||
|
||||
@implementation RTCDispatcher
|
||||
|
||||
+ (void)initialize {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
kAudioSessionQueue = dispatch_queue_create(
|
||||
"org.webrtc.RTCDispatcherAudioSession",
|
||||
DISPATCH_QUEUE_SERIAL);
|
||||
kCaptureSessionQueue = dispatch_queue_create(
|
||||
"org.webrtc.RTCDispatcherCaptureSession",
|
||||
DISPATCH_QUEUE_SERIAL);
|
||||
});
|
||||
}
|
||||
|
||||
+ (void)dispatchAsyncOnType:(RTCDispatcherQueueType)dispatchType
|
||||
block:(dispatch_block_t)block {
|
||||
dispatch_queue_t queue = [self dispatchQueueForType:dispatchType];
|
||||
dispatch_async(queue, block);
|
||||
}
|
||||
|
||||
+ (BOOL)isOnQueueForType:(RTCDispatcherQueueType)dispatchType {
|
||||
dispatch_queue_t targetQueue = [self dispatchQueueForType:dispatchType];
|
||||
const char* targetLabel = dispatch_queue_get_label(targetQueue);
|
||||
const char* currentLabel = dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL);
|
||||
|
||||
NSAssert(strlen(targetLabel) > 0, @"Label is required for the target queue.");
|
||||
NSAssert(strlen(currentLabel) > 0, @"Label is required for the current queue.");
|
||||
|
||||
return strcmp(targetLabel, currentLabel) == 0;
|
||||
}
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
+ (dispatch_queue_t)dispatchQueueForType:(RTCDispatcherQueueType)dispatchType {
|
||||
switch (dispatchType) {
|
||||
case RTCDispatcherTypeMain:
|
||||
return dispatch_get_main_queue();
|
||||
case RTCDispatcherTypeCaptureSession:
|
||||
return kCaptureSessionQueue;
|
||||
case RTCDispatcherTypeAudioSession:
|
||||
return kAudioSessionQueue;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
69
sdk/objc/Framework/Classes/Common/RTCFieldTrials.mm
Normal file
69
sdk/objc/Framework/Classes/Common/RTCFieldTrials.mm
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2016 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 "WebRTC/RTCFieldTrials.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#import "WebRTC/RTCLogging.h"
|
||||
|
||||
// Adding 'nogncheck' to disable the gn include headers check.
|
||||
// We don't want to depend on 'system_wrappers:field_trial_default' because
|
||||
// clients should be able to provide their own implementation.
|
||||
#include "webrtc/system_wrappers/include/field_trial_default.h" // nogncheck
|
||||
|
||||
NSString * const kRTCFieldTrialAudioSendSideBweKey = @"WebRTC-Audio-SendSideBwe";
|
||||
NSString * const kRTCFieldTrialSendSideBweWithOverheadKey = @"WebRTC-SendSideBwe-WithOverhead";
|
||||
NSString * const kRTCFieldTrialFlexFec03AdvertisedKey = @"WebRTC-FlexFEC-03-Advertised";
|
||||
NSString * const kRTCFieldTrialFlexFec03Key = @"WebRTC-FlexFEC-03";
|
||||
NSString * const kRTCFieldTrialImprovedBitrateEstimateKey = @"WebRTC-ImprovedBitrateEstimate";
|
||||
NSString * const kRTCFieldTrialMedianSlopeFilterKey = @"WebRTC-BweMedianSlopeFilter";
|
||||
NSString * const kRTCFieldTrialTrendlineFilterKey = @"WebRTC-BweTrendlineFilter";
|
||||
NSString * const kRTCFieldTrialH264HighProfileKey = @"WebRTC-H264HighProfile";
|
||||
NSString * const kRTCFieldTrialMinimizeResamplingOnMobileKey =
|
||||
@"WebRTC-Audio-MinimizeResamplingOnMobile";
|
||||
NSString * const kRTCFieldTrialEnabledValue = @"Enabled";
|
||||
|
||||
static std::unique_ptr<char[]> gFieldTrialInitString;
|
||||
|
||||
NSString *RTCFieldTrialMedianSlopeFilterValue(
|
||||
size_t windowSize, double thresholdGain) {
|
||||
NSString *format = @"Enabled-%zu,%lf";
|
||||
return [NSString stringWithFormat:format, windowSize, thresholdGain];
|
||||
}
|
||||
|
||||
NSString *RTCFieldTrialTrendlineFilterValue(
|
||||
size_t windowSize, double smoothingCoeff, double thresholdGain) {
|
||||
NSString *format = @"Enabled-%zu,%lf,%lf";
|
||||
return [NSString stringWithFormat:format, windowSize, smoothingCoeff, thresholdGain];
|
||||
}
|
||||
|
||||
void RTCInitFieldTrialDictionary(NSDictionary<NSString *, NSString *> *fieldTrials) {
|
||||
if (!fieldTrials) {
|
||||
RTCLogWarning(@"No fieldTrials provided.");
|
||||
return;
|
||||
}
|
||||
// Assemble the keys and values into the field trial string.
|
||||
// We don't perform any extra format checking. That should be done by the underlying WebRTC calls.
|
||||
NSMutableString *fieldTrialInitString = [NSMutableString string];
|
||||
for (NSString *key in fieldTrials) {
|
||||
NSString *fieldTrialEntry = [NSString stringWithFormat:@"%@/%@/", key, fieldTrials[key]];
|
||||
[fieldTrialInitString appendString:fieldTrialEntry];
|
||||
}
|
||||
size_t len = fieldTrialInitString.length + 1;
|
||||
gFieldTrialInitString.reset(new char[len]);
|
||||
if (![fieldTrialInitString getCString:gFieldTrialInitString.get()
|
||||
maxLength:len
|
||||
encoding:NSUTF8StringEncoding]) {
|
||||
RTCLogError(@"Failed to convert field trial string.");
|
||||
return;
|
||||
}
|
||||
webrtc::field_trial::InitFieldTrialsFromString(gFieldTrialInitString.get());
|
||||
}
|
||||
176
sdk/objc/Framework/Classes/Common/RTCFileLogger.mm
Normal file
176
sdk/objc/Framework/Classes/Common/RTCFileLogger.mm
Normal file
@ -0,0 +1,176 @@
|
||||
/*
|
||||
* 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 "WebRTC/RTCFileLogger.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "webrtc/rtc_base/checks.h"
|
||||
#include "webrtc/rtc_base/filerotatingstream.h"
|
||||
#include "webrtc/rtc_base/logging.h"
|
||||
#include "webrtc/rtc_base/logsinks.h"
|
||||
|
||||
NSString *const kDefaultLogDirName = @"webrtc_logs";
|
||||
NSUInteger const kDefaultMaxFileSize = 10 * 1024 * 1024; // 10MB.
|
||||
const char *kRTCFileLoggerRotatingLogPrefix = "rotating_log";
|
||||
|
||||
@implementation RTCFileLogger {
|
||||
BOOL _hasStarted;
|
||||
NSString *_dirPath;
|
||||
NSUInteger _maxFileSize;
|
||||
std::unique_ptr<rtc::FileRotatingLogSink> _logSink;
|
||||
}
|
||||
|
||||
@synthesize severity = _severity;
|
||||
@synthesize rotationType = _rotationType;
|
||||
@synthesize shouldDisableBuffering = _shouldDisableBuffering;
|
||||
|
||||
- (instancetype)init {
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(
|
||||
NSDocumentDirectory, NSUserDomainMask, YES);
|
||||
NSString *documentsDirPath = [paths firstObject];
|
||||
NSString *defaultDirPath =
|
||||
[documentsDirPath stringByAppendingPathComponent:kDefaultLogDirName];
|
||||
return [self initWithDirPath:defaultDirPath
|
||||
maxFileSize:kDefaultMaxFileSize];
|
||||
}
|
||||
|
||||
- (instancetype)initWithDirPath:(NSString *)dirPath
|
||||
maxFileSize:(NSUInteger)maxFileSize {
|
||||
return [self initWithDirPath:dirPath
|
||||
maxFileSize:maxFileSize
|
||||
rotationType:RTCFileLoggerTypeCall];
|
||||
}
|
||||
|
||||
- (instancetype)initWithDirPath:(NSString *)dirPath
|
||||
maxFileSize:(NSUInteger)maxFileSize
|
||||
rotationType:(RTCFileLoggerRotationType)rotationType {
|
||||
NSParameterAssert(dirPath.length);
|
||||
NSParameterAssert(maxFileSize);
|
||||
if (self = [super init]) {
|
||||
BOOL isDir = NO;
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
if ([fileManager fileExistsAtPath:dirPath isDirectory:&isDir]) {
|
||||
if (!isDir) {
|
||||
// Bail if something already exists there.
|
||||
return nil;
|
||||
}
|
||||
} else {
|
||||
if (![fileManager createDirectoryAtPath:dirPath
|
||||
withIntermediateDirectories:NO
|
||||
attributes:nil
|
||||
error:nil]) {
|
||||
// Bail if we failed to create a directory.
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
_dirPath = dirPath;
|
||||
_maxFileSize = maxFileSize;
|
||||
_severity = RTCFileLoggerSeverityInfo;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[self stop];
|
||||
}
|
||||
|
||||
- (void)start {
|
||||
if (_hasStarted) {
|
||||
return;
|
||||
}
|
||||
switch (_rotationType) {
|
||||
case RTCFileLoggerTypeApp:
|
||||
_logSink.reset(
|
||||
new rtc::FileRotatingLogSink(_dirPath.UTF8String,
|
||||
kRTCFileLoggerRotatingLogPrefix,
|
||||
_maxFileSize,
|
||||
_maxFileSize / 10));
|
||||
break;
|
||||
case RTCFileLoggerTypeCall:
|
||||
_logSink.reset(
|
||||
new rtc::CallSessionFileRotatingLogSink(_dirPath.UTF8String,
|
||||
_maxFileSize));
|
||||
break;
|
||||
}
|
||||
if (!_logSink->Init()) {
|
||||
LOG(LS_ERROR) << "Failed to open log files at path: "
|
||||
<< _dirPath.UTF8String;
|
||||
_logSink.reset();
|
||||
return;
|
||||
}
|
||||
if (_shouldDisableBuffering) {
|
||||
_logSink->DisableBuffering();
|
||||
}
|
||||
rtc::LogMessage::LogThreads(true);
|
||||
rtc::LogMessage::LogTimestamps(true);
|
||||
rtc::LogMessage::AddLogToStream(_logSink.get(), [self rtcSeverity]);
|
||||
_hasStarted = YES;
|
||||
}
|
||||
|
||||
- (void)stop {
|
||||
if (!_hasStarted) {
|
||||
return;
|
||||
}
|
||||
RTC_DCHECK(_logSink);
|
||||
rtc::LogMessage::RemoveLogToStream(_logSink.get());
|
||||
_hasStarted = NO;
|
||||
_logSink.reset();
|
||||
}
|
||||
|
||||
- (NSData *)logData {
|
||||
if (_hasStarted) {
|
||||
return nil;
|
||||
}
|
||||
NSMutableData* logData = [NSMutableData data];
|
||||
std::unique_ptr<rtc::FileRotatingStream> stream;
|
||||
switch(_rotationType) {
|
||||
case RTCFileLoggerTypeApp:
|
||||
stream.reset(
|
||||
new rtc::FileRotatingStream(_dirPath.UTF8String,
|
||||
kRTCFileLoggerRotatingLogPrefix));
|
||||
break;
|
||||
case RTCFileLoggerTypeCall:
|
||||
stream.reset(new rtc::CallSessionFileRotatingStream(_dirPath.UTF8String));
|
||||
break;
|
||||
}
|
||||
if (!stream->Open()) {
|
||||
return logData;
|
||||
}
|
||||
size_t bufferSize = 0;
|
||||
if (!stream->GetSize(&bufferSize) || bufferSize == 0) {
|
||||
return logData;
|
||||
}
|
||||
size_t read = 0;
|
||||
// Allocate memory using malloc so we can pass it direcly to NSData without
|
||||
// copying.
|
||||
std::unique_ptr<uint8_t[]> buffer(static_cast<uint8_t*>(malloc(bufferSize)));
|
||||
stream->ReadAll(buffer.get(), bufferSize, &read, nullptr);
|
||||
logData = [[NSMutableData alloc] initWithBytesNoCopy:buffer.release()
|
||||
length:read];
|
||||
return logData;
|
||||
}
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
- (rtc::LoggingSeverity)rtcSeverity {
|
||||
switch (_severity) {
|
||||
case RTCFileLoggerSeverityVerbose:
|
||||
return rtc::LS_VERBOSE;
|
||||
case RTCFileLoggerSeverityInfo:
|
||||
return rtc::LS_INFO;
|
||||
case RTCFileLoggerSeverityWarning:
|
||||
return rtc::LS_WARNING;
|
||||
case RTCFileLoggerSeverityError:
|
||||
return rtc::LS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
47
sdk/objc/Framework/Classes/Common/RTCLogging.mm
Normal file
47
sdk/objc/Framework/Classes/Common/RTCLogging.mm
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 "WebRTC/RTCLogging.h"
|
||||
|
||||
#include "webrtc/rtc_base/logging.h"
|
||||
|
||||
rtc::LoggingSeverity RTCGetNativeLoggingSeverity(RTCLoggingSeverity severity) {
|
||||
switch (severity) {
|
||||
case RTCLoggingSeverityVerbose:
|
||||
return rtc::LS_VERBOSE;
|
||||
case RTCLoggingSeverityInfo:
|
||||
return rtc::LS_INFO;
|
||||
case RTCLoggingSeverityWarning:
|
||||
return rtc::LS_WARNING;
|
||||
case RTCLoggingSeverityError:
|
||||
return rtc::LS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
void RTCLogEx(RTCLoggingSeverity severity, NSString* log_string) {
|
||||
if (log_string.length) {
|
||||
const char* utf8_string = log_string.UTF8String;
|
||||
LOG_V(RTCGetNativeLoggingSeverity(severity)) << utf8_string;
|
||||
}
|
||||
}
|
||||
|
||||
void RTCSetMinDebugLogLevel(RTCLoggingSeverity severity) {
|
||||
rtc::LogMessage::LogToDebug(RTCGetNativeLoggingSeverity(severity));
|
||||
}
|
||||
|
||||
NSString* RTCFileName(const char* file_path) {
|
||||
NSString* ns_file_path =
|
||||
[[NSString alloc] initWithBytesNoCopy:const_cast<char*>(file_path)
|
||||
length:strlen(file_path)
|
||||
encoding:NSUTF8StringEncoding
|
||||
freeWhenDone:NO];
|
||||
return ns_file_path.lastPathComponent;
|
||||
}
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2016 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.
|
||||
*/
|
||||
|
||||
#if defined(WEBRTC_IOS)
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface RTCUIApplicationStatusObserver : NSObject
|
||||
|
||||
+ (instancetype)sharedInstance;
|
||||
+ (void)prepareForUse;
|
||||
|
||||
- (BOOL)isApplicationActive;
|
||||
|
||||
@end
|
||||
|
||||
#endif // WEBRTC_IOS
|
||||
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright 2016 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.
|
||||
*/
|
||||
|
||||
#include "RTCUIApplicationStatusObserver.h"
|
||||
|
||||
#if defined(WEBRTC_IOS)
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#include "webrtc/rtc_base/checks.h"
|
||||
|
||||
@interface RTCUIApplicationStatusObserver ()
|
||||
|
||||
@property(nonatomic, assign) BOOL initialized;
|
||||
@property(nonatomic, assign) UIApplicationState state;
|
||||
|
||||
@end
|
||||
|
||||
@implementation RTCUIApplicationStatusObserver {
|
||||
BOOL _initialized;
|
||||
dispatch_block_t _initializeBlock;
|
||||
dispatch_semaphore_t _waitForInitializeSemaphore;
|
||||
UIApplicationState _state;
|
||||
|
||||
id<NSObject> _activeObserver;
|
||||
id<NSObject> _backgroundObserver;
|
||||
}
|
||||
|
||||
@synthesize initialized = _initialized;
|
||||
@synthesize state = _state;
|
||||
|
||||
+ (instancetype)sharedInstance {
|
||||
static id sharedInstance;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
sharedInstance = [[self alloc] init];
|
||||
});
|
||||
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
// Method to make sure observers are added and the initialization block is
|
||||
// scheduled to run on the main queue.
|
||||
+ (void)prepareForUse {
|
||||
__unused RTCUIApplicationStatusObserver *observer = [self sharedInstance];
|
||||
}
|
||||
|
||||
- (id)init {
|
||||
if (self = [super init]) {
|
||||
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
||||
__weak RTCUIApplicationStatusObserver *weakSelf = self;
|
||||
_activeObserver = [center addObserverForName:UIApplicationDidBecomeActiveNotification
|
||||
object:nil
|
||||
queue:[NSOperationQueue mainQueue]
|
||||
usingBlock:^(NSNotification *note) {
|
||||
weakSelf.state =
|
||||
[UIApplication sharedApplication].applicationState;
|
||||
}];
|
||||
|
||||
_backgroundObserver = [center addObserverForName:UIApplicationDidEnterBackgroundNotification
|
||||
object:nil
|
||||
queue:[NSOperationQueue mainQueue]
|
||||
usingBlock:^(NSNotification *note) {
|
||||
weakSelf.state =
|
||||
[UIApplication sharedApplication].applicationState;
|
||||
}];
|
||||
|
||||
_waitForInitializeSemaphore = dispatch_semaphore_create(1);
|
||||
_initialized = NO;
|
||||
_initializeBlock = dispatch_block_create(DISPATCH_BLOCK_INHERIT_QOS_CLASS, ^{
|
||||
weakSelf.state = [UIApplication sharedApplication].applicationState;
|
||||
weakSelf.initialized = YES;
|
||||
});
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), _initializeBlock);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
||||
[center removeObserver:_activeObserver];
|
||||
[center removeObserver:_backgroundObserver];
|
||||
}
|
||||
|
||||
- (BOOL)isApplicationActive {
|
||||
// NOTE: The function `dispatch_block_wait` can only legally be called once.
|
||||
// Because of this, if several threads call the `isApplicationActive` method before
|
||||
// the `_initializeBlock` has been executed, instead of multiple threads calling
|
||||
// `dispatch_block_wait`, the other threads need to wait for the first waiting thread
|
||||
// instead.
|
||||
if (!_initialized) {
|
||||
dispatch_semaphore_wait(_waitForInitializeSemaphore, DISPATCH_TIME_FOREVER);
|
||||
if (!_initialized) {
|
||||
long ret = dispatch_block_wait(_initializeBlock,
|
||||
dispatch_time(DISPATCH_TIME_NOW, 10.0 * NSEC_PER_SEC));
|
||||
RTC_DCHECK_EQ(ret, 0);
|
||||
}
|
||||
dispatch_semaphore_signal(_waitForInitializeSemaphore);
|
||||
}
|
||||
return _state == UIApplicationStateActive;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif // WEBRTC_IOS
|
||||
176
sdk/objc/Framework/Classes/Common/UIDevice+RTCDevice.mm
Normal file
176
sdk/objc/Framework/Classes/Common/UIDevice+RTCDevice.mm
Normal file
@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Copyright 2016 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 "WebRTC/UIDevice+RTCDevice.h"
|
||||
|
||||
#include <memory>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
@implementation UIDevice (RTCDevice)
|
||||
|
||||
+ (RTCDeviceType)deviceType {
|
||||
NSDictionary *machineNameToType = @{
|
||||
@"iPhone1,1": @(RTCDeviceTypeIPhone1G),
|
||||
@"iPhone1,2": @(RTCDeviceTypeIPhone3G),
|
||||
@"iPhone2,1": @(RTCDeviceTypeIPhone3GS),
|
||||
@"iPhone3,1": @(RTCDeviceTypeIPhone4),
|
||||
@"iPhone3,3": @(RTCDeviceTypeIPhone4Verizon),
|
||||
@"iPhone4,1": @(RTCDeviceTypeIPhone4S),
|
||||
@"iPhone5,1": @(RTCDeviceTypeIPhone5GSM),
|
||||
@"iPhone5,2": @(RTCDeviceTypeIPhone5GSM_CDMA),
|
||||
@"iPhone5,3": @(RTCDeviceTypeIPhone5CGSM),
|
||||
@"iPhone5,4": @(RTCDeviceTypeIPhone5CGSM_CDMA),
|
||||
@"iPhone6,1": @(RTCDeviceTypeIPhone5SGSM),
|
||||
@"iPhone6,2": @(RTCDeviceTypeIPhone5SGSM_CDMA),
|
||||
@"iPhone7,1": @(RTCDeviceTypeIPhone6Plus),
|
||||
@"iPhone7,2": @(RTCDeviceTypeIPhone6),
|
||||
@"iPhone8,1": @(RTCDeviceTypeIPhone6S),
|
||||
@"iPhone8,2": @(RTCDeviceTypeIPhone6SPlus),
|
||||
@"iPod1,1": @(RTCDeviceTypeIPodTouch1G),
|
||||
@"iPod2,1": @(RTCDeviceTypeIPodTouch2G),
|
||||
@"iPod3,1": @(RTCDeviceTypeIPodTouch3G),
|
||||
@"iPod4,1": @(RTCDeviceTypeIPodTouch4G),
|
||||
@"iPod5,1": @(RTCDeviceTypeIPodTouch5G),
|
||||
@"iPad1,1": @(RTCDeviceTypeIPad),
|
||||
@"iPad2,1": @(RTCDeviceTypeIPad2Wifi),
|
||||
@"iPad2,2": @(RTCDeviceTypeIPad2GSM),
|
||||
@"iPad2,3": @(RTCDeviceTypeIPad2CDMA),
|
||||
@"iPad2,4": @(RTCDeviceTypeIPad2Wifi2),
|
||||
@"iPad2,5": @(RTCDeviceTypeIPadMiniWifi),
|
||||
@"iPad2,6": @(RTCDeviceTypeIPadMiniGSM),
|
||||
@"iPad2,7": @(RTCDeviceTypeIPadMiniGSM_CDMA),
|
||||
@"iPad3,1": @(RTCDeviceTypeIPad3Wifi),
|
||||
@"iPad3,2": @(RTCDeviceTypeIPad3GSM_CDMA),
|
||||
@"iPad3,3": @(RTCDeviceTypeIPad3GSM),
|
||||
@"iPad3,4": @(RTCDeviceTypeIPad4Wifi),
|
||||
@"iPad3,5": @(RTCDeviceTypeIPad4GSM),
|
||||
@"iPad3,6": @(RTCDeviceTypeIPad4GSM_CDMA),
|
||||
@"iPad4,1": @(RTCDeviceTypeIPadAirWifi),
|
||||
@"iPad4,2": @(RTCDeviceTypeIPadAirCellular),
|
||||
@"iPad4,4": @(RTCDeviceTypeIPadMini2GWifi),
|
||||
@"iPad4,5": @(RTCDeviceTypeIPadMini2GCellular),
|
||||
@"i386": @(RTCDeviceTypeSimulatori386),
|
||||
@"x86_64": @(RTCDeviceTypeSimulatorx86_64),
|
||||
};
|
||||
|
||||
size_t size = 0;
|
||||
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
|
||||
std::unique_ptr<char[]> machine;
|
||||
machine.reset(new char[size]);
|
||||
sysctlbyname("hw.machine", machine.get(), &size, NULL, 0);
|
||||
NSString *machineName = [[NSString alloc] initWithCString:machine.get()
|
||||
encoding:NSUTF8StringEncoding];
|
||||
RTCDeviceType deviceType = RTCDeviceTypeUnknown;
|
||||
NSNumber *typeNumber = machineNameToType[machineName];
|
||||
if (typeNumber) {
|
||||
deviceType = static_cast<RTCDeviceType>(typeNumber.integerValue);
|
||||
}
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
+ (NSString *)stringForDeviceType:(RTCDeviceType)deviceType {
|
||||
switch (deviceType) {
|
||||
case RTCDeviceTypeUnknown:
|
||||
return @"Unknown";
|
||||
case RTCDeviceTypeIPhone1G:
|
||||
return @"iPhone 1G";
|
||||
case RTCDeviceTypeIPhone3G:
|
||||
return @"iPhone 3G";
|
||||
case RTCDeviceTypeIPhone3GS:
|
||||
return @"iPhone 3GS";
|
||||
case RTCDeviceTypeIPhone4:
|
||||
return @"iPhone 4";
|
||||
case RTCDeviceTypeIPhone4Verizon:
|
||||
return @"iPhone 4 Verizon";
|
||||
case RTCDeviceTypeIPhone4S:
|
||||
return @"iPhone 4S";
|
||||
case RTCDeviceTypeIPhone5GSM:
|
||||
return @"iPhone 5 (GSM)";
|
||||
case RTCDeviceTypeIPhone5GSM_CDMA:
|
||||
return @"iPhone 5 (GSM+CDMA)";
|
||||
case RTCDeviceTypeIPhone5CGSM:
|
||||
return @"iPhone 5C (GSM)";
|
||||
case RTCDeviceTypeIPhone5CGSM_CDMA:
|
||||
return @"iPhone 5C (GSM+CDMA)";
|
||||
case RTCDeviceTypeIPhone5SGSM:
|
||||
return @"iPhone 5S (GSM)";
|
||||
case RTCDeviceTypeIPhone5SGSM_CDMA:
|
||||
return @"iPhone 5S (GSM+CDMA)";
|
||||
case RTCDeviceTypeIPhone6Plus:
|
||||
return @"iPhone 6 Plus";
|
||||
case RTCDeviceTypeIPhone6:
|
||||
return @"iPhone 6";
|
||||
case RTCDeviceTypeIPhone6S:
|
||||
return @"iPhone 6S";
|
||||
case RTCDeviceTypeIPhone6SPlus:
|
||||
return @"iPhone 6S Plus";
|
||||
case RTCDeviceTypeIPodTouch1G:
|
||||
return @"iPod Touch 1G";
|
||||
case RTCDeviceTypeIPodTouch2G:
|
||||
return @"iPod Touch 2G";
|
||||
case RTCDeviceTypeIPodTouch3G:
|
||||
return @"iPod Touch 3G";
|
||||
case RTCDeviceTypeIPodTouch4G:
|
||||
return @"iPod Touch 4G";
|
||||
case RTCDeviceTypeIPodTouch5G:
|
||||
return @"iPod Touch 5G";
|
||||
case RTCDeviceTypeIPad:
|
||||
return @"iPad";
|
||||
case RTCDeviceTypeIPad2Wifi:
|
||||
return @"iPad 2 (WiFi)";
|
||||
case RTCDeviceTypeIPad2GSM:
|
||||
return @"iPad 2 (GSM)";
|
||||
case RTCDeviceTypeIPad2CDMA:
|
||||
return @"iPad 2 (CDMA)";
|
||||
case RTCDeviceTypeIPad2Wifi2:
|
||||
return @"iPad 2 (WiFi) 2";
|
||||
case RTCDeviceTypeIPadMiniWifi:
|
||||
return @"iPad Mini (WiFi)";
|
||||
case RTCDeviceTypeIPadMiniGSM:
|
||||
return @"iPad Mini (GSM)";
|
||||
case RTCDeviceTypeIPadMiniGSM_CDMA:
|
||||
return @"iPad Mini (GSM+CDMA)";
|
||||
case RTCDeviceTypeIPad3Wifi:
|
||||
return @"iPad 3 (WiFi)";
|
||||
case RTCDeviceTypeIPad3GSM_CDMA:
|
||||
return @"iPad 3 (GSM+CDMA)";
|
||||
case RTCDeviceTypeIPad3GSM:
|
||||
return @"iPad 3 (GSM)";
|
||||
case RTCDeviceTypeIPad4Wifi:
|
||||
return @"iPad 4 (WiFi)";
|
||||
case RTCDeviceTypeIPad4GSM:
|
||||
return @"iPad 4 (GSM)";
|
||||
case RTCDeviceTypeIPad4GSM_CDMA:
|
||||
return @"iPad 4 (GSM+CDMA)";
|
||||
case RTCDeviceTypeIPadAirWifi:
|
||||
return @"iPad Air (WiFi)";
|
||||
case RTCDeviceTypeIPadAirCellular:
|
||||
return @"iPad Air (Cellular)";
|
||||
case RTCDeviceTypeIPadMini2GWifi:
|
||||
return @"iPad Mini 2G (Wifi)";
|
||||
case RTCDeviceTypeIPadMini2GCellular:
|
||||
return @"iPad Mini 2G (Cellular)";
|
||||
case RTCDeviceTypeSimulatori386:
|
||||
return @"i386 Simulator";
|
||||
case RTCDeviceTypeSimulatorx86_64:
|
||||
return @"x86_64 Simulator";
|
||||
}
|
||||
return @"Unknown";
|
||||
}
|
||||
|
||||
+ (double)currentDeviceSystemVersion {
|
||||
return [self currentDevice].systemVersion.doubleValue;
|
||||
}
|
||||
|
||||
+ (BOOL)isIOS9OrLater {
|
||||
return [self currentDeviceSystemVersion] >= 9.0;
|
||||
}
|
||||
|
||||
@end
|
||||
76
sdk/objc/Framework/Classes/Common/helpers.h
Normal file
76
sdk/objc/Framework/Classes/Common/helpers.h
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_COMMON_HELPERS_H_
|
||||
#define WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_COMMON_HELPERS_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace webrtc {
|
||||
namespace ios {
|
||||
|
||||
bool CheckAndLogError(BOOL success, NSError* error);
|
||||
|
||||
NSString *NSStringFromStdString(const std::string& stdString);
|
||||
std::string StdStringFromNSString(NSString* nsString);
|
||||
|
||||
// Return thread ID as a string.
|
||||
std::string GetThreadId();
|
||||
|
||||
// Return thread ID as string suitable for debug logging.
|
||||
std::string GetThreadInfo();
|
||||
|
||||
// Returns [NSThread currentThread] description as string.
|
||||
// Example: <NSThread: 0x170066d80>{number = 1, name = main}
|
||||
std::string GetCurrentThreadDescription();
|
||||
|
||||
#if defined(WEBRTC_IOS)
|
||||
// Returns the current name of the operating system.
|
||||
std::string GetSystemName();
|
||||
|
||||
// Returns the current version of the operating system as a string.
|
||||
std::string GetSystemVersionAsString();
|
||||
|
||||
// Returns the version of the operating system in double representation.
|
||||
// Uses a cached value of the system version.
|
||||
double GetSystemVersion();
|
||||
|
||||
// Returns the device type.
|
||||
// Examples: ”iPhone” and ”iPod touch”.
|
||||
std::string GetDeviceType();
|
||||
#endif // defined(WEBRTC_IOS)
|
||||
|
||||
// Returns a more detailed device name.
|
||||
// Examples: "iPhone 5s (GSM)" and "iPhone 6 Plus".
|
||||
std::string GetDeviceName();
|
||||
|
||||
// Returns the name of the process. Does not uniquely identify the process.
|
||||
std::string GetProcessName();
|
||||
|
||||
// Returns the identifier of the process (often called process ID).
|
||||
int GetProcessID();
|
||||
|
||||
// Returns a string containing the version of the operating system on which the
|
||||
// process is executing. The string is string is human readable, localized, and
|
||||
// is appropriate for displaying to the user.
|
||||
std::string GetOSVersionString();
|
||||
|
||||
// Returns the number of processing cores available on the device.
|
||||
int GetProcessorCount();
|
||||
|
||||
#if defined(WEBRTC_IOS)
|
||||
// Indicates whether Low Power Mode is enabled on the iOS device.
|
||||
bool GetLowPowerModeEnabled();
|
||||
#endif
|
||||
|
||||
} // namespace ios
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_COMMON_HELPERS_H_
|
||||
135
sdk/objc/Framework/Classes/Common/helpers.mm
Normal file
135
sdk/objc/Framework/Classes/Common/helpers.mm
Normal file
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (c) 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 <Foundation/Foundation.h>
|
||||
#import <sys/sysctl.h>
|
||||
#if defined(WEBRTC_IOS)
|
||||
#import <UIKit/UIKit.h>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "webrtc/rtc_base/checks.h"
|
||||
#include "webrtc/rtc_base/logging.h"
|
||||
#include "webrtc/sdk/objc/Framework/Classes/Common/helpers.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace ios {
|
||||
|
||||
#if defined(WEBRTC_IOS)
|
||||
bool isOperatingSystemAtLeastVersion(double version) {
|
||||
return GetSystemVersion() >= version;
|
||||
}
|
||||
#endif
|
||||
|
||||
NSString* NSStringFromStdString(const std::string& stdString) {
|
||||
// std::string may contain null termination character so we construct
|
||||
// using length.
|
||||
return [[NSString alloc] initWithBytes:stdString.data()
|
||||
length:stdString.length()
|
||||
encoding:NSUTF8StringEncoding];
|
||||
}
|
||||
|
||||
std::string StdStringFromNSString(NSString* nsString) {
|
||||
NSData* charData = [nsString dataUsingEncoding:NSUTF8StringEncoding];
|
||||
return std::string(reinterpret_cast<const char*>([charData bytes]),
|
||||
[charData length]);
|
||||
}
|
||||
|
||||
bool CheckAndLogError(BOOL success, NSError* error) {
|
||||
if (!success) {
|
||||
NSString* msg =
|
||||
[NSString stringWithFormat:@"Error: %ld, %@, %@", (long)error.code,
|
||||
error.localizedDescription,
|
||||
error.localizedFailureReason];
|
||||
LOG(LS_ERROR) << StdStringFromNSString(msg);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO(henrika): see if it is possible to move to GetThreadName in
|
||||
// platform_thread.h and base it on pthread methods instead.
|
||||
std::string GetCurrentThreadDescription() {
|
||||
NSString* name = [NSString stringWithFormat:@"%@", [NSThread currentThread]];
|
||||
return StdStringFromNSString(name);
|
||||
}
|
||||
|
||||
#if defined(WEBRTC_IOS)
|
||||
std::string GetSystemName() {
|
||||
NSString* osName = [[UIDevice currentDevice] systemName];
|
||||
return StdStringFromNSString(osName);
|
||||
}
|
||||
|
||||
std::string GetSystemVersionAsString() {
|
||||
NSString* osVersion = [[UIDevice currentDevice] systemVersion];
|
||||
return StdStringFromNSString(osVersion);
|
||||
}
|
||||
|
||||
double GetSystemVersion() {
|
||||
static dispatch_once_t once_token;
|
||||
static double system_version;
|
||||
dispatch_once(&once_token, ^{
|
||||
system_version = [UIDevice currentDevice].systemVersion.doubleValue;
|
||||
});
|
||||
return system_version;
|
||||
}
|
||||
|
||||
std::string GetDeviceType() {
|
||||
NSString* deviceModel = [[UIDevice currentDevice] model];
|
||||
return StdStringFromNSString(deviceModel);
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string GetDeviceName() {
|
||||
size_t size;
|
||||
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
|
||||
std::unique_ptr<char[]> machine;
|
||||
machine.reset(new char[size]);
|
||||
sysctlbyname("hw.machine", machine.get(), &size, NULL, 0);
|
||||
return std::string(machine.get());
|
||||
}
|
||||
|
||||
std::string GetProcessName() {
|
||||
NSString* processName = [NSProcessInfo processInfo].processName;
|
||||
return StdStringFromNSString(processName);
|
||||
}
|
||||
|
||||
int GetProcessID() {
|
||||
return [NSProcessInfo processInfo].processIdentifier;
|
||||
}
|
||||
|
||||
std::string GetOSVersionString() {
|
||||
NSString* osVersion =
|
||||
[NSProcessInfo processInfo].operatingSystemVersionString;
|
||||
return StdStringFromNSString(osVersion);
|
||||
}
|
||||
|
||||
int GetProcessorCount() {
|
||||
return [NSProcessInfo processInfo].processorCount;
|
||||
}
|
||||
|
||||
#if defined(__IPHONE_9_0) && defined(__IPHONE_OS_VERSION_MAX_ALLOWED) \
|
||||
&& __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0
|
||||
bool GetLowPowerModeEnabled() {
|
||||
if (isOperatingSystemAtLeastVersion(9.0)) {
|
||||
// lowPoweredModeEnabled is only available on iOS9+.
|
||||
return [NSProcessInfo processInfo].lowPowerModeEnabled;
|
||||
}
|
||||
LOG(LS_WARNING) << "webrtc::ios::GetLowPowerModeEnabled() is not "
|
||||
"supported. Requires at least iOS 9.0";
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace ios
|
||||
} // namespace webrtc
|
||||
|
||||
Reference in New Issue
Block a user