[Flac-dev] Unexpected writeCallback() calls

Peter Kunath kunath at justmail.de
Sat Feb 23 05:31:04 PST 2002


I've recently written a FLAC input plugin which uses the
seekable stream decoder API of libFLAC 1.02. It works so
far, but one thing is pretty annoying and should be changed
in future libFLAC versions, IMHO:
The writeCallback is not only called after functions which
do decoding (like process_whole_stream(), process_one_frame()
or process_remaining_frames()), ie. where one expects that
new data arrives. Instead, also functions like seek_absolute()
can create decoded data.
I think that generating new data should be restricted to the
three functions mentioned above, because it would make libFLAC
easier to use. Currently, it is best that a developer does all
FLAC API calls in one function, because one never knows when
new data arrives. This makes it necessary to use annoying flags
like e.g. 'needs_seek' in the Winamp3 plugin. Wouldn't it be
better and more intuitive to call seek_absolute() directly in
Winamp3's onSeeked() routine?
Besides, the current behaviour can cause buffer overflows
easily if you arn't careful and empty the output reservoir
fast enough (or use overflow/safety margins like the Winamp3
plugin does - which is a bad programming style, IMHO). Another
(bad) solution would be to test if the revervoir can hold all
new samples and to copy the samples only partially if the
buffer is full - but this would lead hickups in the sound and
thus cure only the symptoms, but not the real cause.

   - Peter.

More information about the Flac-dev mailing list