/src/mozilla-central/dom/media/mp4/MP4Metadata.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
2 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | | |
5 | | #ifndef MP4METADATA_H_ |
6 | | #define MP4METADATA_H_ |
7 | | |
8 | | #include "mozilla/TypeTraits.h" |
9 | | #include "mozilla/UniquePtr.h" |
10 | | #include "DecoderData.h" |
11 | | #include "Index.h" |
12 | | #include "MediaData.h" |
13 | | #include "MediaInfo.h" |
14 | | #include "MediaResult.h" |
15 | | #include "ByteStream.h" |
16 | | #include "mp4parse.h" |
17 | | |
18 | | namespace mozilla { |
19 | | |
20 | | DDLoggedTypeDeclName(MP4Metadata); |
21 | | |
22 | | // The memory owner in mIndice.indices is rust mp4 parser, so lifetime of this |
23 | | // class SHOULD NOT longer than rust parser. |
24 | | class IndiceWrapper |
25 | | { |
26 | | public: |
27 | | size_t Length() const; |
28 | | |
29 | | bool GetIndice(size_t aIndex, Index::Indice& aIndice) const; |
30 | | |
31 | | explicit IndiceWrapper(Mp4parseByteData& aRustIndice); |
32 | | |
33 | | protected: |
34 | | Mp4parseByteData mIndice; |
35 | | }; |
36 | | |
37 | 0 | struct FreeMP4Parser { void operator()(Mp4parseParser* aPtr) { mp4parse_free(aPtr); } }; |
38 | | |
39 | | // Wrap an Stream to remember the read offset. |
40 | | class StreamAdaptor { |
41 | | public: |
42 | | explicit StreamAdaptor(ByteStream* aSource) |
43 | | : mSource(aSource) |
44 | | , mOffset(0) |
45 | 0 | { |
46 | 0 | } |
47 | | |
48 | 0 | ~StreamAdaptor() {} |
49 | | |
50 | | bool Read(uint8_t* buffer, uintptr_t size, size_t* bytes_read); |
51 | | |
52 | | private: |
53 | | ByteStream* mSource; |
54 | | CheckedInt<size_t> mOffset; |
55 | | }; |
56 | | |
57 | | class MP4Metadata : public DecoderDoctorLifeLogger<MP4Metadata> |
58 | | { |
59 | | public: |
60 | | explicit MP4Metadata(ByteStream* aSource); |
61 | | ~MP4Metadata(); |
62 | | |
63 | | // Simple template class containing a MediaResult and another type. |
64 | | template <typename T> |
65 | | class ResultAndType |
66 | | { |
67 | | public: |
68 | | template <typename M2, typename T2> |
69 | | ResultAndType(M2&& aM, T2&& aT) |
70 | | : mResult(std::forward<M2>(aM)), mT(std::forward<T2>(aT)) |
71 | 0 | { |
72 | 0 | } Unexecuted instantiation: mozilla::MP4Metadata::ResultAndType<unsigned int>::ResultAndType<mozilla::MediaResult, unsigned int>(mozilla::MediaResult&&, unsigned int&&) Unexecuted instantiation: mozilla::MP4Metadata::ResultAndType<unsigned int>::ResultAndType<nsresult const&, unsigned int&>(nsresult const&, unsigned int&) Unexecuted instantiation: mozilla::MP4Metadata::ResultAndType<mozilla::UniquePtr<mozilla::TrackInfo, mozilla::DefaultDelete<mozilla::TrackInfo> > >::ResultAndType<mozilla::MediaResult, decltype(nullptr)>(mozilla::MediaResult&&, decltype(nullptr)&&) Unexecuted instantiation: mozilla::MP4Metadata::ResultAndType<mozilla::UniquePtr<mozilla::TrackInfo, mozilla::DefaultDelete<mozilla::TrackInfo> > >::ResultAndType<nsresult const&, mozilla::UniquePtr<mozilla::TrackInfo, mozilla::DefaultDelete<mozilla::TrackInfo> > >(nsresult const&, mozilla::UniquePtr<mozilla::TrackInfo, mozilla::DefaultDelete<mozilla::TrackInfo> >&&) Unexecuted instantiation: mozilla::MP4Metadata::ResultAndType<mozilla::CryptoFile const*>::ResultAndType<nsresult const&, mozilla::CryptoFile const*>(nsresult const&, mozilla::CryptoFile const*&&) Unexecuted instantiation: mozilla::MP4Metadata::ResultAndType<mozilla::UniquePtr<mozilla::IndiceWrapper, mozilla::DefaultDelete<mozilla::IndiceWrapper> > >::ResultAndType<mozilla::MediaResult, decltype(nullptr)>(mozilla::MediaResult&&, decltype(nullptr)&&) Unexecuted instantiation: mozilla::MP4Metadata::ResultAndType<mozilla::UniquePtr<mozilla::IndiceWrapper, mozilla::DefaultDelete<mozilla::IndiceWrapper> > >::ResultAndType<nsresult const&, mozilla::UniquePtr<mozilla::IndiceWrapper, mozilla::DefaultDelete<mozilla::IndiceWrapper> > >(nsresult const&, mozilla::UniquePtr<mozilla::IndiceWrapper, mozilla::DefaultDelete<mozilla::IndiceWrapper> >&&) Unexecuted instantiation: mozilla::MP4Metadata::ResultAndType<RefPtr<mozilla::MediaByteBuffer> >::ResultAndType<mozilla::MediaResult, decltype(nullptr)>(mozilla::MediaResult&&, decltype(nullptr)&&) Unexecuted instantiation: mozilla::MP4Metadata::ResultAndType<RefPtr<mozilla::MediaByteBuffer> >::ResultAndType<nsresult const&, RefPtr<mozilla::MediaByteBuffer> >(nsresult const&, RefPtr<mozilla::MediaByteBuffer>&&) |
73 | | ResultAndType(const ResultAndType&) = default; |
74 | | ResultAndType& operator=(const ResultAndType&) = default; |
75 | | ResultAndType(ResultAndType&&) = default; |
76 | 0 | ResultAndType& operator=(ResultAndType&&) = default; |
77 | | |
78 | 0 | mozilla::MediaResult& Result() { return mResult; } Unexecuted instantiation: mozilla::MP4Metadata::ResultAndType<RefPtr<mozilla::MediaByteBuffer> >::Result() Unexecuted instantiation: mozilla::MP4Metadata::ResultAndType<unsigned int>::Result() Unexecuted instantiation: mozilla::MP4Metadata::ResultAndType<mozilla::UniquePtr<mozilla::TrackInfo, mozilla::DefaultDelete<mozilla::TrackInfo> > >::Result() Unexecuted instantiation: mozilla::MP4Metadata::ResultAndType<mozilla::UniquePtr<mozilla::IndiceWrapper, mozilla::DefaultDelete<mozilla::IndiceWrapper> > >::Result() Unexecuted instantiation: mozilla::MP4Metadata::ResultAndType<mozilla::CryptoFile const*>::Result() |
79 | 0 | T& Ref() { return mT; } Unexecuted instantiation: mozilla::MP4Metadata::ResultAndType<RefPtr<mozilla::MediaByteBuffer> >::Ref() Unexecuted instantiation: mozilla::MP4Metadata::ResultAndType<unsigned int>::Ref() Unexecuted instantiation: mozilla::MP4Metadata::ResultAndType<mozilla::UniquePtr<mozilla::TrackInfo, mozilla::DefaultDelete<mozilla::TrackInfo> > >::Ref() Unexecuted instantiation: mozilla::MP4Metadata::ResultAndType<mozilla::UniquePtr<mozilla::IndiceWrapper, mozilla::DefaultDelete<mozilla::IndiceWrapper> > >::Ref() Unexecuted instantiation: mozilla::MP4Metadata::ResultAndType<mozilla::CryptoFile const*>::Ref() |
80 | | |
81 | | private: |
82 | | mozilla::MediaResult mResult; |
83 | | typename mozilla::Decay<T>::Type mT; |
84 | | }; |
85 | | |
86 | | using ResultAndByteBuffer = ResultAndType<RefPtr<mozilla::MediaByteBuffer>>; |
87 | | static ResultAndByteBuffer Metadata(ByteStream* aSource); |
88 | | |
89 | 0 | static constexpr uint32_t NumberTracksError() { return UINT32_MAX; } |
90 | | using ResultAndTrackCount = ResultAndType<uint32_t>; |
91 | | ResultAndTrackCount GetNumberTracks(mozilla::TrackInfo::TrackType aType) const; |
92 | | |
93 | | using ResultAndTrackInfo = |
94 | | ResultAndType<mozilla::UniquePtr<mozilla::TrackInfo>>; |
95 | | ResultAndTrackInfo GetTrackInfo(mozilla::TrackInfo::TrackType aType, |
96 | | size_t aTrackNumber) const; |
97 | | |
98 | | bool CanSeek() const; |
99 | | |
100 | | using ResultAndCryptoFile = ResultAndType<const CryptoFile*>; |
101 | | ResultAndCryptoFile Crypto() const; |
102 | | |
103 | | using ResultAndIndice = ResultAndType<mozilla::UniquePtr<IndiceWrapper>>; |
104 | | ResultAndIndice GetTrackIndice(mozilla::TrackID aTrackID); |
105 | | |
106 | | nsresult Parse(); |
107 | | |
108 | | private: |
109 | | void UpdateCrypto(); |
110 | | Maybe<uint32_t> TrackTypeToGlobalTrackIndex(mozilla::TrackInfo::TrackType aType, size_t aTrackNumber) const; |
111 | | |
112 | | CryptoFile mCrypto; |
113 | | RefPtr<ByteStream> mSource; |
114 | | StreamAdaptor mSourceAdaptor; |
115 | | mozilla::UniquePtr<Mp4parseParser, FreeMP4Parser> mParser; |
116 | | }; |
117 | | |
118 | | } // namespace mozilla |
119 | | |
120 | | #endif // MP4METADATA_H_ |