<p>Sean Bright has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/8815">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">format_pcm: Correct behavior of fseek and ftell for G.722<br><br>There are twice as many samples in the same number of bytes, so redefine<br>some of the G.722 format functions in terms of their PCM counterparts.<br><br>Change-Id: I6a8c7352624b930a5f2d9e4857f75283fa5dd9f9<br>---<br>M formats/format_pcm.c<br>1 file changed, 25 insertions(+), 16 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/15/8815/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/formats/format_pcm.c b/formats/format_pcm.c<br>index 8710370..e4021b2 100644<br>--- a/formats/format_pcm.c<br>+++ b/formats/format_pcm.c<br>@@ -93,10 +93,7 @@<br> return NULL;<br> }<br> s->fr.datalen = res;<br>- if (ast_format_cmp(s->fmt->format, ast_format_g722) == AST_FORMAT_CMP_EQUAL)<br>- *whennext = s->fr.samples = res * 2;<br>- else<br>- *whennext = s->fr.samples = res;<br>+ *whennext = s->fr.samples = res;<br> return &s->fr;<br> }<br> <br>@@ -412,15 +409,10 @@<br> static int au_seek(struct ast_filestream *fs, off_t sample_offset, int whence)<br> {<br> off_t min, max, cur;<br>- long offset = 0, bytes;<br>+ long offset = 0;<br> struct au_desc *desc = fs->_private;<br> <br> min = desc->hdr_size;<br>-<br>- if (ast_format_cmp(fs->fmt->format, ast_format_g722) == AST_FORMAT_CMP_EQUAL)<br>- bytes = sample_offset / 2;<br>- else<br>- bytes = sample_offset;<br> <br> if ((cur = ftello(fs->f)) < 0) {<br> ast_log(AST_LOG_WARNING, "Unable to determine current position in au filestream %p: %s\n", fs, strerror(errno));<br>@@ -438,11 +430,11 @@<br> }<br> <br> if (whence == SEEK_SET)<br>- offset = bytes + min;<br>+ offset = sample_offset + min;<br> else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)<br>- offset = bytes + cur;<br>+ offset = sample_offset + cur;<br> else if (whence == SEEK_END)<br>- offset = max - bytes;<br>+ offset = max - sample_offset;<br> <br> if (whence != SEEK_FORCECUR) {<br> offset = (offset > max) ? max : offset;<br>@@ -481,6 +473,23 @@<br> return offset - desc->hdr_size;<br> }<br> <br>+static struct ast_frame *g722_read(struct ast_filestream *s, int *whennext)<br>+{<br>+ struct ast_frame *f = pcm_read(s, whennext);<br>+ *whennext = s->fr.samples = (*whennext * 2);<br>+ return f;<br>+}<br>+<br>+static int g722_seek(struct ast_filestream *fs, off_t sample_offset, int whence)<br>+{<br>+ return pcm_seek(fs, sample_offset / 2, whence);<br>+}<br>+<br>+static off_t g722_tell(struct ast_filestream *fs)<br>+{<br>+ return pcm_tell(fs) * 2;<br>+}<br>+<br> static struct ast_format_def alaw_f = {<br> .name = "alaw",<br> .exts = "alaw|al|alw",<br>@@ -512,10 +521,10 @@<br> .name = "g722",<br> .exts = "g722",<br> .write = pcm_write,<br>- .seek = pcm_seek,<br>+ .seek = g722_seek,<br> .trunc = pcm_trunc,<br>- .tell = pcm_tell,<br>- .read = pcm_read,<br>+ .tell = g722_tell,<br>+ .read = g722_read,<br> .buf_size = (BUF_SIZE * 2) + AST_FRIENDLY_OFFSET,<br> };<br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8815">change 8815</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/8815"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I6a8c7352624b930a5f2d9e4857f75283fa5dd9f9 </div>
<div style="display:none"> Gerrit-Change-Number: 8815 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>