~ubuntu-branches/ubuntu/maverick/sflphone/maverick

« back to all changes in this revision

Viewing changes to sflphone-common/libs/pjproject/pjmedia/src/test/mips_test.c

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2010-06-03 15:59:46 UTC
  • Revision ID: james.westby@ubuntu.com-20100603155946-ybe8d8o8zx8lp0m8
Tags: upstream-0.9.8.3
ImportĀ upstreamĀ versionĀ 0.9.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: mips_test.c 2978 2009-10-30 01:18:28Z bennylp $ */
 
2
/* 
 
3
 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
 
4
 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 
19
 *
 
20
 *  Additional permission under GNU GPL version 3 section 7:
 
21
 *
 
22
 *  If you modify this program, or any covered work, by linking or
 
23
 *  combining it with the OpenSSL project's OpenSSL library (or a
 
24
 *  modified version of that library), containing parts covered by the
 
25
 *  terms of the OpenSSL or SSLeay licenses, Teluu Inc. (http://www.teluu.com)
 
26
 *  grants you additional permission to convey the resulting work.
 
27
 *  Corresponding Source for a non-source form of such a combination
 
28
 *  shall include the source code for the parts of OpenSSL used as well
 
29
 *  as that of the covered work.
 
30
 */
 
31
#include "test.h"
 
32
#include <pjmedia-codec.h>
 
33
 
 
34
/* Define your CPU MIPS here!! */
 
35
 
 
36
#ifndef CPU_IPS
 
37
    /*
 
38
    For complete table see:
 
39
    http://en.wikipedia.org/wiki/Million_instructions_per_second
 
40
 
 
41
    Processor                       IPS/MHz
 
42
    -------------------------------------------
 
43
    PowerPC G3                      2.253 MIPS/MHz
 
44
    Intel Pentium III               2.708 MIPS/MHz
 
45
    AMD Athlon                      2.967 MIPS/MHz
 
46
    Pentium 4 Extreme Edition       3.039 MIPS/MHz
 
47
    AMD Athlon FX-57                4.285 MIPS/MHz
 
48
 
 
49
 
 
50
    From: http://en.wikipedia.org/wiki/ARM_architecture
 
51
 
 
52
    Family      Arch            Core        IPS/MHz
 
53
    -------------------------------------------------------
 
54
    ARM7TDMI    ARMv4T          ARM7TDMI    0.892 MIPS/MHz
 
55
                                ARM710T     0.900 MIPS/MHz
 
56
                                ARM720T     1.003 MIPS/MHz
 
57
    ARM9TDMI    ARMv4T          ARM920T     1.111 MIPS/MHz
 
58
    ARM9E       ARMv5TEJ        ARM926EJ-S  1.100 MIPS/MHz
 
59
    XScale      ARMv5TE         PXA255      1.000 MIPS/MHz (?)
 
60
                                PXA27x      1.282 MIPS/MHz
 
61
    Cortex      ARMv7-A         Cortex-A8   2.000 MIPS/MHz
 
62
                                Cortex-A9   2.000 MIPS/MHz
 
63
                ARMv7-M         Cortex-M3   1.250 MIPS/MHz
 
64
    */
 
65
 
 
66
#   define CPU_MHZ          (2666)
 
67
#   define CPU_IPS          (3.039 * CPU_MHZ * MEGA)    /* P4 2.6GHz    */
 
68
 
 
69
//#   define CPU_MHZ        700
 
70
//#   define CPU_IPS        (700 * MEGA * 2.708)        /* P3 700Mhz    */
 
71
 
 
72
//#   define CPU_MHZ        180
 
73
//#   define CPU_IPS        (CPU_MHZ * MEGA * 1.1)      /* ARM926EJ-S */
 
74
 
 
75
//#   define CPU_MHZ        312
 
76
//#   define CPU_IPS        (CPU_MHZ * MEGA * 1.282)    /* Dell Axim PDA */
 
77
 
 
78
#endif
 
79
 
 
80
 
 
81
 
 
82
/* Sample speech data, 360ms length, encoded at 8Khz */
 
