Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: webkit/media/android/webmediaplayer_android.h

Issue 10073016: Upstream WebMediaPlayerAndroid as WebKit::WebMediaPlayer implementation on android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: small changes to address comments Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | webkit/media/android/webmediaplayer_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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(WebKit::WebCanvas* canvas,
66 const WebKit::WebRect& rect,
67 uint8_t alpha) OVERRIDE;
68
69 // True if the loaded media has a playable video/audio track.
70 virtual bool hasVideo() const OVERRIDE;
71 virtual bool hasAudio() const OVERRIDE;
72
73 // Dimensions of the video.
74 virtual WebKit::WebSize naturalSize() const OVERRIDE;
75
76 // Getters of playback state.
77 virtual bool paused() const OVERRIDE;
78 virtual bool seeking() const OVERRIDE;
79 virtual float duration() const OVERRIDE;
80 virtual float currentTime() const OVERRIDE;
81
82 // Get rate of loading the resource.
83 virtual int32 dataRate() const OVERRIDE;
84
85 virtual unsigned long long bytesLoaded() const OVERRIDE;
86 virtual unsigned long long totalBytes() const OVERRIDE;
87
88 // Internal states of loading and network.
89 virtual WebKit::WebMediaPlayer::NetworkState networkState() const OVERRIDE;
90 virtual WebKit::WebMediaPlayer::ReadyState readyState() const OVERRIDE;
91
92 virtual bool hasSingleSecurityOrigin() const OVERRIDE;
93 virtual WebKit::WebMediaPlayer::MovieLoadType movieLoadType() const OVERRIDE;
94
95 virtual float mediaTimeForTimeValue(float timeValue) const OVERRIDE;
96
97 // Provide statistics.
98 virtual unsigned decodedFrameCount() const OVERRIDE;
99 virtual unsigned droppedFrameCount() const OVERRIDE;
100 virtual unsigned audioDecodedByteCount() const OVERRIDE;
101 virtual unsigned videoDecodedByteCount() const OVERRIDE;
102
103 // Methods called from VideoLayerChromium. These methods are running on the
104 // compositor thread.
105 virtual WebKit::WebVideoFrame* getCurrentFrame() OVERRIDE;
106 virtual void putCurrentFrame(WebKit::WebVideoFrame*) OVERRIDE;
107
108 // Media player callback handlers.
109 void OnMediaPrepared();
110 void OnPlaybackComplete();
111 void OnBufferingUpdate(int percentage);
112 void OnSeekComplete();
113 void OnMediaError(int error_type);
114 void OnMediaInfo(int info_type);
115 void OnVideoSizeChanged(int width, int height);
116
117 // Method to set the video surface for android media player.
118 void SetVideoSurface(jobject j_surface);
119
120 private:
121 // Create a media player to load the |url_| and prepare for playback.
122 // Because of limited decoding resources on mobile devices, idle media players
123 // could get released. In that case, we call this function to get a new media
124 // player when needed.
125 void InitializeMediaPlayer();
126
127 // Functions that implements media player control.
128 void PlayInternal();
129 void PauseInternal();
130 void SeekInternal(float seconds);
131
132 // Helper methods for posting task for setting states and update WebKit.
133 void UpdateNetworkState(WebKit::WebMediaPlayer::NetworkState state);
134 void UpdateReadyState(WebKit::WebMediaPlayer::ReadyState state);
135
136 // whether the current process is incognito mode
137 static bool incognito_mode_;
138
139 WebKit::WebMediaPlayerClient* const client_;
140
141 // Save the list of buffered time ranges.
142 WebKit::WebTimeRanges buffered_;
143
144 // Bridge to the android media player.
145 scoped_ptr<media::MediaPlayerBridge> media_player_;
146
147 // Size of the media element.
148 WebKit::WebSize texture_size_;
149
150 // Size of the video.
151 WebKit::WebSize natural_size_;
152
153 // The video frame object used for renderering by WebKit.
154 scoped_ptr<WebKit::WebVideoFrame> video_frame_;
155
156 // Proxy object that delegates method calls on Render Thread.
157 // This object is created on the Render Thread and is only called in the
158 // destructor.
159 scoped_refptr<WebMediaPlayerProxyAndroid> proxy_;
160
161 // If this is set to true, prepare of the media player is done.
162 bool prepared_;
163
164 // URL of the media file to be fetched.
165 GURL url_;
166
167 // Media duration.
168 float duration_;
169
170 // When switching tabs, we release the media player. This variable keeps
171 // track of the current playback time so that a seek will be performed
172 // next time the media player gets recreated.
173 float pending_seek_;
174
175 // Internal seek state.
176 bool seeking_;
177
178 // Whether playback has completed.
179 float playback_completed_;
180
181 // Fake it by self increasing on every OnBufferingUpdate event.
182 int64 buffered_bytes_;
183
184 // Pointer to the cookie jar to get the cookie for the media url.
185 WebKit::WebCookieJar* cookie_jar_;
186
187 // Whether the user has clicked the play button while media player
188 // is preparing.
189 bool pending_play_event_;
190
191 // Current player states.
192 WebKit::WebMediaPlayer::NetworkState network_state_;
193 WebKit::WebMediaPlayer::ReadyState ready_state_;
194
195 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid);
196 };
197
198 } // namespace webkit_media
199
200 #endif // WEBKIT_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_
OLDNEW
« no previous file with comments | « no previous file | webkit/media/android/webmediaplayer_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698