| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#ifndef TRACK_H |
| 22 |
#define TRACK_H |
| 23 |
|
| 24 |
#include "ffms.h" |
| 25 |
|
| 26 |
#include <cstddef> |
| 27 |
#include <vector> |
| 28 |
#include <memory> |
| 29 |
|
| 30 |
class ZipFile; |
| 31 |
|
| 32 |
struct FrameInfo { |
| 33 |
int64_t PTS; |
| 34 |
int64_t OriginalPTS; |
| 35 |
int64_t FilePos; |
| 36 |
int64_t SampleStart; |
| 37 |
uint32_t SampleCount; |
| 38 |
size_t OriginalPos; |
| 39 |
size_t PosInDecodingOrder; |
| 40 |
int FrameType; |
| 41 |
int RepeatPict; |
| 42 |
bool KeyFrame; |
| 43 |
bool MarkedHidden; |
| 44 |
bool SecondField; |
| 45 |
|
| 46 |
int64_t DTS; |
| 47 |
|
| 48 |
|
| 49 |
constexpr bool Skipped() const { return MarkedHidden || SecondField; } |
| 50 |
}; |
| 51 |
|
| 52 |
struct FFMS_Track { |
| 53 |
private: |
| 54 |
typedef std::vector<FrameInfo> frame_vec; |
| 55 |
struct TrackData { |
| 56 |
frame_vec Frames; |
| 57 |
std::vector<int> RealFrameNumbers; |
| 58 |
std::vector<FFMS_FrameInfo> PublicFrameInfo; |
| 59 |
}; |
| 60 |
|
| 61 |
std::shared_ptr<TrackData> Data; |
| 62 |
|
| 63 |
void MaybeReorderFrames(); |
| 64 |
void GeneratePublicInfo(); |
| 65 |
|
| 66 |
public: |
| 67 |
FFMS_TrackType TT = FFMS_TYPE_UNKNOWN; |
| 68 |
FFMS_TrackTimeBase TB = FFMS_TrackTimeBase{ 0, 0 }; |
| 69 |
int MaxBFrames = 0; |
| 70 |
bool UseDTS = false; |
| 71 |
bool HasTS = false; |
| 72 |
bool HasDiscontTS = false; |
| 73 |
int64_t LastDuration = 0; |
| 74 |
int SampleRate = 0; |
| 75 |
|
| 76 |
void AddVideoFrame(int64_t PTS, int64_t DTS, int RepeatPict, bool KeyFrame, int FrameType, int64_t FilePos = 0, bool Invisible = false, bool SecondField = false); |
| 77 |
void AddAudioFrame(int64_t PTS, int64_t DTS, int64_t SampleStart, uint32_t SampleCount, bool KeyFrame, int64_t FilePos = 0, bool Invisible = false); |
| 78 |
|
| 79 |
void RevertToDTS(); |
| 80 |
void MaybeHideFrames(); |
| 81 |
void FinalizeTrack(); |
| 82 |
void FillAudioGaps(); |
| 83 |
|
| 84 |
int FindClosestVideoKeyFrame(int Frame) const; |
| 85 |
int FrameFromPTS(int64_t PTS, bool AllowHidden = false) const; |
| 86 |
int FrameFromPos(int64_t Pos, bool AllowHidden = false) const; |
| 87 |
int ClosestFrameFromPTS(int64_t PTS) const; |
| 88 |
int RealFrameNumber(int Frame) const; |
| 89 |
int VisibleFrameCount() const; |
| 90 |
|
| 91 |
const FFMS_FrameInfo *GetFrameInfo(size_t N) const; |
| 92 |
|
| 93 |
void WriteTimecodes(const char *TimecodeFile) const; |
| 94 |
void Write(ZipFile &Stream) const; |
| 95 |
|
| 96 |
typedef frame_vec::allocator_type allocator_type; |
| 97 |
typedef frame_vec::size_type size_type; |
| 98 |
typedef frame_vec::difference_type difference_type; |
| 99 |
typedef frame_vec::const_pointer pointer; |
| 100 |
typedef frame_vec::const_reference reference; |
| 101 |
typedef frame_vec::value_type value_type; |
| 102 |
typedef frame_vec::const_iterator iterator; |
| 103 |
typedef frame_vec::const_reverse_iterator reverse_iterator; |
| 104 |
|
| 105 |
void clear() { |
| 106 |
Data = std::make_shared<TrackData>(); |
| 107 |
} |
| 108 |
|
| 109 |
bool empty() const { return Data->Frames.empty(); } |
| 110 |
size_type size() const { return Data->Frames.size(); } |
| 111 |
reference operator[](size_type pos) const { return Data->Frames[pos]; } |
| 112 |
reference front() const { return Data->Frames.front(); } |
| 113 |
reference back() const { return Data->Frames.back(); } |
| 114 |
iterator begin() const { return Data->Frames.begin(); } |
| 115 |
iterator end() const { return Data->Frames.end(); } |
| 116 |
|
| 117 |
FFMS_Track(); |
| 118 |
FFMS_Track(ZipFile &Stream); |
| 119 |
FFMS_Track(int64_t Num, int64_t Den, FFMS_TrackType TT, bool HasDiscontTS, bool UseDTS, bool HasTS = true); |
| 120 |
}; |
| 121 |
|
| 122 |
#endif |