Move locale information into FontDescription
[WebKit-https.git] / Source / WebCore / platform / graphics / MediaPlayer.h
index 1bb85d7..e327e2e 100644 (file)
 #include "IntRect.h"
 #include "URL.h"
 #include "LayoutRect.h"
-#include "MediaSession.h"
+#include "MediaPlayerEnums.h"
 #include "NativeImagePtr.h"
 #include "PlatformLayer.h"
+#include "PlatformMediaResourceLoader.h"
+#include "PlatformMediaSession.h"
 #include "Timer.h"
 #include "VideoTrackPrivate.h"
 #include <runtime/Uint8Array.h>
 #include <wtf/HashSet.h>
 #include <wtf/MediaTime.h>
 #include <wtf/Noncopyable.h>
-#include <wtf/OwnPtr.h>
-#include <wtf/PassOwnPtr.h>
 #include <wtf/text/StringHash.h>
 
 #if ENABLE(AVF_CAPTIONS)
 #include "PlatformTextTrack.h"
 #endif
 
-#if USE(PLATFORM_TEXT_TRACK_MENU)
-#include "PlatformTextTrackMenu.h"
-#endif
-
 OBJC_CLASS AVAsset;
 OBJC_CLASS AVPlayer;
 OBJC_CLASS NSArray;