83
static const pj_int16_t ref_signal[] = {
 
84
         0,    -4,     0,     0,     1,     8,     8,     7,    12,    16,
 
85
        20,    29,    28,    48,    40,    48,    56,    76,    68,    76,
 
86
        96,   100,   104,   124,   117,   120,   144,   120,   136,   168,
 
87
       184,   188,   176,   216,   237,   235,   268,   301,   312,   316,
 
88
       367,   356,   384,   400,   344,   409,   392,   416,   380,   432,
 
89
       404,   444,   457,   456,   453,   512,   499,   512,   584,   584,
 
90
       544,   584,   608,   596,   552,   628,   600,   667,   728,   672,
 
91
       681,   755,   736,   764,   752,   764,   724,   769,   792,   840,
 
92
       820,   895,   841,   856,   852,   867,   944,   944,   939,   944,
 
93
       907,   928,   920,   960,   833,   881,  1004,  1007,  1000,  1057,
 
94
      1032,  1056,  1016,  1056,  1072,  1080,  1108,  1028,  1076,  1072,
 
95
       956,  1020,  1080,  1008,  1095,   992,  1056,  1028,   940,   976,
 
96
      1008,   940,   916,   968,   849,   868,   956,   940,   852,   892,
 
97
       968,   860,   777,   904,   825,   716,   764,   708,   635,   728,
 
98
       620,   648,   472,   724,   548,   448,   472,   372,   272,   437,
 
99
       419,   260,   237,   371,   196,   136,   177,   264,    49,   120,
 
100
        40,   124,    32,   136,    71,   120,   -95,   -20,   -76,  -140,
 
101
      -304,    12,  -148,  -168,  -192,   -63,  -212,   -36,  -288,  -232,
 
102
      -352,  -128,  -397,  -308,  -431,  -280,  -675,  -497,  -761,  -336,
 
103
      -760,  -471, -1088,  3013, -1596, -2000,   412,  -968,   213,  -668,
 
104
     -1096, -1048, -1039,  -825,  -580,  -612, -1056,  -888, -1324, -1064,
 
105
     -1164,  -819,  -940,  -780, -1236,  -688, -1931,    -1,  -464, -1804,
 
106
      1088, -1605, -1208,  -664,  -912,  -905,  -832, -1167,  -512,  1832,
 
107
      -924,   -60,   660, -2143,   248, -1660,  1496, -3464,  -164,  2072,
 
108
     -3040,   539,  2904,  2040, -3488,  2600,  2412,   820,  -551, -1401,
 
109
      1068,  -385,   397, -2112,  -980,  1064, -1244,  -736, -1335,   332,
 
110
     -1232, -1852,   -12, -1073, -1747, -3328,  -796, -2241, -4901, -3248,
 
111
     -3124, -3432, -5892, -3840, -3968, -4752, -5668, -4796, -3580, -5909,
 
112
     -5412, -6144, -5800, -5908, -6696, -6460, -8609, -3804, -5668, -8499,
 
113
     -4636, -5744, -2377, -7132, -3712, -7221, -6608,  1656,-11728, -6656,
 
114
     -3736,  -204, -8580, -4808,  -591, -5752,  -472,-10308, -2116,  -257,
 
115
     -4720, -7640, -1279,  6412,-16404, -1495,  6204, -8072,  -335, -3877,
 
116
     -2363,   464,   441, -6872,  1447,  7884,-13197,   936,  5009, -4416,
 
117
     -4445,  3956,  2280, -2844,  2036, -4285,   744,  4161, -7216,  5548,
 
118
       172,  -964, -2873,  3296,  2184, -7424,  4300,  1855,  1453,   -32,
 
119
      1585,  2160, -3440,   448,  4084, -1617,  1928,  3944, -3728,  4699,
 
120
      4556, -5556,  4096, 12928, -8287, -4320, 10739,  3172, -6068,  3684,
 
121
      6484,  1652, -1104, -1820, 11964, -1567, -4117,  7197,  5112, -2608,
 
122
     -2363,  7379,   936,  1596,   217,  6508,  3284,  3960,     0,  2691,
 
123
     11324, -6140,  6720,  6188,  3596, -1120,  5319,  9420, -9360,  5780,
 
124
      5135,   623, -1844,  3473,  8488, -4532,  2844,  8368,  4387, -8628,
 
125
     14180,  3196, -4852,  9092,  5540,  -600,  3088,  9864, -4992, 13984,
 
126
      2536, -5932, 10584,  7044, -2548,   388, 12597, -4776,  -247,  7728,
 
127
      6048, -6152,  6449,  9644, -8924,  8993,  6319,   877,  1108,  9804,
 
128
      -696,  2584,  9097, -3236,  4308,  5444, -2660,  -365, 11427, -6900,
 
129
      -803,  9388, -2444, -1068,  9160,   703, -5632, 12088, -2964, -1077,
 
130
      9804, -1263, -3679, 10161,  3337, -9755, 11601,  -160, -6421, 11008,
 
131
     -1952, -3411,  6792, -1665, -1344,  9116, -2545, -4100, 11577,   240,
 
132
     -3612,  5140,   603, -2100,  4284,  -784,   108,   968, -1244,  3500,
 
133
      3696,  -108,  3780,  3836,   -16,  4035,  2772,  1300,  -688,  1544,
 
134
      2268, -2144,  1156,  -564,   628, -1040,  -168,   491,   -72,  -408,
 
135
     -1812,  3460, -2083,   -72,   797,  1436, -3824,  1200,   308, -3512,
 
136
       572, -4060,   540,   -84, -4492, -1808,  4644, -4340, -3224,  5832,
 
137
     -2180, -2544,  1475,  2224, -2588,  1312,  1452, -1676,  -428, -1596,
 
138
      -860,  -116, -4000,  -364,   148, -3680, -2229, -1632,   236, -3004,
 
139
     -1917,   124, -1748, -2991,  -644,  -752, -3691, -1945, -3236, -2005,
 
140
     -4388, -2084, -2052, -3788, -3100,  -824, -2432, -3419, -1905, -2520,
 
141
     -2120, -2904, -2200, -1712, -2500, -2796, -1140, -2460, -2955,  -984,
 
142
     -1519,  -400,  -412,   356,    97,  -389,  1708,  -115,   452,  1140,
 
143
      -820,  1912,  1421, -1604,   556,  -632, -1991, -1409, -1904, -3604,
 
144
     -3292, -3405, -5584, -4891, -5436, -8940, -6280, -6604,-11764, -6389,
 
145
     -9081,-10928, -7784, -8492,-11263, -8292, -8829, -9632, -7828, -8920,
 
146
    -10224, -8912, -9836, -7313, -2916,-10240, -3748,  2860, -3308, -1236,
 
147
      6816,  4580,  1585,  9808,  7484,  5612,  6868,  7399,  6244,  5064,
 
148
      3823,  5159,  4940,   316,  4496,  4864,  1020,  3997,  6236,  3316,
 
149
      5712,  7032,  5568,  7329,  6135,  6904,  6431,  3768,  2580,  3724,
 
150
       504, -2213,  -661, -3320, -6660, -6696, -7971,-11208,-11316,-11784,
 
151
    -14212,-13651,-16312,-15876,-15984,-20283,-15168,  2073,-23888, -5839,
 
152
     13360, -8568,  1240, 18480, 11440,  4236, 23916, 15388, 14072, 15960,
 
153
     15064, 14840,  9395,  6981,  8584,  6540, -5453,  3568,   928, -7741,
 
154
     -5260,   -12, -5692, -7608,  1408,  2136,   776,  1775, 13568, 10992,
 
155
      8445, 17527, 21084, 14851, 15820, 23060, 15988, 11560, 15088, 14164,
 
156
      3376,  4059,  5212, -2520, -5891, -3596, -5080,-11752, -8861, -8124,
 
157
    -12104,-12076,-10028,-12333,-14180,-12516,-16036,-15559,-20416, -4240,
 
158
     -1077,-31052, 14840,  7405,-12660, 11896, 23572,  2829, 10932, 28444,
 
159
     10268, 15412, 13896, 16976, 10161,  6172,  5336,  9639, -2208, -7160,
 
160
      6544, -7188,-11280, -3308, -2428,-13447, -4880,  -824, -6664, -1436,
 
161
      4608,  7473,  2688, 14275, 14921, 13564, 15960, 20393, 16976, 14832,
 
162
     17540, 13524, 10744,  6876,  7328,  1772, -2340, -3528, -4516, -9576,
 
163
    -10872, -8640,-13092,-12825,-14076,-12192,-16620,-16207,-17004,-17548,
 
164
    -22088,-21700,-20320,  2836,-29576,-15860, 25811,-22555, -1868, 23624,
 
165
      9872, -4044, 29472, 16037,  7433, 16640, 14577, 13119,  3120,  7072,
 
166
      5828,  2285,-12087,  3180, -4031,-17840, -6349, -5300,-15452,-13852,
 
167
     -2659,-12079, -8568, -4492,  -672,   660,  5424,  3040, 16488, 11408,
 
168
      8996, 24976, 15120,  9940, 21400, 16885,  2624, 13939,  8644, -2815,
 
169
       332,  -160, -9312,-10172, -8320,-14033,-13056,-16200,-14113,-15712,
 
170
    -18153,-18664,-15937,-21692,-23500,-18597,-25948, -8597,-10368,-32768,
 
171
     16916, -4469,-17121, 18448, 14791, -4252, 18880, 22312,  4347, 17672,
 
172
     12672, 12964,  7384,  5404,  5176,  5668, -7692, -2356,  1148,-14872,
 
173
     -8920, -5593,-12753,-14600, -6429,-10608,-10372, -6757, -4857, -2044,
 
174
     -2720,  8995,  5088,  6516, 18384, 12853, 14952, 18048, 17439, 13920,
 
175
     15512, 10960, 10268,  5136,  2888,  1184, -4271, -7104, -7376, -9688,
 
176
    -14691,-11336,-14073,-17056,-14268,-16776,-17957,-19460,-18068,-23056,
 
177
    -20512,-24004, -3396,-19239,-27272, 22283,-16439, -7300, 19484,  9020,
 
178
     -1088, 22895, 15868,  9640, 17344, 11443, 17912,  6084,  6712,  9988,
 
179
      6104, -8559,  6403, -1196,-13152, -3632, -5388,-11924,-11973, -5748,
 
180
    -10292, -8420, -8468, -2256, -2829, -4132,  6344,  8785,  7444,  9508,
 
181
     22152, 15108, 13151, 22536, 20725, 10672, 17028, 17052,  5536,  6192,
 
182
      7484,   403, -5520, -2132, -5532,-11527,-10644, -9572,-13316,-16124,
 
183
    -10883,-15965,-17335,-17316,-16064,-20436,-21660, -8547, -3732,-32768,
 
184
     14672,  2213,-17200, 17964, 14387,  4232, 14800, 24296, 11288, 21368,
 
185
     11144, 22992, 13599,  6973, 14444, 12312, -2340,  4436,  8060, -9008,
 
186
     -2188, -2164, -5756,-10268, -5076, -6292, -6472, -7916, -2336,   327,
 
187
     -4492,  7144,  7696,  5691, 16352, 14244, 17764, 19852, 17296, 23160,
 
188
     18496, 14197, 19564, 13356,  5779, 10559,  4576, -2736,  -528, -3211,
 
189
     -8796, -8428, -9153,-10928,-13296,-12101,-12528,-14985,-16036,-14600,
 
190
    -15888,-18792,-19604, -3176, -8887,-29240, 21405, -6999, -9568, 19052,
 
191
     11952,  3037, 20055, 18376, 14501, 18672, 11023, 24776,  9488,  7921,
 
192
     15896, 11068, -4484,  9667,  4328, -7544, -1240, -1456, -7204, -9192,
 
193
     -5084, -5816, -6864, -9444,   276, -2316, -2852,  4640,  9600,  4412,
 
194
     13300, 16856, 12836, 18892, 17632, 18336, 16031, 14808, 13860, 12052,
 
195
      4284,  7372,  2623, -4284, -2172, -5036,-10163, -9788,-10384,-13205,
 
196
    -13180,-13453,-14460,-15540,-16580,-15472,-17961,-19148,-18824, -8063,
 
197
     -8620,-28300, 14323, -6748,-10204, 13100, 10548,   956, 16056, 14640,
 
198
     12680, 14171,  9672, 19741,  7524,  6615, 11825,  8788, -5080,  7224,
 
199
      1112, -6024, -4176, -1912, -7968, -8576, -7184, -5640, -8200, -9388,
 
200
     -1980, -2064, -4040,   240,  9327,  2192,  8451, 13604, 13124, 10057,
 
201
     16505, 15099, 11008, 10344, 12405,  7244,  1948,  4420,   132, -5312,
 
202
     -6072, -5772,-11608,-11756,-11660,-12684,-14335,-14548,-12400,-15268,
 
203
    -15277,-14949,-14889,-17376,-16640,-15656, -1128,-23476, -6084,  7268,
 
204
    -13880,   400, 10984,  1468,  4388, 14156,  6600, 13684,  5428, 12240,
 
205
     11815,  5460,  3663, 13164, -1269,   772,  3884,  -788, -5536, -1652,
 
206
     -4857, -4596, -7912, -6152, -4132, -7201, -6288, -1196, -1332, -4236,
 
207
      5020,  5020,  1648,  8572, 10224,  6256,  9816,  9404,  8124,  6644,
 
208
      4380,  4707,   636, -3300, -3208, -4395, -9716, -7540, -8175, -9980,
 
209
    -10237, -7680,-12172, -9981,-10459, -9712, -8451,-13008,-10196, -9308,
 
210
    -13109,-11700,-11636, -6143, -9472,-12117,   985, -3627, -6120,  2828,
 
211
      5268,    33,  6984,  6488,  7803,  6265,  6992,  8032,  7892,  3408,
 
212
      6021,  6224,  1016,  2053,  2632,  -648, -1936, -1796, -2504, -2865,
 
213
     -4400, -2524, -2388, -2524, -1432,   283,   696,  1180,  2912,  3996,
 
214
      3328,  3948,  5101,  4905,  3396,  3500,  3323,  2472,  -152,  1580,
 
215
      -860, -2109, -1331, -2460, -2960, -3396, -3476, -2616, -5172, -3352,
 
216
     -4036, -4440, -5480, -4028, -4220, -5876, -4656, -5233, -4621, -5465,
 
217
     -6417, -4936, -5092, -1860, -5651, -2699,  1273,  -920,  -888,  4279,
 
218
      3260,  2952,  5861,  5584,  5980,  6428,  5732,  6516,  6825,  4156,
 
219
      5000,  5071,  2669,  1764,  3273,  1148,  1312,   880,  1788,  1457,
 
220
      1299,   648,  3172,  2004,  1060,  3544,  1963,  2516,  3192,  3057,
 
221
      2936,  2892,  2896,  2224,  3188,  1524,  1541,  3120,   624,   917,
 
222
      1472,  1128,  -317,   687,   400, -1131,   164,  -812, -1232, -1120,
 
223
     -1311, -1364, -1500, -1660, -2380, -1835, -2456, -2468, -2168, -2785,
 
224
     -2824, -2408, -3316,  -552, -1204, -3153,  1188,  1572,  -752,  1756,
 
225
      4108,  2344,  3595,  4504,  4152,  4556,  4224,  3568,  4801,  3165,
 
226
      2776,  2808,  3233,  1300,  2411,  1536,  1828,  1424,  1576,  1412,
 
227
      1880,   895,  1601,  1916,  1763,   944,  2599,  1349,  1873,  1988,
 
228
      1744,  1956,  1667,  1548,  1812,  1048,  1528,   488,  1428,   832,
 
229
       232,   207,   632,  -152,  -520,    20,    15, -1580,  -841,  -948,
 
230
     -1120, -1455, -2004, -1244, -1344, -2236, -1312, -1344, -2156, -1420,
 
231
     -1856, -1637, -1847, -1460, -1780, -1372,  -508, -1256,  -752,     0,
 
232
       600,   859,  1156,  1532,  2364,  2204,  2059,  2269,  2240,  1928,
 
233
      1889,  2055,  1205,  1068,  1268,   892,  1371,  1036,   413,  1552,
 
234
       572,   -84,  1364,   260,   624,   820,  -160,  1492,   188,   204,
 
235
       796,   468,   552,   945,  -504,   697,  -936,   284, -1116,  -204,
 
236
     -1052,  -700, -1637,  -673, -2744,   -25, -2163, -1728, -1704, -1260,
 
237
     -2228, -2512,  -496, -3992,  -824, -2699, -2172, -2196, -1684, -3376,
 
238
      -540, -3047, -2220,  -376, -3416,     8, -2424,  -428, -1111,  -927,
 
239
        68, -1152,   640, -1308,   276,   536,   592,  -292,  2256,  -368,
 
240
       680,  2532,  -536,  1548,   780,   -92,  1596,    56,   444,   348,
 
241
       356,   500, -2168,  1527, -1632,  -677,  -980,  -904,  -868,   480,
 
242
     -1476,  -804, -1515,  -335, -2472, -1533, -1007,  -644, -2308, -1592,
 
243
      -104, -3860,  -984, -2364,     0, -1372, -2500, -2548,  1280, -3767,
 
244
     -2228,  -440, -2168, -2691,   628, -2013, -3773, -4292,  3796, -6452,
 
245
     -1268,  -156, -1320, -3779,  2612, -2924,  -864,  -619,  1227, -3408,
 
246
      3016,  -200, -1432,  2219,   -45, -1356,  5744, -2069,  4396,   488,
 
247
      3048,  -801,  3876,   857,  2064,    80,  4240,  -700,  1928,  1568,
 
248
     -1992,  3431,   600,  2221,   657, -3116,  5888, -2668,  4871, -7963,
 
249
      8016, -4907,  1264, -1969,  3688, -4396, -1276,  2448, -3760,  2156,
 
250
     -3039, -3064,   940,  2384, -7907,  4520, -2876,  2384, -5784,  4484,
 
251
     -5487,  1907, -4064,  1991, -3496,  1304, -4521,  5255, -4189,  1136,
 
252
     -2397,  -152,   768, -1671,  2084, -2709,  6413, -1460,  1952,   448,
 
253
      7064,  -444,  6256,   600,  8872,  2115,  4672,  7628,  6264,  2993,
 
254
      8920,  2876,  7744,  3956,  4848,  7236,   804,  7684,  5201,  2216,
 
255
      6360,  4900,  -340,  6885,  1307,  2468,  1884,  4812, -1376,  4740,
 
256
      1751,   135,  1124,  3284, -3228,  3968,  1748, -4453,  1587, -1515,
 
257
      3084, -3300, -2548,  -544,  -296,   396, -7808,  4956, -5164,  -292,
 
258
     -4947,   212, -4055,  -108, -4301, -2088, -2912,  3016,   952, -1888,
 
259
      4972,  4441,  6136,  1464,  9387,  4137,  6812,  6281,  2440,  6940,
 
260
      3928,  2704, -1204,  4260, -2289,  -712, -1768,  -383, -1195,   920,
 
261
     -1200,  -336,  4372,   720,  4392,  1291,  5819,  4528,  7532,   992,
 
262
      8176,  5588,  2760,  2836,  3412,  1132,   531,  2236, -5044,   621,
 
263
     -2916, -3964, -5849,  -864, -6300,-10019, -3964, -5524, -7004, -6833,
 
264
     -7236, -9484, -2528,-10112,-12900, -4199, -8580,-12427,-10924, -8604,
 
265
    -11520, -9636, -6560, -1647, -6948,  -460,  1752,  2952,  4196,  4360,
 
266
      4215,  8156,  4528,  2464,  2500,  3299, -2224, -3812, -2568, -5875,
 
267
     -5556, -7728, -8288, -5765, -6448, -7620, -5288, -2680, -4368,  -972,
 
268
       472,  1716,  2467,  4408,  5141,  4724,  7316,  4132,  3493,  5935,
 
269
      3564,    96,  1068,   868, -2160, -2736, -3449, -5428, -3339, -5200,
 
270
     -7156, -4189, -7928, -8064, -7532, -7999,-12124, -8509, -9888,-12420,
 
271
    -13568,-13187,-15384,-14996,-15152,-15284,-17059,-15292,-11792, -1160,
 
272
     -7300, -8284,  7237,  7241,  1616,  6327, 12064,  7920,  9564,  3556,
 
273
      4612,  6980,   261, -6365, -2028, -1701,-10136, -9573, -6901, -7747,
 
274
     -7868, -8076, -6123, -1508,  -100, -3048,  2004,  6704,  4507,  3256,
 
275
      9432,  8672,  7673,  6804,  7632,  8777,  6908,  3332,  3771,  6552,
 
276
      3153,   400,  3029,  4388,  1328,   160,  2304,  2023,  1325, -2640,
 
277
     -2356, -1544, -3436, -8584, -6939, -7180,-10455,-12928,-12296,-14653,
 
278
    -15243,-16436,-15240,-16672,-15476,-14628,  7004, -1360,-10100, 16344,
 
279
     18300,  9108, 12869, 22541, 16119, 17856, 10697,  6720, 12128,  6904,
 
280
     -8184, -3440,  2592,-10440,-11735, -4739, -4455, -5457, -2432, -1476,
 
281
      4520, 10045,  5512,  7988, 17032, 15052,  9211, 13309, 14624, 10324,
 
282
     10488,  7809,  6908,  9896,  5861,  3284,  8348, 10505,  5189,  8144,
 
283
     13280, 11732, 10035, 12559, 12104, 12456, 10148,  6520,  5944,  5603,
 
284
     -1848, -4196, -2544, -5876,-11416,-10032,-10248,-12753,-13344,-14900,
 
285
    -14320,-11265,-14220,-17067, -1440, 20120, -9884,  2783, 32220, 22208,
 
286
      9032, 22661, 26820, 19916, 17747,  5288,  8628, 14293, -3331,-15672,
 
287
      1252,  -324,-18236,-11592, -1172, -3384, -3864,  1052,  3640, 13099,
 
288
     13691,  6520, 14320, 22856, 12887,  7152, 14764, 13276,  4060,  2568,
 
289
      2268,  2224,  3312, -3336,  -875,  9000,  6180,  1872, 10851, 17464,
 
290
     12312, 11197, 15388, 17816, 12024,  8332,  7119,  8096,  1608, -5611,
 
291
     -5964, -4729,-11317,-14784,-12833,-11272,-14888,-16128,-15012,-12028,
 
292
    -14472,-16227,-15356,-14484,-15056, 11496,   352,-14108, 19216, 24616,
 
293
      3724,  7872, 25948, 13832,  9680,  7492,  2052,  5220,  1188,-16112,
 
294
    -11340,   703,-15400,-21572, -5816, -3320,-12072, -5664,  2296,  3101,
 
295
      6708,  5396,  5735, 13601, 12040,  1924,  6071, 10420,   984, -4904,
 
296
      -204, -1945, -6229, -7460, -5636,  2864,  -476, -2832,  6104, 13160,
 
297
      7151,  7148, 13063, 13596,  8796,  5092,  5976,  5668,  -431, -7624,
 
298
     -6741, -5676,-14332,-18700,-13396,-12387,-18576,-17516,-14184,-14124,
 
299
    -15972,-17456,-16323,-14712,-18056,-23213,-10744, 12016,-14824,-12636,
 
300
     21656, 14112, -4085,  9255, 20864,  8196,  6384,  1223,  2244,  5304,
 
301
     -6660,-19192, -4961, -2875,-22564,-18400, -3220, -8488,-14544, -5040,
 
302
      -324,   820,  2732,   628,  5484, 11924,  4813,  -852,  8656,  7160,
 
303
     -3924, -2955,  1337, -3268, -7359, -2552, -2528,  -532,   128,   411,
 
304
      5324,  9301,  5601,  6200, 11684, 10072,  4924,  5508,  6660,  1568,
 
305
     -2332, -4268, -5628, -7987,-12004,-13760,-11567,-12104,-16539,-14437,
 
306
    -12012,-14309,-16736,-14573,-13604,-15468,-18204,-19103, -9140, 10132,
 
307
    -13631, -9568, 22580, 13756, -3548, 12112, 23891,  8144,  5964,  7240,
 
308
      7216,  4284, -4800,-11761, -1308, -3044,-19584,-13808,  -759, -7968,
 
309
    -14524, -1503,  3072,  -396,  1936,  5900,  9264, 10769,  7240,  5961,
 
310
     13112,  8788,   660,  2807,  7980,  -449, -2477,  3940,  2792,  1584,
 
311
      2791,  5603,  7528,  9692,  5924,  9123, 15240,  9636,  4924, 11044,
 
312
     11113,   956,   756,  2812, -1832, -6920, -7120, -7192, -7711, -9717,
 
313
    -12704, -8736, -7508,-12067,-13176, -8133, -9304,-13160,-13437,-13268,
 
314
     -4084, 11400,-12785,  -700, 24992, 12168, -1268, 19404, 25183,  8373,
 
315
     10256, 13664, 11200,  5879,   -60, -3656,  4556, -2972,-14688, -4932,
 
316
      2432, -9279,-10691,  4280,  3180, -2444,  4088,  9992,  9176,  9156,
 
317
      9520, 11164, 14484,  8608,  4919, 10556,  9792,  2740,  3456,  8840,
 
318
      6424,  2348,  5696,  9420,  6596,  5380,  8364, 10952,  8499,  6800,
 
319
      8728,  9641,  5412,  2340,  3596,  2039, -2864, -5489, -3616, -5596,
 
320
     -9232, -8744, -7788, -9860,-11104, -9356, -9464,-11188,-11312,-11036,
 
321
    -11736,-13564, -6016,  8744,-11784, -1196, 18972,  9512,  -572, 17407,
 
322
     20316,  7472,  9784, 13369,  8952,  5092,  1003, -2004,  2755, -3952,
 
323
    -12761, -4648,  -744,-11667,-10240,  1556, -1572, -5872,  2196,  6011,
 
324
      3900,  5384,  7529,  8924,  9629,  6324,  5744,  9484,  7829,  3420,
 
325
      4384,  8644,  4360,  1500,  5248,  5921,  2200,  2564,  5212,  5037,
 
326
      2849,  2836,  3985,  3952,   875,  -560,   416, -1052, -5228, -5185,
 
327
     -4996, -7820, -9616, -9076,-10644,-11239,-11816,-12360,-12228,-12420,
 
328
    -13560,-12940,-13044,-15648,-11664,  1945, -9676, -9088,  9676,  6708,
 
329
     -3048,  8185, 15520,  4620,  5764, 10716,  6584,  2684,  2276, -1436,
 
330
       -56, -2948, -9140, -6611, -2868, -9897,-10565, -2012, -3948, -7916,
 
331
     -1440,  2420,  -241,  1164,  4428,  4932,  5461,  3884,  4476,  6620,
 
332
      7724,  1779,  3172,  8256,  3132,  -749,  5192,  4300, -1388,  1192,
 
333
      3575,   789,  -228,  1185,   995,   937,  -952, -2624,  -449, -1992,
 
334
     -6204, -4648, -3000, -7604, -8536, -5868, -9024,-10507,-10064, -9296,
 
335
    -12896,-11120,-11776,-13288,-14137,-12668,-15780,-14157, -8392, -7444,
 
336
    -11156, -2300,  2828, -1747,  1164,  8152,  6280,  4876,  7912,  7604,
 
337
      5609,  5164,  2600,  1620,  1592, -3237, -4441, -2068, -5052, -8268,
 
338
     -4503, -3304, -6332, -4460,  -388,  -297,  -319,  1911,  4071,  4272,
 
339
      4659,  8368,  6933,  6720,  8764,  8640,  6412,  6384,  5927,  3820,
 
340
      3488,  2648,  1104,  1220,   884,  -692,   327,   616,  -972,  -160,
 
341
       713,  -593,  -652,   179,  -651, -2005,  -656, -1536, -2968, -3748,
 
342
     -2640, -5052, -5548, -3476, -6151, -6388, -5168, -6099, -7416, -5752,
 
343
     -7579, -8220, -8312, -8472, -5287, -8056, -3527, -2356, -1704,  1892,
 
344
      2408,  2893,  5965,  8121,  5136,  8480,  8928,  7364,  6408,  7960,
 
345
      4315,  4392,  3864,  1353,   928,  1436, -1480,  -488,  1640,  -380,
 
346
       -36,  3420,  4044,  4432,  5185,  8044,  8740,  7983,  7912,  9588,
 
347
      8588,  6804,  6944,  6700,  4308,  2852,  3252,  2192,  -136,   876,
 
348
      1008,   244,   160,   205,   992,  1684,  -136,   984,  3312,   853,
 
349
      -772,  2372,   436, -3008, -1024,  -136, -3800, -2263, -3212, -2749,
 
350
     -3688, -2424, -5372, -2136, -3288, -4952, -3596, -2028, -4640, -5797,
 
351
     -2696, -4040, -7152, -4055, -2568, -6460, -4228, -1092, -2780, -2492,
 
352
       468,  -235,  1620,  3500,  2040,  2840,  6300,  4488,  2488,  5707,
 
353
      5576,  3537,  2291,  4301,  2844,  3364,  1153,  2500,  3340,  3160,
 
354
      1224,  3220,  4016,  2228,  1788,  4199,  3604,  2096,  1763,  3237,
 
355
      2044,  -564,  1280,   876,  -584, -1904,    24,   -60, -2948, -1440,
 
356
     -1228, -1824, -2092, -1945, -3912,  -227, -2411, -3219, -2252, -1808,
 
357
     -3044, -1035, -3092, -1456, -3724, -2284, -3149, -3028, -2788, -1804,
 
358
     -3360, -1276, -4097, -2531, -2248, -1635, -3215, -2376, -2468, -2596,
 
359
     -2825, -2792, -1980, -4036, -1721, -2059, -4117,   364, -1452, -2772,
 
360
     -1336,   480, -1043,   244, -2904,   924, -1329,   968, -1891,   523,
 
361
      -624,  -464,  -564,   187,  -852,   584,  -764,  -260,  -147,   160,
 
362
       339,   -32,   936,  -896,   288,   136,    56,   -36,  -736,  -683,
 
363
      -332,   696, -2319,  -259,   564, -2196,  -860,  1108, -2177,  -728,
 
364
      1344, -2520,  -440,  1080,  -780, -3513,  3272, -1635, -1597,  -188,
 
365
       744, -1944,   140,  -636, -1644,  -141,  -596, -1132,  -816,  1168,
 
366
     -2836,   196,   312,   136, -1381,   628,  -223,  -368,  -425,   604,
 
367
      -776,   595,  -628,  -128,  -884,   960, -1092,    76,   144,     8,
 
368
       161,  -504,   760,  -808,   336,   185,   100,   404,   120,   236,
 
369
        68,  -148,   -64,   312,   320,  -560,   117,   -28,   236,  -231,
 
370
       -92,    60,   356,  -176,   176,   212,   124,   -57,   -76,   168,
 
371
        88,  -140,   -37,   160,     0,   -92,    96,    24,   -84,     0,
 
372
};
 
