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