• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2011 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 #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_UTIL_UTILITY_H_
12 #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_UTIL_UTILITY_H_
13 
14 #include <stdio.h>
15 #include <stdlib.h>
16 
17 #if defined(__cplusplus)
18 extern "C" {
19 #endif
20 
21 #define OPEN_FILE_WB(filePtr, fullPath)                     \
22   do {                                                      \
23     if (fullPath != NULL) {                                 \
24       filePtr = fopen(fullPath, "wb");                      \
25       if (filePtr == NULL) {                                \
26         printf("could not open %s to write to.", fullPath); \
27         return -1;                                          \
28       }                                                     \
29     } else {                                                \
30       filePtr = NULL;                                       \
31     }                                                       \
32   } while (0)
33 
34 #define OPEN_FILE_AB(filePtr, fullPath)                     \
35   do {                                                      \
36     if (fullPath != NULL) {                                 \
37       filePtr = fopen(fullPath, "ab");                      \
38       if (filePtr == NULL) {                                \
39         printf("could not open %s to write to.", fullPath); \
40         return -1;                                          \
41       }                                                     \
42     } else {                                                \
43       filePtr = NULL;                                       \
44     }                                                       \
45   } while (0)
46 
47 #define OPEN_FILE_RB(filePtr, fullPath)                      \
48   do {                                                       \
49     if (fullPath != NULL) {                                  \
50       filePtr = fopen(fullPath, "rb");                       \
51       if (filePtr == NULL) {                                 \
52         printf("could not open %s to read from.", fullPath); \
53         return -1;                                           \
54       }                                                      \
55     } else {                                                 \
56       filePtr = NULL;                                        \
57     }                                                        \
58   } while (0)
59 
60 #define WRITE_FILE_D(bufferPtr, len, filePtr)      \
61   do {                                             \
62     if (filePtr != NULL) {                         \
63       double dummy[1000];                          \
64       int cntr;                                    \
65       for (cntr = 0; cntr < (len); cntr++) {       \
66         dummy[cntr] = (double)bufferPtr[cntr];     \
67       }                                            \
68       fwrite(dummy, sizeof(double), len, filePtr); \
69       fflush(filePtr);                             \
70     }                                              \
71   } while (0)
72 
73 typedef struct {
74   unsigned int whenPackGeneratedMs;
75   unsigned int whenPrevPackLeftMs;
76   unsigned int sendTimeMs;   /* milisecond */
77   unsigned int arrival_time; /* samples */
78   unsigned int sample_count; /* samples, also used as "send time stamp" */
79   unsigned int rtp_number;
80 } BottleNeckModel;
81 
82 void get_arrival_time(int current_framesamples, /* samples */
83                       size_t packet_size,       /* bytes */
84                       int bottleneck,           /* excluding headers; bits/s */
85                       BottleNeckModel* BN_data,
86                       short senderSampFreqHz,
87                       short receiverSampFreqHz);
88 
89 /* function for reading audio data from PCM file */
90 int readframe(short* data, FILE* inp, int length);
91 
92 short readSwitch(int argc, char* argv[], char* strID);
93 
94 double readParamDouble(int argc, char* argv[], char* strID, double defaultVal);
95 
96 int readParamInt(int argc, char* argv[], char* strID, int defaultVal);
97 
98 int readParamString(int argc,
99                     char* argv[],
100                     char* strID,
101                     char* stringParam,
102                     int maxSize);
103 
104 #if defined(__cplusplus)
105 }
106 #endif
107 
108 #endif
109