Make read/write mode have a lock parameter and use it properly.
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@2572 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
parent
f23e53be88
commit
5acf40987d
4
app.c
4
app.c
|
@ -86,7 +86,7 @@ int ast_app_getvoice(struct ast_channel *c, char *dest, char *dstfmt, char *prom
|
|||
return res;
|
||||
}
|
||||
rfmt = c->readformat;
|
||||
res = ast_set_read_format(c, AST_FORMAT_SLINEAR);
|
||||
res = ast_set_read_format(c, AST_FORMAT_SLINEAR, 1);
|
||||
if (res < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");
|
||||
return -1;
|
||||
|
@ -135,7 +135,7 @@ int ast_app_getvoice(struct ast_channel *c, char *dest, char *dstfmt, char *prom
|
|||
ast_frfree(f);
|
||||
}
|
||||
}
|
||||
res = ast_set_read_format(c, rfmt);
|
||||
res = ast_set_read_format(c, rfmt, 1);
|
||||
if (res)
|
||||
ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", c->name);
|
||||
ast_dsp_free(sildet);
|
||||
|
|
|
@ -521,7 +521,7 @@ static int handle_recordfile(struct ast_channel *chan, AGI *agi, int argc, char
|
|||
|
||||
if (silence > 0) {
|
||||
rfmt = chan->readformat;
|
||||
res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
|
||||
res = ast_set_read_format(chan, AST_FORMAT_SLINEAR, 1);
|
||||
if (res < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");
|
||||
return -1;
|
||||
|
@ -633,7 +633,7 @@ static int handle_recordfile(struct ast_channel *chan, AGI *agi, int argc, char
|
|||
fdprintf(agi->fd, "200 result=%d (randomerror) endpos=%ld\n", res, sample_offset);
|
||||
|
||||
if (silence > 0) {
|
||||
res = ast_set_read_format(chan, rfmt);
|
||||
res = ast_set_read_format(chan, rfmt, 1);
|
||||
if (res)
|
||||
ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", chan->name);
|
||||
ast_dsp_free(sildet);
|
||||
|
@ -1484,13 +1484,13 @@ static int eagi_exec(struct ast_channel *chan, void *data)
|
|||
int readformat;
|
||||
int res;
|
||||
readformat = chan->readformat;
|
||||
if (ast_set_read_format(chan, AST_FORMAT_SLINEAR)) {
|
||||
if (ast_set_read_format(chan, AST_FORMAT_SLINEAR, 1)) {
|
||||
ast_log(LOG_WARNING, "Unable to set channel '%s' to linear mode\n", chan->name);
|
||||
return -1;
|
||||
}
|
||||
res = agi_exec_full(chan, data, 1, 0);
|
||||
if (!res) {
|
||||
if (ast_set_read_format(chan, readformat)) {
|
||||
if (ast_set_read_format(chan, readformat, 1)) {
|
||||
ast_log(LOG_WARNING, "Unable to restore channel '%s' to format %s\n", chan->name, ast_getformatname(readformat));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,12 +129,12 @@ static int disa_exec(struct ast_channel *chan, void *data)
|
|||
FILE *fp;
|
||||
char *stringp=NULL;
|
||||
|
||||
if (ast_set_write_format(chan,AST_FORMAT_ULAW))
|
||||
if (ast_set_write_format(chan,AST_FORMAT_ULAW, 1))
|
||||
{
|
||||
ast_log(LOG_WARNING, "Unable to set write format to Mu-law on %s\n",chan->name);
|
||||
return -1;
|
||||
}
|
||||
if (ast_set_read_format(chan,AST_FORMAT_ULAW))
|
||||
if (ast_set_read_format(chan,AST_FORMAT_ULAW, 1))
|
||||
{
|
||||
ast_log(LOG_WARNING, "Unable to set read format to Mu-law on %s\n",chan->name);
|
||||
return -1;
|
||||
|
|
|
@ -45,13 +45,15 @@ static int echo_exec(struct ast_channel *chan, void *data)
|
|||
struct localuser *u;
|
||||
struct ast_frame *f;
|
||||
LOCAL_USER_ADD(u);
|
||||
ast_set_write_format(chan, ast_best_codec(chan->nativeformats));
|
||||
ast_set_read_format(chan, ast_best_codec(chan->nativeformats));
|
||||
ast_set_write_format(chan, ast_best_codec(chan->nativeformats), 1);
|
||||
ast_set_read_format(chan, ast_best_codec(chan->nativeformats), 1);
|
||||
/* Do our thing here */
|
||||
while(ast_waitfor(chan, -1) > -1) {
|
||||
f = ast_read(chan);
|
||||
if (!f)
|
||||
break;
|
||||
f->delivery.tv_sec = 0;
|
||||
f->delivery.tv_usec = 0;
|
||||
if (f->frametype == AST_FRAME_VOICE) {
|
||||
if (ast_write(chan, f))
|
||||
break;
|
||||
|
|
|
@ -158,7 +158,7 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
|
|||
ast_stopstream(chan);
|
||||
|
||||
owriteformat = chan->writeformat;
|
||||
res = ast_set_write_format(chan, AST_FORMAT_SLINEAR);
|
||||
res = ast_set_write_format(chan, AST_FORMAT_SLINEAR, 1);
|
||||
if (res < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set write format to signed linear\n");
|
||||
return -1;
|
||||
|
@ -230,7 +230,7 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
|
|||
// if (pid > -1)
|
||||
// kill(pid, SIGKILL);
|
||||
if (!res && owriteformat)
|
||||
ast_set_write_format(chan, owriteformat);
|
||||
ast_set_write_format(chan, owriteformat, 1);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ static int intercom_exec(struct ast_channel *chan, void *data)
|
|||
/* Remember original read format */
|
||||
oreadformat = chan->readformat;
|
||||
/* Set mode to signed linear */
|
||||
res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
|
||||
res = ast_set_read_format(chan, AST_FORMAT_SLINEAR, 1);
|
||||
if (res < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set format to signed linear on channel %s\n", chan->name);
|
||||
return -1;
|
||||
|
@ -170,7 +170,7 @@ static int intercom_exec(struct ast_channel *chan, void *data)
|
|||
}
|
||||
LOCAL_USER_REMOVE(u);
|
||||
if (!res)
|
||||
ast_set_read_format(chan, oreadformat);
|
||||
ast_set_read_format(chan, oreadformat, 1);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -274,25 +274,25 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c
|
|||
|
||||
if (confflags & CONFFLAG_VIDEO) {
|
||||
/* Set it into linear mode (write) */
|
||||
if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
|
||||
if (ast_set_write_format(chan, AST_FORMAT_SLINEAR, 1) < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set '%s' to write linear mode\n", chan->name);
|
||||
goto outrun;
|
||||
}
|
||||
|
||||
/* Set it into linear mode (read) */
|
||||
if (ast_set_read_format(chan, AST_FORMAT_SLINEAR) < 0) {
|
||||
if (ast_set_read_format(chan, AST_FORMAT_SLINEAR, 1) < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set '%s' to read linear mode\n", chan->name);
|
||||
goto outrun;
|
||||
}
|
||||
} else {
|
||||
/* Set it into U-law mode (write) */
|
||||
if (ast_set_write_format(chan, AST_FORMAT_ULAW) < 0) {
|
||||
if (ast_set_write_format(chan, AST_FORMAT_ULAW, 1) < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set '%s' to write ulaw mode\n", chan->name);
|
||||
goto outrun;
|
||||
}
|
||||
|
||||
/* Set it into U-law mode (read) */
|
||||
if (ast_set_read_format(chan, AST_FORMAT_ULAW) < 0) {
|
||||
if (ast_set_read_format(chan, AST_FORMAT_ULAW, 1) < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set '%s' to read ulaw mode\n", chan->name);
|
||||
goto outrun;
|
||||
}
|
||||
|
|
|
@ -104,8 +104,8 @@ static int milliwatt_exec(struct ast_channel *chan, void *data)
|
|||
|
||||
struct localuser *u;
|
||||
LOCAL_USER_ADD(u);
|
||||
ast_set_write_format(chan, AST_FORMAT_ULAW);
|
||||
ast_set_read_format(chan, AST_FORMAT_ULAW);
|
||||
ast_set_write_format(chan, AST_FORMAT_ULAW, 1);
|
||||
ast_set_read_format(chan, AST_FORMAT_ULAW, 1);
|
||||
if (chan->_state != AST_STATE_UP)
|
||||
{
|
||||
ast_answer(chan);
|
||||
|
|
|
@ -126,7 +126,7 @@ static int mp3_exec(struct ast_channel *chan, void *data)
|
|||
ast_stopstream(chan);
|
||||
|
||||
owriteformat = chan->writeformat;
|
||||
res = ast_set_write_format(chan, AST_FORMAT_SLINEAR);
|
||||
res = ast_set_write_format(chan, AST_FORMAT_SLINEAR, 1);
|
||||
if (res < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set write format to signed linear\n");
|
||||
return -1;
|
||||
|
@ -190,7 +190,7 @@ static int mp3_exec(struct ast_channel *chan, void *data)
|
|||
if (pid > -1)
|
||||
kill(pid, SIGKILL);
|
||||
if (!res && owriteformat)
|
||||
ast_set_write_format(chan, owriteformat);
|
||||
ast_set_write_format(chan, owriteformat, 1);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -219,8 +219,8 @@ time_t t;
|
|||
channel = ast_request(dialstr,AST_FORMAT_SLINEAR,tele);
|
||||
if (channel)
|
||||
{
|
||||
ast_set_read_format(channel,AST_FORMAT_SLINEAR);
|
||||
ast_set_write_format(channel,AST_FORMAT_SLINEAR);
|
||||
ast_set_read_format(channel,AST_FORMAT_SLINEAR, 1);
|
||||
ast_set_write_format(channel,AST_FORMAT_SLINEAR, 1);
|
||||
#ifdef OURCLID
|
||||
if (channel->callerid)
|
||||
free(channel->callerid);
|
||||
|
|
|
@ -141,7 +141,7 @@ static int record_exec(struct ast_channel *chan, void *data)
|
|||
|
||||
if (silence > 0) {
|
||||
rfmt = chan->readformat;
|
||||
res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
|
||||
res = ast_set_read_format(chan, AST_FORMAT_SLINEAR, 1);
|
||||
if (res < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");
|
||||
return -1;
|
||||
|
@ -223,7 +223,7 @@ static int record_exec(struct ast_channel *chan, void *data)
|
|||
|
||||
LOCAL_USER_REMOVE(u);
|
||||
if (silence > 0) {
|
||||
res = ast_set_read_format(chan, rfmt);
|
||||
res = ast_set_read_format(chan, rfmt, 1);
|
||||
if (res)
|
||||
ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", chan->name);
|
||||
if (sildet)
|
||||
|
|
|
@ -1028,7 +1028,7 @@ static int play_and_prepend(struct ast_channel *chan, char *playfile, char *reco
|
|||
|
||||
if (maxsilence > 0) {
|
||||
rfmt = chan->readformat;
|
||||
res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
|
||||
res = ast_set_read_format(chan, AST_FORMAT_SLINEAR, 1);
|
||||
if (res < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");
|
||||
return -1;
|
||||
|
@ -1161,7 +1161,7 @@ static int play_and_prepend(struct ast_channel *chan, char *playfile, char *reco
|
|||
}
|
||||
}
|
||||
if (rfmt) {
|
||||
if (ast_set_read_format(chan, rfmt)) {
|
||||
if (ast_set_read_format(chan, rfmt, 1)) {
|
||||
ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", ast_getformatname(rfmt), chan->name);
|
||||
}
|
||||
}
|
||||
|
@ -1239,7 +1239,7 @@ static int play_and_record(struct ast_channel *chan, char *playfile, char *recor
|
|||
|
||||
if (maxsilence > 0) {
|
||||
rfmt = chan->readformat;
|
||||
res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
|
||||
res = ast_set_read_format(chan, AST_FORMAT_SLINEAR, 1);
|
||||
if (res < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");
|
||||
return -1;
|
||||
|
@ -1344,7 +1344,7 @@ static int play_and_record(struct ast_channel *chan, char *playfile, char *recor
|
|||
ast_closestream(others[x]);
|
||||
}
|
||||
if (rfmt) {
|
||||
if (ast_set_read_format(chan, rfmt)) {
|
||||
if (ast_set_read_format(chan, rfmt, 1)) {
|
||||
ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", ast_getformatname(rfmt), chan->name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,13 +93,13 @@ static int conf_run(struct ast_channel *chan, int confno, int confflags)
|
|||
char *buf = __buf + AST_FRIENDLY_OFFSET;
|
||||
|
||||
/* Set it into U-law mode (write) */
|
||||
if (ast_set_write_format(chan, AST_FORMAT_ULAW) < 0) {
|
||||
if (ast_set_write_format(chan, AST_FORMAT_ULAW, 1) < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set '%s' to write ulaw mode\n", chan->name);
|
||||
goto outrun;
|
||||
}
|
||||
|
||||
/* Set it into U-law mode (read) */
|
||||
if (ast_set_read_format(chan, AST_FORMAT_ULAW) < 0) {
|
||||
if (ast_set_read_format(chan, AST_FORMAT_ULAW, 1) < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set '%s' to read ulaw mode\n", chan->name);
|
||||
goto outrun;
|
||||
}
|
||||
|
|
|
@ -93,13 +93,13 @@ static int conf_run(struct ast_channel *chan, int confno, int confflags)
|
|||
char *buf = __buf + AST_FRIENDLY_OFFSET;
|
||||
|
||||
/* Set it into U-law mode (write) */
|
||||
if (ast_set_write_format(chan, AST_FORMAT_ULAW) < 0) {
|
||||
if (ast_set_write_format(chan, AST_FORMAT_ULAW, 1) < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set '%s' to write ulaw mode\n", chan->name);
|
||||
goto outrun;
|
||||
}
|
||||
|
||||
/* Set it into U-law mode (read) */
|
||||
if (ast_set_read_format(chan, AST_FORMAT_ULAW) < 0) {
|
||||
if (ast_set_read_format(chan, AST_FORMAT_ULAW, 1) < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set '%s' to read ulaw mode\n", chan->name);
|
||||
goto outrun;
|
||||
}
|
||||
|
|
31
channel.c
31
channel.c
|
@ -1499,12 +1499,13 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr)
|
|||
return res;
|
||||
}
|
||||
|
||||
int ast_set_write_format(struct ast_channel *chan, int fmts)
|
||||
int ast_set_write_format(struct ast_channel *chan, int fmts, int needlock)
|
||||
{
|
||||
int fmt;
|
||||
int native;
|
||||
int res;
|
||||
|
||||
ast_mutex_lock(&chan->lock);
|
||||
native = chan->nativeformats;
|
||||
fmt = fmts;
|
||||
|
||||
|
@ -1512,6 +1513,7 @@ int ast_set_write_format(struct ast_channel *chan, int fmts)
|
|||
if (res < 0) {
|
||||
ast_log(LOG_NOTICE, "Unable to find a path from %s to %s\n",
|
||||
ast_getformatname(fmts), ast_getformatname(chan->nativeformats));
|
||||
ast_mutex_unlock(&chan->lock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1526,15 +1528,18 @@ int ast_set_write_format(struct ast_channel *chan, int fmts)
|
|||
chan->pvt->writetrans = ast_translator_build_path(chan->pvt->rawwriteformat, chan->writeformat);
|
||||
if (option_debug)
|
||||
ast_log(LOG_DEBUG, "Set channel %s to write format %s\n", chan->name, ast_getformatname(chan->writeformat));
|
||||
ast_mutex_unlock(&chan->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ast_set_read_format(struct ast_channel *chan, int fmts)
|
||||
int ast_set_read_format(struct ast_channel *chan, int fmts, int needlock)
|
||||
{
|
||||
int fmt;
|
||||
int native;
|
||||
int res;
|
||||
|
||||
if (needlock)
|
||||
ast_mutex_lock(&chan->lock);
|
||||
native = chan->nativeformats;
|
||||
fmt = fmts;
|
||||
/* Find a translation path from the native read format to one of the user's read formats */
|
||||
|
@ -1542,6 +1547,7 @@ int ast_set_read_format(struct ast_channel *chan, int fmts)
|
|||
if (res < 0) {
|
||||
ast_log(LOG_NOTICE, "Unable to find a path from %s to %s\n",
|
||||
ast_getformatname(chan->nativeformats), ast_getformatname(fmts));
|
||||
ast_mutex_unlock(&chan->lock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1557,6 +1563,7 @@ int ast_set_read_format(struct ast_channel *chan, int fmts)
|
|||
if (option_debug)
|
||||
ast_log(LOG_DEBUG, "Set channel %s to read format %s\n",
|
||||
chan->name, ast_getformatname(chan->readformat));
|
||||
ast_mutex_unlock(&chan->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1913,21 +1920,25 @@ int ast_channel_make_compatible(struct ast_channel *chan, struct ast_channel *pe
|
|||
int peerf;
|
||||
int chanf;
|
||||
int res;
|
||||
ast_mutex_lock(&peer->lock);
|
||||
peerf = peer->nativeformats;
|
||||
ast_mutex_unlock(&peer->lock);
|
||||
ast_mutex_lock(&chan->lock);
|
||||
chanf = chan->nativeformats;
|
||||
ast_mutex_unlock(&chan->lock);
|
||||
res = ast_translator_best_choice(&peerf, &chanf);
|
||||
if (res < 0) {
|
||||
ast_log(LOG_WARNING, "No path to translate from %s(%d) to %s(%d)\n", chan->name, chan->nativeformats, peer->name, peer->nativeformats);
|
||||
return -1;
|
||||
}
|
||||
/* Set read format on channel */
|
||||
res = ast_set_read_format(chan, peerf);
|
||||
res = ast_set_read_format(chan, peerf, 1);
|
||||
if (res < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", chan->name, chanf);
|
||||
return -1;
|
||||
}
|
||||
/* Set write format on peer channel */
|
||||
res = ast_set_write_format(peer, peerf);
|
||||
res = ast_set_write_format(peer, peerf, 1);
|
||||
if (res < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", peer->name, peerf);
|
||||
return -1;
|
||||
|
@ -1941,13 +1952,13 @@ int ast_channel_make_compatible(struct ast_channel *chan, struct ast_channel *pe
|
|||
return -1;
|
||||
}
|
||||
/* Set writeformat on channel */
|
||||
res = ast_set_write_format(chan, chanf);
|
||||
res = ast_set_write_format(chan, chanf, 1);
|
||||
if (res < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", chan->name, chanf);
|
||||
return -1;
|
||||
}
|
||||
/* Set read format on peer channel */
|
||||
res = ast_set_read_format(peer, chanf);
|
||||
res = ast_set_read_format(peer, chanf, 1);
|
||||
if (res < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", peer->name, peerf);
|
||||
return -1;
|
||||
|
@ -2154,10 +2165,10 @@ int ast_do_masquerade(struct ast_channel *original, int needlock)
|
|||
/* pvt switches. pbx stays the same, as does next */
|
||||
|
||||
/* Set the write format */
|
||||
ast_set_write_format(original, wformat);
|
||||
ast_set_write_format(original, wformat, 0);
|
||||
|
||||
/* Set the read format */
|
||||
ast_set_read_format(original, rformat);
|
||||
ast_set_read_format(original, rformat, 0);
|
||||
|
||||
ast_log(LOG_DEBUG, "Putting channel %s in %d/%d formats\n", original->name, wformat, rformat);
|
||||
|
||||
|
@ -2453,7 +2464,7 @@ static void tonepair_release(struct ast_channel *chan, void *params)
|
|||
{
|
||||
struct tonepair_state *ts = params;
|
||||
if (chan) {
|
||||
ast_set_write_format(chan, ts->origwfmt);
|
||||
ast_set_write_format(chan, ts->origwfmt, 0);
|
||||
}
|
||||
free(ts);
|
||||
}
|
||||
|
@ -2467,7 +2478,7 @@ static void * tonepair_alloc(struct ast_channel *chan, void *params)
|
|||
return NULL;
|
||||
memset(ts, 0, sizeof(struct tonepair_state));
|
||||
ts->origwfmt = chan->writeformat;
|
||||
if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
|
||||
if (ast_set_write_format(chan, AST_FORMAT_SLINEAR, 1)) {
|
||||
ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", chan->name);
|
||||
tonepair_release(NULL, ts);
|
||||
ts = NULL;
|
||||
|
|
|
@ -137,13 +137,13 @@ static struct agent_pvt {
|
|||
/* Native formats changed, reset things */ \
|
||||
ast->nativeformats = p->chan->nativeformats; \
|
||||
ast_log(LOG_DEBUG, "Resetting read to %d and write to %d\n", ast->readformat, ast->writeformat);\
|
||||
ast_set_read_format(ast, ast->readformat); \
|
||||
ast_set_write_format(ast, ast->writeformat); \
|
||||
ast_set_read_format(ast, ast->readformat, 0); \
|
||||
ast_set_write_format(ast, ast->writeformat, 0); \
|
||||
} \
|
||||
if (p->chan->readformat != ast->pvt->rawreadformat) \
|
||||
ast_set_read_format(p->chan, ast->pvt->rawreadformat); \
|
||||
ast_set_read_format(p->chan, ast->pvt->rawreadformat, 0); \
|
||||
if (p->chan->writeformat != ast->pvt->rawwriteformat) \
|
||||
ast_set_write_format(p->chan, ast->pvt->rawwriteformat); \
|
||||
ast_set_write_format(p->chan, ast->pvt->rawwriteformat, 0); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
@ -464,7 +464,7 @@ static int agent_call(struct ast_channel *ast, char *dest, int timeout)
|
|||
ast_log( LOG_DEBUG, "Waited for stream, result '%d'\n", res);
|
||||
}
|
||||
if (!res) {
|
||||
res = ast_set_read_format(p->chan, ast_best_codec(p->chan->nativeformats));
|
||||
res = ast_set_read_format(p->chan, ast_best_codec(p->chan->nativeformats), 0);
|
||||
ast_log( LOG_DEBUG, "Set read format, result '%d'\n", res);
|
||||
if (res)
|
||||
ast_log(LOG_WARNING, "Unable to set read format to %s\n", ast_getformatname(ast_best_codec(p->chan->nativeformats)));
|
||||
|
@ -474,7 +474,7 @@ static int agent_call(struct ast_channel *ast, char *dest, int timeout)
|
|||
}
|
||||
|
||||
if (!res) {
|
||||
ast_set_write_format(p->chan, ast_best_codec(p->chan->nativeformats));
|
||||
ast_set_write_format(p->chan, ast_best_codec(p->chan->nativeformats), 0);
|
||||
ast_log( LOG_DEBUG, "Set write format, result '%d'\n", res);
|
||||
if (res)
|
||||
ast_log(LOG_WARNING, "Unable to set write format to %s\n", ast_getformatname(ast_best_codec(p->chan->nativeformats)));
|
||||
|
@ -1261,12 +1261,12 @@ static int __login_exec(struct ast_channel *chan, void *data, int callbackmode)
|
|||
ast_mutex_lock(&agentlock);
|
||||
ast_mutex_lock(&p->lock);
|
||||
if (!res) {
|
||||
res = ast_set_read_format(chan, ast_best_codec(chan->nativeformats));
|
||||
res = ast_set_read_format(chan, ast_best_codec(chan->nativeformats), 0);
|
||||
if (res)
|
||||
ast_log(LOG_WARNING, "Unable to set read format to %d\n", ast_best_codec(chan->nativeformats));
|
||||
}
|
||||
if (!res) {
|
||||
ast_set_write_format(chan, ast_best_codec(chan->nativeformats));
|
||||
ast_set_write_format(chan, ast_best_codec(chan->nativeformats), 0);
|
||||
if (res)
|
||||
ast_log(LOG_WARNING, "Unable to set write format to %d\n", ast_best_codec(chan->nativeformats));
|
||||
}
|
||||
|
|
|
@ -4725,7 +4725,7 @@ retryowner:
|
|||
orignative = iaxs[fr.callno]->owner->nativeformats;
|
||||
iaxs[fr.callno]->owner->nativeformats = f.subclass;
|
||||
if (iaxs[fr.callno]->owner->readformat)
|
||||
ast_set_read_format(iaxs[fr.callno]->owner, iaxs[fr.callno]->owner->readformat);
|
||||
ast_set_read_format(iaxs[fr.callno]->owner, iaxs[fr.callno]->owner->readformat, 0);
|
||||
iaxs[fr.callno]->owner->nativeformats = orignative;
|
||||
ast_mutex_unlock(&iaxs[fr.callno]->owner->lock);
|
||||
}
|
||||
|
@ -4962,9 +4962,9 @@ retryowner2:
|
|||
if (iaxs[fr.callno] && iaxs[fr.callno]->owner) {
|
||||
/* Setup read/write formats properly. */
|
||||
if (iaxs[fr.callno]->owner->writeformat)
|
||||
ast_set_write_format(iaxs[fr.callno]->owner, iaxs[fr.callno]->owner->writeformat);
|
||||
ast_set_write_format(iaxs[fr.callno]->owner, iaxs[fr.callno]->owner->writeformat, 0);
|
||||
if (iaxs[fr.callno]->owner->readformat)
|
||||
ast_set_read_format(iaxs[fr.callno]->owner, iaxs[fr.callno]->owner->readformat);
|
||||
ast_set_read_format(iaxs[fr.callno]->owner, iaxs[fr.callno]->owner->readformat, 0);
|
||||
ast_mutex_unlock(&iaxs[fr.callno]->owner->lock);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1015,8 +1015,8 @@ static struct ast_frame *mgcp_rtp_read(struct mgcp_subchannel *sub)
|
|||
if (f->subclass != sub->owner->nativeformats) {
|
||||
ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass);
|
||||
sub->owner->nativeformats = f->subclass;
|
||||
ast_set_read_format(sub->owner, sub->owner->readformat);
|
||||
ast_set_write_format(sub->owner, sub->owner->writeformat);
|
||||
ast_set_read_format(sub->owner, sub->owner->readformat, 0);
|
||||
ast_set_write_format(sub->owner, sub->owner->writeformat, 0);
|
||||
}
|
||||
/* Courtesy fearnor aka alex@pilosoft.com */
|
||||
if (sub->parent->dtmfinband) {
|
||||
|
|
|
@ -1675,8 +1675,8 @@ static struct ast_frame *sip_rtp_read(struct ast_channel *ast, struct sip_pvt *p
|
|||
if (f->subclass != p->owner->nativeformats) {
|
||||
ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass);
|
||||
p->owner->nativeformats = f->subclass;
|
||||
ast_set_read_format(p->owner, p->owner->readformat);
|
||||
ast_set_write_format(p->owner, p->owner->writeformat);
|
||||
ast_set_read_format(p->owner, p->owner->readformat, 0);
|
||||
ast_set_write_format(p->owner, p->owner->writeformat, 0);
|
||||
}
|
||||
if (p->dtmfmode & SIP_DTMF_INBAND) {
|
||||
f = ast_dsp_process(p->owner,p->vad,f,0);
|
||||
|
@ -2132,8 +2132,8 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req)
|
|||
if (!(p->owner->nativeformats & p->jointcapability)) {
|
||||
ast_log(LOG_DEBUG, "Oooh, we need to change our formats since our peer supports only %d and not %d\n", p->jointcapability, p->owner->nativeformats);
|
||||
p->owner->nativeformats = sip_codec_choose(p->jointcapability);
|
||||
ast_set_read_format(p->owner, p->owner->readformat);
|
||||
ast_set_write_format(p->owner, p->owner->writeformat);
|
||||
ast_set_read_format(p->owner, p->owner->readformat, 0);
|
||||
ast_set_write_format(p->owner, p->owner->writeformat, 0);
|
||||
}
|
||||
if (p->owner->bridge) {
|
||||
/* Turn on/off music on hold if we are holding/unholding */
|
||||
|
|
|
@ -1602,8 +1602,8 @@ static struct ast_frame *skinny_rtp_read(struct skinny_subchannel *sub)
|
|||
if (f->subclass != sub->owner->nativeformats) {
|
||||
ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass);
|
||||
sub->owner->nativeformats = f->subclass;
|
||||
ast_set_read_format(sub->owner, sub->owner->readformat);
|
||||
ast_set_write_format(sub->owner, sub->owner->writeformat);
|
||||
ast_set_read_format(sub->owner, sub->owner->readformat, 0);
|
||||
ast_set_write_format(sub->owner, sub->owner->writeformat, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
4
file.c
4
file.c
|
@ -166,7 +166,7 @@ int ast_stopstream(struct ast_channel *tmp)
|
|||
ast_closestream(tmp->vstream);
|
||||
if (tmp->stream) {
|
||||
ast_closestream(tmp->stream);
|
||||
if (tmp->oldwriteformat && ast_set_write_format(tmp, tmp->oldwriteformat))
|
||||
if (tmp->oldwriteformat && ast_set_write_format(tmp, tmp->oldwriteformat, 1))
|
||||
ast_log(LOG_WARNING, "Unable to restore format back to %d\n", tmp->oldwriteformat);
|
||||
}
|
||||
return 0;
|
||||
|
@ -464,7 +464,7 @@ struct ast_filestream *ast_openstream(struct ast_channel *chan, char *filename,
|
|||
}
|
||||
chan->oldwriteformat = chan->writeformat;
|
||||
/* Set the channel to a format we can work with */
|
||||
res = ast_set_write_format(chan, fmts);
|
||||
res = ast_set_write_format(chan, fmts, 1);
|
||||
|
||||
fd = ast_filehelper(filename2, (char *)chan, NULL, ACTION_OPEN);
|
||||
if(fd >= 0)
|
||||
|
|
|
@ -572,7 +572,7 @@ int ast_prod(struct ast_channel *chan);
|
|||
* Set read format for channel to whichever component of "format" is best.
|
||||
* Returns 0 on success, -1 on failure
|
||||
*/
|
||||
int ast_set_read_format(struct ast_channel *chan, int format);
|
||||
int ast_set_read_format(struct ast_channel *chan, int format, int needlock);
|
||||
|
||||
//! Sets write format on channel chan
|
||||
/*!
|
||||
|
@ -581,7 +581,7 @@ int ast_set_read_format(struct ast_channel *chan, int format);
|
|||
* Set write format for channel to whichever compoent of "format" is best.
|
||||
* Returns 0 on success, -1 on failure
|
||||
*/
|
||||
int ast_set_write_format(struct ast_channel *chan, int format);
|
||||
int ast_set_write_format(struct ast_channel *chan, int format, int needlock);
|
||||
|
||||
//! Sends text to a channel
|
||||
/*!
|
||||
|
|
|
@ -58,7 +58,7 @@ static void playtones_release(struct ast_channel *chan, void *params)
|
|||
{
|
||||
struct playtones_state *ps = params;
|
||||
if (chan) {
|
||||
ast_set_write_format(chan, ps->origwfmt);
|
||||
ast_set_write_format(chan, ps->origwfmt, 0);
|
||||
}
|
||||
if (ps->items) free(ps->items);
|
||||
free(ps);
|
||||
|
@ -72,7 +72,7 @@ static void * playtones_alloc(struct ast_channel *chan, void *params)
|
|||
return NULL;
|
||||
memset(ps, 0, sizeof(struct playtones_state));
|
||||
ps->origwfmt = chan->writeformat;
|
||||
if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
|
||||
if (ast_set_write_format(chan, AST_FORMAT_SLINEAR, 1)) {
|
||||
ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", chan->name);
|
||||
playtones_release(NULL, ps);
|
||||
ps = NULL;
|
||||
|
|
|
@ -367,15 +367,15 @@ int adsi_transmit_message(struct ast_channel *chan, unsigned char *msg, int msgl
|
|||
|
||||
ast_stopstream(chan);
|
||||
|
||||
if (ast_set_write_format(chan, AST_FORMAT_ULAW)) {
|
||||
if (ast_set_write_format(chan, AST_FORMAT_ULAW, 1)) {
|
||||
ast_log(LOG_WARNING, "Unable to set write format to ULAW\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ast_set_read_format(chan, AST_FORMAT_ULAW)) {
|
||||
if (ast_set_read_format(chan, AST_FORMAT_ULAW, 1)) {
|
||||
ast_log(LOG_WARNING, "Unable to set read format to ULAW\n");
|
||||
if (writeformat) {
|
||||
if (ast_set_write_format(chan, writeformat))
|
||||
if (ast_set_write_format(chan, writeformat, 1))
|
||||
ast_log(LOG_WARNING, "Unable to restore write format to %d\n", writeformat);
|
||||
}
|
||||
return -1;
|
||||
|
@ -385,9 +385,9 @@ int adsi_transmit_message(struct ast_channel *chan, unsigned char *msg, int msgl
|
|||
chan->adsicpe = (chan->adsicpe & ~ADSI_FLAG_DATAMODE) | newdatamode;
|
||||
|
||||
if (writeformat)
|
||||
ast_set_write_format(chan, writeformat);
|
||||
ast_set_write_format(chan, writeformat, 1);
|
||||
if (readformat)
|
||||
ast_set_read_format(chan, readformat);
|
||||
ast_set_read_format(chan, readformat, 1);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -397,7 +397,7 @@ static void moh_release(struct ast_channel *chan, void *data)
|
|||
oldwfmt = moh->origwfmt;
|
||||
free(moh);
|
||||
if (chan) {
|
||||
if (oldwfmt && ast_set_write_format(chan, oldwfmt))
|
||||
if (oldwfmt && ast_set_write_format(chan, oldwfmt, 0))
|
||||
ast_log(LOG_WARNING, "Unable to restore channel '%s' to format %s\n", chan->name, ast_getformatname(oldwfmt));
|
||||
if (option_verbose > 2)
|
||||
ast_verbose(VERBOSE_PREFIX_3 "Stopped music on hold on %s\n", chan->name);
|
||||
|
@ -420,7 +420,7 @@ static void *moh_alloc(struct ast_channel *chan, void *params)
|
|||
ast_mutex_unlock(&moh_lock);
|
||||
if (res) {
|
||||
res->origwfmt = chan->writeformat;
|
||||
if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
|
||||
if (ast_set_write_format(chan, AST_FORMAT_SLINEAR, 1)) {
|
||||
ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format\n", chan->name);
|
||||
moh_release(NULL, res);
|
||||
res = NULL;
|
||||
|
|
Reference in New Issue