[ogg-dev] Problems seeking with liboggz

Julio Cesar Esteves Cabezas jcabezas at inovax.com.br
Mon May 21 13:48:45 PDT 2012


Hi,

                The Ogg-Speex test file I used is CBR.  I am sure of that by running oggz-dump on the file and confirming that all audio packets have 38 bytes; that means (for narrowband) a constant 15 Kbps.

                I wrote a very basic test program in Visual Studio 2010 that demonstrates the strange behaviour I mentioned. 

The output shows that the audio file has 8 pages, 6 of them have audio packets;  the output show the page sequential number, time offset and byte offset of each page.

 

                Then after reading all of the file, for three times I request a time seek. It can be seen in the output that the result of the seek is never what was requested and is always the time offset of the end of some near page but never the page that contains the time point requested in seek.

                What could be going wrong ???

 

Thanks in advance,

Julio.

 

PROGRAM:

// TestaOgg.cpp : Defines the entry point for the console application.

#include "stdafx.h"

#include <exception>

#include <oggz/oggz.h>

 

int myReadPacketCallback (OGGZ* oggz, oggz_packet* packet, long serialno, void* user_data);

int myReadPageCallback (OGGZ* oggz, const ogg_page* og, long serialno, void* user_data);

 

int _tmain(int argc, _TCHAR* argv[])

{

  OGGZ* pOGGZ;

  int ret;

  oggz_off_t ofs;

 

  pOGGZ = oggz_open("MyAudio.spx", OGGZ_READ | OGGZ_AUTO);

  ret   = oggz_set_read_callback (pOGGZ, -1, myReadPacketCallback, (void*)0);

  ret   = oggz_set_read_page     (pOGGZ, -1, myReadPageCallback, (void*)0);

 

  ofs   = oggz_seek(pOGGZ, 0, SEEK_END);

  printf("\n Audio file size in bytes = %8lld", ofs);

  ofs   = oggz_seek(pOGGZ, 0, SEEK_SET);

  ret   = oggz_read(pOGGZ, 28779);

 

  for(int i=0; i<3; i++)

  {

    ogg_int64_t seektime  = (i==0 ? 5000  :  i==1 ? 10000  :  13000);

    ogg_int64_t rseek     = oggz_seek_units(pOGGZ, seektime, SEEK_SET);

    ogg_int64_t tellseek  = oggz_tell_units(pOGGZ);

    printf("\n Requested seek time = %8lld,  return of time seek function = %8lld,  return of time tell function = %8lld", seektime, rseek, tellseek);

  }

 

  oggz_close(pOGGZ);

  return 0;

}

//-----------------------------------------------------------------------------

int myReadPageCallback (OGGZ* oggz, const ogg_page* og, long serialno, void* user_data)

{

  ogg_int64_t bitstSerialNumber = og->header[14] + 256 * (og->header[15] + 256 * (og->header[16] + 256 * og->header[17]));

  ogg_int64_t pageSeqNumber     = og->header[18] + 256 * (og->header[19] + 256 * (og->header[20] + 256 * og->header[21]));

  ogg_int64_t headerGranulePos  = og->header[6]  + 256 * (og->header[7]  + 256 * (og->header[8]  + 256 * (og->header[9] + 

                                  256 * (og->header[10]  + 256 * (og->header[11]  + 256 * (og->header[12] ))))));

  ogg_int64_t currTimeOffset  = oggz_tell_units(oggz);

  ogg_int64_t currByteOffset  = oggz_tell(oggz);

 

  printf("\n Page seq.number = %8lld,  Time offset = %8lld,  Byte offset = %8lld,  Bitstream serial no. = %8lld,  GranulePos  = %8lld", 

          pageSeqNumber, currTimeOffset, currByteOffset, bitstSerialNumber, headerGranulePos);

  return 0;

}

//-----------------------------------------------------------------------------

int myReadPacketCallback (OGGZ* oggz, oggz_packet* packet, long serialno, void* user_data)

{

  //nothing useful done here

  return 0;

}

 

 

OUTPUT:

Audio file size in bytes =    27393

Page seq.number =        0,  Time offset =        0,  Byte offset =        0,  Bitstream serial no. =    16850,  GranulePos  =        0

