aboutsummaryrefslogtreecommitdiffstats
path: root/formats
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2008-03-07 00:24:58 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2008-03-07 00:24:58 +0000
commit5ffedddec1865ff45cede194076c3ff69b3f53ab (patch)
treed3cc4eb0d3575328fd5fb7eb2fdb1743f78fadb2 /formats
parente2787803841f33a7dff2dfbc98b79dcbd058a551 (diff)
Merge changes from team/russell/g722-sillyness ...
Fix a number of other places where the number of samples in a G722 frame was not properly handled because of various reasons. main/rtp.c: - When a G722 frame is read from the smoother, the number of samples in the frame must be divided by 2 before being sent out over the network. Even though G722 is 16 kHz, an error in some previous spec has made it so that we have to list the number of samples such as if it was 8 kHz. main/file.c: - When scheduling the next time to expect a frame, take into account that the format of the file we're reading from may not be 8 kHz. codecs/codec_g722.c: - When converting from G722 to slinear, g722_decode() expects its samples parameter to be in the silly (real samples / 2) format. Make it so. - When converting from slinear to G722, properly set the number of samples in the frame to be the number of bytes of output * 2. formats/format_pcm.c: - This format module handles G722, among a number of other formats. However, the read() and seek() functions did not account for the fact that G722 has 2 samples per byte. (closes issue #12130, reported by rickross, patched by me) git-svn-id: http://svn.digium.com/svn/asterisk/trunk@106501 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'formats')
-rw-r--r--formats/format_pcm.c27
1 files changed, 19 insertions, 8 deletions
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);
}