blob: b90ce8fe3c24adb883c389faddb435052994f4b3 [file] [log] [blame]
Tristan Matthews0a329cc2013-07-17 13:20:14 -04001/* $Id: systest.c 4537 2013-06-19 06:47:43Z riza $ */
2/*
3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#include "systest.h"
20#include "gui.h"
21
22#define THIS_FILE "systest.c"
23
24unsigned test_item_count;
25test_item_t test_items[SYSTEST_MAX_TEST];
26char doc_path[PATH_LENGTH] = {0};
27char res_path[PATH_LENGTH] = {0};
28char fpath[PATH_LENGTH];
29
30#define USER_ERROR "User used said not okay"
31
32static void systest_wizard(void);
33static void systest_list_audio_devs(void);
34static void systest_display_settings(void);
35static void systest_play_tone(void);
36static void systest_play_wav1(void);
37static void systest_play_wav2(void);
38static void systest_rec_audio(void);
39static void systest_audio_test(void);
40static void systest_latency_test(void);
41static void systest_aec_test(void);
42static void exit_app(void);
43
44/* Menus */
45static gui_menu menu_exit = { "Exit", &exit_app };
46
47static gui_menu menu_wizard = { "Run test wizard", &systest_wizard };
48static gui_menu menu_playtn = { "Play Tone", &systest_play_tone };
49static gui_menu menu_playwv1 = { "Play WAV File1", &systest_play_wav1 };
50static gui_menu menu_playwv2 = { "Play WAV File2", &systest_play_wav2 };
51static gui_menu menu_recaud = { "Record Audio", &systest_rec_audio };
52static gui_menu menu_audtest = { "Device Test", &systest_audio_test };
53static gui_menu menu_calclat = { "Latency Test", &systest_latency_test };
54static gui_menu menu_sndaec = { "AEC/AES Test", &systest_aec_test };
55
56static gui_menu menu_listdev = { "View Devices", &systest_list_audio_devs };
57static gui_menu menu_getsets = { "View Settings", &systest_display_settings };
58
59static gui_menu menu_tests = {
60 "Tests", NULL,
61 10,
62 {
63 &menu_wizard,
64 &menu_audtest,
65 &menu_playtn,
66 &menu_playwv1,
67 &menu_playwv2,
68 &menu_recaud,
69 &menu_calclat,
70 &menu_sndaec,
71 NULL,
72 &menu_exit
73 }
74};
75
76static gui_menu menu_options = {
77 "Options", NULL,
78 2,
79 {
80 &menu_listdev,
81 &menu_getsets,
82 }
83};
84
85static gui_menu root_menu = {
86 "Root", NULL, 2, {&menu_tests, &menu_options}
87};
88
89/*****************************************************************/
90
91#if defined(PJ_DARWINOS) && PJ_DARWINOS!=0
92PJ_INLINE(char *) add_path(const char *path, const char *fname)
93{
94 strncpy(fpath, path, PATH_LENGTH);
95 strncat(fpath, fname, PATH_LENGTH);
96 return fpath;
97}
98#else
99# define add_path(path, fname) fname
100#endif
101
102static void exit_app(void)
103{
104 systest_save_result(add_path(doc_path, RESULT_OUT_PATH));
105 gui_destroy();
106}
107
108
109#include <pjsua-lib/pjsua.h>
110#include <pjmedia_audiodev.h>
111
112typedef struct systest_t
113{
114 pjsua_config ua_cfg;
115 pjsua_media_config media_cfg;
116 pjmedia_aud_dev_index rec_id;
117 pjmedia_aud_dev_index play_id;
118} systest_t;
119
120static systest_t systest;
121static char textbuf[600];
122
123/* Device ID to test */
124int systest_cap_dev_id = PJMEDIA_AUD_DEFAULT_CAPTURE_DEV;
125int systest_play_dev_id = PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV;
126
127static void systest_perror(const char *title, pj_status_t status)
128{
129 char errmsg[PJ_ERR_MSG_SIZE];
130 char themsg[PJ_ERR_MSG_SIZE + 100];
131
132 if (status != PJ_SUCCESS)
133 pj_strerror(status, errmsg, sizeof(errmsg));
134 else
135 errmsg[0] = '\0';
136
137 strcpy(themsg, title);
138 strncat(themsg, errmsg, sizeof(themsg)-1);
139 themsg[sizeof(themsg)-1] = '\0';
140
141 gui_msgbox("Error", themsg, WITH_OK);
142}
143
144test_item_t *systest_alloc_test_item(const char *title)
145{
146 test_item_t *ti;
147
148 if (test_item_count == SYSTEST_MAX_TEST) {
149 gui_msgbox("Error", "You have done too many tests", WITH_OK);
150 return NULL;
151 }
152
153 ti = &test_items[test_item_count++];
154 pj_bzero(ti, sizeof(*ti));
155 pj_ansi_strcpy(ti->title, title);
156
157 return ti;
158}
159
160/*****************************************************************************
161 * test: play simple ringback tone and hear it
162 */
163static void systest_play_tone(void)
164{
165 /* Ringtones */
166 #define RINGBACK_FREQ1 440 /* 400 */
167 #define RINGBACK_FREQ2 480 /* 450 */
168 #define RINGBACK_ON 3000 /* 400 */
169 #define RINGBACK_OFF 4000 /* 200 */
170 #define RINGBACK_CNT 1 /* 2 */
171 #define RINGBACK_INTERVAL 4000 /* 2000 */
172
173 unsigned i, samples_per_frame;
174 pjmedia_tone_desc tone[RINGBACK_CNT];
175 pj_pool_t *pool = NULL;
176 pjmedia_port *ringback_port = NULL;
177 enum gui_key key;
178 int ringback_slot = -1;
179 test_item_t *ti;
180 pj_str_t name;
181 const char *title = "Audio Tone Playback Test";
182 pj_status_t status;
183
184 ti = systest_alloc_test_item(title);
185 if (!ti)
186 return;
187
188 key = gui_msgbox(title,
189 "This test will play simple ringback tone to "
190 "the speaker. Please listen carefully for audio "
191 "impairments such as stutter. You may need "
192 "to let this test running for a while to "
193 "make sure that everything is okay. Press "
194 "OK to start, CANCEL to skip",
195 WITH_OKCANCEL);
196 if (key != KEY_OK) {
197 ti->skipped = PJ_TRUE;
198 return;
199 }
200
201 PJ_LOG(3,(THIS_FILE, "Running %s", title));
202
203 pool = pjsua_pool_create("ringback", 512, 512);
204 samples_per_frame = systest.media_cfg.audio_frame_ptime *
205 systest.media_cfg.clock_rate *
206 systest.media_cfg.channel_count / 1000;
207
208 /* Ringback tone (call is ringing) */
209 name = pj_str("ringback");
210 status = pjmedia_tonegen_create2(pool, &name,
211 systest.media_cfg.clock_rate,
212 systest.media_cfg.channel_count,
213 samples_per_frame,
214 16, PJMEDIA_TONEGEN_LOOP,
215 &ringback_port);
216 if (status != PJ_SUCCESS)
217 goto on_return;
218
219 pj_bzero(&tone, sizeof(tone));
220 for (i=0; i<RINGBACK_CNT; ++i) {
221 tone[i].freq1 = RINGBACK_FREQ1;
222 tone[i].freq2 = RINGBACK_FREQ2;
223 tone[i].on_msec = RINGBACK_ON;
224 tone[i].off_msec = RINGBACK_OFF;
225 }
226 tone[RINGBACK_CNT-1].off_msec = RINGBACK_INTERVAL;
227
228 status = pjmedia_tonegen_play(ringback_port, RINGBACK_CNT, tone,
229 PJMEDIA_TONEGEN_LOOP);
230 if (status != PJ_SUCCESS)
231 goto on_return;
232
233 status = pjsua_conf_add_port(pool, ringback_port, &ringback_slot);
234 if (status != PJ_SUCCESS)
235 goto on_return;
236
237 status = pjsua_conf_connect(ringback_slot, 0);
238 if (status != PJ_SUCCESS)
239 goto on_return;
240
241 key = gui_msgbox(title,
242 "Ringback tone should be playing now in the "
243 "speaker. Press OK to stop. ", WITH_OK);
244
245 status = PJ_SUCCESS;
246
247on_return:
248 if (ringback_slot != -1)
249 pjsua_conf_remove_port(ringback_slot);
250 if (ringback_port)
251 pjmedia_port_destroy(ringback_port);
252 if (pool)
253 pj_pool_release(pool);
254
255 if (status != PJ_SUCCESS) {
256 systest_perror("Sorry we encounter error when initializing "
257 "the tone generator: ", status);
258 ti->success = PJ_FALSE;
259 pj_strerror(status, ti->reason, sizeof(ti->reason));
260 } else {
261 key = gui_msgbox(title, "Is the audio okay?", WITH_YESNO);
262 ti->success = (key == KEY_YES);
263 if (!ti->success)
264 pj_ansi_strcpy(ti->reason, USER_ERROR);
265 }
266 return;
267}
268
269/* Util: create file player, each time trying different paths until we get
270 * the file.
271 */
272static pj_status_t create_player(unsigned path_cnt, const char *paths[],
273 pjsua_player_id *p_id)
274{
275 pj_str_t name;
276 pj_status_t status = PJ_ENOTFOUND;
277 unsigned i;
278
279 for (i=0; i<path_cnt; ++i) {
280 status = pjsua_player_create(pj_cstr(&name, paths[i]), 0, p_id);
281 if (status == PJ_SUCCESS)
282 return PJ_SUCCESS;
283 }
284 return status;
285}
286
287/*****************************************************************************
288 * test: play WAV file
289 */
290static void systest_play_wav(unsigned path_cnt, const char *paths[])
291{
292 pjsua_player_id play_id = PJSUA_INVALID_ID;
293 enum gui_key key;
294 test_item_t *ti;
295 const char *title = "WAV File Playback Test";
296 pj_status_t status;
297
298 ti = systest_alloc_test_item(title);
299 if (!ti)
300 return;
301
302 pj_ansi_snprintf(textbuf, sizeof(textbuf),
303 "This test will play %s file to "
304 "the speaker. Please listen carefully for audio "
305 "impairments such as stutter. Let this test run "
306 "for a while to make sure that everything is okay."
307 " Press OK to start, CANCEL to skip",
308 paths[0]);
309
310 key = gui_msgbox(title, textbuf,
311 WITH_OKCANCEL);
312 if (key != KEY_OK) {
313 ti->skipped = PJ_TRUE;
314 return;
315 }
316
317 PJ_LOG(3,(THIS_FILE, "Running %s", title));
318
319 /* WAV port */
320 status = create_player(path_cnt, paths, &play_id);
321 if (status != PJ_SUCCESS)
322 goto on_return;
323
324 status = pjsua_conf_connect(pjsua_player_get_conf_port(play_id), 0);
325 if (status != PJ_SUCCESS)
326 goto on_return;
327
328 key = gui_msgbox(title,
329 "WAV file should be playing now in the "
330 "speaker. Press OK to stop. ", WITH_OK);
331
332 status = PJ_SUCCESS;
333
334on_return:
335 if (play_id != -1)
336 pjsua_player_destroy(play_id);
337
338 if (status != PJ_SUCCESS) {
339 systest_perror("Sorry we've encountered error", status);
340 ti->success = PJ_FALSE;
341 pj_strerror(status, ti->reason, sizeof(ti->reason));
342 } else {
343 key = gui_msgbox(title, "Is the audio okay?", WITH_YESNO);
344 ti->success = (key == KEY_YES);
345 if (!ti->success)
346 pj_ansi_strcpy(ti->reason, USER_ERROR);
347 }
348 return;
349}
350
351static void systest_play_wav1(void)
352{
353 const char *paths[] = { add_path(res_path, WAV_PLAYBACK_PATH),
354 ALT_PATH1 WAV_PLAYBACK_PATH };
355 systest_play_wav(PJ_ARRAY_SIZE(paths), paths);
356}
357
358static void systest_play_wav2(void)
359{
360 const char *paths[] = { add_path(res_path, WAV_TOCK8_PATH),
361 ALT_PATH1 WAV_TOCK8_PATH};
362 systest_play_wav(PJ_ARRAY_SIZE(paths), paths);
363}
364
365
366/*****************************************************************************
367 * test: record audio
368 */
369static void systest_rec_audio(void)
370{
371 const pj_str_t filename = pj_str(add_path(doc_path, WAV_REC_OUT_PATH));
372 pj_pool_t *pool = NULL;
373 enum gui_key key;
374 pjsua_recorder_id rec_id = PJSUA_INVALID_ID;
375 pjsua_player_id play_id = PJSUA_INVALID_ID;
376 pjsua_conf_port_id rec_slot = PJSUA_INVALID_ID;
377 pjsua_conf_port_id play_slot = PJSUA_INVALID_ID;
378 pj_status_t status = PJ_SUCCESS;
379 const char *title = "Audio Recording";
380 test_item_t *ti;
381
382 ti = systest_alloc_test_item(title);
383 if (!ti)
384 return;
385
386 key = gui_msgbox(title,
387 "This test will allow you to record audio "
388 "from the microphone, and playback the "
389 "audio to the speaker. Press OK to start recording, "
390 "CANCEL to skip.",
391 WITH_OKCANCEL);
392 if (key != KEY_OK) {
393 ti->skipped = PJ_TRUE;
394 return;
395 }
396
397 PJ_LOG(3,(THIS_FILE, "Running %s", title));
398
399 pool = pjsua_pool_create("rectest", 512, 512);
400
401 status = pjsua_recorder_create(&filename, 0, NULL, -1, 0, &rec_id);
402 if (status != PJ_SUCCESS)
403 goto on_return;
404
405 rec_slot = pjsua_recorder_get_conf_port(rec_id);
406
407 status = pjsua_conf_connect(0, rec_slot);
408 if (status != PJ_SUCCESS)
409 goto on_return;
410
411 key = gui_msgbox(title,
412 "Recording is in progress now, please say "
413 "something in the microphone. Press OK "
414 "to stop recording", WITH_OK);
415
416 pjsua_conf_disconnect(0, rec_slot);
417 rec_slot = PJSUA_INVALID_ID;
418 pjsua_recorder_destroy(rec_id);
419 rec_id = PJSUA_INVALID_ID;
420
421 status = pjsua_player_create(&filename, 0, &play_id);
422 if (status != PJ_SUCCESS)
423 goto on_return;
424
425 play_slot = pjsua_player_get_conf_port(play_id);
426
427 status = pjsua_conf_connect(play_slot, 0);
428 if (status != PJ_SUCCESS)
429 goto on_return;
430
431 key = gui_msgbox(title,
432 "Recording has been stopped. "
433 "The recorded audio is being played now to "
434 "the speaker device, in a loop. Listen for "
435 "any audio impairments. Press OK to stop.",
436 WITH_OK);
437
438on_return:
439 if (rec_slot != PJSUA_INVALID_ID)
440 pjsua_conf_disconnect(0, rec_slot);
441 if (rec_id != PJSUA_INVALID_ID)
442 pjsua_recorder_destroy(rec_id);
443 if (play_slot != PJSUA_INVALID_ID)
444 pjsua_conf_disconnect(play_slot, 0);
445 if (play_id != PJSUA_INVALID_ID)
446 pjsua_player_destroy(play_id);
447 if (pool)
448 pj_pool_release(pool);
449
450 if (status != PJ_SUCCESS) {
451 systest_perror("Sorry we encountered an error: ", status);
452 ti->success = PJ_FALSE;
453 pj_strerror(status, ti->reason, sizeof(ti->reason));
454 } else {
455 key = gui_msgbox(title, "Is the audio okay?", WITH_YESNO);
456 ti->success = (key == KEY_YES);
457 if (!ti->success) {
458 pj_ansi_snprintf(textbuf, sizeof(textbuf),
459 "You will probably need to copy the recorded "
460 "WAV file %s to a desktop computer and analyze "
461 "it, to find out whether it's a recording "
462 "or playback problem.",
463 WAV_REC_OUT_PATH);
464 gui_msgbox(title, textbuf, WITH_OK);
465 pj_ansi_strcpy(ti->reason, USER_ERROR);
466 }
467 }
468}
469
470
471/****************************************************************************
472 * test: audio system test
473 */
474static void systest_audio_test(void)
475{
476 enum {
477 GOOD_MAX_INTERVAL = 5,
478 };
479 const pjmedia_dir dir = PJMEDIA_DIR_CAPTURE_PLAYBACK;
480 pjmedia_aud_param param;
481 pjmedia_aud_test_results result;
482 pj_size_t textbufpos;
483 enum gui_key key;
484 unsigned problem_count = 0;
485 const char *problems[16];
486 char drifttext[120];
487 test_item_t *ti;
488 const char *title = "Audio Device Test";
489 pj_status_t status;
490
491 ti = systest_alloc_test_item(title);
492 if (!ti)
493 return;
494
495 key = gui_msgbox(title,
496 "This will run an automated test for about "
497 "ten seconds or so, and display some "
498 "statistics about your sound device. "
499 "Please don't do anything until the test completes. "
500 "Press OK to start, or CANCEL to skip this test.",
501 WITH_OKCANCEL);
502 if (key != KEY_OK) {
503 ti->skipped = PJ_TRUE;
504 return;
505 }
506
507 PJ_LOG(3,(THIS_FILE, "Running %s", title));
508
509 /* Disable sound device in pjsua first */
510 pjsua_set_no_snd_dev();
511
512 /* Setup parameters */
513 status = pjmedia_aud_dev_default_param(systest.play_id, &param);
514 if (status != PJ_SUCCESS) {
515 systest_perror("Sorry we had error in pjmedia_aud_dev_default_param()", status);
516 pjsua_set_snd_dev(systest.rec_id, systest.play_id);
517 ti->success = PJ_FALSE;
518 pj_strerror(status, ti->reason, sizeof(ti->reason));
519 ti->reason[sizeof(ti->reason)-1] = '\0';
520 return;
521 }
522
523 param.dir = dir;
524 param.rec_id = systest.rec_id;
525 param.play_id = systest.play_id;
526 param.clock_rate = systest.media_cfg.snd_clock_rate;
527 param.channel_count = systest.media_cfg.channel_count;
528 param.samples_per_frame = param.clock_rate * param.channel_count *
529 systest.media_cfg.audio_frame_ptime / 1000;
530
531 /* Latency settings */
532 param.flags |= (PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY |
533 PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY);
534 param.input_latency_ms = systest.media_cfg.snd_rec_latency;
535 param.output_latency_ms = systest.media_cfg.snd_play_latency;
536
537 /* Run the test */
538 status = pjmedia_aud_test(&param, &result);
539 if (status != PJ_SUCCESS) {
540 systest_perror("Sorry we encountered error with the test", status);
541 pjsua_set_snd_dev(systest.rec_id, systest.play_id);
542 ti->success = PJ_FALSE;
543 pj_strerror(status, ti->reason, sizeof(ti->reason));
544 ti->reason[sizeof(ti->reason)-1] = '\0';
545 return;
546 }
547
548 /* Restore pjsua sound device */
549 pjsua_set_snd_dev(systest.rec_id, systest.play_id);
550
551 /* Analyze the result! */
552 strcpy(textbuf, "Here are the audio statistics:\r\n");
553 textbufpos = strlen(textbuf);
554
555 if (result.rec.frame_cnt==0) {
556 problems[problem_count++] =
557 "No audio frames were captured from the microphone. "
558 "This means the audio device is not working properly.";
559 } else {
560 pj_ansi_snprintf(textbuf+textbufpos,
561 sizeof(textbuf)-textbufpos,
562 "Rec : interval (min/max/avg/dev)=\r\n"
563 " %u/%u/%u/%u (ms)\r\n"
564 " max burst=%u\r\n",
565 result.rec.min_interval,
566 result.rec.max_interval,
567 result.rec.avg_interval,
568 result.rec.dev_interval,
569 result.rec.max_burst);
570 textbufpos = strlen(textbuf);
571
572 if (result.rec.max_burst > GOOD_MAX_INTERVAL) {
573 problems[problem_count++] =
574 "Recording max burst is quite high";
575 }
576 }
577
578 if (result.play.frame_cnt==0) {
579 problems[problem_count++] =
580 "No audio frames were played to the speaker. "
581 "This means the audio device is not working properly.";
582 } else {
583 pj_ansi_snprintf(textbuf+textbufpos,
584 sizeof(textbuf)-textbufpos,
585 "Play: interval (min/max/avg/dev)=\r\n"
586 " %u/%u/%u/%u (ms)\r\n"
587 " burst=%u\r\n",
588 result.play.min_interval,
589 result.play.max_interval,
590 result.play.avg_interval,
591 result.play.dev_interval,
592 result.play.max_burst);
593 textbufpos = strlen(textbuf);
594
595 if (result.play.max_burst > GOOD_MAX_INTERVAL) {
596 problems[problem_count++] =
597 "Playback max burst is quite high";
598 }
599 }
600
601 if (result.rec_drift_per_sec) {
602 const char *which = result.rec_drift_per_sec>=0 ? "faster" : "slower";
603 unsigned drift = result.rec_drift_per_sec>=0 ?
604 result.rec_drift_per_sec :
605 -result.rec_drift_per_sec;
606
607 pj_ansi_snprintf(drifttext, sizeof(drifttext),
608 "Clock drifts detected. Capture "
609 "is %d samples/sec %s "
610 "than the playback device",
611 drift, which);
612 problems[problem_count++] = drifttext;
613 }
614
615 if (problem_count == 0) {
616 pj_ansi_snprintf(textbuf+textbufpos,
617 sizeof(textbuf)-textbufpos,
618 "\r\nThe sound device seems to be okay!");
619 textbufpos = strlen(textbuf);
620
621 key = gui_msgbox("Audio Device Test", textbuf, WITH_OK);
622 } else {
623 unsigned i;
624
625 pj_ansi_snprintf(textbuf+textbufpos,
626 sizeof(textbuf)-textbufpos,
627 "There could be %d problem(s) with the "
628 "sound device:\r\n",
629 problem_count);
630 textbufpos = strlen(textbuf);
631
632 for (i=0; i<problem_count; ++i) {
633 pj_ansi_snprintf(textbuf+textbufpos,
634 sizeof(textbuf)-textbufpos,
635 " %d: %s\r\n", i+1, problems[i]);
636 textbufpos = strlen(textbuf);
637 }
638
639 key = gui_msgbox(title, textbuf, WITH_OK);
640 }
641
642 ti->success = PJ_TRUE;
643 pj_ansi_strncpy(ti->reason, textbuf, sizeof(ti->reason));
644 ti->reason[sizeof(ti->reason)-1] = '\0';
645}
646
647
648/****************************************************************************
649 * sound latency test
650 */
651static int calculate_latency(pj_pool_t *pool, pjmedia_port *wav,
652 unsigned *lat_sum, unsigned *lat_cnt,
653 unsigned *lat_min, unsigned *lat_max)
654{
655 pjmedia_frame frm;
656 short *buf;
657 unsigned i, clock_rate, samples_per_frame;
658 pj_size_t read, len;
659 unsigned start_pos;
660 pj_bool_t first;
661 pj_status_t status;
662
663 *lat_sum = 0;
664 *lat_cnt = 0;
665 *lat_min = 10000;
666 *lat_max = 0;
667
668 samples_per_frame = PJMEDIA_PIA_SPF(&wav->info);
669 clock_rate = PJMEDIA_PIA_SRATE(&wav->info);
670 frm.buf = pj_pool_alloc(pool, samples_per_frame * 2);
671 frm.size = samples_per_frame * 2;
672 len = pjmedia_wav_player_get_len(wav);
673 buf = pj_pool_alloc(pool, len + samples_per_frame);
674
675 /* Read the whole file */
676 read = 0;
677 while (read < len/2) {
678 status = pjmedia_port_get_frame(wav, &frm);
679 if (status != PJ_SUCCESS)
680 break;
681
682 pjmedia_copy_samples(buf+read, (short*)frm.buf, samples_per_frame);
683 read += samples_per_frame;
684 }
685
686 if (read < 2 * clock_rate) {
687 systest_perror("The WAV file is too short", PJ_SUCCESS);
688 return -1;
689 }
690
691 /* Zero the first 500ms to remove loud click noises
692 * (keypad press, etc.)
693 */
694 pjmedia_zero_samples(buf, clock_rate / 2);
695
696 /* Loop to calculate latency */
697 start_pos = 0;
698 first = PJ_TRUE;
699 while (start_pos < len/2 - clock_rate) {
700 int max_signal = 0;
701 unsigned max_signal_pos = start_pos;
702 unsigned max_echo_pos = 0;
703 unsigned pos;
704 unsigned lat;
705
706 /* Get the largest signal in the next 0.7s */
707 for (i=start_pos; i<start_pos + clock_rate * 700 / 1000; ++i) {
708 if (abs(buf[i]) > max_signal) {
709 max_signal = abs(buf[i]);
710 max_signal_pos = i;
711 }
712 }
713
714 /* Advance 10ms from max_signal_pos */
715 pos = max_signal_pos + 10 * clock_rate / 1000;
716
717 /* Get the largest signal in the next 800ms */
718 max_signal = 0;
719 max_echo_pos = pos;
720 for (i=pos; i<pos+clock_rate * 8 / 10; ++i) {
721 if (abs(buf[i]) > max_signal) {
722 max_signal = abs(buf[i]);
723 max_echo_pos = i;
724 }
725 }
726
727 lat = (max_echo_pos - max_signal_pos) * 1000 / clock_rate;
728
729#if 0
730 PJ_LOG(4,(THIS_FILE, "Signal at %dms, echo at %d ms, latency %d ms",
731 max_signal_pos * 1000 / clock_rate,
732 max_echo_pos * 1000 / clock_rate,
733 lat));
734#endif
735
736 *lat_sum += lat;
737 (*lat_cnt)++;
738 if (lat < *lat_min)
739 *lat_min = lat;
740 if (lat > *lat_max)
741 *lat_max = lat;
742
743 /* Advance next loop */
744 if (first) {
745 start_pos = max_signal_pos + clock_rate * 9 / 10;
746 first = PJ_FALSE;
747 } else {
748 start_pos += clock_rate;
749 }
750 }
751
752 return 0;
753}
754
755
756static void systest_latency_test(void)
757{
758 const char *ref_wav_paths[] = { add_path(res_path, WAV_TOCK8_PATH), ALT_PATH1 WAV_TOCK8_PATH };
759 pj_str_t rec_wav_file;
760 pjsua_player_id play_id = PJSUA_INVALID_ID;
761 pjsua_conf_port_id play_slot = PJSUA_INVALID_ID;
762 pjsua_recorder_id rec_id = PJSUA_INVALID_ID;
763 pjsua_conf_port_id rec_slot = PJSUA_INVALID_ID;
764 pj_pool_t *pool = NULL;
765 pjmedia_port *wav_port = NULL;
766 unsigned lat_sum=0, lat_cnt=0, lat_min=0, lat_max=0;
767 enum gui_key key;
768 test_item_t *ti;
769 const char *title = "Audio Latency Test";
770 pj_status_t status;
771
772 ti = systest_alloc_test_item(title);
773 if (!ti)
774 return;
775
776 key = gui_msgbox(title,
777 "This test will try to find the audio device's "
778 "latency. We will play a special WAV file to the "
779 "speaker for ten seconds, then at the end "
780 "calculate the latency. Please don't do anything "
781 "until the test is done.", WITH_OKCANCEL);
782 if (key != KEY_OK) {
783 ti->skipped = PJ_TRUE;
784 return;
785 }
786 key = gui_msgbox(title,
787 "For this test to work, we must be able to capture "
788 "the audio played in the speaker (the echo), and only"
789 " that audio (i.e. you must be in relatively quiet "
790 "place to run this test). "
791 "Press OK to start, or CANCEL to skip.",
792 WITH_OKCANCEL);
793 if (key != KEY_OK) {
794 ti->skipped = PJ_TRUE;
795 return;
796 }
797
798 PJ_LOG(3,(THIS_FILE, "Running %s", title));
799
800 status = create_player(PJ_ARRAY_SIZE(ref_wav_paths), ref_wav_paths,
801 &play_id);
802 if (status != PJ_SUCCESS)
803 goto on_return;
804
805 play_slot = pjsua_player_get_conf_port(play_id);
806
807 rec_wav_file = pj_str(add_path(doc_path, WAV_LATENCY_OUT_PATH));
808 status = pjsua_recorder_create(&rec_wav_file, 0, NULL, -1, 0, &rec_id);
809 if (status != PJ_SUCCESS)
810 goto on_return;
811
812 rec_slot = pjsua_recorder_get_conf_port(rec_id);
813
814 /* Setup the test */
815 //status = pjsua_conf_connect(0, 0);
816 status = pjsua_conf_connect(play_slot, 0);
817 status = pjsua_conf_connect(0, rec_slot);
818 status = pjsua_conf_connect(play_slot, rec_slot);
819
820
821 /* We're running */
822 PJ_LOG(3,(THIS_FILE, "Please wait while test is running (~10 sec)"));
823 gui_sleep(10);
824
825 /* Done with the test */
826 //status = pjsua_conf_disconnect(0, 0);
827 status = pjsua_conf_disconnect(play_slot, rec_slot);
828 status = pjsua_conf_disconnect(0, rec_slot);
829 status = pjsua_conf_disconnect(play_slot, 0);
830
831 pjsua_recorder_destroy(rec_id);
832 rec_id = PJSUA_INVALID_ID;
833
834 pjsua_player_destroy(play_id);
835 play_id = PJSUA_INVALID_ID;
836
837 /* Confirm that echo is heard */
838 gui_msgbox(title,
839 "Test is done. Now we need to confirm that we indeed "
840 "captured the echo. We will play the captured audio "
841 "and please confirm that you can hear the 'tock' echo.",
842 WITH_OK);
843
844 status = pjsua_player_create(&rec_wav_file, 0, &play_id);
845 if (status != PJ_SUCCESS)
846 goto on_return;
847
848 play_slot = pjsua_player_get_conf_port(play_id);
849
850 status = pjsua_conf_connect(play_slot, 0);
851 if (status != PJ_SUCCESS)
852 goto on_return;
853
854 key = gui_msgbox(title,
855 "The captured audio is being played back now. "
856 "Can you hear the 'tock' echo?",
857 WITH_YESNO);
858
859 pjsua_player_destroy(play_id);
860 play_id = PJSUA_INVALID_ID;
861
862 if (key != KEY_YES)
863 goto on_return;
864
865 /* Now analyze the latency */
866 pool = pjsua_pool_create("latency", 512, 512);
867
868 status = pjmedia_wav_player_port_create(pool, rec_wav_file.ptr, 0, 0, 0, &wav_port);
869 if (status != PJ_SUCCESS)
870 goto on_return;
871
872 status = calculate_latency(pool, wav_port, &lat_sum, &lat_cnt,
873 &lat_min, &lat_max);
874 if (status != PJ_SUCCESS)
875 goto on_return;
876
877on_return:
878 if (wav_port)
879 pjmedia_port_destroy(wav_port);
880 if (pool)
881 pj_pool_release(pool);
882 if (play_id != PJSUA_INVALID_ID)
883 pjsua_player_destroy(play_id);
884 if (rec_id != PJSUA_INVALID_ID)
885 pjsua_recorder_destroy(rec_id);
886
887 if (status != PJ_SUCCESS) {
888 systest_perror("Sorry we encountered an error: ", status);
889 ti->success = PJ_FALSE;
890 pj_strerror(status, ti->reason, sizeof(ti->reason));
891 } else if (key != KEY_YES) {
892 ti->success = PJ_FALSE;
893 if (!ti->success) {
894 pj_ansi_strcpy(ti->reason, USER_ERROR);
895 }
896 } else {
897 char msg[200];
898 pj_size_t msglen;
899
900 pj_ansi_snprintf(msg, sizeof(msg),
901 "The sound device latency:\r\n"
902 " Min=%u, Max=%u, Avg=%u\r\n",
903 lat_min, lat_max, lat_sum/lat_cnt);
904 msglen = strlen(msg);
905
906 if (lat_sum/lat_cnt > 500) {
907 pj_ansi_snprintf(msg+msglen, sizeof(msg)-msglen,
908 "The latency is huge!\r\n");
909 msglen = strlen(msg);
910 } else if (lat_sum/lat_cnt > 200) {
911 pj_ansi_snprintf(msg+msglen, sizeof(msg)-msglen,
912 "The latency is quite high\r\n");
913 msglen = strlen(msg);
914 }
915
916 key = gui_msgbox(title, msg, WITH_OK);
917
918 ti->success = PJ_TRUE;
919 pj_ansi_strncpy(ti->reason, msg, sizeof(ti->reason));
920 ti->reason[sizeof(ti->reason)-1] = '\0';
921 }
922}
923
924
925static void systest_aec_test(void)
926{
927 const char *ref_wav_paths[] = { add_path(res_path, WAV_PLAYBACK_PATH),
928 ALT_PATH1 WAV_PLAYBACK_PATH };
929 pjsua_player_id player_id = PJSUA_INVALID_ID;
930 pjsua_recorder_id writer_id = PJSUA_INVALID_ID;
931 enum gui_key key;
932 test_item_t *ti;
933 const char *title = "AEC/AES Test";
934 unsigned last_ec_tail = 0;
935 pj_status_t status;
936 pj_str_t tmp;
937
938 ti = systest_alloc_test_item(title);
939 if (!ti)
940 return;
941
942 key = gui_msgbox(title,
943 "This test will try to find whether the AEC/AES "
944 "works good on this system. Test will play a file "
945 "while recording from mic. The recording will be "
946 "played back later so you can check if echo is there. "
947 "Press OK to start.",
948 WITH_OKCANCEL);
949 if (key != KEY_OK) {
950 ti->skipped = PJ_TRUE;
951 return;
952 }
953
954 /* Save current EC tail */
955 status = pjsua_get_ec_tail(&last_ec_tail);
956 if (status != PJ_SUCCESS)
957 goto on_return;
958
959 /* Set EC tail setting to default */
960 status = pjsua_set_ec(PJSUA_DEFAULT_EC_TAIL_LEN, 0);
961 if (status != PJ_SUCCESS)
962 goto on_return;
963
964 /*
965 * Create player and recorder
966 */
967 status = create_player(PJ_ARRAY_SIZE(ref_wav_paths), ref_wav_paths,
968 &player_id);
969 if (status != PJ_SUCCESS) {
970 PJ_PERROR(1,(THIS_FILE, status, "Error opening WAV file %s",
971 WAV_PLAYBACK_PATH));
972 goto on_return;
973 }
974
975 status = pjsua_recorder_create(
976 pj_cstr(&tmp, add_path(doc_path, AEC_REC_PATH)), 0, 0, -1,
977 0, &writer_id);
978 if (status != PJ_SUCCESS) {
979 PJ_PERROR(1,(THIS_FILE, status, "Error writing WAV file %s",
980 AEC_REC_PATH));
981 goto on_return;
982 }
983
984 /*
985 * Start playback and recording.
986 */
987 pjsua_conf_connect(pjsua_player_get_conf_port(player_id), 0);
988 pj_thread_sleep(100);
989 pjsua_conf_connect(0, pjsua_recorder_get_conf_port(writer_id));
990
991 /* Wait user signal */
992 gui_msgbox(title, "AEC/AES test is running. Press OK to stop this test.",
993 WITH_OK);
994
995 /*
996 * Stop and close playback and recorder
997 */
998 pjsua_conf_disconnect(0, pjsua_recorder_get_conf_port(writer_id));
999 pjsua_conf_disconnect(pjsua_player_get_conf_port(player_id), 0);
1000 pjsua_recorder_destroy(writer_id);
1001 pjsua_player_destroy(player_id);
1002 player_id = PJSUA_INVALID_ID;
1003 writer_id = PJSUA_INVALID_ID;
1004
1005 /*
1006 * Play the result.
1007 */
1008 status = pjsua_player_create(
1009 pj_cstr(&tmp, add_path(doc_path, AEC_REC_PATH)),
1010 0, &player_id);
1011 if (status != PJ_SUCCESS) {
1012 PJ_PERROR(1,(THIS_FILE, status, "Error opening WAV file %s", AEC_REC_PATH));
1013 goto on_return;
1014 }
1015 pjsua_conf_connect(pjsua_player_get_conf_port(player_id), 0);
1016
1017 /* Wait user signal */
1018 gui_msgbox(title, "We are now playing the captured audio from the mic. "
1019 "Check if echo (of the audio played back previously) is "
1020 "present in the audio. The recording is stored in "
1021 AEC_REC_PATH " for offline analysis. "
1022 "Press OK to stop.",
1023 WITH_OK);
1024
1025 pjsua_conf_disconnect(pjsua_player_get_conf_port(player_id), 0);
1026
1027 key = gui_msgbox(title,
1028 "Did you notice any echo in the recording?",
1029 WITH_YESNO);
1030
1031
1032on_return:
1033 if (player_id != PJSUA_INVALID_ID)
1034 pjsua_player_destroy(player_id);
1035 if (writer_id != PJSUA_INVALID_ID)
1036 pjsua_recorder_destroy(writer_id);
1037
1038 /* Wait until sound device closed before restoring back EC tail setting */
1039 while (pjsua_snd_is_active())
1040 pj_thread_sleep(10);
1041 pjsua_set_ec(last_ec_tail, 0);
1042
1043
1044 if (status != PJ_SUCCESS) {
1045 systest_perror("Sorry we encountered an error: ", status);
1046 ti->success = PJ_FALSE;
1047 pj_strerror(status, ti->reason, sizeof(ti->reason));
1048 } else if (key == KEY_YES) {
1049 ti->success = PJ_FALSE;
1050 if (!ti->success) {
1051 pj_ansi_strcpy(ti->reason, USER_ERROR);
1052 }
1053 } else {
1054 char msg[200];
1055
1056 pj_ansi_snprintf(msg, sizeof(msg), "Test succeeded.\r\n");
1057
1058 ti->success = PJ_TRUE;
1059 pj_ansi_strncpy(ti->reason, msg, sizeof(ti->reason));
1060 ti->reason[sizeof(ti->reason)-1] = '\0';
1061 }
1062}
1063
1064
1065/****************************************************************************
1066 * configurations
1067 */
1068static void systest_list_audio_devs()
1069{
1070 unsigned i, dev_count;
1071 pj_size_t len=0;
1072 pj_status_t status;
1073 test_item_t *ti;
1074 enum gui_key key;
1075 const char *title = "Audio Device List";
1076
1077 ti = systest_alloc_test_item(title);
1078 if (!ti)
1079 return;
1080
1081 PJ_LOG(3,(THIS_FILE, "Running %s", title));
1082
1083 dev_count = pjmedia_aud_dev_count();
1084 if (dev_count == 0) {
1085 key = gui_msgbox(title,
1086 "No audio devices are found", WITH_OK);
1087 ti->success = PJ_FALSE;
1088 pj_ansi_strcpy(ti->reason, "No device found");
1089 return;
1090 }
1091
1092 pj_ansi_snprintf(ti->reason+len, sizeof(ti->reason)-len,
1093 "Found %u devices\r\n", dev_count);
1094 len = strlen(ti->reason);
1095
1096 for (i=0; i<dev_count; ++i) {
1097 pjmedia_aud_dev_info info;
1098
1099 status = pjmedia_aud_dev_get_info(i, &info);
1100 if (status != PJ_SUCCESS) {
1101 systest_perror("Error retrieving device info: ", status);
1102 ti->success = PJ_FALSE;
1103 pj_strerror(status, ti->reason, sizeof(ti->reason));
1104 return;
1105 }
1106
1107 pj_ansi_snprintf(ti->reason+len, sizeof(ti->reason)-len,
1108 " %2d: %s [%s] (%d/%d)\r\n",
1109 i, info.driver, info.name,
1110 info.input_count, info.output_count);
1111 len = strlen(ti->reason);
1112 }
1113
1114 ti->reason[len] = '\0';
1115 key = gui_msgbox(title, ti->reason, WITH_OK);
1116
1117 ti->success = PJ_TRUE;
1118}
1119
1120static void systest_display_settings(void)
1121{
1122 pjmedia_aud_dev_info di;
1123 pj_size_t len = 0;
1124 enum gui_key key;
1125 test_item_t *ti;
1126 const char *title = "Audio Settings";
1127 pj_status_t status;
1128
1129 ti = systest_alloc_test_item(title);
1130 if (!ti)
1131 return;
1132
1133 PJ_LOG(3,(THIS_FILE, "Running %s", title));
1134
1135 pj_ansi_snprintf(textbuf+len, sizeof(textbuf)-len, "Version: %s\r\n",
1136 pj_get_version());
1137 len = strlen(textbuf);
1138
1139 pj_ansi_snprintf(textbuf+len, sizeof(textbuf)-len, "Test clock rate: %d\r\n",
1140 systest.media_cfg.clock_rate);
1141 len = strlen(textbuf);
1142
1143 pj_ansi_snprintf(textbuf+len, sizeof(textbuf)-len, "Device clock rate: %d\r\n",
1144 systest.media_cfg.snd_clock_rate);
1145 len = strlen(textbuf);
1146
1147 pj_ansi_snprintf(textbuf+len, sizeof(textbuf)-len, "Aud frame ptime: %d\r\n",
1148 systest.media_cfg.audio_frame_ptime);
1149 len = strlen(textbuf);
1150
1151 pj_ansi_snprintf(textbuf+len, sizeof(textbuf)-len, "Channel count: %d\r\n",
1152 systest.media_cfg.channel_count);
1153 len = strlen(textbuf);
1154
1155 pj_ansi_snprintf(textbuf+len, sizeof(textbuf)-len, "Audio switching: %s\r\n",
1156 (PJMEDIA_CONF_USE_SWITCH_BOARD ? "Switchboard" : "Conf bridge"));
1157 len = strlen(textbuf);
1158
1159 pj_ansi_snprintf(textbuf+len, sizeof(textbuf)-len, "Snd buff count: %d\r\n",
1160 PJMEDIA_SOUND_BUFFER_COUNT);
1161 len = strlen(textbuf);
1162
1163 /* Capture device */
1164 status = pjmedia_aud_dev_get_info(systest.rec_id, &di);
1165 if (status != PJ_SUCCESS) {
1166 systest_perror("Error querying device info", status);
1167 ti->success = PJ_FALSE;
1168 pj_strerror(status, ti->reason, sizeof(ti->reason));
1169 return;
1170 }
1171
1172 pj_ansi_snprintf(textbuf+len, sizeof(textbuf)-len,
1173 "Rec dev : %d (%s) [%s]\r\n",
1174 systest.rec_id,
1175 di.name,
1176 di.driver);
1177 len = strlen(textbuf);
1178
1179 pj_ansi_snprintf(textbuf+len, sizeof(textbuf)-len,
1180 "Rec buf : %d msec\r\n",
1181 systest.media_cfg.snd_rec_latency);
1182 len = strlen(textbuf);
1183
1184 /* Playback device */
1185 status = pjmedia_aud_dev_get_info(systest.play_id, &di);
1186 if (status != PJ_SUCCESS) {
1187 systest_perror("Error querying device info", status);
1188 return;
1189 }
1190
1191 pj_ansi_snprintf(textbuf+len, sizeof(textbuf)-len,
1192 "Play dev: %d (%s) [%s]\r\n",
1193 systest.play_id,
1194 di.name,
1195 di.driver);
1196 len = strlen(textbuf);
1197
1198 pj_ansi_snprintf(textbuf+len, sizeof(textbuf)-len,
1199 "Play buf: %d msec\r\n",
1200 systest.media_cfg.snd_play_latency);
1201 len = strlen(textbuf);
1202
1203 ti->success = PJ_TRUE;
1204 pj_ansi_strncpy(ti->reason, textbuf, sizeof(ti->reason));
1205 ti->reason[sizeof(ti->reason)-1] = '\0';
1206 key = gui_msgbox(title, textbuf, WITH_OK);
1207
1208}
1209
1210/*****************************************************************/
1211
1212int systest_init(void)
1213{
1214 pjsua_logging_config log_cfg;
1215 pj_status_t status = PJ_SUCCESS;
1216
1217 status = pjsua_create();
1218 if (status != PJ_SUCCESS) {
1219 systest_perror("Sorry we've had error in pjsua_create(): ", status);
1220 return status;
1221 }
1222
1223 pjsua_logging_config_default(&log_cfg);
1224 log_cfg.log_filename = pj_str(add_path(doc_path, LOG_OUT_PATH));
1225
1226 pjsua_config_default(&systest.ua_cfg);
1227 pjsua_media_config_default(&systest.media_cfg);
1228 systest.media_cfg.clock_rate = TEST_CLOCK_RATE;
1229 systest.media_cfg.snd_clock_rate = DEV_CLOCK_RATE;
1230 if (OVERRIDE_AUD_FRAME_PTIME)
1231 systest.media_cfg.audio_frame_ptime = OVERRIDE_AUD_FRAME_PTIME;
1232 systest.media_cfg.channel_count = CHANNEL_COUNT;
1233 systest.rec_id = REC_DEV_ID;
1234 systest.play_id = PLAY_DEV_ID;
1235 systest.media_cfg.ec_tail_len = 0;
1236 systest.media_cfg.snd_auto_close_time = 0;
1237
1238#if defined(OVERRIDE_AUDDEV_PLAY_LAT) && OVERRIDE_AUDDEV_PLAY_LAT!=0
1239 systest.media_cfg.snd_play_latency = OVERRIDE_AUDDEV_PLAY_LAT;
1240#endif
1241
1242#if defined(OVERRIDE_AUDDEV_REC_LAT) && OVERRIDE_AUDDEV_REC_LAT!=0
1243 systest.media_cfg.snd_rec_latency = OVERRIDE_AUDDEV_REC_LAT;
1244#endif
1245
1246 status = pjsua_init(&systest.ua_cfg, &log_cfg, &systest.media_cfg);
1247 if (status != PJ_SUCCESS) {
1248 pjsua_destroy();
1249 systest_perror("Sorry we've had error in pjsua_init(): ", status);
1250 return status;
1251 }
1252
1253 status = pjsua_start();
1254 if (status != PJ_SUCCESS) {
1255 pjsua_destroy();
1256 systest_perror("Sorry we've had error in pjsua_start(): ", status);
1257 return status;
1258 }
1259
1260 status = gui_init(&root_menu);
1261 if (status != 0)
1262 goto on_return;
1263
1264 return 0;
1265
1266on_return:
1267 gui_destroy();
1268 return status;
1269}
1270
1271
1272int systest_set_dev(int cap_dev, int play_dev)
1273{
1274 systest.rec_id = systest_cap_dev_id = cap_dev;
1275 systest.play_id = systest_play_dev_id = play_dev;
1276 return pjsua_set_snd_dev(cap_dev, play_dev);
1277}
1278
1279static void systest_wizard(void)
1280{
1281 PJ_LOG(3,(THIS_FILE, "Running test wizard"));
1282 systest_list_audio_devs();
1283 systest_display_settings();
1284 systest_play_tone();
1285 systest_play_wav1();
1286 systest_rec_audio();
1287 systest_audio_test();
1288 systest_latency_test();
1289 systest_aec_test();
1290 gui_msgbox("Test wizard", "Test wizard complete.", WITH_OK);
1291}
1292
1293
1294int systest_run(void)
1295{
1296 gui_start(&root_menu);
1297 return 0;
1298}
1299
1300void systest_save_result(const char *filename)
1301{
1302 unsigned i;
1303 pj_oshandle_t fd;
1304 pj_time_val tv;
1305 pj_parsed_time pt;
1306 pj_ssize_t size;
1307 const char *text;
1308 pj_status_t status;
1309
1310 status = pj_file_open(NULL, filename, PJ_O_WRONLY | PJ_O_APPEND, &fd);
1311 if (status != PJ_SUCCESS) {
1312 pj_ansi_snprintf(textbuf, sizeof(textbuf),
1313 "Error opening file %s",
1314 filename);
1315 systest_perror(textbuf, status);
1316 return;
1317 }
1318
1319 text = "\r\n\r\nPJSYSTEST Report\r\n";
1320 size = strlen(text);
1321 pj_file_write(fd, text, &size);
1322
1323 /* Put timestamp */
1324 pj_gettimeofday(&tv);
1325 if (pj_time_decode(&tv, &pt) == PJ_SUCCESS) {
1326 pj_ansi_snprintf(textbuf, sizeof(textbuf),
1327 "Time: %04d/%02d/%02d %02d:%02d:%02d\r\n",
1328 pt.year, pt.mon+1, pt.day,
1329 pt.hour, pt.min, pt.sec);
1330 size = strlen(textbuf);
1331 pj_file_write(fd, textbuf, &size);
1332 }
1333
1334 pj_ansi_snprintf(textbuf, sizeof(textbuf),
1335 "Tests invoked: %u\r\n"
1336 "-----------------------------------------------\r\n",
1337 test_item_count);
1338 size = strlen(textbuf);
1339 pj_file_write(fd, textbuf, &size);
1340
1341 for (i=0; i<test_item_count; ++i) {
1342 test_item_t *ti = &test_items[i];
1343 pj_ansi_snprintf(textbuf, sizeof(textbuf),
1344 "\r\nTEST %d: %s %s\r\n",
1345 i, ti->title,
1346 (ti->skipped? "Skipped" : (ti->success ? "Success" : "Failed")));
1347 size = strlen(textbuf);
1348 pj_file_write(fd, textbuf, &size);
1349
1350 size = strlen(ti->reason);
1351 pj_file_write(fd, ti->reason, &size);
1352
1353 size = 2;
1354 pj_file_write(fd, "\r\n", &size);
1355 }
1356
1357
1358 pj_file_close(fd);
1359
1360 pj_ansi_snprintf(textbuf, sizeof(textbuf),
1361 "Test result successfully appended to file %s",
1362 filename);
1363 gui_msgbox("Test result saved", textbuf, WITH_OK);
1364}
1365
1366void systest_deinit(void)
1367{
1368 gui_destroy();
1369 pjsua_destroy();
1370}
1371