API CHANGE: Add an onUninit callback to ma_data_source_vtable.

This callback to execute the data source's uninitialization routine.
This commit is contained in:
David Reid
2026-04-28 17:27:31 +10:00
parent 3e729e4b28
commit 77074f0597
5 changed files with 120 additions and 30 deletions
@@ -13,6 +13,11 @@
#include <string.h> /* For memset(). */
#include <assert.h>
static void ma_libvorbis_ds_uninit(ma_data_source* pDataSource)
{
ma_libvorbis_uninit((ma_libvorbis*)pDataSource);
}
static ma_result ma_libvorbis_ds_read(ma_data_source* pDataSource, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead)
{
return ma_libvorbis_read_pcm_frames((ma_libvorbis*)pDataSource, pFramesOut, frameCount, pFramesRead);
@@ -40,6 +45,7 @@ static ma_result ma_libvorbis_ds_get_length(ma_data_source* pDataSource, ma_uint
static ma_data_source_vtable ma_gDataSourceVTable_libvorbis =
{
ma_libvorbis_ds_uninit,
ma_libvorbis_ds_read,
ma_libvorbis_ds_seek,
ma_libvorbis_ds_get_data_format,
@@ -117,6 +123,7 @@ static ma_result ma_libvorbis_init_internal(const ma_decoding_backend_config* pC
}
memset(pVorbis, 0, sizeof(*pVorbis));
ma_allocation_callbacks_init_copy(&pVorbis->allocationCallbacks, pAllocationCallbacks);
pVorbis->format = ma_format_f32; /* f32 by default. */
if (pConfig != NULL && (pConfig->preferredFormat == ma_format_f32 || pConfig->preferredFormat == ma_format_s16)) {
@@ -237,14 +244,12 @@ MA_API ma_result ma_libvorbis_init_file(const char* pFilePath, const ma_decoding
#endif
}
MA_API void ma_libvorbis_uninit(ma_libvorbis* pVorbis, const ma_allocation_callbacks* pAllocationCallbacks)
MA_API void ma_libvorbis_uninit(ma_libvorbis* pVorbis)
{
if (pVorbis == NULL) {
return;
}
(void)pAllocationCallbacks;
#if !defined(MA_NO_LIBVORBIS)
{
ov_clear((OggVorbis_File*)pVorbis->vf);
@@ -257,7 +262,7 @@ MA_API void ma_libvorbis_uninit(ma_libvorbis* pVorbis, const ma_allocation_callb
#endif
ma_data_source_base_uninit(&pVorbis->ds);
ma_free(pVorbis->vf, pAllocationCallbacks);
ma_free(pVorbis->vf, &pVorbis->allocationCallbacks);
}
MA_API ma_result ma_libvorbis_read_pcm_frames(ma_libvorbis* pVorbis, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead)
@@ -16,6 +16,7 @@ extern "C" {
typedef struct
{
ma_data_source_base ds; /* The libvorbis decoder can be used independently as a data source. */
ma_allocation_callbacks allocationCallbacks;
ma_read_proc onRead;
ma_seek_proc onSeek;
ma_tell_proc onTell;
@@ -26,7 +27,7 @@ typedef struct
MA_API ma_result ma_libvorbis_init(ma_read_proc onRead, ma_seek_proc onSeek, ma_tell_proc onTell, void* pReadSeekTellUserData, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_libvorbis* pVorbis);
MA_API ma_result ma_libvorbis_init_file(const char* pFilePath, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_libvorbis* pVorbis);
MA_API void ma_libvorbis_uninit(ma_libvorbis* pVorbis, const ma_allocation_callbacks* pAllocationCallbacks);
MA_API void ma_libvorbis_uninit(ma_libvorbis* pVorbis);
MA_API ma_result ma_libvorbis_read_pcm_frames(ma_libvorbis* pVorbis, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead);
MA_API ma_result ma_libvorbis_seek_to_pcm_frame(ma_libvorbis* pVorbis, ma_uint64 frameIndex);
MA_API ma_result ma_libvorbis_get_data_format(ma_libvorbis* pVorbis, ma_format* pFormat, ma_uint32* pChannels, ma_uint32* pSampleRate, ma_channel* pChannelMap, size_t channelMapCap);