mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-23 20:51:58 +00:00
add session_displace api and app
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5366 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -565,7 +565,7 @@ SWITCH_STANDARD_API(session_record_function)
|
||||
goto usage;
|
||||
}
|
||||
|
||||
if ((argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) != 3) {
|
||||
if ((argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) < 3) {
|
||||
goto usage;
|
||||
}
|
||||
|
||||
@@ -609,6 +609,73 @@ SWITCH_STANDARD_API(session_record_function)
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
SWITCH_STANDARD_API(session_displace_function)
|
||||
{
|
||||
switch_core_session_t *rsession = NULL;
|
||||
char *mycmd = NULL, *argv[5] = { 0 };
|
||||
char *uuid = NULL, *action = NULL, *path = NULL;
|
||||
int argc = 0;
|
||||
uint32_t limit = 0;
|
||||
char *flags = NULL;
|
||||
|
||||
if (session) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
if (switch_strlen_zero(cmd)) {
|
||||
goto usage;
|
||||
}
|
||||
|
||||
if (!(mycmd = strdup(cmd))) {
|
||||
goto usage;
|
||||
}
|
||||
|
||||
if ((argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) < 3) {
|
||||
goto usage;
|
||||
}
|
||||
|
||||
uuid = argv[0];
|
||||
action = argv[1];
|
||||
path = argv[2];
|
||||
limit = argv[3] ? atoi(argv[3]) : 0;
|
||||
flags = argv[4];
|
||||
|
||||
if (!(rsession = switch_core_session_locate(uuid))) {
|
||||
stream->write_function(stream, "-Error Cannot locate session!\n");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (switch_strlen_zero(action) || switch_strlen_zero(path)) {
|
||||
goto usage;
|
||||
}
|
||||
|
||||
if (!strcasecmp(action, "start")) {
|
||||
switch_ivr_displace_session(rsession, path, limit, flags);
|
||||
} else if (!strcasecmp(action, "stop")) {
|
||||
switch_ivr_stop_displace_session(rsession, path);
|
||||
} else {
|
||||
goto usage;
|
||||
}
|
||||
|
||||
goto done;
|
||||
|
||||
usage:
|
||||
|
||||
stream->write_function(stream, "INVALID SYNTAX\n");
|
||||
switch_safe_free(mycmd);
|
||||
|
||||
|
||||
done:
|
||||
|
||||
if (rsession) {
|
||||
switch_core_session_rwunlock(rsession);
|
||||
}
|
||||
|
||||
switch_safe_free(mycmd);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
SWITCH_STANDARD_API(pause_function)
|
||||
{
|
||||
switch_core_session_t *psession = NULL;
|
||||
@@ -1237,12 +1304,20 @@ static switch_api_interface_t session_record_api_interface = {
|
||||
/*.next */ &broadcast_api_interface
|
||||
};
|
||||
|
||||
static switch_api_interface_t session_displace_api_interface = {
|
||||
/*.interface_name */ "session_displace",
|
||||
/*.desc */ "session displace",
|
||||
/*.function */ session_displace_function,
|
||||
/*.syntax */ "<uuid> [start|stop] <path> [<limit>] [mux]",
|
||||
/*.next */ &broadcast_api_interface
|
||||
};
|
||||
|
||||
static switch_api_interface_t uuid_bridge_api_interface = {
|
||||
/*.interface_name */ "uuid_bridge",
|
||||
/*.desc */ "uuid_bridge",
|
||||
/*.function */ uuid_bridge_function,
|
||||
/*.syntax */ "<uuid> <other_uuid>",
|
||||
/*.next */ &session_record_api_interface
|
||||
/*.next */ &session_displace_api_interface
|
||||
};
|
||||
|
||||
static switch_api_interface_t status_api_interface = {
|
||||
|
||||
@@ -789,6 +789,43 @@ static void playback_function(switch_core_session_t *session, char *data)
|
||||
|
||||
}
|
||||
|
||||
static void displace_session_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
switch_channel_t *channel;
|
||||
char *path = NULL;
|
||||
uint32_t limit = 0;
|
||||
char *argv[6];
|
||||
int x, argc;
|
||||
char *lbuf = NULL;
|
||||
char *flags = NULL;
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
|
||||
if (data && (lbuf = switch_core_session_strdup(session, data))
|
||||
&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
|
||||
path = argv[0];
|
||||
for(x = 0; x < argc; x++) {
|
||||
if (strchr(argv[x], '+')) {
|
||||
limit = atoi(argv[x]);
|
||||
} else if (!switch_strlen_zero(argv[x])) {
|
||||
flags = argv[x];
|
||||
}
|
||||
}
|
||||
switch_ivr_displace_session(session, path, limit, flags);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void stop_displace_session_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
switch_channel_t *channel;
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
|
||||
switch_ivr_stop_displace_session(session, data);
|
||||
}
|
||||
|
||||
|
||||
static void record_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
@@ -995,6 +1032,26 @@ static switch_application_interface_t speak_application_interface = {
|
||||
&bridge_application_interface
|
||||
};
|
||||
|
||||
static switch_application_interface_t displace_application_interface = {
|
||||
/*.interface_name */ "displace",
|
||||
/*.application_function */ displace_session_function,
|
||||
/* long_desc */ "Displace audio from a file to the channels input",
|
||||
/* short_desc */ "Displace File",
|
||||
/* syntax */ "<path> [+time_limit_ms] [mux]",
|
||||
/* flags */ SAF_NONE,
|
||||
&speak_application_interface
|
||||
};
|
||||
|
||||
static switch_application_interface_t stop_displace_application_interface = {
|
||||
/*.interface_name */ "displace",
|
||||
/*.application_function */ stop_displace_session_function,
|
||||
/* long_desc */ "Stop Displacing to a file",
|
||||
/* short_desc */ "Stop Displace File",
|
||||
/* syntax */ "<path>",
|
||||
/* flags */ SAF_NONE,
|
||||
&displace_application_interface
|
||||
};
|
||||
|
||||
static switch_application_interface_t record_application_interface = {
|
||||
/*.interface_name */ "record",
|
||||
/*.application_function */ record_function,
|
||||
@@ -1002,7 +1059,7 @@ static switch_application_interface_t record_application_interface = {
|
||||
/* short_desc */ "Record File",
|
||||
/* syntax */ "<path> [+time_limit_ms]",
|
||||
/* flags */ SAF_NONE,
|
||||
&speak_application_interface
|
||||
&stop_displace_application_interface
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -257,8 +257,13 @@ static void soundtouch_start_function(switch_core_session_t *session, char *data
|
||||
char *lbuf = NULL;
|
||||
int x;
|
||||
|
||||
if (switch_channel_get_private(channel, "_soundtouch_")) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot run 2 at once on the same channel!\n");
|
||||
if ((bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_soundtouch_"))) {
|
||||
if (!switch_strlen_zero(data) && !strcasecmp(data, "stop")) {
|
||||
switch_channel_set_private(channel, "_soundtouch_", NULL);
|
||||
switch_core_media_bug_remove(session, &bug);
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot run 2 at once on the same channel!\n");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user