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_
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"
26 struct MediaPlayerHostMsg_Initialize_Params
;
29 class WebMediaPlayerAndroid
;
31 // Class for managing all the WebMediaPlayerAndroid objects in the same
33 class RendererMediaPlayerManager
: public RenderFrameObserver
{
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
,
47 const GURL
& first_party_for_cookies
,
48 int demuxer_client_id
,
49 const GURL
& frame_url
,
50 bool allow_credentials
);
53 void Start(int player_id
);
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 to exit fullscreen.
87 void ExitFullscreen(int player_id
);
89 // Requests the player with |player_id| to use the CDM with |cdm_id|.
90 // Does nothing if |cdm_id| is kInvalidCdmId.
91 // TODO(xhwang): Update this when we implement setCdm(0).
92 void SetCdm(int player_id
, int cdm_id
);
94 #if defined(VIDEO_HOLE)
95 // Requests an external surface for out-of-band compositing.
96 void RequestExternalSurface(int player_id
, const gfx::RectF
& geometry
);
98 // RenderFrameObserver overrides.
99 void DidCommitCompositorFrame() override
;
101 // Returns true if a media player should use video-overlay for the embedded
103 bool ShouldUseVideoOverlayForEmbeddedEncryptedVideo();
104 #endif // defined(VIDEO_HOLE)
106 // Registers and unregisters a WebMediaPlayerAndroid object.
107 int RegisterMediaPlayer(WebMediaPlayerAndroid
* player
);
108 void UnregisterMediaPlayer(int player_id
);
110 // Gets the pointer to WebMediaPlayerAndroid given the |player_id|.
111 WebMediaPlayerAndroid
* GetMediaPlayer(int player_id
);
113 #if defined(VIDEO_HOLE)
114 // Gets the list of media players with video geometry changes.
115 void RetrieveGeometryChanges(std::map
<int, gfx::RectF
>* changes
);
116 #endif // defined(VIDEO_HOLE)
120 void OnMediaMetadataChanged(int player_id
,
121 base::TimeDelta duration
,
125 void OnMediaPlaybackCompleted(int player_id
);
126 void OnMediaBufferingUpdate(int player_id
, int percent
);
127 void OnSeekRequest(int player_id
, const base::TimeDelta
& time_to_seek
);
128 void OnSeekCompleted(int player_id
,
129 const base::TimeDelta
& current_timestamp
);
130 void OnMediaError(int player_id
, int error
);
131 void OnVideoSizeChanged(int player_id
, int width
, int height
);
132 void OnTimeUpdate(int player_id
,
133 base::TimeDelta current_timestamp
,
134 base::TimeTicks current_time_ticks
);
135 void OnMediaPlayerReleased(int player_id
);
136 void OnConnectedToRemoteDevice(int player_id
,
137 const std::string
& remote_playback_message
);
138 void OnDisconnectedFromRemoteDevice(int player_id
);
139 void OnDidExitFullscreen(int player_id
);
140 void OnDidEnterFullscreen(int player_id
);
141 void OnPlayerPlay(int player_id
);
142 void OnPlayerPause(int player_id
);
143 void OnRequestFullscreen(int player_id
);
144 void OnRemoteRouteAvailabilityChanged(int player_id
, bool routes_available
);
146 // Release all video player resources.
147 // If something is in progress the resource will not be freed. It will
148 // only be freed once the tab is destroyed or if the user navigates away
149 // via WebMediaPlayerAndroid::Destroy.
150 void ReleaseVideoResources();
152 // Info for all available WebMediaPlayerAndroid on a page; kept so that
153 // we can enumerate them to send updates about tab focus and visibility.
154 std::map
<int, WebMediaPlayerAndroid
*> media_players_
;
156 int next_media_player_id_
;
158 DISALLOW_COPY_AND_ASSIGN(RendererMediaPlayerManager
);
161 } // namespace content
163 #endif // CONTENT_RENDERER_MEDIA_ANDROID_RENDERER_MEDIA_PLAYER_MANAGER_H_