ContainerParser.h 3.3 KB

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