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 "public/platform/WebMediaPlayer.h"
     32 #include "wtf/Forward.h"
     33 #include "wtf/Noncopyable.h"
     34 
     35 namespace blink {
     36 class WebGraphicsContext3D;
     37 class WebContentDecryptionModule;
     38 class WebInbandTextTrack;
     39 class WebLayer;
     40 class WebMediaSource;
     41 }
     42 
     43 namespace WebCore {
     44 
     45 class AudioSourceProvider;
     46 class GraphicsContext;
     47 class IntRect;
     48 class KURL;
     49 class MediaPlayer;
     50 class TimeRanges;
     51 
     52 // GL types as defined in OpenGL ES 2.0 header file gl2.h from khronos.org.
     53 // That header cannot be included directly due to a conflict with NPAPI headers.
     54 // See crbug.com/328085.
     55 typedef unsigned GC3Denum;
     56 typedef int GC3Dint;
     57 
     58 class MediaPlayerClient {
     59 public:
     60     virtual ~MediaPlayerClient() { }
     61 
     62     // the network state has changed
     63     virtual void mediaPlayerNetworkStateChanged() = 0;
     64 
     65     // the ready state has changed
     66     virtual void mediaPlayerReadyStateChanged() = 0;
     67 
     68     // time has jumped, eg. not as a result of normal playback
     69     virtual void mediaPlayerTimeChanged() = 0;
     70 
     71     // the media file duration has changed, or is now known
     72     virtual void mediaPlayerDurationChanged() = 0;
     73 
     74     // the play/pause status changed
     75     virtual void mediaPlayerPlaybackStateChanged() = 0;
     76 
     77     virtual void mediaPlayerRequestFullscreen() = 0;
     78 
     79     virtual void mediaPlayerRequestSeek(double) = 0;
     80 
     81     // The URL for video poster image.
     82     // FIXME: Remove this when WebMediaPlayerClientImpl::loadInternal does not depend on it.
     83     virtual KURL mediaPlayerPosterURL() = 0;
     84 
     85 // Presentation-related methods
     86     // a new frame of video is available
     87     virtual void mediaPlayerRepaint() = 0;
     88 
     89     // the movie size has changed
     90     virtual void mediaPlayerSizeChanged() = 0;
     91 
     92     virtual void mediaPlayerSetWebLayer(blink::WebLayer*) = 0;
     93 
     94     virtual void mediaPlayerDidAddTextTrack(blink::WebInbandTextTrack*) = 0;
     95     virtual void mediaPlayerDidRemoveTextTrack(blink::WebInbandTextTrack*) = 0;
     96 
     97     virtual void mediaPlayerMediaSourceOpened(blink::WebMediaSource*) = 0;
     98 };
     99 
    100 typedef PassOwnPtr<MediaPlayer> (*CreateMediaEnginePlayer)(MediaPlayerClient*);
    101 
    102 class PLATFORM_EXPORT MediaPlayer {
    103     WTF_MAKE_NONCOPYABLE(MediaPlayer);
    104 public:
    105     static PassOwnPtr<MediaPlayer> create(MediaPlayerClient*);
    106     static void setMediaEngineCreateFunction(CreateMediaEnginePlayer);
    107 
    108     static double invalidTime() { return -1.0; }
    109 
    110     MediaPlayer() { }
    111     virtual ~MediaPlayer() { }
    112 
    113     virtual void load(blink::WebMediaPlayer::LoadType, const String& url, blink::WebMediaPlayer::CORSMode) = 0;
    114 
    115     virtual void play() = 0;
    116     virtual void pause() = 0;
    117 
    118     virtual bool supportsSave() const = 0;
    119 
    120     virtual double duration() const = 0;
    121 
    122     virtual double currentTime() const = 0;
    123 
    124     virtual void seek(double) = 0;
    125 
    126     virtual bool seeking() const = 0;
    127 
    128     virtual double rate() const = 0;
    129     virtual void setRate(double) = 0;
    130 
    131     virtual bool paused() const = 0;
    132 
    133     virtual void setPoster(const KURL&) = 0;
    134 
    135     enum NetworkState { Empty, Idle, Loading, Loaded, FormatError, NetworkError, DecodeError };
    136     virtual NetworkState networkState() const = 0;
    137 
    138     virtual double maxTimeSeekable() const = 0;
    139     virtual PassRefPtr<TimeRanges> buffered() const = 0;
    140 
    141     virtual bool didLoadingProgress() const = 0;
    142 
    143     virtual void paint(GraphicsContext*, const IntRect&) = 0;
    144     virtual bool copyVideoTextureToPlatformTexture(blink::WebGraphicsContext3D*, Platform3DObject, GC3Dint, GC3Denum, GC3Denum, bool, bool) = 0;
    145 
    146     enum Preload { None, MetaData, Auto };
    147     virtual void setPreload(Preload) = 0;
    148 
    149     virtual bool hasSingleSecurityOrigin() const = 0;
    150 
    151     // Time value in the movie's time scale. It is only necessary to override this if the media
    152     // engine uses rational numbers to represent media time.
    153     virtual double mediaTimeForTimeValue(double timeValue) const = 0;
    154 
    155 #if ENABLE(WEB_AUDIO)
    156     virtual AudioSourceProvider* audioSourceProvider() = 0;
    157 #endif
    158     virtual blink::WebMediaPlayer* webMediaPlayer() const = 0;
    159 };
    160 
    161 }
    162 
    163 #endif // MediaPlayer_h
    164