tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ContainerParser.h (3824B)


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