373
 
 
374
#define THIS_FILE           "mips_test.c"
 
375
#define DURATION            5000
 
376
#define PTIME               20  /* MUST be 20! */
 
377
#define MEGA                1000000
 
378
#define GIGA                1000000000
 
379
 
 
380
enum op
 
381
{
 
382
    OP_GET  = 1,
 
383
    OP_PUT  = 2,
 
384
    OP_GET_PUT = 4,
 
385
    OP_PUT_GET = 8
 
386
};
 
387
 
 
388
enum clock_rate
 
389
{
 
390
    K8  = 1,
 
391
    K16 = 2,
 
392
    K32 = 4,
 
393
};
 
394
 
 
395
 
 
396
struct test_entry
 
397
{
 
398
    const char      *title;
 
399
    unsigned         valid_op;
 
400
    unsigned         valid_clock_rate;
 
401
 
 
402
    pjmedia_port*  (*init)(pj_pool_t *pool,
 
403
                          unsigned clock_rate,
 
404
                          unsigned channel_count,
 
405
                          unsigned samples_per_frame,
 
406
                          unsigned flags,
 
407
                          struct test_entry *);
 
408
    void           (*custom_run)(struct test_entry*);
 
409
    void           (*custom_deinit)(struct test_entry*);
 
410
 
 
411
    void            *pdata[4];
 
412
    unsigned         idata[4];
 
413
};
 
414
 
 
415
 
 
416
/***************************************************************************/
 
417
/* pjmedia_port to supply with continuous frames */
 
418
static pjmedia_port* create_gen_port(pj_pool_t *pool,
 
419
                                     unsigned clock_rate,
 
420
                                     unsigned channel_count,
 
421
                                     unsigned samples_per_frame,
 
422
                                     unsigned pct_level)
 
423
{
 
424
    pjmedia_port *port;
 
425
    pj_status_t status;
 
426
 
 
427
    if (pct_level == 100 && channel_count==1) {
 
428
        status = pjmedia_mem_player_create(pool, ref_signal, 
 
429
                                           sizeof(ref_signal), clock_rate, 
 
430
                                           channel_count, samples_per_frame,
 
431
                                           16, 0, &port);
 
432
    } else {
 
433
        pj_int16_t *buf;
 
434
        unsigned c;
 
435
 
 
436
        buf = (pj_int16_t*)
 
437
              pj_pool_alloc(pool, sizeof(ref_signal)*channel_count);
 
438
        for (c=0; c<channel_count; ++c) {
 
439
            unsigned i;
 
440
            pj_int16_t *p;
 
441
 
 
442
            p = buf+c;
 
443
            for (i=0; i<PJ_ARRAY_SIZE(ref_signal); ++i) {
 
444
                *p = (pj_int16_t)(ref_signal[i] * pct_level / 100);
 
445
                p += channel_count;
 
446
            }
 
447
        }
 
448
        status = pjmedia_mem_player_create(pool, buf, 
 
449
                                           sizeof(ref_signal)*channel_count, 
 
450
                                           clock_rate,  channel_count, 
 
451
                                           samples_per_frame,
 
452
                                           16, 0, &port);
 
453
    }
 
454
 
 
455
    return status==PJ_SUCCESS? port : NULL;
 
456
}
 
457
 
 
458
/***************************************************************************/
 
459
static pjmedia_port* gen_port_test_init(pj_pool_t *pool,
 
460
                                        unsigned clock_rate,
 
461
                                        unsigned channel_count,
 
462
                                        unsigned samples_per_frame,
 
463
                                        unsigned flags,
 
464
                                        struct test_entry *te)
 
465
{
 
466
    PJ_UNUSED_ARG(flags);
 
467
    PJ_UNUSED_ARG(te);
 
468
    return create_gen_port(pool, clock_rate, channel_count, samples_per_frame,
 
469
                           100);
 
470
}
 
471
 
 
472
 
 
473
/***************************************************************************/
 
474
static pjmedia_port* init_conf_port(unsigned nb_participant,
 
475
                                    pj_pool_t *pool,
 
476
                                    unsigned clock_rate,
 
477
                                    unsigned channel_count,
 
478
                                    unsigned samples_per_frame,
 
479
                                    unsigned flags,
 
480
                                    struct test_entry *te)
 
481
{
 
482
    pjmedia_conf *conf;
 
483
    unsigned i;
 
484
    pj_status_t status;
 
485
 
 
486
    PJ_UNUSED_ARG(flags);
 
487
    PJ_UNUSED_ARG(te);
 
488
 
 
489
    /* Create conf */
 
490
    status = pjmedia_conf_create(pool, 2+nb_participant*2, clock_rate, 
 
491
                                 channel_count, samples_per_frame, 16, 
 
492
                                 PJMEDIA_CONF_NO_DEVICE, &conf);
 
493
    if (status != PJ_SUCCESS)
 
494
        return NULL;
 
495
 
 
496
    for (i=0; i<nb_participant; ++i) {
 
497
        pjmedia_port *gen_port, *null_port;
 
498
        unsigned slot1, slot2;
 
499
 
 
500
        /* Create gen_port for source audio */
 
501
        gen_port = create_gen_port(pool, clock_rate, channel_count,
 
502
                                   samples_per_frame, 100 / nb_participant);
 
503
        if (!gen_port)
 
504
            return NULL;
 
505
 
 
506
        /* Add port */
 
507
        status = pjmedia_conf_add_port(conf, pool, gen_port, NULL, &slot1);
 
508
        if (status != PJ_SUCCESS)
 
509
            return NULL;
 
510
 
 
511
        /* Connect gen_port to sound dev */
 
512
        status = pjmedia_conf_connect_port(conf, slot1, 0, 0);
 
513
        if (status != PJ_SUCCESS)
 
514
            return NULL;
 
515
 
 
516
        /* Create null sink frame */
 
517
        status = pjmedia_null_port_create(pool, clock_rate, channel_count,
 
518
                                          samples_per_frame, 16, &null_port);
 
519
        if (status != PJ_SUCCESS)
 
520
            return NULL;
 
521
 
 
522
        /* add null port */
 
523
        status = pjmedia_conf_add_port(conf, pool, null_port, NULL, &slot2);
 
524
        if (status != PJ_SUCCESS)
 
525
            return NULL;
 
526
 
 
527
        /* connect sound to null sink port */
 
528
        status = pjmedia_conf_connect_port(conf, 0, slot2, 0);
 
529
        if (status != PJ_SUCCESS)
 
530
            return NULL;
 
531
 
 
532
        /* connect gen_port to null sink port */
 
533
#if 0
 
534
        status = pjmedia_conf_connect_port(conf, slot1, slot2, 0);
 
535
        if (status != PJ_SUCCESS)
 
536
            return NULL;
 
537
#endif  
 
538
    }
 
539
 
 
540
    return pjmedia_conf_get_master_port(conf);
 
541
}
 
542
 
 
543
 
 
544
/***************************************************************************/
 
545
/* Benchmark conf with 1 participant, no mixing */
 
546
static pjmedia_port* conf1_test_init(pj_pool_t *pool,
 
547
                                     unsigned clock_rate,
 
548
                                     unsigned channel_count,
 
549
                                     unsigned samples_per_frame,
 
550
                                     unsigned flags,
 
551
                                     struct test_entry *te)
 
552
{
 
553
    return init_conf_port(1, pool, clock_rate, channel_count, 
 
554
                          samples_per_frame, flags, te);
 
555
}
 
556
 
 
557
 
 
558
/***************************************************************************/
 
559
/* Benchmark conf with 2 participants, mixing to/from snd dev */
 
560
static pjmedia_port* conf2_test_init(pj_pool_t *pool,
 
561
                                     unsigned clock_rate,
 
562
                                     unsigned channel_count,
 
563
                                     unsigned samples_per_frame,
 
564
                                     unsigned flags,
 
565
                                     struct test_entry *te)
 
566
{
 
567
    return init_conf_port(2, pool, clock_rate, channel_count, 
 
568
                          samples_per_frame, flags, te);
 
569
}
 
570
 
 
571
/***************************************************************************/
 
572
/* Benchmark conf with 4 participants, mixing to/from snd dev */
 
573
static pjmedia_port* conf4_test_init(pj_pool_t *pool,
 
574
                                     unsigned clock_rate,
 
575
                                     unsigned channel_count,
 
576
                                     unsigned samples_per_frame,
 
577
                                     unsigned flags,
 
578
                                     struct test_entry *te)
 
579
{
 
580
    return init_conf_port(4, pool, clock_rate, channel_count, 
 
581
                          samples_per_frame, flags, te);
 
582
}
 
583
 
 
584
/***************************************************************************/
 
585
/* Benchmark conf with 8 participants, mixing to/from snd dev */
 
586
static pjmedia_port* conf8_test_init(pj_pool_t *pool,
 
587
                                     unsigned clock_rate,
 
588
                                     unsigned channel_count,
 
589
                                     unsigned samples_per_frame,
 
590
                                     unsigned flags,
 
591
                                     struct test_entry *te)
 
592
{
 
593
    return init_conf_port(8, pool, clock_rate, channel_count, 
 
594
                          samples_per_frame, flags, te);
 
595
}
 
596
 
 
597
/***************************************************************************/
 
598
/* Benchmark conf with 16 participants, mixing to/from snd dev */
 
599
static pjmedia_port* conf16_test_init(pj_pool_t *pool,
 
600
                                      unsigned clock_rate,
 
601
                                      unsigned channel_count,
 
602
                                      unsigned samples_per_frame,
 
603
                                      unsigned flags,
 
604
                                      struct test_entry *te)
 
605
{
 
606
    PJ_UNUSED_ARG(flags);
 
607
    return init_conf_port(16, pool, clock_rate, channel_count, 
 
608
                          samples_per_frame, flags, te);
 
609
}
 
610
 
 
611
/***************************************************************************/
 
612
/* Up and downsample */
 
613
static pjmedia_port* updown_resample_get(pj_pool_t *pool,
 
614
                                         pj_bool_t high_quality,
 
615
                                         pj_bool_t large_filter,
 
616
                                         unsigned clock_rate,
 
617
                                         unsigned channel_count,
 
618
                                         unsigned samples_per_frame,
 
619
                                         unsigned flags,
 
620
                                         struct test_entry *te)
 
621
{
 
622
    pjmedia_port *gen_port, *up, *down;
 
623
    unsigned opt = 0;
 
624
    pj_status_t status;
 
625
 
 
626
    PJ_UNUSED_ARG(flags);
 
627
    PJ_UNUSED_ARG(te);
 
628
 
 
629
    if (!high_quality)
 
630
        opt |= PJMEDIA_RESAMPLE_USE_LINEAR;
 
631
    if (!large_filter)
 
632
        opt |= PJMEDIA_RESAMPLE_USE_SMALL_FILTER;
 
633
 
 
634
    gen_port = create_gen_port(pool, clock_rate, channel_count,
 
635
                               samples_per_frame, 100);
 
636
    status = pjmedia_resample_port_create(pool, gen_port, clock_rate*2, opt, &up);
 
637
    if (status != PJ_SUCCESS)
 
638
        return NULL;
 
639
    status = pjmedia_resample_port_create(pool, up, clock_rate, opt, &down);
 
640
    if (status != PJ_SUCCESS)
 
641
        return NULL;
 
642
 
 
643
    return down;
 
644
}
 
645
 
 
646
/* Linear resampling */
 
647
static pjmedia_port* linear_resample( pj_pool_t *pool,
 
648
                                      unsigned clock_rate,
 
649
                                      unsigned channel_count,
 
650
                                      unsigned samples_per_frame,
 
651
                                      unsigned flags,
 
652
                                      struct test_entry *te)
 
653
{
 
654
    return updown_resample_get(pool, PJ_FALSE, PJ_FALSE, clock_rate,
 
655
                               channel_count, samples_per_frame, flags, te);
 
656
}
 
657
 
 
658
/* Small filter resampling */
 
659
static pjmedia_port* small_filt_resample( pj_pool_t *pool,
 
660
                                          unsigned clock_rate,
 
661
                                          unsigned channel_count,
 
662
                                          unsigned samples_per_frame,
 
663
                                          unsigned flags,
 
664
                                          struct test_entry *te)
 
665
{
 
666
    return updown_resample_get(pool, PJ_TRUE, PJ_FALSE, clock_rate,
 
667
                               channel_count, samples_per_frame, flags, te);
 
668
}
 
669
 
 
670
/* Larger filter resampling */
 
671
static pjmedia_port* large_filt_resample( pj_pool_t *pool,
 
672
                                          unsigned clock_rate,
 
673
                                          unsigned channel_count,
 
674
                                          unsigned samples_per_frame,
 
675
                                          unsigned flags,
 
676
                                          struct test_entry *te)
 
677
{
 
678
    return updown_resample_get(pool, PJ_TRUE, PJ_TRUE, clock_rate,
 
679
                               channel_count, samples_per_frame, flags, te);
 
680
}
 
681
 
 
682
 
 
683
/***************************************************************************/
 
684
/* Codec encode/decode */
 
685
 
 
686
struct codec_port
 
687
{
 
688
    pjmedia_port     base;
 
689
    pjmedia_endpt   *endpt;
 
690
    pjmedia_codec   *codec;
 
691
    pj_status_t    (*codec_deinit)();
 
692
    pj_uint8_t       pkt[640];
 
693
    pj_uint16_t      pcm[32000 * PTIME / 1000];
 
694
};
 
695
 
 
696
 
 
697
static pj_status_t codec_put_frame(struct pjmedia_port *this_port, 
 
698
                                   const pjmedia_frame *frame)
 
699
{
 
700
    struct codec_port *cp = (struct codec_port*)this_port;
 
701
    pjmedia_frame out_frame;
 
702
    pj_status_t status;
 
703
 
 
704
    out_frame.buf = cp->pkt;
 
705
    out_frame.size = sizeof(cp->pkt);
 
706
    status = cp->codec->op->encode(cp->codec, frame, sizeof(cp->pkt),
 
707
                                   &out_frame);
 
708
    pj_assert(status == PJ_SUCCESS);
 
709
 
 
710
    if (out_frame.size != 0) {
 
711
        pjmedia_frame parsed_frm[2], pcm_frm;
 
712
        unsigned frame_cnt = PJ_ARRAY_SIZE(parsed_frm);
 
713
        unsigned i;
 
714
 
 
715
        status = cp->codec->op->parse(cp->codec, out_frame.buf, 
 
716
                                      out_frame.size, &out_frame.timestamp,
 
717
                                      &frame_cnt, parsed_frm);
 
718
        pj_assert(status == PJ_SUCCESS);
 
719
        
 
720
        for (i=0; i<frame_cnt; ++i) {
 
721
            pcm_frm.buf = cp->pcm;
 
722
            pcm_frm.size = sizeof(cp->pkt);
 
723
            status = cp->codec->op->decode(cp->codec, &parsed_frm[i], 
 
724
                                           sizeof(cp->pcm), &pcm_frm);
 
725
            pj_assert(status == PJ_SUCCESS);
 
726
        }
 
727
    }
 
728
 
 
729
    return PJ_SUCCESS;
 
730
}
 
731
 
 
732
static pj_status_t codec_on_destroy(struct pjmedia_port *this_port)
 
733
{
 
734
    struct codec_port *cp = (struct codec_port*)this_port;
 
735
 
 
736
    cp->codec->op->close(cp->codec);
 
737
    pjmedia_codec_mgr_dealloc_codec(pjmedia_endpt_get_codec_mgr(cp->endpt),
 
738
                                    cp->codec);
 
739
    cp->codec_deinit();
 
740
    pjmedia_endpt_destroy(cp->endpt);
 
741
    return PJ_SUCCESS;
 
742
}
 
743
 
 
744
static pjmedia_port* codec_encode_decode( pj_pool_t *pool,
 
745
                                          const char *codec,
 
746
                                          pj_status_t (*codec_init)(pjmedia_endpt*),
 
747
                                          pj_status_t (*codec_deinit)(),
 
748
                                          unsigned clock_rate,
 
749
                                          unsigned channel_count,
 
750
                                          unsigned samples_per_frame,
 
751
                                          unsigned flags,
 
752
                                          struct test_entry *te)
 
