initial import
[vuplus_webkit] / Source / WebKit / chromium / public / WebMediaPlayer.h
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 WebAudioSourceProvider;
41 class WebMediaPlayerClient;
42 class WebURL;
43 struct WebRect;
44 struct WebSize;
45
46 struct WebTimeRange {
47     WebTimeRange() : start(0), end(0) {}
48     WebTimeRange(float s, float e) : start(s), end(e) {}
49
50     float start;
51     float end;
52 };
53
54 typedef WebVector<WebTimeRange> WebTimeRanges;
55
56 class WebMediaPlayer {
57 public:
58     enum NetworkState {
59         Empty,
60         Idle,
61         Loading,
62         Loaded,
63         FormatError,
64         NetworkError,
65         DecodeError,
66     };
67
68     enum ReadyState {
69         HaveNothing,
70         HaveMetadata,
71         HaveCurrentData,
72         HaveFutureData,
73         HaveEnoughData,
74     };
75
76     enum MovieLoadType {
77         Unknown,
78         Download,
79         StoredStream,
80         LiveStream,
81     };
82
83     enum Preload {
84         None,
85         MetaData,
86         Auto,
87     };
88
89     enum EndOfStreamStatus {
90         EosNoError,
91         EosNetworkError,
92         EosDecodeError,
93     };
94
95     virtual ~WebMediaPlayer() {}
96
97     virtual void load(const WebURL&) = 0;
98     virtual void cancelLoad() = 0;
99
100     // Playback controls.
101     virtual void play() = 0;
102     virtual void pause() = 0;
103     virtual bool supportsFullscreen() const = 0;
104     virtual bool supportsSave() const = 0;
105     virtual void seek(float seconds) = 0;
106     virtual void setEndTime(float seconds) = 0;
107     virtual void setRate(float) = 0;
108     virtual void setVolume(float) = 0;
109     virtual void setVisible(bool) = 0;
110     virtual void setPreload(Preload) { };
111     virtual bool totalBytesKnown() = 0;
112     virtual const WebTimeRanges& buffered() = 0;
113     virtual float maxTimeSeekable() const = 0;
114
115     virtual void setSize(const WebSize&) = 0;
116
117     virtual void paint(WebCanvas*, const WebRect&) = 0;
118
119     // True if the loaded media has a playable video/audio track.
120     virtual bool hasVideo() const = 0;
121     virtual bool hasAudio() const = 0;
122
123     // Dimension of the video.
124     virtual WebSize naturalSize() const = 0;
125
126     // Getters of playback state.
127     virtual bool paused() const = 0;
128     virtual bool seeking() const = 0;
129     virtual float duration() const = 0;
130     virtual float currentTime() const = 0;
131
132     // Get rate of loading the resource.
133     virtual int dataRate() const = 0;
134
135     // Internal states of loading and network.
136     virtual NetworkState networkState() const = 0;
137     virtual ReadyState readyState() const = 0;
138
139     virtual unsigned long long bytesLoaded() const = 0;
140     virtual unsigned long long totalBytes() const = 0;
141
142     virtual bool hasSingleSecurityOrigin() const = 0;
143     virtual MovieLoadType movieLoadType() const = 0;
144
145     virtual float mediaTimeForTimeValue(float timeValue) const = 0;
146
147     virtual unsigned decodedFrameCount() const = 0;
148     virtual unsigned droppedFrameCount() const = 0;
149     virtual unsigned audioDecodedByteCount() const = 0;
150     virtual unsigned videoDecodedByteCount() const = 0;
151
152     // This function returns a pointer to a WebVideoFrame, which is
153     // a WebKit wrapper for a video frame in chromium. This places a lock
154     // on the frame in chromium, and calls to this method should always be
155     // followed with a call to putCurrentFrame(). The ownership of this object
156     // is not transferred to the caller, and the caller should not free the
157     // returned object.
158     virtual WebVideoFrame* getCurrentFrame() { return 0; }
159     // This function releases the lock on the current video frame in Chromium.
160     // It should always be called after getCurrentFrame(). Frame passed to this
161     // method should no longer be referenced after the call is made.
162     virtual void putCurrentFrame(WebVideoFrame*) { }
163
164     virtual WebAudioSourceProvider* audioSourceProvider() { return 0; }
165
166     virtual bool sourceAppend(const unsigned char* data, unsigned length) { return false; }
167     virtual void sourceEndOfStream(EndOfStreamStatus)  { }
168 };
169
170 } // namespace WebKit
171
172 #endif