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