From b206573965c3f4ddee92140a2f198477883ac325 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Sun, 21 Jan 2007 07:12:47 +0000 Subject: [PATCH] Clean up to factory classes. Originally committed to SVN as r863. --- aegisub/factory.h | 6 +- aegisub/setup.cpp | 11 --- aegisub/subtitles_provider.cpp | 9 +-- aegisub/subtitles_provider_csri.cpp | 25 +++++- aegisub/subtitles_provider_csri.h | 62 --------------- aegisub/video_context.cpp | 1 + aegisub/video_provider.cpp | 9 +-- aegisub/video_provider_avs.cpp | 55 +++++++++++-- aegisub/video_provider_avs.h | 108 -------------------------- aegisub/video_provider_dshow.cpp | 86 +++++++++++++++++++-- aegisub/video_provider_dshow.h | 115 ---------------------------- 11 files changed, 161 insertions(+), 326 deletions(-) delete mode 100644 aegisub/subtitles_provider_csri.h delete mode 100644 aegisub/video_provider_avs.h delete mode 100644 aegisub/video_provider_dshow.h diff --git a/aegisub/factory.h b/aegisub/factory.h index 3931305cd..9e76457ef 100644 --- a/aegisub/factory.h +++ b/aegisub/factory.h @@ -63,10 +63,12 @@ protected: } public: - static wxArrayString GetFactoryList() { + static wxArrayString GetFactoryList(wxString favourite=_T("")) { wxArrayString list; + favourite = favourite.Lower(); for (std::map::iterator cur=factories->begin();cur!=factories->end();cur++) { - list.Add(cur->first); + if (cur->first == favourite) list.Insert(cur->first,0); + else list.Add(cur->first); } return list; } diff --git a/aegisub/setup.cpp b/aegisub/setup.cpp index f658effb0..892662293 100644 --- a/aegisub/setup.cpp +++ b/aegisub/setup.cpp @@ -137,17 +137,6 @@ #endif -////////////// -// DirectShow -#if USE_DIRECTSHOW == 1 -#ifdef __WXDEBUG__ -#pragma comment(lib, "strmbasdu.lib") -#else -#pragma comment(lib, "strmbaseu.lib") -#endif -#endif - - ///////////// // PortAudio #if USE_PORTAUDIO == 1 diff --git a/aegisub/subtitles_provider.cpp b/aegisub/subtitles_provider.cpp index 2ae355a4f..5ffc32c53 100644 --- a/aegisub/subtitles_provider.cpp +++ b/aegisub/subtitles_provider.cpp @@ -50,18 +50,11 @@ SubtitlesProvider::~SubtitlesProvider() { // Get provider SubtitlesProvider* SubtitlesProviderFactory::GetProvider() { // List of providers - wxArrayString list = GetFactoryList(); + wxArrayString list = GetFactoryList(Options.AsText(_T("Subtitles provider"))); // None available if (list.Count() == 0) throw _T("No video providers are available."); - // Put preffered on top - wxString preffered = Options.AsText(_T("Subtitles provider")).Lower(); - if (list.Index(preffered) != wxNOT_FOUND) { - list.Remove(preffered); - list.Insert(preffered,0); - } - // Get provider wxString error; for (unsigned int i=0;i= 1200 #pragma comment(lib,"asa.lib") #endif +///////////////////////////////////////////////// +// Common Subtitles Rendering Interface provider +class CSRISubtitlesProvider : public SubtitlesProvider { +private: + csri_inst *instance; + +public: + CSRISubtitlesProvider(); + ~CSRISubtitlesProvider(); + + bool CanRaster() { return true; } + + void LoadSubtitles(AssFile *subs); + void DrawSubtitles(AegiVideoFrame &dst,double time); +}; + + /////////// // Factory class CSRISubtitlesProviderFactory : public SubtitlesProviderFactory { diff --git a/aegisub/subtitles_provider_csri.h b/aegisub/subtitles_provider_csri.h deleted file mode 100644 index f87c09aa7..000000000 --- a/aegisub/subtitles_provider_csri.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) 2007, Rodrigo Braz Monteiro -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of the Aegisub Group nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -// ----------------------------------------------------------------------------- -// -// AEGISUB -// -// Website: http://aegisub.cellosoft.com -// Contact: mailto:zeratul@cellosoft.com -// - - -#pragma once - - -/////////// -// Headers -#include "subtitles_provider.h" -#define CSRIAPI __declspec(dllexport) -#include "csri/csri.h" -#include "csri/loader.h" - - -///////////////////////////////////////////////// -// Common Subtitles Rendering Interface provider -class CSRISubtitlesProvider : public SubtitlesProvider { -private: - csri_inst *instance; - -public: - CSRISubtitlesProvider(); - ~CSRISubtitlesProvider(); - - bool CanRaster() { return true; } - - void LoadSubtitles(AssFile *subs); - void DrawSubtitles(AegiVideoFrame &dst,double time); -}; diff --git a/aegisub/video_context.cpp b/aegisub/video_context.cpp index 9833b747b..b8367be78 100644 --- a/aegisub/video_context.cpp +++ b/aegisub/video_context.cpp @@ -310,6 +310,7 @@ void VideoContext::UpdateDisplays(bool full) { display->ControlSlider->SetRange(0,GetLength()-1); } display->ControlSlider->SetValue(GetFrameN()); + display->ControlSlider->Update(); display->UpdatePositionDisplay(); display->Refresh(); display->Update(); diff --git a/aegisub/video_provider.cpp b/aegisub/video_provider.cpp index 79627bdf3..447e71d30 100644 --- a/aegisub/video_provider.cpp +++ b/aegisub/video_provider.cpp @@ -130,18 +130,11 @@ void VideoProvider::ClearCache() { // Get provider VideoProvider *VideoProviderFactory::GetProvider(wxString video,double fps) { // List of providers - wxArrayString list = GetFactoryList(); + wxArrayString list = GetFactoryList(Options.AsText(_T("Video provider"))); // None available if (list.Count() == 0) throw _T("No video providers are available."); - // Put preffered on top - wxString preffered = Options.AsText(_T("Video provider")).Lower(); - if (list.Index(preffered) != wxNOT_FOUND) { - list.Remove(preffered); - list.Insert(preffered,0); - } - // Get provider wxString error; for (unsigned int i=0;i #include #include #include -#include "video_provider_avs.h" +#include "avisynth_wrap.h" +#include "video_provider.h" +#include "subtitles_provider.h" #include "video_context.h" #include "options.h" #include "main.h" @@ -45,7 +50,50 @@ #include "ass_file.h" -#ifdef __WIN32__ +//////////// +// Provider +class AvisynthVideoProvider: public VideoProvider, SubtitlesProvider, AviSynthWrapper { +private: + VideoInfo vi; + AegiVideoFrame iframe; + + wxString rendererCallString; + + int num_frames; + int last_fnum; + + double fps; + wxArrayInt frameTime; + + PClip RGB32Video; + PClip SubtitledVideo; + + PClip OpenVideo(wxString _filename, bool mpeg2dec3_priority = true); + PClip ApplySubtitles(wxString _filename, PClip videosource); + + void LoadVSFilter(); + void LoadASA(); + void LoadRenderer(); + +public: + AvisynthVideoProvider(wxString _filename, double fps=0.0); + ~AvisynthVideoProvider(); + + SubtitlesProvider *GetAsSubtitlesProvider(); + void LoadSubtitles(AssFile *subs); + + const AegiVideoFrame DoGetFrame(int n); + void GetFloatFrame(float* Buffer, int n); + + // properties + int GetPosition() { return last_fnum; }; + int GetFrameCount() { return num_frames? num_frames: vi.num_frames; }; + double GetFPS() { return (double)vi.fps_numerator/(double)vi.fps_denominator; }; + int GetWidth() { return vi.width; }; + int GetHeight() { return vi.height; }; + + void OverrideFrameTimeList(wxArrayInt list); +}; /////////// @@ -473,6 +521,3 @@ void AvisynthVideoProvider::OverrideFrameTimeList(wxArrayInt list) { frameTime = list; num_frames = frameTime.Count(); } - - -#endif diff --git a/aegisub/video_provider_avs.h b/aegisub/video_provider_avs.h deleted file mode 100644 index 0027dfac6..000000000 --- a/aegisub/video_provider_avs.h +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright (c) 2006, Fredrik Mellbin -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of the Aegisub Group nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -// ----------------------------------------------------------------------------- -// -// AEGISUB -// -// Website: http://aegisub.cellosoft.com -// Contact: mailto:zeratul@cellosoft.com -// - - -#pragma once - - -/////////// -// Headers -#include - -#ifdef __WIN32__ -#include "avisynth_wrap.h" -#include "video_provider.h" -#include "subtitles_provider.h" - -/*class GetFrameVPThread: public wxThread { -private: - int getting_n; - int current_n; - - PClip video; - - wxThread::ExitCode Entry(); -public: - void GetFrame(int n); - GetFrameVPThread(PClip clip); -};*/ - - -//////////// -// Provider -class AvisynthVideoProvider: public VideoProvider, SubtitlesProvider, AviSynthWrapper { -private: - VideoInfo vi; - AegiVideoFrame iframe; - - wxString rendererCallString; - - int num_frames; - int last_fnum; - - double fps; - wxArrayInt frameTime; - - PClip RGB32Video; - PClip SubtitledVideo; - - PClip OpenVideo(wxString _filename, bool mpeg2dec3_priority = true); - PClip ApplySubtitles(wxString _filename, PClip videosource); - - void LoadVSFilter(); - void LoadASA(); - void LoadRenderer(); - -public: - AvisynthVideoProvider(wxString _filename, double fps=0.0); - ~AvisynthVideoProvider(); - - SubtitlesProvider *GetAsSubtitlesProvider(); - void LoadSubtitles(AssFile *subs); - - const AegiVideoFrame DoGetFrame(int n); - void GetFloatFrame(float* Buffer, int n); - - // properties - int GetPosition() { return last_fnum; }; - int GetFrameCount() { return num_frames? num_frames: vi.num_frames; }; - double GetFPS() { return (double)vi.fps_numerator/(double)vi.fps_denominator; }; - int GetWidth() { return vi.width; }; - int GetHeight() { return vi.height; }; - - void OverrideFrameTimeList(wxArrayInt list); -}; - -#endif diff --git a/aegisub/video_provider_dshow.cpp b/aegisub/video_provider_dshow.cpp index 23b065935..1645a6ae7 100644 --- a/aegisub/video_provider_dshow.cpp +++ b/aegisub/video_provider_dshow.cpp @@ -36,17 +36,92 @@ /////////// // Headers -#include "setup.h" -#if USE_DIRECTSHOW == 1 #pragma warning(disable: 4995) -#include -#include +#include +#include +#include +#include +#include #include #include #include -#include "video_provider_dshow.h" +#include +#include +#include "video_provider.h" #include "utils.h" #include "vfr.h" +#include "videosink.h" + + +/////////////////////// +// DirectShow library +#ifdef __WXDEBUG__ +#pragma comment(lib, "strmbasdu.lib") +#else +#pragma comment(lib, "strmbaseu.lib") +#endif + + +/////////////////////////////////// +// DirectShow Video Provider class +class DirectShowVideoProvider: public VideoProvider { + struct DF { + public: + REFERENCE_TIME timestamp; // DS timestamp that we used for this frame + AegiVideoFrame frame; + + DF() : timestamp(-1) { } + DF(AegiVideoFrame f) : timestamp(-1), frame(f) { } + DF(const DF& f) { operator=(f); } + DF& operator=(const DF& f) { timestamp = f.timestamp; frame = f.frame; return *this; } + }; + +private: + wxArrayInt frameTime; + + unsigned int last_fnum; + unsigned int width; + unsigned int height; + unsigned int num_frames; + double fps; + long long defd; + + HRESULT OpenVideo(wxString _filename); + void CloseVideo(); + + static void ReadFrame(long long timestamp, unsigned format, unsigned bpp, const unsigned char *frame, unsigned width, unsigned height, int stride, unsigned arx, unsigned ary, void *arg); + int NextFrame(DF &df,int &fn); + + void RegROT(); + void UnregROT(); + + REFERENCE_TIME duration; + DF rdf; + CComPtr m_pR; + CComPtr m_pGC; + CComPtr m_pGS; + HANDLE m_hFrameReady; + bool m_registered; + DWORD m_rot_cookie; + +public: + DirectShowVideoProvider(wxString _filename, double _fps=0.0); + ~DirectShowVideoProvider(); + + void RefreshSubtitles(); + + const AegiVideoFrame DoGetFrame(int n); + void GetFloatFrame(float* Buffer, int n); + + int GetPosition() { return last_fnum; }; + int GetFrameCount() { return num_frames; }; + double GetFPS() { return fps; }; + int GetWidth() { return width; }; + int GetHeight() { return height; }; + + void OverrideFrameTimeList(wxArrayInt list); +}; + /////////// @@ -511,4 +586,3 @@ void DirectShowVideoProvider::OverrideFrameTimeList(wxArrayInt list) { } -#endif diff --git a/aegisub/video_provider_dshow.h b/aegisub/video_provider_dshow.h deleted file mode 100644 index 94da58cab..000000000 --- a/aegisub/video_provider_dshow.h +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright (c) 2006, Rodrigo Braz Monteiro -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of the Aegisub Group nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -// ----------------------------------------------------------------------------- -// -// AEGISUB -// -// Website: http://aegisub.cellosoft.com -// Contact: mailto:zeratul@cellosoft.com -// - - -#pragma once - - -/////////// -// Headers -#include "setup.h" -#if USE_DIRECTSHOW == 1 -#include "video_provider.h" -#pragma warning(disable: 4995) -#include -#include -#include -#include -#include -#include -#include "videosink.h" - - -/////////////////////////////////// -// DirectShow Video Provider class -class DirectShowVideoProvider: public VideoProvider { - struct DF { - public: - REFERENCE_TIME timestamp; // DS timestamp that we used for this frame - AegiVideoFrame frame; - - DF() : timestamp(-1) { } - DF(AegiVideoFrame f) : timestamp(-1), frame(f) { } - DF(const DF& f) { operator=(f); } - DF& operator=(const DF& f) { timestamp = f.timestamp; frame = f.frame; return *this; } - }; - -private: - wxArrayInt frameTime; - - unsigned int last_fnum; - unsigned int width; - unsigned int height; - unsigned int num_frames; - double fps; - long long defd; - - HRESULT OpenVideo(wxString _filename); - void CloseVideo(); - - static void ReadFrame(long long timestamp, unsigned format, unsigned bpp, const unsigned char *frame, unsigned width, unsigned height, int stride, unsigned arx, unsigned ary, void *arg); - int NextFrame(DF &df,int &fn); - - void RegROT(); - void UnregROT(); - - REFERENCE_TIME duration; - DF rdf; - CComPtr m_pR; - CComPtr m_pGC; - CComPtr m_pGS; - HANDLE m_hFrameReady; - bool m_registered; - DWORD m_rot_cookie; - -public: - DirectShowVideoProvider(wxString _filename, double _fps=0.0); - ~DirectShowVideoProvider(); - - void RefreshSubtitles(); - - const AegiVideoFrame DoGetFrame(int n); - void GetFloatFrame(float* Buffer, int n); - - int GetPosition() { return last_fnum; }; - int GetFrameCount() { return num_frames; }; - double GetFPS() { return fps; }; - int GetWidth() { return width; }; - int GetHeight() { return height; }; - - void OverrideFrameTimeList(wxArrayInt list); -}; - -#endif