| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Only compile this file in debug build. This gives us one more level of | 5 // Only compile this file in debug build. This gives us one more level of |
| 6 // protection that if the linker tries to link in strings/symbols appended to | 6 // protection that if the linker tries to link in strings/symbols appended to |
| 7 // "DLOG() <<" in release build (which it shouldn't), we'll get "undefined | 7 // "DLOG() <<" in release build (which it shouldn't), we'll get "undefined |
| 8 // reference" errors. | 8 // reference" errors. |
| 9 | 9 |
| 10 #include "media/cdm/ppapi/cdm_logging.h" | 10 #include "media/cdm/ppapi/cdm_logging.h" |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "build/build_config.h" |
| 13 | 13 |
| 14 #if defined(OS_WIN) | 14 #if defined(OS_WIN) |
| 15 #include <io.h> | 15 #include <io.h> |
| 16 #include <windows.h> | 16 #include <windows.h> |
| 17 #elif defined(OS_MACOSX) | 17 #elif defined(OS_MACOSX) |
| 18 #include <mach/mach.h> | 18 #include <mach/mach.h> |
| 19 #include <mach/mach_time.h> | 19 #include <mach/mach_time.h> |
| 20 #include <mach-o/dyld.h> | 20 #include <mach-o/dyld.h> |
| 21 #elif defined(OS_POSIX) | 21 #elif defined(OS_POSIX) |
| 22 #include <sys/syscall.h> | 22 #include <sys/syscall.h> |
| 23 #include <time.h> | 23 #include <time.h> |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 #if defined(OS_POSIX) | 26 #if defined(OS_POSIX) |
| 27 #include <errno.h> | 27 #include <errno.h> |
| 28 #include <pthread.h> | 28 #include <pthread.h> |
| 29 #include <stdlib.h> | 29 #include <stdlib.h> |
| 30 #include <stdio.h> | 30 #include <stdio.h> |
| 31 #include <string.h> | 31 #include <string.h> |
| 32 #include <unistd.h> | 32 #include <unistd.h> |
| 33 #endif | 33 #endif |
| 34 | 34 |
| 35 #include <stdint.h> |
| 36 |
| 35 #include <iomanip> | 37 #include <iomanip> |
| 36 #include <iostream> | 38 #include <iostream> |
| 37 | 39 |
| 38 namespace media { | 40 namespace media { |
| 39 | 41 |
| 40 #if !defined(NDEBUG) | 42 #if !defined(NDEBUG) |
| 41 | 43 |
| 42 namespace { | 44 namespace { |
| 43 | 45 |
| 44 // Helper functions to wrap platform differences. | 46 // Helper functions to wrap platform differences. |
| 45 | 47 |
| 46 int32 CurrentProcessId() { | 48 int32_t CurrentProcessId() { |
| 47 #if defined(OS_WIN) | 49 #if defined(OS_WIN) |
| 48 return GetCurrentProcessId(); | 50 return GetCurrentProcessId(); |
| 49 #elif defined(OS_POSIX) | 51 #elif defined(OS_POSIX) |
| 50 return getpid(); | 52 return getpid(); |
| 51 #endif | 53 #endif |
| 52 } | 54 } |
| 53 | 55 |
| 54 int32 CurrentThreadId() { | 56 int32_t CurrentThreadId() { |
| 55 // Pthreads doesn't have the concept of a thread ID, so we have to reach down | 57 // Pthreads doesn't have the concept of a thread ID, so we have to reach down |
| 56 // into the kernel. | 58 // into the kernel. |
| 57 #if defined(OS_LINUX) | 59 #if defined(OS_LINUX) |
| 58 return syscall(__NR_gettid); | 60 return syscall(__NR_gettid); |
| 59 #elif defined(OS_ANDROID) | 61 #elif defined(OS_ANDROID) |
| 60 return gettid(); | 62 return gettid(); |
| 61 #elif defined(OS_SOLARIS) | 63 #elif defined(OS_SOLARIS) |
| 62 return pthread_self(); | 64 return pthread_self(); |
| 63 #elif defined(OS_POSIX) | 65 #elif defined(OS_POSIX) |
| 64 return reinterpret_cast<int64>(pthread_self()); | 66 return reinterpret_cast<int64_t>(pthread_self()); |
| 65 #elif defined(OS_WIN) | 67 #elif defined(OS_WIN) |
| 66 return static_cast<int32>(::GetCurrentThreadId()); | 68 return static_cast<int32_t>(::GetCurrentThreadId()); |
| 67 #endif | 69 #endif |
| 68 } | 70 } |
| 69 | 71 |
| 70 uint64 TickCount() { | 72 uint64_t TickCount() { |
| 71 #if defined(OS_WIN) | 73 #if defined(OS_WIN) |
| 72 return GetTickCount(); | 74 return GetTickCount(); |
| 73 #elif defined(OS_MACOSX) | 75 #elif defined(OS_MACOSX) |
| 74 return mach_absolute_time(); | 76 return mach_absolute_time(); |
| 75 #elif defined(OS_POSIX) | 77 #elif defined(OS_POSIX) |
| 76 struct timespec ts; | 78 struct timespec ts; |
| 77 clock_gettime(CLOCK_MONOTONIC, &ts); | 79 clock_gettime(CLOCK_MONOTONIC, &ts); |
| 78 | 80 |
| 79 uint64 absolute_micro = | 81 uint64_t absolute_micro = static_cast<int64_t>(ts.tv_sec) * 1000000 + |
| 80 static_cast<int64>(ts.tv_sec) * 1000000 + | 82 static_cast<int64_t>(ts.tv_nsec) / 1000; |
| 81 static_cast<int64>(ts.tv_nsec) / 1000; | |
| 82 | 83 |
| 83 return absolute_micro; | 84 return absolute_micro; |
| 84 #endif | 85 #endif |
| 85 } | 86 } |
| 86 | 87 |
| 87 } // namespace | 88 } // namespace |
| 88 | 89 |
| 89 CdmLogMessage::CdmLogMessage(const char* file, int line) { | 90 CdmLogMessage::CdmLogMessage(const char* file, int line) { |
| 90 std::string filename(file); | 91 std::string filename(file); |
| 91 size_t last_slash_pos = filename.find_last_of("\\/"); | 92 size_t last_slash_pos = filename.find_last_of("\\/"); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 std::cout << std::endl; | 134 std::cout << std::endl; |
| 134 } | 135 } |
| 135 | 136 |
| 136 #endif // !defined(NDEBUG) | 137 #endif // !defined(NDEBUG) |
| 137 | 138 |
| 138 std::ostream& CdmLogStream::stream() { | 139 std::ostream& CdmLogStream::stream() { |
| 139 return std::cout; | 140 return std::cout; |
| 140 } | 141 } |
| 141 | 142 |
| 142 } // namespace media | 143 } // namespace media |
| OLD | NEW |