opensource

libtheora

2009-10-06: libtheora with SDL_audio
The changes are based on libtheora-1.1.0 - download code.


The Problem
The original player_example.c file from libtherora used SDL for the video portion for the sample executable - but used OSS (and complained about it vs. ALSA and something else about the kernel folks).

In a nutt shell, the audio portion of the example code was a little distracting from learning how to use libtheora properly. The audio video synchronization mechanism was quite horrendous to follow. And quite frankly, the audio handler didn't work at all on my platform.

The Solution
SDL's audio library is pretty rock solid. Just a little side note on how SDL_audio does things (with streaming data): Instead of buffering the audio data and then writting to the device when you want to, SDL_audio uses a callback function, provides you with a buffer location and it's size for you to fill in.

In other words, for SDL_audio, read, decode and write the audio data when they ask for it. Accumulating the size of the samples read-in, then provides the same data to synchronize the audio and video streams. I threw out all of "calibration/timing" and "audiobuf_ready/videobuf_ready" code and just used the accumulated value against the video's current time from:

	th_granule_time();
This streamlined a lot of the code.

In closing
The modifications should be close to a drop in replacement. The intention was to keep the code as close to the current examples already in place to maintain its original purpose as a learning resource. So, there are no additional error checks, globals are kept where they are and most of the original lines of code are there (they may have been moved around though). Only the audio code and synchronization mechanism have been surgically replaced. =)

Additional Resources
I thought about also posting a cleaned up version with no globals (for true re-entrant function usage) and move lines of code into well defined functions. But, there are examples of these already online by some fine random folks for both C and C++ versions.

I haven't tried running them. But they seem to be sound. And if anything, it is just another learning resource.


Copyright © 2009 by Nick Shin. All Rights Reserved.
These pages are designed by ESTSS.