FFmpegSource2: crash less

Originally committed to SVN as r2404.
This commit is contained in:
Fredrik Mellbin 2008-10-01 19:07:59 +00:00
parent b0137363f6
commit 4683c5a9d0
3 changed files with 36 additions and 28 deletions

View file

@ -118,9 +118,10 @@ AVSValue __cdecl CreateFFVideoSource(AVSValue Args, void* UserData, IScriptEnvir
if (!strcmp(CacheFile, ""))
CacheFile = DefaultCache.c_str();
FrameIndex *Index;
if (Cache) {
if (!(Index = FFMS_ReadIndex(CacheFile, ErrorMsg, MsgSize))) {
FrameIndex *Index = NULL;
if (Cache)
Index = FFMS_ReadIndex(CacheFile, ErrorMsg, MsgSize);
if (!Index) {
if (!(Index = FFMS_MakeIndex(Source, 0, 0, NULL, true, NULL, NULL, ErrorMsg, MsgSize)))
Env->ThrowError("FFVideoSource: %s", ErrorMsg);
@ -130,7 +131,6 @@ AVSValue __cdecl CreateFFVideoSource(AVSValue Args, void* UserData, IScriptEnvir
Env->ThrowError("FFVideoSource: %s", ErrorMsg);
}
}
}
if (Track == -1)
Track = FFMS_GetFirstTrackOfType(Index, FFMS_TYPE_VIDEO, ErrorMsg, MsgSize);
@ -179,9 +179,10 @@ AVSValue __cdecl CreateFFAudioSource(AVSValue Args, void* UserData, IScriptEnvir
if (!strcmp(CacheFile, ""))
CacheFile = DefaultCache.c_str();
FrameIndex *Index;
if (Cache) {
if (!(Index = FFMS_ReadIndex(CacheFile, ErrorMsg, MsgSize))) {
FrameIndex *Index = NULL;
if (Cache)
Index = FFMS_ReadIndex(CacheFile, ErrorMsg, MsgSize);
if (!Index) {
if (!(Index = FFMS_MakeIndex(Source, -1, 0, CacheFile, true, NULL, NULL, ErrorMsg, MsgSize)))
Env->ThrowError("FFAudioSource: %s", ErrorMsg);
@ -191,7 +192,6 @@ AVSValue __cdecl CreateFFAudioSource(AVSValue Args, void* UserData, IScriptEnvir
Env->ThrowError("FFAudioSource: %s", ErrorMsg);
}
}
}
if (Track == -1)
Track = FFMS_GetFirstTrackOfType(Index, FFMS_TYPE_AUDIO, ErrorMsg, MsgSize);

View file

@ -110,7 +110,7 @@ VideoBase::~VideoBase() {
}
AVFrameLite *VideoBase::GetFrameByTime(double Time, char *ErrorMsg, unsigned MsgSize) {
int Frame = Frames.ClosestFrameFromDTS((Time * Frames.TB.Num) / Frames.TB.Den);
int Frame = Frames.ClosestFrameFromDTS((Time * Frames.TB.Num) / Frames.TB.Den + 0.5);
return GetFrame(Frame, ErrorMsg, MsgSize);
}

View file

@ -60,7 +60,7 @@ public:
FFAudioContext() {
W64W = NULL;
CTX = 0;
CTX = NULL;
CurrentSample = 0;
}
@ -206,6 +206,8 @@ static FrameIndex *MakeMatroskaIndex(const char *SourceFile, int IndexMask, int
if (mkv_GetTrackInfo(MF, i)->CompEnabled) {
AudioContexts[i].CS = cs_Create(MF, i, ErrorMessage, sizeof(ErrorMessage));
if (AudioContexts[i].CS == NULL) {
av_free(AudioCodecContext);
AudioContexts[i].CTX = NULL;
_snprintf(ErrorMsg, MsgSize, "Can't create decompressor: %s", ErrorMessage);
return NULL;
}
@ -213,11 +215,15 @@ static FrameIndex *MakeMatroskaIndex(const char *SourceFile, int IndexMask, int
AVCodec *AudioCodec = avcodec_find_decoder(MatroskaToFFCodecID(mkv_GetTrackInfo(MF, i)));
if (AudioCodec == NULL) {
av_free(AudioCodecContext);
AudioContexts[i].CTX = NULL;
_snprintf(ErrorMsg, MsgSize, "Audio codec not found");
return NULL;
}
if (avcodec_open(AudioCodecContext, AudioCodec) < 0) {
av_free(AudioCodecContext);
AudioContexts[i].CTX = NULL;
_snprintf(ErrorMsg, MsgSize, "Could not open audio codec");
return NULL;
}
@ -350,6 +356,8 @@ FrameIndex *MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const
_snprintf(ErrorMsg, MsgSize, "Could not open audio codec");
return NULL;
}
AudioContexts[i].CTX = AudioCodecContext;
} else {
IndexMask &= ~(1 << i);
}