OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 CONTENT_RENDERER_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ |
6 #define CONTENT_RENDERER_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ | 6 #define CONTENT_RENDERER_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
18 #include "base/time/default_tick_clock.h" | 18 #include "base/time/default_tick_clock.h" |
19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
20 #include "cc/layers/video_frame_provider.h" | 20 #include "cc/layers/video_frame_provider.h" |
21 #include "content/common/media/media_player_messages_enums_android.h" | |
22 #include "content/public/renderer/render_frame_observer.h" | 21 #include "content/public/renderer/render_frame_observer.h" |
23 #include "content/renderer/media/android/media_info_loader.h" | 22 #include "content/renderer/media/android/media_info_loader.h" |
24 #include "content/renderer/media/android/media_source_delegate.h" | 23 #include "content/renderer/media/android/media_source_delegate.h" |
| 24 #include "content/renderer/media/android/renderer_media_player_manager.h" |
25 #include "content/renderer/media/android/stream_texture_factory.h" | 25 #include "content/renderer/media/android/stream_texture_factory.h" |
26 #include "gpu/command_buffer/common/mailbox.h" | 26 #include "gpu/command_buffer/common/mailbox.h" |
27 #include "media/base/android/media_player_android.h" | 27 #include "media/base/android/media_player_android.h" |
28 #include "media/base/cdm_context.h" | 28 #include "media/base/cdm_context.h" |
29 #include "media/base/demuxer_stream.h" | 29 #include "media/base/demuxer_stream.h" |
30 #include "media/base/media_keys.h" | 30 #include "media/base/media_keys.h" |
31 #include "media/base/time_delta_interpolator.h" | 31 #include "media/base/time_delta_interpolator.h" |
32 #include "media/blink/webmediaplayer_params.h" | 32 #include "media/blink/webmediaplayer_params.h" |
33 #include "media/cdm/proxy_decryptor.h" | 33 #include "media/cdm/proxy_decryptor.h" |
34 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 34 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 class RendererCdmManager; | 74 class RendererCdmManager; |
75 class RendererMediaPlayerManager; | 75 class RendererMediaPlayerManager; |
76 | 76 |
77 // This class implements blink::WebMediaPlayer by keeping the android | 77 // This class implements blink::WebMediaPlayer by keeping the android |
78 // media player in the browser process. It listens to all the status changes | 78 // media player in the browser process. It listens to all the status changes |
79 // sent from the browser process and sends playback controls to the media | 79 // sent from the browser process and sends playback controls to the media |
80 // player. | 80 // player. |
81 class WebMediaPlayerAndroid : public blink::WebMediaPlayer, | 81 class WebMediaPlayerAndroid : public blink::WebMediaPlayer, |
82 public cc::VideoFrameProvider, | 82 public cc::VideoFrameProvider, |
83 public RenderFrameObserver, | 83 public RenderFrameObserver, |
84 public StreamTextureFactoryContextObserver { | 84 public StreamTextureFactoryContextObserver, |
| 85 public media::RendererMediaPlayerInterface { |
85 public: | 86 public: |
86 // Construct a WebMediaPlayerAndroid object. This class communicates with the | 87 // Construct a WebMediaPlayerAndroid object. This class communicates with the |
87 // MediaPlayerAndroid object in the browser process through |proxy|. | 88 // MediaPlayerAndroid object in the browser process through |proxy|. |
88 // TODO(qinmin): |frame| argument is used to determine whether the current | 89 // TODO(qinmin): |frame| argument is used to determine whether the current |
89 // player can enter fullscreen. This logic should probably be moved into | 90 // player can enter fullscreen. This logic should probably be moved into |
90 // blink, so that enterFullscreen() will not be called if another video is | 91 // blink, so that enterFullscreen() will not be called if another video is |
91 // already in fullscreen. | 92 // already in fullscreen. |
92 WebMediaPlayerAndroid( | 93 WebMediaPlayerAndroid( |
93 blink::WebFrame* frame, | 94 blink::WebFrame* frame, |
94 blink::WebMediaPlayerClient* client, | 95 blink::WebMediaPlayerClient* client, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 void SetVideoFrameProviderClient( | 185 void SetVideoFrameProviderClient( |
185 cc::VideoFrameProvider::Client* client) override; | 186 cc::VideoFrameProvider::Client* client) override; |
186 bool UpdateCurrentFrame(base::TimeTicks deadline_min, | 187 bool UpdateCurrentFrame(base::TimeTicks deadline_min, |
187 base::TimeTicks deadline_max) override; | 188 base::TimeTicks deadline_max) override; |
188 bool HasCurrentFrame() override; | 189 bool HasCurrentFrame() override; |
189 scoped_refptr<media::VideoFrame> GetCurrentFrame() override; | 190 scoped_refptr<media::VideoFrame> GetCurrentFrame() override; |
190 void PutCurrentFrame() override; | 191 void PutCurrentFrame() override; |
191 | 192 |
192 // Media player callback handlers. | 193 // Media player callback handlers. |
193 void OnMediaMetadataChanged(base::TimeDelta duration, int width, | 194 void OnMediaMetadataChanged(base::TimeDelta duration, int width, |
194 int height, bool success); | 195 int height, bool success) override; |
195 void OnPlaybackComplete(); | 196 void OnPlaybackComplete() override; |
196 void OnBufferingUpdate(int percentage); | 197 void OnBufferingUpdate(int percentage) override; |
197 void OnSeekRequest(const base::TimeDelta& time_to_seek); | 198 void OnSeekRequest(const base::TimeDelta& time_to_seek) override; |
198 void OnSeekComplete(const base::TimeDelta& current_time); | 199 void OnSeekComplete(const base::TimeDelta& current_time) override; |
199 void OnMediaError(int error_type); | 200 void OnMediaError(int error_type) override; |
200 void OnVideoSizeChanged(int width, int height); | 201 void OnVideoSizeChanged(int width, int height) override; |
201 void OnDurationChanged(const base::TimeDelta& duration); | 202 void OnDurationChanged(const base::TimeDelta& duration); |
202 | 203 |
203 // Called to update the current time. | 204 // Called to update the current time. |
204 void OnTimeUpdate(base::TimeDelta current_timestamp, | 205 void OnTimeUpdate(base::TimeDelta current_timestamp, |
205 base::TimeTicks current_time_ticks); | 206 base::TimeTicks current_time_ticks) override; |
206 | 207 |
207 // Functions called when media player status changes. | 208 // Functions called when media player status changes. |
208 void OnConnectedToRemoteDevice(const std::string& remote_playback_message); | 209 void OnConnectedToRemoteDevice(const std::string& remote_playback_message) |
209 void OnDisconnectedFromRemoteDevice(); | 210 override; |
210 void OnDidExitFullscreen(); | 211 void OnDisconnectedFromRemoteDevice() override; |
211 void OnMediaPlayerPlay(); | 212 void OnDidExitFullscreen() override; |
212 void OnMediaPlayerPause(); | 213 void OnMediaPlayerPlay() override; |
213 void OnRemoteRouteAvailabilityChanged(bool routes_available); | 214 void OnMediaPlayerPause() override; |
| 215 void OnRemoteRouteAvailabilityChanged(bool routes_available) override; |
214 | 216 |
215 // StreamTextureFactoryContextObserver implementation. | 217 // StreamTextureFactoryContextObserver implementation. |
216 void ResetStreamTextureProxy() override; | 218 void ResetStreamTextureProxy() override; |
217 | 219 |
218 // Called when the player is released. | 220 // Called when the player is released. |
219 virtual void OnPlayerReleased(); | 221 void OnPlayerReleased() override; |
220 | 222 |
221 // This function is called by the RendererMediaPlayerManager to pause the | 223 // This function is called by the RendererMediaPlayerManager to pause the |
222 // video and release the media player and surface texture when we switch tabs. | 224 // video and release the media player and surface texture when we switch tabs. |
223 // However, the actual GlTexture is not released to keep the video screenshot. | 225 // However, the actual GlTexture is not released to keep the video screenshot. |
224 void SuspendAndReleaseResources(); | 226 void SuspendAndReleaseResources() override; |
225 | 227 |
226 // RenderFrameObserver implementation. | 228 // RenderFrameObserver implementation. |
227 void OnDestruct() override; | 229 void OnDestruct() override; |
228 | 230 |
229 #if defined(VIDEO_HOLE) | 231 #if defined(VIDEO_HOLE) |
230 // Calculate the boundary rectangle of the media player (i.e. location and | 232 // Calculate the boundary rectangle of the media player (i.e. location and |
231 // size of the video frame). | 233 // size of the video frame). |
232 // Returns true if the geometry has been changed since the last call. | 234 // Returns true if the geometry has been changed since the last call. |
233 bool UpdateBoundaryRectangle(); | 235 bool UpdateBoundaryRectangle() override; |
234 | 236 |
235 const gfx::RectF GetBoundaryRectangle(); | 237 const gfx::RectF GetBoundaryRectangle() override; |
236 #endif // defined(VIDEO_HOLE) | 238 #endif // defined(VIDEO_HOLE) |
237 | 239 |
238 MediaKeyException generateKeyRequest(const blink::WebString& key_system, | 240 MediaKeyException generateKeyRequest(const blink::WebString& key_system, |
239 const unsigned char* init_data, | 241 const unsigned char* init_data, |
240 unsigned init_data_length) override; | 242 unsigned init_data_length) override; |
241 MediaKeyException addKey(const blink::WebString& key_system, | 243 MediaKeyException addKey(const blink::WebString& key_system, |
242 const unsigned char* key, | 244 const unsigned char* key, |
243 unsigned key_length, | 245 unsigned key_length, |
244 const unsigned char* init_data, | 246 const unsigned char* init_data, |
245 unsigned init_data_length, | 247 unsigned init_data_length, |
(...skipping 14 matching lines...) Expand all Loading... |
260 const std::vector<uint8_t>& message, | 262 const std::vector<uint8_t>& message, |
261 const GURL& destination_url); | 263 const GURL& destination_url); |
262 | 264 |
263 void OnMediaSourceOpened(blink::WebMediaSource* web_media_source); | 265 void OnMediaSourceOpened(blink::WebMediaSource* web_media_source); |
264 | 266 |
265 void OnEncryptedMediaInitData(media::EmeInitDataType init_data_type, | 267 void OnEncryptedMediaInitData(media::EmeInitDataType init_data_type, |
266 const std::vector<uint8_t>& init_data); | 268 const std::vector<uint8_t>& init_data); |
267 | 269 |
268 // Called when a decoder detects that the key needed to decrypt the stream | 270 // Called when a decoder detects that the key needed to decrypt the stream |
269 // is not available. | 271 // is not available. |
270 void OnWaitingForDecryptionKey(); | 272 void OnWaitingForDecryptionKey() override; |
271 | 273 |
272 protected: | 274 protected: |
273 // Helper method to update the playing state. | 275 // Helper method to update the playing state. |
274 void UpdatePlayingState(bool is_playing_); | 276 void UpdatePlayingState(bool is_playing_); |
275 | 277 |
276 // Helper methods for posting task for setting states and update WebKit. | 278 // Helper methods for posting task for setting states and update WebKit. |
277 void UpdateNetworkState(blink::WebMediaPlayer::NetworkState state); | 279 void UpdateNetworkState(blink::WebMediaPlayer::NetworkState state); |
278 void UpdateReadyState(blink::WebMediaPlayer::ReadyState state); | 280 void UpdateReadyState(blink::WebMediaPlayer::ReadyState state); |
279 void TryCreateStreamTextureProxyIfNeeded(); | 281 void TryCreateStreamTextureProxyIfNeeded(); |
280 void DoCreateStreamTexture(); | 282 void DoCreateStreamTexture(); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 | 541 |
540 // NOTE: Weak pointers must be invalidated before all other member variables. | 542 // NOTE: Weak pointers must be invalidated before all other member variables. |
541 base::WeakPtrFactory<WebMediaPlayerAndroid> weak_factory_; | 543 base::WeakPtrFactory<WebMediaPlayerAndroid> weak_factory_; |
542 | 544 |
543 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid); | 545 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid); |
544 }; | 546 }; |
545 | 547 |
546 } // namespace content | 548 } // namespace content |
547 | 549 |
548 #endif // CONTENT_RENDERER_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ | 550 #endif // CONTENT_RENDERER_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ |
OLD | NEW |