Debian Codegraph @

src/core/track.h

raw symbols SCIP
1 // Copyright (c) 2013 Thomas Goyne <[email protected]>
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
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; // Frames[Frames[n].OriginalPos] will be the n-th frame in decoding order
39 size_t PosInDecodingOrder;
40 int FrameType;
41 int RepeatPict;
42 bool KeyFrame;
43 bool MarkedHidden;
44 bool SecondField;
45
46 int64_t DTS; // Only used during indexing and not stored in the index file. (If UseDTS is true, the PTS values will be DTS)
47
48 // If true, no frame corresponding to this packet will be output
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; // not persisted
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