Home | History | Annotate | Download | only in audio_device
      1 /*
      2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
      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 
     11 #include <assert.h>
     12 
     13 #include "webrtc/modules/audio_device/audio_device_utility.h"
     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 
     30 void AudioDeviceUtility::WaitForKey()
     31 {
     32 	_getch();
     33 }
     34 
     35 uint32_t AudioDeviceUtility::GetTimeInMS()
     36 {
     37 	return timeGetTime();
     38 }
     39 
     40 bool AudioDeviceUtility::StringCompare(
     41     const char* str1 , const char* str2,
     42     const uint32_t length)
     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 
     55 #include <stdio.h>      // getchar
     56 #include <string.h>     // strncasecmp
     57 #include <sys/time.h>   // gettimeofday
     58 #include <termios.h>    // tcgetattr
     59 #include <time.h>       // gettimeofday
     60 
     61 #include <unistd.h>
     62 
     63 namespace webrtc
     64 {
     65 
     66 void AudioDeviceUtility::WaitForKey()
     67 {
     68 
     69     struct termios oldt, newt;
     70 
     71     tcgetattr( STDIN_FILENO, &oldt );
     72 
     73     // we don't want getchar to echo!
     74 
     75     newt = oldt;
     76     newt.c_lflag &= ~( ICANON | ECHO );
     77     tcsetattr( STDIN_FILENO, TCSANOW, &newt );
     78 
     79     // catch any newline that's hanging around...
     80 
     81     // you'll have to hit enter twice if you
     82 
     83     // choose enter out of all available keys
     84 
     85     if (getchar() == '\n')
     86     {
     87         getchar();
     88     }
     89 
     90     tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
     91 }
     92 
     93 uint32_t AudioDeviceUtility::GetTimeInMS()
     94 {
     95     struct timeval tv;
     96     struct timezone tz;
     97     uint32_t val;
     98 
     99     gettimeofday(&tv, &tz);
    100     val = (uint32_t)(tv.tv_sec*1000 + tv.tv_usec/1000);
    101     return val;
    102 }
    103 
    104 bool AudioDeviceUtility::StringCompare(
    105     const char* str1 , const char* str2, const uint32_t length)
    106 {
    107     return (strncasecmp(str1, str2, length) == 0)?true: false;
    108 }
    109 
    110 }  // namespace webrtc
    111 
    112 #endif  // defined(WEBRTC_LINUX) || defined(WEBRTC_MAC)
    113