[Asterisk-code-review] format g726: add support for seeking (asterisk[13])
Eyal Hasson
asteriskteam at digium.com
Tue Jan 22 12:06:28 CST 2019
Eyal Hasson has uploaded this change for review. ( https://gerrit.asterisk.org/10907
Change subject: format_g726: add support for seeking
......................................................................
format_g726: add support for seeking
Added support for the seek function in format_g726
so playback can start from anywhere.
Before the fix, palyback of g726 files
always started from the beginning.
ASTERISK-28246
Change-Id: I626235bc4642df1479050d3d06828412603a9b40
---
M formats/format_g726.c
1 file changed, 36 insertions(+), 2 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/07/10907/1
diff --git a/formats/format_g726.c b/formats/format_g726.c
index 8379925..01b68df 100644
--- a/formats/format_g726.c
+++ b/formats/format_g726.c
@@ -157,7 +157,39 @@
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 +199,9 @@
static off_t g726_tell(struct ast_filestream *fs)
{
- return -1;
+ off_t offset;
+ offset = ftello(fs->f) << 1;
+ return offset;
}
static struct ast_format_def f[] = {
--
To view, visit https://gerrit.asterisk.org/10907
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: I626235bc4642df1479050d3d06828412603a9b40
Gerrit-Change-Number: 10907
Gerrit-PatchSet: 1
Gerrit-Owner: Eyal Hasson <eyal at kolhl.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190122/cf897c41/attachment.html>
More information about the asterisk-code-review
mailing list