[ogg-dev] Help with Opus Streaming

Philipp Schafft phschafft at de.loewenfelsen.net
Tue Nov 8 09:59:09 UTC 2016


Good morning,

On Tue, 2016-11-08 at 14:35 +0530, Deepak K wrote:
> Hi,
> 
> We have an windows client application to playback wav audio. Now we
> have to support Ogg Opus audio. The client is WPF application and the
> audio player component is in C++. The opus audio file is downloaded
> from an web-service and written to a Stream which is loaded into the
> player. I need to achieve the following:
> 
> 1. Start playback immediately as and when the audio is being
> downloaded.
> 
> 2. Allow user to jump to any position (by moving the audio slider)
> while the file is still being downloaded and written to the file
> stream.
> 
Ok.


> I am able to achieve the above when the file has completely downloaded
> but not when the file is downloading. 
> 
> 
> 1. How can I know the audio length to initialize my player? Is it
> available in the Ogg header?

No. Ogg/Opus is designed for streaming. As by definition of streaming
there is no total length (or it is always infinite, depending on how
you're looking at it). For non-streaming you can find out the total
length by looking at the last page.


> 2. When the user moves the slider forward, how can I calculate the
> audio position and request the server for file from that offset?

As with any non perfectly constant bitrate system this is hard to tell.
As there is no seektable that will help you, you need to guess the
position. You can estimate based on the bitrate of what you have already
where about the target position is. Then you can read a bit before that
position and look at the actual timestamp (also check the serial so you
don't break chaining!). If you're close before your target start
decoding and do skip the left over difference on the decoded stream. If
you are too far away update your guess based on the knew bitrate and
seek again.

Some notes:
      * libvorbisfile has a nice implementation of that, it also takes
        care of matching the signal at the very point of the jump.
      * libogg tries to generate pages of about 4kByte. Any sane
        implementation should not generate much bigger pages. With opus
        pages are likely a bit smaller, depending on the encoder
        setting. When seeking seek a few kByte before the actual
        position to ensure that you can read a complete page.
      * libogg will handle re-syncing and finding the next complete page
        in the buffer. No need to worry about seeking exactly to the
        start of a fresh page.

> 
> Any guidance on this will be helpful.

Hope that helped you a bit.

with best regards,


-- 
Philipp Schafft (CEO/Geschäftsführer) 
Telephon: +49.3535 490 17 92

Löwenfelsen UG (haftungsbeschränkt)     Registration number:
Bickinger Straße 21                     HRB 12308 CB
04916 Herzberg (Elster)                 VATIN/USt-ID:
Germany                                 DE305133015
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part
URL: <http://lists.xiph.org/pipermail/ogg-dev/attachments/20161108/b4728013/attachment.sig>


More information about the ogg-dev mailing list