From eeb2ca5b26dfb3d47fa9676f1ef35fff64d3aaeb Mon Sep 17 00:00:00 2001 From: Mark Spencer Date: Sat, 27 Mar 2004 06:50:12 +0000 Subject: Make read/write mode have a lock parameter and use it properly. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2572 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- app.c | 4 ++-- apps/app_agi.c | 8 ++++---- apps/app_disa.c | 4 ++-- apps/app_echo.c | 6 ++++-- apps/app_festival.c | 4 ++-- apps/app_intercom.c | 4 ++-- apps/app_meetme.c | 8 ++++---- apps/app_milliwatt.c | 4 ++-- apps/app_mp3.c | 4 ++-- apps/app_qcall.c | 4 ++-- apps/app_record.c | 4 ++-- apps/app_voicemail.c | 8 ++++---- apps/app_zapbarge.c | 4 ++-- apps/app_zapscan.c | 4 ++-- channel.c | 31 +++++++++++++++++++++---------- channels/chan_agent.c | 16 ++++++++-------- channels/chan_iax2.c | 6 +++--- channels/chan_mgcp.c | 4 ++-- channels/chan_sip.c | 8 ++++---- channels/chan_skinny.c | 4 ++-- file.c | 4 ++-- include/asterisk/channel.h | 4 ++-- indications.c | 4 ++-- res/res_adsi.c | 10 +++++----- res/res_musiconhold.c | 4 ++-- 25 files changed, 89 insertions(+), 76 deletions(-) diff --git a/app.c b/app.c index 4c4cfab8b..32a5f42ee 100755 --- a/app.c +++ b/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); diff --git a/apps/app_agi.c b/apps/app_agi.c index 529fbe2e1..e2cdd0ebc 100755 --- a/apps/app_agi.c +++ b/apps/app_agi.c @@ -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)); } } diff --git a/apps/app_disa.c b/apps/app_disa.c index 26676d4bb..a518cb7e1 100755 --- a/apps/app_disa.c +++ b/apps/app_disa.c @@ -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; diff --git a/apps/app_echo.c b/apps/app_echo.c index 27ba0d86f..7de30008b 100755 --- a/apps/app_echo.c +++ b/apps/app_echo.c @@ -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; diff --git a/apps/app_festival.c b/apps/app_festival.c index 337de43b6..702fdd8e6 100755 --- a/apps/app_festival.c +++ b/apps/app_festival.c @@ -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; } diff --git a/apps/app_intercom.c b/apps/app_intercom.c index 925ea37c2..96219deec 100755 --- a/apps/app_intercom.c +++ b/apps/app_intercom.c @@ -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; } diff --git a/apps/app_meetme.c b/apps/app_meetme.c index b7d488ad0..ad58809b3 100755 --- a/apps/app_meetme.c +++ b/apps/app_meetme.c @@ -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; } diff --git a/apps/app_milliwatt.c b/apps/app_milliwatt.c index 78f0604ce..03c2050a7 100755 --- a/apps/app_milliwatt.c +++ b/apps/app_milliwatt.c @@ -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); diff --git a/apps/app_mp3.c b/apps/app_mp3.c index d050d5896..7f7d31849 100755 --- a/apps/app_mp3.c +++ b/apps/app_mp3.c @@ -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; } diff --git a/apps/app_qcall.c b/apps/app_qcall.c index e876f0ae3..879b1c8ad 100755 --- a/apps/app_qcall.c +++ b/apps/app_qcall.c @@ -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); diff --git a/apps/app_record.c b/apps/app_record.c index 80dd1da89..81a7704e8 100755 --- a/apps/app_record.c +++ b/apps/app_record.c @@ -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) diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index fdf6208d9..5e562e333 100755 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -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); } } diff --git a/apps/app_zapbarge.c b/apps/app_zapbarge.c index 0b865df5b..1c03afc0b 100755 --- a/apps/app_zapbarge.c +++ b/apps/app_zapbarge.c @@ -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; } diff --git a/apps/app_zapscan.c b/apps/app_zapscan.c index b24fe5d57..ef7ac4215 100755 --- a/apps/app_zapscan.c +++ b/apps/app_zapscan.c @@ -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; } diff --git a/channel.c b/channel.c index f5b9fc3d1..4c46e7017 100755 --- a/channel.c +++ b/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; diff --git a/channels/chan_agent.c b/channels/chan_agent.c index e329f5fcb..d47b0a6c4 100755 --- a/channels/chan_agent.c +++ b/channels/chan_agent.c @@ -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)); } diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index c7d866a55..daf52eaf6 100755 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -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); } } diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c index 49b24dba1..375515914 100755 --- a/channels/chan_mgcp.c +++ b/channels/chan_mgcp.c @@ -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) { diff --git a/channels/chan_sip.c b/channels/chan_sip.c index ac7363454..e4abd936a 100755 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -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 */ diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c index cccb8429c..344de37e2 100755 --- a/channels/chan_skinny.c +++ b/channels/chan_skinny.c @@ -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); } } } diff --git a/file.c b/file.c index 9cdaec575..578b1febe 100755 --- a/file.c +++ b/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) diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h index c0cd6cd23..dea3708fa 100755 --- a/include/asterisk/channel.h +++ b/include/asterisk/channel.h @@ -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 /*! diff --git a/indications.c b/indications.c index fefec9153..5a6a8b913 100755 --- a/indications.c +++ b/indications.c @@ -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; diff --git a/res/res_adsi.c b/res/res_adsi.c index c581e7a4f..e23718947 100755 --- a/res/res_adsi.c +++ b/res/res_adsi.c @@ -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; } diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c index d0c1b640d..febdaaa04 100755 --- a/res/res_musiconhold.c +++ b/res/res_musiconhold.c @@ -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; -- cgit v1.2.3