test.cpp 77.7 KB
Newer Older
sletz's avatar
sletz committed
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
    Log("---------------------------DEVICES-------------------------\n");
    Log("-----------------------------------------------------------\n");
    a = 0;
    while (inports[a] != NULL) {
        flag = jack_port_flags(jack_port_by_name(client1, inports[a]) );
        Log("   * %s (id : %i)\n", inports[a], jack_port_by_name(client1, inports[a]));
        Log("    (");
        if (flag & JackPortIsInput)
            Log("JackPortIsInput ");
        if (flag & JackPortIsOutput)
            Log("JackPortIsOutput ");
        if (flag & JackPortIsPhysical)
            Log("JackPortIsPhysical ");
        if (flag & JackPortCanMonitor)
            Log("JackPortCanMonitor ");
        if (flag & JackPortIsTerminal)
            Log("JackPortIsTerminal ");
        Log(")\n\n");
        a++;
    }
    Log("-----------------------------------------------------------\n\n");

    /**
     * list all PHY in/out ports...
     * This list will be used later many times.
     *
     */
    outports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsOutput);
    inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);

    if (outports == NULL) {
        printf("!!! WARNING !!! no physical capture ports founded !\n");
    }
    if (inports == NULL) {
        printf("!!! WARNING !!! no physical output ports founded !\n");
    }

    /**
     * Brute test : try to create as many ports as possible.
     * It stops when jack returns an error.
     * Then try to connect each port to physical entry...
     * Check also that graph reorder callback is called.
     *
     */
    Log("Registering as many ports as possible and connect them to physical entries...\n");
    lineports = linecount;
    t_error = 0;

    i = 0;	// number of couple 'input-ouput'
    j = 0;	// number of ports created
    port_callback_reg = 0;	// number of port registration received by the callback
    reorder = 0;			// number of graph reorder callback activation
    test_link = 0 ;			// Test the "overconnect" function only one time
    while (t_error == 0) {
        sprintf (portname, "input_%d", i);
        input_port1 = jack_port_register(client1, portname,
                                         JACK_DEFAULT_AUDIO_TYPE,
                                         JackPortIsInput, 0);
        j++;
        if (input_port1 == NULL) {
            j--;
            t_error = 1;
        } else {
            // Connect created input to PHY output
            a = 0;
            while (outports[a] != NULL) {
                if (jack_connect(client1, outports[a], jack_port_name(input_port1))) {
                    printf ("error : cannot connect input PHY port to client port %s\n", jack_port_name(input_port1));
                } else {
                    // printf ("input PHY port %s connected to client port %s\n", outports[a], jack_port_name(input_port1));
                }
                a++;
            }
            // Try one time to "overconnect" 2 ports (the latest created)...
            if (test_link == 0) {
                if (jack_connect(client1, outports[a - 1], jack_port_name(input_port1)) == EEXIST) {
                    // cannot over-connect input PHY port to client port. ok.
                    test_link = 1;
                }
            }
        }

        sprintf(portname, "output_%d", i);
        output_port1 = jack_port_register(client1, portname,
                                          JACK_DEFAULT_AUDIO_TYPE,
                                          JackPortIsOutput, 0);
        j++;
        if (output_port1 == NULL) {
            t_error = 1;
            j--;
        } else {
            // Connect created input to PHY output
            a = 0;
            while (inports[a] != NULL) {
                if (jack_connect(client1, jack_port_name(output_port1), inports[a])) {
                    printf ("error : cannot connect input PHY port %s to client port %s\n", inports[a], jack_port_name(output_port1));
                } else {
                    // output PHY port %s connected to client port. ok.
                }
                a++;
            }
            // Try one time to "overconnect" 2 ports (the latest created)...
            if (test_link == 0) {
                if (jack_connect(client1, jack_port_name(output_port1), inports[a - 1]) == EEXIST) {
                    // cannot over-connect output PHY port to client port. ok.
                    test_link = 1;
                }
            }
        }
        i++;
    }

    jack_sleep(1 * 1000); // To hope all port registration and reorder callback have been received...
1114
1115
    
    // Check port registration callback
sletz's avatar
sletz committed
1116
1117
1118
    if (j == port_callback_reg) {
        Log("%i ports have been successfully created, and %i callback reg ports have been received... ok\n", j, port_callback_reg);
    } else {
1119
        printf("!!! ERROR !!! %i ports have been created, and %i callback reg ports have been received !\n", j, port_callback_reg);
sletz's avatar
sletz committed
1120
    }
1121
    
sletz's avatar
sletz committed
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
    if (reorder == (2 * j)) {
        Log("%i graph reorder callback have been received... ok\n", reorder);
    } else {
        printf("!!! ERROR !!! %i graph reorder callback have been received (maybe non-valid value)...\n", reorder);
    }
    /**
     * print basic test connection functions result ...
     * over-connected means here that we try to connect 2 ports that are already connected.
     *
     */
    if (test_link) {
        Log("Jack links can't be 'over-connected'... ok\n");
    } else {
        printf("!!! ERROR !!! Jack links can be 'over-connected'...\n");
    }
    /**
     * Print the result of the two jack_is_mine test.
     *
     */
    if (is_mine == 1) {
1142
        Log("Checking jack_port_is_mine()... ok\n");
sletz's avatar
sletz committed
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
    } else {
        printf("!!! ERROR !!! jack_port_is_mine() function seems to send non-valid datas !\n");
    }
    /**
     * Free the array of the physical input and ouput ports.
     * (as mentionned in the doc of jack_get_ports)
     *
     */
    free(inports);
    free(outports);

    /**
     * Try to "reactivate" the client whereas it's already activated...
     *
     */
    if (jack_activate(client1) < 0) {
        printf("!!! ERROR !!! Cannot activate client1 a second time...\n");
        exit(1);
    } else {
        Log("jackd server accept client.jack_activate() re-activation (while client was already activated).\n");
    }

    /**
     * Deregister all ports previously created.
     *
     */
