OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_ANDROID_H_ | 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_ |
6 #define MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_ | 6 #define MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "media/base/android/media_player_listener.h" | 14 #include "media/base/android/media_player_listener.h" |
15 #include "media/base/media_export.h" | 15 #include "media/base/media_export.h" |
| 16 #include "ui/gfx/geometry/size.h" |
16 #include "ui/gl/android/scoped_java_surface.h" | 17 #include "ui/gl/android/scoped_java_surface.h" |
17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
18 | 19 |
19 namespace media { | 20 namespace media { |
20 | 21 |
21 class BrowserCdm; | 22 class BrowserCdm; |
22 class MediaPlayerManager; | 23 class MediaPlayerManager; |
23 | 24 |
24 // This class serves as the base class for different media player | 25 // This class serves as the base class for different media player |
25 // implementations on Android. Subclasses need to provide their own | 26 // implementations on Android. Subclasses need to provide their own |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 virtual bool IsPlayerReady() = 0; | 73 virtual bool IsPlayerReady() = 0; |
73 virtual bool CanPause() = 0; | 74 virtual bool CanPause() = 0; |
74 virtual bool CanSeekForward() = 0; | 75 virtual bool CanSeekForward() = 0; |
75 virtual bool CanSeekBackward() = 0; | 76 virtual bool CanSeekBackward() = 0; |
76 virtual GURL GetUrl(); | 77 virtual GURL GetUrl(); |
77 virtual GURL GetFirstPartyForCookies(); | 78 virtual GURL GetFirstPartyForCookies(); |
78 | 79 |
79 // Associates the |cdm| with this player. | 80 // Associates the |cdm| with this player. |
80 virtual void SetCdm(BrowserCdm* cdm); | 81 virtual void SetCdm(BrowserCdm* cdm); |
81 | 82 |
| 83 // Overridden in MediaCodecPlayer to pass data between threads. |
| 84 virtual void OnMediaMetadataChanged( |
| 85 base::TimeDelta duration, const gfx::Size& video_size) {} |
| 86 |
| 87 // Overridden in MediaCodecPlayer to pass data between threads. |
| 88 virtual void OnTimeUpdate(base::TimeDelta current_timestamp, |
| 89 base::TimeTicks current_time_ticks) {} |
| 90 |
82 int player_id() { return player_id_; } | 91 int player_id() { return player_id_; } |
83 | 92 |
84 GURL frame_url() { return frame_url_; } | 93 GURL frame_url() { return frame_url_; } |
85 | 94 |
| 95 // Attach/Detaches |listener_| for listening to all the media events. If |
| 96 // |j_media_player| is NULL, |listener_| only listens to the system media |
| 97 // events. Otherwise, it also listens to the events from |j_media_player|. |
| 98 void AttachListener(jobject j_media_player); |
| 99 void DetachListener(); |
| 100 |
86 protected: | 101 protected: |
87 MediaPlayerAndroid(int player_id, | 102 MediaPlayerAndroid(int player_id, |
88 MediaPlayerManager* manager, | 103 MediaPlayerManager* manager, |
89 const RequestMediaResourcesCB& request_media_resources_cb, | 104 const RequestMediaResourcesCB& request_media_resources_cb, |
90 const GURL& frame_url); | 105 const GURL& frame_url); |
91 | 106 |
92 // TODO(qinmin): Simplify the MediaPlayerListener class to only listen to | 107 // TODO(qinmin): Simplify the MediaPlayerListener class to only listen to |
93 // media interrupt events. And have a separate child class to listen to all | 108 // media interrupt events. And have a separate child class to listen to all |
94 // the events needed by MediaPlayerBridge. http://crbug.com/422597. | 109 // the events needed by MediaPlayerBridge. http://crbug.com/422597. |
95 // MediaPlayerListener callbacks. | 110 // MediaPlayerListener callbacks. |
96 virtual void OnVideoSizeChanged(int width, int height); | 111 virtual void OnVideoSizeChanged(int width, int height); |
97 virtual void OnMediaError(int error_type); | 112 virtual void OnMediaError(int error_type); |
98 virtual void OnBufferingUpdate(int percent); | 113 virtual void OnBufferingUpdate(int percent); |
99 virtual void OnPlaybackComplete(); | 114 virtual void OnPlaybackComplete(); |
100 virtual void OnMediaInterrupted(); | 115 virtual void OnMediaInterrupted(); |
101 virtual void OnSeekComplete(); | 116 virtual void OnSeekComplete(); |
102 virtual void OnMediaPrepared(); | 117 virtual void OnMediaPrepared(); |
103 | 118 |
104 // Attach/Detaches |listener_| for listening to all the media events. If | |
105 // |j_media_player| is NULL, |listener_| only listens to the system media | |
106 // events. Otherwise, it also listens to the events from |j_media_player|. | |
107 void AttachListener(jobject j_media_player); | |
108 void DetachListener(); | |
109 | |
110 // When destroying a subclassed object on a non-UI thread | 119 // When destroying a subclassed object on a non-UI thread |
111 // it is still required to destroy the |listener_| related stuff | 120 // it is still required to destroy the |listener_| related stuff |
112 // on the UI thread. | 121 // on the UI thread. |
113 void DestroyListenerOnUIThread(); | 122 void DestroyListenerOnUIThread(); |
114 void SetAudible(bool is_audible); | 123 void SetAudible(bool is_audible); |
115 | 124 |
116 MediaPlayerManager* manager() { return manager_; } | 125 MediaPlayerManager* manager() { return manager_; } |
117 | 126 |
| 127 base::WeakPtr<MediaPlayerAndroid> WeakPtrForUIThread(); |
| 128 |
118 RequestMediaResourcesCB request_media_resources_cb_; | 129 RequestMediaResourcesCB request_media_resources_cb_; |
119 | 130 |
120 private: | 131 private: |
121 friend class MediaPlayerListener; | 132 friend class MediaPlayerListener; |
122 | 133 |
123 // Player ID assigned to this player. | 134 // Player ID assigned to this player. |
124 int player_id_; | 135 int player_id_; |
125 | 136 |
126 // Resource manager for all the media players. | 137 // Resource manager for all the media players. |
127 MediaPlayerManager* manager_; | 138 MediaPlayerManager* manager_; |
(...skipping 10 matching lines...) Expand all Loading... |
138 // Weak pointer passed to |listener_| for callbacks. | 149 // Weak pointer passed to |listener_| for callbacks. |
139 // NOTE: Weak pointers must be invalidated before all other member variables. | 150 // NOTE: Weak pointers must be invalidated before all other member variables. |
140 base::WeakPtrFactory<MediaPlayerAndroid> weak_factory_; | 151 base::WeakPtrFactory<MediaPlayerAndroid> weak_factory_; |
141 | 152 |
142 DISALLOW_COPY_AND_ASSIGN(MediaPlayerAndroid); | 153 DISALLOW_COPY_AND_ASSIGN(MediaPlayerAndroid); |
143 }; | 154 }; |
144 | 155 |
145 } // namespace media | 156 } // namespace media |
146 | 157 |
147 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_ | 158 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_ |
OLD | NEW |