Line data Source code
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 "mp4_demuxer/DecoderData.h"
11 : #include "mp4_demuxer/Index.h"
12 : #include "MediaData.h"
13 : #include "MediaInfo.h"
14 : #include "MediaResult.h"
15 : #include "Stream.h"
16 : #include "mp4parse.h"
17 :
18 : namespace mp4_demuxer {
19 :
20 : class MP4MetadataStagefright;
21 : class MP4MetadataRust;
22 :
23 0 : class IndiceWrapper {
24 : public:
25 : virtual size_t Length() const = 0;
26 :
27 : // TODO: Index::Indice is from stagefright, we should use another struct once
28 : // stagefrigth is removed.
29 : virtual bool GetIndice(size_t aIndex, Index::Indice& aIndice) const = 0;
30 :
31 0 : virtual ~IndiceWrapper() {}
32 : };
33 :
34 : class MP4Metadata
35 : {
36 : public:
37 : explicit MP4Metadata(Stream* aSource);
38 : ~MP4Metadata();
39 :
40 : // Simple template class containing a MediaResult and another type.
41 : template <typename T>
42 0 : class ResultAndType
43 : {
44 : public:
45 : template <typename M2, typename T2>
46 0 : ResultAndType(M2&& aM, T2&& aT)
47 0 : : mResult(Forward<M2>(aM)), mT(Forward<T2>(aT))
48 : {
49 0 : }
50 0 : ResultAndType(const ResultAndType&) = default;
51 : ResultAndType& operator=(const ResultAndType&) = default;
52 0 : ResultAndType(ResultAndType&&) = default;
53 : ResultAndType& operator=(ResultAndType&&) = default;
54 :
55 0 : mozilla::MediaResult& Result() { return mResult; }
56 0 : T& Ref() { return mT; }
57 :
58 : private:
59 : mozilla::MediaResult mResult;
60 : typename mozilla::Decay<T>::Type mT;
61 : };
62 :
63 : using ResultAndByteBuffer = ResultAndType<RefPtr<mozilla::MediaByteBuffer>>;
64 : static ResultAndByteBuffer Metadata(Stream* aSource);
65 :
66 0 : static constexpr uint32_t NumberTracksError() { return UINT32_MAX; }
67 : using ResultAndTrackCount = ResultAndType<uint32_t>;
68 : ResultAndTrackCount GetNumberTracks(mozilla::TrackInfo::TrackType aType) const;
69 :
70 : using ResultAndTrackInfo =
71 : ResultAndType<mozilla::UniquePtr<mozilla::TrackInfo>>;
72 : ResultAndTrackInfo GetTrackInfo(mozilla::TrackInfo::TrackType aType,
73 : size_t aTrackNumber) const;
74 :
75 : bool CanSeek() const;
76 :
77 : using ResultAndCryptoFile = ResultAndType<const CryptoFile*>;
78 : ResultAndCryptoFile Crypto() const;
79 :
80 : using ResultAndIndice = ResultAndType<mozilla::UniquePtr<IndiceWrapper>>;
81 : ResultAndIndice GetTrackIndice(mozilla::TrackID aTrackID);
82 :
83 : private:
84 : UniquePtr<MP4MetadataStagefright> mStagefright;
85 : UniquePtr<MP4MetadataRust> mRust;
86 : mutable bool mDisableRust;
87 : mutable bool mReportedAudioTrackTelemetry;
88 : mutable bool mReportedVideoTrackTelemetry;
89 : bool ShouldPreferRust() const;
90 : };
91 :
92 : } // namespace mp4_demuxer
93 :
94 : #endif // MP4METADATA_H_
|