Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" | |
| 16 #include "base/time.h" | 17 #include "base/time.h" |
| 17 #include "base/timer.h" | 18 #include "base/timer.h" |
| 18 #include "media/base/media_export.h" | 19 #include "media/base/media_export.h" |
| 19 #include "media/base/android/media_player_listener.h" | 20 #include "media/base/android/media_player_listener.h" |
| 20 | 21 |
| 21 namespace media { | 22 namespace media { |
| 22 | 23 |
| 23 class CookieGetter; | 24 class MediaResourceGetter; |
| 24 class MediaPlayerBridgeManager; | 25 class MediaPlayerBridgeManager; |
| 25 | 26 |
| 26 // This class serves as a bridge for native code to call java functions inside | 27 // 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 | 28 // android mediaplayer class. For more information on android mediaplayer, check |
| 28 // http://developer.android.com/reference/android/media/MediaPlayer.html | 29 // http://developer.android.com/reference/android/media/MediaPlayer.html |
| 29 // The actual android mediaplayer instance is created lazily when Start(), | 30 // The actual android mediaplayer instance is created lazily when Start(), |
| 30 // Pause(), SeekTo() gets called. As a result, media information may not | 31 // Pause(), SeekTo() gets called. As a result, media information may not |
| 31 // be available until one of those operations is performed. After that, we | 32 // be available until one of those operations is performed. After that, we |
| 32 // will cache those information in case the mediaplayer gets released. | 33 // will cache those information in case the mediaplayer gets released. |
| 33 class MEDIA_EXPORT MediaPlayerBridge { | 34 class MEDIA_EXPORT MediaPlayerBridge { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 typedef base::Callback<void(int, base::TimeDelta)> TimeUpdateCB; | 68 typedef base::Callback<void(int, base::TimeDelta)> TimeUpdateCB; |
| 68 | 69 |
| 69 static bool RegisterMediaPlayerBridge(JNIEnv* env); | 70 static bool RegisterMediaPlayerBridge(JNIEnv* env); |
| 70 | 71 |
| 71 // Construct a MediaPlayerBridge object with all the needed media player | 72 // Construct a MediaPlayerBridge object with all the needed media player |
| 72 // callbacks. This object needs to call |manager|'s RequestMediaResources() | 73 // callbacks. This object needs to call |manager|'s RequestMediaResources() |
| 73 // before decoding the media stream. This allows |manager| to track | 74 // before decoding the media stream. This allows |manager| to track |
| 74 // unused resources and free them when needed. On the other hand, it needs | 75 // unused resources and free them when needed. On the other hand, it needs |
| 75 // to call ReleaseMediaResources() when it is done with decoding. | 76 // to call ReleaseMediaResources() when it is done with decoding. |
| 76 MediaPlayerBridge(int player_id, | 77 MediaPlayerBridge(int player_id, |
| 77 const std::string& url, | 78 const std::string& url, |
|
scherkus (not reviewing)
2013/03/08 21:26:27
hmm... it'd be nice to use a GURL instead of a str
qinmin
2013/03/08 22:36:12
Fixed.
I remember I tried to use GURL in the past
| |
| 78 const std::string& first_party_for_cookies, | 79 const std::string& first_party_for_cookies, |
| 79 CookieGetter* cookie_getter, | 80 MediaResourceGetter* resource_getter, |
| 80 bool hide_url_log, | 81 bool hide_url_log, |
| 81 MediaPlayerBridgeManager* manager, | 82 MediaPlayerBridgeManager* manager, |
| 82 const MediaErrorCB& media_error_cb, | 83 const MediaErrorCB& media_error_cb, |
| 83 const VideoSizeChangedCB& video_size_changed_cb, | 84 const VideoSizeChangedCB& video_size_changed_cb, |
| 84 const BufferingUpdateCB& buffering_update_cb, | 85 const BufferingUpdateCB& buffering_update_cb, |
| 85 const MediaPreparedCB& media_prepared_cb, | 86 const MediaPreparedCB& media_prepared_cb, |
| 86 const PlaybackCompleteCB& playback_complete_cb, | 87 const PlaybackCompleteCB& playback_complete_cb, |
| 87 const SeekCompleteCB& seek_complete_cb, | 88 const SeekCompleteCB& seek_complete_cb, |
| 88 const TimeUpdateCB& time_update_cb, | 89 const TimeUpdateCB& time_update_cb, |
| 89 const MediaInterruptedCB& media_interrupted_cb); | 90 const MediaInterruptedCB& media_interrupted_cb); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 void OnMediaInterrupted(); | 135 void OnMediaInterrupted(); |
| 135 | 136 |
| 136 // Prepare the player for playback, asynchronously. When succeeds, | 137 // Prepare the player for playback, asynchronously. When succeeds, |
| 137 // OnMediaPrepared() will be called. Otherwise, OnMediaError() will | 138 // OnMediaPrepared() will be called. Otherwise, OnMediaError() will |
| 138 // be called with an error type. | 139 // be called with an error type. |
| 139 void Prepare(); | 140 void Prepare(); |
| 140 | 141 |
| 141 // Callback function passed to |cookies_retriever_|. | 142 // Callback function passed to |cookies_retriever_|. |
| 142 void GetCookiesCallback(const std::string& cookies); | 143 void GetCookiesCallback(const std::string& cookies); |
| 143 | 144 |
| 145 // Set the data source for the media player. | |
| 146 void SetDataSource(const std::string& url); | |
| 147 | |
| 144 int player_id() { return player_id_; } | 148 int player_id() { return player_id_; } |
| 145 bool can_pause() { return can_pause_; } | 149 bool can_pause() { return can_pause_; } |
| 146 bool can_seek_forward() { return can_seek_forward_; } | 150 bool can_seek_forward() { return can_seek_forward_; } |
| 147 bool can_seek_backward() { return can_seek_backward_; } | 151 bool can_seek_backward() { return can_seek_backward_; } |
| 148 bool prepared() { return prepared_; } | 152 bool prepared() { return prepared_; } |
| 149 | 153 |
| 150 private: | 154 private: |
| 151 // Create the actual android media player. | 155 // Create the actual android media player. |
| 152 void InitializePlayer(); | 156 void InitializePlayer(); |
| 153 | 157 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 // Stats about the media. | 199 // Stats about the media. |
| 196 base::TimeDelta duration_; | 200 base::TimeDelta duration_; |
| 197 int width_; | 201 int width_; |
| 198 int height_; | 202 int height_; |
| 199 | 203 |
| 200 // Meta data about actions can be taken. | 204 // Meta data about actions can be taken. |
| 201 bool can_pause_; | 205 bool can_pause_; |
| 202 bool can_seek_forward_; | 206 bool can_seek_forward_; |
| 203 bool can_seek_backward_; | 207 bool can_seek_backward_; |
| 204 | 208 |
| 205 // Cookies for |url_| | 209 // Cookies for |url_| |
|
scherkus (not reviewing)
2013/03/08 21:26:27
nit: this should end w/ period
qinmin
2013/03/08 22:36:12
Done.
| |
| 206 std::string cookies_; | 210 std::string cookies_; |
| 207 | 211 |
| 208 // Resource manager for all the media players. | 212 // Resource manager for all the media players. |
| 209 MediaPlayerBridgeManager* manager_; | 213 MediaPlayerBridgeManager* manager_; |
| 210 | 214 |
| 211 // Object for retrieving cookies for this media player. | 215 // Object for retrieving resources for this media player. |
| 212 scoped_ptr<CookieGetter> cookie_getter_; | 216 scoped_ptr<MediaResourceGetter> resource_getter_; |
| 213 | 217 |
| 214 // Java MediaPlayer instance. | 218 // Java MediaPlayer instance. |
| 215 base::android::ScopedJavaGlobalRef<jobject> j_media_player_; | 219 base::android::ScopedJavaGlobalRef<jobject> j_media_player_; |
| 216 | 220 |
| 217 base::RepeatingTimer<MediaPlayerBridge> time_update_timer_; | 221 base::RepeatingTimer<MediaPlayerBridge> time_update_timer_; |
| 218 | 222 |
| 219 // Weak pointer passed to |listener_| for callbacks. | 223 // Weak pointer passed to |listener_| for callbacks. |
| 220 base::WeakPtrFactory<MediaPlayerBridge> weak_this_; | 224 base::WeakPtrFactory<MediaPlayerBridge> weak_this_; |
| 221 | 225 |
| 222 // Listener object that listens to all the media player events. | 226 // Listener object that listens to all the media player events. |
| 223 MediaPlayerListener listener_; | 227 MediaPlayerListener listener_; |
| 224 | 228 |
| 225 DISALLOW_COPY_AND_ASSIGN(MediaPlayerBridge); | 229 DISALLOW_COPY_AND_ASSIGN(MediaPlayerBridge); |
| 226 }; | 230 }; |
| 227 | 231 |
| 228 } // namespace media | 232 } // namespace media |
| 229 | 233 |
| 230 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_BRIDGE_H_ | 234 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_BRIDGE_H_ |
| OLD | NEW |