From c0b62ff3779570f8fd1d66d4dbd71437b43278c9 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Sat, 7 Apr 2007 23:45:46 +0000 Subject: [PATCH] Re-coded threaded video mode, but it fails spetacularly. It's currently disabled in source, but there. Originally committed to SVN as r1021. --- aegisub/video_context.cpp | 80 +++++++++++++++++++++++++++++++++++---- aegisub/video_context.h | 19 ++++++++++ 2 files changed, 91 insertions(+), 8 deletions(-) diff --git a/aegisub/video_context.cpp b/aegisub/video_context.cpp index e708c55c6..4e3ac8255 100644 --- a/aegisub/video_context.cpp +++ b/aegisub/video_context.cpp @@ -108,8 +108,12 @@ VideoContext::VideoContext() { arType = 0; arValue = 1.0; isPlaying = false; - threaded = Options.AsBool(_T("Threaded Video")); nextFrame = -1; + + // Threads + threaded = Options.AsBool(_T("Threaded Video")); + threadLocked = false; + threadNextFrame = -1; } @@ -373,15 +377,30 @@ void VideoContext::JumpToFrame(int n) { // Prevent intervention during playback if (isPlaying && n != playNextFrame) return; - // Set frame number - frame_n = n; - GetFrameAsTexture(n); + // Threaded + if (threaded && false) { // Doesn't work, so it's disabled + wxMutexLocker lock(vidMutex); + threadNextFrame = n; + if (!threadLocked) { + threadLocked = true; + thread = new VideoContextThread(this); + thread->Create(); + thread->Run(); + } + } - // Display - UpdateDisplays(false); + // Not threaded + else { + // Set frame number + frame_n = n; + GetFrameAsTexture(n); - // Update grid - if (!isPlaying && Options.AsBool(_T("Highlight subs in frame"))) grid->Refresh(false); + // Display + UpdateDisplays(false); + + // Update grid + if (!isPlaying && Options.AsBool(_T("Highlight subs in frame"))) grid->Refresh(false); + } } @@ -804,3 +823,48 @@ void VideoContext::SetShader(bool enabled) { bool VideoContext::HasIndependentSubs() { return subsProvider && subsProvider->CanRaster(); } + + +////////////////////// +// Thread constructor +VideoContextThread::VideoContextThread(VideoContext *par) +: wxThread(wxTHREAD_DETACHED) +{ + parent = par; +} + + +////////////////////// +// Thread entry point +wxThread::ExitCode VideoContextThread::Entry() { + // Set up thread + int frame = parent->threadNextFrame; + int curFrame = parent->frame_n; + bool highSubs = Options.AsBool(_T("Highlight subs in frame")); + + // Loop while there is work to do + while (true) { + // Get frame and set frame number + parent->GetFrameAsTexture(frame); + parent->frame_n = frame; + + // Display + parent->UpdateDisplays(false); + + // Update grid + if (!parent->isPlaying && highSubs) parent->grid->Refresh(false); + + // Get lock and check if there is more to do + wxMutexLocker lock(parent->vidMutex); + curFrame = parent->frame_n; + frame = parent->threadNextFrame; + + // Work done, kill thread and release context + if (curFrame == frame) { + parent->threadLocked = false; + parent->threadNextFrame = -1; + Delete(); + return 0; + } + } +} diff --git a/aegisub/video_context.h b/aegisub/video_context.h index 7ac336d56..8254bf187 100644 --- a/aegisub/video_context.h +++ b/aegisub/video_context.h @@ -54,6 +54,7 @@ class AssDialogue; class VideoProvider; class VideoDisplay; class SubtitlesProvider; +class VideoContextThread; ////////////// @@ -61,6 +62,7 @@ class SubtitlesProvider; class VideoContext : public wxEvtHandler { friend class AudioProvider; friend class VideoDisplayVisual; + friend class VideoContextThread; private: static VideoContext *instance; @@ -92,7 +94,12 @@ private: int endFrame; int playNextFrame; int nextFrame; + bool threaded; + bool threadLocked; + int threadNextFrame; + wxMutex vidMutex; + wxThread *thread; bool loaded; bool isInverted; @@ -182,3 +189,15 @@ public: DECLARE_EVENT_TABLE() }; + + +////////// +// Thread +class VideoContextThread : public wxThread { +private: + VideoContext *parent; + +public: + VideoContextThread(VideoContext *parent); + wxThread::ExitCode Entry(); +};