mirror of
https://github.com/love2d/love.git
synced 2026-08-20 12:40:20 +02:00
Improve seeking, hopefully fix hangs on shutdown
Instead of returning the frame past our target, now return the frame for our target. Also defer to rewind implictly, rather than explicitly. Lastly, detect seeking past the end of the stream, and set EOS appropriately.
This commit is contained in:
@@ -266,13 +266,19 @@ void VideoStream::rewind()
|
|||||||
|
|
||||||
void VideoStream::seekDecoder(double target)
|
void VideoStream::seekDecoder(double target)
|
||||||
{
|
{
|
||||||
|
if (target < 0.01)
|
||||||
|
{
|
||||||
|
rewind();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
double low = 0;
|
double low = 0;
|
||||||
double high = file->getSize();
|
double high = file->getSize();
|
||||||
|
|
||||||
while (high-low > 0.0001)
|
while (high-low > 0.0001)
|
||||||
{
|
{
|
||||||
// Determine our next binary search position
|
// Determine our next binary search position
|
||||||
double pos = (high-low)/2+low;
|
double pos = (high+low)/2;
|
||||||
file->seek(pos);
|
file->seek(pos);
|
||||||
|
|
||||||
// Break sync
|
// Break sync
|
||||||
@@ -280,12 +286,18 @@ void VideoStream::seekDecoder(double target)
|
|||||||
ogg_sync_pageseek(&sync, &page);
|
ogg_sync_pageseek(&sync, &page);
|
||||||
|
|
||||||
// Read a packet
|
// Read a packet
|
||||||
readPacket(true);
|
readPacket(false);
|
||||||
|
if (eos)
|
||||||
|
return;
|
||||||
|
|
||||||
// Determine if this is the right place
|
// Determine if this is the right place
|
||||||
double curTime = th_granule_time(decoder, packet.granulepos);
|
double curTime = th_granule_time(decoder, packet.granulepos);
|
||||||
if (curTime > target && th_granule_time(decoder, packet.granulepos-1) < target)
|
double nextTime = th_granule_time(decoder, packet.granulepos+1);
|
||||||
break;
|
|
||||||
|
if (curTime == -1)
|
||||||
|
continue; // Invalid granule position (magic?)
|
||||||
|
else if (curTime <= target && nextTime > target)
|
||||||
|
break; // the current frame should be displaying right now
|
||||||
else if (curTime > target)
|
else if (curTime > target)
|
||||||
high = pos;
|
high = pos;
|
||||||
else
|
else
|
||||||
@@ -306,12 +318,7 @@ void VideoStream::threadedFillBackBuffer(double dt)
|
|||||||
|
|
||||||
// Seeking backwards
|
// Seeking backwards
|
||||||
if (position < lastFrame)
|
if (position < lastFrame)
|
||||||
{
|
seekDecoder(position);
|
||||||
if (position < 0.01)
|
|
||||||
rewind();
|
|
||||||
else
|
|
||||||
seekDecoder(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we're at the end of the stream, or if we're displaying the right frame
|
// If we're at the end of the stream, or if we're displaying the right frame
|
||||||
// stop here
|
// stop here
|
||||||
|
|||||||
Reference in New Issue
Block a user