Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call timeEndPeriod(1) when playback is stopped/paused on Windows #3421

Closed
DerpMcDerp opened this issue Aug 14, 2016 · 14 comments
Closed

Call timeEndPeriod(1) when playback is stopped/paused on Windows #3421

DerpMcDerp opened this issue Aug 14, 2016 · 14 comments
Labels
down-upstream features and bugs that need to be implemented and fixed upstream os:win

Comments

@DerpMcDerp
Copy link

It seems like mpv suffers from the problem documented in:

https://randomascii.wordpress.com/2013/07/08/windows-timer-resolution-megawatts-wasted/

timeBeginPeriod(1) gets called in mp_raw_time_init() on startup but timeEndPeriod(1) never gets called - not even when playback is stopped/paused.

I think a better scheme is to remove timeBeginPeriod(1) from mp_raw_time_init and add 2 more functions which get called when a stream starts playing and when a stream ends playing which gets forwarded to time(Begin|End)Period on Windows.

@ghost ghost added down-upstream features and bugs that need to be implemented and fixed upstream os:win labels Aug 15, 2016
@ghost
Copy link

ghost commented Aug 15, 2016

I don't feel particularly inclined to do anything about this. Although I wonder if we need the timer resolution at all.

@rossy opinions?

@sda89ha9
Copy link

sda89ha9 commented Aug 16, 2016

it seems windows increases timer resolution to 0.5ms while playing video using mpv, mpc-hc or vlc
timeBeginPeriod's 1ms resolution is only active while paused
so on my system timeBeginPeriod is useless

windows 10 AU
intel haswell
powercfg.exe -energy
timeBeginPeriod
timeBeginPeriod while PAUSED
without timeBeginPeriod
without timeBeginPeriod while PAUSED

@rossy
Copy link
Member

rossy commented Aug 16, 2016

Well, the timer resolution still affects the granularity of Sleep() on Windows 7 and 8.1, where the default granularity is 15.625ms. I haven't tested on 10 yet. On the other hand, timer resolution doesn't affect the granularity of QueryPerformanceCounter() and I don't think it affects when the WASAPI thread is woken by the audio subsystem or when the VO thread is woken up after VSync. It's hard to test this stuff though. There's a Java app running in the background on my PC right now that is pinning the timer frequency to 1ms.

@sda89ha9 That's strange. mpv never requests a timer frequency of 0.5ms itself, but it does activate some MMCSS profiles and apparently they can change the timer frequency, though they are not guaranteed to change it in Windows 7 and up (see https://msdn.microsoft.com/en-us/library/windows/desktop/ms684247.aspx) It could also be an audio or video driver that's making the request, which would explain why mpv, MPC-HC and VLC are affected. I can't repro on my computer (also, all the MMCSS profiles on my computer have "Clock Rate" set to 1ms.)

@sda89ha9
Copy link

mpv(lachs0r) --no-audio = timer interval: 1.001 ms
mpv(lachs0r) --no-video = timer interval: 0.500 ms
mpv(no timeBeginPeriod) --no-audio = timer interval: 15.625 ms
mpv(no timeBeginPeriod) --no-video = timer interval: 0.500 ms
same results with mpc-hc, vlc, wmp
playing audio increases timer resolution to 0.5ms, while video has no effect on timer resolution
probably windows 10 bug / feature

@ghost
Copy link

ghost commented Aug 16, 2016

I only see 2 places that indirectly call Sleep():

audio/out/ao_wasapi_utils.c
video/out/opengl/hwdec_dxva2egl.c

The latter one seems like it could be a problem if it sleeps as much as 16ms, though.

But what's more important is that the timer precision of SleepConditionVariable via pthread_cond_timedwait is probably influenced, which is used for non-display-sync video timing.

Potentially we could stuff timeBeginPeriod/timeEndPeriod in the same place we call the MMCSS API, but not sure if we should even care.

@pcenthusiast92
Copy link

This is very annoying for old platform games such counter strike 1.6 , it clearly says that, the game uses a high timer, but windows 10 is forcing the audio of the game to runs 0.5 ms :/

What can i do? i have A ryzen pc, and ryzen pc doesn't perform well on old microsoft....
foto1

@haasn
Copy link
Member

haasn commented Oct 19, 2017

i have A ryzen pc, and ryzen pc doesn't perform well on old microsoft....

Have you tried running CS 1.6 via WINE on Linux?

@Hrxn
Copy link
Contributor

Hrxn commented Oct 20, 2017

How about using CSGO?

Have you tried to use this Windows compatibility mode setting?

@ghost
Copy link

ghost commented Oct 20, 2017

What does this have to do with mpv?

@Hrxn
Copy link
Contributor

Hrxn commented Oct 20, 2017

I'd wager a guess.. nothing.

@pcenthusiast92
Copy link

@haasn To be honest no :O do you think thats posible on ryzen architecture?

And if that was the case, what would be the process to run cs 1.6? what are the requirements ?

Thank you.

@pcenthusiast92
Copy link

Because i'm tiring of have bad performance in games such counter strike 1.6 I don't know what i'm doing wrong, if something related to AMD bios in ryzen? all options seems to be in Auto, and i really don't know anything about AMD BIOS , i always use intel before, and.... to be honest in Google there is not such information that covered the whole bios in AMD or ryzen...

@garoto
Copy link
Contributor

garoto commented Oct 20, 2017

Try compiling mpv from source with latest ffmpeg, pretty sure it'll fix your issues.

@Hrxn
Copy link
Contributor

Hrxn commented Oct 21, 2017

But remember to compile mpv with --enable-cs16 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
down-upstream features and bugs that need to be implemented and fixed upstream os:win
Projects
None yet
Development

No branches or pull requests

8 participants