#ifndef MediaPlayer_h
#define MediaPlayer_h
#if ENABLE(VIDEO)
#include "GraphicsTypes3D.h"
#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
#include "MediaPlayerProxy.h"
#endif
#include "AudioTrackPrivate.h"
#include "InbandTextTrackPrivate.h"
#include "IntRect.h"
#include "KURL.h"
#include "LayoutRect.h"
#include "Timer.h"
#include "VideoTrackPrivate.h"
#include <wtf/Forward.h>
#include <wtf/HashSet.h>
#include <wtf/OwnPtr.h>
#include <wtf/Noncopyable.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/text/StringHash.h>
#if USE(ACCELERATED_COMPOSITING)
#include "PlatformLayer.h"
#endif
#if USE(PLATFORM_TEXT_TRACK_MENU)
#include "PlatformTextTrackMenu.h"
#endif
OBJC_CLASS AVPlayer;
OBJC_CLASS QTMovie;
class AVCFPlayer;
class QTMovieGWorld;
class QTMovieVisualContext;
namespace WebCore {
class AudioSourceProvider;
class Document;
class GStreamerGWorld;
class MediaPlayerPrivateInterface;
#if ENABLE(MEDIA_SOURCE)
class MediaSource;
#endif
class TextTrackRepresentation;
struct PlatformMedia {
enum {
None,
QTMovieType,
QTMovieGWorldType,
QTMovieVisualContextType,
GStreamerGWorldType,
ChromiumMediaPlayerType,
QtMediaPlayerType,
AVFoundationMediaPlayerType,
AVFoundationCFMediaPlayerType
} type;
union {
QTMovie* qtMovie;
QTMovieGWorld* qtMovieGWorld;
QTMovieVisualContext* qtMovieVisualContext;
GStreamerGWorld* gstreamerGWorld;
MediaPlayerPrivateInterface* chromiumMediaPlayer;
MediaPlayerPrivateInterface* qtMediaPlayer;
AVPlayer* avfMediaPlayer;
AVCFPlayer* avcfMediaPlayer;
} media;
};
extern const PlatformMedia NoPlatformMedia;
class CachedResourceLoader;
class ContentType;
class FrameView;
class GraphicsContext;
class GraphicsContext3D;
class IntRect;
class IntSize;
class MediaPlayer;
struct MediaPlayerFactory;
class TimeRanges;
class HostWindow;
#if PLATFORM(WIN) && USE(AVFOUNDATION)
struct GraphicsDeviceAdapter;
#endif
class MediaPlayerClient {
public:
enum CORSMode { Unspecified, Anonymous, UseCredentials };
virtual ~MediaPlayerClient() { }
virtual Document* mediaPlayerOwningDocument() { return 0; }
virtual void mediaPlayerNetworkStateChanged(MediaPlayer*) { }
virtual void mediaPlayerReadyStateChanged(MediaPlayer*) { }
virtual void mediaPlayerVolumeChanged(MediaPlayer*) { }
virtual void mediaPlayerMuteChanged(MediaPlayer*) { }
virtual void mediaPlayerTimeChanged(MediaPlayer*) { }
virtual void mediaPlayerDurationChanged(MediaPlayer*) { }
virtual void mediaPlayerRateChanged(MediaPlayer*) { }
virtual void mediaPlayerPlaybackStateChanged(MediaPlayer*) { }
virtual void mediaPlayerSawUnsupportedTracks(MediaPlayer*) { }
virtual void mediaPlayerResourceNotSupported(MediaPlayer*) { }
virtual void mediaPlayerRepaint(MediaPlayer*) { }
virtual void mediaPlayerSizeChanged(MediaPlayer*) { }
virtual void mediaPlayerEngineUpdated(MediaPlayer*) { }
virtual void mediaPlayerFirstVideoFrameAvailable(MediaPlayer*) { }
virtual void mediaPlayerCharacteristicChanged(MediaPlayer*) { }
#if USE(ACCELERATED_COMPOSITING)
virtual bool mediaPlayerRenderingCanBeAccelerated(MediaPlayer*) { return false; }
virtual void mediaPlayerRenderingModeChanged(MediaPlayer*) { }
#endif
#if PLATFORM(WIN) && USE(AVFOUNDATION)
virtual GraphicsDeviceAdapter* mediaPlayerGraphicsDeviceAdapter(const MediaPlayer*) const { return 0; }
#endif
#if ENABLE(ENCRYPTED_MEDIA)
enum MediaKeyErrorCode { UnknownError = 1, ClientError, ServiceError, OutputError, HardwareChangeError, DomainError };
virtual void mediaPlayerKeyAdded(MediaPlayer*, const String& , const String& ) { }
virtual void mediaPlayerKeyError(MediaPlayer*, const String& , const String& , MediaKeyErrorCode, unsigned short ) { }
virtual void mediaPlayerKeyMessage(MediaPlayer*, const String& , const String& , const unsigned char* , unsigned , const KURL& ) { }
virtual bool mediaPlayerKeyNeeded(MediaPlayer*, const String& , const String& , const unsigned char* , unsigned ) { return false; }
#endif
#if ENABLE(ENCRYPTED_MEDIA_V2)
virtual bool mediaPlayerKeyNeeded(MediaPlayer*, Uint8Array*) { return false; }
#endif
virtual String mediaPlayerReferrer() const { return String(); }
virtual String mediaPlayerUserAgent() const { return String(); }
virtual CORSMode mediaPlayerCORSMode() const { return Unspecified; }
virtual void mediaPlayerEnterFullscreen() { }
virtual void mediaPlayerExitFullscreen() { }
virtual bool mediaPlayerIsFullscreen() const { return false; }
virtual bool mediaPlayerIsFullscreenPermitted() const { return false; }
virtual bool mediaPlayerIsVideo() const { return false; }
virtual LayoutRect mediaPlayerContentBoxRect() const { return LayoutRect(); }
virtual void mediaPlayerSetSize(const IntSize&) { }
virtual void mediaPlayerPause() { }
virtual void mediaPlayerPlay() { }
virtual bool mediaPlayerIsPaused() const { return true; }
virtual bool mediaPlayerIsLooping() const { return false; }
virtual HostWindow* mediaPlayerHostWindow() { return 0; }
virtual IntRect mediaPlayerWindowClipRect() { return IntRect(); }
virtual CachedResourceLoader* mediaPlayerCachedResourceLoader() { return 0; }
#if ENABLE(VIDEO_TRACK)
virtual void mediaPlayerDidAddAudioTrack(PassRefPtr<AudioTrackPrivate>) { }
virtual void mediaPlayerDidAddTextTrack(PassRefPtr<InbandTextTrackPrivate>) { }
virtual void mediaPlayerDidAddVideoTrack(PassRefPtr<VideoTrackPrivate>) { }
virtual void mediaPlayerDidRemoveAudioTrack(PassRefPtr<AudioTrackPrivate>) { }
virtual void mediaPlayerDidRemoveTextTrack(PassRefPtr<InbandTextTrackPrivate>) { }
virtual void mediaPlayerDidRemoveVideoTrack(PassRefPtr<VideoTrackPrivate>) { }
virtual void textTrackRepresentationBoundsChanged(const IntRect&) { }
virtual void paintTextTrackRepresentation(GraphicsContext*, const IntRect&) { }
#endif
};
class MediaPlayerSupportsTypeClient {
public:
virtual ~MediaPlayerSupportsTypeClient() { }
virtual bool mediaPlayerNeedsSiteSpecificHacks() const { return false; }
virtual String mediaPlayerDocumentHost() const { return String(); }
};
class MediaPlayer {
WTF_MAKE_NONCOPYABLE(MediaPlayer); WTF_MAKE_FAST_ALLOCATED;
public:
static PassOwnPtr<MediaPlayer> create(MediaPlayerClient* client)
{
return adoptPtr(new MediaPlayer(client));
}
virtual ~MediaPlayer();
enum SupportsType { IsNotSupported, IsSupported, MayBeSupported };
static MediaPlayer::SupportsType supportsType(const ContentType&, const String& keySystem, const KURL&, const MediaPlayerSupportsTypeClient*);
static void getSupportedTypes(HashSet<String>&);
static bool isAvailable();
static void getSitesInMediaCache(Vector<String>&);
static void clearMediaCache();
static void clearMediaCacheForSite(const String&);
bool supportsFullscreen() const;
bool supportsSave() const;
bool supportsScanning() const;
bool requiresImmediateCompositing() const;
PlatformMedia platformMedia() const;
#if USE(ACCELERATED_COMPOSITING)
PlatformLayer* platformLayer() const;
#endif
IntSize naturalSize();
bool hasVideo() const;
bool hasAudio() const;
void setFrameView(FrameView* frameView) { m_frameView = frameView; }
FrameView* frameView() { return m_frameView; }
bool inMediaDocument();
IntSize size() const { return m_size; }
void setSize(const IntSize& size);
bool load(const KURL&, const ContentType&, const String& keySystem);
#if ENABLE(MEDIA_SOURCE)
bool load(const KURL&, PassRefPtr<MediaSource>);
#endif
void cancelLoad();
bool visible() const;
void setVisible(bool);
void prepareToPlay();
void play();
void pause();
#if ENABLE(ENCRYPTED_MEDIA)
enum MediaKeyException { NoError, InvalidPlayerState, KeySystemNotSupported };
MediaKeyException generateKeyRequest(const String& keySystem, const unsigned char* initData, unsigned initDataLength);
MediaKeyException addKey(const String& keySystem, const unsigned char* key, unsigned keyLength, const unsigned char* initData, unsigned initDataLength, const String& sessionId);
MediaKeyException cancelKeyRequest(const String& keySystem, const String& sessionId);
#endif
bool paused() const;
bool seeking() const;
static double invalidTime() { return -1.0;}
double duration() const;
double currentTime() const;
void seek(double time);
double startTime() const;
double initialTime() const;
double rate() const;
void setRate(double);
bool preservesPitch() const;
void setPreservesPitch(bool);
PassRefPtr<TimeRanges> buffered();
PassRefPtr<TimeRanges> seekable();
double minTimeSeekable();
double maxTimeSeekable();
bool didLoadingProgress();
double volume() const;
void setVolume(double);
bool muted() const;
void setMuted(bool);
bool hasClosedCaptions() const;
void setClosedCaptionsVisible(bool closedCaptionsVisible);
bool autoplay() const;
void setAutoplay(bool);
void paint(GraphicsContext*, const IntRect&);
void paintCurrentFrameInContext(GraphicsContext*, const IntRect&);
bool copyVideoTextureToPlatformTexture(GraphicsContext3D*, Platform3DObject texture, GC3Dint level, GC3Denum type, GC3Denum internalFormat, bool premultiplyAlpha, bool flipY);
enum NetworkState { Empty, Idle, Loading, Loaded, FormatError, NetworkError, DecodeError };
NetworkState networkState();
enum ReadyState { HaveNothing, HaveMetadata, HaveCurrentData, HaveFutureData, HaveEnoughData };
ReadyState readyState();
enum MovieLoadType { Unknown, Download, StoredStream, LiveStream };
MovieLoadType movieLoadType() const;
enum Preload { None, MetaData, Auto };
Preload preload() const;
void setPreload(Preload);
void networkStateChanged();
void readyStateChanged();
void volumeChanged(double);
void muteChanged(bool);
void timeChanged();
void sizeChanged();
void rateChanged();
void playbackStateChanged();
void durationChanged();
void firstVideoFrameAvailable();
void characteristicChanged();
void repaint();
MediaPlayerClient* mediaPlayerClient() const { return m_mediaPlayerClient; }
void clearMediaPlayerClient() { m_mediaPlayerClient = 0; }
bool hasAvailableVideoFrame() const;
void prepareForRendering();
bool canLoadPoster() const;
void setPoster(const String&);
#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
void deliverNotification(MediaPlayerProxyNotificationType notification);
void setMediaPlayerProxy(WebMediaPlayerProxy* proxy);
void setControls(bool);
#endif
#if ENABLE(PLUGIN_PROXY_FOR_VIDEO) || USE(NATIVE_FULLSCREEN_VIDEO)
void enterFullscreen();
void exitFullscreen();
#endif
#if USE(NATIVE_FULLSCREEN_VIDEO)
bool canEnterFullscreen() const;
#endif
#if USE(ACCELERATED_COMPOSITING)
bool supportsAcceleratedRendering() const;
void acceleratedRenderingStateChanged();
#endif
#if PLATFORM(WIN) && USE(AVFOUNDATION)
GraphicsDeviceAdapter* graphicsDeviceAdapter() const;
#endif
bool hasSingleSecurityOrigin() const;
bool didPassCORSAccessCheck() const;
double mediaTimeForTimeValue(double) const;
double maximumDurationToCacheMediaTime() const;
unsigned decodedFrameCount() const;
unsigned droppedFrameCount() const;
unsigned audioDecodedByteCount() const;
unsigned videoDecodedByteCount() const;
void setPrivateBrowsingMode(bool);
#if ENABLE(WEB_AUDIO)
AudioSourceProvider* audioSourceProvider();
#endif
#if ENABLE(ENCRYPTED_MEDIA)
void keyAdded(const String& keySystem, const String& sessionId);
void keyError(const String& keySystem, const String& sessionId, MediaPlayerClient::MediaKeyErrorCode, unsigned short systemCode);
void keyMessage(const String& keySystem, const String& sessionId, const unsigned char* message, unsigned messageLength, const KURL& defaultURL);
bool keyNeeded(const String& keySystem, const String& sessionId, const unsigned char* initData, unsigned initDataLength);
#endif
#if ENABLE(ENCRYPTED_MEDIA_V2)
bool keyNeeded(Uint8Array* initData);
#endif
String referrer() const;
String userAgent() const;
String engineDescription() const;
CachedResourceLoader* cachedResourceLoader();
#if ENABLE(VIDEO_TRACK)
void addAudioTrack(PassRefPtr<AudioTrackPrivate>);
void addTextTrack(PassRefPtr<InbandTextTrackPrivate>);
void addVideoTrack(PassRefPtr<VideoTrackPrivate>);
void removeAudioTrack(PassRefPtr<AudioTrackPrivate>);
void removeTextTrack(PassRefPtr<InbandTextTrackPrivate>);
void removeVideoTrack(PassRefPtr<VideoTrackPrivate>);
bool requiresTextTrackRepresentation() const;
void setTextTrackRepresentation(TextTrackRepresentation*);
#endif
static void resetMediaEngines();
#if USE(PLATFORM_TEXT_TRACK_MENU)
bool implementsTextTrackControls() const;
PassRefPtr<PlatformTextTrackMenuInterface> textTrackMenu();
#endif
#if USE(GSTREAMER)
void simulateAudioInterruption();
#endif
String languageOfPrimaryAudioTrack() const;
size_t extraMemoryCost() const;
private:
MediaPlayer(MediaPlayerClient*);
void loadWithNextMediaEngine(MediaPlayerFactory*);
void reloadTimerFired(Timer<MediaPlayer>*);
static void initializeMediaEngines();
MediaPlayerClient* m_mediaPlayerClient;
Timer<MediaPlayer> m_reloadTimer;
OwnPtr<MediaPlayerPrivateInterface> m_private;
MediaPlayerFactory* m_currentMediaEngine;
KURL m_url;
String m_contentMIMEType;
String m_contentTypeCodecs;
String m_keySystem;
FrameView* m_frameView;
IntSize m_size;
Preload m_preload;
bool m_visible;
double m_rate;
double m_volume;
bool m_muted;
bool m_preservesPitch;
bool m_privateBrowsing;
bool m_shouldPrepareToRender;
bool m_contentMIMETypeWasInferredFromExtension;
#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
WebMediaPlayerProxy* m_playerProxy; #endif
#if ENABLE(MEDIA_SOURCE)
RefPtr<MediaSource> m_mediaSource;
#endif
};
typedef PassOwnPtr<MediaPlayerPrivateInterface> (*CreateMediaEnginePlayer)(MediaPlayer*);
typedef void (*MediaEngineSupportedTypes)(HashSet<String>& types);
#if ENABLE(ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA_V2)
typedef MediaPlayer::SupportsType (*MediaEngineSupportsType)(const String& type, const String& codecs, const String& keySystem, const KURL& url);
#else
typedef MediaPlayer::SupportsType (*MediaEngineSupportsType)(const String& type, const String& codecs, const KURL& url);
#endif
typedef void (*MediaEngineGetSitesInMediaCache)(Vector<String>&);
typedef void (*MediaEngineClearMediaCache)();
typedef void (*MediaEngineClearMediaCacheForSite)(const String&);
typedef void (*MediaEngineRegistrar)(CreateMediaEnginePlayer, MediaEngineSupportedTypes, MediaEngineSupportsType,
MediaEngineGetSitesInMediaCache, MediaEngineClearMediaCache, MediaEngineClearMediaCacheForSite);
}
#endif // ENABLE(VIDEO)
#endif