Line data Source code
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 0 : 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 0 : explicit SourceBufferAttributes(bool aGenerateTimestamp)
29 0 : : mGenerateTimestamps(aGenerateTimestamp)
30 : , mAppendWindowStart(0)
31 0 : , mAppendWindowEnd(PositiveInfinity<double>())
32 : , mAppendMode(dom::SourceBufferAppendMode::Segments)
33 : , mApparentTimestampOffset(0)
34 0 : , mAppendState(AppendState::WAITING_FOR_SEGMENT)
35 0 : {}
36 :
37 0 : SourceBufferAttributes(const SourceBufferAttributes& aOther) = default;
38 :
39 0 : double GetAppendWindowStart() const
40 : {
41 0 : return mAppendWindowStart;
42 : }
43 :
44 0 : double GetAppendWindowEnd() const
45 : {
46 0 : return mAppendWindowEnd;
47 : }
48 :
49 0 : void SetAppendWindowStart(double aWindowStart)
50 : {
51 0 : mAppendWindowStart = aWindowStart;
52 0 : }
53 :
54 0 : void SetAppendWindowEnd(double aWindowEnd)
55 : {
56 0 : mAppendWindowEnd = aWindowEnd;
57 0 : }
58 :
59 0 : double GetApparentTimestampOffset() const
60 : {
61 0 : return mApparentTimestampOffset;
62 : }
63 :
64 0 : void SetApparentTimestampOffset(double aTimestampOffset)
65 : {
66 0 : mApparentTimestampOffset = aTimestampOffset;
67 0 : mTimestampOffset = media::TimeUnit::FromSeconds(aTimestampOffset);
68 0 : }
69 :
70 0 : media::TimeUnit GetTimestampOffset() const
71 : {
72 0 : return mTimestampOffset;
73 : }
74 :
75 0 : void SetTimestampOffset(const media::TimeUnit& aTimestampOffset)
76 : {
77 0 : mTimestampOffset = aTimestampOffset;
78 0 : mApparentTimestampOffset = aTimestampOffset.ToSeconds();
79 0 : }
80 :
81 0 : dom::SourceBufferAppendMode GetAppendMode() const
82 : {
83 0 : return mAppendMode;
84 : }
85 :
86 0 : void SetAppendMode(dom::SourceBufferAppendMode aAppendMode)
87 : {
88 0 : mAppendMode = aAppendMode;
89 0 : }
90 :
91 0 : void SetGroupStartTimestamp(const media::TimeUnit& aGroupStartTimestamp)
92 : {
93 0 : mGroupStartTimestamp = Some(aGroupStartTimestamp);
94 0 : }
95 :
96 0 : media::TimeUnit GetGroupStartTimestamp() const
97 : {
98 0 : return mGroupStartTimestamp.ref();
99 : }
100 :
101 0 : bool HaveGroupStartTimestamp() const
102 : {
103 0 : return mGroupStartTimestamp.isSome();
104 : }
105 :
106 0 : void ResetGroupStartTimestamp()
107 : {
108 0 : mGroupStartTimestamp.reset();
109 0 : }
110 :
111 0 : void RestartGroupStartTimestamp()
112 : {
113 0 : mGroupStartTimestamp = Some(mGroupEndTimestamp);
114 0 : }
115 :
116 0 : media::TimeUnit GetGroupEndTimestamp() const
117 : {
118 0 : return mGroupEndTimestamp;
119 : }
120 :
121 0 : void SetGroupEndTimestamp(const media::TimeUnit& aGroupEndTimestamp)
122 : {
123 0 : mGroupEndTimestamp = aGroupEndTimestamp;
124 0 : }
125 :
126 0 : AppendState GetAppendState() const
127 : {
128 0 : return mAppendState;
129 : }
130 :
131 0 : void SetAppendState(AppendState aState)
132 : {
133 0 : mAppendState = aState;
134 0 : }
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_ */
|