niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 11 | #include <assert.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
pbos@webrtc.org | 811269d | 2013-07-11 13:24:38 +0000 | [diff] [blame] | 13 | #include "webrtc/modules/audio_device/audio_device_utility.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 14 | |
| 15 | #if defined(_WIN32) |
| 16 | |
| 17 | // ============================================================================ |
| 18 | // Windows |
| 19 | // ============================================================================ |
| 20 | |
| 21 | #include <windows.h> |
| 22 | #include <conio.h> |
| 23 | #include <ctype.h> |
| 24 | #include <stdio.h> |
| 25 | #include <mmsystem.h> |
| 26 | |
| 27 | namespace webrtc |
| 28 | { |
| 29 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | void AudioDeviceUtility::WaitForKey() |
| 31 | { |
| 32 | _getch(); |
| 33 | } |
| 34 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 35 | uint32_t AudioDeviceUtility::GetTimeInMS() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | { |
| 37 | return timeGetTime(); |
| 38 | } |
| 39 | |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 40 | bool AudioDeviceUtility::StringCompare( |
| 41 | const char* str1 , const char* str2, |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 42 | const uint32_t length) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | { |
| 44 | return ((_strnicmp(str1, str2, length) == 0) ? true : false); |
| 45 | } |
| 46 | |
| 47 | } // namespace webrtc |
| 48 | |
| 49 | #elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) |
| 50 | |
| 51 | // ============================================================================ |
| 52 | // Linux & Mac |
| 53 | // ============================================================================ |
| 54 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | #include <stdio.h> // getchar |
pbos@webrtc.org | 811269d | 2013-07-11 13:24:38 +0000 | [diff] [blame] | 56 | #include <string.h> // strncasecmp |
| 57 | #include <sys/time.h> // gettimeofday |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | #include <termios.h> // tcgetattr |
pbos@webrtc.org | 811269d | 2013-07-11 13:24:38 +0000 | [diff] [blame] | 59 | #include <time.h> // gettimeofday |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 61 | #include <unistd.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | |
| 63 | namespace webrtc |
| 64 | { |
| 65 | |
| 66 | void AudioDeviceUtility::WaitForKey() |
| 67 | { |
| 68 | |
xians@google.com | e74a9ea | 2011-08-30 08:27:02 +0000 | [diff] [blame] | 69 | struct termios oldt, newt; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | |
xians@google.com | e74a9ea | 2011-08-30 08:27:02 +0000 | [diff] [blame] | 71 | tcgetattr( STDIN_FILENO, &oldt ); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | |
xians@google.com | e74a9ea | 2011-08-30 08:27:02 +0000 | [diff] [blame] | 73 | // we don't want getchar to echo! |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 74 | |
xians@google.com | e74a9ea | 2011-08-30 08:27:02 +0000 | [diff] [blame] | 75 | newt = oldt; |
| 76 | newt.c_lflag &= ~( ICANON | ECHO ); |
| 77 | tcsetattr( STDIN_FILENO, TCSANOW, &newt ); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | |
xians@google.com | e74a9ea | 2011-08-30 08:27:02 +0000 | [diff] [blame] | 79 | // catch any newline that's hanging around... |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | |
xians@google.com | e74a9ea | 2011-08-30 08:27:02 +0000 | [diff] [blame] | 81 | // you'll have to hit enter twice if you |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 82 | |
xians@google.com | e74a9ea | 2011-08-30 08:27:02 +0000 | [diff] [blame] | 83 | // choose enter out of all available keys |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | |
xians@google.com | e74a9ea | 2011-08-30 08:27:02 +0000 | [diff] [blame] | 85 | if (getchar() == '\n') |
| 86 | { |
| 87 | getchar(); |
| 88 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | |
xians@google.com | e74a9ea | 2011-08-30 08:27:02 +0000 | [diff] [blame] | 90 | tcsetattr( STDIN_FILENO, TCSANOW, &oldt ); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | } |
| 92 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 93 | uint32_t AudioDeviceUtility::GetTimeInMS() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 94 | { |
| 95 | struct timeval tv; |
| 96 | struct timezone tz; |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 97 | uint32_t val; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | |
| 99 | gettimeofday(&tv, &tz); |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 100 | val = (uint32_t)(tv.tv_sec*1000 + tv.tv_usec/1000); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 101 | return val; |
| 102 | } |
| 103 | |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 104 | bool AudioDeviceUtility::StringCompare( |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 105 | const char* str1 , const char* str2, const uint32_t length) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 106 | { |
| 107 | return (strncasecmp(str1, str2, length) == 0)?true: false; |
| 108 | } |
| 109 | |
| 110 | } // namespace webrtc |
| 111 | |
| 112 | #endif // defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) |