erikd/libsndfile — pull request #6 by umlaeute (2012-03-16 21:37:15+00:00)
Title: sample implementation to allow reading multiple custom-chunks via an iterator

this is my attempt on implementing the reading of multiple custom chunks as discussed on the mailing-list.

noteable differences:

#1 i replaced the original sf_get_chunk_size() and sf_get_chunk_size() with new iterator-based versions
(my original proposal had both sf_get_chunk_*() and sf_get_iterator_chunk_*(); this would lead to a lot of code duplication, so i removed the old functions)

#2 to get an iterator, call sf_create_chunk_iterator(sndfile, chunk_info)
to increment an iterator, call sf_next_chunk_iterator(iterator)

#3 my original plan was to have constant linked-lists stored somewhere in the PSF, for all custom chunk ids.i ended up making it simpler and doing a "search next" whenever the next_iterator is requested, and updating the iterator itself (by simply updating a "current" index), so the semantics of sf_next_chunk_iterator() is "increment the iterator" rather than "give me a new iterator pointing to the next element"

#4 the original proposal was a bit unclear about memory management of the iterators (since the original linked-lists would have been allocated when adding new read-chunks, and deallocated when calling sf_close()); with the now implemented scheme this is no longer possible, so memory management works like:
- sf_create_chunk_iterator() will allocate memory for the iterator
- sf_next_chunk_iterator() will eventually modify this memory, when incrementing to the next item
- sf_next_chunk_iterator() will free the memory once it goes beyond the last element.
currently, the only way to free an iterator is by calling sf_next_chunk_iterator() until it returns NULL.

#5 i added some more "const" qualifiers to the code where possible

#6 i added a simple test for writing multiple custom chunks with the same ID, and trying to read them back.