diff options
author | Tuomas Virtanen <katajakasa@gmail.com> | 2016-01-21 03:15:02 +0200 |
---|---|---|
committer | Tuomas Virtanen <katajakasa@gmail.com> | 2016-01-21 03:15:02 +0200 |
commit | e97b8b89d5b8e072859c4e9a948595fbce0be22c (patch) | |
tree | 711360bb3791f668ef01df732af00a3e4f9799b8 /examples | |
parent | 4be87201ba39d42a4aed12b68a0c2ee37705ccbe (diff) |
Get as much audio data in the video playback example as necessary
Diffstat (limited to 'examples')
-rw-r--r-- | examples/example_video.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/examples/example_video.c b/examples/example_video.c index 915cbe8..1f411ca 100644 --- a/examples/example_video.c +++ b/examples/example_video.c @@ -295,15 +295,21 @@ int main(int argc, char *argv[]) { gui_enabled = (mouse_y >= limit); // Refresh audio - ret = SDL_GetQueuedAudioSize(audio_dev); - if(ret < AUDIOBUFFER_SIZE) { - ret = Kit_GetAudioData(player, (unsigned char*)audiobuf, AUDIOBUFFER_SIZE, (size_t)ret); - if(ret > 0) { - SDL_LockAudio(); - SDL_QueueAudio(audio_dev, audiobuf, ret); - SDL_UnlockAudio(); - SDL_PauseAudioDevice(audio_dev, 0); + if(SDL_GetQueuedAudioSize(audio_dev) < AUDIOBUFFER_SIZE) { + int need = AUDIOBUFFER_SIZE - ret; + + SDL_LockAudio(); + while(need > 0) { + ret = Kit_GetAudioData(player, (unsigned char*)audiobuf, AUDIOBUFFER_SIZE, (size_t)SDL_GetQueuedAudioSize(audio_dev)); + need -= ret; + if(ret > 0) { + SDL_QueueAudio(audio_dev, audiobuf, ret); + } else { + break; + } } + SDL_UnlockAudio(); + SDL_PauseAudioDevice(audio_dev, 0); } // Clear screen with black |