diff options
author | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-03-05 18:36:31 +0000 |
---|---|---|
committer | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-03-05 18:36:31 +0000 |
commit | aada5c97a114d2e377532b205fb24f7e1052236c (patch) | |
tree | 7aec9f702b437d5de11667be63d0407ab7417dad /main/rtp.c | |
parent | 8a6eca9fc0d411cb79812ebb0b3c343b94e3495c (diff) |
Merged revisions 180373 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
................
r180373 | kpfleming | 2009-03-05 12:29:38 -0600 (Thu, 05 Mar 2009) | 15 lines
Merged revisions 180372 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r180372 | kpfleming | 2009-03-05 12:22:16 -0600 (Thu, 05 Mar 2009) | 9 lines
Fix problems when RTP packet frame size is changed
During some code analysis, I found that calling ast_rtp_codec_setpref() on an ast_rtp session does not work as expected; it does not adjust the smoother that may on the RTP session, in fact it summarily drops it, even if it has data in it, even if the current format's framing size has not changed. This is not good.
This patch changes this behavior, so that if the packetization size for the current format changes, any existing smoother is safely updated to use the new size, and if no smoother was present, one is created. A new API call for smoothers, ast_smoother_reconfigure(), was required to implement these changes.
Review: http://reviewboard.digium.com/r/184/
........
................
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.0@180377 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/rtp.c')
-rw-r--r-- | main/rtp.c | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/main/rtp.c b/main/rtp.c index 2c647e78b..a63dc282d 100644 --- a/main/rtp.c +++ b/main/rtp.c @@ -3124,14 +3124,48 @@ static int ast_rtp_raw_write(struct ast_rtp *rtp, struct ast_frame *f, int codec void ast_rtp_codec_setpref(struct ast_rtp *rtp, struct ast_codec_pref *prefs) { - int x; - for (x = 0; x < 32; x++) { /* Ugly way */ - rtp->pref.order[x] = prefs->order[x]; - rtp->pref.framing[x] = prefs->framing[x]; + struct ast_format_list current_format_old, current_format_new; + + /* if no packets have been sent through this session yet, then + * changing preferences does not require any extra work + */ + if (rtp->lasttxformat == 0) { + rtp->pref = *prefs; + return; } - if (rtp->smoother) - ast_smoother_free(rtp->smoother); - rtp->smoother = NULL; + + current_format_old = ast_codec_pref_getsize(&rtp->pref, rtp->lasttxformat); + + rtp->pref = *prefs; + + current_format_new = ast_codec_pref_getsize(&rtp->pref, rtp->lasttxformat); + + /* if the framing desired for the current format has changed, we may have to create + * or adjust the smoother for this session + */ + if ((current_format_new.inc_ms != 0) && + (current_format_new.cur_ms != current_format_old.cur_ms)) { + int new_size = (current_format_new.cur_ms * current_format_new.fr_len) / current_format_new.inc_ms; + + if (rtp->smoother) { + ast_smoother_reconfigure(rtp->smoother, new_size); + if (option_debug) { + ast_log(LOG_DEBUG, "Adjusted smoother to %d ms and %d bytes\n", current_format_new.cur_ms, new_size); + } + } else { + if (!(rtp->smoother = ast_smoother_new(new_size))) { + ast_log(LOG_WARNING, "Unable to create smoother: format: %d ms: %d len: %d\n", rtp->lasttxformat, current_format_new.cur_ms, new_size); + return; + } + if (current_format_new.flags) { + ast_smoother_set_flags(rtp->smoother, current_format_new.flags); + } + if (option_debug) { + ast_log(LOG_DEBUG, "Created smoother: format: %d ms: %d len: %d\n", rtp->lasttxformat, current_format_new.cur_ms, new_size); + } + } + } + } struct ast_codec_pref *ast_rtp_codec_getpref(struct ast_rtp *rtp) |