Changed video provider to not depend on wxWidgets.

Originally committed to SVN as r1958.
This commit is contained in:
Rodrigo Braz Monteiro 2008-03-07 21:24:14 +00:00
parent 01f5f99b67
commit 6b12f54d72
13 changed files with 55 additions and 52 deletions

View file

@ -52,6 +52,9 @@ namespace Aegisub {
// String array
typedef std::vector<String> StringArray;
// Integer array
typedef std::vector<int> IntArray;
};

View file

@ -66,17 +66,17 @@ public:
virtual double GetFPS()=0; // Get framerate in frames per second
// Use this to set any post-loading warnings, such as "being loaded with unreliable seeking"
virtual wxString GetWarning() { return _T(""); }
virtual Aegisub::String GetWarning() { return L""; }
// Name of decoder, e.g. "Avisynth/FFMPegSource"
virtual wxString GetDecoderName() { return _("Unknown"); }
virtual Aegisub::String GetDecoderName() { return L"Unknown"; }
// How many frames does this provider wants that Aegisub caches? Set to 0 if it doesn't require caching.
virtual int GetDesiredCacheSize() { return 0; }
// For providers that are natively time-based (e.g. DirectShow)
virtual bool IsNativelyByFrames() { return true; }
virtual void OverrideFrameTimeList(wxArrayInt list) {} // Override the list with the provided one, for VFR handling
virtual void OverrideFrameTimeList(Aegisub::IntArray list) {} // Override the list with the provided one, for VFR handling
// If this video provider has a built-in subtitles provider, return that
virtual SubtitlesProvider *GetAsSubtitlesProvider() { return NULL; }
@ -87,5 +87,5 @@ public:
// Factory
class VideoProviderFactory {
public:
virtual VideoProvider *CreateProvider(wxString video,double fps=0.0)=0;
virtual VideoProvider *CreateProvider(Aegisub::String video,double fps=0.0)=0;
};

View file

@ -404,10 +404,8 @@ int FrameRate::GetTimeAtFrame(int frame,bool start,bool exact) {
////////////////////////////////////////
// Get the current list of frames/times
wxArrayInt FrameRate::GetFrameTimeList() {
wxArrayInt final;
for (unsigned int i=0;i<Frame.size();i++) final.Add(Frame[i]);
return final;
Aegisub::IntArray FrameRate::GetFrameTimeList() {
return Frame;
}

View file

@ -47,6 +47,7 @@
#include <vector>
#include <wx/wxprec.h>
#include <wx/dynarray.h>
#include "include/aegisub/aegisub.h"
///////////////////////
@ -65,7 +66,7 @@ class FrameRate {
private:
double last_time;
int last_frame;
std::vector<int> Frame;
Aegisub::IntArray Frame;
// contains the assumed fps for v1 timecodes, average for v2 and actual fps for cfr
double AverageFrameRate;
@ -101,7 +102,7 @@ public:
ASS_FrameRateType GetFrameRateType() { return FrameRateType; };
wxString GetFilename() { return vfrFile; };
wxArrayInt GetFrameTimeList();
Aegisub::IntArray GetFrameTimeList();
double GetCommonFPS();
};

View file

@ -52,7 +52,7 @@
///////////////
// Constructor
AvisynthVideoProvider::AvisynthVideoProvider(wxString _filename, double _fps) {
AvisynthVideoProvider::AvisynthVideoProvider(Aegisub::String _filename, double _fps) {
AVSTRACE(wxString::Format(_T("AvisynthVideoProvider: Creating new AvisynthVideoProvider: \"%s\", \"%s\""), _filename, _subfilename));
bool mpeg2dec3_priority = true;
RGB32Video = NULL;
@ -97,7 +97,7 @@ AvisynthVideoProvider::~AvisynthVideoProvider() {
/////////////////////////////////////////
// Actually open the video into Avisynth
PClip AvisynthVideoProvider::OpenVideo(wxString _filename, bool mpeg2dec3_priority) {
PClip AvisynthVideoProvider::OpenVideo(Aegisub::String _filename, bool mpeg2dec3_priority) {
AVSTRACE(_T("AvisynthVideoProvider::OpenVideo: Opening video"));
wxMutexLocker lock(AviSynthMutex);
AVSTRACE(_T("AvisynthVideoProvider::OpenVideo: Got AVS mutex"));
@ -107,7 +107,7 @@ PClip AvisynthVideoProvider::OpenVideo(wxString _filename, bool mpeg2dec3_priori
usedDirectShow = false;
decoderName = _("Unknown");
wxString extension = _filename.Right(4);
wxString extension = wxString(_filename.c_str()).Right(4);
extension.LowerCase();
try {
@ -369,7 +369,7 @@ const AegiVideoFrame AvisynthVideoProvider::GetFrame(int _n,int formatMask) {
////////////////////////////////////////////////////////
// Apply VSFilter subtitles, or whatever is appropriate
PClip AvisynthVideoProvider::ApplySubtitles(wxString _filename, PClip videosource) {
PClip AvisynthVideoProvider::ApplySubtitles(Aegisub::String _filename, PClip videosource) {
AVSTRACE(_T("AvisynthVideoProvider::ApplySutitles: Applying subtitles"));
wxMutexLocker lock(AviSynthMutex);
AVSTRACE(_T("AvisynthVideoProvider::ApplySutitles: Got AVS mutex"));
@ -383,7 +383,7 @@ PClip AvisynthVideoProvider::ApplySubtitles(wxString _filename, PClip videosourc
try {
AVSTRACE(_T("AvisynthVideoProvider::ApplySutitles: Now invoking ") + rendererCallString);
script = env->Invoke(rendererCallString.mb_str(wxConvUTF8), AVSValue(args,2));
script = env->Invoke(wxString(rendererCallString.c_str()).mb_str(wxConvUTF8), AVSValue(args,2));
AVSTRACE(_T("AvisynthVideoProvider::ApplySutitles: Invoked successfully"));
}
catch (AvisynthError &err) {
@ -422,7 +422,7 @@ void AvisynthVideoProvider::LoadSubtitles(AssFile *subs) {
delete subs;
// Load subtitles
SubtitledVideo = ApplySubtitles(subfilename, RGB32Video);
SubtitledVideo = ApplySubtitles(subfilename.c_str(), RGB32Video);
AVSTRACE(_T("AvisynthVideoProvider::RefreshSubtitles: Subtitles refreshed"));
vi = SubtitledVideo->GetVideoInfo();
AVSTRACE(_T("AvisynthVideoProvider: Got video info"));
@ -527,9 +527,9 @@ void AvisynthVideoProvider::OverrideFrameTimeList(wxArrayInt list) {
///////////////
// Get warning
wxString AvisynthVideoProvider::GetWarning() {
if (usedDirectShow) return _("Warning! The file is being opened using Avisynth's DirectShowSource, which has unreliable seeking. Frame numbers might not match the real number. PROCEED AT YOUR OWN RISK!");
else return _T("");
Aegisub::String AvisynthVideoProvider::GetWarning() {
if (usedDirectShow) return L"Warning! The file is being opened using Avisynth's DirectShowSource, which has unreliable seeking. Frame numbers might not match the real number. PROCEED AT YOUR OWN RISK!";
else return L"";
}
#endif

View file

@ -51,8 +51,8 @@ private:
AegiVideoFrame iframe;
bool usedDirectShow;
wxString rendererCallString;
wxString decoderName;
Aegisub::String rendererCallString;
Aegisub::String decoderName;
int num_frames;
int last_fnum;
@ -64,15 +64,15 @@ private:
PClip RGB32Video;
PClip SubtitledVideo;
PClip OpenVideo(wxString _filename, bool mpeg2dec3_priority = true);
PClip ApplySubtitles(wxString _filename, PClip videosource);
PClip OpenVideo(Aegisub::String _filename, bool mpeg2dec3_priority = true);
PClip ApplySubtitles(Aegisub::String _filename, PClip videosource);
void LoadVSFilter();
void LoadASA();
void LoadRenderer();
public:
AvisynthVideoProvider(wxString _filename, double fps=0.0);
AvisynthVideoProvider(Aegisub::String _filename, double fps=0.0);
~AvisynthVideoProvider();
SubtitlesProvider *GetAsSubtitlesProvider();
@ -91,8 +91,8 @@ public:
void OverrideFrameTimeList(wxArrayInt list);
bool IsNativelyByFrames() { return byFrame; }
wxString GetWarning();
wxString GetDecoderName() { return _T("Avisynth/") + decoderName; }
Aegisub::String GetWarning();
Aegisub::String GetDecoderName() { return Aegisub::String(L"Avisynth/") + decoderName; }
};
@ -100,7 +100,7 @@ public:
// Factory
class AvisynthVideoProviderFactory : public VideoProviderFactory {
public:
VideoProvider *CreateProvider(wxString video,double fps=0.0) { return new AvisynthVideoProvider(video,fps); }
VideoProvider *CreateProvider(Aegisub::String video,double fps=0.0) { return new AvisynthVideoProvider(video,fps); }
};

View file

@ -162,15 +162,15 @@ int VideoProviderCache::GetHeight() {
double VideoProviderCache::GetFPS() {
return master->GetFPS();
}
void VideoProviderCache::OverrideFrameTimeList(wxArrayInt list) {
void VideoProviderCache::OverrideFrameTimeList(Aegisub::IntArray list) {
master->OverrideFrameTimeList(list);
}
bool VideoProviderCache::IsNativelyByFrames() {
return master->IsNativelyByFrames();
}
wxString VideoProviderCache::GetWarning() {
Aegisub::String VideoProviderCache::GetWarning() {
return master->GetWarning();
}
wxString VideoProviderCache::GetDecoderName() {
Aegisub::String VideoProviderCache::GetDecoderName() {
return master->GetDecoderName();
}

View file

@ -86,8 +86,8 @@ public:
virtual int GetWidth(); // Returns the video width in pixels
virtual int GetHeight(); // Returns the video height in pixels
virtual double GetFPS(); // Get framerate in frames per second
virtual void OverrideFrameTimeList(wxArrayInt list); // Override the list with the provided one, for VFR handling
virtual void OverrideFrameTimeList(Aegisub::IntArray list); // Override the list with the provided one, for VFR handling
virtual bool IsNativelyByFrames();
virtual wxString GetWarning();
virtual wxString GetDecoderName();
virtual Aegisub::String GetWarning();
virtual Aegisub::String GetDecoderName();
};

View file

@ -62,7 +62,7 @@
///////////////
// Constructor
// Based on Haali's code for DirectShowSource2
DirectShowVideoProvider::DirectShowVideoProvider(wxString _filename, double _fps) {
DirectShowVideoProvider::DirectShowVideoProvider(Aegisub::String _filename, double _fps) {
fps = _fps;
m_registered = false;
m_hFrameReady = CreateEvent(NULL, FALSE, FALSE, NULL);
@ -387,17 +387,17 @@ int DirectShowVideoProvider::NextFrame(DF &df,int &_fn) {
if (df.timestamp >= 0) {
// CFR frame number
int frameno = -1;
if (frameTime.Count() == 0) frameno = (int)((double)df.timestamp / defd + 0.5);
if (frameTime.size() == 0) frameno = (int)((double)df.timestamp / defd + 0.5);
// VFR
else {
for (unsigned int i=0;i<frameTime.Count();i++) {
for (unsigned int i=0;i<frameTime.size();i++) {
if (df.timestamp < (int64_t) frameTime[i] * 10000) {
frameno = i-1;
break;
}
}
if (frameno == -1) frameno = frameTime.Count()-1;
if (frameno == -1) frameno = frameTime.size()-1;
}
// Got a good one
@ -427,7 +427,7 @@ const AegiVideoFrame DirectShowVideoProvider::GetFrame(int n,int formatMask) {
// Time to seek to
REFERENCE_TIME cur;
cur = defd * n + 10001;
if (frameTime.Count() > (unsigned) n) cur = frameTime[n] * 10000 + 10001;
if (frameTime.size() > (unsigned) n) cur = frameTime[n] * 10000 + 10001;
if (cur < 0) cur = 0;
// Is next
@ -505,9 +505,9 @@ void DirectShowVideoProvider::GetFloatFrame(float* Buffer, int n) {
////////////////////////
// Override frame times
void DirectShowVideoProvider::OverrideFrameTimeList(wxArrayInt list) {
void DirectShowVideoProvider::OverrideFrameTimeList(Aegisub::IntArray list) {
frameTime = list;
num_frames = frameTime.Count();
num_frames = frameTime.size();
}
#endif

View file

@ -69,7 +69,7 @@ class DirectShowVideoProvider: public VideoProvider {
};
private:
wxArrayInt frameTime;
Aegisub::IntArray frameTime;
unsigned int last_fnum;
unsigned int width;
@ -97,7 +97,7 @@ private:
DWORD m_rot_cookie;
public:
DirectShowVideoProvider(wxString _filename, double _fps=0.0);
DirectShowVideoProvider(Aegisub::String _filename, double _fps=0.0);
~DirectShowVideoProvider();
void RefreshSubtitles();
@ -110,10 +110,10 @@ public:
double GetFPS() { return fps; };
int GetWidth() { return width; };
int GetHeight() { return height; };
wxString GetDecoderName() { return _("DirectShow"); }
Aegisub::String GetDecoderName() { return L"DirectShow"; }
bool IsNativelyByFrames() { return false; }
void OverrideFrameTimeList(wxArrayInt list);
void OverrideFrameTimeList(Aegisub::IntArray list);
int GetDesiredCacheSize() { return 8; }
};
@ -123,7 +123,7 @@ public:
// Factory
class DirectShowVideoProviderFactory : public VideoProviderFactory {
public:
VideoProvider *CreateProvider(wxString video,double fps=0.0) { return new DirectShowVideoProvider(video,fps); }
VideoProvider *CreateProvider(Aegisub::String video,double fps=0.0) { return new DirectShowVideoProvider(video,fps); }
};
#endif

View file

@ -119,8 +119,9 @@ void DummyVideoProvider::Create(double _fps, int frames, int _width, int _height
///////////////////////
// Parsing constructor
DummyVideoProvider::DummyVideoProvider(wxString filename, double _fps)
DummyVideoProvider::DummyVideoProvider(Aegisub::String _filename, double _fps)
{
wxString filename = _filename;
wxString params;
if (!filename.StartsWith(_T("?dummy:"), &params)) {
throw _T("Attempted creating dummy video provider with non-dummy filename");
@ -246,7 +247,7 @@ double DummyVideoProvider::GetFPS() {
////////////////////
// Get decoder name
wxString DummyVideoProvider::GetDecoderName() {
return _("Dummy Video Provider");
Aegisub::String DummyVideoProvider::GetDecoderName() {
return L"Dummy Video Provider";
}

View file

@ -59,7 +59,7 @@ private:
void Create(double fps, int frames, int _width, int _height, const wxColour &colour, bool pattern);
public:
DummyVideoProvider(wxString filename, double fps);
DummyVideoProvider(Aegisub::String filename, double fps);
DummyVideoProvider(double fps, int frames, int _width, int _height, const wxColour &colour, bool pattern);
~DummyVideoProvider();
@ -72,7 +72,7 @@ public:
int GetWidth();
int GetHeight();
double GetFPS();
wxString GetDecoderName();
Aegisub::String GetDecoderName();
};
#endif

View file

@ -58,7 +58,7 @@
VideoProvider *VideoProviderFactoryManager::GetProvider(wxString video,double fps) {
// First check special case of dummy video
if (video.StartsWith(_T("?dummy:"))) {
return new DummyVideoProvider(video, fps);
return new DummyVideoProvider(video.c_str(), fps);
}
// List of providers
@ -72,7 +72,7 @@ VideoProvider *VideoProviderFactoryManager::GetProvider(wxString video,double fp
for (unsigned int i=0;i<list.Count();i++) {
try {
// Create provider
VideoProvider *provider = GetFactory(list[i])->CreateProvider(video,fps);
VideoProvider *provider = GetFactory(list[i])->CreateProvider(video.c_str(),fps);
if (provider) {
// Cache if necessary
if (provider->GetDesiredCacheSize()) {