@@ -70,10 +66,13 @@ namespace WebCore {
 
 class AudioSourceProvider;
 class AuthenticationChallenge;
-class Document;
+class MediaPlaybackTarget;
 #if ENABLE(MEDIA_SOURCE)
 class MediaSourcePrivateClient;
 #endif
+#if ENABLE(MEDIA_STREAM)
+class MediaStreamPrivate;
+#endif
 class MediaPlayerPrivateInterface;
 class TextTrackRepresentation;
 struct Cookie;
@@ -88,8 +87,6 @@ struct PlatformMedia {
         QTMovieType,
         QTMovieGWorldType,
         QTMovieVisualContextType,
-        ChromiumMediaPlayerType,
-        QtMediaPlayerType,
         AVFoundationMediaPlayerType,
         AVFoundationCFMediaPlayerType,
         AVFoundationAssetType,
@@ -99,8 +96,6 @@ struct PlatformMedia {
         QTMovie* qtMovie;
         QTMovieGWorld* qtMovieGWorld;
         QTMovieVisualContext* qtMovieVisualContext;
-        MediaPlayerPrivateInterface* chromiumMediaPlayer;
-        MediaPlayerPrivateInterface* qtMediaPlayer;
         AVPlayer* avfMediaPlayer;
         AVCFPlayer* avcfMediaPlayer;
         AVAsset* avfAsset;
@@ -108,51 +103,42 @@ struct PlatformMedia {
 };
 
 struct MediaEngineSupportParameters {
+
+    MediaEngineSupportParameters() { }
+
     String type;
     String codecs;
     URL url;
-#if ENABLE(ENCRYPTED_MEDIA)
     String keySystem;
-#endif
-#if ENABLE(MEDIA_SOURCE)
-    bool isMediaSource;
-#endif
-
-    MediaEngineSupportParameters()
-#if ENABLE(MEDIA_SOURCE)
-        : isMediaSource(false)
-#endif
-    {
-    }
+    bool isMediaSource { false };
+    bool isMediaStream { false };
 };
 
 extern const PlatformMedia NoPlatformMedia;
 
 class CachedResourceLoader;
 class ContentType;
-class FrameView;
 class GraphicsContext;
 class GraphicsContext3D;
-class HostWindow;
 class IntRect;
 class IntSize;
 class MediaPlayer;
-struct MediaPlayerFactory;
 class PlatformTimeRanges;
 
+struct MediaPlayerFactory;
+
 #if PLATFORM(WIN) && USE(AVFOUNDATION)
 struct GraphicsDeviceAdapter;
 #endif
 
+#if USE(GSTREAMER)
+class MediaPlayerRequestInstallMissingPluginsCallback;
+#endif
+
 class MediaPlayerClient {
 public:
-    enum CORSMode { Unspecified, Anonymous, UseCredentials };
-
     virtual ~MediaPlayerClient() { }
 
-    // Get the document which the media player is owned by
-    virtual Document* mediaPlayerOwningDocument() { return 0; }
-
     // the network state has changed
     virtual void mediaPlayerNetworkStateChanged(MediaPlayer*) { }
 
@@ -221,32 +207,37 @@ public:
 #endif
 
 #if ENABLE(ENCRYPTED_MEDIA_V2)
+    virtual RefPtr<ArrayBuffer> mediaPlayerCachedKeyForKeyId(const String&) const { return nullptr; }
     virtual bool mediaPlayerKeyNeeded(MediaPlayer*, Uint8Array*) { return false; }
+    virtual String mediaPlayerMediaKeysStorageDirectory() const { return emptyString(); }
 #endif
     
-#if ENABLE(IOS_AIRPLAY)
+#if ENABLE(MEDIA_STREAM)
+    virtual String mediaPlayerMediaDeviceIdentifierStorageDirectory() const { return emptyString(); }
+#endif
+
+    
+#if ENABLE(WIRELESS_PLAYBACK_TARGET)
     virtual void mediaPlayerCurrentPlaybackTargetIsWirelessChanged(MediaPlayer*) { };
-    virtual void mediaPlayerPlaybackTargetAvailabilityChanged(MediaPlayer*) { };
 #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 float mediaPlayerContentsScale() const { return 1; }
     virtual void mediaPlayerSetSize(const IntSize&) { }
     virtual void mediaPlayerPause() { }
     virtual void mediaPlayerPlay() { }
     virtual bool mediaPlayerPlatformVolumeConfigurationRequired() const { return false; }
     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; }
+    virtual RefPtr<PlatformMediaResourceLoader> mediaPlayerCreateResourceLoader(std::unique_ptr<PlatformMediaResourceLoaderClient>) { return nullptr; }
     virtual bool doesHaveAttribute(const AtomicString&, AtomicString* = 0) const { return false; }
 
 #if ENABLE(VIDEO_TRACK)
@@ -269,9 +260,20 @@ public:
 #endif
     
     virtual bool mediaPlayerShouldWaitForResponseToAuthenticationChallenge(const AuthenticationChallenge&) { return false; }
-    virtual void mediaPlayerHandlePlaybackCommand(MediaSession::RemoteControlCommandType) { }
+    virtual void mediaPlayerHandlePlaybackCommand(PlatformMediaSession::RemoteControlCommandType) { }
 
     virtual String mediaPlayerSourceApplicationIdentifier() const { return emptyString(); }
+
+    virtual bool mediaPlayerIsInMediaDocument() const { return false; }
+    virtual void mediaPlayerEngineFailedToLoad() const { }
+
+    virtual double mediaPlayerRequestedPlaybackRate() const { return 0; }
+    virtual MediaPlayerEnums::VideoFullscreenMode mediaPlayerFullscreenMode() const { return MediaPlayerEnums::VideoFullscreenModeNone; }
+    virtual Vector<String> mediaPlayerPreferredAudioCharacteristics() const { return Vector<String>(); }
+
+#if USE(GSTREAMER)
+    virtual void requestInstallMissingPlugins(const String&, const String&, MediaPlayerRequestInstallMissingPluginsCallback&) { };
+#endif
 };
 
 class MediaPlayerSupportsTypeClient {
@@ -282,14 +284,10 @@ public:
     virtual String mediaPlayerDocumentHost() const { return String(); }
 };
 
-class MediaPlayer {
+class MediaPlayer : public MediaPlayerEnums {
     WTF_MAKE_NONCOPYABLE(MediaPlayer); WTF_MAKE_FAST_ALLOCATED;
 public:
-
-    static PassOwnPtr<MediaPlayer> create(MediaPlayerClient* client)
-    {
-        return adoptPtr(new MediaPlayer(client));
-    }
+    explicit MediaPlayer(MediaPlayerClient&);
     virtual ~MediaPlayer();
 
     // Media engine support.
@@ -303,8 +301,8 @@ public:
     static bool supportsKeySystem(const String& keySystem, const String& mimeType);
 
     bool supportsFullscreen() const;
-    bool supportsSave() const;
     bool supportsScanning() const;
+    bool canSaveMediaData() const;
     bool requiresImmediateCompositing() const;
     bool doesHaveAttribute(const AtomicString&, AtomicString* value = nullptr) const;
     PlatformMedia platformMedia() const;
@@ -312,21 +310,21 @@ public:
 #if PLATFORM(IOS)
     void setVideoFullscreenLayer(PlatformLayer*);
     void setVideoFullscreenFrame(FloatRect);
-    enum VideoGravity { VideoGravityResize, VideoGravityResizeAspect, VideoGravityResizeAspectFill };
+    using MediaPlayerEnums::VideoGravity;
     void setVideoFullscreenGravity(VideoGravity);
+    void setVideoFullscreenMode(VideoFullscreenMode);
+    VideoFullscreenMode fullscreenMode() const;
 
     NSArray *timedMetadata() const;
     String accessLog() const;
     String errorLog() const;
 #endif
 
-    IntSize naturalSize();
+    FloatSize naturalSize();
     bool hasVideo() const;
     bool hasAudio() const;
 
-    void setFrameView(FrameView* frameView) { m_frameView = frameView; }
-    FrameView* frameView() { return m_frameView; }
-    bool inMediaDocument();
+    bool inMediaDocument() const;
 
     IntSize size() const { return m_size; }
     void setSize(const IntSize& size);
@@ -335,6 +333,9 @@ public:
 #if ENABLE(MEDIA_SOURCE)
     bool load(const URL&, const ContentType&, MediaSourcePrivateClient*);
 #endif
+#if ENABLE(MEDIA_STREAM)
+    bool load(MediaStreamPrivate*);
+#endif
     void cancelLoad();
 
     bool visible() const;
@@ -359,37 +360,41 @@ public:
 
 #if ENABLE(ENCRYPTED_MEDIA_V2)
     std::unique_ptr<CDMSession> createSession(const String& keySystem);
+    void setCDMSession(CDMSession*);
+    void keyAdded();
 #endif
 
     bool paused() const;
     bool seeking() const;
 
     static double invalidTime() { return -1.0;}
-    double duration() const;
-    double currentTime() const;
-    void seek(double time);
-    void seekWithTolerance(double time, double negativeTolerance, double positiveTolerance);
+    MediaTime duration() const;
+    MediaTime currentTime() const;
+    void seek(const MediaTime&);
+    void seekWithTolerance(const MediaTime&, const MediaTime& negativeTolerance, const MediaTime& positiveTolerance);
 
-    double startTime() const;
+    MediaTime startTime() const;
+    MediaTime initialTime() const;
 
-    double initialTime() const;
+    MediaTime getStartDate() const;
 
     double rate() const;
     void setRate(double);
+    double requestedRate() const;
 
     bool preservesPitch() const;
     void setPreservesPitch(bool);
 
     std::unique_ptr<PlatformTimeRanges> buffered();
     std::unique_ptr<PlatformTimeRanges> seekable();
-    double minTimeSeekable();
-    double maxTimeSeekable();
+    MediaTime minTimeSeekable();
+    MediaTime maxTimeSeekable();
 
     bool didLoadingProgress();
 
     double volume() const;
     void setVolume(double);
-    bool platformVolumeConfigurationRequired() const { return m_mediaPlayerClient->mediaPlayerPlatformVolumeConfigurationRequired(); }
+    bool platformVolumeConfigurationRequired() const { return m_client.mediaPlayerPlatformVolumeConfigurationRequired(); }
 
     bool muted() const;
     void setMuted(bool);
@@ -400,8 +405,8 @@ public:
     bool autoplay() const;
     void setAutoplay(bool);
 
-    void paint(GraphicsContext*, const IntRect&);
-    void paintCurrentFrameInContext(GraphicsContext*, const IntRect&);
+    void paint(GraphicsContext&, const FloatRect&);
+    void paintCurrentFrameInContext(GraphicsContext&, const FloatRect&);
 
     // copyVideoTextureToPlatformTexture() is used to do the GPU-GPU textures copy without a readback to system memory.
     // The first five parameters denote the corresponding GraphicsContext, destination texture, requested level, requested type and the required internalFormat for destination texture.
@@ -420,16 +425,16 @@ public:
 
     PassNativeImagePtr nativeImageForCurrentTime();
 
-    enum NetworkState { Empty, Idle, Loading, Loaded, FormatError, NetworkError, DecodeError };
+    using MediaPlayerEnums::NetworkState;
     NetworkState networkState();
 
-    enum ReadyState  { HaveNothing, HaveMetadata, HaveCurrentData, HaveFutureData, HaveEnoughData };
+    using MediaPlayerEnums::ReadyState;
     ReadyState readyState();
 
-    enum MovieLoadType { Unknown, Download, StoredStream, LiveStream };
+    using MediaPlayerEnums::MovieLoadType;
     MovieLoadType movieLoadType() const;
 
-    enum Preload { None, MetaData, Auto };
+    using MediaPlayerEnums::Preload;
     Preload preload() const;
     void setPreload(Preload);
 
@@ -447,8 +452,7 @@ public:
 
     void repaint();
 
-    MediaPlayerClient* mediaPlayerClient() const { return m_mediaPlayerClient; }
-    void clearMediaPlayerClient() { m_mediaPlayerClient = 0; }
+    MediaPlayerClient& client() const { return m_client; }
 
     bool hasAvailableVideoFrame() const;
     void prepareForRendering();
@@ -461,25 +465,23 @@ public:
     void exitFullscreen();
 #endif
 
-#if ENABLE(IOS_AIRPLAY)
-    bool isCurrentPlaybackTargetWireless() const;
-
+#if ENABLE(WIRELESS_PLAYBACK_TARGET)
     enum WirelessPlaybackTargetType { TargetTypeNone, TargetTypeAirPlay, TargetTypeTVOut };
     WirelessPlaybackTargetType wirelessPlaybackTargetType() const;
 
     String wirelessPlaybackTargetName() const;
 
-    void showPlaybackTargetPicker();
-
-    bool hasWirelessPlaybackTargets() const;
-
     bool wirelessVideoPlaybackDisabled() const;
     void setWirelessVideoPlaybackDisabled(bool);
 
     void currentPlaybackTargetIsWirelessChanged();
     void playbackTargetAvailabilityChanged();
 
-    void setHasPlaybackTargetAvailabilityListeners(bool);
+    bool isCurrentPlaybackTargetWireless() const;
+    bool canPlayToWirelessPlaybackTarget() const;
+    void setWirelessPlaybackTarget(Ref<MediaPlaybackTarget>&&);
+
+    void setShouldPlayToPlaybackTarget(bool);
 #endif
 
     double minFastReverseRate() const;
@@ -505,7 +507,7 @@ public:
 
     bool didPassCORSAccessCheck() const;
 
-    double mediaTimeForTimeValue(double) const;
+    MediaTime mediaTimeForTimeValue(const MediaTime&) const;
 
     double maximumDurationToCacheMediaTime() const;
 
@@ -528,20 +530,19 @@ public:
 #endif
 
 #if ENABLE(ENCRYPTED_MEDIA_V2)
+    RefPtr<ArrayBuffer> cachedKeyForKeyId(const String& keyId) const;
     bool keyNeeded(Uint8Array* initData);
+    String mediaKeysStorageDirectory() const;
 #endif
 
     String referrer() const;
     String userAgent() const;
 
     String engineDescription() const;
-
-#if PLATFORM(IOS)
-    void attributeChanged(const String& name, const String& value);
-    bool readyForPlayback() const;
-#endif
+    long platformErrorCode() const;
 
     CachedResourceLoader* cachedResourceLoader();
+    PassRefPtr<PlatformMediaResourceLoader> createResourceLoader(std::unique_ptr<PlatformMediaResourceLoaderClient>);
 
 #if ENABLE(VIDEO_TRACK)
     void addAudioTrack(PassRefPtr<AudioTrackPrivate>);
@@ -554,6 +555,7 @@ public:
     bool requiresTextTrackRepresentation() const;
     void setTextTrackRepresentation(TextTrackRepresentation*);
     void syncTextTrackBounds();
+    void tracksChanged();
 #if ENABLE(AVF_CAPTIONS)
     void notifyTrackModeChanged();
     Vector<RefPtr<PlatformTextTrack>> outOfBandTrackSources();
@@ -567,13 +569,8 @@ public:
 
     static void resetMediaEngines();
 
-#if USE(PLATFORM_TEXT_TRACK_MENU)
-    bool implementsTextTrackControls() const;
-    PassRefPtr<PlatformTextTrackMenuInterface> textTrackMenu();
-#endif
-
 #if USE(GSTREAMER)
-    void simulateAudioInterruption();
+    WEBCORE_EXPORT void simulateAudioInterruption();
 #endif
 
     String languageOfPrimaryAudioTrack() const;
@@ -586,34 +583,34 @@ public:
     unsigned long totalVideoFrames();
     unsigned long droppedVideoFrames();
     unsigned long corruptedVideoFrames();
-    double totalFrameDelay();
+    MediaTime totalFrameDelay();
 #endif
 
     bool shouldWaitForResponseToAuthenticationChallenge(const AuthenticationChallenge&);
-    void handlePlaybackCommand(MediaSession::RemoteControlCommandType);
+    void handlePlaybackCommand(PlatformMediaSession::RemoteControlCommandType);
     String sourceApplicationIdentifier() const;
+    Vector<String> preferredAudioCharacteristics() const;
+
+    bool ended() const;
 
 private:
-    MediaPlayer(MediaPlayerClient*);
-    MediaPlayerFactory* nextBestMediaEngine(MediaPlayerFactory*) const;
-    void loadWithNextMediaEngine(MediaPlayerFactory*);
-    void reloadTimerFired(Timer<MediaPlayer>&);
+    const MediaPlayerFactory* nextBestMediaEngine(const MediaPlayerFactory*) const;
+    void loadWithNextMediaEngine(const MediaPlayerFactory*);
+    void reloadTimerFired();
 
     static void initializeMediaEngines();
 
-    MediaPlayerClient* m_mediaPlayerClient;
-    Timer<MediaPlayer> m_reloadTimer;
-    OwnPtr<MediaPlayerPrivateInterface> m_private;
-    MediaPlayerFactory* m_currentMediaEngine;
+    MediaPlayerClient& m_client;
+    Timer m_reloadTimer;
+    std::unique_ptr<MediaPlayerPrivateInterface> m_private;
+    const MediaPlayerFactory* m_currentMediaEngine;
     URL 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;
@@ -624,9 +621,12 @@ private:
 #if ENABLE(MEDIA_SOURCE)
     RefPtr<MediaSourcePrivateClient> m_mediaSource;
 #endif
+#if ENABLE(MEDIA_STREAM)
+    RefPtr<MediaStreamPrivate> m_mediaStream;
+#endif
 };
 
-typedef PassOwnPtr<MediaPlayerPrivateInterface> (*CreateMediaEnginePlayer)(MediaPlayer*);
+typedef std::function<std::unique_ptr<MediaPlayerPrivateInterface> (MediaPlayer*)> CreateMediaEnginePlayer;
 typedef void (*MediaEngineSupportedTypes)(HashSet<String>& types);
 typedef MediaPlayer::SupportsType (*MediaEngineSupportsType)(const MediaEngineSupportParameters& parameters);
 typedef void (*MediaEngineGetSitesInMediaCache)(Vector<String>&);
@@ -640,7 +640,7 @@ typedef void (*MediaEngineRegister)(MediaEngineRegistrar);
 
 class MediaPlayerFactorySupport {
 public:
-    static void callRegisterMediaEngine(MediaEngineRegister);
+    WEBCORE_EXPORT static void callRegisterMediaEngine(MediaEngineRegister);
 };
 
 }