mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-24 09:14:04 +02:00
Restructuring in preparation for future work.
This commit is contained in:
+41
-20
@@ -46654,7 +46654,7 @@ static ma_result ma_decoder__init_data_converter(ma_decoder* pDecoder, const ma_
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Custom decoders. */
|
|
||||||
static ma_result ma_decoder_internal_on_read__custom(void* pUserData, void* pBufferOut, size_t bytesToRead, size_t* pBytesRead)
|
static ma_result ma_decoder_internal_on_read__custom(void* pUserData, void* pBufferOut, size_t bytesToRead, size_t* pBytesRead)
|
||||||
{
|
{
|
||||||
ma_decoder* pDecoder = (ma_decoder*)pUserData;
|
ma_decoder* pDecoder = (ma_decoder*)pUserData;
|
||||||
@@ -46679,31 +46679,29 @@ static ma_result ma_decoder_internal_on_tell__custom(void* pUserData, ma_int64*
|
|||||||
return ma_decoder_tell_bytes(pDecoder, pCursor);
|
return ma_decoder_tell_bytes(pDecoder, pCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ma_result ma_decoder_init_custom__internal(const ma_decoder_config* pConfig, ma_decoder* pDecoder)
|
|
||||||
{
|
|
||||||
ma_result result = MA_NO_BACKEND;
|
|
||||||
ma_data_source* pBackend;
|
|
||||||
ma_decoding_backend_config backendConfig;
|
|
||||||
size_t ivtable;
|
|
||||||
|
|
||||||
|
static ma_result ma_decoder_init_from_vtable(const ma_decoding_backend_vtable* pVTable, void* pVTableUserData, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
|
||||||
|
{
|
||||||
|
ma_result result;
|
||||||
|
ma_decoding_backend_config backendConfig;
|
||||||
|
ma_data_source* pBackend;
|
||||||
|
|
||||||
|
MA_ASSERT(pVTable != NULL);
|
||||||
MA_ASSERT(pConfig != NULL);
|
MA_ASSERT(pConfig != NULL);
|
||||||
MA_ASSERT(pDecoder != NULL);
|
MA_ASSERT(pDecoder != NULL);
|
||||||
|
|
||||||
(void)pConfig;
|
if (pVTable->onInit == NULL) {
|
||||||
|
return MA_NOT_IMPLEMENTED;
|
||||||
if (pConfig->ppCustomBackendVTables == NULL) {
|
|
||||||
return MA_NO_BACKEND;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
backendConfig = ma_decoding_backend_config_init(pConfig->format);
|
backendConfig = ma_decoding_backend_config_init(pConfig->format);
|
||||||
|
|
||||||
/* The order each backend is listed is what defines the priority. */
|
result = pVTable->onInit(pVTableUserData, ma_decoder_internal_on_read__custom, ma_decoder_internal_on_seek__custom, ma_decoder_internal_on_tell__custom, pDecoder, &backendConfig, &pDecoder->allocationCallbacks, &pBackend);
|
||||||
for (ivtable = 0; ivtable < pConfig->customBackendCount; ivtable += 1) {
|
if (result != MA_SUCCESS) {
|
||||||
const ma_decoding_backend_vtable* pVTable = pConfig->ppCustomBackendVTables[ivtable];
|
return result; /* Failed to initialize the backend from this vtable. */
|
||||||
if (pVTable != NULL && pVTable->onInit != NULL) {
|
}
|
||||||
result = pVTable->onInit(pConfig->pCustomBackendUserData, ma_decoder_internal_on_read__custom, ma_decoder_internal_on_seek__custom, ma_decoder_internal_on_tell__custom, pDecoder, &backendConfig, &pDecoder->allocationCallbacks, &pBackend);
|
|
||||||
if (result == MA_SUCCESS) {
|
/* Getting here means we were able to initialize the backend so we can now initialize the decoder. */
|
||||||
/* We found our decoding backend. Now we just need to set up some stuff in the decoder. */
|
|
||||||
pDecoder->pBackend = pBackend;
|
pDecoder->pBackend = pBackend;
|
||||||
pDecoder->pBackendVTable = pVTable;
|
pDecoder->pBackendVTable = pVTable;
|
||||||
pDecoder->pBackendUserData = pConfig->pCustomBackendUserData;
|
pDecoder->pBackendUserData = pConfig->pCustomBackendUserData;
|
||||||
@@ -46717,16 +46715,39 @@ static ma_result ma_decoder_init_custom__internal(const ma_decoder_config* pConf
|
|||||||
ma_get_standard_channel_map(ma_standard_channel_map_default, ma_min(pDecoder->internalChannels, ma_countof(pDecoder->internalChannelMap)), pDecoder->internalChannelMap);
|
ma_get_standard_channel_map(ma_standard_channel_map_default, ma_min(pDecoder->internalChannels, ma_countof(pDecoder->internalChannelMap)), pDecoder->internalChannelMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return MA_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static ma_result ma_decoder_init_custom__internal(const ma_decoder_config* pConfig, ma_decoder* pDecoder)
|
||||||
|
{
|
||||||
|
ma_result result = MA_NO_BACKEND;
|
||||||
|
size_t ivtable;
|
||||||
|
|
||||||
|
MA_ASSERT(pConfig != NULL);
|
||||||
|
MA_ASSERT(pDecoder != NULL);
|
||||||
|
|
||||||
|
if (pConfig->ppCustomBackendVTables == NULL) {
|
||||||
|
return MA_NO_BACKEND;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The order each backend is listed is what defines the priority. */
|
||||||
|
for (ivtable = 0; ivtable < pConfig->customBackendCount; ivtable += 1) {
|
||||||
|
const ma_decoding_backend_vtable* pVTable = pConfig->ppCustomBackendVTables[ivtable];
|
||||||
|
if (pVTable != NULL && pVTable->onInit != NULL) {
|
||||||
|
result = ma_decoder_init_from_vtable(pVTable, pConfig->pCustomBackendUserData, pConfig, pDecoder);
|
||||||
|
if (result == MA_SUCCESS) {
|
||||||
return MA_SUCCESS;
|
return MA_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
/* Initialization failed. Move on to the next one, but seek back to the start. */
|
/* Initialization failed. Move on to the next one, but seek back to the start first so the next vtable starts from the first byte of the file. */
|
||||||
result = ma_decoder_seek_bytes(pDecoder, 0, ma_seek_origin_start);
|
result = ma_decoder_seek_bytes(pDecoder, 0, ma_seek_origin_start);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
return result; /* Failed to seek back to the start. */
|
return result; /* Failed to seek back to the start. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* No onInit callback. */
|
/* No vtable. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user