forked from mia/Aegisub
FFMS2: revert the initialization mess, instead require the caller to initialize com where it's needed
Originally committed to SVN as r2984.
This commit is contained in:
parent
c60b4b449f
commit
5857345b8d
4 changed files with 9 additions and 32 deletions
|
@ -31,33 +31,14 @@ extern "C" {
|
||||||
#define _snprintf snprintf
|
#define _snprintf snprintf
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int InitCount = 0;
|
|
||||||
static bool FFmpegInited = false;
|
static bool FFmpegInited = false;
|
||||||
|
|
||||||
FFMS_API(int) FFMS_Init() {
|
FFMS_API(void) FFMS_Init() {
|
||||||
if (!FFmpegInited) {
|
if (!FFmpegInited) {
|
||||||
av_register_all();
|
av_register_all();
|
||||||
av_log_set_level(AV_LOG_QUIET);
|
av_log_set_level(AV_LOG_QUIET);
|
||||||
|
FFmpegInited = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!InitCount) {
|
|
||||||
#ifdef HAALISOURCE
|
|
||||||
::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
InitCount++;
|
|
||||||
return InitCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
FFMS_API(int) FFMS_DeInit() {
|
|
||||||
InitCount--;
|
|
||||||
if (!InitCount) {
|
|
||||||
#ifdef HAALISOURCE
|
|
||||||
::CoUninitialize();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
return InitCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FFMS_API(int) FFMS_GetLogLevel() {
|
FFMS_API(int) FFMS_GetLogLevel() {
|
||||||
|
|
|
@ -122,8 +122,7 @@ typedef int (FFMS_CC *TAudioNameCallback)(const char *SourceFile, int Track, con
|
||||||
|
|
||||||
// Most functions return 0 on success
|
// Most functions return 0 on success
|
||||||
// Functions without error message output can be assumed to never fail
|
// Functions without error message output can be assumed to never fail
|
||||||
FFMS_API(int) FFMS_Init();
|
FFMS_API(void) FFMS_Init();
|
||||||
FFMS_API(int) FFMS_DeInit();
|
|
||||||
FFMS_API(int) FFMS_GetLogLevel();
|
FFMS_API(int) FFMS_GetLogLevel();
|
||||||
FFMS_API(void) FFMS_SetLogLevel(int Level);
|
FFMS_API(void) FFMS_SetLogLevel(int Level);
|
||||||
FFMS_API(FFVideo *) FFMS_CreateVideoSource(const char *SourceFile, int Track, FFIndex *Index, const char *PP, int Threads, int SeekMode, char *ErrorMsg, unsigned MsgSize);
|
FFMS_API(FFVideo *) FFMS_CreateVideoSource(const char *SourceFile, int Track, FFIndex *Index, const char *PP, int Threads, int SeekMode, char *ErrorMsg, unsigned MsgSize);
|
||||||
|
|
|
@ -51,9 +51,9 @@ static int FFMS_CC UpdateProgress(int64_t Current, int64_t Total, void *Private)
|
||||||
|
|
||||||
void TestFullDump1(char *SrcFile, bool WithAudio) {
|
void TestFullDump1(char *SrcFile, bool WithAudio) {
|
||||||
int Private;
|
int Private;
|
||||||
|
int ret;
|
||||||
char ErrorMsg[2000];
|
char ErrorMsg[2000];
|
||||||
int ret = FFMS_Init();
|
FFMS_Init();
|
||||||
assert(!ret);
|
|
||||||
|
|
||||||
FFIndexer *FIdx = FFMS_CreateIndexer(SrcFile, ErrorMsg, sizeof(ErrorMsg));
|
FFIndexer *FIdx = FFMS_CreateIndexer(SrcFile, ErrorMsg, sizeof(ErrorMsg));
|
||||||
assert(FIdx);
|
assert(FIdx);
|
||||||
|
@ -61,6 +61,8 @@ void TestFullDump1(char *SrcFile, bool WithAudio) {
|
||||||
FIdx = FFMS_CreateIndexer(SrcFile, ErrorMsg, sizeof(ErrorMsg));
|
FIdx = FFMS_CreateIndexer(SrcFile, ErrorMsg, sizeof(ErrorMsg));
|
||||||
assert(FIdx);
|
assert(FIdx);
|
||||||
|
|
||||||
|
const char *Name = FFMS_GetCodecNameI(FIdx, 0);
|
||||||
|
|
||||||
FFIndex *FI = FFMS_DoIndexing(FIdx, -1, -1, FFMS_DefaultAudioFilename, NULL, false, UpdateProgress, &Private, ErrorMsg, sizeof(ErrorMsg));
|
FFIndex *FI = FFMS_DoIndexing(FIdx, -1, -1, FFMS_DefaultAudioFilename, NULL, false, UpdateProgress, &Private, ErrorMsg, sizeof(ErrorMsg));
|
||||||
assert(FI);
|
assert(FI);
|
||||||
|
|
||||||
|
@ -95,7 +97,6 @@ void TestFullDump1(char *SrcFile, bool WithAudio) {
|
||||||
|
|
||||||
FFMS_DestroyFFIndex(FI);
|
FFMS_DestroyFFIndex(FI);
|
||||||
FFMS_DestroyVideoSource(V);
|
FFMS_DestroyVideoSource(V);
|
||||||
FFMS_DeInit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
@ -109,7 +110,7 @@ int main(int argc, char *argv[]) {
|
||||||
TestFiles1[6] = "pyramid-adaptive-10-bframes.mkv";
|
TestFiles1[6] = "pyramid-adaptive-10-bframes.mkv";
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++)
|
for (int i = 0; i < 5; i++)
|
||||||
TestFullDump1(TestFiles1[i], true);
|
TestFullDump1(TestFiles1[3], true);
|
||||||
/*
|
/*
|
||||||
TestFullDump1(TestFiles1[5], false);
|
TestFullDump1(TestFiles1[5], false);
|
||||||
|
|
||||||
|
|
|
@ -186,10 +186,7 @@ int main(int argc, char *argv[]) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FFMS_Init()) {
|
FFMS_Init();
|
||||||
std::cout << std::endl << "Error: initialization failed" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Verbose)
|
if (Verbose)
|
||||||
FFMS_SetLogLevel(AV_LOG_INFO);
|
FFMS_SetLogLevel(AV_LOG_INFO);
|
||||||
|
@ -211,6 +208,5 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
FFMS_DestroyFFIndex(Index);
|
FFMS_DestroyFFIndex(Index);
|
||||||
FFMS_DeInit();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue