Commit 85cd9c18 authored by David Reid's avatar David Reid

Fix a bug with ma_resource_manager_data_stream relating to seeking.

parent d5ba8460
...@@ -7268,6 +7268,16 @@ MA_API ma_result ma_resource_manager_data_stream_map(ma_resource_manager_data_st ...@@ -7268,6 +7268,16 @@ MA_API ma_result ma_resource_manager_data_stream_map(ma_resource_manager_data_st
return MA_SUCCESS; return MA_SUCCESS;
} }
static void ma_resource_manager_data_stream_set_absolute_cursor(ma_resource_manager_data_stream* pDataStream, ma_uint64 absoluteCursor)
{
/* Loop if possible. */
if (absoluteCursor > pDataStream->totalLengthInPCMFrames && pDataStream->totalLengthInPCMFrames > 0) {
absoluteCursor = absoluteCursor % pDataStream->totalLengthInPCMFrames;
}
c89atomic_exchange_64(&pDataStream->absoluteCursor, absoluteCursor);
}
MA_API ma_result ma_resource_manager_data_stream_unmap(ma_resource_manager_data_stream* pDataStream, ma_uint64 frameCount) MA_API ma_result ma_resource_manager_data_stream_unmap(ma_resource_manager_data_stream* pDataStream, ma_uint64 frameCount)
{ {
ma_uint32 newRelativeCursor; ma_uint32 newRelativeCursor;
...@@ -7292,11 +7302,8 @@ MA_API ma_result ma_resource_manager_data_stream_unmap(ma_resource_manager_data_ ...@@ -7292,11 +7302,8 @@ MA_API ma_result ma_resource_manager_data_stream_unmap(ma_resource_manager_data_
pageSizeInFrames = ma_resource_manager_data_stream_get_page_size_in_frames(pDataStream); pageSizeInFrames = ma_resource_manager_data_stream_get_page_size_in_frames(pDataStream);
/* The absolute cursor needs to be updated. We want to make sure to loop if possible. */ /* The absolute cursor needs to be updated for ma_resource_manager_data_stream_get_cursor_in_pcm_frames(). */
pDataStream->absoluteCursor += frameCount; ma_resource_manager_data_stream_set_absolute_cursor(pDataStream, c89atomic_load_64(&pDataStream->absoluteCursor) + frameCount);
if (pDataStream->absoluteCursor > pDataStream->totalLengthInPCMFrames && pDataStream->totalLengthInPCMFrames > 0) {
pDataStream->absoluteCursor = pDataStream->absoluteCursor % pDataStream->totalLengthInPCMFrames;
}
/* Here is where we need to check if we need to load a new page, and if so, post a job to load it. */ /* Here is where we need to check if we need to load a new page, and if so, post a job to load it. */
newRelativeCursor = pDataStream->relativeCursor + (ma_uint32)frameCount; newRelativeCursor = pDataStream->relativeCursor + (ma_uint32)frameCount;
...@@ -7346,6 +7353,9 @@ MA_API ma_result ma_resource_manager_data_stream_seek_to_pcm_frame(ma_resource_m ...@@ -7346,6 +7353,9 @@ MA_API ma_result ma_resource_manager_data_stream_seek_to_pcm_frame(ma_resource_m
/* Increment the seek counter first to indicate to read_paged_pcm_frames() and map_paged_pcm_frames() that we are in the middle of a seek and MA_BUSY should be returned. */ /* Increment the seek counter first to indicate to read_paged_pcm_frames() and map_paged_pcm_frames() that we are in the middle of a seek and MA_BUSY should be returned. */
c89atomic_fetch_add_32(&pDataStream->seekCounter, 1); c89atomic_fetch_add_32(&pDataStream->seekCounter, 1);
/* Update the absolute cursor so that ma_resource_manager_data_stream_get_cursor_in_pcm_frames() returns the new position. */
ma_resource_manager_data_stream_set_absolute_cursor(pDataStream, frameIndex);
/* /*
We need to clear our currently loaded pages so that the stream starts playback from the new seek point as soon as possible. These are for the purpose of the public We need to clear our currently loaded pages so that the stream starts playback from the new seek point as soon as possible. These are for the purpose of the public
API and will be ignored by the seek job. The seek job will operate on the assumption that both pages have been marked as invalid and the cursor is at the start of API and will be ignored by the seek job. The seek job will operate on the assumption that both pages have been marked as invalid and the cursor is at the start of
......
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