summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorTuomas Virtanen <katajakasa@gmail.com>2018-06-20 01:15:00 +0300
committerTuomas Virtanen <katajakasa@gmail.com>2018-06-20 01:15:00 +0300
commite1c160951914428e30f044d16ffd9a564283a3c7 (patch)
tree28cb6618e749ec56743a75e89e9e2b0b9c795a73 /examples
parentbdb8a99e0c640875ca45e3a3cc98766fdedba77e (diff)
Miscellaneous seeking and locking bugfixes (ref issue #32)
Diffstat (limited to 'examples')
-rw-r--r--examples/example_audio.c8
-rw-r--r--examples/example_video.c13
2 files changed, 11 insertions, 10 deletions
diff --git a/examples/example_audio.c b/examples/example_audio.c
index 45cf43d..dae252a 100644
--- a/examples/example_audio.c
+++ b/examples/example_audio.c
@@ -125,13 +125,11 @@ int main(int argc, char *argv[]) {
}
// Refresh audio
- ret = SDL_GetQueuedAudioSize(audio_dev);
- if(ret < AUDIOBUFFER_SIZE) {
- ret = Kit_GetAudioData(player, (unsigned char*)audiobuf, AUDIOBUFFER_SIZE);
+ int queued = SDL_GetQueuedAudioSize(audio_dev);
+ if(queued < AUDIOBUFFER_SIZE) {
+ ret = Kit_GetAudioData(player, (unsigned char*)audiobuf, AUDIOBUFFER_SIZE - queued);
if(ret > 0) {
- SDL_LockAudio();
SDL_QueueAudio(audio_dev, audiobuf, ret);
- SDL_UnlockAudio();
}
}
diff --git a/examples/example_video.c b/examples/example_video.c
index 72467ab..cef613d 100644
--- a/examples/example_video.c
+++ b/examples/example_video.c
@@ -253,6 +253,7 @@ int main(int argc, char *argv[]) {
if(Kit_PlayerSeek(player, m_time) != 0) {
fprintf(stderr, "%s\n", Kit_GetError());
}
+ SDL_ClearQueuedAudio(audio_dev);
} else {
// Handle pause
if(Kit_GetPlayerState(player) == KIT_PAUSED) {
@@ -274,10 +275,10 @@ int main(int argc, char *argv[]) {
gui_enabled = (mouse_y >= limit);
// Refresh audio
- if(SDL_GetQueuedAudioSize(audio_dev) < AUDIOBUFFER_SIZE) {
- int need = AUDIOBUFFER_SIZE - ret;
+ int queued = SDL_GetQueuedAudioSize(audio_dev);
+ if(queued < AUDIOBUFFER_SIZE) {
+ int need = AUDIOBUFFER_SIZE - queued;
- SDL_LockAudio();
while(need > 0) {
ret = Kit_GetAudioData(
player,
@@ -290,8 +291,10 @@ int main(int argc, char *argv[]) {
break;
}
}
- SDL_UnlockAudio();
- SDL_PauseAudioDevice(audio_dev, 0);
+ // If we now have data, start playback (again)
+ if(SDL_GetQueuedAudioSize(audio_dev) > 0) {
+ SDL_PauseAudioDevice(audio_dev, 0);
+ }
}
// Clear screen with black