753
{
 
754
    struct codec_port *cp;
 
755
    pj_str_t codec_id;
 
756
    const pjmedia_codec_info *ci[1];
 
757
    unsigned count;
 
758
    pjmedia_codec_param codec_param;
 
759
    pj_status_t status;
 
760
 
 
761
    PJ_UNUSED_ARG(flags);
 
762
    PJ_UNUSED_ARG(te);
 
763
 
 
764
    codec_id = pj_str((char*)codec);
 
765
    cp = PJ_POOL_ZALLOC_T(pool, struct codec_port);
 
766
    pjmedia_port_info_init(&cp->base.info, &codec_id, 0x123456, clock_rate,
 
767
                           channel_count, 16, samples_per_frame);
 
768
    cp->base.put_frame = &codec_put_frame;
 
769
    cp->base.on_destroy = &codec_on_destroy;
 
770
    cp->codec_deinit = codec_deinit;
 
771
 
 
772
    status = pjmedia_endpt_create(mem, NULL, 0, &cp->endpt);
 
773
    if (status != PJ_SUCCESS)
 
774
        return NULL;
 
775
 
 
776
    status = codec_init(cp->endpt);
 
777
    if (status != PJ_SUCCESS)
 
778
        return NULL;
 
779
 
 
780
    count = 1;
 
781
    status = pjmedia_codec_mgr_find_codecs_by_id(pjmedia_endpt_get_codec_mgr(cp->endpt),
 
782
                                                 &codec_id, &count, ci, NULL);
 
783
    if (status != PJ_SUCCESS)
 
784
        return NULL;
 
785
 
 
786
    status = pjmedia_codec_mgr_alloc_codec(pjmedia_endpt_get_codec_mgr(cp->endpt),
 
787
                                           ci[0], &cp->codec);
 
788
    if (status != PJ_SUCCESS)
 
789
        return NULL;
 
790
 
 
791
    status = pjmedia_codec_mgr_get_default_param(pjmedia_endpt_get_codec_mgr(cp->endpt),
 
792
                                                 ci[0], &codec_param);
 
793
    if (status != PJ_SUCCESS)
 
794
        return NULL;
 
795
 
 
796
    status = (*cp->codec->op->init)(cp->codec, pool);
 
797
    if (status != PJ_SUCCESS)
 
798
        return NULL;
 
799
 
 
800
    status = cp->codec->op->open(cp->codec, &codec_param);
 
801
    if (status != PJ_SUCCESS)
 
802
        return NULL;
 
803
 
 
804
    return &cp->base;
 
805
}
 
806
 
 
807
/* G.711 benchmark */
 
808
static pjmedia_port* g711_encode_decode(  pj_pool_t *pool,
 
809
                                          unsigned clock_rate,
 
810
                                          unsigned channel_count,
 
811
                                          unsigned samples_per_frame,
 
812
                                          unsigned flags,
 
813
                                          struct test_entry *te)
 
814
{
 
815
    return codec_encode_decode(pool, "pcmu", &pjmedia_codec_g711_init, 
 
816
                               &pjmedia_codec_g711_deinit,
 
817
                               clock_rate, channel_count,
 
818
                               samples_per_frame, flags, te);
 
819
}
 
820
 
 
821
/* GSM benchmark */
 
822
static pjmedia_port* gsm_encode_decode(  pj_pool_t *pool,
 
823
                                         unsigned clock_rate,
 
824
                                         unsigned channel_count,
 
825
                                         unsigned samples_per_frame,
 
826
                                         unsigned flags,
 
827
                                         struct test_entry *te)
 
828
{
 
829
    return codec_encode_decode(pool, "gsm", &pjmedia_codec_gsm_init, 
 
830
                               &pjmedia_codec_gsm_deinit, 
 
831
                               clock_rate, channel_count,
 
832
                               samples_per_frame, flags, te);
 
833
}
 
834
 
 
835
static pj_status_t ilbc_init(pjmedia_endpt *endpt)
 
836
{
 
837
    return pjmedia_codec_ilbc_init(endpt, 20);
 
838
}
 
839
 
 
840
/* iLBC benchmark */
 
841
static pjmedia_port* ilbc_encode_decode( pj_pool_t *pool,
 
842
                                         unsigned clock_rate,
 
843
                                         unsigned channel_count,
 
844
                                         unsigned samples_per_frame,
 
845
                                         unsigned flags,
 
846
                                         struct test_entry *te)
 
847
{
 
848
    samples_per_frame = 30 * clock_rate / 1000;
 
849
    return codec_encode_decode(pool, "ilbc", &ilbc_init, 
 
850
                               &pjmedia_codec_ilbc_deinit, clock_rate, 
 
851
                               channel_count, samples_per_frame, flags, te);
 
852
}
 
853
 
 
854
/* Speex narrowband benchmark */
 
855
static pjmedia_port* speex8_encode_decode(pj_pool_t *pool,
 
856
                                          unsigned clock_rate,
 
857
                                          unsigned channel_count,
 
858
                                          unsigned samples_per_frame,
 
859
                                          unsigned flags,
 
860
                                          struct test_entry *te)
 
861
{
 
862
    return codec_encode_decode(pool, "speex/8000", 
 
863
                               &pjmedia_codec_speex_init_default, 
 
864
                               &pjmedia_codec_speex_deinit, 
 
865
                               clock_rate, channel_count,
 
866
                               samples_per_frame, flags, te);
 
867
}
 
868
 
 
869
/* Speex wideband benchmark */
 
870
static pjmedia_port* speex16_encode_decode(pj_pool_t *pool,
 
871
                                           unsigned clock_rate,
 
872
                                           unsigned channel_count,
 
873
                                           unsigned samples_per_frame,
 
874
                                           unsigned flags,
 
875
                                           struct test_entry *te)
 
876
{
 
877
    return codec_encode_decode(pool, "speex/16000", 
 
878
                               &pjmedia_codec_speex_init_default, 
 
879
                               &pjmedia_codec_speex_deinit, 
 
880
                               clock_rate, channel_count,
 
881
                               samples_per_frame, flags, te);
 
882
}
 
883
 
 
884
/* G.722 benchmark benchmark */
 
885
static pjmedia_port* g722_encode_decode(pj_pool_t *pool,
 
886
                                        unsigned clock_rate,
 
887
                                        unsigned channel_count,
 
888
                                        unsigned samples_per_frame,
 
889
                                        unsigned flags,
 
890
                                        struct test_entry *te)
 
891
{
 
892
    return codec_encode_decode(pool, "g722", &pjmedia_codec_g722_init, 
 
893
                               &pjmedia_codec_g722_deinit, 
 
894
                               clock_rate, channel_count,
 
895
                               samples_per_frame, flags, te);
 
896
}
 
897
 
 
898
#if PJMEDIA_HAS_G7221_CODEC
 
899
/* G.722.1 benchmark benchmark */
 
900
static pjmedia_port* g7221_encode_decode(pj_pool_t *pool,
 
901
                                         unsigned clock_rate,
 
902
                                         unsigned channel_count,
 
903
                                         unsigned samples_per_frame,
 
904
                                         unsigned flags,
 
905
                                         struct test_entry *te)
 
906
{
 
907
    return codec_encode_decode(pool, "g7221/16000", 
 
908
                               &pjmedia_codec_g7221_init,
 
909
                               &pjmedia_codec_g7221_deinit,
 
910
                               clock_rate, channel_count,
 
911
                               samples_per_frame, flags, te);
 
912
}
 
913
 
 
914
/* G.722.1 Annex C benchmark benchmark */
 
915
static pjmedia_port* g7221c_encode_decode(pj_pool_t *pool,
 
916
                                          unsigned clock_rate,
 
917
                                          unsigned channel_count,
 
918
                                          unsigned samples_per_frame,
 
919
                                          unsigned flags,
 
920
                                          struct test_entry *te)
 
921
{
 
922
    return codec_encode_decode(pool, "g7221/32000", 
 
923
                               &pjmedia_codec_g7221_init,
 
924
                               &pjmedia_codec_g7221_deinit,
 
925
                               clock_rate, channel_count,
 
926
                               samples_per_frame, flags, te);
 
927
}
 
928
#endif  /* PJMEDIA_HAS_G7221_CODEC */
 
929
 
 
930
#if defined(PJMEDIA_HAS_L16_CODEC) && PJMEDIA_HAS_L16_CODEC!=0
 
931
static pj_status_t init_l16_default(pjmedia_endpt *endpt)
 
932
{
 
933
    return pjmedia_codec_l16_init(endpt, 0);
 
934
}
 
935
 
 
936
/* L16/8000/1 benchmark */
 
937
static pjmedia_port* l16_8_encode_decode(pj_pool_t *pool,
 
938
                                         unsigned clock_rate,
 
939
                                         unsigned channel_count,
 
940
                                         unsigned samples_per_frame,
 
941
                                         unsigned flags,
 
942
                                         struct test_entry *te)
 
943
{
 
944
    return codec_encode_decode(pool, "L16/8000/1", &init_l16_default, 
 
945
                               &pjmedia_codec_l16_deinit, 
 
946
                               clock_rate, channel_count,
 
947
                               samples_per_frame, flags, te);
 
948
}
 
949
 
 
950
/* L16/16000/1 benchmark */
 
951
static pjmedia_port* l16_16_encode_decode(pj_pool_t *pool,
 
952
                                          unsigned clock_rate,
 
953
                                          unsigned channel_count,
 
954
                                          unsigned samples_per_frame,
 
955
                                          unsigned flags,
 
956
                                          struct test_entry *te)
 
957
{
 
958
    return codec_encode_decode(pool, "L16/16000/1", &init_l16_default, 
 
959
                               &pjmedia_codec_l16_deinit, 
 
960
                               clock_rate, channel_count,
 
961
                               samples_per_frame, flags, te);
 
962
}
 
963
#endif
 
964
 
 
965
/***************************************************************************/
 
966
/* WSOLA PLC mode */
 
967
 
 
968
struct wsola_plc_port
 
969
{
 
970
    pjmedia_port     base;
 
971
    pjmedia_wsola   *wsola;
 
972
    pjmedia_port    *gen_port;
 
973
    int              loss_pct;
 
974
    pj_bool_t        prev_lost;
 
975
};
 
976
 
 
977
 
 
978
static pj_status_t wsola_plc_get_frame(struct pjmedia_port *this_port, 
 
979
                                       pjmedia_frame *frame)
 
980
{
 
981
    struct wsola_plc_port *wp = (struct wsola_plc_port*)this_port;
 
982
    pj_status_t status;
 
983
 
 
984
 
 
985
    if ((pj_rand() % 100) > wp->loss_pct) {
 
986
        status = pjmedia_port_get_frame(wp->gen_port, frame);
 
987
        pj_assert(status == PJ_SUCCESS);
 
988
 
 
989
        status = pjmedia_wsola_save(wp->wsola, (short*)frame->buf, 
 
990
                                    wp->prev_lost);
 
991
        pj_assert(status == PJ_SUCCESS);
 
992
 
 
993
        wp->prev_lost = PJ_FALSE;
 
994
    } else {
 
995
        status = pjmedia_wsola_generate(wp->wsola, (short*)frame->buf);
 
996
        wp->prev_lost = PJ_TRUE;
 
997
    }
 
998
 
 
999
    return PJ_SUCCESS;
 
1000
}
 
1001
 
 
1002
static pj_status_t wsola_plc_on_destroy(struct pjmedia_port *this_port)
 
1003
{
 
1004
    struct wsola_plc_port *wp = (struct wsola_plc_port*)this_port;
 
1005
    pjmedia_port_destroy(wp->gen_port);
 
1006
    pjmedia_wsola_destroy(wp->wsola);
 
1007
    return PJ_SUCCESS;
 
1008
}
 
1009
 
 
1010
static pjmedia_port* create_wsola_plc(unsigned loss_pct,
 
1011
                                      pj_pool_t *pool,
 
1012
                                      unsigned clock_rate,
 
1013
                                      unsigned channel_count,
 
1014
                                      unsigned samples_per_frame,
 
1015
                                      unsigned flags,
 
1016
                                      struct test_entry *te)
 
1017
{
 
1018
    struct wsola_plc_port *wp;
 
1019
    pj_str_t name = pj_str("wsola");
 
1020
    unsigned opt = 0;
 
1021
    pj_status_t status;
 
1022
 
 
1023
    PJ_UNUSED_ARG(flags);
 
1024
    PJ_UNUSED_ARG(te);
 
1025
 
 
1026
    wp = PJ_POOL_ZALLOC_T(pool, struct wsola_plc_port);
 
1027
    wp->loss_pct = loss_pct;
 
1028
    wp->base.get_frame = &wsola_plc_get_frame;
 
1029
    wp->base.on_destroy = &wsola_plc_on_destroy;
 
1030
    pjmedia_port_info_init(&wp->base.info, &name, 0x4123, clock_rate, 
 
1031
                           channel_count, 16, samples_per_frame);
 
1032
 
 
1033
    if (loss_pct == 0)
 
1034
        opt |= PJMEDIA_WSOLA_NO_PLC;
 
1035
 
 
1036
    status = pjmedia_wsola_create(pool, clock_rate, samples_per_frame,
 
1037
                                  channel_count, 0, &wp->wsola);
 
1038
    if (status != PJ_SUCCESS)
 
1039
        return NULL;
 
1040
 
 
1041
    wp->gen_port = create_gen_port(pool, clock_rate, channel_count, 
 
1042
                                   samples_per_frame, 100);
 
1043
    if (wp->gen_port == NULL)
 
1044
        return NULL;
 
1045
 
 
1046
    return &wp->base;
 
1047
}
 
1048
 
 
1049
 
 
1050
/* WSOLA PLC with 0% packet loss */
 
1051
static pjmedia_port* wsola_plc_0( pj_pool_t *pool,
 
1052
                                  unsigned clock_rate,
 
1053
                                  unsigned channel_count,
 
1054
                                  unsigned samples_per_frame,
 
1055
                                  unsigned flags,
 
1056
                                  struct test_entry *te)
 
1057
{
 
1058
    return create_wsola_plc(0, pool, clock_rate, channel_count, 
 
1059
                            samples_per_frame, flags, te);
 
1060
}
 
1061
 
 
1062
 
 
1063
/* WSOLA PLC with 2% packet loss */
 
1064
static pjmedia_port* wsola_plc_2( pj_pool_t *pool,
 
1065
                                  unsigned clock_rate,
 
1066
                                  unsigned channel_count,
 
1067
                                  unsigned samples_per_frame,
 
1068
                                  unsigned flags,
 
1069
                                  struct test_entry *te)
 
1070
{
 
1071
    return create_wsola_plc(2, pool, clock_rate, channel_count, 
 
1072
                            samples_per_frame, flags, te);
 
1073
}
 
1074
 
 
1075
/* WSOLA PLC with 5% packet loss */
 
1076
static pjmedia_port* wsola_plc_5( pj_pool_t *pool,
 
1077
                                  unsigned clock_rate,
 
1078
                                  unsigned channel_count,
 
1079
                                  unsigned samples_per_frame,
 
1080
                                  unsigned flags,
 
1081
                                  struct test_entry *te)
 
1082
{
 
1083
    return create_wsola_plc(5, pool, clock_rate, channel_count, 
 
1084
                            samples_per_frame, flags, te);
 
1085
}
 
1086
 
 
1087
/* WSOLA PLC with 10% packet loss */
 
1088
static pjmedia_port* wsola_plc_10(pj_pool_t *pool,
 
1089
                                  unsigned clock_rate,
 
1090
                                  unsigned channel_count,
 
1091
                                  unsigned samples_per_frame,
 
1092
                                  unsigned flags,
 
1093
                                  struct test_entry *te)
 
1094
{
 
1095
    return create_wsola_plc(10, pool, clock_rate, channel_count, 
 
1096
                            samples_per_frame, flags, te);
 
1097
}
 
1098
 
 
1099
/* WSOLA PLC with 20% packet loss */
 
1100
static pjmedia_port* wsola_plc_20(pj_pool_t *pool,
 
1101
                                  unsigned clock_rate,
 
1102
                                  unsigned channel_count,
 
1103
                                  unsigned samples_per_frame,
 
1104
                                  unsigned flags,
 
1105
                                  struct test_entry *te)
 
1106
{
 
1107
    return create_wsola_plc(20, pool, clock_rate, channel_count, 
 
1108
                            samples_per_frame, flags, te);
 
1109
}
 
1110
 
 
1111
/* WSOLA PLC with 50% packet loss */
 
1112
static pjmedia_port* wsola_plc_50(pj_pool_t *pool,
 
1113
                                  unsigned clock_rate,
 
1114
                                  unsigned channel_count,
 
1115
                                  unsigned samples_per_frame,
 
1116
                                  unsigned flags,
 
1117
                                  struct test_entry *te)
 
1118
{
 
1119
    return create_wsola_plc(50, pool, clock_rate, channel_count, 
 
1120
                            samples_per_frame, flags, te);
 
1121
}
 
1122
 
 
1123
 
 
1124
 
 
1125
/***************************************************************************/
 
1126
/* WSOLA discard mode */
 
