4

Recently I tried to understand how ogg vorbis works inside, so I wrote simple encoder/decoder for ogg vorbis. And now I'm trying to understand how all internet ogg radiostations work. And the thing I do not understand: if you need to process all 3 vorbis headers to know how to decode audio (channels, rate etc), how can they permanently stream audio and stream it from the random position of the track?

Brad
  • 146,404
  • 44
  • 300
  • 476

1 Answers1

3

Ogg (Vorbis or otherwise) streams don't work by streaming from random positions in the track. This makes it a wrapper that is more difficult for internet radio servers, and why Ogg doesn't work on SHOUTcast servers.

To stream Ogg, the server must parse the initial Ogg frame headers from the source stream. When a new client connects, these frame headers are sent to the client before any new audio data. After this, the server begins sending frames for the current position in the stream, but it doesn't start randomly. It begins on a proper frame boundary.

You can see this behavior yourself. Start up an Icecast server with a source stream using Ogg with Vorbis or FLAC. Use Wireshark to capture packets from two different client connections started at different times. Then, compare the initial Ogg frames you get from the server. You will see two frames that set things up, followed by the frames in the middle of the stream.

Brad
  • 146,404
  • 44
  • 300
  • 476
  • Looks like your answer was similar with my experiment for streaming microphone with socket.io.. But after I extracted the header and combine it on client's browser, there are small gap/delay on each buffer.. I was trying to do some buffer manipulation but still don't know how to find where is the header ends. Even [the experiment](https://github.com/ScarletsFiction/SFMediaStream/tree/master/example/StreamingTest) was working, but could anyone help me fix the delay? – StefansArya Nov 28 '18 at 12:59