Trouble implementing ov_callbacks, endless loop calling seek_func

Rich E <[email protected]> Sun, 2 Feb 2014 04:54:15 -0500
Newsgroups gmane.comp.multimedia.ogg.vorbis.general
Message-ID <CA+vnWEhOiP_dDBFjZSbiPn8MqgcXctSZNMzkosc4_e1bzTTSEw@mail.gmail.com>
--===============1046925357==
Content-Type: multipart/alternative; boundary=047d7b33d7f0d759da04f1696392

--047d7b33d7f0d759da04f1696392
Content-Type: text/plain; charset=ISO-8859-1

Hello list,

I've been having a tough time adding windows resource support to my ogg
vorbise decoder, although I think I am close. Basically when I call
ov_open_callbacks(), it doesn't ever return and repeatedly calls my
seek_func.

I'm hoping it is something obvious, but I can't see why my seek_func is
being called endlessly.  If the file is seekable, I should return 0, right?
If any one can take a look at the following callback functions and see if
they can spot what I'm doing wrong, it'd be much appreciated:

size_t SourceFileImplOggVorbis::readFn( void *ptr, size_t size, size_t
nmemb, void *datasource )
{
auto sourceFile = (SourceFileImplOggVorbis *)datasource;

size_t bytes = size * nmemb;
sourceFile->mStream->readData( ptr, bytes );

return nmemb;
}

int SourceFileImplOggVorbis::seekFn( void *datasource, ogg_int64_t offset,
int whence )
{
auto sourceFile = (SourceFileImplOggVorbis *)datasource;

switch( whence ) {
case SEEK_SET:
sourceFile->mStream->seekAbsolute( (off_t)offset );
break;
case SEEK_CUR:
sourceFile->mStream->seekRelative( (off_t)offset );
break;
case SEEK_END:
sourceFile->mStream->seekAbsolute( (off_t)( - offset ) );
break;
default:
CI_ASSERT_NOT_REACHABLE();
return -1;
}

return 0;
}

int SourceFileImplOggVorbis::closeFn( void *datasource )
{
return 0;
}

long SourceFileImplOggVorbis::tellFn( void *datasource )
{
auto sourceFile = (SourceFileImplOggVorbis *)datasource;

long pos = sourceFile->mStream->tell();

return pos;
}

The source file for this code can also be found
here<https://github.com/richardeakin/Cinder-Audio2/blob/85126bdddc69110d6ea8bbd982bc11ff20d536d3/src/cinder/audio2/FileOggVorbis.cpp#L153>
.

Thanks a ton,
Rich

--047d7b33d7f0d759da04f1696392
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hello list,<div><br></div><div>I&#39;ve been having a toug=
h time adding windows resource support to my ogg vorbise decoder, although =
I think I am close. Basically when I call ov_open_callbacks(), it doesn&#39=
;t ever return and repeatedly calls my seek_func.</div>
<div><br></div><div>I&#39;m hoping it is something obvious, but I can&#39;t=
 see why my seek_func is being called endlessly. =A0If the file is seekable=
, I should return 0, right? If any one can take a look at the following cal=
lback functions and see if they can spot what I&#39;m doing wrong, it&#39;d=
 be much appreciated:</div>
<div><br></div><div><div>size_t SourceFileImplOggVorbis::readFn( void *ptr,=
 size_t size, size_t nmemb, void *datasource )<br></div><div>{</div><div><s=
pan class=3D"" style=3D"white-space:pre">	</span>auto sourceFile =3D (Sourc=
eFileImplOggVorbis *)datasource;</div>
<div><br></div><div><span class=3D"" style=3D"white-space:pre">	</span>size=
_t bytes =3D size * nmemb;</div><div><span class=3D"" style=3D"white-space:=
pre">	</span>sourceFile-&gt;mStream-&gt;readData( ptr, bytes );</div><div><=
br></div>
<div><span class=3D"" style=3D"white-space:pre">	</span>return nmemb;</div>=
<div>}</div><div><br></div><div>int SourceFileImplOggVorbis::seekFn( void *=
datasource, ogg_int64_t offset, int whence )<br></div><div>{</div><div><spa=
n class=3D"" style=3D"white-space:pre">	</span>auto sourceFile =3D (SourceF=
ileImplOggVorbis *)datasource;</div>
<div><br></div><div><span class=3D"" style=3D"white-space:pre">	</span>swit=
ch( whence ) {<br></div><div><span class=3D"" style=3D"white-space:pre">		<=
/span>case SEEK_SET:</div><div><span class=3D"" style=3D"white-space:pre">	=
		</span>sourceFile-&gt;mStream-&gt;seekAbsolute( (off_t)offset );</div>
<div><span class=3D"" style=3D"white-space:pre">			</span>break;</div><div>=
<span class=3D"" style=3D"white-space:pre">		</span>case SEEK_CUR:</div><di=
v><span class=3D"" style=3D"white-space:pre">			</span>sourceFile-&gt;mStre=
am-&gt;seekRelative( (off_t)offset );</div>
<div><span class=3D"" style=3D"white-space:pre">			</span>break;</div><div>=
<span class=3D"" style=3D"white-space:pre">		</span>case SEEK_END:</div><di=
v><span class=3D"" style=3D"white-space:pre">			</span>sourceFile-&gt;mStre=
am-&gt;seekAbsolute( (off_t)( - offset ) );<br>
</div><div><span class=3D"" style=3D"white-space:pre">			</span>break;</div=
><div><span class=3D"" style=3D"white-space:pre">		</span>default:</div><di=
v><span class=3D"" style=3D"white-space:pre">			</span>CI_ASSERT_NOT_REACHA=
BLE();</div>
<div><span class=3D"" style=3D"white-space:pre">			</span>return -1;</div><=
div><span class=3D"" style=3D"white-space:pre">	</span>}</div><div><br></di=
v><div><span class=3D"" style=3D"white-space:pre">	</span>return 0;</div><d=
iv>}</div>
<div><br></div><div>int<span class=3D"" style=3D"white-space:pre">	</span>S=
ourceFileImplOggVorbis::closeFn( void *datasource )<br></div><div>{</div><d=
iv><span class=3D"" style=3D"white-space:pre">	</span>return 0;</div><div>}=
</div>
<div><br></div><div>long SourceFileImplOggVorbis::tellFn( void *datasource =
)<br></div><div>{</div><div><span class=3D"" style=3D"white-space:pre">	</s=
pan>auto sourceFile =3D (SourceFileImplOggVorbis *)datasource;</div><div><b=
r>
</div><div><span class=3D"" style=3D"white-space:pre">	</span>long pos =3D =
sourceFile-&gt;mStream-&gt;tell();</div><div><br></div><div><span class=3D"=
" style=3D"white-space:pre">	</span>return pos;<br></div><div>}</div></div>=
<div><br>
</div><div>The source file for this code can also be <a href=3D"https://git=
hub.com/richardeakin/Cinder-Audio2/blob/85126bdddc69110d6ea8bbd982bc11ff20d=
536d3/src/cinder/audio2/FileOggVorbis.cpp#L153">found here</a>.</div><div>
<br></div><div>Thanks a ton,</div><div>Rich</div></div>

--047d7b33d7f0d759da04f1696392--

--===============1046925357==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Vorbis mailing list
[email protected]
http://lists.xiph.org/mailman/listinfo/vorbis

--===============1046925357==--