Home | History | Annotate | Download | only in graphics
      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 MediaPlayer_h
     27 #define MediaPlayer_h
     28 
     29 #include "core/platform/graphics/GraphicsTypes3D.h"
     30 #include "wtf/Forward.h"
     31 #include "wtf/Noncopyable.h"
     32 
     33 namespace WebKit { class WebLayer; }
     34 
     35 namespace WebCore {
     36 
     37 class AudioSourceProvider;
     38 class GraphicsContext;
     39 class GraphicsContext3D;
     40 class InbandTextTrackPrivate;
     41 class IntRect;
     42 class IntSize;
     43 class KURL;
     44 class MediaPlayer;
     45 class HTMLMediaSource;
     46 class TimeRanges;
     47 
     48 class MediaPlayerClient {
     49 public:
     50     enum CORSMode { Unspecified, Anonymous, UseCredentials };
     51 
     52     virtual ~MediaPlayerClient() { }
     53 
     54     // the network state has changed
     55     virtual void mediaPlayerNetworkStateChanged() = 0;
     56 
     57     // the ready state has changed
     58     virtual void mediaPlayerReadyStateChanged() = 0;
     59 
     60     // time has jumped, eg. not as a result of normal playback
     61     virtual void mediaPlayerTimeChanged() = 0;
     62 
     63     // the media file duration has changed, or is now known
     64     virtual void mediaPlayerDurationChanged() = 0;
     65 
     66     // the play/pause status changed
     67     virtual void mediaPlayerPlaybackStateChanged() = 0;
     68 
     69 // Presentation-related methods
     70     // a new frame of video is available
     71     virtual void mediaPlayerRepaint() = 0;
     72 
     73     // the movie size has changed
     74     virtual void mediaPlayerSizeChanged() = 0;
     75 
     76     virtual void mediaPlayerEngineUpdated() = 0;
     77 
     78     enum MediaKeyErrorCode { UnknownError = 1, ClientError, ServiceError, OutputError, HardwareChangeError, DomainError };
     79     virtual void mediaPlayerKeyAdded(const String& /* keySystem */, const String& /* sessionId */) = 0;
     80     virtual void mediaPlayerKeyError(const String& /* keySystem */, const String& /* sessionId */, MediaKeyErrorCode, unsigned short /* systemCode */) = 0;
     81     virtual void mediaPlayerKeyMessage(const String& /* keySystem */, const String& /* sessionId */, const unsigned char* /* message */, unsigned /* messageLength */, const KURL& /* defaultURL */) = 0;
     82     virtual bool mediaPlayerKeyNeeded(const String& /* keySystem */, const String& /* sessionId */, const unsigned char* /* initData */, unsigned /* initDataLength */) = 0;
     83 
     84 #if ENABLE(ENCRYPTED_MEDIA_V2)
     85     virtual bool mediaPlayerKeyNeeded(Uint8Array*) = 0;
     86 #endif
     87 
     88     virtual CORSMode mediaPlayerCORSMode() const = 0;
     89 
     90     virtual void mediaPlayerScheduleLayerUpdate() = 0;
     91 
     92     virtual void mediaPlayerDidAddTrack(PassRefPtr<InbandTextTrackPrivate>) = 0;
     93     virtual void mediaPlayerDidRemoveTrack(PassRefPtr<InbandTextTrackPrivate>) = 0;
     94 };
     95 
     96 typedef PassOwnPtr<MediaPlayer> (*CreateMediaEnginePlayer)(MediaPlayerClient*);
     97 
     98 class MediaPlayer {
     99     WTF_MAKE_NONCOPYABLE(MediaPlayer);
    100 public:
    101     static PassOwnPtr<MediaPlayer> create(MediaPlayerClient*);
    102     static void setMediaEngineCreateFunction(CreateMediaEnginePlayer);
    103 
    104     static double invalidTime() { return -1.0; }
    105 
    106     MediaPlayer() { }
    107     virtual ~MediaPlayer() { }
    108 
    109     virtual void load(const String& url) = 0;
    110     virtual void load(const String& url, PassRefPtr<HTMLMediaSource>) = 0;
    111 
    112     virtual void prepareToPlay() = 0;
    113     virtual WebKit::WebLayer* platformLayer() const = 0;
    114 
    115     virtual void play() = 0;
    116     virtual void pause() = 0;
    117 
    118     virtual bool supportsFullscreen() const = 0;
    119     virtual bool supportsSave() const = 0;
    120     virtual IntSize naturalSize() const = 0;
    121 
    122     virtual bool hasVideo() const = 0;
    123     virtual bool hasAudio() const = 0;
    124 
    125     virtual double duration() const = 0;
    126 
    127     virtual double currentTime() const = 0;
    128 
    129     virtual void seek(double) = 0;
    130 
    131     virtual bool seeking() const = 0;
    132 
    133     virtual double rate() const = 0;
    134     virtual void setRate(double) = 0;
    135 
    136     virtual bool paused() const = 0;
    137 
    138     virtual void setVolume(double) = 0;
    139     virtual void setMuted(bool) = 0;
    140 
    141     enum NetworkState { Empty, Idle, Loading, Loaded, FormatError, NetworkError, DecodeError };
    142     virtual NetworkState networkState() const = 0;
    143 
    144     enum ReadyState  { HaveNothing, HaveMetadata, HaveCurrentData, HaveFutureData, HaveEnoughData };
    145     virtual ReadyState readyState() const = 0;
    146 
    147     virtual double maxTimeSeekable() const = 0;
    148     virtual PassRefPtr<TimeRanges> buffered() const = 0;
    149 
    150     virtual bool didLoadingProgress() const = 0;
    151 
    152     virtual void paint(GraphicsContext*, const IntRect&) = 0;
    153 
    154     virtual void paintCurrentFrameInContext(GraphicsContext*, const IntRect&) = 0;
    155     virtual bool copyVideoTextureToPlatformTexture(GraphicsContext3D*, Platform3DObject, GC3Dint, GC3Denum, GC3Denum, bool, bool) = 0;
    156 
    157     enum Preload { None, MetaData, Auto };
    158     virtual void setPreload(Preload) = 0;
    159 
    160 #if USE(NATIVE_FULLSCREEN_VIDEO)
    161     virtual void enterFullscreen() = 0;
    162     virtual void exitFullscreen() = 0;
    163     virtual bool canEnterFullscreen() const = 0;
    164 #endif
    165 
    166     // whether accelerated rendering is supported by the media engine for the current media.
    167     virtual bool supportsAcceleratedRendering() const = 0;
    168 
    169     virtual bool hasSingleSecurityOrigin() const = 0;
    170 
    171     virtual bool didPassCORSAccessCheck() const = 0;
    172 
    173     // Time value in the movie's time scale. It is only necessary to override this if the media
    174     // engine uses rational numbers to represent media time.
    175     virtual double mediaTimeForTimeValue(double timeValue) const = 0;
    176 
    177     virtual unsigned decodedFrameCount() const = 0;
    178     virtual unsigned droppedFrameCount() const = 0;
    179     virtual unsigned audioDecodedByteCount() const = 0;
    180     virtual unsigned videoDecodedByteCount() const = 0;
    181 
    182 #if ENABLE(WEB_AUDIO)
    183     virtual AudioSourceProvider* audioSourceProvider() = 0;
    184 #endif
    185 
    186     enum MediaKeyException { NoError, InvalidPlayerState, KeySystemNotSupported };
    187     virtual MediaKeyException addKey(const String&, const unsigned char*, unsigned, const unsigned char*, unsigned, const String&) = 0;
    188     virtual MediaKeyException generateKeyRequest(const String&, const unsigned char*, unsigned) = 0;
    189     virtual MediaKeyException cancelKeyRequest(const String&, const String&) = 0;
    190 };
    191 
    192 }
    193 
    194 #endif // MediaPlayer_h
    195