From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- dom/media/mediasource/SourceBufferAttributes.h | 116 +++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 dom/media/mediasource/SourceBufferAttributes.h (limited to 'dom/media/mediasource/SourceBufferAttributes.h') diff --git a/dom/media/mediasource/SourceBufferAttributes.h b/dom/media/mediasource/SourceBufferAttributes.h new file mode 100644 index 0000000000..f15845b8a9 --- /dev/null +++ b/dom/media/mediasource/SourceBufferAttributes.h @@ -0,0 +1,116 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_SourceBufferAttributes_h_ +#define mozilla_SourceBufferAttributes_h_ + +#include "TimeUnits.h" +#include "mozilla/dom/SourceBufferBinding.h" +#include "mozilla/Maybe.h" + +namespace mozilla { + +class SourceBufferAttributes { + public: + // Current state as per Segment Parser Loop Algorithm + // http://w3c.github.io/media-source/index.html#sourcebuffer-segment-parser-loop + enum class AppendState { + WAITING_FOR_SEGMENT, + PARSING_INIT_SEGMENT, + PARSING_MEDIA_SEGMENT, + }; + + explicit SourceBufferAttributes(bool aGenerateTimestamp) + : mGenerateTimestamps(aGenerateTimestamp), + mAppendWindowStart(0), + mAppendWindowEnd(PositiveInfinity()), + mAppendMode(dom::SourceBufferAppendMode::Segments), + mApparentTimestampOffset(0), + mAppendState(AppendState::WAITING_FOR_SEGMENT) {} + + SourceBufferAttributes(const SourceBufferAttributes& aOther) = default; + + double GetAppendWindowStart() const { return mAppendWindowStart; } + + double GetAppendWindowEnd() const { return mAppendWindowEnd; } + + void SetAppendWindowStart(double aWindowStart) { + mAppendWindowStart = aWindowStart; + } + + void SetAppendWindowEnd(double aWindowEnd) { mAppendWindowEnd = aWindowEnd; } + + double GetApparentTimestampOffset() const { return mApparentTimestampOffset; } + + void SetApparentTimestampOffset(double aTimestampOffset) { + mApparentTimestampOffset = aTimestampOffset; + mTimestampOffset = media::TimeUnit::FromSeconds(aTimestampOffset); + } + + media::TimeUnit GetTimestampOffset() const { return mTimestampOffset; } + + void SetTimestampOffset(const media::TimeUnit& aTimestampOffset) { + mTimestampOffset = aTimestampOffset; + mApparentTimestampOffset = aTimestampOffset.ToSeconds(); + } + + dom::SourceBufferAppendMode GetAppendMode() const { return mAppendMode; } + + void SetAppendMode(dom::SourceBufferAppendMode aAppendMode) { + mAppendMode = aAppendMode; + } + + void SetGroupStartTimestamp(const media::TimeUnit& aGroupStartTimestamp) { + mGroupStartTimestamp = Some(aGroupStartTimestamp); + } + + media::TimeUnit GetGroupStartTimestamp() const { + return mGroupStartTimestamp.ref(); + } + + bool HaveGroupStartTimestamp() const { return mGroupStartTimestamp.isSome(); } + + void ResetGroupStartTimestamp() { mGroupStartTimestamp.reset(); } + + void RestartGroupStartTimestamp() { + mGroupStartTimestamp = Some(mGroupEndTimestamp); + } + + media::TimeUnit GetGroupEndTimestamp() const { return mGroupEndTimestamp; } + + void SetGroupEndTimestamp(const media::TimeUnit& aGroupEndTimestamp) { + mGroupEndTimestamp = aGroupEndTimestamp; + } + + AppendState GetAppendState() const { return mAppendState; } + + void SetAppendState(AppendState aState) { mAppendState = aState; } + + // mGenerateTimestamp isn't mutable once the source buffer has been + // constructed + bool mGenerateTimestamps; + + SourceBufferAttributes& operator=(const SourceBufferAttributes& aOther) = + default; + + private: + SourceBufferAttributes() = delete; + + double mAppendWindowStart; + double mAppendWindowEnd; + dom::SourceBufferAppendMode mAppendMode; + double mApparentTimestampOffset; + media::TimeUnit mTimestampOffset; + Maybe mGroupStartTimestamp; + media::TimeUnit mGroupEndTimestamp; + // The current append state as per + // https://w3c.github.io/media-source/#sourcebuffer-append-state + AppendState mAppendState; +}; + +} // end namespace mozilla + +#endif /* mozilla_SourceBufferAttributes_h_ */ -- cgit v1.2.3