提交 7e38ce98 authored 作者: Chris Rienzo's avatar Chris Rienzo

FS-8838 [mod_rayo] improve logging and error handling when executing API on…

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.
上级 2d46e0af
/* /*
* mod_rayo for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application * 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 * Version: MPL 1.1
* *
...@@ -245,15 +245,23 @@ static iks *start_mixer_output_component(struct rayo_actor *mixer, struct rayo_m ...@@ -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) static iks *stop_output_component(struct rayo_actor *component, struct rayo_message *msg, void *data)
{ {
iks *iq = msg->payload; iks *iq = msg->payload;
iks *result = NULL;
switch_stream_handle_t stream = { 0 }; switch_stream_handle_t stream = { 0 };
char *command = switch_mprintf("%s stop", RAYO_JID(component)); char *command = switch_mprintf("%s stop", RAYO_JID(component));
SWITCH_STANDARD_STREAM(stream); SWITCH_STANDARD_STREAM(stream);
OUTPUT_COMPONENT(component)->stop = 1; OUTPUT_COMPONENT(component)->stop = 1;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s stopping\n", RAYO_JID(component)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s stopping\n", RAYO_JID(component));
switch_api_execute("fileman", command, NULL, &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(stream.data);
switch_safe_free(command); 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 ...@@ -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) static iks *pause_output_component(struct rayo_actor *component, struct rayo_message *msg, void *data)
{ {
iks *iq = msg->payload; iks *iq = msg->payload;
iks *result = NULL;
switch_stream_handle_t stream = { 0 }; switch_stream_handle_t stream = { 0 };
char *command = switch_mprintf("%s pause", RAYO_JID(component)); char *command = switch_mprintf("%s pause", RAYO_JID(component));
SWITCH_STANDARD_STREAM(stream); SWITCH_STANDARD_STREAM(stream);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s pausing\n", RAYO_JID(component)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s pausing\n", RAYO_JID(component));
switch_api_execute("fileman", command, NULL, &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(stream.data);
switch_safe_free(command); 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 ...@@ -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) static iks *resume_output_component(struct rayo_actor *component, struct rayo_message *msg, void *data)
{ {
iks *iq = msg->payload; iks *iq = msg->payload;
iks *result = NULL;
switch_stream_handle_t stream = { 0 }; switch_stream_handle_t stream = { 0 };
char *command = switch_mprintf("%s resume", RAYO_JID(component)); char *command = switch_mprintf("%s resume", RAYO_JID(component));
SWITCH_STANDARD_STREAM(stream); SWITCH_STANDARD_STREAM(stream);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s resuming\n", RAYO_JID(component)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s resuming\n", RAYO_JID(component));
switch_api_execute("fileman", command, NULL, &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(stream.data);
switch_safe_free(command); 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 ...@@ -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) static iks *speed_up_output_component(struct rayo_actor *component, struct rayo_message *msg, void *data)
{ {
iks *iq = msg->payload; iks *iq = msg->payload;
iks *result = NULL;
switch_stream_handle_t stream = { 0 }; switch_stream_handle_t stream = { 0 };
char *command = switch_mprintf("%s speed:+", RAYO_JID(component)); char *command = switch_mprintf("%s speed:+", RAYO_JID(component));
SWITCH_STANDARD_STREAM(stream); SWITCH_STANDARD_STREAM(stream);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s speeding up\n", RAYO_JID(component)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s speeding up\n", RAYO_JID(component));
switch_api_execute("fileman", command, NULL, &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(stream.data);
switch_safe_free(command); 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_ ...@@ -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) static iks *speed_down_output_component(struct rayo_actor *component, struct rayo_message *msg, void *data)
{ {
iks *iq = msg->payload; iks *iq = msg->payload;
iks *result = NULL;
switch_stream_handle_t stream = { 0 }; switch_stream_handle_t stream = { 0 };
char *command = switch_mprintf("%s speed:-", RAYO_JID(component)); char *command = switch_mprintf("%s speed:-", RAYO_JID(component));
SWITCH_STANDARD_STREAM(stream); SWITCH_STANDARD_STREAM(stream);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s slowing down\n", RAYO_JID(component)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s slowing down\n", RAYO_JID(component));
switch_api_execute("fileman", command, NULL, &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(stream.data);
switch_safe_free(command); 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 ...@@ -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) static iks *volume_up_output_component(struct rayo_actor *component, struct rayo_message *msg, void *data)
{ {
iks *iq = msg->payload; iks *iq = msg->payload;
iks *result = NULL;
switch_stream_handle_t stream = { 0 }; switch_stream_handle_t stream = { 0 };
char *command = switch_mprintf("%s volume:+", RAYO_JID(component)); char *command = switch_mprintf("%s volume:+", RAYO_JID(component));
SWITCH_STANDARD_STREAM(stream); SWITCH_STANDARD_STREAM(stream);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s increasing volume\n", RAYO_JID(component)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s increasing volume\n", RAYO_JID(component));
switch_api_execute("fileman", command, NULL, &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(stream.data);
switch_safe_free(command); 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 ...@@ -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) static iks *volume_down_output_component(struct rayo_actor *component, struct rayo_message *msg, void *data)
{ {
iks *iq = msg->payload; iks *iq = msg->payload;
iks *result = NULL;
switch_stream_handle_t stream = { 0 }; switch_stream_handle_t stream = { 0 };
char *command = switch_mprintf("%s volume:-", RAYO_JID(component)); char *command = switch_mprintf("%s volume:-", RAYO_JID(component));
SWITCH_STANDARD_STREAM(stream); SWITCH_STANDARD_STREAM(stream);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s lowering volume\n", RAYO_JID(component)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s lowering volume\n", RAYO_JID(component));
switch_api_execute("fileman", command, NULL, &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(stream.data);
switch_safe_free(command); 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 ...@@ -361,6 +417,7 @@ static iks *seek_output_component(struct rayo_actor *component, struct rayo_mess
iks *seek = iks_find(iq, "seek"); iks *seek = iks_find(iq, "seek");
if (VALIDATE_RAYO_OUTPUT_SEEK(seek)) { if (VALIDATE_RAYO_OUTPUT_SEEK(seek)) {
iks *result = NULL;
int is_forward = !strcmp("forward", iks_find_attrib(seek, "direction")); int is_forward = !strcmp("forward", iks_find_attrib(seek, "direction"));
int amount_ms = iks_find_int_attrib(seek, "amount"); int amount_ms = iks_find_int_attrib(seek, "amount");
char *command = switch_mprintf("%s seek:%s%i", RAYO_JID(component), 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 ...@@ -369,11 +426,17 @@ static iks *seek_output_component(struct rayo_actor *component, struct rayo_mess
SWITCH_STANDARD_STREAM(stream); SWITCH_STANDARD_STREAM(stream);
switch_api_execute("fileman", command, NULL, &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(stream.data);
switch_safe_free(command); switch_safe_free(command);
return iks_new_iq_result(iq); return result;
} }
return iks_new_error(iq, STANZA_ERROR_BAD_REQUEST); return iks_new_error(iq, STANZA_ERROR_BAD_REQUEST);
} }
...@@ -693,6 +756,8 @@ struct fileman_file_context { ...@@ -693,6 +756,8 @@ struct fileman_file_context {
const char *uuid; const char *uuid;
/** fileman control ID */ /** fileman control ID */
const char *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 ...@@ -861,7 +926,11 @@ static switch_status_t fileman_file_read(switch_file_handle_t *handle, void *dat
int do_speed = 1; int do_speed = 1;
size_t read_bytes = 0; 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"); //switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->uuid), SWITCH_LOG_DEBUG, "Read pause frame\n");
memset(context->abuf, 255, *len * 2); memset(context->abuf, 255, *len * 2);
do_speed = 0; do_speed = 0;
...@@ -1105,8 +1174,10 @@ static switch_status_t fileman_process_cmd(const char *cmd, switch_file_handle_t ...@@ -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); switch_clear_flag(fhp, SWITCH_FILE_PAUSE);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} else if (!strcasecmp(cmd, "stop")) { } 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); switch_set_flag(fhp, SWITCH_FILE_DONE);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_SUCCESS;
} else if (!strcasecmp(cmd, "truncate")) { } else if (!strcasecmp(cmd, "truncate")) {
switch_core_file_truncate(fhp, 0); switch_core_file_truncate(fhp, 0);
} else if (!strcasecmp(cmd, "restart")) { } else if (!strcasecmp(cmd, "restart")) {
...@@ -1175,12 +1246,17 @@ SWITCH_STANDARD_API(fileman_api) ...@@ -1175,12 +1246,17 @@ SWITCH_STANDARD_API(fileman_api)
switch_mutex_lock(fileman_globals.mutex); switch_mutex_lock(fileman_globals.mutex);
fh = (switch_file_handle_t *)switch_core_hash_find(fileman_globals.hash, id); fh = (switch_file_handle_t *)switch_core_hash_find(fileman_globals.hash, id);
if (fh) { if (fh) {
fileman_process_cmd(cmd, fh); if (fileman_process_cmd(cmd, fh) == SWITCH_STATUS_SUCCESS) {
switch_mutex_unlock(fileman_globals.mutex);
stream->write_function(stream, "+OK\n"); stream->write_function(stream, "+OK\n");
} else { } 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);
} 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); 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; goto done;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论