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