Coverage Report

Created: 2018-09-25 14:53

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