Abstracted video provider

Originally committed to SVN as r123.
This commit is contained in:
Rodrigo Braz Monteiro 2006-02-23 03:41:29 +00:00
parent 5cc37edf38
commit 61b8089de4
6 changed files with 137 additions and 73 deletions

View File

@ -97,7 +97,7 @@ void FrameMain::OnVideoTrackPoints(wxCommandEvent &event) {
// Get Video // Get Video
bool usedDirectshow; bool usedDirectshow;
VideoProvider *movie = new VideoProvider(videoBox->videoDisplay->videoName, wxString(_T("")), 1.0,usedDirectshow,true); VideoProvider *movie = new AvisynthVideoProvider(videoBox->videoDisplay->videoName, wxString(_T("")), 1.0,usedDirectshow,true);
// Create Tracker // Create Tracker
if( curline->Tracker ) delete curline->Tracker; if( curline->Tracker ) delete curline->Tracker;

View File

@ -157,7 +157,7 @@ void VideoDisplay::SetVideo(const wxString &filename) {
bool usedDirectshow; bool usedDirectshow;
provider = new VideoProvider(filename,GetTempWorkFile(),zoomValue,usedDirectshow,true); provider = new AvisynthVideoProvider(filename,GetTempWorkFile(),zoomValue,usedDirectshow,true);
// Set keyframes // Set keyframes
wxString ext = filename.Right(4).Lower(); wxString ext = filename.Right(4).Lower();

View File

@ -43,7 +43,7 @@
#include <wx/wxprec.h> #include <wx/wxprec.h>
#include <windows.h> #include <windows.h>
#include <time.h> #include <time.h>
#include "video_provider.h" #include "video_provider_avs.h"
////////////// //////////////

View File

@ -1,4 +1,4 @@
// Copyright (c) 2006, Fredrik Mellbin // Copyright (c) 2006, Rodrigo Braz Monteiro, Fredrik Mellbin
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
@ -33,70 +33,31 @@
// Contact: mailto:zeratul@cellosoft.com // Contact: mailto:zeratul@cellosoft.com
// //
#ifndef VIDEO_PROVIDER_H
#define VIDEO_PROVIDER_H
#include "avisynth_wrap.h" #pragma once
/*class GetFrameVPThread: public wxThread {
private:
int getting_n;
int current_n;
PClip video; ////////////////////////////
// Video Provider interface
wxThread::ExitCode Entry(); class VideoProvider {
public: public:
void GetFrame(int n); virtual ~VideoProvider() {}
GetFrameVPThread(PClip clip);
};*/
class VideoProvider: public AviSynthWrapper { virtual void RefreshSubtitles()=0;
private: virtual void SetDAR(double _dar)=0;
VideoInfo vi; virtual void SetZoom(double _zoom)=0;
wxString subfilename; virtual wxBitmap GetFrame(int n)=0;
virtual void GetFloatFrame(float* Buffer, int n)=0;
int last_fnum; virtual int GetPosition()=0;
virtual int GetFrameCount()=0;
virtual double GetFPS()=0;
unsigned char* data; virtual int GetWidth()=0;
wxBitmap last_frame; virtual int GetHeight()=0;
virtual double GetZoom()=0;
double dar; virtual int GetSourceWidth()=0;
double zoom; virtual int GetSourceHeight()=0;
PClip RGB32Video;
PClip SubtitledVideo;
PClip ResizedVideo;
PClip OpenVideo(wxString _filename, bool &usedDirectshow, bool mpeg2dec3_priority = true);
PClip ApplySubtitles(wxString _filename, PClip videosource);
PClip ApplyDARZoom(double _zoom, double _dar, PClip videosource);
wxBitmap GetFrame(int n, bool force);
void LoadVSFilter();
public:
VideoProvider(wxString _filename, wxString _subfilename, double _zoom, bool &usedDirectshow, bool mpeg2dec3_priority = true);
~VideoProvider();
void RefreshSubtitles();
void SetDAR(double _dar);
void SetZoom(double _zoom);
wxBitmap GetFrame(int n) { return GetFrame(n,false); };
void GetFloatFrame(float* Buffer, int n);
// properties
int GetPosition() { return last_fnum; };
int GetFrameCount() { return vi.num_frames; };
double GetFPS() { return (double)vi.fps_numerator/(double)vi.fps_denominator; };
int GetWidth() { return vi.width; };
int GetHeight() { return vi.height; };
double GetZoom() { return zoom; };
int GetSourceWidth() { return RGB32Video->GetVideoInfo().width; };
int GetSourceHeight() { return RGB32Video->GetVideoInfo().height; };
}; };
#endif

View File

@ -35,12 +35,12 @@
#include <wx/filename.h> #include <wx/filename.h>
#include <wx/msw/registry.h> #include <wx/msw/registry.h>
#include "video_provider.h" #include "video_provider_avs.h"
#include "options.h" #include "options.h"
#include "main.h" #include "main.h"
VideoProvider::VideoProvider(wxString _filename, wxString _subfilename, double _zoom, bool &usedDirectshow, bool mpeg2dec3_priority) { AvisynthVideoProvider::AvisynthVideoProvider(wxString _filename, wxString _subfilename, double _zoom, bool &usedDirectshow, bool mpeg2dec3_priority) {
RGB32Video = NULL; RGB32Video = NULL;
SubtitledVideo = NULL; SubtitledVideo = NULL;
ResizedVideo = NULL; ResizedVideo = NULL;
@ -68,14 +68,14 @@ VideoProvider::VideoProvider(wxString _filename, wxString _subfilename, double _
vi = ResizedVideo->GetVideoInfo(); vi = ResizedVideo->GetVideoInfo();
} }
VideoProvider::~VideoProvider() { AvisynthVideoProvider::~AvisynthVideoProvider() {
RGB32Video = NULL; RGB32Video = NULL;
SubtitledVideo = NULL; SubtitledVideo = NULL;
ResizedVideo = NULL; ResizedVideo = NULL;
if( data ) delete data; if( data ) delete data;
} }
void VideoProvider::RefreshSubtitles() { void AvisynthVideoProvider::RefreshSubtitles() {
ResizedVideo = NULL; ResizedVideo = NULL;
SubtitledVideo = NULL; SubtitledVideo = NULL;
@ -84,7 +84,7 @@ void VideoProvider::RefreshSubtitles() {
GetFrame(last_fnum,true); GetFrame(last_fnum,true);
} }
void VideoProvider::SetDAR(double _dar) { void AvisynthVideoProvider::SetDAR(double _dar) {
dar = _dar; dar = _dar;
ResizedVideo = NULL; ResizedVideo = NULL;
@ -95,7 +95,7 @@ void VideoProvider::SetDAR(double _dar) {
GetFrame(last_fnum,true); GetFrame(last_fnum,true);
} }
void VideoProvider::SetZoom(double _zoom) { void AvisynthVideoProvider::SetZoom(double _zoom) {
zoom = _zoom; zoom = _zoom;
ResizedVideo = NULL; ResizedVideo = NULL;
@ -106,7 +106,7 @@ void VideoProvider::SetZoom(double _zoom) {
GetFrame(last_fnum,true); GetFrame(last_fnum,true);
} }
PClip VideoProvider::OpenVideo(wxString _filename, bool &usedDirectshow, bool mpeg2dec3_priority) { PClip AvisynthVideoProvider::OpenVideo(wxString _filename, bool &usedDirectshow, bool mpeg2dec3_priority) {
wxMutexLocker lock(AviSynthMutex); wxMutexLocker lock(AviSynthMutex);
AVSValue script; AVSValue script;
@ -161,7 +161,7 @@ PClip VideoProvider::OpenVideo(wxString _filename, bool &usedDirectshow, bool mp
return (env->Invoke("Cache", script)).AsClip(); return (env->Invoke("Cache", script)).AsClip();
} }
PClip VideoProvider::ApplySubtitles(wxString _filename, PClip videosource) { PClip AvisynthVideoProvider::ApplySubtitles(wxString _filename, PClip videosource) {
wxMutexLocker lock(AviSynthMutex); wxMutexLocker lock(AviSynthMutex);
// Insert subs // Insert subs
@ -180,7 +180,7 @@ PClip VideoProvider::ApplySubtitles(wxString _filename, PClip videosource) {
return (env->Invoke("Cache", script)).AsClip(); return (env->Invoke("Cache", script)).AsClip();
} }
PClip VideoProvider::ApplyDARZoom(double _zoom, double _dar, PClip videosource) { PClip AvisynthVideoProvider::ApplyDARZoom(double _zoom, double _dar, PClip videosource) {
wxMutexLocker lock(AviSynthMutex); wxMutexLocker lock(AviSynthMutex);
AVSValue script; AVSValue script;
@ -205,7 +205,7 @@ PClip VideoProvider::ApplyDARZoom(double _zoom, double _dar, PClip videosource)
return (env->Invoke("Cache",script)).AsClip(); return (env->Invoke("Cache",script)).AsClip();
} }
wxBitmap VideoProvider::GetFrame(int n, bool force) { wxBitmap AvisynthVideoProvider::GetFrame(int n, bool force) {
if (n != last_fnum || force) { if (n != last_fnum || force) {
wxMutexLocker lock(AviSynthMutex); wxMutexLocker lock(AviSynthMutex);
@ -234,7 +234,7 @@ wxBitmap VideoProvider::GetFrame(int n, bool force) {
return wxBitmap(last_frame); return wxBitmap(last_frame);
} }
void VideoProvider::GetFloatFrame(float* Buffer, int n) { void AvisynthVideoProvider::GetFloatFrame(float* Buffer, int n) {
wxMutexLocker lock(AviSynthMutex); wxMutexLocker lock(AviSynthMutex);
PVideoFrame frame = ResizedVideo->GetFrame(n,env); PVideoFrame frame = ResizedVideo->GetFrame(n,env);
@ -253,7 +253,7 @@ void VideoProvider::GetFloatFrame(float* Buffer, int n) {
} }
} }
void VideoProvider::LoadVSFilter() { void AvisynthVideoProvider::LoadVSFilter() {
// Loading an avisynth plugin multiple times does almost nothing // Loading an avisynth plugin multiple times does almost nothing
wxFileName vsfilterPath(AegisubApp::folderName + _T("vsfilter.dll")); wxFileName vsfilterPath(AegisubApp::folderName + _T("vsfilter.dll"));

103
core/video_provider_avs.h Normal file
View File

@ -0,0 +1,103 @@
// 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
//
#ifndef VIDEO_PROVIDER_AVS_H
#define VIDEO_PROVIDER_AVS_H
#include "avisynth_wrap.h"
#include "video_provider.h"
/*class GetFrameVPThread: public wxThread {
private:
int getting_n;
int current_n;
PClip video;
wxThread::ExitCode Entry();
public:
void GetFrame(int n);
GetFrameVPThread(PClip clip);
};*/
class AvisynthVideoProvider: public VideoProvider, AviSynthWrapper {
private:
VideoInfo vi;
wxString subfilename;
int last_fnum;
unsigned char* data;
wxBitmap last_frame;
double dar;
double zoom;
PClip RGB32Video;
PClip SubtitledVideo;
PClip ResizedVideo;
PClip OpenVideo(wxString _filename, bool &usedDirectshow, bool mpeg2dec3_priority = true);
PClip ApplySubtitles(wxString _filename, PClip videosource);
PClip ApplyDARZoom(double _zoom, double _dar, PClip videosource);
wxBitmap GetFrame(int n, bool force);
void LoadVSFilter();
public:
AvisynthVideoProvider(wxString _filename, wxString _subfilename, double _zoom, bool &usedDirectshow, bool mpeg2dec3_priority = true);
~AvisynthVideoProvider();
void RefreshSubtitles();
void SetDAR(double _dar);
void SetZoom(double _zoom);
wxBitmap GetFrame(int n) { return GetFrame(n,false); };
void GetFloatFrame(float* Buffer, int n);
// properties
int GetPosition() { return last_fnum; };
int GetFrameCount() { return vi.num_frames; };
double GetFPS() { return (double)vi.fps_numerator/(double)vi.fps_denominator; };
int GetWidth() { return vi.width; };
int GetHeight() { return vi.height; };
double GetZoom() { return zoom; };
int GetSourceWidth() { return RGB32Video->GetVideoInfo().width; };
int GetSourceHeight() { return RGB32Video->GetVideoInfo().height; };
};
#endif