Newer
Older
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)) {
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
} 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;
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
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
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
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
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
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_mutex_lock(&formatlock)) {
ast_log(LOG_WARNING, "Unable to lock format list\n");
return -1;
Mark Spencer
committed
f = formats;
while(f) {
ast_cli(fd, FORMAT2, ast_getformatname(f->format), f->name, f->exts);
f = f->next;
Mark Spencer
committed
};
ast_mutex_unlock(&formatlock);
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;
}