Changed video providers to be initialized explicitly. (Only avisynth tested, though)

Originally committed to SVN as r1890.
This commit is contained in:
Rodrigo Braz Monteiro 2008-03-05 02:05:01 +00:00
parent 5047295635
commit 59f1962e7c
9 changed files with 413 additions and 139 deletions

View File

@ -40,6 +40,16 @@
#include "video_provider_dummy.h"
#include "options.h"
#include "vfr.h"
#ifdef WITH_AVISYNTH
#include "video_provider_avs.h"
#endif
#ifdef WITH_DIRECTSHOW
#include "video_provider_dshow.h"
#endif
#ifdef WITH_FFMPEG
#include "video_provider_lavc.h"
#endif
#include "video_provider_dummy.h"
///////////////
@ -149,6 +159,12 @@ VideoProvider *VideoProviderFactory::GetProvider(wxString video,double fps) {
return new DummyVideoProvider(video, fps);
}
// Register the first time
// HACK: move this into program initialization later
static bool init = false;
if (!init) RegisterProviders();
init = true;
// List of providers
wxArrayString list = GetFactoryList(Options.AsText(_T("Video provider")));
@ -172,6 +188,21 @@ VideoProvider *VideoProviderFactory::GetProvider(wxString video,double fps) {
}
//////////////////////////
// Register all providers
void VideoProviderFactory::RegisterProviders() {
#ifdef WITH_AVISYNTH
new AvisynthVideoProviderFactory();
#endif
#ifdef WITH_DIRECTSHOW
new DirectShowVideoProviderFactory();
#endif
#ifdef WITH_FFMPEG
new LAVCVideoProviderFactory();
#endif
}
//////////
// Static
template <class VideoProviderFactory> std::map<wxString,VideoProviderFactory*>* AegisubFactory<VideoProviderFactory>::factories=NULL;

View File

@ -111,4 +111,6 @@ protected:
public:
virtual ~VideoProviderFactory() {}
static VideoProvider *GetProvider(wxString video,double fps=0.0);
static void RegisterProviders();
};

View File

@ -41,9 +41,7 @@
#include <wx/filename.h>
#include <wx/msw/registry.h>
#include <wx/filename.h>
#include "avisynth_wrap.h"
#include "video_provider.h"
#include "subtitles_provider.h"
#include "video_provider_avs.h"
#include "video_context.h"
#include "options.h"
#include "standard_paths.h"
@ -52,68 +50,6 @@
#include "gl_wrap.h"
////////////
// Provider
class AvisynthVideoProvider: public VideoProvider, SubtitlesProvider, AviSynthWrapper {
private:
VideoInfo vi;
AegiVideoFrame iframe;
bool usedDirectShow;
wxString rendererCallString;
wxString decoderName;
int num_frames;
int last_fnum;
double fps;
wxArrayInt frameTime;
bool byFrame;
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);
bool LockedToVideo() { return true; }
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);
bool IsNativelyByFrames() { return byFrame; }
wxString GetWarning();
wxString GetDecoderName() { return _T("Avisynth/") + decoderName; }
};
///////////
// Factory
class AvisynthVideoProviderFactory : public VideoProviderFactory {
public:
VideoProvider *CreateProvider(wxString video,double fps=0.0) { return new AvisynthVideoProvider(video,fps); }
AvisynthVideoProviderFactory() : VideoProviderFactory(_T("avisynth")) {}
} registerAVS;
///////////////
// Constructor
AvisynthVideoProvider::AvisynthVideoProvider(wxString _filename, double _fps) {

View File

@ -0,0 +1,108 @@
// 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
//
///////////
// Headers
#include <wx/wxprec.h>
#ifdef WITH_AVISYNTH
#include "avisynth_wrap.h"
#include "video_provider.h"
#include "subtitles_provider.h"
////////////
// Provider
class AvisynthVideoProvider: public VideoProvider, SubtitlesProvider, AviSynthWrapper {
private:
VideoInfo vi;
AegiVideoFrame iframe;
bool usedDirectShow;
wxString rendererCallString;
wxString decoderName;
int num_frames;
int last_fnum;
double fps;
wxArrayInt frameTime;
bool byFrame;
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);
bool LockedToVideo() { return true; }
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);
bool IsNativelyByFrames() { return byFrame; }
wxString GetWarning();
wxString GetDecoderName() { return _T("Avisynth/") + decoderName; }
};
///////////
// Factory
class AvisynthVideoProviderFactory : public VideoProviderFactory {
public:
VideoProvider *CreateProvider(wxString video,double fps=0.0) { return new AvisynthVideoProvider(video,fps); }
AvisynthVideoProviderFactory() : VideoProviderFactory(_T("avisynth")) {}
};
#endif

View File

@ -51,12 +51,12 @@
#include <windows.h>
#include <tchar.h>
#include <initguid.h>
#include "video_provider.h"
#include "utils.h"
#include "vfr.h"
#include "videosink.h"
#include "gl_wrap.h"
#include "options.h"
#include "video_provider_dshow.h"
///////////////////////////////////

View File

@ -0,0 +1,128 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro, Mike Matsnev
// 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_DIRECTSHOW
#pragma warning(disable: 4995)
#include <wx/wxprec.h>
#ifdef __WINDOWS__
#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.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;
int64_t defd;
HRESULT OpenVideo(wxString _filename);
void CloseVideo();
static void ReadFrame(__int64 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; };
wxString GetDecoderName() { return _("DirectShow"); }
void OverrideFrameTimeList(wxArrayInt list);
};
///////////
// Factory
class DirectShowVideoProviderFactory : public VideoProviderFactory {
public:
VideoProvider *CreateProvider(wxString video,double fps=0.0) { return new DirectShowVideoProvider(video,fps); }
DirectShowVideoProviderFactory() : VideoProviderFactory(_T("dshow")) {}
};
#endif

View File

@ -42,11 +42,6 @@
#ifdef WIN32
#define EMULATE_INTTYPES
#endif
extern "C" {
#include <ffmpeg/avcodec.h>
#include <ffmpeg/avformat.h>
#include <ffmpeg/swscale.h>
}
#include <wx/wxprec.h>
#include <wx/image.h>
#include <algorithm>
@ -58,74 +53,6 @@ extern "C" {
#include "ass_file.h"
///////////////////////
// LibAVCodec provider
class LAVCVideoProvider : public VideoProvider {
friend class LAVCAudioProvider;
private:
MatroskaWrapper mkv;
LAVCFile *lavcfile;
AVCodecContext *codecContext;
AVStream *stream;
AVCodec *codec;
AVFrame *frame;
int vidStream;
AVFrame *frameRGB;
uint8_t *bufferRGB;
SwsContext *sws_context;
int display_w;
int display_h;
wxArrayInt bytePos;
bool isMkv;
int64_t lastDecodeTime;
int frameNumber;
int length;
AegiVideoFrame curFrame;
bool validFrame;
uint8_t *buffer1;
uint8_t *buffer2;
int buffer1Size;
int buffer2Size;
bool GetNextFrame();
void LoadVideo(wxString filename, double fps);
void Close();
protected:
const AegiVideoFrame DoGetFrame(int n);
public:
LAVCVideoProvider(wxString filename, double fps);
~LAVCVideoProvider();
int GetPosition();
int GetFrameCount();
int GetWidth();
int GetHeight();
double GetFPS();
wxString GetDecoderName() { return _T("FFMpeg/libavcodec"); }
bool IsNativelyByFrames() { return true; }
};
///////////
// Factory
class LAVCVideoProviderFactory : public VideoProviderFactory {
public:
VideoProvider *CreateProvider(wxString video,double fps=0.0) { return new LAVCVideoProvider(video,fps); }
LAVCVideoProviderFactory() : VideoProviderFactory(_T("ffmpeg")) {}
} registerLAVCVideo;
///////////////
// Constructor
LAVCVideoProvider::LAVCVideoProvider(wxString filename,double fps) {

View File

@ -0,0 +1,122 @@
// Copyright (c) 2006-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_FFMPEG
#ifdef WIN32
#define EMULATE_INTTYPES
#endif
extern "C" {
#include <ffmpeg/avcodec.h>
#include <ffmpeg/avformat.h>
#include <ffmpeg/swscale.h>
}
#include "video_provider.h"
#include "mkv_wrap.h"
#include "lavc_file.h"
///////////////////////
// LibAVCodec provider
class LAVCVideoProvider : public VideoProvider {
friend class LAVCAudioProvider;
private:
MatroskaWrapper mkv;
LAVCFile *lavcfile;
AVCodecContext *codecContext;
AVStream *stream;
AVCodec *codec;
AVFrame *frame;
int vidStream;
AVFrame *frameRGB;
uint8_t *bufferRGB;
SwsContext *sws_context;
int display_w;
int display_h;
wxArrayInt bytePos;
bool isMkv;
int64_t lastDecodeTime;
int frameNumber;
int length;
AegiVideoFrame curFrame;
bool validFrame;
uint8_t *buffer1;
uint8_t *buffer2;
int buffer1Size;
int buffer2Size;
bool GetNextFrame();
void LoadVideo(wxString filename, double fps);
void Close();
protected:
const AegiVideoFrame DoGetFrame(int n);
public:
LAVCVideoProvider(wxString filename, double fps);
~LAVCVideoProvider();
int GetPosition();
int GetFrameCount();
int GetWidth();
int GetHeight();
double GetFPS();
wxString GetDecoderName() { return _T("FFMpeg/libavcodec"); }
bool IsNativelyByFrames() { return true; }
};
///////////
// Factory
class LAVCVideoProviderFactory : public VideoProviderFactory {
public:
VideoProvider *CreateProvider(wxString video,double fps=0.0) { return new LAVCVideoProvider(video,fps); }
LAVCVideoProviderFactory() : VideoProviderFactory(_T("ffmpeg")) {}
};
#endif

View File

@ -1471,6 +1471,14 @@
<File
RelativePath="..\..\aegisub\version.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="FINAL_RELEASE"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\aegisub\version.h"
@ -1568,10 +1576,18 @@
RelativePath="..\..\aegisub\video_provider_avs.cpp"
>
</File>
<File
RelativePath="..\..\aegisub\video_provider_avs.h"
>
</File>
<File
RelativePath="..\..\aegisub\video_provider_dshow.cpp"
>
</File>
<File
RelativePath="..\..\aegisub\video_provider_dshow.h"
>
</File>
<File
RelativePath="..\..\aegisub\video_provider_dummy.cpp"
>
@ -1584,6 +1600,10 @@
RelativePath="..\..\aegisub\video_provider_lavc.cpp"
>
</File>
<File
RelativePath="..\..\aegisub\video_provider_lavc.h"
>
</File>
<File
RelativePath="..\..\aegisub\video_slider.cpp"
>