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/mp4/MP4Metadata.h | 116 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 dom/media/mp4/MP4Metadata.h (limited to 'dom/media/mp4/MP4Metadata.h') diff --git a/dom/media/mp4/MP4Metadata.h b/dom/media/mp4/MP4Metadata.h new file mode 100644 index 0000000000..e900fbedc3 --- /dev/null +++ b/dom/media/mp4/MP4Metadata.h @@ -0,0 +1,116 @@ +/* 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 MP4METADATA_H_ +#define MP4METADATA_H_ + +#include + +#include "mozilla/UniquePtr.h" +#include "DecoderData.h" +#include "MediaData.h" +#include "MediaInfo.h" +#include "MediaResult.h" +#include "ByteStream.h" +#include "mp4parse.h" +#include "SampleIterator.h" + +namespace mozilla { + +DDLoggedTypeDeclName(MP4Metadata); + +// The memory owner in mIndice.indices is rust mp4 parser, so lifetime of this +// class SHOULD NOT longer than rust parser. +class IndiceWrapper { + public: + size_t Length() const; + + bool GetIndice(size_t aIndex, MP4SampleIndex::Indice& aIndice) const; + + explicit IndiceWrapper(Mp4parseByteData& aRustIndice); + + protected: + Mp4parseByteData mIndice; +}; + +struct FreeMP4Parser { + void operator()(Mp4parseParser* aPtr) { mp4parse_free(aPtr); } +}; + +// Wrap an Stream to remember the read offset. +class StreamAdaptor { + public: + explicit StreamAdaptor(ByteStream* aSource) : mSource(aSource), mOffset(0) {} + + ~StreamAdaptor() = default; + + bool Read(uint8_t* buffer, uintptr_t size, size_t* bytes_read); + + private: + ByteStream* mSource; + CheckedInt mOffset; +}; + +class MP4Metadata : public DecoderDoctorLifeLogger { + public: + explicit MP4Metadata(ByteStream* aSource); + ~MP4Metadata(); + + // Simple template class containing a MediaResult and another type. + template + class ResultAndType { + public: + template + ResultAndType(M2&& aM, T2&& aT) + : mResult(std::forward(aM)), mT(std::forward(aT)) {} + ResultAndType(const ResultAndType&) = default; + ResultAndType& operator=(const ResultAndType&) = default; + ResultAndType(ResultAndType&&) = default; + ResultAndType& operator=(ResultAndType&&) = default; + + mozilla::MediaResult& Result() { return mResult; } + T& Ref() { return mT; } + + private: + mozilla::MediaResult mResult; + std::decay_t mT; + }; + + using ResultAndByteBuffer = ResultAndType>; + static ResultAndByteBuffer Metadata(ByteStream* aSource); + + static constexpr uint32_t NumberTracksError() { return UINT32_MAX; } + using ResultAndTrackCount = ResultAndType; + ResultAndTrackCount GetNumberTracks( + mozilla::TrackInfo::TrackType aType) const; + + using ResultAndTrackInfo = + ResultAndType>; + ResultAndTrackInfo GetTrackInfo(mozilla::TrackInfo::TrackType aType, + size_t aTrackNumber) const; + + bool CanSeek() const; + + using ResultAndCryptoFile = ResultAndType; + ResultAndCryptoFile Crypto() const; + + using ResultAndIndice = ResultAndType>; + ResultAndIndice GetTrackIndice(uint32_t aTrackId) const; + + nsresult Parse(); + + private: + void UpdateCrypto(); + Maybe TrackTypeToGlobalTrackIndex( + mozilla::TrackInfo::TrackType aType, size_t aTrackNumber) const; + + CryptoFile mCrypto; + RefPtr mSource; + StreamAdaptor mSourceAdaptor; + mozilla::UniquePtr mParser; +}; + +} // namespace mozilla + +#endif // MP4METADATA_H_ -- cgit v1.2.3