1/*
2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef HTMLMediaElement_h
27#define HTMLMediaElement_h
28
29#include "core/dom/ActiveDOMObject.h"
30#include "core/events/GenericEventQueue.h"
31#include "core/html/HTMLElement.h"
32#include "core/html/track/TextTrack.h"
33#include "core/html/track/TextTrackCue.h"
34#include "core/html/track/vtt/VTTCue.h"
35#include "platform/PODIntervalTree.h"
36#include "platform/Supplementable.h"
37#include "platform/graphics/media/MediaPlayer.h"
38#include "public/platform/WebMediaPlayerClient.h"
39#include "public/platform/WebMimeRegistry.h"
40
41namespace blink {
42class WebContentDecryptionModule;
43class WebInbandTextTrack;
44class WebLayer;
45}
46
47namespace blink {
48
49#if ENABLE(WEB_AUDIO)
50class AudioSourceProvider;
51class AudioSourceProviderClient;
52#endif
53class AudioTrackList;
54class ContentType;
55class Event;
56class ExceptionState;
57class HTMLSourceElement;
58class HTMLTrackElement;
59class KURL;
60class MediaController;
61class MediaControls;
62class MediaError;
63class HTMLMediaSource;
64class TextTrackList;
65class TimeRanges;
66class URLRegistry;
67class VideoTrackList;
68
69typedef PODIntervalTree<double, TextTrackCue*> CueIntervalTree;
70typedef CueIntervalTree::IntervalType CueInterval;
71typedef Vector<CueInterval> CueList;
72
73// FIXME: The inheritance from MediaPlayerClient here should be private inheritance.
74// But it can't be until the Chromium WebMediaPlayerClientImpl class is fixed so it
75// no longer depends on typecasting a MediaPlayerClient to an HTMLMediaElement.
76
77class HTMLMediaElement : public HTMLElement, public WillBeHeapSupplementable<HTMLMediaElement>, public MediaPlayerClient, public ActiveDOMObject {
78    DEFINE_WRAPPERTYPEINFO();
79    WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(HTMLMediaElement);
80public:
81    static blink::WebMimeRegistry::SupportsType supportsType(const ContentType&, const String& keySystem = String());
82
83    static void setMediaStreamRegistry(URLRegistry*);
84    static bool isMediaStreamURL(const String& url);
85
86    virtual void trace(Visitor*) OVERRIDE;
87#if ENABLE(WEB_AUDIO)
88    void clearWeakMembers(Visitor*);
89#endif
90    blink::WebMediaPlayer* webMediaPlayer() const { return m_player ? m_player->webMediaPlayer() : 0; }
91
92    virtual bool hasVideo() const { return false; }
93    bool hasAudio() const;
94
95    bool supportsSave() const;
96
97    blink::WebLayer* platformLayer() const;
98
99    enum DelayedActionType {
100        LoadMediaResource = 1 << 0,
101        LoadTextTrackResource = 1 << 1,
102        TextTrackChangesNotification = 1 << 2
103    };
104    void scheduleDelayedAction(DelayedActionType);
105
106    bool isActive() const { return m_active; }
107
108    bool hasRemoteRoutes() const { return m_remoteRoutesAvailable; }
109    bool isPlayingRemotely() const { return m_playingRemotely; }
110
111    // error state
112    PassRefPtrWillBeRawPtr<MediaError> error() const;
113
114    // network state
115    void setSrc(const AtomicString&);
116    const KURL& currentSrc() const { return m_currentSrc; }
117
118    enum NetworkState { NETWORK_EMPTY, NETWORK_IDLE, NETWORK_LOADING, NETWORK_NO_SOURCE };
119    NetworkState networkState() const;
120
121    String preload() const;
122    void setPreload(const AtomicString&);
123
124    PassRefPtrWillBeRawPtr<TimeRanges> buffered() const;
125    void load();
126    String canPlayType(const String& mimeType, const String& keySystem = String()) const;
127
128    // ready state
129    enum ReadyState { HAVE_NOTHING, HAVE_METADATA, HAVE_CURRENT_DATA, HAVE_FUTURE_DATA, HAVE_ENOUGH_DATA };
130    ReadyState readyState() const;
131    bool seeking() const;
132
133    // playback state
134    double currentTime() const;
135    void setCurrentTime(double, ExceptionState&);
136    double duration() const;
137    bool paused() const;
138    double defaultPlaybackRate() const;
139    void setDefaultPlaybackRate(double);
140    double playbackRate() const;
141    void setPlaybackRate(double);
142    void updatePlaybackRate();
143    PassRefPtrWillBeRawPtr<TimeRanges> played();
144    PassRefPtrWillBeRawPtr<TimeRanges> seekable() const;
145    bool ended() const;
146    bool autoplay() const;
147    bool loop() const;
148    void setLoop(bool);
149    void play();
150    void pause();
151    void requestRemotePlayback();
152    void requestRemotePlaybackControl();
153
154    // statistics
155    unsigned webkitAudioDecodedByteCount() const;
156    unsigned webkitVideoDecodedByteCount() const;
157
158    // media source extensions
159    void closeMediaSource();
160    void durationChanged(double duration, bool requestSeek);
161
162    // controls
163    bool shouldShowControls() const;
164    double volume() const;
165    void setVolume(double, ExceptionState&);
166    bool muted() const;
167    void setMuted(bool);
168
169    // play/pause toggling that uses the media controller if present. togglePlayStateWillPlay() is
170    // true if togglePlayState() will call play() or unpause() on the media element or controller.
171    bool togglePlayStateWillPlay() const;
172    void togglePlayState();
173
174    AudioTrackList& audioTracks();
175    void audioTrackChanged();
176
177    VideoTrackList& videoTracks();
178    void selectedVideoTrackChanged(blink::WebMediaPlayer::TrackId*);
179
180    PassRefPtrWillBeRawPtr<TextTrack> addTextTrack(const AtomicString& kind, const AtomicString& label, const AtomicString& language, ExceptionState&);
181    PassRefPtrWillBeRawPtr<TextTrack> addTextTrack(const AtomicString& kind, const AtomicString& label, ExceptionState& exceptionState) { return addTextTrack(kind, label, emptyAtom, exceptionState); }
182    PassRefPtrWillBeRawPtr<TextTrack> addTextTrack(const AtomicString& kind, ExceptionState& exceptionState) { return addTextTrack(kind, emptyAtom, emptyAtom, exceptionState); }
183
184    TextTrackList* textTracks();
185    CueList currentlyActiveCues() const { return m_currentlyActiveCues; }
186
187    void addTextTrack(TextTrack*);
188    void removeTextTrack(TextTrack*);
189    void textTracksChanged();
190    void notifyMediaPlayerOfTextTrackChanges();
191
192    // Implements the "forget the media element's media-resource-specific tracks" algorithm in the HTML5 spec.
193    void forgetResourceSpecificTracks();
194
195    void didAddTrackElement(HTMLTrackElement*);
196    void didRemoveTrackElement(HTMLTrackElement*);
197
198    blink::WebMediaPlayer::TrackId addAudioTrack(const String& id, blink::WebMediaPlayerClient::AudioTrackKind, const AtomicString& label, const AtomicString& language, bool enabled);
199    void removeAudioTrack(blink::WebMediaPlayer::TrackId);
200    blink::WebMediaPlayer::TrackId addVideoTrack(const String& id, blink::WebMediaPlayerClient::VideoTrackKind, const AtomicString& label, const AtomicString& language, bool selected);
201    void removeVideoTrack(blink::WebMediaPlayer::TrackId);
202
203    virtual void mediaPlayerDidAddTextTrack(blink::WebInbandTextTrack*) OVERRIDE FINAL;
204    virtual void mediaPlayerDidRemoveTextTrack(blink::WebInbandTextTrack*) OVERRIDE FINAL;
205    // FIXME: Remove this when WebMediaPlayerClientImpl::loadInternal does not depend on it.
206    virtual KURL mediaPlayerPosterURL() OVERRIDE { return KURL(); }
207
208    class TrackGroup {
209        STACK_ALLOCATED();
210    public:
211        enum GroupKind { CaptionsAndSubtitles, Description, Chapter, Metadata, Other };
212
213        explicit TrackGroup(GroupKind kind)
214            : visibleTrack(nullptr)
215            , defaultTrack(nullptr)
216            , kind(kind)
217            , hasSrcLang(false)
218        {
219        }
220
221        WillBeHeapVector<RefPtrWillBeMember<TextTrack> > tracks;
222        RefPtrWillBeMember<TextTrack> visibleTrack;
223        RefPtrWillBeMember<TextTrack> defaultTrack;
224        GroupKind kind;
225        bool hasSrcLang;
226    };
227
228    void configureTextTrackGroupForLanguage(const TrackGroup&) const;
229    void configureTextTracks();
230    void configureTextTrackGroup(const TrackGroup&);
231
232    bool textTracksAreReady() const;
233    enum VisibilityChangeAssumption {
234        AssumeNoVisibleChange,
235        AssumeVisibleChange
236    };
237    void configureTextTrackDisplay(VisibilityChangeAssumption);
238    void updateTextTrackDisplay();
239    void textTrackReadyStateChanged(TextTrack*);
240
241    void textTrackKindChanged(TextTrack*);
242    void textTrackModeChanged(TextTrack*);
243    void textTrackAddCues(TextTrack*, const TextTrackCueList*);
244    void textTrackRemoveCues(TextTrack*, const TextTrackCueList*);
245    void textTrackAddCue(TextTrack*, PassRefPtrWillBeRawPtr<TextTrackCue>);
246    void textTrackRemoveCue(TextTrack*, PassRefPtrWillBeRawPtr<TextTrackCue>);
247
248    // EventTarget function.
249    // Both Node (via HTMLElement) and ActiveDOMObject define this method, which
250    // causes an ambiguity error at compile time. This class's constructor
251    // ensures that both implementations return document, so return the result
252    // of one of them here.
253    using HTMLElement::executionContext;
254
255    bool hasSingleSecurityOrigin() const { return !m_player || (webMediaPlayer() && webMediaPlayer()->hasSingleSecurityOrigin()); }
256
257    bool isFullscreen() const;
258    void enterFullscreen();
259    void exitFullscreen();
260
261    bool hasClosedCaptions() const;
262    bool closedCaptionsVisible() const;
263    void setClosedCaptionsVisible(bool);
264
265    void remoteRouteAvailabilityChanged(bool);
266    void connectedToRemoteDevice();
267    void disconnectedFromRemoteDevice();
268
269    MediaControls* mediaControls() const;
270
271    void sourceWasRemoved(HTMLSourceElement*);
272    void sourceWasAdded(HTMLSourceElement*);
273
274    // ActiveDOMObject functions.
275    virtual bool hasPendingActivity() const OVERRIDE FINAL;
276    virtual void contextDestroyed() OVERRIDE FINAL;
277
278#if ENABLE(WEB_AUDIO)
279    AudioSourceProviderClient* audioSourceNode() { return m_audioSourceNode; }
280    void setAudioSourceNode(AudioSourceProviderClient*);
281
282    AudioSourceProvider* audioSourceProvider();
283#endif
284
285    enum InvalidURLAction { DoNothing, Complain };
286    bool isSafeToLoadURL(const KURL&, InvalidURLAction);
287
288    MediaController* controller() const;
289    void setController(PassRefPtrWillBeRawPtr<MediaController>); // Resets the MediaGroup and sets the MediaController.
290
291    void scheduleEvent(PassRefPtrWillBeRawPtr<Event>);
292
293    // Returns the "effective media volume" value as specified in the HTML5 spec.
294    double effectiveMediaVolume() const;
295
296#if ENABLE(OILPAN)
297    bool isFinalizing() const { return m_isFinalizing; }
298
299    // Oilpan: finalization of the media element is observable from its
300    // attached MediaSource; it entering a closed state.
301    //
302    // Express that by having the MediaSource keep a weak reference
303    // to the media element and signal that it wants to be notified
304    // of destruction if it survives a GC, but the media element
305    // doesn't.
306    void setCloseMediaSourceWhenFinalizing();
307#endif
308
309    // Predicates also used when dispatching wrapper creation (cf. [SpecialWrapFor] IDL attribute usage.)
310    virtual bool isHTMLAudioElement() const { return false; }
311    virtual bool isHTMLVideoElement() const { return false; }
312
313protected:
314    HTMLMediaElement(const QualifiedName&, Document&);
315    virtual ~HTMLMediaElement();
316
317    virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
318    virtual void finishParsingChildren() OVERRIDE FINAL;
319    virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
320    virtual void attach(const AttachContext& = AttachContext()) OVERRIDE;
321
322    virtual void didMoveToNewDocument(Document& oldDocument) OVERRIDE;
323
324    enum DisplayMode { Unknown, Poster, PosterWaitingForVideo, Video };
325    DisplayMode displayMode() const { return m_displayMode; }
326    virtual void setDisplayMode(DisplayMode mode) { m_displayMode = mode; }
327
328    void setControllerInternal(PassRefPtrWillBeRawPtr<MediaController>);
329
330    bool ignoreTrackDisplayUpdateRequests() const { return m_ignoreTrackDisplayUpdate > 0; }
331    void beginIgnoringTrackDisplayUpdateRequests();
332    void endIgnoringTrackDisplayUpdateRequests();
333
334private:
335    void createMediaPlayer();
336
337    virtual bool alwaysCreateUserAgentShadowRoot() const OVERRIDE FINAL { return true; }
338    virtual bool areAuthorShadowsAllowed() const OVERRIDE FINAL { return false; }
339
340    virtual bool supportsFocus() const OVERRIDE FINAL;
341    virtual bool isMouseFocusable() const OVERRIDE FINAL;
342    virtual bool rendererIsNeeded(const RenderStyle&) OVERRIDE;
343    virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
344    virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE FINAL;
345    virtual void didNotifySubtreeInsertionsToDocument() OVERRIDE;
346    virtual void removedFrom(ContainerNode*) OVERRIDE FINAL;
347    virtual void didRecalcStyle(StyleRecalcChange) OVERRIDE FINAL;
348
349    virtual void didBecomeFullscreenElement() OVERRIDE FINAL;
350    virtual void willStopBeingFullscreenElement() OVERRIDE FINAL;
351    virtual bool isInteractiveContent() const OVERRIDE FINAL;
352    virtual void defaultEventHandler(Event*) OVERRIDE FINAL;
353
354    // ActiveDOMObject functions.
355    virtual void stop() OVERRIDE FINAL;
356
357    virtual void updateDisplayState() { }
358
359    void setReadyState(ReadyState);
360    void setNetworkState(blink::WebMediaPlayer::NetworkState);
361
362    virtual void mediaPlayerNetworkStateChanged() OVERRIDE FINAL;
363    virtual void mediaPlayerReadyStateChanged() OVERRIDE FINAL;
364    virtual void mediaPlayerTimeChanged() OVERRIDE FINAL;
365    virtual void mediaPlayerDurationChanged() OVERRIDE FINAL;
366    virtual void mediaPlayerPlaybackStateChanged() OVERRIDE FINAL;
367    virtual void mediaPlayerRequestFullscreen() OVERRIDE FINAL;
368    virtual void mediaPlayerRequestSeek(double) OVERRIDE FINAL;
369    virtual void mediaPlayerRepaint() OVERRIDE FINAL;
370    virtual void mediaPlayerSizeChanged() OVERRIDE FINAL;
371    virtual void mediaPlayerSetWebLayer(blink::WebLayer*) OVERRIDE FINAL;
372    virtual void mediaPlayerMediaSourceOpened(blink::WebMediaSource*) OVERRIDE FINAL;
373
374    void loadTimerFired(Timer<HTMLMediaElement>*);
375    void progressEventTimerFired(Timer<HTMLMediaElement>*);
376    void playbackProgressTimerFired(Timer<HTMLMediaElement>*);
377    void startPlaybackProgressTimer();
378    void startProgressEventTimer();
379    void stopPeriodicTimers();
380
381    void seek(double time);
382    void finishSeek();
383    void checkIfSeekNeeded();
384    void addPlayedRange(double start, double end);
385
386    void scheduleTimeupdateEvent(bool periodicEvent);
387    void scheduleEvent(const AtomicString& eventName); // FIXME: Rename to scheduleNamedEvent for clarity.
388
389    // loading
390    void prepareForLoad();
391    void loadInternal();
392    void selectMediaResource();
393    void loadResource(const KURL&, ContentType&, const String& keySystem);
394    void startPlayerLoad();
395    void setPlayerPreload();
396    blink::WebMediaPlayer::LoadType loadType() const;
397    void scheduleNextSourceChild();
398    void loadNextSourceChild();
399    void userCancelledLoad();
400    void clearMediaPlayer(int flags);
401    void clearMediaPlayerAndAudioSourceProviderClientWithoutLocking();
402    bool havePotentialSourceChild();
403    void noneSupported();
404    void mediaEngineError(PassRefPtrWillBeRawPtr<MediaError>);
405    void cancelPendingEventsAndCallbacks();
406    void waitForSourceChange();
407    void prepareToPlay();
408
409    KURL selectNextSourceChild(ContentType*, String* keySystem, InvalidURLAction);
410
411    void mediaLoadingFailed(blink::WebMediaPlayer::NetworkState);
412
413    // deferred loading (preload=none)
414    bool loadIsDeferred() const;
415    void deferLoad();
416    void cancelDeferredLoad();
417    void startDeferredLoad();
418    void executeDeferredLoad();
419    void deferredLoadTimerFired(Timer<HTMLMediaElement>*);
420
421    void updateActiveTextTrackCues(double);
422    HTMLTrackElement* showingTrackWithSameKind(HTMLTrackElement*) const;
423
424    void markCaptionAndSubtitleTracksAsUnconfigured();
425
426    // This does not check user gesture restrictions.
427    void playInternal();
428
429    void allowVideoRendering();
430
431    void updateVolume();
432    void updatePlayState();
433    bool potentiallyPlaying() const;
434    bool endedPlayback() const;
435    bool stoppedDueToErrors() const;
436    bool couldPlayIfEnoughData() const;
437
438    void setShouldDelayLoadEvent(bool);
439    void invalidateCachedTime();
440    void refreshCachedTime() const;
441
442    bool hasMediaControls() const;
443    bool createMediaControls();
444    void configureMediaControls();
445
446    virtual void* preDispatchEventHandler(Event*) OVERRIDE FINAL;
447
448    void changeNetworkStateFromLoadingToIdle();
449
450    const AtomicString& mediaGroup() const;
451    void setMediaGroup(const AtomicString&);
452    void updateMediaController();
453    bool isBlocked() const;
454    bool isBlockedOnMediaController() const;
455    bool isAutoplaying() const { return m_autoplaying; }
456
457    blink::WebMediaPlayer::CORSMode corsMode() const;
458
459    // Returns the "direction of playback" value as specified in the HTML5 spec.
460    enum DirectionOfPlayback { Backward, Forward };
461    DirectionOfPlayback directionOfPlayback() const;
462
463    // Returns the "effective playback rate" value as specified in the HTML5 spec.
464    double effectivePlaybackRate() const;
465
466    // Creates placeholder AudioTrack and/or VideoTrack objects when WebMemediaPlayer objects
467    // advertise they have audio and/or video, but don't explicitly signal them via
468    // addAudioTrack() and addVideoTrack().
469    // FIXME: Remove this once all WebMediaPlayer implementations properly report their track info.
470    void createPlaceholderTracksIfNecessary();
471
472    // Sets the selected/enabled tracks if they aren't set before we initially
473    // transition to HAVE_METADATA.
474    void selectInitialTracksIfNecessary();
475
476    void audioTracksTimerFired(Timer<HTMLMediaElement>*);
477
478    Timer<HTMLMediaElement> m_loadTimer;
479    Timer<HTMLMediaElement> m_progressEventTimer;
480    Timer<HTMLMediaElement> m_playbackProgressTimer;
481    Timer<HTMLMediaElement> m_audioTracksTimer;
482    RefPtrWillBeMember<TimeRanges> m_playedTimeRanges;
483    OwnPtrWillBeMember<GenericEventQueue> m_asyncEventQueue;
484
485    double m_playbackRate;
486    double m_defaultPlaybackRate;
487    NetworkState m_networkState;
488    ReadyState m_readyState;
489    ReadyState m_readyStateMaximum;
490    KURL m_currentSrc;
491
492    RefPtrWillBeMember<MediaError> m_error;
493
494    double m_volume;
495    double m_lastSeekTime;
496
497    double m_previousProgressTime;
498
499    // Cached duration to suppress duplicate events if duration unchanged.
500    double m_duration;
501
502    // The last time a timeupdate event was sent (wall clock).
503    double m_lastTimeUpdateEventWallTime;
504
505    // The last time a timeupdate event was sent in movie time.
506    double m_lastTimeUpdateEventMovieTime;
507
508    // The default playback start position.
509    double m_defaultPlaybackStartPosition;
510
511    // Loading state.
512    enum LoadState { WaitingForSource, LoadingFromSrcAttr, LoadingFromSourceElement };
513    LoadState m_loadState;
514    RefPtrWillBeMember<HTMLSourceElement> m_currentSourceNode;
515    RefPtrWillBeMember<Node> m_nextChildNodeToConsider;
516
517    // "Deferred loading" state (for preload=none).
518    enum DeferredLoadState {
519        // The load is not deferred.
520        NotDeferred,
521        // The load is deferred, and waiting for the task to set the
522        // delaying-the-load-event flag (to false).
523        WaitingForStopDelayingLoadEventTask,
524        // The load is the deferred, and waiting for a triggering event.
525        WaitingForTrigger,
526        // The load is deferred, and waiting for the task to set the
527        // delaying-the-load-event flag, after which the load will be executed.
528        ExecuteOnStopDelayingLoadEventTask
529    };
530    DeferredLoadState m_deferredLoadState;
531    Timer<HTMLMediaElement> m_deferredLoadTimer;
532
533    OwnPtr<MediaPlayer> m_player;
534    blink::WebLayer* m_webLayer;
535
536    MediaPlayer::Preload m_preload;
537
538    DisplayMode m_displayMode;
539
540    RefPtrWillBeMember<HTMLMediaSource> m_mediaSource;
541
542    // Cached time value. Only valid when ready state is HAVE_METADATA or
543    // higher, otherwise the current time is assumed to be zero.
544    mutable double m_cachedTime;
545
546    double m_fragmentEndTime;
547
548    typedef unsigned PendingActionFlags;
549    PendingActionFlags m_pendingActionFlags;
550
551    // FIXME: MediaElement has way too many state bits.
552    bool m_userGestureRequiredForPlay : 1;
553    bool m_playing : 1;
554    bool m_shouldDelayLoadEvent : 1;
555    bool m_haveFiredLoadedData : 1;
556    bool m_active : 1;
557    bool m_autoplaying : 1;
558    bool m_muted : 1;
559    bool m_paused : 1;
560    bool m_seeking : 1;
561
562    // data has not been loaded since sending a "stalled" event
563    bool m_sentStalledEvent : 1;
564
565    // time has not changed since sending an "ended" event
566    bool m_sentEndEvent : 1;
567
568    bool m_closedCaptionsVisible : 1;
569
570    bool m_completelyLoaded : 1;
571    bool m_havePreparedToPlay : 1;
572    bool m_delayingLoadForPreloadNone : 1;
573
574    bool m_tracksAreReady : 1;
575    bool m_haveVisibleTextTrack : 1;
576    bool m_processingPreferenceChange : 1;
577    bool m_remoteRoutesAvailable : 1;
578    bool m_playingRemotely : 1;
579#if ENABLE(OILPAN)
580    bool m_isFinalizing : 1;
581    bool m_closeMediaSourceWhenFinalizing : 1;
582#endif
583    double m_lastTextTrackUpdateTime;
584
585    RefPtrWillBeMember<AudioTrackList> m_audioTracks;
586    RefPtrWillBeMember<VideoTrackList> m_videoTracks;
587    RefPtrWillBeMember<TextTrackList> m_textTracks;
588    WillBeHeapVector<RefPtrWillBeMember<TextTrack> > m_textTracksWhenResourceSelectionBegan;
589
590    CueIntervalTree m_cueTree;
591
592    CueList m_currentlyActiveCues;
593    int m_ignoreTrackDisplayUpdate;
594
595#if ENABLE(WEB_AUDIO)
596    // This is a weak reference, since m_audioSourceNode holds a reference to us.
597    // FIXME: Oilpan: Consider making this a strongly traced pointer with oilpan where strong cycles are not a problem.
598    GC_PLUGIN_IGNORE("http://crbug.com/404577")
599    RawPtrWillBeWeakMember<AudioSourceProviderClient> m_audioSourceNode;
600#endif
601
602    friend class MediaController;
603    RefPtrWillBeMember<MediaController> m_mediaController;
604
605    friend class Internals;
606    friend class TrackDisplayUpdateScope;
607
608    static URLRegistry* s_mediaStreamRegistry;
609};
610
611#ifndef NDEBUG
612// Template specializations required by PodIntervalTree in debug mode.
613template <>
614struct ValueToString<double> {
615    static String string(const double value)
616    {
617        return String::number(value);
618    }
619};
620
621template <>
622struct ValueToString<TextTrackCue*> {
623    static String string(TextTrackCue* const& cue)
624    {
625        return cue->toString();
626    }
627};
628#endif
629
630inline bool isHTMLMediaElement(const HTMLElement& element)
631{
632    return isHTMLAudioElement(element) || isHTMLVideoElement(element);
633}
634
635DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLMediaElement);
636
637} // namespace blink
638
639#endif // HTMLMediaElement_h
640