[asterisk-commits] russell: branch 1.4 r114550 - in /branches/1.4: formats/ main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Apr 22 16:14:56 CDT 2008
Author: russell
Date: Tue Apr 22 16:14:55 2008
New Revision: 114550
URL: http://svn.digium.com/view/asterisk?view=rev&rev=114550
Log:
I thought I was going to be able to leave 1.4 alone, but that was not the case.
I ran into some problems with G.722 in 1.4, so I have merged in all of the fixes
in this area that I have made in trunk/1.6.0, and things are happy again.
Modified:
branches/1.4/formats/format_pcm.c
branches/1.4/main/channel.c
branches/1.4/main/file.c
branches/1.4/main/rtp.c
Modified: branches/1.4/formats/format_pcm.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/formats/format_pcm.c?view=diff&rev=114550&r1=114549&r2=114550
==============================================================================
--- branches/1.4/formats/format_pcm.c (original)
+++ branches/1.4/formats/format_pcm.c Tue Apr 22 16:14:55 2008
@@ -102,7 +102,10 @@
return NULL;
}
s->fr.datalen = res;
- *whennext = s->fr.samples = res;
+ if (s->fmt->format == AST_FORMAT_G722)
+ *whennext = s->fr.samples = res * 2;
+ else
+ *whennext = s->fr.samples = res;
return &s->fr;
}
@@ -380,24 +383,31 @@
static int au_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{
off_t min, max, cur;
- long offset = 0, samples;
-
- samples = sample_offset;
+ long offset = 0, bytes;
+
+ if (fs->fmt->format == AST_FORMAT_G722)
+ bytes = sample_offset / 2;
+ else
+ bytes = sample_offset;
+
min = AU_HEADER_SIZE;
cur = ftello(fs->f);
fseek(fs->f, 0, SEEK_END);
max = ftello(fs->f);
+
if (whence == SEEK_SET)
- offset = samples + min;
+ offset = bytes + min;
else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
- offset = samples + cur;
+ offset = bytes + cur;
else if (whence == SEEK_END)
- offset = max - samples;
+ offset = max - bytes;
if (whence != SEEK_FORCECUR) {
offset = (offset > max) ? max : offset;
}
+
/* always protect the header space. */
offset = (offset < min) ? min : offset;
+
return fseeko(fs->f, offset, SEEK_SET);
}
Modified: branches/1.4/main/channel.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/channel.c?view=diff&rev=114550&r1=114549&r2=114550
==============================================================================
--- branches/1.4/main/channel.c (original)
+++ branches/1.4/main/channel.c Tue Apr 22 16:14:55 2008
@@ -1573,7 +1573,7 @@
if (!tmp || !generate)
return 0;
- res = generate(chan, tmp, 0, 160);
+ res = generate(chan, tmp, 0, ast_format_rate(chan->writeformat & AST_FORMAT_AUDIO_MASK) / 50);
chan->generatordata = tmp;
@@ -1889,6 +1889,7 @@
void *tmp = chan->generatordata;
int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples) = NULL;
int res;
+ int samples;
if (chan->timingfunc) {
if (option_debug > 1)
@@ -1897,6 +1898,15 @@
}
chan->generatordata = NULL; /* reset, to let writes go through */
+
+ if (f->subclass != chan->writeformat) {
+ float factor;
+ factor = ((float) ast_format_rate(chan->writeformat)) / ((float) ast_format_rate(f->subclass));
+ samples = (int) ( ((float) f->samples) * factor );
+ } else {
+ samples = f->samples;
+ }
+
if (chan->generator->generate) {
generate = chan->generator->generate;
}
@@ -1909,7 +1919,7 @@
* avoidance not to work in deeper functions
*/
ast_channel_unlock(chan);
- res = generate(chan, tmp, f->datalen, f->samples);
+ res = generate(chan, tmp, f->datalen, samples);
ast_channel_lock(chan);
chan->generatordata = tmp;
if (res) {
Modified: branches/1.4/main/file.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/file.c?view=diff&rev=114550&r1=114549&r2=114550
==============================================================================
--- branches/1.4/main/file.c (original)
+++ branches/1.4/main/file.c Tue Apr 22 16:14:55 2008
@@ -680,11 +680,21 @@
}
if (whennext != s->lasttimeout) {
#ifdef HAVE_ZAPTEL
- if (s->owner->timingfd > -1)
- ast_settimeout(s->owner, whennext, ast_fsread_audio, s);
- else
+ if (s->owner->timingfd > -1) {
+ int zap_timer_samples = whennext;
+ int rate;
+ /* whennext is in samples, but zaptel timers operate in 8 kHz samples. */
+ if ((rate = ast_format_rate(s->fmt->format)) != 8000) {
+ float factor;
+ factor = ((float) rate) / ((float) 8000.0);
+ zap_timer_samples = (int) ( ((float) zap_timer_samples) / factor );
+ }
+ ast_settimeout(s->owner, zap_timer_samples, ast_fsread_audio, s);
+ } else
#endif
- s->owner->streamid = ast_sched_add(s->owner->sched, whennext/8, ast_fsread_audio, s);
+ s->owner->streamid = ast_sched_add(s->owner->sched,
+ whennext / (ast_format_rate(s->fmt->format) / 1000),
+ ast_fsread_audio, s);
s->lasttimeout = whennext;
return FSREAD_SUCCESS_NOSCHED;
}
@@ -728,7 +738,8 @@
}
if (whennext != s->lasttimeout) {
- s->owner->vstreamid = ast_sched_add(s->owner->sched, whennext / 8,
+ s->owner->vstreamid = ast_sched_add(s->owner->sched,
+ whennext / (ast_format_rate(s->fmt->format) / 1000),
ast_fsread_video, s);
s->lasttimeout = whennext;
return FSREAD_SUCCESS_NOSCHED;
Modified: branches/1.4/main/rtp.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/rtp.c?view=diff&rev=114550&r1=114549&r2=114550
==============================================================================
--- branches/1.4/main/rtp.c (original)
+++ branches/1.4/main/rtp.c Tue Apr 22 16:14:55 2008
@@ -1313,7 +1313,7 @@
/* Add timing data to let ast_generic_bridge() put the frame into a jitterbuf */
ast_set_flag(&rtp->f, AST_FRFLAG_HAS_TIMING_INFO);
rtp->f.ts = timestamp / 8;
- rtp->f.len = rtp->f.samples / ( (ast_format_rate(rtp->f.subclass) == 16000) ? 16 : 8 );
+ rtp->f.len = rtp->f.samples / (ast_format_rate(rtp->f.subclass) / 1000);
} else {
/* Video -- samples is # of samples vs. 90000 */
if (!rtp->lastividtimestamp)
@@ -2795,17 +2795,28 @@
ast_smoother_feed(rtp->smoother, _f);
}
- while((f = ast_smoother_read(rtp->smoother)) && (f->data))
+ while ((f = ast_smoother_read(rtp->smoother)) && (f->data)) {
+ if (f->subclass == AST_FORMAT_G722) {
+ /* G.722 is silllllllllllllly */
+ f->samples /= 2;
+ }
+
ast_rtp_raw_write(rtp, f, codec);
+ }
} else {
- /* Don't buffer outgoing frames; send them one-per-packet: */
+ /* Don't buffer outgoing frames; send them one-per-packet: */
if (_f->offset < hdrlen) {
f = ast_frdup(_f);
} else {
f = _f;
}
- if (f->data)
+ if (f->data) {
+ if (f->subclass == AST_FORMAT_G722) {
+ /* G.722 is silllllllllllllly */
+ f->samples /= 2;
+ }
ast_rtp_raw_write(rtp, f, codec);
+ }
if (f != _f)
ast_frfree(f);
}
More information about the asterisk-commits
mailing list