...And done making subtitle providers register manually. If anything goes wrong, blame movax.

Originally committed to SVN as r1894.
This commit is contained in:
Rodrigo Braz Monteiro 2008-03-05 02:58:11 +00:00
parent ee61192c43
commit 1b96e656ff
6 changed files with 206 additions and 94 deletions

View File

@ -37,6 +37,12 @@
/////////// ///////////
// Headers // Headers
#include "subtitles_provider.h" #include "subtitles_provider.h"
#ifdef WITH_CSRI
#include "subtitles_provider_csri.h"
#endif
#ifdef WITH_LIBASS
#include "subtitles_provider_libass.h"
#endif
#include "options.h" #include "options.h"
@ -59,6 +65,12 @@ bool SubtitlesProviderFactory::ProviderAvailable() {
//////////////// ////////////////
// Get provider // Get provider
SubtitlesProvider* SubtitlesProviderFactory::GetProvider() { SubtitlesProvider* SubtitlesProviderFactory::GetProvider() {
// Register them
// HACK: fix me
static bool init = false;
if (!init) RegisterProviders();
init = true;
// List of providers // List of providers
wxArrayString list = GetFactoryList(Options.AsText(_T("Subtitles provider"))); wxArrayString list = GetFactoryList(Options.AsText(_T("Subtitles provider")));
@ -85,6 +97,18 @@ SubtitlesProvider* SubtitlesProviderFactory::GetProvider() {
} }
//////////////////////
// Register providers
void SubtitlesProviderFactory::RegisterProviders() {
#ifdef WITH_CSRI
new CSRISubtitlesProviderFactory();
#endif
#ifdef WITH_LIBASS
new LibassSubtitlesProviderFactory();
#endif
}
////////// //////////
// Static // Static
template <class SubtitlesProviderFactory> std::map<wxString,SubtitlesProviderFactory*>* AegisubFactory<SubtitlesProviderFactory>::factories=NULL; template <class SubtitlesProviderFactory> std::map<wxString,SubtitlesProviderFactory*>* AegisubFactory<SubtitlesProviderFactory>::factories=NULL;

View File

@ -75,5 +75,6 @@ protected:
public: public:
virtual ~SubtitlesProviderFactory() {} virtual ~SubtitlesProviderFactory() {}
static SubtitlesProvider *GetProvider(); static SubtitlesProvider *GetProvider();
static void RegisterProviders();
static bool ProviderAvailable(); static bool ProviderAvailable();
}; };

View File

@ -40,66 +40,9 @@
#ifdef WITH_CSRI #ifdef WITH_CSRI
#include <wx/wxprec.h> #include <wx/wxprec.h>
#include "subtitles_provider.h" #include "subtitles_provider_csri.h"
#include "ass_file.h" #include "ass_file.h"
#include "video_context.h" #include "video_context.h"
#ifdef WIN32
#define CSRIAPI
#endif
#include "csri/csri.h"
///////////////////
// Link to library
#if __VISUALC__ >= 1200
//#pragma comment(lib,"asa.lib")
#endif
/////////////////////////////////////////////////
// Common Subtitles Rendering Interface provider
class CSRISubtitlesProvider : public SubtitlesProvider {
private:
wxString subType;
csri_inst *instance;
public:
CSRISubtitlesProvider(wxString subType);
~CSRISubtitlesProvider();
bool CanRaster() { return true; }
void LoadSubtitles(AssFile *subs);
void DrawSubtitles(AegiVideoFrame &dst,double time);
};
///////////
// Factory
class CSRISubtitlesProviderFactory : public SubtitlesProviderFactory {
public:
SubtitlesProvider *CreateProvider(wxString subType=_T("")) { return new CSRISubtitlesProvider(subType); }
wxArrayString GetSubTypes() {
csri_info *info;
wxArrayString final;
for (csri_rend *cur = csri_renderer_default();cur;cur = csri_renderer_next(cur)) {
// Get renderer name
info = csri_renderer_info(cur);
const char* buffer = info->name;
// wxWidgets isn't initialized, so h4x into a wxString
int len = strlen(buffer);
wxString str;
str.Alloc(len+1);
for (int i=0;i<len;i++) {
str.Append((wxChar)buffer[i]);
}
final.Add(str);
}
return final;
}
CSRISubtitlesProviderFactory() : SubtitlesProviderFactory(_T("csri"),GetSubTypes()) {}
} registerCSRI;
/////////////// ///////////////
@ -203,4 +146,28 @@ void CSRISubtitlesProvider::DrawSubtitles(AegiVideoFrame &dst,double time) {
csri_render(instance,&frame,time); csri_render(instance,&frame,time);
} }
/////////////////////
// Get CSRI subtypes
wxArrayString CSRISubtitlesProviderFactory::GetSubTypes() {
csri_info *info;
wxArrayString final;
for (csri_rend *cur = csri_renderer_default();cur;cur = csri_renderer_next(cur)) {
// Get renderer name
info = csri_renderer_info(cur);
const char* buffer = info->name;
// wxWidgets isn't initialized, so h4x into a wxString
int len = strlen(buffer);
wxString str;
str.Alloc(len+1);
for (int i=0;i<len;i++) {
str.Append((wxChar)buffer[i]);
}
final.Add(str);
}
return final;
}
#endif // WITH_CSRI #endif // WITH_CSRI

View File

@ -0,0 +1,77 @@
// 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
//
///////////
// Headers
#ifdef WITH_CSRI
#include <wx/wxprec.h>
#include "subtitles_provider.h"
#ifdef WIN32
#define CSRIAPI
#endif
#include "csri/csri.h"
/////////////////////////////////////////////////
// Common Subtitles Rendering Interface provider
class CSRISubtitlesProvider : public SubtitlesProvider {
private:
wxString subType;
csri_inst *instance;
public:
CSRISubtitlesProvider(wxString subType);
~CSRISubtitlesProvider();
bool CanRaster() { return true; }
void LoadSubtitles(AssFile *subs);
void DrawSubtitles(AegiVideoFrame &dst,double time);
};
///////////
// Factory
class CSRISubtitlesProviderFactory : public SubtitlesProviderFactory {
public:
SubtitlesProvider *CreateProvider(wxString subType=_T("")) { return new CSRISubtitlesProvider(subType); }
wxArrayString GetSubTypes();
CSRISubtitlesProviderFactory() : SubtitlesProviderFactory(_T("csri"),GetSubTypes()) {}
};
#endif

View File

@ -42,42 +42,6 @@
#include "ass_file.h" #include "ass_file.h"
#include "video_context.h" #include "video_context.h"
#include "utils.h" #include "utils.h"
extern "C" {
#ifdef __VISUALC__
#include "stdint.h"
#endif
#include "../libass/ass.h"
}
///////////////////
// libass provider
class LibassSubtitlesProvider : public SubtitlesProvider {
private:
static ass_library_t* ass_library;
ass_renderer_t* ass_renderer;
ass_track_t* ass_track;
public:
LibassSubtitlesProvider();
~LibassSubtitlesProvider();
bool CanRaster() { return true; }
void LoadSubtitles(AssFile *subs);
void DrawSubtitles(AegiVideoFrame &dst,double time);
};
ass_library_t* LibassSubtitlesProvider::ass_library;
///////////
// Factory
class LibassSubtitlesProviderFactory : public SubtitlesProviderFactory {
public:
SubtitlesProvider *CreateProvider(wxString subType=_T("")) { return new LibassSubtitlesProvider(); }
LibassSubtitlesProviderFactory() : SubtitlesProviderFactory(_T("libass")) {}
} registerLibass;
/////////////// ///////////////

View File

@ -0,0 +1,79 @@
// Copyright (c) 2006-2007, Rodrigo Braz Monteiro, Evgeniy Stepanov
// 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
//
///////////
// Headers
#ifdef WITH_LIBASS
#include "subtitles_provider.h"
extern "C" {
#ifdef __VISUALC__
#include "stdint.h"
#endif
#include "../libass/ass.h"
}
///////////////////
// libass provider
class LibassSubtitlesProvider : public SubtitlesProvider {
private:
static ass_library_t* ass_library;
ass_renderer_t* ass_renderer;
ass_track_t* ass_track;
public:
LibassSubtitlesProvider();
~LibassSubtitlesProvider();
bool CanRaster() { return true; }
void LoadSubtitles(AssFile *subs);
void DrawSubtitles(AegiVideoFrame &dst,double time);
};
ass_library_t* LibassSubtitlesProvider::ass_library;
///////////
// Factory
class LibassSubtitlesProviderFactory : public SubtitlesProviderFactory {
public:
SubtitlesProvider *CreateProvider(wxString subType=_T("")) { return new LibassSubtitlesProvider(); }
LibassSubtitlesProviderFactory() : SubtitlesProviderFactory(_T("libass")) {}
};
#endif