From 76da71cef4bb5433c4fbc7e798efa4a8555ae302 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Thu, 1 Nov 2007 18:14:56 +0000 Subject: [PATCH] Applied perchr's patch for a progress bar while loading keyframes on posix. Originally committed to SVN as r1646. --- aegisub/lavc_keyframes.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/aegisub/lavc_keyframes.cpp b/aegisub/lavc_keyframes.cpp index 79249692f..aac10f74a 100644 --- a/aegisub/lavc_keyframes.cpp +++ b/aegisub/lavc_keyframes.cpp @@ -36,6 +36,7 @@ /////////// // Headers +#include "dialog_progress.h" #include "lavc_keyframes.h" /////////////// @@ -84,14 +85,28 @@ LAVCKeyFrames::~LAVCKeyFrames() { // Parse file for keyframes wxArrayInt LAVCKeyFrames::GetKeyFrames() { wxArrayInt keyframes; - + AVPacket packet; + int total_frames = stream->duration; register unsigned int frameN = 0; // Number of parsed frames - while (av_read_frame(file->fctx, &packet) >= 0) { + + volatile bool canceled = false; + DialogProgress *progress = new DialogProgress(NULL,_("Load keyframes"),&canceled,_("Reading keyframes from video"),0,total_frames); + progress->Show(); + progress->SetProgress(0,1); + + while (av_read_frame(file->fctx, &packet) >= 0 && !canceled) { // Check if packet is part of video stream if (packet.stream_index == streamN) { // Increment number of passed frames ++frameN; + + /* Might need some adjustments here, to make it + appear as fluid as wanted. Just copied 2points thingy, + and reduced it a bit */ + if ((frameN & (1024 - 1)) == 0) + progress->SetProgress(frameN,total_frames); + // Decode frame int frameFinished; avcodec_decode_video(codecContext, frame, &frameFinished, packet.data, packet.size); @@ -107,7 +122,11 @@ wxArrayInt LAVCKeyFrames::GetKeyFrames() { av_free_packet(&packet); } } - } - + } + + // Clean up progress + if (!canceled) progress->Destroy(); + else throw wxString(_T("Keyframe loading cancelled by user")); + return keyframes; }