1/*
2 * Copyright (C) 2007-2014 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 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 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 MediaPlayer_h
27#define MediaPlayer_h
28
29#if ENABLE(VIDEO)
30#include "GraphicsTypes3D.h"
31
32#include "AudioTrackPrivate.h"
33#include "CDMSession.h"
34#include "InbandTextTrackPrivate.h"
35#include "IntRect.h"
36#include "URL.h"
37#include "LayoutRect.h"
38#include "MediaSession.h"
39#include "NativeImagePtr.h"
40#include "PlatformLayer.h"
41#include "Timer.h"
42#include "VideoTrackPrivate.h"
43#include <runtime/Uint8Array.h>
44#include <wtf/Forward.h>
45#include <wtf/HashSet.h>
46#include <wtf/MediaTime.h>
47#include <wtf/Noncopyable.h>
48#include <wtf/OwnPtr.h>
49#include <wtf/PassOwnPtr.h>
50#include <wtf/text/StringHash.h>
51
52#if ENABLE(AVF_CAPTIONS)
53#include "PlatformTextTrack.h"
54#endif
55
56#if USE(PLATFORM_TEXT_TRACK_MENU)
57#include "PlatformTextTrackMenu.h"
58#endif
59
60OBJC_CLASS AVAsset;
61OBJC_CLASS AVPlayer;
62OBJC_CLASS NSArray;
63OBJC_CLASS QTMovie;
64
65class AVCFPlayer;
66class QTMovieGWorld;
67class QTMovieVisualContext;
68
69namespace WebCore {
70
71class AudioSourceProvider;
72class AuthenticationChallenge;
73class Document;
74#if ENABLE(MEDIA_SOURCE)
75class MediaSourcePrivateClient;
76#endif
77class MediaPlayerPrivateInterface;
78class TextTrackRepresentation;
79struct Cookie;
80
81// Structure that will hold every native
82// types supported by the current media player.
83// We have to do that has multiple media players
84// backend can live at runtime.
85struct PlatformMedia {
86    enum {
87        None,
88        QTMovieType,
89        QTMovieGWorldType,
90        QTMovieVisualContextType,
91        ChromiumMediaPlayerType,
92        QtMediaPlayerType,
93        AVFoundationMediaPlayerType,
94        AVFoundationCFMediaPlayerType,
95        AVFoundationAssetType,
96    } type;
97
98    union {
99        QTMovie* qtMovie;
100        QTMovieGWorld* qtMovieGWorld;
101        QTMovieVisualContext* qtMovieVisualContext;
102        MediaPlayerPrivateInterface* chromiumMediaPlayer;
103        MediaPlayerPrivateInterface* qtMediaPlayer;
104        AVPlayer* avfMediaPlayer;
105        AVCFPlayer* avcfMediaPlayer;
106        AVAsset* avfAsset;
107    } media;
108};
109
110struct MediaEngineSupportParameters {
111    String type;
112    String codecs;
113    URL url;
114#if ENABLE(ENCRYPTED_MEDIA)
115    String keySystem;
116#endif
117#if ENABLE(MEDIA_SOURCE)
118    bool isMediaSource;
119#endif
120
121    MediaEngineSupportParameters()
122#if ENABLE(MEDIA_SOURCE)
123        : isMediaSource(false)
124#endif
125    {
126    }
127};
128
129extern const PlatformMedia NoPlatformMedia;
130
131class CachedResourceLoader;
132class ContentType;
133class FrameView;
134class GraphicsContext;
135class GraphicsContext3D;
136class HostWindow;
137class IntRect;
138class IntSize;
139class MediaPlayer;
140struct MediaPlayerFactory;
141class PlatformTimeRanges;
142
143#if PLATFORM(WIN) && USE(AVFOUNDATION)
144struct GraphicsDeviceAdapter;
145#endif
146
147class MediaPlayerClient {
148public:
149    enum CORSMode { Unspecified, Anonymous, UseCredentials };
150
151    virtual ~MediaPlayerClient() { }
152
153    // Get the document which the media player is owned by
154    virtual Document* mediaPlayerOwningDocument() { return 0; }
155
156    // the network state has changed
157    virtual void mediaPlayerNetworkStateChanged(MediaPlayer*) { }
158
159    // the ready state has changed
160    virtual void mediaPlayerReadyStateChanged(MediaPlayer*) { }
161
162    // the volume state has changed
163    virtual void mediaPlayerVolumeChanged(MediaPlayer*) { }
164
165    // the mute state has changed
166    virtual void mediaPlayerMuteChanged(MediaPlayer*) { }
167
168    // time has jumped, eg. not as a result of normal playback
169    virtual void mediaPlayerTimeChanged(MediaPlayer*) { }
170
171    // the media file duration has changed, or is now known
172    virtual void mediaPlayerDurationChanged(MediaPlayer*) { }
173
174    // the playback rate has changed
175    virtual void mediaPlayerRateChanged(MediaPlayer*) { }
176
177    // the play/pause status changed
178    virtual void mediaPlayerPlaybackStateChanged(MediaPlayer*) { }
179
180    // The MediaPlayer has found potentially problematic media content.
181    // This is used internally to trigger swapping from a <video>
182    // element to an <embed> in standalone documents
183    virtual void mediaPlayerSawUnsupportedTracks(MediaPlayer*) { }
184
185    // The MediaPlayer could not discover an engine which supports the requested resource.
186    virtual void mediaPlayerResourceNotSupported(MediaPlayer*) { }
187
188// Presentation-related methods
189    // a new frame of video is available
190    virtual void mediaPlayerRepaint(MediaPlayer*) { }
191
192    // the movie size has changed
193    virtual void mediaPlayerSizeChanged(MediaPlayer*) { }
194
195    virtual void mediaPlayerEngineUpdated(MediaPlayer*) { }
196
197    // The first frame of video is available to render. A media engine need only make this callback if the
198    // first frame is not available immediately when prepareForRendering is called.
199    virtual void mediaPlayerFirstVideoFrameAvailable(MediaPlayer*) { }
200
201    // A characteristic of the media file, eg. video, audio, closed captions, etc, has changed.
202    virtual void mediaPlayerCharacteristicChanged(MediaPlayer*) { }
203
204    // whether the rendering system can accelerate the display of this MediaPlayer.
205    virtual bool mediaPlayerRenderingCanBeAccelerated(MediaPlayer*) { return false; }
206
207    // called when the media player's rendering mode changed, which indicates a change in the
208    // availability of the platformLayer().
209    virtual void mediaPlayerRenderingModeChanged(MediaPlayer*) { }
210
211#if PLATFORM(WIN) && USE(AVFOUNDATION)
212    virtual GraphicsDeviceAdapter* mediaPlayerGraphicsDeviceAdapter(const MediaPlayer*) const { return 0; }
213#endif
214
215#if ENABLE(ENCRYPTED_MEDIA)
216    enum MediaKeyErrorCode { UnknownError = 1, ClientError, ServiceError, OutputError, HardwareChangeError, DomainError };
217    virtual void mediaPlayerKeyAdded(MediaPlayer*, const String& /* keySystem */, const String& /* sessionId */) { }
218    virtual void mediaPlayerKeyError(MediaPlayer*, const String& /* keySystem */, const String& /* sessionId */, MediaKeyErrorCode, unsigned short /* systemCode */) { }
219    virtual void mediaPlayerKeyMessage(MediaPlayer*, const String& /* keySystem */, const String& /* sessionId */, const unsigned char* /* message */, unsigned /* messageLength */, const URL& /* defaultURL */) { }
220    virtual bool mediaPlayerKeyNeeded(MediaPlayer*, const String& /* keySystem */, const String& /* sessionId */, const unsigned char* /* initData */, unsigned /* initDataLength */) { return false; }
221#endif
222
223#if ENABLE(ENCRYPTED_MEDIA_V2)
224    virtual bool mediaPlayerKeyNeeded(MediaPlayer*, Uint8Array*) { return false; }
225#endif
226
227#if ENABLE(IOS_AIRPLAY)
228    virtual void mediaPlayerCurrentPlaybackTargetIsWirelessChanged(MediaPlayer*) { };
229    virtual void mediaPlayerPlaybackTargetAvailabilityChanged(MediaPlayer*) { };
230#endif
231
232    virtual String mediaPlayerReferrer() const { return String(); }
233    virtual String mediaPlayerUserAgent() const { return String(); }
234    virtual CORSMode mediaPlayerCORSMode() const { return Unspecified; }
235    virtual void mediaPlayerEnterFullscreen() { }
236    virtual void mediaPlayerExitFullscreen() { }
237    virtual bool mediaPlayerIsFullscreen() const { return false; }
238    virtual bool mediaPlayerIsFullscreenPermitted() const { return false; }
239    virtual bool mediaPlayerIsVideo() const { return false; }
240    virtual LayoutRect mediaPlayerContentBoxRect() const { return LayoutRect(); }
241    virtual void mediaPlayerSetSize(const IntSize&) { }
242    virtual void mediaPlayerPause() { }
243    virtual void mediaPlayerPlay() { }
244    virtual bool mediaPlayerPlatformVolumeConfigurationRequired() const { return false; }
245    virtual bool mediaPlayerIsPaused() const { return true; }
246    virtual bool mediaPlayerIsLooping() const { return false; }
247    virtual HostWindow* mediaPlayerHostWindow() { return 0; }
248    virtual IntRect mediaPlayerWindowClipRect() { return IntRect(); }
249    virtual CachedResourceLoader* mediaPlayerCachedResourceLoader() { return 0; }
250    virtual bool doesHaveAttribute(const AtomicString&, AtomicString* = 0) const { return false; }
251
252#if ENABLE(VIDEO_TRACK)
253    virtual void mediaPlayerDidAddAudioTrack(PassRefPtr<AudioTrackPrivate>) { }
254    virtual void mediaPlayerDidAddTextTrack(PassRefPtr<InbandTextTrackPrivate>) { }
255    virtual void mediaPlayerDidAddVideoTrack(PassRefPtr<VideoTrackPrivate>) { }
256    virtual void mediaPlayerDidRemoveAudioTrack(PassRefPtr<AudioTrackPrivate>) { }
257    virtual void mediaPlayerDidRemoveTextTrack(PassRefPtr<InbandTextTrackPrivate>) { }
258    virtual void mediaPlayerDidRemoveVideoTrack(PassRefPtr<VideoTrackPrivate>) { }
259
260    virtual void textTrackRepresentationBoundsChanged(const IntRect&) { }
261#if ENABLE(AVF_CAPTIONS)
262    virtual Vector<RefPtr<PlatformTextTrack>> outOfBandTrackSources() { return Vector<RefPtr<PlatformTextTrack>>(); }
263#endif
264#endif
265
266#if PLATFORM(IOS)
267    virtual String mediaPlayerNetworkInterfaceName() const { return String(); }
268    virtual bool mediaPlayerGetRawCookies(const URL&, Vector<Cookie>&) const { return false; }
269#endif
270
271    virtual bool mediaPlayerShouldWaitForResponseToAuthenticationChallenge(const AuthenticationChallenge&) { return false; }
272    virtual void mediaPlayerHandlePlaybackCommand(MediaSession::RemoteControlCommandType) { }
273
274    virtual String mediaPlayerSourceApplicationIdentifier() const { return emptyString(); }
275};
276
277class MediaPlayerSupportsTypeClient {
278public:
279    virtual ~MediaPlayerSupportsTypeClient() { }
280
281    virtual bool mediaPlayerNeedsSiteSpecificHacks() const { return false; }
282    virtual String mediaPlayerDocumentHost() const { return String(); }
283};
284
285class MediaPlayer {
286    WTF_MAKE_NONCOPYABLE(MediaPlayer); WTF_MAKE_FAST_ALLOCATED;
287public:
288
289    static PassOwnPtr<MediaPlayer> create(MediaPlayerClient* client)
290    {
291        return adoptPtr(new MediaPlayer(client));
292    }
293    virtual ~MediaPlayer();
294
295    // Media engine support.
296    enum SupportsType { IsNotSupported, IsSupported, MayBeSupported };
297    static MediaPlayer::SupportsType supportsType(const MediaEngineSupportParameters&, const MediaPlayerSupportsTypeClient*);
298    static void getSupportedTypes(HashSet<String>&);
299    static bool isAvailable();
300    static void getSitesInMediaCache(Vector<String>&);
301    static void clearMediaCache();
302    static void clearMediaCacheForSite(const String&);
303    static bool supportsKeySystem(const String& keySystem, const String& mimeType);
304
305    bool supportsFullscreen() const;
306    bool supportsSave() const;
307    bool supportsScanning() const;
308    bool requiresImmediateCompositing() const;
309    bool doesHaveAttribute(const AtomicString&, AtomicString* value = nullptr) const;
310    PlatformMedia platformMedia() const;
311    PlatformLayer* platformLayer() const;
312#if PLATFORM(IOS)
313    void setVideoFullscreenLayer(PlatformLayer*);
314    void setVideoFullscreenFrame(FloatRect);
315    enum VideoGravity { VideoGravityResize, VideoGravityResizeAspect, VideoGravityResizeAspectFill };
316    void setVideoFullscreenGravity(VideoGravity);
317
318    NSArray *timedMetadata() const;
319    String accessLog() const;
320    String errorLog() const;
321#endif
322
323    IntSize naturalSize();
324    bool hasVideo() const;
325    bool hasAudio() const;
326
327    void setFrameView(FrameView* frameView) { m_frameView = frameView; }
328    FrameView* frameView() { return m_frameView; }
329    bool inMediaDocument();
330
331    IntSize size() const { return m_size; }
332    void setSize(const IntSize& size);
333
334    bool load(const URL&, const ContentType&, const String& keySystem);
335#if ENABLE(MEDIA_SOURCE)
336    bool load(const URL&, const ContentType&, MediaSourcePrivateClient*);
337#endif
338    void cancelLoad();
339
340    bool visible() const;
341    void setVisible(bool);
342
343    void prepareToPlay();
344    void play();
345    void pause();
346    void setShouldBufferData(bool);
347
348#if ENABLE(ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA_V2)
349    // Represents synchronous exceptions that can be thrown from the Encrypted Media methods.
350    // This is different from the asynchronous MediaKeyError.
351    enum MediaKeyException { NoError, InvalidPlayerState, KeySystemNotSupported };
352#endif
353
354#if ENABLE(ENCRYPTED_MEDIA)
355    MediaKeyException generateKeyRequest(const String& keySystem, const unsigned char* initData, unsigned initDataLength);
356    MediaKeyException addKey(const String& keySystem, const unsigned char* key, unsigned keyLength, const unsigned char* initData, unsigned initDataLength, const String& sessionId);
357    MediaKeyException cancelKeyRequest(const String& keySystem, const String& sessionId);
358#endif
359
360#if ENABLE(ENCRYPTED_MEDIA_V2)
361    std::unique_ptr<CDMSession> createSession(const String& keySystem);
362#endif
363
364    bool paused() const;
365    bool seeking() const;
366
367    static double invalidTime() { return -1.0;}
368    double duration() const;
369    double currentTime() const;
370    void seek(double time);
371    void seekWithTolerance(double time, double negativeTolerance, double positiveTolerance);
372
373    double startTime() const;
374
375    double initialTime() const;
376
377    double rate() const;
378    void setRate(double);
379
380    bool preservesPitch() const;
381    void setPreservesPitch(bool);
382
383    std::unique_ptr<PlatformTimeRanges> buffered();
384    std::unique_ptr<PlatformTimeRanges> seekable();
385    double minTimeSeekable();
386    double maxTimeSeekable();
387
388    bool didLoadingProgress();
389
390    double volume() const;
391    void setVolume(double);
392    bool platformVolumeConfigurationRequired() const { return m_mediaPlayerClient->mediaPlayerPlatformVolumeConfigurationRequired(); }
393
394    bool muted() const;
395    void setMuted(bool);
396
397    bool hasClosedCaptions() const;
398    void setClosedCaptionsVisible(bool closedCaptionsVisible);
399
400    bool autoplay() const;
401    void setAutoplay(bool);
402
403    void paint(GraphicsContext*, const IntRect&);
404    void paintCurrentFrameInContext(GraphicsContext*, const IntRect&);
405
406    // copyVideoTextureToPlatformTexture() is used to do the GPU-GPU textures copy without a readback to system memory.
407    // The first five parameters denote the corresponding GraphicsContext, destination texture, requested level, requested type and the required internalFormat for destination texture.
408    // The last two parameters premultiplyAlpha and flipY denote whether addtional premultiplyAlpha and flip operation are required during the copy.
409    // It returns true on success and false on failure.
410
411    // In the GPU-GPU textures copy, the source texture(Video texture) should have valid target, internalFormat and size, etc.
412    // The destination texture may need to be resized to to the dimensions of the source texture or re-defined to the required internalFormat.
413    // The current restrictions require that format shoud be RGB or RGBA, type should be UNSIGNED_BYTE and level should be 0. It may be lifted in the future.
414
415    // Each platform port can have its own implementation on this function. The default implementation for it is a single "return false" in MediaPlayerPrivate.h.
416    // In chromium, the implementation is based on GL_CHROMIUM_copy_texture extension which is documented at
417    // http://src.chromium.org/viewvc/chrome/trunk/src/gpu/GLES2/extensions/CHROMIUM/CHROMIUM_copy_texture.txt and implemented at
418    // http://src.chromium.org/viewvc/chrome/trunk/src/gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.cc via shaders.
419    bool copyVideoTextureToPlatformTexture(GraphicsContext3D*, Platform3DObject texture, GC3Dint level, GC3Denum type, GC3Denum internalFormat, bool premultiplyAlpha, bool flipY);
420
421    PassNativeImagePtr nativeImageForCurrentTime();
422
423    enum NetworkState { Empty, Idle, Loading, Loaded, FormatError, NetworkError, DecodeError };
424    NetworkState networkState();
425
426    enum ReadyState  { HaveNothing, HaveMetadata, HaveCurrentData, HaveFutureData, HaveEnoughData };
427    ReadyState readyState();
428
429    enum MovieLoadType { Unknown, Download, StoredStream, LiveStream };
430    MovieLoadType movieLoadType() const;
431
432    enum Preload { None, MetaData, Auto };
433    Preload preload() const;
434    void setPreload(Preload);
435
436    void networkStateChanged();
437    void readyStateChanged();
438    void volumeChanged(double);
439    void muteChanged(bool);
440    void timeChanged();
441    void sizeChanged();
442    void rateChanged();
443    void playbackStateChanged();
444    void durationChanged();
445    void firstVideoFrameAvailable();
446    void characteristicChanged();
447
448    void repaint();
449
450    MediaPlayerClient* mediaPlayerClient() const { return m_mediaPlayerClient; }
451    void clearMediaPlayerClient() { m_mediaPlayerClient = 0; }
452
453    bool hasAvailableVideoFrame() const;
454    void prepareForRendering();
455
456    bool canLoadPoster() const;
457    void setPoster(const String&);
458
459#if USE(NATIVE_FULLSCREEN_VIDEO)
460    void enterFullscreen();
461    void exitFullscreen();
462#endif
463
464#if ENABLE(IOS_AIRPLAY)
465    bool isCurrentPlaybackTargetWireless() const;
466
467    enum WirelessPlaybackTargetType { TargetTypeNone, TargetTypeAirPlay, TargetTypeTVOut };
468    WirelessPlaybackTargetType wirelessPlaybackTargetType() const;
469
470    String wirelessPlaybackTargetName() const;
471
472    void showPlaybackTargetPicker();
473
474    bool hasWirelessPlaybackTargets() const;
475
476    bool wirelessVideoPlaybackDisabled() const;
477    void setWirelessVideoPlaybackDisabled(bool);
478
479    void currentPlaybackTargetIsWirelessChanged();
480    void playbackTargetAvailabilityChanged();
481
482    void setHasPlaybackTargetAvailabilityListeners(bool);
483#endif
484
485    double minFastReverseRate() const;
486    double maxFastForwardRate() const;
487
488#if USE(NATIVE_FULLSCREEN_VIDEO)
489    bool canEnterFullscreen() const;
490#endif
491
492    // whether accelerated rendering is supported by the media engine for the current media.
493    bool supportsAcceleratedRendering() const;
494    // called when the rendering system flips the into or out of accelerated rendering mode.
495    void acceleratedRenderingStateChanged();
496
497    bool shouldMaintainAspectRatio() const;
498    void setShouldMaintainAspectRatio(bool);
499
500#if PLATFORM(WIN) && USE(AVFOUNDATION)
501    GraphicsDeviceAdapter* graphicsDeviceAdapter() const;
502#endif
503
504    bool hasSingleSecurityOrigin() const;
505
506    bool didPassCORSAccessCheck() const;
507
508    double mediaTimeForTimeValue(double) const;
509
510    double maximumDurationToCacheMediaTime() const;
511
512    unsigned decodedFrameCount() const;
513    unsigned droppedFrameCount() const;
514    unsigned audioDecodedByteCount() const;
515    unsigned videoDecodedByteCount() const;
516
517    void setPrivateBrowsingMode(bool);
518
519#if ENABLE(WEB_AUDIO)
520    AudioSourceProvider* audioSourceProvider();
521#endif
522
523#if ENABLE(ENCRYPTED_MEDIA)
524    void keyAdded(const String& keySystem, const String& sessionId);
525    void keyError(const String& keySystem, const String& sessionId, MediaPlayerClient::MediaKeyErrorCode, unsigned short systemCode);
526    void keyMessage(const String& keySystem, const String& sessionId, const unsigned char* message, unsigned messageLength, const URL& defaultURL);
527    bool keyNeeded(const String& keySystem, const String& sessionId, const unsigned char* initData, unsigned initDataLength);
528#endif
529
530#if ENABLE(ENCRYPTED_MEDIA_V2)
531    bool keyNeeded(Uint8Array* initData);
532#endif
533
534    String referrer() const;
535    String userAgent() const;
536
537    String engineDescription() const;
538
539#if PLATFORM(IOS)
540    void attributeChanged(const String& name, const String& value);
541    bool readyForPlayback() const;
542#endif
543
544    CachedResourceLoader* cachedResourceLoader();
545
546#if ENABLE(VIDEO_TRACK)
547    void addAudioTrack(PassRefPtr<AudioTrackPrivate>);
548    void addTextTrack(PassRefPtr<InbandTextTrackPrivate>);
549    void addVideoTrack(PassRefPtr<VideoTrackPrivate>);
550    void removeAudioTrack(PassRefPtr<AudioTrackPrivate>);
551    void removeTextTrack(PassRefPtr<InbandTextTrackPrivate>);
552    void removeVideoTrack(PassRefPtr<VideoTrackPrivate>);
553
554    bool requiresTextTrackRepresentation() const;
555    void setTextTrackRepresentation(TextTrackRepresentation*);
556    void syncTextTrackBounds();
557#if ENABLE(AVF_CAPTIONS)
558    void notifyTrackModeChanged();
559    Vector<RefPtr<PlatformTextTrack>> outOfBandTrackSources();
560#endif
561#endif
562
563#if PLATFORM(IOS)
564    String mediaPlayerNetworkInterfaceName() const;
565    bool getRawCookies(const URL&, Vector<Cookie>&) const;
566#endif
567
568    static void resetMediaEngines();
569
570#if USE(PLATFORM_TEXT_TRACK_MENU)
571    bool implementsTextTrackControls() const;
572    PassRefPtr<PlatformTextTrackMenuInterface> textTrackMenu();
573#endif
574
575#if USE(GSTREAMER)
576    void simulateAudioInterruption();
577#endif
578
579    String languageOfPrimaryAudioTrack() const;
580
581    size_t extraMemoryCost() const;
582
583    unsigned long long fileSize() const;
584
585#if ENABLE(MEDIA_SOURCE)
586    unsigned long totalVideoFrames();
587    unsigned long droppedVideoFrames();
588    unsigned long corruptedVideoFrames();
589    double totalFrameDelay();
590#endif
591
592    bool shouldWaitForResponseToAuthenticationChallenge(const AuthenticationChallenge&);
593    void handlePlaybackCommand(MediaSession::RemoteControlCommandType);
594    String sourceApplicationIdentifier() const;
595
596private:
597    MediaPlayer(MediaPlayerClient*);
598    MediaPlayerFactory* nextBestMediaEngine(MediaPlayerFactory*) const;
599    void loadWithNextMediaEngine(MediaPlayerFactory*);
600    void reloadTimerFired(Timer<MediaPlayer>&);
601
602    static void initializeMediaEngines();
603
604    MediaPlayerClient* m_mediaPlayerClient;
605    Timer<MediaPlayer> m_reloadTimer;
606    OwnPtr<MediaPlayerPrivateInterface> m_private;
607    MediaPlayerFactory* m_currentMediaEngine;
608    URL m_url;
609    String m_contentMIMEType;
610    String m_contentTypeCodecs;
611    String m_keySystem;
612    FrameView* m_frameView;
613    IntSize m_size;
614    Preload m_preload;
615    bool m_visible;
616    double m_rate;
617    double m_volume;
618    bool m_muted;
619    bool m_preservesPitch;
620    bool m_privateBrowsing;
621    bool m_shouldPrepareToRender;
622    bool m_contentMIMETypeWasInferredFromExtension;
623
624#if ENABLE(MEDIA_SOURCE)
625    RefPtr<MediaSourcePrivateClient> m_mediaSource;
626#endif
627};
628
629typedef PassOwnPtr<MediaPlayerPrivateInterface> (*CreateMediaEnginePlayer)(MediaPlayer*);
630typedef void (*MediaEngineSupportedTypes)(HashSet<String>& types);
631typedef MediaPlayer::SupportsType (*MediaEngineSupportsType)(const MediaEngineSupportParameters& parameters);
632typedef void (*MediaEngineGetSitesInMediaCache)(Vector<String>&);
633typedef void (*MediaEngineClearMediaCache)();
634typedef void (*MediaEngineClearMediaCacheForSite)(const String&);
635typedef bool (*MediaEngineSupportsKeySystem)(const String& keySystem, const String& mimeType);
636
637typedef void (*MediaEngineRegistrar)(CreateMediaEnginePlayer, MediaEngineSupportedTypes, MediaEngineSupportsType,
638    MediaEngineGetSitesInMediaCache, MediaEngineClearMediaCache, MediaEngineClearMediaCacheForSite, MediaEngineSupportsKeySystem);
639typedef void (*MediaEngineRegister)(MediaEngineRegistrar);
640
641class MediaPlayerFactorySupport {
642public:
643    static void callRegisterMediaEngine(MediaEngineRegister);
644};
645
646}
647
648#endif // ENABLE(VIDEO)
649
650#endif
651