OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #if defined(WEBRTC_IOS) | 11 #if defined(WEBRTC_IOS) |
12 | 12 |
13 #if !defined(__has_feature) || !__has_feature(objc_arc) | 13 #import <AVFoundation/AVFoundation.h> |
14 #error "This file requires ARC support." | |
15 #endif | |
16 | |
17 #import <Foundation/Foundation.h> | 14 #import <Foundation/Foundation.h> |
18 #include <string.h> | 15 #include <pthread.h> |
19 | 16 |
20 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
21 #include "webrtc/typedefs.h" | 18 #include "webrtc/modules/utility/interface/helpers_ios.h" |
22 | 19 |
23 namespace webrtc { | 20 namespace webrtc { |
24 namespace test { | 21 namespace ios { |
25 | 22 |
26 // TODO(henrika): move to shared location. | 23 // TODO(henrika): move to shared location. |
27 // See https://code.google.com/p/webrtc/issues/detail?id=4773 for details. | 24 // See https://code.google.com/p/webrtc/issues/detail?id=4773 for details. |
28 NSString* NSStringFromStdString(const std::string& stdString) { | 25 NSString* NSStringFromStdString(const std::string& stdString) { |
29 // std::string may contain null termination character so we construct | 26 // std::string may contain null termination character so we construct |
30 // using length. | 27 // using length. |
31 return [[NSString alloc] initWithBytes:stdString.data() | 28 return [[NSString alloc] initWithBytes:stdString.data() |
32 length:stdString.length() | 29 length:stdString.length() |
33 encoding:NSUTF8StringEncoding]; | 30 encoding:NSUTF8StringEncoding]; |
34 } | 31 } |
35 | 32 |
36 std::string StdStringFromNSString(NSString* nsString) { | 33 std::string StdStringFromNSString(NSString* nsString) { |
37 NSData* charData = [nsString dataUsingEncoding:NSUTF8StringEncoding]; | 34 NSData* charData = [nsString dataUsingEncoding:NSUTF8StringEncoding]; |
38 return std::string(reinterpret_cast<const char*>([charData bytes]), | 35 return std::string(reinterpret_cast<const char*>([charData bytes]), |
39 [charData length]); | 36 [charData length]); |
40 } | 37 } |
41 | 38 |
42 // For iOS, resource files are added to the application bundle in the root | 39 bool CheckAndLogError(BOOL success, NSError* error) { |
43 // and not in separate folders as is the case for other platforms. This method | 40 if (!success) { |
44 // therefore removes any prepended folders and uses only the actual file name. | 41 NSLog(@"Error: %ld, %@", (long)error.code, error.localizedDescription); |
tkchin_webrtc
2015/07/06 03:46:29
I think it is better to stick with webrtc LOG macr
henrika_webrtc
2015/07/07 16:01:39
Done.
henrika_webrtc
2015/07/08 15:20:10
Not sure if my way is what you wanted. Hope it loo
tkchin_webrtc
2015/07/08 19:41:14
Yeah, just wanted LS_ERROR. Format is up to you, l
| |
45 std::string IOSResourcePath(std::string name, std::string extension) { | 42 return false; |
46 @autoreleasepool { | |
47 NSString* path = NSStringFromStdString(name); | |
48 NSString* fileName = path.lastPathComponent; | |
49 NSString* fileType = NSStringFromStdString(extension); | |
50 // Get full pathname for the resource identified by the name and extension. | |
51 NSString* pathString = [[NSBundle mainBundle] pathForResource:fileName | |
52 ofType:fileType]; | |
53 return StdStringFromNSString(pathString); | |
54 } | 43 } |
44 return true; | |
55 } | 45 } |
56 | 46 |
57 } // namespace test | 47 std::string GetCurrentThreadDescription() { |
48 NSString* name = [NSString stringWithFormat:@"%@", [NSThread currentThread]]; | |
tkchin_webrtc
2015/07/06 03:46:29
I would add these functions to logging.cc so that
henrika_webrtc
2015/07/07 16:01:39
Great idea, let me add support for GetThreadId as
henrika_webrtc
2015/07/08 15:20:10
Found a way. Done. Given new calls in the added un
| |
49 return StdStringFromNSString(name); | |
50 } | |
51 | |
52 std::string GetThreadId() { | |
53 char buf[21]; // Big enough to hold a kuint64max plus terminating NULL. | |
54 pid_t thread_id = pthread_mach_thread_np(pthread_self()); | |
55 CHECK_LT(snprintf(buf, sizeof(buf), "%i", thread_id), | |
56 static_cast<int>(sizeof(buf))) | |
57 << "Thread id is bigger than uint64??"; | |
58 return std::string(buf); | |
59 } | |
60 | |
61 std::string GetThreadInfo() { | |
62 return "@[tid=" + GetThreadId() + "]"; | |
63 } | |
64 | |
65 AVAudioSession* GetAudioSession() { | |
tkchin_webrtc
2015/07/06 03:46:29
Is this necessary since it's a one-liner?
henrika_webrtc
2015/07/07 16:01:39
Removed.
| |
66 // Implicit initialization happens when we obtain a reference to the | |
67 // AVAudioSession object. | |
68 return [AVAudioSession sharedInstance]; | |
69 } | |
70 | |
71 } // namespace ios | |
58 } // namespace webrtc | 72 } // namespace webrtc |
59 | 73 |
60 #endif // defined(WEBRTC_IOS) | 74 #endif // defined(WEBRTC_IOS) |
OLD | NEW |