1127
enum { CIRC_BUF_FRAME_CNT = 4 };
 
1128
struct wsola_discard_port
 
1129
{
 
1130
    pjmedia_port         base;
 
1131
    pjmedia_port        *gen_port;
 
1132
    pjmedia_wsola       *wsola;
 
1133
    pjmedia_circ_buf    *circbuf;
 
1134
    unsigned             discard_pct;
 
1135
};
 
1136
 
 
1137
 
 
1138
static pj_status_t wsola_discard_get_frame(struct pjmedia_port *this_port, 
 
1139
                                           pjmedia_frame *frame)
 
1140
{
 
1141
    struct wsola_discard_port *wp = (struct wsola_discard_port*)this_port;
 
1142
    pj_status_t status;
 
1143
 
 
1144
    while (pjmedia_circ_buf_get_len(wp->circbuf) <
 
1145
                wp->base.info.samples_per_frame * (CIRC_BUF_FRAME_CNT-1))
 
1146
    {
 
1147
        status = pjmedia_port_get_frame(wp->gen_port, frame);
 
1148
        pj_assert(status==PJ_SUCCESS);
 
1149
 
 
1150
        status = pjmedia_circ_buf_write(wp->circbuf, (short*)frame->buf, 
 
1151
                                        wp->base.info.samples_per_frame);
 
1152
        pj_assert(status==PJ_SUCCESS);
 
1153
    }
 
1154
    
 
1155
    if ((pj_rand() % 100) < (int)wp->discard_pct) {
 
1156
        pj_int16_t *reg1, *reg2;
 
1157
        unsigned reg1_len, reg2_len;
 
1158
        unsigned del_cnt;
 
1159
 
 
1160
        pjmedia_circ_buf_get_read_regions(wp->circbuf, &reg1, &reg1_len,
 
1161
                                          &reg2, &reg2_len);
 
1162
 
 
1163
        del_cnt = wp->base.info.samples_per_frame;
 
1164
        status = pjmedia_wsola_discard(wp->wsola, reg1, reg1_len, reg2, 
 
1165
                                       reg2_len, &del_cnt);
 
1166
        pj_assert(status==PJ_SUCCESS);
 
1167
 
 
1168
        status = pjmedia_circ_buf_adv_read_ptr(wp->circbuf, del_cnt);
 
1169
        pj_assert(status==PJ_SUCCESS);
 
1170
    }
 
1171
 
 
1172
    return PJ_SUCCESS;
 
1173
}
 
1174
 
 
1175
static pj_status_t wsola_discard_on_destroy(struct pjmedia_port *this_port)
 
1176
{
 
1177
    struct wsola_discard_port *wp = (struct wsola_discard_port*)this_port;
 
1178
    pjmedia_port_destroy(wp->gen_port);
 
1179
    pjmedia_wsola_destroy(wp->wsola);
 
1180
    return PJ_SUCCESS;
 
1181
}
 
1182
 
 
1183
 
 
1184
static pjmedia_port* create_wsola_discard(unsigned discard_pct,
 
1185
                                          pj_pool_t *pool,
 
1186
                                          unsigned clock_rate,
 
1187
                                          unsigned channel_count,
 
1188
                                          unsigned samples_per_frame,
 
1189
                                          unsigned flags,
 
1190
                                          struct test_entry *te)
 
1191
{
 
1192
    struct wsola_discard_port *wp;
 
1193
    pj_str_t name = pj_str("wsola");
 
1194
    unsigned i, opt = 0;
 
1195
    pj_status_t status;
 
1196
 
 
1197
    PJ_UNUSED_ARG(flags);
 
1198
    PJ_UNUSED_ARG(te);
 
1199
 
 
1200
    wp = PJ_POOL_ZALLOC_T(pool, struct wsola_discard_port);
 
1201
    wp->discard_pct = discard_pct;
 
1202
    wp->base.get_frame = &wsola_discard_get_frame;
 
1203
    wp->base.on_destroy = &wsola_discard_on_destroy;
 
1204
    pjmedia_port_info_init(&wp->base.info, &name, 0x4123, clock_rate, 
 
1205
                           channel_count, 16, samples_per_frame);
 
1206
 
 
1207
    if (discard_pct == 0)
 
1208
        opt |= PJMEDIA_WSOLA_NO_DISCARD;
 
1209
 
 
1210
    status = pjmedia_wsola_create(pool, clock_rate, samples_per_frame,
 
1211
                                  channel_count, 0, &wp->wsola);
 
1212
    if (status != PJ_SUCCESS)
 
1213
        return NULL;
 
1214
 
 
1215
    wp->gen_port = create_gen_port(pool, clock_rate, channel_count, 
 
1216
                                   samples_per_frame, 100);
 
1217
    if (wp->gen_port == NULL)
 
1218
        return NULL;
 
1219
 
 
1220
    status = pjmedia_circ_buf_create(pool, samples_per_frame * CIRC_BUF_FRAME_CNT, 
 
1221
                                     &wp->circbuf);
 
1222
    if (status != PJ_SUCCESS)
 
1223
        return NULL;
 
1224
 
 
1225
    /* fill up the circbuf */
 
1226
    for (i=0; i<CIRC_BUF_FRAME_CNT; ++i) {
 
1227
        short pcm[320];
 
1228
        pjmedia_frame frm;
 
1229
 
 
1230
        pj_assert(PJ_ARRAY_SIZE(pcm) >= samples_per_frame);
 
1231
        frm.buf = pcm;
 
1232
        frm.size = samples_per_frame * 2;
 
1233
 
 
1234
        status = pjmedia_port_get_frame(wp->gen_port, &frm);
 
1235
        pj_assert(status==PJ_SUCCESS);
 
1236
 
 
1237
        status = pjmedia_circ_buf_write(wp->circbuf, pcm, samples_per_frame);
 
1238
        pj_assert(status==PJ_SUCCESS);
 
1239
    }
 
1240
 
 
1241
    return &wp->base;
 
1242
}
 
1243
 
 
1244
 
 
1245
/* WSOLA with 2% discard rate */
 
1246
static pjmedia_port* wsola_discard_2( pj_pool_t *pool,
 
1247
                                      unsigned clock_rate,
 
1248
                                      unsigned channel_count,
 
1249
                                      unsigned samples_per_frame,
 
1250
                                      unsigned flags,
 
1251
                                      struct test_entry *te)
 
1252
{
 
1253
    return create_wsola_discard(2, pool, clock_rate, channel_count, 
 
1254
                                samples_per_frame, flags, te);
 
1255
}
 
1256
 
 
1257
/* WSOLA with 5% discard rate */
 
1258
static pjmedia_port* wsola_discard_5( pj_pool_t *pool,
 
1259
                                      unsigned clock_rate,
 
1260
                                      unsigned channel_count,
 
1261
                                      unsigned samples_per_frame,
 
1262
                                      unsigned flags,
 
1263
                                      struct test_entry *te)
 
1264
{
 
1265
    return create_wsola_discard(5, pool, clock_rate, channel_count, 
 
1266
                                samples_per_frame, flags, te);
 
1267
}
 
1268
 
 
1269
/* WSOLA with 10% discard rate */
 
1270
static pjmedia_port* wsola_discard_10(pj_pool_t *pool,
 
1271
                                      unsigned clock_rate,
 
1272
                                      unsigned channel_count,
 
1273
                                      unsigned samples_per_frame,
 
1274
                                      unsigned flags,
 
1275
                                      struct test_entry *te)
 
1276
{
 
1277
    return create_wsola_discard(10, pool, clock_rate, channel_count, 
 
1278
                                samples_per_frame, flags, te);
 
1279
}
 
1280
 
 
1281
/* WSOLA with 20% discard rate */
 
1282
static pjmedia_port* wsola_discard_20(pj_pool_t *pool,
 
1283
                                      unsigned clock_rate,
 
1284
                                      unsigned channel_count,
 
1285
                                      unsigned samples_per_frame,
 
1286
                                      unsigned flags,
 
1287
                                      struct test_entry *te)
 
1288
{
 
1289
    return create_wsola_discard(20, pool, clock_rate, channel_count, 
 
1290
                                samples_per_frame, flags, te);
 
1291
}
 
1292
 
 
1293
/* WSOLA with 50% discard rate */
 
1294
static pjmedia_port* wsola_discard_50(pj_pool_t *pool,
 
1295
                                      unsigned clock_rate,
 
1296
                                      unsigned channel_count,
 
1297
                                      unsigned samples_per_frame,
 
1298
                                      unsigned flags,
 
1299
                                      struct test_entry *te)
 
1300
{
 
1301
    return create_wsola_discard(50, pool, clock_rate, channel_count, 
 
1302
                                samples_per_frame, flags, te);
 
1303
}
 
1304
 
 
1305
 
 
1306
 
 
1307
/***************************************************************************/
 
1308
 
 
1309
static pjmedia_port* ec_create(unsigned ec_tail_msec,
 
1310
                               pj_pool_t *pool,
 
1311
                               unsigned clock_rate,
 
1312
                               unsigned channel_count,
 
1313
                               unsigned samples_per_frame,
 
1314
                               unsigned flags,
 
1315
                               struct test_entry *te)
 
1316
{
 
1317
    pjmedia_port *gen_port, *ec_port;
 
1318
    pj_status_t status;
 
1319
 
 
1320
    PJ_UNUSED_ARG(te);
 
1321
 
 
1322
    gen_port = create_gen_port(pool, clock_rate, channel_count, 
 
1323
                               samples_per_frame, 100);
 
1324
    if (gen_port == NULL)
 
1325
        return NULL;
 
1326
 
 
1327
    status = pjmedia_echo_port_create(pool, gen_port, ec_tail_msec, 0,
 
1328
                                      flags, &ec_port);
 
1329
    if (status != PJ_SUCCESS)
 
1330
        return NULL;
 
1331
 
 
1332
    return ec_port;
 
1333
}
 
1334
 
 
1335
/* EC with 100ms tail length */
 
1336
static pjmedia_port* ec_create_100(pj_pool_t *pool,
 
1337
                                   unsigned clock_rate,
 
1338
                                   unsigned channel_count,
 
1339
                                   unsigned samples_per_frame,
 
1340
                                   unsigned flags,
 
1341
                                   struct test_entry *te)
 
1342
{
 
1343
    flags = 0;
 
1344
    return ec_create(100, pool, clock_rate, channel_count, samples_per_frame,
 
1345
                     flags, te);
 
1346
}
 
1347
 
 
1348
/* EC with 128ms tail length */
 
1349
static pjmedia_port* ec_create_128(pj_pool_t *pool,
 
1350
                                   unsigned clock_rate,
 
1351
                                   unsigned channel_count,
 
1352
                                   unsigned samples_per_frame,
 
1353
                                   unsigned flags,
 
1354
                                   struct test_entry *te)
 
1355
{
 
1356
    flags = 0;
 
1357
    return ec_create(128, pool, clock_rate, channel_count, samples_per_frame,
 
1358
                     flags, te);
 
1359
}
 
1360
 
 
1361
/* EC with 200ms tail length */
 
1362
static pjmedia_port* ec_create_200(pj_pool_t *pool,
 
1363
                                   unsigned clock_rate,
 
1364
                                   unsigned channel_count,
 
1365
                                   unsigned samples_per_frame,
 
1366
                                   unsigned flags,
 
1367
                                   struct test_entry *te)
 
1368
{
 
1369
    flags = 0;
 
1370
    return ec_create(200, pool, clock_rate, channel_count, samples_per_frame,
 
1371
                     flags, te);
 
1372
}
 
1373
 
 
1374
/* EC with 256ms tail length */
 
1375
static pjmedia_port* ec_create_256(pj_pool_t *pool,
 
1376
                                   unsigned clock_rate,
 
1377
                                   unsigned channel_count,
 
1378
                                   unsigned samples_per_frame,
 
1379
                                   unsigned flags,
 
1380
                                   struct test_entry *te)
 
1381
{
 
1382
    flags = 0;
 
1383
    return ec_create(256, pool, clock_rate, channel_count, samples_per_frame,
 
1384
                     flags, te);
 
1385
}
 
1386
 
 
1387
 
 
1388
/* EC with 400ms tail length */
 
1389
static pjmedia_port* ec_create_400(pj_pool_t *pool,
 
1390
                                   unsigned clock_rate,
 
1391
                                   unsigned channel_count,
 
1392
                                   unsigned samples_per_frame,
 
1393
                                   unsigned flags,
 
1394
                                   struct test_entry *te)
 
1395
{
 
1396
    flags = 0;
 
1397
    return ec_create(400, pool, clock_rate, channel_count, samples_per_frame,
 
1398
                     flags, te);
 
1399
}
 
1400
 
 
1401
/* EC with 500ms tail length */
 
1402
static pjmedia_port* ec_create_500(pj_pool_t *pool,
 
1403
                                   unsigned clock_rate,
 
1404
                                   unsigned channel_count,
 
1405
                                   unsigned samples_per_frame,
 
1406
                                   unsigned flags,
 
1407
                                   struct test_entry *te)
 
1408
{
 
1409
    flags = 0;
 
1410
    return ec_create(500, pool, clock_rate, channel_count, samples_per_frame,
 
1411
                     flags, te);
 
1412
}
 
1413
 
 
1414
/* EC with 512ms tail length */
 
1415
static pjmedia_port* ec_create_512(pj_pool_t *pool,
 
1416
                                   unsigned clock_rate,
 
1417
                                   unsigned channel_count,
 
1418
                                   unsigned samples_per_frame,
 
1419
                                   unsigned flags,
 
1420
                                   struct test_entry *te)
 
1421
{
 
1422
    flags = 0;
 
1423
    return ec_create(512, pool, clock_rate, channel_count, samples_per_frame,
 
1424
                     flags, te);
 
1425
}
 
1426
 
 
1427
/* EC with 600ms tail length */
 
1428
static pjmedia_port* ec_create_600(pj_pool_t *pool,
 
1429
                                   unsigned clock_rate,
 
1430
                                   unsigned channel_count,
 
1431
                                   unsigned samples_per_frame,
 
1432
                                   unsigned flags,
 
1433
                                   struct test_entry *te)
 
1434
{
 
1435
    flags = 0;
 
1436
    return ec_create(600, pool, clock_rate, channel_count, samples_per_frame,
 
1437
                     flags, te);
 
1438
}
 
1439
 
 
1440
/* EC with 800ms tail length */
 
1441
static pjmedia_port* ec_create_800(pj_pool_t *pool,
 
1442
                                   unsigned clock_rate,
 
1443
                                   unsigned channel_count,
 
1444
                                   unsigned samples_per_frame,
 
1445
                                   unsigned flags,
 
1446
                                   struct test_entry *te)
 
1447
{
 
1448
    flags = 0;
 
1449
    return ec_create(800, pool, clock_rate, channel_count, samples_per_frame,
 
1450
                     flags, te);
 
1451
}
 
1452
 
 
1453
 
 
1454
 
 
1455
/* Echo suppressor with 100ms tail length */
 
1456
static pjmedia_port* es_create_100(pj_pool_t *pool,
 
1457
                                   unsigned clock_rate,
 
1458
                                   unsigned channel_count,
 
1459
                                   unsigned samples_per_frame,
 
1460
                                   unsigned flags,
 
1461
                                   struct test_entry *te)
 
1462
{
 
1463
    flags = PJMEDIA_ECHO_SIMPLE;
 
1464
    return ec_create(100, pool, clock_rate, channel_count, samples_per_frame,
 
1465
                     flags, te);
 
1466
}
 
1467
 
 
1468
/* Echo suppressor with 128ms tail length */
 
1469
static pjmedia_port* es_create_128(pj_pool_t *pool,
 
1470
                                   unsigned clock_rate,
 
1471
                                   unsigned channel_count,
 
1472
                                   unsigned samples_per_frame,
 
1473
                                   unsigned flags,
 
1474
                                   struct test_entry *te)
 
1475
{
 
1476
    flags = PJMEDIA_ECHO_SIMPLE;
 
1477
    return ec_create(128, pool, clock_rate, channel_count, samples_per_frame,
 
1478
                     flags, te);
 
1479
}
 
1480
 
 
1481
/* Echo suppressor with 200ms tail length */
 
1482
static pjmedia_port* es_create_200(pj_pool_t *pool,
 
1483
                                   unsigned clock_rate,
 
1484
                                   unsigned channel_count,
 
1485
                                   unsigned samples_per_frame,
 
1486
                                   unsigned flags,
 
1487
                                   struct test_entry *te)
 
1488
{
 
1489
    flags = PJMEDIA_ECHO_SIMPLE;
 
1490
    return ec_create(200, pool, clock_rate, channel_count, samples_per_frame,
 
1491
                     flags, te);
 
1492
}
 
1493
 
 
1494
/* Echo suppressor with 256ms tail length */
 
1495
static pjmedia_port* es_create_256(pj_pool_t *pool,
 
1496
                                   unsigned clock_rate,
 
1497
                                   unsigned channel_count,
 
1498
                                   unsigned samples_per_frame,
 
1499
                                   unsigned flags,
 
1500
                                   struct test_entry *te)
 
