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.
This commit is contained in:
Grigori Goronzy 2009-09-09 03:24:34 +00:00
parent 9d0daf6821
commit 5ab1eab906

View file

@ -90,6 +90,12 @@ void OSSPlayer::OpenStream()
throw _T("OSS player: opening device failed"); 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 // Set number of channels
int channels = provider->GetChannels(); int channels = provider->GetChannels();
if (ioctl(dspdev, SNDCTL_DSP_CHANNELS, &channels) < 0) { if (ioctl(dspdev, SNDCTL_DSP_CHANNELS, &channels) < 0) {
@ -214,6 +220,13 @@ bool OSSPlayer::IsPlaying()
void OSSPlayer::SetEndPosition(int64_t pos) void OSSPlayer::SetEndPosition(int64_t pos)
{ {
end_frame = pos; end_frame = pos;
if (end_frame <= GetCurrentPosition()) {
ioctl(dspdev, SNDCTL_DSP_RESET, NULL);
if (thread && thread->IsAlive())
thread->Delete();
}
} }