2
0

switch_ivr_play_say.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. /*
  2. * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  3. * Copyright (C) 2005-2020, Anthony Minessale II <anthm@freeswitch.org>
  4. *
  5. * Version: MPL 1.1
  6. *
  7. * The contents of this file are subject to the Mozilla Public License Version
  8. * 1.1 (the "License"); you may not use this file except in compliance with
  9. * the License. You may obtain a copy of the License at
  10. * http://www.mozilla.org/MPL/
  11. *
  12. * Software distributed under the License is distributed on an "AS IS" basis,
  13. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14. * for the specific language governing rights and limitations under the
  15. * License.
  16. *
  17. * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  18. *
  19. * The Initial Developer of the Original Code is
  20. * Anthony Minessale II <anthm@freeswitch.org>
  21. * Portions created by the Initial Developer are Copyright (C)
  22. * the Initial Developer. All Rights Reserved.
  23. *
  24. * Contributor(s):
  25. * Chris Rienzo <chris@signalwire.com>
  26. *
  27. *
  28. * switch_ivr_play_say.c -- IVR tests
  29. *
  30. */
  31. #include <switch.h>
  32. #include <stdlib.h>
  33. #include <test/switch_test.h>
  34. static void on_record_start(switch_event_t *event)
  35. {
  36. char *str = NULL;
  37. const char *uuid = switch_event_get_header(event, "Unique-ID");
  38. switch_event_serialize(event, &str, SWITCH_FALSE);
  39. switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s", str);
  40. switch_safe_free(str);
  41. if (uuid) {
  42. switch_core_session_t *session = switch_core_session_locate(uuid);
  43. if (session) {
  44. switch_channel_t *channel = switch_core_session_get_channel(session);
  45. const char *recording_id = switch_event_get_header_nil(event, "Recording-Variable-ID");
  46. if (!strcmp(recording_id, "foo")) {
  47. switch_channel_set_variable(channel, "record_start_event_test_pass", "true");
  48. }
  49. switch_core_session_rwunlock(session);
  50. }
  51. }
  52. }
  53. static void on_record_stop(switch_event_t *event)
  54. {
  55. char *str = NULL;
  56. const char *uuid = switch_event_get_header(event, "Unique-ID");
  57. switch_event_serialize(event, &str, SWITCH_FALSE);
  58. switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s", str);
  59. switch_safe_free(str);
  60. if (uuid) {
  61. switch_core_session_t *session = switch_core_session_locate(uuid);
  62. if (session) {
  63. switch_channel_t *channel = switch_core_session_get_channel(session);
  64. const char *recording_id = switch_event_get_header_nil(event, "Recording-Variable-ID");
  65. if (!strcmp(recording_id, "foo")) {
  66. switch_channel_set_variable(channel, "record_stop_event_test_pass", "true");
  67. }
  68. switch_core_session_rwunlock(session);
  69. }
  70. }
  71. }
  72. static switch_status_t partial_play_and_collect_input_callback(switch_core_session_t *session, void *input, switch_input_type_t input_type, void *data, __attribute__((unused))unsigned int len)
  73. {
  74. switch_status_t status = SWITCH_STATUS_SUCCESS;
  75. int *count = (int *)data;
  76. if (input_type == SWITCH_INPUT_TYPE_EVENT) {
  77. switch_event_t *event = (switch_event_t *)input;
  78. if (event->event_id == SWITCH_EVENT_DETECTED_SPEECH) {
  79. const char *speech_type = switch_event_get_header(event, "Speech-Type");
  80. char *body = switch_event_get_body(event);
  81. if (zstr(speech_type) || strcmp(speech_type, "detected-partial-speech")) {
  82. return status;
  83. }
  84. (*count)++;
  85. switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "partial events count: %d\n", *count);
  86. switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "body=[%s]\n", body);
  87. }
  88. } else if (input_type == SWITCH_INPUT_TYPE_DTMF) {
  89. // never mind
  90. }
  91. return status;
  92. }
  93. FST_CORE_BEGIN("./conf_playsay")
  94. {
  95. FST_SUITE_BEGIN(switch_ivr_play_say)
  96. {
  97. FST_SETUP_BEGIN()
  98. {
  99. fst_requires_module("mod_tone_stream");
  100. fst_requires_module("mod_sndfile");
  101. fst_requires_module("mod_dptools");
  102. fst_requires_module("mod_test");
  103. }
  104. FST_SETUP_END()
  105. FST_TEARDOWN_BEGIN()
  106. {
  107. }
  108. FST_TEARDOWN_END()
  109. FST_SESSION_BEGIN(play_and_collect_input_failure)
  110. {
  111. char terminator_collected = 0;
  112. char *digits_collected = NULL;
  113. cJSON *recognition_result = NULL;
  114. // args
  115. const char *play_files = "silence_stream://2000";
  116. const char *speech_engine = "test";
  117. const char *terminators = "#";
  118. int min_digits = 1;
  119. int max_digits = 3;
  120. int digit_timeout = 15000;
  121. int no_input_timeout = digit_timeout;
  122. int speech_complete_timeout = digit_timeout;
  123. int speech_recognition_timeout = digit_timeout;
  124. char *speech_grammar_args = switch_core_session_sprintf(fst_session, "{start-input-timers=false,no-input-timeout=%d,vad-silence-ms=%d,speech-timeout=%d,language=en-US}default",
  125. no_input_timeout, speech_complete_timeout, speech_recognition_timeout);
  126. switch_status_t status;
  127. // collect input - 1#
  128. fst_sched_recv_dtmf("+1", "1");
  129. fst_sched_recv_dtmf("+2", "2");
  130. fst_sched_recv_dtmf("+3", "3");
  131. status = switch_ivr_play_and_collect_input(fst_session, play_files, speech_engine, speech_grammar_args, min_digits, max_digits, terminators, digit_timeout, &recognition_result, &digits_collected, &terminator_collected, NULL);
  132. fst_check(recognition_result == NULL);
  133. fst_check(status == SWITCH_STATUS_SUCCESS); // might be break?
  134. fst_check_string_equals(cJSON_GetObjectCstr(recognition_result, "text"), NULL);
  135. fst_check_string_equals(digits_collected, "123");
  136. fst_check(terminator_collected == 0);
  137. cJSON_Delete(recognition_result);
  138. }
  139. FST_SESSION_END()
  140. FST_SESSION_BEGIN(play_and_collect_input_success)
  141. {
  142. char terminator_collected = 0;
  143. char *digits_collected = NULL;
  144. cJSON *recognition_result = NULL;
  145. // args
  146. const char *play_files = "silence_stream://1000";
  147. const char *speech_engine = "test";
  148. const char *terminators = "#";
  149. int min_digits = 1;
  150. int max_digits = 99;
  151. int digit_timeout = 5000;
  152. int no_input_timeout = digit_timeout;
  153. int speech_complete_timeout = digit_timeout;
  154. int speech_recognition_timeout = 60000;
  155. char *speech_grammar_args = switch_core_session_sprintf(fst_session, "{start-input-timers=false,no-input-timeout=%d,vad-silence-ms=%d,speech-timeout=%d,language=en-US}default",
  156. no_input_timeout, speech_complete_timeout, speech_recognition_timeout);
  157. switch_status_t status;
  158. // collect input - 1#
  159. fst_sched_recv_dtmf("+2", "1#");
  160. terminator_collected = 0;
  161. digits_collected = NULL;
  162. recognition_result = NULL;
  163. fst_time_mark();
  164. status = switch_ivr_play_and_collect_input(fst_session, play_files, speech_engine, speech_grammar_args, min_digits, max_digits, terminators, digit_timeout, &recognition_result, &digits_collected, &terminator_collected, NULL);
  165. fst_check(recognition_result == NULL);
  166. // check results
  167. fst_check_duration(2500, 1000); // should return immediately when term digit is received
  168. fst_check(status == SWITCH_STATUS_SUCCESS); // might be break?
  169. fst_check_string_equals(cJSON_GetObjectCstr(recognition_result, "text"), NULL);
  170. fst_check_string_equals(digits_collected, "1");
  171. fst_check(terminator_collected == '#');
  172. // collect input - 1# again, same session
  173. fst_sched_recv_dtmf("+2", "1#");
  174. terminator_collected = 0;
  175. digits_collected = NULL;
  176. if (recognition_result) cJSON_Delete(recognition_result);
  177. recognition_result = NULL;
  178. fst_time_mark();
  179. status = switch_ivr_play_and_collect_input(fst_session, play_files, speech_engine, speech_grammar_args, min_digits, max_digits, terminators, digit_timeout, &recognition_result, &digits_collected, &terminator_collected, NULL);
  180. // check results
  181. fst_check(status == SWITCH_STATUS_SUCCESS); // might be break?
  182. fst_check_duration(2500, 1000); // should return immediately when term digit is received
  183. fst_check_string_equals(cJSON_GetObjectCstr(recognition_result, "text"), NULL);
  184. fst_check_string_equals(digits_collected, "1");
  185. fst_check(terminator_collected == '#');
  186. // collect input - 1
  187. fst_sched_recv_dtmf("+2", "1");
  188. terminator_collected = 0;
  189. digits_collected = NULL;
  190. if (recognition_result) cJSON_Delete(recognition_result);
  191. recognition_result = NULL;
  192. fst_time_mark();
  193. status = switch_ivr_play_and_collect_input(fst_session, play_files, speech_engine, speech_grammar_args, min_digits, max_digits, terminators, digit_timeout, &recognition_result, &digits_collected, &terminator_collected, NULL);
  194. fst_check(recognition_result == NULL);
  195. // check results
  196. fst_check(status == SWITCH_STATUS_SUCCESS); // might be break?
  197. fst_check_duration(7000, 1000); // should return after timeout when prompt finishes playing
  198. fst_check_string_equals(cJSON_GetObjectCstr(recognition_result, "text"), NULL);
  199. fst_check_string_equals(digits_collected, "1");
  200. fst_check(terminator_collected == 0);
  201. // collect input - 12#
  202. fst_sched_recv_dtmf("+2", "12#");
  203. terminator_collected = 0;
  204. digits_collected = NULL;
  205. if (recognition_result) cJSON_Delete(recognition_result);
  206. recognition_result = NULL;
  207. fst_time_mark();
  208. status = switch_ivr_play_and_collect_input(fst_session, play_files, speech_engine, speech_grammar_args, min_digits, max_digits, terminators, digit_timeout, &recognition_result, &digits_collected, &terminator_collected, NULL);
  209. fst_check(recognition_result == NULL);
  210. // check results
  211. fst_check(status == SWITCH_STATUS_SUCCESS); // might be break?
  212. fst_check_duration(2500, 1000); // should return after timeout when prompt finishes playing
  213. fst_check_string_equals(cJSON_GetObjectCstr(recognition_result, "text"), NULL);
  214. fst_check_string_equals(digits_collected, "12");
  215. fst_check(terminator_collected == '#');
  216. // collect input - 12# - long spacing
  217. fst_sched_recv_dtmf("+2", "1");
  218. fst_sched_recv_dtmf("+4", "2");
  219. fst_sched_recv_dtmf("+6", "3");
  220. fst_sched_recv_dtmf("+8", "4");
  221. fst_sched_recv_dtmf("+10", "#");
  222. terminator_collected = 0;
  223. digits_collected = NULL;
  224. if (recognition_result) cJSON_Delete(recognition_result);
  225. recognition_result = NULL;
  226. fst_time_mark();
  227. status = switch_ivr_play_and_collect_input(fst_session, play_files, speech_engine, speech_grammar_args, min_digits, max_digits, terminators, digit_timeout, &recognition_result, &digits_collected, &terminator_collected, NULL);
  228. fst_check(recognition_result == NULL);
  229. // check results
  230. fst_check(status == SWITCH_STATUS_SUCCESS); // might be break?
  231. fst_check_duration(10000, 1000); // should return when dtmf terminator is pressed
  232. fst_check_string_equals(cJSON_GetObjectCstr(recognition_result, "text"), NULL);
  233. fst_check_string_equals(digits_collected, "1234");
  234. fst_check(terminator_collected == '#');
  235. // collect input - make an utterance
  236. speech_complete_timeout = 500; // 'auto' mode...
  237. speech_grammar_args = switch_core_session_sprintf(fst_session, "{start-input-timers=false,no-input-timeout=%d,vad-silence-ms=%d,speech-timeout=%d,language=en-US}default",
  238. no_input_timeout, speech_complete_timeout, speech_recognition_timeout);
  239. switch_ivr_displace_session(fst_session, "file_string://silence_stream://500,0!tone_stream://%%(2000,0,350,440)", 0, "r");
  240. terminator_collected = 0;
  241. digits_collected = NULL;
  242. if (recognition_result) cJSON_Delete(recognition_result);
  243. recognition_result = NULL;
  244. fst_time_mark();
  245. status = switch_ivr_play_and_collect_input(fst_session, play_files, speech_engine, speech_grammar_args, min_digits, max_digits, terminators, digit_timeout, &recognition_result, &digits_collected, &terminator_collected, NULL);
  246. fst_requires(recognition_result);
  247. // check results
  248. fst_check(status == SWITCH_STATUS_SUCCESS); // might be break?
  249. fst_check_duration(2500, 1000); // returns when utterance is done
  250. fst_check_string_equals(cJSON_GetObjectCstr(recognition_result, "text"), "agent");
  251. fst_check_string_equals(digits_collected, NULL);
  252. fst_check(terminator_collected == 0);
  253. // single digit test
  254. fst_sched_recv_dtmf("+2", "2");
  255. max_digits = 1;
  256. terminator_collected = 0;
  257. digits_collected = NULL;
  258. if (recognition_result) cJSON_Delete(recognition_result);
  259. recognition_result = NULL;
  260. fst_time_mark();
  261. status = switch_ivr_play_and_collect_input(fst_session, play_files, speech_engine, speech_grammar_args, min_digits, max_digits, terminators, digit_timeout, &recognition_result, &digits_collected, &terminator_collected, NULL);
  262. fst_check(recognition_result == NULL);
  263. // check results
  264. fst_check(status == SWITCH_STATUS_SUCCESS); // might be break?
  265. fst_check_duration(2500, 1000); // returns when single digit is pressed
  266. fst_check_string_equals(cJSON_GetObjectCstr(recognition_result, "text"), NULL);
  267. fst_check_string_equals(digits_collected, "2");
  268. fst_check(terminator_collected == 0);
  269. // three digit test
  270. fst_sched_recv_dtmf("+2", "259");
  271. min_digits = 1;
  272. max_digits = 3;
  273. terminator_collected = 0;
  274. digits_collected = NULL;
  275. if (recognition_result) cJSON_Delete(recognition_result);
  276. recognition_result = NULL;
  277. fst_time_mark();
  278. status = switch_ivr_play_and_collect_input(fst_session, play_files, speech_engine, speech_grammar_args, min_digits, max_digits, terminators, digit_timeout, &recognition_result, &digits_collected, &terminator_collected, NULL);
  279. fst_check(recognition_result == NULL);
  280. // check results
  281. fst_check(status == SWITCH_STATUS_SUCCESS); // might be break?
  282. fst_check_duration(2000, 1000); // returns when single digit is pressed
  283. fst_check_string_equals(cJSON_GetObjectCstr(recognition_result, "text"), NULL);
  284. fst_check_string_equals(digits_collected, "259");
  285. fst_check(terminator_collected == 0);
  286. // min digit test
  287. fst_sched_recv_dtmf("+2", "25");
  288. min_digits = 3;
  289. max_digits = 3;
  290. terminator_collected = 0;
  291. digits_collected = NULL;
  292. if (recognition_result) cJSON_Delete(recognition_result);
  293. recognition_result = NULL;
  294. fst_time_mark();
  295. status = switch_ivr_play_and_collect_input(fst_session, play_files, speech_engine, speech_grammar_args, min_digits, max_digits, terminators, digit_timeout, &recognition_result, &digits_collected, &terminator_collected, NULL);
  296. fst_requires(recognition_result);
  297. // check results
  298. fst_check(status == SWITCH_STATUS_SUCCESS); // might be break?
  299. fst_check_duration(7000, 1000); // inter-digit timeout after 2nd digit pressed
  300. fst_check_string_equals(cJSON_GetObjectCstr(recognition_result, "text"), "");
  301. fst_check_string_equals(digits_collected, NULL);
  302. fst_check(terminator_collected == 0);
  303. if (recognition_result) cJSON_Delete(recognition_result);
  304. recognition_result = NULL;
  305. }
  306. FST_SESSION_END()
  307. FST_SESSION_BEGIN(play_and_collect_input_partial)
  308. {
  309. char terminator_collected = 0;
  310. char *digits_collected = NULL;
  311. cJSON *recognition_result = NULL;
  312. // args
  313. const char *play_files = "silence_stream://1000";
  314. const char *speech_engine = "test";
  315. const char *terminators = "#";
  316. int min_digits = 1;
  317. int max_digits = 99;
  318. int digit_timeout = 500;
  319. int no_input_timeout = digit_timeout;
  320. int speech_complete_timeout = digit_timeout;
  321. int speech_recognition_timeout = 60000;
  322. char *speech_grammar_args = switch_core_session_sprintf(fst_session, "{start-input-timers=false,no-input-timeout=%d,vad-silence-ms=%d,speech-timeout=%d,language=en-US,partial=true}default",
  323. no_input_timeout, speech_complete_timeout, speech_recognition_timeout);
  324. switch_status_t status;
  325. switch_input_args_t collect_input_args = { 0 };
  326. switch_input_args_t *args = NULL;
  327. int count = 0;
  328. switch_ivr_displace_session(fst_session, "file_string://silence_stream://500,0!tone_stream://%%(2000,0,350,440)", 0, "r");
  329. terminator_collected = 0;
  330. digits_collected = NULL;
  331. if (recognition_result) cJSON_Delete(recognition_result);
  332. recognition_result = NULL;
  333. fst_time_mark();
  334. status = switch_ivr_play_and_collect_input(fst_session, play_files, speech_engine, speech_grammar_args, min_digits, max_digits, terminators, digit_timeout, &recognition_result, &digits_collected, &terminator_collected, NULL);
  335. fst_requires(recognition_result);
  336. // check results
  337. fst_check(status == SWITCH_STATUS_SUCCESS); // might be break?
  338. fst_check_duration(2500, 1000); // returns when utterance is done
  339. fst_check_string_equals(cJSON_GetObjectCstr(recognition_result, "text"), "agent");
  340. fst_check_string_equals(digits_collected, NULL);
  341. fst_check(terminator_collected == 0);
  342. switch_ivr_displace_session(fst_session, "file_string://silence_stream://500,0!tone_stream://%%(2000,0,350,440)", 0, "r");
  343. terminator_collected = 0;
  344. digits_collected = NULL;
  345. if (recognition_result) cJSON_Delete(recognition_result);
  346. recognition_result = NULL;
  347. args = &collect_input_args;
  348. args->input_callback = partial_play_and_collect_input_callback;
  349. args->buf = &count;
  350. args->buflen = sizeof(int);
  351. fst_time_mark();
  352. status = switch_ivr_play_and_collect_input(fst_session, play_files, speech_engine, speech_grammar_args, min_digits, max_digits, terminators, digit_timeout, &recognition_result, &digits_collected, &terminator_collected, args);
  353. fst_requires(recognition_result);
  354. // check results
  355. fst_check(status == SWITCH_STATUS_SUCCESS); // might be break?
  356. fst_check_duration(2500, 1000); // returns when utterance is done
  357. fst_check_string_equals(cJSON_GetObjectCstr(recognition_result, "text"), "agent");
  358. fst_check_string_equals(digits_collected, NULL);
  359. fst_check(terminator_collected == 0);
  360. switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "xxx count = %d\n", count);
  361. fst_check(count == 3); // 3 partial results
  362. cJSON_Delete(recognition_result);
  363. }
  364. FST_SESSION_END()
  365. FST_SESSION_BEGIN(record_file_event_vars)
  366. {
  367. const char *record_filename = switch_core_session_sprintf(fst_session, "%s" SWITCH_PATH_SEPARATOR "record_file_event_vars-tmp-%s.wav", SWITCH_GLOBAL_dirs.temp_dir, switch_core_session_get_uuid(fst_session));
  368. switch_event_t *rec_vars = NULL;
  369. switch_status_t status;
  370. switch_event_create_subclass(&rec_vars, SWITCH_EVENT_CLONE, SWITCH_EVENT_SUBCLASS_ANY);
  371. fst_requires(rec_vars);
  372. switch_event_bind("record_file_event", SWITCH_EVENT_RECORD_START, SWITCH_EVENT_SUBCLASS_ANY, on_record_start, NULL);
  373. switch_event_bind("record_file_event", SWITCH_EVENT_RECORD_STOP, SWITCH_EVENT_SUBCLASS_ANY, on_record_stop, NULL);
  374. switch_event_add_header_string(rec_vars, SWITCH_STACK_BOTTOM, "execute_on_record_start", "set record_start_test_pass=true");
  375. switch_event_add_header_string(rec_vars, SWITCH_STACK_BOTTOM, "execute_on_record_stop", "set record_stop_test_pass=true");
  376. switch_event_add_header_string(rec_vars, SWITCH_STACK_BOTTOM, "ID", "foo");
  377. switch_ivr_displace_session(fst_session, "file_string://silence_stream://500,0!tone_stream://%%(2000,0,350,440)", 0, "r");
  378. status = switch_ivr_record_file_event(fst_session, NULL, record_filename, NULL, 4, rec_vars);
  379. fst_check(status == SWITCH_STATUS_SUCCESS);
  380. fst_xcheck(switch_channel_var_true(fst_channel, "record_start_test_pass"), "Expect record_start_test_pass channel variable set to true");
  381. fst_xcheck(switch_channel_var_true(fst_channel, "record_stop_test_pass"), "Expect record_stop_test_pass channel variable set to true");
  382. switch_sleep(1000 * 1000);
  383. fst_xcheck(switch_channel_var_true(fst_channel, "record_start_event_test_pass"), "Expect RECORD_START event received with Recording-Variable-ID set");
  384. fst_xcheck(switch_channel_var_true(fst_channel, "record_stop_event_test_pass"), "Expect RECORD_STOP event received with Recording-Variable-ID set");
  385. switch_event_unbind_callback(on_record_start);
  386. switch_event_unbind_callback(on_record_stop);
  387. switch_event_destroy(&rec_vars);
  388. fst_xcheck(switch_file_exists(record_filename, fst_pool) == SWITCH_STATUS_SUCCESS, "Expect recording file to exist");
  389. unlink(record_filename);
  390. }
  391. FST_SESSION_END()
  392. FST_SESSION_BEGIN(record_file_event_chan_vars)
  393. {
  394. const char *record_filename = switch_core_session_sprintf(fst_session, "%s" SWITCH_PATH_SEPARATOR "record_file_event_chan_vars-tmp-%s.wav", SWITCH_GLOBAL_dirs.temp_dir, switch_core_session_get_uuid(fst_session));
  395. switch_event_t *rec_vars = NULL;
  396. switch_status_t status;
  397. switch_event_create_subclass(&rec_vars, SWITCH_EVENT_CLONE, SWITCH_EVENT_SUBCLASS_ANY);
  398. fst_requires(rec_vars);
  399. switch_event_bind("record_file_event", SWITCH_EVENT_RECORD_START, SWITCH_EVENT_SUBCLASS_ANY, on_record_start, NULL);
  400. switch_event_bind("record_file_event", SWITCH_EVENT_RECORD_STOP, SWITCH_EVENT_SUBCLASS_ANY, on_record_stop, NULL);
  401. switch_channel_set_variable(fst_channel, "execute_on_record_start_1", "set record_start_test_pass=true");
  402. switch_channel_set_variable(fst_channel, "execute_on_record_stop_1", "set record_stop_test_pass=true");
  403. switch_event_add_header_string(rec_vars, SWITCH_STACK_BOTTOM, "ID", "foo");
  404. switch_ivr_displace_session(fst_session, "file_string://silence_stream://500,0!tone_stream://%%(2000,0,350,440)", 0, "r");
  405. status = switch_ivr_record_file_event(fst_session, NULL, record_filename, NULL, 4, rec_vars);
  406. fst_check(status == SWITCH_STATUS_SUCCESS);
  407. fst_xcheck(switch_channel_var_true(fst_channel, "record_start_test_pass"), "Expect record_start_test_pass channel variable set to true");
  408. fst_xcheck(switch_channel_var_true(fst_channel, "record_stop_test_pass"), "Expect record_stop_test_pass channel variable set to true");
  409. switch_sleep(1000 * 1000);
  410. fst_xcheck(switch_channel_var_true(fst_channel, "record_start_event_test_pass"), "Expect RECORD_START event received with Recording-Variable-ID set");
  411. fst_xcheck(switch_channel_var_true(fst_channel, "record_stop_event_test_pass"), "Expect RECORD_STOP event received with Recording-Variable-ID set");
  412. switch_event_unbind_callback(on_record_start);
  413. switch_event_unbind_callback(on_record_stop);
  414. switch_event_destroy(&rec_vars);
  415. fst_xcheck(switch_file_exists(record_filename, fst_pool) == SWITCH_STATUS_SUCCESS, "Expect recording file to exist");
  416. unlink(record_filename);
  417. }
  418. FST_SESSION_END()
  419. FST_SESSION_BEGIN(record_file_event_chan_vars_only)
  420. {
  421. const char *record_filename = switch_core_session_sprintf(fst_session, "%s" SWITCH_PATH_SEPARATOR "record_file_event_chan_vars-tmp-%s.wav", SWITCH_GLOBAL_dirs.temp_dir, switch_core_session_get_uuid(fst_session));
  422. switch_status_t status;
  423. switch_channel_set_variable(fst_channel, "execute_on_record_start_1", "set record_start_test_pass=true");
  424. switch_channel_set_variable(fst_channel, "execute_on_record_stop_1", "set record_stop_test_pass=true");
  425. switch_ivr_displace_session(fst_session, "file_string://silence_stream://500,0!tone_stream://%%(2000,0,350,440)", 0, "r");
  426. status = switch_ivr_record_file_event(fst_session, NULL, record_filename, NULL, 4, NULL);
  427. fst_check(status == SWITCH_STATUS_SUCCESS);
  428. fst_xcheck(switch_channel_var_true(fst_channel, "record_start_test_pass"), "Expect record_start_test_pass channel variable set to true");
  429. fst_xcheck(switch_channel_var_true(fst_channel, "record_stop_test_pass"), "Expect record_stop_test_pass channel variable set to true");
  430. switch_sleep(1000 * 1000);
  431. fst_xcheck(switch_file_exists(record_filename, fst_pool) == SWITCH_STATUS_SUCCESS, "Expect recording file to exist");
  432. unlink(record_filename);
  433. }
  434. FST_SESSION_END()
  435. }
  436. FST_SUITE_END()
  437. }
  438. FST_CORE_END()