Skip to content

How to decode Opus in a non-blocking way from an OGG stream (code inside) #44

@stefan-reich

Description

@stefan-reich

Hi, I'm receiving opus audio data (.ogg) as a live stream, and want to decode each packet as it arrives.

So I assume I'll have to patch OggPacketReader to "pause" when no more bytes are available currently.

I could use blocking I/O, but that's really not preferred.

Edit: After looking at the sources, I don't think it's going to be very hard. Just have the InputStream return null when temporarily out of bytes, and rewind the stream when getNextPacket() returns null. Plus make sure OpusFile gets enough initial packets to start up.

Edit 2: I got it done! Demo: https://code.botcompany.de/1032909, main class: https://code.botcompany.de/1032905 (it's in my dialect JavaX, but you can click on "Pure Java Version")

The trick is to have your InputStream simply behave like EOF when it is currently out of bytes, and have the other classes work properly with this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions