forked from mia/Aegisub
Pick the CSRI renderer when the provider is created rather than every time subtitles are loaded
Originally committed to SVN as r6688.
This commit is contained in:
parent
9f87a2bacb
commit
30565530eb
2 changed files with 54 additions and 45 deletions
|
@ -49,9 +49,40 @@
|
||||||
#include "video_context.h"
|
#include "video_context.h"
|
||||||
#include "video_frame.h"
|
#include "video_frame.h"
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define CSRIAPI
|
||||||
|
#include "../../contrib/csri/include/csri/csri.h"
|
||||||
|
#else
|
||||||
|
#include <csri/csri.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
static wxMutex csri_mutex;
|
static wxMutex csri_mutex;
|
||||||
|
|
||||||
CSRISubtitlesProvider::CSRISubtitlesProvider(std::string type) : subType(type) {
|
CSRISubtitlesProvider::CSRISubtitlesProvider(std::string type)
|
||||||
|
: can_open_mem(true)
|
||||||
|
, instance(0, csri_close)
|
||||||
|
{
|
||||||
|
wxMutexLocker lock(csri_mutex);
|
||||||
|
|
||||||
|
csri_rend *cur = NULL;
|
||||||
|
|
||||||
|
// Select renderer
|
||||||
|
for (cur = csri_renderer_default(); cur; cur = csri_renderer_next(cur)) {
|
||||||
|
std::string name(csri_renderer_info(cur)->name);
|
||||||
|
if (name == type) {
|
||||||
|
renderer = cur;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Matching renderer not found, fallback to default
|
||||||
|
if (!renderer)
|
||||||
|
renderer = csri_renderer_default();
|
||||||
|
if (!renderer)
|
||||||
|
throw "No CSRI renderer available, cannot show subtitles. Try installing one or switch to another subtitle provider.";
|
||||||
|
|
||||||
|
std::string name(csri_renderer_info(renderer)->name);
|
||||||
|
can_open_mem = (name.find("vsfilter") == name.npos);
|
||||||
}
|
}
|
||||||
|
|
||||||
CSRISubtitlesProvider::~CSRISubtitlesProvider() {
|
CSRISubtitlesProvider::~CSRISubtitlesProvider() {
|
||||||
|
@ -61,35 +92,12 @@ CSRISubtitlesProvider::~CSRISubtitlesProvider() {
|
||||||
void CSRISubtitlesProvider::LoadSubtitles(AssFile *subs) {
|
void CSRISubtitlesProvider::LoadSubtitles(AssFile *subs) {
|
||||||
wxMutexLocker lock(csri_mutex);
|
wxMutexLocker lock(csri_mutex);
|
||||||
|
|
||||||
// CSRI variables
|
|
||||||
csri_rend *cur,*renderer=NULL;
|
|
||||||
|
|
||||||
// Select renderer
|
|
||||||
bool canOpenMem = true;
|
|
||||||
for (cur = csri_renderer_default();cur;cur=csri_renderer_next(cur)) {
|
|
||||||
std::string name(csri_renderer_info(cur)->name);
|
|
||||||
if (name == subType) {
|
|
||||||
renderer = cur;
|
|
||||||
if (name.find("vsfilter") != name.npos) canOpenMem = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Matching renderer not found, fallback to default
|
|
||||||
if (!renderer) {
|
|
||||||
renderer = csri_renderer_default();
|
|
||||||
if (!renderer) {
|
|
||||||
throw "No CSRI renderer available, cannot show subtitles. Try installing one or switch to another subtitle provider.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open from memory
|
// Open from memory
|
||||||
if (canOpenMem) {
|
if (can_open_mem) {
|
||||||
std::vector<char> data;
|
std::vector<char> data;
|
||||||
subs->SaveMemory(data);
|
subs->SaveMemory(data);
|
||||||
instance.reset(csri_open_mem(renderer,&data[0],data.size(),NULL), &csri_close);
|
instance = csri_open_mem(renderer, &data[0], data.size(), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open from disk
|
// Open from disk
|
||||||
else {
|
else {
|
||||||
if (tempfile.empty()) {
|
if (tempfile.empty()) {
|
||||||
|
@ -97,16 +105,14 @@ void CSRISubtitlesProvider::LoadSubtitles(AssFile *subs) {
|
||||||
wxRemoveFile(tempfile);
|
wxRemoveFile(tempfile);
|
||||||
tempfile += ".ass";
|
tempfile += ".ass";
|
||||||
}
|
}
|
||||||
subs->Save(tempfile,false,false,wxSTRING_ENCODING);
|
subs->Save(tempfile, false, false, wxSTRING_ENCODING);
|
||||||
instance.reset(csri_open_file(renderer,tempfile.utf8_str(),NULL), &csri_close);
|
instance = csri_open_file(renderer, tempfile.utf8_str(), NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSRISubtitlesProvider::DrawSubtitles(AegiVideoFrame &dst,double time) {
|
void CSRISubtitlesProvider::DrawSubtitles(AegiVideoFrame &dst,double time) {
|
||||||
// Check if CSRI loaded properly
|
// Check if CSRI loaded properly
|
||||||
if (!instance.get()) return;
|
if (!instance) return;
|
||||||
|
|
||||||
wxMutexLocker lock(csri_mutex);
|
|
||||||
|
|
||||||
// Load data into frame
|
// Load data into frame
|
||||||
csri_frame frame;
|
csri_frame frame;
|
||||||
|
@ -125,11 +131,13 @@ void CSRISubtitlesProvider::DrawSubtitles(AegiVideoFrame &dst,double time) {
|
||||||
format.width = dst.w;
|
format.width = dst.w;
|
||||||
format.height = dst.h;
|
format.height = dst.h;
|
||||||
format.pixfmt = frame.pixfmt;
|
format.pixfmt = frame.pixfmt;
|
||||||
int error = csri_request_fmt(instance.get(),&format);
|
|
||||||
|
wxMutexLocker lock(csri_mutex);
|
||||||
|
int error = csri_request_fmt(instance, &format);
|
||||||
if (error) return;
|
if (error) return;
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
csri_render(instance.get(),&frame,time);
|
csri_render(instance, &frame, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> CSRISubtitlesProvider::GetSubTypes() {
|
std::vector<std::string> CSRISubtitlesProvider::GetSubTypes() {
|
||||||
|
|
|
@ -36,18 +36,16 @@
|
||||||
|
|
||||||
#ifdef WITH_CSRI
|
#ifdef WITH_CSRI
|
||||||
|
|
||||||
|
#include "include/aegisub/subtitles_provider.h"
|
||||||
|
|
||||||
#ifndef AGI_PRE
|
#ifndef AGI_PRE
|
||||||
#include <tr1/memory>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "include/aegisub/subtitles_provider.h"
|
#include <libaegisub/scoped_ptr.h>
|
||||||
#ifdef WIN32
|
|
||||||
#define CSRIAPI
|
typedef void csri_rend;
|
||||||
#include "../../contrib/csri/include/csri/csri.h"
|
typedef void csri_inst;
|
||||||
#else
|
|
||||||
#include <csri/csri.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// DOCME
|
/// DOCME
|
||||||
/// @class CSRISubtitlesProvider
|
/// @class CSRISubtitlesProvider
|
||||||
|
@ -55,12 +53,15 @@
|
||||||
///
|
///
|
||||||
/// DOCME
|
/// DOCME
|
||||||
class CSRISubtitlesProvider : public SubtitlesProvider {
|
class CSRISubtitlesProvider : public SubtitlesProvider {
|
||||||
/// DOCME
|
agi::scoped_holder<csri_inst*> instance;
|
||||||
std::string subType;
|
csri_rend *renderer;
|
||||||
|
|
||||||
/// DOCME
|
/// VSFilter's implementation of csri_open_mem writes the file to disk then
|
||||||
std::tr1::shared_ptr<csri_inst> instance;
|
/// opens it with the standard file reader, and by writing the file ourselves
|
||||||
|
/// we can skip a few pointless charset conversions
|
||||||
|
bool can_open_mem;
|
||||||
|
|
||||||
|
/// Name of the file passed to renderers with can_open_mem false
|
||||||
wxString tempfile;
|
wxString tempfile;
|
||||||
public:
|
public:
|
||||||
CSRISubtitlesProvider(std::string subType);
|
CSRISubtitlesProvider(std::string subType);
|
||||||
|
|
Loading…
Reference in a new issue