1501
{
 
1502
    flags = PJMEDIA_ECHO_SIMPLE;
 
1503
    return ec_create(256, pool, clock_rate, channel_count, samples_per_frame,
 
1504
                     flags, te);
 
1505
}
 
1506
 
 
1507
 
 
1508
/* Echo suppressor with 400ms tail length */
 
1509
static pjmedia_port* es_create_400(pj_pool_t *pool,
 
1510
                                   unsigned clock_rate,
 
1511
                                   unsigned channel_count,
 
1512
                                   unsigned samples_per_frame,
 
1513
                                   unsigned flags,
 
1514
                                   struct test_entry *te)
 
1515
{
 
1516
    flags = PJMEDIA_ECHO_SIMPLE;
 
1517
    return ec_create(400, pool, clock_rate, channel_count, samples_per_frame,
 
1518
                     flags, te);
 
1519
}
 
1520
 
 
1521
/* Echo suppressor with 500ms tail length */
 
1522
static pjmedia_port* es_create_500(pj_pool_t *pool,
 
1523
                                   unsigned clock_rate,
 
1524
                                   unsigned channel_count,
 
1525
                                   unsigned samples_per_frame,
 
1526
                                   unsigned flags,
 
1527
                                   struct test_entry *te)
 
1528
{
 
1529
    flags = PJMEDIA_ECHO_SIMPLE;
 
1530
    return ec_create(500, pool, clock_rate, channel_count, samples_per_frame,
 
1531
                     flags, te);
 
1532
}
 
1533
 
 
1534
/* Echo suppressor with 512ms tail length */
 
1535
static pjmedia_port* es_create_512(pj_pool_t *pool,
 
1536
                                   unsigned clock_rate,
 
1537
                                   unsigned channel_count,
 
1538
                                   unsigned samples_per_frame,
 
1539
                                   unsigned flags,
 
1540
                                   struct test_entry *te)
 
1541
{
 
1542
    flags = PJMEDIA_ECHO_SIMPLE;
 
1543
    return ec_create(512, pool, clock_rate, channel_count, samples_per_frame,
 
1544
                     flags, te);
 
1545
}
 
1546
 
 
1547
/* Echo suppressor with 600ms tail length */
 
1548
static pjmedia_port* es_create_600(pj_pool_t *pool,
 
1549
                                   unsigned clock_rate,
 
1550
                                   unsigned channel_count,
 
1551
                                   unsigned samples_per_frame,
 
1552
                                   unsigned flags,
 
1553
                                   struct test_entry *te)
 
1554
{
 
1555
    flags = PJMEDIA_ECHO_SIMPLE;
 
1556
    return ec_create(600, pool, clock_rate, channel_count, samples_per_frame,
 
1557
                     flags, te);
 
1558
}
 
1559
 
 
1560
/* Echo suppressor with 800ms tail length */
 
1561
static pjmedia_port* es_create_800(pj_pool_t *pool,
 
1562
                                   unsigned clock_rate,
 
1563
                                   unsigned channel_count,
 
1564
                                   unsigned samples_per_frame,
 
1565
                                   unsigned flags,
 
1566
                                   struct test_entry *te)
 
1567
{
 
1568
    flags = PJMEDIA_ECHO_SIMPLE;
 
1569
    return ec_create(800, pool, clock_rate, channel_count, samples_per_frame,
 
1570
                     flags, te);
 
1571
}
 
1572
 
 
1573
 
 
1574
/***************************************************************************/
 
1575
/* Tone generator, single frequency */
 
1576
static pjmedia_port* create_tonegen(unsigned freq1,
 
1577
                                    unsigned freq2,
 
1578
                                    pj_pool_t *pool,
 
1579
                                    unsigned clock_rate,
 
1580
                                    unsigned channel_count,
 
1581
                                    unsigned samples_per_frame,
 
1582
                                    unsigned flags,
 
1583
                                    struct test_entry *te)
 
1584
{
 
1585
    pjmedia_port *tonegen;
 
1586
    pjmedia_tone_desc tones[2];
 
1587
    pj_status_t status;
 
1588
 
 
1589
    PJ_UNUSED_ARG(flags);
 
1590
    PJ_UNUSED_ARG(te);
 
1591
 
 
1592
    status = pjmedia_tonegen_create(pool, clock_rate, channel_count,
 
1593
                                    samples_per_frame, 16, 
 
1594
                                    PJMEDIA_TONEGEN_LOOP, &tonegen);
 
1595
    if (status != PJ_SUCCESS)
 
1596
        return NULL;
 
1597
 
 
1598
    pj_bzero(tones, sizeof(tones));
 
1599
    tones[0].freq1 = (short)freq1;
 
1600
    tones[0].freq2 = (short)freq2;
 
1601
    tones[0].on_msec = 400;
 
1602
    tones[0].off_msec = 0;
 
1603
    tones[1].freq1 = (short)freq1;
 
1604
    tones[1].freq2 = (short)freq2;
 
1605
    tones[1].on_msec = 400;
 
1606
    tones[1].off_msec = 100;
 
1607
 
 
1608
    status = pjmedia_tonegen_play(tonegen, PJ_ARRAY_SIZE(tones), tones, 
 
1609
                                  PJMEDIA_TONEGEN_LOOP);
 
1610
    if (status != PJ_SUCCESS)
 
1611
        return NULL;
 
1612
 
 
1613
    return tonegen;
 
1614
}
 
1615
 
 
1616
/* Tonegen with single frequency */
 
1617
static pjmedia_port* create_tonegen1(pj_pool_t *pool,
 
1618
                                     unsigned clock_rate,
 
1619
                                     unsigned channel_count,
 
1620
                                     unsigned samples_per_frame,
 
1621
                                     unsigned flags,
 
1622
                                     struct test_entry *te)
 
1623
{
 
1624
    return create_tonegen(400, 0, pool, clock_rate, channel_count,
 
1625
                          samples_per_frame, flags, te);
 
1626
}
 
1627
 
 
1628
/* Tonegen with dual frequency */
 
1629
static pjmedia_port* create_tonegen2(pj_pool_t *pool,
 
1630
                                     unsigned clock_rate,
 
1631
                                     unsigned channel_count,
 
1632
                                     unsigned samples_per_frame,
 
1633
                                     unsigned flags,
 
1634
                                     struct test_entry *te)
 
1635
{
 
1636
    return create_tonegen(400, 440, pool, clock_rate, channel_count,
 
1637
                          samples_per_frame, flags, te);
 
1638
}
 
1639
 
 
1640
 
 
1641
 
 
1642
/***************************************************************************/
 
1643
/* Stream */
 
1644
 
 
1645
struct stream_port
 
1646
{
 
1647
    pjmedia_port         base;
 
1648
    pj_status_t        (*codec_deinit)();
 
1649
    pjmedia_endpt       *endpt;
 
1650
    pjmedia_stream      *stream;
 
1651
    pjmedia_transport   *transport;
 
1652
};
 
1653
 
 
1654
 
 
1655
static void stream_port_custom_deinit(struct test_entry *te)
 
1656
{
 
1657
    struct stream_port *sp = (struct stream_port*) te->pdata[0];
 
1658
 
 
1659
    pjmedia_stream_destroy(sp->stream);
 
1660
    pjmedia_transport_close(sp->transport);
 
1661
    sp->codec_deinit();
 
1662
    pjmedia_endpt_destroy(sp->endpt);
 
1663
 
 
1664
}
 
1665
 
 
1666
static pjmedia_port* create_stream( pj_pool_t *pool,
 
1667
                                    const char *codec,
 
1668
                                    pj_status_t (*codec_init)(pjmedia_endpt*),
 
1669
                                    pj_status_t (*codec_deinit)(),
 
1670
                                    pj_bool_t srtp_enabled,
 
1671
                                    pj_bool_t srtp_80,
 
1672
                                    pj_bool_t srtp_auth,
 
1673
                                    unsigned clock_rate,
 
1674
                                    unsigned channel_count,
 
1675
                                    unsigned samples_per_frame,
 
1676
                                    unsigned flags,
 
1677
                                    struct test_entry *te)
 
1678
{
 
1679
    struct stream_port *sp;
 
1680
    pj_str_t codec_id;
 
1681
    pjmedia_port *port;
 
1682
    const pjmedia_codec_info *ci[1];
 
1683
    unsigned count;
 
1684
    pjmedia_codec_param codec_param;
 
1685
    pjmedia_stream_info si;
 
1686
    pj_status_t status;
 
1687
 
 
1688
    PJ_UNUSED_ARG(flags);
 
1689
 
 
1690
    codec_id = pj_str((char*)codec);
 
1691
    sp = PJ_POOL_ZALLOC_T(pool, struct stream_port);
 
1692
    pjmedia_port_info_init(&sp->base.info, &codec_id, 0x123456, clock_rate,
 
1693
                           channel_count, 16, samples_per_frame);
 
1694
 
 
1695
    te->pdata[0] = sp;
 
1696
    te->custom_deinit = &stream_port_custom_deinit;
 
1697
    sp->codec_deinit = codec_deinit;
 
1698
 
 
1699
    status = pjmedia_endpt_create(mem, NULL, 0, &sp->endpt);
 
1700
    if (status != PJ_SUCCESS)
 
1701
        return NULL;
 
1702
 
 
1703
    status = codec_init(sp->endpt);
 
1704
    if (status != PJ_SUCCESS)
 
1705
        return NULL;
 
1706
 
 
1707
    count = 1;
 
1708
    status = pjmedia_codec_mgr_find_codecs_by_id(pjmedia_endpt_get_codec_mgr(sp->endpt),
 
1709
                                                 &codec_id, &count, ci, NULL);
 
1710
    if (status != PJ_SUCCESS)
 
1711
        return NULL;
 
1712
 
 
1713
 
 
1714
 
 
1715
    status = pjmedia_codec_mgr_get_default_param(pjmedia_endpt_get_codec_mgr(sp->endpt),
 
1716
                                                 ci[0], &codec_param);
 
1717
    if (status != PJ_SUCCESS)
 
1718
        return NULL;
 
1719
 
 
1720
    /* Create stream info */
 
1721
    pj_bzero(&si, sizeof(si));
 
1722
    si.type = PJMEDIA_TYPE_AUDIO;
 
1723
    si.proto = PJMEDIA_TP_PROTO_RTP_AVP;
 
1724
    si.dir = PJMEDIA_DIR_ENCODING_DECODING;
 
1725
    pj_sockaddr_in_init(&si.rem_addr.ipv4, NULL, 4000);
 
1726
    pj_sockaddr_in_init(&si.rem_rtcp.ipv4, NULL, 4001);
 
1727
    pj_memcpy(&si.fmt, ci[0], sizeof(pjmedia_codec_info));
 
1728
    si.param = NULL;
 
1729
    si.tx_pt = ci[0]->pt;
 
1730
    si.tx_event_pt = 101;
 
1731
    si.rx_event_pt = 101;
 
1732
    si.ssrc = pj_rand();
 
1733
    si.jb_init = si.jb_min_pre = si.jb_max_pre = si.jb_max = -1;
 
1734
 
 
1735
    /* Create loop transport */
 
1736
    status = pjmedia_transport_loop_create(sp->endpt, &sp->transport);
 
1737
    if (status != PJ_SUCCESS)
 
1738
        return NULL;
 
1739
 
 
1740
    if (srtp_enabled) {
 
1741
        pjmedia_srtp_setting opt;
 
1742
        pjmedia_srtp_crypto crypto;
 
1743
        pjmedia_transport *srtp;
 
1744
 
 
1745
        pjmedia_srtp_setting_default(&opt);
 
1746
        opt.close_member_tp = PJ_TRUE;
 
1747
        opt.use = PJMEDIA_SRTP_MANDATORY;
 
1748
 
 
1749
        status = pjmedia_transport_srtp_create(sp->endpt, sp->transport, &opt,
 
1750
                                               &srtp);
 
1751
        if (status != PJ_SUCCESS)
 
1752
            return NULL;
 
1753
 
 
1754
        pj_bzero(&crypto, sizeof(crypto));
 
1755
        if (srtp_80) {
 
1756
            crypto.key = pj_str("123456789012345678901234567890");
 
1757
            crypto.name = pj_str("AES_CM_128_HMAC_SHA1_80");
 
1758
        } else {
 
1759
            crypto.key = pj_str("123456789012345678901234567890");
 
1760
            crypto.name = pj_str("AES_CM_128_HMAC_SHA1_32");
 
1761
        }
 
1762
 
 
1763
        if (!srtp_auth)
 
1764
            crypto.flags = PJMEDIA_SRTP_NO_AUTHENTICATION;
 
1765
 
 
1766
        status = pjmedia_transport_srtp_start(srtp, &crypto, &crypto);
 
1767
        if (status != PJ_SUCCESS)
 
1768
            return NULL;
 
1769
 
 
1770
        sp->transport = srtp;
 
1771
    }
 
1772
 
 
1773
    /* Create stream */
 
1774
    status = pjmedia_stream_create(sp->endpt, pool, &si, sp->transport, NULL, 
 
1775
                                   &sp->stream);
 
1776
    if (status != PJ_SUCCESS)
 
1777
        return NULL;
 
1778
 
 
1779
    /* Start stream */
 
1780
    status = pjmedia_stream_start(sp->stream);
 
1781
    if (status != PJ_SUCCESS)
 
1782
        return NULL;
 
1783
 
 
1784
    status = pjmedia_stream_get_port(sp->stream, &port);
 
1785
    if (status != PJ_SUCCESS)
 
1786
        return NULL;
 
1787
 
 
1788
    return port;
 
1789
}
 
1790
 
 
1791
/* G.711 stream, no SRTP */
 
1792
static pjmedia_port* create_stream_pcmu( pj_pool_t *pool,
 
1793
                                         unsigned clock_rate,
 
1794
                                         unsigned channel_count,
 
1795
                                         unsigned samples_per_frame,
 
1796
                                         unsigned flags,
 
1797
                                         struct test_entry *te)
 
1798
{
 
1799
    return create_stream(pool, "pcmu", &pjmedia_codec_g711_init, 
 
1800
                         &pjmedia_codec_g711_deinit,
 
1801
                         PJ_FALSE, PJ_FALSE, PJ_FALSE,
 
1802
                         clock_rate, channel_count,
 
1803
                         samples_per_frame, flags, te);
 
1804
}
 
1805
 
 
1806
/* G.711 stream, SRTP 32bit key no auth */
 
1807
static pjmedia_port* create_stream_pcmu_srtp32_no_auth( pj_pool_t *pool,
 
1808
                                                        unsigned clock_rate,
 
1809
                                                        unsigned channel_count,
 
1810
                                                        unsigned samples_per_frame,
 
1811
                                                        unsigned flags,
 
1812
                                                        struct test_entry *te)
 
1813
{
 
1814
    return create_stream(pool, "pcmu", &pjmedia_codec_g711_init, 
 
1815
                         &pjmedia_codec_g711_deinit,
 
1816
                         PJ_TRUE, PJ_FALSE, PJ_FALSE,
 
1817
                         clock_rate, channel_count,
 
1818
                         samples_per_frame, flags, te);
 
1819
}
 
1820
 
 
1821
/* G.711 stream, SRTP 32bit key with auth */
 
1822
static pjmedia_port* create_stream_pcmu_srtp32_with_auth(pj_pool_t *pool,
 
1823
                                                         unsigned clock_rate,
 
1824
                                                         unsigned channel_count,
 
1825
                                                         unsigned samples_per_frame,
 
1826
                                                         unsigned flags,
 
1827
                                                         struct test_entry *te)
 
1828
{
 
1829
    return create_stream(pool, "pcmu", &pjmedia_codec_g711_init, 
 
1830
                         &pjmedia_codec_g711_deinit,
 
1831
                         PJ_TRUE, PJ_FALSE, PJ_TRUE,
 
1832
                         clock_rate, channel_count,
 
1833
                         samples_per_frame, flags, te);
 
1834
}
 
1835
 
 
1836
/* G.711 stream, SRTP 80bit key no auth */
 
1837
static pjmedia_port* create_stream_pcmu_srtp80_no_auth( pj_pool_t *pool,
 
1838
                                                        unsigned clock_rate,
 
1839
                                                        unsigned channel_count,
 
1840
                                                        unsigned samples_per_frame,
 
1841
                                                        unsigned flags,
 
1842
                                                        struct test_entry *te)
 
1843
{
 
1844
    return create_stream(pool, "pcmu", &pjmedia_codec_g711_init, 
 
1845
                         &pjmedia_codec_g711_deinit,
 
1846
                         PJ_TRUE, PJ_TRUE, PJ_FALSE,
 
1847
                         clock_rate, channel_count,
 
1848
                         samples_per_frame, flags, te);
 
1849
}
 
1850
 
 
1851
/* G.711 stream, SRTP 80bit key with auth */
 
1852
static pjmedia_port* create_stream_pcmu_srtp80_with_auth(pj_pool_t *pool,
 
1853
                                                         unsigned clock_rate,
 
1854
                                                         unsigned channel_count,
 
1855
                                                         unsigned samples_per_frame,
 
1856
                                                         unsigned flags,
 
1857
                                                         struct test_entry *te)
 
