/*
* mod_rayo for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2013-2015, Grasshopper
+ * Copyright (C) 2013-2016, Grasshopper
*
* Version: MPL 1.1
*
static iks *stop_output_component(struct rayo_actor *component, struct rayo_message *msg, void *data)
{
iks *iq = msg->payload;
+ iks *result = NULL;
switch_stream_handle_t stream = { 0 };
char *command = switch_mprintf("%s stop", RAYO_JID(component));
SWITCH_STANDARD_STREAM(stream);
OUTPUT_COMPONENT(component)->stop = 1;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s stopping\n", RAYO_JID(component));
switch_api_execute("fileman", command, NULL, &stream);
+ if (!zstr((char *)stream.data) && !strncmp((char *)stream.data, "+OK", 3)) {
+ result = iks_new_iq_result(iq);
+ } else if (!zstr((char *)stream.data)) {
+ result = iks_new_error_detailed_printf(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, "%s", (char *)stream.data);
+ } else {
+ result = iks_new_error(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR);
+ }
switch_safe_free(stream.data);
switch_safe_free(command);
- return iks_new_iq_result(iq);
+ return result;
}
/**
static iks *pause_output_component(struct rayo_actor *component, struct rayo_message *msg, void *data)
{
iks *iq = msg->payload;
+ iks *result = NULL;
switch_stream_handle_t stream = { 0 };
char *command = switch_mprintf("%s pause", RAYO_JID(component));
SWITCH_STANDARD_STREAM(stream);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s pausing\n", RAYO_JID(component));
switch_api_execute("fileman", command, NULL, &stream);
+ if (!zstr((char *)stream.data) && !strncmp((char *)stream.data, "+OK", 3)) {
+ result = iks_new_iq_result(iq);
+ } else if (!zstr((char *)stream.data)) {
+ result = iks_new_error_detailed_printf(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, "%s", (char *)stream.data);
+ } else {
+ result = iks_new_error(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR);
+ }
switch_safe_free(stream.data);
switch_safe_free(command);
- return iks_new_iq_result(iq);
+ return result;
}
/**
static iks *resume_output_component(struct rayo_actor *component, struct rayo_message *msg, void *data)
{
iks *iq = msg->payload;
+ iks *result = NULL;
switch_stream_handle_t stream = { 0 };
char *command = switch_mprintf("%s resume", RAYO_JID(component));
SWITCH_STANDARD_STREAM(stream);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s resuming\n", RAYO_JID(component));
switch_api_execute("fileman", command, NULL, &stream);
+ if (!zstr((char *)stream.data) && !strncmp((char *)stream.data, "+OK", 3)) {
+ result = iks_new_iq_result(iq);
+ } else if (!zstr((char *)stream.data)) {
+ result = iks_new_error_detailed_printf(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, "%s", (char *)stream.data);
+ } else {
+ result = iks_new_error(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR);
+ }
switch_safe_free(stream.data);
switch_safe_free(command);
- return iks_new_iq_result(iq);
+ return result;
}
/**
static iks *speed_up_output_component(struct rayo_actor *component, struct rayo_message *msg, void *data)
{
iks *iq = msg->payload;
+ iks *result = NULL;
switch_stream_handle_t stream = { 0 };
char *command = switch_mprintf("%s speed:+", RAYO_JID(component));
SWITCH_STANDARD_STREAM(stream);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s speeding up\n", RAYO_JID(component));
switch_api_execute("fileman", command, NULL, &stream);
+ if (!zstr((char *)stream.data) && !strncmp((char *)stream.data, "+OK", 3)) {
+ result = iks_new_iq_result(iq);
+ } else if (!zstr((char *)stream.data)) {
+ result = iks_new_error_detailed_printf(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, "%s", (char *)stream.data);
+ } else {
+ result = iks_new_error(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR);
+ }
switch_safe_free(stream.data);
switch_safe_free(command);
- return iks_new_iq_result(iq);
+ return result;
}
/**
static iks *speed_down_output_component(struct rayo_actor *component, struct rayo_message *msg, void *data)
{
iks *iq = msg->payload;
+ iks *result = NULL;
switch_stream_handle_t stream = { 0 };
char *command = switch_mprintf("%s speed:-", RAYO_JID(component));
SWITCH_STANDARD_STREAM(stream);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s slowing down\n", RAYO_JID(component));
switch_api_execute("fileman", command, NULL, &stream);
+ if (!zstr((char *)stream.data) && !strncmp((char *)stream.data, "+OK", 3)) {
+ result = iks_new_iq_result(iq);
+ } else if (!zstr((char *)stream.data)) {
+ result = iks_new_error_detailed_printf(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, "%s", (char *)stream.data);
+ } else {
+ result = iks_new_error(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR);
+ }
switch_safe_free(stream.data);
switch_safe_free(command);
- return iks_new_iq_result(iq);
+ return result;
}
/**
static iks *volume_up_output_component(struct rayo_actor *component, struct rayo_message *msg, void *data)
{
iks *iq = msg->payload;
+ iks *result = NULL;
switch_stream_handle_t stream = { 0 };
char *command = switch_mprintf("%s volume:+", RAYO_JID(component));
SWITCH_STANDARD_STREAM(stream);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s increasing volume\n", RAYO_JID(component));
switch_api_execute("fileman", command, NULL, &stream);
+ if (!zstr((char *)stream.data) && !strncmp((char *)stream.data, "+OK", 3)) {
+ result = iks_new_iq_result(iq);
+ } else if (!zstr((char *)stream.data)) {
+ result = iks_new_error_detailed_printf(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, "%s", (char *)stream.data);
+ } else {
+ result = iks_new_error(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR);
+ }
switch_safe_free(stream.data);
switch_safe_free(command);
- return iks_new_iq_result(iq);
+ return result;
}
/**
static iks *volume_down_output_component(struct rayo_actor *component, struct rayo_message *msg, void *data)
{
iks *iq = msg->payload;
+ iks *result = NULL;
switch_stream_handle_t stream = { 0 };
char *command = switch_mprintf("%s volume:-", RAYO_JID(component));
SWITCH_STANDARD_STREAM(stream);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s lowering volume\n", RAYO_JID(component));
switch_api_execute("fileman", command, NULL, &stream);
+ if (!zstr((char *)stream.data) && !strncmp((char *)stream.data, "+OK", 3)) {
+ result = iks_new_iq_result(iq);
+ } else if (!zstr((char *)stream.data)) {
+ result = iks_new_error_detailed_printf(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, "%s", (char *)stream.data);
+ } else {
+ result = iks_new_error(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR);
+ }
switch_safe_free(stream.data);
switch_safe_free(command);
- return iks_new_iq_result(iq);
+ return result;
}
/**
iks *seek = iks_find(iq, "seek");
if (VALIDATE_RAYO_OUTPUT_SEEK(seek)) {
+ iks *result = NULL;
int is_forward = !strcmp("forward", iks_find_attrib(seek, "direction"));
int amount_ms = iks_find_int_attrib(seek, "amount");
char *command = switch_mprintf("%s seek:%s%i", RAYO_JID(component),
SWITCH_STANDARD_STREAM(stream);
switch_api_execute("fileman", command, NULL, &stream);
-
+ if (!zstr((char *)stream.data) && !strncmp((char *)stream.data, "+OK", 3)) {
+ result = iks_new_iq_result(iq);
+ } else if (!zstr((char *)stream.data)) {
+ result = iks_new_error_detailed_printf(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, "%s", (char *)stream.data);
+ } else {
+ result = iks_new_error(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR);
+ }
switch_safe_free(stream.data);
switch_safe_free(command);
- return iks_new_iq_result(iq);
+ return result;
}
return iks_new_error(iq, STANZA_ERROR_BAD_REQUEST);
}
const char *uuid;
/** fileman control ID */
const char *id;
+ /** done flag */
+ int done;
};
/**
int do_speed = 1;
size_t read_bytes = 0;
- if (switch_test_flag(handle, SWITCH_FILE_PAUSE)) {
+ if (context->done) {
+ /* done with this file */
+ status = SWITCH_STATUS_FALSE;
+ goto done;
+ } else if (switch_test_flag(handle, SWITCH_FILE_PAUSE)) {
//switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->uuid), SWITCH_LOG_DEBUG, "Read pause frame\n");
memset(context->abuf, 255, *len * 2);
do_speed = 0;
switch_clear_flag(fhp, SWITCH_FILE_PAUSE);
return SWITCH_STATUS_SUCCESS;
} else if (!strcasecmp(cmd, "stop")) {
+ switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->uuid), SWITCH_LOG_DEBUG, "Stopping file\n");
+ context->done = 1;
switch_set_flag(fhp, SWITCH_FILE_DONE);
- return SWITCH_STATUS_FALSE;
+ return SWITCH_STATUS_SUCCESS;
} else if (!strcasecmp(cmd, "truncate")) {
switch_core_file_truncate(fhp, 0);
} else if (!strcasecmp(cmd, "restart")) {
switch_mutex_lock(fileman_globals.mutex);
fh = (switch_file_handle_t *)switch_core_hash_find(fileman_globals.hash, id);
if (fh) {
- fileman_process_cmd(cmd, fh);
+ if (fileman_process_cmd(cmd, fh) == SWITCH_STATUS_SUCCESS) {
+ stream->write_function(stream, "+OK\n");
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "fileman API failed for file %s\n", zstr(fh->file_path) ? "<null>" : fh->file_path);
+ stream->write_function(stream, "-ERR API call failed");
+ }
switch_mutex_unlock(fileman_globals.mutex);
- stream->write_function(stream, "+OK\n");
} else {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "fileman API failed for ID %s\n", zstr(id) : "<null>" : id);
switch_mutex_unlock(fileman_globals.mutex);
- stream->write_function(stream, "-ERR No file handle!\n");
+ stream->write_function(stream, "-ERR file handle not found\n");
}
goto done;
}