Commit 23993590 authored by David Reid's avatar David Reid

API CHANGE: Update ma_decoder_get_length_in_pcm_frames().

This is now consistent with all other data sources:

  * Returns a result code
  * Length is returned via an output parameter
parent 619822e1
...@@ -6249,7 +6249,7 @@ For MP3's, this will decode the entire file. Do not call this in time critical s ...@@ -6249,7 +6249,7 @@ For MP3's, this will decode the entire file. Do not call this in time critical s
This function is not thread safe without your own synchronization. This function is not thread safe without your own synchronization.
*/ */
MA_API ma_uint64 ma_decoder_get_length_in_pcm_frames(ma_decoder* pDecoder); MA_API ma_result ma_decoder_get_length_in_pcm_frames(ma_decoder* pDecoder, ma_uint64* pLength);
/* /*
Reads PCM frames from the given decoder. Reads PCM frames from the given decoder.
...@@ -49623,12 +49623,7 @@ static ma_result ma_decoder__data_source_on_get_length(ma_data_source* pDataSour ...@@ -49623,12 +49623,7 @@ static ma_result ma_decoder__data_source_on_get_length(ma_data_source* pDataSour
{ {
ma_decoder* pDecoder = (ma_decoder*)pDataSource; ma_decoder* pDecoder = (ma_decoder*)pDataSource;
*pLength = ma_decoder_get_length_in_pcm_frames(pDecoder); return ma_decoder_get_length_in_pcm_frames(pDecoder, pLength);
if (*pLength == 0) {
return MA_NOT_IMPLEMENTED;
}
return MA_SUCCESS;
} }
static ma_data_source_vtable g_ma_decoder_data_source_vtable = static ma_data_source_vtable g_ma_decoder_data_source_vtable =
...@@ -50413,32 +50408,43 @@ MA_API ma_result ma_decoder_get_cursor_in_pcm_frames(ma_decoder* pDecoder, ma_ui ...@@ -50413,32 +50408,43 @@ MA_API ma_result ma_decoder_get_cursor_in_pcm_frames(ma_decoder* pDecoder, ma_ui
return MA_SUCCESS; return MA_SUCCESS;
} }
MA_API ma_uint64 ma_decoder_get_length_in_pcm_frames(ma_decoder* pDecoder) MA_API ma_result ma_decoder_get_length_in_pcm_frames(ma_decoder* pDecoder, ma_uint64* pLength)
{ {
if (pLength == NULL) {
return MA_INVALID_ARGS;
}
*pLength = 0;
if (pDecoder == NULL) { if (pDecoder == NULL) {
return 0; return MA_INVALID_ARGS;
} }
if (pDecoder->pBackend != NULL) { if (pDecoder->pBackend != NULL) {
ma_result result; ma_result result;
ma_uint64 nativeLengthInPCMFrames; ma_uint64 internalLengthInPCMFrames;
ma_uint32 internalSampleRate; ma_uint32 internalSampleRate;
ma_data_source_get_length_in_pcm_frames(pDecoder->pBackend, &nativeLengthInPCMFrames); result = ma_data_source_get_length_in_pcm_frames(pDecoder->pBackend, &internalLengthInPCMFrames);
if (result != MA_SUCCESS) {
return result; /* Failed to retrieve the internal length. */
}
result = ma_data_source_get_data_format(pDecoder->pBackend, NULL, NULL, &internalSampleRate); result = ma_data_source_get_data_format(pDecoder->pBackend, NULL, NULL, &internalSampleRate);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return 0; /* Failed to retrieve the internal sample rate. */ return result; /* Failed to retrieve the internal sample rate. */
} }
if (internalSampleRate == pDecoder->outputSampleRate) { if (internalSampleRate == pDecoder->outputSampleRate) {
return nativeLengthInPCMFrames; *pLength = internalLengthInPCMFrames;
} else { } else {
return ma_calculate_frame_count_after_resampling(pDecoder->outputSampleRate, internalSampleRate, nativeLengthInPCMFrames); *pLength = ma_calculate_frame_count_after_resampling(pDecoder->outputSampleRate, internalSampleRate, internalLengthInPCMFrames);
} }
}
return 0; return MA_SUCCESS;
} else {
return MA_NO_BACKEND;
}
} }
MA_API ma_uint64 ma_decoder_read_pcm_frames(ma_decoder* pDecoder, void* pFramesOut, ma_uint64 frameCount) MA_API ma_uint64 ma_decoder_read_pcm_frames(ma_decoder* pDecoder, void* pFramesOut, ma_uint64 frameCount)
...@@ -50571,6 +50577,7 @@ MA_API ma_result ma_decoder_seek_to_pcm_frame(ma_decoder* pDecoder, ma_uint64 fr ...@@ -50571,6 +50577,7 @@ MA_API ma_result ma_decoder_seek_to_pcm_frame(ma_decoder* pDecoder, ma_uint64 fr
MA_API ma_result ma_decoder_get_available_frames(ma_decoder* pDecoder, ma_uint64* pAvailableFrames) MA_API ma_result ma_decoder_get_available_frames(ma_decoder* pDecoder, ma_uint64* pAvailableFrames)
{ {
ma_result result;
ma_uint64 totalFrameCount; ma_uint64 totalFrameCount;
if (pAvailableFrames == NULL) { if (pAvailableFrames == NULL) {
...@@ -50583,9 +50590,9 @@ MA_API ma_result ma_decoder_get_available_frames(ma_decoder* pDecoder, ma_uint64 ...@@ -50583,9 +50590,9 @@ MA_API ma_result ma_decoder_get_available_frames(ma_decoder* pDecoder, ma_uint64
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
} }
totalFrameCount = ma_decoder_get_length_in_pcm_frames(pDecoder); result = ma_decoder_get_length_in_pcm_frames(pDecoder, &totalFrameCount);
if (totalFrameCount == 0) { if (result != MA_SUCCESS) {
return MA_NOT_IMPLEMENTED; return result;
} }
if (totalFrameCount <= pDecoder->readPointerInPCMFrames) { if (totalFrameCount <= pDecoder->readPointerInPCMFrames) {
...@@ -50594,7 +50601,7 @@ MA_API ma_result ma_decoder_get_available_frames(ma_decoder* pDecoder, ma_uint64 ...@@ -50594,7 +50601,7 @@ MA_API ma_result ma_decoder_get_available_frames(ma_decoder* pDecoder, ma_uint64
*pAvailableFrames = totalFrameCount - pDecoder->readPointerInPCMFrames; *pAvailableFrames = totalFrameCount - pDecoder->readPointerInPCMFrames;
} }
return MA_SUCCESS; /* No frames available. */ return MA_SUCCESS;
} }
...@@ -7736,7 +7736,11 @@ static ma_result ma_resource_manager_data_buffer_node_init_supply_decoded(ma_res ...@@ -7736,7 +7736,11 @@ static ma_result ma_resource_manager_data_buffer_node_init_supply_decoded(ma_res
allocated buffer, whereas a paged buffer is a linked list of paged-sized buffers. The latter allocated buffer, whereas a paged buffer is a linked list of paged-sized buffers. The latter
is used when the length of a sound is unknown until a full decode has been performed. is used when the length of a sound is unknown until a full decode has been performed.
*/ */
totalFrameCount = ma_decoder_get_length_in_pcm_frames(pDecoder); result = ma_decoder_get_length_in_pcm_frames(pDecoder, &totalFrameCount);
if (result != MA_SUCCESS) {
return result;
}
if (totalFrameCount > 0) { if (totalFrameCount > 0) {
/* It's a known length. The data supply is a regular decoded buffer. */ /* It's a known length. The data supply is a regular decoded buffer. */
ma_uint64 dataSizeInBytes; ma_uint64 dataSizeInBytes;
...@@ -10200,7 +10204,10 @@ static ma_result ma_resource_manager_process_job__load_data_stream(ma_resource_m ...@@ -10200,7 +10204,10 @@ static ma_result ma_resource_manager_process_job__load_data_stream(ma_resource_m
} }
/* Retrieve the total length of the file before marking the decoder are loaded. */ /* Retrieve the total length of the file before marking the decoder are loaded. */
pDataStream->totalLengthInPCMFrames = ma_decoder_get_length_in_pcm_frames(&pDataStream->decoder); result = ma_decoder_get_length_in_pcm_frames(&pDataStream->decoder, &pDataStream->totalLengthInPCMFrames);
if (result != MA_SUCCESS) {
goto done; /* Failed to retrieve the length. */
}
/* /*
Only mark the decoder as initialized when the length of the decoder has been retrieved because that can possibly require a scan over the whole file Only mark the decoder as initialized when the length of the decoder has been retrieved because that can possibly require a scan over the whole file
......
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