Newer
Older
while(c->stream) {
res = ast_sched_wait(c->sched);
if ((res < 0) && !c->timingfunc) {
Mark Spencer
committed
ast_stopstream(c);
if (res < 0)
res = 1000;
res = ast_waitfor(c, res);
if (res < 0) {
ast_log(LOG_WARNING, "Select failed (%s)\n", strerror(errno));
return res;
fr = ast_read(c);
if (!fr) {
#if 0
ast_log(LOG_DEBUG, "Got hung up\n");
#endif
return -1;
}
switch(fr->frametype) {
case AST_FRAME_DTMF:
res = fr->subclass;
if (strchr(breakon, res)) {
ast_frfree(fr);
break;
case AST_FRAME_CONTROL:
switch(fr->subclass) {
case AST_CONTROL_HANGUP:
ast_frfree(fr);
return -1;
case AST_CONTROL_RINGING:
case AST_CONTROL_ANSWER:
default:
ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", fr->subclass);
}
}
Kevin P. Fleming
committed
int ast_waitstream_fr(struct ast_channel *c, const char *breakon, const char *forward, const char *rewind, int ms)
{
int res;
struct ast_frame *fr;
Josh Roberson
committed
if (!breakon)
breakon = "";
if (!forward)
forward = "";
if (!rewind)
rewind = "";
while(c->stream) {
res = ast_sched_wait(c->sched);
Mark Spencer
committed
ast_stopstream(c);
res = ast_waitfor(c, res);
if (res < 0) {
ast_log(LOG_WARNING, "Select failed (%s)\n", strerror(errno));
return res;
} else
if (res > 0) {
fr = ast_read(c);
if (!fr) {
#if 0
ast_log(LOG_DEBUG, "Got hung up\n");
#endif
return -1;
}
switch(fr->frametype) {
case AST_FRAME_DTMF:
res = fr->subclass;
if (strchr(forward,res)) {
ast_stream_fastforward(c->stream, ms);
} else if (strchr(rewind,res)) {
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
} else if (strchr(breakon, res)) {
ast_frfree(fr);
return res;
}
break;
case AST_FRAME_CONTROL:
switch(fr->subclass) {
case AST_CONTROL_HANGUP:
ast_frfree(fr);
return -1;
case AST_CONTROL_RINGING:
case AST_CONTROL_ANSWER:
/* Unimportant */
break;
default:
ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", fr->subclass);
}
}
/* Ignore */
ast_frfree(fr);
} else
ast_sched_runq(c->sched);
}
return (c->_softhangup ? -1 : 0);
}
Kevin P. Fleming
committed
int ast_waitstream_full(struct ast_channel *c, const char *breakon, int audiofd, int cmdfd)
{
int res;
int ms;
int outfd;
struct ast_frame *fr;
struct ast_channel *rchan;
Josh Roberson
committed
if (!breakon)
breakon = "";
while(c->stream) {
ms = ast_sched_wait(c->sched);
Mark Spencer
committed
ast_stopstream(c);
rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms);
if (!rchan && (outfd < 0) && (ms)) {
/* Continue */
if (errno == EINTR)
continue;
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno));
return -1;
} else if (outfd > -1) {
/* The FD we were watching has something waiting */
return 1;
} else if (rchan) {
fr = ast_read(c);
if (!fr) {
#if 0
ast_log(LOG_DEBUG, "Got hung up\n");
#endif
return -1;
}
switch(fr->frametype) {
case AST_FRAME_DTMF:
res = fr->subclass;
if (strchr(breakon, res)) {
ast_frfree(fr);
return res;
}
break;
case AST_FRAME_CONTROL:
switch(fr->subclass) {
case AST_CONTROL_HANGUP:
ast_frfree(fr);
return -1;
case AST_CONTROL_RINGING:
case AST_CONTROL_ANSWER:
/* Unimportant */
break;
default:
ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", fr->subclass);
}
case AST_FRAME_VOICE:
/* Write audio if appropriate */
if (audiofd > -1)
write(audiofd, fr->data, fr->datalen);
}
/* Ignore */
ast_frfree(fr);
}
return (c->_softhangup ? -1 : 0);
}
Mark Spencer
committed
Kevin P. Fleming
committed
int ast_waitstream_exten(struct ast_channel *c, const char *context)
{
/* Waitstream, with return in the case of a valid 1 digit extension */
/* in the current or specified context being pressed */
/* XXX Maybe I should just front-end ast_waitstream_full ? XXX */
int res;
struct ast_frame *fr;
char exten[AST_MAX_EXTENSION];
Kevin P. Fleming
committed
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
if (!context) context = c->context;
while(c->stream) {
res = ast_sched_wait(c->sched);
if ((res < 0) && !c->timingfunc) {
ast_stopstream(c);
break;
}
if (res < 0)
res = 1000;
res = ast_waitfor(c, res);
if (res < 0) {
ast_log(LOG_WARNING, "Select failed (%s)\n", strerror(errno));
return res;
} else if (res > 0) {
fr = ast_read(c);
if (!fr) {
#if 0
ast_log(LOG_DEBUG, "Got hung up\n");
#endif
return -1;
}
switch(fr->frametype) {
case AST_FRAME_DTMF:
res = fr->subclass;
snprintf(exten, sizeof(exten), "%c", res);
if (ast_exists_extension(c, context, exten, 1, c->cid.cid_num)) {
ast_frfree(fr);
return res;
}
break;
case AST_FRAME_CONTROL:
switch(fr->subclass) {
case AST_CONTROL_HANGUP:
ast_frfree(fr);
return -1;
case AST_CONTROL_RINGING:
case AST_CONTROL_ANSWER:
/* Unimportant */
break;
default:
ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", fr->subclass);
}
}
/* Ignore */
ast_frfree(fr);
}
ast_sched_runq(c->sched);
}
return (c->_softhangup ? -1 : 0);
}
Mark Spencer
committed
static int show_file_formats(int fd, int argc, char *argv[])
{
#define FORMAT "%-10s %-10s %-20s\n"
#define FORMAT2 "%-10s %-10s %-20s\n"
struct ast_format *f;
Mark Spencer
committed
if (argc != 3)
return RESULT_SHOWUSAGE;
ast_cli(fd, FORMAT, "Format", "Name", "Extensions");
if (AST_LIST_LOCK(&formats)) {
Mark Spencer
committed
ast_log(LOG_WARNING, "Unable to lock format list\n");
return -1;
Mark Spencer
committed
AST_LIST_TRAVERSE(&formats, f, list) {
Mark Spencer
committed
ast_cli(fd, FORMAT2, ast_getformatname(f->format), f->name, f->exts);
}
AST_LIST_UNLOCK(&formats);
ast_cli(fd, "%d file formats registered.\n", count_fmt);
Mark Spencer
committed
return RESULT_SUCCESS;
#undef FORMAT
#undef FORMAT2
Mark Spencer
committed
}
struct ast_cli_entry show_file =
{
{ "show", "file", "formats" },
show_file_formats,
"Displays file formats",
"Usage: show file formats\n"
" displays currently registered file formats (if any)\n"
};
int ast_file_init(void)
{
ast_cli_register(&show_file);
return 0;
}