Line data Source code
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 0 : class ContainerParser
21 : {
22 : public:
23 : explicit ContainerParser(const MediaContainerType& aType);
24 : virtual ~ContainerParser();
25 :
26 : // Return true if aData starts with an initialization segment.
27 : // The base implementation exists only for debug logging and is expected
28 : // to be called first from the overriding implementation.
29 : // Return NS_OK if segment is present, NS_ERROR_NOT_AVAILABLE if no sufficient
30 : // data is currently available to make a determination. Any other value
31 : // indicates an error.
32 : virtual MediaResult IsInitSegmentPresent(MediaByteBuffer* aData);
33 :
34 : // Return true if aData starts with a media segment.
35 : // The base implementation exists only for debug logging and is expected
36 : // to be called first from the overriding implementation.
37 : // Return NS_OK if segment is present, NS_ERROR_NOT_AVAILABLE if no sufficient
38 : // data is currently available to make a determination. Any other value
39 : // indicates an error.
40 : virtual MediaResult IsMediaSegmentPresent(MediaByteBuffer* aData);
41 :
42 : // Parse aData to extract the start and end frame times from the media
43 : // segment. aData may not start on a parser sync boundary. Return NS_OK
44 : // if aStart and aEnd have been updated and NS_ERROR_NOT_AVAILABLE otherwise
45 : // when no error were encountered.
46 : virtual MediaResult ParseStartAndEndTimestamps(MediaByteBuffer* aData,
47 : int64_t& aStart, int64_t& aEnd);
48 :
49 : // Compare aLhs and rHs, considering any error that may exist in the
50 : // timestamps from the format's base representation. Return true if aLhs
51 : // == aRhs within the error epsilon.
52 : bool TimestampsFuzzyEqual(int64_t aLhs, int64_t aRhs);
53 :
54 : virtual int64_t GetRoundingError();
55 :
56 : MediaByteBuffer* InitData();
57 :
58 0 : bool HasInitData()
59 : {
60 0 : return mHasInitData;
61 : }
62 :
63 : // Return true if a complete initialization segment has been passed
64 : // to ParseStartAndEndTimestamps(). The calls below to retrieve
65 : // MediaByteRanges will be valid from when this call first succeeds.
66 : bool HasCompleteInitData();
67 : // Returns the byte range of the first complete init segment, or an empty
68 : // range if not complete.
69 : MediaByteRange InitSegmentRange();
70 : // Returns the byte range of the first complete media segment header,
71 : // or an empty range if not complete.
72 : MediaByteRange MediaHeaderRange();
73 : // Returns the byte range of the first complete media segment or an empty
74 : // range if not complete.
75 : MediaByteRange MediaSegmentRange();
76 :
77 : static ContainerParser* CreateForMIMEType(const MediaContainerType& aType);
78 :
79 : protected:
80 : RefPtr<MediaByteBuffer> mInitData;
81 : RefPtr<SourceBufferResource> mResource;
82 : bool mHasInitData;
83 : uint64_t mTotalParsed;
84 : uint64_t mGlobalOffset;
85 : MediaByteRange mCompleteInitSegmentRange;
86 : MediaByteRange mCompleteMediaHeaderRange;
87 : MediaByteRange mCompleteMediaSegmentRange;
88 : const MediaContainerType mType;
89 : };
90 :
91 : } // namespace mozilla
92 :
93 : #endif /* MOZILLA_CONTAINERPARSER_H_ */
|