SourceBufferAttributes.h (4006B)
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/DefineEnum.h" 12 #include "mozilla/Maybe.h" 13 #include "mozilla/dom/SourceBufferBinding.h" 14 15 namespace mozilla { 16 17 class SourceBufferAttributes { 18 public: 19 // Current state as per Segment Parser Loop Algorithm 20 // http://w3c.github.io/media-source/index.html#sourcebuffer-segment-parser-loop 21 MOZ_DEFINE_ENUM_CLASS_WITH_TOSTRING_AT_CLASS_SCOPE(AppendState, 22 (WAITING_FOR_SEGMENT, 23 PARSING_INIT_SEGMENT, 24 PARSING_MEDIA_SEGMENT)); 25 26 explicit SourceBufferAttributes(bool aGenerateTimestamp) 27 : mGenerateTimestamps(aGenerateTimestamp), 28 mAppendWindowStart(0), 29 mAppendWindowEnd(PositiveInfinity<double>()), 30 mAppendMode(dom::SourceBufferAppendMode::Segments), 31 mApparentTimestampOffset(0), 32 mAppendState(AppendState::WAITING_FOR_SEGMENT) {} 33 34 SourceBufferAttributes(const SourceBufferAttributes& aOther) = default; 35 36 double GetAppendWindowStart() const { return mAppendWindowStart; } 37 38 double GetAppendWindowEnd() const { return mAppendWindowEnd; } 39 40 void SetAppendWindowStart(double aWindowStart) { 41 mAppendWindowStart = aWindowStart; 42 } 43 44 void SetAppendWindowEnd(double aWindowEnd) { mAppendWindowEnd = aWindowEnd; } 45 46 double GetApparentTimestampOffset() const { return mApparentTimestampOffset; } 47 48 void SetApparentTimestampOffset(double aTimestampOffset) { 49 mApparentTimestampOffset = aTimestampOffset; 50 mTimestampOffset = media::TimeUnit::FromSeconds(aTimestampOffset); 51 } 52 53 media::TimeUnit GetTimestampOffset() const { return mTimestampOffset; } 54 55 void SetTimestampOffset(const media::TimeUnit& aTimestampOffset) { 56 mTimestampOffset = aTimestampOffset; 57 mApparentTimestampOffset = aTimestampOffset.ToSeconds(); 58 } 59 60 dom::SourceBufferAppendMode GetAppendMode() const { return mAppendMode; } 61 62 void SetAppendMode(dom::SourceBufferAppendMode aAppendMode) { 63 mAppendMode = aAppendMode; 64 } 65 66 void SetGroupStartTimestamp(const media::TimeUnit& aGroupStartTimestamp) { 67 mGroupStartTimestamp = Some(aGroupStartTimestamp); 68 } 69 70 media::TimeUnit GetGroupStartTimestamp() const { 71 return mGroupStartTimestamp.ref(); 72 } 73 74 bool HaveGroupStartTimestamp() const { return mGroupStartTimestamp.isSome(); } 75 76 void ResetGroupStartTimestamp() { mGroupStartTimestamp.reset(); } 77 78 void RestartGroupStartTimestamp() { 79 mGroupStartTimestamp = Some(mGroupEndTimestamp); 80 } 81 82 media::TimeUnit GetGroupEndTimestamp() const { return mGroupEndTimestamp; } 83 84 void SetGroupEndTimestamp(const media::TimeUnit& aGroupEndTimestamp) { 85 mGroupEndTimestamp = aGroupEndTimestamp; 86 } 87 88 AppendState GetAppendState() const { return mAppendState; } 89 90 void SetAppendState(AppendState aState) { mAppendState = aState; } 91 92 // mGenerateTimestamp isn't mutable once the source buffer has been 93 // constructed 94 bool mGenerateTimestamps; 95 96 SourceBufferAttributes& operator=(const SourceBufferAttributes& aOther) = 97 default; 98 99 private: 100 SourceBufferAttributes() = delete; 101 102 double mAppendWindowStart; 103 double mAppendWindowEnd; 104 dom::SourceBufferAppendMode mAppendMode; 105 double mApparentTimestampOffset; 106 media::TimeUnit mTimestampOffset; 107 Maybe<media::TimeUnit> mGroupStartTimestamp; 108 media::TimeUnit mGroupEndTimestamp; 109 // The current append state as per 110 // https://w3c.github.io/media-source/#sourcebuffer-append-state 111 AppendState mAppendState; 112 }; 113 114 } // end namespace mozilla 115 116 #endif /* mozilla_SourceBufferAttributes_h_ */