1169
    port_callback_reg = 0; // to check registration callback
sletz's avatar
sletz committed
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
    Log("Deregistering all ports of the client...\n");
    inports = jack_get_ports(client1, NULL, NULL, 0);
    a = 0;
    while (inports[a] != NULL) {
        flag = jack_port_flags(jack_port_by_name(client1, inports[a]));
        input_port1 = jack_port_by_name(client1, inports[a]);
        if (jack_port_is_mine(client1, input_port1)) {
            if (jack_port_unregister(client1, input_port1) != 0) {
                printf("!!! ERROR !!! while unregistering port %s.\n", jack_port_name(output_port1));
            }
        }
        a++;
    }
1183
1184
1185
1186
1187
1188
1189
    
    // Check port registration callback again
    if (j == port_callback_reg) { 
        Log("%i ports have been successfully created, and %i callback reg ports have been received... ok\n", j, port_callback_reg);
    } else {
        printf("!!! ERROR !!! %i ports have been created, and %i callback reg ports have been received !\n", j, port_callback_reg);
    }
sletz's avatar
sletz committed
1190
1191

    free(inports); // free array of ports (as mentionned in the doc of jack_get_ports)
sletz's avatar
sletz committed
1192

sletz's avatar
sletz committed
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
    /**
     *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
     *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
     				Open a new client (second one) to test some other things...
     *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
     *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
     */

    Log("\n\n----------------------------------------------------------------------\n");
    Log("Starting second new client 'jack_test_#2'...\n");
    /* open a client connection to the JACK server */
    client_name2 = "jack_test_#2";
    linecl2 = linecount; // reminders for graph analysis
    client2 = jack_client_new(client_name2);

    if (client2 == NULL) {
        fprintf(stderr, "jack_client_new() failed for %s.\n"
                "status = 0x%2.0x\n", client_name2, status);
        if (status & JackServerFailed) {
            fprintf(stderr, "Unable to connect client2 to JACK server\n");
        }
        exit(1);
    }
sletz's avatar
sletz committed
1216

sletz's avatar
sletz committed
1217
	// Check client registration callback
1218
	jack_sleep(1000);
sletz's avatar
sletz committed
1219
1220
	if (client_register == 0)
		printf("!!! ERROR !!! Client registration callback not called!\n");
