From 496e00e947bd37c5eed6e9d96950bd06722278f7 Mon Sep 17 00:00:00 2001
From: dec05eba <dec05eba@protonmail.com>
Date: Fri, 19 Jan 2024 18:41:09 +0100
Subject: Better handle pausing with missing audio frames

---
 src/main.cpp | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/main.cpp b/src/main.cpp
index 21f5f8c..801625e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2296,6 +2296,16 @@ int main(int argc, char **argv) {
 
                     const double this_audio_frame_time = clock_get_monotonic_seconds() - paused_time_offset;
 
+                    if(paused) {
+                        if(got_audio_data)
+                            received_audio_time = this_audio_frame_time;
+
+                        if(!audio_device.sound_device.handle)
+                            usleep(timeout_ms * 1000);
+
+                        continue;
+                    }
+
                     int ret = av_frame_make_writable(audio_device.frame);
                     if (ret < 0) {
                         fprintf(stderr, "Failed to make audio frame writable\n");
@@ -2313,13 +2323,6 @@ int main(int argc, char **argv) {
                     if(got_audio_data)
                         received_audio_time = this_audio_frame_time;
 
-                    if(paused) {
-                        received_audio_time = this_audio_frame_time;
-                        if(!audio_device.sound_device.handle)
-                            usleep(timeout_ms * 1000);
-                        continue;
-                    }
-
                     // Jesus is there a better way to do this? I JUST WANT TO KEEP VIDEO AND AUDIO SYNCED HOLY FUCK I WANT TO KILL MYSELF NOW.
                     // THIS PIECE OF SHIT WANTS EMPTY FRAMES OTHERWISE VIDEO PLAYS TOO FAST TO KEEP UP WITH AUDIO OR THE AUDIO PLAYS TOO EARLY.
                     // BUT WE CANT USE DELAYS TO GIVE DUMMY DATA BECAUSE PULSEAUDIO MIGHT GIVE AUDIO A BIG DELAYED!!!
-- 
cgit v1.2.3-70-g09d2