Page seq.number =        1,  Time offset =        0,  Byte offset =      108,  Bitstream serial no. =    16850,  GranulePos  =        0

Page seq.number =        2,  Time offset =     2155,  Byte offset =      177,  Bitstream serial no. =    16850,  GranulePos  =    17240

Page seq.number =        3,  Time offset =     4315,  Byte offset =     4416,  Bitstream serial no. =    16850,  GranulePos  =    34520

Page seq.number =        4,  Time offset =     6475,  Byte offset =     8655,  Bitstream serial no. =    16850,  GranulePos  =    51800

Page seq.number =        5,  Time offset =     8635,  Byte offset =    12894,  Bitstream serial no. =    16850,  GranulePos  =    69080

Page seq.number =        6,  Time offset =    10795,  Byte offset =    17133,  Bitstream serial no. =    16850,  GranulePos  =    86360

Page seq.number =        7,  Time offset =    12955,  Byte offset =    21372,  Bitstream serial no. =    16850,  GranulePos  =   103640

Page seq.number =        8,  Time offset =    13840,  Byte offset =    25611,  Bitstream serial no. =    16850,  GranulePos  =   110720

Requested seek time =     5000,  return of time seek function =     2155,  return of time tell function =     2155

Requested seek time =    10000,  return of time seek function =     6475,  return of time tell function =     6475

Requested seek time =    13000,  return of time seek function =       -1,  return of time tell function =    10795

 

 

 

From: Milutin Jovanović [mailto:jovanovic.milutin at gmail.com] 
Sent: quinta-feira, 17 de maio de 2012 11:04
To: jcabezas at inovax.com.br
Cc: ogg-dev at xiph.org
Subject: Re: [ogg-dev] Problems seeking with liboggz

 


I'm no expert, but it sounds to me like normal variable bitrate stream behaviour. With variable bit rate, you cannot calculate exact byte address from time reference. So, in general you estimate and get close to time reference requested. Whenever you need precise pocision, you should use constant bit rate or a byte offset (instead of time/milliseconds).

FYI, in my apps, I use time to show progres to the user, but when I save a bookmark or pause, I record exact sample offset, and restart from there. So, time for UI, samples/bytes for hidden/underlying code.

Miki.




On 16 May 2012 18:52, Julio Cesar Esteves Cabezas < <mailto:jcabezas at inovax.com.br> jcabezas at inovax.com.br> wrote:

Hi,

 

  I intend to use Ogg+Speex for voice recording/playback in a VoIP app.

  I am experimenting with liboggz to get acquainted with its API. 

  As test files I am using some Ogg-Speex files converted from WAV files with speexenc.exe.

  

  I wrote a little testing app in Visual Studio 2010 under Windows 7. 

  I defined OggzReadPage and OggzReadPacket callbacks with oggz_set_read_page() and oggz_set_read_callback().

  

  For the moment I am mainly having troubles with seeking. Maybe I am not using correctly liboggz API.

  What happens:

  - I open a Ogg Speex-encoded audio file with oggz_open("MyFile.spx", OGGZ_READ | OGGZ_AUTO); 

  - I have a loop of invocations of oggz_read() that triggers in the due time the page and packet callbacks defined by me.

  - But when I randomly do seeking by means of  

      ogg_int64_t rseek = oggz_seek_units(pOGGZ, posMsecs, SEEK_SET);

    I get erratic results: 

      Many times rseek does not match posMsecs.      

      The first page callback after the seek invocation refers to a page that is sometimes previous and sometimes after the page that contains posMsecs.

      

 

  What rules are to be followed for seeking with liboggz and what exact results can be expected from it ?

 

 

Thanks in advance

Julio Cabezas

 

 


_______________________________________________
ogg-dev mailing list
 <mailto:ogg-dev at xiph.org> ogg-dev at xiph.org
 <http://lists.xiph.org/mailman/listinfo/ogg-dev> http://lists.xiph.org/mailman/listinfo/ogg-dev

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/ogg-dev/attachments/20120521/72f84fe3/attachment-0001.htm 


More information about the ogg-dev mailing list