Roll src/third_party/WebKit d10c917:a1123a1 (svn 198729:198730)
[chromium-blink-merge.git] / content / renderer / media / android / renderer_media_player_manager.h
blob5e754bc579566fb2b78ff4f21d6c9368ec783fc6
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_MEDIA_ANDROID_RENDERER_MEDIA_PLAYER_MANAGER_H_
6 #define CONTENT_RENDERER_MEDIA_ANDROID_RENDERER_MEDIA_PLAYER_MANAGER_H_
8 #include <map>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/time/time.h"
13 #include "content/common/media/media_player_messages_enums_android.h"
14 #include "content/public/renderer/render_frame_observer.h"
15 #include "media/base/android/media_player_android.h"
16 #include "url/gurl.h"
18 namespace blink {
19 class WebFrame;
22 namespace gfx {
23 class RectF;
26 struct MediaPlayerHostMsg_Initialize_Params;
28 namespace content {
29 class WebMediaPlayerAndroid;
31 // Class for managing all the WebMediaPlayerAndroid objects in the same
32 // RenderFrame.
33 class RendererMediaPlayerManager : public RenderFrameObserver {
34 public:
35 // Constructs a RendererMediaPlayerManager object for the |render_frame|.
36 explicit RendererMediaPlayerManager(RenderFrame* render_frame);
37 ~RendererMediaPlayerManager() override;
39 // RenderFrameObserver overrides.
40 bool OnMessageReceived(const IPC::Message& msg) override;
41 void WasHidden() override;
43 // Initializes a MediaPlayerAndroid object in browser process.
44 void Initialize(MediaPlayerHostMsg_Initialize_Type type,
45 int player_id,
46 const GURL& url,
47 const GURL& first_party_for_cookies,
48 int demuxer_client_id,
49 const GURL& frame_url,
50 bool allow_credentials);
52 // Starts the player.
53 void Start(int player_id);
55 // Pauses the player.
56 // is_media_related_action should be true if this pause is coming from an
57 // an action that explicitly pauses the video (user pressing pause, JS, etc.)
58 // Otherwise it should be false if Pause is being called due to other reasons
59 // (cleanup, freeing resources, etc.)
60 void Pause(int player_id, bool is_media_related_action);
62 // Performs seek on the player.
63 void Seek(int player_id, const base::TimeDelta& time);
65 // Sets the player volume.
66 void SetVolume(int player_id, double volume);
68 // Sets the poster image.
69 void SetPoster(int player_id, const GURL& poster);
71 // Releases resources for the player.
72 void ReleaseResources(int player_id);
74 // Destroys the player in the browser process
75 void DestroyPlayer(int player_id);
77 // Requests remote playback if possible
78 void RequestRemotePlayback(int player_id);
80 // Requests control of remote playback
81 void RequestRemotePlaybackControl(int player_id);
83 // Requests the player to enter fullscreen.
84 void EnterFullscreen(int player_id);
86 // Requests the player with |player_id| to use the CDM with |cdm_id|.
87 // Does nothing if |cdm_id| is kInvalidCdmId.
88 // TODO(xhwang): Update this when we implement setCdm(0).
89 void SetCdm(int player_id, int cdm_id);
91 #if defined(VIDEO_HOLE)
92 // Requests an external surface for out-of-band compositing.
93 void RequestExternalSurface(int player_id, const gfx::RectF& geometry);
95 // RenderFrameObserver overrides.
96 void DidCommitCompositorFrame() override;
98 // Returns true if a media player should use video-overlay for the embedded
99 // encrypted video.
100 bool ShouldUseVideoOverlayForEmbeddedEncryptedVideo();
101 #endif // defined(VIDEO_HOLE)
103 // Registers and unregisters a WebMediaPlayerAndroid object.
104 int RegisterMediaPlayer(WebMediaPlayerAndroid* player);
105 void UnregisterMediaPlayer(int player_id);
107 // Gets the pointer to WebMediaPlayerAndroid given the |player_id|.
108 WebMediaPlayerAndroid* GetMediaPlayer(int player_id);
110 #if defined(VIDEO_HOLE)
111 // Gets the list of media players with video geometry changes.
112 void RetrieveGeometryChanges(std::map<int, gfx::RectF>* changes);
113 #endif // defined(VIDEO_HOLE)
115 private:
116 // Message handlers.
117 void OnMediaMetadataChanged(int player_id,
118 base::TimeDelta duration,
119 int width,
120 int height,
121 bool success);
122 void OnMediaPlaybackCompleted(int player_id);
123 void OnMediaBufferingUpdate(int player_id, int percent);
124 void OnSeekRequest(int player_id, const base::TimeDelta& time_to_seek);
125 void OnSeekCompleted(int player_id,
126 const base::TimeDelta& current_timestamp);
127 void OnMediaError(int player_id, int error);
128 void OnVideoSizeChanged(int player_id, int width, int height);
129 void OnTimeUpdate(int player_id,
130 base::TimeDelta current_timestamp,
131 base::TimeTicks current_time_ticks);
132 void OnWaitingForDecryptionKey(int player_id);
133 void OnMediaPlayerReleased(int player_id);
134 void OnConnectedToRemoteDevice(int player_id,
135 const std::string& remote_playback_message);
136 void OnDisconnectedFromRemoteDevice(int player_id);
137 void OnDidExitFullscreen(int player_id);
138 void OnDidEnterFullscreen(int player_id);
139 void OnPlayerPlay(int player_id);
140 void OnPlayerPause(int player_id);
141 void OnRemoteRouteAvailabilityChanged(int player_id, bool routes_available);
143 // Release all video player resources.
144 // If something is in progress the resource will not be freed. It will
145 // only be freed once the tab is destroyed or if the user navigates away
146 // via WebMediaPlayerAndroid::Destroy.
147 void ReleaseVideoResources();
149 // Info for all available WebMediaPlayerAndroid on a page; kept so that
150 // we can enumerate them to send updates about tab focus and visibility.
151 std::map<int, WebMediaPlayerAndroid*> media_players_;
153 int next_media_player_id_;
155 DISALLOW_COPY_AND_ASSIGN(RendererMediaPlayerManager);
158 } // namespace content
160 #endif // CONTENT_RENDERER_MEDIA_ANDROID_RENDERER_MEDIA_PLAYER_MANAGER_H_