forked from mia/Aegisub
FFmpegSource2: more portability
Originally committed to SVN as r2389.
This commit is contained in:
parent
a2c5b5778c
commit
770e581ca7
6 changed files with 30 additions and 18 deletions
|
@ -19,6 +19,8 @@
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#include "ffaudiosource.h"
|
#include "ffaudiosource.h"
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AudioBase::AudioBase() {
|
AudioBase::AudioBase() {
|
||||||
|
|
|
@ -62,7 +62,7 @@ AVSValue __cdecl CreateFFIndex(AVSValue Args, void* UserData, IScriptEnvironment
|
||||||
|
|
||||||
FrameIndex *Index;
|
FrameIndex *Index;
|
||||||
if (OverWrite || !(Index = FFMS_ReadIndex(CacheFile, ErrorMsg, MsgSize))) {
|
if (OverWrite || !(Index = FFMS_ReadIndex(CacheFile, ErrorMsg, MsgSize))) {
|
||||||
if (!(Index = FFMS_MakeIndex(Source, IndexMask, DumpMask, AudioFile, NULL, NULL, ErrorMsg, MsgSize)))
|
if (!(Index = FFMS_MakeIndex(Source, IndexMask, DumpMask, AudioFile, true, NULL, NULL, ErrorMsg, MsgSize)))
|
||||||
Env->ThrowError("FFIndex: %s", ErrorMsg);
|
Env->ThrowError("FFIndex: %s", ErrorMsg);
|
||||||
if (FFMS_WriteIndex(CacheFile, Index, ErrorMsg, MsgSize)) {
|
if (FFMS_WriteIndex(CacheFile, Index, ErrorMsg, MsgSize)) {
|
||||||
FFMS_DestroyFrameIndex(Index);
|
FFMS_DestroyFrameIndex(Index);
|
||||||
|
@ -119,7 +119,7 @@ AVSValue __cdecl CreateFFVideoSource(AVSValue Args, void* UserData, IScriptEnvir
|
||||||
FrameIndex *Index;
|
FrameIndex *Index;
|
||||||
if (Cache) {
|
if (Cache) {
|
||||||
if (!(Index = FFMS_ReadIndex(CacheFile, ErrorMsg, MsgSize))) {
|
if (!(Index = FFMS_ReadIndex(CacheFile, ErrorMsg, MsgSize))) {
|
||||||
if (!(Index = FFMS_MakeIndex(Source, 0, 0, NULL, NULL, NULL, ErrorMsg, MsgSize)))
|
if (!(Index = FFMS_MakeIndex(Source, 0, 0, NULL, true, NULL, NULL, ErrorMsg, MsgSize)))
|
||||||
Env->ThrowError("FFVideoSource: %s", ErrorMsg);
|
Env->ThrowError("FFVideoSource: %s", ErrorMsg);
|
||||||
|
|
||||||
if (Cache)
|
if (Cache)
|
||||||
|
@ -176,7 +176,7 @@ AVSValue __cdecl CreateFFAudioSource(AVSValue Args, void* UserData, IScriptEnvir
|
||||||
FrameIndex *Index;
|
FrameIndex *Index;
|
||||||
if (Cache) {
|
if (Cache) {
|
||||||
if (!(Index = FFMS_ReadIndex(CacheFile, ErrorMsg, MsgSize))) {
|
if (!(Index = FFMS_ReadIndex(CacheFile, ErrorMsg, MsgSize))) {
|
||||||
if (!(Index = FFMS_MakeIndex(Source, -1, 0, CacheFile, NULL, NULL, ErrorMsg, MsgSize)))
|
if (!(Index = FFMS_MakeIndex(Source, -1, 0, CacheFile, true, NULL, NULL, ErrorMsg, MsgSize)))
|
||||||
Env->ThrowError("FFAudioSource: %s", ErrorMsg);
|
Env->ThrowError("FFAudioSource: %s", ErrorMsg);
|
||||||
|
|
||||||
if (Cache)
|
if (Cache)
|
||||||
|
|
|
@ -163,8 +163,8 @@ FFMS_API(int) FFMS_WriteTimecodes(FrameInfoVector *FIV, const char *TimecodeFile
|
||||||
return FIV->WriteTimecodes(TimecodeFile, ErrorMsg, MsgSize);
|
return FIV->WriteTimecodes(TimecodeFile, ErrorMsg, MsgSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
FFMS_API(FrameIndex *) FFMS_MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const char *AudioFile, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize) {
|
FFMS_API(FrameIndex *) FFMS_MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const char *AudioFile, bool IgnoreDecodeErrors, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize) {
|
||||||
return MakeIndex(SourceFile, IndexMask, DumpMask, AudioFile, IP, Private, ErrorMsg, MsgSize);
|
return MakeIndex(SourceFile, IndexMask, DumpMask, AudioFile, IgnoreDecodeErrors, IP, Private, ErrorMsg, MsgSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
FFMS_API(FrameIndex *) FFMS_ReadIndex(const char *IndexFile, char *ErrorMsg, unsigned MsgSize) {
|
FFMS_API(FrameIndex *) FFMS_ReadIndex(const char *IndexFile, char *ErrorMsg, unsigned MsgSize) {
|
||||||
|
|
|
@ -182,7 +182,7 @@ FFMS_API(int) FFMS_FrameFromDTS(FrameInfoVector *FIV, int64_t DTS, char *ErrorMs
|
||||||
FFMS_API(int) FFMS_ClosestFrameFromDTS(FrameInfoVector *FIV, int64_t DTS, char *ErrorMsg, unsigned MsgSize);
|
FFMS_API(int) FFMS_ClosestFrameFromDTS(FrameInfoVector *FIV, int64_t DTS, char *ErrorMsg, unsigned MsgSize);
|
||||||
FFMS_API(const TrackTimeBase *) FFMS_GetTimeBase(FrameInfoVector *FIV, char *ErrorMsg, unsigned MsgSize);
|
FFMS_API(const TrackTimeBase *) FFMS_GetTimeBase(FrameInfoVector *FIV, char *ErrorMsg, unsigned MsgSize);
|
||||||
FFMS_API(int) FFMS_WriteTimecodes(FrameInfoVector *FIV, const char *TimecodeFile, char *ErrorMsg, unsigned MsgSize);
|
FFMS_API(int) FFMS_WriteTimecodes(FrameInfoVector *FIV, const char *TimecodeFile, char *ErrorMsg, unsigned MsgSize);
|
||||||
FFMS_API(FrameIndex *) FFMS_MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const char *AudioFile, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize);
|
FFMS_API(FrameIndex *) FFMS_MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const char *AudioFile, bool IgnoreDecodeErrors, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize);
|
||||||
FFMS_API(FrameIndex *) FFMS_ReadIndex(const char *IndexFile, char *ErrorMsg, unsigned MsgSize);
|
FFMS_API(FrameIndex *) FFMS_ReadIndex(const char *IndexFile, char *ErrorMsg, unsigned MsgSize);
|
||||||
FFMS_API(int) FFMS_WriteIndex(const char *IndexFile, FrameIndex *TrackIndices, char *ErrorMsg, unsigned MsgSize);
|
FFMS_API(int) FFMS_WriteIndex(const char *IndexFile, FrameIndex *TrackIndices, char *ErrorMsg, unsigned MsgSize);
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,7 @@ int WriteIndex(const char *IndexFile, FrameIndex *TrackIndices, char *ErrorMsg,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FrameIndex *MakeMatroskaIndex(const char *SourceFile, int IndexMask, int DumpMask, const char *AudioFile, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize) {
|
static FrameIndex *MakeMatroskaIndex(const char *SourceFile, int IndexMask, int DumpMask, const char *AudioFile, bool IgnoreDecodeErrors, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize) {
|
||||||
MatroskaFile *MF;
|
MatroskaFile *MF;
|
||||||
char ErrorMessage[256];
|
char ErrorMessage[256];
|
||||||
MatroskaReaderContext MC;
|
MatroskaReaderContext MC;
|
||||||
|
@ -187,7 +187,6 @@ static FrameIndex *MakeMatroskaIndex(const char *SourceFile, int IndexMask, int
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
IndexMask &= ~(1 << i);
|
IndexMask &= ~(1 << i);
|
||||||
DumpMask &= ~(1 << i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,10 +232,16 @@ static FrameIndex *MakeMatroskaIndex(const char *SourceFile, int IndexMask, int
|
||||||
int dbsize = AVCODEC_MAX_AUDIO_FRAME_SIZE*10;
|
int dbsize = AVCODEC_MAX_AUDIO_FRAME_SIZE*10;
|
||||||
int Ret = avcodec_decode_audio2(AudioCodecContext, db, &dbsize, Data, Size);
|
int Ret = avcodec_decode_audio2(AudioCodecContext, db, &dbsize, Data, Size);
|
||||||
if (Ret < 0) {
|
if (Ret < 0) {
|
||||||
|
if (IgnoreDecodeErrors) {
|
||||||
|
(*TrackIndices)[Track].clear();
|
||||||
|
IndexMask &= ~(1 << Track);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
_snprintf(ErrorMsg, MsgSize, "Audio decoding error");
|
_snprintf(ErrorMsg, MsgSize, "Audio decoding error");
|
||||||
delete TrackIndices;
|
delete TrackIndices;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Ret > 0) {
|
if (Ret > 0) {
|
||||||
Size -= Ret;
|
Size -= Ret;
|
||||||
|
@ -269,7 +274,7 @@ static FrameIndex *MakeMatroskaIndex(const char *SourceFile, int IndexMask, int
|
||||||
return TrackIndices;
|
return TrackIndices;
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameIndex *MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const char *AudioFile, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize) {
|
FrameIndex *MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const char *AudioFile, bool IgnoreDecodeErrors, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize) {
|
||||||
AVFormatContext *FormatContext = NULL;
|
AVFormatContext *FormatContext = NULL;
|
||||||
IndexMask |= DumpMask;
|
IndexMask |= DumpMask;
|
||||||
|
|
||||||
|
@ -281,7 +286,7 @@ FrameIndex *MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const
|
||||||
// Do matroska indexing instead?
|
// Do matroska indexing instead?
|
||||||
if (!strcmp(FormatContext->iformat->name, "matroska")) {
|
if (!strcmp(FormatContext->iformat->name, "matroska")) {
|
||||||
av_close_input_file(FormatContext);
|
av_close_input_file(FormatContext);
|
||||||
return MakeMatroskaIndex(SourceFile, IndexMask, DumpMask, AudioFile, IP, Private, ErrorMsg, MsgSize);
|
return MakeMatroskaIndex(SourceFile, IndexMask, DumpMask, AudioFile, IgnoreDecodeErrors, IP, Private, ErrorMsg, MsgSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (av_find_stream_info(FormatContext) < 0) {
|
if (av_find_stream_info(FormatContext) < 0) {
|
||||||
|
@ -312,7 +317,6 @@ FrameIndex *MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
IndexMask &= ~(1 << i);
|
IndexMask &= ~(1 << i);
|
||||||
DumpMask &= ~(1 << i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,10 +354,16 @@ FrameIndex *MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const
|
||||||
int dbsize = AVCODEC_MAX_AUDIO_FRAME_SIZE*10;
|
int dbsize = AVCODEC_MAX_AUDIO_FRAME_SIZE*10;
|
||||||
int Ret = avcodec_decode_audio2(AudioCodecContext, db, &dbsize, Data, Size);
|
int Ret = avcodec_decode_audio2(AudioCodecContext, db, &dbsize, Data, Size);
|
||||||
if (Ret < 0) {
|
if (Ret < 0) {
|
||||||
|
if (IgnoreDecodeErrors) {
|
||||||
|
(*TrackIndices)[Packet.stream_index].clear();
|
||||||
|
IndexMask &= ~(1 << Packet.stream_index);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
_snprintf(ErrorMsg, MsgSize, "Audio decoding error");
|
_snprintf(ErrorMsg, MsgSize, "Audio decoding error");
|
||||||
delete TrackIndices;
|
delete TrackIndices;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Ret > 0) {
|
if (Ret > 0) {
|
||||||
Size -= Ret;
|
Size -= Ret;
|
||||||
|
|
|
@ -62,7 +62,7 @@ public:
|
||||||
int Decoder;
|
int Decoder;
|
||||||
};
|
};
|
||||||
|
|
||||||
FrameIndex *MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const char *AudioFile, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize);
|
FrameIndex *MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const char *AudioFile, bool IgnoreDecodeErrors, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize);
|
||||||
FrameIndex *ReadIndex(const char *IndexFile, char *ErrorMsg, unsigned MsgSize);
|
FrameIndex *ReadIndex(const char *IndexFile, char *ErrorMsg, unsigned MsgSize);
|
||||||
int WriteIndex(const char *IndexFile, FrameIndex *TrackIndices, char *ErrorMsg, unsigned MsgSize);
|
int WriteIndex(const char *IndexFile, FrameIndex *TrackIndices, char *ErrorMsg, unsigned MsgSize);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue