[Freeswitch-svn] [commit] r5498 - in freeswitch/trunk/src: . include mod/applications/mod_commands mod/languages/mod_spidermonkey
Freeswitch SVN
anthm at freeswitch.org
Thu Jul 5 13:03:15 EDT 2007
Author: anthm
Date: Thu Jul 5 13:03:14 2007
New Revision: 5498
Modified:
freeswitch/trunk/src/include/switch_module_interfaces.h
freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
freeswitch/trunk/src/switch_core_file.c
freeswitch/trunk/src/switch_ivr_play_say.c
Log:
add uuid fsapi function, last_file_position variable, and volume controls to js callback volume:+1 etc
Modified: freeswitch/trunk/src/include/switch_module_interfaces.h
==============================================================================
--- freeswitch/trunk/src/include/switch_module_interfaces.h (original)
+++ freeswitch/trunk/src/include/switch_module_interfaces.h Thu Jul 5 13:03:14 2007
@@ -284,6 +284,9 @@
switch_buffer_t *audio_buffer;
uint32_t thresh;
uint32_t silence_hits;
+ uint32_t offset_pos;
+ uint32_t last_pos;
+ int32_t vol;
};
/*! \brief Abstract interface to an asr module */
Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c (original)
+++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c Thu Jul 5 13:03:14 2007
@@ -311,6 +311,19 @@
return SWITCH_STATUS_SUCCESS;
}
+
+SWITCH_STANDARD_API(uuid_function)
+{
+ switch_uuid_t uuid;
+ char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
+
+ switch_uuid_get(&uuid);
+ switch_uuid_format(uuid_str, &uuid);
+ stream->write_function(stream, "%s", uuid_str);
+ return SWITCH_STATUS_SUCCESS;
+}
+
+
#define SCHED_TRANSFER_SYNTAX "[+]<time> <uuid> <extension> [<dialplan>] [<context>]"
SWITCH_STANDARD_API(sched_transfer_function)
{
@@ -1282,7 +1295,7 @@
SWITCH_ADD_API(commands_api_interface, "break", "Break", break_function, BREAK_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "show", "Show", show_function, SHOW_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "status", "status", status_function, "");
- SWITCH_ADD_API(commands_api_interface, "uuid_bridge", "uuid_bridge", uuid_bridge_function, UUID_SYNTAX);
+ SWITCH_ADD_API(commands_api_interface, "uuid_bridge", "uuid_bridge", uuid_bridge_function, "");
SWITCH_ADD_API(commands_api_interface, "session_displace", "session displace", session_displace_function, "<uuid> [start|stop] <path> [<limit>] [mux]");
SWITCH_ADD_API(commands_api_interface, "session_record", "session record", session_record_function, SESS_REC_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "broadcast", "broadcast", uuid_broadcast_function, BROADCAST_SYNTAX);
@@ -1294,6 +1307,7 @@
SWITCH_ADD_API(commands_api_interface, "sched_hangup", "Schedule a running call to hangup", sched_hangup_function, SCHED_HANGUP_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "sched_broadcast", "Schedule a broadcast event to a running call", sched_broadcast_function, SCHED_BROADCAST_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "sched_transfer", "Schedule a broadcast event to a running call", sched_transfer_function, SCHED_TRANSFER_SYNTAX);
+ SWITCH_ADD_API(commands_api_interface, "create_uuid", "Create a uuid", uuid_function, UUID_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "sched_api", "Schedule an api command", sched_api_function, "[+]<time> <group_name> <command_string>");
SWITCH_ADD_API(commands_api_interface, "sched_del", "Delete a Scheduled task", sched_del_function, "<task_id>|<group_id>");
SWITCH_ADD_API(commands_api_interface, "xml_wrap", "Wrap another api command in xml", xml_wrap_api_function, "<command> <args>");
Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c (original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c Thu Jul 5 13:03:14 2007
@@ -930,6 +930,29 @@
}
return SWITCH_STATUS_FALSE;
+ } else if (!strncasecmp(ret, "volume", 6)) {
+ char *p;
+
+ if ((p = strchr(ret, ':'))) {
+ p++;
+ if (*p == '+' || *p == '-') {
+ int step;
+ if (!(step = atoi(p))) {
+ step = 1;
+ }
+ fh->vol += step;
+ } else {
+ int vol = atoi(p);
+ fh->vol = vol;
+ }
+ return SWITCH_STATUS_SUCCESS;
+ }
+
+ if (fh->vol) {
+ switch_normalize_volume(fh->vol);
+ }
+
+ return SWITCH_STATUS_FALSE;
} else if (!strcasecmp(ret, "pause")) {
if (switch_test_flag(fh, SWITCH_FILE_PAUSE)) {
switch_clear_flag(fh, SWITCH_FILE_PAUSE);
@@ -1361,8 +1384,8 @@
switch_file_handle_t fh = { 0 };
JSFunction *function;
switch_input_args_t args = { 0 };
- char *prebuf;
-
+ char *prebuf, posbuf[35] = "";
+
METHOD_SANITY_CHECK();
channel = switch_core_session_get_channel(jss->session);
@@ -1420,6 +1443,9 @@
JS_ResumeRequest(cx, cb_state.saveDepth);
*rval = cb_state.ret;
+ snprintf(posbuf, sizeof(posbuf), "%u", fh.offset_pos);
+ switch_channel_set_variable(channel, "last_file_position", posbuf);
+
return JS_TRUE;
}
@@ -1768,15 +1794,19 @@
CHANNEL_SANITY_CHECK();
- if (argc > 1) {
+ if (argc > 0) {
const switch_application_interface_t *application_interface;
char *app_name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
- char *app_arg = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
+ char *app_arg = NULL;
struct js_session *jss = JS_GetPrivate(cx, obj);
jsrefcount saveDepth;
METHOD_SANITY_CHECK();
+ if (argc > 1) {
+ app_arg = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
+ }
+
if ((application_interface = switch_loadable_module_get_application_interface(app_name))) {
if (application_interface->application_function) {
saveDepth = JS_SuspendRequest(cx);
Modified: freeswitch/trunk/src/switch_core_file.c
==============================================================================
--- freeswitch/trunk/src/switch_core_file.c (original)
+++ freeswitch/trunk/src/switch_core_file.c Thu Jul 5 13:03:14 2007
@@ -110,11 +110,17 @@
SWITCH_DECLARE(switch_status_t) switch_core_file_seek(switch_file_handle_t *fh, unsigned int *cur_pos, int64_t samples, int whence)
{
+ switch_status_t status;
+
assert(fh != NULL);
assert(fh->file_interface != NULL);
switch_set_flag(fh, SWITCH_FILE_SEEK);
- return fh->file_interface->file_seek(fh, cur_pos, samples, whence);
+ status = fh->file_interface->file_seek(fh, cur_pos, samples, whence);
+ if (samples) {
+ fh->offset_pos = *cur_pos;
+ }
+ return status;
}
SWITCH_DECLARE(switch_status_t) switch_core_file_set_string(switch_file_handle_t *fh, switch_audio_col_t col, const char *string)
Modified: freeswitch/trunk/src/switch_ivr_play_say.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_play_say.c (original)
+++ freeswitch/trunk/src/switch_ivr_play_say.c Thu Jul 5 13:03:14 2007
@@ -692,6 +692,7 @@
if (sample_start > 0) {
uint32_t pos = 0;
+ switch_core_file_seek(fh, &pos, 0, SEEK_SET);
switch_core_file_seek(fh, &pos, sample_start, SEEK_CUR);
}
@@ -879,6 +880,7 @@
if (done || olen <= 0) {
break;
}
+
if (!asis) {
if (fh->speed > 2) {
@@ -940,8 +942,15 @@
olen = llen;
}
- write_frame.datalen = (uint32_t) (olen * (asis ? 1 : 2));
- write_frame.samples = (uint32_t) olen;
+ write_frame.samples = olen;
+
+ if (asis) {
+ write_frame.datalen = olen;
+ } else {
+ write_frame.datalen = write_frame.samples * 2;
+ }
+
+
llen = olen;
@@ -957,8 +966,13 @@
#endif
stream_id = 0;
- status = switch_core_session_write_frame(session, &write_frame, -1, stream_id);
+ if (fh->vol) {
+ switch_change_sln_volume(write_frame.data, write_frame.datalen / 2, fh->vol);
+ }
+ fh->offset_pos += write_frame.samples / 2;
+ status = switch_core_session_write_frame(session, &write_frame, -1, stream_id);
+
if (status == SWITCH_STATUS_MORE_DATA) {
status = SWITCH_STATUS_SUCCESS;
continue;
@@ -991,6 +1005,8 @@
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "done playing file\n");
+ switch_core_file_seek(fh, &fh->last_pos, 0, SEEK_CUR);
+
switch_core_file_close(fh);
switch_buffer_destroy(&fh->audio_buffer);
if (!asis) {
More information about the Freeswitch-svn
mailing list