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/time.h" | 16 #include "base/time.h" |
17 #include "base/timer.h" | 17 #include "base/timer.h" |
18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
19 #include "media/base/media_export.h" | 19 #include "media/base/media_export.h" |
20 #include "media/base/android/media_player_listener.h" | 20 #include "media/base/android/media_player_listener.h" |
21 | 21 |
22 namespace media { | 22 namespace media { |
23 | 23 |
24 class MediaResourceGetter; | 24 class MediaPlayerManager; |
25 class MediaPlayerBridgeManager; | |
26 | 25 |
27 // This class serves as a bridge for native code to call java functions inside | 26 // This class serves as a bridge for native code to call java functions inside |
28 // android mediaplayer class. For more information on android mediaplayer, check | 27 // android mediaplayer class. For more information on android mediaplayer, check |
29 // http://developer.android.com/reference/android/media/MediaPlayer.html | 28 // http://developer.android.com/reference/android/media/MediaPlayer.html |
30 // The actual android mediaplayer instance is created lazily when Start(), | 29 // The actual android mediaplayer instance is created lazily when Start(), |
31 // Pause(), SeekTo() gets called. As a result, media information may not | 30 // Pause(), SeekTo() gets called. As a result, media information may not |
32 // be available until one of those operations is performed. After that, we | 31 // be available until one of those operations is performed. After that, we |
33 // will cache those information in case the mediaplayer gets released. | 32 // will cache those information in case the mediaplayer gets released. |
34 class MEDIA_EXPORT MediaPlayerBridge { | 33 class MEDIA_EXPORT MediaPlayerBridge { |
35 public: | 34 public: |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 static bool RegisterMediaPlayerBridge(JNIEnv* env); | 70 static bool RegisterMediaPlayerBridge(JNIEnv* env); |
72 | 71 |
73 // Construct a MediaPlayerBridge object with all the needed media player | 72 // Construct a MediaPlayerBridge object with all the needed media player |
74 // callbacks. This object needs to call |manager|'s RequestMediaResources() | 73 // callbacks. This object needs to call |manager|'s RequestMediaResources() |
75 // before decoding the media stream. This allows |manager| to track | 74 // before decoding the media stream. This allows |manager| to track |
76 // 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 |
77 // to call ReleaseMediaResources() when it is done with decoding. | 76 // to call ReleaseMediaResources() when it is done with decoding. |
78 MediaPlayerBridge(int player_id, | 77 MediaPlayerBridge(int player_id, |
79 const GURL& url, | 78 const GURL& url, |
80 const GURL& first_party_for_cookies, | 79 const GURL& first_party_for_cookies, |
81 MediaResourceGetter* resource_getter, | |
82 bool hide_url_log, | 80 bool hide_url_log, |
83 MediaPlayerBridgeManager* manager, | 81 MediaPlayerManager* manager, |
84 const MediaErrorCB& media_error_cb, | 82 const MediaErrorCB& media_error_cb, |
85 const VideoSizeChangedCB& video_size_changed_cb, | 83 const VideoSizeChangedCB& video_size_changed_cb, |
86 const BufferingUpdateCB& buffering_update_cb, | 84 const BufferingUpdateCB& buffering_update_cb, |
87 const MediaMetadataChangedCB& media_prepared_cb, | 85 const MediaMetadataChangedCB& media_prepared_cb, |
88 const PlaybackCompleteCB& playback_complete_cb, | 86 const PlaybackCompleteCB& playback_complete_cb, |
89 const SeekCompleteCB& seek_complete_cb, | 87 const SeekCompleteCB& seek_complete_cb, |
90 const TimeUpdateCB& time_update_cb, | 88 const TimeUpdateCB& time_update_cb, |
91 const MediaInterruptedCB& media_interrupted_cb); | 89 const MediaInterruptedCB& media_interrupted_cb); |
92 ~MediaPlayerBridge(); | 90 ~MediaPlayerBridge(); |
93 | 91 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 209 |
212 // Meta data about actions can be taken. | 210 // Meta data about actions can be taken. |
213 bool can_pause_; | 211 bool can_pause_; |
214 bool can_seek_forward_; | 212 bool can_seek_forward_; |
215 bool can_seek_backward_; | 213 bool can_seek_backward_; |
216 | 214 |
217 // Cookies for |url_|. | 215 // Cookies for |url_|. |
218 std::string cookies_; | 216 std::string cookies_; |
219 | 217 |
220 // Resource manager for all the media players. | 218 // Resource manager for all the media players. |
221 MediaPlayerBridgeManager* manager_; | 219 MediaPlayerManager* manager_; |
222 | |
223 // Object for retrieving resources for this media player. | |
224 scoped_ptr<MediaResourceGetter> resource_getter_; | |
225 | 220 |
226 // Java MediaPlayer instance. | 221 // Java MediaPlayer instance. |
227 base::android::ScopedJavaGlobalRef<jobject> j_media_player_; | 222 base::android::ScopedJavaGlobalRef<jobject> j_media_player_; |
228 | 223 |
229 base::RepeatingTimer<MediaPlayerBridge> time_update_timer_; | 224 base::RepeatingTimer<MediaPlayerBridge> time_update_timer_; |
230 | 225 |
231 // Weak pointer passed to |listener_| for callbacks. | 226 // Weak pointer passed to |listener_| for callbacks. |
232 base::WeakPtrFactory<MediaPlayerBridge> weak_this_; | 227 base::WeakPtrFactory<MediaPlayerBridge> weak_this_; |
233 | 228 |
234 // Listener object that listens to all the media player events. | 229 // Listener object that listens to all the media player events. |
235 MediaPlayerListener listener_; | 230 MediaPlayerListener listener_; |
236 | 231 |
237 DISALLOW_COPY_AND_ASSIGN(MediaPlayerBridge); | 232 DISALLOW_COPY_AND_ASSIGN(MediaPlayerBridge); |
238 }; | 233 }; |
239 | 234 |
240 } // namespace media | 235 } // namespace media |
241 | 236 |
242 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_BRIDGE_H_ | 237 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_BRIDGE_H_ |
OLD | NEW |