Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/MediaDecoderOwner.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim:set ts=2 sw=2 sts=2 et cindent: */
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
#ifndef MediaDecoderOwner_h_
7
#define MediaDecoderOwner_h_
8
9
#include "mozilla/UniquePtr.h"
10
#include "MediaInfo.h"
11
#include "MediaSegment.h"
12
#include "nsSize.h"
13
14
class nsIDocument;
15
16
namespace mozilla {
17
18
class AbstractThread;
19
class GMPCrashHelper;
20
class VideoFrameContainer;
21
class MediaInfo;
22
class MediaResult;
23
24
namespace dom {
25
class HTMLMediaElement;
26
} // namespace dom
27
28
class MediaDecoderOwner
29
{
30
public:
31
  // Called by the media decoder to indicate that the download is progressing.
32
  virtual void DownloadProgressed() = 0;
33
34
  // Dispatch an asynchronous event to the decoder owner
35
  virtual void DispatchAsyncEvent(const nsAString& aName) = 0;
36
37
  // Triggers a recomputation of readyState.
38
  virtual void UpdateReadyState() = 0;
39
40
  /**
41
   * Fires a timeupdate event. If aPeriodic is true, the event will only
42
   * be fired if we've not fired a timeupdate event (for any reason) in the
43
   * last 250ms, as required by the spec when the current time is periodically
44
   * increasing during playback.
45
   */
46
  virtual void FireTimeUpdate(bool aPeriodic) = 0;
47
48
  // Return true if decoding should be paused
49
  virtual bool GetPaused() = 0;
50
51
  // Called by the video decoder object, on the main thread,
52
  // when it has read the metadata containing video dimensions,
53
  // etc.
54
  // Must take ownership of MetadataTags aTags argument.
55
  virtual void MetadataLoaded(const MediaInfo* aInfo,
56
                              UniquePtr<const MetadataTags> aTags) = 0;
57
58
  // Called by the decoder object, on the main thread,
59
  // when it has read the first frame of the video or audio.
60
  virtual void FirstFrameLoaded() = 0;
61
62
  // Called by the decoder object, on the main thread,
63
  // when the resource has a network error during loading.
64
  // The decoder owner should call Shutdown() on the decoder and drop the
65
  // reference to the decoder to prevent further calls into the decoder.
66
  virtual void NetworkError(const MediaResult& aError) = 0;
67
68
  // Called by the decoder object, on the main thread, when the
69
  // resource has a decode error during metadata loading or decoding.
70
  // The decoder owner should call Shutdown() on the decoder and drop the
71
  // reference to the decoder to prevent further calls into the decoder.
72
  virtual void DecodeError(const MediaResult& aError) = 0;
73
74
  // Called by the decoder object, on the main thread, when the
75
  // resource has a decode issue during metadata loading or decoding, but can
76
  // continue decoding.
77
  virtual void DecodeWarning(const MediaResult& aError) = 0;
78
79
  // Return true if media element error attribute is not null.
80
  virtual bool HasError() const = 0;
81
82
  // Called by the video decoder object, on the main thread, when the
83
  // resource load has been cancelled.
84
  virtual void LoadAborted() = 0;
85
86
  // Called by the video decoder object, on the main thread,
87
  // when the video playback has ended.
88
  virtual void PlaybackEnded() = 0;
89
90
  // Called by the video decoder object, on the main thread,
91
  // when the resource has started seeking.
92
  virtual void SeekStarted() = 0;
93
94
  // Called by the video decoder object, on the main thread,
95
  // when the resource has completed seeking.
96
  virtual void SeekCompleted() = 0;
97
98
  // Called by the media stream, on the main thread, when the download
99
  // has been suspended by the cache or because the element itself
100
  // asked the decoder to suspend the download.
101
  virtual void DownloadSuspended() = 0;
102
103
  // Called by the media decoder to indicate whether the media cache has
104
  // suspended the channel.
105
  virtual void NotifySuspendedByCache(bool aSuspendedByCache) = 0;
106
107
  // called to notify that the principal of the decoder's media resource has changed.
108
  virtual void NotifyDecoderPrincipalChanged() = 0;
109
110
  // The status of the next frame which might be available from the decoder
111
  enum NextFrameStatus {
112
    // The next frame of audio/video is available
113
    NEXT_FRAME_AVAILABLE,
114
    // The next frame of audio/video is unavailable because the decoder
115
    // is paused while it buffers up data
116
    NEXT_FRAME_UNAVAILABLE_BUFFERING,
117
    // The next frame of audio/video is unavailable for the decoder is seeking.
118
    NEXT_FRAME_UNAVAILABLE_SEEKING,
119
    // The next frame of audio/video is unavailable for some other reasons
120
    NEXT_FRAME_UNAVAILABLE,
121
    // Sentinel value
122
    NEXT_FRAME_UNINITIALIZED
123
  };
124
125
  // Called by media decoder when the audible state changed
126
  virtual void SetAudibleState(bool aAudible) = 0;
127
128
  // Notified by the decoder that XPCOM shutdown has begun.
129
  // The decoder owner should call Shutdown() on the decoder and drop the
130
  // reference to the decoder to prevent further calls into the decoder.
131
  virtual void NotifyXPCOMShutdown() = 0;
132
133
  // Dispatches a "encrypted" event to the HTMLMediaElement, with the
134
  // provided init data. Actual dispatch may be delayed until HAVE_METADATA.
135
  // Main thread only.
136
  virtual void DispatchEncrypted(const nsTArray<uint8_t>& aInitData,
137
                                 const nsAString& aInitDataType) = 0;
138
139
  // Called by the media decoder to create audio/video tracks and add to its
140
  // owner's track list.
141
  virtual void ConstructMediaTracks(const MediaInfo* aInfo) = 0;
142
143
  // Called by the media decoder to removes all audio/video tracks from its
144
  // owner's track list.
145
  virtual void RemoveMediaTracks() = 0;
146
147
  // Called by the media decoder to notify the owner to resolve a seek promise.
148
  virtual void AsyncResolveSeekDOMPromiseIfExists() = 0;
149
150
  // Called by the media decoder to notify the owner to reject a seek promise.
151
  virtual void AsyncRejectSeekDOMPromiseIfExists() = 0;
152
153
  // Notified by the decoder that a decryption key is required before emitting
154
  // further output.
155
0
  virtual void NotifyWaitingForKey() {}
156
157
  /*
158
   * Methods that are used only in Gecko go here. We provide defaul
159
   * implementations so they can compile in Servo without modification.
160
   */
161
  // Return an abstract thread on which to run main thread runnables.
162
0
  virtual AbstractThread* AbstractMainThread() const { return nullptr; }
163
164
  // Get the HTMLMediaElement object if the decoder is being used from an
165
  // HTML media element, and null otherwise.
166
0
  virtual dom::HTMLMediaElement* GetMediaElement() { return nullptr; }
167
168
  // Called by the media decoder and the video frame to get the
169
  // ImageContainer containing the video data.
170
0
  virtual VideoFrameContainer* GetVideoFrameContainer() { return nullptr; }
171
172
  // Return the decoder owner's owner document.
173
0
  virtual nsIDocument* GetDocument() const { return nullptr; }
174
175
  // Called by the media decoder to create a GMPCrashHelper.
176
  virtual already_AddRefed<GMPCrashHelper> CreateGMPCrashHelper()
177
0
  {
178
0
    return nullptr;
179
0
  }
180
181
  // Called by the frame container to notify the layout engine that the
182
  // size of the image has changed, or the video needs to be be repainted
183
  // for some other reason.
184
  virtual void Invalidate(bool aImageSizeChanged,
185
                          Maybe<nsIntSize>& aNewIntrinsicSize,
186
0
                          bool aForceInvalidate) {}
187
188
  // Called after the MediaStream we're playing rendered a frame to aContainer
189
  // with a different principalHandle than the previous frame.
190
  virtual void PrincipalHandleChangedForVideoFrameContainer(
191
    VideoFrameContainer* aContainer,
192
0
    const PrincipalHandle& aNewPrincipalHandle) {}
193
194
  /*
195
   * Servo only methods go here. Please provide default implementations so they
196
   * can build in Gecko without any modification.
197
   */
198
};
199
200
} // namespace mozilla
201
202
#endif
203