OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "content/browser/media/android/media_web_contents_observer_android.h" | 5 #include "content/browser/media/android/media_web_contents_observer_android.h" |
6 | 6 |
7 #include "base/callback.h" | |
7 #include "content/browser/media/android/browser_media_player_manager.h" | 8 #include "content/browser/media/android/browser_media_player_manager.h" |
8 #include "content/browser/media/android/browser_media_session_manager.h" | 9 #include "content/browser/media/android/browser_media_session_manager.h" |
9 #include "content/browser/media/android/media_session.h" | 10 #include "content/browser/media/android/media_session.h" |
10 #include "content/browser/media/android/media_session_controller.h" | 11 #include "content/browser/media/android/media_session_controller.h" |
11 #include "content/browser/media/android/media_session_observer.h" | 12 #include "content/browser/media/android/media_session_observer.h" |
12 #include "content/browser/media/cdm/browser_cdm_manager.h" | 13 #include "content/browser/media/cdm/browser_cdm_manager.h" |
13 #include "content/browser/web_contents/web_contents_impl.h" | 14 #include "content/browser/web_contents/web_contents_impl.h" |
14 #include "content/common/media/media_player_delegate_messages.h" | 15 #include "content/common/media/media_player_delegate_messages.h" |
15 #include "content/common/media/media_player_messages_android.h" | 16 #include "content/common/media/media_player_messages_android.h" |
16 #include "content/common/media/media_session_messages_android.h" | 17 #include "content/common/media/media_session_messages_android.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 it != media_player_managers_.end(); ++it) { | 81 it != media_player_managers_.end(); ++it) { |
81 it->second->OnFrameInfoUpdated(); | 82 it->second->OnFrameInfoUpdated(); |
82 } | 83 } |
83 } | 84 } |
84 #endif // defined(VIDEO_HOLE) | 85 #endif // defined(VIDEO_HOLE) |
85 | 86 |
86 void MediaWebContentsObserverAndroid::RenderFrameDeleted( | 87 void MediaWebContentsObserverAndroid::RenderFrameDeleted( |
87 RenderFrameHost* render_frame_host) { | 88 RenderFrameHost* render_frame_host) { |
88 MediaWebContentsObserver::RenderFrameDeleted(render_frame_host); | 89 MediaWebContentsObserver::RenderFrameDeleted(render_frame_host); |
89 | 90 |
91 const int routing_id = render_frame_host->GetRoutingID(); | |
92 for (auto it = focus_waiters_.begin(); it != focus_waiters_.end();) { | |
93 if (it->first == routing_id) | |
94 it = focus_waiters_.erase(it); | |
95 else | |
96 ++it; | |
97 } | |
98 | |
90 for (auto it = media_session_map_.begin(); it != media_session_map_.end();) { | 99 for (auto it = media_session_map_.begin(); it != media_session_map_.end();) { |
91 if (it->first.first == render_frame_host) | 100 if (it->first.first == render_frame_host) |
92 it = media_session_map_.erase(it); | 101 it = media_session_map_.erase(it); |
93 else | 102 else |
94 ++it; | 103 ++it; |
95 } | 104 } |
96 | 105 |
97 // Always destroy the media players before CDMs because we do not support | 106 // Always destroy the media players before CDMs because we do not support |
98 // detaching CDMs from media players yet. See http://crbug.com/330324 | 107 // detaching CDMs from media players yet. See http://crbug.com/330324 |
99 media_player_managers_.erase(render_frame_host); | 108 media_player_managers_.erase(render_frame_host); |
(...skipping 25 matching lines...) Expand all Loading... | |
125 | 134 |
126 if (OnMediaPlayerSetCdmMessageReceived(msg, render_frame_host)) | 135 if (OnMediaPlayerSetCdmMessageReceived(msg, render_frame_host)) |
127 return true; | 136 return true; |
128 | 137 |
129 if (OnMediaSessionMessageReceived(msg, render_frame_host)) | 138 if (OnMediaSessionMessageReceived(msg, render_frame_host)) |
130 return true; | 139 return true; |
131 | 140 |
132 return false; | 141 return false; |
133 } | 142 } |
134 | 143 |
144 void MediaWebContentsObserverAndroid::WaitForAudioFocusAsyncInternal( | |
145 int render_frame_id, | |
146 const base::Closure& focus_cb) { | |
147 // See if audio focus has already been approved for the given render frame; we | |
148 // don't care which delegate it corresponds to, just that one has approval and | |
149 // is actively playing audio. | |
150 for (const auto& kv : media_session_map_) { | |
151 if (kv.first.first->GetRoutingID() == render_frame_id && | |
152 kv.second->is_playing()) { | |
mlamouri (slow - plz ping)
2016/02/03 15:20:51
Couldn't a controller be playing even though it do
| |
153 focus_cb.Run(); | |
154 return; | |
155 } | |
156 } | |
157 | |
158 focus_waiters_.push_back(FocusWaiter(render_frame_id, focus_cb)); | |
159 } | |
160 | |
135 void MediaWebContentsObserverAndroid::OnMediaPlayerDelegateMessageReceived( | 161 void MediaWebContentsObserverAndroid::OnMediaPlayerDelegateMessageReceived( |
136 const IPC::Message& msg, | 162 const IPC::Message& msg, |
137 RenderFrameHost* render_frame_host) { | 163 RenderFrameHost* render_frame_host) { |
138 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(MediaWebContentsObserverAndroid, msg, | 164 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(MediaWebContentsObserverAndroid, msg, |
139 render_frame_host) | 165 render_frame_host) |
140 IPC_MESSAGE_HANDLER(MediaPlayerDelegateHostMsg_OnMediaDestroyed, | 166 IPC_MESSAGE_HANDLER(MediaPlayerDelegateHostMsg_OnMediaDestroyed, |
141 OnMediaDestroyed) | 167 OnMediaDestroyed) |
142 IPC_MESSAGE_HANDLER(MediaPlayerDelegateHostMsg_OnMediaPaused, OnMediaPaused) | 168 IPC_MESSAGE_HANDLER(MediaPlayerDelegateHostMsg_OnMediaPaused, OnMediaPaused) |
143 IPC_MESSAGE_HANDLER(MediaPlayerDelegateHostMsg_OnMediaPlaying, | 169 IPC_MESSAGE_HANDLER(MediaPlayerDelegateHostMsg_OnMediaPlaying, |
144 OnMediaPlaying) | 170 OnMediaPlaying) |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 bool is_remote, | 316 bool is_remote, |
291 base::TimeDelta duration) { | 317 base::TimeDelta duration) { |
292 const MediaPlayerId id(render_frame_host, delegate_id); | 318 const MediaPlayerId id(render_frame_host, delegate_id); |
293 | 319 |
294 // Since we don't remove session instances on pause, there may be an existing | 320 // Since we don't remove session instances on pause, there may be an existing |
295 // instance for this playback attempt. | 321 // instance for this playback attempt. |
296 // | 322 // |
297 // In this case, try to reinitialize it with the new settings. If they are | 323 // In this case, try to reinitialize it with the new settings. If they are |
298 // the same, this is a no-op. If the reinitialize fails, destroy the | 324 // the same, this is a no-op. If the reinitialize fails, destroy the |
299 // controller. A later playback attempt will create a new controller. | 325 // controller. A later playback attempt will create a new controller. |
300 auto it = media_session_map_.find(id); | 326 auto session_it = media_session_map_.find(id); |
301 if (it != media_session_map_.end()) { | 327 if (session_it != media_session_map_.end()) { |
302 if (!it->second->Initialize(has_audio, is_remote, duration)) | 328 if (!session_it->second->Initialize(has_audio, is_remote, duration)) { |
303 media_session_map_.erase(it); | 329 media_session_map_.erase(session_it); |
304 return; | 330 return; |
331 } | |
332 } else { | |
333 scoped_ptr<MediaSessionController> controller( | |
334 new MediaSessionController(id, this)); | |
335 | |
336 if (!controller->Initialize(has_audio, is_remote, duration)) | |
337 return; | |
338 | |
339 media_session_map_[id] = std::move(controller); | |
305 } | 340 } |
306 | 341 |
307 scoped_ptr<MediaSessionController> controller( | 342 // Notify all focus waiters for the render frame that audio output is allowed, |
308 new MediaSessionController(id, this)); | 343 // delegates will still pause audio as necessary in response to focus changes |
309 | 344 // from the media session. |
310 if (!controller->Initialize(has_audio, is_remote, duration)) | 345 const int routing_id = render_frame_host->GetRoutingID(); |
311 return; | 346 for (auto it = focus_waiters_.begin(); it != focus_waiters_.end();) { |
312 | 347 if (it->first == routing_id) { |
313 media_session_map_[id] = std::move(controller); | 348 it->second.Run(); |
349 it = focus_waiters_.erase(it); | |
350 } else { | |
351 ++it; | |
352 } | |
353 } | |
314 } | 354 } |
315 | 355 |
316 } // namespace content | 356 } // namespace content |
OLD | NEW |