aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--codecs/codec_g722.c8
-rw-r--r--formats/format_pcm.c27
-rw-r--r--main/file.c6
-rw-r--r--main/rtp.c8
4 files changed, 36 insertions, 13 deletions
diff --git a/codecs/codec_g722.c b/codecs/codec_g722.c
index 99c3856bc..7dd2744c3 100644
--- a/codecs/codec_g722.c
+++ b/codecs/codec_g722.c
@@ -102,9 +102,13 @@ static int g722tolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
{
struct g722_decoder_pvt *tmp = pvt->pvt;
int out_samples;
+ int in_samples;
+
+ /* g722_decode expects the samples to be in the invalid samples / 2 format */
+ in_samples = f->samples / 2;
out_samples = g722_decode(&tmp->g722, (int16_t *) &pvt->outbuf[pvt->samples * sizeof(int16_t)],
- (uint8_t *) f->data, f->samples);
+ (uint8_t *) f->data, in_samples);
pvt->samples += out_samples;
@@ -121,7 +125,7 @@ static int lintog722_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
outlen = g722_encode(&tmp->g722, (uint8_t *) (&pvt->outbuf[pvt->datalen]),
(int16_t *) f->data, f->samples);
- pvt->samples += outlen;
+ pvt->samples += outlen * 2;
pvt->datalen += outlen;
diff --git a/formats/format_pcm.c b/formats/format_pcm.c
index c514b5863..118353552 100644
--- a/formats/format_pcm.c
+++ b/formats/format_pcm.c
@@ -89,7 +89,10 @@ static struct ast_frame *pcm_read(struct ast_filestream *s, int *whennext)
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;
}
@@ -367,24 +370,32 @@ static int au_rewrite(struct ast_filestream *s, const char *comment)
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;
- if (whence != SEEK_FORCECUR) {
+ 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);
}
diff --git a/main/file.c b/main/file.c
index fb684755e..1bec4fca4 100644
--- a/main/file.c
+++ b/main/file.c
@@ -669,7 +669,8 @@ static enum fsread_res ast_readaudio_callback(struct ast_filestream *s)
ast_settimeout(s->owner, whennext, 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;
}
@@ -713,7 +714,8 @@ static enum fsread_res ast_readvideo_callback(struct ast_filestream *s)
}
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;
diff --git a/main/rtp.c b/main/rtp.c
index 433fa2c79..c449b8b17 100644
--- a/main/rtp.c
+++ b/main/rtp.c
@@ -3186,8 +3186,14 @@ int ast_rtp_write(struct ast_rtp *rtp, struct ast_frame *_f)
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: */
if (_f->offset < hdrlen)