mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-03 03:20:57 +00:00
format_g726: add support for seeking
Added support for the seek function in format_g726 so playback can start from anywhere. Before the fix, playback of g726 files always started from the beginning. ASTERISK-28246 Change-Id: I626235bc4642df1479050d3d06828412603a9b40
This commit is contained in:
@@ -157,7 +157,38 @@ static int g726_write(struct ast_filestream *s, struct ast_frame *f)
|
||||
|
||||
static int g726_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
|
||||
{
|
||||
return -1;
|
||||
off_t offset = 0, min = 0, cur, max, distance;
|
||||
|
||||
if ((cur = ftello(fs->f)) < 0) {
|
||||
ast_log(AST_LOG_WARNING, "Unable to determine current position in g726 filestream %p: %s\n", fs, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fseeko(fs->f, 0, SEEK_END) < 0) {
|
||||
ast_log(AST_LOG_WARNING, "Unable to seek to end of g726 filestream %p: %s\n", fs, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((max = ftello(fs->f)) < 0) {
|
||||
ast_log(AST_LOG_WARNING, "Unable to determine max position in g726 filestream %p: %s\n", fs, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* have to fudge to frame here, so not fully to sample */
|
||||
distance = sample_offset / 2;
|
||||
if (whence == SEEK_SET) {
|
||||
offset = distance;
|
||||
} else if (whence == SEEK_CUR || whence == SEEK_FORCECUR) {
|
||||
offset = distance + cur;
|
||||
} else if (whence == SEEK_END) {
|
||||
offset = max - distance;
|
||||
}
|
||||
|
||||
if (whence != SEEK_FORCECUR) {
|
||||
offset = offset > max ? max : offset;
|
||||
offset = offset < min ? min : offset;
|
||||
}
|
||||
return fseeko(fs->f, offset, SEEK_SET);
|
||||
}
|
||||
|
||||
static int g726_trunc(struct ast_filestream *fs)
|
||||
@@ -167,7 +198,7 @@ static int g726_trunc(struct ast_filestream *fs)
|
||||
|
||||
static off_t g726_tell(struct ast_filestream *fs)
|
||||
{
|
||||
return -1;
|
||||
return ftello(fs->f) << 1;
|
||||
}
|
||||
|
||||
static struct ast_format_def f[] = {
|
||||
|
Reference in New Issue
Block a user