FS-8838 [mod_rayo] improve logging and error handling when executing API on output component. Attempt to make output component stop a little more robust.

This commit is contained in:
Chris Rienzo 2016-02-16 13:54:14 -05:00
parent 2d46e0af01
commit 7e38ce9899
1 changed files with 91 additions and 15 deletions

View File

@ -1,6 +1,6 @@
/*
* 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
*
@ -245,15 +245,23 @@ static iks *start_mixer_output_component(struct rayo_actor *mixer, struct rayo_m
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;
}
/**
@ -262,14 +270,22 @@ static iks *stop_output_component(struct rayo_actor *component, struct rayo_mess
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;
}
/**
@ -278,14 +294,22 @@ static iks *pause_output_component(struct rayo_actor *component, struct rayo_mes
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;
}
/**
@ -294,14 +318,22 @@ static iks *resume_output_component(struct rayo_actor *component, struct rayo_me
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;
}
/**
@ -310,14 +342,22 @@ static iks *speed_up_output_component(struct rayo_actor *component, struct rayo_
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;
}
/**
@ -326,14 +366,22 @@ static iks *speed_down_output_component(struct rayo_actor *component, struct ray
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;
}
/**
@ -342,14 +390,22 @@ static iks *volume_up_output_component(struct rayo_actor *component, struct rayo
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;
}
/**
@ -361,6 +417,7 @@ static iks *seek_output_component(struct rayo_actor *component, struct rayo_mess
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),
@ -369,11 +426,17 @@ static iks *seek_output_component(struct rayo_actor *component, struct rayo_mess
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);
}
@ -693,6 +756,8 @@ struct fileman_file_context {
const char *uuid;
/** fileman control ID */
const char *id;
/** done flag */
int done;
};
/**
@ -861,7 +926,11 @@ static switch_status_t fileman_file_read(switch_file_handle_t *handle, void *dat
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;
@ -1105,8 +1174,10 @@ static switch_status_t fileman_process_cmd(const char *cmd, switch_file_handle_t
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")) {
@ -1175,12 +1246,17 @@ SWITCH_STANDARD_API(fileman_api)
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);
switch_mutex_unlock(fileman_globals.mutex);
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, "-ERR No file handle!\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 file handle not found\n");
}
goto done;
}