[PATCH] ao_initialize() and ao_shutdown() should be stacked
The following situation: Two parts of a program, for example program itself and a 3rd party plugin tries to access libao.
At the moment they need to signalize each other that ao_initialize() was already called, and when ao_shutdown() must be called. This is a bad thing when it comes to 3rd party code not under your (direct) control.
If you call them multiple times stuff may be left in inconsistent state, memory leak or wrong pointers (after a very quick look at the code).
The solution I see is to have a reference counter like counter. If it is zero and ao_initialize() is called the init is done and counter is set to one. if it is non-zero nothing is done but to increment the counter. ao_shutdown() works exactly the other way: each time it is called the counter is decremented. If it falls to zero the actual shutdown is done.