1858
{
 
1859
    return create_stream(pool, "pcmu", &pjmedia_codec_g711_init, 
 
1860
                         &pjmedia_codec_g711_deinit,
 
1861
                         PJ_TRUE, PJ_TRUE, PJ_TRUE,
 
1862
                         clock_rate, channel_count,
 
1863
                         samples_per_frame, flags, te);
 
1864
}
 
1865
 
 
1866
/* GSM stream */
 
1867
static pjmedia_port* create_stream_gsm(  pj_pool_t *pool,
 
1868
                                         unsigned clock_rate,
 
1869
                                         unsigned channel_count,
 
1870
                                         unsigned samples_per_frame,
 
1871
                                         unsigned flags,
 
1872
                                         struct test_entry *te)
 
1873
{
 
1874
    return create_stream(pool, "gsm", &pjmedia_codec_gsm_init, 
 
1875
                         &pjmedia_codec_gsm_deinit, 
 
1876
                         PJ_FALSE, PJ_FALSE, PJ_FALSE,
 
1877
                         clock_rate, channel_count,
 
1878
                         samples_per_frame, flags, te);
 
1879
}
 
1880
 
 
1881
/* GSM stream, SRTP 32bit, no auth */
 
1882
static pjmedia_port* create_stream_gsm_srtp32_no_auth(pj_pool_t *pool,
 
1883
                                                      unsigned clock_rate,
 
1884
                                                      unsigned channel_count,
 
1885
                                                      unsigned samples_per_frame,
 
1886
                                                      unsigned flags,
 
1887
                                                      struct test_entry *te)
 
1888
{
 
1889
    return create_stream(pool, "gsm", &pjmedia_codec_gsm_init, 
 
1890
                         &pjmedia_codec_gsm_deinit, 
 
1891
                         PJ_TRUE, PJ_FALSE, PJ_FALSE,
 
1892
                         clock_rate, channel_count,
 
1893
                         samples_per_frame, flags, te);
 
1894
}
 
1895
 
 
1896
/* GSM stream, SRTP 32bit, with auth */
 
1897
static pjmedia_port* create_stream_gsm_srtp32_with_auth(pj_pool_t *pool,
 
1898
                                                        unsigned clock_rate,
 
1899
                                                        unsigned channel_count,
 
1900
                                                        unsigned samples_per_frame,
 
1901
                                                        unsigned flags,
 
1902
                                                        struct test_entry *te)
 
1903
{
 
1904
    return create_stream(pool, "gsm", &pjmedia_codec_gsm_init, 
 
1905
                         &pjmedia_codec_gsm_deinit, 
 
1906
                         PJ_TRUE, PJ_FALSE, PJ_TRUE,
 
1907
                         clock_rate, channel_count,
 
1908
                         samples_per_frame, flags, te);
 
1909
}
 
1910
 
 
1911
/* GSM stream, SRTP 80bit, no auth */
 
1912
static pjmedia_port* create_stream_gsm_srtp80_no_auth(pj_pool_t *pool,
 
1913
                                                      unsigned clock_rate,
 
1914
                                                      unsigned channel_count,
 
1915
                                                      unsigned samples_per_frame,
 
1916
                                                      unsigned flags,
 
1917
                                                      struct test_entry *te)
 
1918
{
 
1919
    return create_stream(pool, "gsm", &pjmedia_codec_gsm_init, 
 
1920
                         &pjmedia_codec_gsm_deinit, 
 
1921
                         PJ_TRUE, PJ_TRUE, PJ_FALSE,
 
1922
                         clock_rate, channel_count,
 
1923
                         samples_per_frame, flags, te);
 
1924
}
 
1925
 
 
1926
/* GSM stream, SRTP 80bit, with auth */
 
1927
static pjmedia_port* create_stream_gsm_srtp80_with_auth(pj_pool_t *pool,
 
1928
                                                        unsigned clock_rate,
 
1929
                                                        unsigned channel_count,
 
1930
                                                        unsigned samples_per_frame,
 
1931
                                                        unsigned flags,
 
1932
                                                        struct test_entry *te)
 
1933
{
 
1934
    return create_stream(pool, "gsm", &pjmedia_codec_gsm_init, 
 
1935
                         &pjmedia_codec_gsm_deinit, 
 
1936
                         PJ_TRUE, PJ_TRUE, PJ_TRUE,
 
1937
                         clock_rate, channel_count,
 
1938
                         samples_per_frame, flags, te);
 
1939
}
 
1940
 
 
1941
/* G722 stream */
 
1942
static pjmedia_port* create_stream_g722( pj_pool_t *pool,
 
1943
                                         unsigned clock_rate,
 
1944
                                         unsigned channel_count,
 
1945
                                         unsigned samples_per_frame,
 
1946
                                         unsigned flags,
 
1947
                                         struct test_entry *te)
 
1948
{
 
1949
    return create_stream(pool, "g722", &pjmedia_codec_g722_init, 
 
1950
                         &pjmedia_codec_g722_deinit, 
 
1951
                         PJ_FALSE, PJ_FALSE, PJ_FALSE,
 
1952
                         clock_rate, channel_count,
 
1953
                         samples_per_frame, flags, te);
 
1954
}
 
1955
 
 
1956
/* G722.1 stream */
 
1957
#if PJMEDIA_HAS_G7221_CODEC
 
1958
static pjmedia_port* create_stream_g7221( pj_pool_t *pool,
 
1959
                                          unsigned clock_rate,
 
1960
                                          unsigned channel_count,
 
1961
                                          unsigned samples_per_frame,
 
1962
                                          unsigned flags,
 
1963
                                          struct test_entry *te)
 
1964
{
 
1965
    return create_stream(pool, "g7221/16000", &pjmedia_codec_g7221_init, 
 
1966
                         &pjmedia_codec_g7221_deinit, 
 
1967
                         PJ_FALSE, PJ_FALSE, PJ_FALSE,
 
1968
                         clock_rate, channel_count,
 
1969
                         samples_per_frame, flags, te);
 
1970
}
 
1971
 
 
1972
/* G722.1 Annex C stream */
 
1973
static pjmedia_port* create_stream_g7221c( pj_pool_t *pool,
 
1974
                                           unsigned clock_rate,
 
1975
                                           unsigned channel_count,
 
1976
                                           unsigned samples_per_frame,
 
1977
                                           unsigned flags,
 
1978
                                           struct test_entry *te)
 
1979
{
 
1980
    return create_stream(pool, "g7221/32000", &pjmedia_codec_g7221_init,
 
1981
                         &pjmedia_codec_g7221_deinit, 
 
1982
                         PJ_FALSE, PJ_FALSE, PJ_FALSE,
 
1983
                         clock_rate, channel_count,
 
1984
                         samples_per_frame, flags, te);
 
1985
}
 
1986
#endif  /* PJMEDIA_HAS_G7221_CODEC */ 
 
1987
 
 
1988
/***************************************************************************/
 
1989
/* Delay buffer */
 
1990
enum {DELAY_BUF_MAX_DELAY = 80};
 
1991
struct delaybuf_port
 
1992
{
 
1993
    pjmedia_port         base;
 
1994
    pjmedia_delay_buf   *delaybuf;
 
1995
    pjmedia_port        *gen_port;
 
1996
    int                  drift_pct;
 
1997
};
 
1998
 
 
1999
 
 
2000
static pj_status_t delaybuf_get_frame(struct pjmedia_port *this_port, 
 
2001
                                      pjmedia_frame *frame)
 
2002
{
 
2003
    struct delaybuf_port *dp = (struct delaybuf_port*)this_port;
 
2004
    pj_status_t status;
 
2005
 
 
2006
    status = pjmedia_delay_buf_get(dp->delaybuf, (pj_int16_t*)frame->buf);
 
2007
    pj_assert(status == PJ_SUCCESS);
 
2008
 
 
2009
    /* Additional GET when drift_pct is negative */
 
2010
    if (dp->drift_pct < 0) {
 
2011
        int rnd;
 
2012
        rnd = pj_rand() % 100;
 
2013
 
 
2014
        if (rnd < -dp->drift_pct) {
 
2015
            status = pjmedia_delay_buf_get(dp->delaybuf, (pj_int16_t*)frame->buf);
 
2016
            pj_assert(status == PJ_SUCCESS);
 
2017
        }
 
2018
    }
 
2019
 
 
2020
    return PJ_SUCCESS;
 
2021
}
 
2022
 
 
2023
static pj_status_t delaybuf_put_frame(struct pjmedia_port *this_port, 
 
2024
                                      const pjmedia_frame *frame)
 
2025
{
 
2026
    struct delaybuf_port *dp = (struct delaybuf_port*)this_port;
 
2027
    pj_status_t status;
 
2028
    pjmedia_frame f = *frame;
 
2029
 
 
2030
    status = pjmedia_port_get_frame(dp->gen_port, &f);
 
2031
    pj_assert(status == PJ_SUCCESS);
 
2032
    status = pjmedia_delay_buf_put(dp->delaybuf, (pj_int16_t*)f.buf);
 
2033
    pj_assert(status == PJ_SUCCESS);
 
2034
 
 
2035
    /* Additional PUT when drift_pct is possitive */
 
2036
    if (dp->drift_pct > 0) {
 
2037
        int rnd;
 
2038
        rnd = pj_rand() % 100;
 
2039
 
 
2040
        if (rnd < dp->drift_pct) {
 
2041
            status = pjmedia_port_get_frame(dp->gen_port, &f);
 
2042
            pj_assert(status == PJ_SUCCESS);
 
2043
            status = pjmedia_delay_buf_put(dp->delaybuf, (pj_int16_t*)f.buf);
 
2044
            pj_assert(status == PJ_SUCCESS);
 
2045
        }
 
2046
    }
 
2047
 
 
2048
    return PJ_SUCCESS;
 
2049
}
 
2050
 
 
2051
static pj_status_t delaybuf_on_destroy(struct pjmedia_port *this_port)
 
2052
{
 
2053
    struct delaybuf_port *dp = (struct delaybuf_port*)this_port;
 
2054
    pjmedia_port_destroy(dp->gen_port);
 
2055
    pjmedia_delay_buf_destroy(dp->delaybuf);
 
2056
    return PJ_SUCCESS;
 
2057
}
 
2058
 
 
2059
static pjmedia_port* create_delaybuf(int drift_pct,
 
2060
                                     pj_pool_t *pool,
 
2061
                                     unsigned clock_rate,
 
2062
                                     unsigned channel_count,
 
2063
                                     unsigned samples_per_frame,
 
2064
                                     unsigned flags,
 
2065
                                     struct test_entry *te)
 
2066
{
 
2067
    struct delaybuf_port *dp;
 
2068
    pj_str_t name = pj_str("delaybuf");
 
2069
    unsigned opt = 0;
 
2070
    pj_status_t status;
 
2071
 
 
2072
    PJ_UNUSED_ARG(flags);
 
2073
    PJ_UNUSED_ARG(te);
 
2074
 
 
2075
    dp = PJ_POOL_ZALLOC_T(pool, struct delaybuf_port);
 
2076
    dp->drift_pct = drift_pct;
 
2077
    dp->base.get_frame = &delaybuf_get_frame;
 
2078
    dp->base.put_frame = &delaybuf_put_frame;
 
2079
    dp->base.on_destroy = &delaybuf_on_destroy;
 
2080
    pjmedia_port_info_init(&dp->base.info, &name, 0x5678, clock_rate, 
 
2081
                           channel_count, 16, samples_per_frame);
 
2082
 
 
2083
    status = pjmedia_delay_buf_create(pool, "mips_test", clock_rate, 
 
2084
                                      samples_per_frame, channel_count, 
 
2085
                                      DELAY_BUF_MAX_DELAY,
 
2086
                                      opt, &dp->delaybuf);
 
2087
    if (status != PJ_SUCCESS)
 
2088
        return NULL;
 
2089
 
 
2090
    dp->gen_port = create_gen_port(pool, clock_rate, channel_count, 
 
2091
                                   samples_per_frame, 100);
 
2092
    if (dp->gen_port == NULL)
 
2093
        return NULL;
 
2094
 
 
2095
    return &dp->base;
 
2096
}
 
2097
 
 
2098
 
 
2099
/* Delay buffer without drift */
 
2100
static pjmedia_port* delaybuf_0( pj_pool_t *pool,
 
2101
                                  unsigned clock_rate,
 
2102
                                  unsigned channel_count,
 
2103
                                  unsigned samples_per_frame,
 
2104
                                  unsigned flags,
 
2105
                                  struct test_entry *te)
 
2106
{
 
2107
    return create_delaybuf(0, pool, clock_rate, channel_count, 
 
2108
                           samples_per_frame, flags, te);
 
2109
}
 
2110
 
 
2111
 
 
2112
/* Delay buffer with 2% drift */
 
2113
static pjmedia_port* delaybuf_p2( pj_pool_t *pool,
 
2114
                                  unsigned clock_rate,
 
2115
                                  unsigned channel_count,
 
2116
                                  unsigned samples_per_frame,
 
2117
                                  unsigned flags,
 
2118
                                  struct test_entry *te)
 
2119
{
 
2120
    return create_delaybuf(2, pool, clock_rate, channel_count, 
 
2121
                           samples_per_frame, flags, te);
 
2122
}
 
2123
 
 
2124
/* Delay buffer with 5% drift */
 
2125
static pjmedia_port* delaybuf_p5( pj_pool_t *pool,
 
2126
                                  unsigned clock_rate,
 
2127
                                  unsigned channel_count,
 
2128
                                  unsigned samples_per_frame,
 
2129
                                  unsigned flags,
 
2130
                                  struct test_entry *te)
 
2131
{
 
2132
    return create_delaybuf(5, pool, clock_rate, channel_count, 
 
2133
                           samples_per_frame, flags, te);
 
2134
}
 
2135
 
 
2136
/* Delay buffer with 10% drift */
 
2137
static pjmedia_port* delaybuf_p10(pj_pool_t *pool,
 
2138
                                  unsigned clock_rate,
 
2139
                                  unsigned channel_count,
 
2140
                                  unsigned samples_per_frame,
 
2141
                                  unsigned flags,
 
2142
                                  struct test_entry *te)
 
2143
{
 
2144
    return create_delaybuf(10, pool, clock_rate, channel_count, 
 
2145
                           samples_per_frame, flags, te);
 
2146
}
 
2147
 
 
2148
/* Delay buffer with 20% drift */
 
2149
static pjmedia_port* delaybuf_p20(pj_pool_t *pool,
 
2150
                                  unsigned clock_rate,
 
2151
                                  unsigned channel_count,
 
2152
                                  unsigned samples_per_frame,
 
2153
                                  unsigned flags,
 
2154
                                  struct test_entry *te)
 
2155
{
 
2156
    return create_delaybuf(20, pool, clock_rate, channel_count, 
 
2157
                           samples_per_frame, flags, te);
 
2158
}
 
2159
 
 
2160
/* Delay buffer with -2% drift */
 
2161
static pjmedia_port* delaybuf_n2( pj_pool_t *pool,
 
2162
                                  unsigned clock_rate,
 
2163
                                  unsigned channel_count,
 
2164
                                  unsigned samples_per_frame,
 
2165
                                  unsigned flags,
 
2166
                                  struct test_entry *te)
 
2167
{
 
2168
    return create_delaybuf(-2, pool, clock_rate, channel_count, 
 
2169
                           samples_per_frame, flags, te);
 
2170
}
 
2171
 
 
2172
/* Delay buffer with -5% drift */
 
2173
static pjmedia_port* delaybuf_n5( pj_pool_t *pool,
 
2174
                                  unsigned clock_rate,
 
2175
                                  unsigned channel_count,
 
2176
                                  unsigned samples_per_frame,
 
2177
                                  unsigned flags,
 
2178
                                  struct test_entry *te)
 
2179
{
 
2180
    return create_delaybuf(-5, pool, clock_rate, channel_count, 
 
2181
                           samples_per_frame, flags, te);
 
2182
}
 
2183
 
 
2184
/* Delay buffer with -10% drift */
 
2185
static pjmedia_port* delaybuf_n10(pj_pool_t *pool,
 
2186
                                  unsigned clock_rate,
 
2187
                                  unsigned channel_count,
 
2188
                                  unsigned samples_per_frame,
 
2189
                                  unsigned flags,
 
2190
                                  struct test_entry *te)
 
2191
{
 
2192
    return create_delaybuf(-10, pool, clock_rate, channel_count, 
 
2193
                           samples_per_frame, flags, te);
 
2194
}
 
2195
 
 
2196
/* Delay buffer with -20% drift */
 
2197
static pjmedia_port* delaybuf_n20(pj_pool_t *pool,
 
2198
                                  unsigned clock_rate,
 
2199
                                  unsigned channel_count,
 
2200
                                  unsigned samples_per_frame,
 
2201
                                  unsigned flags,
 
2202
                                  struct test_entry *te)
 
2203
{
 
2204
    return create_delaybuf(-20, pool, clock_rate, channel_count, 
 
2205
                           samples_per_frame, flags, te);
 
2206
}
 
2207
 
 
2208
 
 
2209
/***************************************************************************/
 
