summaryrefslogtreecommitdiffstats
path: root/WebCore/html/HTMLMediaElement.h
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/html/HTMLMediaElement.h')
-rw-r--r--WebCore/html/HTMLMediaElement.h184
1 files changed, 126 insertions, 58 deletions
diff --git a/WebCore/html/HTMLMediaElement.h b/WebCore/html/HTMLMediaElement.h
index 6dd562c..ab0ab11 100644
--- a/WebCore/html/HTMLMediaElement.h
+++ b/WebCore/html/HTMLMediaElement.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -31,13 +31,17 @@
#include "HTMLElement.h"
#include "MediaPlayer.h"
#include "Timer.h"
-#include "VoidCallback.h"
+
+#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
+#include "MediaPlayerProxy.h"
+#endif
namespace WebCore {
+class Event;
class MediaError;
-class TimeRanges;
class KURL;
+class TimeRanges;
class HTMLMediaElement : public HTMLElement, public MediaPlayerClient {
public:
@@ -58,6 +62,7 @@ public:
MediaPlayer* player() const { return m_player.get(); }
virtual bool isVideo() const { return false; }
+ virtual bool hasVideo() const { return false; }
void scheduleLoad();
@@ -76,15 +81,16 @@ public:
KURL src() const;
void setSrc(const String&);
String currentSrc() const;
-
- enum NetworkState { EMPTY, LOADING, LOADED_METADATA, LOADED_FIRST_FRAME, LOADED };
+
+ enum NetworkState { NETWORK_EMPTY, NETWORK_IDLE, NETWORK_LOADING, NETWORK_LOADED, NETWORK_NO_SOURCE };
NetworkState networkState() const;
- float bufferingRate();
PassRefPtr<TimeRanges> buffered() const;
void load(ExceptionCode&);
+
+ String canPlayType(const String& mimeType) const;
// ready state
- enum ReadyState { DATA_UNAVAILABLE, CAN_SHOW_CURRENT_FRAME, CAN_PLAY, CAN_PLAY_THROUGH };
+ enum ReadyState { HAVE_NOTHING, HAVE_METADATA, HAVE_CURRENT_DATA, HAVE_FUTURE_DATA, HAVE_ENOUGH_DATA };
ReadyState readyState() const;
bool seeking() const;
@@ -94,31 +100,19 @@ public:
float duration() const;
bool paused() const;
float defaultPlaybackRate() const;
- void setDefaultPlaybackRate(float, ExceptionCode&);
+ void setDefaultPlaybackRate(float);
float playbackRate() const;
- void setPlaybackRate(float, ExceptionCode&);
+ void setPlaybackRate(float);
PassRefPtr<TimeRanges> played() const;
PassRefPtr<TimeRanges> seekable() const;
bool ended() const;
bool autoplay() const;
void setAutoplay(bool b);
- void play(ExceptionCode&);
- void pause(ExceptionCode&);
-
-// looping
- float start() const;
- void setStart(float time);
- float end() const;
- void setEnd(float time);
- float loopStart() const;
- void setLoopStart(float time);
- float loopEnd() const;
- void setLoopEnd(float time);
- unsigned playCount() const;
- void setPlayCount(unsigned, ExceptionCode&);
- unsigned currentLoop() const;
- void setCurrentLoop(unsigned);
-
+ bool loop() const;
+ void setLoop(bool b);
+ void play();
+ void pause();
+
// controls
bool controls() const;
void setControls(bool);
@@ -126,9 +120,20 @@ public:
void setVolume(float, ExceptionCode&);
bool muted() const;
void setMuted(bool);
+ void togglePlayState();
+ void beginScrubbing();
+ void endScrubbing();
bool canPlay() const;
+#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
+ void setNeedWidgetUpdate(bool needWidgetUpdate) { m_needWidgetUpdate = needWidgetUpdate; }
+ void deliverNotification(MediaPlayerProxyNotificationType notification);
+ void setMediaPlayerProxy(WebMediaPlayerProxy* proxy);
+ String initialURL();
+ virtual void finishParsingChildren();
+#endif
+
protected:
float getTimeOffsetAttribute(const QualifiedName&, float valueOnError) const;
void setTimeOffsetAttribute(const QualifiedName&, float value);
@@ -137,73 +142,136 @@ protected:
virtual void documentDidBecomeActive();
virtual void mediaVolumeDidChange();
- void initAndDispatchProgressEvent(const AtomicString& eventName);
- void dispatchEventAsync(const AtomicString& eventName);
-
- void setReadyState(ReadyState);
+ void setReadyState(MediaPlayer::ReadyState);
+ void setNetworkState(MediaPlayer::NetworkState);
private: // MediaPlayerObserver
virtual void mediaPlayerNetworkStateChanged(MediaPlayer*);
virtual void mediaPlayerReadyStateChanged(MediaPlayer*);
virtual void mediaPlayerTimeChanged(MediaPlayer*);
virtual void mediaPlayerRepaint(MediaPlayer*);
+ virtual void mediaPlayerVolumeChanged(MediaPlayer*);
+ virtual void mediaPlayerDurationChanged(MediaPlayer*);
+ virtual void mediaPlayerRateChanged(MediaPlayer*);
+ virtual void mediaPlayerSizeChanged(MediaPlayer*);
private:
void loadTimerFired(Timer<HTMLMediaElement>*);
void asyncEventTimerFired(Timer<HTMLMediaElement>*);
void progressEventTimerFired(Timer<HTMLMediaElement>*);
- void seek(float time, ExceptionCode& ec);
+ void playbackProgressTimerFired(Timer<HTMLMediaElement>*);
+ void startPlaybackProgressTimer();
+ void startProgressEventTimer();
+ void stopPeriodicTimers();
+
+ void seek(float time, ExceptionCode&);
void checkIfSeekNeeded();
- String pickMedia();
+ void scheduleTimeupdateEvent(bool periodicEvent);
+ void scheduleProgressEvent(const AtomicString& eventName);
+ void scheduleEvent(const AtomicString& eventName);
+ void enqueueEvent(RefPtr<Event> event);
+
+ // loading
+ void selectMediaResource();
+ void loadResource(String url, ContentType& contentType);
+ void loadNextSourceChild();
+ void userCancelledLoad();
+ String nextSourceChild(ContentType* contentType = 0);
+ bool havePotentialSourceChild();
+ void noneSupported();
+ void mediaEngineError(PassRefPtr<MediaError> err);
+
+ // These "internal" functions do not check user gesture restrictions.
+ void loadInternal();
+ void playInternal();
+ void pauseInternal();
+
+ bool processingUserGesture() const;
+ bool processingMediaPlayerCallback() const { return m_processingMediaPlayerCallback > 0; }
+ void beginProcessingMediaPlayerCallback() { ++m_processingMediaPlayerCallback; }
+ void endProcessingMediaPlayerCallback() { ASSERT(m_processingMediaPlayerCallback); --m_processingMediaPlayerCallback; }
+
void updateVolume();
void updatePlayState();
- float effectiveStart() const;
- float effectiveEnd() const;
- float effectiveLoopStart() const;
- float effectiveLoopEnd() const;
- bool activelyPlaying() const;
+ bool potentiallyPlaying() const;
bool endedPlayback() const;
-
+ bool stoppedDueToErrors() const;
+ bool pausedForUserInteraction() const;
+
+ // Restrictions to change default behaviors. This is a effectively a compile time choice at the moment
+ // because there are no accessor methods.
+ enum BehaviorRestrictions
+ {
+ NoRestrictions = 0,
+ RequireUserGestureForLoadRestriction = 1 << 0,
+ RequireUserGestureForRateChangeRestriction = 1 << 1,
+ };
+
protected:
Timer<HTMLMediaElement> m_loadTimer;
Timer<HTMLMediaElement> m_asyncEventTimer;
Timer<HTMLMediaElement> m_progressEventTimer;
- Vector<AtomicString> m_asyncEventsToDispatch;
+ Timer<HTMLMediaElement> m_playbackProgressTimer;
+ Vector<RefPtr<Event> > m_pendingEvents;
+ float m_playbackRate;
float m_defaultPlaybackRate;
NetworkState m_networkState;
ReadyState m_readyState;
String m_currentSrc;
RefPtr<MediaError> m_error;
-
- bool m_begun;
- bool m_loadedFirstFrame;
- bool m_autoplaying;
-
- unsigned m_currentLoop;
+
float m_volume;
- bool m_muted;
-
- bool m_paused;
- bool m_seeking;
-
float m_currentTimeDuringSeek;
unsigned m_previousProgress;
double m_previousProgressTime;
- bool m_sentStalledEvent;
-
- float m_bufferingRate;
+
+ // the last time a timeupdate event was sent (wall clock)
+ double m_lastTimeUpdateEventWallTime;
+
+ // the last time a timeupdate event was sent in movie time
+ float m_lastTimeUpdateEventMovieTime;
- unsigned m_loadNestingLevel;
- unsigned m_terminateLoadBelowNestingLevel;
+ // loading state
+ enum LoadState { WaitingForSource, LoadingFromSrcAttr, LoadingFromSourceElement };
+ LoadState m_loadState;
+ Node *m_currentSourceNode;
- bool m_pausedInternal;
- bool m_inActiveDocument;
-
OwnPtr<MediaPlayer> m_player;
+
+ BehaviorRestrictions m_restrictions;
+
+ // counter incremented while processing a callback from the media player, so we can avoid
+ // calling the media engine recursively
+ int m_processingMediaPlayerCallback;
+
+ bool m_processingLoad : 1;
+ bool m_delayingTheLoadEvent : 1;
+ bool m_haveFiredLoadedData : 1;
+ bool m_inActiveDocument : 1;
+ bool m_autoplaying : 1;
+ bool m_muted : 1;
+ bool m_paused : 1;
+ bool m_seeking : 1;
+
+ // data has not been loaded since sending a "stalled" event
+ bool m_sentStalledEvent : 1;
+
+ // time has not changed since sending an "ended" event
+ bool m_sentEndEvent : 1;
+
+ bool m_pausedInternal : 1;
+
+ // Not all media engines provide enough information about a file to be able to
+ // support progress events so setting m_sendProgressEvents disables them
+ bool m_sendProgressEvents : 1;
+
+#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
+ bool m_needWidgetUpdate : 1;
+#endif
};
} //namespace