add a progress dialog to the ffmpegsource video provider's indexing process

Originally committed to SVN as r2318.
This commit is contained in:
Karl Blomster 2008-09-04 22:17:34 +00:00
parent 7fb0d975bd
commit 1655f97a59
2 changed files with 44 additions and 9 deletions

View file

@ -39,9 +39,8 @@
// Headers
#include "video_provider_ffmpegsource.h"
#include <ffms.h>
#include "vfr.h"
#include "video_context.h"
#include "options.h" // for later use
#include "options.h"
///////////////
@ -81,15 +80,25 @@ void FFmpegSourceVideoProvider::LoadVideo(Aegisub::String filename, double fps)
wxString CacheName(filename.c_str());
CacheName.append(_T(".ffindex"));
// initialize index object
FrameIndex *Index = FFMS_CreateFrameIndex();
// try to read index (these index functions all return 0 on success)
if (FFMS_ReadIndex(CacheName.char_str(), Index, FFMSErrorMessage, MessageSize)) {
FrameIndex *Index;
// try to read index
Index = FFMS_ReadIndex(CacheName.char_str(), FFMSErrorMessage, MessageSize);
if (Index == NULL) {
// reading failed, create index
if (FFMS_MakeIndex(FileNameWX.char_str(), Index, 0, NULL, NULL, FFMSErrorMessage, MessageSize)) {
// prepare stuff for callback
IndexingProgressDialog Progress;
Progress.IndexingCanceled = false;
Progress.ProgressDialog = new DialogProgress(NULL, _("Indexing"), &Progress.IndexingCanceled, _("Reading keyframes and timecodes from video"), 0, 1);
Progress.ProgressDialog->Show();
Progress.ProgressDialog->SetProgress(0,1);
Index = FFMS_MakeIndex(FileNameWX.char_str(), 0, "", FFmpegSourceVideoProvider::UpdateIndexingProgress, &Progress, FFMSErrorMessage, MessageSize);
if (Index == NULL) {
ErrorMsg.Printf(_T("FFmpegSource video provider: %s"), FFMSErrorMessage);
throw ErrorMsg;
}
Progress.ProgressDialog->Destroy();
// write it to disk
if (FFMS_WriteIndex(CacheName.char_str(), Index, FFMSErrorMessage, MessageSize)) {
ErrorMsg.Printf(_T("FFmpegSource video provider: %s"), FFMSErrorMessage);
@ -194,6 +203,20 @@ void FFmpegSourceVideoProvider::Close() {
FrameNumber = -1;
}
///////////////
// Update indexing progress
int __stdcall FFmpegSourceVideoProvider::UpdateIndexingProgress(int State, int64_t Current, int64_t Total, void *Private) {
IndexingProgressDialog *Progress = (IndexingProgressDialog *)Private;
Progress->ProgressDialog->SetProgress(int(Current), int(Total));
if (Progress->IndexingCanceled) {
// Close();
return 1;
} else {
return 0;
}
}
///////////////
// Get frame
const AegiVideoFrame FFmpegSourceVideoProvider::GetFrame(int _n, int FormatType) {
@ -289,4 +312,6 @@ double FFmpegSourceVideoProvider::GetFPS() {
}
#endif /* WITH_FFMPEGSOURCE */

View file

@ -42,6 +42,8 @@
#endif /* WIN32 */
#include "include/aegisub/video_provider.h"
#include "include/aegisub/aegisub.h"
#include "dialog_progress.h"
#include "vfr.h"
extern "C" {
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
@ -75,9 +77,16 @@ private:
unsigned MessageSize;
wxString ErrorMsg;
struct IndexingProgressDialog {
volatile bool IndexingCanceled;
DialogProgress *ProgressDialog;
};
void LoadVideo(Aegisub::String filename, double fps);
void Close();
static int __stdcall FFmpegSourceVideoProvider::UpdateIndexingProgress(int State, int64_t Current, int64_t Total, void *Private);
protected:
public:
@ -108,4 +117,5 @@ public:
VideoProvider *CreateProvider(Aegisub::String video,double fps=0.0) { return new FFmpegSourceVideoProvider(video,fps); }
};
#endif /* WITH_FFMPEGSOURCE */