Cleaned up provider creation interface

Originally committed to SVN as r148.
This commit is contained in:
Rodrigo Braz Monteiro 2006-02-24 08:43:44 +00:00
parent 9b395f283d
commit 360147d4ea
8 changed files with 37 additions and 20 deletions

View File

@ -14,7 +14,7 @@
#include <wx/rawbmp.h> #include <wx/rawbmp.h>
#include "subs_grid.h" #include "subs_grid.h"
#include "frame_main.h" #include "frame_main.h"
#include "video_provider_avs.h" #include "video_provider.h"
#include "video_display.h" #include "video_display.h"
#include "video_box.h" #include "video_box.h"
#include "ass_file.h" #include "ass_file.h"
@ -75,8 +75,7 @@ void FrameMain::OnVideoTrackPoints(wxCommandEvent &event) {
if( !config.FeatureNumber ) return; if( !config.FeatureNumber ) return;
// Get Video // Get Video
bool usedDirectshow; VideoProvider *movie = VideoProvider::GetProvider(videoBox->videoDisplay->videoName, wxString(_T("")));
VideoProvider *movie = new AvisynthVideoProvider(videoBox->videoDisplay->videoName, wxString(_T("")), 1.0,usedDirectshow);
// Create Tracker // Create Tracker
if( curline->Tracker ) delete curline->Tracker; if( curline->Tracker ) delete curline->Tracker;

View File

@ -163,6 +163,8 @@ void VideoDisplay::SetVideo(const wxString &filename) {
// Choose a provider // Choose a provider
bool usedDirectshow = false; bool usedDirectshow = false;
provider = VideoProvider::GetProvider(filename,GetTempWorkFile()); provider = VideoProvider::GetProvider(filename,GetTempWorkFile());
provider->SetZoom(zoomValue);
provider->SetDAR(GetARFromType(arType));
// Set keyframes // Set keyframes
wxString ext = filename.Right(4).Lower(); wxString ext = filename.Right(4).Lower();
@ -484,17 +486,20 @@ void VideoDisplay::SetZoomPos(int value) {
} }
/////////////////// //////////////////////////
// Sets zoom level // Calculate aspect ratio
double VideoDisplay::GetARFromType(int type) {
if (type == 0) return (double)provider->GetSourceWidth()/(double)provider->GetSourceHeight();
if (type == 1) return 4.0/3.0;
if (type == 2) return 16.0/9.0;
}
/////////////////////
// Sets aspect ratio
void VideoDisplay::SetAspectRatio(int value) { void VideoDisplay::SetAspectRatio(int value) {
if (provider) { if (provider) {
if (value == 0) provider->SetDAR(GetARFromType(value));
provider->SetDAR((float)provider->GetSourceWidth()/(float)provider->GetSourceHeight());
else if (value == 1)
provider->SetDAR(4.0/3.0);
else if (value == 2)
provider->SetDAR(16.0/9.0);
arType = value; arType = value;
UpdateSize(); UpdateSize();
RefreshVideo(); RefreshVideo();

View File

@ -131,6 +131,7 @@ public:
void RefreshVideo(); void RefreshVideo();
void DrawText( wxPoint Pos, wxString Text ); void DrawText( wxPoint Pos, wxString Text );
void UpdatePositionDisplay(); void UpdatePositionDisplay();
double GetARFromType(int type);
void SetAspectRatio(int type); void SetAspectRatio(int type);
void SetZoom(double value); void SetZoom(double value);
int GetAspectRatio() { return arType; } int GetAspectRatio() { return arType; }

View File

@ -62,9 +62,13 @@ VideoProvider *VideoProvider::GetProvider(wxString video,wxString subtitles) {
#ifdef USE_LAVC #ifdef USE_LAVC
if (Options.AsBool(_T("Use ffmpeg"))) { if (Options.AsBool(_T("Use ffmpeg"))) {
try { try {
provider = new LAVCVideoProvider(video,subtitles,1.0); provider = new LAVCVideoProvider(video,subtitles);
} }
catch (...) { catch (...) {
// Delete old provider
delete provider;
// Try to fallback to avisynth
if (avisynthAvailable) { if (avisynthAvailable) {
wxMessageBox(_T("Failed loading FFmpeg decoder for video, falling back to Avisynth."),_T("FFmpeg error.")); wxMessageBox(_T("Failed loading FFmpeg decoder for video, falling back to Avisynth."),_T("FFmpeg error."));
provider = NULL; provider = NULL;
@ -79,7 +83,15 @@ VideoProvider *VideoProvider::GetProvider(wxString video,wxString subtitles) {
// Use avisynth provider // Use avisynth provider
#ifdef __WINDOWS__ #ifdef __WINDOWS__
bool usedDirectshow = false; bool usedDirectshow = false;
if (!provider) provider = new AvisynthVideoProvider(video,subtitles,1.0,usedDirectshow); if (!provider) {
try {
provider = new AvisynthVideoProvider(video,subtitles,usedDirectshow);
}
catch (...) {
delete provider;
throw;
}
}
#endif #endif
// Return provider // Return provider

View File

@ -43,7 +43,7 @@
#ifdef __WINDOWS__ #ifdef __WINDOWS__
AvisynthVideoProvider::AvisynthVideoProvider(wxString _filename, wxString _subfilename, double _zoom, bool &usedDirectshow) { AvisynthVideoProvider::AvisynthVideoProvider(wxString _filename, wxString _subfilename, bool &usedDirectshow) {
bool mpeg2dec3_priority = true; bool mpeg2dec3_priority = true;
RGB32Video = NULL; RGB32Video = NULL;
SubtitledVideo = NULL; SubtitledVideo = NULL;
@ -53,7 +53,7 @@ AvisynthVideoProvider::AvisynthVideoProvider(wxString _filename, wxString _subfi
last_fnum = -1; last_fnum = -1;
subfilename = _subfilename; subfilename = _subfilename;
zoom = _zoom; zoom = 1.0;
LoadVSFilter(); LoadVSFilter();

View File

@ -83,7 +83,7 @@ private:
void LoadVSFilter(); void LoadVSFilter();
public: public:
AvisynthVideoProvider(wxString _filename, wxString _subfilename, double _zoom, bool &usedDirectshow); AvisynthVideoProvider(wxString _filename, wxString _subfilename, bool &usedDirectshow);
~AvisynthVideoProvider(); ~AvisynthVideoProvider();
void RefreshSubtitles(); void RefreshSubtitles();

View File

@ -45,7 +45,7 @@
/////////////// ///////////////
// Constructor // Constructor
LAVCVideoProvider::LAVCVideoProvider(wxString filename, wxString subfilename, double _zoom) { LAVCVideoProvider::LAVCVideoProvider(wxString filename, wxString subfilename) {
// Init variables // Init variables
codecContext = NULL; codecContext = NULL;
formatContext = NULL; formatContext = NULL;
@ -57,7 +57,7 @@ LAVCVideoProvider::LAVCVideoProvider(wxString filename, wxString subfilename, do
buffer1Size = 0; buffer1Size = 0;
buffer2Size = 0; buffer2Size = 0;
vidStream = -1; vidStream = -1;
zoom = _zoom; zoom = 1.0;
validFrame = false; validFrame = false;
// Register types // Register types

View File

@ -87,7 +87,7 @@ private:
wxBitmap AVFrameToWX(AVFrame *frame); wxBitmap AVFrameToWX(AVFrame *frame);
public: public:
LAVCVideoProvider(wxString filename, wxString subfilename, double zoom); LAVCVideoProvider(wxString filename, wxString subfilename);
~LAVCVideoProvider(); ~LAVCVideoProvider();
void RefreshSubtitles(); void RefreshSubtitles();