sletz's avatar
sletz committed
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292

    /**
     * Register callback for this client.
     * Callbacks are the same as the first client for most of them, excepted for process audio callback.
     *
     */
    jack_set_port_registration_callback(client2, Jack_Port_Register, 0);

    jack_set_process_callback(client2, process2, 0);

    jack_on_shutdown(client2, jack_shutdown, 0);

    /**
     * Register one input and one output for each client.
     *
     */
    Log("registering 1 input/output ports for each client...\n");

    output_port1 = jack_port_register(client1, "out1",
                                      JACK_DEFAULT_AUDIO_TYPE,
                                      JackPortIsOutput, 0);
    output_port2 = jack_port_register(client2, "out2",
                                      JACK_DEFAULT_AUDIO_TYPE,
                                      JackPortIsOutput, 0);
    input_port1 = jack_port_register(client1, "in1",
                                     JACK_DEFAULT_AUDIO_TYPE,
                                     JackPortIsInput, 0);
    input_port2 = jack_port_register(client2, "in2",
                                     JACK_DEFAULT_AUDIO_TYPE,
                                     JackPortIsInput, 0);
    if ((output_port1 == NULL) || (output_port2 == NULL) || (input_port1 == NULL) || (input_port2 == NULL)) {
        printf("!!! ERROR !!! Unable to register ports...\n");
    }

    /**
     * Set each process mode to idle and activate client2
     *
     */
    process2_activated = -1;
    process1_activated = -1;
    if (jack_activate(client2) < 0) {
        printf ("Fatal error : cannot activate client2\n");
        exit (1);
    }

    /**
     * Connect the two clients and check that all connections are well-done.
     *
     */
    Log("Testing connections functions between clients...\n");
    if (jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2)) != 0) {
        printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
    }
    if (jack_connect(client2, jack_port_name(output_port2), jack_port_name(input_port1)) != 0) {
        printf("!!! ERROR !!! while client2 intenting to connect ports...\n");
    }
    if (jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port1)) != 0) {
        printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
    }

    /**
     * Test the port_connected function...
     *
     */
    if ((jack_port_connected(output_port1) == jack_port_connected(input_port1)) &&
            (jack_port_connected(output_port2) == jack_port_connected(input_port2)) &&
            (jack_port_connected(output_port2) == 1) &&
            (jack_port_connected(output_port1) == 2)
       ) {
        Log("Checking jack_port_connected()... ok.\n");
    } else {
        printf("!!! ERROR !!! function jack_port_connected() return a bad value !\n");
sletz's avatar
sletz committed
1293
1294
1295
1296
        printf("jack_port_connected(output_port1) %d\n", jack_port_connected(output_port1));
        printf("jack_port_connected(output_port2) %d\n", jack_port_connected(output_port2));
        printf("jack_port_connected(input_port1) %d\n", jack_port_connected(input_port1));
        printf("jack_port_connected(input_port2) %d\n", jack_port_connected(input_port2));
sletz's avatar
sletz committed
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
    }

    /**
     * Test a new time the port_by_name function...(now we are in multi-client mode)
     *
     */
    Log("Testing again jack_port_by_name...\n");
    if (output_port1 != jack_port_by_name(client1, jack_port_name(output_port1))) {
        printf("!!! ERROR !!! function jack_port_by_name() return bad value in a multi-client application!\n");
        printf("!!! jack_port_by_name(jack_port_name(_ID_) ) != _ID_ in multiclient application.\n");
    } else {
        Log("Checking jack_port_by_name() function with a multi-client application... ok\n");
    }

    /**
     * Test the port_connected_to function...
     *
     */
    if ((jack_port_connected_to (output_port1, jack_port_name(input_port2))) &&
            (!(jack_port_connected_to (output_port2, jack_port_name(input_port2))))) {
        Log("checking jack_port_connected_to()... ok\n");
    } else {
        printf("!!! ERROR !!! jack_port_connected_to() return bad value !\n");
    }

    /**
     * Test the port_get_connections & port_get_all_connections functions...
     *
     */
    Log("Testing jack_port_get_connections and jack_port_get_all_connections...\n");
    a = 0;
    t_error = 0;
    connexions1 = jack_port_get_connections (output_port1);
    connexions2 = jack_port_get_all_connections(client1, output_port1);
    if ((connexions1 == NULL) || (connexions2 == NULL)) {
        printf("!!! ERROR !!! port_get_connexions or port_get_all_connexions return a NULL pointer !\n");
    } else {
        while ((connexions1[a] != NULL) && (connexions2[a] != NULL) && (t_error == 0)) {
            t_error = strcmp(connexions1[a], connexions2[a]);
            a++;
        }

        if (t_error == 0) {
            Log("Checking jack_port_get_connections Vs jack_port_get_all_connections... ok\n");
        } else {
            printf("!!! ERROR !!! while checking jack_port_get_connections Vs jack_port_get_all_connections...\n");
        }
    }
    a = 0;
    t_error = 0;
    inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
    connexions1 = NULL;
    assert(inports != NULL);
    if (inports[0] != NULL) {
        connexions1 = jack_port_get_connections (jack_port_by_name(client1, inports[0]));
        connexions2 = jack_port_get_all_connections(client1, jack_port_by_name(client1, inports[0]));
    }

    free (inports);
    if (connexions1 == NULL) {
1357
        Log("checking jack_port_get_connections() for external client... ok\n");
sletz's avatar
sletz committed
1358
1359
1360
1361
1362
1363
1364
    } else {
        while ((connexions1[a] != NULL) && (connexions2[a] != NULL) && (t_error == 0)) {
            t_error = strcmp(connexions1[a], connexions2[a]);
            a++;
        }
    }
    if (t_error == 0) {
1365
        Log("Checking jack_port_get_connections() Vs jack_port_get_all_connections() on PHY port... ok\n");
sletz's avatar
sletz committed
1366
    } else {
1367
        printf("!!! ERROR !!! while checking jack_port_get_connections() Vs jack_port_get_all_connections() on PHY port...\n");
sletz's avatar
sletz committed
1368
1369
    }

1370
	if (jack_disconnect(client1, jack_port_name(output_port1), jack_port_name(input_port1)) != 0) {
sletz's avatar
sletz committed
1371
1372
        printf("!!! ERROR !!! while client1 intenting to disconnect ports...\n");
    }
