/work/obj-fuzz/dist/include/SourceBufferAttributes.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef mozilla_SourceBufferAttributes_h_ |
8 | | #define mozilla_SourceBufferAttributes_h_ |
9 | | |
10 | | #include "TimeUnits.h" |
11 | | #include "mozilla/dom/SourceBufferBinding.h" |
12 | | #include "mozilla/Maybe.h" |
13 | | |
14 | | namespace mozilla { |
15 | | |
16 | | class SourceBufferAttributes { |
17 | | public: |
18 | | |
19 | | // Current state as per Segment Parser Loop Algorithm |
20 | | // http://w3c.github.io/media-source/index.html#sourcebuffer-segment-parser-loop |
21 | | enum class AppendState |
22 | | { |
23 | | WAITING_FOR_SEGMENT, |
24 | | PARSING_INIT_SEGMENT, |
25 | | PARSING_MEDIA_SEGMENT, |
26 | | }; |
27 | | |
28 | | explicit SourceBufferAttributes(bool aGenerateTimestamp) |
29 | | : mGenerateTimestamps(aGenerateTimestamp) |
30 | | , mAppendWindowStart(0) |
31 | | , mAppendWindowEnd(PositiveInfinity<double>()) |
32 | | , mAppendMode(dom::SourceBufferAppendMode::Segments) |
33 | | , mApparentTimestampOffset(0) |
34 | | , mAppendState(AppendState::WAITING_FOR_SEGMENT) |
35 | | {} |
36 | | |
37 | | SourceBufferAttributes(const SourceBufferAttributes& aOther) = default; |
38 | | |
39 | | double GetAppendWindowStart() const |
40 | 0 | { |
41 | 0 | return mAppendWindowStart; |
42 | 0 | } |
43 | | |
44 | | double GetAppendWindowEnd() const |
45 | 0 | { |
46 | 0 | return mAppendWindowEnd; |
47 | 0 | } |
48 | | |
49 | | void SetAppendWindowStart(double aWindowStart) |
50 | | { |
51 | | mAppendWindowStart = aWindowStart; |
52 | | } |
53 | | |
54 | | void SetAppendWindowEnd(double aWindowEnd) |
55 | | { |
56 | | mAppendWindowEnd = aWindowEnd; |
57 | | } |
58 | | |
59 | | double GetApparentTimestampOffset() const |
60 | 0 | { |
61 | 0 | return mApparentTimestampOffset; |
62 | 0 | } |
63 | | |
64 | | void SetApparentTimestampOffset(double aTimestampOffset) |
65 | | { |
66 | | mApparentTimestampOffset = aTimestampOffset; |
67 | | mTimestampOffset = media::TimeUnit::FromSeconds(aTimestampOffset); |
68 | | } |
69 | | |
70 | | media::TimeUnit GetTimestampOffset() const |
71 | | { |
72 | | return mTimestampOffset; |
73 | | } |
74 | | |
75 | | void SetTimestampOffset(const media::TimeUnit& aTimestampOffset) |
76 | | { |
77 | | mTimestampOffset = aTimestampOffset; |
78 | | mApparentTimestampOffset = aTimestampOffset.ToSeconds(); |
79 | | } |
80 | | |
81 | | dom::SourceBufferAppendMode GetAppendMode() const |
82 | 0 | { |
83 | 0 | return mAppendMode; |
84 | 0 | } |
85 | | |
86 | | void SetAppendMode(dom::SourceBufferAppendMode aAppendMode) |
87 | | { |
88 | | mAppendMode = aAppendMode; |
89 | | } |
90 | | |
91 | | void SetGroupStartTimestamp(const media::TimeUnit& aGroupStartTimestamp) |
92 | | { |
93 | | mGroupStartTimestamp = Some(aGroupStartTimestamp); |
94 | | } |
95 | | |
96 | | media::TimeUnit GetGroupStartTimestamp() const |
97 | | { |
98 | | return mGroupStartTimestamp.ref(); |
99 | | } |
100 | | |
101 | | bool HaveGroupStartTimestamp() const |
102 | | { |
103 | | return mGroupStartTimestamp.isSome(); |
104 | | } |
105 | | |
106 | | void ResetGroupStartTimestamp() |
107 | | { |
108 | | mGroupStartTimestamp.reset(); |
109 | | } |
110 | | |
111 | | void RestartGroupStartTimestamp() |
112 | | { |
113 | | mGroupStartTimestamp = Some(mGroupEndTimestamp); |
114 | | } |
115 | | |
116 | | media::TimeUnit GetGroupEndTimestamp() const |
117 | | { |
118 | | return mGroupEndTimestamp; |
119 | | } |
120 | | |
121 | | void SetGroupEndTimestamp(const media::TimeUnit& aGroupEndTimestamp) |
122 | | { |
123 | | mGroupEndTimestamp = aGroupEndTimestamp; |
124 | | } |
125 | | |
126 | | AppendState GetAppendState() const |
127 | | { |
128 | | return mAppendState; |
129 | | } |
130 | | |
131 | | void SetAppendState(AppendState aState) |
132 | | { |
133 | | mAppendState = aState; |
134 | | } |
135 | | |
136 | | // mGenerateTimestamp isn't mutable once the source buffer has been constructed |
137 | | bool mGenerateTimestamps; |
138 | | |
139 | | SourceBufferAttributes& operator=(const SourceBufferAttributes& aOther) = default; |
140 | | |
141 | | private: |
142 | | SourceBufferAttributes() = delete; |
143 | | |
144 | | double mAppendWindowStart; |
145 | | double mAppendWindowEnd; |
146 | | dom::SourceBufferAppendMode mAppendMode; |
147 | | double mApparentTimestampOffset; |
148 | | media::TimeUnit mTimestampOffset; |
149 | | Maybe<media::TimeUnit> mGroupStartTimestamp; |
150 | | media::TimeUnit mGroupEndTimestamp; |
151 | | // The current append state as per https://w3c.github.io/media-source/#sourcebuffer-append-state |
152 | | AppendState mAppendState; |
153 | | }; |
154 | | |
155 | | } // end namespace mozilla |
156 | | |
157 | | #endif /* mozilla_SourceBufferAttributes_h_ */ |