From 5ab1eab9061d5d1db01193deff1044531380a86c Mon Sep 17 00:00:00 2001 From: Grigori Goronzy Date: Wed, 9 Sep 2009 03:24:34 +0000 Subject: [PATCH] OSS player: handle changing end position correctly If the slider is moved to the playbar while the player is running, the playback needs to be stopped. Handle this situation properly. Additionally, select a low-latency buffer policy if possible (OSS4 only). This will make it possible to move the slide near the playbar without stopping playback (the current writing position is always in advance of the playback position by the buffer size!) Originally committed to SVN as r3498. --- aegisub/src/audio_player_oss.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/aegisub/src/audio_player_oss.cpp b/aegisub/src/audio_player_oss.cpp index 4db315160..b73ff1c0a 100644 --- a/aegisub/src/audio_player_oss.cpp +++ b/aegisub/src/audio_player_oss.cpp @@ -90,6 +90,12 @@ void OSSPlayer::OpenStream() throw _T("OSS player: opening device failed"); } + // Use a reasonable buffer policy for low latency (OSS4) +#ifdef SNDCTL_DSP_POLICY + int policy = 3; + ioctl(dspdev, SNDCTL_DSP_POLICY, &policy); +#endif + // Set number of channels int channels = provider->GetChannels(); if (ioctl(dspdev, SNDCTL_DSP_CHANNELS, &channels) < 0) { @@ -214,6 +220,13 @@ bool OSSPlayer::IsPlaying() void OSSPlayer::SetEndPosition(int64_t pos) { end_frame = pos; + + if (end_frame <= GetCurrentPosition()) { + ioctl(dspdev, SNDCTL_DSP_RESET, NULL); + if (thread && thread->IsAlive()) + thread->Delete(); + } + }