1373
1374
    if (jack_disconnect(client1, jack_port_name(output_port2), jack_port_name(input_port1)) != 0) {
        printf("!!! ERROR !!! while client1 intenting to disconnect ports...\n");
sletz's avatar
sletz committed
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
    }
    // No links should subsist now...

    /**
     * Checking data connexion
     * establishing a link between client1.out1 --> client2.in2
     * Send the signal1 test on out1. Record the result into signal2. (see process functions).
    ---------------------------------------------------------------------------*/
    Log("Testing connections datas between clients...\n");
    jack_connect(client2, jack_port_name(output_port1), jack_port_name(input_port2) );
    process2_activated = -1;
    process1_activated = -1;
    Log("process 2 : idle mode...\n");
    Log("Sending datas...");
    index1 = 0;
    index2 = 0;
    process1_activated = 1; // We start emitting first.
    process2_activated = 1; // So record begin at least when we just begin to emitt the signal, else at next call of process with
    // nframe = jack buffersize shifting.

    while (process2_activated == 1) {
        jack_sleep(1 * 1000);
        Log(".");
    }
    index2 = 0;
    Log("\nAnalysing datas...\n"); // search the first occurence of the first element of the reference signal in the recorded signal
    while (signal2[index2] != signal1[1] ) {
        index2++;
        if (index2 == 95999) {
            printf("!!! ERROR !!! Data not found in first connexion data check!\n");
            break;
        }
    }
    index1 = index2;
    Log("Data founded at offset %i.\n", index2);
    // And now we founded were the recorded data are, we can see if the two signals matches...
    while ( (signal2[index2] == signal1[index2 - index1 + 1]) || (index2 == 95999) || ((index2 - index1 + 1) == 47999) ) {
        index2++;
    }
    Log("Checking difference between datas... %i have the same value...\n", index2 - index1);
    if ((index2 - index1) == 48000) {
        Log("Data received are valid...\n");
    } else {
        printf("!!! ERROR !!! data transmission seems not to be valid in first connexion data check!\n");
    }
    if (jack_disconnect(client1, jack_port_name(output_port1), jack_port_name(input_port2) ) != 0)
        // no more connection between ports exist now...
    {
        printf("Error while establishing new connexion (disconnect).\n");
    }

    /**
sletz's avatar
sletz committed
1427
     * Test TIE MODE
sletz's avatar
sletz committed
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
     * (This mode seems to be problematic in standard jack version 0.100. It seems that nobody
     * is used to apply this mode because the tie mode doesn't work at all. A patch seems difficult to produce
     * in this version of jack. Tie mode work well in MP version.)
     * Test some basic thinks (tie with 2 differents client, tie non-owned ports...)
     * Tie client1.in1 and client1.out1 ports, and make some data test to check the validity of the tie.
     *
     */
    Log("Testing tie mode...\n");
    if (jack_port_tie(input_port1, output_port2) != 0) {
        Log("not possible to tie two ports from two differents clients... ok\n");
    } else {
        printf("!!! ERROR !!! port_tie has allowed a connexion between two differents clients !\n");
        jack_port_untie(output_port2);
    }
    Log("Testing connections datas in tie mode...\n");
    int g;
    for (g = 0; g < 96000; g++)
        signal2[g] = 0.0;
    // Create a loop (emit test) client2.out2----client.in1--tie--client1.out1-----client2.in1 (receive test)
    if (jack_port_tie(input_port1, output_port1) != 0) {
        printf("Unable to tie... fatal error : data test will not be performed on tie mode !!\n");
    } else { // begin of tie
        if (jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2)) != 0) {
            printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
        }
        if (jack_connect(client1, jack_port_name(output_port2), jack_port_name(input_port1)) != 0) {
            printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
        }

        process1_activated = -1;
        process2_activated = -1;

        //		We can manualy check here that the tie is effective.
        //		ie : playing a wav with a client, connecting ports manualy with qjackctl, and listen...
        // 		printf("manual test\n");
        // 		jack_sleep(50);
        // 		printf("end of manual test\n");

        index1 = 0;
        index2 = 0;
        process1_activated = -1;
        process2_activated = 2;

        Log("Sending datas...");

        while (process2_activated == 2) {
            jack_sleep(1 * 1000);
            Log(".");
        }
        process1_activated = -1;
        process2_activated = -1;
        index2 = 0;
        Log("\nAnalysing datas...\n");
        // We must find at least 2 identical values to ensure we are at the right place in the siusoidal array...
        while (!((signal2[index2] == signal1[1]) && (signal2[index2 + 1] == signal1[2]))) {
            index2++;
            if (index2 == 95999) {
                printf("!!! ERROR !!! Data not found in connexion check of tie mode!\n");
                break;
            }
        }
        index1 = index2;
        Log("Tie mode : Data founded at offset %i.\n", index2);
        while (signal2[index2] == signal1[index2 - index1 + 1]) {
            index2++;
            if ((index2 == 95999) || ((index2 - index1 + 1) == 47999)) {
                break;
            }
        }
        Log("Checking difference between datas... %i have the same value...\n", index2 - index1);
        if ((index2 - index1) > 47995) {
            Log("Data received in tie mode are valid...\n");
        } else {
            // in tie mode, the buffers adress should be the same for the two tied ports.
            printf("!!! ERROR !!! data transmission seems not to be valid !\n");
            printf("Links topology : (emitt) client2.out2 ----> client1.in1--(tie)--client1.out1----->client2.in2 (recive)\n");
            printf("  port_name    : Port_adress \n");
sletz's avatar
sletz committed
1505
1506
1507
1508
            printf("  output_port1 : %px\n", jack_port_get_buffer(output_port1, cur_buffer_size));
            printf("  input_port2  : %px\n", jack_port_get_buffer(input_port2, cur_buffer_size));
            printf("  output_port2 : %px\n", jack_port_get_buffer(output_port2, cur_buffer_size));
            printf("  input_port1  : %px\n", jack_port_get_buffer(input_port1, cur_buffer_size));
sletz's avatar
sletz committed
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
        }

        jack_port_untie(output_port1);
        jack_port_disconnect(client1, output_port2);
        jack_port_disconnect(client1, output_port1);

    } //end of tie


    /**
     * Testing SUMMATION CAPABILITIES OF JACK CONNECTIONS
     *
     * In a short test, we just check a simple summation in jack.
     * A first client(client1) send two signal in phase opposition
     * A second client(client2) record the summation at one of his port
     * So, the result must be zero...
     * See process1 for details about steps of this test
     *
sletz's avatar
sletz committed
1527
     */
