add uuid fsapi function, last_file_position variable, and volume controls to js callback volume:+1 etc
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5498 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
c02f435a30
commit
7feef76fb2
|
@ -284,6 +284,9 @@ struct switch_file_handle {
|
|||
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 */
|
||||
|
|
|
@ -311,6 +311,19 @@ SWITCH_STANDARD_API(tone_detect_session_function)
|
|||
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_MODULE_LOAD_FUNCTION(mod_commands_load)
|
|||
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_MODULE_LOAD_FUNCTION(mod_commands_load)
|
|||
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>");
|
||||
|
|
|
@ -929,6 +929,29 @@ static switch_status_t js_stream_input_callback(switch_core_session_t *session,
|
|||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
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)) {
|
||||
|
@ -1361,8 +1384,8 @@ static JSBool session_streamfile(JSContext * cx, JSObject * obj, uintN argc, jsv
|
|||
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 @@ static JSBool session_streamfile(JSContext * cx, JSObject * obj, uintN argc, jsv
|
|||
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 @@ static JSBool session_execute(JSContext * cx, JSObject * obj, uintN argc, jsval
|
|||
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);
|
||||
|
|
|
@ -110,11 +110,17 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh,
|
|||
|
||||
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)
|
||||
|
|
|
@ -692,6 +692,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
|
|||
|
||||
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 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
|
|||
if (done || olen <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (!asis) {
|
||||
if (fh->speed > 2) {
|
||||
|
@ -940,8 +942,15 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
|
|||
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 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
|
|||
#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_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
|
|||
}
|
||||
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue