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

Side by Side Diff: media/base/android/media_player_bridge.h

Issue 12595005: Parsing filesystem url before giving it to media player (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixing nits Created 7 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_BASE_ANDROID_MEDIA_PLAYER_BRIDGE_H_ 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_PLAYER_BRIDGE_H_
6 #define MEDIA_BASE_ANDROID_MEDIA_PLAYER_BRIDGE_H_ 6 #define MEDIA_BASE_ANDROID_MEDIA_PLAYER_BRIDGE_H_
7 7
8 #include <jni.h> 8 #include <jni.h>
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 11
12 #include "base/android/scoped_java_ref.h" 12 #include "base/android/scoped_java_ref.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/string_util.h"
palmer 2013/03/18 19:54:34 Do you need this?
qinmin 2013/03/18 22:27:59 removed. On 2013/03/18 19:54:34, Chris P. wrote:
16 #include "base/time.h" 17 #include "base/time.h"
17 #include "base/timer.h" 18 #include "base/timer.h"
19 #include "googleurl/src/gurl.h"
18 #include "media/base/media_export.h" 20 #include "media/base/media_export.h"
19 #include "media/base/android/media_player_listener.h" 21 #include "media/base/android/media_player_listener.h"
20 22
21 namespace media { 23 namespace media {
22 24
23 class CookieGetter; 25 class MediaResourceGetter;
24 class MediaPlayerBridgeManager; 26 class MediaPlayerBridgeManager;
25 27
26 // This class serves as a bridge for native code to call java functions inside 28 // This class serves as a bridge for native code to call java functions inside
27 // android mediaplayer class. For more information on android mediaplayer, check 29 // android mediaplayer class. For more information on android mediaplayer, check
28 // http://developer.android.com/reference/android/media/MediaPlayer.html 30 // http://developer.android.com/reference/android/media/MediaPlayer.html
29 // The actual android mediaplayer instance is created lazily when Start(), 31 // The actual android mediaplayer instance is created lazily when Start(),
30 // Pause(), SeekTo() gets called. As a result, media information may not 32 // Pause(), SeekTo() gets called. As a result, media information may not
31 // be available until one of those operations is performed. After that, we 33 // be available until one of those operations is performed. After that, we
32 // will cache those information in case the mediaplayer gets released. 34 // will cache those information in case the mediaplayer gets released.
33 class MEDIA_EXPORT MediaPlayerBridge { 35 class MEDIA_EXPORT MediaPlayerBridge {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 typedef base::Callback<void(int, base::TimeDelta)> TimeUpdateCB; 69 typedef base::Callback<void(int, base::TimeDelta)> TimeUpdateCB;
68 70
69 static bool RegisterMediaPlayerBridge(JNIEnv* env); 71 static bool RegisterMediaPlayerBridge(JNIEnv* env);
70 72
71 // Construct a MediaPlayerBridge object with all the needed media player 73 // Construct a MediaPlayerBridge object with all the needed media player
72 // callbacks. This object needs to call |manager|'s RequestMediaResources() 74 // callbacks. This object needs to call |manager|'s RequestMediaResources()
73 // before decoding the media stream. This allows |manager| to track 75 // before decoding the media stream. This allows |manager| to track
74 // unused resources and free them when needed. On the other hand, it needs 76 // unused resources and free them when needed. On the other hand, it needs
75 // to call ReleaseMediaResources() when it is done with decoding. 77 // to call ReleaseMediaResources() when it is done with decoding.
76 MediaPlayerBridge(int player_id, 78 MediaPlayerBridge(int player_id,
77 const std::string& url, 79 const GURL& url,
palmer 2013/03/18 19:54:34 Thanks for changing from string to GURL, btw.
78 const std::string& first_party_for_cookies, 80 const GURL& first_party_for_cookies,
79 CookieGetter* cookie_getter, 81 MediaResourceGetter* resource_getter,
80 bool hide_url_log, 82 bool hide_url_log,
81 MediaPlayerBridgeManager* manager, 83 MediaPlayerBridgeManager* manager,
82 const MediaErrorCB& media_error_cb, 84 const MediaErrorCB& media_error_cb,
83 const VideoSizeChangedCB& video_size_changed_cb, 85 const VideoSizeChangedCB& video_size_changed_cb,
84 const BufferingUpdateCB& buffering_update_cb, 86 const BufferingUpdateCB& buffering_update_cb,
85 const MediaPreparedCB& media_prepared_cb, 87 const MediaPreparedCB& media_prepared_cb,
86 const PlaybackCompleteCB& playback_complete_cb, 88 const PlaybackCompleteCB& playback_complete_cb,
87 const SeekCompleteCB& seek_complete_cb, 89 const SeekCompleteCB& seek_complete_cb,
88 const TimeUpdateCB& time_update_cb, 90 const TimeUpdateCB& time_update_cb,
89 const MediaInterruptedCB& media_interrupted_cb); 91 const MediaInterruptedCB& media_interrupted_cb);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 void OnPlaybackComplete(); 133 void OnPlaybackComplete();
132 void OnSeekComplete(); 134 void OnSeekComplete();
133 void OnMediaPrepared(); 135 void OnMediaPrepared();
134 void OnMediaInterrupted(); 136 void OnMediaInterrupted();
135 137
136 // Prepare the player for playback, asynchronously. When succeeds, 138 // Prepare the player for playback, asynchronously. When succeeds,
137 // OnMediaPrepared() will be called. Otherwise, OnMediaError() will 139 // OnMediaPrepared() will be called. Otherwise, OnMediaError() will
138 // be called with an error type. 140 // be called with an error type.
139 void Prepare(); 141 void Prepare();
140 142
141 // Callback function passed to |cookies_retriever_|. 143 // Callback function passed to |resource_getter_|.
142 void GetCookiesCallback(const std::string& cookies); 144 void GetCookiesCallback(const std::string& cookies);
143 145
144 int player_id() { return player_id_; } 146 int player_id() { return player_id_; }
145 bool can_pause() { return can_pause_; } 147 bool can_pause() { return can_pause_; }
146 bool can_seek_forward() { return can_seek_forward_; } 148 bool can_seek_forward() { return can_seek_forward_; }
147 bool can_seek_backward() { return can_seek_backward_; } 149 bool can_seek_backward() { return can_seek_backward_; }
148 bool prepared() { return prepared_; } 150 bool prepared() { return prepared_; }
149 151
150 private: 152 private:
151 // Create the actual android media player. 153 // Create the actual android media player.
152 void InitializePlayer(); 154 void InitializePlayer();
153 155
156 // Set the data source for the media player.
157 void SetDataSource(const std::string& url);
158
154 // Functions that implements media player control. 159 // Functions that implements media player control.
155 void StartInternal(); 160 void StartInternal();
156 void PauseInternal(); 161 void PauseInternal();
157 void SeekInternal(base::TimeDelta time); 162 void SeekInternal(base::TimeDelta time);
158 163
159 // Callbacks when events are received. 164 // Callbacks when events are received.
160 MediaErrorCB media_error_cb_; 165 MediaErrorCB media_error_cb_;
161 VideoSizeChangedCB video_size_changed_cb_; 166 VideoSizeChangedCB video_size_changed_cb_;
162 BufferingUpdateCB buffering_update_cb_; 167 BufferingUpdateCB buffering_update_cb_;
163 MediaPreparedCB media_prepared_cb_; 168 MediaPreparedCB media_prepared_cb_;
(...skipping 10 matching lines...) Expand all
174 // Whether the player is prepared for playback. 179 // Whether the player is prepared for playback.
175 bool prepared_; 180 bool prepared_;
176 181
177 // Pending play event while player is preparing. 182 // Pending play event while player is preparing.
178 bool pending_play_; 183 bool pending_play_;
179 184
180 // Pending seek time while player is preparing. 185 // Pending seek time while player is preparing.
181 base::TimeDelta pending_seek_; 186 base::TimeDelta pending_seek_;
182 187
183 // Url for playback. 188 // Url for playback.
184 std::string url_; 189 GURL url_;
185 190
186 // First party url for cookies. 191 // First party url for cookies.
187 std::string first_party_for_cookies_; 192 GURL first_party_for_cookies_;
188 193
189 // Whether cookies are available. 194 // Whether cookies are available.
190 bool has_cookies_; 195 bool has_cookies_;
191 196
192 // Hide url log from media player. 197 // Hide url log from media player.
193 bool hide_url_log_; 198 bool hide_url_log_;
194 199
195 // Stats about the media. 200 // Stats about the media.
196 base::TimeDelta duration_; 201 base::TimeDelta duration_;
197 int width_; 202 int width_;
198 int height_; 203 int height_;
199 204
200 // Meta data about actions can be taken. 205 // Meta data about actions can be taken.
201 bool can_pause_; 206 bool can_pause_;
202 bool can_seek_forward_; 207 bool can_seek_forward_;
203 bool can_seek_backward_; 208 bool can_seek_backward_;
204 209
205 // Cookies for |url_| 210 // Cookies for |url_|.
206 std::string cookies_; 211 std::string cookies_;
207 212
208 // Resource manager for all the media players. 213 // Resource manager for all the media players.
209 MediaPlayerBridgeManager* manager_; 214 MediaPlayerBridgeManager* manager_;
210 215
211 // Object for retrieving cookies for this media player. 216 // Object for retrieving resources for this media player.
212 scoped_ptr<CookieGetter> cookie_getter_; 217 scoped_ptr<MediaResourceGetter> resource_getter_;
213 218
214 // Java MediaPlayer instance. 219 // Java MediaPlayer instance.
215 base::android::ScopedJavaGlobalRef<jobject> j_media_player_; 220 base::android::ScopedJavaGlobalRef<jobject> j_media_player_;
216 221
217 base::RepeatingTimer<MediaPlayerBridge> time_update_timer_; 222 base::RepeatingTimer<MediaPlayerBridge> time_update_timer_;
218 223
219 // Weak pointer passed to |listener_| for callbacks. 224 // Weak pointer passed to |listener_| for callbacks.
220 base::WeakPtrFactory<MediaPlayerBridge> weak_this_; 225 base::WeakPtrFactory<MediaPlayerBridge> weak_this_;
221 226
222 // Listener object that listens to all the media player events. 227 // Listener object that listens to all the media player events.
223 MediaPlayerListener listener_; 228 MediaPlayerListener listener_;
224 229
225 DISALLOW_COPY_AND_ASSIGN(MediaPlayerBridge); 230 DISALLOW_COPY_AND_ASSIGN(MediaPlayerBridge);
226 }; 231 };
227 232
228 } // namespace media 233 } // namespace media
229 234
230 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_BRIDGE_H_ 235 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_BRIDGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698