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