summaryrefslogtreecommitdiffstats
path: root/dom/media/mediasource/SourceBufferList.h
blob: ddd9e224a13c6d9874c069218002fa36c7cafe54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_dom_SourceBufferList_h_
#define mozilla_dom_SourceBufferList_h_

#include "SourceBuffer.h"
#include "js/RootingAPI.h"
#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "nsCycleCollectionNoteChild.h"
#include "nsCycleCollectionParticipant.h"
#include "nsISupports.h"
#include "nsTArray.h"

struct JSContext;
class JSObject;

namespace mozilla {

template <typename T> class AsyncEventRunner;

namespace dom {

class MediaSource;

class SourceBufferList final : public DOMEventTargetHelper
{
public:
  /** WebIDL Methods. */
  SourceBuffer* IndexedGetter(uint32_t aIndex, bool& aFound);

  uint32_t Length();

  IMPL_EVENT_HANDLER(addsourcebuffer);
  IMPL_EVENT_HANDLER(removesourcebuffer);

  /** End WebIDL methods. */

  NS_DECL_ISUPPORTS_INHERITED
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SourceBufferList,
                                           DOMEventTargetHelper)

  explicit SourceBufferList(MediaSource* aMediaSource);

  MediaSource* GetParentObject() const;

  JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;

  // Append a SourceBuffer and fire "addsourcebuffer" at the list.
  void Append(SourceBuffer* aSourceBuffer);

  // Remove a SourceBuffer and fire "removesourcebuffer" at the list.
  void Remove(SourceBuffer* aSourceBuffer);

  // Returns true if aSourceBuffer is present in the list.
  bool Contains(SourceBuffer* aSourceBuffer);

  // Remove all SourceBuffers and fire a single "removesourcebuffer" at the list.
  void Clear();

  // True if list has zero entries.
  bool IsEmpty();

  // Returns true if updating is true on any SourceBuffers in the list.
  bool AnyUpdating();

  // Runs the range removal steps from the MSE specification on each SourceBuffer.
  void RangeRemoval(double aStart, double aEnd);

  // Mark all SourceBuffers input buffers as ended.
  void Ended();

  // Returns the highest end time of any of the Sourcebuffers.
  double GetHighestBufferedEndTime();

  // Append a SourceBuffer to the list. No event is fired.
  void AppendSimple(SourceBuffer* aSourceBuffer);

  // Remove all SourceBuffers from mSourceBuffers.
  //  No event is fired and no action is performed on the sourcebuffers.
  void ClearSimple();

  double HighestStartTime();
  double HighestEndTime();

private:
  ~SourceBufferList();

  friend class AsyncEventRunner<SourceBufferList>;
  void DispatchSimpleEvent(const char* aName);
  void QueueAsyncSimpleEvent(const char* aName);

  RefPtr<MediaSource> mMediaSource;
  nsTArray<RefPtr<SourceBuffer> > mSourceBuffers;
};

} // namespace dom

} // namespace mozilla

#endif /* mozilla_dom_SourceBufferList_h_ */