Clean up to factory classes.

Originally committed to SVN as r863.
This commit is contained in:
Rodrigo Braz Monteiro 2007-01-21 07:12:47 +00:00
parent 287167788f
commit b206573965
11 changed files with 161 additions and 326 deletions

View File

@ -63,10 +63,12 @@ protected:
}
public:
static wxArrayString GetFactoryList() {
static wxArrayString GetFactoryList(wxString favourite=_T("")) {
wxArrayString list;
favourite = favourite.Lower();
for (std::map<wxString,T*>::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;
}

View File

@ -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

View File

@ -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<list.Count();i++) {

View File

@ -36,15 +36,38 @@
///////////
// Headers
#include "subtitles_provider_csri.h"
#include "subtitles_provider.h"
#include "ass_file.h"
#include "video_context.h"
#define CSRIAPI __declspec(dllexport)
#include "csri/csri.h"
#include "csri/loader.h"
///////////////////
// Link to library
#if __VISUALC__ >= 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 {

View File

@ -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);
};

View File

@ -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();

View File

@ -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<list.Count();i++) {

View File

@ -33,11 +33,16 @@
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/wxprec.h>
#include <wx/filename.h>
#include <wx/msw/registry.h>
#include <wx/filename.h>
#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

View File

@ -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 <wx/wxprec.h>
#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

View File

@ -36,17 +36,92 @@
///////////
// Headers
#include "setup.h"
#if USE_DIRECTSHOW == 1
#pragma warning(disable: 4995)
#include <wx/wxprec.h>
#include <wx/image.h>
#include <dshow.h>
#include <atlbase.h>
#include <atlcom.h>
#include <atlstr.h>
#include <atlcoll.h>
#include <windows.h>
#include <tchar.h>
#include <initguid.h>
#include "video_provider_dshow.h"
#include <wx/wxprec.h>
#include <wx/image.h>
#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<IVideoSink> m_pR;
CComPtr<IMediaControl> m_pGC;
CComPtr<IMediaSeeking> 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

View File

@ -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 <wx/wxprec.h>
#include <dshow.h>
#include <atlbase.h>
#include <atlcom.h>
#include <atlstr.h>
#include <atlcoll.h>
#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<IVideoSink> m_pR;
CComPtr<IMediaControl> m_pGC;
CComPtr<IMediaSeeking> 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