From f3e7208df6433f7307b15cdacf54b94ccc94b22f Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Mon, 6 Dec 2021 15:47:32 -0600 Subject: [PATCH] Adding some additional logging --- src/AudioReaderSource.cpp | 5 +---- src/Qt/PlayerPrivate.cpp | 13 +++++-------- src/Qt/VideoCacheThread.cpp | 1 - 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/AudioReaderSource.cpp b/src/AudioReaderSource.cpp index 14390b24..67359a69 100644 --- a/src/AudioReaderSource.cpp +++ b/src/AudioReaderSource.cpp @@ -161,7 +161,6 @@ juce::AudioBuffer* AudioReaderSource::reverse_buffer(juce::AudioBuffergetNumSamples(); int buffer_channels = buffer->getNumChannels(); @@ -225,9 +224,7 @@ void AudioReaderSource::getNextAudioBlock(const juce::AudioSourceChannelInfo& in } // Prepare to play this audio source -void AudioReaderSource::prepareToPlay(int, double) { - std::cout << "R: prepare" << std::endl; -} +void AudioReaderSource::prepareToPlay(int, double) {} // Release all resources void AudioReaderSource::releaseResources() { } diff --git a/src/Qt/PlayerPrivate.cpp b/src/Qt/PlayerPrivate.cpp index 805de1fc..6fd5f26c 100644 --- a/src/Qt/PlayerPrivate.cpp +++ b/src/Qt/PlayerPrivate.cpp @@ -26,7 +26,7 @@ namespace openshot , audioPlayback(new openshot::AudioPlaybackThread()) , videoPlayback(new openshot::VideoPlaybackThread(rb)) , videoCache(new openshot::VideoCacheThread()) - , speed(1), reader(NULL), last_video_position(1), max_sleep_ms(3000) + , speed(1), reader(NULL), last_video_position(1), max_sleep_ms(1500) { } // Destructor @@ -74,7 +74,6 @@ namespace openshot || (video_position > reader->info.video_length) ) { speed = 0; - std::cout << "A: " << frame_duration.count() << std::endl; std::this_thread::sleep_for(frame_duration); continue; } @@ -111,8 +110,8 @@ namespace openshot ZmqLogger::Instance()->AppendDebugMethod("PlayerPrivate::run (determine sleep)", "video_frame_diff", video_frame_diff, "video_position", video_position, "audio_position", audio_position, "speed", speed, "render_time(ms)", render_time.count(), "sleep_time(ms)", sleep_time.count()); // Adjust drift (if more than a few frames off between audio and video) - std::cout << "VD: " << video_frame_diff << std::endl; - if (video_frame_diff > 0 && reader->info.has_audio && reader->info.has_video) { + std::cout << "VD: " << video_frame_diff << " (render: " << render_time.count() << ", sleep: " << sleep_time.count() << ")" << std::endl; + if (video_frame_diff > 6 && reader->info.has_audio && reader->info.has_video) { // Since the audio and video threads are running independently, // they will quickly get out of sync. To fix this, we calculate // how far ahead or behind the video frame is, and adjust the amount @@ -120,13 +119,11 @@ namespace openshot // If a frame is ahead of the audio, we sleep for longer. // If a frame is behind the audio, we sleep less (or not at all), // in order for the video to catch up. - std::cout << "D: " << duration_cast(video_frame_diff * frame_duration).count() << std::endl; - sleep_time += duration_cast(video_frame_diff * frame_duration); + sleep_time += duration_cast((video_frame_diff / 2) * frame_duration); } - else if (video_frame_diff < -10 && reader->info.has_audio && reader->info.has_video) { + else if (video_frame_diff < -6 && reader->info.has_audio && reader->info.has_video) { // Skip frame(s) to catch up to the audio (if more than 10 frames behind) - std::cout << "L: " << std::fabs(video_frame_diff) / 2 << std::endl; video_position += std::fabs(video_frame_diff) / 2; // Seek forward 1/2 the difference sleep_time = sleep_time.zero(); // Don't sleep now... immediately go to next position } diff --git a/src/Qt/VideoCacheThread.cpp b/src/Qt/VideoCacheThread.cpp index de3b57fd..60d94d1d 100644 --- a/src/Qt/VideoCacheThread.cpp +++ b/src/Qt/VideoCacheThread.cpp @@ -114,7 +114,6 @@ namespace openshot } // Sleep for 1 frame length - std::cout << "C: " << frame_duration.count() << std::endl; std::this_thread::sleep_for(frame_duration); }