Line data Source code
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 : #include "AbstractMediaDecoder.h"
9 : #include "nsAutoPtr.h"
10 :
11 : namespace mozilla {
12 :
13 : class AbstractThread;
14 : class GMPCrashHelper;
15 : class VideoFrameContainer;
16 : class MediaInfo;
17 : class MediaResult;
18 :
19 : namespace dom {
20 : class HTMLMediaElement;
21 : } // namespace dom
22 :
23 1 : class MediaDecoderOwner
24 : {
25 : public:
26 : // Called by the media decoder to indicate that the download is progressing.
27 : virtual void DownloadProgressed() = 0;
28 :
29 : // Dispatch an asynchronous event to the decoder owner
30 : virtual nsresult DispatchAsyncEvent(const nsAString& aName) = 0;
31 :
32 : // Triggers a recomputation of readyState.
33 : virtual void UpdateReadyState() = 0;
34 :
35 : /**
36 : * Fires a timeupdate event. If aPeriodic is true, the event will only
37 : * be fired if we've not fired a timeupdate event (for any reason) in the
38 : * last 250ms, as required by the spec when the current time is periodically
39 : * increasing during playback.
40 : */
41 : virtual void FireTimeUpdate(bool aPeriodic) = 0;
42 :
43 : // Get the HTMLMediaElement object if the decoder is being used from an
44 : // HTML media element, and null otherwise.
45 0 : virtual dom::HTMLMediaElement* GetMediaElement()
46 : {
47 0 : return nullptr;
48 : }
49 :
50 : // Return an abstract thread on which to run main thread runnables.
51 : virtual AbstractThread* AbstractMainThread() const = 0;
52 :
53 : // Return true if decoding should be paused
54 : virtual bool GetPaused() = 0;
55 :
56 : // Called by the video decoder object, on the main thread,
57 : // when it has read the metadata containing video dimensions,
58 : // etc.
59 : // Must take ownership of MetadataTags aTags argument.
60 : virtual void MetadataLoaded(const MediaInfo* aInfo,
61 : nsAutoPtr<const MetadataTags> aTags) = 0;
62 :
63 : // Called by the decoder object, on the main thread,
64 : // when it has read the first frame of the video or audio.
65 : virtual void FirstFrameLoaded() = 0;
66 :
67 : // Called by the decoder object, on the main thread,
68 : // when the resource has a network error during loading.
69 : // The decoder owner should call Shutdown() on the decoder and drop the
70 : // reference to the decoder to prevent further calls into the decoder.
71 : virtual void NetworkError() = 0;
72 :
73 : // Called by the decoder object, on the main thread, when the
74 : // resource has a decode error during metadata loading or decoding.
75 : // The decoder owner should call Shutdown() on the decoder and drop the
76 : // reference to the decoder to prevent further calls into the decoder.
77 : virtual void DecodeError(const MediaResult& aError) = 0;
78 :
79 : // Called by the decoder object, on the main thread, when the
80 : // resource has a decode issue during metadata loading or decoding, but can
81 : // continue decoding.
82 : virtual void DecodeWarning(const MediaResult& aError) = 0;
83 :
84 : // Return true if media element error attribute is not null.
85 : virtual bool HasError() const = 0;
86 :
87 : // Called by the video decoder object, on the main thread, when the
88 : // resource load has been cancelled.
89 : virtual void LoadAborted() = 0;
90 :
91 : // Called by the video decoder object, on the main thread,
92 : // when the video playback has ended.
93 : virtual void PlaybackEnded() = 0;
94 :
95 : // Called by the video decoder object, on the main thread,
96 : // when the resource has started seeking.
97 : virtual void SeekStarted() = 0;
98 :
99 : // Called by the video decoder object, on the main thread,
100 : // when the resource has completed seeking.
101 : virtual void SeekCompleted() = 0;
102 :
103 : // Called by the media stream, on the main thread, when the download
104 : // has been suspended by the cache or because the element itself
105 : // asked the decoder to suspend the download.
106 : virtual void DownloadSuspended() = 0;
107 :
108 : // Called by the media stream, on the main thread, when the download
109 : // has been resumed by the cache or because the element itself
110 : // asked the decoder to resumed the download.
111 : // If aForceNetworkLoading is True, ignore the fact that the download has
112 : // previously finished. We are downloading the middle of the media after
113 : // having downloaded the end, we need to notify the element a download in
114 : // ongoing.
115 : virtual void DownloadResumed(bool aForceNetworkLoading = false) = 0;
116 :
117 : // Called by the media decoder to indicate whether the media cache has
118 : // suspended the channel.
119 : virtual void NotifySuspendedByCache(bool aIsSuspended) = 0;
120 :
121 : // called to notify that the principal of the decoder's media resource has changed.
122 : virtual void NotifyDecoderPrincipalChanged() = 0;
123 :
124 : // The status of the next frame which might be available from the decoder
125 : enum NextFrameStatus {
126 : // The next frame of audio/video is available
127 : NEXT_FRAME_AVAILABLE,
128 : // The next frame of audio/video is unavailable because the decoder
129 : // is paused while it buffers up data
130 : NEXT_FRAME_UNAVAILABLE_BUFFERING,
131 : // The next frame of audio/video is unavailable for the decoder is seeking.
132 : NEXT_FRAME_UNAVAILABLE_SEEKING,
133 : // The next frame of audio/video is unavailable for some other reasons
134 : NEXT_FRAME_UNAVAILABLE,
135 : // Sentinel value
136 : NEXT_FRAME_UNINITIALIZED
137 : };
138 :
139 : // Check if the decoder owner is active.
140 : virtual bool IsActive() const = 0;
141 :
142 : // Check if the decoder owner is hidden.
143 : virtual bool IsHidden() const = 0;
144 :
145 : // Called by the media decoder and the video frame to get the
146 : // ImageContainer containing the video data.
147 : virtual VideoFrameContainer* GetVideoFrameContainer() = 0;
148 :
149 : // Called by media decoder when the audible state changed
150 : virtual void SetAudibleState(bool aAudible) = 0;
151 :
152 : // Notified by the decoder that XPCOM shutdown has begun.
153 : // The decoder owner should call Shutdown() on the decoder and drop the
154 : // reference to the decoder to prevent further calls into the decoder.
155 : virtual void NotifyXPCOMShutdown() = 0;
156 :
157 : // Dispatches a "encrypted" event to the HTMLMediaElement, with the
158 : // provided init data. Actual dispatch may be delayed until HAVE_METADATA.
159 : // Main thread only.
160 : virtual void DispatchEncrypted(const nsTArray<uint8_t>& aInitData,
161 : const nsAString& aInitDataType) = 0;
162 :
163 : // Return the decoder owner's owner document.
164 : virtual nsIDocument* GetDocument() const = 0;
165 :
166 : // Called by the media decoder to create audio/video tracks and add to its
167 : // owner's track list.
168 : virtual void ConstructMediaTracks(const MediaInfo* aInfo) = 0;
169 :
170 : // Called by the media decoder to removes all audio/video tracks from its
171 : // owner's track list.
172 : virtual void RemoveMediaTracks() = 0;
173 :
174 : // Called by the media decoder to create a GMPCrashHelper.
175 : virtual already_AddRefed<GMPCrashHelper> CreateGMPCrashHelper() = 0;
176 :
177 : // Called by the media decoder to notify the owner to resolve a seek promise.
178 : virtual void AsyncResolveSeekDOMPromiseIfExists() = 0;
179 :
180 : // Called by the media decoder to notify the owner to reject a seek promise.
181 : virtual void AsyncRejectSeekDOMPromiseIfExists() = 0;
182 : };
183 :
184 : } // namespace mozilla
185 :
186 : #endif
187 :
|