sletz's avatar
sletz committed
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
    // fprintf(file, "Sum test\n");
    Log("Checking summation capabilities of patching...\n");
    output_port1b = jack_port_register(client1, "out1b",
                                       JACK_DEFAULT_AUDIO_TYPE,
                                       JackPortIsOutput, 0);
    jack_connect(client2, jack_port_name(output_port1), jack_port_name(input_port2));
    jack_connect(client2, jack_port_name(output_port1b), jack_port_name(input_port2));

    process1_activated = 3;
    process2_activated = -1;
    for (g = 0; g < 96000; g++)
        signal2[g] = 0.0;
    index1 = 0;
    index2 = 0;

    Log("Sending datas...");
    process2_activated = 3;

    while (process2_activated == 3) {
        jack_sleep(1 * 1000);
        Log(".");
    }
    process1_activated = -1;
    process2_activated = -1;
    index2 = 0;
    Log("\nAnalysing datas...\n"); // same idea as above, with first data check...
    while (!((signal2[index2] == 0.0 ) && (signal2[(index2 + 1)] == 0.0 ))) {
        index2++;
        if (index2 == 95999) {
            printf("!!! ERROR !!! Data not found in summation check!\n");
            break;
        }
    }
    index1 = index2;
    Log("Data founded at offset %i.\n", index2);

    while ( signal2[index2] == 0.0 ) {
        index2++;
        if ((index2 > 95998) || ((index2 - index1 + 1) > 47998)) {
            break;
        }
    }
    Log("Checking difference between datas...\n");
    if ((index2 - index1) > 47996) {
        Log("Data mixed received are valid...\nSummation is well done.\n");
    } else {
        printf("!!! ERROR !!! data transmission / summation seems not to be valid !\n");
    }
    jack_port_disconnect(client1, output_port1);
    jack_port_disconnect(client1, output_port1b);
    jack_port_unregister(client1, output_port1b);

    if (jack_port_name(output_port1b) != NULL ) {
        printf("!!! WARNING !!! port_name return something while the port have been unregistered !\n");
        printf("!!! Name of unregistered port : %s !\n", jack_port_name(output_port1b));
    } else {
1584
        Log("Checking jack_port_name() with a non valid port... ok\n");
sletz's avatar
sletz committed
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
    }

    if (jack_port_set_name(output_port1b, "new_name") == 0 ) {
        printf("!!! WARNING !!! An unregistered port can be renamed successfully !\n");
    } else {
        Log("Checking renaming of an unregistered port... ok\n");
    }
    inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
    if (jack_port_set_name(jack_port_by_name(client1, inports[0]), "new_name") == 0 ) {
        printf("!!! WARNING !!! A PHYSICAL port can be renamed successfully !\n");
    } else {
        Log("Checking renaming of an unregistered port... ok\n");
    }
    free (inports);


    /**
     * Checking latency issues
     * here are simple latency check
     * We simply check that the value returned by jack seems ok
     * Latency compensation is a difficult point.
     * Actually, jack is not able to see "thru" client to build a full latency chain.
     * Ardour use theses informations to do internally his compensations.
     *
     * 3 test are done : one with no connections between client, one with a serial connection, and one with parallel connection
     */
    Log("Checking about latency functions...\n");
    t_error = 0;
    jack_recompute_total_latencies(client1);
    if ((jack_port_get_latency (output_port1) != 0) ||
            (jack_port_get_total_latency(client1, output_port1) != 0) ) {
        t_error = 1;
        printf("!!! ERROR !!! default latency of a non-PHY device is not set to zero !\n");
    }

    inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
    outports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsOutput);
    if (inports[0] != NULL) {
1623
        output_ext_latency = jack_port_get_latency (jack_port_by_name(client1, inports[0]));  // from client to out driver (which has "inputs" ports..)
sletz's avatar
sletz committed
1624
		input_ext_latency = jack_port_get_latency (jack_port_by_name(client1, outports[0]));  // from in driver (which has "output" ports..) to client
1625
        if (output_ext_latency != jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0]))) {
sletz's avatar
sletz committed
1626
1627
1628
1629
1630
1631
1632
1633
            t_error = 1;
            printf("!!! ERROR !!! get_latency & get_all_latency for a PHY device (unconnected) didn't return the same value !\n");
        }
        Log("Checking a serial model with 2 clients...\n");

        jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2));
        jack_connect(client1, outports[0], jack_port_name(input_port1));
        jack_connect(client2, jack_port_name(output_port2), inports[0]);
1634
        jack_port_set_latency(output_port2, 256);
sletz's avatar
sletz committed
1635
1636
1637
1638
        jack_recompute_total_latencies(client1);

        if ((jack_port_get_latency (output_port1) != 0) ||
                (jack_port_get_total_latency(client1, output_port1) != 0) ||
1639
1640
1641
                (jack_port_get_latency (jack_port_by_name(client1, inports[0])) != (output_ext_latency)) ||
                (jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0])) != (output_ext_latency + 256)) ||
                (jack_port_get_total_latency(client1, output_port2) != (output_ext_latency + 256)) ||
sletz's avatar
sletz committed
1642
                (jack_port_get_total_latency(client1, input_port2) != 0) ||
1643
1644
1645
                (jack_port_get_total_latency(client1, input_port1) != input_ext_latency) ||
                (jack_port_get_latency (jack_port_by_name(client1, outports[0])) != input_ext_latency) ||
                (jack_port_get_total_latency(client1, jack_port_by_name(client1, outports[0])) != input_ext_latency)
sletz's avatar
sletz committed
1646
1647
           ) {
            printf("!!! WARNING !!! get_latency functions may have a problem : bad value returned !\n");
1648
            printf("!!! get_latency(output_port1) : %i (must be 0)\n", jack_port_get_latency(output_port1));
sletz's avatar
sletz committed
1649
            printf("!!! get_total_latency(output_port1) : %i (must be 0)\n", jack_port_get_total_latency(client1, output_port1));
1650
1651
1652
            printf("!!! get_latency(PHY[0]) : %i (must be external latency : %i)\n", jack_port_get_latency(jack_port_by_name(client1, inports[0])), output_ext_latency);
            printf("!!! get_total_latency(PHY[0]) : %i (must be %i)\n", jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0])) , (output_ext_latency + 256));
            printf("!!! get_total_latency(output_port2) : %i (must be %i)\n", jack_port_get_total_latency(client1, output_port2), (output_ext_latency + 256));
