#include "asterisk.h"
#include <signal.h>
#include <fcntl.h>
#include <sys/time.h>
#include "asterisk/paths.h"
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/frame.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/translate.h"
#include "asterisk/app.h"

Go to the source code of this file.
Defines | |
| #define | path_BIN "/usr/bin/" |
| #define | path_LOCAL "/usr/local/bin/" |
Functions | |
| static void | __reg_module (void) |
| static void | __unreg_module (void) |
| static int | ices_exec (struct ast_channel *chan, const char *data) |
| static int | icesencode (char *filename, int fd) |
| static int | load_module (void) |
| static int | unload_module (void) |
Variables | |
| static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Encode and Stream via icecast and ices" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } |
| static char * | app = "ICES" |
| static struct ast_module_info * | ast_module_info = &__mod_info |
Definition in file app_ices.c.
| #define path_BIN "/usr/bin/" |
| #define path_LOCAL "/usr/local/bin/" |
| static void __reg_module | ( | void | ) | [static] |
Definition at line 216 of file app_ices.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 216 of file app_ices.c.
| static int ices_exec | ( | struct ast_channel * | chan, | |
| const char * | data | |||
| ) | [static] |
Definition at line 111 of file app_ices.c.
References ast_channel::_state, ast_answer(), ast_config_AST_CONFIG_DIR, ast_copy_string(), ast_debug, ast_format_clear(), ast_format_copy(), AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_frfree, ast_log(), ast_read(), ast_set_read_format(), ast_set_read_format_by_id(), AST_STATE_UP, ast_stopstream(), ast_strlen_zero(), ast_waitfor(), ast_frame::data, ast_frame::datalen, errno, f, ast_flags::flags, ast_frame::frametype, icesencode(), ast_format::id, LOG_WARNING, ast_frame::ptr, and ast_channel::readformat.
Referenced by load_module().
00112 { 00113 int res = 0; 00114 int fds[2]; 00115 int ms = -1; 00116 int pid = -1; 00117 int flags; 00118 struct ast_format oreadformat; 00119 struct ast_frame *f; 00120 char filename[256]=""; 00121 char *c; 00122 00123 ast_format_clear(&oreadformat); 00124 if (ast_strlen_zero(data)) { 00125 ast_log(LOG_WARNING, "ICES requires an argument (configfile.xml)\n"); 00126 return -1; 00127 } 00128 00129 if (pipe(fds)) { 00130 ast_log(LOG_WARNING, "Unable to create pipe\n"); 00131 return -1; 00132 } 00133 flags = fcntl(fds[1], F_GETFL); 00134 fcntl(fds[1], F_SETFL, flags | O_NONBLOCK); 00135 00136 ast_stopstream(chan); 00137 00138 if (chan->_state != AST_STATE_UP) 00139 res = ast_answer(chan); 00140 00141 if (res) { 00142 close(fds[0]); 00143 close(fds[1]); 00144 ast_log(LOG_WARNING, "Answer failed!\n"); 00145 return -1; 00146 } 00147 00148 ast_format_copy(&oreadformat, &chan->readformat); 00149 res = ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR); 00150 if (res < 0) { 00151 close(fds[0]); 00152 close(fds[1]); 00153 ast_log(LOG_WARNING, "Unable to set write format to signed linear\n"); 00154 return -1; 00155 } 00156 if (((char *)data)[0] == '/') 00157 ast_copy_string(filename, (char *) data, sizeof(filename)); 00158 else 00159 snprintf(filename, sizeof(filename), "%s/%s", ast_config_AST_CONFIG_DIR, (char *)data); 00160 /* Placeholder for options */ 00161 c = strchr(filename, '|'); 00162 if (c) 00163 *c = '\0'; 00164 res = icesencode(filename, fds[0]); 00165 if (res >= 0) { 00166 pid = res; 00167 for (;;) { 00168 /* Wait for audio, and stream */ 00169 ms = ast_waitfor(chan, -1); 00170 if (ms < 0) { 00171 ast_debug(1, "Hangup detected\n"); 00172 res = -1; 00173 break; 00174 } 00175 f = ast_read(chan); 00176 if (!f) { 00177 ast_debug(1, "Null frame == hangup() detected\n"); 00178 res = -1; 00179 break; 00180 } 00181 if (f->frametype == AST_FRAME_VOICE) { 00182 res = write(fds[1], f->data.ptr, f->datalen); 00183 if (res < 0) { 00184 if (errno != EAGAIN) { 00185 ast_log(LOG_WARNING, "Write failed to pipe: %s\n", strerror(errno)); 00186 res = -1; 00187 ast_frfree(f); 00188 break; 00189 } 00190 } 00191 } 00192 ast_frfree(f); 00193 } 00194 } 00195 close(fds[0]); 00196 close(fds[1]); 00197 00198 if (pid > -1) 00199 kill(pid, SIGKILL); 00200 if (!res && oreadformat.id) 00201 ast_set_read_format(chan, &oreadformat); 00202 00203 return res; 00204 }
| static int icesencode | ( | char * | filename, | |
| int | fd | |||
| ) | [static] |
Definition at line 76 of file app_ices.c.
References ast_close_fds_above_n(), ast_debug, ast_log(), ast_opt_high_priority, ast_safe_fork(), ast_set_priority(), LOG_WARNING, path_BIN, path_LOCAL, and SENTINEL.
Referenced by ices_exec().
00077 { 00078 int res; 00079 00080 res = ast_safe_fork(0); 00081 if (res < 0) 00082 ast_log(LOG_WARNING, "Fork failed\n"); 00083 if (res) { 00084 return res; 00085 } 00086 00087 if (ast_opt_high_priority) 00088 ast_set_priority(0); 00089 dup2(fd, STDIN_FILENO); 00090 ast_close_fds_above_n(STDERR_FILENO); 00091 00092 /* Most commonly installed in /usr/local/bin 00093 * But many places has it in /usr/bin 00094 * As a last-ditch effort, try to use PATH 00095 */ 00096 execl(path_LOCAL "ices2", "ices", filename, SENTINEL); 00097 execl(path_BIN "ices2", "ices", filename, SENTINEL); 00098 execlp("ices2", "ices", filename, SENTINEL); 00099 00100 ast_debug(1, "Couldn't find ices version 2, attempting to use ices version 1."); 00101 00102 execl(path_LOCAL "ices", "ices", filename, SENTINEL); 00103 execl(path_BIN "ices", "ices", filename, SENTINEL); 00104 execlp("ices", "ices", filename, SENTINEL); 00105 00106 ast_log(LOG_WARNING, "Execute of ices failed, could not find command.\n"); 00107 close(fd); 00108 _exit(0); 00109 }
| static int load_module | ( | void | ) | [static] |
Definition at line 211 of file app_ices.c.
References ast_register_application_xml, and ices_exec().
00212 { 00213 return ast_register_application_xml(app, ices_exec); 00214 }
| static int unload_module | ( | void | ) | [static] |
Definition at line 206 of file app_ices.c.
References ast_unregister_application().
00207 { 00208 return ast_unregister_application(app); 00209 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Encode and Stream via icecast and ices" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static] |
Definition at line 216 of file app_ices.c.
char* app = "ICES" [static] |
Definition at line 74 of file app_ices.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 216 of file app_ices.c.
1.5.6