Some more API cleanup
General cleanup

Originally committed to SVN as r2947.
This commit is contained in:
Fredrik Mellbin 2009-05-17 22:02:43 +00:00
parent 8195d36ee5
commit cd8d965324
11 changed files with 73 additions and 52 deletions

View file

@ -80,7 +80,7 @@ protected:
public:
FFAudio();
~FFAudio();
FFTrack *GetFFTrack() { return &Frames; }
const TAudioProperties& GetTAudioProperties() { return AP; }
virtual int GetAudio(void *Buf, int64_t Start, int64_t Count, char *ErrorMsg, unsigned MsgSize) = 0;
};

View file

@ -33,7 +33,7 @@ AvisynthVideoSource::AvisynthVideoSource(const char *SourceFile, int Track, FFIn
if (!V)
Env->ThrowError(ErrorMsg);
const TVideoProperties VP = *FFMS_GetTVideoProperties(V);
const TVideoProperties VP = *FFMS_GetVideoProperties(V);
VI.image_type = VideoInfo::IT_TFF;
VI.width = VP.Width;
@ -143,7 +143,7 @@ PVideoFrame AvisynthVideoSource::GetFrame(int n, IScriptEnvironment *Env) {
const TAVFrameLite *Frame;
if (FPSNum > 0 && FPSDen > 0)
Frame = FFMS_GetFrameByTime(V, FFMS_GetTVideoProperties(V)->FirstTime + (double)(n * (int64_t)FPSDen) / FPSNum, ErrorMsg, MsgSize);
Frame = FFMS_GetFrameByTime(V, FFMS_GetVideoProperties(V)->FirstTime + (double)(n * (int64_t)FPSDen) / FPSNum, ErrorMsg, MsgSize);
else
Frame = FFMS_GetFrame(V, n, ErrorMsg, MsgSize);
@ -161,7 +161,7 @@ AvisynthAudioSource::AvisynthAudioSource(const char *SourceFile, int Track, FFIn
if (!A)
Env->ThrowError(ErrorMsg);
const TAudioProperties AP = *FFMS_GetTAudioProperties(A);
const TAudioProperties AP = *FFMS_GetAudioProperties(A);
VI.nchannels = AP.Channels;
VI.num_audio_samples = AP.NumSamples;

View file

@ -138,7 +138,7 @@ AVSValue __cdecl CreateFFVideoSource(AVSValue Args, void* UserData, IScriptEnvir
Env->ThrowError("FFVideoSource: No video track found");
if (strcmp(Timecodes, "")) {
if (FFMS_WriteTimecodes(FFMS_GetTITrackIndex(Index, Track, ErrorMsg, MsgSize), Timecodes, ErrorMsg, MsgSize)) {
if (FFMS_WriteTimecodes(FFMS_GetTrackFromIndex(Index, Track, ErrorMsg, MsgSize), Timecodes, ErrorMsg, MsgSize)) {
FFMS_DestroyFFIndex(Index);
Env->ThrowError("FFVideoSource: %s", ErrorMsg);
}

View file

@ -112,11 +112,11 @@ FFMS_API(void) FFMS_DestroyAudioSource(FFAudio *A) {
delete A;
}
FFMS_API(const TVideoProperties *) FFMS_GetTVideoProperties(FFVideo *V) {
FFMS_API(const TVideoProperties *) FFMS_GetVideoProperties(FFVideo *V) {
return &V->GetTVideoProperties();
}
FFMS_API(const TAudioProperties *) FFMS_GetTAudioProperties(FFAudio *A) {
FFMS_API(const TAudioProperties *) FFMS_GetAudioProperties(FFAudio *A) {
return &A->GetTAudioProperties();
}
@ -146,9 +146,9 @@ FFMS_API(void) FFMS_DestroyFFIndex(FFIndex *Index) {
FFMS_API(int) FFMS_GetFirstTrackOfType(FFIndex *Index, int TrackType, char *ErrorMsg, unsigned MsgSize) {
for (int i = 0; i < static_cast<int>(Index->size()); i++)
if ((*Index)[i].TT == TrackType)
if ((*Index)[i].TT == TrackType && (*Index)[i].size() > 0)
return i;
_snprintf(ErrorMsg, MsgSize, "No suitable track found");
_snprintf(ErrorMsg, MsgSize, "No suitable, indexed track found");
return -1;
}
@ -164,7 +164,7 @@ FFMS_API(int) FFMS_GetNumFrames(FFTrack *T) {
return T->size();
}
FFMS_API(const TFrameInfo *) FFMS_GetTFrameInfo(FFTrack *T, int Frame, char *ErrorMsg, unsigned MsgSize) {
FFMS_API(const TFrameInfo *) FFMS_GetFrameInfo(FFTrack *T, int Frame, char *ErrorMsg, unsigned MsgSize) {
if (Frame < 0 || Frame >= static_cast<int>(T->size())) {
_snprintf(ErrorMsg, MsgSize, "Invalid frame specified");
return NULL;
@ -173,7 +173,7 @@ FFMS_API(const TFrameInfo *) FFMS_GetTFrameInfo(FFTrack *T, int Frame, char *Err
}
}
FFMS_API(FFTrack *) FFMS_GetTITrackIndex(FFIndex *Index, int Track, char *ErrorMsg, unsigned MsgSize) {
FFMS_API(FFTrack *) FFMS_GetTrackFromIndex(FFIndex *Index, int Track, char *ErrorMsg, unsigned MsgSize) {
if (Track < 0 || Track >= static_cast<int>(Index->size())) {
_snprintf(ErrorMsg, MsgSize, "Invalid track specified");
return NULL;
@ -182,10 +182,14 @@ FFMS_API(FFTrack *) FFMS_GetTITrackIndex(FFIndex *Index, int Track, char *ErrorM
}
}
FFMS_API(FFTrack *) FFMS_GetVSTrackIndex(FFVideo *V) {
FFMS_API(FFTrack *) FFMS_GetTrackFromVideo(FFVideo *V) {
return V->GetFFTrack();
}
FFMS_API(FFTrack *) FFMS_GetTrackFromAudio(FFAudio *A) {
return A->GetFFTrack();
}
FFMS_API(int) FFMS_FindClosestKeyFrame(FFTrack *T, int Frame, char *ErrorMsg, unsigned MsgSize) {
if (Frame < 0 || Frame >= static_cast<int>(T->size())) {
_snprintf(ErrorMsg, MsgSize, "Out of range frame specified");
@ -212,14 +216,9 @@ FFMS_API(FFIndex *) FFMS_ReadIndex(const char *IndexFile, char *ErrorMsg, unsign
}
FFMS_API(int) FFMS_WriteIndex(const char *IndexFile, FFIndex *Index, char *ErrorMsg, unsigned MsgSize) {
return WriteIndex(IndexFile, Index, ErrorMsg, MsgSize);
return Index->WriteIndex(IndexFile, ErrorMsg, MsgSize);
}
FFMS_API(int) FFMS_GetPixFmt(const char *Name) {
return avcodec_get_pix_fmt(Name);
}
FFMS_API(int) FFMS_DefaultAudioName(const char *SourceFile, int Track, const TAudioProperties *AP, char *FileName, unsigned FNSize) {
return 0;
}

View file

@ -114,9 +114,10 @@ struct TAudioProperties {
bool Float;
int64_t NumSamples;
double FirstTime;
double LastTime;
};
typedef int (FFMS_CC *TIndexCallback)(int State, int64_t Current, int64_t Total, void *Private);
typedef int (FFMS_CC *TIndexCallback)(int64_t Current, int64_t Total, void *Private);
typedef int (FFMS_CC *TAudioNameCallback)(const char *SourceFile, int Track, const TAudioProperties *AP, char *FileName, unsigned FNSize);
// Most functions return 0 on success
@ -128,8 +129,8 @@ FFMS_API(FFVideo *) FFMS_CreateVideoSource(const char *SourceFile, int Track, FF
FFMS_API(FFAudio *) FFMS_CreateAudioSource(const char *SourceFile, int Track, FFIndex *Index, char *ErrorMsg, unsigned MsgSize);
FFMS_API(void) FFMS_DestroyVideoSource(FFVideo *V);
FFMS_API(void) FFMS_DestroyAudioSource(FFAudio *A);
FFMS_API(const TVideoProperties *) FFMS_GetTVideoProperties(FFVideo *V);
FFMS_API(const TAudioProperties *) FFMS_GetTAudioProperties(FFAudio *A);
FFMS_API(const TVideoProperties *) FFMS_GetVideoProperties(FFVideo *V);
FFMS_API(const TAudioProperties *) FFMS_GetAudioProperties(FFAudio *A);
FFMS_API(const TAVFrameLite *) FFMS_GetFrame(FFVideo *V, int n, char *ErrorMsg, unsigned MsgSize);
FFMS_API(const TAVFrameLite *) FFMS_GetFrameByTime(FFVideo *V, double Time, char *ErrorMsg, unsigned MsgSize);
FFMS_API(int) FFMS_GetAudio(FFAudio *A, void *Buf, int64_t Start, int64_t Count, char *ErrorMsg, unsigned MsgSize);
@ -140,10 +141,10 @@ FFMS_API(int) FFMS_GetFirstTrackOfType(FFIndex *Index, int TrackType, char *Erro
FFMS_API(int) FFMS_GetNumTracks(FFIndex *Index);
FFMS_API(int) FFMS_GetTrackType(FFTrack *T);
FFMS_API(int) FFMS_GetNumFrames(FFTrack *T);
FFMS_API(const TFrameInfo *) FFMS_GetTFrameInfo(FFTrack *T, int Frame, char *ErrorMsg, unsigned MsgSize);
FFMS_API(FFTrack *) FFMS_GetTITrackIndex(FFIndex *Index, int Track, char *ErrorMsg, unsigned MsgSize);
FFMS_API(FFTrack *) FFMS_GetVSTrackIndex(FFVideo *V);
FFMS_API(FFTrack *) FFMS_GetASTrackIndex(FFAudio *A);
FFMS_API(const TFrameInfo *) FFMS_GetFrameInfo(FFTrack *T, int Frame, char *ErrorMsg, unsigned MsgSize);
FFMS_API(FFTrack *) FFMS_GetTrackFromIndex(FFIndex *Index, int Track, char *ErrorMsg, unsigned MsgSize);
FFMS_API(FFTrack *) FFMS_GetTrackFromVideo(FFVideo *V);
FFMS_API(FFTrack *) FFMS_GetTrackFromAudio(FFAudio *A);
FFMS_API(int) FFMS_FindClosestKeyFrame(FFTrack *T, int Frame, char *ErrorMsg, unsigned MsgSize);
FFMS_API(const TTrackTimeBase *) FFMS_GetTimeBase(FFTrack *T);
FFMS_API(int) FFMS_WriteTimecodes(FFTrack *T, const char *TimecodeFile, char *ErrorMsg, unsigned MsgSize);
@ -151,5 +152,4 @@ FFMS_API(FFIndex *) FFMS_MakeIndex(const char *SourceFile, int IndexMask, int Du
FFMS_API(FFIndex *) FFMS_ReadIndex(const char *IndexFile, char *ErrorMsg, unsigned MsgSize);
FFMS_API(int) FFMS_WriteIndex(const char *IndexFile, FFIndex *Index, char *ErrorMsg, unsigned MsgSize);
FFMS_API(int) FFMS_GetPixFmt(const char *Name);
FFMS_API(int) FFMS_DefaultAudioName(const char *SourceFile, int Track, const TAudioProperties *AP, char *FileName, unsigned FNSize);
#endif

View file

@ -224,11 +224,13 @@ tn:64:128:256
<p><b>FFmpeg svn</b> from http://ffmpeg.mplayerhq.hu/</p>
<p><b>pthreads</b> only required for ffmpeg-mt compiles</p>
<p><b>Required FFmpeg Configuration:</b>
./configure --enable-memalign-hack --enable-gpl --enable-postproc
<p><b>Suggested Additional Options:</b>
--enable-w32threads --disable-encoders --disable-muxers --disable-network --disable-debug</p>
--enable-pthreads --disable-encoders --disable-muxers --disable-network --disable-debug --enable-libfaad --disable-decoder=aac</p>
<p>
Note that --enable-w32threads is required for multithreaded decoding to work.
@ -237,13 +239,14 @@ Note that --enable-w32threads is required for multithreaded decoding to work.
<h2>Changes</h2>
<ul>
<li>2.00 beta 9<ul>
<li>Now has stricter index checking to detect when different FFmpeg versions were used to create an inded of the same version</li>
<li>Fixed an access violation occurring when unindexed or empty audio tracks in matroska files were opened</li>
<li>Less type conversion/signedness warnings</li>
<li>When audio track dumping is performed a custom callback can now be supplied to name the tracks</li>
<li>The audio track delay is now exposed in the API in the same way as video tracks</li>
<li>A big type and argument name cleanup in the API, many things have been renamed to be clearer and it should be completely C friendly now</li>
<li>Removed FFNoLog and replaced it with FFSetLogLevel and FFGetLogLevel, the default logging is now also set to quiet, the magical numbers to supply it can be found in avutil/log.h</li>
<li>Updated FFmpeg to rev X</li>
<li>Updated FFmpeg to rev X (now with pthreads and faad2 again by popular demand, updated to GCC 4.4.0 for compiling all libraries)</li>
</ul></li>
<li>2.00 beta 8<ul>

View file

@ -31,7 +31,7 @@ using namespace std;
//#define VERBOSE
static int FFMS_CC UpdateProgress(int State, int64_t Current, int64_t Total, void *Private) {
static int FFMS_CC UpdateProgress(int64_t Current, int64_t Total, void *Private) {
static int LastPercentage = -1;
int Percentage = int((double(Current)/double(Total)) * 100);
@ -85,7 +85,7 @@ int main(int argc, char *argv[]) {
return 3;
}
const TVideoProperties *VP = FFMS_GetTVideoProperties(V);
const TVideoProperties *VP = FFMS_GetVideoProperties(V);
for (int i = 0; i < VP->NumFrames; i++) {
const TAVFrameLite *AVF = FFMS_GetFrame(V, i, ErrorMsg, sizeof(ErrorMsg));
if (!AVF) {

View file

@ -118,7 +118,7 @@ void ParseCMDLine (int argc, char *argv[]) {
}
static int FFMS_CC UpdateProgress(int State, int64_t Current, int64_t Total, void *Private) {
static int FFMS_CC UpdateProgress(int64_t Current, int64_t Total, void *Private) {
using namespace std;
int *LastPercentage = (int *)Private;
int Percentage = int((double(Current)/double(Total)) * 100);

View file

@ -172,7 +172,7 @@ static void SortTrackIndices(FFIndex *Index) {
std::sort(Cur->begin(), Cur->end(), DTSComparison);
}
int WriteIndex(const char *IndexFile, FFIndex *Index, char *ErrorMsg, unsigned MsgSize) {
int FFIndex::WriteIndex(const char *IndexFile, char *ErrorMsg, unsigned MsgSize) {
std::ofstream IndexStream(IndexFile, std::ios::out | std::ios::binary | std::ios::trunc);
if (!IndexStream.is_open()) {
@ -184,22 +184,28 @@ int WriteIndex(const char *IndexFile, FFIndex *Index, char *ErrorMsg, unsigned M
IndexHeader IH;
IH.Id = INDEXID;
IH.Version = INDEXVERSION;
IH.Tracks = Index->size();
IH.Decoder = Index->Decoder;
IH.Tracks = size();
IH.Decoder = Decoder;
IH.LAVUVersion = LIBAVUTIL_VERSION_INT;
IH.LAVFVersion = LIBAVFORMAT_VERSION_INT;
IH.LAVCVersion = LIBAVCODEC_VERSION_INT;
IH.LSWSVersion = LIBSWSCALE_VERSION_INT;
IH.LPPVersion = LIBPOSTPROC_VERSION_INT;
IndexStream.write(reinterpret_cast<char *>(&IH), sizeof(IH));
for (unsigned int i = 0; i < IH.Tracks; i++) {
int TT = (*Index)[i].TT;
int TT = at(i).TT;
IndexStream.write(reinterpret_cast<char *>(&TT), sizeof(TT));
int64_t Num = (*Index)[i].TB.Num;
int64_t Num = at(i).TB.Num;
IndexStream.write(reinterpret_cast<char *>(&Num), sizeof(Num));
int64_t Den = (*Index)[i].TB.Den;
int64_t Den = at(i).TB.Den;
IndexStream.write(reinterpret_cast<char *>(&Den), sizeof(Den));
size_t Frames = (*Index)[i].size();
size_t Frames = at(i).size();
IndexStream.write(reinterpret_cast<char *>(&Frames), sizeof(Frames));
for (size_t j = 0; j < Frames; j++)
IndexStream.write(reinterpret_cast<char *>(&(Index->at(i)[j])), sizeof(TFrameInfo));
IndexStream.write(reinterpret_cast<char *>(&(at(i)[j])), sizeof(TFrameInfo));
}
return 0;
@ -336,7 +342,7 @@ static FFIndex *MakeHaaliIndex(const char *SourceFile, int IndexMask, int DumpMa
for (;;) {
if (IP) {
if ((*IP)(0, 0, 1, Private)) {
if ((*IP)(0, 1, Private)) {
_snprintf(ErrorMsg, MsgSize, "Cancelled by user");
delete TrackIndices;
return NULL;
@ -497,7 +503,7 @@ static FFIndex *MakeMatroskaIndex(const char *SourceFile, int IndexMask, int Dum
while (mkv_ReadFrame(MF, 0, &Track, &StartTime, &EndTime, &FilePos, &FrameSize, &FrameFlags) == 0) {
// Update progress
if (IP) {
if ((*IP)(0, _ftelli64(MC.ST.fp), SourceSize, Private)) {
if ((*IP)(_ftelli64(MC.ST.fp), SourceSize, Private)) {
_snprintf(ErrorMsg, MsgSize, "Cancelled by user");
delete TrackIndices;
return NULL;
@ -637,7 +643,7 @@ FFIndex *MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const ch
while (av_read_frame(FormatContext, &Packet) >= 0) {
// Update progress
if (IP) {
if ((*IP)(0, FormatContext->pb->pos, FormatContext->file_size, Private)) {
if ((*IP)(FormatContext->pb->pos, FormatContext->file_size, Private)) {
_snprintf(ErrorMsg, MsgSize, "Cancelled by user");
delete TrackIndices;
return NULL;
@ -723,6 +729,13 @@ FFIndex *ReadIndex(const char *IndexFile, char *ErrorMsg, unsigned MsgSize) {
return NULL;
}
if (IH.LAVUVersion != LIBAVUTIL_VERSION_INT || IH.LAVFVersion != LIBAVFORMAT_VERSION_INT ||
IH.LAVCVersion != LIBAVCODEC_VERSION_INT || IH.LSWSVersion != LIBSWSCALE_VERSION_INT ||
IH.LPPVersion != LIBPOSTPROC_VERSION_INT) {
_snprintf(ErrorMsg, MsgSize, "A different FFmpeg build was used to create this index", IndexFile);
return NULL;
}
FFIndex *TrackIndices = new FFIndex();
try {

View file

@ -25,7 +25,7 @@
#include "utils.h"
#include "ffms.h"
#define INDEXVERSION 20
#define INDEXVERSION 21
#define INDEXID 0x53920873
struct IndexHeader {
@ -33,9 +33,15 @@ struct IndexHeader {
uint32_t Version;
uint32_t Tracks;
uint32_t Decoder;
uint32_t LAVUVersion;
uint32_t LAVFVersion;
uint32_t LAVCVersion;
uint32_t LSWSVersion;
uint32_t LPPVersion;
};
struct FFTrack : public std::vector<TFrameInfo> {
public:
int TT;
TTrackTimeBase TB;
@ -49,11 +55,12 @@ struct FFTrack : public std::vector<TFrameInfo> {
};
struct FFIndex : public std::vector<FFTrack> {
public:
int Decoder;
int WriteIndex(const char *IndexFile, char *ErrorMsg, unsigned MsgSize);
};
FFIndex *MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const char *AudioFile, bool IgnoreDecodeErrors, TIndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize);
FFIndex *ReadIndex(const char *IndexFile, char *ErrorMsg, unsigned MsgSize);
int WriteIndex(const char *IndexFile, FFIndex *Index, char *ErrorMsg, unsigned MsgSize);
#endif

View file

@ -145,6 +145,7 @@ void FillAP(TAudioProperties &AP, AVCodecContext *CTX, FFTrack &Frames) {
AP.SampleRate = CTX->sample_rate;
AP.NumSamples = (Frames.back()).SampleStart;
AP.FirstTime = ((Frames.front().DTS * Frames.TB.Num) / (double)Frames.TB.Den) / 1000;
AP.LastTime = ((Frames.back().DTS * Frames.TB.Num) / (double)Frames.TB.Den) / 1000;
}
#ifdef HAALISOURCE
@ -204,7 +205,7 @@ CodecID MatroskaToFFCodecID(char *Codec, void *CodecPrivate) {
case MAKEFOURCC('D', 'I', 'V', 'X'):
case MAKEFOURCC('D', 'X', '5', '0'):
case MAKEFOURCC('M', 'P', '4', 'V'):
case MAKEFOURCC('m', 'p', '4', 'v'): // This one may be my fault
case MAKEFOURCC('m', 'p', '4', 'v'):
case MAKEFOURCC('3', 'I', 'V', 'X'):
case MAKEFOURCC('W', 'V', '1', 'F'):
case MAKEFOURCC('F', 'M', 'P', '4'):
@ -268,7 +269,7 @@ CodecID MatroskaToFFCodecID(char *Codec, void *CodecPrivate) {
case MAKEFOURCC('M', 'J', 'P', 'G'):
case MAKEFOURCC('L', 'J', 'P', 'G'):
case MAKEFOURCC('M', 'J', 'L', 'S'):
case MAKEFOURCC('J', 'P', 'E', 'G'): // questionable fourcc?
case MAKEFOURCC('J', 'P', 'E', 'G'):
case MAKEFOURCC('A', 'V', 'R', 'N'):
case MAKEFOURCC('M', 'J', 'P', 'A'):
return CODEC_ID_MJPEG;
@ -312,10 +313,8 @@ CodecID MatroskaToFFCodecID(char *Codec, void *CodecPrivate) {
return CODEC_ID_ZLIB;
case MAKEFOURCC('F', 'L', 'V', '1'):
return CODEC_ID_FLV1;
/*
case MAKEFOURCC('P', 'N', 'G', '1'):
return CODEC_ID_COREPNG;
*/
return CODEC_ID_PNG;
case MAKEFOURCC('M', 'P', 'N', 'G'):
return CODEC_ID_PNG;
/*
@ -395,7 +394,7 @@ CodecID MatroskaToFFCodecID(char *Codec, void *CodecPrivate) {
else if (!strcmp(Codec, "V_THEORA"))
return CODEC_ID_THEORA;
else if (!strcmp(Codec, "V_UNCOMPRESSED"))
return CODEC_ID_NONE; // bleh
return CODEC_ID_NONE; // FIXME: bleh
else if (!strcmp(Codec, "V_QUICKTIME"))
return CODEC_ID_SVQ3; // no idea if this is right
else if (!strcmp(Codec, "V_CIPC"))
@ -449,7 +448,7 @@ CodecID MatroskaToFFCodecID(char *Codec, void *CodecPrivate) {
*/
return CODEC_ID_NONE;
} else if (!strcmp(Codec, "A_PCM/FLOAT/IEEE"))
return CODEC_ID_PCM_F32LE; // only a most likely guess, may do bad things
return CODEC_ID_PCM_F32LE; // FIXME: only a most likely guess, may do bad things
else if (!strcmp(Codec, "A_FLAC"))
return CODEC_ID_FLAC;
else if (!strcmp(Codec, "A_MPC"))
@ -467,7 +466,7 @@ CodecID MatroskaToFFCodecID(char *Codec, void *CodecPrivate) {
else if (!strcmp(Codec, "A_REAL/COOK"))
return CODEC_ID_COOK;
else if (!strcmp(Codec, "A_REAL/SIPR"))
return CODEC_ID_NONE; // no sipr codec id?
return CODEC_ID_SIPR;
else if (!strcmp(Codec, "A_REAL/ATRC"))
return CODEC_ID_ATRAC3;
else if (!strncmp(Codec, "A_AAC", 5))