mirror of
				https://github.com/yattee/yattee.git
				synced 2025-11-03 22:22:02 +00:00 
			
		
		
		
	tweaked A/V-sync for MPV
Signed-off-by: Toni Förster <toni.foerster@gmail.com>
This commit is contained in:
		
				
					committed by
					
						
						Toni Förster
					
				
			
			
				
	
			
			
			
						parent
						
							8596ee8811
						
					
				
				
					commit
					c52b4e1007
				
			@@ -79,14 +79,21 @@ final class MPVClient: ObservableObject {
 | 
			
		||||
        checkError(mpv_set_option_string(mpv, "user-agent", UserAgentManager.shared.userAgent))
 | 
			
		||||
        checkError(mpv_set_option_string(mpv, "initial-audio-sync", Defaults[.mpvInitialAudioSync] ? "yes" : "no"))
 | 
			
		||||
 | 
			
		||||
        // A/V-SYNC //
 | 
			
		||||
 | 
			
		||||
        // Enable VSYNC – needed for `video-sync`
 | 
			
		||||
        checkError(mpv_set_option_string(mpv, "opengl-swapinterval", "1"))
 | 
			
		||||
        checkError(mpv_set_option_string(mpv, "video-sync", "display-resample"))
 | 
			
		||||
        checkError(mpv_set_option_string(mpv, "interpolation", "yes"))
 | 
			
		||||
        checkError(mpv_set_option_string(mpv, "tscale", "mitchell"))
 | 
			
		||||
        checkError(mpv_set_option_string(mpv, "tscale-window", "blackman"))
 | 
			
		||||
        checkError(mpv_set_option_string(mpv, "vd-lavc-framedrop", "nonref"))
 | 
			
		||||
        checkError(mpv_set_option_string(mpv, "vd-lavc-framedrop", "no"))
 | 
			
		||||
        checkError(mpv_set_option_string(mpv, "display-fps-override", "\(String(getScreenRefreshRate()))"))
 | 
			
		||||
        checkError(mpv_set_option_string(mpv, "video-sync-max-factor", "1.1"))
 | 
			
		||||
        checkError(mpv_set_option_string(mpv, "video-sync-max-video-change", "10"))
 | 
			
		||||
        checkError(mpv_set_option_string(mpv, "audio-buffer", "0.2"))
 | 
			
		||||
        checkError(mpv_set_option_string(mpv, "audio-wait-open", "no"))
 | 
			
		||||
        checkError(mpv_set_option_string(mpv, "force-window", "yes"))
 | 
			
		||||
 | 
			
		||||
        // CPU //
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -269,6 +269,15 @@ final class PlayerModel: ObservableObject {
 | 
			
		||||
            }
 | 
			
		||||
        #endif
 | 
			
		||||
 | 
			
		||||
        DispatchQueue.global(qos: .userInteractive).async { [weak self] in
 | 
			
		||||
            guard let self else { return }
 | 
			
		||||
 | 
			
		||||
            if !self.musicMode, self.activeBackend == .mpv {
 | 
			
		||||
                self.mpvBackend.setVideoToAuto()
 | 
			
		||||
                self.mpvBackend.controls.resetTimer()
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        presentingPlayer = true
 | 
			
		||||
 | 
			
		||||
        #if os(macOS)
 | 
			
		||||
@@ -290,6 +299,9 @@ final class PlayerModel: ObservableObject {
 | 
			
		||||
        DispatchQueue.main.async { [weak self] in
 | 
			
		||||
            Delay.by(0.3) {
 | 
			
		||||
                self?.exitFullScreen(showControls: false)
 | 
			
		||||
                if self?.activeBackend == .mpv, !(self?.musicMode ?? false) {
 | 
			
		||||
                    self?.mpvBackend.setVideoToNo()
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -1013,10 +1025,9 @@ final class PlayerModel: ObservableObject {
 | 
			
		||||
    #else
 | 
			
		||||
        func handleEnterForeground() {
 | 
			
		||||
            DispatchQueue.global(qos: .userInteractive).async { [weak self] in
 | 
			
		||||
                guard let self = self else { return }
 | 
			
		||||
                guard let self else { return }
 | 
			
		||||
 | 
			
		||||
                if !self.musicMode, self.activeBackend == .mpv {
 | 
			
		||||
                    self.mpvBackend.addVideoTrackFromStream()
 | 
			
		||||
                if !self.musicMode, self.activeBackend == .mpv, presentingPlayer {
 | 
			
		||||
                    self.mpvBackend.setVideoToAuto()
 | 
			
		||||
                    self.mpvBackend.controls.resetTimer()
 | 
			
		||||
                } else if !self.musicMode, self.activeBackend == .appleAVPlayer {
 | 
			
		||||
@@ -1047,7 +1058,7 @@ final class PlayerModel: ObservableObject {
 | 
			
		||||
                pause()
 | 
			
		||||
            } else if !playingInPictureInPicture, activeBackend == .appleAVPlayer {
 | 
			
		||||
                avPlayerBackend.removePlayerFromLayer()
 | 
			
		||||
            } else if activeBackend == .mpv, !musicMode {
 | 
			
		||||
            } else if activeBackend == .mpv, !musicMode, presentingPlayer {
 | 
			
		||||
                mpvBackend.setVideoToNo()
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user