OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef WEBKIT_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ | |
6 #define WEBKIT_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ | |
7 | |
8 #include <jni.h> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/message_loop_proxy.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayer.h" | |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" | |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h" | |
17 | |
18 namespace WebKit { | |
19 class WebCookieJar; | |
20 class WebFrame; | |
21 } | |
22 | |
23 namespace media { | |
24 class MediaPlayerBridge; | |
25 } | |
26 | |
27 namespace webkit_media { | |
28 | |
29 class WebMediaPlayerProxyAndroid; | |
30 | |
31 // This class serves as the android implementation of WebKit::WebMediaPlayer. | |
32 // It implements all the playback functions by forwarding calls to android | |
33 // media player, and reports player state changes to the webkit. | |
34 class WebMediaPlayerAndroid : public WebKit::WebMediaPlayer { | |
35 public: | |
36 WebMediaPlayerAndroid(WebKit::WebFrame* frame, | |
37 WebKit::WebMediaPlayerClient* client, | |
38 WebKit::WebCookieJar* cookie_jar); | |
39 virtual ~WebMediaPlayerAndroid() OVERRIDE; | |
40 | |
41 // Set |incognito_mode_| to true if in incognito mode. | |
42 static void InitIncognito(bool incognito_mode); | |
43 | |
44 // Resource loading. | |
45 virtual void load(const WebKit::WebURL& url) OVERRIDE; | |
46 virtual void cancelLoad() OVERRIDE; | |
47 | |
48 // Playback controls. | |
49 virtual void play() OVERRIDE; | |
50 virtual void pause() OVERRIDE; | |
51 virtual void seek(float seconds) OVERRIDE; | |
52 virtual bool supportsFullscreen() const OVERRIDE; | |
53 virtual bool supportsSave() const OVERRIDE; | |
54 virtual void setEndTime(float seconds) OVERRIDE; | |
55 virtual void setRate(float rate) OVERRIDE; | |
56 virtual void setVolume(float volume) OVERRIDE; | |
57 virtual void setVisible(bool visible) OVERRIDE; | |
58 virtual bool totalBytesKnown() OVERRIDE; | |
59 virtual const WebKit::WebTimeRanges& buffered() OVERRIDE; | |
60 virtual float maxTimeSeekable() const OVERRIDE; | |
61 | |
62 // Methods for painting. | |
63 virtual void setSize(const WebKit::WebSize& size) OVERRIDE; | |
64 virtual void paint( | |
65 WebKit::WebCanvas* canvas, const WebKit::WebRect& rect) OVERRIDE; | |
66 | |
67 // True if the loaded media has a playable video/audio track. | |
68 virtual bool hasVideo() const OVERRIDE; | |
69 virtual bool hasAudio() const OVERRIDE; | |
70 | |
71 // Dimensions of the video. | |
72 virtual WebKit::WebSize naturalSize() const OVERRIDE; | |
73 | |
74 // Getters of playback state. | |
75 virtual bool paused() const OVERRIDE; | |
76 virtual bool seeking() const OVERRIDE; | |
77 virtual float duration() const OVERRIDE; | |
78 virtual float currentTime() const OVERRIDE; | |
79 | |
80 // Get rate of loading the resource. | |
81 virtual int32 dataRate() const OVERRIDE; | |
82 | |
83 virtual unsigned long long bytesLoaded() const OVERRIDE; | |
84 virtual unsigned long long totalBytes() const OVERRIDE; | |
85 | |
86 // Internal states of loading and network. | |
87 virtual WebKit::WebMediaPlayer::NetworkState networkState() const OVERRIDE; | |
88 virtual WebKit::WebMediaPlayer::ReadyState readyState() const OVERRIDE; | |
89 | |
90 virtual bool hasSingleSecurityOrigin() const OVERRIDE; | |
91 virtual WebKit::WebMediaPlayer::MovieLoadType movieLoadType() const OVERRIDE; | |
92 | |
93 virtual float mediaTimeForTimeValue(float timeValue) const OVERRIDE; | |
94 | |
95 // Provide statistics. | |
96 virtual unsigned decodedFrameCount() const OVERRIDE; | |
97 virtual unsigned droppedFrameCount() const OVERRIDE; | |
98 virtual unsigned audioDecodedByteCount() const OVERRIDE; | |
99 virtual unsigned videoDecodedByteCount() const OVERRIDE; | |
100 | |
101 // Methods called from VideoLayerChromium. These methods are running on the | |
102 // composite thread if useThreadedCompositor flag is set. | |
scherkus (not reviewing)
2012/04/17 03:57:31
s/composite/compositor
scherkus (not reviewing)
2012/04/17 03:57:31
what is useThreadedCompositor? I don't see this fl
qinmin
2012/04/18 20:06:30
Done.
qinmin
2012/04/18 20:06:30
This flag is outdated. When compositor thread was
| |
103 virtual WebKit::WebVideoFrame* getCurrentFrame() OVERRIDE; | |
104 virtual void putCurrentFrame(WebKit::WebVideoFrame*) OVERRIDE; | |
105 | |
106 // Media player callback handlers. | |
107 void OnMediaPrepared(); | |
scherkus (not reviewing)
2012/04/17 03:57:31
do these need OVERRIDE or are they callbacks?
qinmin
2012/04/18 20:06:30
No, OVERRIDE is only for inherited methods. These
| |
108 void OnPlaybackComplete(); | |
109 void OnBufferingUpdate(int percentage); | |
110 void OnSeekComplete(); | |
111 void OnMediaError(int error_type); | |
112 void OnMediaInfo(int info_type); | |
113 void OnVideoSizeChanged(int width, int height); | |
114 | |
115 // Method to set the video surface for android media player. | |
116 void SetVideoSurface(jobject j_surface); | |
117 | |
118 private: | |
119 // In case |media_player_| is deleted, we call this function to get | |
scherkus (not reviewing)
2012/04/17 03:57:31
this comment is inaccurate -- the real reason why
qinmin
2012/04/18 20:06:30
For this change, you are right. But for the upcomi
| |
120 // a new media_player_. | |
121 void InitializeMediaPlayer(); | |
122 | |
123 // Ask the media player to load the url and start prepareAsync. | |
124 void LoadUrl(WebKit::WebURL url); | |
scherkus (not reviewing)
2012/04/17 03:57:31
why bother having the arg? you always pass url_, w
qinmin
2012/04/18 20:06:30
Done.
| |
125 | |
126 // Functions that implements media player control. | |
127 void PlayInternal(); | |
128 void PauseInternal(); | |
129 void SeekInternal(float seconds); | |
130 | |
131 // Helper methods for posting task for setting states and update WebKit. | |
132 void UpdateNetworkState(WebKit::WebMediaPlayer::NetworkState state); | |
133 void UpdateReadyState(WebKit::WebMediaPlayer::ReadyState state); | |
134 | |
135 // whether the current process is incognito mode | |
136 static bool incognito_mode_; | |
137 | |
138 WebKit::WebFrame* const frame_; | |
139 WebKit::WebMediaPlayerClient* const client_; | |
140 | |
141 // Message loops for posting tasks to render thread. | |
142 scoped_refptr<base::MessageLoopProxy> render_message_loop_; | |
143 | |
144 // Save the list of buffered time ranges. | |
145 WebKit::WebTimeRanges time_ranges_; | |
146 | |
147 // Bridge to the android media player. | |
148 scoped_ptr<media::MediaPlayerBridge> media_player_; | |
149 | |
150 // Size of the media element. | |
151 WebKit::WebSize texture_size_; | |
152 | |
153 // Size of the video. | |
154 WebKit::WebSize natural_size_; | |
155 | |
156 // The video frame object used for renderering by WebKit. | |
157 scoped_ptr<WebKit::WebVideoFrame> video_frame_; | |
158 | |
159 // Proxy object that delegates method calls on Render Thread. | |
160 // This object is created on the Render Thread and is only called in the | |
161 // destructor. | |
162 scoped_refptr<WebMediaPlayerProxyAndroid> proxy_; | |
163 | |
164 // If this is set to true, prepare of the media player is done. | |
165 bool prepared_; | |
166 | |
167 // URL of the media file to be fetched. | |
168 WebKit::WebURL url_; | |
169 | |
170 // Media duration. | |
171 float duration_; | |
172 | |
173 // When switching tabs, we release the media player. This variable keeps | |
174 // track of the current playback time so that a seek will be performed | |
175 // next time the media player gets recreated. | |
176 float time_to_seek_; | |
177 | |
178 // Internal seek state. | |
179 bool seeking_; | |
180 | |
181 // the current playing time. | |
182 float current_time_; | |
183 | |
184 // Fake it by self increasing on every OnBufferingUpdate event. | |
185 int64 buffered_bytes_; | |
186 | |
187 // Pointer to the cookie jar to get the cookie for the media url. | |
188 WebKit::WebCookieJar* cookie_jar_; | |
189 | |
190 // Whether the user has clicked the play button while media player | |
191 // is preparing. | |
192 bool pending_play_event_; | |
193 | |
194 // Whether we skipped loading the media. | |
195 bool skip_loading_; | |
196 | |
197 // Current player states. | |
198 WebKit::WebMediaPlayer::NetworkState network_state_; | |
199 WebKit::WebMediaPlayer::ReadyState ready_state_; | |
200 | |
201 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid); | |
202 }; | |
203 | |
204 } // namespace webkit_media | |
205 | |
206 #endif // WEBKIT_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ | |
OLD | NEW |