blob: b6c5c482536563cc531502013850c0d1c03bbdc9 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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.org12dc1a32013-08-05 16:22:53 +000011#include <assert.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000012
pbos@webrtc.org811269d2013-07-11 13:24:38 +000013#include "webrtc/modules/audio_device/audio_device_utility.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000014
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
27namespace webrtc
28{
29
niklase@google.com470e71d2011-07-07 08:21:25 +000030void AudioDeviceUtility::WaitForKey()
31{
32 _getch();
33}
34
pbos@webrtc.org25509882013-04-09 10:30:35 +000035uint32_t AudioDeviceUtility::GetTimeInMS()
niklase@google.com470e71d2011-07-07 08:21:25 +000036{
37 return timeGetTime();
38}
39
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000040bool AudioDeviceUtility::StringCompare(
41 const char* str1 , const char* str2,
pbos@webrtc.org25509882013-04-09 10:30:35 +000042 const uint32_t length)
niklase@google.com470e71d2011-07-07 08:21:25 +000043{
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.com470e71d2011-07-07 08:21:25 +000055#include <stdio.h> // getchar
pbos@webrtc.org811269d2013-07-11 13:24:38 +000056#include <string.h> // strncasecmp
57#include <sys/time.h> // gettimeofday
niklase@google.com470e71d2011-07-07 08:21:25 +000058#include <termios.h> // tcgetattr
pbos@webrtc.org811269d2013-07-11 13:24:38 +000059#include <time.h> // gettimeofday
niklase@google.com470e71d2011-07-07 08:21:25 +000060
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000061#include <unistd.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000062
63namespace webrtc
64{
65
66void AudioDeviceUtility::WaitForKey()
67{
68
xians@google.come74a9ea2011-08-30 08:27:02 +000069 struct termios oldt, newt;
niklase@google.com470e71d2011-07-07 08:21:25 +000070
xians@google.come74a9ea2011-08-30 08:27:02 +000071 tcgetattr( STDIN_FILENO, &oldt );
niklase@google.com470e71d2011-07-07 08:21:25 +000072
xians@google.come74a9ea2011-08-30 08:27:02 +000073 // we don't want getchar to echo!
niklase@google.com470e71d2011-07-07 08:21:25 +000074
xians@google.come74a9ea2011-08-30 08:27:02 +000075 newt = oldt;
76 newt.c_lflag &= ~( ICANON | ECHO );
77 tcsetattr( STDIN_FILENO, TCSANOW, &newt );
niklase@google.com470e71d2011-07-07 08:21:25 +000078
xians@google.come74a9ea2011-08-30 08:27:02 +000079 // catch any newline that's hanging around...
niklase@google.com470e71d2011-07-07 08:21:25 +000080
xians@google.come74a9ea2011-08-30 08:27:02 +000081 // you'll have to hit enter twice if you
niklase@google.com470e71d2011-07-07 08:21:25 +000082
xians@google.come74a9ea2011-08-30 08:27:02 +000083 // choose enter out of all available keys
niklase@google.com470e71d2011-07-07 08:21:25 +000084
xians@google.come74a9ea2011-08-30 08:27:02 +000085 if (getchar() == '\n')
86 {
87 getchar();
88 }
niklase@google.com470e71d2011-07-07 08:21:25 +000089
xians@google.come74a9ea2011-08-30 08:27:02 +000090 tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
niklase@google.com470e71d2011-07-07 08:21:25 +000091}
92
pbos@webrtc.org25509882013-04-09 10:30:35 +000093uint32_t AudioDeviceUtility::GetTimeInMS()
niklase@google.com470e71d2011-07-07 08:21:25 +000094{
95 struct timeval tv;
96 struct timezone tz;
pbos@webrtc.org25509882013-04-09 10:30:35 +000097 uint32_t val;
niklase@google.com470e71d2011-07-07 08:21:25 +000098
99 gettimeofday(&tv, &tz);
pbos@webrtc.org25509882013-04-09 10:30:35 +0000100 val = (uint32_t)(tv.tv_sec*1000 + tv.tv_usec/1000);
niklase@google.com470e71d2011-07-07 08:21:25 +0000101 return val;
102}
103
leozwang@webrtc.org28f39132012-03-01 18:01:48 +0000104bool AudioDeviceUtility::StringCompare(
pbos@webrtc.org25509882013-04-09 10:30:35 +0000105 const char* str1 , const char* str2, const uint32_t length)
niklase@google.com470e71d2011-07-07 08:21:25 +0000106{
107 return (strncasecmp(str1, str2, length) == 0)?true: false;
108}
109
110} // namespace webrtc
111
112#endif // defined(WEBRTC_LINUX) || defined(WEBRTC_MAC)