From eb38d1820f537bc7956f95af97b3f18b95507f35 Mon Sep 17 00:00:00 2001 From: Karl Blomster Date: Fri, 12 Sep 2008 16:50:21 +0000 Subject: [PATCH] ffms2 indexer: now with less OO Originally committed to SVN as r2348. --- FFmpegSource2/ffmsindex.cpp | 28 ++++++++++++---------------- FFmpegSource2/ffmsindex.h | 25 ++++++++++--------------- 2 files changed, 22 insertions(+), 31 deletions(-) diff --git a/FFmpegSource2/ffmsindex.cpp b/FFmpegSource2/ffmsindex.cpp index bba965b96..bd628e64a 100644 --- a/FFmpegSource2/ffmsindex.cpp +++ b/FFmpegSource2/ffmsindex.cpp @@ -22,10 +22,8 @@ #include "ffmsindex.h" int main(int argc, char *argv[]) { - FFMSIndexApp *App; - try { - App = new FFMSIndexApp(argc, argv); + ParseCMDLine(argc, argv); } catch (const char *Error) { std::cout << std::endl << Error << std::endl; return 1; @@ -40,23 +38,23 @@ int main(int argc, char *argv[]) { FFMS_Init(); try { - App->DoIndexing(); + DoIndexing(); } catch (const char *Error) { std::cout << Error << std::endl; - delete App; + FFMS_DestroyFrameIndex(Index); return 1; } catch (...) { std::cout << std::endl << "Unknown error" << std::endl; - delete App; + FFMS_DestroyFrameIndex(Index); return 1; } - delete App; + FFMS_DestroyFrameIndex(Index); return 0; } -FFMSIndexApp::FFMSIndexApp (int argc, char *argv[]) { +void ParseCMDLine (int argc, char *argv[]) { if (argc <= 1) { PrintUsage(); throw ""; @@ -109,12 +107,9 @@ FFMSIndexApp::FFMSIndexApp (int argc, char *argv[]) { } } -FFMSIndexApp::~FFMSIndexApp () { - FFMS_DestroyFrameIndex(Index); -} -void FFMSIndexApp::PrintUsage () { +void PrintUsage () { using namespace std; cout << "FFmpegSource2 indexing app" << endl << "Usage: ffmsindex [options] inputfile [outputfile]" << endl @@ -122,11 +117,11 @@ void FFMSIndexApp::PrintUsage () { << "Options:" << endl << "-f Overwrite existing index file if it exists (default: no)" << endl << "-t N Set the audio trackmask to N (-1 means decode all tracks, 0 means decode none; default: 0)" << endl - << "-a NAME Set the audio output base filename to NAME (default: input filename)" << endl << endl; + << "-a NAME Set the audio output base filename to NAME (default: input filename)"; } -void FFMSIndexApp::DoIndexing () { +void DoIndexing () { char FFMSErrMsg[1024]; int MsgSize = sizeof(FFMSErrMsg); int Progress = 0; @@ -134,7 +129,7 @@ void FFMSIndexApp::DoIndexing () { Index = FFMS_ReadIndex(CacheFile.c_str(), FFMSErrMsg, MsgSize); if (Overwrite || Index == NULL) { std::cout << "Indexing, please wait... 0%"; - Index = FFMS_MakeIndex(InputFile.c_str(), TrackMask, AudioFile.c_str(), FFMSIndexApp::UpdateProgress, &Progress, FFMSErrMsg, MsgSize); + Index = FFMS_MakeIndex(InputFile.c_str(), TrackMask, AudioFile.c_str(), UpdateProgress, &Progress, FFMSErrMsg, MsgSize); if (Index == NULL) { std::string Err = "Indexing error: "; Err.append(FFMSErrMsg); @@ -158,7 +153,8 @@ void FFMSIndexApp::DoIndexing () { } } -int FFMSIndexApp::UpdateProgress(int State, int64_t Current, int64_t Total, void *Private) { + +static int __stdcall UpdateProgress(int State, int64_t Current, int64_t Total, void *Private) { using namespace std; int *LastPercentage = (int *)Private; int Percentage = int((double(Current)/double(Total)) * 100); diff --git a/FFmpegSource2/ffmsindex.h b/FFmpegSource2/ffmsindex.h index a907bc570..e998be479 100644 --- a/FFmpegSource2/ffmsindex.h +++ b/FFmpegSource2/ffmsindex.h @@ -25,21 +25,16 @@ #include "ffms.h" -class FFMSIndexApp { -private: - int TrackMask; - bool Overwrite; - std::string InputFile; - std::string CacheFile; - std::string AudioFile; +int TrackMask; +bool Overwrite; +std::string InputFile; +std::string CacheFile; +std::string AudioFile; - FrameIndex *Index; +FrameIndex *Index; - void PrintUsage(); +void PrintUsage(); +void ParseCMDLine(int argc, char *argv[]); +void DoIndexing(); -public: - FFMSIndexApp(int argc, char *argv[]); - ~FFMSIndexApp(); - void DoIndexing(); - static int __stdcall UpdateProgress(int State, int64_t Current, int64_t Total, void *Private); -}; \ No newline at end of file +static int __stdcall UpdateProgress(int State, int64_t Current, int64_t Total, void *Private);