Commit 8ad250cc authored by David Reid's avatar David Reid

Updates to custom decoders.

parent b40803cf
...@@ -95,7 +95,7 @@ endif() ...@@ -95,7 +95,7 @@ endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
list(APPEND COMPILE_OPTIONS -Wall -Wextra -Wpedantic) list(APPEND COMPILE_OPTIONS -Wall -Wextra -Wpedantic)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
list(APPEND COMPILE_OPTIONS /W4) #list(APPEND COMPILE_OPTIONS /W4)
endif() endif()
...@@ -445,29 +445,21 @@ if (MINIAUDIO_BUILD_EXAMPLES) ...@@ -445,29 +445,21 @@ if (MINIAUDIO_BUILD_EXAMPLES)
add_miniaudio_example(miniaudio_custom_backend custom_backend.c) add_miniaudio_example(miniaudio_custom_backend custom_backend.c)
add_miniaudio_example(miniaudio_custom_decoder_engine custom_decoder_engine.c) add_miniaudio_example(miniaudio_custom_decoder_engine custom_decoder_engine.c)
if(HAS_LIBVORBIS) if(NOT HAS_LIBVORBIS)
target_link_libraries(miniaudio_custom_decoder_engine PRIVATE miniaudio_libvorbis)
else()
target_compile_definitions(miniaudio_custom_decoder_engine PRIVATE MA_NO_LIBVORBIS) target_compile_definitions(miniaudio_custom_decoder_engine PRIVATE MA_NO_LIBVORBIS)
message(STATUS "miniaudio_libvorbis is disabled. Vorbis support is disabled in miniaudio_custom_decoder_engine.") message(STATUS "miniaudio_libvorbis is disabled. Vorbis support is disabled in miniaudio_custom_decoder_engine.")
endif() endif()
if(HAS_LIBOPUS) if(NOT HAS_LIBOPUS)
target_link_libraries(miniaudio_custom_decoder_engine PRIVATE miniaudio_libopus)
else()
target_compile_definitions(miniaudio_custom_decoder_engine PRIVATE MA_NO_LIBOPUS) target_compile_definitions(miniaudio_custom_decoder_engine PRIVATE MA_NO_LIBOPUS)
message(STATUS "miniaudio_libopus is disabled. Opus support is disabled in miniaudio_custom_decoder_engine.") message(STATUS "miniaudio_libopus is disabled. Opus support is disabled in miniaudio_custom_decoder_engine.")
endif() endif()
add_miniaudio_example(miniaudio_custom_decoder custom_decoder.c) add_miniaudio_example(miniaudio_custom_decoder custom_decoder.c)
if(HAS_LIBVORBIS) if(NOT HAS_LIBVORBIS)
target_link_libraries(miniaudio_custom_decoder PRIVATE miniaudio_libvorbis)
else()
target_compile_definitions(miniaudio_custom_decoder PRIVATE MA_NO_LIBVORBIS) target_compile_definitions(miniaudio_custom_decoder PRIVATE MA_NO_LIBVORBIS)
message(STATUS "miniaudio_libvorbis is disabled. Vorbis support is disabled in miniaudio_custom_decoder.") message(STATUS "miniaudio_libvorbis is disabled. Vorbis support is disabled in miniaudio_custom_decoder.")
endif() endif()
if(HAS_LIBOPUS) if(NOT HAS_LIBOPUS)
target_link_libraries(miniaudio_custom_decoder PRIVATE miniaudio_libopus)
else()
target_compile_definitions(miniaudio_custom_decoder PRIVATE MA_NO_LIBOPUS) target_compile_definitions(miniaudio_custom_decoder PRIVATE MA_NO_LIBOPUS)
message(STATUS "miniaudio_libopus is disabled. Opus support is disabled in miniaudio_custom_decoder.") message(STATUS "miniaudio_libopus is disabled. Opus support is disabled in miniaudio_custom_decoder.")
endif() endif()
......
...@@ -20,145 +20,12 @@ The `onInitFile`, `onInitFileW` and `onInitMemory` functions are optional. ...@@ -20,145 +20,12 @@ The `onInitFile`, `onInitFileW` and `onInitMemory` functions are optional.
For now these need to be declared before miniaudio.c due to some compatibility issues with the old For now these need to be declared before miniaudio.c due to some compatibility issues with the old
MINIAUDIO_IMPLEMENTATION system. This will change from version 0.12. MINIAUDIO_IMPLEMENTATION system. This will change from version 0.12.
*/ */
#include "../extras/decoders/libvorbis/miniaudio_libvorbis.h" #include "../extras/decoders/libvorbis/miniaudio_libvorbis.c"
#include "../extras/decoders/libopus/miniaudio_libopus.h" #include "../extras/decoders/libopus/miniaudio_libopus.c"
#include "../miniaudio.c" #include "../miniaudio.c"
#include <stdio.h> #include <stdio.h>
static ma_result ma_decoding_backend_init__libvorbis(void* pUserData, 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_data_source** ppBackend)
{
ma_result result;
ma_libvorbis* pVorbis;
(void)pUserData;
pVorbis = (ma_libvorbis*)ma_malloc(sizeof(*pVorbis), pAllocationCallbacks);
if (pVorbis == NULL) {
return MA_OUT_OF_MEMORY;
}
result = ma_libvorbis_init(onRead, onSeek, onTell, pReadSeekTellUserData, pConfig, pAllocationCallbacks, pVorbis);
if (result != MA_SUCCESS) {
ma_free(pVorbis, pAllocationCallbacks);
return result;
}
*ppBackend = pVorbis;
return MA_SUCCESS;
}
static ma_result ma_decoding_backend_init_file__libvorbis(void* pUserData, const char* pFilePath, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_data_source** ppBackend)
{
ma_result result;
ma_libvorbis* pVorbis;
(void)pUserData;
pVorbis = (ma_libvorbis*)ma_malloc(sizeof(*pVorbis), pAllocationCallbacks);
if (pVorbis == NULL) {
return MA_OUT_OF_MEMORY;
}
result = ma_libvorbis_init_file(pFilePath, pConfig, pAllocationCallbacks, pVorbis);
if (result != MA_SUCCESS) {
ma_free(pVorbis, pAllocationCallbacks);
return result;
}
*ppBackend = pVorbis;
return MA_SUCCESS;
}
static void ma_decoding_backend_uninit__libvorbis(void* pUserData, ma_data_source* pBackend, const ma_allocation_callbacks* pAllocationCallbacks)
{
ma_libvorbis* pVorbis = (ma_libvorbis*)pBackend;
(void)pUserData;
ma_libvorbis_uninit(pVorbis, pAllocationCallbacks);
ma_free(pVorbis, pAllocationCallbacks);
}
static ma_decoding_backend_vtable g_ma_decoding_backend_vtable_libvorbis =
{
ma_decoding_backend_init__libvorbis,
ma_decoding_backend_init_file__libvorbis,
NULL, /* onInitFileW() */
NULL, /* onInitMemory() */
ma_decoding_backend_uninit__libvorbis
};
static ma_result ma_decoding_backend_init__libopus(void* pUserData, 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_data_source** ppBackend)
{
ma_result result;
ma_libopus* pOpus;
(void)pUserData;
pOpus = (ma_libopus*)ma_malloc(sizeof(*pOpus), pAllocationCallbacks);
if (pOpus == NULL) {
return MA_OUT_OF_MEMORY;
}
result = ma_libopus_init(onRead, onSeek, onTell, pReadSeekTellUserData, pConfig, pAllocationCallbacks, pOpus);
if (result != MA_SUCCESS) {
ma_free(pOpus, pAllocationCallbacks);
return result;
}
*ppBackend = pOpus;
return MA_SUCCESS;
}
static ma_result ma_decoding_backend_init_file__libopus(void* pUserData, const char* pFilePath, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_data_source** ppBackend)
{
ma_result result;
ma_libopus* pOpus;
(void)pUserData;
pOpus = (ma_libopus*)ma_malloc(sizeof(*pOpus), pAllocationCallbacks);
if (pOpus == NULL) {
return MA_OUT_OF_MEMORY;
}
result = ma_libopus_init_file(pFilePath, pConfig, pAllocationCallbacks, pOpus);
if (result != MA_SUCCESS) {
ma_free(pOpus, pAllocationCallbacks);
return result;
}
*ppBackend = pOpus;
return MA_SUCCESS;
}
static void ma_decoding_backend_uninit__libopus(void* pUserData, ma_data_source* pBackend, const ma_allocation_callbacks* pAllocationCallbacks)
{
ma_libopus* pOpus = (ma_libopus*)pBackend;
(void)pUserData;
ma_libopus_uninit(pOpus, pAllocationCallbacks);
ma_free(pOpus, pAllocationCallbacks);
}
static ma_decoding_backend_vtable g_ma_decoding_backend_vtable_libopus =
{
ma_decoding_backend_init__libopus,
ma_decoding_backend_init_file__libopus,
NULL, /* onInitFileW() */
NULL, /* onInitMemory() */
ma_decoding_backend_uninit__libopus
};
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
{ {
...@@ -187,10 +54,10 @@ int main(int argc, char** argv) ...@@ -187,10 +54,10 @@ int main(int argc, char** argv)
Add your custom backend vtables here. The order in the array defines the order of priority. The Add your custom backend vtables here. The order in the array defines the order of priority. The
vtables will be passed in via the decoder config. vtables will be passed in via the decoder config.
*/ */
ma_decoding_backend_vtable* pCustomBackendVTables[] = const ma_decoding_backend_vtable* pCustomBackendVTables[] =
{ {
&g_ma_decoding_backend_vtable_libvorbis, ma_decoding_backend_libvorbis,
&g_ma_decoding_backend_vtable_libopus ma_decoding_backend_libopus
}; };
......
...@@ -10,145 +10,12 @@ example (via libopus). ...@@ -10,145 +10,12 @@ example (via libopus).
For now these need to be declared before miniaudio.c due to some compatibility issues with the old For now these need to be declared before miniaudio.c due to some compatibility issues with the old
MINIAUDIO_IMPLEMENTATION system. This will change from version 0.12. MINIAUDIO_IMPLEMENTATION system. This will change from version 0.12.
*/ */
#include "../extras/decoders/libvorbis/miniaudio_libvorbis.h" #include "../extras/decoders/libvorbis/miniaudio_libvorbis.c"
#include "../extras/decoders/libopus/miniaudio_libopus.h" #include "../extras/decoders/libopus/miniaudio_libopus.c"
#include "../miniaudio.c" #include "../miniaudio.c"
#include <stdio.h> #include <stdio.h>
static ma_result ma_decoding_backend_init__libvorbis(void* pUserData, 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_data_source** ppBackend)
{
ma_result result;
ma_libvorbis* pVorbis;
(void)pUserData;
pVorbis = (ma_libvorbis*)ma_malloc(sizeof(*pVorbis), pAllocationCallbacks);
if (pVorbis == NULL) {
return MA_OUT_OF_MEMORY;
}
result = ma_libvorbis_init(onRead, onSeek, onTell, pReadSeekTellUserData, pConfig, pAllocationCallbacks, pVorbis);
if (result != MA_SUCCESS) {
ma_free(pVorbis, pAllocationCallbacks);
return result;
}
*ppBackend = pVorbis;
return MA_SUCCESS;
}
static ma_result ma_decoding_backend_init_file__libvorbis(void* pUserData, const char* pFilePath, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_data_source** ppBackend)
{
ma_result result;
ma_libvorbis* pVorbis;
(void)pUserData;
pVorbis = (ma_libvorbis*)ma_malloc(sizeof(*pVorbis), pAllocationCallbacks);
if (pVorbis == NULL) {
return MA_OUT_OF_MEMORY;
}
result = ma_libvorbis_init_file(pFilePath, pConfig, pAllocationCallbacks, pVorbis);
if (result != MA_SUCCESS) {
ma_free(pVorbis, pAllocationCallbacks);
return result;
}
*ppBackend = pVorbis;
return MA_SUCCESS;
}
static void ma_decoding_backend_uninit__libvorbis(void* pUserData, ma_data_source* pBackend, const ma_allocation_callbacks* pAllocationCallbacks)
{
ma_libvorbis* pVorbis = (ma_libvorbis*)pBackend;
(void)pUserData;
ma_libvorbis_uninit(pVorbis, pAllocationCallbacks);
ma_free(pVorbis, pAllocationCallbacks);
}
static ma_decoding_backend_vtable g_ma_decoding_backend_vtable_libvorbis =
{
ma_decoding_backend_init__libvorbis,
ma_decoding_backend_init_file__libvorbis,
NULL, /* onInitFileW() */
NULL, /* onInitMemory() */
ma_decoding_backend_uninit__libvorbis
};
static ma_result ma_decoding_backend_init__libopus(void* pUserData, 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_data_source** ppBackend)
{
ma_result result;
ma_libopus* pOpus;
(void)pUserData;
pOpus = (ma_libopus*)ma_malloc(sizeof(*pOpus), pAllocationCallbacks);
if (pOpus == NULL) {
return MA_OUT_OF_MEMORY;
}
result = ma_libopus_init(onRead, onSeek, onTell, pReadSeekTellUserData, pConfig, pAllocationCallbacks, pOpus);
if (result != MA_SUCCESS) {
ma_free(pOpus, pAllocationCallbacks);
return result;
}
*ppBackend = pOpus;
return MA_SUCCESS;
}
static ma_result ma_decoding_backend_init_file__libopus(void* pUserData, const char* pFilePath, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_data_source** ppBackend)
{
ma_result result;
ma_libopus* pOpus;
(void)pUserData;
pOpus = (ma_libopus*)ma_malloc(sizeof(*pOpus), pAllocationCallbacks);
if (pOpus == NULL) {
return MA_OUT_OF_MEMORY;
}
result = ma_libopus_init_file(pFilePath, pConfig, pAllocationCallbacks, pOpus);
if (result != MA_SUCCESS) {
ma_free(pOpus, pAllocationCallbacks);
return result;
}
*ppBackend = pOpus;
return MA_SUCCESS;
}
static void ma_decoding_backend_uninit__libopus(void* pUserData, ma_data_source* pBackend, const ma_allocation_callbacks* pAllocationCallbacks)
{
ma_libopus* pOpus = (ma_libopus*)pBackend;
(void)pUserData;
ma_libopus_uninit(pOpus, pAllocationCallbacks);
ma_free(pOpus, pAllocationCallbacks);
}
static ma_decoding_backend_vtable g_ma_decoding_backend_vtable_libopus =
{
ma_decoding_backend_init__libopus,
ma_decoding_backend_init_file__libopus,
NULL, /* onInitFileW() */
NULL, /* onInitMemory() */
ma_decoding_backend_uninit__libopus
};
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
...@@ -162,10 +29,10 @@ int main(int argc, char** argv) ...@@ -162,10 +29,10 @@ int main(int argc, char** argv)
Add your custom backend vtables here. The order in the array defines the order of priority. The Add your custom backend vtables here. The order in the array defines the order of priority. The
vtables will be passed in to the resource manager config. vtables will be passed in to the resource manager config.
*/ */
ma_decoding_backend_vtable* pCustomBackendVTables[] = const ma_decoding_backend_vtable* pCustomBackendVTables[] =
{ {
&g_ma_decoding_backend_vtable_libvorbis, ma_decoding_backend_libvorbis,
&g_ma_decoding_backend_vtable_libopus ma_decoding_backend_libopus
}; };
......
...@@ -3,8 +3,12 @@ ...@@ -3,8 +3,12 @@
#include "miniaudio_libopus.h" #include "miniaudio_libopus.h"
#if !defined(MA_NO_LIBOPUS)
#include <opusfile.h> #include <opusfile.h>
#endif
#include <string.h> /* For memset(). */ #include <string.h> /* For memset(). */
#include <assert.h>
static ma_result ma_libopus_ds_read(ma_data_source* pDataSource, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead) static ma_result ma_libopus_ds_read(ma_data_source* pDataSource, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead)
{ {
...@@ -221,7 +225,7 @@ MA_API void ma_libopus_uninit(ma_libopus* pOpus, const ma_allocation_callbacks* ...@@ -221,7 +225,7 @@ MA_API void ma_libopus_uninit(ma_libopus* pOpus, const ma_allocation_callbacks*
#else #else
{ {
/* libopus is disabled. Should never hit this since initialization would have failed. */ /* libopus is disabled. Should never hit this since initialization would have failed. */
MA_ASSERT(MA_FALSE); assert(MA_FALSE);
} }
#endif #endif
...@@ -296,7 +300,7 @@ MA_API ma_result ma_libopus_read_pcm_frames(ma_libopus* pOpus, void* pFramesOut, ...@@ -296,7 +300,7 @@ MA_API ma_result ma_libopus_read_pcm_frames(ma_libopus* pOpus, void* pFramesOut,
#else #else
{ {
/* libopus is disabled. Should never hit this since initialization would have failed. */ /* libopus is disabled. Should never hit this since initialization would have failed. */
MA_ASSERT(MA_FALSE); assert(MA_FALSE);
(void)pFramesOut; (void)pFramesOut;
(void)frameCount; (void)frameCount;
...@@ -331,7 +335,7 @@ MA_API ma_result ma_libopus_seek_to_pcm_frame(ma_libopus* pOpus, ma_uint64 frame ...@@ -331,7 +335,7 @@ MA_API ma_result ma_libopus_seek_to_pcm_frame(ma_libopus* pOpus, ma_uint64 frame
#else #else
{ {
/* libopus is disabled. Should never hit this since initialization would have failed. */ /* libopus is disabled. Should never hit this since initialization would have failed. */
MA_ASSERT(MA_FALSE); assert(MA_FALSE);
(void)frameIndex; (void)frameIndex;
...@@ -385,7 +389,7 @@ MA_API ma_result ma_libopus_get_data_format(ma_libopus* pOpus, ma_format* pForma ...@@ -385,7 +389,7 @@ MA_API ma_result ma_libopus_get_data_format(ma_libopus* pOpus, ma_format* pForma
#else #else
{ {
/* libopus is disabled. Should never hit this since initialization would have failed. */ /* libopus is disabled. Should never hit this since initialization would have failed. */
MA_ASSERT(MA_FALSE); assert(MA_FALSE);
return MA_NOT_IMPLEMENTED; return MA_NOT_IMPLEMENTED;
} }
#endif #endif
...@@ -417,7 +421,7 @@ MA_API ma_result ma_libopus_get_cursor_in_pcm_frames(ma_libopus* pOpus, ma_uint6 ...@@ -417,7 +421,7 @@ MA_API ma_result ma_libopus_get_cursor_in_pcm_frames(ma_libopus* pOpus, ma_uint6
#else #else
{ {
/* libopus is disabled. Should never hit this since initialization would have failed. */ /* libopus is disabled. Should never hit this since initialization would have failed. */
MA_ASSERT(MA_FALSE); assert(MA_FALSE);
return MA_NOT_IMPLEMENTED; return MA_NOT_IMPLEMENTED;
} }
#endif #endif
...@@ -449,10 +453,84 @@ MA_API ma_result ma_libopus_get_length_in_pcm_frames(ma_libopus* pOpus, ma_uint6 ...@@ -449,10 +453,84 @@ MA_API ma_result ma_libopus_get_length_in_pcm_frames(ma_libopus* pOpus, ma_uint6
#else #else
{ {
/* libopus is disabled. Should never hit this since initialization would have failed. */ /* libopus is disabled. Should never hit this since initialization would have failed. */
MA_ASSERT(MA_FALSE); assert(MA_FALSE);
return MA_NOT_IMPLEMENTED; return MA_NOT_IMPLEMENTED;
} }
#endif #endif
} }
/*
The code below defines the vtable that you'll plug into your `ma_decoder_config` object.
*/
#if !defined(MA_NO_LIBOPUS)
static ma_result ma_decoding_backend_init__libopus(void* pUserData, 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_data_source** ppBackend)
{
ma_result result;
ma_libopus* pOpus;
(void)pUserData;
pOpus = (ma_libopus*)ma_malloc(sizeof(*pOpus), pAllocationCallbacks);
if (pOpus == NULL) {
return MA_OUT_OF_MEMORY;
}
result = ma_libopus_init(onRead, onSeek, onTell, pReadSeekTellUserData, pConfig, pAllocationCallbacks, pOpus);
if (result != MA_SUCCESS) {
ma_free(pOpus, pAllocationCallbacks);
return result;
}
*ppBackend = pOpus;
return MA_SUCCESS;
}
static ma_result ma_decoding_backend_init_file__libopus(void* pUserData, const char* pFilePath, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_data_source** ppBackend)
{
ma_result result;
ma_libopus* pOpus;
(void)pUserData;
pOpus = (ma_libopus*)ma_malloc(sizeof(*pOpus), pAllocationCallbacks);
if (pOpus == NULL) {
return MA_OUT_OF_MEMORY;
}
result = ma_libopus_init_file(pFilePath, pConfig, pAllocationCallbacks, pOpus);
if (result != MA_SUCCESS) {
ma_free(pOpus, pAllocationCallbacks);
return result;
}
*ppBackend = pOpus;
return MA_SUCCESS;
}
static void ma_decoding_backend_uninit__libopus(void* pUserData, ma_data_source* pBackend, const ma_allocation_callbacks* pAllocationCallbacks)
{
ma_libopus* pOpus = (ma_libopus*)pBackend;
(void)pUserData;
ma_libopus_uninit(pOpus, pAllocationCallbacks);
ma_free(pOpus, pAllocationCallbacks);
}
static ma_decoding_backend_vtable ma_gDecodingBackendVTable_libopus =
{
ma_decoding_backend_init__libopus,
ma_decoding_backend_init_file__libopus,
NULL, /* onInitFileW() */
NULL, /* onInitMemory() */
ma_decoding_backend_uninit__libopus
};
const ma_decoding_backend_vtable* ma_decoding_backend_libopus = &ma_gDecodingBackendVTable_libopus;
#else
const ma_decoding_backend_vtable* ma_decoding_backend_libopus = NULL;
#endif
#endif /* miniaudio_libopus_c */ #endif /* miniaudio_libopus_c */
...@@ -33,6 +33,9 @@ MA_API ma_result ma_libopus_get_data_format(ma_libopus* pOpus, ma_format* pForma ...@@ -33,6 +33,9 @@ MA_API ma_result ma_libopus_get_data_format(ma_libopus* pOpus, ma_format* pForma
MA_API ma_result ma_libopus_get_cursor_in_pcm_frames(ma_libopus* pOpus, ma_uint64* pCursor); MA_API ma_result ma_libopus_get_cursor_in_pcm_frames(ma_libopus* pOpus, ma_uint64* pCursor);
MA_API ma_result ma_libopus_get_length_in_pcm_frames(ma_libopus* pOpus, ma_uint64* pLength); MA_API ma_result ma_libopus_get_length_in_pcm_frames(ma_libopus* pOpus, ma_uint64* pLength);
/* Decoding backend vtable. This is what you'll plug into ma_decoder_config.pBackendVTables. No user data required. */
extern const ma_decoding_backend_vtable* ma_decoding_backend_libopus;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#endif #endif
#include <string.h> /* For memset(). */ #include <string.h> /* For memset(). */
#include <assert.h>
static ma_result ma_libvorbis_ds_read(ma_data_source* pDataSource, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead) static ma_result ma_libvorbis_ds_read(ma_data_source* pDataSource, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead)
{ {
...@@ -135,11 +136,20 @@ static ma_result ma_libvorbis_init_internal(const ma_decoding_backend_config* pC ...@@ -135,11 +136,20 @@ static ma_result ma_libvorbis_init_internal(const ma_decoding_backend_config* pC
return result; /* Failed to initialize the base data source. */ return result; /* Failed to initialize the base data source. */
} }
pVorbis->vf = (OggVorbis_File*)ma_malloc(sizeof(OggVorbis_File), pAllocationCallbacks); #if !defined(MA_NO_LIBVORBIS)
if (pVorbis->vf == NULL) { {
ma_data_source_uninit(&pVorbis->ds); pVorbis->vf = (OggVorbis_File*)ma_malloc(sizeof(OggVorbis_File), pAllocationCallbacks);
return MA_OUT_OF_MEMORY; if (pVorbis->vf == NULL) {
ma_data_source_uninit(&pVorbis->ds);
return MA_OUT_OF_MEMORY;
}
}
#else
{
/* libvorbis is disabled. */
return MA_NOT_IMPLEMENTED;
} }
#endif
return MA_SUCCESS; return MA_SUCCESS;
} }
...@@ -236,7 +246,7 @@ MA_API void ma_libvorbis_uninit(ma_libvorbis* pVorbis, const ma_allocation_callb ...@@ -236,7 +246,7 @@ MA_API void ma_libvorbis_uninit(ma_libvorbis* pVorbis, const ma_allocation_callb
#else #else
{ {
/* libvorbis is disabled. Should never hit this since initialization would have failed. */ /* libvorbis is disabled. Should never hit this since initialization would have failed. */
MA_ASSERT(MA_FALSE); assert(MA_FALSE);
} }
#endif #endif
...@@ -327,7 +337,7 @@ MA_API ma_result ma_libvorbis_read_pcm_frames(ma_libvorbis* pVorbis, void* pFram ...@@ -327,7 +337,7 @@ MA_API ma_result ma_libvorbis_read_pcm_frames(ma_libvorbis* pVorbis, void* pFram
#else #else
{ {
/* libvorbis is disabled. Should never hit this since initialization would have failed. */ /* libvorbis is disabled. Should never hit this since initialization would have failed. */
MA_ASSERT(MA_FALSE); assert(MA_FALSE);
(void)pFramesOut; (void)pFramesOut;
(void)frameCount; (void)frameCount;
...@@ -362,7 +372,7 @@ MA_API ma_result ma_libvorbis_seek_to_pcm_frame(ma_libvorbis* pVorbis, ma_uint64 ...@@ -362,7 +372,7 @@ MA_API ma_result ma_libvorbis_seek_to_pcm_frame(ma_libvorbis* pVorbis, ma_uint64
#else #else
{ {
/* libvorbis is disabled. Should never hit this since initialization would have failed. */ /* libvorbis is disabled. Should never hit this since initialization would have failed. */
MA_ASSERT(MA_FALSE); assert(MA_FALSE);
(void)frameIndex; (void)frameIndex;
...@@ -419,7 +429,7 @@ MA_API ma_result ma_libvorbis_get_data_format(ma_libvorbis* pVorbis, ma_format* ...@@ -419,7 +429,7 @@ MA_API ma_result ma_libvorbis_get_data_format(ma_libvorbis* pVorbis, ma_format*
#else #else
{ {
/* libvorbis is disabled. Should never hit this since initialization would have failed. */ /* libvorbis is disabled. Should never hit this since initialization would have failed. */
MA_ASSERT(MA_FALSE); assert(MA_FALSE);
return MA_NOT_IMPLEMENTED; return MA_NOT_IMPLEMENTED;
} }
#endif #endif
...@@ -451,7 +461,7 @@ MA_API ma_result ma_libvorbis_get_cursor_in_pcm_frames(ma_libvorbis* pVorbis, ma ...@@ -451,7 +461,7 @@ MA_API ma_result ma_libvorbis_get_cursor_in_pcm_frames(ma_libvorbis* pVorbis, ma
#else #else
{ {
/* libvorbis is disabled. Should never hit this since initialization would have failed. */ /* libvorbis is disabled. Should never hit this since initialization would have failed. */
MA_ASSERT(MA_FALSE); assert(MA_FALSE);
return MA_NOT_IMPLEMENTED; return MA_NOT_IMPLEMENTED;
} }
#endif #endif
...@@ -479,10 +489,85 @@ MA_API ma_result ma_libvorbis_get_length_in_pcm_frames(ma_libvorbis* pVorbis, ma ...@@ -479,10 +489,85 @@ MA_API ma_result ma_libvorbis_get_length_in_pcm_frames(ma_libvorbis* pVorbis, ma
#else #else
{ {
/* libvorbis is disabled. Should never hit this since initialization would have failed. */ /* libvorbis is disabled. Should never hit this since initialization would have failed. */
MA_ASSERT(MA_FALSE); assert(MA_FALSE);
return MA_NOT_IMPLEMENTED; return MA_NOT_IMPLEMENTED;
} }
#endif #endif
} }
/*
The code below defines the vtable that you'll plug into your `ma_decoder_config` object.
*/
#if !defined(MA_NO_LIBVORBIS)
static ma_result ma_decoding_backend_init__libvorbis(void* pUserData, 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_data_source** ppBackend)
{
ma_result result;
ma_libvorbis* pVorbis;
(void)pUserData;
pVorbis = (ma_libvorbis*)ma_malloc(sizeof(*pVorbis), pAllocationCallbacks);
if (pVorbis == NULL) {
return MA_OUT_OF_MEMORY;
}
result = ma_libvorbis_init(onRead, onSeek, onTell, pReadSeekTellUserData, pConfig, pAllocationCallbacks, pVorbis);
if (result != MA_SUCCESS) {
ma_free(pVorbis, pAllocationCallbacks);
return result;
}
*ppBackend = pVorbis;
return MA_SUCCESS;
}
static ma_result ma_decoding_backend_init_file__libvorbis(void* pUserData, const char* pFilePath, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_data_source** ppBackend)
{
ma_result result;
ma_libvorbis* pVorbis;
(void)pUserData;
pVorbis = (ma_libvorbis*)ma_malloc(sizeof(*pVorbis), pAllocationCallbacks);
if (pVorbis == NULL) {
return MA_OUT_OF_MEMORY;
}
result = ma_libvorbis_init_file(pFilePath, pConfig, pAllocationCallbacks, pVorbis);
if (result != MA_SUCCESS) {
ma_free(pVorbis, pAllocationCallbacks);
return result;
}
*ppBackend = pVorbis;
return MA_SUCCESS;
}
static void ma_decoding_backend_uninit__libvorbis(void* pUserData, ma_data_source* pBackend, const ma_allocation_callbacks* pAllocationCallbacks)
{
ma_libvorbis* pVorbis = (ma_libvorbis*)pBackend;
(void)pUserData;
ma_libvorbis_uninit(pVorbis, pAllocationCallbacks);
ma_free(pVorbis, pAllocationCallbacks);
}
static ma_decoding_backend_vtable ma_gDecodingBackendVTable_libvorbis =
{
ma_decoding_backend_init__libvorbis,
ma_decoding_backend_init_file__libvorbis,
NULL, /* onInitFileW() */
NULL, /* onInitMemory() */
ma_decoding_backend_uninit__libvorbis
};
const ma_decoding_backend_vtable* ma_decoding_backend_libvorbis = &ma_gDecodingBackendVTable_libvorbis;
#else
const ma_decoding_backend_vtable* ma_decoding_backend_libvorbis = NULL;
#endif
#endif /* miniaudio_libvorbis_c */ #endif /* miniaudio_libvorbis_c */
...@@ -33,6 +33,9 @@ MA_API ma_result ma_libvorbis_get_data_format(ma_libvorbis* pVorbis, ma_format* ...@@ -33,6 +33,9 @@ MA_API ma_result ma_libvorbis_get_data_format(ma_libvorbis* pVorbis, ma_format*
MA_API ma_result ma_libvorbis_get_cursor_in_pcm_frames(ma_libvorbis* pVorbis, ma_uint64* pCursor); MA_API ma_result ma_libvorbis_get_cursor_in_pcm_frames(ma_libvorbis* pVorbis, ma_uint64* pCursor);
MA_API ma_result ma_libvorbis_get_length_in_pcm_frames(ma_libvorbis* pVorbis, ma_uint64* pLength); MA_API ma_result ma_libvorbis_get_length_in_pcm_frames(ma_libvorbis* pVorbis, ma_uint64* pLength);
/* Decoding backend vtable. This is what you'll plug into ma_decoder_config.pBackendVTables. No user data required. */
extern const ma_decoding_backend_vtable* ma_decoding_backend_libvorbis;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -9955,7 +9955,7 @@ typedef struct ...@@ -9955,7 +9955,7 @@ typedef struct
ma_allocation_callbacks allocationCallbacks; ma_allocation_callbacks allocationCallbacks;
ma_encoding_format encodingFormat; ma_encoding_format encodingFormat;
ma_uint32 seekPointCount; /* When set to > 0, specifies the number of seek points to use for the generation of a seek table. Not all decoding backends support this. */ ma_uint32 seekPointCount; /* When set to > 0, specifies the number of seek points to use for the generation of a seek table. Not all decoding backends support this. */
ma_decoding_backend_vtable** ppCustomBackendVTables; const ma_decoding_backend_vtable** ppCustomBackendVTables;
ma_uint32 customBackendCount; ma_uint32 customBackendCount;
void* pCustomBackendUserData; void* pCustomBackendUserData;
} ma_decoder_config; } ma_decoder_config;
...@@ -10482,7 +10482,7 @@ typedef struct ...@@ -10482,7 +10482,7 @@ typedef struct
ma_uint32 jobQueueCapacity; /* The maximum number of jobs that can fit in the queue at a time. Defaults to MA_JOB_TYPE_RESOURCE_MANAGER_QUEUE_CAPACITY. Cannot be zero. */ ma_uint32 jobQueueCapacity; /* The maximum number of jobs that can fit in the queue at a time. Defaults to MA_JOB_TYPE_RESOURCE_MANAGER_QUEUE_CAPACITY. Cannot be zero. */
ma_uint32 flags; ma_uint32 flags;
ma_vfs* pVFS; /* Can be NULL in which case defaults will be used. */ ma_vfs* pVFS; /* Can be NULL in which case defaults will be used. */
ma_decoding_backend_vtable** ppCustomDecodingBackendVTables; const ma_decoding_backend_vtable** ppCustomDecodingBackendVTables;
ma_uint32 customDecodingBackendCount; ma_uint32 customDecodingBackendCount;
void* pCustomDecodingBackendUserData; void* pCustomDecodingBackendUserData;
} ma_resource_manager_config; } ma_resource_manager_config;
...@@ -68274,8 +68274,9 @@ MA_API ma_result ma_resource_manager_init(const ma_resource_manager_config* pCon ...@@ -68274,8 +68274,9 @@ MA_API ma_result ma_resource_manager_init(const ma_resource_manager_config* pCon
/* Custom decoding backends. */ /* Custom decoding backends. */
if (pConfig->ppCustomDecodingBackendVTables != NULL && pConfig->customDecodingBackendCount > 0) { if (pConfig->ppCustomDecodingBackendVTables != NULL && pConfig->customDecodingBackendCount > 0) {
size_t sizeInBytes = sizeof(*pResourceManager->config.ppCustomDecodingBackendVTables) * pConfig->customDecodingBackendCount; size_t sizeInBytes = sizeof(*pResourceManager->config.ppCustomDecodingBackendVTables) * pConfig->customDecodingBackendCount;
ma_decoding_backend_vtable** ppCustomDecodingBackendVTables;
pResourceManager->config.ppCustomDecodingBackendVTables = (ma_decoding_backend_vtable**)ma_malloc(sizeInBytes, &pResourceManager->config.allocationCallbacks); ppCustomDecodingBackendVTables = (ma_decoding_backend_vtable**)ma_malloc(sizeInBytes, &pResourceManager->config.allocationCallbacks);
if (pResourceManager->config.ppCustomDecodingBackendVTables == NULL) { if (pResourceManager->config.ppCustomDecodingBackendVTables == NULL) {
ma_job_queue_uninit(&pResourceManager->jobQueue, &pResourceManager->config.allocationCallbacks); ma_job_queue_uninit(&pResourceManager->jobQueue, &pResourceManager->config.allocationCallbacks);
return MA_OUT_OF_MEMORY; return MA_OUT_OF_MEMORY;
...@@ -68283,6 +68284,7 @@ MA_API ma_result ma_resource_manager_init(const ma_resource_manager_config* pCon ...@@ -68283,6 +68284,7 @@ MA_API ma_result ma_resource_manager_init(const ma_resource_manager_config* pCon
MA_COPY_MEMORY(pResourceManager->config.ppCustomDecodingBackendVTables, pConfig->ppCustomDecodingBackendVTables, sizeInBytes); MA_COPY_MEMORY(pResourceManager->config.ppCustomDecodingBackendVTables, pConfig->ppCustomDecodingBackendVTables, sizeInBytes);
pResourceManager->config.ppCustomDecodingBackendVTables = (const ma_decoding_backend_vtable**)ppCustomDecodingBackendVTables;
pResourceManager->config.customDecodingBackendCount = pConfig->customDecodingBackendCount; pResourceManager->config.customDecodingBackendCount = pConfig->customDecodingBackendCount;
pResourceManager->config.pCustomDecodingBackendUserData = pConfig->pCustomDecodingBackendUserData; pResourceManager->config.pCustomDecodingBackendUserData = pConfig->pCustomDecodingBackendUserData;
} }
...@@ -68386,7 +68388,7 @@ MA_API void ma_resource_manager_uninit(ma_resource_manager* pResourceManager) ...@@ -68386,7 +68388,7 @@ MA_API void ma_resource_manager_uninit(ma_resource_manager* pResourceManager)
#endif #endif
} }
ma_free(pResourceManager->config.ppCustomDecodingBackendVTables, &pResourceManager->config.allocationCallbacks); ma_free((ma_decoding_backend_vtable**)pResourceManager->config.ppCustomDecodingBackendVTables, &pResourceManager->config.allocationCallbacks); /* <-- Naughty const-cast, but this is safe. */
if (pResourceManager->config.pLog == &pResourceManager->log) { if (pResourceManager->config.pLog == &pResourceManager->log) {
ma_log_uninit(&pResourceManager->log); ma_log_uninit(&pResourceManager->log);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment