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 // String array
typedef std::vector<String> StringArray; 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 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" // 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" // 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. // How many frames does this provider wants that Aegisub caches? Set to 0 if it doesn't require caching.
virtual int GetDesiredCacheSize() { return 0; } virtual int GetDesiredCacheSize() { return 0; }
// For providers that are natively time-based (e.g. DirectShow) // For providers that are natively time-based (e.g. DirectShow)
virtual bool IsNativelyByFrames() { return true; } 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 // If this video provider has a built-in subtitles provider, return that
virtual SubtitlesProvider *GetAsSubtitlesProvider() { return NULL; } virtual SubtitlesProvider *GetAsSubtitlesProvider() { return NULL; }
@ -87,5 +87,5 @@ public:
// Factory // Factory
class VideoProviderFactory { class VideoProviderFactory {
public: 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 // Get the current list of frames/times
wxArrayInt FrameRate::GetFrameTimeList() { Aegisub::IntArray FrameRate::GetFrameTimeList() {
wxArrayInt final; return Frame;
for (unsigned int i=0;i<Frame.size();i++) final.Add(Frame[i]);
return final;
} }

View file

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

View file

@ -52,7 +52,7 @@
/////////////// ///////////////
// Constructor // 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)); AVSTRACE(wxString::Format(_T("AvisynthVideoProvider: Creating new AvisynthVideoProvider: \"%s\", \"%s\""), _filename, _subfilename));
bool mpeg2dec3_priority = true; bool mpeg2dec3_priority = true;
RGB32Video = NULL; RGB32Video = NULL;
@ -97,7 +97,7 @@ AvisynthVideoProvider::~AvisynthVideoProvider() {
///////////////////////////////////////// /////////////////////////////////////////
// Actually open the video into Avisynth // 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")); AVSTRACE(_T("AvisynthVideoProvider::OpenVideo: Opening video"));
wxMutexLocker lock(AviSynthMutex); wxMutexLocker lock(AviSynthMutex);
AVSTRACE(_T("AvisynthVideoProvider::OpenVideo: Got AVS mutex")); AVSTRACE(_T("AvisynthVideoProvider::OpenVideo: Got AVS mutex"));
@ -107,7 +107,7 @@ PClip AvisynthVideoProvider::OpenVideo(wxString _filename, bool mpeg2dec3_priori
usedDirectShow = false; usedDirectShow = false;
decoderName = _("Unknown"); decoderName = _("Unknown");
wxString extension = _filename.Right(4); wxString extension = wxString(_filename.c_str()).Right(4);
extension.LowerCase(); extension.LowerCase();
try { try {
@ -369,7 +369,7 @@ const AegiVideoFrame AvisynthVideoProvider::GetFrame(int _n,int formatMask) {
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
// Apply VSFilter subtitles, or whatever is appropriate // 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")); AVSTRACE(_T("AvisynthVideoProvider::ApplySutitles: Applying subtitles"));
wxMutexLocker lock(AviSynthMutex); wxMutexLocker lock(AviSynthMutex);
AVSTRACE(_T("AvisynthVideoProvider::ApplySutitles: Got AVS mutex")); AVSTRACE(_T("AvisynthVideoProvider::ApplySutitles: Got AVS mutex"));
@ -383,7 +383,7 @@ PClip AvisynthVideoProvider::ApplySubtitles(wxString _filename, PClip videosourc
try { try {
AVSTRACE(_T("AvisynthVideoProvider::ApplySutitles: Now invoking ") + rendererCallString); 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")); AVSTRACE(_T("AvisynthVideoProvider::ApplySutitles: Invoked successfully"));
} }
catch (AvisynthError &err) { catch (AvisynthError &err) {
@ -422,7 +422,7 @@ void AvisynthVideoProvider::LoadSubtitles(AssFile *subs) {
delete subs; delete subs;
// Load subtitles // Load subtitles
SubtitledVideo = ApplySubtitles(subfilename, RGB32Video); SubtitledVideo = ApplySubtitles(subfilename.c_str(), RGB32Video);
AVSTRACE(_T("AvisynthVideoProvider::RefreshSubtitles: Subtitles refreshed")); AVSTRACE(_T("AvisynthVideoProvider::RefreshSubtitles: Subtitles refreshed"));
vi = SubtitledVideo->GetVideoInfo(); vi = SubtitledVideo->GetVideoInfo();
AVSTRACE(_T("AvisynthVideoProvider: Got video info")); AVSTRACE(_T("AvisynthVideoProvider: Got video info"));
@ -527,9 +527,9 @@ void AvisynthVideoProvider::OverrideFrameTimeList(wxArrayInt list) {
/////////////// ///////////////
// Get warning // Get warning
wxString AvisynthVideoProvider::GetWarning() { Aegisub::String 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!"); 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 _T(""); else return L"";
} }
#endif #endif

View file

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

View file

@ -86,8 +86,8 @@ public:
virtual int GetWidth(); // Returns the video width in pixels virtual int GetWidth(); // Returns the video width in pixels
virtual int GetHeight(); // Returns the video height in pixels virtual int GetHeight(); // Returns the video height in pixels
virtual double GetFPS(); // Get framerate in frames per second 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 bool IsNativelyByFrames();
virtual wxString GetWarning(); virtual Aegisub::String GetWarning();
virtual wxString GetDecoderName(); virtual Aegisub::String GetDecoderName();
}; };

View file

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

View file

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

View file

@ -119,8 +119,9 @@ void DummyVideoProvider::Create(double _fps, int frames, int _width, int _height
/////////////////////// ///////////////////////
// Parsing constructor // Parsing constructor
DummyVideoProvider::DummyVideoProvider(wxString filename, double _fps) DummyVideoProvider::DummyVideoProvider(Aegisub::String _filename, double _fps)
{ {
wxString filename = _filename;
wxString params; wxString params;
if (!filename.StartsWith(_T("?dummy:"), &params)) { if (!filename.StartsWith(_T("?dummy:"), &params)) {
throw _T("Attempted creating dummy video provider with non-dummy filename"); throw _T("Attempted creating dummy video provider with non-dummy filename");
@ -246,7 +247,7 @@ double DummyVideoProvider::GetFPS() {
//////////////////// ////////////////////
// Get decoder name // Get decoder name
wxString DummyVideoProvider::GetDecoderName() { Aegisub::String DummyVideoProvider::GetDecoderName() {
return _("Dummy Video Provider"); 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); void Create(double fps, int frames, int _width, int _height, const wxColour &colour, bool pattern);
public: 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(double fps, int frames, int _width, int _height, const wxColour &colour, bool pattern);
~DummyVideoProvider(); ~DummyVideoProvider();
@ -72,7 +72,7 @@ public:
int GetWidth(); int GetWidth();
int GetHeight(); int GetHeight();
double GetFPS(); double GetFPS();
wxString GetDecoderName(); Aegisub::String GetDecoderName();
}; };
#endif #endif

View file

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