Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

Video stutter when resuming it after pausing it. #54

Open
aroom opened this issue May 17, 2022 · 13 comments
Open

Video stutter when resuming it after pausing it. #54

aroom opened this issue May 17, 2022 · 13 comments

Comments

@aroom
Copy link

aroom commented May 17, 2022

System and IINA version:

Actual behavior:

Sometimes when I pause the video to check an email or safari on another desktop (4 fingers drag kind of desktop) the video will stutter when resuming it.

I have to quit IINA and start it again to fix the issue.

Steps to reproduce:

I don't know how to precisely reproduce it

  • pause the video
  • do something else
  • restart the video

How often does this happen?

Not really often. But I never had the issue before the 3-4 last versions.

@CarterLi
Copy link
Owner

M1 or Intel?

@aroom
Copy link
Author

aroom commented May 17, 2022 via email

@GreyAsteroid
Copy link

I'm also having this issue on my Intel system. One thing to note is that for me at least this only occurs sometimes when using my spacebar to play/pause. If I right click with my mouse to play/pause or click on the play/pause button this does not occur and if it is already happening then using right click or the play/pause button will stop it from happening.

@liu731
Copy link

liu731 commented May 18, 2022

I have the same problem,But only when using the SMB(2.0+ with multi channel) protocol. M1 Pro~

@CarterLi
Copy link
Owner

Did it ever happen on the official version? I have no idea what's going on.

@GreyAsteroid
Copy link

Alright, I looked into it some more and here's what I've found,

It can be triggered by any video file / video stream.
It only happens when using the the spacebar to use the cycle pause command.
It only happens when I've used a different method other than the spacebar to pause the video followed by using the spacebar to unpause.
Once the stuttering has happened the only way to stop it is to either restart IINA or play the paused video using something other than the spacebar.
While the stuttering is happening the log is getting filled with mpv_render_report_swap() not being called

Also, this is reproducible with the latest official nightly build.

@GreyAsteroid
Copy link

Alright, I found that the latest stable official build does not have this issue however the earliest available official nightly build does so that means it was caused by one of the 32 commits that happened between 2/5/21 and 12/13/21.

@GreyAsteroid
Copy link

Alright, learned how to compile IINA today and it looks like this issue is a side effect of iina#3538

@low-batt do you know why that code might be causing this issue?

@low-batt
Copy link
Collaborator

What that change is doing is stopping two threads that were needlessly running and therefore wasting battery while paused.
One thread updates the OSC. The other is a high priority thread that displays frames (display link).
I'm expecting it is the display link that is the issue.
One possibility is that the link needs to be started before resuming playback.
But I need to look into this and see what is actually happening.
Caught me very busy today, but will get to it soon.
Sorry about the regression!

@low-batt
Copy link
Collaborator

I just noticed this IINA issue: iina#3744
That is with IINA 1.2.0 which does not have the above change.
Seems like the change to conserve energy may have made an existing issue worse.

@GreyAsteroid
Copy link

I just noticed this IINA issue: iina#3744
That is with IINA 1.2.0 which does not have the above change.
Seems like the change to conserve energy may have made an existing issue worse.

I'm not too sure, that issue seems a bit different (resume taking a second vs constant stuttering after resume). Also when debugging this issue I tried removing mainWindow.videoView.startDisplayLink() from the resume function and voilà! this made right click resume and the pause/resume button behave the same way as the spacebar resume with the constant stuttering.

This leads me to believe that input.conf toggle pause for some reason is not using the proper pause/resume functions (therefore not calling mainWindow.videoView.startDisplayLink()) compared to the pause/resume button and right click resume which are or the resume function is just ignoring that call for the input.conf toggle pause for some reason.

However, while trying to look into this, all of a sudden I'm unable to reproduce this behavior with any build of IINA at all. With no change to any settings or reboot of my mac the issue has been completely fixed for me. Possibly because of the swapping between IINA builds? maybe? or this is a bug that can only be reproduced when CVDisplayLink has been confused? Boy would I love to know!

Regardless, good luck? 😅

@low-batt
Copy link
Collaborator

Late here and I'm fried, but I was unhappy that it seemed like I added a serious regression so I've been looking into this. I'm testing with one of the new 16" MacBook Pros with the M1 chip under macOS 12.3.1. I was pausing and resuming using using clicking on the window, pressing the space bar and clicking on the OSC control. All worked fine. I added debug logs. I added code to log the return codes from display link calls that were not being checked. All looked good. Tried over and over again. No issue. All worked fine.

I was about to give up and... some of the debug log messages stopped coming out. Pressing the space bar was no longer causing the IINA PlayerCore pause and resume methods to be called. At that point I used the OSC to pause playback. That caused the PlayerCore method to be called which shutdown the display link. Then I pressed space and playback resumed but since PlayerCore.resume was not called the link was not running, the video stuttered and mpv said:

[1152.763][v][vo/libmpv] mpv_render_report_swap() not being called.
[1153.028][v][vo/libmpv] mpv_render_report_swap() not being called.

This confirms exactly what @GreyAsteroid had already determined. My change in PR iina#3538 is definitely responsible for this regression. Both IINA and IINA+ need a fix.

Before I can fix this I need to figure out what is going on with key press handling. What is causing the behavior change? Will be tied up tomorrow but have time to get back to this on Friday.

Sorry again for the trouble! Thanks for all the work to trace this to my commit.

low-batt added a commit that referenced this issue May 24, 2022
This commit will:
- Add code to MPVController.handlePropertyChange to suspend/resume
  active systems not needed while paused
- Remove code added to PlayerCore methods pause and resume that
  attempted to manage these active systems

This corrects a regression added by PR iina#3538 that could cause playback
to stutter, due to the display link not being restarted. The original
fix failed when the OSC was used to pause playback, which went through
PlayerCore.pause and then playback was resumed using the space bar which
by-passed PlayerCore.resume, leaving the display link shutdown.
@low-batt
Copy link
Collaborator

Reproducing

  • Start a video playing
  • Pause playback by clicking on the button in the OSC
  • Resume playback by pressing the space key

Playback resumes, but video stutters.

Analysis

As already correctly determined above, this is a regression caused by PR iina#3538.

The change to shutdown systems that were needlessly running while paused was made in the PlayerCore pause and resume methods. Trouble is those methods are not always called. Key presses are directly processed by mpv, by passing PlayerCore.

Fixing

The code for pausing operations must be moved from PlayerCore to MPVController.handlePropertyChange and key off the value of the mpv property MPVOption.PlaybackControl.pause.


Fix is in the latest IINA+ build. Try it out and let me know if you encounter any issues.
I will be putting up a PR in the main IINA repository as this same regression is currently in the develop branch.

Thanks to all for reporting and tracking down my mistake!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants