mirror of
https://github.com/libretro/gambatte-libretro.git
synced 2024-11-23 07:49:48 +00:00
350533a224
underruns are caused by video I/O blocking (even when not syncing to vblank). It also means that vsync blocking is a non-issue. Lots of thread-safety considerations had to be done. Lots of tools developed to deal with new problems. Things redesigned to be asynchronous to avoid blocking the worker thread. New interfaces developed to give clients access to these things without too much pain, as clients need to deal with thread-safety issues, and be able to do things asynchronously to avoid blocking and unnecessary synchronization. Things developed and then scrapped as I changed my mind. Lots of thinking and testing to ensure video smoothness. - Make configuration of the multimedia framework way more flexible, by adding methods for configuring video and sound, rather than forcing the use of the SoundDialog or VideoDialog. Thus clients can make their own GUI for such things. - Pass raw input events to MediaSources so that clients will not have to use the InputDialog with its Button system. - Split BlitterWidget blitting into three methods: blit, draw, and sync, such that blitting is supposedly a fast pixel copy or buffer swap, while draw prepares for presentation, and sync presents the completed video frame ASAP. Blit needs to be fast to avoid blocking the worker thread to avoid underruns. - Allow heavy MediaSource video work to be skipped when frames are skipped. - Do some work in parallel on SMP systems. - Adjust low audio buffer detection to make it more robust. - Move variance calculation to the user of estimations, because the variance calculated by estimators is not well defined anyway. - Add support for adjustable fast-forward speed. - Fast-forward now outputs audio, by skipping entire segments of audio when skipping frames. - Adjust blitters to conform to the new threaded model. - Direct3DBlitter: Apparently vertices point to the center of pixels. Subtract 0.5 from vertex coordinates. - DirectDrawBlitter: Sleep more when far from vblank. - QGLBlitter: Get rid of makeCurrent calls, because they apparently block and can be slow and don't seem to be needed anyway. They also seem to cause instability with some drivers. - XvBlitter: Double buffer to delay updates to sync time. - X11Blitter: Double buffer when not scaling to delay updates to sync time. - QPainterBlitter: Double buffer when not scaling to delay updates to sync time. - SdlBlitter: Delay updates to sync time. - AlsaEngine: Set max periods to 16 to work around stupid ALSA plugins and drivers that advertise smaller period sizes than properly supported. ALSA always picks the maximum number of periods allowed, which means it picks the smallest period size allowed for a given buffer size. - QPainterBlitter: Don't disable updates when not paused, because this breaks macx. - Support pause on focus out. - Add MiscDialog to allow user configuration of fast-forward speed and focus policy. - Separate sync to refresh rate logic from sync to vblank logic. - Sync to refresh rate menu option. - Use semi-bilinear filtering rather than bilinear filtering for soft-scaling blitters. - MakeSincKernel: Consider rounding effects when computing absolute gain. - MakeSincKernel: Use a function pointer rather than a template argument to reduce code bloat. - Reorder sinc kernel phases. - PolyPhaseConvoluter: Simplify some calculations. - Replace Hamming and Blackman windowed sincs with Kaiser windowed sinc of appropriate betas, because they require a lower number of taps to achieve the same specs. - Use rounding shifts in resamplers for higher precision and performance. - libgambatte: Update returns on video frame completion rather than using a callback for notification. - libgambatte: Move video filters and color conversion out of the library. - libgambatte: Get rid of unnecessarily complex VideoBlitter interface. - libgambatte: Use bit flags rather bools for input state. - Change some parameters to constants in 2xsai and hqx video filters. - Probably other stuff I've forgotten about. git-svn-id: https://gambatte.svn.sourceforge.net/svnroot/gambatte@234 9dfb2916-2d38-0410-aef4-c5fe6c9ffc24
57 lines
2.2 KiB
C++
57 lines
2.2 KiB
C++
/***************************************************************************
|
|
* Copyright (C) 2008 by Sindre Aamås *
|
|
* aamas@stud.ntnu.no *
|
|
* *
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License version 2 as *
|
|
* published by the Free Software Foundation. *
|
|
* *
|
|
* This program is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
* GNU General Public License version 2 for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* version 2 along with this program; if not, write to the *
|
|
* Free Software Foundation, Inc., *
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
***************************************************************************/
|
|
#include "adaptivesleep.h"
|
|
|
|
usec_t AdaptiveSleep::sleepUntil(usec_t base, usec_t inc) {
|
|
usec_t now = getusecs();
|
|
usec_t diff = now - base;
|
|
|
|
if (diff >= inc)
|
|
return diff - inc;
|
|
|
|
diff = inc - diff;
|
|
|
|
if (diff > oversleep + oversleepVar) {
|
|
diff -= oversleep + oversleepVar;
|
|
usecsleep(diff);
|
|
const usec_t ideal = now + diff;
|
|
now = getusecs();
|
|
|
|
{
|
|
usec_t curOversleep = now - ideal;
|
|
|
|
if (negate(curOversleep) < curOversleep)
|
|
curOversleep = 0;
|
|
|
|
oversleepVar = (oversleepVar * 15 + (curOversleep < oversleep ? oversleep - curOversleep : curOversleep - oversleep) + 8) >> 4;
|
|
oversleep = (oversleep * 15 + curOversleep + 8) >> 4;
|
|
}
|
|
|
|
noSleep = 60;
|
|
} else if (--noSleep == 0) {
|
|
noSleep = 60;
|
|
oversleep = oversleepVar = 0;
|
|
}
|
|
|
|
while (now - base < inc)
|
|
now = getusecs();
|
|
|
|
return 0;
|
|
}
|