From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- dom/media/webcodecs/EncodedVideoChunk.h | 119 ++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 dom/media/webcodecs/EncodedVideoChunk.h (limited to 'dom/media/webcodecs/EncodedVideoChunk.h') diff --git a/dom/media/webcodecs/EncodedVideoChunk.h b/dom/media/webcodecs/EncodedVideoChunk.h new file mode 100644 index 0000000000..3a9fb1e368 --- /dev/null +++ b/dom/media/webcodecs/EncodedVideoChunk.h @@ -0,0 +1,119 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* 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_dom_EncodedVideoChunk_h +#define mozilla_dom_EncodedVideoChunk_h + +#include "js/TypeDecls.h" +#include "mozilla/Attributes.h" +#include "mozilla/Buffer.h" +#include "mozilla/ErrorResult.h" +#include "mozilla/Maybe.h" +#include "mozilla/dom/BindingDeclarations.h" +#include "nsCycleCollectionParticipant.h" +#include "nsWrapperCache.h" + +class nsIGlobalObject; + +namespace mozilla { + +class MediaAlignedByteBuffer; +class MediaRawData; + +namespace dom { + +class MaybeSharedArrayBufferViewOrMaybeSharedArrayBuffer; +class OwningMaybeSharedArrayBufferViewOrMaybeSharedArrayBuffer; +class StructuredCloneHolder; + +enum class EncodedVideoChunkType : uint8_t; +struct EncodedVideoChunkInit; + +} // namespace dom +} // namespace mozilla + +namespace mozilla::dom { + +class EncodedVideoChunkData { + public: + EncodedVideoChunkData(already_AddRefed aBuffer, + const EncodedVideoChunkType& aType, int64_t aTimestamp, + Maybe&& aDuration); + EncodedVideoChunkData(const EncodedVideoChunkData& aData) = default; + ~EncodedVideoChunkData(); + + UniquePtr Clone() const; + already_AddRefed TakeData(); + + protected: + // mBuffer's byte length is guaranteed to be smaller than UINT32_MAX. + RefPtr mBuffer; + EncodedVideoChunkType mType; + int64_t mTimestamp; + Maybe mDuration; +}; + +class EncodedVideoChunk final : public EncodedVideoChunkData, + public nsISupports, + public nsWrapperCache { + public: + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(EncodedVideoChunk) + + public: + EncodedVideoChunk(nsIGlobalObject* aParent, + already_AddRefed aBuffer, + const EncodedVideoChunkType& aType, int64_t aTimestamp, + Maybe&& aDuration); + + EncodedVideoChunk(nsIGlobalObject* aParent, + const EncodedVideoChunkData& aData); + + protected: + ~EncodedVideoChunk() = default; + + public: + nsIGlobalObject* GetParentObject() const; + + JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + + static already_AddRefed Constructor( + const GlobalObject& aGlobal, const EncodedVideoChunkInit& aInit, + ErrorResult& aRv); + + EncodedVideoChunkType Type() const; + + int64_t Timestamp() const; + + Nullable GetDuration() const; + + uint32_t ByteLength() const; + + void CopyTo( + const MaybeSharedArrayBufferViewOrMaybeSharedArrayBuffer& aDestination, + ErrorResult& aRv); + + // [Serializable] implementations: {Read, Write}StructuredClone + static JSObject* ReadStructuredClone(JSContext* aCx, nsIGlobalObject* aGlobal, + JSStructuredCloneReader* aReader, + const EncodedVideoChunkData& aData); + + bool WriteStructuredClone(JSStructuredCloneWriter* aWriter, + StructuredCloneHolder* aHolder) const; + + private: + // EncodedVideoChunk can run on either main thread or worker thread. + void AssertIsOnOwningThread() const { + NS_ASSERT_OWNINGTHREAD(EncodedVideoChunk); + } + + nsCOMPtr mParent; +}; + +} // namespace mozilla::dom + +#endif // mozilla_dom_EncodedVideoChunk_h -- cgit v1.2.3