From 1f4fa827262eaac30cb3646057661c2b855957c1 Mon Sep 17 00:00:00 2001 From: Karl Blomster Date: Sat, 21 Nov 2009 21:11:41 +0000 Subject: [PATCH] Update ffms2 to r234, part 1. Compilation broken in this commit. Originally committed to SVN as r3814. --- aegisub/libffms/include/ffms.h | 36 +++++++++++----------- aegisub/libffms/src/core/indexing.cpp | 28 ++++++++--------- aegisub/libffms/src/core/indexing.h | 10 +++--- aegisub/libffms/src/core/lavfaudio.cpp | 22 ++++++------- aegisub/libffms/src/core/lavfvideo.cpp | 18 +++++------ aegisub/libffms/src/core/matroskaaudio.cpp | 2 +- aegisub/libffms/src/core/matroskavideo.cpp | 8 ++--- aegisub/libffms/src/core/utils.cpp | 4 +-- aegisub/libffms/src/core/videosource.cpp | 2 +- aegisub/libffms/src/core/videosource.h | 2 +- 10 files changed, 66 insertions(+), 66 deletions(-) diff --git a/aegisub/libffms/include/ffms.h b/aegisub/libffms/include/ffms.h index 2a2652dcd..0168497e4 100644 --- a/aegisub/libffms/include/ffms.h +++ b/aegisub/libffms/include/ffms.h @@ -46,18 +46,18 @@ # define FFMS_API(ret) EXTERN_C ret FFMS_CC #endif -struct FFMS_ErrorInfo { +typedef struct { int ErrorType; int SubType; int BufferSize; char *Buffer; -}; +} FFMS_ErrorInfo; -FFMS_CLASS_TYPE FFMS_VideoSource; -FFMS_CLASS_TYPE FFMS_AudioSource; -FFMS_CLASS_TYPE FFMS_Indexer; -FFMS_CLASS_TYPE FFMS_Index; -FFMS_CLASS_TYPE FFMS_Track; +typedef FFMS_CLASS_TYPE FFMS_VideoSource FFMS_VideoSource; +typedef FFMS_CLASS_TYPE FFMS_AudioSource FFMS_AudioSource; +typedef FFMS_CLASS_TYPE FFMS_Indexer FFMS_Indexer; +typedef FFMS_CLASS_TYPE FFMS_Index FFMS_Index; +typedef FFMS_CLASS_TYPE FFMS_Track FFMS_Track; enum FFMS_Errors { // No error @@ -174,7 +174,7 @@ enum FFMS_Resizers { FFMS_RESIZER_SPLINE = 0x0400 }; -struct FFMS_Frame { +typedef struct { uint8_t *Data[4]; int Linesize[4]; int EncodedWidth; @@ -188,20 +188,20 @@ struct FFMS_Frame { int InterlacedFrame; int TopFieldFirst; char PictType; -}; +} FFMS_Frame; -struct FFMS_TrackTimeBase { +typedef struct { int64_t Num; int64_t Den; -}; +} FFMS_TrackTimeBase; -#define FFMS_FRAMEINFO_COMMON int64_t DTS; int RepeatPict; int KeyFrame; +#define FFMS_FRAMEINFO_COMMON int64_t PTS; int RepeatPict; int KeyFrame; -struct FFMS_FrameInfo { +typedef struct { FFMS_FRAMEINFO_COMMON -}; +} FFMS_FrameInfo; -struct FFMS_VideoProperties { +typedef struct { int FPSDenominator; int FPSNumerator; int RFFDenominator; @@ -218,9 +218,9 @@ struct FFMS_VideoProperties { int ColorRange; // 0=unspecified, 1=16-235, 2=0-255 double FirstTime; double LastTime; -}; +} FFMS_VideoProperties; -struct FFMS_AudioProperties { +typedef struct { int SampleFormat; int SampleRate; int BitsPerSample; @@ -229,7 +229,7 @@ struct FFMS_AudioProperties { int64_t NumSamples; double FirstTime; double LastTime; -}; +} FFMS_AudioProperties; typedef int (FFMS_CC *TIndexCallback)(int64_t Current, int64_t Total, void *ICPrivate); typedef int (FFMS_CC *TAudioNameCallback)(const char *SourceFile, int Track, const FFMS_AudioProperties *AP, char *FileName, int FNSize, void *Private); diff --git a/aegisub/libffms/src/core/indexing.cpp b/aegisub/libffms/src/core/indexing.cpp index 3b45130c8..dc823ebc3 100644 --- a/aegisub/libffms/src/core/indexing.cpp +++ b/aegisub/libffms/src/core/indexing.cpp @@ -97,8 +97,8 @@ SharedAudioContext::~SharedAudioContext() { TFrameInfo::TFrameInfo() { } -TFrameInfo::TFrameInfo(int64_t DTS, int64_t SampleStart, unsigned int SampleCount, int RepeatPict, bool KeyFrame, int64_t FilePos, unsigned int FrameSize) { - this->DTS = DTS; +TFrameInfo::TFrameInfo(int64_t PTS, int64_t SampleStart, unsigned int SampleCount, int RepeatPict, bool KeyFrame, int64_t FilePos, unsigned int FrameSize) { + this->PTS = PTS; this->RepeatPict = RepeatPict; this->KeyFrame = KeyFrame; this->SampleStart = SampleStart; @@ -108,12 +108,12 @@ TFrameInfo::TFrameInfo(int64_t DTS, int64_t SampleStart, unsigned int SampleCoun this->OriginalPos = 0; } -TFrameInfo TFrameInfo::VideoFrameInfo(int64_t DTS, int RepeatPict, bool KeyFrame, int64_t FilePos, unsigned int FrameSize) { - return TFrameInfo(DTS, 0, 0, RepeatPict, KeyFrame, FilePos, FrameSize); +TFrameInfo TFrameInfo::VideoFrameInfo(int64_t PTS, int RepeatPict, bool KeyFrame, int64_t FilePos, unsigned int FrameSize) { + return TFrameInfo(PTS, 0, 0, RepeatPict, KeyFrame, FilePos, FrameSize); } -TFrameInfo TFrameInfo::AudioFrameInfo(int64_t DTS, int64_t SampleStart, unsigned int SampleCount, bool KeyFrame, int64_t FilePos, unsigned int FrameSize) { - return TFrameInfo(DTS, SampleStart, SampleCount, 0, KeyFrame, FilePos, FrameSize); +TFrameInfo TFrameInfo::AudioFrameInfo(int64_t PTS, int64_t SampleStart, unsigned int SampleCount, bool KeyFrame, int64_t FilePos, unsigned int FrameSize) { + return TFrameInfo(PTS, SampleStart, SampleCount, 0, KeyFrame, FilePos, FrameSize); } void FFMS_Track::WriteTimecodes(const char *TimecodeFile) { @@ -128,21 +128,21 @@ void FFMS_Track::WriteTimecodes(const char *TimecodeFile) { Timecodes << "# timecode format v2\n"; for (iterator Cur=begin(); Cur!=end(); Cur++) - Timecodes << std::fixed << ((Cur->DTS * TB.Num) / (double)TB.Den) << "\n"; + Timecodes << std::fixed << ((Cur->PTS * TB.Num) / (double)TB.Den) << "\n"; } -int FFMS_Track::FrameFromDTS(int64_t DTS) { +int FFMS_Track::FrameFromPTS(int64_t PTS) { for (int i = 0; i < static_cast(size()); i++) - if (at(i).DTS == DTS) + if (at(i).PTS == PTS) return i; return -1; } -int FFMS_Track::ClosestFrameFromDTS(int64_t DTS) { +int FFMS_Track::ClosestFrameFromPTS(int64_t PTS) { int Frame = 0; int64_t BestDiff = 0xFFFFFFFFFFFFFFLL; // big number for (int i = 0; i < static_cast(size()); i++) { - int64_t CurrentDiff = FFABS(at(i).DTS - DTS); + int64_t CurrentDiff = FFABS(at(i).PTS - PTS); if (CurrentDiff < BestDiff) { BestDiff = CurrentDiff; Frame = i; @@ -234,8 +234,8 @@ void FFMS_Index::CalculateFileSignature(const char *Filename, int64_t *Filesize, av_sha1_final(ctx, Digest); } -static bool DTSComparison(TFrameInfo FI1, TFrameInfo FI2) { - return FI1.DTS < FI2.DTS; +static bool PTSComparison(TFrameInfo FI1, TFrameInfo FI2) { + return FI1.PTS < FI2.PTS; } void FFMS_Index::Sort() { @@ -244,7 +244,7 @@ void FFMS_Index::Sort() { for (size_t i = 0; i < Cur->size(); i++) Cur->at(i).OriginalPos = i; - std::sort(Cur->begin(), Cur->end(), DTSComparison); + std::sort(Cur->begin(), Cur->end(), PTSComparison); std::vector ReorderTemp; ReorderTemp.resize(Cur->size()); diff --git a/aegisub/libffms/src/core/indexing.h b/aegisub/libffms/src/core/indexing.h index c1e921922..52e71c7ed 100644 --- a/aegisub/libffms/src/core/indexing.h +++ b/aegisub/libffms/src/core/indexing.h @@ -74,10 +74,10 @@ public: size_t OriginalPos; TFrameInfo(); - static TFrameInfo VideoFrameInfo(int64_t DTS, int RepeatPict, bool KeyFrame, int64_t FilePos = 0, unsigned int FrameSize = 0); - static TFrameInfo AudioFrameInfo(int64_t DTS, int64_t SampleStart, unsigned int SampleCount, bool KeyFrame, int64_t FilePos = 0, unsigned int FrameSize = 0); + static TFrameInfo VideoFrameInfo(int64_t PTS, int RepeatPict, bool KeyFrame, int64_t FilePos = 0, unsigned int FrameSize = 0); + static TFrameInfo AudioFrameInfo(int64_t PTS, int64_t SampleStart, unsigned int SampleCount, bool KeyFrame, int64_t FilePos = 0, unsigned int FrameSize = 0); private: - TFrameInfo(int64_t DTS, int64_t SampleStart, unsigned int SampleCount, int RepeatPict, bool KeyFrame, int64_t FilePos, unsigned int FrameSize); + TFrameInfo(int64_t PTS, int64_t SampleStart, unsigned int SampleCount, int RepeatPict, bool KeyFrame, int64_t FilePos, unsigned int FrameSize); }; class FFMS_Track : public std::vector { @@ -87,8 +87,8 @@ public: int FindClosestVideoKeyFrame(int Frame); int FindClosestAudioKeyFrame(int64_t Sample); - int FrameFromDTS(int64_t DTS); - int ClosestFrameFromDTS(int64_t DTS); + int FrameFromPTS(int64_t PTS); + int ClosestFrameFromPTS(int64_t PTS); void WriteTimecodes(const char *TimecodeFile); FFMS_Track(); diff --git a/aegisub/libffms/src/core/lavfaudio.cpp b/aegisub/libffms/src/core/lavfaudio.cpp index 6e0eb42fc..7d4d2551e 100644 --- a/aegisub/libffms/src/core/lavfaudio.cpp +++ b/aegisub/libffms/src/core/lavfaudio.cpp @@ -55,8 +55,8 @@ FFLAVFAudio::FFLAVFAudio(const char *SourceFile, int Track, FFMS_Index *Index) int64_t Dummy; DecodeNextAudioBlock(&Dummy); - if (av_seek_frame(FormatContext, AudioTrack, Frames[0].DTS, AVSEEK_FLAG_BACKWARD) < 0) - av_seek_frame(FormatContext, AudioTrack, Frames[0].DTS, AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_ANY); + if (av_seek_frame(FormatContext, AudioTrack, Frames[0].PTS, AVSEEK_FLAG_BACKWARD) < 0) + av_seek_frame(FormatContext, AudioTrack, Frames[0].PTS, AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_ANY); avcodec_flush_buffers(CodecContext); FillAP(AP, CodecContext, Frames); @@ -116,7 +116,7 @@ void FFLAVFAudio::GetAudio(void *Buf, int64_t Start, int64_t Count) { const int64_t SizeConst = (av_get_bits_per_sample_format(CodecContext->sample_fmt) * CodecContext->channels) / 8; memset(Buf, 0, static_cast(SizeConst * Count)); - int PreDecBlocks = 0; + unsigned int PreDecBlocks = 0; uint8_t *DstBuf = static_cast(Buf); // Fill with everything in the cache @@ -136,8 +136,8 @@ void FFLAVFAudio::GetAudio(void *Buf, int64_t Start, int64_t Count) { } // Did the seeking fail? - if (av_seek_frame(FormatContext, AudioTrack, Frames[CurrentAudioBlock].DTS, AVSEEK_FLAG_BACKWARD) < 0) - av_seek_frame(FormatContext, AudioTrack, Frames[CurrentAudioBlock].DTS, AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_ANY); + if (av_seek_frame(FormatContext, AudioTrack, Frames[CurrentAudioBlock].PTS, AVSEEK_FLAG_BACKWARD) < 0) + av_seek_frame(FormatContext, AudioTrack, Frames[CurrentAudioBlock].PTS, AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_ANY); avcodec_flush_buffers(CodecContext); @@ -147,15 +147,15 @@ void FFLAVFAudio::GetAudio(void *Buf, int64_t Start, int64_t Count) { InitNullPacket(Packet); // Establish where we actually are - // Trigger on packet dts difference since groups can otherwise be indistinguishable - int64_t LastDTS = - 1; + // Trigger on packet PTS difference since groups can otherwise be indistinguishable + int64_t LastPTS = - 1; while (av_read_frame(FormatContext, &Packet) >= 0) { if (Packet.stream_index == AudioTrack) { - if (LastDTS < 0) { - LastDTS = Packet.dts; - } else if (LastDTS != Packet.dts) { + if (LastPTS < 0) { + LastPTS = Packet.dts; + } else if (LastPTS != Packet.dts) { for (size_t i = 0; i < Frames.size(); i++) - if (Frames[i].DTS == Packet.dts) { + if (Frames[i].PTS == Packet.dts) { // The current match was consumed CurrentAudioBlock = i + 1; break; diff --git a/aegisub/libffms/src/core/lavfvideo.cpp b/aegisub/libffms/src/core/lavfvideo.cpp index 2c78a93ab..e62a02c7d 100644 --- a/aegisub/libffms/src/core/lavfvideo.cpp +++ b/aegisub/libffms/src/core/lavfvideo.cpp @@ -40,7 +40,7 @@ FFLAVFVideo::FFLAVFVideo(const char *SourceFile, int Track, FFMS_Index *Index, LAVFOpenFile(SourceFile, FormatContext); - if (SeekMode >= 0 && av_seek_frame(FormatContext, VideoTrack, Frames[0].DTS, AVSEEK_FLAG_BACKWARD) < 0) + if (SeekMode >= 0 && av_seek_frame(FormatContext, VideoTrack, Frames[0].PTS, AVSEEK_FLAG_BACKWARD) < 0) throw FFMS_Exception(FFMS_ERROR_DECODING, FFMS_ERROR_CODEC, "Video track is unseekable"); @@ -76,8 +76,8 @@ FFLAVFVideo::FFLAVFVideo(const char *SourceFile, int Track, FFMS_Index *Index, VP.ColorSpace = 0; VP.ColorRange = 0; #endif - VP.FirstTime = ((Frames.front().DTS * Frames.TB.Num) / (double)Frames.TB.Den) / 1000; - VP.LastTime = ((Frames.back().DTS * Frames.TB.Num) / (double)Frames.TB.Den) / 1000; + VP.FirstTime = ((Frames.front().PTS * Frames.TB.Num) / (double)Frames.TB.Den) / 1000; + VP.LastTime = ((Frames.back().PTS * Frames.TB.Num) / (double)Frames.TB.Den) / 1000; if (CodecContext->width <= 0 || CodecContext->height <= 0) throw FFMS_Exception(FFMS_ERROR_DECODING, FFMS_ERROR_CODEC, @@ -91,8 +91,8 @@ FFLAVFVideo::FFLAVFVideo(const char *SourceFile, int Track, FFMS_Index *Index, // Adjust framerate to match the duration of the first frame if (Frames.size() >= 2) { - unsigned int DTSDiff = (unsigned int)FFMAX(Frames[1].DTS - Frames[0].DTS, 1); - VP.FPSDenominator *= DTSDiff; + unsigned int PTSDiff = (unsigned int)FFMAX(Frames[1].PTS - Frames[0].PTS, 1); + VP.FPSDenominator *= PTSDiff; } // Cannot "output" to PPFrame without doing all other initialization @@ -158,7 +158,7 @@ FFMS_Frame *FFLAVFVideo::GetFrame(int n) { if (SeekMode == 0) { if (n < CurrentFrame) { - av_seek_frame(FormatContext, VideoTrack, Frames[0].DTS, AVSEEK_FLAG_BACKWARD); + av_seek_frame(FormatContext, VideoTrack, Frames[0].PTS, AVSEEK_FLAG_BACKWARD); avcodec_flush_buffers(CodecContext); CurrentFrame = 0; } @@ -167,7 +167,7 @@ FFMS_Frame *FFLAVFVideo::GetFrame(int n) { if (n < CurrentFrame || ClosestKF > CurrentFrame + 10 || (SeekMode == 3 && n > CurrentFrame + 10)) { ReSeek: av_seek_frame(FormatContext, VideoTrack, - (SeekMode == 3) ? Frames[n].DTS : Frames[ClosestKF + SeekOffset].DTS, + (SeekMode == 3) ? Frames[n].PTS : Frames[ClosestKF + SeekOffset].PTS, AVSEEK_FLAG_BACKWARD); avcodec_flush_buffers(CodecContext); HasSeeked = true; @@ -186,7 +186,7 @@ ReSeek: HasSeeked = false; // Is the seek destination time known? Does it belong to a frame? - if (StartTime < 0 || (CurrentFrame = Frames.FrameFromDTS(StartTime)) < 0) { + if (StartTime < 0 || (CurrentFrame = Frames.FrameFromPTS(StartTime)) < 0) { switch (SeekMode) { case 1: // No idea where we are so go back a bit further @@ -199,7 +199,7 @@ ReSeek: goto ReSeek; case 2: case 3: - CurrentFrame = Frames.ClosestFrameFromDTS(StartTime); + CurrentFrame = Frames.ClosestFrameFromPTS(StartTime); break; default: throw FFMS_Exception(FFMS_ERROR_SEEKING, FFMS_ERROR_UNKNOWN, diff --git a/aegisub/libffms/src/core/matroskaaudio.cpp b/aegisub/libffms/src/core/matroskaaudio.cpp index d8acc9a7b..7ce9419b4 100644 --- a/aegisub/libffms/src/core/matroskaaudio.cpp +++ b/aegisub/libffms/src/core/matroskaaudio.cpp @@ -107,7 +107,7 @@ void FFMatroskaAudio::GetAudio(void *Buf, int64_t Start, int64_t Count) { const int64_t SizeConst = (av_get_bits_per_sample_format(CodecContext->sample_fmt) * CodecContext->channels) / 8; memset(Buf, 0, static_cast(SizeConst * Count)); - int PreDecBlocks = 0; + unsigned int PreDecBlocks = 0; uint8_t *DstBuf = static_cast(Buf); // Fill with everything in the cache diff --git a/aegisub/libffms/src/core/matroskavideo.cpp b/aegisub/libffms/src/core/matroskavideo.cpp index 0c9510316..d45c95a8f 100644 --- a/aegisub/libffms/src/core/matroskavideo.cpp +++ b/aegisub/libffms/src/core/matroskavideo.cpp @@ -107,8 +107,8 @@ FFMatroskaVideo::FFMatroskaVideo(const char *SourceFile, int Track, VP.ColorSpace = 0; VP.ColorRange = 0; #endif - VP.FirstTime = ((Frames.front().DTS * Frames.TB.Num) / (double)Frames.TB.Den) / 1000; - VP.LastTime = ((Frames.back().DTS * Frames.TB.Num) / (double)Frames.TB.Den) / 1000; + VP.FirstTime = ((Frames.front().PTS * Frames.TB.Num) / (double)Frames.TB.Den) / 1000; + VP.LastTime = ((Frames.back().PTS * Frames.TB.Num) / (double)Frames.TB.Den) / 1000; if (CodecContext->width <= 0 || CodecContext->height <= 0) throw FFMS_Exception(FFMS_ERROR_DECODING, FFMS_ERROR_CODEC, @@ -116,8 +116,8 @@ FFMatroskaVideo::FFMatroskaVideo(const char *SourceFile, int Track, // Calculate the average framerate if (Frames.size() >= 2) { - double DTSDiff = (double)(Frames.back().DTS - Frames.front().DTS); - VP.FPSDenominator = (unsigned int)(DTSDiff * mkv_TruncFloat(TI->TimecodeScale) / (double)1000 / (double)(VP.NumFrames - 1) + 0.5); + double PTSDiff = (double)(Frames.back().PTS - Frames.front().PTS); + VP.FPSDenominator = (unsigned int)(PTSDiff * mkv_TruncFloat(TI->TimecodeScale) / (double)1000 / (double)(VP.NumFrames - 1) + 0.5); VP.FPSNumerator = 1000000; } diff --git a/aegisub/libffms/src/core/utils.cpp b/aegisub/libffms/src/core/utils.cpp index a552becc0..061765bdb 100644 --- a/aegisub/libffms/src/core/utils.cpp +++ b/aegisub/libffms/src/core/utils.cpp @@ -217,8 +217,8 @@ void FillAP(FFMS_AudioProperties &AP, AVCodecContext *CTX, FFMS_Track &Frames) { AP.ChannelLayout = CTX->channel_layout; AP.SampleRate = CTX->sample_rate; AP.NumSamples = (Frames.back()).SampleStart + (Frames.back()).SampleCount; - 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; + AP.FirstTime = ((Frames.front().PTS * Frames.TB.Num) / (double)Frames.TB.Den) / 1000; + AP.LastTime = ((Frames.back().PTS * Frames.TB.Num) / (double)Frames.TB.Den) / 1000; } #ifdef HAALISOURCE diff --git a/aegisub/libffms/src/core/videosource.cpp b/aegisub/libffms/src/core/videosource.cpp index 1405a3534..cf03d76cd 100644 --- a/aegisub/libffms/src/core/videosource.cpp +++ b/aegisub/libffms/src/core/videosource.cpp @@ -194,7 +194,7 @@ FFMS_VideoSource::~FFMS_VideoSource() { } FFMS_Frame *FFMS_VideoSource::GetFrameByTime(double Time) { - int Frame = Frames.ClosestFrameFromDTS(static_cast((Time * 1000 * Frames.TB.Den) / Frames.TB.Num)); + int Frame = Frames.ClosestFrameFromPTS(static_cast((Time * 1000 * Frames.TB.Den) / Frames.TB.Num)); return GetFrame(Frame); } diff --git a/aegisub/libffms/src/core/videosource.h b/aegisub/libffms/src/core/videosource.h index 867ddb6de..70d25a745 100644 --- a/aegisub/libffms/src/core/videosource.h +++ b/aegisub/libffms/src/core/videosource.h @@ -99,7 +99,7 @@ private: int SeekMode; FFSourceResources Res; - void DecodeNextFrame(int64_t *DTS); + void DecodeNextFrame(int64_t *PTS); protected: void Free(bool CloseCodec); public: