Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/MediaSource.h
Line
Count
Source (jump to first uncovered line)
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_MediaSource_h_
8
#define mozilla_dom_MediaSource_h_
9
10
#include "MediaSourceDecoder.h"
11
#include "js/RootingAPI.h"
12
#include "mozilla/Assertions.h"
13
#include "mozilla/Attributes.h"
14
#include "mozilla/DOMEventTargetHelper.h"
15
#include "mozilla/MozPromise.h"
16
#include "mozilla/dom/MediaSourceBinding.h"
17
#include "nsCOMPtr.h"
18
#include "nsCycleCollectionNoteChild.h"
19
#include "nsCycleCollectionParticipant.h"
20
#include "nsID.h"
21
#include "nsISupports.h"
22
#include "nscore.h"
23
#include "TimeUnits.h"
24
25
struct JSContext;
26
class JSObject;
27
class nsPIDOMWindowInner;
28
29
namespace mozilla {
30
31
class AbstractThread;
32
class ErrorResult;
33
template <typename T> class AsyncEventRunner;
34
class MediaResult;
35
36
namespace dom {
37
class MediaSource;
38
} // namespace dom
39
DDLoggedTypeName(dom::MediaSource);
40
41
namespace dom {
42
43
class GlobalObject;
44
class SourceBuffer;
45
class SourceBufferList;
46
template <typename T> class Optional;
47
48
#define MOZILLA_DOM_MEDIASOURCE_IMPLEMENTATION_IID \
49
  { 0x3839d699, 0x22c5, 0x439f, \
50
  { 0x94, 0xca, 0x0e, 0x0b, 0x26, 0xf9, 0xca, 0xbf } }
51
52
class MediaSource final
53
  : public DOMEventTargetHelper
54
  , public DecoderDoctorLifeLogger<MediaSource>
55
{
56
public:
57
  /** WebIDL Methods. */
58
  static already_AddRefed<MediaSource>
59
  Constructor(const GlobalObject& aGlobal,
60
              ErrorResult& aRv);
61
62
  SourceBufferList* SourceBuffers();
63
  SourceBufferList* ActiveSourceBuffers();
64
  MediaSourceReadyState ReadyState();
65
66
  double Duration();
67
  void SetDuration(double aDuration, ErrorResult& aRv);
68
69
  already_AddRefed<SourceBuffer> AddSourceBuffer(const nsAString& aType, ErrorResult& aRv);
70
  void RemoveSourceBuffer(SourceBuffer& aSourceBuffer, ErrorResult& aRv);
71
72
  void EndOfStream(const Optional<MediaSourceEndOfStreamError>& aError, ErrorResult& aRv);
73
  void EndOfStream(const MediaResult& aError);
74
75
  void SetLiveSeekableRange(double aStart, double aEnd, ErrorResult& aRv);
76
  void ClearLiveSeekableRange(ErrorResult& aRv);
77
78
  static bool IsTypeSupported(const GlobalObject&, const nsAString& aType);
79
  static nsresult IsTypeSupported(const nsAString& aType, DecoderDoctorDiagnostics* aDiagnostics);
80
81
  static bool Enabled(JSContext* cx, JSObject* aGlobal);
82
  static bool ExperimentalEnabled(JSContext* cx, JSObject* aGlobal);
83
84
  IMPL_EVENT_HANDLER(sourceopen);
85
  IMPL_EVENT_HANDLER(sourceended);
86
  IMPL_EVENT_HANDLER(sourceclosed);
87
88
  /** End WebIDL Methods. */
89
90
  NS_DECL_ISUPPORTS_INHERITED
91
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaSource, DOMEventTargetHelper)
92
  NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_MEDIASOURCE_IMPLEMENTATION_IID)
93
94
  nsPIDOMWindowInner* GetParentObject() const;
95
96
  JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
97
98
  // Attach this MediaSource to Decoder aDecoder.  Returns false if already attached.
99
  bool Attach(MediaSourceDecoder* aDecoder);
100
  void Detach();
101
102
  // Set mReadyState to aState and fire the required events at the MediaSource.
103
  void SetReadyState(MediaSourceReadyState aState);
104
105
 // Used by SourceBuffer to call CreateSubDecoder.
106
  MediaSourceDecoder* GetDecoder()
107
  {
108
    return mDecoder;
109
  }
110
111
  nsIPrincipal* GetPrincipal()
112
0
  {
113
0
    return mPrincipal;
114
0
  }
115
116
  // Returns a string describing the state of the MediaSource internal
117
  // buffered data. Used for debugging purposes.
118
  void GetMozDebugReaderData(nsAString& aString);
119
120
  bool HasLiveSeekableRange() const { return mLiveSeekableRange.isSome(); }
121
  media::TimeInterval LiveSeekableRange() const
122
  {
123
    return mLiveSeekableRange.value();
124
  }
125
126
  AbstractThread* AbstractMainThread() const
127
  {
128
    return mAbstractMainThread;
129
  }
130
131
  // Resolve all CompletionPromise pending.
132
  void CompletePendingTransactions();
133
134
private:
135
  // SourceBuffer uses SetDuration and SourceBufferIsActive
136
  friend class mozilla::dom::SourceBuffer;
137
138
  ~MediaSource();
139
140
  explicit MediaSource(nsPIDOMWindowInner* aWindow);
141
142
  friend class AsyncEventRunner<MediaSource>;
143
  void DispatchSimpleEvent(const char* aName);
144
  void QueueAsyncSimpleEvent(const char* aName);
145
146
  void DurationChange(double aNewDuration, ErrorResult& aRv);
147
148
  // SetDuration with no checks.
149
  void SetDuration(double aDuration);
150
151
  typedef MozPromise<bool, MediaResult, /* IsExclusive = */ true>
152
    ActiveCompletionPromise;
153
  // Mark SourceBuffer as active and rebuild ActiveSourceBuffers.
154
  // Return a MozPromise that will be resolved once all related operations are
155
  // completed, or can't progress any further.
156
  // Such as, transition of readyState from HAVE_NOTHING to HAVE_METADATA.
157
  RefPtr<ActiveCompletionPromise> SourceBufferIsActive(
158
    SourceBuffer* aSourceBuffer);
159
160
  RefPtr<SourceBufferList> mSourceBuffers;
161
  RefPtr<SourceBufferList> mActiveSourceBuffers;
162
163
  RefPtr<MediaSourceDecoder> mDecoder;
164
  // Ensures the media element remains alive to dispatch progress and
165
  // durationchanged events.
166
  RefPtr<HTMLMediaElement> mMediaElement;
167
168
  RefPtr<nsIPrincipal> mPrincipal;
169
170
  const RefPtr<AbstractThread> mAbstractMainThread;
171
172
  MediaSourceReadyState mReadyState;
173
174
  Maybe<media::TimeInterval> mLiveSeekableRange;
175
  nsTArray<MozPromiseHolder<ActiveCompletionPromise>> mCompletionPromises;
176
};
177
178
NS_DEFINE_STATIC_IID_ACCESSOR(MediaSource, MOZILLA_DOM_MEDIASOURCE_IMPLEMENTATION_IID)
179
180
} // namespace dom
181
182
} // namespace mozilla
183
184
#endif /* mozilla_dom_MediaSource_h_ */