2210
/* Run test entry, return elapsed time */
 
2211
static pj_timestamp run_entry(unsigned clock_rate, struct test_entry *e)
 
2212
{
 
2213
    pj_pool_t *pool;
 
2214
    pjmedia_port *port;
 
2215
    pj_timestamp t0, t1;
 
2216
    unsigned j, samples_per_frame;
 
2217
    pj_int16_t pcm[32000 * PTIME / 1000];
 
2218
    pjmedia_port *gen_port;
 
2219
    pj_status_t status;
 
2220
 
 
2221
    samples_per_frame = clock_rate * PTIME / 1000;
 
2222
 
 
2223
    pool = pj_pool_create(mem, "pool", 1024, 1024, NULL);
 
2224
    port = e->init(pool, clock_rate, 1, samples_per_frame, 0, e);
 
2225
    if (port == NULL) {
 
2226
        t0.u64 = 0;
 
2227
        pj_pool_release(pool);
 
2228
        PJ_LOG(1,(THIS_FILE, " init error"));
 
2229
        return t0;
 
2230
    }
 
2231
 
 
2232
    /* Port may decide to use different ptime (e.g. iLBC) */
 
2233
    samples_per_frame = port->info.samples_per_frame;
 
2234
 
 
2235
    gen_port = create_gen_port(pool, clock_rate, 1, 
 
2236
                               samples_per_frame, 100);
 
2237
    if (gen_port == NULL) {
 
2238
        t0.u64 = 0;
 
2239
        pj_pool_release(pool);
 
2240
        return t0;
 
2241
    }
 
2242
 
 
2243
    pj_get_timestamp(&t0);
 
2244
    for (j=0; j<DURATION*clock_rate/samples_per_frame/1000; ++j) {
 
2245
        pjmedia_frame frm;
 
2246
 
 
2247
        if (e->valid_op==OP_GET_PUT) {
 
2248
            frm.buf = (void*)pcm;
 
2249
            frm.size = samples_per_frame * 2;
 
2250
            frm.type = PJMEDIA_FRAME_TYPE_NONE;
 
2251
 
 
2252
            status = pjmedia_port_get_frame(port, &frm);
 
2253
            pj_assert(status == PJ_SUCCESS);
 
2254
 
 
2255
            status = pjmedia_port_put_frame(port, &frm);
 
2256
            pj_assert(status == PJ_SUCCESS);
 
2257
 
 
2258
        } else if (e->valid_op == OP_GET) {
 
2259
            frm.buf = (void*)pcm;
 
2260
            frm.size = samples_per_frame * 2;
 
2261
            frm.type = PJMEDIA_FRAME_TYPE_NONE;
 
2262
 
 
2263
            status = pjmedia_port_get_frame(port, &frm);
 
2264
            pj_assert(status == PJ_SUCCESS);
 
2265
 
 
2266
        } else if (e->valid_op == OP_PUT) {
 
2267
            frm.buf = (void*)pcm;
 
2268
            frm.size = samples_per_frame * 2;
 
2269
            frm.type = PJMEDIA_FRAME_TYPE_NONE;
 
2270
 
 
2271
            status = pjmedia_port_get_frame(gen_port, &frm);
 
2272
            pj_assert(status == PJ_SUCCESS);
 
2273
 
 
2274
            status = pjmedia_port_put_frame(port, &frm);
 
2275
            pj_assert(status == PJ_SUCCESS);
 
2276
 
 
2277
        } else if (e->valid_op == OP_PUT_GET) {
 
2278
            frm.buf = (void*)pcm;
 
2279
            frm.size = samples_per_frame * 2;
 
2280
            frm.type = PJMEDIA_FRAME_TYPE_NONE;
 
2281
 
 
2282
            status = pjmedia_port_get_frame(gen_port, &frm);
 
2283
            pj_assert(status == PJ_SUCCESS);
 
2284
 
 
2285
            status = pjmedia_port_put_frame(port, &frm);
 
2286
            pj_assert(status == PJ_SUCCESS);
 
2287
 
 
2288
            status = pjmedia_port_get_frame(port, &frm);
 
2289
            pj_assert(status == PJ_SUCCESS);
 
2290
        }
 
2291
    }
 
2292
    pj_get_timestamp(&t1);
 
2293
 
 
2294
    pj_sub_timestamp(&t1, &t0);
 
2295
 
 
2296
    if (e->custom_deinit)
 
2297
        e->custom_deinit(e);
 
2298
 
 
2299
    pjmedia_port_destroy(port);
 
2300
    pj_pool_release(pool);
 
2301
 
 
2302
    return t1;
 
2303
}
 
2304
 
 
2305
/***************************************************************************/
 
2306
int mips_test(void)
 
2307
{
 
2308
    struct test_entry entries[] = {
 
2309
        { "get from memplayer", OP_GET, K8|K16, &gen_port_test_init},
 
2310
        { "conference bridge with 1 call", OP_GET_PUT, K8|K16, &conf1_test_init},
 
2311
        { "conference bridge with 2 calls", OP_GET_PUT, K8|K16, &conf2_test_init},
 
2312
        { "conference bridge with 4 calls", OP_GET_PUT, K8|K16, &conf4_test_init},
 
2313
        { "conference bridge with 8 calls", OP_GET_PUT, K8|K16, &conf8_test_init},
 
2314
        { "conference bridge with 16 calls", OP_GET_PUT, K8|K16, &conf16_test_init},
 
2315
        { "upsample+downsample - linear", OP_GET, K8|K16, &linear_resample},
 
2316
        { "upsample+downsample - small filter", OP_GET, K8|K16, &small_filt_resample},
 
2317
        { "upsample+downsample - large filter", OP_GET, K8|K16, &large_filt_resample},
 
2318
        { "WSOLA PLC - 0% loss", OP_GET, K8|K16, &wsola_plc_0},
 
2319
        { "WSOLA PLC - 2% loss", OP_GET, K8|K16, &wsola_plc_2},
 
2320
        { "WSOLA PLC - 5% loss", OP_GET, K8|K16, &wsola_plc_5},
 
2321
        { "WSOLA PLC - 10% loss", OP_GET, K8|K16, &wsola_plc_10},
 
2322
        { "WSOLA PLC - 20% loss", OP_GET, K8|K16, &wsola_plc_20},
 
2323
        { "WSOLA PLC - 50% loss", OP_GET, K8|K16, &wsola_plc_50},
 
2324
        { "WSOLA discard 2% excess", OP_GET, K8|K16, &wsola_discard_2},
 
2325
        { "WSOLA discard 5% excess", OP_GET, K8|K16, &wsola_discard_5},
 
2326
        { "WSOLA discard 10% excess", OP_GET, K8|K16, &wsola_discard_10},
 
2327
        { "WSOLA discard 20% excess", OP_GET, K8|K16, &wsola_discard_20},
 
2328
        { "WSOLA discard 50% excess", OP_GET, K8|K16, &wsola_discard_50},
 
2329
        { "Delay buffer", OP_GET_PUT, K8|K16, &delaybuf_0},
 
2330
        { "Delay buffer - drift -2%", OP_GET_PUT, K8|K16, &delaybuf_n2},
 
2331
        { "Delay buffer - drift -5%", OP_GET_PUT, K8|K16, &delaybuf_n5},
 
2332
        { "Delay buffer - drift -10%", OP_GET_PUT, K8|K16, &delaybuf_n10},
 
2333
        { "Delay buffer - drift -20%", OP_GET_PUT, K8|K16, &delaybuf_n20},
 
2334
        { "Delay buffer - drift +2%", OP_GET_PUT, K8|K16, &delaybuf_p2},
 
2335
        { "Delay buffer - drift +5%", OP_GET_PUT, K8|K16, &delaybuf_p5},
 
2336
        { "Delay buffer - drift +10%", OP_GET_PUT, K8|K16, &delaybuf_p10},
 
2337
        { "Delay buffer - drift +20%", OP_GET_PUT, K8|K16, &delaybuf_p20},
 
2338
        { "echo canceller 100ms tail len", OP_GET_PUT, K8|K16, &ec_create_100},
 
2339
        { "echo canceller 128ms tail len", OP_GET_PUT, K8|K16, &ec_create_128},
 
2340
        { "echo canceller 200ms tail len", OP_GET_PUT, K8|K16, &ec_create_200},
 
2341
        { "echo canceller 256ms tail len", OP_GET_PUT, K8|K16, &ec_create_256},
 
2342
        { "echo canceller 400ms tail len", OP_GET_PUT, K8|K16, &ec_create_400},
 
2343
        { "echo canceller 500ms tail len", OP_GET_PUT, K8|K16, &ec_create_500},
 
2344
        { "echo canceller 512ms tail len", OP_GET_PUT, K8|K16, &ec_create_512},
 
2345
        { "echo canceller 600ms tail len", OP_GET_PUT, K8|K16, &ec_create_600},
 
2346
        { "echo canceller 800ms tail len", OP_GET_PUT, K8|K16, &ec_create_800},
 
2347
        { "echo suppressor 100ms tail len", OP_GET_PUT, K8|K16, &es_create_100},
 
2348
        { "echo suppressor 128ms tail len", OP_GET_PUT, K8|K16, &es_create_128},
 
2349
        { "echo suppressor 200ms tail len", OP_GET_PUT, K8|K16, &es_create_200},
 
2350
        { "echo suppressor 256ms tail len", OP_GET_PUT, K8|K16, &es_create_256},
 
2351
        { "echo suppressor 400ms tail len", OP_GET_PUT, K8|K16, &es_create_400},
 
2352
        { "echo suppressor 500ms tail len", OP_GET_PUT, K8|K16, &es_create_500},
 
2353
        { "echo suppressor 512ms tail len", OP_GET_PUT, K8|K16, &es_create_512},
 
2354
        { "echo suppressor 600ms tail len", OP_GET_PUT, K8|K16, &es_create_600},
 
2355
        { "echo suppressor 800ms tail len", OP_GET_PUT, K8|K16, &es_create_800},
 
2356
        { "tone generator with single freq", OP_GET, K8|K16, &create_tonegen1},
 
2357
        { "tone generator with dual freq", OP_GET, K8|K16, &create_tonegen2},
 
2358
#if PJMEDIA_HAS_G711_CODEC
 
2359
        { "codec encode/decode - G.711", OP_PUT, K8, &g711_encode_decode},
 
2360
#endif
 
2361
#if PJMEDIA_HAS_G722_CODEC
 
2362
        { "codec encode/decode - G.722", OP_PUT, K16, &g722_encode_decode},
 
2363
#endif
 
2364
#if PJMEDIA_HAS_GSM_CODEC
 
2365
        { "codec encode/decode - GSM", OP_PUT, K8, &gsm_encode_decode},
 
2366
#endif
 
2367
#if PJMEDIA_HAS_ILBC_CODEC
 
2368
        { "codec encode/decode - iLBC", OP_PUT, K8, &ilbc_encode_decode},
 
2369
#endif
 
2370
#if PJMEDIA_HAS_SPEEX_CODEC
 
2371
        { "codec encode/decode - Speex 8Khz", OP_PUT, K8, &speex8_encode_decode},
 
2372
        { "codec encode/decode - Speex 16Khz", OP_PUT, K16, &speex16_encode_decode},
 
2373
#endif
 
2374
#if PJMEDIA_HAS_G7221_CODEC
 
2375
        { "codec encode/decode - G.722.1", OP_PUT, K16, &g7221_encode_decode},
 
2376
        { "codec encode/decode - G.722.1c", OP_PUT, K32, &g7221c_encode_decode},
 
2377
#endif
 
2378
#if PJMEDIA_HAS_L16_CODEC
 
2379
        { "codec encode/decode - L16/8000/1", OP_PUT, K8, &l16_8_encode_decode},
 
2380
        { "codec encode/decode - L16/16000/1", OP_PUT, K16, &l16_16_encode_decode},
 
2381
#endif
 
2382
#if PJMEDIA_HAS_G711_CODEC
 
2383
        { "stream TX/RX - G.711", OP_PUT_GET, K8, &create_stream_pcmu},
 
2384
        { "stream TX/RX - G.711 SRTP 32bit", OP_PUT_GET, K8, &create_stream_pcmu_srtp32_no_auth},
 
2385
        { "stream TX/RX - G.711 SRTP 32bit +auth", OP_PUT_GET, K8, &create_stream_pcmu_srtp32_with_auth},
 
2386
        { "stream TX/RX - G.711 SRTP 80bit", OP_PUT_GET, K8, &create_stream_pcmu_srtp80_no_auth},
 
2387
        { "stream TX/RX - G.711 SRTP 80bit +auth", OP_PUT_GET, K8, &create_stream_pcmu_srtp80_with_auth},
 
2388
#endif
 
2389
#if PJMEDIA_HAS_G722_CODEC
 
2390
        { "stream TX/RX - G.722", OP_PUT_GET, K16, &create_stream_g722},
 
2391
#endif
 
2392
#if PJMEDIA_HAS_GSM_CODEC
 
2393
        { "stream TX/RX - GSM", OP_PUT_GET, K8, &create_stream_gsm},
 
2394
        { "stream TX/RX - GSM SRTP 32bit", OP_PUT_GET, K8, &create_stream_gsm_srtp32_no_auth},
 
2395
        { "stream TX/RX - GSM SRTP 32bit + auth", OP_PUT_GET, K8, &create_stream_gsm_srtp32_with_auth},
 
2396
        { "stream TX/RX - GSM SRTP 80bit", OP_PUT_GET, K8, &create_stream_gsm_srtp80_no_auth},
 
2397
        { "stream TX/RX - GSM SRTP 80bit + auth", OP_PUT_GET, K8, &create_stream_gsm_srtp80_with_auth},
 
2398
#endif
 
2399
#if PJMEDIA_HAS_G7221_CODEC
 
2400
        { "stream TX/RX - G.722.1", OP_PUT_GET, K16, &create_stream_g7221},
 
2401
        { "stream TX/RX - G.722.1c", OP_PUT_GET, K32, &create_stream_g7221c},
 
2402
#endif
 
2403
    };
 
2404
 
 
2405
    unsigned i, c, k[3] = {K8, K16, K32}, clock_rates[3] = {8000, 16000, 32000};
 
2406
 
 
2407
    PJ_LOG(3,(THIS_FILE, "MIPS test, with CPU=%dMhz, %6.1f MIPS", CPU_MHZ, CPU_IPS / 1000000));
 
2408
    PJ_LOG(3,(THIS_FILE, "Clock  Item                                      Time     CPU    MIPS"));
 
2409
    PJ_LOG(3,(THIS_FILE, " Rate                                           (usec)    (%%)       "));
 
2410
    PJ_LOG(3,(THIS_FILE, "----------------------------------------------------------------------"));
 
2411
 
 
2412
    for (c=0; c<PJ_ARRAY_SIZE(clock_rates); ++c) {
 
2413
        for (i=0; i<PJ_ARRAY_SIZE(entries); ++i) {
 
2414
            enum 
 
2415
            {
 
2416
                RETRY   = 5,    /* number of test retries */
 
2417
            };
 
2418
            struct test_entry *e = &entries[i];
 
2419
            pj_timestamp times[RETRY], tzero;
 
2420
            int usec;
 
2421
            float cpu_pct, mips_val;
 
2422
            unsigned j, clock_rate = clock_rates[c];
 
2423
 
 
2424
            if ((e->valid_clock_rate & k[c]) == 0)
 
2425
                continue;
 
2426
 
 
2427
            /* Run test */
 
2428
            for (j=0; j<RETRY; ++j) {
 
2429
                pj_thread_sleep(1);
 
2430
                times[j] = run_entry(clock_rate, e);
 
2431
            }
 
2432
 
 
2433
            /* Sort ascending */
 
2434
            for (j=0; j<RETRY; ++j) {
 
2435
                unsigned k;
 
2436
                for (k=j+1; k<RETRY; ++k) {
 
2437
                    if (times[k].u64 < times[j].u64) {
 
2438
                        pj_timestamp tmp = times[j];
 
2439
                        times[j] = times[k];
 
2440
                        times[k] = tmp;
 
2441
                    }
 
2442
                }
 
2443
            }
 
2444
 
 
2445
            /* Calculate usec elapsed as average of two best times */
 
2446
            tzero.u32.hi = tzero.u32.lo = 0;
 
2447
            usec = (pj_elapsed_usec(&tzero, &times[0]) + 
 
2448
                    pj_elapsed_usec(&tzero, &times[1])) / 2;
 
2449
 
 
2450
            usec = usec / (DURATION / 1000);
 
2451
 
 
2452
            mips_val = (float)(CPU_IPS * usec / 1000000.0 / 1000000);
 
2453
            cpu_pct = (float)(100.0 * usec / 1000000);
 
2454
            PJ_LOG(3,(THIS_FILE, "%2dKHz %-38s % 8d %8.3f %7.2f", 
 
2455
                      clock_rate/1000, e->title, usec, cpu_pct, mips_val));
 
2456
 
 
2457
        }
 
2458
    }
 
2459
 
 
2460
    return 0;
 
2461
}
 
2462
 
 
2463
 
 
2464