sletz's avatar
sletz committed
1653
            printf("!!! get_total_latency(input_port2) : %i (must be 0)\n", jack_port_get_total_latency(client1, input_port2));
1654
1655
1656
            printf("!!! get_total_latency(input_port1) : %i (must be %i)\n", jack_port_get_total_latency(client1, input_port1), input_ext_latency);
            printf("!!! get_latency(PHY[0]) : %i (must be %i)\n", jack_port_get_latency(jack_port_by_name(client1, outports[0])), input_ext_latency);
            printf("!!! get_total_latency(PHY[0]) : %i (must be %i)\n", jack_port_get_total_latency(client1, jack_port_by_name(client1, outports[0])), input_ext_latency);
sletz's avatar
sletz committed
1657
1658
1659
1660
1661
1662

        } else {
            Log("get_latency & get_total_latency seems quite ok...\n");
        }

        jack_port_disconnect(client1, output_port1);
sletz's avatar
Cleanup    
sletz committed
1663
1664
1665
1666
	    jack_port_disconnect(client1, output_port2);
		jack_port_disconnect(client1, input_port1);
	    jack_port_disconnect(client1, input_port2);
	    Log("Checking a parallel model with 2 clients...\n");
1667
1668
1669
1670
        jack_connect(client2, outports[0], jack_port_name(input_port1));
        jack_connect(client2, outports[0], jack_port_name(input_port2));
        jack_connect(client2, jack_port_name(output_port1), inports[0]);
        jack_connect(client2, jack_port_name(output_port2), inports[0]);
1671
1672
        jack_port_set_latency(output_port1, 256);
        jack_port_set_latency(output_port2, 512);
sletz's avatar
sletz committed
1673
1674
        jack_recompute_total_latencies(client1);

1675
1676
1677
1678
1679
1680
        if ((jack_port_get_latency(output_port1) != 256 ) ||
			(jack_port_get_total_latency(client1, output_port1) != (256 + output_ext_latency)) ||
			(jack_port_get_latency(output_port2) != 512) ||
			(jack_port_get_total_latency(client1, output_port2) != (512 + output_ext_latency)) ||
			(jack_port_get_latency(jack_port_by_name(client1, inports[0])) != output_ext_latency) ||
			(jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0])) != (512 + output_ext_latency))
sletz's avatar
sletz committed
1681
1682
           ) {
            printf("!!! WARNING !!! get_latency functions may have a problem : bad value returned !\n");
1683
1684
1685
1686
1687
1688
			printf("!!! get_latency(output_port1) : %i (must be 256)\n", jack_port_get_latency(output_port1));
			printf("!!! get_total_latency(output_port1) : %i (must be 256 + output_ext_latency)\n", jack_port_get_total_latency(client1, output_port1));
			printf("!!! get_latency(output_port2) : %i (must 512)\n", jack_port_get_latency(output_port2));
			printf("!!! get_total_latency(output_port2) : %i (must 512 + output_ext_latency)\n", jack_port_get_total_latency(client1, output_port2));
			printf("!!! get_latency(inports[0])) : %i (must output_ext_latency)\n", jack_port_get_latency(jack_port_by_name(client1, inports[0])));
			printf("!!! get_total_latency(inports[0]) : %i (must 512 + output_ext_latency)\n", jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0])));
sletz's avatar
sletz committed
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
        } else {
            Log("get_latency & get_total_latency seems quite ok...\n");
        }
    } else {
        printf("No physical port founded : not able to test latency functions...");
    }

    jack_port_disconnect(client1, input_port1);
    jack_port_disconnect(client1, input_port2);
    jack_port_disconnect(client1, output_port1);
    jack_port_disconnect(client1, output_port2);
sletz's avatar
sletz committed
1700

1701
	jack_sleep(1000);
sletz's avatar
sletz committed
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711

    free(inports);
    free(outports);

    /**
     * Checking transport API.
     * Simple transport test.
     * Check a transport start with a "slow" client, simulating a delay around 1 sec before becoming ready.
     *
     */
sletz's avatar
sletz committed
1712
1713
1714
	Log("-----------------------------------------------------------\n");
    Log("---------------------------TRANSPORT-----------------------\n");
    Log("-----------------------------------------------------------\n");
