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/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "media/base/android/media_player_listener.h" | 15 #include "media/base/android/media_player_listener.h" |
16 #include "media/base/media_export.h" | 16 #include "media/base/media_export.h" |
17 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
18 #include "ui/gl/android/scoped_java_surface.h" | 18 #include "ui/gl/android/scoped_java_surface.h" |
19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
20 | 20 |
21 namespace media { | 21 namespace media { |
22 | 22 |
23 class MediaKeys; | 23 class MediaKeys; |
24 class MediaPlayerManager; | 24 class MediaPlayerManager; |
25 | 25 |
| 26 enum { |
| 27 // Id used for players not participating in any media sessions |
| 28 // because of undefined behavior in the specification. When all |
| 29 // media session interactions have been worked out, this id should |
| 30 // no longer be used. |
| 31 kInvalidMediaSessionId = -1, |
| 32 |
| 33 // The media session for media elements that don't have an explicit |
| 34 // user created media session set. Must be in-sync with |
| 35 // WebMediaSession::DefaultID in blink. |
| 36 kDefaultMediaSessionId = 0 |
| 37 }; |
| 38 |
26 // This class serves as the base class for different media player | 39 // This class serves as the base class for different media player |
27 // implementations on Android. Subclasses need to provide their own | 40 // implementations on Android. Subclasses need to provide their own |
28 // MediaPlayerAndroid::Create() implementation. | 41 // MediaPlayerAndroid::Create() implementation. |
29 class MEDIA_EXPORT MediaPlayerAndroid { | 42 class MEDIA_EXPORT MediaPlayerAndroid { |
30 public: | 43 public: |
31 virtual ~MediaPlayerAndroid(); | 44 virtual ~MediaPlayerAndroid(); |
32 | 45 |
33 // Error types for MediaErrorCB. | 46 // Error types for MediaErrorCB. |
34 enum MediaErrorType { | 47 enum MediaErrorType { |
35 MEDIA_ERROR_FORMAT, | 48 MEDIA_ERROR_FORMAT, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 const gfx::Size& video_size) {} | 114 const gfx::Size& video_size) {} |
102 | 115 |
103 // Overridden in MediaCodecPlayer to pass data between threads. | 116 // Overridden in MediaCodecPlayer to pass data between threads. |
104 virtual void OnTimeUpdate(base::TimeDelta current_timestamp, | 117 virtual void OnTimeUpdate(base::TimeDelta current_timestamp, |
105 base::TimeTicks current_time_ticks) {} | 118 base::TimeTicks current_time_ticks) {} |
106 | 119 |
107 int player_id() { return player_id_; } | 120 int player_id() { return player_id_; } |
108 | 121 |
109 GURL frame_url() { return frame_url_; } | 122 GURL frame_url() { return frame_url_; } |
110 | 123 |
| 124 int media_session_id() { return media_session_id_; } |
| 125 |
111 // Attach/Detaches |listener_| for listening to all the media events. If | 126 // Attach/Detaches |listener_| for listening to all the media events. If |
112 // |j_media_player| is NULL, |listener_| only listens to the system media | 127 // |j_media_player| is NULL, |listener_| only listens to the system media |
113 // events. Otherwise, it also listens to the events from |j_media_player|. | 128 // events. Otherwise, it also listens to the events from |j_media_player|. |
114 void AttachListener(jobject j_media_player); | 129 void AttachListener(jobject j_media_player); |
115 void DetachListener(); | 130 void DetachListener(); |
116 | 131 |
117 protected: | 132 protected: |
118 MediaPlayerAndroid( | 133 MediaPlayerAndroid( |
119 int player_id, | 134 int player_id, |
120 MediaPlayerManager* manager, | 135 MediaPlayerManager* manager, |
121 const OnDecoderResourcesReleasedCB& on_decoder_resources_released_cb, | 136 const OnDecoderResourcesReleasedCB& on_decoder_resources_released_cb, |
122 const GURL& frame_url); | 137 const GURL& frame_url, |
| 138 int media_session_id); |
123 | 139 |
124 // TODO(qinmin): Simplify the MediaPlayerListener class to only listen to | 140 // TODO(qinmin): Simplify the MediaPlayerListener class to only listen to |
125 // media interrupt events. And have a separate child class to listen to all | 141 // media interrupt events. And have a separate child class to listen to all |
126 // the events needed by MediaPlayerBridge. http://crbug.com/422597. | 142 // the events needed by MediaPlayerBridge. http://crbug.com/422597. |
127 // MediaPlayerListener callbacks. | 143 // MediaPlayerListener callbacks. |
128 virtual void OnVideoSizeChanged(int width, int height); | 144 virtual void OnVideoSizeChanged(int width, int height); |
129 virtual void OnMediaError(int error_type); | 145 virtual void OnMediaError(int error_type); |
130 virtual void OnBufferingUpdate(int percent); | 146 virtual void OnBufferingUpdate(int percent); |
131 virtual void OnPlaybackComplete(); | 147 virtual void OnPlaybackComplete(); |
132 virtual void OnMediaInterrupted(); | 148 virtual void OnMediaInterrupted(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 182 |
167 // Resource manager for all the media players. | 183 // Resource manager for all the media players. |
168 MediaPlayerManager* manager_; | 184 MediaPlayerManager* manager_; |
169 | 185 |
170 // Url for the frame that contains this player. | 186 // Url for the frame that contains this player. |
171 GURL frame_url_; | 187 GURL frame_url_; |
172 | 188 |
173 // Listener object that listens to all the media player events. | 189 // Listener object that listens to all the media player events. |
174 scoped_ptr<MediaPlayerListener> listener_; | 190 scoped_ptr<MediaPlayerListener> listener_; |
175 | 191 |
| 192 // Media session ID assigned to this player. |
| 193 int media_session_id_; |
| 194 |
176 // Weak pointer passed to |listener_| for callbacks. | 195 // Weak pointer passed to |listener_| for callbacks. |
177 // NOTE: Weak pointers must be invalidated before all other member variables. | 196 // NOTE: Weak pointers must be invalidated before all other member variables. |
178 base::WeakPtrFactory<MediaPlayerAndroid> weak_factory_; | 197 base::WeakPtrFactory<MediaPlayerAndroid> weak_factory_; |
179 | 198 |
180 DISALLOW_COPY_AND_ASSIGN(MediaPlayerAndroid); | 199 DISALLOW_COPY_AND_ASSIGN(MediaPlayerAndroid); |
181 }; | 200 }; |
182 | 201 |
183 } // namespace media | 202 } // namespace media |
184 | 203 |
185 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_ | 204 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_ |
OLD | NEW |