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 "base/memory/weak_ptr.h" | |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayer.h" | |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" | |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h" | |
18 | |
19 namespace WebKit { | |
20 class WebCookieJar; | |
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 : | |
35 public WebKit::WebMediaPlayer, | |
36 public base::SupportsWeakPtr<WebMediaPlayerAndroid> { | |
37 public: | |
38 WebMediaPlayerAndroid(WebKit::WebMediaPlayerClient* client, | |
39 WebKit::WebCookieJar* cookie_jar); | |
40 virtual ~WebMediaPlayerAndroid() OVERRIDE; | |
41 | |
42 // Set |incognito_mode_| to true if in incognito mode. | |
43 static void InitIncognito(bool incognito_mode); | |
44 | |
45 // Resource loading. | |
46 virtual void load(const WebKit::WebURL& url) OVERRIDE; | |
47 virtual void cancelLoad() OVERRIDE; | |
48 | |
49 // Playback controls. | |
50 virtual void play() OVERRIDE; | |
51 virtual void pause() OVERRIDE; | |
52 virtual void seek(float seconds) OVERRIDE; | |
53 virtual bool supportsFullscreen() const OVERRIDE; | |
54 virtual bool supportsSave() const OVERRIDE; | |
55 virtual void setEndTime(float seconds) OVERRIDE; | |
56 virtual void setRate(float rate) OVERRIDE; | |
57 virtual void setVolume(float volume) OVERRIDE; | |
58 virtual void setVisible(bool visible) OVERRIDE; | |
59 virtual bool totalBytesKnown() OVERRIDE; | |
60 virtual const WebKit::WebTimeRanges& buffered() OVERRIDE; | |
61 virtual float maxTimeSeekable() const OVERRIDE; | |
62 | |
63 // Methods for painting. | |
64 virtual void setSize(const WebKit::WebSize& size) OVERRIDE; | |
65 virtual void paint( | |
66 WebKit::WebCanvas* canvas, const WebKit::WebRect& rect) OVERRIDE; | |
67 | |
68 // True if the loaded media has a playable video/audio track. | |
69 virtual bool hasVideo() const OVERRIDE; | |
70 virtual bool hasAudio() const OVERRIDE; | |
71 | |
72 // Dimensions of the video. | |
73 virtual WebKit::WebSize naturalSize() const OVERRIDE; | |
74 | |
75 // Getters of playback state. | |
76 virtual bool paused() const OVERRIDE; | |
77 virtual bool seeking() const OVERRIDE; | |
78 virtual float duration() const OVERRIDE; | |
79 virtual float currentTime() const OVERRIDE; | |
80 | |
81 // Get rate of loading the resource. | |
82 virtual int32 dataRate() const OVERRIDE; | |
83 | |
84 virtual unsigned long long bytesLoaded() const OVERRIDE; | |
85 virtual unsigned long long totalBytes() const OVERRIDE; | |
86 | |
87 // Internal states of loading and network. | |
88 virtual WebKit::WebMediaPlayer::NetworkState networkState() const OVERRIDE; | |
89 virtual WebKit::WebMediaPlayer::ReadyState readyState() const OVERRIDE; | |
90 | |
91 virtual bool hasSingleSecurityOrigin() const OVERRIDE; | |
92 virtual WebKit::WebMediaPlayer::MovieLoadType movieLoadType() const OVERRIDE; | |
93 | |
94 virtual float mediaTimeForTimeValue(float timeValue) const OVERRIDE; | |
95 | |
96 // Provide statistics. | |
97 virtual unsigned decodedFrameCount() const OVERRIDE; | |
98 virtual unsigned droppedFrameCount() const OVERRIDE; | |
99 virtual unsigned audioDecodedByteCount() const OVERRIDE; | |
100 virtual unsigned videoDecodedByteCount() const OVERRIDE; | |
101 | |
102 // Methods called from VideoLayerChromium. These methods are running on the | |
103 // compositor thread. | |
104 virtual WebKit::WebVideoFrame* getCurrentFrame() OVERRIDE; | |
105 virtual void putCurrentFrame(WebKit::WebVideoFrame*) OVERRIDE; | |
106 | |
107 // Media player callback handlers. | |
108 void OnMediaPrepared(); | |
109 void OnPlaybackComplete(); | |
110 void OnBufferingUpdate(int percentage); | |
111 void OnSeekComplete(); | |
112 void OnMediaError(int error_type); | |
113 void OnMediaInfo(int info_type); | |
114 void OnVideoSizeChanged(int width, int height); | |
115 | |
116 // Method to set the video surface for android media player. | |
117 void SetVideoSurface(jobject j_surface); | |
118 | |
119 private: | |
120 // Create a media player to load the url_ and prepare for playback. | |
scherkus (not reviewing)
2012/04/21 03:02:05
nit: "the url_" -> "|url_|"
qinmin
2012/04/23 18:57:04
Done.
| |
121 // Because of limited decoding resources on mobile devices, idle media players | |
122 // could get released. In that case, we call this function to get a new media | |
123 // player when needed. | |
124 void InitializeMediaPlayer(); | |
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::WebMediaPlayerClient* const client_; | |
139 | |
140 // Save the list of buffered time ranges. | |
141 WebKit::WebTimeRanges time_ranges_; | |
142 | |
143 // Bridge to the android media player. | |
144 scoped_ptr<media::MediaPlayerBridge> media_player_; | |
145 | |
146 // Size of the media element. | |
147 WebKit::WebSize texture_size_; | |
148 | |
149 // Size of the video. | |
150 WebKit::WebSize natural_size_; | |
151 | |
152 // The video frame object used for renderering by WebKit. | |
153 scoped_ptr<WebKit::WebVideoFrame> video_frame_; | |
154 | |
155 // Proxy object that delegates method calls on Render Thread. | |
156 // This object is created on the Render Thread and is only called in the | |
157 // destructor. | |
158 scoped_refptr<WebMediaPlayerProxyAndroid> proxy_; | |
159 | |
160 // If this is set to true, prepare of the media player is done. | |
161 bool prepared_; | |
162 | |
163 // URL of the media file to be fetched. | |
164 GURL url_; | |
165 | |
166 // Media duration. | |
167 float duration_; | |
168 | |
169 // When switching tabs, we release the media player. This variable keeps | |
170 // track of the current playback time so that a seek will be performed | |
171 // next time the media player gets recreated. | |
172 float pending_seek_; | |
173 | |
174 // Internal seek state. | |
175 bool seeking_; | |
176 | |
177 // Whether playback has completed. | |
178 float playback_completed_; | |
179 | |
180 // Fake it by self increasing on every OnBufferingUpdate event. | |
181 int64 buffered_bytes_; | |
182 | |
183 // Pointer to the cookie jar to get the cookie for the media url. | |
184 WebKit::WebCookieJar* cookie_jar_; | |
185 | |
186 // Whether the user has clicked the play button while media player | |
187 // is preparing. | |
188 bool pending_play_event_; | |
189 | |
190 // Current player states. | |
191 WebKit::WebMediaPlayer::NetworkState network_state_; | |
192 WebKit::WebMediaPlayer::ReadyState ready_state_; | |
193 | |
194 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid); | |
195 }; | |
196 | |
197 } // namespace webkit_media | |
198 | |
199 #endif // WEBKIT_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ | |
OLD | NEW |