From cb1a9ba0b3b3c8ab7f15347d3f292de218c98f04 Mon Sep 17 00:00:00 2001 From: Fredrik Mellbin Date: Fri, 22 May 2009 23:28:08 +0000 Subject: [PATCH] FFMS2: Fix the weird crash bug Fix *nix compilation Originally committed to SVN as r2976. --- aegisub/FFmpegSource2/ffms.cpp | 5 ++--- aegisub/FFmpegSource2/ffms2rt.cpp | 21 +++++++++++---------- aegisub/FFmpegSource2/indexing.h | 5 +++-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/aegisub/FFmpegSource2/ffms.cpp b/aegisub/FFmpegSource2/ffms.cpp index 4c682a5f1..0662f1561 100644 --- a/aegisub/FFmpegSource2/ffms.cpp +++ b/aegisub/FFmpegSource2/ffms.cpp @@ -29,7 +29,6 @@ extern "C" { #ifdef __UNIX__ #define _snprintf snprintf -#define _scprintf scprintf #endif static int InitCount = 0; @@ -219,9 +218,9 @@ FFMS_API(FFIndex *) FFMS_MakeIndex(const char *SourceFile, int IndexMask, int Du FFMS_API(int) FFMS_DefaultAudioFilename(const char *SourceFile, int Track, const TAudioProperties *AP, char *FileName, void *Private) { const char * FormatString = "%s.%d2.w64"; if (FileName == NULL) - return _scprintf(FormatString, SourceFile, Track) + 1; + return _snprintf(NULL, 0, FormatString, SourceFile, Track) + 1; else - return sprintf(FileName, FormatString, SourceFile, Track) + 1; + return _snprintf(FileName, 999999, FormatString, SourceFile, Track) + 1; } FFMS_API(FFIndexer *) FFMS_CreateIndexer(const char *SourceFile, char *ErrorMsg, unsigned MsgSize) { diff --git a/aegisub/FFmpegSource2/ffms2rt.cpp b/aegisub/FFmpegSource2/ffms2rt.cpp index acc22f648..0e77cca06 100644 --- a/aegisub/FFmpegSource2/ffms2rt.cpp +++ b/aegisub/FFmpegSource2/ffms2rt.cpp @@ -34,13 +34,13 @@ using namespace std; static int FFMS_CC UpdateProgress(int64_t Current, int64_t Total, void *Private) { - int LastPercentage = (int)Private; + int *LastPercentage = (int *)Private; int Percentage = int((double(Current)/double(Total)) * 100); - if (Percentage <= LastPercentage) + if (Percentage <= *LastPercentage) return 0; - Private = (void *)Percentage; + *LastPercentage = Percentage; #ifdef VERBOSE cout << "Indexing, please wait... " << Percentage << "% \r" << flush; @@ -50,6 +50,7 @@ static int FFMS_CC UpdateProgress(int64_t Current, int64_t Total, void *Private) } void TestFullDump1(char *SrcFile, bool WithAudio) { + int Private; char ErrorMsg[2000]; int ret = FFMS_Init(); assert(!ret); @@ -60,7 +61,7 @@ void TestFullDump1(char *SrcFile, bool WithAudio) { FIdx = FFMS_CreateIndexer(SrcFile, ErrorMsg, sizeof(ErrorMsg)); assert(FIdx); - FFIndex *FI = FFMS_DoIndexing(FIdx, -1, -1, FFMS_DefaultAudioFilename, NULL, false, UpdateProgress, NULL, ErrorMsg, sizeof(ErrorMsg)); + FFIndex *FI = FFMS_DoIndexing(FIdx, -1, -1, FFMS_DefaultAudioFilename, NULL, false, UpdateProgress, &Private, ErrorMsg, sizeof(ErrorMsg)); assert(FI); int vtrack = FFMS_GetFirstTrackOfType(FI, FFMS_TYPE_VIDEO, ErrorMsg, sizeof(ErrorMsg)); @@ -68,7 +69,7 @@ void TestFullDump1(char *SrcFile, bool WithAudio) { int atrack = FFMS_GetFirstTrackOfType(FI, FFMS_TYPE_AUDIO, ErrorMsg, sizeof(ErrorMsg)); assert(atrack >= 0); - FFVideo *V = FFMS_CreateVideoSource(SrcFile, vtrack, FI, "", 1, 1, ErrorMsg, sizeof(ErrorMsg)); + FFVideo *V = FFMS_CreateVideoSource(SrcFile, vtrack, FI, "", 2, 1, ErrorMsg, sizeof(ErrorMsg)); assert(V); if (WithAudio) { @@ -101,13 +102,13 @@ int main(int argc, char *argv[]) { char *TestFiles1[10]; TestFiles1[0] = "[FLV1]_The_Melancholy_of_Haruhi_Suzumiya_-_Full_Clean_Ending.flv"; TestFiles1[1] = "jra_jupiter.avi"; - TestFiles1[2] = "h264_16-bframes_16-references_pyramid_crash-indexing.mkv"; - TestFiles1[3] = "pyramid-adaptive-10-bframes.mkv"; + TestFiles1[2] = "Zero1_ITV2_TS_Test.ts"; + TestFiles1[3] = "zx.starship.operators.01.h264.mkv"; TestFiles1[4] = "negative-timecodes.avi"; - TestFiles1[5] = "Zero1_ITV2_TS_Test.ts"; - TestFiles1[6] = "zx.starship.operators.01.h264.mkv"; + TestFiles1[5] = "h264_16-bframes_16-references_pyramid_crash-indexing.mkv"; + TestFiles1[6] = "pyramid-adaptive-10-bframes.mkv"; - for (int i = 0; i < 6; i++) + for (int i = 0; i < 5; i++) TestFullDump1(TestFiles1[i], true); /* TestFullDump1(TestFiles1[5], false); diff --git a/aegisub/FFmpegSource2/indexing.h b/aegisub/FFmpegSource2/indexing.h index c30d5de7e..72349009c 100644 --- a/aegisub/FFmpegSource2/indexing.h +++ b/aegisub/FFmpegSource2/indexing.h @@ -66,12 +66,13 @@ protected: TAudioNameCallback ANC; void *ANCPrivate; const char *SourceFile; - int16_t DecodingBuffer[AVCODEC_MAX_AUDIO_FRAME_SIZE * 5]; + int16_t *DecodingBuffer; bool WriteAudio(SharedAudioContext &AudioContext, FFIndex *Index, int Track, int DBSize, char *ErrorMsg, unsigned MsgSize); public: static FFIndexer *CreateFFIndexer(const char *Filename, char *ErrorMsg, unsigned MsgSize); - virtual ~FFIndexer() { } + FFIndexer() { DecodingBuffer = new int16_t[AVCODEC_MAX_AUDIO_FRAME_SIZE * 5]; } + virtual ~FFIndexer() { delete[] DecodingBuffer; } void SetIndexMask(int IndexMask) { this->IndexMask = IndexMask; } void SetDumpMask(int DumpMask) { this->DumpMask = DumpMask; } void SetIgnoreDecodeErrors(bool IgnoreDecodeErrors) { this->IgnoreDecodeErrors = IgnoreDecodeErrors; }