Home | History | Annotate | Download | only in public
      1 /*
      2  * Copyright (C) 2009 Google 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 are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #ifndef WebMediaPlayer_h
     32 #define WebMediaPlayer_h
     33 
     34 #include "WebCanvas.h"
     35 #include "WebVector.h"
     36 #include "WebVideoFrame.h"
     37 
     38 namespace WebKit {
     39 
     40 class WebMediaPlayerClient;
     41 class WebURL;
     42 struct WebRect;
     43 struct WebSize;
     44 
     45 struct WebTimeRange {
     46     WebTimeRange() : start(0), end(0) {}
     47     WebTimeRange(float s, float e) : start(s), end(e) {}
     48 
     49     float start;
     50     float end;
     51 };
     52 
     53 typedef WebVector<WebTimeRange> WebTimeRanges;
     54 
     55 class WebMediaPlayer {
     56 public:
     57     enum NetworkState {
     58         Empty,
     59         Idle,
     60         Loading,
     61         Loaded,
     62         FormatError,
     63         NetworkError,
     64         DecodeError,
     65     };
     66 
     67     enum ReadyState {
     68         HaveNothing,
     69         HaveMetadata,
     70         HaveCurrentData,
     71         HaveFutureData,
     72         HaveEnoughData,
     73     };
     74 
     75     enum MovieLoadType {
     76         Unknown,
     77         Download,
     78         StoredStream,
     79         LiveStream,
     80     };
     81 
     82     enum Preload {
     83         None,
     84         MetaData,
     85         Auto,
     86     };
     87 
     88     virtual ~WebMediaPlayer() {}
     89 
     90     virtual void load(const WebURL&) = 0;
     91     virtual void cancelLoad() = 0;
     92 
     93     // Playback controls.
     94     virtual void play() = 0;
     95     virtual void pause() = 0;
     96     virtual bool supportsFullscreen() const = 0;
     97     virtual bool supportsSave() const = 0;
     98     virtual void seek(float seconds) = 0;
     99     virtual void setEndTime(float seconds) = 0;
    100     virtual void setRate(float) = 0;
    101     virtual void setVolume(float) = 0;
    102     virtual void setVisible(bool) = 0;
    103     virtual void setPreload(Preload) { };
    104     virtual bool totalBytesKnown() = 0;
    105     virtual const WebTimeRanges& buffered() = 0;
    106     virtual float maxTimeSeekable() const = 0;
    107 
    108     virtual void setSize(const WebSize&) = 0;
    109 
    110     virtual void paint(WebCanvas*, const WebRect&) = 0;
    111 
    112     // True if the loaded media has a playable video/audio track.
    113     virtual bool hasVideo() const = 0;
    114     virtual bool hasAudio() const = 0;
    115 
    116     // Dimension of the video.
    117     virtual WebSize naturalSize() const = 0;
    118 
    119     // Getters of playback state.
    120     virtual bool paused() const = 0;
    121     virtual bool seeking() const = 0;
    122     virtual float duration() const = 0;
    123     virtual float currentTime() const = 0;
    124 
    125     // Get rate of loading the resource.
    126     virtual int dataRate() const = 0;
    127 
    128     // Internal states of loading and network.
    129     virtual NetworkState networkState() const = 0;
    130     virtual ReadyState readyState() const = 0;
    131 
    132     virtual unsigned long long bytesLoaded() const = 0;
    133     virtual unsigned long long totalBytes() const = 0;
    134 
    135     virtual bool hasSingleSecurityOrigin() const = 0;
    136     virtual MovieLoadType movieLoadType() const = 0;
    137 
    138     virtual unsigned decodedFrameCount() const = 0;
    139     virtual unsigned droppedFrameCount() const = 0;
    140     virtual unsigned audioDecodedByteCount() const = 0;
    141     virtual unsigned videoDecodedByteCount() const = 0;
    142 
    143     // This function returns a pointer to a WebVideoFrame, which is
    144     // a WebKit wrapper for a video frame in chromium. This places a lock
    145     // on the frame in chromium, and calls to this method should always be
    146     // followed with a call to putCurrentFrame(). The ownership of this object
    147     // is not transferred to the caller, and the caller should not free the
    148     // returned object.
    149     virtual WebVideoFrame* getCurrentFrame() { return 0; }
    150     // This function releases the lock on the current video frame in Chromium.
    151     // It should always be called after getCurrentFrame(). Frame passed to this
    152     // method should no longer be referenced after the call is made.
    153     virtual void putCurrentFrame(WebVideoFrame*) { }
    154 };
    155 
    156 } // namespace WebKit
    157 
    158 #endif
    159