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