fix: correct buffering unpause condition to check buffer coverage#393
fix: correct buffering unpause condition to check buffer coverage#393nukes wants to merge 1 commit intoalnitak:mainfrom
Conversation
Changed the unpause condition from checking if new data >= margin to checking if buffer covers playback position + margin. This fixes play/pause toggling when seeking beyond buffered data. The old logic would unpause immediately after receiving enough new data, even if the playback position was still beyond the buffer.
|
Hi @nukes, by modifying the check like that, the If you tell me what your concerns are, we can try to see what can be done for buffering behavior. I cannot accept this change. |
|
Hi @alnitak I think my modification does consider the bufferingTimeNeeds. this fix mainly wants to solve the user seek beyond the current play position. which triggers the play&pause state switch incorrectly. Let me explain more carefully: Condition Before the Fix if (currBufferTime + addedDataTime - mParent->handle[i].bufferingTime >= mBufferingTimeNeeds && isPaused)Calculation: Meaning: Resume playback once the amount of data received since pause ≥ 2 seconds Problem Scenario: When paused: bufferingTime = 5s But the buffer only reaches 7s, while playback position is at 12s, still missing 5s of data! if (pos >= currBufferTime + addedDataTime && !isPaused)→ Causes immediate pause again → Repeated play/pause toggling Condition After the Fix if (currBufferTime + addedDataTime >= pos + mBufferingTimeNeeds && isPaused)Calculation: Meaning: Resume playback only when buffer covers playback position + 2 second margin Same Scenario: Check: 5s < 12s + 2s = 14s ✗ → Continue waiting Continue buffering... after buffering reaches 14s: Now the buffer covers playback position + 2s margin, playback is stable |
|
Hi @alnitak ,Any feedback ? |
|
This doesn't work for me. I've tried using the websocket example (read the note at the start of the code). It works using websocketd, which sends data to the example. If you set a
this is the correct behavior, I think. When the buffer reaches 7S, it means that the audio length is 7s ( The |
Got it, i will try to write a demo with seekbar to reproduce this issue. just give me some time. |
|
Hi @alnitak, Demo file (check the attached demo file, and rename to xxx.dart)How to reproducecd example
flutter run -d macos -t tests/buffering_bug_demo.dart
Expected: onBuffering(true) then onBuffering(false) once when buffer finally Actual: onBuffering toggles dozens of times until the buffer catches up to the seek position. Root cause In src/audiobuffer/audiobuffer.cpp, the checkBuffering() unpause condition is: if (currBufferTime + addedDataTime - mParent->handle[i].bufferingTime >= bufferingTime is recorded when the handle is paused, so this calculates how much new data has When seeking to 30s with only 10s buffered:
Fix Change the unpause condition from "new data >= margin" to "buffer covers playback position + // Before (buggy): // After (fixed): This way, the handle stays paused until the buffer actually reaches pos + margin (e.g. 30.5s), |
|
@nukes thank you for taking the time to provide the example. I realize now that I may not have fully understood the problem. This can be merged, but the root cause of this issue is when you seek beyond the length of the actual stream data. I think this should not be permitted (ie seek at 70s in your example). What are your thoughts? |
|
@alnitak In summary: streaming audio for simultaneously minimizing the latency and playback control should be considered in system. |
Description
Type of Change