sletz's avatar
sletz committed
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894

    lineports = linecount;

    if (transport_mode) {
        int wait_count;
        ts = jack_transport_query(client1, &pos);
        if (ts == JackTransportStopped) {
            Log("Transport is stopped...\n");
        } else {
            jack_transport_stop(client1);
            Log("Transport state : %i\n", ts);
        }
        if (jack_set_sync_callback(client2, Jack_Sync_Callback, 0) != 0)
            printf("error while calling set_sync_callback...\n");

        Log("starting transport...\n");

        starting_state = 1; // Simulate starting state
        jack_transport_start(client1);

        // Wait until sync callback is called
        while (!(sync_called)) {
            jack_sleep(1 * 1000);
        }

        // Wait untill rolling : simulate sync time out
        Log("Simulate a slow-sync client exceeding the time-out\n");
        wait_count = 0;

        do {
            jack_sleep(100); // Wait 100 ms each cycle
            wait_count++;
            if (wait_count == 100) {
                Log("!!! ERROR !!! max time-out exceedeed : sync time-out does not work correctly\n");
                break;
            }
            ts = jack_transport_query(client2, &pos);
            Log("Waiting....pos = %ld\n", pos.frame);
            display_transport_state();

        } while (ts != JackTransportRolling);

        Log("Sync callback have been called %i times.\n", sync_called);
        jack_transport_stop(client1);

        // Wait until stopped
        ts = jack_transport_query(client2, &pos);
        while (ts != JackTransportStopped) {
            jack_sleep(1 * 1000);
            ts = jack_transport_query(client2, &pos);
        }

        // Simulate starting a slow-sync client that rolls after 0.5 sec
        Log("Simulate a slow-sync client that needs 0.5 sec to start\n");
        sync_called = 0;
        wait_count = 0;
        starting_state = 1; // Simulate starting state

        Log("Starting transport...\n");
        jack_transport_start(client1);
        display_transport_state();

        Log("Waiting 0.5 sec...\n");
        jack_sleep(500);
        starting_state = 0; // Simulate end of starting state after 0.5 sec

        // Wait untill rolling
        ts = jack_transport_query(client2, &pos);
        while (ts != JackTransportRolling) {
            jack_sleep(100); // Wait 100 ms each cycle
            wait_count++;
            if (wait_count == 10) {
                Log("!!! ERROR !!! starting a slow-sync client does not work correctly\n");
                break;
            }
            ts = jack_transport_query(client2, &pos);
        }

        if (sync_called == 0)
            Log("!!! ERROR !!! starting a slow-sync client does not work correctly\n");

        Log("Sync callback have been called %i times.\n", sync_called);
        display_transport_state();

        // Test jack_transport_locate while rolling
        Log("Test jack_transport_locate while rolling\n");
        ts = jack_transport_query(client2, &pos);
        Log("Transport current frame = %ld\n", pos.frame);
        jack_nframes_t cur_frame = pos.frame;

        wait_count = 0;
        do {
            display_transport_state();
            jack_sleep(10);  // 10 ms
            // locate at first...
            wait_count++;
            if (wait_count == 1) {
                Log("Do jack_transport_locate\n");
                jack_transport_locate(client1, cur_frame / 2);
            } else if (wait_count == 100) {
                break;
            }
            ts = jack_transport_query(client2, &pos);
            Log("Locating.... frame = %ld\n", pos.frame);
        } while (pos.frame > cur_frame);

        ts = jack_transport_query(client2, &pos);
        Log("Transport current frame = %ld\n", pos.frame);
        if (wait_count == 100) {
            printf("!!! ERROR !!! jack_transport_locate does not work correctly\n");
        }

        // Test jack_transport_reposition while rolling
        Log("Test jack_transport_reposition while rolling\n");
        ts = jack_transport_query(client2, &pos);
        Log("Transport current frame = %ld\n", pos.frame);
        cur_frame = pos.frame;

        wait_count = 0;
        do {
            display_transport_state();
            jack_sleep(10);  // 10 ms
            // locate at first...
            wait_count++;
            if (wait_count == 1) {
                Log("Do jack_transport_reposition\n");
                request_pos.frame = cur_frame / 2;
                jack_transport_reposition(client1, &request_pos);
            } else if (wait_count == 100) {
                break;
            }
            ts = jack_transport_query(client2, &pos);
            Log("Locating.... frame = %ld\n", pos.frame);
        } while (pos.frame > cur_frame);

        ts = jack_transport_query(client2, &pos);
        Log("Transport current frame = %ld\n", pos.frame);
        if (wait_count == 100) {
            printf("!!! ERROR !!! jack_transport_reposition does not work correctly\n");
        }

        // Test jack_transport_reposition while stopped
        jack_transport_stop(client1);
        ts = jack_transport_query(client2, &pos);
        Log("Transport current frame = %ld\n", pos.frame);

        Log("Test jack_transport_reposition while stopped\n");
        wait_count = 0;
        request_pos.frame = 10000;
        jack_transport_reposition(client1, &request_pos);

        do {
            display_transport_state();
            jack_sleep(100); // 100 ms
            if (wait_count++ == 10)
                break;
            ts = jack_transport_query(client2, &pos);
            Log("Locating.... frame = %ld\n", pos.frame);
        } while (pos.frame != 10000);

        ts = jack_transport_query(client2, &pos);
        Log("Transport current frame = %ld\n", pos.frame);
        if (pos.frame != 10000) {
            printf("!!! ERROR !!! jack_transport_reposition does not work correctly\n");
        }

        jack_transport_stop(client1);

        /* Tell the JACK server that we are ready to roll.  Our
         * process() callback will start running now. */

    } else {
        printf("Transport check is disabled...\n");
    }

    time_before_exit = time_to_run;
    while (time_before_exit != 0) {
        jack_sleep (1 * 1000);
        time_before_exit--;
    }
sletz's avatar
sletz committed
1895

sletz's avatar
sletz committed
1896
1897
1898
1899
1900
1901
	if (jack_deactivate(client2) != 0) {
        printf("!!! ERROR !!! jack_deactivate does not return 0 for client2 !\n");
    }
    if (jack_deactivate(client1) != 0) {
        printf("!!! ERROR !!! jack_deactivate does not return 0 for client1 !\n");
    }
