Debian Codegraph @

Xpjproject/pjmedia/src/test/mips_test.c

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