SourceBufferList.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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_dom_SourceBufferList_h_
  6. #define mozilla_dom_SourceBufferList_h_
  7. #include "SourceBuffer.h"
  8. #include "js/RootingAPI.h"
  9. #include "mozilla/Assertions.h"
  10. #include "mozilla/Attributes.h"
  11. #include "mozilla/DOMEventTargetHelper.h"
  12. #include "nsCycleCollectionNoteChild.h"
  13. #include "nsCycleCollectionParticipant.h"
  14. #include "nsISupports.h"
  15. #include "nsTArray.h"
  16. struct JSContext;
  17. class JSObject;
  18. namespace mozilla {
  19. template <typename T> class AsyncEventRunner;
  20. namespace dom {
  21. class MediaSource;
  22. class SourceBufferList final : public DOMEventTargetHelper
  23. {
  24. public:
  25. /** WebIDL Methods. */
  26. SourceBuffer* IndexedGetter(uint32_t aIndex, bool& aFound);
  27. uint32_t Length();
  28. IMPL_EVENT_HANDLER(addsourcebuffer);
  29. IMPL_EVENT_HANDLER(removesourcebuffer);
  30. /** End WebIDL methods. */
  31. NS_DECL_ISUPPORTS_INHERITED
  32. NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SourceBufferList,
  33. DOMEventTargetHelper)
  34. explicit SourceBufferList(MediaSource* aMediaSource);
  35. MediaSource* GetParentObject() const;
  36. JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
  37. // Append a SourceBuffer and fire "addsourcebuffer" at the list.
  38. void Append(SourceBuffer* aSourceBuffer);
  39. // Remove a SourceBuffer and fire "removesourcebuffer" at the list.
  40. void Remove(SourceBuffer* aSourceBuffer);
  41. // Returns true if aSourceBuffer is present in the list.
  42. bool Contains(SourceBuffer* aSourceBuffer);
  43. // Remove all SourceBuffers and fire a single "removesourcebuffer" at the list.
  44. void Clear();
  45. // True if list has zero entries.
  46. bool IsEmpty();
  47. // Returns true if updating is true on any SourceBuffers in the list.
  48. bool AnyUpdating();
  49. // Runs the range removal steps from the MSE specification on each SourceBuffer.
  50. void RangeRemoval(double aStart, double aEnd);
  51. // Mark all SourceBuffers input buffers as ended.
  52. void Ended();
  53. // Returns the highest end time of any of the Sourcebuffers.
  54. double GetHighestBufferedEndTime();
  55. // Append a SourceBuffer to the list. No event is fired.
  56. void AppendSimple(SourceBuffer* aSourceBuffer);
  57. // Remove all SourceBuffers from mSourceBuffers.
  58. // No event is fired and no action is performed on the sourcebuffers.
  59. void ClearSimple();
  60. double HighestStartTime();
  61. double HighestEndTime();
  62. private:
  63. ~SourceBufferList();
  64. friend class AsyncEventRunner<SourceBufferList>;
  65. void DispatchSimpleEvent(const char* aName);
  66. void QueueAsyncSimpleEvent(const char* aName);
  67. RefPtr<MediaSource> mMediaSource;
  68. nsTArray<RefPtr<SourceBuffer> > mSourceBuffers;
  69. };
  70. } // namespace dom
  71. } // namespace mozilla
  72. #endif /* mozilla_dom_SourceBufferList_h_ */