sletz's avatar
sletz committed
1902

1903
1904
1905
1906
1907
	/**
     * Checking jack_frame_time.
    */
	Log("Testing jack_frame_time...\n");
	jack_set_process_callback(client1, process4, client1);
sletz's avatar
sletz committed
1908
	jack_activate(client1);
sletz's avatar
sletz committed
1909
1910
1911
	jack_sleep(2 * 1000);


1912
1913
1914
	/**
     * Checking alternate thread model
    */
sletz's avatar
sletz committed
1915
	Log("Testing alternate thread model...\n");
1916
1917
1918
1919
1920
	jack_deactivate(client1);
	jack_set_process_callback(client1, NULL, NULL);  // remove callback
	jack_set_process_thread(client1, jack_thread, client1);
	jack_activate(client1);
	jack_sleep(2 * 1000);
sletz's avatar
sletz committed
1921

1922
1923
1924
1925
1926
	/**
     * Checking callback exiting : when the return code is != 0, the client is desactivated.
    */
	Log("Testing callback exiting...\n");
	jack_deactivate(client1);
1927
	jack_set_process_thread(client1, NULL, NULL); // remove thread callback
1928
1929
	jack_set_process_callback(client1, process3, 0);
	jack_activate(client1);
sletz's avatar
sletz committed
1930
1931
	jack_sleep(3 * 1000);

sletz's avatar
sletz committed
1932
1933
1934
1935
1936
1937
1938
1939
    /**
     *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
     *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
     *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
     						Closing program
    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1940
	*/
sletz's avatar
sletz committed
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957

    if (jack_deactivate(client2) != 0) {
        printf("!!! ERROR !!! jack_deactivate does not return 0 for client2 !\n");
    }
    if (jack_deactivate(client1) != 0) {
        printf("!!! ERROR !!! jack_deactivate does not return 0 for client1 !\n");
    }
    if (jack_client_close(client2) != 0) {
        printf("!!! ERROR !!! jack_client_close does not return 0 for client2 !\n");
    }
    if (jack_client_close(client1) != 0) {
        printf("!!! ERROR !!! jack_client_close does not return 0 for client1 !\n");
    }

    if (xrun == 0) {
        Log("No Xrun have been detected during this test... cool !\n");
    } else {
sletz's avatar
sletz committed
1958
        printf("%i Xrun have been detected during this session (seen callback messages to see where are the problems).\n", xrun);
sletz's avatar
sletz committed
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
    }
    free(framecollect);
    free(signal1);
    free(signal2);
    Log("Exiting jack_test...\n");
    fclose(file);
    printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
    sprintf (filename, "framegraph-%i.gnu", cur_buffer_size);
    file = fopen(filename, "w");
    if (file == NULL) {
        fprintf(stderr, "Erreur dans l'ouverture du fichier");
        exit( -1);
    }
    fprintf(file, "reset\n");
    fprintf(file, "set terminal png transparent nocrop enhanced\n");
    fprintf(file, "set output 'framegraph-%i-1.png'\n", cur_buffer_size);
    fprintf(file, "set title \"Frame time evolution during jack_test run\"\n");
    fprintf(file, "set yrange [ %i.00000 : %i.0000 ] noreverse nowriteback\n", cur_buffer_size - (cur_buffer_size / 8), cur_buffer_size + (cur_buffer_size / 8));
    fprintf(file, "set xrange [ 0.00000 : %i.0000 ] noreverse nowriteback\n" , linecount - 1);
    fprintf(file, "set ylabel \"Frametime evolution (d(ft)/dt)\"\n");
    fprintf(file, "set xlabel \"FrameTime\"\n");
    fprintf(file, "set label \"| buf.siz:%i | fr.wl:%i | rg.ports:%i | 2nd.client:%i | trsprt:%i |\" at graph 0.01, 0.04\n", linebuf, linefw, lineports, linecl2, linetransport);
    fprintf(file, "plot 'framefile-%i.dat' using 2 with impulses title \"Xruns\",'framefile-%i.dat' using 1 with line title \"Sampletime variation at %i\"\n", cur_buffer_size, cur_buffer_size, cur_buffer_size);

    fprintf(file, "set output 'framegraph-%i-2.png'\n", cur_buffer_size);
    fprintf(file, "set title \"Frame time evolution during jack_test run\"\n");
    fprintf(file, "set yrange [ %i.00000 : %i.0000 ] noreverse nowriteback\n", (int) (cur_buffer_size / 2), (int) (2*cur_buffer_size + (cur_buffer_size / 8)));
    fprintf(file, "set xrange [ 0.00000 : %i.0000 ] noreverse nowriteback\n" , linecount - 1);
    fprintf(file, "set ylabel \"Frametime evolution (d(ft)/dt)\"\n");
    fprintf(file, "set xlabel \"FrameTime\"\n");
    fprintf(file, "set label \"| buf.siz:%i | fr.wl:%i | rg.ports:%i | 2nd.client:%i | trsprt:%i |\" at graph 0.01, 0.04\n", linebuf, linefw, lineports, linecl2, linetransport);
    fprintf(file, "plot 'framefile-%i.dat' using 2 with impulses title \"Xruns\",'framefile-%i.dat' using 1 with line title \"Sampletime variation at %i\"\n", cur_buffer_size, cur_buffer_size, cur_buffer_size);
    fclose(file);
sletz's avatar
sletz committed
1992
    return 0;
sletz's avatar
sletz committed
1993
}