OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_ANDROID_MEDIA_PLAYER_MANAGER_ANDROID_H_ |
| 6 #define CONTENT_BROWSER_ANDROID_MEDIA_PLAYER_MANAGER_ANDROID_H_ |
| 7 |
| 8 #include <map> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/scoped_vector.h" |
| 13 #include "base/time.h" |
| 14 #include "content/browser/android/content_video_view.h" |
| 15 #include "content/public/browser/render_view_host_observer.h" |
| 16 #include "googleurl/src/gurl.h" |
| 17 #include "media/base/android/media_player_bridge.h" |
| 18 #include "media/base/android/media_player_bridge_manager.h" |
| 19 |
| 20 namespace content { |
| 21 |
| 22 class WebContents; |
| 23 |
| 24 // This class manages all the MediaPlayerBridge objects. It receives |
| 25 // control operations from the the render process, and forwards |
| 26 // them to corresponding MediaPlayerBridge object. Callbacks from |
| 27 // MediaPlayerBridge objects are converted to IPCs and then sent to the |
| 28 // render process. |
| 29 class MediaPlayerManagerAndroid |
| 30 : public RenderViewHostObserver, |
| 31 public media::MediaPlayerBridgeManager { |
| 32 public: |
| 33 // Create a MediaPlayerManagerAndroid object for the |render_view_host|. |
| 34 explicit MediaPlayerManagerAndroid(RenderViewHost* render_view_host); |
| 35 virtual ~MediaPlayerManagerAndroid(); |
| 36 |
| 37 // RenderViewHostObserver overrides. |
| 38 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 39 |
| 40 // Fullscreen video playback controls. |
| 41 void FullscreenPlayerPlay(); |
| 42 void FullscreenPlayerPause(); |
| 43 void FullscreenPlayerSeek(int msec); |
| 44 void ExitFullscreen(bool release_media_player); |
| 45 void SetVideoSurface(jobject surface); |
| 46 |
| 47 // An internal method that checks for current time routinely and generates |
| 48 // time update events. |
| 49 void OnTimeUpdate(int player_id, base::TimeDelta current_time); |
| 50 |
| 51 // Callbacks needed by media::MediaPlayerBridge. |
| 52 void OnMediaMetadataChanged(int player_id, base::TimeDelta duration, |
| 53 int width, int height, bool success); |
| 54 void OnPlaybackComplete(int player_id); |
| 55 void OnMediaInterrupted(int player_id); |
| 56 void OnBufferingUpdate(int player_id, int percentage); |
| 57 void OnSeekComplete(int player_id, base::TimeDelta current_time); |
| 58 void OnError(int player_id, int error); |
| 59 void OnVideoSizeChanged(int player_id, int width, int height); |
| 60 |
| 61 // media::MediaPlayerBridgeManager overrides. |
| 62 virtual void RequestMediaResources(media::MediaPlayerBridge* player) OVERRIDE; |
| 63 virtual void ReleaseMediaResources(media::MediaPlayerBridge* player) OVERRIDE; |
| 64 |
| 65 // Release all the players managed by this object. |
| 66 void DestroyAllMediaPlayers(); |
| 67 |
| 68 void AttachExternalVideoSurface(int player_id, jobject surface); |
| 69 void DetachExternalVideoSurface(int player_id); |
| 70 |
| 71 media::MediaPlayerBridge* GetFullscreenPlayer(); |
| 72 media::MediaPlayerBridge* GetPlayer(int player_id); |
| 73 |
| 74 private: |
| 75 // Message handlers. |
| 76 void OnEnterFullscreen(int player_id); |
| 77 void OnExitFullscreen(int player_id); |
| 78 void OnInitialize(int player_id, const GURL& url, |
| 79 const GURL& first_party_for_cookies); |
| 80 void OnStart(int player_id); |
| 81 void OnSeek(int player_id, base::TimeDelta time); |
| 82 void OnPause(int player_id); |
| 83 void OnReleaseResources(int player_id); |
| 84 void OnDestroyPlayer(int player_id); |
| 85 void OnRequestExternalSurface(int player_id); |
| 86 |
| 87 // An array of managed players. |
| 88 ScopedVector<media::MediaPlayerBridge> players_; |
| 89 |
| 90 // The fullscreen video view object. |
| 91 scoped_ptr<ContentVideoView> video_view_; |
| 92 |
| 93 // Player ID of the fullscreen media player. |
| 94 int fullscreen_player_id_; |
| 95 |
| 96 WebContents* web_contents_; |
| 97 |
| 98 DISALLOW_COPY_AND_ASSIGN(MediaPlayerManagerAndroid); |
| 99 }; |
| 100 |
| 101 } // namespace content |
| 102 |
| 103 #endif // CONTENT_BROWSER_ANDROID_MEDIA_PLAYER_MANAGER_ANDROID_H_ |
OLD | NEW |