/src/mozilla-central/dom/media/mediasource/ContainerParser.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef MOZILLA_CONTAINERPARSER_H_ |
8 | | #define MOZILLA_CONTAINERPARSER_H_ |
9 | | |
10 | | #include "mozilla/RefPtr.h" |
11 | | #include "MediaContainerType.h" |
12 | | #include "MediaResource.h" |
13 | | #include "MediaResult.h" |
14 | | |
15 | | namespace mozilla { |
16 | | |
17 | | class MediaByteBuffer; |
18 | | class SourceBufferResource; |
19 | | |
20 | | DDLoggedTypeDeclName(ContainerParser); |
21 | | |
22 | | class ContainerParser : public DecoderDoctorLifeLogger<ContainerParser> |
23 | | { |
24 | | public: |
25 | | explicit ContainerParser(const MediaContainerType& aType); |
26 | | virtual ~ContainerParser(); |
27 | | |
28 | | // Return true if aData starts with an initialization segment. |
29 | | // The base implementation exists only for debug logging and is expected |
30 | | // to be called first from the overriding implementation. |
31 | | // Return NS_OK if segment is present, NS_ERROR_NOT_AVAILABLE if no sufficient |
32 | | // data is currently available to make a determination. Any other value |
33 | | // indicates an error. |
34 | | virtual MediaResult IsInitSegmentPresent(MediaByteBuffer* aData); |
35 | | |
36 | | // Return true if aData starts with a media segment. |
37 | | // The base implementation exists only for debug logging and is expected |
38 | | // to be called first from the overriding implementation. |
39 | | // Return NS_OK if segment is present, NS_ERROR_NOT_AVAILABLE if no sufficient |
40 | | // data is currently available to make a determination. Any other value |
41 | | // indicates an error. |
42 | | virtual MediaResult IsMediaSegmentPresent(MediaByteBuffer* aData); |
43 | | |
44 | | // Parse aData to extract the start and end frame times from the media |
45 | | // segment. aData may not start on a parser sync boundary. Return NS_OK |
46 | | // if aStart and aEnd have been updated and NS_ERROR_NOT_AVAILABLE otherwise |
47 | | // when no error were encountered. |
48 | | virtual MediaResult ParseStartAndEndTimestamps(MediaByteBuffer* aData, |
49 | | int64_t& aStart, int64_t& aEnd); |
50 | | |
51 | | // Compare aLhs and rHs, considering any error that may exist in the |
52 | | // timestamps from the format's base representation. Return true if aLhs |
53 | | // == aRhs within the error epsilon. |
54 | | bool TimestampsFuzzyEqual(int64_t aLhs, int64_t aRhs); |
55 | | |
56 | | virtual int64_t GetRoundingError(); |
57 | | |
58 | | MediaByteBuffer* InitData(); |
59 | | |
60 | | bool HasInitData() |
61 | 0 | { |
62 | 0 | return mHasInitData; |
63 | 0 | } |
64 | | |
65 | | // Return true if a complete initialization segment has been passed |
66 | | // to ParseStartAndEndTimestamps(). The calls below to retrieve |
67 | | // MediaByteRanges will be valid from when this call first succeeds. |
68 | | bool HasCompleteInitData(); |
69 | | // Returns the byte range of the first complete init segment, or an empty |
70 | | // range if not complete. |
71 | | MediaByteRange InitSegmentRange(); |
72 | | // Returns the byte range of the first complete media segment header, |
73 | | // or an empty range if not complete. |
74 | | MediaByteRange MediaHeaderRange(); |
75 | | // Returns the byte range of the first complete media segment or an empty |
76 | | // range if not complete. |
77 | | MediaByteRange MediaSegmentRange(); |
78 | | |
79 | | static ContainerParser* CreateForMIMEType(const MediaContainerType& aType); |
80 | | |
81 | 0 | const MediaContainerType& ContainerType() const { return mType; } |
82 | | |
83 | | protected: |
84 | | RefPtr<MediaByteBuffer> mInitData; |
85 | | RefPtr<SourceBufferResource> mResource; |
86 | | bool mHasInitData; |
87 | | uint64_t mTotalParsed; |
88 | | uint64_t mGlobalOffset; |
89 | | MediaByteRange mCompleteInitSegmentRange; |
90 | | MediaByteRange mCompleteMediaHeaderRange; |
91 | | MediaByteRange mCompleteMediaSegmentRange; |
92 | | const MediaContainerType mType; |
93 | | }; |
94 | | |
95 | | } // namespace mozilla |
96 | | |
97 | | #endif /* MOZILLA_CONTAINERPARSER_H_ */ |